[gnome-panel/wip/status-notifier: 14/14] snh: add empty preferences dialog



commit da8e5a1dd0eabacce39e06070d854e9ede79ecd9
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Jul 21 03:01:24 2015 +0300

    snh: add empty preferences dialog

 applets/snh/Makefile.am               |   21 +++++++++
 applets/snh/snh-applet.c              |   73 +++++++++++++++++++++++++++++++++
 applets/snh/snh-menu.xml              |    6 +++
 applets/snh/snh-preferences-dialog.c  |   51 +++++++++++++++++++++++
 applets/snh/snh-preferences-dialog.h  |   33 +++++++++++++++
 applets/snh/snh-preferences-dialog.ui |   11 +++++
 applets/snh/snh.gresource.xml         |    7 +++
 7 files changed, 202 insertions(+), 0 deletions(-)
---
diff --git a/applets/snh/Makefile.am b/applets/snh/Makefile.am
index af4e8d9..67b6edc 100644
--- a/applets/snh/Makefile.am
+++ b/applets/snh/Makefile.am
@@ -18,6 +18,9 @@ SNH_SOURCES = \
        snh-applet.h \
        snh-item.c \
        snh-item.h \
+       snh-preferences-dialog.c \
+       snh-preferences-dialog.h \
+       $(BUILT_SOURCES) \
        $(NULL)
 
 SNH_LDADD = \
@@ -47,8 +50,26 @@ $(applet_in_files): $(applet_in_files).in Makefile
 
 @PANEL_INTLTOOL_PANEL_APPLET_RULE@
 
+SNH_RESOURCES = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) \
+       --generate-dependencies $(srcdir)/snh.gresource.xml)
+
+snh-resources.c: snh.gresource.xml $(SNH_RESOURCES)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) \
+               --generate --c-name snh $<
+
+snh-resources.h: snh.gresource.xml $(SNH_RESOURCES)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) \
+               --generate --c-name snh $<
+
+BUILT_SOURCES = \
+       snh-resources.c \
+       snh-resources.h \
+       $(NULL)
+
 EXTRA_DIST = \
        org.gnome.panel.SnhApplet.panel-applet.in.in \
+       snh.gresource.xml \
+       $(SNH_RESOURCES) \
        $(NULL)
 
 CLEANFILES = \
diff --git a/applets/snh/snh-applet.c b/applets/snh/snh-applet.c
index 443beee..09908f3 100644
--- a/applets/snh/snh-applet.c
+++ b/applets/snh/snh-applet.c
@@ -19,6 +19,7 @@
 
 #include "snh-applet.h"
 #include "snh-item.h"
+#include "snh-preferences-dialog.h"
 
 struct _SnhApplet
 {
@@ -27,6 +28,8 @@ struct _SnhApplet
   SnHost      *host;
 
   GtkWidget   *menu_bar;
+
+  GtkWidget   *preferences_dialog;
 };
 
 G_DEFINE_TYPE (SnhApplet, snh_applet, PANEL_TYPE_APPLET)
@@ -96,6 +99,12 @@ snh_applet_dispose (GObject *object)
 
   g_clear_object (&applet->host);
 
+  if (applet->preferences_dialog != NULL)
+    {
+      gtk_widget_destroy (applet->preferences_dialog);
+      applet->preferences_dialog = NULL;
+    }
+
   G_OBJECT_CLASS (snh_applet_parent_class)->dispose (object);
 }
 
@@ -149,6 +158,68 @@ snh_applet_class_init (SnhAppletClass *applet_class)
 }
 
 static void
+preferences_dialog_destroy_cb (GtkWidget *widget,
+                               gpointer   user_data)
+{
+  SnhApplet *applet;
+
+  applet = SNH_APPLET (user_data);
+
+  applet->preferences_dialog = NULL;
+}
+
+static void
+display_preferences_dialog (GSimpleAction *action,
+                            GVariant      *parameter,
+                            gpointer       user_data)
+{
+  SnhApplet *applet;
+
+  applet = SNH_APPLET (user_data);
+
+  if (applet->preferences_dialog == NULL)
+    {
+      applet->preferences_dialog = snh_preferences_dialog_new ();
+
+      g_signal_connect (applet->preferences_dialog, "destroy",
+                        G_CALLBACK (preferences_dialog_destroy_cb), applet);
+    }
+
+  gtk_window_present (GTK_WINDOW (applet->preferences_dialog));
+}
+
+static const GActionEntry menu_actions [] = {
+  { "preferences", display_preferences_dialog, NULL, NULL, NULL }
+};
+
+static void
+snh_applet_setup_menu (PanelApplet *applet)
+{
+  GSimpleActionGroup *action_group;
+  const gchar *resource_name;
+  GAction *action;
+
+  action_group = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (action_group), menu_actions,
+                                   G_N_ELEMENTS (menu_actions), applet);
+
+  resource_name = "/org/gnome/gnome-panel/snh/snh-menu.xml";
+  panel_applet_setup_menu_from_resource (applet, resource_name, action_group,
+                                              GETTEXT_PACKAGE);
+
+  gtk_widget_insert_action_group (GTK_WIDGET (applet), "snh",
+                                  G_ACTION_GROUP (action_group));
+
+  action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+                                       "preferences");
+  g_object_bind_property (applet, "locked-down", action, "enabled",
+                          G_BINDING_DEFAULT | G_BINDING_INVERT_BOOLEAN |
+                          G_BINDING_SYNC_CREATE);
+
+       g_object_unref (action_group);
+}
+
+static void
 snh_applet_init (SnhApplet *applet)
 {
   PanelApplet *panel_applet;
@@ -158,6 +229,8 @@ snh_applet_init (SnhApplet *applet)
   panel_applet_set_flags (panel_applet, PANEL_APPLET_HAS_HANDLE |
                           PANEL_APPLET_EXPAND_MINOR);
 
+  snh_applet_setup_menu (panel_applet);
+
   applet->host = sn_host_new ();
   g_signal_connect (applet->host, "items-changed",
                     G_CALLBACK (items_changed_cb), applet);
diff --git a/applets/snh/snh-menu.xml b/applets/snh/snh-menu.xml
new file mode 100644
index 0000000..cd65694
--- /dev/null
+++ b/applets/snh/snh-menu.xml
@@ -0,0 +1,6 @@
+<section>
+  <item>
+    <attribute name="label" translatable="yes">Preferences</attribute>
+    <attribute name="action">snh.preferences</attribute>
+  </item>
+</section>
diff --git a/applets/snh/snh-preferences-dialog.c b/applets/snh/snh-preferences-dialog.c
new file mode 100644
index 0000000..6280e5a
--- /dev/null
+++ b/applets/snh/snh-preferences-dialog.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2015 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/>.
+ */
+
+#include "config.h"
+
+#include "snh-preferences-dialog.h"
+
+struct _SnhPreferencesDialog
+{
+  GtkWindow parent;
+};
+
+G_DEFINE_TYPE (SnhPreferencesDialog, snh_preferences_dialog, GTK_TYPE_WINDOW)
+
+static void
+snh_preferences_dialog_class_init (SnhPreferencesDialogClass *dialog_class)
+{
+  GtkWidgetClass *widget_class;
+  const gchar *resource_name;
+
+  widget_class = GTK_WIDGET_CLASS (dialog_class);
+
+  resource_name = "/org/gnome/gnome-panel/snh/snh-preferences-dialog.ui";
+  gtk_widget_class_set_template_from_resource (widget_class, resource_name);
+}
+
+static void
+snh_preferences_dialog_init (SnhPreferencesDialog *dialog)
+{
+  gtk_widget_init_template (GTK_WIDGET (dialog));
+}
+
+GtkWidget *
+snh_preferences_dialog_new (void)
+{
+  return g_object_new (SNH_TYPE_PREFERENCES_DIALOG, NULL);
+}
diff --git a/applets/snh/snh-preferences-dialog.h b/applets/snh/snh-preferences-dialog.h
new file mode 100644
index 0000000..187c5e9
--- /dev/null
+++ b/applets/snh/snh-preferences-dialog.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2015 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/>.
+ */
+
+#ifndef SNH_PREFERENCES_DIALOG_H
+#define SNH_PREFERENCES_DIALOG_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define SNH_TYPE_PREFERENCES_DIALOG snh_preferences_dialog_get_type ()
+G_DECLARE_FINAL_TYPE (SnhPreferencesDialog, snh_preferences_dialog,
+                      SNH, PREFERENCES_DIALOG, GtkWindow)
+
+GtkWidget *snh_preferences_dialog_new (void);
+
+G_END_DECLS
+
+#endif
diff --git a/applets/snh/snh-preferences-dialog.ui b/applets/snh/snh-preferences-dialog.ui
new file mode 100644
index 0000000..703a430
--- /dev/null
+++ b/applets/snh/snh-preferences-dialog.ui
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.19.0 -->
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <template class="SnhPreferencesDialog" parent="GtkWindow">
+    <property name="can_focus">False</property>
+    <child>
+      <placeholder/>
+    </child>
+  </template>
+</interface>
diff --git a/applets/snh/snh.gresource.xml b/applets/snh/snh.gresource.xml
new file mode 100644
index 0000000..365c2f8
--- /dev/null
+++ b/applets/snh/snh.gresource.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/gnome-panel/snh">
+    <file compressed="true">snh-preferences-dialog.ui</file>
+    <file compressed="true">snh-menu.xml</file>
+  </gresource>
+</gresources>


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