gtk-ui: add forgotten files

This commit is contained in:
Jussi Kukkonen 2009-09-30 14:54:49 +03:00
parent cf9896de6f
commit e87e2d33b8
5 changed files with 257 additions and 597 deletions

View file

@ -1,406 +0,0 @@
#include "config.h"
#ifndef USE_MOBLIN_UX
#include <glib/gi18n.h>
#include <gnome-keyring.h>
#include "sync-ui.h"
#include "sync-config-widget.h"
#include "sync-config-widget-gtk.h"
G_DEFINE_TYPE (SyncConfigWidgetGtk, sync_config_widget_gtk, GTK_TYPE_HBOX)
enum
{
PROP_0,
PROP_SERVER,
PROP_CURRENT,
PROP_DBUS_SERVICE,
};
static void
sync_config_widget_gtk_set_config (SyncConfigWidgetGtk *self,
server_config *config)
{
if (self->config)
server_config_free (self->config);
self->config = config;
}
static void
find_password_for_settings_cb (GnomeKeyringResult result, GList *list, server_data *data)
{
switch (result) {
case GNOME_KEYRING_RESULT_NO_MATCH:
g_warning ("no password found in keyring");
break;
case GNOME_KEYRING_RESULT_OK:
if (list && list->data) {
GnomeKeyringNetworkPasswordData *key_data;
key_data = (GnomeKeyringNetworkPasswordData*)list->data;
data->config->password = g_strdup (key_data->password);
}
break;
default:
g_warning ("getting password from GNOME keyring failed: %s",
gnome_keyring_result_to_message (result));
break;
}
sync_config_widget_gtk_set_config (SYNC_CONFIG_WIDGET_GTK (data->data), data->config);
server_data_free (data, FALSE);
return;
}
static void
get_server_config_for_template_cb (SyncevoService *service, GPtrArray *options, GError *error, server_data *data)
{
gboolean getting_password = FALSE;
if (error) {
g_warning ("Failed to get service configuration from SyncEvolution: %s",
error->message);
g_error_free (error);
server_data_free (data, TRUE);
} else {
char *server_address;
g_ptr_array_foreach (options, (GFunc)add_server_option, data->config);
if (data->options_override)
g_ptr_array_foreach (data->options_override, (GFunc)add_server_option, data->config);
server_config_ensure_default_sources_exist (data->config);
data->config->changed = TRUE;
/* get password from keyring if we have an url */
if (data->config->base_url) {
server_address = strstr (data->config->base_url, "://");
if (server_address)
server_address = server_address + 3;
if (!server_address) {
g_warning ("Server configuration has suspect URL '%s'",
data->config->base_url);
} else {
gnome_keyring_find_network_password (data->config->username,
NULL,
server_address,
NULL,
NULL,
NULL,
0,
(GnomeKeyringOperationGetListCallback)find_password_for_settings_cb,
data,
NULL);
getting_password = TRUE;
}
}
if (!getting_password) {
sync_config_widget_gtk_set_config (SYNC_CONFIG_WIDGET_GTK (data->data),
data->config);
server_data_free (data, FALSE);
}
if (options) {
g_ptr_array_foreach (options, (GFunc)syncevo_option_free, NULL);
g_ptr_array_free (options, TRUE);
}
}
}
static void
fetch_server_config (SyncConfigWidgetGtk *self)
{
const char *name;
if (!self->server || !self->dbus_service) {
return;
}
syncevo_server_get (self->server, &name, NULL, NULL, NULL);
syncevo_service_get_server_config_async (self->dbus_service,
(char*)name,
(SyncevoGetServerConfigCb)get_server_config_for_template_cb,
server_data_new (name, (gpointer)self));
}
static void
setup_service_clicked (GtkButton *btn, SyncConfigWidgetGtk *self)
{
show_settings_window (hack_data, self->config);
}
static GdkPixbuf*
load_icon (const char *uri, guint icon_size)
{
GError *error = NULL;
GdkPixbuf *pixbuf;
const char *filename;
if (uri && strlen (uri) > 0) {
if (g_str_has_prefix (uri, "file://")) {
filename = uri+7;
} else {
g_warning ("only file:// icon uri is supported: %s", uri);
filename = THEMEDIR "sync-generic.png";
}
} else {
filename = THEMEDIR "sync-generic.png";
}
pixbuf = gdk_pixbuf_new_from_file_at_scale (filename,
icon_size, icon_size,
TRUE, &error);
if (!pixbuf) {
g_warning ("Failed to load service icon: %s", error->message);
g_error_free (error);
return NULL;
}
return pixbuf;
}
static void
update_label (SyncConfigWidgetGtk *self)
{
if (self->server) {
const char *name, *url;
char *str;
syncevo_server_get (self->server, &name, &url, NULL, NULL);
if (self->current) {
str = g_strdup_printf ("<b>%s</b>", name);
} else {
str = g_strdup_printf ("%s", name);
}
if (url && strlen (url) > 0) {
char *tmp = g_strdup_printf ("%s -",str);
g_free (str);
str = tmp;
}
gtk_label_set_markup (GTK_LABEL (self->label), str);
g_free (str);
}
}
void
sync_config_widget_gtk_set_dbus_service (SyncConfigWidgetGtk *self,
SyncevoService *dbus_service)
{
self->dbus_service = dbus_service;
fetch_server_config (self);
}
void
sync_config_widget_gtk_set_current (SyncConfigWidgetGtk *self,
gboolean current)
{
self->current = current;
update_label (self);
}
void
sync_config_widget_gtk_set_server (SyncConfigWidgetGtk *self,
SyncevoServer *server)
{
if (self->server) {
syncevo_server_free (self->server);
self->server = NULL;
}
if (!server && !self->server) {
return;
}
self->server = server;
if (!server) {
g_debug (" 1 %d", (int)self);
gtk_image_clear (GTK_IMAGE (self->image));
g_debug ("...1");
gtk_label_set_markup (GTK_LABEL (self->label), "");
gtk_widget_hide (self->link);
} else {
const char *url, *icon;
GdkPixbuf *buf;
syncevo_server_get (server, NULL, &url, &icon, NULL);
buf = load_icon (icon, SYNC_UI_LIST_ICON_SIZE);
gtk_image_set_from_pixbuf (GTK_IMAGE (self->image), buf);
g_object_unref (buf);
update_label (self);
if (url && strlen (url) > 0) {
gtk_link_button_set_uri (GTK_LINK_BUTTON (self->link), url);
gtk_widget_show (self->link);
} else {
gtk_widget_hide (self->link);
}
fetch_server_config (self);
}
}
static void
sync_config_widget_gtk_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
SyncConfigWidgetGtk *self = SYNC_CONFIG_WIDGET_GTK (object);
switch (property_id) {
case PROP_SERVER:
sync_config_widget_gtk_set_server (self, g_value_get_pointer (value));
break;
case PROP_CURRENT:
sync_config_widget_gtk_set_current (self, g_value_get_boolean (value));
break;
case PROP_DBUS_SERVICE:
sync_config_widget_gtk_set_dbus_service (self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
sync_config_widget_gtk_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
SyncConfigWidgetGtk *self = SYNC_CONFIG_WIDGET_GTK (object);
switch (property_id) {
case PROP_SERVER:
g_value_set_pointer (value, self->server);
case PROP_CURRENT:
g_value_set_boolean (value, self->current);
case PROP_DBUS_SERVICE:
g_value_set_object (value, self->dbus_service);
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
sync_config_widget_gtk_dispose (GObject *object)
{
SyncConfigWidgetGtk *self = SYNC_CONFIG_WIDGET_GTK (object);
sync_config_widget_gtk_set_server (self, NULL);
G_OBJECT_CLASS (sync_config_widget_gtk_parent_class)->dispose (object);
}
static void
sync_config_widget_gtk_class_init (SyncConfigWidgetGtkClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
object_class->set_property = sync_config_widget_gtk_set_property;
object_class->get_property = sync_config_widget_gtk_get_property;
object_class->dispose = sync_config_widget_gtk_dispose;
pspec = g_param_spec_pointer ("server",
"SyncevoServer",
"The SyncevoServer struct this widget represents",
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_SERVER, pspec);
pspec = g_param_spec_boolean ("current",
"Current",
"Whether the server is currently used",
FALSE,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_CURRENT, pspec);
pspec = g_param_spec_object ("dbus-service",
"DBus service",
"The SyncevoService DBus wrapper object",
SYNCEVO_TYPE_SERVICE,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_DBUS_SERVICE, pspec);
}
static void
sync_config_widget_gtk_init (SyncConfigWidgetGtk *self)
{
GtkWidget *tmp_box, *hbox, *vbox;
hbox = gtk_hbox_new (FALSE, 8);
gtk_widget_set_size_request (hbox, -1, SYNC_UI_LIST_ICON_SIZE + 6);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (self), hbox, TRUE, TRUE, 0);
self->image = gtk_image_new ();
gtk_widget_set_size_request (self->image,
SYNC_UI_LIST_ICON_SIZE,
SYNC_UI_LIST_ICON_SIZE);
gtk_widget_show (self->image);
gtk_box_pack_start (GTK_BOX (hbox), self->image, FALSE, FALSE, 0);
tmp_box = gtk_hbox_new (FALSE, 0);
gtk_widget_show (tmp_box);
gtk_box_pack_start (GTK_BOX (hbox), tmp_box, FALSE, FALSE, 0);
self->label = gtk_label_new ("");
gtk_misc_set_alignment (GTK_MISC (self->label), 0.0, 0.5);
gtk_widget_show (self->label);
gtk_box_pack_start (GTK_BOX (tmp_box), self->label, FALSE, FALSE, 0);
vbox = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox);
gtk_box_pack_start (GTK_BOX (tmp_box), vbox, FALSE, FALSE, 0);
self->link = gtk_link_button_new_with_label ("", _("Launch website"));
gtk_widget_set_no_show_all (self->link, TRUE);
gtk_box_pack_start (GTK_BOX (vbox), self->link, TRUE, FALSE, 0);
vbox = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox);
gtk_box_pack_end (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
self->button = gtk_button_new_with_label (_("Setup now"));
gtk_widget_set_size_request (self->button, SYNC_UI_LIST_BTN_WIDTH, -1);
g_signal_connect (self->button, "clicked",
G_CALLBACK (setup_service_clicked), self);
gtk_widget_show (self->button);
gtk_box_pack_start (GTK_BOX (vbox), self->button, TRUE, FALSE, 0);
}
GtkWidget*
sync_config_widget_new (SyncevoServer *server,
gboolean current,
SyncevoService *dbus_service)
{
return g_object_new (SYNC_TYPE_CONFIG_WIDGET_GTK,
"server", server,
"current", current,
"dbus_service", dbus_service,
NULL);
}
#endif

View file

@ -1,59 +0,0 @@
#ifndef _SYNC_CONFIG_WIDGET_GTK
#define _SYNC_CONFIG_WIDGET_GTK
#ifndef USE_MOBLIN_UX
#include <glib-object.h>
#include <gtk/gtk.h>
#include "syncevo-dbus.h"
#include "sync-ui-config.h"
G_BEGIN_DECLS
#define SYNC_TYPE_CONFIG_WIDGET_GTK sync_config_widget_gtk_get_type()
#define SYNC_CONFIG_WIDGET_GTK(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), SYNC_TYPE_CONFIG_WIDGET_GTK, SyncConfigWidgetGtk))
#define SYNC_CONFIG_WIDGET_GTK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), SYNC_TYPE_CONFIG_WIDGET_GTK, SyncConfigWidgetGtkClass))
#define SYNC_IS_CONFIG_WIDGET_GTK(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), SYNC_TYPE_CONFIG_WIDGET_GTK))
#define SYNC_IS_CONFIG_WIDGET_GTK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), SYNC_TYPE_CONFIG_WIDGET_GTK))
#define SYNC_CONFIG_WIDGET_GTK_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), SYNC_TYPE_CONFIG_WIDGET_GTK, SyncConfigWidgetGtkClass))
typedef struct {
GtkHBox parent;
SyncevoService *dbus_service;
gboolean current;
SyncevoServer *server;
server_config *config;
GtkWidget *image;
GtkWidget *label;
GtkWidget *link;
GtkWidget *button;
} SyncConfigWidgetGtk;
typedef struct {
GtkHBoxClass parent_class;
} SyncConfigWidgetGtkClass;
GType sync_config_widget_gtk_get_type (void);
G_END_DECLS
#endif
#endif

View file

@ -1,84 +0,0 @@
#ifndef _SYNC_CONFIG_WIDGET
#define _SYNC_CONFIG_WIDGET
#include <glib-object.h>
#ifdef USE_MOBLIN_UX
#include <nbtk/nbtk-gtk.h>
#else
#include <gtk/gtk.h>
#endif
#include "syncevo-dbus.h"
#include "sync-ui-config.h"
G_BEGIN_DECLS
#define SYNC_TYPE_CONFIG_WIDGET sync_config_widget_get_type()
#define SYNC_CONFIG_WIDGET(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), SYNC_TYPE_CONFIG_WIDGET, SyncConfigWidget))
#define SYNC_CONFIG_WIDGET_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), SYNC_TYPE_CONFIG_WIDGET, SyncConfigWidgetClass))
#define SYNC_IS_CONFIG_WIDGET(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), SYNC_TYPE_CONFIG_WIDGET))
#define SYNC_IS_CONFIG_WIDGET_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), SYNC_TYPE_CONFIG_WIDGET))
#define SYNC_CONFIG_WIDGET_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), SYNC_TYPE_CONFIG_WIDGET, SyncConfigWidgetClass))
typedef struct {
#ifdef USE_MOBLIN_UX
NbtkGtkExpander parent;
#else
GtkVBox parent;
GtkWidget *expando_box_for_gtk;
#endif
SyncevoService *dbus_service;
gboolean current;
SyncevoServer *server;
server_config *config;
GPtrArray *options_override;
/* label */
GtkWidget *image;
GtkWidget *label;
GtkWidget *entry;
GtkWidget *link;
GtkWidget *button;
/* content */
GtkWidget *description_label;
GtkWidget *name_label;
GtkWidget *name_entry;
GtkWidget *username_entry;
GtkWidget *password_entry;
GtkWidget *expander;
GtkWidget *server_settings_table;
GtkWidget *reset_delete_button;
GtkWidget *use_button;
GList *uri_entries;
} SyncConfigWidget;
typedef struct {
#ifdef USE_MOBLIN_UX
NbtkGtkExpanderClass parent_class;
#else
GtkVBoxClass parent_class;
#endif
} SyncConfigWidgetClass;
GType sync_config_widget_get_type (void);
GtkWidget *sync_config_widget_new (SyncevoServer *server, gboolean current, SyncevoService *dbus_service);
G_END_DECLS
#endif

View file

@ -5,7 +5,6 @@
#include "sync-ui.h"
#include "sync-config-widget.h"
#include "sync-config-widget-moblin.h"
#ifdef USE_MOBLIN_UX
@ -23,24 +22,58 @@ enum
PROP_DBUS_SERVICE,
};
enum {
SIGNAL_REMOVED,
SIGNAL_EXPANDED,
LAST_SIGNAL
};
static guint32 signals[LAST_SIGNAL] = {0, };
static void get_server_config_for_template_cb (SyncevoService *service, GPtrArray *options, GError *error, SyncConfigWidget *self);
static void
show_error_dialog (SyncConfigWidget *self, const char* message)
{
GtkWindow *window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)));
GtkWidget *w;
w = gtk_message_dialog_new (window,
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"%s",
message);
gtk_dialog_run (GTK_DIALOG (w));
gtk_widget_destroy (w);
}
static void
remove_child (GtkWidget *widget, GtkContainer *container)
{
gtk_container_remove (container, widget);
}
static void
sync_config_widget_close_expander (SyncConfigWidget *self)
const char*
get_service_description (const char *service)
{
gtk_widget_show (self->button);
if (!service)
return "";
#ifdef USE_MOBLIN_UX
nbtk_gtk_expander_set_expanded (NBTK_GTK_EXPANDER (self), FALSE);
#else
gtk_widget_hide (self->expando_box_for_gtk);
#endif
if (strcmp (service, "ScheduleWorld") == 0) {
return _("ScheduleWorld enables you to keep your contacts, events, "
"tasks, and notes in sync.");
}else if (strcmp (service, "Google") == 0) {
return _("Google Sync can backup and synchronize your Address Book "
"with your Gmail contacts.");
}else if (strcmp (service, "Funambol") == 0) {
/* TRANSLATORS: Please include the word "demo" (or the equivalent in
your language): Funambol is going to be a 90 day demo service
in the future */
return _("Backup your contacts and calendar. Sync with a single"
"click, anytime, anywhere (DEMO).");
}
return "";
}
static void
@ -55,6 +88,91 @@ remove_server_config_cb (SyncevoService *service,
}
}
static gboolean
update_value (char **str, GtkWidget *entry)
{
const char *new_str;
new_str = gtk_entry_get_text (GTK_ENTRY (entry));
if ((*str == NULL && strlen (new_str) != 0) ||
(*str != NULL && strcmp (*str, new_str) != 0)) {
g_free (*str);
*str = g_strdup (new_str);
return TRUE;
}
return FALSE;
}
static void
stop_clicked_cb (GtkButton *btn, SyncConfigWidget *self)
{
sync_config_widget_set_current (self, FALSE);
}
static void
use_clicked_cb (GtkButton *btn, SyncConfigWidget *self)
{
server_config *config;
GList *l, *entry;
if (!self->server || !self->dbus_service) {
return;
}
config = self->config;
/* compare config and stuff in entries... */
if (update_value (&config->name, self->entry))
self->changed = TRUE;
if (update_value (&config->username, self->username_entry))
self->changed = self->auth_changed = TRUE;
if (update_value (&config->password, self->password_entry))
self->changed = self->auth_changed = TRUE;
if (update_value (&config->base_url, self->baseurl_entry))
self->changed = self->auth_changed = TRUE;
entry = self->uri_entries;
for (l = self->config->source_configs; l && entry; l = l->next) {
char *uri = ((source_config*)l->data)->uri;
if (update_value (&uri, GTK_WIDGET (entry->data))) {
self->changed = TRUE;
}
entry = entry->next;
}
if (!config->name || strlen (config->name) == 0 ||
!config->base_url || strlen (config->base_url) == 0) {
show_error_dialog (self,
_("Service must have a name and server URL"));
/* TODO should save the info on change status ...*/
return;
}
/* make a wild guess if no scheme in url */
if (strstr (config->base_url, "://") == NULL) {
char *tmp = g_strdup_printf ("http://%s", config->base_url);
g_free (config->base_url);
config->base_url = tmp;
}
/* TODO save password in keyring if auth_changed */
/* TODO save config if changed */
/* TODO save gconf -> triggers current service change -> triggers list update */
sync_config_widget_set_current (self, TRUE);
}
static void
reset_delete_clicked_cb (GtkButton *btn, SyncConfigWidget *self)
{
@ -77,8 +195,7 @@ reset_delete_clicked_cb (GtkButton *btn, SyncConfigWidget *self)
(SyncevoRemoveServerConfigCb)remove_server_config_cb,
self);
/* TODO let main know so it can remove me and
save_gconf_settings(appdata, NULL) if I'm current */
g_signal_emit (self, signals[SIGNAL_REMOVED], 0);
}
}
@ -101,18 +218,16 @@ sync_config_widget_update_expander (SyncConfigWidget *self)
self->config->name ? self->config->name : "");
if (self->config->name) {
gtk_widget_show (self->label);
gtk_widget_hide (self->entry);
} else {
gtk_widget_show (self->entry);
gtk_widget_hide (self->label);
}
gtk_label_set_text (GTK_LABEL (self->description_label),
get_service_description (self->config->name));
gtk_expander_set_expanded (GTK_EXPANDER (self->expander),
!self->config->from_template);
!self->config->name);
if (self->config->from_template) {
gtk_button_set_label (GTK_BUTTON (self->reset_delete_button),
@ -128,11 +243,9 @@ sync_config_widget_update_expander (SyncConfigWidget *self)
}
if (self->current) {
gtk_button_set_label (GTK_BUTTON (self->use_button),
_("Stop using service"));
gtk_widget_show (self->stop_button);
} else {
gtk_button_set_label (GTK_BUTTON (self->use_button),
_("Save and use"));
gtk_widget_hide (self->stop_button);
}
if (self->config->username &&
@ -152,13 +265,14 @@ sync_config_widget_update_expander (SyncConfigWidget *self)
gtk_table_attach (GTK_TABLE (self->server_settings_table), label,
0, 1, i, i + 1, GTK_FILL, GTK_EXPAND, 0, 0);
entry = gtk_entry_new ();
gtk_entry_set_max_length (GTK_ENTRY (entry), 99);
gtk_entry_set_width_chars (GTK_ENTRY (entry), 80);
gtk_entry_set_text (GTK_ENTRY (entry),
self->baseurl_entry = gtk_entry_new ();
gtk_entry_set_max_length (GTK_ENTRY (self->baseurl_entry), 99);
gtk_entry_set_width_chars (GTK_ENTRY (self->baseurl_entry), 80);
gtk_entry_set_text (GTK_ENTRY (self->baseurl_entry),
self->config->base_url ? self->config->base_url : "");
gtk_widget_show (entry);
gtk_table_attach_defaults (GTK_TABLE (self->server_settings_table), entry,
gtk_widget_show (self->baseurl_entry);
gtk_table_attach_defaults (GTK_TABLE (self->server_settings_table),
self->baseurl_entry,
1, 2, i, i + 1);
g_list_free (self->uri_entries);
@ -192,6 +306,8 @@ sync_config_widget_update_expander (SyncConfigWidget *self)
1, 2, i, i + 1);
}
/* hack for widgets added with "add new service" */
gtk_widget_grab_focus (GTK_WIDGET (self));
}
static void
@ -216,7 +332,7 @@ sync_config_widget_set_config (SyncConfigWidget *self,
g_ptr_array_foreach (options_override, (GFunc)add_server_option, self->config);
server_config_ensure_default_sources_exist (self->config);
self->config->changed = TRUE;
}
@ -254,8 +370,7 @@ get_server_config_for_template_cb (SyncevoService *service, GPtrArray *options,
} else {
char *server_address;
sync_config_widget_set_config (self,
options, self->options_override);
sync_config_widget_set_config (self, options, self->options_override);
sync_config_widget_update_expander (self);
/* get password from keyring if we have an url */
@ -303,6 +418,36 @@ fetch_server_config (SyncConfigWidget *self)
}
syncevo_server_get (self->server, &name, NULL, NULL, NULL);
if (!name) {
/* get a fresh template */
name = "default";
SyncevoOption *option;
self->options_override = g_ptr_array_new ();
/* syncevolution defaults are not empty, override ... */
self->options_override = g_ptr_array_new ();
option = syncevo_option_new (NULL, "username", NULL);
g_ptr_array_add (self->options_override, option);
option = syncevo_option_new (NULL, "password", NULL);
g_ptr_array_add (self->options_override, option);
option = syncevo_option_new (NULL, "syncURL", NULL);
g_ptr_array_add (self->options_override, option);
option = syncevo_option_new (NULL, "webURL", NULL);
g_ptr_array_add (self->options_override, option);
option = syncevo_option_new (NULL, "fromTemplate", "no");
g_ptr_array_add (self->options_override, option);
option = syncevo_option_new ("memo", "uri", NULL);
g_ptr_array_add (self->options_override, option);
option = syncevo_option_new ("todo", "uri", NULL);
g_ptr_array_add (self->options_override, option);
option = syncevo_option_new ("addressbook", "uri", NULL);
g_ptr_array_add (self->options_override, option);
option = syncevo_option_new ("calendar", "uri", NULL);
g_ptr_array_add (self->options_override, option);
}
syncevo_service_get_server_config_async (self->dbus_service,
(char*)name,
(SyncevoGetServerConfigCb)get_server_config_for_template_cb,
@ -312,13 +457,7 @@ fetch_server_config (SyncConfigWidget *self)
static void
setup_service_clicked (GtkButton *btn, SyncConfigWidget *self)
{
#ifdef USE_MOBLIN_UX
nbtk_gtk_expander_set_expanded (NBTK_GTK_EXPANDER (self), TRUE);
#else
gtk_widget_show (self->expando_box_for_gtk);
#endif
gtk_widget_hide (self->button);
sync_config_widget_set_expanded (self, TRUE);
}
static GdkPixbuf*
@ -359,15 +498,19 @@ update_label (SyncConfigWidget *self)
char *str;
syncevo_server_get (self->server, &name, &url, NULL, NULL);
if (self->current) {
str = g_strdup_printf ("<b>%s</b>", name);
if (name) {
if (self->current) {
str = g_strdup_printf ("<b>%s</b>", name);
} else {
str = g_strdup_printf ("%s", name);
}
if (url && strlen (url) > 0) {
char *tmp = g_strdup_printf ("%s -",str);
g_free (str);
str = tmp;
}
} else {
str = g_strdup_printf ("%s", name);
}
if (url && strlen (url) > 0) {
char *tmp = g_strdup_printf ("%s -",str);
g_free (str);
str = tmp;
str = g_strdup ("Server name");
}
gtk_label_set_markup (GTK_LABEL (self->label), str);
g_free (str);
@ -388,9 +531,11 @@ void
sync_config_widget_set_current (SyncConfigWidget *self,
gboolean current)
{
self->current = current;
update_label (self);
if (self->current != current) {
self->current = current;
update_label (self);
g_object_notify (G_OBJECT (self), "current");
}
}
void
@ -518,6 +663,25 @@ sync_config_widget_class_init (SyncConfigWidgetClass *klass)
SYNCEVO_TYPE_SERVICE,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_DBUS_SERVICE, pspec);
signals[SIGNAL_REMOVED] =
g_signal_new ("removed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
G_STRUCT_OFFSET (SyncConfigWidgetClass, removed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
signals[SIGNAL_EXPANDED] =
g_signal_new ("expanded",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
G_STRUCT_OFFSET (SyncConfigWidgetClass, expanded),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
}
static void
@ -547,7 +711,7 @@ sync_config_widget_init (SyncConfigWidget *self)
self->entry = gtk_entry_new ();
gtk_widget_set_no_show_all (self->entry, TRUE);
gtk_box_pack_start (GTK_BOX (tmp_box), self->entry, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (tmp_box), self->entry, FALSE, FALSE, 4);
vbox = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox);
@ -659,9 +823,22 @@ sync_config_widget_init (SyncConfigWidget *self)
gtk_widget_show (tmp_box);
gtk_box_pack_start (GTK_BOX (vbox), tmp_box, FALSE, FALSE, 8);
self->use_button = gtk_button_new ();
self->use_button = gtk_button_new_with_label ("Save and use");
gtk_widget_show (self->use_button);
gtk_box_pack_end (GTK_BOX (tmp_box), self->use_button, FALSE, FALSE, 8);
g_signal_connect (self->use_button, "clicked",
G_CALLBACK (use_clicked_cb), self);
self->stop_button = gtk_button_new ();
gtk_box_pack_end (GTK_BOX (tmp_box), self->stop_button, FALSE, FALSE, 8);
g_signal_connect (self->stop_button, "clicked",
G_CALLBACK (stop_clicked_cb), self);
self->stop_button = gtk_button_new ();
gtk_widget_show (self->use_button);
gtk_box_pack_end (GTK_BOX (tmp_box), self->use_button, FALSE, FALSE, 8);
g_signal_connect (self->use_button, "clicked",
G_CALLBACK (use_clicked_cb), self);
self->reset_delete_button = gtk_button_new ();
gtk_widget_show (self->reset_delete_button);
@ -676,10 +853,37 @@ sync_config_widget_new (SyncevoServer *server,
gboolean current,
SyncevoService *dbus_service)
{
return g_object_new (SYNC_TYPE_CONFIG_WIDGET_MOBLIN,
return g_object_new (SYNC_TYPE_CONFIG_WIDGET,
"server", server,
"current", current,
"dbus_service", dbus_service,
NULL);
}
void
sync_config_widget_set_expanded (SyncConfigWidget *widget, gboolean expanded)
{
if (expanded) {
gtk_widget_hide (widget->button);
#ifdef USE_MOBLIN_UX
nbtk_gtk_expander_set_expanded (NBTK_GTK_EXPANDER (widget), TRUE);
#else
gtk_widget_show (widget->expando_box_for_gtk);
#endif
g_signal_emit (widget, signals[SIGNAL_EXPANDED], 0);
} else {
gtk_widget_show (widget->button);
#ifdef USE_MOBLIN_UX
nbtk_gtk_expander_set_expanded (NBTK_GTK_EXPANDER (widget), FALSE);
#else
gtk_widget_hide (widget->expando_box_for_gtk);
#endif
}
}
gboolean
sync_config_widget_get_current (SyncConfigWidget *widget)
{
return widget->current;
}

View file

@ -46,6 +46,9 @@ typedef struct {
server_config *config;
GPtrArray *options_override;
gboolean changed;
gboolean auth_changed;
/* label */
GtkWidget *image;
GtkWidget *label;
@ -63,6 +66,7 @@ typedef struct {
GtkWidget *expander;
GtkWidget *server_settings_table;
GtkWidget *reset_delete_button;
GtkWidget *stop_button;
GtkWidget *use_button;
GList *uri_entries;
} SyncConfigWidget;
@ -85,6 +89,7 @@ GtkWidget *sync_config_widget_new (SyncevoServer *server, gboolean current, Sync
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);
G_END_DECLS