Sun, 22 Jul 2007 08:14:16 +0000
revert 'no visible tabs when only one conversation' as it proved unpopular. Made tabs only fill the entire width of the notebook when there's only one tab to avoid http://pidgin.im/~deryni/that_just_looks_dumb.png
| 6287 | 1 | #include "internal.h" |
| 2 | ||
| 3 | #include "debug.h" | |
| 4576 | 4 | #include "sound.h" |
| 9954 | 5 | #include "version.h" |
| 6677 | 6 | |
| 7 | #include "gtkblist.h" | |
| 6287 | 8 | #include "gtkplugin.h" |
| 9 | ||
| 5255 | 10 | #define MAILCHK_PLUGIN_ID "gtk-mailchk" |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4655
diff
changeset
|
11 | |
| 1803 | 12 | #define ANY_MAIL 0x01 |
| 13 | #define UNREAD_MAIL 0x02 | |
| 14 | #define NEW_MAIL 0x04 | |
| 15 | ||
| 16 | static guint32 timer = 0; | |
| 17 | static GtkWidget *mail = NULL; | |
| 18 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
19 | static gint |
|
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
20 | check_mail() |
| 1803 | 21 | { |
| 22 | static off_t oldsize = 0; | |
| 23 | gchar *filename; | |
| 24 | off_t newsize; | |
| 25 | struct stat s; | |
| 26 | gint ret = 0; | |
| 27 | ||
| 4655 | 28 | filename = g_strdup(g_getenv("MAIL")); |
| 1803 | 29 | if (!filename) |
| 30 | filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); | |
| 31 | ||
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10218
diff
changeset
|
32 | if (g_stat(filename, &s) < 0) { |
| 1803 | 33 | g_free(filename); |
| 34 | return -1; | |
| 35 | } | |
| 36 | ||
| 37 | newsize = s.st_size; | |
| 38 | if (newsize) ret |= ANY_MAIL; | |
| 39 | if (s.st_mtime > s.st_atime && newsize) ret |= UNREAD_MAIL; | |
| 40 | if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; | |
| 41 | oldsize = newsize; | |
| 42 | ||
| 43 | g_free(filename); | |
| 44 | ||
| 45 | return ret; | |
| 46 | } | |
| 47 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
48 | static void |
|
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
49 | destroy_cb() |
| 1803 | 50 | { |
| 51 | mail = NULL; | |
| 52 | } | |
| 53 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
54 | static gboolean |
|
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
55 | check_timeout(gpointer data) |
| 1803 | 56 | { |
| 57 | gint count = check_mail(); | |
| 15884 | 58 | PurpleBuddyList *list = purple_get_blist(); |
| 6287 | 59 | |
| 1803 | 60 | if (count == -1) |
| 61 | return FALSE; | |
| 62 | ||
| 15884 | 63 | if (!list || !PURPLE_IS_GTK_BLIST(list) || !(PIDGIN_BLIST(list)->vbox)) |
| 1803 | 64 | return TRUE; |
| 65 | ||
| 66 | if (!mail) { | |
| 67 | /* guess we better build it then :P */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
68 | GtkWidget *vbox = PIDGIN_BLIST(list)->vbox; |
| 1803 | 69 | |
| 70 | mail = gtk_label_new("No mail messages."); | |
| 5255 | 71 | gtk_box_pack_start(GTK_BOX(vbox), mail, FALSE, FALSE, 0); |
| 72 | gtk_box_reorder_child(GTK_BOX(vbox), mail, 1); | |
|
5314
56ef6a09fb99
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5255
diff
changeset
|
73 | g_signal_connect(G_OBJECT(mail), "destroy", G_CALLBACK(destroy_cb), NULL); |
| 1803 | 74 | gtk_widget_show(mail); |
| 75 | } | |
| 76 | ||
| 77 | if (count & NEW_MAIL) | |
| 15884 | 78 | purple_sound_play_event(PURPLE_SOUND_POUNCE_DEFAULT, NULL); |
| 1803 | 79 | |
| 80 | if (count & UNREAD_MAIL) | |
| 81 | gtk_label_set_text(GTK_LABEL(mail), "You have new mail!"); | |
| 82 | else if (count & ANY_MAIL) | |
| 83 | gtk_label_set_text(GTK_LABEL(mail), "You have mail."); | |
| 84 | else | |
| 85 | gtk_label_set_text(GTK_LABEL(mail), "No mail messages."); | |
| 86 | ||
| 87 | return TRUE; | |
| 88 | } | |
| 89 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
90 | static void |
| 15884 | 91 | signon_cb(PurpleConnection *gc) |
| 1803 | 92 | { |
| 15884 | 93 | PurpleBuddyList *list = purple_get_blist(); |
| 94 | if (list && PURPLE_IS_GTK_BLIST(list) && !timer) { | |
| 6287 | 95 | check_timeout(NULL); /* we want the box to be drawn immediately */ |
| 4168 | 96 | timer = g_timeout_add(2000, check_timeout, NULL); |
| 6287 | 97 | } |
| 1803 | 98 | } |
| 99 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
100 | static void |
| 15884 | 101 | signoff_cb(PurpleConnection *gc) |
| 1803 | 102 | { |
| 15884 | 103 | PurpleBuddyList *list = purple_get_blist(); |
| 104 | if ((!list || !PURPLE_IS_GTK_BLIST(list) || !PIDGIN_BLIST(list)->vbox) && timer) { | |
| 4168 | 105 | g_source_remove(timer); |
| 2259 | 106 | timer = 0; |
| 107 | } | |
| 1803 | 108 | } |
| 109 | ||
| 5255 | 110 | /* |
| 111 | * EXPORTED FUNCTIONS | |
| 112 | */ | |
| 113 | ||
| 114 | static gboolean | |
| 15884 | 115 | plugin_load(PurplePlugin *plugin) |
| 1803 | 116 | { |
| 15884 | 117 | PurpleBuddyList *list = purple_get_blist(); |
| 118 | void *conn_handle = purple_connections_get_handle(); | |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
119 | |
| 5255 | 120 | if (!check_timeout(NULL)) { |
| 15884 | 121 | purple_debug_warning("mailchk", "Could not read $MAIL or /var/spool/mail/$USER"); |
| 5255 | 122 | return FALSE; |
| 123 | } | |
| 124 | ||
| 15884 | 125 | if (list && PURPLE_IS_GTK_BLIST(list) && PIDGIN_BLIST(list)->vbox) |
| 4168 | 126 | timer = g_timeout_add(2000, check_timeout, NULL); |
| 5255 | 127 | |
| 15884 | 128 | purple_signal_connect(conn_handle, "signed-on", |
| 129 | plugin, PURPLE_CALLBACK(signon_cb), NULL); | |
| 130 | purple_signal_connect(conn_handle, "signed-off", | |
| 131 | plugin, PURPLE_CALLBACK(signoff_cb), NULL); | |
| 5255 | 132 | |
| 133 | return TRUE; | |
| 1803 | 134 | } |
| 135 | ||
| 5255 | 136 | static gboolean |
| 15884 | 137 | plugin_unload(PurplePlugin *plugin) |
| 1803 | 138 | { |
| 139 | if (timer) | |
| 4168 | 140 | g_source_remove(timer); |
| 1803 | 141 | timer = 0; |
| 142 | if (mail) | |
| 143 | gtk_widget_destroy(mail); | |
| 144 | mail = NULL; | |
| 5255 | 145 | |
| 146 | return TRUE; | |
| 1803 | 147 | } |
| 148 | ||
| 15884 | 149 | static PurplePluginInfo info = |
| 5255 | 150 | { |
| 15884 | 151 | PURPLE_PLUGIN_MAGIC, |
| 152 | PURPLE_MAJOR_VERSION, | |
| 153 | PURPLE_MINOR_VERSION, | |
| 154 | PURPLE_PLUGIN_STANDARD, | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
155 | PIDGIN_PLUGIN_TYPE, |
| 6287 | 156 | 0, |
| 157 | NULL, | |
| 15884 | 158 | PURPLE_PRIORITY_DEFAULT, |
| 6287 | 159 | MAILCHK_PLUGIN_ID, |
| 160 | N_("Mail Checker"), | |
| 161 | VERSION, | |
| 5255 | 162 | N_("Checks for new local mail."), |
| 8598 | 163 | N_("Adds a small box to the buddy list that" |
| 164 | " shows if you have new mail."), | |
| 6287 | 165 | "Eric Warmenhoven <eric@warmenhoven.org>", |
| 15884 | 166 | PURPLE_WEBSITE, |
| 6287 | 167 | plugin_load, |
| 168 | plugin_unload, | |
| 169 | NULL, | |
| 170 | NULL, | |
| 8993 | 171 | NULL, |
| 172 | NULL, | |
| 6287 | 173 | NULL |
| 5255 | 174 | }; |
| 175 | ||
| 176 | static void | |
| 15884 | 177 | init_plugin(PurplePlugin *plugin) |
| 5255 | 178 | { |
| 3551 | 179 | } |
| 180 | ||
| 15884 | 181 | PURPLE_INIT_PLUGIN(mailchk, init_plugin, info) |