Browse Source

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.
upstream/xfce4-panel-4.10.1
Nick Schermer 12 years ago
parent
commit
e538ca4c74
  1. 10
      common/panel-private.h
  2. 2
      panel/panel-dialogs.c
  3. 29
      panel/panel-plugin-external-46.c
  4. 29
      panel/panel-plugin-external.c

10
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)

2
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 "

29
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,19 +473,18 @@ 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),
@ -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));

29
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,19 +488,18 @@ 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),
@ -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));

Loading…
Cancel
Save