[Xfce4-commits] <xfce4-panel:devel> Use a timer for a minimum time between auto plugin restart.

Nick Schermer noreply at xfce.org
Wed Jan 20 21:08:07 CET 2010


Updating branch refs/heads/devel
         to 4d6d78392c3ea237284890ba8326ff2141875210 (commit)
       from 9e19d4d961835c5762f711852c20f068ac0b2102 (commit)

commit 4d6d78392c3ea237284890ba8326ff2141875210
Author: Nick Schermer <nick at xfce.org>
Date:   Wed Jan 20 15:31:56 2010 +0100

    Use a timer for a minimum time between auto plugin restart.
    
    The restart counter was a bit flawed, because if the panel would
    run for weeks and 3 restarts occured, it's not a big deal, still
    the panel would've bothered the user what to do.
    
    We now use a minimum time between restarts, if there was another
    restart in the last 60 seconds, ask the user what to do.

 common/panel-private.h           |   10 +++-------
 panel/panel-dialogs.c            |    2 +-
 panel/panel-plugin-external-46.c |   29 +++++++++++++++++------------
 panel/panel-plugin-external.c    |   29 +++++++++++++++++------------
 4 files changed, 38 insertions(+), 32 deletions(-)

diff --git a/common/panel-private.h b/common/panel-private.h
index aee58f0..d694c29 100644
--- a/common/panel-private.h
+++ b/common/panel-private.h
@@ -63,13 +63,9 @@
 /* xfconf property base (printf format) */
 #define PANEL_PLUGIN_PROPERTY_BASE "/plugins/plugin-%d"
 
-/* Number of automatic plugin restarts before the panel
- * asks the users what to do  */
-#ifndef NDEBUG
-#define PANEL_PLUGIN_AUTOMATIC_RESTARTS (0)
-#else
-#define PANEL_PLUGIN_AUTOMATIC_RESTARTS (2)
-#endif
+/* minimum time in seconds between automatic restarts of panel plugins
+ * without asking the user what to do */
+#define PANEL_PLUGIN_AUTO_RESTART (60)
 
 /* quick GList and GSList counting without traversing */
 #define LIST_HAS_ONE_ENTRY(l)           ((l) != NULL && (l)->next == NULL)
diff --git a/panel/panel-dialogs.c b/panel/panel-dialogs.c
index 60c93b2..68d677a 100644
--- a/panel/panel-dialogs.c
+++ b/panel/panel-dialogs.c
@@ -163,7 +163,7 @@ panel_dialogs_restart_plugin (GtkWindow   *parent,
   dialog = gtk_message_dialog_new (parent,
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
                                    GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
-                                   _("Plugin \"%s\" unexpectedly left the building, do you want to restart it?"),
+                                   _("Plugin \"%s\" unexpectedly left the panel, do you want to restart it?"),
                                    plugin_name);
   gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("If you press Execute "
                                             "the panel will try to restart the plugin otherwise it "
diff --git a/panel/panel-plugin-external-46.c b/panel/panel-plugin-external-46.c
index 05a9b1b..b77cbf4 100644
--- a/panel/panel-plugin-external-46.c
+++ b/panel/panel-plugin-external-46.c
@@ -117,8 +117,8 @@ struct _PanelPluginExternal46
   /* client-event queue */
   GSList           *queue;
 
-  /* number of automatic restarts restarts */
-  guint             n_restarts;
+  /* auto restart timer */
+  GTimer           *restart_timer;
 
   /* some info we store here */
   guint             show_configure : 1;
@@ -213,7 +213,7 @@ panel_plugin_external_46_init (PanelPluginExternal46 *external)
   external->queue = NULL;
   external->arguments = NULL;
   external->plug_embedded = FALSE;
-  external->n_restarts = 0;
+  external->restart_timer = NULL;
   external->show_configure = FALSE;
   external->show_about = FALSE;
 
@@ -265,6 +265,9 @@ panel_plugin_external_46_finalize (GObject *object)
 
   g_strfreev (external->arguments);
 
+  if (external->restart_timer != NULL)
+    g_timer_destroy (external->restart_timer);
+
   g_object_unref (G_OBJECT (external->module));
 
   (*G_OBJECT_CLASS (panel_plugin_external_46_parent_class)->finalize) (object);
@@ -470,20 +473,19 @@ panel_plugin_external_46_plug_removed (GtkSocket *socket)
   window = gtk_widget_get_toplevel (GTK_WIDGET (socket));
   panel_return_val_if_fail (PANEL_IS_WINDOW (window), FALSE);
 
-  if (external->n_restarts++ <= PANEL_PLUGIN_AUTOMATIC_RESTARTS)
+  /* create a restart timer if we don't have any */
+  if (external->restart_timer == NULL)
+    external->restart_timer = g_timer_new ();
+
+  if (g_timer_elapsed (external->restart_timer, NULL) > PANEL_PLUGIN_AUTO_RESTART)
     {
-      g_message ("Automatically restarting plugin %s-%d, try %d",
+      g_message ("Automatically restarting plugin %s-%d",
                  panel_module_get_name (external->module),
-                 external->unique_id, external->n_restarts);
+                 external->unique_id);
     }
-  else if (panel_dialogs_restart_plugin (GTK_WINDOW (window),
+  else if (!panel_dialogs_restart_plugin (GTK_WINDOW (window),
                panel_module_get_display_name (external->module)))
     {
-      /* reset the restart counter */
-      external->n_restarts = 0;
-    }
-  else
-    {
       /* cleanup the plugin configuration (in panel-application) */
       xfce_panel_plugin_provider_emit_signal (XFCE_PANEL_PLUGIN_PROVIDER (external),
                                               PROVIDER_SIGNAL_REMOVE_PLUGIN);
@@ -494,6 +496,9 @@ panel_plugin_external_46_plug_removed (GtkSocket *socket)
       return FALSE;
     }
 
+  /* reset the restart counter, user agreed to restart again */
+  g_timer_reset (external->restart_timer);
+
   /* send panel information to the plugin (queued until realize) */
   panel_window_set_povider_info (PANEL_WINDOW (window), GTK_WIDGET (external));
 
diff --git a/panel/panel-plugin-external.c b/panel/panel-plugin-external.c
index ac397e0..b8b02d3 100644
--- a/panel/panel-plugin-external.c
+++ b/panel/panel-plugin-external.c
@@ -135,8 +135,8 @@ struct _PanelPluginExternal
   /* dbus message queue */
   GPtrArray        *queue;
 
-  /* number of automatic restarts restarts */
-  guint             n_restarts;
+  /* auto restart timer */
+  GTimer           *restart_timer;
 
   /* some info we store here */
   guint             show_configure : 1;
@@ -239,8 +239,8 @@ panel_plugin_external_init (PanelPluginExternal *external)
   external->module = NULL;
   external->arguments = NULL;
   external->queue = NULL;
+  external->restart_timer = NULL;
   external->plug_embedded = FALSE;
-  external->n_restarts = 0;
   external->show_configure = FALSE;
   external->show_about = FALSE;
 
@@ -324,6 +324,9 @@ panel_plugin_external_finalize (GObject *object)
 
   g_strfreev (external->arguments);
 
+  if (external->restart_timer != NULL)
+    g_timer_destroy (external->restart_timer);
+
   g_object_unref (G_OBJECT (external->module));
 
   (*G_OBJECT_CLASS (panel_plugin_external_parent_class)->finalize) (object);
@@ -485,20 +488,19 @@ panel_plugin_external_plug_removed (GtkSocket *socket)
   window = gtk_widget_get_toplevel (GTK_WIDGET (socket));
   panel_return_val_if_fail (PANEL_IS_WINDOW (window), FALSE);
 
-  if (external->n_restarts++ <= PANEL_PLUGIN_AUTOMATIC_RESTARTS)
+  /* create a restart timer if we don't have any */
+  if (external->restart_timer == NULL)
+    external->restart_timer = g_timer_new ();
+
+  if (g_timer_elapsed (external->restart_timer, NULL) > PANEL_PLUGIN_AUTO_RESTART)
     {
-      g_message ("Automatically restarting plugin %s-%d, try %d",
+      g_message ("Automatically restarting plugin %s-%d",
                  panel_module_get_name (external->module),
-                 external->unique_id, external->n_restarts);
+                 external->unique_id);
     }
-  else if (panel_dialogs_restart_plugin (GTK_WINDOW (window),
+  else if (!panel_dialogs_restart_plugin (GTK_WINDOW (window),
                panel_module_get_display_name (external->module)))
     {
-      /* reset the restart counter */
-      external->n_restarts = 0;
-    }
-  else
-    {
       /* cleanup the plugin configuration (in panel-application) */
       xfce_panel_plugin_provider_emit_signal (XFCE_PANEL_PLUGIN_PROVIDER (external),
                                               PROVIDER_SIGNAL_REMOVE_PLUGIN);
@@ -509,6 +511,9 @@ panel_plugin_external_plug_removed (GtkSocket *socket)
       return FALSE;
     }
 
+  /* reset the restart counter, user agreed to restart again */
+  g_timer_reset (external->restart_timer);
+
   /* send panel information to the plugin (queued until realize) */
   panel_window_set_povider_info (PANEL_WINDOW (window), GTK_WIDGET (external));
 



More information about the Xfce4-commits mailing list