aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Terry <mike@mterry.name>2011-02-18 16:31:17 -0500
committerMichael Terry <mike@mterry.name>2011-02-18 16:31:17 -0500
commit1e274bb18d9936c39d4c22e00ec895dc79178390 (patch)
tree4f629320dabf77d93dc56824e9fdd731d18a5bcb
parent6dda4370c9cc94bb25c1cd388adce14f1c0e9f19 (diff)
downloadayatana-indicator-datetime-1e274bb18d9936c39d4c22e00ec895dc79178390.tar.gz
ayatana-indicator-datetime-1e274bb18d9936c39d4c22e00ec895dc79178390.tar.bz2
ayatana-indicator-datetime-1e274bb18d9936c39d4c22e00ec895dc79178390.zip
start of locations dialog
-rw-r--r--data/datetime-dialog.ui22
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/Makefile.am2
-rw-r--r--src/datetime-prefs-locations.c137
-rw-r--r--src/datetime-prefs-locations.h34
-rw-r--r--src/datetime-prefs.c11
6 files changed, 202 insertions, 5 deletions
diff --git a/data/datetime-dialog.ui b/data/datetime-dialog.ui
index 1e0f726..a849107 100644
--- a/data/datetime-dialog.ui
+++ b/data/datetime-dialog.ui
@@ -5,16 +5,28 @@
<object class="GtkWindow" id="locationsDialog">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Locations</property>
+ <property name="modal">True</property>
+ <property name="destroy_with_parent">True</property>
<property name="icon_name">time-admin</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
- <object class="GtkTreeView" id="locationsView">
+ <object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="model">locationsStore</property>
+ <property name="hscrollbar_policy">automatic</property>
+ <property name="vscrollbar_policy">automatic</property>
+ <child>
+ <object class="GtkTreeView" id="locationsView">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="model">locationsStore</property>
+ <property name="reorderable">True</property>
+ <property name="search_column">0</property>
+ </object>
+ </child>
</object>
<packing>
<property name="expand">True</property>
@@ -27,10 +39,11 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
- <object class="GtkButton" id="button1">
+ <object class="GtkButton" id="addButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Add a Location…</property>
<property name="use_action_appearance">False</property>
<child>
<object class="GtkImage" id="addImage">
@@ -47,10 +60,11 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="button2">
+ <object class="GtkButton" id="removeButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Remove This Location</property>
<property name="use_action_appearance">False</property>
<child>
<object class="GtkImage" id="removeImage">
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2eb7ec1..0fa22d4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,4 +1,5 @@
src/indicator-datetime.c
src/datetime-service.c
src/datetime-prefs.c
+src/datetime-prefs-locations.c
[type: gettext/glade]data/datetime-dialog.ui
diff --git a/src/Makefile.am b/src/Makefile.am
index 150c87d..94d179d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -41,6 +41,8 @@ libdatetime_la_LDFLAGS = \
indicator_datetime_preferences_SOURCES =\
datetime-prefs.c \
+ datetime-prefs-locations.c \
+ datetime-prefs-locations.h \
utils.c \
utils.h \
settings-shared.h
diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c
new file mode 100644
index 0000000..24efd04
--- /dev/null
+++ b/src/datetime-prefs-locations.c
@@ -0,0 +1,137 @@
+/* -*- Mode: C; coding: utf-8; indent-tabs-mode: nil; tab-width: 2 -*-
+
+A dialog for setting time and date preferences.
+
+Copyright 2011 Canonical Ltd.
+
+Authors:
+ Michael Terry <michael.terry@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "datetime-prefs-locations.h"
+#include "settings-shared.h"
+
+#define DATETIME_DIALOG_UI_FILE PKGDATADIR "/datetime-dialog.ui"
+
+static void
+handle_add (GtkWidget * button, gpointer user_data)
+{
+}
+
+static void
+handle_remove (GtkWidget * button, gpointer user_data)
+{
+}
+
+static void
+fill_from_settings (GObject * store, GSettings * conf)
+{
+ gchar ** locations = g_settings_get_strv (conf, SETTINGS_LOCATIONS_S);
+
+ gtk_list_store_clear (GTK_LIST_STORE (store));
+
+ gchar ** striter;
+ GtkTreeIter iter;
+ for (striter = locations; *striter; ++striter) {
+ gtk_list_store_append (GTK_LIST_STORE (store), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (store), &iter, 0, *striter, -1);
+ }
+
+ g_strfreev (locations);
+}
+
+static void
+save_to_settings (GtkWidget * dlg, GObject * store)
+{
+ GVariantBuilder builder;
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
+
+ GtkTreeIter iter;
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) {
+ do {
+ GValue value = {0};
+ gtk_tree_model_get_value (GTK_TREE_MODEL (store), &iter, 0, &value);
+ g_variant_builder_add (&builder, "s", g_value_get_string (&value));
+ g_value_unset (&value);
+ } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter));
+ }
+
+ GVariant * locations = g_variant_builder_end (&builder);
+
+ GSettings * conf = G_SETTINGS (g_object_get_data (G_OBJECT (dlg), "conf"));
+ g_settings_set_strv (conf, SETTINGS_LOCATIONS_S, g_variant_get_strv (locations, NULL));
+
+ g_variant_unref (locations);
+}
+
+GtkWidget *
+datetime_setup_locations_dialog (GtkWindow * parent)
+{
+ GError * error = NULL;
+ GtkBuilder * builder = gtk_builder_new ();
+ gtk_builder_add_from_file (builder, DATETIME_DIALOG_UI_FILE, &error);
+ if (error != NULL) {
+ /* We have to abort, we can't continue without the ui file */
+ g_error ("Could not load ui file %s: %s", DATETIME_DIALOG_UI_FILE, error->message);
+ g_error_free (error);
+ return NULL;
+ }
+
+ gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
+
+ GSettings * conf = g_settings_new (SETTINGS_INTERFACE);
+
+#define WIG(name) GTK_WIDGET (gtk_builder_get_object (builder, name))
+
+ GtkWidget * dlg = WIG ("locationsDialog");
+ GtkWidget * tree = WIG ("locationsView");
+ GObject * store = gtk_builder_get_object (builder, "locationsStore");
+
+ /* Configure tree */
+ GtkCellRenderer * cell = gtk_cell_renderer_text_new ();
+ g_object_set (cell, "editable", TRUE, NULL);
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1,
+ _("Location"), cell,
+ "text", 0, NULL);
+ cell = gtk_cell_renderer_text_new ();
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1,
+ _("Time"), cell,
+ "text", 1, NULL);
+ gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree)), GTK_SELECTION_MULTIPLE);
+
+ g_signal_connect (WIG ("addButton"), "clicked", G_CALLBACK (handle_add), NULL);
+ g_signal_connect (WIG ("removeButton"), "clicked", G_CALLBACK (handle_remove), NULL);
+
+ fill_from_settings (store, conf);
+ g_object_set_data_full (G_OBJECT (dlg), "conf", g_object_ref (conf), g_object_unref);
+ g_signal_connect (dlg, "destroy", G_CALLBACK (save_to_settings), store);
+
+ gtk_window_set_transient_for (GTK_WINDOW (dlg), parent);
+
+#undef WIG
+
+ g_object_unref (conf);
+ g_object_unref (builder);
+
+ return dlg;
+}
+
diff --git a/src/datetime-prefs-locations.h b/src/datetime-prefs-locations.h
new file mode 100644
index 0000000..d5dd534
--- /dev/null
+++ b/src/datetime-prefs-locations.h
@@ -0,0 +1,34 @@
+/* -*- Mode: C; coding: utf-8; indent-tabs-mode: nil; tab-width: 2 -*-
+
+A dialog for setting time and date preferences.
+
+Copyright 2011 Canonical Ltd.
+
+Authors:
+ Michael Terry <michael.terry@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __DATETIME_PREFS_LOCATIONS_H__
+#define __DATETIME_PREFS_LOCATIONS_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+GtkWidget * datetime_setup_locations_dialog (GtkWindow * parent);
+
+G_END_DECLS
+
+#endif
diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c
index a42c46b..97b106d 100644
--- a/src/datetime-prefs.c
+++ b/src/datetime-prefs.c
@@ -35,6 +35,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "settings-shared.h"
#include "utils.h"
+#include "datetime-prefs-locations.h"
#define DATETIME_DIALOG_UI_FILE PKGDATADIR "/datetime-dialog.ui"
@@ -324,6 +325,13 @@ setup_time_spinner (GtkWidget * spinner, GtkWidget * other, gboolean is_time)
update_spinner (spinner);
}
+static void
+show_locations (GtkWidget * button, GtkWidget * dlg)
+{
+ GtkWidget * locationsDlg = datetime_setup_locations_dialog (GTK_WINDOW (dlg));
+ gtk_widget_show_all (locationsDlg);
+}
+
static GtkWidget *
create_dialog (void)
{
@@ -351,7 +359,6 @@ create_dialog (void)
gtk_box_pack_start (GTK_BOX (WIG ("timeDateBox")), polkit_button, FALSE, TRUE, 0);
/* Set up settings bindings */
-
g_settings_bind (conf, SETTINGS_SHOW_CLOCK_S, WIG ("showClockCheck"),
"active", G_SETTINGS_BIND_DEFAULT);
g_settings_bind (conf, SETTINGS_SHOW_DAY_S, WIG ("showWeekdayCheck"),
@@ -398,6 +405,8 @@ create_dialog (void)
GtkWidget * dlg = WIG ("timeDateDialog");
+ g_signal_connect (WIG ("locationsButton"), "clicked", G_CALLBACK (show_locations), dlg);
+
/* Grab proxy for settings daemon */
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
"org.gnome.SettingsDaemon.DateTimeMechanism",