[Goodies-commits] r7067 - in xfce4-clipman-plugin/trunk: . panel-plugin

Mike Massonnet mmassonnet at xfce.org
Tue Mar 31 21:36:56 CEST 2009


Author: mmassonnet
Date: 2009-03-31 19:36:56 +0000 (Tue, 31 Mar 2009)
New Revision: 7067

Modified:
   xfce4-clipman-plugin/trunk/ChangeLog
   xfce4-clipman-plugin/trunk/TODO
   xfce4-clipman-plugin/trunk/panel-plugin/collector.c
Log:
Make Clipman the owner of the clipboard contents

Modified: xfce4-clipman-plugin/trunk/ChangeLog
===================================================================
--- xfce4-clipman-plugin/trunk/ChangeLog	2009-03-31 18:02:15 UTC (rev 7066)
+++ xfce4-clipman-plugin/trunk/ChangeLog	2009-03-31 19:36:56 UTC (rev 7067)
@@ -1,4 +1,15 @@
 2009-03-31	Mike Massonnet
+Make Clipman the owner of the clipboard contents
+
+	- panel-plugin/collector.c:
+		Rename priv->restoring to priv->internal_change.  Drop function
+		_clipman_collector_restore_clipboard in favor of making Clipman
+		automatically the owner of the clipboard contents.  This doesn't work
+		for the primary clipboard as it would destroy the selection under hand
+		thus it will lack this functionnality, but all-in-all this clipboard
+		is not as mandatory as the default clipboard.
+
+2009-03-31	Mike Massonnet
 Save/Load the history in the correct order
 
 	- panel-plugin/panel-plugin.c(panel_plugin_save):

Modified: xfce4-clipman-plugin/trunk/TODO
===================================================================
--- xfce4-clipman-plugin/trunk/TODO	2009-03-31 18:02:15 UTC (rev 7066)
+++ xfce4-clipman-plugin/trunk/TODO	2009-03-31 19:36:56 UTC (rev 7067)
@@ -1,7 +1,3 @@
-Deps:
-- Check deps versions
 Actions:
 - Set sensitivity of "ok" button in the actions settings dialogs
 - A regex validator dialog
-Collector:
-- Drop the restore code and push the clipboard data inside the plugin so it's the owner

Modified: xfce4-clipman-plugin/trunk/panel-plugin/collector.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/collector.c	2009-03-31 18:02:15 UTC (rev 7066)
+++ xfce4-clipman-plugin/trunk/panel-plugin/collector.c	2009-03-31 19:36:56 UTC (rev 7067)
@@ -45,7 +45,7 @@
   GtkClipboard         *default_clipboard;
   GtkClipboard         *primary_clipboard;
   guint                 primary_clipboard_timeout;
-  gboolean              restoring;
+  gboolean              internal_change;
   gboolean              add_primary_clipboard;
   gboolean              enable_actions;
 };
@@ -70,13 +70,6 @@
                                                              GParamSpec *pspec);
 
 /*
- * Private methods declarations
- */
-
-static void            _clipman_collector_restore_clipboard (ClipmanCollector *collector,
-                                                             GtkClipboard *clipboard);
-
-/*
  * Callbacks declarations
  */
 
@@ -99,36 +92,17 @@
   gchar *text;
   GdkPixbuf *image;
 
+  /* Take only care of new clipboard content */
+  if (event != GDK_OWNER_CHANGE_NEW_OWNER)
+    return;
+
   /* Jump over if the content is set from within clipman */
-  if (collector->priv->restoring)
+  if (collector->priv->internal_change)
     {
-      collector->priv->restoring = FALSE;
+      collector->priv->internal_change = FALSE;
       return;
     }
 
-  /* Prevent the clipboard from getting empty */
-  if (event->reason == GDK_OWNER_CHANGE_DESTROY || event->reason == GDK_OWNER_CHANGE_CLOSE)
-    {
-      if (event->selection == GDK_SELECTION_CLIPBOARD)
-        {
-          DBG ("The default clipboard is empty");
-          _clipman_collector_restore_clipboard (collector, collector->priv->default_clipboard);
-        }
-      else if (event->selection == GDK_SELECTION_PRIMARY)
-        {
-          DBG ("The primary clipboard is empty");
-          /* This case is seldomly reached, the experience showed that it only
-           * happens when the application is properly quit through the menu
-           * (Ctrl+Q in general).  Most of the time the primary clipboard will
-           * be set empty ("") instead of being destroyed when the application
-           * closes (Alt+F4). */
-          if (collector->priv->add_primary_clipboard)
-            _clipman_collector_restore_clipboard (collector, collector->priv->primary_clipboard);
-        }
-
-      return;
-    }
-
   /* Save the clipboard content to ClipmanHistory */
   if (event->selection == GDK_SELECTION_CLIPBOARD)
     {
@@ -139,14 +113,28 @@
         {
           text = gtk_clipboard_wait_for_text (collector->priv->default_clipboard);
           if (text != NULL && text[0] != '\0')
-            clipman_history_add_text (collector->priv->history, text);
+            {
+              /* Make Clipman the owner */
+              collector->priv->internal_change = TRUE;
+              gtk_clipboard_set_text (collector->priv->default_clipboard, text, -1);
+
+              /* Add to history */
+              clipman_history_add_text (collector->priv->history, text);
+            }
           g_free (text);
         }
       else if (has_image)
         {
           image = gtk_clipboard_wait_for_image (collector->priv->default_clipboard);
           if (image != NULL)
-            clipman_history_add_image (collector->priv->history, image);
+            {
+              /* Make Clipman the owner */
+              collector->priv->internal_change = TRUE;
+              gtk_clipboard_set_image (collector->priv->default_clipboard, image);
+
+              /* Add to history */
+              clipman_history_add_image (collector->priv->history, image);
+            }
           g_object_unref (image);
         }
     }
@@ -184,10 +172,11 @@
         {
           if (collector->priv->add_primary_clipboard)
             {
+              /* Add to history */
               clipman_history_add_text (collector->priv->history, text);
 
               /* Make a copy inside the default clipboard */
-              collector->priv->restoring = TRUE;
+              collector->priv->internal_change = TRUE;
               gtk_clipboard_set_text (collector->priv->default_clipboard, text, -1);
             }
 
@@ -197,52 +186,12 @@
         }
       g_free (text);
     }
-  else if (collector->priv->add_primary_clipboard)
-    {
-      DBG ("The primary clipboard is empty");
-      _clipman_collector_restore_clipboard (collector, collector->priv->primary_clipboard);
-    }
 
   collector->priv->primary_clipboard_timeout = 0;
   return FALSE;
 }
 
 /*
- * Private methods
- */
-
-static void
-_clipman_collector_restore_clipboard (ClipmanCollector *collector,
-                                      GtkClipboard *clipboard)
-{
-  /* TODO See how to store the content in clipman, instead of trying to restore
-   * empty clipboards. */
-  const ClipmanHistoryItem *item;
-
-  collector->priv->restoring = TRUE;
-
-  item = clipman_history_get_item_to_restore (collector->priv->history);
-  if (item == NULL)
-    return;
-
-  DBG ("Restore the clipboard with the most recent content from ClipmanHistory");
-
-  switch (item->type)
-    {
-    case CLIPMAN_HISTORY_TYPE_TEXT:
-      gtk_clipboard_set_text (clipboard, item->content.text, -1);
-      break;
-
-    case CLIPMAN_HISTORY_TYPE_IMAGE:
-      gtk_clipboard_set_image (clipboard, item->content.image);
-      break;
-
-    default:
-      g_assert_not_reached ();
-    }
-}
-
-/*
  * Public methods
  */
 
@@ -260,7 +209,7 @@
 void
 clipman_collector_set_is_restoring (ClipmanCollector *collector)
 {
-  collector->priv->restoring = TRUE;
+  collector->priv->internal_change = TRUE;
 }
 
 ClipmanCollector *
@@ -320,7 +269,7 @@
 
   /* This bit is set to TRUE when a clipboard has to be set from within clipman
    * while avoiding to re-add it to the history. */
-  collector->priv->restoring = FALSE;
+  collector->priv->internal_change = FALSE;
 
   /* ClipmanActions */
   collector->priv->actions = clipman_actions_get ();




More information about the Goodies-commits mailing list