From 0e064de971dd8b5e565558cd14efdca8ae4dbcb0 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 4 Sep 2011 11:45:25 -0400 Subject: EAttachmentPaned: Add "resize-toplevel" property. Similiar to the new GtkExpander:resize-toplevel property in GTK+ 3.2, but adapted to the fact that EAttachmentPaned's expander has no direct child widget, and instead acts on the child widget in the lower pane. CompEditor now uses this to fix the weird vertical resizing behavior when its attachment bar is expanded and then collapsed again. --- widgets/misc/e-attachment-paned.c | 122 ++++++++++++++++++++++++++++++++++---- widgets/misc/e-attachment-paned.h | 5 ++ 2 files changed, 114 insertions(+), 13 deletions(-) (limited to 'widgets') diff --git a/widgets/misc/e-attachment-paned.c b/widgets/misc/e-attachment-paned.c index b842aecf8d..2903c84227 100644 --- a/widgets/misc/e-attachment-paned.c +++ b/widgets/misc/e-attachment-paned.c @@ -53,7 +53,8 @@ struct _EAttachmentPanedPrivate { GtkWidget *content_area; gint active_view; - guint expanded : 1; + gboolean expanded; + gboolean resize_toplevel; }; enum { @@ -61,7 +62,8 @@ enum { PROP_ACTIVE_VIEW, PROP_DRAGGING, PROP_EDITABLE, - PROP_EXPANDED + PROP_EXPANDED, + PROP_RESIZE_TOPLEVEL }; /* Forward Declarations */ @@ -87,6 +89,9 @@ attachment_paned_notify_cb (EAttachmentPaned *paned, GParamSpec *pspec, GtkExpander *expander) { + GtkAllocation toplevel_allocation; + GtkWidget *toplevel; + GtkWidget *child; GtkLabel *label; const gchar *text; @@ -99,6 +104,47 @@ attachment_paned_notify_cb (EAttachmentPaned *paned, text = _("Show Attachment _Bar"); gtk_label_set_text_with_mnemonic (label, text); + + /* Resize the top-level window if required conditions are met. + * This is based on gtk_expander_resize_toplevel(), but adapted + * to the fact our GtkExpander has no direct child widget. */ + + if (!e_attachment_paned_get_resize_toplevel (paned)) + return; + + if (!gtk_widget_get_realized (GTK_WIDGET (paned))) + return; + + child = gtk_paned_get_child2 (GTK_PANED (paned)); + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned)); + + if (toplevel == NULL) + return; + + if (!gtk_widget_get_realized (GTK_WIDGET (toplevel))) + return; + + gtk_widget_get_allocation (toplevel, &toplevel_allocation); + + if (gtk_expander_get_expanded (expander)) { + GtkRequisition child_requisition; + + gtk_widget_get_preferred_size ( + child, &child_requisition, NULL); + + toplevel_allocation.height += child_requisition.height; + } else { + GtkAllocation child_allocation; + + gtk_widget_get_allocation (child, &child_allocation); + + toplevel_allocation.height -= child_allocation.height; + } + + gtk_window_resize ( + GTK_WINDOW (toplevel), + toplevel_allocation.width, + toplevel_allocation.height); } static void @@ -177,6 +223,12 @@ attachment_paned_set_property (GObject *object, E_ATTACHMENT_PANED (object), g_value_get_boolean (value)); return; + + case PROP_RESIZE_TOPLEVEL: + e_attachment_paned_set_resize_toplevel ( + E_ATTACHMENT_PANED (object), + g_value_get_boolean (value)); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -191,25 +243,36 @@ attachment_paned_get_property (GObject *object, switch (property_id) { case PROP_ACTIVE_VIEW: g_value_set_int ( - value, e_attachment_paned_get_active_view ( + value, + e_attachment_paned_get_active_view ( E_ATTACHMENT_PANED (object))); return; case PROP_DRAGGING: g_value_set_boolean ( - value, e_attachment_view_get_dragging ( + value, + e_attachment_view_get_dragging ( E_ATTACHMENT_VIEW (object))); return; case PROP_EDITABLE: g_value_set_boolean ( - value, e_attachment_view_get_editable ( + value, + e_attachment_view_get_editable ( E_ATTACHMENT_VIEW (object))); return; case PROP_EXPANDED: g_value_set_boolean ( - value, e_attachment_paned_get_expanded ( + value, + e_attachment_paned_get_expanded ( + E_ATTACHMENT_PANED (object))); + return; + + case PROP_RESIZE_TOPLEVEL: + g_value_set_boolean ( + value, + e_attachment_paned_get_resize_toplevel ( E_ATTACHMENT_PANED (object))); return; } @@ -494,7 +557,14 @@ e_attachment_paned_class_init (EAttachmentPanedClass *class) NUM_VIEWS, 0, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); + + g_object_class_override_property ( + object_class, PROP_DRAGGING, "dragging"); + + g_object_class_override_property ( + object_class, PROP_EDITABLE, "editable"); g_object_class_install_property ( object_class, @@ -505,13 +575,20 @@ e_attachment_paned_class_init (EAttachmentPanedClass *class) NULL, FALSE, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_override_property ( - object_class, PROP_DRAGGING, "dragging"); + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); - g_object_class_override_property ( - object_class, PROP_EDITABLE, "editable"); + g_object_class_install_property ( + object_class, + PROP_RESIZE_TOPLEVEL, + g_param_spec_boolean ( + "resize-toplevel", + "Resize-Toplevel", + NULL, + FALSE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); } static void @@ -768,6 +845,25 @@ e_attachment_paned_set_expanded (EAttachmentPaned *paned, g_object_notify (G_OBJECT (paned), "expanded"); } +gboolean +e_attachment_paned_get_resize_toplevel (EAttachmentPaned *paned) +{ + g_return_val_if_fail (E_IS_ATTACHMENT_PANED (paned), FALSE); + + return paned->priv->resize_toplevel; +} + +void +e_attachment_paned_set_resize_toplevel (EAttachmentPaned *paned, + gboolean resize_toplevel) +{ + g_return_if_fail (E_IS_ATTACHMENT_PANED (paned)); + + paned->priv->resize_toplevel = resize_toplevel; + + g_object_notify (G_OBJECT (paned), "resize-toplevel"); +} + void e_attachment_paned_drag_data_received (EAttachmentPaned *paned, GdkDragContext *context, diff --git a/widgets/misc/e-attachment-paned.h b/widgets/misc/e-attachment-paned.h index a9022a7bc6..7daffd5508 100644 --- a/widgets/misc/e-attachment-paned.h +++ b/widgets/misc/e-attachment-paned.h @@ -70,6 +70,11 @@ void e_attachment_paned_set_active_view gboolean e_attachment_paned_get_expanded (EAttachmentPaned *paned); void e_attachment_paned_set_expanded (EAttachmentPaned *paned, gboolean expanded); +gboolean e_attachment_paned_get_resize_toplevel + (EAttachmentPaned *paned); +void e_attachment_paned_set_resize_toplevel + (EAttachmentPaned *paned, + gboolean resize_toplevel); void e_attachment_paned_drag_data_received (EAttachmentPaned *paned, GdkDragContext *context, -- cgit v1.2.3 From ef05d73b0a06cfc5eaf1a74c7b5c25134d81e328 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 4 Sep 2011 13:04:55 -0400 Subject: Remove EHintedEntry. GtkEntry in GTK+ 3.2 now provides this functionality through the new GtkEntry:placeholder-text property. --- widgets/misc/Makefile.am | 2 - widgets/misc/e-hinted-entry.c | 293 ------------------------------------------ widgets/misc/e-hinted-entry.h | 73 ----------- 3 files changed, 368 deletions(-) delete mode 100644 widgets/misc/e-hinted-entry.c delete mode 100644 widgets/misc/e-hinted-entry.h (limited to 'widgets') diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am index cd5cada041..79bc14bcbe 100644 --- a/widgets/misc/Makefile.am +++ b/widgets/misc/Makefile.am @@ -38,7 +38,6 @@ widgetsinclude_HEADERS = \ e-contact-marker.h \ e-dateedit.h \ e-focus-tracker.h \ - e-hinted-entry.h \ e-image-chooser.h \ e-import-assistant.h \ e-map.h \ @@ -123,7 +122,6 @@ libemiscwidgets_la_SOURCES = \ e-contact-marker.c \ e-dateedit.c \ e-focus-tracker.c \ - e-hinted-entry.c \ e-image-chooser.c \ e-import-assistant.c \ e-map.c \ diff --git a/widgets/misc/e-hinted-entry.c b/widgets/misc/e-hinted-entry.c deleted file mode 100644 index 21a4fff58e..0000000000 --- a/widgets/misc/e-hinted-entry.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * e-hinted-entry.c - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "e-hinted-entry.h" - -struct _EHintedEntryPrivate { - gchar *hint; - guint hint_shown : 1; -}; - -enum { - PROP_0, - PROP_HINT, - PROP_HINT_SHOWN -}; - -G_DEFINE_TYPE ( - EHintedEntry, - e_hinted_entry, - GTK_TYPE_ENTRY) - -static void -hinted_entry_show_hint (EHintedEntry *entry) -{ - GtkStyle *style; - const GdkColor *color; - const gchar *hint; - - entry->priv->hint_shown = TRUE; - - hint = e_hinted_entry_get_hint (entry); - gtk_entry_set_text (GTK_ENTRY (entry), hint); - - style = gtk_widget_get_style (GTK_WIDGET (entry)); - color = &style->text[GTK_STATE_INSENSITIVE]; - gtk_widget_modify_text (GTK_WIDGET (entry), GTK_STATE_NORMAL, color); - - g_object_notify (G_OBJECT (entry), "hint-shown"); -} - -static void -hinted_entry_show_text (EHintedEntry *entry, - const gchar *text) -{ - entry->priv->hint_shown = FALSE; - - gtk_entry_set_text (GTK_ENTRY (entry), text); - - gtk_widget_modify_text (GTK_WIDGET (entry), GTK_STATE_NORMAL, NULL); - - g_object_notify (G_OBJECT (entry), "hint-shown"); -} - -static void -hinted_entry_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_HINT: - e_hinted_entry_set_hint ( - E_HINTED_ENTRY (object), - g_value_get_string (value)); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -hinted_entry_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_HINT: - g_value_set_string ( - value, e_hinted_entry_get_hint ( - E_HINTED_ENTRY (object))); - return; - - case PROP_HINT_SHOWN: - g_value_set_boolean ( - value, e_hinted_entry_get_hint_shown ( - E_HINTED_ENTRY (object))); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -hinted_entry_finalize (GObject *object) -{ - EHintedEntryPrivate *priv; - - priv = E_HINTED_ENTRY (object)->priv; - - g_free (priv->hint); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (e_hinted_entry_parent_class)->finalize (object); -} - -static void -hinted_entry_grab_focus (GtkWidget *widget) -{ - GtkWidgetClass *chain_class; - - /* We don't want hints to be selected so we chain to - * the GtkEntry parent if we have a hint set */ - chain_class = e_hinted_entry_parent_class; - if (e_hinted_entry_get_hint_shown (E_HINTED_ENTRY (widget))) - chain_class = g_type_class_peek_parent (chain_class); - - /* Chain up to parent's grab_focus() method. */ - GTK_WIDGET_CLASS (chain_class)->grab_focus (widget); -} - -static gboolean -hinted_entry_focus_in_event (GtkWidget *widget, - GdkEventFocus *event) -{ - EHintedEntry *entry = E_HINTED_ENTRY (widget); - - if (e_hinted_entry_get_hint_shown (entry)) - hinted_entry_show_text (entry, ""); - - /* Chain up to parent's focus_in_event() method. */ - return GTK_WIDGET_CLASS (e_hinted_entry_parent_class)-> - focus_in_event (widget, event); -} - -static gboolean -hinted_entry_focus_out_event (GtkWidget *widget, - GdkEventFocus *event) -{ - EHintedEntry *entry = E_HINTED_ENTRY (widget); - const gchar *text; - - text = e_hinted_entry_get_text (entry); - - if (text == NULL || *text == '\0') - hinted_entry_show_hint (E_HINTED_ENTRY (widget)); - - /* Chain up to parent's focus_out_event() method. */ - return GTK_WIDGET_CLASS (e_hinted_entry_parent_class)-> - focus_out_event (widget, event); -} - -static void -e_hinted_entry_class_init (EHintedEntryClass *class) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - - g_type_class_add_private (class, sizeof (EHintedEntryPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->set_property = hinted_entry_set_property; - object_class->get_property = hinted_entry_get_property; - object_class->finalize = hinted_entry_finalize; - - widget_class = GTK_WIDGET_CLASS (class); - widget_class->grab_focus = hinted_entry_grab_focus; - widget_class->focus_in_event = hinted_entry_focus_in_event; - widget_class->focus_out_event = hinted_entry_focus_out_event; - - g_object_class_install_property ( - object_class, - PROP_HINT, - g_param_spec_string ( - "hint", - "Hint", - NULL, - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_HINT_SHOWN, - g_param_spec_boolean ( - "hint-shown", - "Hint Shown", - NULL, - FALSE, - G_PARAM_READABLE)); -} - -static void -e_hinted_entry_init (EHintedEntry *entry) -{ - entry->priv = G_TYPE_INSTANCE_GET_PRIVATE ( - entry, E_TYPE_HINTED_ENTRY, EHintedEntryPrivate); - entry->priv->hint = g_strdup (""); /* hint must never be NULL */ - hinted_entry_show_hint (entry); -} - -GtkWidget * -e_hinted_entry_new (void) -{ - return g_object_new (E_TYPE_HINTED_ENTRY, NULL); -} - -const gchar * -e_hinted_entry_get_hint (EHintedEntry *entry) -{ - g_return_val_if_fail (E_IS_HINTED_ENTRY (entry), NULL); - - return entry->priv->hint; -} - -void -e_hinted_entry_set_hint (EHintedEntry *entry, - const gchar *hint) -{ - g_return_if_fail (E_IS_HINTED_ENTRY (entry)); - - if (hint == NULL) - hint = ""; - - g_free (entry->priv->hint); - entry->priv->hint = g_strdup (hint); - - if (e_hinted_entry_get_hint_shown (entry)) - gtk_entry_set_text (GTK_ENTRY (entry), hint); - - g_object_notify (G_OBJECT (entry), "hint"); -} - -gboolean -e_hinted_entry_get_hint_shown (EHintedEntry *entry) -{ - g_return_val_if_fail (E_IS_HINTED_ENTRY (entry), FALSE); - - return entry->priv->hint_shown; -} - -const gchar * -e_hinted_entry_get_text (EHintedEntry *entry) -{ - const gchar *text = ""; - - /* XXX This clumsily overrides gtk_entry_get_text(). */ - - g_return_val_if_fail (E_IS_HINTED_ENTRY (entry), NULL); - - if (!e_hinted_entry_get_hint_shown (entry)) - text = gtk_entry_get_text (GTK_ENTRY (entry)); - - return text; -} - -void -e_hinted_entry_set_text (EHintedEntry *entry, - const gchar *text) -{ - /* XXX This clumsily overrides gtk_entry_set_text(). */ - - g_return_if_fail (E_IS_HINTED_ENTRY (entry)); - - if (text == NULL) - text = ""; - - if (*text == '\0' && !gtk_widget_has_focus (GTK_WIDGET (entry))) - hinted_entry_show_hint (entry); - else - hinted_entry_show_text (entry, text); -} diff --git a/widgets/misc/e-hinted-entry.h b/widgets/misc/e-hinted-entry.h deleted file mode 100644 index 02379d4ad7..0000000000 --- a/widgets/misc/e-hinted-entry.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * e-hinted-entry.h - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_HINTED_ENTRY_H -#define E_HINTED_ENTRY_H - -#include - -/* Standard GObject macros */ -#define E_TYPE_HINTED_ENTRY \ - (e_hinted_entry_get_type ()) -#define E_HINTED_ENTRY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_HINTED_ENTRY, EHintedEntry)) -#define E_HINTED_ENTRY_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_HINTED_ENTRY, EHintedEntryClass)) -#define E_IS_HINTED_ENTRY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_HINTED_ENTRY)) -#define E_IS_HINTED_ENTRY_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_HINTED_ENTRY)) -#define E_HINTED_ENTRY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_HINTED_ENTRY, EHintedEntryClass)) - -G_BEGIN_DECLS - -typedef struct _EHintedEntry EHintedEntry; -typedef struct _EHintedEntryClass EHintedEntryClass; -typedef struct _EHintedEntryPrivate EHintedEntryPrivate; - -struct _EHintedEntry { - GtkEntry parent; - EHintedEntryPrivate *priv; -}; - -struct _EHintedEntryClass { - GtkEntryClass parent_class; -}; - -GType e_hinted_entry_get_type (void); -GtkWidget * e_hinted_entry_new (void); -const gchar * e_hinted_entry_get_hint (EHintedEntry *entry); -void e_hinted_entry_set_hint (EHintedEntry *entry, - const gchar *hint); -gboolean e_hinted_entry_get_hint_shown (EHintedEntry *entry); -const gchar * e_hinted_entry_get_text (EHintedEntry *entry); -void e_hinted_entry_set_text (EHintedEntry *entry, - const gchar *text); - -G_END_DECLS - -#endif /* E_HINTED_ENTRY_H */ -- cgit v1.2.3 From 938505da180727fbc56b68b80851adc3cf676523 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 4 Sep 2011 14:30:36 -0400 Subject: Let GtkFileChooser track its own last-used-folder. GtkFileChooser in GTK+ 3.2 now keeps track of the last-used-folder itself, even across applications, so get out of its way and let it handle it. --- widgets/misc/e-attachment-store.c | 123 +------------------------------------- widgets/misc/e-attachment-store.h | 8 --- 2 files changed, 2 insertions(+), 129 deletions(-) (limited to 'widgets') diff --git a/widgets/misc/e-attachment-store.c b/widgets/misc/e-attachment-store.c index 691fd518b8..2670369a51 100644 --- a/widgets/misc/e-attachment-store.c +++ b/widgets/misc/e-attachment-store.c @@ -34,14 +34,12 @@ struct _EAttachmentStorePrivate { GHashTable *attachment_index; - gchar *current_folder_uri; guint ignore_row_changed : 1; }; enum { PROP_0, - PROP_CURRENT_FOLDER_URI, PROP_NUM_ATTACHMENTS, PROP_NUM_LOADING, PROP_TOTAL_SIZE @@ -52,23 +50,6 @@ G_DEFINE_TYPE ( e_attachment_store, GTK_TYPE_LIST_STORE) -static void -attachment_store_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_CURRENT_FOLDER_URI: - e_attachment_store_set_current_folder_uri ( - E_ATTACHMENT_STORE (object), - g_value_get_string (value)); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - static void attachment_store_get_property (GObject *object, guint property_id, @@ -76,13 +57,6 @@ attachment_store_get_property (GObject *object, GParamSpec *pspec) { switch (property_id) { - case PROP_CURRENT_FOLDER_URI: - g_value_set_string ( - value, - e_attachment_store_get_current_folder_uri ( - E_ATTACHMENT_STORE (object))); - return; - case PROP_NUM_ATTACHMENTS: g_value_set_uint ( value, @@ -126,27 +100,10 @@ attachment_store_finalize (GObject *object) g_hash_table_destroy (priv->attachment_index); - g_free (priv->current_folder_uri); - /* Chain up to parent's finalize() method. */ G_OBJECT_CLASS (e_attachment_store_parent_class)->finalize (object); } -static void -attachment_store_constructed (GObject *object) -{ - GConfBridge *bridge; - const gchar *key; - - bridge = gconf_bridge_get (); - - key = "/apps/evolution/shell/file_chooser_folder"; - gconf_bridge_bind_property (bridge, key, object, "current-folder-uri"); - - /* Chain up to parent's constructed() method. */ - G_OBJECT_CLASS (e_attachment_store_parent_class)->constructed (object); -} - static void e_attachment_store_class_init (EAttachmentStoreClass *class) { @@ -155,22 +112,9 @@ e_attachment_store_class_init (EAttachmentStoreClass *class) g_type_class_add_private (class, sizeof (EAttachmentStorePrivate)); object_class = G_OBJECT_CLASS (class); - object_class->set_property = attachment_store_set_property; object_class->get_property = attachment_store_get_property; object_class->dispose = attachment_store_dispose; object_class->finalize = attachment_store_finalize; - object_class->constructed = attachment_store_constructed; - - g_object_class_install_property ( - object_class, - PROP_CURRENT_FOLDER_URI, - g_param_spec_string ( - "current-folder-uri", - "Current Folder URI", - NULL, - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); g_object_class_install_property ( object_class, @@ -409,34 +353,6 @@ e_attachment_store_get_attachments (EAttachmentStore *store) return g_list_reverse (list); } -const gchar * -e_attachment_store_get_current_folder_uri (EAttachmentStore *store) -{ - g_return_val_if_fail (E_IS_ATTACHMENT_STORE (store), NULL); - - return store->priv->current_folder_uri; -} - -void -e_attachment_store_set_current_folder_uri (EAttachmentStore *store, - const gchar *current_folder_uri) -{ - gchar *allocated; - - g_return_if_fail (E_IS_ATTACHMENT_STORE (store)); - - if (current_folder_uri == NULL) { - const gchar *home_dir = g_get_home_dir (); - allocated = g_filename_to_uri (home_dir, NULL, NULL); - } else - allocated = g_strdup (current_folder_uri); - - g_free (store->priv->current_folder_uri); - store->priv->current_folder_uri = allocated; - - g_object_notify (G_OBJECT (store), "current-folder-uri"); -} - guint e_attachment_store_get_num_attachments (EAttachmentStore *store) { @@ -493,41 +409,6 @@ e_attachment_store_get_total_size (EAttachmentStore *store) return total_size; } -gint -e_attachment_store_run_file_chooser_dialog (EAttachmentStore *store, - GtkWidget *dialog) -{ - GtkFileChooser *file_chooser; - gint response = GTK_RESPONSE_NONE; - const gchar *current_uri; - gboolean update_folder; - - g_return_val_if_fail (E_IS_ATTACHMENT_STORE (store), response); - g_return_val_if_fail (GTK_IS_FILE_CHOOSER_DIALOG (dialog), response); - - file_chooser = GTK_FILE_CHOOSER (dialog); - current_uri = e_attachment_store_get_current_folder_uri (store); - gtk_file_chooser_set_current_folder_uri (file_chooser, current_uri); - - response = gtk_dialog_run (GTK_DIALOG (dialog)); - - update_folder = - (response == GTK_RESPONSE_ACCEPT) || - (response == GTK_RESPONSE_OK) || - (response == GTK_RESPONSE_YES) || - (response == GTK_RESPONSE_APPLY); - - if (update_folder) { - gchar *uri; - - uri = gtk_file_chooser_get_current_folder_uri (file_chooser); - e_attachment_store_set_current_folder_uri (store, uri); - g_free (uri); - } - - return response; -} - void e_attachment_store_run_load_dialog (EAttachmentStore *store, GtkWindow *parent) @@ -560,7 +441,7 @@ e_attachment_store_run_load_dialog (EAttachmentStore *store, gtk_file_chooser_set_extra_widget (file_chooser, option); gtk_widget_show (option); - response = e_attachment_store_run_file_chooser_dialog (store, dialog); + response = gtk_dialog_run (GTK_DIALOG (dialog)); if (response != GTK_RESPONSE_OK) goto exit; @@ -643,7 +524,7 @@ e_attachment_store_run_save_dialog (EAttachmentStore *store, gtk_file_chooser_set_current_name (file_chooser, name); } - response = e_attachment_store_run_file_chooser_dialog (store, dialog); + response = gtk_dialog_run (GTK_DIALOG (dialog)); if (response == GTK_RESPONSE_OK) destination = gtk_file_chooser_get_file (file_chooser); diff --git a/widgets/misc/e-attachment-store.h b/widgets/misc/e-attachment-store.h index cdf33f507a..7309dd9415 100644 --- a/widgets/misc/e-attachment-store.h +++ b/widgets/misc/e-attachment-store.h @@ -87,20 +87,12 @@ void e_attachment_store_add_to_multipart const gchar *default_charset); GList * e_attachment_store_get_attachments (EAttachmentStore *store); -const gchar * e_attachment_store_get_current_folder_uri - (EAttachmentStore *store); -void e_attachment_store_set_current_folder_uri - (EAttachmentStore *store, - const gchar *current_folder); guint e_attachment_store_get_num_attachments (EAttachmentStore *store); guint e_attachment_store_get_num_loading (EAttachmentStore *store); goffset e_attachment_store_get_total_size (EAttachmentStore *store); -gint e_attachment_store_run_file_chooser_dialog - (EAttachmentStore *store, - GtkWidget *dialog); void e_attachment_store_run_load_dialog (EAttachmentStore *store, GtkWindow *parent); -- cgit v1.2.3 From 126aa2398abc1bbab0fd0cd76fda5042cc83fe76 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Thu, 6 Oct 2011 09:35:14 -0400 Subject: Prefer g_simple_async_result_take_error(). Slightly more efficient and convenient than: g_simple_async_result_set_from_error (simple, error); g_error_free (error); One less GError to copy and destroy. --- widgets/misc/e-attachment-store.c | 18 ++++++------------ widgets/misc/e-attachment.c | 15 +++++---------- 2 files changed, 11 insertions(+), 22 deletions(-) (limited to 'widgets') diff --git a/widgets/misc/e-attachment-store.c b/widgets/misc/e-attachment-store.c index 2670369a51..8c808d9731 100644 --- a/widgets/misc/e-attachment-store.c +++ b/widgets/misc/e-attachment-store.c @@ -654,10 +654,8 @@ attachment_store_get_uris_save_cb (EAttachment *attachment, if (error == NULL) g_simple_async_result_set_op_res_gpointer (simple, uris, NULL); - else { - g_simple_async_result_set_from_error (simple, error); - g_error_free (error); - } + else + g_simple_async_result_take_error (simple, error); g_simple_async_result_complete (simple); @@ -877,10 +875,8 @@ attachment_store_load_ready_cb (EAttachment *attachment, if (error == NULL) g_simple_async_result_set_op_res_gboolean (simple, TRUE); - else { - g_simple_async_result_set_from_error (simple, error); - g_error_free (error); - } + else + g_simple_async_result_take_error (simple, error); g_simple_async_result_complete (simple); @@ -1158,21 +1154,19 @@ attachment_store_save_cb (EAttachment *attachment, save_context->error = NULL; simple = save_context->simple; - g_simple_async_result_set_from_error (simple, error); + g_simple_async_result_take_error (simple, error); g_simple_async_result_complete (simple); attachment_store_save_context_free (save_context); - g_error_free (error); return; } if (error != NULL) { simple = save_context->simple; - g_simple_async_result_set_from_error (simple, error); + g_simple_async_result_take_error (simple, error); g_simple_async_result_complete (simple); attachment_store_save_context_free (save_context); - g_error_free (error); return; } diff --git a/widgets/misc/e-attachment.c b/widgets/misc/e-attachment.c index ccd135e5a0..4174fe92a5 100644 --- a/widgets/misc/e-attachment.c +++ b/widgets/misc/e-attachment.c @@ -1517,9 +1517,8 @@ attachment_load_check_for_error (LoadContext *load_context, return FALSE; simple = load_context->simple; - g_simple_async_result_set_from_error (simple, error); + g_simple_async_result_take_error (simple, error); g_simple_async_result_complete (simple); - g_error_free (error); attachment_load_context_free (load_context); @@ -2021,9 +2020,8 @@ attachment_open_check_for_error (OpenContext *open_context, return FALSE; simple = open_context->simple; - g_simple_async_result_set_from_error (simple, error); + g_simple_async_result_take_error (simple, error); g_simple_async_result_complete (simple); - g_error_free (error); attachment_open_context_free (open_context); @@ -2064,10 +2062,8 @@ attachment_open_file (GFile *file, g_simple_async_result_set_op_res_gboolean (simple, success); - if (error != NULL) { - g_simple_async_result_set_from_error (simple, error); - g_error_free (error); - } + if (error != NULL) + g_simple_async_result_take_error (simple, error); g_simple_async_result_complete (simple); attachment_open_context_free (open_context); @@ -2324,9 +2320,8 @@ attachment_save_check_for_error (SaveContext *save_context, return FALSE; simple = save_context->simple; - g_simple_async_result_set_from_error (simple, error); + g_simple_async_result_take_error (simple, error); g_simple_async_result_complete (simple); - g_error_free (error); attachment_save_context_free (save_context); -- cgit v1.2.3 From aa75990c13d0fb2aea2ced1f9f7bd7d1785bdffc Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Fri, 7 Oct 2011 15:35:15 +0200 Subject: Bug #235665 - Heavy hard disk access when resizing columns in views --- widgets/table/e-table-header-item.c | 10 ++++++++++ widgets/table/e-table.c | 33 ++++++++++++++++++++++++++++++++- widgets/table/e-table.h | 6 ++++++ widgets/table/e-tree.c | 36 +++++++++++++++++++++++++++++++++++- widgets/table/e-tree.h | 3 +++ 5 files changed, 86 insertions(+), 2 deletions(-) (limited to 'widgets') diff --git a/widgets/table/e-table-header-item.c b/widgets/table/e-table-header-item.c index b8aa55f369..43871a278a 100644 --- a/widgets/table/e-table-header-item.c +++ b/widgets/table/e-table-header-item.c @@ -1192,6 +1192,11 @@ ethi_end_resize (ETableHeaderItem *ethi) ethi->resize_col = -1; ethi->resize_guide = GINT_TO_POINTER (0); + if (ethi->table) + e_table_thaw_state_change (ethi->table); + else if (ethi->tree) + e_tree_thaw_state_change (ethi->tree); + gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (ethi)); } @@ -1903,6 +1908,11 @@ ethi_event (GnomeCanvasItem *item, ethi->resize_col = col; ethi->resize_start_pos = start - ecol->width; ethi->resize_min_width = ecol->min_width; + + if (ethi->table) + e_table_freeze_state_change (ethi->table); + else if (ethi->tree) + e_tree_freeze_state_change (ethi->tree); } else { if (e->button.button == 1) { ethi->click_x = e->button.x; diff --git a/widgets/table/e-table.c b/widgets/table/e-table.c index 472681796f..e81dc6b23c 100644 --- a/widgets/table/e-table.c +++ b/widgets/table/e-table.c @@ -203,7 +203,10 @@ et_disconnect_model (ETable *et) static void e_table_state_change (ETable *et) { - g_signal_emit (G_OBJECT (et), et_signals[STATE_CHANGE], 0); + if (et->state_change_freeze) + et->state_changed = TRUE; + else + g_signal_emit (G_OBJECT (et), et_signals[STATE_CHANGE], 0); } #define CHECK_HORIZONTAL(et) \ @@ -605,6 +608,9 @@ e_table_init (ETable *e_table) e_table->current_search_col = NULL; e_table->header_width = 0; + + e_table->state_changed = FALSE; + e_table->state_change_freeze = 0; } /* Grab_focus handler for the ETable */ @@ -3709,3 +3715,28 @@ e_table_class_init (ETableClass *class) gal_a11y_e_table_init (); } + +void +e_table_freeze_state_change (ETable *table) +{ + g_return_if_fail (table != NULL); + + table->state_change_freeze++; + if (table->state_change_freeze == 1) + table->state_changed = FALSE; + + g_return_if_fail (table->state_change_freeze != 0); +} + +void +e_table_thaw_state_change (ETable *table) +{ + g_return_if_fail (table != NULL); + g_return_if_fail (table->state_change_freeze != 0); + + table->state_change_freeze--; + if (table->state_change_freeze == 0 && table->state_changed) { + table->state_changed = FALSE; + e_table_state_change (table); + } +} diff --git a/widgets/table/e-table.h b/widgets/table/e-table.h index e1e4e0eb8f..6c2908811c 100644 --- a/widgets/table/e-table.h +++ b/widgets/table/e-table.h @@ -170,6 +170,9 @@ struct _ETable { gint header_width; gchar *domain; + + gboolean state_changed; + guint state_change_freeze; }; struct _ETableClass { @@ -386,6 +389,9 @@ void e_table_right_click_up (ETable *table); void e_table_commit_click_to_add (ETable *table); +void e_table_freeze_state_change (ETable *table); +void e_table_thaw_state_change (ETable *table); + G_END_DECLS #endif /* _E_TABLE_H_ */ diff --git a/widgets/table/e-tree.c b/widgets/table/e-tree.c index effd1e9aa6..e24ce6a6e0 100644 --- a/widgets/table/e-tree.c +++ b/widgets/table/e-tree.c @@ -197,6 +197,9 @@ struct _ETreePrivate { ETreeDragSourceSite *site; GList *expanded_list; + + gboolean state_changed; + guint state_change_freeze; }; static guint et_signals[LAST_SIGNAL] = { 0, }; @@ -299,7 +302,10 @@ current_search_col (ETree *et) static void e_tree_state_change (ETree *et) { - g_signal_emit (G_OBJECT (et), et_signals[STATE_CHANGE], 0); + if (et->priv->state_change_freeze) + et->priv->state_changed = TRUE; + else + g_signal_emit (G_OBJECT (et), et_signals[STATE_CHANGE], 0); } static void @@ -629,6 +635,9 @@ e_tree_init (ETree *e_tree) G_CALLBACK (et_search_accept), e_tree); e_tree->priv->always_search = g_getenv ("GAL_ALWAYS_SEARCH") ? TRUE : FALSE; + + e_tree->priv->state_changed = FALSE; + e_tree->priv->state_change_freeze = 0; } /* Grab_focus handler for the ETree */ @@ -3787,3 +3796,28 @@ e_tree_set_info_message (ETree *tree, } else gnome_canvas_item_set (tree->priv->info_text, "text", info_message, NULL); } + +void +e_tree_freeze_state_change (ETree *tree) +{ + g_return_if_fail (tree != NULL); + + tree->priv->state_change_freeze++; + if (tree->priv->state_change_freeze == 1) + tree->priv->state_changed = FALSE; + + g_return_if_fail (tree->priv->state_change_freeze != 0); +} + +void +e_tree_thaw_state_change (ETree *tree) +{ + g_return_if_fail (tree != NULL); + g_return_if_fail (tree->priv->state_change_freeze != 0); + + tree->priv->state_change_freeze--; + if (tree->priv->state_change_freeze == 0 && tree->priv->state_changed) { + tree->priv->state_changed = FALSE; + e_tree_state_change (tree); + } +} diff --git a/widgets/table/e-tree.h b/widgets/table/e-tree.h index 6504caf474..08e56039b3 100644 --- a/widgets/table/e-tree.h +++ b/widgets/table/e-tree.h @@ -362,6 +362,9 @@ GnomeCanvasItem * void e_tree_set_info_message (ETree *tree, const gchar *info_message); +void e_tree_freeze_state_change (ETree *table); +void e_tree_thaw_state_change (ETree *table); + G_END_DECLS #endif /* _E_TREE_H_ */ -- cgit v1.2.3