diff options
Diffstat (limited to 'calendar/conduits/todo/todo-conduit.c')
-rw-r--r-- | calendar/conduits/todo/todo-conduit.c | 315 |
1 files changed, 245 insertions, 70 deletions
diff --git a/calendar/conduits/todo/todo-conduit.c b/calendar/conduits/todo/todo-conduit.c index 8b68110847..ec24707596 100644 --- a/calendar/conduits/todo/todo-conduit.c +++ b/calendar/conduits/todo/todo-conduit.c @@ -31,22 +31,17 @@ #include <cal-util/timeutil.h> #include <pi-source.h> #include <pi-socket.h> -#include <pi-file.h> #include <pi-dlp.h> +#include <pi-todo.h> #include <libical/src/libical/icaltypes.h> +#include <gpilotd/gnome-pilot-conduit.h> +#include <gpilotd/gnome-pilot-conduit-sync-abs.h> +#include <libgpilotdCM/gnome-pilot-conduit-management.h> +#include <libgpilotdCM/gnome-pilot-conduit-config.h> +#include <e-pilot-map.h> +#include <e-pilot-settings.h> #include <e-pilot-util.h> -#define TODO_CONFIG_LOAD 1 -#define TODO_CONFIG_SAVE 1 -#define TODO_CONFIG_DESTROY 1 -#include <todo-conduit-config.h> -#undef TODO_CONFIG_LOAD -#undef TODO_CONFIG_SAVE -#undef TODO_CONFIG_DESTROY - -#include <todo-conduit.h> - -static void free_local (EToDoLocalRecord *local); GnomePilotConduit * conduit_get_gpilot_conduit (guint32); void conduit_destroy_gpilot_conduit (GnomePilotConduit*); @@ -56,10 +51,10 @@ void conduit_destroy_gpilot_conduit (GnomePilotConduit*); #endif #define G_LOG_DOMAIN "etodoconduit" -#define DEBUG_CALCONDUIT 1 -/* #undef DEBUG_CALCONDUIT */ +#define DEBUG_TODOCONDUIT 1 +/* #undef DEBUG_TODOCONDUIT */ -#ifdef DEBUG_CALCONDUIT +#ifdef DEBUG_TODOCONDUIT #define LOG(e...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, e) #else #define LOG(e...) @@ -68,62 +63,137 @@ void conduit_destroy_gpilot_conduit (GnomePilotConduit*); #define WARN(e...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, e) #define INFO(e...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, e) -/* Debug routines */ -static char * -print_local (EToDoLocalRecord *local) +typedef struct _EToDoLocalRecord EToDoLocalRecord; +typedef struct _EToDoConduitCfg EToDoConduitCfg; +typedef struct _EToDoConduitContext EToDoConduitContext; + +/* Local Record */ +struct _EToDoLocalRecord { + /* The stuff from gnome-pilot-conduit-standard-abs.h + Must be first in the structure, or instances of this + structure cannot be used by gnome-pilot-conduit-standard-abs. + */ + GnomePilotDesktopRecord local; + + /* The corresponding Comp object */ + CalComponent *comp; + + /* pilot-link todo structure */ + struct ToDo *todo; +}; + +static void +todoconduit_destroy_record (EToDoLocalRecord *local) { - static char buff[ 4096 ]; + gtk_object_unref (GTK_OBJECT (local->comp)); + free_ToDo (local->todo); + g_free (local->todo); + g_free (local); +} - if (local == NULL) { - sprintf (buff, "[NULL]"); - return buff; - } +/* Configuration */ +struct _EToDoConduitCfg { + guint32 pilot_id; + GnomePilotConduitSyncType sync_type; - if (local->todo && local->todo->description) { - g_snprintf (buff, 4096, "[%d %ld %d %d '%s' '%s']", - local->todo->indefinite, - mktime (& local->todo->due), - local->todo->priority, - local->todo->complete, - local->todo->description ? - local->todo->description : "", - local->todo->note ? - local->todo->note : ""); - return buff; - } + gboolean secret; + gchar *last_uri; +}; - return ""; +static void +todoconduit_load_configuration (EToDoConduitCfg **c, guint32 pilot_id) +{ + GnomePilotConduitManagement *management; + GnomePilotConduitConfig *config; + gchar prefix[256]; + g_snprintf (prefix, 255, "/gnome-pilot.d/e-todo-conduit/Pilot_%u/", + pilot_id); + + *c = g_new0 (EToDoConduitCfg,1); + g_assert (*c != NULL); + + (*c)->pilot_id = pilot_id; + + management = gnome_pilot_conduit_management_new ("e_todo_conduit", GNOME_PILOT_CONDUIT_MGMT_ID); + config = gnome_pilot_conduit_config_new (management, pilot_id); + if (!gnome_pilot_conduit_config_is_enabled (config, &(*c)->sync_type)) + (*c)->sync_type = GnomePilotConduitSyncTypeNotSet; + gtk_object_unref (GTK_OBJECT (config)); + gtk_object_unref (GTK_OBJECT (management)); + + /* Custom settings */ + gnome_config_push_prefix (prefix); + + (*c)->secret = gnome_config_get_bool ("secret=FALSE"); + (*c)->last_uri = gnome_config_get_string ("last_uri"); + + gnome_config_pop_prefix (); } -static char *print_remote (GnomePilotRecord *remote) +static void +todoconduit_save_configuration (EToDoConduitCfg *c) { - static char buff[ 4096 ]; - struct ToDo todo; + gchar prefix[256]; - if (remote == NULL) { - sprintf (buff, "[NULL]"); - return buff; - } + g_snprintf (prefix, 255, "/gnome-pilot.d/e-todo-conduit/Pilot_%u/", + c->pilot_id); - memset (&todo, 0, sizeof (struct ToDo)); - unpack_ToDo (&todo, remote->record, remote->length); + gnome_config_push_prefix (prefix); + gnome_config_set_bool ("secret", c->secret); + gnome_config_set_string ("last_uri", c->last_uri); + gnome_config_pop_prefix (); - g_snprintf (buff, 4096, "[%d %ld %d %d '%s' '%s']", - todo.indefinite, - mktime (&todo.due), - todo.priority, - todo.complete, - todo.description ? - todo.description : "", - todo.note ? - todo.note : ""); + gnome_config_sync (); + gnome_config_drop_all (); +} - free_ToDo (&todo); - - return buff; +static EToDoConduitCfg* +todoconduit_dupe_configuration (EToDoConduitCfg *c) +{ + EToDoConduitCfg *retval; + + g_return_val_if_fail (c != NULL, NULL); + + retval = g_new0 (EToDoConduitCfg, 1); + retval->sync_type = c->sync_type; + retval->pilot_id = c->pilot_id; + + retval->secret = c->secret; + retval->last_uri = g_strdup (c->last_uri); + + return retval; } -/* Context Routines */ +static void +todoconduit_destroy_configuration (EToDoConduitCfg *c) +{ + g_return_if_fail (c != NULL); + + g_free (c->last_uri); + g_free (c); +} + +/* Context */ +struct _EToDoConduitContext { + EToDoConduitCfg *cfg; + GnomePilotDBInfo *dbi; + + EToDoConduitCfg *new_cfg; + GtkWidget *ps; + + struct ToDoAppInfo ai; + + CalClient *client; + + icaltimezone *timezone; + GList *uids; + GList *changed; + GHashTable *changed_hash; + GList *locals; + + EPilotMap *map; +}; + static EToDoConduitContext * e_todo_context_new (guint32 pilot_id) { @@ -157,7 +227,7 @@ e_todo_context_destroy (EToDoConduitContext *ctxt) g_return_if_fail (ctxt != NULL); if (ctxt->cfg != NULL) - todoconduit_destroy_configuration (&ctxt->cfg); + todoconduit_destroy_configuration (ctxt->cfg); if (ctxt->client != NULL) gtk_object_unref (GTK_OBJECT (ctxt->client)); @@ -172,7 +242,7 @@ e_todo_context_destroy (EToDoConduitContext *ctxt) if (ctxt->locals != NULL) { for (l = ctxt->locals; l != NULL; l = l->next) - free_local (l->data); + todoconduit_destroy_record (l->data); g_list_free (ctxt->locals); } @@ -185,6 +255,62 @@ e_todo_context_destroy (EToDoConduitContext *ctxt) g_free (ctxt); } +/* Debug routines */ +static char * +print_local (EToDoLocalRecord *local) +{ + static char buff[ 4096 ]; + + if (local == NULL) { + sprintf (buff, "[NULL]"); + return buff; + } + + if (local->todo && local->todo->description) { + g_snprintf (buff, 4096, "[%d %ld %d %d '%s' '%s']", + local->todo->indefinite, + mktime (& local->todo->due), + local->todo->priority, + local->todo->complete, + local->todo->description ? + local->todo->description : "", + local->todo->note ? + local->todo->note : ""); + return buff; + } + + return ""; +} + +static char *print_remote (GnomePilotRecord *remote) +{ + static char buff[ 4096 ]; + struct ToDo todo; + + if (remote == NULL) { + sprintf (buff, "[NULL]"); + return buff; + } + + memset (&todo, 0, sizeof (struct ToDo)); + unpack_ToDo (&todo, remote->record, remote->length); + + g_snprintf (buff, 4096, "[%d %ld %d %d '%s' '%s']", + todo.indefinite, + mktime (&todo.due), + todo.priority, + todo.complete, + todo.description ? + todo.description : "", + todo.note ? + todo.note : ""); + + free_ToDo (&todo); + + return buff; +} + + /* Calendar Server routines */ static void start_calendar_server_cb (CalClient *cal_client, @@ -342,15 +468,6 @@ compute_status (EToDoConduitContext *ctxt, EToDoLocalRecord *local, const char * } } -static void -free_local (EToDoLocalRecord *local) -{ - gtk_object_unref (GTK_OBJECT (local->comp)); - free_ToDo (local->todo); - g_free (local->todo); - g_free (local); -} - static GnomePilotRecord local_record_to_pilot_record (EToDoLocalRecord *local, EToDoConduitContext *ctxt) @@ -1089,7 +1206,7 @@ free_match (GnomePilotConduitSyncAbs *conduit, g_return_val_if_fail (local != NULL, -1); - free_local (local); + todoconduit_destroy_record (local); return 0; } @@ -1107,6 +1224,58 @@ prepare (GnomePilotConduitSyncAbs *conduit, return 0; } +/* Pilot Settings Callbacks */ +static void +fill_widgets (EToDoConduitContext *ctxt) +{ + e_pilot_settings_set_secret (E_PILOT_SETTINGS (ctxt->ps), + ctxt->cfg->secret); +} + +static gint +create_settings_window (GnomePilotConduit *conduit, + GtkWidget *parent, + EToDoConduitContext *ctxt) +{ + LOG ("create_settings_window"); + + ctxt->ps = e_pilot_settings_new (); + gtk_container_add (GTK_CONTAINER (parent), ctxt->ps); + gtk_widget_show (ctxt->ps); + + fill_widgets (ctxt); + + return 0; +} +static void +display_settings (GnomePilotConduit *conduit, EToDoConduitContext *ctxt) +{ + LOG ("display_settings"); + + fill_widgets (ctxt); +} + +static void +save_settings (GnomePilotConduit *conduit, EToDoConduitContext *ctxt) +{ + LOG ("save_settings"); + + ctxt->new_cfg->secret = + e_pilot_settings_get_secret (E_PILOT_SETTINGS (ctxt->ps)); + + todoconduit_save_configuration (ctxt->new_cfg); +} + +static void +revert_settings (GnomePilotConduit *conduit, EToDoConduitContext *ctxt) +{ + LOG ("revert_settings"); + + todoconduit_save_configuration (ctxt->cfg); + todoconduit_destroy_configuration (ctxt->new_cfg); + ctxt->new_cfg = todoconduit_dupe_configuration (ctxt->cfg); +} + static ORBit_MessageValidationResult accept_all_cookies (CORBA_unsigned_long request_id, CORBA_Principal *principal, @@ -1166,6 +1335,12 @@ conduit_get_gpilot_conduit (guint32 pilot_id) gtk_signal_connect (retval, "prepare", (GtkSignalFunc) prepare, ctxt); + /* Gui Settings */ + gtk_signal_connect (retval, "create_settings_window", (GtkSignalFunc) create_settings_window, ctxt); + gtk_signal_connect (retval, "display_settings", (GtkSignalFunc) display_settings, ctxt); + gtk_signal_connect (retval, "save_settings", (GtkSignalFunc) save_settings, ctxt); + gtk_signal_connect (retval, "revert_settings", (GtkSignalFunc) revert_settings, ctxt); + return GNOME_PILOT_CONDUIT (retval); } |