[gnome-disk-utility] Add "About" dialog and "Application Menu"



commit 76351951caa03047e06395cdce5f82c4474ef322
Author: David Zeuthen <davidz redhat com>
Date:   Mon Jan 23 13:42:45 2012 -0500

    Add "About" dialog and "Application Menu"
    
    See http://live.gnome.org/ThreePointThree/Features/ApplicationMenu
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 data/ui/Makefile.am             |    2 +
 data/ui/about-dialog.ui         |   41 +++++++++++++++++++++
 data/ui/app-menu.ui             |   11 ++++++
 src/palimpsest/gduapplication.c |   75 +++++++++++++++++++++++++++++++++++++--
 src/palimpsest/gduapplication.h |    2 +-
 src/palimpsest/gduwindow.c      |    6 ++--
 6 files changed, 130 insertions(+), 7 deletions(-)
---
diff --git a/data/ui/Makefile.am b/data/ui/Makefile.am
index 8c0281f..1b3aec3 100644
--- a/data/ui/Makefile.am
+++ b/data/ui/Makefile.am
@@ -20,6 +20,8 @@ ui_DATA = 				\
 	create-disk-image-dialog.ui	\
 	restore-disk-image-dialog.ui	\
 	change-passphrase-dialog.ui	\
+	about-dialog.ui			\
+	app-menu.ui			\
 	$(NULL)
 
 EXTRA_DIST = 				\
diff --git a/data/ui/about-dialog.ui b/data/ui/about-dialog.ui
new file mode 100644
index 0000000..2d05b7d
--- /dev/null
+++ b/data/ui/about-dialog.ui
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkAboutDialog" id="about-dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <property name="type_hint">dialog</property>
+    <property name="program_name">Disks</property>
+    <property name="copyright" translatable="yes">Copyright  2008-2012 Red Hat, Inc.
+Copyright  2008-2012 David Zeuthen</property>
+    <property name="comments" translatable="yes">View, Modify and Configure Disks and Media</property>
+    <property name="website">http://live.gnome.org/Design/Apps/Disks</property>
+    <property name="authors">David Zeuthen</property>
+    <property name="logo_icon_name">palimpsest</property>
+    <property name="license_type">lgpl-2-1</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="aboutdialog-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="aboutdialog-action_area1">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+          </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>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/data/ui/app-menu.ui b/data/ui/app-menu.ui
new file mode 100644
index 0000000..b923410
--- /dev/null
+++ b/data/ui/app-menu.ui
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <menu id='app-menu'>
+    <section>
+      <item action='app.about' label="_About"/>
+    </section>
+    <section>
+      <item action='app.quit' accel='&lt;Primary&gt;q' label="_Quit"/>
+    </section>
+  </menu>
+</interface>
diff --git a/src/palimpsest/gduapplication.c b/src/palimpsest/gduapplication.c
index 0060d1d..fa80b0d 100644
--- a/src/palimpsest/gduapplication.c
+++ b/src/palimpsest/gduapplication.c
@@ -103,6 +103,74 @@ gdu_application_activate (GApplication *_app)
   ;
 }
 
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+quit_activated (GSimpleAction *action,
+                GVariant      *parameter,
+                gpointer       user_data)
+{
+  GduApplication *app = GDU_APPLICATION (user_data);
+  GList *windows, *l;
+
+  windows = gtk_application_get_windows (GTK_APPLICATION (app));
+  for (l = windows; l != NULL; l = l->next)
+    {
+      GtkWindow *window = GTK_WINDOW (l->data);
+      gtk_widget_destroy (GTK_WIDGET (window));
+    }
+}
+
+static void
+about_activated (GSimpleAction *action,
+                 GVariant      *parameter,
+                 gpointer       user_data)
+{
+  GduApplication *app = GDU_APPLICATION (user_data);
+  GtkWidget *dialog;
+
+  dialog = GTK_WIDGET (gdu_application_new_widget (app,
+                                                   "about-dialog.ui",
+                                                   "about-dialog",
+                                                   NULL));
+  gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (dialog), PACKAGE_VERSION);
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (app->window));
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+  gtk_widget_show_all (dialog);
+  gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_hide (dialog);
+  gtk_widget_destroy (dialog);
+}
+
+static GActionEntry app_entries[] =
+{
+  { "about", about_activated, NULL, NULL, NULL },
+  { "quit", quit_activated, NULL, NULL, NULL }
+};
+
+static void
+gdu_application_startup (GApplication *_app)
+{
+  GduApplication *app = GDU_APPLICATION (_app);
+  GMenuModel *app_menu;
+  GtkBuilder *builder;
+
+  if (G_APPLICATION_CLASS (gdu_application_parent_class)->startup != NULL)
+    G_APPLICATION_CLASS (gdu_application_parent_class)->startup (_app);
+
+  g_action_map_add_action_entries (G_ACTION_MAP (app), app_entries, G_N_ELEMENTS (app_entries), app);
+
+  app_menu = G_MENU_MODEL (gdu_application_new_widget (app,
+                                                       "app-menu.ui",
+                                                       "app-menu",
+                                                       &builder));
+  gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
+  g_object_unref (app_menu);
+  g_clear_object (&builder);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
 static void
 gdu_application_class_init (GduApplicationClass *klass)
 {
@@ -115,6 +183,7 @@ gdu_application_class_init (GduApplicationClass *klass)
   application_class = G_APPLICATION_CLASS (klass);
   application_class->local_command_line = gdu_application_local_command_line;
   application_class->activate           = gdu_application_activate;
+  application_class->startup            = gdu_application_startup;
 }
 
 GApplication *
@@ -141,13 +210,13 @@ gdu_application_get_client (GduApplication  *application)
 }
 
 
-GtkWidget *
+GObject *
 gdu_application_new_widget (GduApplication  *application,
                             const gchar     *ui_file,
                             const gchar     *name,
                             GtkBuilder     **out_builder)
 {
-  GtkWidget *ret = NULL;
+  GObject *ret = NULL;
   GtkBuilder *builder = NULL;
   gchar *path = NULL;
   GError *error;
@@ -172,7 +241,7 @@ gdu_application_new_widget (GduApplication  *application,
     }
 
   if (name != NULL)
-    ret = GTK_WIDGET (gtk_builder_get_object (builder, name));
+    ret = G_OBJECT (gtk_builder_get_object (builder, name));
 
  out:
   if (out_builder != NULL)
diff --git a/src/palimpsest/gduapplication.h b/src/palimpsest/gduapplication.h
index e506b85..8f4e81d 100644
--- a/src/palimpsest/gduapplication.h
+++ b/src/palimpsest/gduapplication.h
@@ -35,7 +35,7 @@ G_BEGIN_DECLS
 GType         gdu_application_get_type   (void) G_GNUC_CONST;
 GApplication *gdu_application_new        (void);
 UDisksClient *gdu_application_get_client (GduApplication  *application);
-GtkWidget    *gdu_application_new_widget (GduApplication  *application,
+GObject      *gdu_application_new_widget (GduApplication  *application,
                                           const gchar     *ui_file,
                                           const gchar     *name,
                                           GtkBuilder     **out_builder);
diff --git a/src/palimpsest/gduwindow.c b/src/palimpsest/gduwindow.c
index e9a9324..6fee9ed 100644
--- a/src/palimpsest/gduwindow.c
+++ b/src/palimpsest/gduwindow.c
@@ -60,7 +60,7 @@ typedef enum
 
 struct _GduWindow
 {
-  GtkWindow parent_instance;
+  GtkApplicationWindow parent_instance;
 
   GduApplication *application;
   UDisksClient *client;
@@ -181,7 +181,7 @@ static const struct {
 
 typedef struct
 {
-  GtkWindowClass parent_class;
+  GtkApplicationWindowClass parent_class;
 } GduWindowClass;
 
 enum
@@ -273,7 +273,7 @@ static void on_generic_menu_item_create_volume_image (GtkMenuItem *menu_item,
 static void on_generic_menu_item_restore_volume_image (GtkMenuItem *menu_item,
                                                        gpointer   user_data);
 
-G_DEFINE_TYPE (GduWindow, gdu_window, GTK_TYPE_WINDOW);
+G_DEFINE_TYPE (GduWindow, gdu_window, GTK_TYPE_APPLICATION_WINDOW);
 
 static void
 gdu_window_init (GduWindow *window)



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