Advertisement
Guest User

Untitled

a guest
Apr 28th, 2010
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.53 KB | None | 0 0
  1. Index: pidgin/gtkdocklet-gtk.c
  2. ===================================================================
  3. --- a/pidgin/gtkdocklet-gtk.c 067bfa0897fcb1b8cab70aea3f7e97f0a15f53dd
  4. +++ b/pidgin/gtkdocklet-gtk.c 067bfa0897fcb1b8cab70aea3f7e97f0a15f53dd
  5. @@ -0,0 +1,168 @@
  6. +/*
  7. + * System tray icon (aka docklet) plugin for Purple
  8. + *
  9. + * Copyright (C) 2007 Anders Hasselqvist
  10. + *
  11. + * This program is free software; you can redistribute it and/or
  12. + * modify it under the terms of the GNU General Public License as
  13. + * published by the Free Software Foundation; either version 2 of the
  14. + * License, or (at your option) any later version.
  15. + *
  16. + * This program is distributed in the hope that it will be useful, but
  17. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. + * General Public License for more details.
  20. + *
  21. + * You should have received a copy of the GNU General Public License
  22. + * along with this program; if not, write to the Free Software
  23. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  24. + * 02111-1307, USA.
  25. + */
  26. +
  27. +#include "internal.h"
  28. +#include "pidgin.h"
  29. +#include "debug.h"
  30. +#include "prefs.h"
  31. +#include "pidginstock.h"
  32. +#include "gtkdocklet.h"
  33. +
  34. +#if GTK_CHECK_VERSION(2,10,0)
  35. +
  36. +/* globals */
  37. +GtkStatusIcon *docklet = NULL;
  38. +
  39. +static void
  40. +docklet_gtk_status_activated_cb(GtkStatusIcon *status_icon, gpointer user_data)
  41. +{
  42. + purple_debug_info("docklet", "button clicked %d\n", 1);
  43. +
  44. + pidgin_docklet_clicked(1);
  45. +}
  46. +
  47. +static void
  48. +docklet_gtk_status_clicked_cb(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data)
  49. +{
  50. + purple_debug_info("docklet", "button clicked %d\n", button);
  51. +
  52. + pidgin_docklet_clicked(button);
  53. +}
  54. +
  55. +static void
  56. +docklet_gtk_status_update_icon(PurpleStatusPrimitive status, gboolean connecting, gboolean pending)
  57. +{
  58. + const gchar *icon_name = NULL;
  59. +
  60. + switch (status) {
  61. + case PURPLE_STATUS_OFFLINE:
  62. + icon_name = PIDGIN_STOCK_TRAY_OFFLINE;
  63. + break;
  64. + case PURPLE_STATUS_AWAY:
  65. + icon_name = PIDGIN_STOCK_TRAY_AWAY;
  66. + break;
  67. + case PURPLE_STATUS_UNAVAILABLE:
  68. + icon_name = PIDGIN_STOCK_TRAY_BUSY;
  69. + break;
  70. + case PURPLE_STATUS_EXTENDED_AWAY:
  71. + icon_name = PIDGIN_STOCK_TRAY_XA;
  72. + break;
  73. + case PURPLE_STATUS_INVISIBLE:
  74. + icon_name = PIDGIN_STOCK_TRAY_INVISIBLE;
  75. + break;
  76. + default:
  77. + icon_name = PIDGIN_STOCK_TRAY_AVAILABLE;
  78. + break;
  79. + }
  80. +
  81. + if (pending)
  82. + icon_name = PIDGIN_STOCK_TRAY_PENDING;
  83. + if (connecting)
  84. + icon_name = PIDGIN_STOCK_TRAY_CONNECT;
  85. +
  86. + if (icon_name) {
  87. + gtk_status_icon_set_from_stock(docklet, icon_name);
  88. + }
  89. +
  90. + if(purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/docklet/blink")) {
  91. + gtk_status_icon_set_blinking(docklet, (pending && !connecting));
  92. + } else if(gtk_status_icon_get_blinking(docklet)) {
  93. + gtk_status_icon_set_blinking(docklet, FALSE);
  94. + }
  95. +}
  96. +
  97. +static void
  98. +docklet_gtk_status_set_tooltip(gchar *tooltip)
  99. +{
  100. + if (tooltip) {
  101. + gtk_status_icon_set_tooltip(docklet, tooltip);
  102. + } else {
  103. + gtk_status_icon_set_tooltip(docklet, NULL);
  104. + }
  105. +}
  106. +
  107. +static void
  108. +docklet_gtk_status_position_menu(GtkMenu *menu,
  109. + int *x, int *y, gboolean *push_in,
  110. + gpointer user_data)
  111. +{
  112. + gtk_status_icon_position_menu(menu, x, y, push_in, docklet);
  113. +}
  114. +
  115. +static void
  116. +docklet_gtk_status_destroy(void)
  117. +{
  118. + g_return_if_fail(docklet != NULL);
  119. +
  120. + pidgin_docklet_remove();
  121. +
  122. + g_object_unref(G_OBJECT(docklet));
  123. + docklet = NULL;
  124. +
  125. + purple_debug_info("docklet", "destroyed\n");
  126. +}
  127. +
  128. +static void
  129. +docklet_gtk_status_create(gboolean recreate)
  130. +{
  131. + if (docklet) {
  132. + /* if this is being called when a tray icon exists, it's because
  133. + something messed up. try destroying it before we proceed,
  134. + although docklet_refcount may be all hosed. hopefully won't happen. */
  135. + purple_debug_warning("docklet", "trying to create icon but it already exists?\n");
  136. + docklet_gtk_status_destroy();
  137. + }
  138. +
  139. + docklet = gtk_status_icon_new();
  140. + g_return_if_fail(docklet != NULL);
  141. +
  142. + g_signal_connect(G_OBJECT(docklet), "activate", G_CALLBACK(docklet_gtk_status_activated_cb), NULL);
  143. + g_signal_connect(G_OBJECT(docklet), "popup-menu", G_CALLBACK(docklet_gtk_status_clicked_cb), NULL);
  144. +
  145. + pidgin_docklet_embedded();
  146. + gtk_status_icon_set_visible(docklet, TRUE);
  147. + purple_debug_info("docklet", "created\n");
  148. +}
  149. +
  150. +static void
  151. +docklet_gtk_status_create_ui_op(void)
  152. +{
  153. + docklet_gtk_status_create(FALSE);
  154. +}
  155. +
  156. +static struct docklet_ui_ops ui_ops =
  157. +{
  158. + docklet_gtk_status_create_ui_op,
  159. + docklet_gtk_status_destroy,
  160. + docklet_gtk_status_update_icon,
  161. + NULL,
  162. + docklet_gtk_status_set_tooltip,
  163. + docklet_gtk_status_position_menu
  164. +};
  165. +
  166. +void
  167. +docklet_ui_init(void)
  168. +{
  169. + pidgin_docklet_set_ui_ops(&ui_ops);
  170. +}
  171. +
  172. +#endif /* GTK_CHECK_VERSION(2,10,0) */
  173. +
  174. ============================================================
  175. Index: pidgin/Makefile.am
  176. ===================================================================
  177. --- a/pidgin/Makefile.am 85c83e33db8e13395f710e8d6bce44b97cc19c18
  178. +++ b/pidgin/Makefile.am 9764675159d95ab81d52d35c2f37831a81347fe7
  179. @@ -87,6 +87,7 @@
  180. gtkdialogs.c \
  181. gtkdnd-hints.c \
  182. gtkdocklet.c \
  183. + gtkdocklet-gtk.c \
  184. gtkdocklet-x11.c \
  185. gtkeventloop.c \
  186. gtkexpander.c \
  187. ============================================================
  188. Index: pidgin/gtkdocklet-x11.c
  189. ===================================================================
  190. --- a/pidgin/gtkdocklet-x11.c 5bc5a9b08a44a9fa85818233cd383264ac96109a
  191. +++ b/pidgin/gtkdocklet-x11.c 5afb93cfca02d22eb57e93dcf11ad1190157553d
  192. @@ -34,6 +34,8 @@
  193. #include "gtkdocklet.h"
  194. #include <gdk/gdkkeysyms.h>
  195.  
  196. +#if !GTK_CHECK_VERSION(2,10,0)
  197. +
  198. #define SHORT_EMBED_TIMEOUT 5000
  199. #define LONG_EMBED_TIMEOUT 15000
  200.  
  201. @@ -352,3 +354,6 @@
  202. purple_prefs_add_none(PIDGIN_PREFS_ROOT "/docklet/x11");
  203. purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/docklet/x11/embedded", FALSE);
  204. }
  205. +
  206. +#endif /* !GTK_CHECK_VERSION(2,10,0) */
  207. +
  208. ============================================================
  209. Index: pidgin/gtkdocklet.h
  210. ===================================================================
  211. --- a/pidgin/gtkdocklet.h ab60eb18264813e2890efe5deb5819497d35fc57
  212. +++ b/pidgin/gtkdocklet.h 16acb1dd32c2646895f80d34f177dca23aa5e72c
  213. @@ -49,7 +49,7 @@
  214. void pidgin_docklet_uninit(void);
  215. void*pidgin_docklet_get_handle(void);
  216.  
  217. -/* function in gtkdocklet-{x11,win32}.c */
  218. +/* function in gtkdocklet-{gtk,x11,win32}.c */
  219. void docklet_ui_init(void);
  220.  
  221. #endif /* _GTKDOCKLET_H_ */
  222. ============================================================
  223. Index: pidgin/pidginstock.c
  224. ===================================================================
  225. --- a/pidgin/pidginstock.c c760ceb63ae60f491a23e5843b336adf6f26b73f
  226. +++ b/pidgin/pidginstock.c ded881b2cb875ae154578a9f15f892328a804d11
  227. @@ -198,8 +198,11 @@
  228. { PIDGIN_STOCK_STATUS_LOGOUT, "status", "log-out.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
  229. { PIDGIN_STOCK_STATUS_OFFLINE, "status", "offline.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, PIDGIN_STOCK_STATUS_OFFLINE_I },
  230. { PIDGIN_STOCK_STATUS_PERSON, "status", "person.png", TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
  231. - { PIDGIN_STOCK_STATUS_MESSAGE, "toolbar", "message-new.png", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
  232. + { PIDGIN_STOCK_STATUS_MESSAGE, "toolbar", "message-new.png", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL }
  233. +};
  234.  
  235. +const SizedStockIcon sized_tray_icons [] = {
  236. +
  237. { PIDGIN_STOCK_TRAY_AVAILABLE, "tray", "tray-online.png", FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
  238. { PIDGIN_STOCK_TRAY_INVISIBLE, "tray", "tray-invisible.png", FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
  239. { PIDGIN_STOCK_TRAY_AWAY, "tray", "tray-away.png", FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, NULL },
  240. @@ -332,7 +335,8 @@
  241.  
  242. static void
  243. add_sized_icon(GtkIconSet *iconset, GtkIconSize sizeid, PidginIconTheme *theme,
  244. - const char *size, SizedStockIcon sized_icon, gboolean translucent)
  245. + const char *size, SizedStockIcon sized_icon, gboolean translucent,
  246. + gboolean size_wildcarded)
  247. {
  248. char *filename;
  249. GtkIconSource *source;
  250. @@ -349,7 +353,7 @@
  251. gtk_icon_source_set_direction(source, GTK_TEXT_DIR_LTR);
  252. gtk_icon_source_set_direction_wildcarded(source, !sized_icon.rtl);
  253. gtk_icon_source_set_size(source, sizeid);
  254. - gtk_icon_source_set_size_wildcarded(source, FALSE);
  255. + gtk_icon_source_set_size_wildcarded(source, size_wildcarded);
  256. gtk_icon_source_set_state_wildcarded(source, TRUE);
  257. gtk_icon_set_add_source(iconset, source);
  258. gtk_icon_source_free(source);
  259. @@ -359,7 +363,7 @@
  260. gtk_icon_source_set_pixbuf(source, pixbuf);
  261. gtk_icon_source_set_direction_wildcarded(source, TRUE);
  262. gtk_icon_source_set_size(source, GTK_ICON_SIZE_MENU);
  263. - gtk_icon_source_set_size_wildcarded(source, FALSE);
  264. + gtk_icon_source_set_size_wildcarded(source, size_wildcarded);
  265. gtk_icon_source_set_state_wildcarded(source, TRUE);
  266. gtk_icon_set_add_source(iconset, source);
  267. gtk_icon_source_free(source);
  268. @@ -379,7 +383,7 @@
  269. gtk_icon_source_set_filename(source, filename);
  270. gtk_icon_source_set_direction(source, GTK_TEXT_DIR_RTL);
  271. gtk_icon_source_set_size(source, sizeid);
  272. - gtk_icon_source_set_size_wildcarded(source, FALSE);
  273. + gtk_icon_source_set_size_wildcarded(source, size_wildcarded);
  274. gtk_icon_source_set_state_wildcarded(source, TRUE);
  275. gtk_icon_set_add_source(iconset, source);
  276. g_free(filename);
  277. @@ -435,9 +439,9 @@
  278.  
  279. #define ADD_SIZED_ICON(name, size) \
  280. if (sized_status_icons[i].name) { \
  281. - add_sized_icon(normal, name, PIDGIN_ICON_THEME(theme), size, sized_status_icons[i], FALSE); \
  282. + add_sized_icon(normal, name, PIDGIN_ICON_THEME(theme), size, sized_status_icons[i], FALSE, FALSE); \
  283. if (sized_status_icons[i].translucent_name) \
  284. - add_sized_icon(translucent, name, PIDGIN_ICON_THEME(theme), size, sized_status_icons[i], TRUE); \
  285. + add_sized_icon(translucent, name, PIDGIN_ICON_THEME(theme), size, sized_status_icons[i], TRUE, FALSE); \
  286. }
  287. ADD_SIZED_ICON(microscopic, "11");
  288. ADD_SIZED_ICON(extra_small, "16");
  289. @@ -456,6 +460,35 @@
  290. }
  291. }
  292.  
  293. + for (i = 0; i < G_N_ELEMENTS(sized_tray_icons); i++)
  294. + {
  295. + normal = gtk_icon_set_new();
  296. + if (sized_tray_icons[i].translucent_name)
  297. + translucent = gtk_icon_set_new();
  298. +
  299. +#define ADD_SIZED_ICON(name, size) \
  300. + if (sized_tray_icons[i].name) { \
  301. + add_sized_icon(normal, name, PIDGIN_ICON_THEME(theme), size, sized_tray_icons[i], FALSE, TRUE); \
  302. + if (sized_tray_icons[i].translucent_name) \
  303. + add_sized_icon(translucent, name, PIDGIN_ICON_THEME(theme), size, sized_tray_icons[i], TRUE, TRUE); \
  304. + }
  305. + ADD_SIZED_ICON(microscopic, "11");
  306. + ADD_SIZED_ICON(extra_small, "16");
  307. + ADD_SIZED_ICON(small, "22");
  308. + ADD_SIZED_ICON(medium, "32");
  309. + ADD_SIZED_ICON(large, "48");
  310. + ADD_SIZED_ICON(huge, "64");
  311. +#undef ADD_SIZED_ICON
  312. +
  313. + gtk_icon_factory_add(icon_factory, sized_tray_icons[i].name, normal);
  314. + gtk_icon_set_unref(normal);
  315. +
  316. + if (sized_tray_icons[i].translucent_name) {
  317. + gtk_icon_factory_add(icon_factory, sized_tray_icons[i].translucent_name, translucent);
  318. + gtk_icon_set_unref(translucent);
  319. + }
  320. + }
  321. +
  322. gtk_widget_destroy(win);
  323. g_object_unref(G_OBJECT(icon_factory));
  324. reload_settings();
  325. @@ -527,7 +560,7 @@
  326.  
  327. #define ADD_SIZED_ICON(name, size) \
  328. if (sized_stock_icons[i].name) \
  329. - add_sized_icon(iconset, name, PIDGIN_ICON_THEME(theme), size, sized_stock_icons[i], FALSE);
  330. + add_sized_icon(iconset, name, PIDGIN_ICON_THEME(theme), size, sized_stock_icons[i], FALSE, FALSE);
  331. ADD_SIZED_ICON(microscopic, "11");
  332. ADD_SIZED_ICON(extra_small, "16");
  333. ADD_SIZED_ICON(small, "22");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement