Updating branch refs/heads/0.6.x to 4f0105bab613e65956c8d41c628cd6066fa8f77d (commit) from d66211cd85bef1987b619e78838a3148c3b794ec (commit)
commit 4f0105bab613e65956c8d41c628cd6066fa8f77d Author: Andre Ellguth <an...@ellguth.com> Date: Thu Aug 16 20:52:15 2012 +0200 Check if only one instance of the plugin is run. panel-plugin/misc.c | 45 ++++++++++++++++++++++++++++ panel-plugin/misc.h | 1 + panel-plugin/wmdock.c | 21 +++++++++++++ po/xfce4-wmdock-plugin.pot | 71 -------------------------------------------- 4 files changed, 67 insertions(+), 71 deletions(-) diff --git a/panel-plugin/misc.c b/panel-plugin/misc.c index de23b88..5472a93 100644 --- a/panel-plugin/misc.c +++ b/panel-plugin/misc.c @@ -34,6 +34,7 @@ #include "extern.h" #include "wmdock.h" +#include "debug.h" #include "dockapp.h" #include "misc.h" @@ -172,6 +173,50 @@ static void wmdock_icon_pressed(GtkWidget *icon) } +/** + * Function get the number of xfce4-wmdock-instances are running. + * + * @return int Process count of wmdock-plugin. + */ +int wmdock_get_instance_count() +{ + int count = 0; + +#ifdef __linux__ + int i; + FILE *fp = NULL; + char buf[BUF_MAX], username[BUF_MAX]; + +#ifdef HAVE_CONFIG_H + snprintf(buf, BUF_MAX, "ps -C %s -ouser=", GETTEXT_PACKAGE); +#else + snprintf(cmd, BUF_MAX, "ps -C xfce4-wmdock-plugin -ouser="); +#endif /* HAVE_CONFIG_H */ + + fp = popen(buf, "r"); + if(!fp) + return(-1); + + strncpy(username, (const char *) g_get_user_name(), BUF_MAX); + while(!feof(fp)) { + buf[0] = 0; + fgets(buf, BUF_MAX, fp); + /* Remove all newline and carriage returns. */ + for(i = 0; i < BUF_MAX; i++) + buf[i] = (buf[i] == 0xA || buf[i] == 0xD) ? 0 : buf[i]; + + if(!strncmp(buf, username, BUF_MAX)) + count++; + } + pclose(fp); +#endif /* __linux__ */ + + debug("misc.c: Instance count: %d", count); + + return count; +} + + void wmdock_panel_draw_wmdock_icon (gboolean redraw) { static GtkWidget *eventBox = NULL; diff --git a/panel-plugin/misc.h b/panel-plugin/misc.h index 5d2adc6..44c8fd6 100644 --- a/panel-plugin/misc.h +++ b/panel-plugin/misc.h @@ -29,5 +29,6 @@ gboolean has_dockapp_hint(WnckWindow *); gboolean comp_dockapp_with_filterlist(const gchar *); gboolean comp_str_with_pattern(const gchar *, gchar *, gsize); void wmdock_panel_draw_wmdock_icon (gboolean redraw); +int wmdock_get_instance_count(); #endif /* __MISC_H__ */ diff --git a/panel-plugin/wmdock.c b/panel-plugin/wmdock.c index 31cf9e0..0f6cf64 100644 --- a/panel-plugin/wmdock.c +++ b/panel-plugin/wmdock.c @@ -149,18 +149,39 @@ static WmdockPlugin *wmdock_plugin_new (XfcePanelPlugin* plugin) static void wmdock_construct (XfcePanelPlugin *plugin) { WnckScreen *s; + GtkWidget *gtkDlg; init_debug(); s = wnck_screen_get(0); +#ifdef HAVE_CONFIG_H xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); +#endif /* HAVE_CONFIG_H */ XfceDockAppAtom=XInternAtom(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "_XFCE4_DOCKAPP",False); wmdock = wmdock_plugin_new (plugin); + if(wmdock_get_instance_count() > 1) { + gtkDlg = gtk_message_dialog_new(GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, +#ifdef HAVE_CONFIG_H + _("Only a single instance of `%s' can run."), + GETTEXT_PACKAGE); +#else + _("Only a single instance of `xfce4-wmdock-plugin' can run.")); +#endif /* HAVE_CONFIG_H */ + + g_signal_connect (gtkDlg, "response", G_CALLBACK (wmdock_error_dialog_response), NULL); + gtk_dialog_run (GTK_DIALOG(gtkDlg)); + + exit(EXIT_SUCCESS); + } + g_signal_connect(s, "window_opened", G_CALLBACK(wmdock_window_open), NULL); g_signal_connect (plugin, "size-changed", G_CALLBACK (wmdock_size_changed), NULL); g_signal_connect (plugin, "orientation-changed", G_CALLBACK (wmdock_orientation_changed), NULL); diff --git a/po/xfce4-wmdock-plugin.pot b/po/xfce4-wmdock-plugin.pot deleted file mode 100644 index 143d50e..0000000 --- a/po/xfce4-wmdock-plugin.pot +++ /dev/null @@ -1,71 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-01-26 20:22+0100\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" -"Language-Team: LANGUAGE <l...@li.org>\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=CHARSET\n" -"Content-Transfer-Encoding: 8bit\n" - -#: panel-plugin/wmdock.c:196 -#, c-format -msgid "Do you want remove the dockapp \"%s\"?" -msgstr "" - -#: panel-plugin/wmdock.c:398 -msgid "No dockapp is running!" -msgstr "" - -#: panel-plugin/wmdock.c:858 -#, c-format -msgid "Failed to start %s!" -msgstr "" - -#: panel-plugin/wmdock.c:1148 -msgid "WMdock" -msgstr "" - -#: panel-plugin/wmdock.c:1151 -msgid "Remove dockapp" -msgstr "" - -#: panel-plugin/wmdock.c:1167 -msgid "General settings" -msgstr "" - -#: panel-plugin/wmdock.c:1168 -msgid "Dockapp detection" -msgstr "" - -#: panel-plugin/wmdock.c:1216 -msgid "Select dockapp to configure:" -msgstr "" - -#: panel-plugin/wmdock.c:1225 -msgid "Shell command:" -msgstr "" - -#: panel-plugin/wmdock.c:1236 -msgid "Display tile in the background." -msgstr "" - -#: panel-plugin/wmdock.c:1237 -msgid "" -"Display a separate WMdock properties\n" -"button in the panel." -msgstr "" - -#: panel-plugin/wmdock.c:1238 -msgid "" -"Add only dockapps which start with\n" -"wm* in the name." -msgstr "" _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits