summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog16
-rw-r--r--src/configuration.c114
-rw-r--r--src/configuration.h8
-rw-r--r--src/editor.c118
-rw-r--r--src/params.h18
-rw-r--r--src/project.c20
-rw-r--r--src/project.h4
7 files changed, 258 insertions, 40 deletions
diff --git a/ChangeLog b/ChangeLog
index 6d4fcd5..dd752ac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+09-11-20 Cyrille Bagard <nocbos@gmail.com>
+
+ * src/configuration.c:
+ * src/configuration.h:
+ Handle boolean values in configurations.
+
+ * src/editor.c:
+ Better supervise the closing of the editor.
+
+ * src/params.h:
+ Define an (not yet used) 'Auto save' parameter.
+
+ * src/project.c:
+ * src/project.h:
+ Provide the storing filename instead of only telling if there is one or not.
+
09-11-19 Cyrille Bagard <nocbos@gmail.com>
* configure.ac:
diff --git a/src/configuration.c b/src/configuration.c
index 8823271..5d17072 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -27,6 +27,7 @@
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "xdg.h"
@@ -73,9 +74,16 @@ configuration *load_configuration(const char *name, config_param *params, unsign
result = (configuration *)calloc(1, sizeof(configuration));
+ printf("reset...\n");
+
+ for (i = 0; i < count; i++)
+ params[i].cur = params[i].def;
+
result->params = params;
result->count = count;
+ printf("init done\n");
+
suffix = strdup("openida/");
suffix = stradd(suffix, name);
suffix = stradd(suffix, ".xml");
@@ -91,6 +99,15 @@ configuration *load_configuration(const char *name, config_param *params, unsign
for (i = 0; i < count; i++)
switch (params[i].type)
{
+ case CVT_BOOLEAN:
+ strval = get_node_text_value(result->context, params[i].path);
+ if (strval != NULL)
+ {
+ set_boolean_config_value(result, i, strcmp(strval, "true") == 0);
+ free(strval);
+ }
+ break;
+
case CVT_STRING:
strval = get_node_text_value(result->context, params[i].path);
set_string_config_value(result, i, strval);
@@ -101,7 +118,7 @@ configuration *load_configuration(const char *name, config_param *params, unsign
break;
}
-
+ printf("loaded\n");
return result;
}
@@ -122,19 +139,52 @@ configuration *load_configuration(const char *name, config_param *params, unsign
void unload_configuration(configuration *config)
{
unsigned int i; /* Boucle de parcours */
+ config_param *params; /* Confort d'utilisation */
printf("Writing '%s'\n", config->filename);
+ close_xml_file(config->xdoc, config->context);
+ create_new_xml_file(&config->xdoc, &config->context);
+
+
for (i = 0; i < config->count; i++)
- switch (1)
+ {
+ params = &config->params[i];
+
+ switch (params->type)
{
- case 1:
+ case CVT_BOOLEAN:
+ if (params->cur.boolean == params->def.boolean)
+ continue;
+
+ add_content_to_node(config->xdoc, config->context,
+ params->path,
+ params->cur.boolean ? "true" : "false");
+
+ break;
+
+ case CVT_STRING:
+
+ if (params->cur.string == NULL && params->def.string == NULL)
+ continue;
+
+ if (params->def.string != NULL && params->def.string != NULL
+ && strcmp(params->cur.string, params->def.string) == 0)
+ continue;
+
add_content_to_node(config->xdoc, config->context,
- config->params[i].path, config->params[i].cur.string);
+ params->path,
+ params->cur.string != NULL ? params->cur.string : "");
+
+ break;
+
+ default:
break;
}
+ }
+
save_xml_file(config->xdoc, config->filename);
free(config);
@@ -148,6 +198,62 @@ void unload_configuration(configuration *config)
* index = indice de l'élément à traiter. *
* value = valeur à considérer comme valeur courante. *
* *
+* Description : Définit une valeur booléenne dans la configuration. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool set_boolean_config_value(configuration *config, unsigned int index, bool value)
+{
+ if (index >= config->count) return false;
+ if (config->params[index].type != CVT_BOOLEAN) return false;
+
+ config->params[index].defined = true;
+
+ config->params[index].cur.boolean = value;
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : config = configuration à venir consulter. *
+* index = indice de l'élément à traiter. *
+* *
+* Description : Fournit une valeur booléenne issue de la configuration. *
+* *
+* Retour : Valeur courante ou par défaut de la configuration. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool get_boolean_config_value(configuration *config, unsigned int index)
+{
+ bool result; /* Valeur à retourner */
+
+ if (index >= config->count) return NULL;
+ if (config->params[index].type != CVT_BOOLEAN) return NULL;
+
+ if (config->params[index].defined) result = config->params[index].cur.boolean;
+ else result = config->params[index].def.boolean;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : config = configuration à venir consulter. *
+* index = indice de l'élément à traiter. *
+* value = valeur à considérer comme valeur courante. *
+* *
* Description : Définit une chaîne de caractères dans la configuration. *
* *
* Retour : - *
diff --git a/src/configuration.h b/src/configuration.h
index 645b17e..4600a7a 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -31,6 +31,7 @@
/* Tyoes de valeur pour élement de configuration */
typedef enum _ConfigValueType
{
+ CVT_BOOLEAN, /* Valeur booléenne */
CVT_STRING, /* Chaîne de caractère */
CVT_COUNT
@@ -40,6 +41,7 @@ typedef enum _ConfigValueType
/* Valeurs supportées par les configurations */
typedef union _config_value
{
+ bool boolean; /* Valeur booléenne */
char *string; /* Chaîne de caractère */
} config_value;
@@ -69,6 +71,12 @@ configuration *load_configuration(const char *, config_param *, unsigned int);
/* Décharge la configuration principale. */
void unload_configuration(configuration *);
+/* Définit une valeur booléenne dans la configuration. */
+bool set_boolean_config_value(configuration *, unsigned int, bool);
+
+/* Fournit une valeur booléenne issue de la configuration. */
+bool get_boolean_config_value(configuration *, unsigned int);
+
/* Définit une chaîne de caractères dans la configuration. */
bool set_string_config_value(configuration *, unsigned int, const char *);
diff --git a/src/editor.c b/src/editor.c
index eed0868..5e39f27 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -69,8 +69,10 @@ void sigchld_handler(int num);
GtkWidget *create_editor(void);
/* Quitte le programme en sortie de la boucle de GTK. */
-void destroy_editor(GtkWidget *, gpointer);
+static gboolean on_delete_editor(GtkWidget *, GdkEvent *, gpointer);
+/* Quitte le programme en sortie de la boucle de GTK. */
+static void on_destroy_editor(GtkWidget *, gpointer);
/* Réagit au menu "Fichier -> Nouveau projet". */
void mcb_file_new_project(GtkMenuItem *, gpointer);
@@ -216,7 +218,8 @@ GtkWidget *create_editor(void)
gtk_container_set_border_width(GTK_CONTAINER(result), 4);
gtk_window_set_title(GTK_WINDOW(result), _("OpenIDA"));
- g_signal_connect(G_OBJECT(result), "destroy", G_CALLBACK(destroy_editor), NULL);
+ g_signal_connect(G_OBJECT(result), "delete-event", G_CALLBACK(on_delete_editor), NULL);
+ g_signal_connect(G_OBJECT(result), "destroy", G_CALLBACK(on_destroy_editor), NULL);
ref = G_OBJECT(result);
@@ -554,6 +557,7 @@ GtkWidget *create_editor(void)
/******************************************************************************
* *
* Paramètres : widget = fenêtre de l'éditeur de préférences. *
+* event = informations liées à l'événement. *
* data = adresse non utilisée ici. *
* *
* Description : Quitte le programme en sortie de la boucle de GTK. *
@@ -564,15 +568,77 @@ GtkWidget *create_editor(void)
* *
******************************************************************************/
-void destroy_editor(GtkWidget *widget, gpointer data)
+static gboolean on_delete_editor(GtkWidget *widget, GdkEvent *event, gpointer data)
{
- close_openida_project(get_current_openida_project());
+ gboolean result; /* Continuation à retourner */
+ openida_project *project; /* Projet courant */
+ GtkWidget *dialog; /* Boîte à afficher */
- gtk_main_quit();
+ result = FALSE;
+
+ project = get_current_openida_project();
+
+ if (g_openida_project_get_filename(project) == NULL)
+ {
+ dialog = gtk_message_dialog_new(widget,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ _("The current project will be lost. Do you you want to save it ?"));
+
+ gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_YES, GTK_RESPONSE_YES);
+ gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_NO, GTK_RESPONSE_NO);
+ gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+
+ switch (gtk_dialog_run(GTK_DIALOG(dialog)))
+ {
+ case GTK_RESPONSE_YES:
+ mcb_file_save_project_as(NULL, widget);
+ break;
+
+ case GTK_RESPONSE_NO:
+ break;
+
+ case GTK_RESPONSE_CANCEL:
+ result = TRUE;
+ break;
+
+ }
+
+ gtk_widget_destroy(dialog);
+
+ }
+
+ return result;
}
+/******************************************************************************
+* *
+* Paramètres : widget = fenêtre de l'éditeur de préférences. *
+* event = informations liées à l'événement. *
+* data = adresse non utilisée ici. *
+* *
+* Description : Quitte le programme en sortie de la boucle de GTK. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void on_destroy_editor(GtkWidget *widget, gpointer data)
+{
+ close_openida_project(get_current_openida_project());
+
+ /* Fermeture propre */
+
+ /* ... */
+
+ gtk_main_quit();
+
+}
@@ -620,16 +686,21 @@ void mcb_file_new_project(GtkMenuItem *menuitem, gpointer data)
void mcb_file_open_project(GtkMenuItem *menuitem, gpointer data)
{
GtkWidget *dialog; /* Boîte à afficher */
- gchar *filename; /* Nom du fichier à intégrer */
openida_project *project; /* Projet chargé */
+ gchar *filename; /* Nom du fichier à intégrer */
- dialog = gtk_file_chooser_dialog_new (_("Open a project"), GTK_WINDOW(data),
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
+ dialog = gtk_file_chooser_dialog_new(_("Open a project"), GTK_WINDOW(data),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ project = get_current_openida_project();
+
+ if (g_openida_project_get_filename(project) != NULL)
+ gtk_file_chooser_set_filename(dialog, g_openida_project_get_filename(project));
- if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
@@ -669,7 +740,7 @@ void mcb_file_save_project(GtkMenuItem *menuitem, gpointer data)
project = get_current_openida_project();
- if (has_storing_filename(project))
+ if (g_openida_project_get_filename(project) != NULL)
{
if (g_openida_project_save(project, NULL))
push_openida_project_into_recent_list(project);
@@ -700,16 +771,19 @@ void mcb_file_save_project_as(GtkMenuItem *menuitem, gpointer data)
openida_project *project; /* Projet courant */
gchar *filename; /* Nom du fichier à intégrer */
- dialog = gtk_file_chooser_dialog_new (_("Save the project as..."), GTK_WINDOW(data),
- GTK_FILE_CHOOSER_ACTION_SAVE,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
+ dialog = gtk_file_chooser_dialog_new(_("Save the project as..."), GTK_WINDOW(data),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
- if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
- {
- project = get_current_openida_project();
+ project = get_current_openida_project();
+
+ if (g_openida_project_get_filename(project) != NULL)
+ gtk_file_chooser_set_filename(dialog, g_openida_project_get_filename(project));
+ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
+ {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
if (g_openida_project_save(project, filename))
@@ -892,7 +966,7 @@ void mcb_project_add_binary(GtkMenuItem *menuitem, gpointer data)
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
- if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
diff --git a/src/params.h b/src/params.h
index c37ef9f..11985b6 100644
--- a/src/params.h
+++ b/src/params.h
@@ -46,19 +46,23 @@ typedef enum _MainParamType
MPT_RECENT_PROJECT_6, /* Projet récent numéro 6 */
MPT_RECENT_PROJECT_7, /* Projet récent numéro 7 */
+ MPT_AUTO_SAVE, /* Sauvegarde automatique ? */
+
MPT_COUNT
} MainParamType;
static config_param main_params[MPT_COUNT] = {
- [MPT_RECENT_PROJECT_1] = { "/OpenIDA/Recents/Project1", CVT_STRING, false, NULL, NULL },
- [MPT_RECENT_PROJECT_2] = { "/OpenIDA/Recents/Project2", CVT_STRING, false, NULL, NULL },
- [MPT_RECENT_PROJECT_3] = { "/OpenIDA/Recents/Project3", CVT_STRING, false, NULL, NULL },
- [MPT_RECENT_PROJECT_4] = { "/OpenIDA/Recents/Project4", CVT_STRING, false, NULL, NULL },
- [MPT_RECENT_PROJECT_5] = { "/OpenIDA/Recents/Project5", CVT_STRING, false, NULL, NULL },
- [MPT_RECENT_PROJECT_6] = { "/OpenIDA/Recents/Project6", CVT_STRING, false, NULL, NULL },
- [MPT_RECENT_PROJECT_7] = { "/OpenIDA/Recents/Project7", CVT_STRING, false, NULL, NULL },
+ [MPT_RECENT_PROJECT_1] = { "/OpenIDA/Recents/Project1", CVT_STRING, false, NULL, NULL },
+ [MPT_RECENT_PROJECT_2] = { "/OpenIDA/Recents/Project2", CVT_STRING, false, NULL, NULL },
+ [MPT_RECENT_PROJECT_3] = { "/OpenIDA/Recents/Project3", CVT_STRING, false, NULL, NULL },
+ [MPT_RECENT_PROJECT_4] = { "/OpenIDA/Recents/Project4", CVT_STRING, false, NULL, NULL },
+ [MPT_RECENT_PROJECT_5] = { "/OpenIDA/Recents/Project5", CVT_STRING, false, NULL, NULL },
+ [MPT_RECENT_PROJECT_6] = { "/OpenIDA/Recents/Project6", CVT_STRING, false, NULL, NULL },
+ [MPT_RECENT_PROJECT_7] = { "/OpenIDA/Recents/Project7", CVT_STRING, false, NULL, NULL },
+
+ [MPT_AUTO_SAVE] = { "/OpenIDA/Project/Autosave", CVT_BOOLEAN, false, true, NULL },
};
diff --git a/src/project.c b/src/project.c
index 1366abf..5bb7b56 100644
--- a/src/project.c
+++ b/src/project.c
@@ -435,6 +435,17 @@ void close_openida_project(openida_project *project)
size_t max; /* Nombre de binaires chargés */
size_t i; /* Boucle de parcours */
+
+
+
+ /* TODO : sauvegarde automatique */
+
+
+
+
+ /* Fermeture propre */
+
+
max = project->binaries_count;
for (i = 0; i < max; i++)
@@ -453,24 +464,23 @@ void close_openida_project(openida_project *project)
* *
* Paramètres : project = project à consulter. *
* *
-* Description : Indique si un projet a tous les éléments pour être sauvé. *
+* Description : Indique le chemin du fichier destiné à la sauvegarde. *
* *
-* Retour : true si aucun nom de fichier n'a à être fourni. *
+* Retour : Chemin de fichier pour l'enregistrement ou NULL si indéfini. *
* *
* Remarques : - *
* *
******************************************************************************/
-bool has_storing_filename(const openida_project *project)
+const char *g_openida_project_get_filename(const openida_project *project)
{
- return (project->filename != NULL);
+ return project->filename;
}
-
/******************************************************************************
* *
* Paramètres : project = project à effacer de la mémoire. *
diff --git a/src/project.h b/src/project.h
index da05aeb..1314b1d 100644
--- a/src/project.h
+++ b/src/project.h
@@ -70,8 +70,8 @@ bool g_openida_project_save(openida_project *, const char *);
/* Ferme un projet et libère la mémoire associée. */
void close_openida_project(openida_project *);
-/* Indique si un projet a tous les éléments pour être sauvé. */
-bool has_storing_filename(const openida_project *);
+/* Indique le chemin du fichier destiné à la sauvegarde. */
+const char *g_openida_project_get_filename(const openida_project *);