[gnome-applets] window-picker: redo preferences dialog
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-applets] window-picker: redo preferences dialog
- Date: Mon, 13 Jul 2015 23:51:06 +0000 (UTC)
commit 566ea53c2787eefc2f212910c3a6da42329f5718
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue Jul 14 02:50:14 2015 +0300
window-picker: redo preferences dialog
po/POTFILES.in | 1 +
windowpicker/src/Makefile.am | 2 +
windowpicker/src/applet.c | 105 ++++++------------
windowpicker/src/wp-preferences-dialog.c | 168 +++++++++++++++++++++++++++++
windowpicker/src/wp-preferences-dialog.h | 39 +++++++
windowpicker/src/wp-preferences-dialog.ui | 13 ++-
6 files changed, 251 insertions(+), 77 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 7c23df2..445e3f8 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -109,3 +109,4 @@ windowpicker/src/applet.c
windowpicker/src/task-title.c
windowpicker/src/task-item.c
windowpicker/src/wp-about-dialog.c
+[type: gettext/glade]windowpicker/src/wp-preferences-dialog.ui
diff --git a/windowpicker/src/Makefile.am b/windowpicker/src/Makefile.am
index 1375b4c..fe0c324 100644
--- a/windowpicker/src/Makefile.am
+++ b/windowpicker/src/Makefile.am
@@ -33,6 +33,8 @@ libwindow_picker_applet_la_LIBADD = \
libwindow_picker_applet_la_SOURCES = \
wp-about-dialog.c \
wp-about-dialog.h \
+ wp-preferences-dialog.c \
+ wp-preferences-dialog.h \
applet.c \
applet.h \
task-item.c \
diff --git a/windowpicker/src/applet.c b/windowpicker/src/applet.c
index 728ae18..5d9a31f 100644
--- a/windowpicker/src/applet.c
+++ b/windowpicker/src/applet.c
@@ -26,6 +26,7 @@
#include "task-list.h"
#include "applet.h"
#include "wp-about-dialog.h"
+#include "wp-preferences-dialog.h"
#include <string.h>
@@ -37,12 +38,7 @@
#include <libwnck/libwnck.h>
-#define SETTINGS_SCHEMA "org.gnome.gnome-applets.window-picker-applet"
-#define KEY_SHOW_ALL_WINDOWS "show-all-windows"
-#define KEY_SHOW_APPLICATION_TITLE "show-application-title"
-#define KEY_SHOW_HOME_TITLE "show-home-title"
-#define KEY_ICONS_GREYSCALE "icons-greyscale"
-#define KEY_EXPAND_TASK_LIST "expand-task-list"
+#define SETTINGS_SCHEMA "org.gnome.gnome-applets.window-picker-applet"
struct _WindowPickerAppletPrivate {
GtkWidget *tasks;
@@ -56,6 +52,7 @@ struct _WindowPickerAppletPrivate {
gboolean expand_task_list;
GtkWidget *about_dialog;
+ GtkWidget *preferences_dialog;
};
enum {
@@ -221,25 +218,20 @@ display_about_dialog (GSimpleAction *action,
gtk_window_present (GTK_WINDOW (applet->priv->about_dialog));
}
-static GtkWidget *
-prepareCheckBox (WindowPickerApplet *windowPickerApplet,
- const gchar *text,
- const gchar *key)
+static void
+wp_preferences_dialog_response_cb (GtkDialog *dialog,
+ gint response_id,
+ gpointer user_data)
{
- GtkWidget *check = gtk_check_button_new_with_label (text);
- GSettings *settings = windowPickerApplet->priv->settings;
- gboolean is_active = g_settings_get_boolean (settings, key);
+ WindowPickerApplet *applet;
- gtk_toggle_button_set_active (
- GTK_TOGGLE_BUTTON (check),
- is_active
- );
+ applet = WINDOW_PICKER_APPLET (user_data);
- g_settings_bind (windowPickerApplet->priv->settings, key,
- check, "active",
- G_SETTINGS_BIND_DEFAULT);
+ if (applet->priv->preferences_dialog == NULL)
+ return;
- return check;
+ gtk_widget_destroy (applet->priv->preferences_dialog);
+ applet->priv->preferences_dialog = NULL;
}
static void
@@ -247,57 +239,21 @@ display_prefs_dialog (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
- WindowPickerApplet *windowPickerApplet = WINDOW_PICKER_APPLET (user_data);
-
- //Setup the Preferences window
- GtkWidget *window, *notebook, *check, *button, *grid;
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title (GTK_WINDOW (window), _("Preferences"));
- gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DIALOG);
- gtk_container_set_border_width (GTK_CONTAINER (window), 12);
- //Setup the notebook which holds our gui items
- notebook = gtk_notebook_new ();
- gtk_container_add (GTK_CONTAINER (window), notebook);
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK(notebook), FALSE);
- grid = gtk_grid_new ();
- gtk_notebook_append_page (GTK_NOTEBOOK (notebook), grid, NULL);
-
- //Prepare the checkboxes and a button and add it to the grid in the notebook
- int i=-1;
-
- check = prepareCheckBox (windowPickerApplet, _("Show windows from all workspaces"),
KEY_SHOW_ALL_WINDOWS);
- gtk_grid_attach (GTK_GRID (grid), check, 0, ++i, 1, 1);
-
- check = prepareCheckBox (windowPickerApplet, _("Show the home title and\n"
- "log out icon when on the desktop"),
- KEY_SHOW_HOME_TITLE);
- gtk_grid_attach (GTK_GRID (grid), check, 0, ++i, 1, 1);
-
- check = prepareCheckBox (windowPickerApplet, _("Show the application title and\nclose icon"),
- KEY_SHOW_APPLICATION_TITLE);
- gtk_grid_attach (GTK_GRID (grid), check, 0, ++i, 1, 1);
-
- check = prepareCheckBox (windowPickerApplet, _("Grey out non-active window icons"), KEY_ICONS_GREYSCALE);
- gtk_grid_attach (GTK_GRID (grid), check, 0, ++i, 1, 1);
-
- check = prepareCheckBox (windowPickerApplet, _("Automatically expand task list to use full space"),
KEY_EXPAND_TASK_LIST);
- gtk_grid_attach (GTK_GRID (grid), check, 0, ++i, 1, 1);
-
- button = gtk_button_new_with_label (_("_Close"));
- gtk_widget_set_halign (button, GTK_ALIGN_END);
- gtk_grid_set_row_spacing (GTK_GRID (grid), 0);
- gtk_grid_attach (GTK_GRID(grid), button, 0, ++i, 1, 1);
-
- //Register all events and show the window
- g_signal_connect (window, "delete-event",
- G_CALLBACK (gtk_widget_destroy), window);
- g_signal_connect (window, "destroy",
- G_CALLBACK (gtk_widget_destroy), window);
- g_signal_connect_swapped (button, "clicked",
- G_CALLBACK (gtk_widget_destroy), window);
-
- gtk_widget_show_all (window);
- gtk_window_present (GTK_WINDOW (window));
+ WindowPickerApplet *applet;
+ GSettings *settings;
+
+ applet = WINDOW_PICKER_APPLET (user_data);
+ settings = applet->priv->settings;
+
+ if (applet->priv->preferences_dialog == NULL)
+ {
+ applet->priv->preferences_dialog = wp_preferences_dialog_new (settings);
+
+ g_signal_connect (applet->priv->preferences_dialog, "response",
+ G_CALLBACK (wp_preferences_dialog_response_cb), applet);
+ }
+
+ gtk_window_present (GTK_WINDOW (applet->priv->preferences_dialog));
}
static gboolean
@@ -390,6 +346,11 @@ window_picker_dispose (GObject *object)
applet->priv->about_dialog = NULL;
}
+ if (applet->priv->preferences_dialog != NULL) {
+ gtk_widget_destroy (applet->priv->preferences_dialog);
+ applet->priv->preferences_dialog = NULL;
+ }
+
G_OBJECT_CLASS (window_picker_applet_parent_class)->dispose (object);
}
diff --git a/windowpicker/src/wp-preferences-dialog.c b/windowpicker/src/wp-preferences-dialog.c
new file mode 100644
index 0000000..2883bde
--- /dev/null
+++ b/windowpicker/src/wp-preferences-dialog.c
@@ -0,0 +1,168 @@
+/*
+ * 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 "wp-preferences-dialog.h"
+
+#define GRESOURCE "/org/gnome/gnome-applets/window-picker/"
+
+struct _WpPreferencesDialog
+{
+ GtkDialog parent;
+
+ GSettings *settings;
+
+ GtkWidget *check_show_all_windows;
+ GtkWidget *check_show_application_title;
+ GtkWidget *check_show_home_title;
+ GtkWidget *check_icons_greyscale;
+ GtkWidget *check_expand_task_list;
+};
+
+enum
+{
+ PROP_0,
+ PROP_SETTINGS,
+ LAST_PROP
+};
+
+static GParamSpec *properties[LAST_PROP] = { NULL };
+
+G_DEFINE_TYPE (WpPreferencesDialog, wp_preferences_dialog, GTK_TYPE_DIALOG)
+
+static void
+wp_preferences_dialog_constructed (GObject *object)
+{
+ WpPreferencesDialog *dialog;
+
+ dialog = WP_PREFERENCES_DIALOG (object);
+
+ G_OBJECT_CLASS (wp_preferences_dialog_parent_class)->constructed (object);
+
+ g_settings_bind (dialog->settings, KEY_SHOW_ALL_WINDOWS,
+ dialog->check_show_all_windows, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
+ g_settings_bind (dialog->settings, KEY_SHOW_APPLICATION_TITLE,
+ dialog->check_show_application_title, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
+ g_settings_bind (dialog->settings, KEY_SHOW_HOME_TITLE,
+ dialog->check_show_home_title, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
+ g_settings_bind (dialog->settings, KEY_ICONS_GREYSCALE,
+ dialog->check_icons_greyscale, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
+ g_settings_bind (dialog->settings, KEY_EXPAND_TASK_LIST,
+ dialog->check_expand_task_list, "active",
+ G_SETTINGS_BIND_DEFAULT);
+}
+
+static void
+wp_preferences_dialog_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ WpPreferencesDialog *dialog;
+
+ dialog = WP_PREFERENCES_DIALOG (object);
+
+ switch (property_id)
+ {
+ case PROP_SETTINGS:
+ dialog->settings = g_value_dup_object (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+wp_preferences_dialog_dispose (GObject *object)
+{
+ WpPreferencesDialog *dialog;
+
+ dialog = WP_PREFERENCES_DIALOG (object);
+
+ g_clear_object (&dialog->settings);
+
+ G_OBJECT_CLASS (wp_preferences_dialog_parent_class)->dispose (object);
+}
+
+static void
+wp_preferences_dialog_class_init (WpPreferencesDialogClass *dialog_class)
+{
+ GObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+ const gchar *resource_name;
+
+ object_class = G_OBJECT_CLASS (dialog_class);
+ widget_class = GTK_WIDGET_CLASS (dialog_class);
+
+ object_class->constructed = wp_preferences_dialog_constructed;
+ object_class->set_property = wp_preferences_dialog_set_property;
+ object_class->dispose = wp_preferences_dialog_dispose;
+
+ properties[PROP_SETTINGS] =
+ g_param_spec_object ("settings",
+ "Settings",
+ "Settings",
+ G_TYPE_SETTINGS,
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
+
+ g_object_class_install_properties (object_class, LAST_PROP, properties);
+
+ resource_name = GRESOURCE "wp-preferences-dialog.ui";
+ gtk_widget_class_set_template_from_resource (widget_class, resource_name);
+
+ gtk_widget_class_bind_template_child (widget_class, WpPreferencesDialog,
+ check_show_all_windows);
+ gtk_widget_class_bind_template_child (widget_class, WpPreferencesDialog,
+ check_show_application_title);
+ gtk_widget_class_bind_template_child (widget_class, WpPreferencesDialog,
+ check_show_home_title);
+ gtk_widget_class_bind_template_child (widget_class, WpPreferencesDialog,
+ check_icons_greyscale);
+ gtk_widget_class_bind_template_child (widget_class, WpPreferencesDialog,
+ check_expand_task_list);
+}
+
+static void
+wp_preferences_dialog_init (WpPreferencesDialog *dialog)
+{
+ gtk_widget_init_template (GTK_WIDGET (dialog));
+}
+
+GtkWidget *
+wp_preferences_dialog_new (GSettings *settings)
+{
+ return g_object_new (WP_TYPE_PREFERENCES_DIALOG,
+ "settings", settings,
+ NULL);
+}
diff --git a/windowpicker/src/wp-preferences-dialog.h b/windowpicker/src/wp-preferences-dialog.h
new file mode 100644
index 0000000..3d9f6a7
--- /dev/null
+++ b/windowpicker/src/wp-preferences-dialog.h
@@ -0,0 +1,39 @@
+/*
+ * 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_PREFERENCES_DIALOG_H
+#define WP_PREFERENCES_DIALOG_H
+
+#include <gtk/gtk.h>
+
+#define KEY_SHOW_ALL_WINDOWS "show-all-windows"
+#define KEY_SHOW_APPLICATION_TITLE "show-application-title"
+#define KEY_SHOW_HOME_TITLE "show-home-title"
+#define KEY_ICONS_GREYSCALE "icons-greyscale"
+#define KEY_EXPAND_TASK_LIST "expand-task-list"
+
+G_BEGIN_DECLS
+
+#define WP_TYPE_PREFERENCES_DIALOG wp_preferences_dialog_get_type ()
+G_DECLARE_FINAL_TYPE (WpPreferencesDialog, wp_preferences_dialog,
+ WP, PREFERENCES_DIALOG, GtkDialog)
+
+GtkWidget *wp_preferences_dialog_new (GSettings *settings);
+
+G_END_DECLS
+
+#endif
diff --git a/windowpicker/src/wp-preferences-dialog.ui b/windowpicker/src/wp-preferences-dialog.ui
index 385e9f0..1f59b20 100644
--- a/windowpicker/src/wp-preferences-dialog.ui
+++ b/windowpicker/src/wp-preferences-dialog.ui
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.19.0 -->
+<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.16"/>
<template class="WpPreferencesDialog" parent="GtkDialog">
@@ -50,7 +50,7 @@
<property name="spacing">5</property>
<property name="homogeneous">True</property>
<child>
- <object class="GtkCheckButton" id="check_show_window_from_all_workspace">
+ <object class="GtkCheckButton" id="check_show_all_windows">
<property name="label" translatable="yes">Show windows from all workspaces</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -81,7 +81,7 @@ log out icon when on the desktop</property>
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="check_show_close_icon">
+ <object class="GtkCheckButton" id="check_show_application_title">
<property name="label" translatable="yes">Show the application title and close
icon</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -96,7 +96,7 @@ log out icon when on the desktop</property>
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="check_grey_window_icons">
+ <object class="GtkCheckButton" id="check_icons_greyscale">
<property name="label" translatable="yes">Grey out non-active window icons</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -111,7 +111,7 @@ log out icon when on the desktop</property>
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="check_expand_applet">
+ <object class="GtkCheckButton" id="check_expand_task_list">
<property name="label" translatable="yes">Automatically expand task list to use full
space</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -134,5 +134,8 @@ log out icon when on the desktop</property>
</child>
</object>
</child>
+ <action-widgets>
+ <action-widget response="0">button_close</action-widget>
+ </action-widgets>
</template>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]