[gnome-applets/wip/muktupavels/window-picker/about] window-picker: subclass GtkAboutDialog



commit 553bce08b1436d8576add5923aa5b0453f9d4da2
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Jul 14 00:14:45 2015 +0300

    window-picker: subclass GtkAboutDialog

 windowpicker/src/Makefile.am       |    2 +
 windowpicker/src/applet.c          |   62 ++++++++++++--------
 windowpicker/src/wp-about-dialog.c |  109 ++++++++++++++++++++++++++++++++++++
 windowpicker/src/wp-about-dialog.h |   33 +++++++++++
 4 files changed, 181 insertions(+), 25 deletions(-)
---
diff --git a/windowpicker/src/Makefile.am b/windowpicker/src/Makefile.am
index d556f87..f8a1c01 100644
--- a/windowpicker/src/Makefile.am
+++ b/windowpicker/src/Makefile.am
@@ -21,6 +21,8 @@ libwindow_picker_applet_la_LIBADD = \
        $(LIBWNCK_LIBS)
 
 libwindow_picker_applet_la_SOURCES = \
+       wp-about-dialog.c \
+       wp-about-dialog.h \
        applet.c \
        applet.h \
        task-item.c \
diff --git a/windowpicker/src/applet.c b/windowpicker/src/applet.c
index bf1f3f0..728ae18 100644
--- a/windowpicker/src/applet.c
+++ b/windowpicker/src/applet.c
@@ -25,6 +25,7 @@
 #include "task-title.h"
 #include "task-list.h"
 #include "applet.h"
+#include "wp-about-dialog.h"
 
 #include <string.h>
 
@@ -53,6 +54,8 @@ struct _WindowPickerAppletPrivate {
     gboolean show_home_title;
     gboolean icons_greyscale;
     gboolean expand_task_list;
+
+    GtkWidget *about_dialog;
 };
 
 enum {
@@ -78,12 +81,6 @@ static const GActionEntry menu_actions[] = {
        { "about", display_about_dialog }
 };
 
-static const gchar *windowPickerAppletAuthors[] = {
-    "Neil J. Patel <neil patel canonical com>",
-    "Sebastian Geiger <sbastig gmx net>",
-    NULL
-};
-
 /**
  * This functions loads our custom CSS and registers the CSS style class
  * for the applets style context
@@ -189,29 +186,39 @@ load_window_picker (PanelApplet *applet) {
 }
 
 static void
+wp_about_dialog_response_cb (GtkDialog *dialog,
+                             gint       response_id,
+                             gpointer   user_data)
+{
+  WindowPickerApplet *applet;
+
+  applet = WINDOW_PICKER_APPLET (user_data);
+
+  if (applet->priv->about_dialog == NULL)
+    return;
+
+  gtk_widget_destroy (applet->priv->about_dialog);
+  applet->priv->about_dialog = NULL;
+}
+
+static void
 display_about_dialog (GSimpleAction *action,
                       GVariant      *parameter,
                       gpointer       user_data)
 {
-    GtkWidget *panel_about_dialog = gtk_about_dialog_new ();
-    g_object_set (panel_about_dialog,
-        "name", _("Window Picker"),
-        "comments", _("Window Picker"),
-        "version", PACKAGE_VERSION,
-        "authors", windowPickerAppletAuthors,
-        "logo-icon-name", "system-preferences-windows",
-        "copyright", "Copyright \xc2\xa9 2008 Canonical Ltd\nand Sebastian Geiger",
-        NULL
-    );
-    char *logo_filename = g_build_filename (WINDOW_PICKER_MENU_UI_DIR, "window-picker-about-logo.png", NULL);
-    GdkPixbuf* logo = gdk_pixbuf_new_from_file(logo_filename, NULL);
-    gtk_about_dialog_set_logo (GTK_ABOUT_DIALOG(panel_about_dialog), logo);
-    if (logo)
-        g_object_unref (logo);
-    gtk_widget_show (panel_about_dialog);
-    g_signal_connect (panel_about_dialog, "response",
-        G_CALLBACK (gtk_widget_destroy), NULL);
-    gtk_window_present (GTK_WINDOW (panel_about_dialog));
+  WindowPickerApplet *applet;
+
+  applet = WINDOW_PICKER_APPLET (user_data);
+
+  if (applet->priv->about_dialog == NULL)
+    {
+      applet->priv->about_dialog = wp_about_dialog_new ();
+
+      g_signal_connect (applet->priv->about_dialog, "response",
+                        G_CALLBACK (wp_about_dialog_response_cb), applet);
+    }
+
+  gtk_window_present (GTK_WINDOW (applet->priv->about_dialog));
 }
 
 static GtkWidget *
@@ -378,6 +385,11 @@ window_picker_dispose (GObject *object)
     WindowPickerApplet *applet = WINDOW_PICKER_APPLET (object);
     g_clear_object (&applet->priv->settings);
 
+    if (applet->priv->about_dialog != NULL) {
+        gtk_widget_destroy (applet->priv->about_dialog);
+        applet->priv->about_dialog = NULL;
+    }
+
     G_OBJECT_CLASS (window_picker_applet_parent_class)->dispose (object);
 }
 
diff --git a/windowpicker/src/wp-about-dialog.c b/windowpicker/src/wp-about-dialog.c
new file mode 100644
index 0000000..9a2a4d6
--- /dev/null
+++ b/windowpicker/src/wp-about-dialog.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2008 Canonical Ltd
+ * 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/>.
+ *
+ * Authors:
+ *     Alberts Muktupāvels <alberts muktupavels gmail com>
+ *     Neil Jagdish Patel <neil patel canonical com>
+ *     Sebastian Geiger <sbastig gmx net>
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include "wp-about-dialog.h"
+
+struct _WpAboutDialog
+{
+  GtkAboutDialog  parent;
+  GdkPixbuf      *logo;
+};
+
+static const gchar *authors[] = {
+  "Neil J. Patel <neil patel canonical com>",
+  "Sebastian Geiger <sbastig gmx net>",
+  NULL
+};
+
+G_DEFINE_TYPE (WpAboutDialog, wp_about_dialog, GTK_TYPE_ABOUT_DIALOG)
+
+static void
+wp_about_dialog_constructed (GObject *object)
+{
+  WpAboutDialog *dialog;
+  gchar *filename;
+
+  G_OBJECT_CLASS (wp_about_dialog_parent_class)->constructed (object);
+
+  dialog = WP_ABOUT_DIALOG (object);
+  filename = g_build_filename (WINDOW_PICKER_MENU_UI_DIR,
+                               "window-picker-about-logo.png",
+                               NULL);
+
+  dialog->logo = gdk_pixbuf_new_from_file (filename, NULL);
+  g_free (filename);
+
+  if (dialog->logo)
+    gtk_about_dialog_set_logo (GTK_ABOUT_DIALOG (dialog), dialog->logo);
+}
+
+static void
+wp_about_dialog_dispose (GObject *object)
+{
+  WpAboutDialog *dialog;
+
+  dialog = WP_ABOUT_DIALOG (object);
+
+  g_clear_object (&dialog->logo);
+
+  G_OBJECT_CLASS (wp_about_dialog_parent_class)->dispose (object);
+}
+
+static void
+wp_about_dialog_class_init (WpAboutDialogClass *dialog_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (dialog_class);
+
+  object_class->constructed = wp_about_dialog_constructed;
+  object_class->dispose = wp_about_dialog_dispose;
+}
+
+static void
+wp_about_dialog_init (WpAboutDialog *dialog)
+{
+}
+
+GtkWidget *
+wp_about_dialog_new (void)
+{
+  const gchar *title;
+  const gchar *copyright;
+
+  title = _("Window Picker");
+  copyright = "Copyright \xc2\xa9 2008 Canonical Ltd\nand Sebastian Geiger";
+
+  return g_object_new (WP_TYPE_ABOUT_DIALOG,
+                       "authors", authors,
+                       "comments", title,
+                       "copyright", copyright,
+                       "name", title,
+                       "program-name", "GNOME Applets",
+                       "version", PACKAGE_VERSION,
+                       NULL);
+}
diff --git a/windowpicker/src/wp-about-dialog.h b/windowpicker/src/wp-about-dialog.h
new file mode 100644
index 0000000..3922f4d
--- /dev/null
+++ b/windowpicker/src/wp-about-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 WP_ABOUT_DIALOG_H
+#define WP_ABOUT_DIALOG_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define WP_TYPE_ABOUT_DIALOG wp_about_dialog_get_type ()
+G_DECLARE_FINAL_TYPE (WpAboutDialog, wp_about_dialog,
+                      WP, ABOUT_DIALOG, GtkAboutDialog)
+
+GtkWidget *wp_about_dialog_new (void);
+
+G_END_DECLS
+
+#endif


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