comparison finch/plugins/gntclipboard.c @ 19575:87e9d418cbf6

Show a helpful error message when the plugin fails to load.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 02 Sep 2007 21:20:32 +0000
parents 30829e806dae
children 44b4e8bd759b
comparison
equal deleted inserted replaced
19572:cfc4e56a6a1e 19575:87e9d418cbf6
36 #include <glib.h> 36 #include <glib.h>
37 37
38 #include <plugin.h> 38 #include <plugin.h>
39 #include <version.h> 39 #include <version.h>
40 #include <debug.h> 40 #include <debug.h>
41 #include <notify.h>
41 #include <gntwm.h> 42 #include <gntwm.h>
42 43
43 #include <gntplugin.h> 44 #include <gntplugin.h>
44 45
46 #ifdef HAVE_X11
45 static pid_t child = 0; 47 static pid_t child = 0;
46 48
47 static gulong sig_handle; 49 static gulong sig_handle;
48 50
49 static void 51 static void
50 set_clip(gchar *string) 52 set_clip(gchar *string)
51 { 53 {
52 #ifdef HAVE_X11
53 Window w; 54 Window w;
54 XEvent e, respond; 55 XEvent e, respond;
55 XSelectionRequestEvent *req; 56 XSelectionRequestEvent *req;
56 const char *ids; 57 const char *ids;
57 Display *dpy = XOpenDisplay(NULL); 58 Display *dpy = XOpenDisplay(NULL);
87 XFlush (dpy); 88 XFlush (dpy);
88 } else if (e.type == SelectionClear) { 89 } else if (e.type == SelectionClear) {
89 return; 90 return;
90 } 91 }
91 } 92 }
92 #endif
93 return; 93 return;
94 } 94 }
95 95
96 static void 96 static void
97 clipboard_changed(GntWM *wm, gchar *string) 97 clipboard_changed(GntWM *wm, gchar *string)
98 { 98 {
99 #ifdef HAVE_X11
100 if (child) { 99 if (child) {
101 kill(child, SIGTERM); 100 kill(child, SIGTERM);
102 } 101 }
103 if ((child = fork() == 0)) { 102 if ((child = fork() == 0)) {
104 set_clip(string); 103 set_clip(string);
105 _exit(0); 104 _exit(0);
106 } 105 }
106 }
107 #endif 107 #endif
108 }
109 108
110 static gboolean 109 static gboolean
111 plugin_load(PurplePlugin *plugin) 110 plugin_load(PurplePlugin *plugin)
112 { 111 {
113 #ifdef HAVE_X11 112 #ifdef HAVE_X11
114 if (!XOpenDisplay(NULL)) { 113 if (!XOpenDisplay(NULL)) {
115 purple_debug_warning("gntclipboard", "Couldn't find X display\n"); 114 purple_debug_warning("gntclipboard", "Couldn't find X display\n");
115 purple_notify_error(NULL, _("Error"), _("Error loading the plugin."),
116 _("Couldn't find X display"));
116 return FALSE; 117 return FALSE;
117 } 118 }
118 #endif
119 if (!getenv("WINDOWID")) { 119 if (!getenv("WINDOWID")) {
120 purple_debug_warning("gntclipboard", "Couldn't find window\n"); 120 purple_debug_warning("gntclipboard", "Couldn't find window\n");
121 purple_notify_error(NULL, _("Error"), _("Error loading the plugin."),
122 _("Couldn't find window"));
121 return FALSE; 123 return FALSE;
122 } 124 }
123 sig_handle = g_signal_connect(G_OBJECT(gnt_get_clipboard()), "clipboard_changed", G_CALLBACK(clipboard_changed), NULL); 125 sig_handle = g_signal_connect(G_OBJECT(gnt_get_clipboard()), "clipboard_changed", G_CALLBACK(clipboard_changed), NULL);
124 return TRUE; 126 return TRUE;
127 #else
128 purple_notify_error(NULL, _("Error"), _("Error loading the plugin."),
129 _("This plugin cannot be loaded because it was not built with X11 support."));
130 return FALSE;
131 #endif
125 } 132 }
126 133
127 static gboolean 134 static gboolean
128 plugin_unload(PurplePlugin *plugin) 135 plugin_unload(PurplePlugin *plugin)
129 { 136 {
137 #ifdef HAVE_X11
130 if (child) { 138 if (child) {
131 kill(child, SIGTERM); 139 kill(child, SIGTERM);
132 child = 0; 140 child = 0;
133 } 141 }
134 g_signal_handler_disconnect(G_OBJECT(gnt_get_clipboard()), sig_handle); 142 g_signal_handler_disconnect(G_OBJECT(gnt_get_clipboard()), sig_handle);
143 #endif
135 return TRUE; 144 return TRUE;
136 } 145 }
137 146
138 static PurplePluginInfo info = 147 static PurplePluginInfo info =
139 { 148 {