[gnome-pilot] Use GKeyFile rather than gnome-config APIs. Part of bug #590215.
- From: Halton Huo <haltonhuo src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-pilot] Use GKeyFile rather than gnome-config APIs. Part of bug #590215.
- Date: Fri, 28 Aug 2009 06:16:10 +0000 (UTC)
commit 4fd7341fcc3a2ecf0876cf000068b01ad74aace4
Author: Halton Huo <halton huo sun com>
Date: Fri Aug 28 14:12:33 2009 +0800
Use GKeyFile rather than gnome-config APIs. Part of bug #590215.
It will automatically migatrate data from ~/.gnome2/gnome-pilot.d/ to ~/.gnome-pilot/
# Changes to be committed:
.gitignore | 1 +
capplet/Makefile.am | 1 +
capplet/pilot.c | 238 +++++++++++++++++++------------
conduits/backup/backup_conduit.c | 79 ++++++----
conduits/backup/backup_conduit.h | 1 -
gpilotd/Makefile.am | 3 +-
gpilotd/gnome-pilot-conduit-config.gob | 192 +++++++++++--------------
gpilotd/gnome-pilot-config.c | 234 ++++++++++++++++++++++++++++++
gpilotd/gnome-pilot-config.h | 41 ++++++
gpilotd/gnome-pilot-structures.c | 148 +++++++++++---------
gpilotd/gpilot-gui.h | 1 -
gpilotd/gpilotd.c | 21 ++-
gpilotd/manager.c | 37 +++---
gpilotd/orbit_daemon_glue.c | 18 ++--
gpilotd/queue_io.c | 248 +++++++++++++++++---------------
15 files changed, 815 insertions(+), 448 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index e27f6ce..e7101d7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -93,3 +93,4 @@ utils/gnome-pilot-make-password
utils/gpilotd-client
utils/gpilotdcm-client
po/*.gmo
+cscope*
diff --git a/capplet/Makefile.am b/capplet/Makefile.am
index 4400293..18d3576 100644
--- a/capplet/Makefile.am
+++ b/capplet/Makefile.am
@@ -7,6 +7,7 @@ INCLUDES = \
-I$(top_srcdir)/gpilotd \
$(GNOME_PILOT_CFLAGS) \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
+ -DGNOMEPIXMAPSDIR=\""$(datadir)/pixmaps"\" \
-DGLADEDATADIR=\""$(gladedir)"\" \
$(NULL)
diff --git a/capplet/pilot.c b/capplet/pilot.c
index 1e297ca..fe2d304 100644
--- a/capplet/pilot.c
+++ b/capplet/pilot.c
@@ -25,10 +25,10 @@
/* handles pilot issues */
#include <config.h>
-#include <libgnome/gnome-config.h>
-#include <libgnome/gnome-util.h>
+#include <glib.h>
#include <pi-util.h>
+#include <gpilotd/gnome-pilot-config.h>
#include "pilot.h"
#include "util.h"
@@ -101,46 +101,74 @@ freePilotState (PilotState *state)
static gint
loadHostID (PilotState *p)
{
- guint32 id;
- gboolean notfound;
+ guint id;
+ gboolean ret;
+ GError *error = NULL;
+ GKeyFile *kfile = NULL;
+
+ kfile = get_gpilotd_kfile ();
+ if (kfile == NULL) {
+ p->syncPCid = random ();
+ return -1;
+ }
- gnome_config_push_prefix ("/gnome-pilot.d/gpilotd/General/");
- id = gnome_config_get_int_with_default ("sync_PC_Id=0", ¬found);
- p->progress_stepping = gnome_config_get_int_with_default ("progress_stepping=5", NULL);
- gnome_config_pop_prefix ();
-
- if (notfound) {
- p->syncPCid = random ();
- return -1;
+ ret = 0;
+ id = g_key_file_get_integer (kfile, "General", "sync_PC_Id", &error);
+ if (error) {
+ g_warning (_("Unable load key gpilotd/General/sync_PC_Id: %s"), error->message);
+ g_error_free (error);
+ error = NULL;
+ ret = -1;
+ p->syncPCid = random ();
} else {
- p->syncPCid = id;
- return 0;
+ if (id ==0)
+ p->syncPCid = random ();
+ else
+ p->syncPCid = id;
}
-}
+
+ p->progress_stepping = g_key_file_get_integer (kfile, "General", "progress_stepping", &error);
+ if (error) {
+ g_warning (_("Unable load key gpilotd/General/progress_stepping: %s"), error->message);
+ g_error_free (error);
+ error = NULL;
+ p->progress_stepping = 5;
+ }
+
+ g_key_file_free (kfile);
+ return ret;
+}
static gint
loadDeviceCfg (PilotState *p)
{
GPilotDevice *device;
- gchar *prefix;
- gchar buf[25];
+ gchar *iDevice;
+ GKeyFile *kfile = NULL;
+ GError *error = NULL;
int i, num;
- gnome_config_push_prefix ("/gnome-pilot.d/gpilotd/General/");
- num = gnome_config_get_int ("num_devices=0");
- gnome_config_pop_prefix ();
+ kfile = get_gpilotd_kfile ();
+ num = g_key_file_get_integer (kfile, "General", "num_devices", NULL);
if (num == 0) {
- g_message ("No pilot cradle information located");
- p->devices = NULL;
- return -1;
+ g_message ("No pilot cradle information located");
+ p->devices = NULL;
+ g_key_file_free (kfile);
+ return -1;
} else {
for (i=0;i<num;i++){
device = g_new0(GPilotDevice, 1);
- prefix = g_strdup_printf ("/gnome-pilot.d/gpilotd/Device%d/", i);
+ iDevice = g_strdup_printf ("Device%d", i);
- gnome_config_push_prefix (prefix);
- device->type = gnome_config_get_int ("type=0");
+ device->type = g_key_file_get_integer (kfile, iDevice, "type", &error);
+ if (error) {
+ g_warning (_("Unable load key gpilotd/%s/type: %s"), iDevice, error->message);
+ g_error_free (error);
+ error = NULL;
+ device->type = 0;
+ };
+
if (device->type == PILOT_DEVICE_SERIAL) {
g_message ("Cradle Type -> Serial");
} else if (device->type == PILOT_DEVICE_USB_VISOR) {
@@ -152,31 +180,50 @@ loadDeviceCfg (PilotState *p)
} else if (device->type == PILOT_DEVICE_BLUETOOTH) {
g_message ("Cradle Type -> Bluetooth");
} else {
- g_warning ("Unknown Cradle Type");
+ g_warning ("Unknown Cradle Type");
}
- sprintf (buf,"name=Cradle%d", i);
- device->name = gnome_config_get_string (buf);
+ device->name = g_key_file_get_string (kfile, iDevice, "name", &error);
+ if (error) {
+ g_warning (_("Unable load key gpilotd/%s/name: iDevice, %s"), iDevice, error->message);
+ g_error_free (error);
+ error = NULL;
+ g_free (device->name);
+ device->name = g_strdup_printf ("Cradle%d", i);
+ };
g_message ("cradle device name -> %s", device->name);
if (device->type == PILOT_DEVICE_NETWORK) {
- device->ip = gnome_config_get_string ("ip");
+ device->ip = g_key_file_get_string (kfile, iDevice, "ip", NULL);
g_message ("cradle network ip -> %s", device->ip);
} else if (device->type == PILOT_DEVICE_BLUETOOTH) {
/* no more parameters */
} else {
- device->port = gnome_config_get_string ("device");
+ device->port = g_key_file_get_string (kfile, iDevice, "device", NULL);
g_message ("cradle device name -> %s", device->port);
- device->speed = gnome_config_get_int ("speed=9600");
+ device->speed = g_key_file_get_integer (kfile, iDevice, "speed", &error);
+ if (error) {
+ g_warning (_("Unable load key gpilotd/%s/speed: %s"), iDevice, error->message);
+ g_error_free (error);
+ error = NULL;
+ device->speed = 9600;
+ };
g_message ("Pilot Speed -> %d", device->speed);
}
- device->timeout = gnome_config_get_int ("timeout=2");
+ device->timeout = g_key_file_get_integer (kfile, iDevice, "timeout", &error);
+ if (error) {
+ g_warning (_("Unable load key gpilotd/%s/timeout: %s"), iDevice, error->message);
+ g_error_free (error);
+ error = NULL;
+ device->timeout = 2;
+ };
g_message ("Timeout -> %d", device->timeout);
- gnome_config_pop_prefix ();
- g_free (prefix);
+ g_free (iDevice);
p->devices = g_list_append (p->devices, device);
}
}
+
+ g_key_file_free (kfile);
return 0;
}
@@ -185,31 +232,45 @@ static gint
loadPilotPilot (PilotState *p)
{
GPilotPilot *pilot;
- gboolean notfound;
- gchar *prefix;
+ gchar *iPilot;
char *local_name;
int i, num;
+ GKeyFile *kfile;
+ GError *error = NULL;
- gnome_config_push_prefix ("/gnome-pilot.d/gpilotd/General/");
- num = gnome_config_get_int ("num_pilots=0");
- gnome_config_pop_prefix ();
+ kfile = get_gpilotd_kfile ();
+
+ num = g_key_file_get_integer (kfile, "General", "num_pilots", NULL);
if (num == 0) {
g_message ("No pilot userid/username information located");
p->pilots = NULL;
+ g_key_file_free (kfile);
return -1;
} else {
for (i=0;i<num;i++){
pilot = g_new0(GPilotPilot, 1);
- prefix = g_strdup_printf ("/gnome-pilot.d/gpilotd/Pilot%d/", i);
- gnome_config_push_prefix (prefix);
- pilot->name = gnome_config_get_string ("name=MyPilot");
+ iPilot = g_strdup_printf ("Pilot%d", i);
+
+ pilot->name = g_key_file_get_string (kfile, iPilot, "name", &error);
+ if (error) {
+ g_warning (_("Unable load key gpilotd/%s/name: %s"), iPilot, error->message);
+ g_error_free (error);
+ error = NULL;
+ g_free (pilot->name);
+ pilot->name = g_strdup ("MyPilot");
+ };
g_message ("Pilot name -> %s", pilot->name);
- pilot->pilot_id = gnome_config_get_int_with_default ("pilotid",¬found);
- if (notfound)
+
+ pilot->pilot_id = g_key_file_get_integer (kfile, iPilot, "pilotid", &error);
+ if (error) {
+ g_warning (_("Unable load key gpilotd/%s/pilotid: %s"), iPilot, error->message);
+ g_error_free (error);
+ error = NULL;
pilot->pilot_id = getuid ();
+ }
g_message ("Pilot id -> %d", pilot->pilot_id);
- local_name = gnome_config_get_string ("pilotusername");
+ local_name = g_key_file_get_string (kfile, iPilot, "pilotusername", NULL);
#ifdef PILOT_LINK_0_12
if (!local_name || (convert_FromPilotChar_WithCharset ("UTF-8", local_name, strlen(local_name), &pilot->pilot_username, NULL) == -1)) {
#else
@@ -220,18 +281,18 @@ loadPilotPilot (PilotState *p)
g_free (local_name);
g_message ("Pilot username -> %s", pilot->pilot_username);
- pilot->creation = gnome_config_get_int ("creation");
- pilot->romversion = gnome_config_get_int ("romversion");
+ pilot->creation = g_key_file_get_integer (kfile, iPilot, "creation", NULL);
+ pilot->romversion = g_key_file_get_integer (kfile, iPilot, "romversion", NULL);
g_message ("Pilot creation/rom = %lu/%lu", pilot->creation, pilot->romversion);
- pilot->sync_options.basedir = gnome_config_get_string ("basedir");
+ pilot->sync_options.basedir = g_key_file_get_string (kfile, iPilot, "basedir", NULL);
if (pilot->sync_options.basedir==NULL) {
pilot->sync_options.basedir = g_strdup_printf ("%s/%s", g_get_home_dir (), pilot->name);
}
#ifdef PILOT_LINK_0_12
- pilot->pilot_charset = gnome_config_get_string ("charset");
+ pilot->pilot_charset = g_key_file_get_string (kfile, iPilot, "charset", NULL);
if (pilot->pilot_charset == NULL)
pilot->pilot_charset =
g_strdup(get_default_pilot_charset());
@@ -241,12 +302,13 @@ loadPilotPilot (PilotState *p)
pilot->number = i;
- g_free (prefix);
- gnome_config_pop_prefix ();
+ g_free (iPilot);
p->pilots = g_list_append (p->pilots, pilot);
}
}
+
+ g_key_file_free (kfile);
return 0;
}
@@ -281,43 +343,43 @@ savePilotState (PilotState *state)
{
int i;
GList *tmp;
- gchar *prefix;
+ gchar *iDevice;
+ gchar *iPilot;
char *local_name;
+ GKeyFile *kfile;
+
+ kfile = get_gpilotd_kfile ();
- gnome_config_clean_section ("/gnome-pilot.d/gpilotd/General/");
+ g_key_file_remove_group (kfile, "General", NULL);
- gnome_config_set_int ("/gnome-pilot.d/gpilotd/General/sync_PC_Id", state->syncPCid);
- gnome_config_set_int ("/gnome-pilot.d/gpilotd/General/progress_stepping", state->progress_stepping);
+ g_key_file_set_integer (kfile, "General", "sync_PC_Id", state->syncPCid);
+ g_key_file_set_integer (kfile, "General", "progress_stepping", state->progress_stepping);
tmp = state->devices;
i=0;
while (tmp!=NULL)
{
GPilotDevice *device=(GPilotDevice*)tmp->data;
- prefix = g_strdup_printf ("/gnome-pilot.d/gpilotd/Device%d/", i);
+ iDevice = g_strdup_printf ("Device%d", i);
- gnome_config_clean_section (prefix);
- gnome_config_push_prefix (prefix);
- gnome_config_set_int ("type", device->type);
- gnome_config_set_string ("name", device->name);
+ g_key_file_remove_group (kfile, iDevice, NULL);
+ g_key_file_set_integer (kfile, iDevice, "type", device->type);
+ g_key_file_set_string (kfile, iDevice, "name", device->name);
if (device->type == PILOT_DEVICE_NETWORK) {
- gnome_config_set_string ("ip", device->ip);
+ g_key_file_set_string (kfile, iDevice, "ip", device->ip);
} else if (device->type == PILOT_DEVICE_BLUETOOTH) {
/* no further info stored */
} else {
- gnome_config_set_string ("device", device->port);
- gnome_config_set_int ("speed", device->speed);
+ g_key_file_set_string (kfile, iDevice, "device", device->port);
+ g_key_file_set_integer (kfile, iDevice, "speed", device->speed);
}
- gnome_config_set_int ("timeout", device->timeout);
- gnome_config_pop_prefix ();
- g_free (prefix);
+ g_key_file_set_integer (kfile, iDevice, "timeout", device->timeout);
+ g_free (iDevice);
tmp = tmp->next;
i++;
}
if (i>0) {
- gnome_config_push_prefix ("/gnome-pilot.d/gpilotd/General/");
- gnome_config_set_int ("num_devices", i);
- gnome_config_pop_prefix ();
+ g_key_file_set_integer (kfile, "General", "num_devices", i);
}
tmp = state->pilots;
@@ -325,14 +387,13 @@ savePilotState (PilotState *state)
while (tmp!=NULL)
{
GPilotPilot *pilot=(GPilotPilot*)tmp->data;
- prefix = g_strdup_printf ("/gnome-pilot.d/gpilotd/Pilot%d/", i);
- gnome_config_clean_section (prefix);
-
- gnome_config_push_prefix (prefix);
- gnome_config_set_string ("name", pilot->name);
- gnome_config_set_int ("pilotid", pilot->pilot_id);
- gnome_config_set_int ("creation", pilot->creation);
- gnome_config_set_int ("romversion", pilot->romversion);
+ iPilot = g_strdup_printf ("Pilot%d", i);
+
+ g_key_file_remove_group (kfile, iPilot, NULL);
+ g_key_file_set_string (kfile, iPilot, "name", pilot->name);
+ g_key_file_set_integer (kfile, iPilot, "pilotid", pilot->pilot_id);
+ g_key_file_set_integer (kfile, iPilot, "creation", pilot->creation);
+ g_key_file_set_integer (kfile, iPilot, "romversion", pilot->romversion);
#ifdef PILOT_LINK_0_12
if (!pilot->pilot_username|| (convert_ToPilotChar_WithCharset ("UTF-8", pilot->pilot_username, strlen (pilot->pilot_username), &local_name, NULL) == -1)) {
#else
@@ -340,24 +401,23 @@ savePilotState (PilotState *state)
#endif
local_name = g_strdup (pilot->pilot_username);
}
- gnome_config_set_string ("pilotusername", local_name);
+ g_key_file_set_string (kfile, iPilot, "pilotusername", local_name);
g_free (local_name);
- gnome_config_set_string ("basedir", pilot->sync_options.basedir);
+ g_key_file_set_string (kfile, iPilot, "basedir", pilot->sync_options.basedir);
#ifdef PILOT_LINK_0_12
- gnome_config_set_string ("charset", pilot->pilot_charset);
+ g_key_file_set_string (kfile, iPilot, "charset", pilot->pilot_charset);
#endif
- gnome_config_pop_prefix ();
- g_free (prefix);
+ g_free (iPilot);
tmp = tmp->next;
i++;
}
if (i>0) {
- gnome_config_push_prefix ("/gnome-pilot.d/gpilotd/General/");
- gnome_config_set_int ("num_pilots", i);
- gnome_config_pop_prefix ();
+ g_key_file_set_integer (kfile, "General", "num_pilots", i);
}
- gnome_config_sync ();
+ save_gpilotd_kfile (kfile);
+ g_key_file_free (kfile);
+
return 0;
}
@@ -367,7 +427,7 @@ load_conduit_list (GPilotPilot *pilot)
{
GList *conduits = NULL, *conduit_states = NULL;
gchar *buf;
-
+
gnome_pilot_conduit_management_get_conduits (&conduits, GNOME_PILOT_CONDUIT_MGMT_NAME);
conduits = g_list_sort (conduits, (GCompareFunc) strcmp);
while (conduits != NULL) {
@@ -382,7 +442,7 @@ load_conduit_list (GPilotPilot *pilot)
conduit_state->description = g_strdup ((gchar*) gnome_pilot_conduit_management_get_attribute (conduit_state->management, "description", NULL));
conduit_state->icon = g_strdup ((gchar*)gnome_pilot_conduit_management_get_attribute (conduit_state->management, "icon", NULL));
if (conduit_state->icon == NULL || g_file_test (conduit_state->icon, G_FILE_TEST_IS_REGULAR)==FALSE) {
- conduit_state->icon = gnome_unconditional_pixmap_file ("gnome-palm-conduit.png");
+ conduit_state->icon = g_strdup_printf ("%s/%s", GNOMEPIXMAPSDIR, "gnome-palm-conduit.png");
}
buf = (gchar*) gnome_pilot_conduit_management_get_attribute (conduit_state->management, "settings", NULL);
diff --git a/conduits/backup/backup_conduit.c b/conduits/backup/backup_conduit.c
index b69a796..2a4a892 100644
--- a/conduits/backup/backup_conduit.c
+++ b/conduits/backup/backup_conduit.c
@@ -27,10 +27,9 @@
#include <config.h>
#endif
+#include <stdio.h>
#include <glib.h>
#include <glib/gi18n.h>
-#include <libgnome/gnome-config.h>
-#include <libgnomeui/gnome-uidefs.h>
#include <pi-source.h>
#include <pi-socket.h>
@@ -51,6 +50,7 @@
#include <dirent.h>
#include <gpilotd/gnome-pilot-conduit-backup.h>
+#include <gpilotd/gnome-pilot-config.h>
#include "backup_conduit.h"
#define DEBUG 1
@@ -90,37 +90,51 @@ load_configuration(GnomePilotConduit *conduit,
GPilotPilot *pilot)
{
gchar *temp_name;
- gchar *prefix;
+ gchar *iPilot;
gchar **exclude_files;
- gint num_of_exclude_files = 0;
+ gsize num_of_exclude_files = 0;
guint i;
DIR *dir;
struct dirent *entry;
+ GKeyFile *kfile;
+ GError *error = NULL;
(*c) = g_new0(ConduitCfg,1);
(*c)->child = -1;
- prefix = g_strdup_printf(CONFIG_PREFIX, pilot->pilot_id);
-
- gnome_config_push_prefix(prefix);
- (*c)->backup_dir = gnome_config_get_string("backup_dir");
- (*c)->updated_only = gnome_config_get_bool("updated_only=TRUE");
- (*c)->remove_deleted = gnome_config_get_bool("remove_deleted=FALSE");
- (*c)->no_of_backups = gnome_config_get_int("no_of_backups=0");
+ kfile = get_backup_kfile ();
+ iPilot = g_strdup_printf ("Pilot_%u", pilot->pilot_id);
+ (*c)->backup_dir = g_key_file_get_string (kfile, iPilot, "backup_dir", NULL);
+
+ (*c)->updated_only = g_key_file_get_boolean (kfile, iPilot, "updated_only", &error);
+ if (error) {
+ g_warning (_("Unable load key backup-conduit/%s/updated_only: %s"), iPilot, error->message);
+ g_error_free (error);
+ error = NULL;
+ (*c)->updated_only = TRUE;
+ }
+
+ (*c)->remove_deleted = g_key_file_get_boolean (kfile, iPilot, "remove_deleted", NULL);
+ if (error) {
+ g_warning (_("Unable load key backup-conduit/%s/remove_deleted: %s"), iPilot, error->message);
+ g_error_free (error);
+ error = NULL;
+ (*c)->remove_deleted = FALSE;
+ }
+
+ (*c)->no_of_backups = g_key_file_get_integer (kfile, iPilot, "no_of_backups", NULL);
(*c)->exclude_files = NULL;
- gnome_config_get_vector("exclude_files",
- &num_of_exclude_files,
- &exclude_files);
+ exclude_files = g_key_file_get_string_list (kfile, iPilot, "exclude_files",
+ &num_of_exclude_files, NULL);
if(num_of_exclude_files) {
for( i = 0; i < num_of_exclude_files ; i++ ) {
(*c)->exclude_files = g_list_append( (*c)->exclude_files ,
g_strdup(exclude_files[i]));
g_free(exclude_files[i]);
}
- g_free(exclude_files);
+ g_strfreev(exclude_files);
}
- gnome_config_pop_prefix();
if ((*c)->backup_dir == NULL) {
if (conduit != NULL && GNOME_IS_PILOT_CONDUIT (conduit)) {
@@ -169,20 +183,23 @@ load_configuration(GnomePilotConduit *conduit,
(*c)->pilotId = pilot->pilot_id;
- g_free(prefix);
+ g_free (iPilot);
+ g_key_file_free (kfile);
}
static void
save_configuration(ConduitCfg *c)
{
- gchar *prefix;
+ gchar *iPilot;
const gchar **exclude = NULL;
GList *iterator;
guint i = 0;
+ GKeyFile *kfile;
g_return_if_fail(c!=NULL);
- prefix= g_strdup_printf("/gnome-pilot.d/backup-conduit/Pilot_%u/",c->pilotId);
+ kfile = get_backup_kfile ();
+ iPilot = g_strdup_printf("Pilot_%u",c->pilotId);
if( c->exclude_files != NULL ) {
iterator = c->exclude_files;
@@ -192,17 +209,17 @@ save_configuration(ConduitCfg *c)
}
exclude[i] = NULL;
}
- gnome_config_push_prefix(prefix);
- gnome_config_set_string("backup_dir",c->backup_dir);
- gnome_config_set_bool("updated_only",c->updated_only);
- gnome_config_set_bool("remove_deleted",c->remove_deleted);
- gnome_config_set_int("no_of_backups",c->no_of_backups);
- gnome_config_set_vector("exclude_files", i, exclude);
- gnome_config_pop_prefix();
- gnome_config_sync();
- gnome_config_drop_all();
- g_free(prefix);
+ g_key_file_set_string (kfile, iPilot, "backup_dir",c->backup_dir);
+ g_key_file_set_boolean (kfile, iPilot, "updated_only",c->updated_only);
+ g_key_file_set_boolean (kfile, iPilot, "remove_deleted",c->remove_deleted);
+ g_key_file_set_integer (kfile, iPilot, "no_of_backups",c->no_of_backups);
+ g_key_file_set_string_list (kfile, iPilot, "exclude_files", exclude, i);
+
+ g_free(iPilot);
g_free(exclude);
+
+ save_backup_kfile (kfile);
+ g_key_file_free (kfile);
}
static void
@@ -857,12 +874,12 @@ static GtkWidget
GtkObject *adjustment;
AtkObject *atk_widget;
- vbox = gtk_vbox_new(FALSE, GNOME_PAD);
+ vbox = gtk_vbox_new (FALSE, 8);
table = gtk_table_new(2, 4, 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, 8);
label = gtk_label_new_with_mnemonic(_("_Backup directory:"));
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
diff --git a/conduits/backup/backup_conduit.h b/conduits/backup/backup_conduit.h
index b424ab5..eb67073 100644
--- a/conduits/backup/backup_conduit.h
+++ b/conduits/backup/backup_conduit.h
@@ -34,7 +34,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/backup-conduit/Pilot_%u/"
typedef struct ConduitCfg {
gchar *backup_dir;
diff --git a/gpilotd/Makefile.am b/gpilotd/Makefile.am
index ed8f037..7eedb4c 100644
--- a/gpilotd/Makefile.am
+++ b/gpilotd/Makefile.am
@@ -52,6 +52,8 @@ GOB_LIBGPILOTD_BUILT_SRCS = \
gnome-pilot-client.c \
gnome-pilot-client-private.h \
gnome-pilot-client.h \
+ gnome-pilot-config.c \
+ gnome-pilot-config.h \
$(NULL)
GOB_GPILOTD_CONDUIT_SRCS= \
@@ -206,7 +208,6 @@ gpilotinclude_HEADERS = \
$(NULL)
gpilotd_SOURCES = \
- gpilotd-conduit-mgmt.h \
gpilotd.c \
manager.c \
manager.h \
diff --git a/gpilotd/gnome-pilot-conduit-config.gob b/gpilotd/gnome-pilot-conduit-config.gob
index f3b2d34..1639b50 100644
--- a/gpilotd/gnome-pilot-conduit-config.gob
+++ b/gpilotd/gnome-pilot-conduit-config.gob
@@ -25,8 +25,8 @@
%h{
#include <glib.h>
#include <gtk/gtkobject.h>
-#include <libgnome/gnome-config.h>
#include <gpilotd/gnome-pilot-conduit.h>
+#include <gpilotd/gnome-pilot-config.h>
#include <libgpilotdCM/gnome-pilot-conduit-management.h>
#include <gmodule.h>
%}
@@ -125,14 +125,12 @@ class Gnome:Pilot:Conduit:Config from Gtk:Object {
/* Sets the variables to reflect the stat */
public int
load_config(self) onerror 0 {
- gchar *prefix,*tmp;
+ char *tmp;
+ GKeyFile *kfile;
if(self_is_enabled(self,NULL)==TRUE) {
- prefix = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/",
- self->_priv->pilot_id,
- gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
- gnome_config_push_prefix(prefix);
- tmp = gnome_config_get_string("sync_type");
+ kfile = get_conduits_kfile (self->_priv->pilot_id);
+ tmp = g_key_file_get_string (kfile, gnome_pilot_conduit_management_get_id(self->_priv->gpcm), "sync_type", NULL);
if (tmp) {
self->sync_type = self_sync_type_str_to_int(tmp);
} else {
@@ -140,16 +138,15 @@ class Gnome:Pilot:Conduit:Config from Gtk:Object {
self->sync_type = GnomePilotConduitSyncTypeNotSet;
}
g_free(tmp);
- tmp = gnome_config_get_string("first_sync_type");
+ tmp = g_key_file_get_string (kfile, gnome_pilot_conduit_management_get_id(self->_priv->gpcm), "first_sync_type", NULL);
if (tmp) {
self->first_sync_type = self_sync_type_str_to_int(tmp);
} else {
self->first_sync_type = GnomePilotConduitSyncTypeNotSet;
}
g_free(tmp);
- self->first_slow = gnome_config_get_bool("slow_sync");
- gnome_config_pop_prefix();
- g_free(prefix);
+ self->first_slow = g_key_file_get_boolean (kfile, gnome_pilot_conduit_management_get_id(self->_priv->gpcm), "slow_sync", NULL);
+ g_key_file_free (kfile);
} else
return 0;
return 1;
@@ -157,24 +154,24 @@ class Gnome:Pilot:Conduit:Config from Gtk:Object {
public int
save_config(self) onerror 0 {
- gchar *prefix;
+ GKeyFile *kfile;
if(self_is_enabled(self,NULL)==TRUE) {
- prefix = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/",
- self->_priv->pilot_id,
- gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
- gnome_config_push_prefix(prefix);
- gnome_config_set_string("sync_type",
+ kfile = get_conduits_kfile (self->_priv->pilot_id);
+ g_key_file_set_string (kfile, gnome_pilot_conduit_management_get_id(self->_priv->gpcm),
+ "sync_type",
self_sync_type_int_to_str(self->sync_type));
- gnome_config_set_string("first_sync_type",
+ g_key_file_set_string (kfile, gnome_pilot_conduit_management_get_id(self->_priv->gpcm),
+ "first_sync_type",
self_sync_type_int_to_str(self->first_sync_type));
- if(self->first_sync_type==GnomePilotConduitSyncTypeSynchronize)
- gnome_config_set_bool("slow_sync",self->first_slow);
+ if(self->first_sync_type == GnomePilotConduitSyncTypeSynchronize)
+ g_key_file_set_boolean (kfile, gnome_pilot_conduit_management_get_id(self->_priv->gpcm),
+ "slow_sync",self->first_slow);
else
- gnome_config_clean_key("slow_sync");
- gnome_config_pop_prefix();
- gnome_config_sync();
- g_free(prefix);
+ g_key_file_remove_key (kfile, gnome_pilot_conduit_management_get_id(self->_priv->gpcm),
+ "slow_sync", NULL);
+ save_conduits_kfile (kfile, self->_priv->pilot_id);
+ g_key_file_free (kfile);
} else
return 0;
return 1;
@@ -190,21 +187,17 @@ class Gnome:Pilot:Conduit:Config from Gtk:Object {
public gboolean
is_enabled(self,
GnomePilotConduitSyncType *sync_type) {
- gchar *tmp;
- int num_conduits,cnt;
+ gsize num_conduits;
+ int cnt;
gchar **conduit_name;
gboolean retval;
+ GKeyFile *kfile;
retval = FALSE;
- tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/General/",
- self->_priv->pilot_id);
- /* g_message("prefix = %s",tmp); */
-
/* load the list */
- gnome_config_push_prefix(tmp);
- gnome_config_get_vector("conduits",&num_conduits,&conduit_name);
- gnome_config_pop_prefix();
+ kfile = get_conduits_kfile (self->_priv->pilot_id);
+ conduit_name = g_key_file_get_string_list (kfile, "General", "conduits", &num_conduits, NULL);
/* g_message("number_of_conduits = %d",num_conduits); */
@@ -216,22 +209,19 @@ class Gnome:Pilot:Conduit:Config from Gtk:Object {
if(g_str_equal(conduit_name[cnt] ,gnome_pilot_conduit_management_get_id(self->_priv->gpcm))) {
/* g_message("match on %s, it is enabled",conduit_name[cnt]); */
if(sync_type) {
- gchar *newpfx,*tmpstr;
- newpfx = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/first_sync_type",
- self->_priv->pilot_id,
- gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
- tmpstr = gnome_config_get_string(newpfx);
+ gchar *tmpstr;
+ tmpstr = g_key_file_get_string (kfile,
+ gnome_pilot_conduit_management_get_id(self->_priv->gpcm),
+ "first_sync_type",
+ NULL);
if (tmpstr == NULL) {
- g_free(newpfx);
- newpfx = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/sync_type",
- self->_priv->pilot_id,
- gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
-
- tmpstr = gnome_config_get_string(newpfx);
+ tmpstr = g_key_file_get_string (kfile,
+ gnome_pilot_conduit_management_get_id(self->_priv->gpcm),
+ "sync_type",
+ NULL);
}
/* g_message("%s says %s",newpfx,tmpstr); */
(*sync_type) = self_sync_type_str_to_int(tmpstr);
- g_free(newpfx);
g_free(tmpstr);
}
retval = TRUE;
@@ -239,7 +229,7 @@ class Gnome:Pilot:Conduit:Config from Gtk:Object {
g_free(conduit_name[cnt]);
}
g_free(conduit_name);
- g_free(tmp);
+ g_key_file_free (kfile);
return retval;
}
@@ -248,20 +238,20 @@ class Gnome:Pilot:Conduit:Config from Gtk:Object {
public void
enable(self,
GnomePilotConduitSyncType sync_type) {
- gchar *tmp;
char **conduit_name;
char **conduit_name_copy;
- int num_conduits,cnt;
+ gsize num_conduits;
+ int cnt;
+ GKeyFile *kfile;
+
+ kfile = get_conduits_kfile (self->_priv->pilot_id);
/* enable conduit, if it wasn't, otherwise, just write
the sync type in case it was changed. */
if(self_is_enabled(self,NULL)==FALSE) {
- tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/General/",self->_priv->pilot_id);
- /* g_message("prefix = %s",tmp); */
-
+
/* load the list of conduits */
- gnome_config_push_prefix(tmp);
- gnome_config_get_vector("conduits",&num_conduits,&conduit_name);
+ conduit_name = g_key_file_get_string_list (kfile, "General", "conduits", &num_conduits, NULL);
/* g_message("num_conduits = %d",num_conduits); */
/* copy the list and attach new conduit */
@@ -277,7 +267,7 @@ class Gnome:Pilot:Conduit:Config from Gtk:Object {
/* write new list */
/* g_message("writing new conduits list, size %d",num_conduits+1); */
- gnome_config_set_vector("conduits",num_conduits+1,(const char**)conduit_name_copy);
+ g_key_file_set_string_list (kfile, "General", "conduits", (const char**)conduit_name_copy, num_conduits+1);
/* free the copy */
/* g_message("freeing %d items",num_conduits+1); */
@@ -287,22 +277,15 @@ class Gnome:Pilot:Conduit:Config from Gtk:Object {
}
g_free(conduit_name_copy);
- gnome_config_pop_prefix();
-
- g_free(tmp);
}
/* make section for conduit */
- tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/",
- self->_priv->pilot_id,
- gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
- /* g_message("prefix = %s",tmp); */
- gnome_config_push_prefix(tmp);
- gnome_config_set_string("sync_type",
+ g_key_file_set_string (kfile, gnome_pilot_conduit_management_get_id(self->_priv->gpcm),
+ "sync_type",
self_sync_type_int_to_str(sync_type));
- gnome_config_pop_prefix();
- gnome_config_sync();
- g_free(tmp);
+
+ save_conduits_kfile (kfile, self->_priv->pilot_id);
+ g_key_file_free (kfile);
}
/* enable the conduit for pilot pilot_id
@@ -312,64 +295,63 @@ class Gnome:Pilot:Conduit:Config from Gtk:Object {
GnomePilotConduitSyncType sync_type,
GnomePilotConduitSyncType first_sync_type,
gboolean slow) {
- gchar *tmp;
-
+ GKeyFile *kfile;
+
self_enable(self,sync_type);
/* add the first_sync info */
- tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/",
- self->_priv->pilot_id,
- gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
- gnome_config_push_prefix(tmp);
- gnome_config_set_string("first_sync_type",
+ kfile = get_conduits_kfile (self->_priv->pilot_id);
+
+ g_key_file_set_string (kfile,
+ gnome_pilot_conduit_management_get_id (self->_priv->gpcm),
+ "first_sync_type",
self_sync_type_int_to_str(first_sync_type));
if(first_sync_type==GnomePilotConduitSyncTypeSynchronize)
- gnome_config_set_bool("slow_sync",slow);
+ g_key_file_set_boolean (kfile, gnome_pilot_conduit_management_get_id (self->_priv->gpcm),
+ "slow_sync",slow);
else
- gnome_config_clean_key("slow_sync");
- gnome_config_pop_prefix();
- gnome_config_sync();
- g_free(tmp);
+ g_key_file_remove_key (kfile, gnome_pilot_conduit_management_get_id (self->_priv->gpcm),
+ "slow_sync", NULL);
+ save_conduits_kfile (kfile, self->_priv->pilot_id);
+ g_key_file_free (kfile);
}
/* clear the first sync flag, if the conduit is not enabled, */
public void
remove_first_sync(self) {
- gchar *tmp;
+ GKeyFile *kfile;
+ kfile = get_conduits_kfile (self->_priv->pilot_id);
+
if (self_is_enabled(self,NULL)) {
/* add the first_sync info */
- tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/",
- self->_priv->pilot_id,
- gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
- if (gnome_config_has_section(tmp)) {
- gnome_config_push_prefix(tmp);
- gnome_config_clean_key("first_sync_type");
- gnome_config_clean_key("slow_sync");
- gnome_config_pop_prefix();
+ if (g_key_file_has_group (kfile, gnome_pilot_conduit_management_get_id(self->_priv->gpcm))) {
+ g_key_file_remove_key (kfile, gnome_pilot_conduit_management_get_id(self->_priv->gpcm),
+ "first_sync_type", NULL);
+ g_key_file_remove_key (kfile, gnome_pilot_conduit_management_get_id(self->_priv->gpcm),
+ "slow_sync", NULL);
}
- gnome_config_sync();
- g_free(tmp);
}
-
+ save_conduits_kfile (kfile, self->_priv->pilot_id);
+ g_key_file_free (kfile);
}
/* disable the conduit for the pilot */
public void
disable(self) {
- gchar *tmp;
gchar **conduit_name;
char **conduit_name_copy;
- int num_conduits,num_conduits_copy,cnt;
+ gsize num_conduits;
+ int num_conduits_copy,cnt;
+ GKeyFile *kfile;
+ kfile = get_conduits_kfile (self->_priv->pilot_id);
+
if(self_is_enabled(self,NULL)==FALSE) return;
- tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/General/",self->_priv->pilot_id);
-
/* load the list of conduits */
- gnome_config_push_prefix(tmp);
- gnome_config_get_vector("conduits",&num_conduits,&conduit_name);
+ conduit_name = g_key_file_get_string_list (kfile, "General", "conduits", &num_conduits, NULL);
/* copy the list, excluding the one to delete, num_conduits is > 0 since is_enables succeeded */
conduit_name_copy = g_new0(char*,num_conduits);
@@ -389,25 +371,19 @@ class Gnome:Pilot:Conduit:Config from Gtk:Object {
/* save new list */
/* g_message("num_conduits_copy = %d",num_conduits_copy); */
if ( num_conduits_copy > 0 )
- gnome_config_set_vector("conduits",num_conduits_copy,(const char**)conduit_name_copy);
+ g_key_file_set_string_list (kfile, "General", "conduits", (const char**)conduit_name_copy, num_conduits_copy);
else
- gnome_config_clean_key("conduits");
+ g_key_file_remove_key (kfile, "General", "conduits", NULL);
/* free copy */
for(cnt=0;cnt<num_conduits_copy;cnt++) g_free(conduit_name_copy[cnt]);
g_free(conduit_name_copy);
- gnome_config_pop_prefix();
-
/* nuke the conduits config section */
- g_free(tmp);
- tmp = g_strdup_printf("/gnome-pilot.d/conduits%d/%s/",
- self->_priv->pilot_id,
- gnome_pilot_conduit_management_get_id(self->_priv->gpcm));
- gnome_config_clean_section(tmp);
-
- gnome_config_sync();
- g_free(tmp);
+ g_key_file_remove_group (kfile, gnome_pilot_conduit_management_get_id(self->_priv->gpcm), NULL);
+
+ save_conduits_kfile (kfile, self->_priv->pilot_id);
+ g_key_file_free (kfile);
}
}
diff --git a/gpilotd/gnome-pilot-config.c b/gpilotd/gnome-pilot-config.c
new file mode 100644
index 0000000..e0f3e00
--- /dev/null
+++ b/gpilotd/gnome-pilot-config.c
@@ -0,0 +1,234 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- *//*
+ * gnome-pilot-config.c
+ *
+ * Copyright (C) 2009 Free Software Foundation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Halton Huo <halton huo sun com>
+ *
+ */
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include "gnome-pilot-config.h"
+
+#define OLD_PREFIX ".gnome2/gnome-pilot.d"
+#define NEW_PREFIX ".gnome-pilot"
+
+#define IS_STR_SET(x) (x != NULL && x[0] != '\0')
+
+static void
+migarate_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);
+
+ migarate_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;
+}
+
+GKeyFile*
+get_gpilotd_kfile ()
+{
+ return get_kfile ("gpilotd");
+}
+
+GKeyFile*
+get_queue_kfile ()
+{
+ return get_kfile ("queue");
+}
+
+GKeyFile*
+get_backup_kfile ()
+{
+ return get_kfile ("backup-conduit");
+}
+
+GKeyFile*
+get_conduits_kfile (gint id)
+{
+ GKeyFile *kfile = NULL;
+ char *conduit = NULL;
+
+ conduit = g_strdup_printf ("conduits%d", id);
+ kfile = get_kfile (conduit);
+
+ g_free (conduit);
+ return kfile;
+}
+
+GKeyFile*
+get_pilot_cache_kfile (gint id)
+{
+ GKeyFile *kfile = NULL;
+ char *pilot = NULL;
+
+ pilot = g_strdup_printf ("PilotCache%d", id);
+ kfile = get_kfile (pilot);
+
+ g_free (pilot);
+ 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;
+}
+
+gboolean
+save_gpilotd_kfile (GKeyFile *kfile)
+{
+ return save_config (kfile, "gpilotd");
+}
+
+gboolean
+save_queue_kfile (GKeyFile *kfile)
+{
+ return save_config (kfile, "queue");
+}
+
+gboolean
+save_backup_kfile (GKeyFile *kfile)
+{
+ return save_config (kfile, "backup-conduit");
+}
+
+gboolean
+save_conduits_kfile (GKeyFile *kfile,
+ gint id)
+{
+ gboolean ret;
+ char *conduit = NULL;
+
+ conduit = g_strdup_printf ("conduits%d", id);
+ ret = save_config (kfile, conduit);
+
+ g_free (conduit);
+ return ret;
+}
+
+gboolean
+save_pilot_cache_kfile (GKeyFile *kfile,
+ gint id)
+{
+ gboolean ret;
+ char *pilot = NULL;
+
+ pilot = g_strdup_printf ("PilotCache%d", id);
+ ret = save_config (kfile, pilot);
+
+ g_free (pilot);
+ return ret;
+}
diff --git a/gpilotd/gnome-pilot-config.h b/gpilotd/gnome-pilot-config.h
new file mode 100644
index 0000000..43ff3f8
--- /dev/null
+++ b/gpilotd/gnome-pilot-config.h
@@ -0,0 +1,41 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- *//*
+ * Copyright (C) 2009 Free Software Foundation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Halton Huo <halton huo sun com>
+ *
+ */
+
+#ifndef _GPILOT_CONFIG_H_
+#define _GPILOT_CONFIG_H_
+
+#include <glib.h>
+
+GKeyFile* get_gpilotd_kfile (void);
+GKeyFile* get_queue_kfile (void);
+GKeyFile* get_backup_kfile (void);
+GKeyFile* get_conduits_kfile (gint id);
+GKeyFile* get_pilot_cache_kfile (gint id);
+gboolean save_gpilotd_kfile (GKeyFile *kfile);
+gboolean save_queue_kfile (GKeyFile *kfile);
+gboolean save_backup_kfile (GKeyFile *kfile);
+gboolean save_conduits_kfile (GKeyFile *kfile,
+ gint id);
+gboolean save_pilot_cache_kfile (GKeyFile *kfile,
+ gint id);
+
+#endif /* _GPILOT_CONFIG_H_ */
diff --git a/gpilotd/gnome-pilot-structures.c b/gpilotd/gnome-pilot-structures.c
index a70c5b2..5e8c486 100644
--- a/gpilotd/gnome-pilot-structures.c
+++ b/gpilotd/gnome-pilot-structures.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <string.h>
#include "gnome-pilot-structures.h"
+#include <gpilotd/gnome-pilot-config.h>
#include "gpilot-gui.h"
#include <glib/gi18n.h>
#include <errno.h>
@@ -37,7 +38,6 @@
#include <string.h>
#include <fcntl.h>
#include <signal.h>
-#include <libgnome/gnome-config.h>
/* From pi-csd */
#include <sys/socket.h>
@@ -74,8 +74,8 @@ static GList *get_pilots (void);
/* context stuff first */
GPilotContext *gpilot_context_new (void)
{
- gchar *str;
- gint id;
+ GKeyFile *kfile;
+ GError *error = NULL;
GPilotContext *retval;
@@ -91,30 +91,33 @@ GPilotContext *gpilot_context_new (void)
retval->visor_err_handle = -1;
#endif
- /* get the id. Does anyone know the valid range for this? */
- srand (time (NULL));
- id = 1 + ((guint) 1000000.0*rand ());
- gnome_config_push_prefix ("/gnome-pilot.d/gpilotd/General/");
- str = g_strdup_printf ("sync_PC_Id=%d", id);
- retval->sync_PC_Id=gnome_config_get_int (str);
- g_free (str);
-
- /* if retval is the default value, store it now */
- if (retval->sync_PC_Id == id) {
- gnome_config_set_int ("sync_PC_Id",
+ kfile = get_gpilotd_kfile ();
+
+ retval->sync_PC_Id = g_key_file_get_integer (kfile, "General", "sync_PC_Id", &error);
+ if (error) {
+ /* get the id. Does anyone know the valid range for this? */
+ srand (time (NULL));
+ retval->sync_PC_Id = 1 + ((guint) 1000000.0*rand ());
+ g_key_file_set_integer (kfile, "General", "sync_PC_Id",
retval->sync_PC_Id);
+ g_error_free (error);
+ error = NULL;
+
}
/* get progress stepping, default is -1, if default is returned,
default to one and set it */
- retval->progress_stepping = gnome_config_get_int ("progress_stepping=-1");
- if (retval->progress_stepping == -1) {
+ retval->progress_stepping = g_key_file_get_integer (kfile, "General", "progress_stepping", &error);
+ if (error) {
retval->progress_stepping = 1;
- gnome_config_set_int ("progress_stepping", retval->progress_stepping);
+ g_key_file_set_integer (kfile, "General", "progress_stepping", retval->progress_stepping);
+ g_error_free (error);
+ error = NULL;
}
- gnome_config_pop_prefix ();
- gnome_config_sync ();
+ save_gpilotd_kfile (kfile);
+ g_key_file_free (kfile);
+
return retval;
}
@@ -124,6 +127,7 @@ GPilotContext *gpilot_context_new (void)
void
gpilot_context_init_user (GPilotContext *context)
{
+ GKeyFile *kfile;
gchar *str;
if (!context->user) {
@@ -139,7 +143,10 @@ gpilot_context_init_user (GPilotContext *context)
context->devices = get_devices ();
context->pilots = get_pilots ();
- context->sync_PC_Id=gnome_config_get_int ("/gnome-pilot.d/gpilotd/General/sync_PC_Id");
+ kfile = get_gpilotd_kfile ();
+ context->sync_PC_Id = g_key_file_get_integer (kfile, "General", "sync_PC_Id", NULL);
+
+ g_key_file_free (kfile);
}
void
@@ -546,46 +553,48 @@ gpilot_device_init (GPilotDevice *device)
return result;
}
-static void
-gpilot_serial_device_load (GPilotDevice *device)
-{
- device->port = gnome_config_get_string ("device");
- device->speed = (guint)gnome_config_get_int ("speed=57600");
-}
-
-static void
-gpilot_network_device_load (GPilotDevice *device)
-{
- device->ip = gnome_config_get_string ("ip");
-}
-
gint
gpilot_device_load (GPilotDevice *device, gint i)
{
- gchar prefix[40];
- gchar tmp[40];
+ gchar *iDevice;
gint result = 0;
+ GKeyFile *kfile;
+ GError *error = NULL;
g_return_val_if_fail (device != NULL,-1);
- g_return_val_if_fail (prefix != NULL,-1);
- g_snprintf (prefix, 39,"/gnome-pilot.d/gpilotd/Device%d/", i);
- gnome_config_push_prefix (prefix);
+ kfile = get_gpilotd_kfile ();
+ iDevice = g_strdup_printf ("Device%d", i);
- g_snprintf (tmp, 39,"name=Cradle%d", i);
- device->type = gnome_config_get_int ("type=0");
- device->name = gnome_config_get_string (tmp);
- device->timeout = gnome_config_get_int ("timeout=3");
+ device->type = g_key_file_get_integer (kfile, iDevice, "type", &error);
+ if (error) {
+ g_error_free (error);
+ error = NULL;
+ device->type = 0;
+ }
+ device->name = g_key_file_get_string (kfile, iDevice, "name", NULL);
+ device->timeout = g_key_file_get_integer (kfile, iDevice, "timeout", &error);
+ if (error) {
+ g_error_free (error);
+ error = NULL;
+ device->timeout = 3;
+ }
switch (device->type) {
case PILOT_DEVICE_SERIAL:
case PILOT_DEVICE_USB_VISOR:
case PILOT_DEVICE_IRDA:
/* These devices share the serial loader */
- gpilot_serial_device_load (device);
+ device->port = g_key_file_get_string (kfile, iDevice, "device", NULL);
+ device->speed = (guint)g_key_file_get_integer (kfile, iDevice, "speed", &error);
+ if (error) {
+ g_error_free (error);
+ error = NULL;
+ device->speed = 57600;
+ }
break;
case PILOT_DEVICE_NETWORK:
- gpilot_network_device_load (device);
+ device->ip = g_key_file_get_string (kfile, iDevice, "ip", NULL);
break;
case PILOT_DEVICE_BLUETOOTH:
break; /* no further info required */
@@ -593,7 +602,8 @@ gpilot_device_load (GPilotDevice *device, gint i)
g_warning (_("Unknown device type"));
}
- gnome_config_pop_prefix ();
+ g_free (iDevice);
+ g_key_file_free (kfile);
return result;
}
@@ -659,8 +669,11 @@ get_devices (void)
{
GList * retval = NULL;
int n, i, final;
-
- final = n = gnome_config_get_int ("/gnome-pilot.d/gpilotd/General/num_devices=0");
+ GKeyFile *kfile;
+
+ kfile = get_gpilotd_kfile ();
+
+ final = n = g_key_file_get_integer (kfile, "General", "num_devices", NULL);
if (n==0) {
g_warning (_("Number of devices is configured to 0"));
@@ -689,6 +702,7 @@ get_devices (void)
g_warning (_("No accessible devices available"));
}
+ g_key_file_free (kfile);
return retval;
}
@@ -697,8 +711,11 @@ get_pilots (void)
{
GList * retval = NULL;
int n, i;
+ GKeyFile *kfile;
+
+ kfile = get_gpilotd_kfile ();
- n = gnome_config_get_int ("/gnome-pilot.d/gpilotd/General/num_pilots=0");
+ n = g_key_file_get_integer (kfile, "General", "num_pilots", NULL);
if (n==0) {
g_warning (_("Number of PDAs is configured to 0"));
@@ -716,11 +733,11 @@ get_pilots (void)
gpilot_pilot_init (pilot, i);
retval = g_list_append (retval, pilot);
}
+
+ g_key_file_free (kfile);
return retval;
}
-
-
GPilotPilot *
gpilot_pilot_new (void)
{
@@ -733,27 +750,29 @@ void
gpilot_pilot_init (GPilotPilot *pilot,
gint i)
{
- gchar *prefix;
+ gchar *iPilot;
+ GKeyFile *kfile;
/* set up stuff */
g_free (pilot->name);
g_free (pilot->passwd);
g_free (pilot->pilot_username);
g_free (pilot->pilot_charset);
- prefix = g_strdup_printf ("/gnome-pilot.d/gpilotd/Pilot%d/", i);
- gnome_config_push_prefix (prefix);
+
+ kfile = get_gpilotd_kfile ();
+ iPilot = g_strdup_printf ("Pilot%d", i);
/* start filling in fields */
- pilot->name = gnome_config_get_string("name");
- pilot->pilot_id = gnome_config_get_int("pilotid");
- pilot->pilot_username = gnome_config_get_string("pilotusername");
- pilot->passwd = gnome_config_get_string("password");
- pilot->creation = gnome_config_get_int ("creation");
- pilot->romversion = gnome_config_get_int ("romversion");
+ pilot->name = g_key_file_get_string (kfile, iPilot, "name", NULL);
+ pilot->pilot_id = g_key_file_get_integer (kfile, iPilot, "pilotid", NULL);
+ pilot->pilot_username = g_key_file_get_string (kfile, iPilot, "pilotusername", NULL);
+ pilot->passwd = g_key_file_get_string (kfile, iPilot, "password", NULL);
+ pilot->creation = g_key_file_get_integer (kfile, iPilot, "creation", NULL);
+ pilot->romversion = g_key_file_get_integer (kfile, iPilot, "romversion", NULL);
pilot->number=i;
- pilot->sync_options.basedir = gnome_config_get_string("basedir");
+ pilot->sync_options.basedir = g_key_file_get_string (kfile, iPilot, "basedir", NULL);
#ifdef PILOT_LINK_0_12
- pilot->pilot_charset = gnome_config_get_string("charset");
+ pilot->pilot_charset = g_key_file_get_string (kfile, iPilot, "charset", NULL);
/* If no charset has been specified by user, fall back
* to the PILOT_CHARSET environment variable, if that
* has been specified.
@@ -774,9 +793,8 @@ gpilot_pilot_init (GPilotPilot *pilot,
pilot->pilot_charset=NULL;
#endif
-
- gnome_config_pop_prefix ();
- g_free(prefix);
+ g_key_file_free (kfile);
+ g_free (iPilot);
}
void
diff --git a/gpilotd/gpilot-gui.h b/gpilotd/gpilot-gui.h
index 8051a3a..b32127b 100644
--- a/gpilotd/gpilot-gui.h
+++ b/gpilotd/gpilot-gui.h
@@ -23,7 +23,6 @@
#ifndef _GPILOT_GUI_H_
#define _GPILOT_GUI_H_
#include <glib.h>
-#include <libgnomeui/gnome-messagebox.h>
#include "gnome-pilot-structures.h"
void gpilot_gui_warning_dialog (gchar *mesg, ...);
diff --git a/gpilotd/gpilotd.c b/gpilotd/gpilotd.c
index aac8b4e..0e9e0a6 100644
--- a/gpilotd/gpilotd.c
+++ b/gpilotd/gpilotd.c
@@ -25,10 +25,11 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
+#endif
+
+#include <glib.h>
#include <glib/gi18n.h>
-#include <libgnome/gnome-config.h>
#include <libgnomeui/gnome-ui-init.h>
-#endif
/* for crypt () */
#ifdef USE_XOPEN_SOURCE
@@ -75,6 +76,7 @@
#include "orbit_daemon_glue.h"
#include "gpilot-gui.h"
#include "gnome-pilot-conduit-backup.h"
+#include "gnome-pilot-config.h"
#include "../libgpilotdCM/gnome-pilot-conduit-management.h"
@@ -300,17 +302,20 @@ static void
write_sync_stamp (GPilotPilot *pilot, int pfd, struct PilotUser *pu,
guint32 last_sync_pc, time_t t)
{
- char prefix[256];
+ GKeyFile *kfile;
+ gchar *iPilot;
pu->lastSyncPC = last_sync_pc;
pu->lastSyncDate = t;
- g_snprintf (prefix, 255, "/gnome-pilot.d/gpilotd/Pilot%d/", pilot->number);
- gnome_config_push_prefix (prefix);
- gnome_config_private_set_int ("sync_date", t);
- gnome_config_pop_prefix ();
- gnome_config_sync ();
+ kfile = get_gpilotd_kfile ();
+ iPilot = g_strdup_printf ("Pilot%d", pilot->number);
+ g_key_file_set_integer (kfile, iPilot, "sync_date", t);
+ save_gpilotd_kfile (kfile);
+ g_key_file_free (kfile);
+ g_free (iPilot);
+
dlp_WriteUserInfo (pfd, pu);
}
diff --git a/gpilotd/manager.c b/gpilotd/manager.c
index 3aff1ae..00a9997 100644
--- a/gpilotd/manager.c
+++ b/gpilotd/manager.c
@@ -25,7 +25,6 @@
#include <config.h>
#endif
-#include <libgnome/gnome-config.h>
#include <glib.h>
#include <gmodule.h>
#include <pi-socket.h>
@@ -45,6 +44,7 @@
#include "gnome-pilot-structures.h"
#include "gnome-pilot-dbinfo.h"
#include "gpilot-gui.h"
+#include "gnome-pilot-config.h"
#include "../libgpilotdCM/gnome-pilot-conduit-management.h"
#include "../libgpilotdCM/gnome-pilot-conduit-config.h"
@@ -656,13 +656,14 @@ gpilot_load_conduits (GPilotContext *context,
GList **blist,
GList **flist)
{
- int i, cnt;
- gchar *prefix;
+ int i;
+ gsize cnt;
GnomePilotConduit *conduit;
guint32 pilotId;
gchar **conduit_name;
GnomePilotConduitManagement *manager;
GnomePilotConduitConfig *conduit_config;
+ GKeyFile *kfile;
pilotId = pilot->pilot_id;
@@ -671,13 +672,12 @@ gpilot_load_conduits (GPilotContext *context,
*flist = NULL;
/* Read the conduit configuration */
- prefix = g_strdup_printf ("gnome-pilot.d/conduits%d/General/", pilot->pilot_id);
- gnome_config_push_prefix (prefix);
- gnome_config_get_vector ("conduits",&cnt,&conduit_name);
- gnome_config_pop_prefix ();
- g_free (prefix);
+ kfile = get_conduits_kfile (pilot->pilot_id);
+ conduit_name = g_key_file_get_string_list (kfile, "General", "conduits", &cnt, NULL);
+ g_key_file_free (kfile);
+
g_message (_("Instantiating %d conduits..."), cnt);
- for (i = 0;i<cnt;i++) {
+ for (i = 0;i<cnt ;i++) {
gint err;
manager = gnome_pilot_conduit_management_new (conduit_name[i], GNOME_PILOT_CONDUIT_MGMT_ID);
if (manager == NULL) {
@@ -721,6 +721,7 @@ gpilot_load_conduits (GPilotContext *context,
g_free (conduit_name);
g_message ("Instantiated %d backup conduits, %d file conduits, %d other conduits",
g_list_length (*blist), g_list_length (*flist), g_list_length (*clist));
+
}
void
@@ -1058,10 +1059,10 @@ gpilot_add_log_entry (int pilot_socket,
void
gpilot_manager_save_databases (GPilotPilot *pilot_info,
GSList *databases) {
- gchar *pfx;
char **charlist;
int cnt=0;
GSList *ptr;
+ GKeyFile *kfile;
charlist = g_new0(char*, g_slist_length (databases)+1);
@@ -1070,17 +1071,15 @@ gpilot_manager_save_databases (GPilotPilot *pilot_info,
cnt++;
}
- pfx = g_strdup_printf ("/gnome-pilot.d/PilotCache%d/Databases/",
- pilot_info->pilot_id);
- gnome_config_push_prefix (pfx);
- gnome_config_set_vector ("databases",
- g_slist_length (databases),
- (const char**)charlist);
- gnome_config_pop_prefix ();
- gnome_config_sync ();
+ kfile = get_pilot_cache_kfile (pilot_info->pilot_id);
+ g_key_file_set_string_list (kfile, "Databases", "databases",
+ (const char**)charlist,
+ g_slist_length (databases));
+ save_pilot_cache_kfile (kfile, pilot_info->pilot_id);
+ g_key_file_free (kfile);
+
/* FIXME: is this okay ? */
g_slist_foreach (databases,(GFunc)g_free, NULL);
- g_free (pfx);
g_free (charlist);
g_slist_free (databases);
}
diff --git a/gpilotd/orbit_daemon_glue.c b/gpilotd/orbit_daemon_glue.c
index 828e8e5..79b3d34 100644
--- a/gpilotd/orbit_daemon_glue.c
+++ b/gpilotd/orbit_daemon_glue.c
@@ -21,7 +21,6 @@
*/
#include "config.h"
-#include <libgnome/gnome-config.h>
#include <bonobo-activation/bonobo-activation.h>
#include <libbonobo.h>
@@ -35,6 +34,7 @@
#include <unistd.h>
#include "gnome-pilot-conduit.h"
#include "gnome-pilot-conduit-standard.h"
+#include "gnome-pilot-config.h"
#include <sys/types.h>
#include <signal.h>
@@ -1239,9 +1239,11 @@ gpilotd_corba_get_databases_from_cache(GNOME_Pilot_Daemon obj,
const CORBA_char *pilot_name,
CORBA_Environment *ev)
{
- char **databases,*pfx;
- int num_bases;
+ char **databases;
+ gsize num_bases;
guint32 pilot_id;
+ GKeyFile *kfile;
+
LOG(("corba: get_databases_from_cache(...)"));
pilot_id = pilot_id_from_name(pilot_name,
@@ -1253,11 +1255,8 @@ gpilotd_corba_get_databases_from_cache(GNOME_Pilot_Daemon obj,
return empty_StringSequence();
return NULL;
} else {
- pfx = g_strdup_printf("/gnome-pilot.d/PilotCache%d/Databases/",
- pilot_id);
- gnome_config_push_prefix(pfx);
- gnome_config_get_vector("databases",&num_bases,&databases);
- gnome_config_pop_prefix();
+ kfile = get_pilot_cache_kfile (pilot_id);
+ databases = g_key_file_get_string_list (kfile, "Databases", "databases", &num_bases, NULL);
/* if there were databases, copy into a corba array
and return, otherwise return an empty array */
@@ -1276,7 +1275,8 @@ gpilotd_corba_get_databases_from_cache(GNOME_Pilot_Daemon obj,
strcpy(pilots->_buffer[i],databases[i]);
g_free(databases[i]);
}
- g_free(databases);
+ g_strfreev (databases);
+ g_key_file_free (kfile);
return pilots;
} else {
return empty_StringSequence();
diff --git a/gpilotd/queue_io.c b/gpilotd/queue_io.c
index 9fea906..e9105ca 100644
--- a/gpilotd/queue_io.c
+++ b/gpilotd/queue_io.c
@@ -21,13 +21,10 @@
*/
#include <glib/gi18n.h>
-#include <libgnome/gnome-config.h>
#include "queue_io.h"
+#include "gnome-pilot-config.h"
#include "orbit_daemon_glue.h"
-#define QUEUE "/gnome-pilot.d/queue/"
-/*#define QUEUE "=/home/deity/.gnome/gnome-pilot.d/queue=/"*/
-/*char QUEUE[128];*/
#define NUMREQ "number-of-requests"
/* defines for entries in the queue file */
@@ -65,29 +62,39 @@ static gint is_system_related (GPilotRequestType type) {
crapcrap, set_section skal tage **, man skal ikke malloc den... duhduh!
*/
-static void set_section (guint32 pilot_id, GPilotRequestType type, gchar **section) {
- g_assert(section!=NULL);
- if (*section!=NULL) { g_warning("set_section: *section!=NULL, potiential leak!"); }
+static void
+set_section (guint32 pilot_id, GPilotRequestType type, gchar **section)
+{
+ g_assert(section != NULL);
+
+ if (*section!=NULL) {
+ g_warning("set_section: *section!=NULL, potiential leak!");
+ }
- if(!is_system_related(type)) {
- (*section) = g_strdup_printf ("%s%u/", QUEUE, pilot_id);
+ if(!is_system_related (type)) {
+ (*section) = g_strdup_printf ("%u", pilot_id);
} else {
- (*section) = g_strdup_printf ("%ssystem/", QUEUE);
+ (*section) = g_strdup ("system");
}
}
-static guint32 set_section_num (guint32 pilot_id,
- GPilotRequestType type,
- gchar **section,
- gint num) {
+static guint32
+set_section_num (guint32 pilot_id,
+ GPilotRequestType type,
+ gchar **section,
+ gint num)
+{
g_assert (section!=NULL);
- if (*section!=NULL) { g_warning("set_section_num: *section!=NULL, potiential leak!"); }
- if(!is_system_related (type)) {
- (*section) = g_strdup_printf ("%s%u-%u/", QUEUE, pilot_id, num);
+ if (*section!=NULL) {
+ g_warning("set_section_num: *section!=NULL, potiential leak!");
+ }
+
+ if (!is_system_related (type)) {
+ (*section) = g_strdup_printf ("%u-%u", pilot_id, num);
return pilot_id*65535+num;
} else {
- (*section) = g_strdup_printf ("%ssystem-%d/", QUEUE, num);
+ (*section) = g_strdup_printf ("system-%d", num);
return num;
}
}
@@ -136,17 +143,19 @@ GList* gpc_queue_load_requests_for_cradle(gchar *cradle) {
return retval;
}
-GList* gpc_queue_load_requests (guint32 pilot_id, GPilotRequestType type, gboolean all) {
+GList*
+gpc_queue_load_requests (guint32 pilot_id, GPilotRequestType type, gboolean all)
+{
int num;
GList *retval = NULL;
- gchar *prefix = NULL;
+ gchar *section = NULL;
+ GKeyFile *kfile;
+
+ kfile = get_queue_kfile ();
- set_section (pilot_id, type, &prefix);
-
- gnome_config_push_prefix (prefix);
- num = gnome_config_get_int (NUMREQ);
- gnome_config_pop_prefix ();
- g_free (prefix);
+ set_section (pilot_id, type, §ion);
+ num = g_key_file_get_integer (kfile, section, NUMREQ, NULL);
+ g_free (section);
for (;num>0;num--) {
GPilotRequest *req;
@@ -157,65 +166,66 @@ GList* gpc_queue_load_requests (guint32 pilot_id, GPilotRequestType type, gboole
}
if(req==NULL) {
- gnome_config_pop_prefix ();
continue;
}
if (req->type!=type && all==FALSE) {
g_free (req);
- gnome_config_pop_prefix ();
continue;
}
retval = g_list_append (retval, req);
- gnome_config_pop_prefix ();
}
+
+ g_key_file_free (kfile);
return retval;
}
GPilotRequest*
-gpc_queue_load_request (guint32 pilot_id, gboolean _type, guint num) {
+gpc_queue_load_request (guint32 pilot_id, gboolean _type, guint num)
+{
GPilotRequest *req;
- gchar *prefix = NULL;
+ gchar *section = NULL;
GPilotRequestType type;
-
+ GKeyFile *kfile;
+
if (_type==TRUE) {
type = GREQ_CRADLE_EVENT;
} else {
type = GREQ_PILOT_EVENT;
}
- set_section_num (pilot_id, type, &prefix, num);
- gnome_config_push_prefix (prefix);
+ kfile = get_queue_kfile ();
+ set_section_num (pilot_id, type, §ion, num);
req = g_new0 (GPilotRequest, sizeof (GPilotRequest));
- req->type = request_type_from_string (gnome_config_get_string (ENT_TYPE));
- if (req->type==GREQ_INVALID) {
+ req->type = request_type_from_string (g_key_file_get_string (kfile, section, ENT_TYPE, NULL));
+ if (req->type == GREQ_INVALID) {
g_free (req);
- gnome_config_pop_prefix ();
+ g_key_file_free (kfile);
return NULL;
}
/* unless I store the sectionname _without_ trailing /, clean_section
can't delete it ? */
- g_free (prefix);
- prefix = NULL;
- req->handle = set_section_num (pilot_id, type, &prefix, num);
- req->queue_data.section_name = g_strdup (prefix);
+ g_free (section);
+ section = NULL;
+ req->handle = set_section_num (pilot_id, type, §ion, num);
+ req->queue_data.section_name = g_strdup (section);
req->pilot_id = pilot_id;
switch (req->type) {
case GREQ_INSTALL:
- req->parameters.install.filename = gnome_config_get_string(ENT_FILENAME);
- req->parameters.install.description = gnome_config_get_string(ENT_DESCRIPTION);
+ req->parameters.install.filename = g_key_file_get_string (kfile, section, ENT_FILENAME, NULL);
+ req->parameters.install.description = g_key_file_get_string (kfile, section, ENT_DESCRIPTION, NULL);
break;
case GREQ_RESTORE:
- req->parameters.restore.directory = gnome_config_get_string(ENT_DIRECTORY);
+ req->parameters.restore.directory = g_key_file_get_string (kfile, section, ENT_DIRECTORY, NULL);
break;
case GREQ_CONDUIT: {
gchar *tmp;
- req->parameters.conduit.name = gnome_config_get_string(ENT_CONDUIT);
- tmp = gnome_config_get_string(ENT_HOW);
- req->parameters.conduit.how = gnome_pilot_conduit_sync_type_str_to_int(tmp);
+ req->parameters.conduit.name = g_key_file_get_string (kfile, section, ENT_CONDUIT, NULL);
+ tmp = g_key_file_get_string (kfile, section, ENT_HOW, NULL);
+ req->parameters.conduit.how = gnome_pilot_conduit_sync_type_str_to_int (tmp);
g_free(tmp);
}
break;
@@ -224,27 +234,27 @@ gpc_queue_load_request (guint32 pilot_id, gboolean _type, guint num) {
case GREQ_GET_SYSINFO:
break;
case GREQ_NEW_USERINFO: /* shares parameters with SET_USERINFO */
- req->parameters.set_userinfo.password = gnome_config_get_string(ENT_PASSWORD);
- req->parameters.set_userinfo.user_id = gnome_config_get_string(ENT_USER_ID);
- req->parameters.set_userinfo.pilot_id = gnome_config_get_int(ENT_PILOT_ID);
+ req->parameters.set_userinfo.password = g_key_file_get_string (kfile, section, ENT_PASSWORD, NULL);
+ req->parameters.set_userinfo.user_id = g_key_file_get_string (kfile, section, ENT_USER_ID, NULL);
+ req->parameters.set_userinfo.pilot_id = g_key_file_get_integer (kfile, section, ENT_PILOT_ID, NULL);
break;
case GREQ_SET_USERINFO:
- req->parameters.set_userinfo.password = gnome_config_get_string(ENT_PASSWORD);
- req->parameters.set_userinfo.user_id = gnome_config_get_string(ENT_USER_ID);
- req->parameters.set_userinfo.pilot_id = gnome_config_get_int(ENT_PILOT_ID);
- req->parameters.set_userinfo.continue_sync = gnome_config_get_bool(ENT_CONT_SYNC);
+ req->parameters.set_userinfo.password = g_key_file_get_string (kfile, section, ENT_PASSWORD, NULL);
+ req->parameters.set_userinfo.user_id = g_key_file_get_string (kfile, section, ENT_USER_ID, NULL);
+ req->parameters.set_userinfo.pilot_id = g_key_file_get_integer (kfile, section, ENT_PILOT_ID, NULL);
+ req->parameters.set_userinfo.continue_sync = g_key_file_get_boolean (kfile, section, ENT_CONT_SYNC, NULL);
break;
default:
g_assert_not_reached();
break;
}
- req->cradle = gnome_config_get_string(ENT_DEVICE);
- req->client_id = gnome_config_get_string(ENT_CLIENT_ID);
- req->timeout = gnome_config_get_int(ENT_TIMEOUT);
- req->handle = gnome_config_get_int(ENT_HANDLE);
- gnome_config_pop_prefix();
- g_free(prefix);
+ req->cradle = g_key_file_get_string (kfile, section, ENT_DEVICE, NULL);
+ req->client_id = g_key_file_get_string (kfile, section, ENT_CLIENT_ID, NULL);
+ req->timeout = g_key_file_get_integer (kfile, section, ENT_TIMEOUT, NULL);
+ req->handle = g_key_file_get_integer (kfile, section, ENT_HANDLE, NULL);
+ g_free (section);
+ g_key_file_free (kfile);
return req;
}
@@ -254,75 +264,78 @@ gpc_queue_load_request (guint32 pilot_id, gboolean _type, guint num) {
thus they're leaked.
*/
-guint gpc_queue_store_request(GPilotRequest req) {
+guint
+gpc_queue_store_request (GPilotRequest req)
+{
guint num;
guint32 handle_num;
- gchar *prefix = NULL;
+ gchar *section = NULL;
+ GKeyFile *kfile;
- set_section(req.pilot_id,req.type,&prefix);
+ set_section (req.pilot_id, req.type, §ion);
- gnome_config_push_prefix(prefix);
- num = gnome_config_get_int(NUMREQ);
+ kfile = get_queue_kfile ();
+
+ num = g_key_file_get_integer (kfile, section, NUMREQ, NULL);
num++;
- gnome_config_set_int(NUMREQ,num);
- gnome_config_pop_prefix();
- g_free(prefix);
- prefix = NULL;
- handle_num = set_section_num(req.pilot_id,req.type,&prefix,num);
+ g_key_file_set_integer (kfile, section, NUMREQ, num);
+ g_free (section);
+
+ section = NULL;
+ handle_num = set_section_num (req.pilot_id, req.type, §ion, num);
- gnome_config_push_prefix(prefix);
- switch(req.type) {
+ switch (req.type) {
case GREQ_INSTALL:
- gnome_config_set_string(ENT_TYPE,"GREQ_INSTALL");
- gnome_config_set_string(ENT_FILENAME,req.parameters.install.filename);
- gnome_config_set_string(ENT_DESCRIPTION,req.parameters.install.description);
+ g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_INSTALL");
+ g_key_file_set_string (kfile, section, ENT_FILENAME, req.parameters.install.filename);
+ g_key_file_set_string (kfile, section, ENT_DESCRIPTION, req.parameters.install.description);
break;
case GREQ_RESTORE:
- gnome_config_set_string(ENT_TYPE,"GREQ_RESTORE");
- gnome_config_set_string(ENT_DIRECTORY,req.parameters.restore.directory);
+ g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_RESTORE");
+ g_key_file_set_string (kfile, section, ENT_DIRECTORY, req.parameters.restore.directory);
break;
case GREQ_CONDUIT:
- g_message("req.parameters.conduit.name = %s",req.parameters.conduit.name);
- gnome_config_set_string(ENT_TYPE,"GREQ_CONDUIT");
- gnome_config_set_string(ENT_CONDUIT,req.parameters.conduit.name);
- gnome_config_set_string(ENT_HOW,
- gnome_pilot_conduit_sync_type_int_to_str(req.parameters.conduit.how));
+ g_message ("req.parameters.conduit.name = %s", req.parameters.conduit.name);
+ g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_CONDUIT");
+ g_key_file_set_string (kfile, section, ENT_CONDUIT, req.parameters.conduit.name);
+ g_key_file_set_string (kfile, section, ENT_HOW,
+ gnome_pilot_conduit_sync_type_int_to_str (req.parameters.conduit.how));
break;
case GREQ_NEW_USERINFO:
- gnome_config_set_string(ENT_TYPE,"GREQ_NEW_USERINFO");
- gnome_config_set_string(ENT_DEVICE,req.cradle);
- gnome_config_set_string(ENT_USER_ID,req.parameters.set_userinfo.user_id);
- gnome_config_set_int(ENT_PILOT_ID,req.parameters.set_userinfo.pilot_id);
+ g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_NEW_USERINFO");
+ g_key_file_set_string (kfile, section, ENT_DEVICE, req.cradle);
+ g_key_file_set_string (kfile, section, ENT_USER_ID, req.parameters.set_userinfo.user_id);
+ g_key_file_set_integer (kfile, section, ENT_PILOT_ID, req.parameters.set_userinfo.pilot_id);
break;
case GREQ_SET_USERINFO:
- gnome_config_set_string(ENT_TYPE,"GREQ_SET_USERINFO");
- gnome_config_set_string(ENT_DEVICE,req.cradle);
- gnome_config_set_string(ENT_PASSWORD,req.parameters.set_userinfo.password);
- gnome_config_set_string(ENT_USER_ID,req.parameters.set_userinfo.user_id);
- gnome_config_set_int(ENT_PILOT_ID,req.parameters.set_userinfo.pilot_id);
- gnome_config_set_bool(ENT_CONT_SYNC,req.parameters.set_userinfo.continue_sync);
+ g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_SET_USERINFO");
+ g_key_file_set_string (kfile, section, ENT_DEVICE, req.cradle);
+ g_key_file_set_string (kfile, section, ENT_PASSWORD, req.parameters.set_userinfo.password);
+ g_key_file_set_string (kfile, section, ENT_USER_ID, req.parameters.set_userinfo.user_id);
+ g_key_file_set_integer (kfile, section, ENT_PILOT_ID, req.parameters.set_userinfo.pilot_id);
+ g_key_file_set_boolean (kfile, section, ENT_CONT_SYNC, req.parameters.set_userinfo.continue_sync);
break;
case GREQ_GET_USERINFO:
- gnome_config_set_string(ENT_TYPE,"GREQ_GET_USERINFO");
- gnome_config_set_string(ENT_DEVICE,req.cradle);
+ g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_GET_USERINFO");
+ g_key_file_set_string (kfile, section, ENT_DEVICE,req.cradle);
break;
case GREQ_GET_SYSINFO:
- gnome_config_set_string(ENT_TYPE,"GREQ_GET_SYSINFO");
- gnome_config_set_string(ENT_DEVICE,req.cradle);
+ g_key_file_set_string (kfile, section, ENT_TYPE, "GREQ_GET_SYSINFO");
+ g_key_file_set_string (kfile, section, ENT_DEVICE, req.cradle);
break;
default:
- g_assert_not_reached();
+ g_assert_not_reached ();
break;
}
- gnome_config_set_int(ENT_TIMEOUT,req.timeout);
- gnome_config_set_int(ENT_HANDLE,handle_num);
- gnome_config_set_string(ENT_CLIENT_ID,req.client_id);
- gnome_config_pop_prefix();
+ g_key_file_set_integer (kfile, section, ENT_TIMEOUT, req.timeout);
+ g_key_file_set_integer (kfile, section, ENT_HANDLE, handle_num);
+ g_key_file_set_string (kfile, section, ENT_CLIENT_ID, req.client_id);
- gnome_config_sync();
- g_free(prefix);
+ g_free (section);
+ save_queue_kfile (kfile);
+ g_key_file_free (kfile);
- LOG(("assigned handle num %u",handle_num));
+ LOG (("assigned handle num %u",handle_num));
return handle_num;
}
@@ -363,22 +376,23 @@ renummerating them would trash that.
void
gpc_queue_purge_request(GPilotRequest **req)
{
- gchar *prefix = NULL;
+ gchar *section = NULL;
int num;
+ GKeyFile *kfile;
- LOG(("gpc_queue_purge_request()"));
+ LOG (("gpc_queue_purge_request()"));
- g_return_if_fail(req!=NULL);
- g_return_if_fail(*req!=NULL);
+ g_return_if_fail (req != NULL);
+ g_return_if_fail (*req != NULL);
- set_section((*req)->pilot_id,(*req)->type,&prefix);
- gnome_config_push_prefix(prefix);
- num = gnome_config_get_int(NUMREQ);
+ kfile = get_queue_kfile ();
+ set_section ((*req)->pilot_id, (*req)->type, §ion);
+ num = g_key_file_get_integer (kfile, section, NUMREQ, NULL);
num--;
- gnome_config_set_int(NUMREQ,num);
- gnome_config_pop_prefix();
+ g_key_file_set_integer (kfile, section, NUMREQ, num);
+
+ g_key_file_remove_group (kfile, (*req)->queue_data.section_name, NULL);
- gnome_config_clean_section((*req)->queue_data.section_name);
switch((*req)->type) {
case GREQ_INSTALL:
unlink((*req)->parameters.install.filename);
@@ -410,8 +424,10 @@ gpc_queue_purge_request(GPilotRequest **req)
g_free(*req);
*req = NULL;
- gnome_config_sync();
- g_free(prefix);
+ g_free (section);
+
+ save_queue_kfile (kfile);
+ g_key_file_free (kfile);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]