[gnome-panel/wip/applets/clock] clock: add ClockLocationEdit



commit 4270b316d070e87d65dcbe04128b19368bafc76c
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Fri Nov 14 21:15:46 2014 +0200

    clock: add ClockLocationEdit
    
    Add ClockLocationEdit that will be used for location editing
    and/or adding new locations.
    
    clock-location-edit.ui is created from clock.ui with small changes:
    1) Marked as composite template.
    2) Removed unused widgets.

 applets/clock/Makefile.am            |    3 +
 applets/clock/clock-location-edit.c  |  152 +++++++++++++++++++
 applets/clock/clock-location-edit.h  |   65 ++++++++
 applets/clock/clock-location-edit.ui |  272 ++++++++++++++++++++++++++++++++++
 applets/clock/clock.gresource.xml    |    1 +
 5 files changed, 493 insertions(+), 0 deletions(-)
---
diff --git a/applets/clock/Makefile.am b/applets/clock/Makefile.am
index c234f05..26ae8b9 100644
--- a/applets/clock/Makefile.am
+++ b/applets/clock/Makefile.am
@@ -32,6 +32,8 @@ CLOCK_SOURCES =               \
        clock-face.h            \
        clock-location.c        \
        clock-location.h        \
+       clock-location-edit.c   \
+       clock-location-edit.h   \
        clock-location-tile.c   \
        clock-location-tile.h   \
        clock-map.c             \
@@ -147,6 +149,7 @@ $(applet_in_files): $(applet_in_files).in Makefile
 
 ui_FILES =             \
        clock.ui        \
+       clock-location-edit.ui \
        clock-preferences.ui \
        clock-menu.xml
 
diff --git a/applets/clock/clock-location-edit.c b/applets/clock/clock-location-edit.c
new file mode 100644
index 0000000..4537b81
--- /dev/null
+++ b/applets/clock/clock-location-edit.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2014 Alberts Muktupāvels
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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/>.
+ *
+ * Authors:
+ *    Alberts Muktupāvels <alberts muktupavels gmail com>
+ */
+
+#include "clock-location-edit.h"
+
+struct _ClockLocationEditPrivate
+{
+        GSettings *settings;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (ClockLocationEdit,
+                            clock_location_edit,
+                            GTK_TYPE_DIALOG)
+
+enum
+{
+       PROP_0,
+       PROP_SETTINGS,
+       N_PROPERTIES
+};
+
+static GParamSpec *object_properties[N_PROPERTIES] = { NULL, };
+
+static void
+clock_location_edit_finalize (GObject *object)
+{
+       ClockLocationEdit *edit;
+
+       edit = CLOCK_LOCATION_EDIT (object)
+
+       g_clear_object (&edit->priv->settings);
+
+       G_OBJECT_CLASS (clock_location_edit_parent_class)->finalize (object);
+}
+
+static void
+clock_location_edit_set_property (GObject      *object,
+                                  guint         property_id,
+                                  const GValue *value,
+                                  GParamSpec   *pspec)
+{
+       ClockLocationEdit *edit;
+       GSettings         *settings;
+
+       edit = CLOCK_LOCATION_EDIT (object);
+
+       switch (property_id)
+       {
+               case PROP_SETTINGS:
+                       settings = g_value_get_object (value);
+                       edit->priv->settings = g_object_ref (settings);
+                       break;
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
+                                                          property_id,
+                                                          pspec);
+                       break;
+       }
+}
+
+static void
+clock_location_edit_get_property (GObject    *object,
+                                  guint       property_id,
+                                  GValue     *value,
+                                  GParamSpec *pspec)
+{
+       ClockLocationEdit *edit;
+
+       edit = CLOCK_LOCATION_EDIT (object);
+
+       switch (property_id)
+       {
+               case PROP_SETTINGS:
+                       g_value_set_object (value, edit->priv->settings);
+                       break;
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
+                                                          property_id,
+                                                          pspec);
+                       break;
+       }
+}
+
+static void
+clock_location_edit_class_init (ClockLocationEditClass *class)
+{
+       GObjectClass   *object_class;
+       GtkWidgetClass *widget_class;
+
+       object_class = G_OBJECT_CLASS (class);
+       widget_class = GTK_WIDGET_CLASS (class);
+
+       object_class->finalize = clock_location_edit_finalize;
+       object_class->set_property = clock_location_edit_set_property;
+       object_class->get_property = clock_location_edit_get_property;
+
+       object_properties[PROP_SETTINGS] =
+               g_param_spec_object ("settings",
+                                    "settings",
+                                    "settings",
+                                    G_TYPE_SETTINGS,
+                                    G_PARAM_CONSTRUCT_ONLY |
+                                    G_PARAM_WRITABLE);
+
+       g_object_class_install_properties (object_class,
+                                          N_PROPERTIES,
+                                          object_properties);
+
+        gtk_widget_class_set_template_from_resource (widget_class,
+                                                     CLOCK_RESOURCE_PATH "clock-location-edit.ui"
+}
+
+static void
+clock_location_edit_init (ClockLocationEdit *edit)
+{
+       edit->priv = clock_location_edit_get_instance_private (edit);
+
+        gtk_widget_init_template (GTK_WIDGET (edit));
+}
+
+GtkWidget *
+clock_location_edit_new (GSettings *settings,
+                         GtkWindow *parent)
+{
+        GObject *object;
+
+        object = g_object_new (CLOCK_TYPE_LOCATION_EDIT,
+                               "settings", settings,
+                               NULL);
+
+        gtk_window_set_transient_for (GTK_WINDOW (object),
+                                      parent);
+
+        return GTK_WIDGET (object);
+}
diff --git a/applets/clock/clock-location-edit.h b/applets/clock/clock-location-edit.h
new file mode 100644
index 0000000..ebadddc
--- /dev/null
+++ b/applets/clock/clock-location-edit.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2014 Alberts Muktupāvels
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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/>.
+ *
+ * Authors:
+ *    Alberts Muktupāvels <alberts muktupavels gmail com>
+ */
+
+#ifndef CLOCK_LOCATION_EDIT_H
+#define CLOCK_LOCATION_EDIT_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define CLOCK_TYPE_LOCATION_EDIT         (clock_location_edit_get_type ())
+#define CLOCK_LOCATION_EDIT(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), \
+                                          CLOCK_TYPE_LOCATION_EDIT,        \
+                                          ClockLocationEdit))
+#define CLOCK_LOCATION_EDIT_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST ((c),    \
+                                          CLOCK_TYPE_LOCATION_EDIT,        \
+                                          ClockLocationEditClass))
+#define CLOCK_IS_LOCATION_EDIT(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), \
+                                          CLOCK_TYPE_LOCATION_EDIT))
+#define CLOCK_IS_LOCATION_EDIT_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE ((c),    \
+                                          CLOCK_TYPE_LOCATION_EDIT))
+#define CLOCK_LOCATION_EDIT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o),   \
+                                          CLOCK_TYPE_LOCATION_EDIT,        \
+                                          ClockLocationEditClass))
+
+typedef struct _ClockLocationEdit        ClockLocationEdit;
+typedef struct _ClockLocationEditClass   ClockLocationEditClass;
+typedef struct _ClockLocationEditPrivate ClockLocationEditPrivate;
+
+struct _ClockLocationEdit
+{
+       GtkDialog                 parent;
+       ClockLocationEditPrivate *priv;
+};
+
+struct _ClockLocationEditClass
+{
+       GtkDialogClass parent_class;
+};
+
+GType      clock_location_edit_get_type (void);
+
+GtkWidget *clock_location_edit_new      (GSettings *settings,
+                                         GtkWindow *parent);
+
+G_END_DECLS
+
+#endif
diff --git a/applets/clock/clock-location-edit.ui b/applets/clock/clock-location-edit.ui
new file mode 100644
index 0000000..861614b
--- /dev/null
+++ b/applets/clock/clock-location-edit.ui
@@ -0,0 +1,272 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.3 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <template class="edit-location-window" parent="GtkDialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="resizable">False</property>
+    <property name="type_hint">normal</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox7">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area7">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkButton" id="edit-location-cancel-button">
+                <property name="label" translatable="yes">_Cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="edit-location-ok-button">
+                <property name="label" translatable="yes">_OK</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</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="table27">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">5</property>
+            <property name="row_spacing">6</property>
+            <property name="column_spacing">6</property>
+            <child>
+              <object class="GtkBox" id="edit-location-name-box">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox" id="edit-location-timezone-box">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">2</property>
+                <property name="width">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="edit-location-latitude-entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hexpand">True</property>
+                <property name="invisible_char">•</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBox" id="edit-location-latitude-combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="model">liststore2</property>
+                <child>
+                  <object class="GtkCellRendererText" id="cellrenderertext2"/>
+                  <attributes>
+                    <attribute name="text">0</attribute>
+                  </attributes>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label240">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">(optional)</property>
+                <attributes>
+                  <attribute name="style" value="italic"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left_attach">3</property>
+                <property name="top_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label239">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">(optional)</property>
+                <attributes>
+                  <attribute name="style" value="italic"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left_attach">3</property>
+                <property name="top_attach">4</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBox" id="edit-location-longitude-combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="model">liststore1</property>
+                <child>
+                  <object class="GtkCellRendererText" id="cellrenderertext1"/>
+                  <attributes>
+                    <attribute name="text">0</attribute>
+                  </attributes>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">4</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="edit-location-longitude-entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hexpand">True</property>
+                <property name="invisible_char">•</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">4</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="location-name-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">_Location Name:</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label237">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">L_atitude:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">edit-location-latitude-entry</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label238">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">L_ongitude:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">edit-location-longitude-entry</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">4</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label243">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="hexpand">True</property>
+                <property name="vexpand">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes" comments="Languages that have a single word that 
translates as either 'state' or 'province' should use that instead of 'region'.">Type a city, region, or 
country name and then select a match from the pop-up.</property>
+                <attributes>
+                  <attribute name="style" value="italic"/>
+                  <attribute name="scale" value="0.82999999999999996"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+                <property name="width">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="timezone-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">_Timezone:</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">edit-location-cancel-button</action-widget>
+      <action-widget response="-5">edit-location-ok-button</action-widget>
+    </action-widgets>
+  </template>
+</interface>
diff --git a/applets/clock/clock.gresource.xml b/applets/clock/clock.gresource.xml
index 844cec2..43092e9 100644
--- a/applets/clock/clock.gresource.xml
+++ b/applets/clock/clock.gresource.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/panel/applet/clock">
     <file compressed="true">clock.ui</file>
+    <file compressed="true">clock-location-edit.ui</file>
     <file compressed="true">clock-preferences.ui</file>
     <file compressed="true">clock-menu.xml</file>
     <file alias="icons/clock-face-morning.svg">pixmaps/clock-face-morning.svg</file>


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