summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lord <chris@openedhand.com>2006-07-24 11:28:26 +0000
committerChris Lord <chris@openedhand.com>2006-07-24 11:28:26 +0000
commit988156e3d43490ca9c2a61b8b45313027a21667c (patch)
tree4b1f8861ddc5b64159b8b42f2ca334ad0fa63915
parent0d64078d65a9c51d8e64715b92ce6569a06d2980 (diff)
downloadsync-988156e3d43490ca9c2a61b8b45313027a21667c.tar.gz
sync-988156e3d43490ca9c2a61b8b45313027a21667c.tar.bz2
sync-988156e3d43490ca9c2a61b8b45313027a21667c.zip
- Rename pokysync->sync
- Clean backup data before backing up
-rw-r--r--sync/ChangeLog18
-rw-r--r--sync/configure.ac6
-rw-r--r--sync/data/Makefile.am6
-rw-r--r--sync/data/sync.glade (renamed from sync/data/pokysync.glade)0
-rw-r--r--sync/src/Makefile.am8
-rw-r--r--sync/src/sync.h (renamed from sync/src/pokysync.h)24
-rw-r--r--sync/src/sync_main.c (renamed from sync/src/pokysync_main.c)131
7 files changed, 129 insertions, 64 deletions
diff --git a/sync/ChangeLog b/sync/ChangeLog
index 2359e30..40aa389 100644
--- a/sync/ChangeLog
+++ b/sync/ChangeLog
@@ -1,3 +1,21 @@
+2006-07-24 Chris Lord,,, <chris@openedhand.com>
+
+ * configure.ac:
+ * data/Makefile.am:
+ * data/pokysync.glade:
+ * src/Makefile.am:
+ * src/pokysync.h:
+ * src/pokysync_main.c:
+ * src/sync.h:
+ * src/sync_main.c: (sync_clean_backup), (sync_get_backup_group),
+ (sync_animate), (OSyncChangeType2String), (sync_conflict_cb),
+ (sync_changestatus_cb), (sync_mappingstatus_cb),
+ (sync_enginestatus_cb), (sync_memberstatus_cb), (sync_backup),
+ (sync_activate_cursor_item_cb), (sync_item_activated_cb),
+ (sync_sync_button_cb), (sync_chooser_cb), (main):
+ - Rename pokysync->sync
+ - Clean backup data before backing up
+
2006-06-16 Chris Lord,,, <chris@openedhand.com>
* src/pokysync_main.c: (pokysync_mappingstatus_cb),
diff --git a/sync/configure.ac b/sync/configure.ac
index 1c58c21..39264b4 100644
--- a/sync/configure.ac
+++ b/sync/configure.ac
@@ -1,7 +1,7 @@
AC_PREREQ(2.53)
-AC_INIT(pokysync, 0.0, http://www.openedhand.com/)
+AC_INIT(sync, 0.0, http://www.openedhand.com/)
AM_INIT_AUTOMAKE()
-AC_CONFIG_SRCDIR(src/pokysync_main.c)
+AC_CONFIG_SRCDIR(src/sync_main.c)
AM_CONFIG_HEADER(src/config.h)
AM_MAINTAINER_MODE
@@ -10,7 +10,7 @@ AC_PROG_CC
AC_STDC_HEADERS
AC_PROG_LIBTOOL
-PKG_CHECK_MODULES(POKYSYNC, glib-2.0 gthread-2.0 gtk+-2.0 libglade-2.0 gconf-2.0 opensync-1.0 osengine-1.0 avahi-glib)
+PKG_CHECK_MODULES(SYNC, glib-2.0 gthread-2.0 gtk+-2.0 libglade-2.0 gconf-2.0 opensync-1.0 osengine-1.0 avahi-glib)
AC_OUTPUT([
Makefile
diff --git a/sync/data/Makefile.am b/sync/data/Makefile.am
index e99d759..3e0b946 100644
--- a/sync/data/Makefile.am
+++ b/sync/data/Makefile.am
@@ -1,13 +1,13 @@
uidir = $(pkgdatadir)
-ui_DATA = pokysync.glade
+ui_DATA = sync.glade
applicationdir = $(datadir)/applications
application_DATA =
-#pokysync.desktop
+#sync.desktop
icondir = $(datadir)/pixmaps/
icon_DATA =
-#pokysync.png
+#sync.png
MAINTAINERCLEANFILES = Makefile.in
diff --git a/sync/data/pokysync.glade b/sync/data/sync.glade
index 0db0f91..0db0f91 100644
--- a/sync/data/pokysync.glade
+++ b/sync/data/sync.glade
diff --git a/sync/src/Makefile.am b/sync/src/Makefile.am
index 601c3fb..646b906 100644
--- a/sync/src/Makefile.am
+++ b/sync/src/Makefile.am
@@ -1,10 +1,10 @@
AM_CPPFLAGS=-DPKGDATADIR=\"$(pkgdatadir)\"
-AM_CFLAGS = -Wall -export-dynamic $(POKYSYNC_CFLAGS)
+AM_CFLAGS = -Wall -export-dynamic $(SYNC_CFLAGS)
-bin_PROGRAMS = pokysync
+bin_PROGRAMS = sync
-pokysync_SOURCES = pokysync_main.c pokysync.h
+sync_SOURCES = sync_main.c sync.h
-pokysync_LDADD = $(POKYSYNC_LIBS)
+sync_LDADD = $(SYNC_LIBS)
MAINTAINERCLEANFILES = config.h.in Makefile.in
diff --git a/sync/src/pokysync.h b/sync/src/sync.h
index 40afacf..ad46340 100644
--- a/sync/src/pokysync.h
+++ b/sync/src/sync.h
@@ -1,21 +1,15 @@
-#ifndef POKYSYNC_H
-#define POKYSYNC_H
+#ifndef SYNC_H
+#define SYNC_H
#include <gtk/gtk.h>
#include <glade/glade.h>
#include <opensync/opensync.h>
-#define XML_FILE PKGDATADIR "/pokysync.glade"
-#define BACKUP_GROUP "pokysync-backup"
-
-#define BACKUP_PLUGIN "file-sync"
-#define BACKUP_CONFIG "<config>" \
- "<path>%s</path>" \
- "<recursive>FALSE</recursive>" \
- "</config>"
+#define XML_FILE PKGDATADIR G_DIR_SEPARATOR_S "sync.glade"
+#define BACKUP_GROUP "sync-backup"
#define BACKUP_PATH "%s" G_DIR_SEPARATOR_S ".gnome2" G_DIR_SEPARATOR_S \
- "poky" G_DIR_SEPARATOR_S "backup"
+ "sync" G_DIR_SEPARATOR_S "backup"
#define EVO2_PLUGIN "evo2-sync"
#define EVO2_CONFIG "<config>" \
@@ -24,6 +18,12 @@
"<tasks_path>default</tasks_path>" \
"</config>"
+#define FILE_PLUGIN "file-sync"
+#define FILE_CONFIG "<config>" \
+ "<path>%s</path>" \
+ "<recursive>FALSE</recursive>" \
+ "</config>"
+
enum {
COL_ID,
COL_NAME,
@@ -47,7 +47,7 @@ typedef struct {
gboolean syncing;
guint animate_id;
-} PokySyncData;
+} SyncData;
#endif
diff --git a/sync/src/pokysync_main.c b/sync/src/sync_main.c
index 880bf5c..e83f21d 100644
--- a/sync/src/pokysync_main.c
+++ b/sync/src/sync_main.c
@@ -3,24 +3,71 @@
#include <math.h>
#include <glib.h>
#include <glib/gprintf.h>
+#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
#include <opensync/opensync.h>
#include <osengine/engine.h>
-#include "pokysync.h"
+#include "sync.h"
+static gboolean
+sync_clean_backup (SyncData *data)
+{
+ OSyncGroup *group;
+ GDir *backup_dir;
+ OSyncError *error = NULL;
+ GError *gerror = NULL;
+ const gchar *filename;
+
+ group = osync_env_find_group (data->osync, BACKUP_GROUP);
+
+ /* Delete group */
+ if ((group) && (!osync_group_delete(group, &error))) {
+ g_warning ("Unable to delete backup group: %s\n",
+ osync_error_print(&error));
+ osync_error_free(&error);
+ return FALSE;
+ }
+
+ /* Remove backup files */
+ if (!g_file_test (BACKUP_PATH, G_FILE_TEST_EXISTS)) return TRUE;
+ if (!g_file_test (BACKUP_PATH, G_FILE_TEST_IS_DIR)) return FALSE;
+ if (!(backup_dir = g_dir_open (BACKUP_PATH, 0, &gerror))) {
+ g_warning ("Error opening backup directory: %s",
+ gerror->message);
+ g_error_free (gerror);
+ return FALSE;
+ }
+ while ((filename = g_dir_read_name (backup_dir))) {
+ if (g_remove (filename) != 0) {
+ g_warning ("Error removing file: %s", filename);
+ break;
+ }
+ }
+ g_dir_close (backup_dir);
+
+ /* Remove backup directory */
+ if (g_rmdir (BACKUP_PATH) != 0) {
+ g_warning ("Error removing backup directory");
+ return FALSE;
+ }
+
+ return TRUE;
+}
static OSyncGroup *
-pokysync_get_backup_group (PokySyncData *data)
+sync_get_backup_group (SyncData *data)
{
OSyncGroup *group;
OSyncMember *member;
OSyncError *error = NULL;
OSyncConfigurationTypes type = NO_CONFIGURATION;
- group = osync_env_find_group (data->osync, BACKUP_GROUP);
- if (group) return group;
+ if (!sync_clean_backup (data)) {
+ g_warning ("Unable to clear old backup data\n");
+ return NULL;
+ }
group = osync_group_new (data->osync);
osync_group_set_name (group, BACKUP_GROUP);
@@ -49,7 +96,7 @@ pokysync_get_backup_group (PokySyncData *data)
/* Setup File sync member */
member = osync_member_new (group);
- if (!osync_member_instance_plugin (member, BACKUP_PLUGIN, &error)) {
+ if (!osync_member_instance_plugin (member, FILE_PLUGIN, &error)) {
g_warning ("Error instancing file plug-in: %s",
osync_error_print (&error));
osync_error_free (&error);
@@ -74,8 +121,7 @@ pokysync_get_backup_group (PokySyncData *data)
return NULL;
}
- backup_config = g_strdup_printf (
- BACKUP_CONFIG, backup_path);
+ backup_config = g_strdup_printf (FILE_CONFIG, backup_path);
osync_member_set_config (
member, backup_config, strlen (backup_config));
g_free (backup_config);
@@ -93,7 +139,7 @@ pokysync_get_backup_group (PokySyncData *data)
}
static gboolean
-pokysync_sync_animate (PokySyncData *data)
+sync_animate (SyncData *data)
{
static gint direction = 1;
gfloat x, y;
@@ -103,7 +149,6 @@ pokysync_sync_animate (PokySyncData *data)
x += 0.05 * direction;
if ((x > 1) || (x < 0)) {
direction = -direction;
- direction = (gfloat)roundf (direction);
}
gtk_misc_set_alignment (GTK_MISC (widget), x, y);
@@ -124,11 +169,11 @@ OSyncChangeType2String (OSyncChangeType c)
}
static void
-pokysync_conflict_cb (OSyncEngine *engine, OSyncMapping *mapping,
+sync_conflict_cb (OSyncEngine *engine, OSyncMapping *mapping,
void *user_data)
{
GtkWidget *widget;
- PokySyncData *data = (PokySyncData *)user_data;
+ SyncData *data = (SyncData *)user_data;
gdk_threads_enter ();
widget = glade_xml_get_widget (data->xml, "main_notebook");
@@ -139,10 +184,10 @@ pokysync_conflict_cb (OSyncEngine *engine, OSyncMapping *mapping,
}
static void
-pokysync_changestatus_cb (OSyncEngine *engine, OSyncChangeUpdate *status,
+sync_changestatus_cb (OSyncEngine *engine, OSyncChangeUpdate *status,
void *user_data)
{
- PokySyncData *data = (PokySyncData *)user_data;
+ SyncData *data = (SyncData *)user_data;
switch (status->type) {
case CHANGE_RECEIVED_INFO:
@@ -190,9 +235,9 @@ pokysync_changestatus_cb (OSyncEngine *engine, OSyncChangeUpdate *status,
}
static void
-pokysync_mappingstatus_cb (OSyncMappingUpdate *status, void *user_data)
+sync_mappingstatus_cb (OSyncMappingUpdate *status, void *user_data)
{
- PokySyncData *data = (PokySyncData *)user_data;
+ SyncData *data = (SyncData *)user_data;
switch (status->type) {
case MAPPING_SOLVED:
@@ -209,21 +254,23 @@ pokysync_mappingstatus_cb (OSyncMappingUpdate *status, void *user_data)
}
static gboolean
-pokysync_sync_finish_cb (gpointer data)
+sync_finish_cb (gpointer data)
{
OSyncEngine *engine = (OSyncEngine *)data;
g_debug ("Finalizing/freeing sync engine");
osengine_finalize (engine);
osengine_free (engine);
+
+ return FALSE;
}
static void
-pokysync_enginestatus_cb (OSyncEngine *engine, OSyncEngineUpdate *status,
+sync_enginestatus_cb (OSyncEngine *engine, OSyncEngineUpdate *status,
void *user_data)
{
GtkWidget *widget;
- PokySyncData *data = (PokySyncData *)user_data;
+ SyncData *data = (SyncData *)user_data;
switch (status->type) {
case ENG_PREV_UNCLEAN:
@@ -270,13 +317,13 @@ pokysync_enginestatus_cb (OSyncEngine *engine, OSyncEngineUpdate *status,
data->syncing = FALSE;
g_debug ("Setting idle function to clean up engine.");
- g_idle_add (pokysync_sync_finish_cb, engine);
+ g_idle_add (sync_finish_cb, engine);
}
static void
-pokysync_memberstatus_cb (OSyncMemberUpdate *status, void *user_data)
+sync_memberstatus_cb (OSyncMemberUpdate *status, void *user_data)
{
- PokySyncData *data = (PokySyncData *)user_data;
+ SyncData *data = (SyncData *)user_data;
switch (status->type) {
case MEMBER_CONNECTED:
@@ -339,7 +386,7 @@ pokysync_memberstatus_cb (OSyncMemberUpdate *status, void *user_data)
}
static void
-pokysync_backup (PokySyncData *data)
+sync_backup (SyncData *data)
{
OSyncGroup *group;
OSyncEngine *engine;
@@ -348,7 +395,7 @@ pokysync_backup (PokySyncData *data)
widget = glade_xml_get_widget (data->xml, "main_notebook");
- if (!(group = pokysync_get_backup_group (data))) {
+ if (!(group = sync_get_backup_group (data))) {
g_warning ("Unable to retrieve back-up group");
gtk_notebook_set_current_page (
GTK_NOTEBOOK (widget), TAB_ERROR);
@@ -366,15 +413,15 @@ pokysync_backup (PokySyncData *data)
/* osengine_set_message_callback (engine, NULL, NULL);*/
osengine_set_conflict_callback (
- engine, pokysync_conflict_cb, data);
+ engine, sync_conflict_cb, data);
osengine_set_changestatus_callback (
- engine, pokysync_changestatus_cb, data);
+ engine, sync_changestatus_cb, data);
osengine_set_mappingstatus_callback (
- engine, pokysync_mappingstatus_cb, data);
+ engine, sync_mappingstatus_cb, data);
osengine_set_enginestatus_callback (
- engine, pokysync_enginestatus_cb, data);
+ engine, sync_enginestatus_cb, data);
osengine_set_memberstatus_callback (
- engine, pokysync_memberstatus_cb, data);
+ engine, sync_memberstatus_cb, data);
if (!osengine_init (engine, &error)) {
g_warning ("Error while initializing syncengine: %s",
@@ -400,18 +447,18 @@ pokysync_backup (PokySyncData *data)
g_debug ("Started synchronisation...");
data->syncing = TRUE;
data->animate_id = g_timeout_add (
- 100, (GSourceFunc)pokysync_sync_animate, data);
+ 100, (GSourceFunc)sync_animate, data);
}
static gboolean
-pokysync_activate_cursor_item_cb (GtkIconView *iconview, PokySyncData *data)
+sync_activate_cursor_item_cb (GtkIconView *iconview, SyncData *data)
{
return FALSE;
}
static void
-pokysync_item_activated_cb (GtkIconView *iconview, GtkTreePath *arg1,
- PokySyncData *data)
+sync_item_activated_cb (GtkIconView *iconview, GtkTreePath *arg1,
+ SyncData *data)
{
GtkTreeIter iter;
@@ -424,7 +471,7 @@ pokysync_item_activated_cb (GtkIconView *iconview, GtkTreePath *arg1,
/* Special case for back-up item */
if (id == 0) {
g_debug ("Performing backup");
- pokysync_backup (data);
+ sync_backup (data);
return;
}
@@ -432,12 +479,12 @@ pokysync_item_activated_cb (GtkIconView *iconview, GtkTreePath *arg1,
}
static void
-pokysync_sync_button_cb (GtkWidget *source, PokySyncData *data)
+sync_sync_button_cb (GtkWidget *source, SyncData *data)
{
GtkWidget *widget = glade_xml_get_widget (data->xml, "main_iconview");
GList *list = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (widget));
if (list) {
- pokysync_item_activated_cb (GTK_ICON_VIEW (widget),
+ sync_item_activated_cb (GTK_ICON_VIEW (widget),
list->data, data);
g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
g_list_free (list);
@@ -445,7 +492,7 @@ pokysync_sync_button_cb (GtkWidget *source, PokySyncData *data)
}
static void
-pokysync_chooser_cb (GtkWidget *source, PokySyncData *data)
+sync_chooser_cb (GtkWidget *source, SyncData *data)
{
GtkWidget *widget = glade_xml_get_widget (data->xml, "main_notebook");
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), TAB_CHOOSE);
@@ -460,7 +507,7 @@ main (int argc, char **argv)
GtkIconTheme *icon_theme;
gint width = 0, height = 0;
OSyncError *error = NULL;
- PokySyncData data;
+ SyncData data;
gtk_init (&argc, &argv);
glade_init ();
@@ -518,20 +565,20 @@ main (int argc, char **argv)
G_CALLBACK (gtk_main_quit), NULL);
widget = glade_xml_get_widget (data.xml, "main_iconview");
g_signal_connect (G_OBJECT (widget), "activate-cursor-item",
- G_CALLBACK (pokysync_activate_cursor_item_cb), &data);
+ G_CALLBACK (sync_activate_cursor_item_cb), &data);
g_signal_connect (G_OBJECT (widget), "item-activated",
- G_CALLBACK (pokysync_item_activated_cb), &data);
+ G_CALLBACK (sync_item_activated_cb), &data);
widget = glade_xml_get_widget (data.xml, "sync_button");
g_signal_connect (G_OBJECT (widget), "clicked",
- G_CALLBACK (pokysync_sync_button_cb), &data);
+ G_CALLBACK (sync_sync_button_cb), &data);
widget = glade_xml_get_widget (data.xml, "success_close_button");
g_signal_connect (G_OBJECT (widget), "clicked",
- G_CALLBACK (pokysync_chooser_cb), &data);
+ G_CALLBACK (sync_chooser_cb), &data);
widget = glade_xml_get_widget (data.xml, "error_close_button");
g_signal_connect (G_OBJECT (widget), "clicked",
- G_CALLBACK (pokysync_chooser_cb), &data);
+ G_CALLBACK (sync_chooser_cb), &data);
gtk_main ();