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

Mike Massonnet mmassonnet at xfce.org
Mon Jun 29 16:45:42 CEST 2009


Author: mmassonnet
Date: 2009-06-29 14:45:41 +0000 (Mon, 29 Jun 2009)
New Revision: 7644

Added:
   xfce4-clipman-plugin/trunk/panel-plugin/xfce4-clipman-settings.c
Modified:
   xfce4-clipman-plugin/trunk/ChangeLog
   xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am
   xfce4-clipman-plugin/trunk/panel-plugin/actions.c
   xfce4-clipman-plugin/trunk/panel-plugin/main.c
Log:
Move the settings dialog outside

Modified: xfce4-clipman-plugin/trunk/ChangeLog
===================================================================
--- xfce4-clipman-plugin/trunk/ChangeLog	2009-06-28 22:56:35 UTC (rev 7643)
+++ xfce4-clipman-plugin/trunk/ChangeLog	2009-06-29 14:45:41 UTC (rev 7644)
@@ -1,4 +1,16 @@
 2009-05-29	Mike Massonnet
+Move the settings dialog outside
+
+	- panel-plugin/Makefile.am:
+		Build new binary xfce4-clipman-settings.
+		Remove Glade dependency on the panel plugin.
+	- panel-plugin/xfce4-clipman-settings.c:
+		Moved all settings dialog related functions from main.c to
+		this file.
+	- panel-plugin/main.c:
+		Make a call to xfce4-clipman-settings instead.
+
+2009-05-29	Mike Massonnet
 === Release 1.0.2 ===
 
 2009-06-28	Mike Massonnet

Modified: xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am	2009-06-28 22:56:35 UTC (rev 7643)
+++ xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am	2009-06-29 14:45:41 UTC (rev 7644)
@@ -24,7 +24,7 @@
 # Popup Command
 #
 
-bin_PROGRAMS = xfce4-clipman-plugin xfce4-popup-clipman
+bin_PROGRAMS = xfce4-clipman-plugin xfce4-popup-clipman xfce4-clipman-settings
 
 xfce4_popup_clipman_SOURCES =						\
 	xfce4-popup-clipman.c						\
@@ -44,6 +44,34 @@
 	$(NULL)
 
 #
+# Settings dialog
+#
+
+xfce4_clipman_settings_SOURCES =					\
+	xfce4-clipman-settings.c					\
+	common.h							\
+	settings-dialog_glade.h						\
+	actions.c			actions.h			\
+	$(NULL)
+
+xfce4_clipman_settings_CFLAGS =						\
+	@GTK_CFLAGS@							\
+	@EXO_CFLAGS@							\
+	@LIBXFCEGUI4_CFLAGS@						\
+	@XFCONF_CFLAGS@							\
+	@GLADE_CFLAGS@							\
+	$(NULL)
+
+xfce4_clipman_settings_LDADD =						\
+	@GTK_LIBS@							\
+	@EXO_LIBS@							\
+	@LIBXFCEGUI4_LIBS@						\
+	@XFCONF_LIBS@							\
+	@GLADE_LIBS@							\
+	$(NULL)
+
+
+#
 # Plugin
 #
 
@@ -54,7 +82,6 @@
 	collector.c			collector.h			\
 	history.c			history.h			\
 	menu.c				menu.h				\
-	settings-dialog_glade.h						\
 	$(NULL)
 
 xfce4_clipman_plugin_CFLAGS =						\
@@ -66,7 +93,6 @@
 	@LIBXFCEGUI4_CFLAGS@						\
 	@LIBXFCE4PANEL_CFLAGS@						\
 	@XFCONF_CFLAGS@							\
-	@GLADE_CFLAGS@							\
 	$(NULL)
 
 xfce4_clipman_plugin_LDADD =						\
@@ -78,7 +104,6 @@
 	@LIBXFCEGUI4_LIBS@						\
 	@LIBXFCE4PANEL_LIBS@						\
 	@XFCONF_LIBS@							\
-	@GLADE_LIBS@							\
 	$(NULL)
 
 #

Modified: xfce4-clipman-plugin/trunk/panel-plugin/actions.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/actions.c	2009-06-28 22:56:35 UTC (rev 7643)
+++ xfce4-clipman-plugin/trunk/panel-plugin/actions.c	2009-06-29 14:45:41 UTC (rev 7644)
@@ -61,6 +61,7 @@
  * Misc functions declarations
  */
 
+static void            _clipman_actions_free_list           (ClipmanActions *actions);
 static gint           __clipman_actions_entry_compare       (gpointer a,
                                                              gpointer b);
 static gint           __clipman_actions_entry_compare_name  (gpointer a,
@@ -347,6 +348,15 @@
  * Misc functions
  */
 
+static void
+_clipman_actions_free_list (ClipmanActions *actions)
+{
+  GSList *l;
+  for (l = actions->priv->entries; l != NULL; l = l->next)
+    __clipman_actions_entry_free (l->data);
+  g_slist_free (actions->priv->entries);
+}
+
 static gint
 __clipman_actions_entry_compare (gpointer a,
                                  gpointer b)
@@ -853,10 +863,6 @@
 clipman_actions_finalize (GObject *object)
 {
   ClipmanActions *actions = CLIPMAN_ACTIONS (object);
-  GSList *l;
-
-  for (l = actions->priv->entries; l != NULL; l = l->next)
-    __clipman_actions_entry_free (l->data);
-  g_slist_free (actions->priv->entries);
+  _clipman_actions_free_list (actions);
 }
 

Modified: xfce4-clipman-plugin/trunk/panel-plugin/main.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/main.c	2009-06-28 22:56:35 UTC (rev 7643)
+++ xfce4-clipman-plugin/trunk/panel-plugin/main.c	2009-06-29 14:45:41 UTC (rev 7644)
@@ -33,10 +33,8 @@
 #include <libxfce4panel/xfce-panel-plugin.h>
 #include <libxfce4panel/xfce-panel-convenience.h>
 #include <xfconf/xfconf.h>
-#include <glade/glade.h>
 
 #include "common.h"
-#include "settings-dialog_glade.h"
 #include "actions.h"
 #include "collector.h"
 #include "history.h"
@@ -57,7 +55,6 @@
   ClipmanActions       *actions;
   ClipmanCollector     *collector;
   ClipmanHistory       *history;
-  GladeXML             *gxml;
   GtkWidget            *button;
   GtkWidget            *image;
   GtkWidget            *menu;
@@ -139,52 +136,8 @@
 static gboolean         cb_message_received             (MyPlugin *plugin,
                                                          GdkEventClient *ev);
 
-/*
- * Settings Dialog
- */
 
-static void             cb_show_help                    (GtkButton *button,
-                                                         MyPlugin *plugin);
-static void             setup_actions_treeview          (GtkTreeView *treeview,
-                                                         MyPlugin *plugin);
-static void             refresh_actions_treeview        (GtkTreeView *treeview,
-                                                         MyPlugin *plugin);
-static void             apply_action                    (const gchar *original_action_name,
-                                                         MyPlugin *plugin);
-static void             cb_actions_selection_changed    (GtkTreeSelection *selection,
-                                                         MyPlugin *plugin);
-static void             cb_add_action                   (GtkButton *button,
-                                                         MyPlugin *plugin);
-static void             cb_edit_action                  (GtkButton *button,
-                                                         MyPlugin *plugin);
-static void             cb_actions_row_activated        (GtkTreeView *treeview,
-                                                         GtkTreePath *path,
-                                                         GtkTreeViewColumn *column,
-                                                         MyPlugin *plugin);
-static void             cb_delete_action                (GtkButton *button,
-                                                         MyPlugin *plugin);
-static void             setup_commands_treeview         (GtkTreeView *treeview,
-                                                         MyPlugin *plugin);
-static void             entry_dialog_cleanup            (GtkDialog *dialog,
-                                                         MyPlugin *plugin);
-#if !GLIB_CHECK_VERSION(2,16,0)
-static void           __foreach_command_fill_commands   (gpointer key,
-                                                         gpointer value,
-                                                         gpointer user_data);
-#endif
-static void             cb_commands_selection_changed   (GtkTreeSelection *selection,
-                                                         MyPlugin *plugin);
-static void             cb_add_command                  (GtkButton *button,
-                                                         MyPlugin *plugin);
-static void             cb_refresh_command              (GtkButton *button,
-                                                         MyPlugin *plugin);
-static void             cb_delete_command               (GtkButton *button,
-                                                         MyPlugin *plugin);
-static void             cb_set_action_dialog_button_ok  (GtkWidget *widget,
-                                                         MyPlugin *plugin);
 
-
-
 /*
  * Plugin Registration
  */
@@ -550,13 +503,13 @@
   while (TRUE)
     {
       filename = g_strdup_printf ("%s/xfce4/clipman/image%d.png", g_get_user_cache_dir (), i++);
-      DBG ("Loading image from cache file %s", filename);
       image = gdk_pixbuf_new_from_file (filename, NULL);
       g_unlink (filename);
       g_free (filename);
       if (image == NULL)
         break;
 
+      DBG ("Loading image from cache file %s", filename);
       clipman_history_add_image (plugin->history, image);
       g_object_unref (image);
     }
@@ -677,11 +630,10 @@
 plugin_about (MyPlugin *plugin)
 {
   const gchar *artists[] = { "Mike Massonnet", NULL, };
-  const gchar *authors[] = { "Mike Massonnet",
-                                    "", _("Authors of previous versions:"),
-                                    "Eduard Roccatello",
-                                    "Nick Schermer",
-                                    NULL, };
+  const gchar *authors[] = { "(c) 2008-2009 Mike Massonnet",
+                             "(c) 2005-2006 Nick Schermer",
+                             "(c) 2003 Eduard Roccatello",
+                             NULL, };
   const gchar *documenters[] = { "Mike Massonnet", NULL, };
   const gchar *license =
     "This program is free software; you can redistribute it and/or modify\n"
@@ -726,89 +678,19 @@
 static void
 plugin_configure (MyPlugin *plugin)
 {
-  GtkWidget *dialog;
-  GtkWidget *action_dialog;
-  GtkWindowGroup *group;
+  GError *error = NULL;
+  GtkWidget *error_dialog;
 
-  /* GladeXML */
-  plugin->gxml = glade_xml_new_from_buffer (settings_dialog_glade, settings_dialog_glade_length, NULL, NULL);
-
-  /* Settings dialog */
-  dialog = glade_xml_get_widget (plugin->gxml, "settings-dialog");
-  if (plugin->panel_plugin != NULL)
-    gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin->panel_plugin))));
-  group = gtk_window_group_new ();
-  gtk_window_group_add_window (group, GTK_WINDOW (dialog));
-
-  /* Action dialog */
-  action_dialog = glade_xml_get_widget (plugin->gxml, "action-dialog");
-  gtk_window_group_add_window (group, GTK_WINDOW (action_dialog));
-
-  /* General settings */
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (plugin->gxml, "add-selections")),
-                                DEFAULT_ADD_PRIMARY_CLIPBOARD);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (plugin->gxml, "history-ignore-selections")),
-                                DEFAULT_HISTORY_IGNORE_PRIMARY_CLIPBOARD);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (plugin->gxml, "save-on-quit")),
-                                DEFAULT_SAVE_ON_QUIT);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (plugin->gxml, "store-an-image")),
-                                (gboolean)DEFAULT_MAX_IMAGES_IN_HISTORY);
-  gtk_spin_button_set_value (GTK_SPIN_BUTTON (glade_xml_get_widget (plugin->gxml, "max-texts-in-history")),
-                             (gdouble)DEFAULT_MAX_TEXTS_IN_HISTORY);
-  xfconf_g_property_bind (plugin->channel, "/settings/add-primary-clipboard", G_TYPE_BOOLEAN,
-                          G_OBJECT (glade_xml_get_widget (plugin->gxml, "add-selections")), "active");
-  xfconf_g_property_bind (plugin->channel, "/settings/add-primary-clipboard", G_TYPE_BOOLEAN,
-                          G_OBJECT (glade_xml_get_widget (plugin->gxml, "history-ignore-selections")), "sensitive");
-  xfconf_g_property_bind (plugin->channel, "/settings/history-ignore-primary-clipboard", G_TYPE_BOOLEAN,
-                          G_OBJECT (glade_xml_get_widget (plugin->gxml, "history-ignore-selections")), "active");
-  xfconf_g_property_bind (plugin->channel, "/settings/save-on-quit", G_TYPE_BOOLEAN,
-                          G_OBJECT (glade_xml_get_widget (plugin->gxml, "save-on-quit")), "active");
-  xfconf_g_property_bind (plugin->channel, "/settings/max-images-in-history", G_TYPE_UINT,
-                          G_OBJECT (glade_xml_get_widget (plugin->gxml, "store-an-image")), "active");
-  xfconf_g_property_bind (plugin->channel, "/settings/max-texts-in-history", G_TYPE_UINT,
-                          G_OBJECT (glade_xml_get_widget (plugin->gxml, "max-texts-in-history")), "value");
-
-  /* Actions tab and dialog */
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (plugin->gxml, "enable-actions")),
-                                DEFAULT_ENABLE_ACTIONS);
-  xfconf_g_property_bind (plugin->channel, "/settings/enable-actions", G_TYPE_BOOLEAN,
-                          G_OBJECT (glade_xml_get_widget (plugin->gxml, "enable-actions")), "active");
-
-  glade_xml_signal_connect_data (plugin->gxml, "cb_add_action", G_CALLBACK (cb_add_action), plugin);
-  glade_xml_signal_connect_data (plugin->gxml, "cb_edit_action", G_CALLBACK (cb_edit_action), plugin);
-  glade_xml_signal_connect_data (plugin->gxml, "cb_delete_action", G_CALLBACK (cb_delete_action), plugin);
-  glade_xml_signal_connect_data (plugin->gxml, "cb_actions_row_activated", G_CALLBACK (cb_actions_row_activated), plugin);
-  glade_xml_signal_connect_data (plugin->gxml, "cb_add_command", G_CALLBACK (cb_add_command), plugin);
-  glade_xml_signal_connect_data (plugin->gxml, "cb_refresh_command", G_CALLBACK (cb_refresh_command), plugin);
-  glade_xml_signal_connect_data (plugin->gxml, "cb_delete_command", G_CALLBACK (cb_delete_command), plugin);
-  glade_xml_signal_connect_data (plugin->gxml, "cb_show_help", G_CALLBACK (cb_show_help), plugin);
-
-  setup_actions_treeview (GTK_TREE_VIEW (glade_xml_get_widget (plugin->gxml, "actions")), plugin);
-  setup_commands_treeview (GTK_TREE_VIEW (glade_xml_get_widget (plugin->gxml, "commands")), plugin);
-
-  /* Callbacks for the OK button sensitivity in the edit action dialog */
-  g_signal_connect_after (glade_xml_get_widget (plugin->gxml, "action-name"), "changed",
-                          G_CALLBACK (cb_set_action_dialog_button_ok), plugin);
-  g_signal_connect_after (glade_xml_get_widget (plugin->gxml, "regex"), "changed",
-                          G_CALLBACK (cb_set_action_dialog_button_ok), plugin);
-  g_signal_connect_after (glade_xml_get_widget (plugin->gxml, "button-add-command"), "clicked",
-                          G_CALLBACK (cb_set_action_dialog_button_ok), plugin);
-  g_signal_connect_after (glade_xml_get_widget (plugin->gxml, "button-delete-command"), "clicked",
-                          G_CALLBACK (cb_set_action_dialog_button_ok), plugin);
-
-  /* Run the dialog */
-  plugin_block_menu (plugin);
-  while (gtk_dialog_run (GTK_DIALOG (dialog)) != 0);
-  plugin_unblock_menu (plugin);
-
-  gtk_widget_destroy (action_dialog);
-  gtk_widget_destroy (dialog);
-  g_object_unref (group);
-  g_object_unref (plugin->gxml);
-  plugin->gxml = NULL;
-
-  /* Save the actions */
-  clipman_actions_save (plugin->actions);
+  gdk_spawn_command_line_on_screen (gdk_screen_get_default (), "xfce4-clipman-settings", &error);
+  if (error != NULL)
+  {
+    error_dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+                                           _("Unable to open the settings dialog"), NULL);
+    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message, NULL);
+    gtk_dialog_run (GTK_DIALOG (error_dialog));
+    gtk_widget_destroy (error_dialog);
+    g_error_free (error);
+  }
 }
 
 static void
@@ -999,499 +881,3 @@
     }
   return FALSE;
 }
-
-/*
- * Settings Dialog
- */
-
-static void
-cb_show_help (GtkButton *button,
-              MyPlugin *plugin)
-{
-  GdkScreen *screen;
-  gchar *locale = NULL;
-  gchar *offset;
-  gchar *filename = NULL;
-  gchar *command = NULL;
-  
-#ifdef ENABLE_NLS
-#ifdef HAVE_LOCALE_H
-  locale = g_strdup (setlocale (LC_ALL, ""));
-  if (locale != NULL)
-    {
-      offset = g_strrstr (locale, ".");
-      if (offset != NULL)
-        *offset = '\0';
-    }
-  else
-    locale = g_strdup ("C");
-#else
-  locale = g_strdup ("C");
-#endif
-
-  filename = g_strdup_printf (DATAROOTDIR"/xfce4/doc/%s/"PACKAGE".html", locale);
-  if (!g_file_test (filename, G_FILE_TEST_EXISTS))
-    {
-      offset = g_strrstr (locale, "_");
-      if (offset == NULL)
-        {
-          g_free (filename);
-          filename = g_strdup (DATAROOTDIR"/xfce4/doc/C/"PACKAGE".html");
-        }
-      else
-        {
-          *offset = '\0';
-          g_free (filename);
-          filename = g_strdup_printf (DATAROOTDIR"/xfce4/doc/%s/"PACKAGE".html", locale);
-          if (!g_file_test (filename, G_FILE_TEST_EXISTS))
-            {
-              g_free (filename);
-              filename = g_strdup (DATAROOTDIR"/xfce4/doc/C/"PACKAGE".html");
-            }
-        }
-    }
-
-  g_free (locale);
-#else
-  filename = g_strdup (DATAROOTDIR"/xfce4/doc/C/"PACKAGE".html");
-#endif
-
-  screen = gtk_widget_get_screen (GTK_WIDGET (button));
-  command = g_strdup_printf ("exo-open file://%s", filename);
-  if (gdk_spawn_command_line_on_screen (screen, command, NULL))
-    goto out;
-
-  g_free (command);
-  command = g_strdup_printf ("firefox file://%s", filename);
-  if (gdk_spawn_command_line_on_screen (screen, command, NULL))
-    goto out;
-
-  xfce_err ("Unable to open documentation \"%s\"", filename);
-
-out:
-  g_free (filename);
-  g_free (command);
-}
-
-/* Actions */
-static void
-setup_actions_treeview (GtkTreeView *treeview,
-                        MyPlugin *plugin)
-{
-  GtkTreeSelection *selection;
-  GtkListStore *model;
-  GtkCellRenderer *cell;
-
-  /* Define the model */
-  model = gtk_list_store_new (2, G_TYPE_POINTER, G_TYPE_STRING);
-  gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (model));
-  g_object_unref (model);
-
-  /* Define the columns */
-  cell = gtk_cell_renderer_text_new ();
-  g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
-  gtk_tree_view_insert_column_with_attributes (treeview, -1, "Action", cell, "markup", 1, NULL);
-
-  refresh_actions_treeview (treeview, plugin);
-
-  selection = gtk_tree_view_get_selection (treeview);
-  g_signal_connect (selection, "changed", G_CALLBACK (cb_actions_selection_changed), plugin);
-}
-
-static void
-refresh_actions_treeview (GtkTreeView *treeview,
-                          MyPlugin *plugin)
-{
-  ClipmanActionsEntry *entry;
-  const GSList *entries;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  gchar *title;
-
-  model = gtk_tree_view_get_model (treeview);
-  gtk_list_store_clear (GTK_LIST_STORE (model));
-
-  entries = clipman_actions_get_entries (plugin->actions);
-  for (; entries != NULL; entries = entries->next)
-    {
-      entry = entries->data;
-
-      title = g_markup_printf_escaped ("<b>%s</b>\n<small>%s</small>",
-                                       entry->action_name, g_regex_get_pattern (entry->regex));
-      gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-      gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, entry, 1, title, -1);
-      g_free (title);
-    }
-}
-
-static void
-apply_action (const gchar *original_action_name,
-              MyPlugin *plugin)
-{
-  GtkWidget *treeview;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  const gchar *action_name;
-  const gchar *regex;
-  gchar *command_name;
-  gchar *command;
-
-  action_name = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "action-name")));
-  regex = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "regex")));
-
-  treeview = glade_xml_get_widget (plugin->gxml, "commands");
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
-  if (!gtk_tree_model_get_iter_first (model, &iter))
-    return;
-
-  /* Remove the old actions */
-  if (original_action_name != NULL)
-    clipman_actions_remove (plugin->actions, original_action_name);
-
-  /* Add the new actions */
-  do
-    {
-      gtk_tree_model_get (model, &iter, 1, &command_name, 2, &command, -1);
-      clipman_actions_add (plugin->actions, action_name, regex, command_name, command);
-      g_free (command_name);
-      g_free (command);
-    }
-  while (gtk_tree_model_iter_next (model, &iter));
-
-  /* Refresh the actions treeview */
-  treeview = glade_xml_get_widget (plugin->gxml, "actions");
-  refresh_actions_treeview (GTK_TREE_VIEW (treeview), plugin);
-}
-
-static void
-cb_actions_selection_changed (GtkTreeSelection *selection,
-                              MyPlugin *plugin)
-{
-  GtkTreeModel *model;
-  gboolean sensitive;
-
-  sensitive = gtk_tree_selection_get_selected (selection, &model, NULL);
-
-  gtk_widget_set_sensitive (glade_xml_get_widget (plugin->gxml, "button-edit-action"), sensitive);
-  gtk_widget_set_sensitive (glade_xml_get_widget (plugin->gxml, "button-delete-action"), sensitive);
-}
-
-static void
-cb_add_action (GtkButton *button,
-               MyPlugin *plugin)
-{
-  GtkWidget *dialog;
-  gint res;
-
-  dialog = glade_xml_get_widget (plugin->gxml, "action-dialog");
-  entry_dialog_cleanup (GTK_DIALOG (dialog), plugin);
-
-  res = gtk_dialog_run (GTK_DIALOG (dialog));
-  gtk_widget_hide (dialog);
-
-  if (res == 1)
-    apply_action (NULL, plugin);
-}
-
-static void
-cb_edit_action (GtkButton *button,
-                MyPlugin *plugin)
-{
-  GtkWidget *treeview;
-  GtkTreeSelection *selection;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  GtkTreePath *path;
-  GtkTreeViewColumn *column;
-
-  treeview = glade_xml_get_widget (plugin->gxml, "actions");
-
-  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
-  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
-    {
-      g_critical ("Trying to edit an action but got no selection");
-      return;
-    }
-
-  path = gtk_tree_model_get_path (model, &iter);
-  column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), 1);
-  gtk_tree_view_row_activated (GTK_TREE_VIEW (treeview), path, column);
-  gtk_tree_path_free (path);
-}
-
-static void
-cb_actions_row_activated (GtkTreeView *treeview,
-                          GtkTreePath *path,
-                          GtkTreeViewColumn *column,
-                          MyPlugin *plugin)
-{
-  ClipmanActionsEntry *entry;
-  GtkTreeModel *actions_model, *commands_model;
-  GtkTreeIter iter;
-  GtkWidget *dialog;
-  gchar *title;
-  gint res;
-
-  dialog = glade_xml_get_widget (plugin->gxml, "action-dialog");
-  entry_dialog_cleanup (GTK_DIALOG (dialog), plugin);
-
-  actions_model = gtk_tree_view_get_model (treeview);
-  gtk_tree_model_get_iter (actions_model, &iter, path);
-  gtk_tree_model_get (actions_model, &iter, 0, &entry, -1);
-
-  commands_model = gtk_tree_view_get_model (GTK_TREE_VIEW (glade_xml_get_widget (plugin->gxml, "commands")));
-#if GLIB_CHECK_VERSION (2,16,0)
-  GHashTableIter hiter;
-  gpointer key, value;
-  g_hash_table_iter_init (&hiter, entry->commands);
-  while (g_hash_table_iter_next (&hiter, &key, &value))
-    {
-      title = g_markup_printf_escaped ("<b>%s</b>\n<small>%s</small>", (gchar *)key, (gchar *)value);
-      gtk_list_store_append (GTK_LIST_STORE (commands_model), &iter);
-      gtk_list_store_set (GTK_LIST_STORE (commands_model), &iter, 0, title, 1, key, 2, value, -1);
-      g_free (title);
-    }
-#else
-  g_hash_table_foreach (entry->commands, (GHFunc)__foreach_command_fill_commands, commands_model);
-#endif
-
-  gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "action-name")), entry->action_name);
-  gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "regex")), g_regex_get_pattern (entry->regex));
-
-  res = gtk_dialog_run (GTK_DIALOG (dialog));
-  gtk_widget_hide (dialog);
-
-  if (res == 1)
-    apply_action (entry->action_name, plugin);
-}
-
-static void
-cb_delete_action (GtkButton *button,
-                  MyPlugin *plugin)
-{
-  ClipmanActionsEntry *entry;
-  GtkWidget *treeview;
-  GtkTreeSelection *selection;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-
-  treeview = glade_xml_get_widget (plugin->gxml, "actions");
-
-  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
-  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
-    {
-      g_critical ("Trying to remove an action but got no selection");
-      return;
-    }
-
-  gtk_tree_model_get (model, &iter, 0, &entry, -1);
-  clipman_actions_remove (plugin->actions, entry->action_name);
-  gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
-}
-
-/* Entry Dialog */
-static void
-setup_commands_treeview (GtkTreeView *treeview,
-                         MyPlugin *plugin)
-{
-  GtkTreeSelection *selection;
-  GtkListStore *model;
-  GtkCellRenderer *cell;
-
-  /* Define the model */
-  model = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
-  gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (model));
-  g_object_unref (model);
-
-  /* Define the columns */
-  cell = gtk_cell_renderer_text_new ();
-  g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
-  gtk_tree_view_insert_column_with_attributes (treeview, -1, "Command", cell, "markup", 0, NULL);
-
-  selection = gtk_tree_view_get_selection (treeview);
-  g_signal_connect (selection, "changed", G_CALLBACK (cb_commands_selection_changed), plugin);
-}
-
-static void
-entry_dialog_cleanup (GtkDialog *dialog,
-                      MyPlugin *plugin)
-{
-  GtkTreeModel *model;
-
-  gtk_widget_set_sensitive (glade_xml_get_widget (plugin->gxml, "action-dialog-button-ok"), FALSE);
-
-  gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "action-name")), "");
-  gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "regex")), "");
-
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (glade_xml_get_widget (plugin->gxml, "commands")));
-  gtk_list_store_clear (GTK_LIST_STORE (model));
-}
-
-#if !GLIB_CHECK_VERSION(2,16,0)
-static void
-__foreach_command_fill_commands (gpointer key,
-                                 gpointer value,
-                                 gpointer user_data)
-{
-  GtkTreeModel *model = user_data;
-  GtkTreeIter iter;
-  gchar *title;
-
-  title = g_markup_printf_escaped ("<b>%s</b>\n<small>%s</small>", (gchar *)key, (gchar *)value);
-  gtk_list_store_append (GTK_LIST_STORE (_model), &iter);
-  gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, title, 1, key, 2, value, -1);
-  g_free (title);
-}
-#endif
-
-static void
-cb_commands_selection_changed (GtkTreeSelection *selection,
-                               MyPlugin *plugin)
-{
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  gboolean sensitive;
-  gchar *command_name = NULL;
-  gchar *command = NULL;
-
-  sensitive = gtk_tree_selection_get_selected (selection, &model, &iter);
-
-  gtk_widget_set_sensitive (glade_xml_get_widget (plugin->gxml, "button-refresh-command"), sensitive);
-  gtk_widget_set_sensitive (glade_xml_get_widget (plugin->gxml, "button-delete-command"), sensitive);
-
-  if (sensitive)
-    {
-      gtk_tree_model_get (model, &iter, 1, &command_name, 2, &command, -1);
-      gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "command-name")), command_name);
-      gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "command")), command);
-      g_free (command_name);
-      g_free (command);
-    }
-  else
-    {
-      gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "command-name")), "");
-      gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "command")), "");
-    }
-}
-
-static void
-cb_add_command (GtkButton *button,
-                MyPlugin *plugin)
-{
-  GtkWidget *command_name;
-  GtkWidget *command;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  gchar *title;
-
-  command_name = glade_xml_get_widget (plugin->gxml, "command-name");
-  command = glade_xml_get_widget (plugin->gxml, "command");
-
-  if (gtk_entry_get_text (GTK_ENTRY (command_name))[0] == '\0'
-      || gtk_entry_get_text (GTK_ENTRY (command))[0] == '\0')
-    return;
-
-  title = g_markup_printf_escaped ("<b>%s</b>\n<small>%s</small>",
-                                   gtk_entry_get_text (GTK_ENTRY (command_name)),
-                                   gtk_entry_get_text (GTK_ENTRY (command)));
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (glade_xml_get_widget (plugin->gxml, "commands")));
-  gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-  gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, title,
-                      1, gtk_entry_get_text (GTK_ENTRY (command_name)),
-                      2, gtk_entry_get_text (GTK_ENTRY (command)), -1);
-  g_free (title);
-
-  gtk_entry_set_text (GTK_ENTRY (command_name), "");
-  gtk_entry_set_text (GTK_ENTRY (command), "");
-}
-
-static void
-cb_refresh_command (GtkButton *button,
-                    MyPlugin *plugin)
-{
-  GtkWidget *treeview;
-  GtkTreeSelection *selection;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  GtkWidget *command_name;
-  GtkWidget *command;
-  gchar *title;
-
-  command_name = glade_xml_get_widget (plugin->gxml, "command-name");
-  command = glade_xml_get_widget (plugin->gxml, "command");
-
-  if (gtk_entry_get_text (GTK_ENTRY (command_name))[0] == '\0'
-      || gtk_entry_get_text (GTK_ENTRY (command))[0] == '\0')
-    return;
-
-  treeview = glade_xml_get_widget (plugin->gxml, "commands");
-  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
-  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
-    {
-      g_critical ("Trying to refresh a command but got no selection");
-      return;
-    }
-
-  title = g_markup_printf_escaped ("<b>%s</b>\n<small>%s</small>",
-                                   gtk_entry_get_text (GTK_ENTRY (command_name)),
-                                   gtk_entry_get_text (GTK_ENTRY (command)));
-  gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, title,
-                      1, gtk_entry_get_text (GTK_ENTRY (command_name)),
-                      2, gtk_entry_get_text (GTK_ENTRY (command)), -1);
-  g_free (title);
-
-  gtk_tree_selection_unselect_all (selection);
-}
-
-static void
-cb_delete_command (GtkButton *button,
-                   MyPlugin *plugin)
-{
-  GtkWidget *treeview;
-  GtkTreeSelection *selection;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-
-  treeview = glade_xml_get_widget (plugin->gxml, "commands");
-
-  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
-  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
-    {
-      g_critical ("Trying to delete a command but got no selection");
-      return;
-    }
-
-  gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
-}
-
-static void
-cb_set_action_dialog_button_ok (GtkWidget *widget,
-                                   MyPlugin *plugin)
-{
-  const gchar *action_name;
-  const gchar *regex_pattern;
-  GRegex *regex;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  gboolean has_commands;
-  gboolean sensitive = FALSE;
-
-  action_name = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "action-name")));
-  regex_pattern = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (plugin->gxml, "regex")));
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (glade_xml_get_widget (plugin->gxml, "commands")));
-  has_commands = gtk_tree_model_get_iter_first (model, &iter);
-
-  if (action_name[0] != '\0' && regex_pattern[0] != '\0' && has_commands)
-    {
-      regex = g_regex_new (regex_pattern, 0, 0, NULL);
-      if (regex != NULL)
-        {
-          sensitive = TRUE;
-          g_regex_unref (regex);
-        }
-    }
-
-  gtk_widget_set_sensitive (glade_xml_get_widget (plugin->gxml, "action-dialog-button-ok"), sensitive);
-  return;
-}
-

Added: xfce4-clipman-plugin/trunk/panel-plugin/xfce4-clipman-settings.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/xfce4-clipman-settings.c	                        (rev 0)
+++ xfce4-clipman-plugin/trunk/panel-plugin/xfce4-clipman-settings.c	2009-06-29 14:45:41 UTC (rev 7644)
@@ -0,0 +1,639 @@
+/*
+ *  Copyright (c) 2009 Mike Massonnet <mmassonnet at xfce.org>
+ *
+ *  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, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <glade/glade.h>
+#include <libxfcegui4/libxfcegui4.h>
+#include <xfconf/xfconf.h>
+
+#include "common.h"
+#include "settings-dialog_glade.h"
+#include "actions.h"
+
+static XfconfChannel *xfconf_channel = NULL;
+static GladeXML *gxml = NULL;
+static ClipmanActions *actions = NULL;
+
+static void             prop_dialog_run                 ();
+static void             cb_show_help                    (GtkButton *button);
+static void             setup_actions_treeview          (GtkTreeView *treeview);
+static void             refresh_actions_treeview        (GtkTreeView *treeview);
+static void             apply_action                    (const gchar *original_action_name);
+static void             cb_actions_selection_changed    (GtkTreeSelection *selection);
+static void             cb_add_action                   (GtkButton *button);
+static void             cb_edit_action                  (GtkButton *button);
+static void             cb_actions_row_activated        (GtkTreeView *treeview,
+                                                         GtkTreePath *path,
+                                                         GtkTreeViewColumn *column);
+static void             cb_delete_action                (GtkButton *button);
+static void             setup_commands_treeview         (GtkTreeView *treeview);
+static void             entry_dialog_cleanup            (GtkDialog *dialog);
+#if !GLIB_CHECK_VERSION(2,16,0)
+static void           __foreach_command_fill_commands   (gpointer key,
+                                                         gpointer value,
+                                                         gpointer user_data);
+#endif
+static void             cb_commands_selection_changed   (GtkTreeSelection *selection);
+static void             cb_add_command                  (GtkButton *button);
+static void             cb_refresh_command              (GtkButton *button);
+static void             cb_delete_command               (GtkButton *button);
+static void             cb_set_action_dialog_button_ok  (GtkWidget *widget);
+
+
+
+static void
+prop_dialog_run ()
+{
+  GtkWidget *dialog;
+  GtkWidget *action_dialog;
+
+  /* GladeXML */
+  gxml = glade_xml_new_from_buffer (settings_dialog_glade, settings_dialog_glade_length, NULL, NULL);
+
+  /* Settings dialog */
+  dialog = glade_xml_get_widget (gxml, "settings-dialog");
+
+  /* Action dialog */
+  actions = clipman_actions_get ();
+  action_dialog = glade_xml_get_widget (gxml, "action-dialog");
+
+  /* General settings */
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (gxml, "add-selections")),
+                                DEFAULT_ADD_PRIMARY_CLIPBOARD);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (gxml, "history-ignore-selections")),
+                                DEFAULT_HISTORY_IGNORE_PRIMARY_CLIPBOARD);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (gxml, "save-on-quit")),
+                                DEFAULT_SAVE_ON_QUIT);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (gxml, "store-an-image")),
+                                (gboolean)DEFAULT_MAX_IMAGES_IN_HISTORY);
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (glade_xml_get_widget (gxml, "max-texts-in-history")),
+                             (gdouble)DEFAULT_MAX_TEXTS_IN_HISTORY);
+  xfconf_g_property_bind (xfconf_channel, "/settings/add-primary-clipboard", G_TYPE_BOOLEAN,
+                          G_OBJECT (glade_xml_get_widget (gxml, "add-selections")), "active");
+  xfconf_g_property_bind (xfconf_channel, "/settings/add-primary-clipboard", G_TYPE_BOOLEAN,
+                          G_OBJECT (glade_xml_get_widget (gxml, "history-ignore-selections")), "sensitive");
+  xfconf_g_property_bind (xfconf_channel, "/settings/history-ignore-primary-clipboard", G_TYPE_BOOLEAN,
+                          G_OBJECT (glade_xml_get_widget (gxml, "history-ignore-selections")), "active");
+  xfconf_g_property_bind (xfconf_channel, "/settings/save-on-quit", G_TYPE_BOOLEAN,
+                          G_OBJECT (glade_xml_get_widget (gxml, "save-on-quit")), "active");
+  xfconf_g_property_bind (xfconf_channel, "/settings/max-images-in-history", G_TYPE_UINT,
+                          G_OBJECT (glade_xml_get_widget (gxml, "store-an-image")), "active");
+  xfconf_g_property_bind (xfconf_channel, "/settings/max-texts-in-history", G_TYPE_UINT,
+                          G_OBJECT (glade_xml_get_widget (gxml, "max-texts-in-history")), "value");
+
+  /* Actions tab and dialog */
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (glade_xml_get_widget (gxml, "enable-actions")),
+                                DEFAULT_ENABLE_ACTIONS);
+  xfconf_g_property_bind (xfconf_channel, "/settings/enable-actions", G_TYPE_BOOLEAN,
+                          G_OBJECT (glade_xml_get_widget (gxml, "enable-actions")), "active");
+
+  glade_xml_signal_connect_data (gxml, "cb_add_action", G_CALLBACK (cb_add_action), NULL);
+  glade_xml_signal_connect_data (gxml, "cb_edit_action", G_CALLBACK (cb_edit_action), NULL);
+  glade_xml_signal_connect_data (gxml, "cb_delete_action", G_CALLBACK (cb_delete_action), NULL);
+  glade_xml_signal_connect_data (gxml, "cb_actions_row_activated", G_CALLBACK (cb_actions_row_activated), NULL);
+  glade_xml_signal_connect_data (gxml, "cb_add_command", G_CALLBACK (cb_add_command), NULL);
+  glade_xml_signal_connect_data (gxml, "cb_refresh_command", G_CALLBACK (cb_refresh_command), NULL);
+  glade_xml_signal_connect_data (gxml, "cb_delete_command", G_CALLBACK (cb_delete_command), NULL);
+  glade_xml_signal_connect_data (gxml, "cb_show_help", G_CALLBACK (cb_show_help), NULL);
+
+  setup_actions_treeview (GTK_TREE_VIEW (glade_xml_get_widget (gxml, "actions")));
+  setup_commands_treeview (GTK_TREE_VIEW (glade_xml_get_widget (gxml, "commands")));
+
+  /* Callbacks for the OK button sensitivity in the edit action dialog */
+  g_signal_connect_after (glade_xml_get_widget (gxml, "action-name"), "changed",
+                          G_CALLBACK (cb_set_action_dialog_button_ok), NULL);
+  g_signal_connect_after (glade_xml_get_widget (gxml, "regex"), "changed",
+                          G_CALLBACK (cb_set_action_dialog_button_ok), NULL);
+  g_signal_connect_after (glade_xml_get_widget (gxml, "button-add-command"), "clicked",
+                          G_CALLBACK (cb_set_action_dialog_button_ok), NULL);
+  g_signal_connect_after (glade_xml_get_widget (gxml, "button-delete-command"), "clicked",
+                          G_CALLBACK (cb_set_action_dialog_button_ok), NULL);
+
+  /* Run the dialog */
+  while ((gtk_dialog_run (GTK_DIALOG (dialog))) == 2);
+
+  gtk_widget_destroy (action_dialog);
+  gtk_widget_destroy (dialog);
+  g_object_unref (gxml);
+
+  /* Save the actions */
+  clipman_actions_save (actions);
+}
+
+static void
+cb_show_help (GtkButton *button)
+{
+  GdkScreen *screen;
+  gchar *locale = NULL;
+  gchar *offset;
+  gchar *filename = NULL;
+  gchar *command = NULL;
+  
+#ifdef ENABLE_NLS
+#ifdef HAVE_LOCALE_H
+  locale = g_strdup (setlocale (LC_ALL, ""));
+  if (locale != NULL)
+    {
+      offset = g_strrstr (locale, ".");
+      if (offset != NULL)
+        *offset = '\0';
+    }
+  else
+    locale = g_strdup ("C");
+#else
+  locale = g_strdup ("C");
+#endif
+
+  filename = g_strdup_printf (DATAROOTDIR"/xfce4/doc/%s/"PACKAGE".html", locale);
+  if (!g_file_test (filename, G_FILE_TEST_EXISTS))
+    {
+      offset = g_strrstr (locale, "_");
+      if (offset == NULL)
+        {
+          g_free (filename);
+          filename = g_strdup (DATAROOTDIR"/xfce4/doc/C/"PACKAGE".html");
+        }
+      else
+        {
+          *offset = '\0';
+          g_free (filename);
+          filename = g_strdup_printf (DATAROOTDIR"/xfce4/doc/%s/"PACKAGE".html", locale);
+          if (!g_file_test (filename, G_FILE_TEST_EXISTS))
+            {
+              g_free (filename);
+              filename = g_strdup (DATAROOTDIR"/xfce4/doc/C/"PACKAGE".html");
+            }
+        }
+    }
+
+  g_free (locale);
+#else
+  filename = g_strdup (DATAROOTDIR"/xfce4/doc/C/"PACKAGE".html");
+#endif
+
+  screen = gtk_widget_get_screen (GTK_WIDGET (button));
+  command = g_strdup_printf ("exo-open file://%s", filename);
+  if (gdk_spawn_command_line_on_screen (screen, command, NULL))
+    goto out;
+
+  g_free (command);
+  command = g_strdup_printf ("firefox file://%s", filename);
+  if (gdk_spawn_command_line_on_screen (screen, command, NULL))
+    goto out;
+
+  xfce_err ("Unable to open documentation \"%s\"", filename);
+
+out:
+  g_free (filename);
+  g_free (command);
+}
+
+
+
+/* Actions */
+static void
+setup_actions_treeview (GtkTreeView *treeview)
+{
+  GtkTreeSelection *selection;
+  GtkListStore *model;
+  GtkCellRenderer *cell;
+
+  /* Define the model */
+  model = gtk_list_store_new (2, G_TYPE_POINTER, G_TYPE_STRING);
+  gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (model));
+  g_object_unref (model);
+
+  /* Define the columns */
+  cell = gtk_cell_renderer_text_new ();
+  g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+  gtk_tree_view_insert_column_with_attributes (treeview, -1, "Action", cell, "markup", 1, NULL);
+
+  refresh_actions_treeview (treeview);
+
+  selection = gtk_tree_view_get_selection (treeview);
+  g_signal_connect (selection, "changed", G_CALLBACK (cb_actions_selection_changed), NULL);
+}
+
+static void
+refresh_actions_treeview (GtkTreeView *treeview)
+{
+  ClipmanActionsEntry *entry;
+  const GSList *entries;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  gchar *title;
+
+  model = gtk_tree_view_get_model (treeview);
+  gtk_list_store_clear (GTK_LIST_STORE (model));
+
+  entries = clipman_actions_get_entries (actions);
+  for (; entries != NULL; entries = entries->next)
+    {
+      entry = entries->data;
+
+      title = g_markup_printf_escaped ("<b>%s</b>\n<small>%s</small>",
+                                       entry->action_name, g_regex_get_pattern (entry->regex));
+      gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+      gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, entry, 1, title, -1);
+      g_free (title);
+    }
+}
+
+static void
+apply_action (const gchar *original_action_name)
+{
+  GtkWidget *treeview;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  const gchar *action_name;
+  const gchar *regex;
+  gchar *command_name;
+  gchar *command;
+
+  action_name = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (gxml, "action-name")));
+  regex = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (gxml, "regex")));
+
+  treeview = glade_xml_get_widget (gxml, "commands");
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
+  if (!gtk_tree_model_get_iter_first (model, &iter))
+    return;
+
+  /* Remove the old actions */
+  if (original_action_name != NULL)
+    clipman_actions_remove (actions, original_action_name);
+
+  /* Add the new actions */
+  do
+    {
+      gtk_tree_model_get (model, &iter, 1, &command_name, 2, &command, -1);
+      clipman_actions_add (actions, action_name, regex, command_name, command);
+      g_free (command_name);
+      g_free (command);
+    }
+  while (gtk_tree_model_iter_next (model, &iter));
+
+  /* Refresh the actions treeview */
+  treeview = glade_xml_get_widget (gxml, "actions");
+  refresh_actions_treeview (GTK_TREE_VIEW (treeview));
+}
+
+static void
+cb_actions_selection_changed (GtkTreeSelection *selection)
+{
+  GtkTreeModel *model;
+  gboolean sensitive;
+
+  sensitive = gtk_tree_selection_get_selected (selection, &model, NULL);
+
+  gtk_widget_set_sensitive (glade_xml_get_widget (gxml, "button-edit-action"), sensitive);
+  gtk_widget_set_sensitive (glade_xml_get_widget (gxml, "button-delete-action"), sensitive);
+}
+
+static void
+cb_add_action (GtkButton *button)
+{
+  GtkWidget *dialog;
+  gint res;
+
+  dialog = glade_xml_get_widget (gxml, "action-dialog");
+  entry_dialog_cleanup (GTK_DIALOG (dialog));
+
+  res = gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_hide (dialog);
+
+  if (res == 1)
+    apply_action (NULL);
+}
+
+static void
+cb_edit_action (GtkButton *button)
+{
+  GtkWidget *treeview;
+  GtkTreeSelection *selection;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  GtkTreePath *path;
+  GtkTreeViewColumn *column;
+
+  treeview = glade_xml_get_widget (gxml, "actions");
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+    {
+      g_critical ("Trying to edit an action but got no selection");
+      return;
+    }
+
+  path = gtk_tree_model_get_path (model, &iter);
+  column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), 1);
+  gtk_tree_view_row_activated (GTK_TREE_VIEW (treeview), path, column);
+  gtk_tree_path_free (path);
+}
+
+static void
+cb_actions_row_activated (GtkTreeView *treeview,
+                          GtkTreePath *path,
+                          GtkTreeViewColumn *column)
+{
+  ClipmanActionsEntry *entry;
+  GtkTreeModel *actions_model, *commands_model;
+  GtkTreeIter iter;
+  GtkWidget *dialog;
+  gchar *title;
+  gint res;
+
+  dialog = glade_xml_get_widget (gxml, "action-dialog");
+  entry_dialog_cleanup (GTK_DIALOG (dialog));
+
+  actions_model = gtk_tree_view_get_model (treeview);
+  gtk_tree_model_get_iter (actions_model, &iter, path);
+  gtk_tree_model_get (actions_model, &iter, 0, &entry, -1);
+
+  commands_model = gtk_tree_view_get_model (GTK_TREE_VIEW (glade_xml_get_widget (gxml, "commands")));
+#if GLIB_CHECK_VERSION (2,16,0)
+  GHashTableIter hiter;
+  gpointer key, value;
+  g_hash_table_iter_init (&hiter, entry->commands);
+  while (g_hash_table_iter_next (&hiter, &key, &value))
+    {
+      title = g_markup_printf_escaped ("<b>%s</b>\n<small>%s</small>", (gchar *)key, (gchar *)value);
+      gtk_list_store_append (GTK_LIST_STORE (commands_model), &iter);
+      gtk_list_store_set (GTK_LIST_STORE (commands_model), &iter, 0, title, 1, key, 2, value, -1);
+      g_free (title);
+    }
+#else
+  g_hash_table_foreach (entry->commands, (GHFunc)__foreach_command_fill_commands, commands_model);
+#endif
+
+  gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (gxml, "action-name")), entry->action_name);
+  gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (gxml, "regex")), g_regex_get_pattern (entry->regex));
+
+  res = gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_hide (dialog);
+
+  if (res == 1)
+    apply_action (entry->action_name);
+}
+
+static void
+cb_delete_action (GtkButton *button)
+{
+  ClipmanActionsEntry *entry;
+  GtkWidget *treeview;
+  GtkTreeSelection *selection;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+
+  treeview = glade_xml_get_widget (gxml, "actions");
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+    {
+      g_critical ("Trying to remove an action but got no selection");
+      return;
+    }
+
+  gtk_tree_model_get (model, &iter, 0, &entry, -1);
+  clipman_actions_remove (actions, entry->action_name);
+  gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+}
+
+
+
+/* Entry Dialog */
+static void
+setup_commands_treeview (GtkTreeView *treeview)
+{
+  GtkTreeSelection *selection;
+  GtkListStore *model;
+  GtkCellRenderer *cell;
+
+  /* Define the model */
+  model = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+  gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (model));
+  g_object_unref (model);
+
+  /* Define the columns */
+  cell = gtk_cell_renderer_text_new ();
+  g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+  gtk_tree_view_insert_column_with_attributes (treeview, -1, "Command", cell, "markup", 0, NULL);
+
+  selection = gtk_tree_view_get_selection (treeview);
+  g_signal_connect (selection, "changed", G_CALLBACK (cb_commands_selection_changed), NULL);
+}
+
+static void
+entry_dialog_cleanup (GtkDialog *dialog)
+{
+  GtkTreeModel *model;
+
+  gtk_widget_set_sensitive (glade_xml_get_widget (gxml, "action-dialog-button-ok"), FALSE);
+
+  gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (gxml, "action-name")), "");
+  gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (gxml, "regex")), "");
+
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (glade_xml_get_widget (gxml, "commands")));
+  gtk_list_store_clear (GTK_LIST_STORE (model));
+}
+
+#if !GLIB_CHECK_VERSION(2,16,0)
+static void
+__foreach_command_fill_commands (gpointer key,
+                                 gpointer value,
+                                 gpointer user_data)
+{
+  GtkTreeModel *model = user_data;
+  GtkTreeIter iter;
+  gchar *title;
+
+  title = g_markup_printf_escaped ("<b>%s</b>\n<small>%s</small>", (gchar *)key, (gchar *)value);
+  gtk_list_store_append (GTK_LIST_STORE (_model), &iter);
+  gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, title, 1, key, 2, value, -1);
+  g_free (title);
+}
+#endif
+
+static void
+cb_commands_selection_changed (GtkTreeSelection *selection)
+{
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  gboolean sensitive;
+  gchar *command_name = NULL;
+  gchar *command = NULL;
+
+  sensitive = gtk_tree_selection_get_selected (selection, &model, &iter);
+
+  gtk_widget_set_sensitive (glade_xml_get_widget (gxml, "button-refresh-command"), sensitive);
+  gtk_widget_set_sensitive (glade_xml_get_widget (gxml, "button-delete-command"), sensitive);
+
+  if (sensitive)
+    {
+      gtk_tree_model_get (model, &iter, 1, &command_name, 2, &command, -1);
+      gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (gxml, "command-name")), command_name);
+      gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (gxml, "command")), command);
+      g_free (command_name);
+      g_free (command);
+    }
+  else
+    {
+      gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (gxml, "command-name")), "");
+      gtk_entry_set_text (GTK_ENTRY (glade_xml_get_widget (gxml, "command")), "");
+    }
+}
+
+static void
+cb_add_command (GtkButton *button)
+{
+  GtkWidget *command_name;
+  GtkWidget *command;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  gchar *title;
+
+  command_name = glade_xml_get_widget (gxml, "command-name");
+  command = glade_xml_get_widget (gxml, "command");
+
+  if (gtk_entry_get_text (GTK_ENTRY (command_name))[0] == '\0'
+      || gtk_entry_get_text (GTK_ENTRY (command))[0] == '\0')
+    return;
+
+  title = g_markup_printf_escaped ("<b>%s</b>\n<small>%s</small>",
+                                   gtk_entry_get_text (GTK_ENTRY (command_name)),
+                                   gtk_entry_get_text (GTK_ENTRY (command)));
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (glade_xml_get_widget (gxml, "commands")));
+  gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+  gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, title,
+                      1, gtk_entry_get_text (GTK_ENTRY (command_name)),
+                      2, gtk_entry_get_text (GTK_ENTRY (command)), -1);
+  g_free (title);
+
+  gtk_entry_set_text (GTK_ENTRY (command_name), "");
+  gtk_entry_set_text (GTK_ENTRY (command), "");
+}
+
+static void
+cb_refresh_command (GtkButton *button)
+{
+  GtkWidget *treeview;
+  GtkTreeSelection *selection;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  GtkWidget *command_name;
+  GtkWidget *command;
+  gchar *title;
+
+  command_name = glade_xml_get_widget (gxml, "command-name");
+  command = glade_xml_get_widget (gxml, "command");
+
+  if (gtk_entry_get_text (GTK_ENTRY (command_name))[0] == '\0'
+      || gtk_entry_get_text (GTK_ENTRY (command))[0] == '\0')
+    return;
+
+  treeview = glade_xml_get_widget (gxml, "commands");
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+    {
+      g_critical ("Trying to refresh a command but got no selection");
+      return;
+    }
+
+  title = g_markup_printf_escaped ("<b>%s</b>\n<small>%s</small>",
+                                   gtk_entry_get_text (GTK_ENTRY (command_name)),
+                                   gtk_entry_get_text (GTK_ENTRY (command)));
+  gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, title,
+                      1, gtk_entry_get_text (GTK_ENTRY (command_name)),
+                      2, gtk_entry_get_text (GTK_ENTRY (command)), -1);
+  g_free (title);
+
+  gtk_tree_selection_unselect_all (selection);
+}
+
+static void
+cb_delete_command (GtkButton *button)
+{
+  GtkWidget *treeview;
+  GtkTreeSelection *selection;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+
+  treeview = glade_xml_get_widget (gxml, "commands");
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+    {
+      g_critical ("Trying to delete a command but got no selection");
+      return;
+    }
+
+  gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+}
+
+static void
+cb_set_action_dialog_button_ok (GtkWidget *widget)
+{
+  const gchar *action_name;
+  const gchar *regex_pattern;
+  GRegex *regex;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  gboolean has_commands;
+  gboolean sensitive = FALSE;
+
+  action_name = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (gxml, "action-name")));
+  regex_pattern = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (gxml, "regex")));
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (glade_xml_get_widget (gxml, "commands")));
+  has_commands = gtk_tree_model_get_iter_first (model, &iter);
+
+  if (action_name[0] != '\0' && regex_pattern[0] != '\0' && has_commands)
+    {
+      regex = g_regex_new (regex_pattern, 0, 0, NULL);
+      if (regex != NULL)
+        {
+          sensitive = TRUE;
+          g_regex_unref (regex);
+        }
+    }
+
+  gtk_widget_set_sensitive (glade_xml_get_widget (gxml, "action-dialog-button-ok"), sensitive);
+  return;
+}
+
+
+
+gint
+main (gint argc,
+      gchar *argv[])
+{
+  GtkWidget *dialog;
+  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, NULL);
+  xfconf_init (NULL);
+  gtk_init (&argc, &argv);
+  xfconf_channel = xfconf_channel_new_with_property_base ("xfce4-panel", "/plugins/clipman");
+  prop_dialog_run ();
+  xfconf_shutdown ();
+  return 0;
+}




More information about the Goodies-commits mailing list