[gnome-control-center/gsoc2011/location: 10/10] [location] add the dialog to append a location to the store



commit 086fac304cbd54f30b654c7844eed4bf95f87ace
Author: StÃphane Maniaci <stephane maniaci gmail com>
Date:   Fri Jul 8 00:55:50 2011 +0200

    [location] add the dialog to append a location to the store
    
    right now it's just a plain text stupid dialog that allow me to
    test settings/data saving, and hooking up to the Shell. In the very
    near future, it should be done with geocode-glib, or fallback to
    LibGWeather, and stop being ugly.

 panels/location/add-location.ui     |  161 +++++++++++++++++++++++++++++++++++
 panels/location/cc-location-panel.c |   41 +++++++++
 panels/location/location.ui         |    8 +-
 3 files changed, 206 insertions(+), 4 deletions(-)
---
diff --git a/panels/location/add-location.ui b/panels/location/add-location.ui
new file mode 100644
index 0000000..fafb18a
--- /dev/null
+++ b/panels/location/add-location.ui
@@ -0,0 +1,161 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkDialog" id="add-location-dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Add a location</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button2">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button1">
+                <property name="label">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_right">6</property>
+            <property name="row_spacing">6</property>
+            <property name="column_spacing">6</property>
+            <property name="column_homogeneous">True</property>
+            <property name="n_columns">2</property>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="label" translatable="yes">City:</property>
+                <property name="justify">right</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="label" translatable="yes">Country:</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="label" translatable="yes">Timezone:</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="city-entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">â</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="country-entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">â</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="tz-entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">â</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">2</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-5">button2</action-widget>
+      <action-widget response="-5">button1</action-widget>
+    </action-widgets>
+  </object>
+</interface>
diff --git a/panels/location/cc-location-panel.c b/panels/location/cc-location-panel.c
index 97635a3..76090f6 100644
--- a/panels/location/cc-location-panel.c
+++ b/panels/location/cc-location-panel.c
@@ -51,10 +51,43 @@ struct _CcLocationPanelPrivate
   GtkBuilder *builder;
   GSettings *settings;
   GDesktopClockFormat clock_format;
+
+  GtkListStore *location_store;
   /* that's where private vars go I guess */
 };
 
 static void
+_on_add_location (GtkToolButton   *bt,
+                  CcLocationPanel *self)
+{
+  CcLocationPanelPrivate *priv = self->priv;
+  GError *e = NULL;
+
+  gtk_builder_add_from_file (self->priv->builder, "add-location.ui", &e);
+  g_assert_no_error (e);
+
+  GtkWidget *dialog = WID ("add-location-dialog");
+  int res = gtk_dialog_run (GTK_DIALOG (dialog));
+
+  GtkTreeIter iter;
+  switch (res) {
+    case GTK_RESPONSE_OK:
+      // FIXME: column ids
+      gtk_list_store_append (priv->location_store, &iter);
+      gtk_list_store_set (priv->location_store, &iter,
+                          0, gtk_entry_get_text (GTK_ENTRY (WID ("city-entry"))),
+                          1, gtk_entry_get_text (GTK_ENTRY (WID ("country-entry"))),
+                          3, gtk_entry_get_text (GTK_ENTRY (WID ("tz-entry"))),
+                          2, "20:00",
+                          -1);
+      break;
+    default:
+      break;
+    }
+  gtk_widget_destroy (dialog);
+}
+
+static void
 _on_24hr_time_switch (GObject         *gobject,
                       GParamSpec      *pspec,
                       CcLocationPanel *self)
@@ -165,6 +198,10 @@ cc_location_panel_init (CcLocationPanel *self)
       return;
     }
 
+  gtk_builder_connect_signals (self->priv->builder, NULL);
+
+  self->priv->location_store = (GtkListStore *) gtk_builder_get_object (self->priv->builder,
+                                                                        "locations-store");
   widget = WID ("locations-scrolledwindow");
   context = gtk_widget_get_style_context (widget);
   gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
@@ -181,6 +218,10 @@ cc_location_panel_init (CcLocationPanel *self)
   g_signal_connect (widget, "notify::active",
                     G_CALLBACK (_on_24hr_time_switch), self);
 
+  widget = WID ("location-add-button");
+  g_signal_connect (widget, "clicked",
+                    G_CALLBACK (_on_add_location), self);
+
   widget = WID ("location-vbox");
   gtk_widget_reparent (widget, (GtkWidget *) self);
 
diff --git a/panels/location/location.ui b/panels/location/location.ui
index 7b40283..10cadac 100644
--- a/panels/location/location.ui
+++ b/panels/location/location.ui
@@ -1,16 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <object class="GtkListStore" id="liststore1">
+  <object class="GtkListStore" id="locations-store">
     <columns>
       <!-- column-name city-name -->
       <column type="gchararray"/>
       <!-- column-name country -->
       <column type="gchararray"/>
-      <!-- column-name time -->
-      <column type="gchararray"/>
       <!-- column-name timezone -->
       <column type="gchararray"/>
+      <!-- column-name time -->
+      <column type="gchararray"/>
     </columns>
   </object>
   <object class="GtkWindow" id="main-window">
@@ -160,7 +160,7 @@
                       <object class="GtkTreeView" id="treeview1">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
-                        <property name="model">liststore1</property>
+                        <property name="model">locations-store</property>
                         <property name="headers_visible">False</property>
                         <property name="headers_clickable">False</property>
                         <property name="search_column">0</property>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]