Fri, 09 Aug 2019 00:41:13 -0400
Split pidgin_account_option_menu into its own files.
| 6287 | 1 | #include "internal.h" |
| 2 | ||
| 3 | #include "debug.h" | |
| 4576 | 4 | #include "sound.h" |
| 9954 | 5 | #include "version.h" |
| 6677 | 6 | |
|
34708
dd67596485ca
Undo renames of UI blist headers back to gntblist.h and gtkblist.h
Ankit Vani <a@nevitus.org>
parents:
34706
diff
changeset
|
7 | #include "gtkblist.h" |
| 6287 | 8 | #include "gtkplugin.h" |
| 9 | ||
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
10 | #define MAILCHK_PLUGIN_ID "gtk-mailchk" |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
11 | #define MAILCHK_PLUGIN_DOMAIN (g_quark_from_static_string(MAILCHK_PLUGIN_ID)) |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4655
diff
changeset
|
12 | |
| 1803 | 13 | #define ANY_MAIL 0x01 |
| 14 | #define UNREAD_MAIL 0x02 | |
| 15 | #define NEW_MAIL 0x04 | |
| 16 | ||
|
26753
a8dca8faae69
A patch from Arunan Balasubramaniam to use timeouts in seconds instead of
Arunan Balasubramaniam <foss@abala.me>
parents:
20288
diff
changeset
|
17 | static guint timer = 0; |
| 1803 | 18 | static GtkWidget *mail = NULL; |
| 19 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
20 | static gint |
|
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
21 | check_mail() |
| 1803 | 22 | { |
| 23 | static off_t oldsize = 0; | |
| 24 | gchar *filename; | |
| 25 | off_t newsize; | |
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
26753
diff
changeset
|
26 | GStatBuf st; |
| 1803 | 27 | gint ret = 0; |
| 28 | ||
| 4655 | 29 | filename = g_strdup(g_getenv("MAIL")); |
| 1803 | 30 | if (!filename) |
| 31 | filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); | |
| 32 | ||
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
26753
diff
changeset
|
33 | if (g_stat(filename, &st) < 0) { |
| 1803 | 34 | g_free(filename); |
| 35 | return -1; | |
| 36 | } | |
| 37 | ||
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
26753
diff
changeset
|
38 | newsize = st.st_size; |
| 1803 | 39 | if (newsize) ret |= ANY_MAIL; |
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
26753
diff
changeset
|
40 | if (st.st_mtime > st.st_atime && newsize) ret |= UNREAD_MAIL; |
| 1803 | 41 | if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; |
| 42 | oldsize = newsize; | |
| 43 | ||
| 44 | g_free(filename); | |
| 45 | ||
| 46 | return ret; | |
| 47 | } | |
| 48 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
49 | static void |
|
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
50 | destroy_cb() |
| 1803 | 51 | { |
| 52 | mail = NULL; | |
| 53 | } | |
| 54 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
55 | static gboolean |
|
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
56 | check_timeout(gpointer data) |
| 1803 | 57 | { |
| 58 | gint count = check_mail(); | |
|
39665
2172e3b8eeef
Rename some buddy list accessor functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38433
diff
changeset
|
59 | PurpleBuddyList *list = purple_blist_get_default(); |
| 6287 | 60 | |
| 1803 | 61 | if (count == -1) |
| 62 | return FALSE; | |
| 63 | ||
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
64 | if (!list || !(PIDGIN_BLIST(list)->vbox)) |
| 1803 | 65 | return TRUE; |
| 66 | ||
| 67 | if (!mail) { | |
| 68 | /* guess we better build it then :P */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
69 | GtkWidget *vbox = PIDGIN_BLIST(list)->vbox; |
| 1803 | 70 | |
| 71 | mail = gtk_label_new("No mail messages."); | |
| 5255 | 72 | gtk_box_pack_start(GTK_BOX(vbox), mail, FALSE, FALSE, 0); |
| 73 | gtk_box_reorder_child(GTK_BOX(vbox), mail, 1); | |
|
5314
56ef6a09fb99
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5255
diff
changeset
|
74 | g_signal_connect(G_OBJECT(mail), "destroy", G_CALLBACK(destroy_cb), NULL); |
| 1803 | 75 | gtk_widget_show(mail); |
| 76 | } | |
| 77 | ||
| 78 | if (count & NEW_MAIL) | |
| 15884 | 79 | purple_sound_play_event(PURPLE_SOUND_POUNCE_DEFAULT, NULL); |
| 1803 | 80 | |
| 81 | if (count & UNREAD_MAIL) | |
| 82 | gtk_label_set_text(GTK_LABEL(mail), "You have new mail!"); | |
| 83 | else if (count & ANY_MAIL) | |
| 84 | gtk_label_set_text(GTK_LABEL(mail), "You have mail."); | |
| 85 | else | |
| 86 | gtk_label_set_text(GTK_LABEL(mail), "No mail messages."); | |
| 87 | ||
| 88 | return TRUE; | |
| 89 | } | |
| 90 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
91 | static void |
| 15884 | 92 | signon_cb(PurpleConnection *gc) |
| 1803 | 93 | { |
|
39665
2172e3b8eeef
Rename some buddy list accessor functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38433
diff
changeset
|
94 | PurpleBuddyList *list = purple_blist_get_default(); |
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
95 | if (list && !timer) { |
| 6287 | 96 | check_timeout(NULL); /* we want the box to be drawn immediately */ |
|
38433
361c801c4536
Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents:
36770
diff
changeset
|
97 | timer = g_timeout_add_seconds(2, check_timeout, NULL); |
| 6287 | 98 | } |
| 1803 | 99 | } |
| 100 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
101 | static void |
| 15884 | 102 | signoff_cb(PurpleConnection *gc) |
| 1803 | 103 | { |
|
39665
2172e3b8eeef
Rename some buddy list accessor functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38433
diff
changeset
|
104 | PurpleBuddyList *list = purple_blist_get_default(); |
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
105 | if ((!list || !PIDGIN_BLIST(list)->vbox) && timer) { |
|
38433
361c801c4536
Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents:
36770
diff
changeset
|
106 | g_source_remove(timer); |
| 2259 | 107 | timer = 0; |
| 108 | } | |
| 1803 | 109 | } |
| 110 | ||
| 5255 | 111 | /* |
| 112 | * EXPORTED FUNCTIONS | |
| 113 | */ | |
| 114 | ||
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
115 | static PidginPluginInfo * |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
116 | plugin_query(GError **error) |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
117 | { |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
118 | const gchar * const authors[] = { |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
119 | "Eric Warmenhoven <eric@warmenhoven.org>", |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
120 | NULL |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
121 | }; |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
122 | |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
123 | return pidgin_plugin_info_new( |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
124 | "id", MAILCHK_PLUGIN_ID, |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
125 | "name", N_("Mail Checker"), |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
126 | "version", DISPLAY_VERSION, |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
127 | "category", N_("Utility"), |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
128 | "summary", N_("Checks for new local mail."), |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
129 | "description", N_("Adds a small box to the buddy list that shows if " |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
130 | "you have new mail."), |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
131 | "authors", authors, |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
132 | "website", PURPLE_WEBSITE, |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
133 | "abi-version", PURPLE_ABI_VERSION, |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
134 | NULL |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
135 | ); |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
136 | } |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
137 | |
| 5255 | 138 | static gboolean |
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
139 | plugin_load(PurplePlugin *plugin, GError **error) |
| 1803 | 140 | { |
|
39665
2172e3b8eeef
Rename some buddy list accessor functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38433
diff
changeset
|
141 | PurpleBuddyList *list = purple_blist_get_default(); |
| 15884 | 142 | void *conn_handle = purple_connections_get_handle(); |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
143 | |
| 5255 | 144 | if (!check_timeout(NULL)) { |
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
145 | g_set_error(error, MAILCHK_PLUGIN_DOMAIN, 0, _("Could not read $MAIL " |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
146 | "or /var/spool/mail/$USER\n")); |
| 5255 | 147 | return FALSE; |
| 148 | } | |
| 149 | ||
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
150 | if (list && PIDGIN_BLIST(list)->vbox) |
|
38433
361c801c4536
Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents:
36770
diff
changeset
|
151 | timer = g_timeout_add_seconds(2, check_timeout, NULL); |
| 5255 | 152 | |
| 15884 | 153 | purple_signal_connect(conn_handle, "signed-on", |
| 154 | plugin, PURPLE_CALLBACK(signon_cb), NULL); | |
| 155 | purple_signal_connect(conn_handle, "signed-off", | |
| 156 | plugin, PURPLE_CALLBACK(signoff_cb), NULL); | |
| 5255 | 157 | |
| 158 | return TRUE; | |
| 1803 | 159 | } |
| 160 | ||
| 5255 | 161 | static gboolean |
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
162 | plugin_unload(PurplePlugin *plugin, GError **error) |
| 1803 | 163 | { |
| 164 | if (timer) | |
|
38433
361c801c4536
Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents:
36770
diff
changeset
|
165 | g_source_remove(timer); |
| 1803 | 166 | timer = 0; |
| 167 | if (mail) | |
| 168 | gtk_widget_destroy(mail); | |
| 169 | mail = NULL; | |
| 5255 | 170 | |
| 171 | return TRUE; | |
| 1803 | 172 | } |
| 173 | ||
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
174 | PURPLE_PLUGIN_INIT(mailchk, plugin_query, plugin_load, plugin_unload); |