[Xfce4-commits] <xfce4-settings:master> Store window and column sizes in xfconf.
Nick Schermer
noreply at xfce.org
Sun Jan 22 12:28:02 CET 2012
Updating branch refs/heads/master
to 63c6f29cb2bf01c87720e22e2b02ef814b7fa58a (commit)
from 6ff624afc831dcb13d783c8d919ed73e40fb3822 (commit)
commit 63c6f29cb2bf01c87720e22e2b02ef814b7fa58a
Author: Nick Schermer <nick at xfce.org>
Date: Sun Jan 22 12:25:31 2012 +0100
Store window and column sizes in xfconf.
This allows to use fixed_height mode as well, which
gives a nice performance boost.
dialogs/mime-settings/Makefile.am | 4 +-
dialogs/mime-settings/main.c | 12 ++++-
dialogs/mime-settings/xfce-mime-window.c | 86 +++++++++++++++++++++++++++--
3 files changed, 93 insertions(+), 9 deletions(-)
diff --git a/dialogs/mime-settings/Makefile.am b/dialogs/mime-settings/Makefile.am
index 29a79be..dd548a3 100644
--- a/dialogs/mime-settings/Makefile.am
+++ b/dialogs/mime-settings/Makefile.am
@@ -21,6 +21,7 @@ xfce4_mime_settings_CFLAGS = \
$(GIO_CFLAGS) \
$(GIO_UNIX_CFLAGS) \
$(LIBXFCE4UI_CFLAGS) \
+ $(XFCONF_CFLAGS) \
$(PLATFORM_CFLAGS)
xfce4_mime_settings_LDFLAGS = \
@@ -31,7 +32,8 @@ xfce4_mime_settings_LDADD = \
$(GTK_LIBS) \
$(LIBXFCE4UI_LIBS) \
$(GIO_LIBS) \
- $(GIO_UNIX_LIBS)
+ $(GIO_UNIX_LIBS) \
+ $(XFCONF_LIBS)
desktopdir = $(datadir)/applications
desktop_in_files = xfce4-mime-settings.desktop.in
diff --git a/dialogs/mime-settings/main.c b/dialogs/mime-settings/main.c
index 02014f2..bddf6d7 100644
--- a/dialogs/mime-settings/main.c
+++ b/dialogs/mime-settings/main.c
@@ -28,6 +28,7 @@
#include <gtk/gtk.h>
#include <libxfce4util/libxfce4util.h>
+#include <xfconf/xfconf.h>
#include "xfce-mime-window.h"
@@ -76,7 +77,7 @@ main (gint argc, gchar **argv)
if (G_UNLIKELY (opt_version))
{
g_print ("%s %s (Xfce %s)\n\n", G_LOG_DOMAIN, PACKAGE_VERSION, xfce_version_string ());
- g_print ("%s\n", "Copyright (c) 2008-2011");
+ g_print ("%s\n", "Copyright (c) 2008-2012");
g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved."));
g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
g_print ("\n");
@@ -84,13 +85,20 @@ main (gint argc, gchar **argv)
return EXIT_SUCCESS;
}
+ if (!xfconf_init (&error))
+ {
+ g_critical ("Failed to initialize xfconf: %s", error->message);
+ g_error_free (error);
+ }
+
window = g_object_new (XFCE_TYPE_MIME_WINDOW, NULL);
- gtk_window_set_default_size (GTK_WINDOW (window), 550, 400);
g_signal_connect (G_OBJECT (window), "response",
G_CALLBACK (gtk_main_quit), NULL);
gtk_window_present (GTK_WINDOW (window));
gtk_main ();
+ xfconf_shutdown ();
+
return EXIT_SUCCESS;
}
diff --git a/dialogs/mime-settings/xfce-mime-window.c b/dialogs/mime-settings/xfce-mime-window.c
index a51316b..3842624 100644
--- a/dialogs/mime-settings/xfce-mime-window.c
+++ b/dialogs/mime-settings/xfce-mime-window.c
@@ -29,6 +29,7 @@
#include <libxfce4util/libxfce4util.h>
#include <libxfce4ui/libxfce4ui.h>
#include <gio/gdesktopappinfo.h>
+#include <xfconf/xfconf.h>
#include "xfce-mime-window.h"
#include "xfce-mime-chooser.h"
@@ -36,6 +37,8 @@
static void xfce_mime_window_finalize (GObject *object);
+static gboolean xfce_mime_window_delete_event (GtkWidget *widget,
+ GdkEventAny *event);
static gint xfce_mime_window_mime_model (XfceMimeWindow *window);
static void xfce_mime_window_filter_changed (GtkEntry *entry,
XfceMimeWindow *window);
@@ -72,6 +75,8 @@ struct _XfceMimeWindow
{
XfceTitledDialog __parent__;
+ XfconfChannel *channel;
+
GtkWidget *treeview;
PangoAttrList *attrs_bold;
@@ -124,11 +129,15 @@ G_DEFINE_TYPE (XfceMimeWindow, xfce_mime_window, XFCE_TYPE_TITLED_DIALOG)
static void
xfce_mime_window_class_init (XfceMimeWindowClass *klass)
{
- GObjectClass *gobject_class;
+ GObjectClass *gobject_class;
+ GtkWidgetClass *gtkwidget_class;
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = xfce_mime_window_finalize;
+ gtkwidget_class = GTK_WIDGET_CLASS (klass);
+ gtkwidget_class->delete_event = xfce_mime_window_delete_event;
+
gtk_rc_parse_string ("style \"mime-statusbar-internal\" {\n"
" GtkStatusbar::shadow-type = GTK_SHADOW_NONE\n"
"}\n"
@@ -155,6 +164,8 @@ xfce_mime_window_init (XfceMimeWindow *window)
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
+ window->channel = xfconf_channel_new ("xfce4-mime-settings");
+
window->attrs_bold = pango_attr_list_new ();
pango_attr_list_insert (window->attrs_bold, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
@@ -166,6 +177,11 @@ xfce_mime_window_init (XfceMimeWindow *window)
xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (window),
_("Associate applications with MIME types"));
+ /* restore old user size */
+ gtk_window_set_default_size (GTK_WINDOW (window),
+ xfconf_channel_get_int (window->channel, "/last/window-width", 550),
+ xfconf_channel_get_int (window->channel, "/last/window-height", 400));
+
/* don't act like a dialog, hide the button box */
area = gtk_dialog_get_action_area (GTK_DIALOG (window));
gtk_widget_hide (area);
@@ -225,6 +241,7 @@ xfce_mime_window_init (XfceMimeWindow *window)
treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (window->filter_model));
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE);
gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW (treeview), TRUE);
+ gtk_tree_view_set_fixed_height_mode (GTK_TREE_VIEW (treeview), TRUE);
gtk_tree_view_set_enable_search (GTK_TREE_VIEW (treeview), FALSE);
gtk_container_add (GTK_CONTAINER (scroll), treeview);
gtk_widget_show (treeview);
@@ -241,16 +258,17 @@ xfce_mime_window_init (XfceMimeWindow *window)
gtk_tree_view_column_set_clickable (column, TRUE);
gtk_tree_view_column_set_sort_indicator (column, TRUE);
gtk_tree_view_column_set_resizable (column, TRUE);
+ gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
g_signal_connect (G_OBJECT (column), "clicked",
G_CALLBACK (xfce_mime_window_column_clicked), window);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
- /* HACK, wont work in gtk3 */
- /* give the first column some initial size that doesn't restrict anything
- * later. Expanding this column will resize the view when a setting
- * is changed */
- column->resized_width = 300;
+ /* HACK */
+ /* https://bugzilla.gnome.org/show_bug.cgi?id=668428 */
column->use_resized_width = TRUE;
+ column->resized_width = xfconf_channel_get_int (window->channel,
+ "/last/mime-width",
+ 300);
renderer = gtk_cell_renderer_pixbuf_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, FALSE);
@@ -269,10 +287,17 @@ xfce_mime_window_init (XfceMimeWindow *window)
gtk_tree_view_column_set_title (column, _("Status"));
gtk_tree_view_column_set_clickable (column, TRUE);
gtk_tree_view_column_set_resizable (column, TRUE);
+ gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
g_signal_connect (G_OBJECT (column), "clicked",
G_CALLBACK (xfce_mime_window_column_clicked), window);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+ /* HACK */
+ column->use_resized_width = TRUE;
+ column->resized_width = xfconf_channel_get_int (window->channel,
+ "/last/status-width",
+ 75);
+
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (column), renderer,
@@ -283,10 +308,17 @@ xfce_mime_window_init (XfceMimeWindow *window)
gtk_tree_view_column_set_title (column, _("Default Application"));
gtk_tree_view_column_set_clickable (column, TRUE);
gtk_tree_view_column_set_resizable (column, TRUE);
+ gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
g_signal_connect (G_OBJECT (column), "clicked",
G_CALLBACK (xfce_mime_window_column_clicked), window);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+ /* HACK */
+ column->use_resized_width = TRUE;
+ column->resized_width = xfconf_channel_get_int (window->channel,
+ "/last/default-width",
+ 100);
+
renderer = gtk_cell_renderer_combo_new ();
g_signal_connect (G_OBJECT (renderer), "editing-started",
G_CALLBACK (xfce_mime_window_combo_populate), window);
@@ -312,6 +344,7 @@ xfce_mime_window_finalize (GObject *object)
g_object_unref (G_OBJECT (window->filter_model));
g_object_unref (G_OBJECT (window->mime_model));
+ g_object_unref (G_OBJECT (window->channel));
pango_attr_list_unref (window->attrs_bold);
@@ -320,6 +353,47 @@ xfce_mime_window_finalize (GObject *object)
+static gboolean
+xfce_mime_window_delete_event (GtkWidget *widget,
+ GdkEventAny *event)
+{
+ XfceMimeWindow *window = XFCE_MIME_WINDOW (widget);
+ gint width, height;
+ GtkTreeViewColumn *column;
+ guint i;
+ const gchar *columns[] = { "mime", "status", "default" };
+ gchar prop[32];
+ GdkWindowState state;
+
+ g_return_val_if_fail (XFCONF_IS_CHANNEL (window->channel), FALSE);
+
+ /* don't save the state for full-screen windows */
+ state = gdk_window_get_state (GTK_WIDGET (window)->window);
+ if ((state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)) == 0)
+ {
+ /* save window size */
+ gtk_window_get_size (GTK_WINDOW (widget), &width, &height);
+ xfconf_channel_set_int (window->channel, "/last/window-width", width),
+ xfconf_channel_set_int (window->channel, "/last/window-height", height);
+
+ /* save column positions */
+ for (i = 0; i < G_N_ELEMENTS (columns); i++)
+ {
+ column = gtk_tree_view_get_column (GTK_TREE_VIEW (window->treeview), i);
+ g_snprintf (prop, sizeof (prop), "/last/%s-width", columns[i]);
+ xfconf_channel_set_int (window->channel, prop,
+ gtk_tree_view_column_get_width (column));
+ }
+ }
+
+ if (GTK_WIDGET_CLASS (xfce_mime_window_parent_class)->delete_event != NULL)
+ return (*GTK_WIDGET_CLASS (xfce_mime_window_parent_class)->delete_event) (widget, event);
+ else
+ return FALSE;
+}
+
+
+
static GHashTable *
xfce_mime_window_mime_user (void)
{
More information about the Xfce4-commits
mailing list