From 50ac24764bde72a9814edf94be7b7df04b6090de Mon Sep 17 00:00:00 2001 From: Salvatore Iovene Date: Sun, 13 Dec 2009 13:49:13 +0200 Subject: [PATCH] New feature: change bookmark labels. --- configure.ac | 4 + debian/control | 2 +- modules/Makefile.am | 4 +- modules/tweakr-desktop.c | 227 +++++++++++++++++++++++++++++++++++++++++++++- po/en_GB.po | 6 ++ po/it_IT.po | 6 ++ 6 files changed, 243 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 9b50ab6..a87d13e 100644 --- a/configure.ac +++ b/configure.ac @@ -36,6 +36,10 @@ PKG_CHECK_MODULES(OSSO, hildon-control-panel) AC_SUBST(CPA_LIBS) AC_SUBST(CPA_CFLAGS) +PKG_CHECK_MODULES(GCONF2, gconf-2.0) +AC_SUBST(GCONF2_LIBS) +AC_SUBST(GCONF2_CFLAGS) + AC_ARG_ENABLE(cast-checks, [ --disable-cast-checks compile with GLIB cast checks disabled],[cchecks=${enableval}],cchecks=yes) if test "x$cchecks" = "xno"; then CFLAGS="$CFLAGS -DG_DISABLE_CAST_CHECKS" diff --git a/debian/control b/debian/control index d7d122d..154aa2c 100644 --- a/debian/control +++ b/debian/control @@ -1,7 +1,7 @@ Source: tweakr Priority: optional Maintainer: Salvatore Iovene -Build-Depends: debhelper (>= 4.1.0), cdbs, libgtk2.0-dev, libhildon1-dev, libosso-dev, libglib2.0-dev, hildon-control-panel-dev +Build-Depends: debhelper (>= 4.1.0), cdbs, libgtk2.0-dev, libhildon1-dev, libosso-dev, libglib2.0-dev, hildon-control-panel-dev, libgconf2-dev Standards-Version: 3.6.0 Package: tweakr diff --git a/modules/Makefile.am b/modules/Makefile.am index ecdb0af..ce5e1c2 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -5,6 +5,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir) \ $(GTK_CFLAGS) \ $(HILDON_CFLAGS) \ + $(GCONF2_CFLAGS) \ -DTRANSITIONS=\"/usr/share/hildon-desktop/transitions.ini\" \ -DMCE=\"/etc/mce/mce.ini\" @@ -19,7 +20,8 @@ libtweakr_desktop_la_LDFLAGS = -avoid-version -module libtweakr_desktop_la_LIBADD = \ $(libtweakr_section) \ $(GTK_LIBS) \ - $(HILDON_LIBS) + $(HILDON_LIBS) \ + $(GCONF2_LIBS) libtweakr_mce_la_SOURCES = tweakr-mce.c libtweakr_mce_la_LDFLAGS = -avoid-version -module diff --git a/modules/tweakr-desktop.c b/modules/tweakr-desktop.c index 173a2a7..e66b296 100644 --- a/modules/tweakr-desktop.c +++ b/modules/tweakr-desktop.c @@ -3,11 +3,17 @@ */ #include +#include #include #include #include #include +#include +#include +#include +#include +#include #include "libtweakr-section/tweakr-section.h" #include "libtweakr-section/tweakr-module.h" @@ -27,7 +33,7 @@ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ TWEAKR_TYPE_DESKTOP_SECTION)) - +#define GCONF_BOOKMARKS "/apps/osso/hildon-home/bookmarks" enum { SNAP_NONE, @@ -51,6 +57,13 @@ static gint snap_values [] = { SNAP_HUGE_VALUE }; +typedef struct +{ + gchar *path; + gchar *value; + guint modified : 1; +} bookmark_t; + typedef struct _TweakrDesktopSection TweakrDesktopSection; typedef struct _TweakrDesktopSectionClass TweakrDesktopSectionClass; @@ -61,6 +74,13 @@ struct _TweakrDesktopSection GKeyFile *ini; GtkWidget *snap_button; + + GConfClient *gconf; + GtkWidget *bookmarks_button; + GtkWidget *bookmarks_dialog; + GtkWidget *bookmarks_box; + GHashTable *bookmarks_table; + guint save_bookmarks : 1; }; struct _TweakrDesktopSectionClass @@ -174,6 +194,169 @@ GtkWidget * _build_snap_to_grid (void) } static void +_bookmark_t_destroy (bookmark_t *b) +{ + g_free (b->path); + g_free (b->value); + g_free (b); +} + +static void +_bookmark_clicked (HildonButton *button, TweakrDesktopSection *section) +{ + GtkWidget *dialog, *entry; + gint ret; + + dialog = gtk_dialog_new_with_buttons + (_("Edit label"), + GTK_WINDOW (section->bookmarks_dialog), + GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR, + GTK_STOCK_OK, GTK_RESPONSE_OK, + NULL); + + entry = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT); + hildon_entry_set_text (HILDON_ENTRY (entry), + hildon_button_get_title (button)); + + gtk_entry_select_region (GTK_ENTRY (entry), 0, -1); + gtk_widget_show (entry); + + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), entry, + TRUE, TRUE, 0); + + ret = gtk_dialog_run (GTK_DIALOG (dialog)); + if (ret == GTK_RESPONSE_OK) + { + bookmark_t *b; + const gchar *label; + + label = hildon_entry_get_text (HILDON_ENTRY (entry)); + if (label && label[0]) + { + hildon_button_set_title (button, label); + + b = g_hash_table_lookup (section->bookmarks_table, button); + if (b) + { + g_free (b->value); + b->value = g_strdup (label); + b->modified = TRUE; + } + } + } + + gtk_widget_destroy (dialog); +} + +static void +_add_bookmark (gchar *bookmark, TweakrDesktopSection *section) +{ + bookmark_t *b; + gchar *title, *value, *url; + GtkWidget *button; + + b = g_new0 (bookmark_t, 1); + b->path = g_strconcat (bookmark, "/label", NULL); + + url = g_strconcat (bookmark, "/url", NULL); + title = gconf_client_get_string (section->gconf, b->path, NULL); + value = gconf_client_get_string (section->gconf, url, NULL); + + g_free (url); + + button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT, + HILDON_BUTTON_ARRANGEMENT_VERTICAL, + title, value); + gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f); + gtk_box_pack_start (GTK_BOX (section->bookmarks_box), button, + FALSE, FALSE, 0); + + g_signal_connect (button, "clicked", G_CALLBACK (_bookmark_clicked), + section); + + if (section->bookmarks_table == NULL) + { + section->bookmarks_table = g_hash_table_new_full + (g_direct_hash, g_direct_equal, NULL, + (GDestroyNotify) _bookmark_t_destroy); + } + g_hash_table_insert (section->bookmarks_table, button, b); + + g_free (title); + g_free (value); +} + +static void +_edit_bookmarks_clicked (GtkButton *button, TweakrDesktopSection *section) +{ + GSList *bookmarks; + + bookmarks = gconf_client_all_dirs (section->gconf, GCONF_BOOKMARKS, + NULL); + if (bookmarks && g_slist_length (bookmarks) > 0) + { + GtkWidget *panarea; + gint ret; + + section->bookmarks_dialog = gtk_dialog_new_with_buttons + (_("Edit bookmark labels"), + GTK_WINDOW (gtk_widget_get_ancestor + (tweakr_section_get_widget + (TWEAKR_SECTION (section)), + GTK_TYPE_WINDOW)), + GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR, + GTK_STOCK_OK, GTK_RESPONSE_OK, + NULL); + + panarea = hildon_pannable_area_new (); + section->bookmarks_box = gtk_vbox_new (FALSE, 0); + hildon_pannable_area_add_with_viewport + (HILDON_PANNABLE_AREA (panarea), section->bookmarks_box); + g_object_set (G_OBJECT (panarea), "height-request", + MIN (350, g_slist_length (bookmarks) * 70), NULL); + + g_slist_foreach (bookmarks, (GFunc) _add_bookmark, section); + + gtk_box_pack_start + (GTK_BOX (GTK_DIALOG (section->bookmarks_dialog)->vbox), + panarea, TRUE, TRUE, 0); + + gtk_widget_show_all (GTK_DIALOG (section->bookmarks_dialog)->vbox); + ret = gtk_dialog_run (GTK_DIALOG (section->bookmarks_dialog)); + if (ret == GTK_RESPONSE_OK) + { + section->save_bookmarks = TRUE; + } + gtk_widget_destroy (section->bookmarks_dialog); + + g_slist_foreach (bookmarks, (GFunc) g_free, NULL); + g_slist_free (bookmarks); + } +} + +GtkWidget * +_build_bookmarks_button (TweakrDesktopSection *section) +{ + GtkWidget *button; + + if (!gconf_client_dir_exists (section->gconf, GCONF_BOOKMARKS, NULL)) + { + return NULL; + } + + button = hildon_button_new_with_text (HILDON_SIZE_AUTO, + HILDON_BUTTON_ARRANGEMENT_VERTICAL, + _("Edit bookmarks labels"), ""); + gtk_button_set_alignment (GTK_BUTTON (button), 0.0f, 0.5f); + hildon_gtk_widget_set_theme_size (button, HILDON_SIZE_FINGER_HEIGHT); + + g_signal_connect (button, "clicked", + G_CALLBACK (_edit_bookmarks_clicked), section); + gtk_widget_show (button); + return button; +} + +static void tweakr_desktop_section_init (TweakrDesktopSection *section) { TweakrSection *iface; @@ -215,13 +398,20 @@ tweakr_desktop_section_init (TweakrDesktopSection *section) (HILDON_PICKER_BUTTON (section->snap_button), SNAP_HUGE); } - + section->gconf = gconf_client_get_default (); + section->bookmarks_button = _build_bookmarks_button (section); iface = TWEAKR_SECTION (section); iface->name = _("Desktop"); iface->widget = gtk_vbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (iface->widget), section->snap_button, FALSE, FALSE, 0); + if (section->bookmarks_button) + { + gtk_box_pack_start (GTK_BOX (iface->widget), + section->bookmarks_button, + FALSE, FALSE, 0); + } } static void @@ -234,13 +424,34 @@ tweakr_desktop_section_dispose (GObject *obj) section->ini = NULL; } + if (section->gconf) + { + g_object_unref (section->gconf); + section->gconf = NULL; + } + + if (section->bookmarks_table) + { + g_hash_table_destroy (section->bookmarks_table); + section->bookmarks_table = NULL; + } + G_OBJECT_CLASS (tweakr_desktop_section_parent_class)->dispose (obj); } +static void +_save_bookmarks (HildonButton *button, bookmark_t *b, + TweakrDesktopSection *section) +{ + if (b->modified) + { + gconf_client_set_string (section->gconf, b->path, b->value, NULL); + } +} -static gboolean _save (TweakrSection *section, - gboolean *requires_restart) +static gboolean _save (TweakrSection *section, + gboolean *requires_restart) { gchar *argv[3]; gint active; @@ -260,6 +471,14 @@ static gboolean _save (TweakrSection *section, g_free (argv[0]); g_free (argv[1]); + if (TWEAKR_DESKTOP_SECTION (section)->save_bookmarks) + { + g_hash_table_foreach + (TWEAKR_DESKTOP_SECTION (section)->bookmarks_table, + (GHFunc) _save_bookmarks, section); + *requires_restart = TRUE; + } + return TRUE; } diff --git a/po/en_GB.po b/po/en_GB.po index f408e7d..1cbf4f3 100644 --- a/po/en_GB.po +++ b/po/en_GB.po @@ -49,6 +49,12 @@ msgstr "Snap icons to grid" msgid "Desktop" msgstr "Desktop" +msgid "Edit bookmark labels" +msgstr "Edit bookmark labels" + +msgid "Edit label" +msgstr "Edit label" + #: modules/tweakr-mce.c:31 msgid "Do nothing" msgstr "Do nothing" diff --git a/po/it_IT.po b/po/it_IT.po index 6b8cdae..6f39b8f 100644 --- a/po/it_IT.po +++ b/po/it_IT.po @@ -49,6 +49,12 @@ msgstr "Aggancia icone alla griglia" msgid "Desktop" msgstr "Desktop" +msgid "Edit bookmark labels" +msgstr "Modifica i nomi dei segnalibri" + +msgid "Edit label" +msgstr "Modifica nome" + #: modules/tweakr-mce.c:31 msgid "Do nothing" msgstr "Ignora" -- 1.7.9.5