file-roller r2550 - in trunk: . src



Author: paobac
Date: Mon Jan 19 16:13:39 2009
New Revision: 2550
URL: http://svn.gnome.org/viewvc/file-roller?rev=2550&view=rev

Log:
2009-01-19  Paolo Bacchilega  <paobac svn gnome org>

	* src/fr-window.c: do use a timeout to update the paste command
	sensitivity, use the owner-change clipboard signal instead.
	
	Fixes bug #560647 â file-roller wakes up the CPU 2 times per 
	second.


Modified:
   trunk/ChangeLog
   trunk/src/fr-window.c

Modified: trunk/src/fr-window.c
==============================================================================
--- trunk/src/fr-window.c	(original)
+++ trunk/src/fr-window.c	Mon Jan 19 16:13:39 2009
@@ -60,7 +60,6 @@
 #define ACTIVITY_DELAY 100
 #define ACTIVITY_PULSE_STEP (0.033)
 #define MAX_MESSAGE_LENGTH 50
-#define CHECK_CLIPBOARD_TIMEOUT 500
 
 #define PROGRESS_DIALOG_DEFAULT_WIDTH 400
 #define PROGRESS_TIMEOUT_MSECS 5000
@@ -332,7 +331,6 @@
 	FrClipboardData *copy_data;
 
 	FrArchive       *copy_from_archive;
-	guint            check_clipboard;
 
 	GtkActionGroup  *actions;
 
@@ -604,10 +602,6 @@
 		g_object_unref (priv->copy_from_archive);
 		priv->copy_from_archive = NULL;
 	}
-	if (priv->check_clipboard != 0) {
-		g_source_remove (priv->check_clipboard);
-		priv->check_clipboard = 0;
-	}
 
 	fr_window_free_open_files (window);
 
@@ -704,11 +698,6 @@
 
 	window->priv->closing = TRUE;
 
-	if (window->priv->check_clipboard != 0) {
-		g_source_remove (window->priv->check_clipboard);
-		window->priv->check_clipboard = 0;
-	}
-
 	if (GTK_WIDGET_REALIZED (window)) {
 		int width, height;
 
@@ -754,6 +743,45 @@
 }
 
 
+static void fr_window_update_paste_command_sensitivity (FrWindow *, GtkClipboard *);
+
+
+static void
+clipboard_owner_change_cb (GtkClipboard *clipboard,
+			   GdkEvent     *event,
+			   gpointer      user_data)
+{
+	fr_window_update_paste_command_sensitivity ((FrWindow *) user_data, clipboard);
+}
+
+
+static void
+fr_window_realized (GtkWidget *window,
+		    gpointer  *data)
+{
+	GtkClipboard *clipboard;
+
+	clipboard = gtk_widget_get_clipboard (window, FR_CLIPBOARD);
+        g_signal_connect (clipboard,
+                          "owner_change",
+                          G_CALLBACK (clipboard_owner_change_cb),
+                          window);
+}
+
+
+static void
+fr_window_unrealized (GtkWidget *window,
+		      gpointer  *data)
+{
+	GtkClipboard *clipboard;
+
+	clipboard = gtk_widget_get_clipboard (window, FR_CLIPBOARD);
+	g_signal_handlers_disconnect_by_func (clipboard,
+					      G_CALLBACK (clipboard_owner_change_cb),
+					      window);
+}
+
+
 static void
 fr_window_init (FrWindow *window)
 {
@@ -761,6 +789,15 @@
 	window->priv->update_dropped_files = FALSE;
 	window->priv->filter_mode = FALSE;
 
+	g_signal_connect (window,
+			  "realize",
+			  G_CALLBACK (fr_window_realized),
+			  NULL);
+	g_signal_connect (window,
+			  "unrealize",
+			  G_CALLBACK (fr_window_unrealized),
+			  NULL);	
+
 	WindowList = g_list_prepend (WindowList, window);
 }
 
@@ -1985,28 +2022,26 @@
 }
 
 
-static gboolean
-check_clipboard_cb (gpointer data)
+static void	
+fr_window_update_paste_command_sensitivity (FrWindow     *window,
+					    GtkClipboard *clipboard)
 {
-	FrWindow     *window = data;
-	GtkClipboard *clipboard;
-	gboolean      running;
-	gboolean      no_archive;
-	gboolean      ro;
-	gboolean      compr_file;
-
+	gboolean running;
+	gboolean no_archive;
+	gboolean ro;
+	gboolean compr_file;
+	
 	if (window->priv->closing)
-		return FALSE;
-
+		return;
+	
+	if (clipboard == NULL)
+		clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window), FR_CLIPBOARD);
 	running    = window->priv->activity_ref > 0;
 	no_archive = (window->archive == NULL) || ! window->priv->archive_present;
 	ro         = ! no_archive && window->archive->read_only;
 	compr_file = ! no_archive && window->archive->is_compressed_file;
-
-	clipboard = gtk_clipboard_get (FR_CLIPBOARD);
+	
 	set_sensitive (window, "Paste", ! no_archive && ! ro && ! running && ! compr_file && (window->priv->list_mode != FR_WINDOW_LIST_MODE_FLAT) && gtk_clipboard_wait_is_target_available (clipboard, FR_SPECIAL_URI_LIST));
-
-	return TRUE;
 }
 
 
@@ -2072,6 +2107,7 @@
 						   GTK_RESPONSE_OK,
 						   running && window->priv->stoppable);
 
+	fr_window_update_paste_command_sensitivity (window, NULL);
 
 	set_sensitive (window, "SelectAll", (window->priv->current_view_length > 0) && (window->priv->current_view_length != n_selected));
 	set_sensitive (window, "DeselectAll", n_selected > 0);
@@ -2081,11 +2117,6 @@
 
 	set_sensitive (window, "ViewAllFiles", ! window->priv->filter_mode);
 	set_sensitive (window, "ViewAsFolder", ! window->priv->filter_mode);
-
-	/**/
-
-	if (! window->priv->closing && (window->priv->check_clipboard == 0))
-		window->priv->check_clipboard = g_timeout_add (CHECK_CLIPBOARD_TIMEOUT, check_clipboard_cb, window);
 }
 
 



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