summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gtk-ui/sync-config-widget.c163
-rw-r--r--src/gtk-ui/sync-config-widget.h14
-rw-r--r--src/gtk-ui/sync-ui.c146
3 files changed, 213 insertions, 110 deletions
diff --git a/src/gtk-ui/sync-config-widget.c b/src/gtk-ui/sync-config-widget.c
index 8a374e71..caecbfc6 100644
--- a/src/gtk-ui/sync-config-widget.c
+++ b/src/gtk-ui/sync-config-widget.c
@@ -20,6 +20,8 @@ enum
PROP_SERVER,
PROP_NAME,
PROP_CURRENT,
+ PROP_HAS_TEMPLATE,
+ PROP_CONFIGURED,
PROP_UNSET,
};
@@ -219,8 +221,6 @@ use_clicked_cb (GtkButton *btn, SyncConfigWidget *self)
static void
reset_delete_clicked_cb (GtkButton *btn, SyncConfigWidget *self)
{
- const char *name;
-
if (!self->config) {
return;
}
@@ -233,13 +233,22 @@ reset_delete_clicked_cb (GtkButton *btn, SyncConfigWidget *self)
}
-static void
-update_use_button (SyncConfigWidget *self)
+static void update_buttons (SyncConfigWidget *self)
{
- if (!self->use_button){
- return;
+ if (self->has_template) {
+ /* TRANSLATORS: button labels */
+ gtk_button_set_label (GTK_BUTTON (self->reset_delete_button),
+ _("Reset service"));
+ } else {
+ gtk_button_set_label (GTK_BUTTON (self->reset_delete_button),
+ _("Delete service"));
+ if (self->configured) {
+ gtk_widget_show (GTK_WIDGET (self->reset_delete_button));
+ } else {
+ gtk_widget_hide (GTK_WIDGET (self->reset_delete_button));
+ }
}
-
+
if (self->unset || self->current) {
gtk_button_set_label (GTK_BUTTON (self->use_button),
_("Save and use"));
@@ -247,8 +256,13 @@ update_use_button (SyncConfigWidget *self)
gtk_button_set_label (GTK_BUTTON (self->use_button),
_("Save and replace\ncurrent service"));
}
-}
+ if (self->current) {
+ gtk_widget_show (self->stop_button);
+ } else {
+ gtk_widget_hide (self->stop_button);
+ }
+}
static void
init_source (char *name,
@@ -314,26 +328,7 @@ sync_config_widget_update_expander (SyncConfigWidget *self)
/* TODO set expanded status based on user pref? */
- if (self->from_template) {
- /* TRANSLATORS: button labels */
- gtk_button_set_label (GTK_BUTTON (self->reset_delete_button),
- _("Reset service"));
- } else {
- gtk_button_set_label (GTK_BUTTON (self->reset_delete_button),
- _("Delete service"));
- if (self->saved) {
- gtk_widget_show (GTK_WIDGET (self->reset_delete_button));
- } else {
- gtk_widget_hide (GTK_WIDGET (self->reset_delete_button));
- }
- }
-
- if (self->current) {
- gtk_widget_show (self->stop_button);
- } else {
- gtk_widget_hide (self->stop_button);
- }
- update_use_button (self);
+ update_buttons (self);
syncevo_config_get_value (config, NULL, "username", &username);
syncevo_config_get_value (config, NULL, "password", &password);
@@ -459,7 +454,7 @@ sync_config_widget_update_label (SyncConfigWidget *self)
} else {
str = g_strdup_printf ("%s", self->config->name);
}
- if (!self->from_template) {
+ if (!self->has_template) {
/* TRANSLATORS: service title for services that are not based on a
* template in service list, the placeholder is the name of the service */
char *tmp = g_strdup_printf (_("%s - manually setup"), str);
@@ -494,7 +489,7 @@ sync_config_widget_set_unset (SyncConfigWidget *self,
{
self->unset = unset;
- update_use_button (self);
+ update_buttons (self);
}
void
@@ -570,6 +565,8 @@ sync_config_widget_set_server (SyncConfigWidget *self,
/* monitor sessions so we can set editing buttons insensitive */
g_signal_connect (self->server, "session-changed",
G_CALLBACK (session_changed_cb), self);
+
+ /* TODO: this is stupid, every widget running the same dbus call*/
syncevo_server_get_sessions (self->server,
(SyncevoServerGetSessionsCb)get_sessions_cb,
self);
@@ -601,6 +598,12 @@ sync_config_widget_set_property (GObject *object,
case PROP_CURRENT:
sync_config_widget_set_current (self, g_value_get_boolean (value));
break;
+ case PROP_HAS_TEMPLATE:
+ sync_config_widget_set_has_template (self, g_value_get_boolean (value));
+ break;
+ case PROP_CONFIGURED:
+ sync_config_widget_set_configured (self, g_value_get_boolean (value));
+ break;
case PROP_UNSET:
sync_config_widget_set_unset (self, g_value_get_boolean (value));
break;
@@ -627,6 +630,10 @@ sync_config_widget_get_property (GObject *object,
g_value_set_string (value, NULL);
case PROP_CURRENT:
g_value_set_boolean (value, self->current);
+ case PROP_HAS_TEMPLATE:
+ g_value_set_boolean (value, self->has_template);
+ case PROP_CONFIGURED:
+ g_value_set_boolean (value, self->configured);
case PROP_UNSET:
g_value_set_boolean (value, self->unset);
default:
@@ -665,17 +672,12 @@ init_default_config (server_config *config)
static void
sync_config_widget_real_init (SyncConfigWidget *self,
- SyncevoConfig *config,
- gboolean saved)
+ SyncevoConfig *config)
{
char *url, *icon;
GdkPixbuf *buf;
server_config_init (self->config, config);
-/* TODO find out "from_template" value... it seems I need to do two GetConfig calls
- * for each service :( */
- self->from_template = TRUE;
- self->saved = saved;
if (self->config->name &&
strcmp (self->config->name, "default") == 0) {
@@ -708,22 +710,6 @@ sync_config_widget_real_init (SyncConfigWidget *self,
}
static void
-get_template_config_cb (SyncevoServer *syncevo,
- SyncevoConfig *config,
- GError *error,
- SyncConfigWidget *self)
-{
- if (error) {
- g_error_free (error);
-
- /* TODO: decide if there are cases where we want to show this in UI */
- return;
- }
-
- sync_config_widget_real_init (self, config, FALSE);
-}
-
-static void
get_config_cb (SyncevoServer *syncevo,
SyncevoConfig *config,
GError *error,
@@ -732,21 +718,13 @@ get_config_cb (SyncevoServer *syncevo,
char *password, *username, *url;
if (error) {
+ g_warning ("Server.GetConfig failed: %s", error->message);
g_error_free (error);
- /* no configuration was found, ask for a template */
- syncevo_server_get_config (self->server,
- self->config->name,
- TRUE,
- (SyncevoServerGetConfigCb)get_template_config_cb,
- self);
-
- /* TODO: check that this really is a "no such config" error */
- /* TODO: decide if there are cases where we want to show this in UI */
+ /* TODO: show in UI */
return;
}
-
- sync_config_widget_real_init (self, config, TRUE);
+ sync_config_widget_real_init (self, config);
self->keyring_password = NULL;
@@ -801,10 +779,9 @@ sync_config_widget_constructor (GType gtype,
g_warning ("No SyncevoServer set for SyncConfigWidget");
}
- /* try to fetch a already set configuration */
syncevo_server_get_config (self->server,
self->config->name,
- FALSE,
+ self->has_template && !self->configured,
(SyncevoServerGetConfigCb)get_config_cb,
self);
return G_OBJECT (self);
@@ -836,14 +813,28 @@ sync_config_widget_class_init (SyncConfigWidgetClass *klass)
pspec = g_param_spec_boolean ("current",
"Current",
- "Whether the server is currently used",
+ "Whether the service is currently used",
FALSE,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_CURRENT, pspec);
+ pspec = g_param_spec_boolean ("has-template",
+ "has template",
+ "Whether the service has a matching template",
+ FALSE,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_HAS_TEMPLATE, pspec);
+
+ pspec = g_param_spec_boolean ("configured",
+ "Configured",
+ "Whether the service has a configuration already",
+ FALSE,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_CONFIGURED, pspec);
+
pspec = g_param_spec_boolean ("unset",
"Unset",
- "Whether there is a curently used server at all",
+ "Whether there is a currently used service at all",
TRUE,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_UNSET, pspec);
@@ -1039,13 +1030,17 @@ GtkWidget*
sync_config_widget_new (SyncevoServer *server,
const char *name,
gboolean current,
- gboolean unset)
+ gboolean unset,
+ gboolean configured,
+ gboolean has_template)
{
return g_object_new (SYNC_TYPE_CONFIG_WIDGET,
"server", server,
"name", name,
"current", current,
"unset", unset,
+ "configured", configured,
+ "has-template", has_template,
NULL);
}
@@ -1071,6 +1066,38 @@ sync_config_widget_set_expanded (SyncConfigWidget *widget, gboolean expanded)
}
+void
+sync_config_widget_set_has_template (SyncConfigWidget *self, gboolean has_template)
+{
+ if (self->has_template != has_template) {
+ self->has_template = has_template;
+ update_buttons (self);
+ sync_config_widget_update_label (self);
+ }
+}
+
+gboolean
+sync_config_widget_get_has_template (SyncConfigWidget *self)
+{
+ return self->has_template;
+}
+
+void
+sync_config_widget_set_configured (SyncConfigWidget *self, gboolean configured)
+{
+ if (self->configured != configured) {
+ self->configured = configured;
+ update_buttons (self);
+ }
+}
+
+gboolean
+sync_config_widget_get_configured (SyncConfigWidget *self)
+{
+ return self->configured;
+}
+
+
gboolean
sync_config_widget_get_current (SyncConfigWidget *widget)
{
diff --git a/src/gtk-ui/sync-config-widget.h b/src/gtk-ui/sync-config-widget.h
index 876f6ea3..2aeea8ce 100644
--- a/src/gtk-ui/sync-config-widget.h
+++ b/src/gtk-ui/sync-config-widget.h
@@ -41,8 +41,8 @@ typedef struct {
gboolean current; /* is this currently used config */
gboolean unset; /* is there a current config at all */
- gboolean saved; /* this service configuration exists on server */
- gboolean from_template; /* this service configuration has a matching template */
+ gboolean configured; /* actual service configuration exists on server */
+ gboolean has_template; /* this service configuration has a matching template */
SyncevoServer *server;
server_config *config;
@@ -88,13 +88,21 @@ GType sync_config_widget_get_type (void);
GtkWidget *sync_config_widget_new (SyncevoServer *server,
const char *name,
gboolean current,
- gboolean unset);
+ gboolean unset,
+ gboolean configured,
+ gboolean has_template);
void sync_config_widget_set_expanded (SyncConfigWidget *widget, gboolean expanded);
gboolean sync_config_widget_get_current (SyncConfigWidget *widget);
void sync_config_widget_set_current (SyncConfigWidget *self, gboolean current);
+void sync_config_widget_set_has_template (SyncConfigWidget *self, gboolean has_template);
+gboolean sync_config_widget_get_has_template (SyncConfigWidget *self);
+
+void sync_config_widget_set_configured (SyncConfigWidget *self, gboolean configured);
+gboolean sync_config_widget_get_configured (SyncConfigWidget *self);
+
const char *sync_config_widget_get_name (SyncConfigWidget *widget);
G_END_DECLS
diff --git a/src/gtk-ui/sync-ui.c b/src/gtk-ui/sync-ui.c
index 43271474..6ae27cc9 100644
--- a/src/gtk-ui/sync-ui.c
+++ b/src/gtk-ui/sync-ui.c
@@ -356,7 +356,6 @@ sync_clicked_cb (GtkButton *btn, app_data *data)
}
}
-g_debug ("Starting session... ");
syncevo_server_start_session (data->server,
data->current_service->name,
(SyncevoServerStartSessionCb)start_session_cb,
@@ -737,9 +736,6 @@ init_ui (app_data *data)
static void
source_check_toggled_cb (GtkCheckButton *check, app_data *data)
{
- GPtrArray *options;
- gboolean *enabled;
-
/* TODO: save to syncevolution config
NOTE the check has source name as data (g_object_set_data)
*/
@@ -870,8 +866,7 @@ check_source_cb (SyncevoSession *session,
static void
update_service_ui (app_data *data)
{
- const char *icon_uri;
- GList *l;
+ char *icon_uri;
g_assert (data->current_service && data->current_service->config);
@@ -911,15 +906,6 @@ unexpand_config_widget (GtkWidget *w, GtkWidget *exception)
}
static void
-config_widget_removed_cb (GtkWidget *widget, app_data *data)
-{
- if (sync_config_widget_get_current (SYNC_CONFIG_WIDGET (widget))) {
- save_gconf_settings (data, NULL);
- }
- gtk_container_remove (GTK_CONTAINER (data->services_box), widget);
-}
-
-static void
config_widget_expanded_cb (GtkWidget *widget, app_data *data)
{
gtk_container_foreach (GTK_CONTAINER (data->services_box),
@@ -940,7 +926,11 @@ config_widget_changed_cb (GtkWidget *widget, app_data *data)
}
static GtkWidget*
-add_server_to_box (GtkBox *box, const char *name, app_data *data)
+add_server_to_box (GtkBox *box,
+ const char *name,
+ gboolean configured,
+ gboolean has_template,
+ app_data *data)
{
GtkWidget *item = NULL;
gboolean current = FALSE;
@@ -952,7 +942,8 @@ add_server_to_box (GtkBox *box, const char *name, app_data *data)
}
unset = !data->current_service;
- item = sync_config_widget_new (data->server, name, current, unset);
+ item = sync_config_widget_new (data->server, name,
+ current, unset, configured, has_template);
g_signal_connect (item, "changed",
G_CALLBACK (config_widget_changed_cb), data);
g_signal_connect (item, "expanded",
@@ -966,8 +957,6 @@ add_server_to_box (GtkBox *box, const char *name, app_data *data)
data->open_current = FALSE;
}
-/* TODO: only show item if consumer_ready */
-
return item;
}
@@ -984,6 +973,7 @@ setup_new_service_clicked (GtkButton *btn, app_data *data)
widget = add_server_to_box (GTK_BOX (data->services_box),
"default",
+ FALSE, TRUE,
data);
sync_config_widget_set_expanded (SYNC_CONFIG_WIDGET (widget), TRUE);
@@ -991,31 +981,113 @@ setup_new_service_clicked (GtkButton *btn, app_data *data)
* so there is no need to wait here... */
}
+
+typedef struct templates_data {
+ app_data *data;
+ char **templates;
+} templates_data;
+
+static void
+get_configs_cb (SyncevoServer *server,
+ char **configs,
+ GError *error,
+ templates_data *templ_data)
+{
+ char **config_iter, **template_iter, **templates;
+ app_data *data;
+ GtkWidget *widget;
+
+ templates = templ_data->templates;
+ data = templ_data->data;
+ g_slice_free (templates_data, templ_data);
+
+ if (error) {
+ show_main_view (data);
+ show_error_dialog (data->sync_win,
+ _("Failed to get list of configured services from SyncEvolution"));
+ g_warning ("Server.GetConfigs() failed: %s", error->message);
+ g_strfreev (templates);
+ g_error_free (error);
+ return;
+ }
+
+ for (template_iter = templates; *template_iter; *template_iter++){
+ gboolean found_config = FALSE;
+
+ for (config_iter = configs; *config_iter; *config_iter++) {
+ if (*template_iter &&
+ *config_iter &&
+ g_ascii_strncasecmp (*template_iter,
+ *config_iter,
+ strlen (*config_iter)) == 0) {
+
+ widget = add_server_to_box (GTK_BOX (data->services_box),
+ *config_iter,
+ TRUE, TRUE,
+ data);
+ found_config = TRUE;
+ break;
+ }
+ }
+ if (!found_config) {
+ widget = add_server_to_box (GTK_BOX (data->services_box),
+ *template_iter,
+ FALSE, TRUE,
+ data);
+ }
+ }
+
+ for (config_iter = configs; *config_iter; *config_iter++) {
+ gboolean found_template = FALSE;
+
+ for (template_iter = templates; *template_iter; *template_iter++) {
+ if (*template_iter &&
+ *config_iter &&
+ g_ascii_strncasecmp (*template_iter,
+ *config_iter,
+ strlen (*config_iter)) == 0) {
+
+ found_template = TRUE;
+ break;
+ }
+ }
+ if (!found_template) {
+ widget = add_server_to_box (GTK_BOX (data->services_box),
+ *config_iter,
+ TRUE, FALSE,
+ data);
+ }
+ }
+
+ g_strfreev (configs);
+ g_strfreev (templates);
+}
+
static void
get_template_configs_cb (SyncevoServer *server,
char **templates,
GError *error,
app_data *data)
{
- char **str;
- GtkWidget *widget;
+ templates_data *templ_data;
if (error) {
show_main_view (data);
show_error_dialog (data->sync_win,
_("Failed to get list of supported services from SyncEvolution"));
- g_warning ("Failed to get list of supported services from SyncEvolution: %s",
- error->message);
+ g_warning ("Server.GetConfigs() failed: %s", error->message);
g_error_free (error);
return;
}
- for (str = templates; *str; *str++){
- widget = add_server_to_box (GTK_BOX (data->services_box),
- *str,
- data);
- }
- g_strfreev (templates);
+ templ_data = g_slice_new (templates_data);
+ templ_data->data = data;
+ templ_data->templates = templates;
+
+ syncevo_server_get_configs (data->server,
+ FALSE,
+ (SyncevoServerGetConfigsCb)get_configs_cb,
+ templ_data);
}
static void
@@ -1032,8 +1104,6 @@ update_services_list (app_data *data)
TRUE,
(SyncevoServerGetConfigsCb)get_template_configs_cb,
data);
-
-
}
static void
@@ -1326,7 +1396,6 @@ sync (app_data *data, SyncevoSession *session)
}
}
- g_debug ("Syncing...");
syncevo_session_sync (session,
data->mode,
source_modes,
@@ -1345,7 +1414,7 @@ status_changed_cb (SyncevoSession *session,
{
GTimeVal val;
- g_debug ("active session status changed -> %d", status);
+ g_debug ("sync session status changed -> %d", status);
switch (status) {
case SYNCEVO_STATUS_IDLE:
/* time for business */
@@ -1365,10 +1434,10 @@ status_changed_cb (SyncevoSession *session,
/* refresh stats -- the service may no longer be the one syncing,
* but what the heck... */
syncevo_server_get_reports (data->server,
- data->current_service->name,
- 0, 1,
- (SyncevoSessionGetReportsCb)get_reports_cb,
- data);
+ data->current_service->name,
+ 0, 1,
+ (SyncevoServerGetReportsCb)get_reports_cb,
+ data);
default:
;
}
@@ -1389,7 +1458,7 @@ get_status_cb (SyncevoSession *session,
return;
}
- g_debug ("active session status is %d", status);
+ g_debug ("sync session status is %d", status);
if (status == SYNCEVO_STATUS_IDLE) {
/* time for business */
sync (data, session);
@@ -1428,7 +1497,6 @@ start_session_cb (SyncevoServer *server,
syncevo_session_get_status (session,
(SyncevoSessionGetStatusCb)get_status_cb,
data);
-g_debug ("Session started");
}
static void