[gnome-pilot-conduits] avoid deprecated gtk symbols for email_conduit and expense_conduit. #594214
- From: Matthew Charles Davey <mcdavey src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-pilot-conduits] avoid deprecated gtk symbols for email_conduit and expense_conduit. #594214
- Date: Sun, 10 Oct 2010 21:56:06 +0000 (UTC)
commit 5b4bca8b0d91e86bf61361f8551b1c9a8faf3fe3
Author: Matt Davey <mcdavey mrao cam ac uk>
Date: Sun Oct 10 21:14:18 2010 +0100
avoid deprecated gtk symbols for email_conduit and expense_conduit. #594214
email/email_conduit.c: port to gtk_file_chooser,
expense/expense_conduit.c: avoid gnome.h, port gnome_config to GKeyFile,
avoid gtk_{get,set}_data, remove option_menus, etc.
expense/expense_conduit.h: avoid gtk_{get,set}_data in macros
email/email_conduit.c | 124 ++++++--------------
expense/expense_conduit.c | 280 +++++++++++++++++++++++++++++++++------------
expense/expense_conduit.h | 9 +-
3 files changed, 248 insertions(+), 165 deletions(-)
---
diff --git a/email/email_conduit.c b/email/email_conduit.c
index 3d67796..661ad77 100644
--- a/email/email_conduit.c
+++ b/email/email_conduit.c
@@ -39,6 +39,9 @@
#define EC_PAD 8
+const char *EC_SEND_ACTION [] = {"delete", "file"};
+const char *EC_RECV_ACTION [] = {"copy", "delete", "mirror"};
+
GnomePilotConduit *conduit_get_gpilot_conduit( guint32 pilotId ) ;
void conduit_destroy_gpilot_conduit( GnomePilotConduit *c );
static gboolean save_config (GKeyFile *kfile, const gchar *conf);
@@ -784,37 +787,6 @@ gint copy_from_pilot( GnomePilotConduit *c, GnomePilotDBInfo *dbi ) {
return( synchronize( c, dbi ) );
}
-void
-handleFileSelector (GtkWidget *widget, gpointer data)
-{
- GtkWidget *fs = data;
- GtkWidget *entry = GTK_WIDGET(g_object_get_data(G_OBJECT(fs), "entry"));
- const gchar *fname;
-
- fname = gtk_file_selection_get_filename (GTK_FILE_SELECTION(fs));
- gtk_entry_set_text(GTK_ENTRY(entry), fname);
-}
-
-
-void
-createFileSelector (GtkWidget *widget, gpointer data)
-{
- GtkWidget *fs;
-
- fs = gtk_file_selection_new(_("Select an mbox file or an MH directory"));
- g_object_set_data(G_OBJECT(fs), "entry", (gpointer) data);
- g_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
- "clicked", G_CALLBACK(handleFileSelector), fs);
-
- g_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(fs)->ok_button),
- "clicked", G_CALLBACK (gtk_widget_destroy), (gpointer) fs, G_CONNECT_AFTER);
- g_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(fs)->cancel_button),
- "clicked", G_CALLBACK (gtk_widget_destroy), (gpointer) fs, G_CONNECT_AFTER);
-
- gtk_widget_show (fs);
- gtk_grab_add (fs); /* take focus from the settings dialog */
-}
-
static GtkWidget
*createCfgWindow (GnomePilotConduit* conduit)
{
@@ -833,19 +805,11 @@ static GtkWidget
/* send_action option menu */
label = gtk_label_new(_("Send Action:"));
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
- widget = gtk_option_menu_new ();
- menu = gtk_menu_new();
- menuItem = gtk_menu_item_new_with_label (_("Delete from PDA"));
- gtk_widget_show(menuItem);
- g_object_set_data(G_OBJECT(menuItem), "short", "delete");
- g_object_set_data(G_OBJECT(widget), "delete", (gpointer) 0);
- gtk_menu_append (GTK_MENU (menu), GTK_WIDGET (menuItem));
- menuItem = gtk_menu_item_new_with_label (_("File on PDA"));
- gtk_widget_show(menuItem);
- g_object_set_data(G_OBJECT(menuItem), "short", "file");
- g_object_set_data(G_OBJECT(widget), "file", (gpointer) 1);
- gtk_menu_append (GTK_MENU (menu), GTK_WIDGET (menuItem));
- gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), GTK_WIDGET (menu));
+ widget = gtk_combo_box_new_text ();
+ gtk_combo_box_append_text(GTK_COMBO_BOX(widget), (_("Delete from PDA")));
+ g_object_set_data(G_OBJECT(widget), EC_SEND_ACTION[0], GINT_TO_POINTER(0));
+ gtk_combo_box_append_text(GTK_COMBO_BOX(widget), _("File on PDA"));
+ g_object_set_data(G_OBJECT(widget), EC_SEND_ACTION[1], GINT_TO_POINTER(1));
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table), widget, 1, 2, 0, 1);
g_object_set_data(G_OBJECT(vbox), "send_action", widget);
@@ -853,7 +817,8 @@ static GtkWidget
/* from_address entry */
label = gtk_label_new(_("From:"));
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
- widget = gtk_entry_new_with_max_length(128);
+ widget = gtk_entry_new();
+ gtk_entry_set_max_length(GTK_ENTRY(widget), 128);
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
gtk_table_attach_defaults(GTK_TABLE(table), widget, 1, 2, 1, 2);
g_object_set_data(G_OBJECT(vbox), "from_address", widget);
@@ -861,7 +826,9 @@ static GtkWidget
/* sendmail entry */
label = gtk_label_new(_("Sendmail command:"));
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
- widget = gtk_entry_new_with_max_length(128);
+ widget = gtk_entry_new();
+ gtk_entry_set_max_length(GTK_ENTRY(widget), 128);
+
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3);
gtk_table_attach_defaults(GTK_TABLE(table), widget, 1, 2, 2, 3);
g_object_set_data(G_OBJECT(vbox), "sendmail", widget);
@@ -869,41 +836,27 @@ static GtkWidget
/* receive_action option menu */
label = gtk_label_new (_("Receive Action:"));
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
- widget = gtk_option_menu_new ();
- menu = gtk_menu_new ();
- menuItem = gtk_menu_item_new_with_label (_("Copy from Inbox"));
- gtk_widget_show(menuItem);
- g_object_set_data(G_OBJECT(menuItem), "short", "copy");
- g_object_set_data(G_OBJECT(widget), "copy", (gpointer) 0);
- gtk_menu_append (GTK_MENU (menu), GTK_WIDGET (menuItem));
- menuItem = gtk_menu_item_new_with_label (_("Delete from Inbox"));
- gtk_widget_show(menuItem);
- g_object_set_data(G_OBJECT(menuItem), "short", "delete");
- g_object_set_data(G_OBJECT(widget), "delete", (gpointer) 1);
- gtk_menu_append (GTK_MENU (menu), GTK_WIDGET (menuItem));
- menuItem = gtk_menu_item_new_with_label (_("Mirror Inbox"));
- gtk_widget_show(menuItem);
- g_object_set_data(G_OBJECT(menuItem), "short", "mirror");
- g_object_set_data(G_OBJECT(widget), "mirror", (gpointer) 2);
- gtk_menu_append (GTK_MENU (menu), GTK_WIDGET (menuItem));
- gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), GTK_WIDGET (menu));
+ widget = gtk_combo_box_new_text ();
+ gtk_combo_box_append_text(GTK_COMBO_BOX(widget), _("Copy from Inbox"));
+ g_object_set_data(G_OBJECT(widget), EC_RECV_ACTION[0], GINT_TO_POINTER(0));
+ gtk_combo_box_append_text(GTK_COMBO_BOX(widget), _("Delete from Inbox"));
+ g_object_set_data(G_OBJECT(widget), EC_RECV_ACTION[1], GINT_TO_POINTER(1));
+ gtk_combo_box_append_text(GTK_COMBO_BOX(widget), _("Mirror Inbox"));
+ g_object_set_data(G_OBJECT(widget), EC_RECV_ACTION[2], GINT_TO_POINTER(2));
gtk_table_attach_defaults (GTK_TABLE(table), label, 0, 1, 3, 4);
gtk_table_attach_defaults(GTK_TABLE(table), widget, 1, 2, 3, 4);
g_object_set_data(G_OBJECT(vbox), "receive_action", widget);
+
/* mbox_file entry */
label = gtk_label_new(_("Copy mail from:"));
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
- widget = gtk_entry_new_with_max_length(128);
- button = gtk_button_new_with_label("...");
- g_signal_connect(GTK_OBJECT(button), "clicked",
- G_CALLBACK(createFileSelector), widget);
- box = gtk_hbox_new(FALSE, 0);
- gtk_box_pack_end(GTK_BOX(box), button, FALSE, FALSE, 0);
- gtk_box_pack_end(GTK_BOX(box), widget, TRUE, TRUE, 0);
+ widget = gtk_file_chooser_button_new (_("Select a file"),
+ GTK_FILE_CHOOSER_ACTION_OPEN);
+
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 4, 5);
- gtk_table_attach_defaults(GTK_TABLE(table), box, 1, 2, 4, 5);
+ gtk_table_attach_defaults(GTK_TABLE(table), widget, 1, 2, 4, 5);
g_object_set_data(G_OBJECT(vbox), "mbox_file", widget);
return vbox;
@@ -923,21 +876,21 @@ setOptionsCfg(GtkWidget *cfg, ConduitCfg *c)
receive_action = g_object_get_data(G_OBJECT(cfg), "receive_action");
mbox_file = g_object_get_data(G_OBJECT(cfg), "mbox_file");
- id = (guint) g_object_get_data(G_OBJECT(send_action), c->sendAction);
- gtk_option_menu_set_history(GTK_OPTION_MENU(send_action), id);
+ id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(send_action), c->sendAction));
+ gtk_combo_box_set_active(GTK_COMBO_BOX(send_action), id);
gtk_entry_set_text(GTK_ENTRY(from_address), (c->fromAddr ? c->fromAddr : ""));
gtk_entry_set_text(GTK_ENTRY(sendmail), (c->sendmail ? c->sendmail : ""));
- id = (guint) g_object_get_data(G_OBJECT(receive_action), c->receiveAction);
- gtk_option_menu_set_history(GTK_OPTION_MENU(receive_action), id);
+ id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(receive_action), c->receiveAction));
+ gtk_combo_box_set_active(GTK_COMBO_BOX(receive_action), id);
if (c->mboxFile && 0 != strcmp(c->mboxFile, "")) {
- gtk_entry_set_text(GTK_ENTRY(mbox_file), c->mboxFile);
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(mbox_file), c->mboxFile);
} else if (c->mhDirectory) {
- gtk_entry_set_text(GTK_ENTRY(mbox_file), c->mhDirectory);
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(mbox_file), c->mhDirectory);
} else {
- gtk_entry_set_text(GTK_ENTRY(mbox_file), "");
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(mbox_file), "");
}
}
@@ -947,6 +900,7 @@ readOptionsCfg(GtkWidget *cfg, ConduitCfg *c)
GtkWidget *send_action, *from_address, *sendmail, *receive_action, *mbox_file;
GtkWidget *menu, *menuItem;
gchar *str;
+ gint id;
struct stat mboxStat;
/* fetch all the controls from the cfg window */
@@ -956,9 +910,8 @@ readOptionsCfg(GtkWidget *cfg, ConduitCfg *c)
receive_action = g_object_get_data(G_OBJECT(cfg), "receive_action");
mbox_file = g_object_get_data(G_OBJECT(cfg), "mbox_file");
- menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(send_action));
- menuItem = gtk_menu_get_active(GTK_MENU(menu));
- str = g_strdup(g_object_get_data(G_OBJECT(menuItem), "short"));
+ id = gtk_combo_box_get_active(GTK_COMBO_BOX(send_action));
+ str = g_strdup(EC_SEND_ACTION[id]);
g_free(c->sendAction);
c->sendAction = str;
@@ -978,13 +931,12 @@ readOptionsCfg(GtkWidget *cfg, ConduitCfg *c)
g_free(c->sendmail);
c->sendmail = str;
- menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(receive_action));
- menuItem = gtk_menu_get_active(GTK_MENU(menu));
- str = g_strdup(g_object_get_data(G_OBJECT(menuItem), "short"));
+ id = gtk_combo_box_get_active(GTK_COMBO_BOX(receive_action));
+ str = g_strdup(EC_RECV_ACTION[id]);
g_free(c->receiveAction);
c->receiveAction = str;
- str = gtk_editable_get_chars(GTK_EDITABLE(mbox_file), 0, -1);
+ str = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(mbox_file));
if (0 == strcmp(str, "")) {
g_free(str);
str = NULL;
diff --git a/expense/expense_conduit.c b/expense/expense_conduit.c
index b96db70..aded2a5 100644
--- a/expense/expense_conduit.c
+++ b/expense/expense_conduit.c
@@ -7,7 +7,8 @@
#endif
#include <glib.h>
-#include <gnome.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
#include <pi-source.h>
#include <pi-socket.h>
@@ -29,8 +30,13 @@
#define CONDUIT_VERSION "0.3"
+#define EC_PAD 8
+
GnomePilotConduit *conduit_get_gpilot_conduit( guint32 pilotId );
void conduit_destroy_gpilot_conduit( GnomePilotConduit *c );
+static gboolean save_config (GKeyFile *kfile, const gchar *conf);
+static GKeyFile* get_kfile (const gchar *conf);
+static void migrate_conf (const gchar *old, const gchar *new);
/* Following depend on the ordering in pi-expense.h ! */
static gchar *ExpenseTypeName[] = { "Airfare", "Breakfast", "Bus", "BusinessMeals", "CarRental",
@@ -59,56 +65,83 @@ static gchar *ExpenseCurrencyName[] = { "AU$", "S", "BF", "R$", "$CN", "DKK", "M
static void
load_configuration(ConduitCfg **c,guint32 pilotId)
{
- gchar *prefix;
+ gchar *iPilot;
+ GKeyFile *kfile;
+ GError *error = NULL;
+
gchar *tempbuf;
g_assert(c!=NULL);
*c = g_new0(ConduitCfg,1);
(*c)->child = -1;
- prefix = g_strdup_printf(CONFIG_PREFIX,pilotId);
-
- gnome_config_push_prefix(prefix);
- (*c)->dir = gnome_config_get_string( "dir");
- (*c)->dateFormat = gnome_config_get_string( "date_format=%x");
- (*c)->outputFormat = gnome_config_get_int("output_format=0");
- tempbuf = gnome_config_get_string("dir mode=0700");
+ kfile = get_kfile("expense-conduit");
+ iPilot = g_strdup_printf ("Pilot_%u", pilotId);
+
+ (*c)->dir = g_key_file_get_string (kfile, iPilot, "dir", &error);
+ if (error) {
+ (*c)->dir = NULL;
+ error = NULL;
+ }
+
+ (*c)->dateFormat = g_key_file_get_string (kfile, iPilot, "date_format", &error);
+ if (error) {
+ (*c)->dateFormat = g_strdup("%x");
+ error = NULL;
+ }
+
+ (*c)->outputFormat = g_key_file_get_integer (kfile, iPilot, "output_format", &error);
+ if (error) {
+ (*c)->outputFormat = 0;
+ error = NULL;
+ }
+
+ tempbuf = g_key_file_get_string (kfile, iPilot, "dir mode", &error);
+ if (error) {
+ tempbuf = g_strdup("0700");
+ error = NULL;
+ }
(*c)->dirMode =(mode_t)strtol(tempbuf,NULL,0);
g_free(tempbuf);
- tempbuf = gnome_config_get_string("file mode=0600");
- (*c)->fileMode =(mode_t)strtol(tempbuf,NULL,0);
+
+ tempbuf = g_key_file_get_string (kfile, iPilot, "file mode", &error);
+ if (error) {
+ tempbuf = g_strdup("0600");
+ error = NULL;
+ }
+ (*c)->fileMode =(mode_t)strtol(tempbuf,NULL,0);
g_free(tempbuf);
- gnome_config_pop_prefix();
(*c)->pilotId = pilotId;
- g_free(prefix);
+ g_free (iPilot);
+ g_key_file_free (kfile);
}
static void
save_configuration(ConduitCfg *c)
{
- gchar *prefix;
+ gchar *iPilot;
+ GKeyFile *kfile;
+
char buf[20];
g_assert(c!=NULL);
- prefix = g_strdup_printf("/gnome-pilot.d/expense-conduit/Pilot_%u/",c->pilotId);
+ kfile = get_kfile("expense-conduit");
+ iPilot = g_strdup_printf ("Pilot_%u", c->pilotId);
- gnome_config_push_prefix(prefix);
- gnome_config_set_string("dir", c->dir);
- gnome_config_set_string("date_format", c->dateFormat);
- gnome_config_set_int("output_format", c->outputFormat);
+ g_key_file_set_string (kfile, iPilot, "dir", c->dir);
+ g_key_file_set_string (kfile, iPilot, "date_format", c->dateFormat);
+ g_key_file_set_integer (kfile, iPilot, "output_format", c->outputFormat);
g_snprintf(buf,sizeof(buf),"0%o", c->dirMode);
- gnome_config_set_string("dir mode", buf);
+ g_key_file_set_string (kfile, iPilot, "dir mode", buf);
g_snprintf(buf,sizeof(buf),"0%o", c->fileMode);
- gnome_config_set_string("file mode", buf);
+ g_key_file_set_string (kfile, iPilot, "file mode", buf);
- gnome_config_pop_prefix();
+ g_free (iPilot);
- gnome_config_sync();
- gnome_config_drop_all();
- g_free(prefix);
+ save_config (kfile, "expense-conduit");
}
static void
@@ -486,37 +519,30 @@ static GtkWidget
{
GtkWidget *vbox, *table;
GtkWidget *entry, *label;
- GtkWidget *menuItem, *optionMenu;
- GtkMenu *menu;
+ GtkWidget *optionMenu;
int i, count=0, widget_offset;
- vbox = gtk_vbox_new(FALSE, GNOME_PAD);
+ vbox = gtk_vbox_new(FALSE, EC_PAD);
table = gtk_table_new(2, 5, FALSE);
gtk_table_set_row_spacings(GTK_TABLE(table), 4);
gtk_table_set_col_spacings(GTK_TABLE(table), 10);
- gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, GNOME_PAD);
+ gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, EC_PAD);
/* set the date format */
label = gtk_label_new(_("Date Format:"));
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
- menu = GTK_MENU(gtk_menu_new());
+ optionMenu = gtk_combo_box_new_text();
for (i = 0; i < DATE_OPTIONS_COUNT; i++) {
- menuItem = gtk_menu_item_new_with_label(_(date_options[i].name));
- gtk_widget_show(menuItem);
- gtk_object_set_data(GTK_OBJECT(menuItem), "format",
- date_options[i].format);
- gtk_menu_append(menu, menuItem);
+ gtk_combo_box_append_text(GTK_COMBO_BOX(optionMenu),
+ _(date_options[i].name));
}
- optionMenu = gtk_option_menu_new();
- gtk_option_menu_set_menu(GTK_OPTION_MENU(optionMenu),GTK_WIDGET(menu));
-
gtk_table_attach_defaults(GTK_TABLE(table), optionMenu, 1, 2, 1, 2);
- gtk_object_set_data(GTK_OBJECT(vbox), "DateFormat", optionMenu);
+ g_object_set_data(G_OBJECT(vbox), "DateFormat", optionMenu);
/* set the writeout format */
label = gtk_label_new(_("Output Format:"));
@@ -524,20 +550,14 @@ static GtkWidget
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3);
- menu = GTK_MENU(gtk_menu_new());
+ optionMenu = gtk_combo_box_new_text();
for (i = 0; i < WRITEOUT_OPTIONS_COUNT; i++) {
- menuItem = gtk_menu_item_new_with_label(_(writeout_options[i].name));
- gtk_widget_show(menuItem);
- gtk_object_set_data (GTK_OBJECT (menuItem), "format",
- &writeout_options[i].format);
- gtk_menu_append(menu, menuItem);
+ gtk_combo_box_append_text(GTK_COMBO_BOX (optionMenu),
+ _(writeout_options[i].name));
}
- optionMenu = gtk_option_menu_new();
- gtk_option_menu_set_menu(GTK_OPTION_MENU(optionMenu),GTK_WIDGET(menu));
-
gtk_table_attach_defaults(GTK_TABLE(table), optionMenu, 1, 2, 2, 3);
- gtk_object_set_data(GTK_OBJECT(vbox), "OutputFormat", optionMenu);
+ g_object_set_data(G_OBJECT(vbox), "OutputFormat", optionMenu);
/* ugh, so we have an asymmetry here: above is done in paste© fashion
and below, we do it nicely with structs and stuff */
@@ -554,10 +574,11 @@ static GtkWidget
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1,
widget_offset+i, widget_offset+i+1);
if(fields[i].label_data!=NULL) {
- gtk_object_set_data(GTK_OBJECT(vbox), fields[i].label_data, label);
+ g_object_set_data(G_OBJECT(vbox), fields[i].label_data, label);
}
- entry = gtk_entry_new_with_max_length(128);
- gtk_object_set_data(GTK_OBJECT(vbox), fields[i].obj_data, entry);
+ entry = gtk_entry_new();
+ gtk_entry_set_max_length(GTK_ENTRY(entry), 128);
+ g_object_set_data(G_OBJECT(vbox), fields[i].obj_data, entry);
gtk_table_attach(GTK_TABLE(table), entry, 1, 2,
widget_offset+i, widget_offset+i+1, 0,0,0,0);
g_signal_connect(GTK_OBJECT(entry), "insert_text",
@@ -577,11 +598,11 @@ setOptionsCfg(GtkWidget *pilotcfg, ConduitCfg *state)
int i;
- DateFormat = gtk_object_get_data(GTK_OBJECT(pilotcfg), "DateFormat");
- OutputFormat = gtk_object_get_data(GTK_OBJECT(pilotcfg), "OutputFormat");
- ExpenseDir = gtk_object_get_data(GTK_OBJECT(pilotcfg), "ExpenseDir");
- DirMode = gtk_object_get_data(GTK_OBJECT(pilotcfg), "DirMode");
- FileMode = gtk_object_get_data(GTK_OBJECT(pilotcfg), "FileMode");
+ DateFormat = g_object_get_data(G_OBJECT(pilotcfg), "DateFormat");
+ OutputFormat = g_object_get_data(G_OBJECT(pilotcfg), "OutputFormat");
+ ExpenseDir = g_object_get_data(G_OBJECT(pilotcfg), "ExpenseDir");
+ DirMode = g_object_get_data(G_OBJECT(pilotcfg), "DirMode");
+ FileMode = g_object_get_data(G_OBJECT(pilotcfg), "FileMode");
g_assert(DateFormat != NULL);
g_assert(OutputFormat != NULL);
@@ -597,10 +618,10 @@ setOptionsCfg(GtkWidget *pilotcfg, ConduitCfg *state)
/* find the entry in the option menu. if not found, default to the last */
for(i = 0; i < DATE_OPTIONS_COUNT && g_ascii_strncasecmp(state->dateFormat, date_options[i].format, 20) != 0; i++);
- gtk_option_menu_set_history(GTK_OPTION_MENU(DateFormat), i);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(DateFormat), i);
for(i = 0; i < WRITEOUT_OPTIONS_COUNT && state->outputFormat != writeout_options[i].format; i++);
- gtk_option_menu_set_history(GTK_OPTION_MENU(OutputFormat), i);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(OutputFormat), i);
}
static void
@@ -609,23 +630,21 @@ readOptionsCfg(GtkWidget *pilotcfg, ConduitCfg *state)
GtkWidget *ExpenseDir, *DirMode, *FileMode;
GtkWidget *option_menu, *menu, *menu_item;
- ExpenseDir = gtk_object_get_data(GTK_OBJECT(pilotcfg), "ExpenseDir");
- DirMode = gtk_object_get_data(GTK_OBJECT(pilotcfg), "DirMode");
- FileMode = gtk_object_get_data(GTK_OBJECT(pilotcfg), "FileMode");
+ ExpenseDir = g_object_get_data(G_OBJECT(pilotcfg), "ExpenseDir");
+ DirMode = g_object_get_data(G_OBJECT(pilotcfg), "DirMode");
+ FileMode = g_object_get_data(G_OBJECT(pilotcfg), "FileMode");
state->dir = g_strdup(gtk_entry_get_text(GTK_ENTRY(ExpenseDir)));
state->dirMode = strtol(gtk_entry_get_text(GTK_ENTRY(DirMode)), NULL, 0);
state->fileMode = strtol(gtk_entry_get_text(GTK_ENTRY(FileMode)), NULL, 0);
- option_menu = gtk_object_get_data(GTK_OBJECT(pilotcfg), "DateFormat");
- menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(option_menu));
- menu_item = gtk_menu_get_active (GTK_MENU (menu));
- state->dateFormat = g_strdup((gchar*)gtk_object_get_data(GTK_OBJECT(menu_item),"format"));
+ option_menu = g_object_get_data(G_OBJECT(pilotcfg), "DateFormat");
+ state->dateFormat = g_strdup(date_options[
+ gtk_combo_box_get_active(GTK_COMBO_BOX(option_menu))].format);
- option_menu = gtk_object_get_data(GTK_OBJECT(pilotcfg), "OutputFormat");
- menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(option_menu));
- menu_item = gtk_menu_get_active (GTK_MENU (menu));
- state->outputFormat = *(enum ExpenseOutputFormat*)gtk_object_get_data(GTK_OBJECT(menu_item),"format");
+ option_menu = g_object_get_data(G_OBJECT(pilotcfg), "OutputFormat");
+ state->outputFormat = writeout_options[
+ gtk_combo_box_get_active(GTK_COMBO_BOX(option_menu))].format;
}
@@ -638,7 +657,7 @@ create_settings_window (GnomePilotConduit *conduit, GtkWidget *parent, gpointer
gtk_container_add(GTK_CONTAINER(parent),cfgWindow);
gtk_widget_show_all(cfgWindow);
- gtk_object_set_data(GTK_OBJECT(conduit),OBJ_DATA_CONFIG_WINDOW,cfgWindow);
+ g_object_set_data(G_OBJECT(conduit),OBJ_DATA_CONFIG_WINDOW,cfgWindow);
setOptionsCfg(GET_CONDUIT_WINDOW(conduit),GET_CONDUIT_CFG(conduit));
return 0;
@@ -692,9 +711,9 @@ GnomePilotConduit *conduit_get_gpilot_conduit( guint32 pilotId )
load_configuration(&cfg,pilotId);
cfg2 = dupe_configuration(cfg);
- gtk_object_set_data(GTK_OBJECT(retval),OBJ_DATA_CONFIG,cfg);
- gtk_object_set_data(GTK_OBJECT(retval),OBJ_DATA_OLDCONFIG,cfg2);
- gtk_object_set_data(retval,OBJ_DATA_CONDUIT,(gpointer)cd);
+ g_object_set_data(G_OBJECT(retval),OBJ_DATA_CONFIG,cfg);
+ g_object_set_data(G_OBJECT(retval),OBJ_DATA_OLDCONFIG,cfg2);
+ g_object_set_data(G_OBJECT(retval),OBJ_DATA_CONDUIT,(gpointer)cd);
return GNOME_PILOT_CONDUIT(retval);
}
@@ -711,3 +730,116 @@ void conduit_destroy_gpilot_conduit( GnomePilotConduit *c )
gtk_object_destroy(GTK_OBJECT(c));
}
+#define OLD_PREFIX ".gnome2/gnome-pilot.d"
+#define NEW_PREFIX ".gnome-pilot"
+
+#define IS_STR_SET(x) (x != NULL && x[0] != '\0')
+
+static void
+migrate_conf (const gchar *old, const gchar *new)
+{
+ gchar *basename = g_path_get_dirname (new);
+
+ if (!g_file_test (basename, G_FILE_TEST_EXISTS)) {
+ g_mkdir_with_parents (basename, S_IRUSR | S_IWUSR | S_IXUSR);
+ } else {
+ if (!g_file_test (basename, G_FILE_TEST_IS_DIR)) {
+ gchar *tmp = g_strdup_printf ("%s.old", basename);
+ rename (basename, tmp);
+ g_free (tmp);
+ g_mkdir_with_parents (basename, S_IRUSR | S_IWUSR | S_IXUSR);
+ }
+ }
+ g_free (basename);
+
+ if (g_file_test (new, G_FILE_TEST_IS_REGULAR)) {
+ return;
+ } else if (g_file_test (old, G_FILE_TEST_IS_REGULAR)) {
+ rename (old, new);
+ } else {
+ creat (new, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ }
+}
+
+static GKeyFile*
+get_kfile (const gchar *conf)
+{
+ GKeyFile *kfile = g_key_file_new ();
+ const char *homedir = g_getenv ("HOME");
+ char *old = NULL;
+ char *new = NULL;
+
+ if (!homedir)
+ homedir = g_get_home_dir ();
+
+ old = g_build_filename (homedir, OLD_PREFIX, conf, NULL);
+ new = g_build_filename (homedir, NEW_PREFIX, conf, NULL);
+
+ migrate_conf (old, new);
+
+ g_key_file_load_from_file (kfile, new, G_KEY_FILE_NONE, NULL);
+ g_key_file_set_list_separator (kfile, ' ');
+
+ g_free (new);
+ g_free (old);
+ return kfile;
+}
+
+static gboolean
+save_config (GKeyFile *kfile,
+ const gchar *conf)
+{
+ const char *homedir = g_getenv ("HOME");
+ GError *error = NULL;
+ gchar *data = NULL;
+ gsize size;
+ gchar *filename = NULL;
+
+ g_return_val_if_fail (kfile, FALSE);
+ g_return_val_if_fail (IS_STR_SET (conf), FALSE);
+
+ if (!homedir)
+ homedir = g_get_home_dir ();
+
+ filename = g_build_filename (homedir, NEW_PREFIX, conf, NULL);
+
+ if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
+ g_free (filename);
+ g_warning ("File %s does not exsit", filename);
+ return FALSE;
+ }
+
+ g_message ("Saving config to disk...");
+
+ g_key_file_set_list_separator (kfile, ' ');
+ data = g_key_file_to_data (kfile, &size, &error);
+ if (error) {
+ g_warning ("Could not get config data to write to file, %s",
+ error->message);
+ g_error_free (error);
+
+ return FALSE;
+ }
+
+ g_file_set_contents (filename, data, size, &error);
+ g_free (data);
+
+ if (error) {
+ g_warning ("Could not write %" G_GSIZE_FORMAT " bytes to file '%s', %s",
+ size,
+ filename,
+ error->message);
+ g_free (filename);
+ g_error_free (error);
+
+ return FALSE;
+ }
+
+ g_message ("Wrote config to '%s' (%" G_GSIZE_FORMAT " bytes)",
+ filename,
+ size);
+
+ g_free (filename);
+
+ return TRUE;
+}
diff --git a/expense/expense_conduit.h b/expense/expense_conduit.h
index a0520bf..838b2cd 100644
--- a/expense/expense_conduit.h
+++ b/expense/expense_conduit.h
@@ -8,7 +8,6 @@
#define OBJ_DATA_CONFIG "conduit_config"
#define OBJ_DATA_OLDCONFIG "conduit_oldconfig"
#define OBJ_DATA_CONFIG_WINDOW "config_window"
-#define CONFIG_PREFIX "/gnome-pilot.d/expense-conduit/Pilot_%u/"
enum ExpenseOutputFormat {
eSimpleFormat, eComplexFormat
@@ -31,9 +30,9 @@ typedef struct ConduitData {
GnomePilotDBInfo *dbi;
} ConduitData;
-#define GET_CONDUIT_CFG(s) ((ConduitCfg*)gtk_object_get_data(GTK_OBJECT(s),OBJ_DATA_CONFIG))
-#define GET_CONDUIT_OLDCFG(s) ((ConduitCfg*)gtk_object_get_data(GTK_OBJECT(s),OBJ_DATA_OLDCONFIG))
-#define GET_CONDUIT_DATA(s) ((ConduitData*)gtk_object_get_data(GTK_OBJECT(s),OBJ_DATA_CONDUIT))
-#define GET_CONDUIT_WINDOW(s) ((GtkWidget*)gtk_object_get_data(GTK_OBJECT(s),OBJ_DATA_CONFIG_WINDOW))
+#define GET_CONDUIT_CFG(s) ((ConduitCfg*)g_object_get_data(G_OBJECT(s),OBJ_DATA_CONFIG))
+#define GET_CONDUIT_OLDCFG(s) ((ConduitCfg*)g_object_get_data(G_OBJECT(s),OBJ_DATA_OLDCONFIG))
+#define GET_CONDUIT_DATA(s) ((ConduitData*)g_object_get_data(G_OBJECT(s),OBJ_DATA_CONDUIT))
+#define GET_CONDUIT_WINDOW(s) ((GtkWidget*)g_object_get_data(G_OBJECT(s),OBJ_DATA_CONFIG_WINDOW))
#endif /* __EXPENSE_CONDUIT_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]