Sun, 01 Nov 2020 02:42:18 -0600
Remove the winprefs plugin as it only interacts with the buddy list window which we will soon be removing
Testing Done:
Built locally, which means I didn't test it on windows, but it's just deleting windows stuff so it should be fine.
Reviewed at https://reviews.imfreedom.org/r/190/
| 6287 | 1 | #include "internal.h" |
| 2 | ||
|
40360
e21f3bbcc2a5
Update all of the pidgin code to include purple.h
Gary Kramlich <grim@reaperworld.com>
parents:
39665
diff
changeset
|
3 | #include <purple.h> |
| 6677 | 4 | |
|
34708
dd67596485ca
Undo renames of UI blist headers back to gntblist.h and gtkblist.h
Ankit Vani <a@nevitus.org>
parents:
34706
diff
changeset
|
5 | #include "gtkblist.h" |
| 6287 | 6 | #include "gtkplugin.h" |
| 7 | ||
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
8 | #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
|
9 | #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
|
10 | |
| 1803 | 11 | #define ANY_MAIL 0x01 |
| 12 | #define UNREAD_MAIL 0x02 | |
| 13 | #define NEW_MAIL 0x04 | |
| 14 | ||
|
26753
a8dca8faae69
A patch from Arunan Balasubramaniam to use timeouts in seconds instead of
Arunan Balasubramaniam <foss@abala.me>
parents:
20288
diff
changeset
|
15 | static guint timer = 0; |
| 1803 | 16 | static GtkWidget *mail = NULL; |
| 17 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
18 | static gint |
|
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
19 | check_mail() |
| 1803 | 20 | { |
| 21 | static off_t oldsize = 0; | |
| 22 | gchar *filename; | |
| 23 | off_t newsize; | |
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
26753
diff
changeset
|
24 | GStatBuf st; |
| 1803 | 25 | gint ret = 0; |
| 26 | ||
| 4655 | 27 | filename = g_strdup(g_getenv("MAIL")); |
| 1803 | 28 | if (!filename) |
| 29 | filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); | |
| 30 | ||
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
26753
diff
changeset
|
31 | if (g_stat(filename, &st) < 0) { |
| 1803 | 32 | g_free(filename); |
| 33 | return -1; | |
| 34 | } | |
| 35 | ||
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
26753
diff
changeset
|
36 | newsize = st.st_size; |
| 1803 | 37 | if (newsize) ret |= ANY_MAIL; |
|
33940
b44d15793c83
Use GStatBuf instead of struct stat
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
26753
diff
changeset
|
38 | if (st.st_mtime > st.st_atime && newsize) ret |= UNREAD_MAIL; |
| 1803 | 39 | if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; |
| 40 | oldsize = newsize; | |
| 41 | ||
| 42 | g_free(filename); | |
| 43 | ||
| 44 | return ret; | |
| 45 | } | |
| 46 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
47 | static void |
|
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
48 | destroy_cb() |
| 1803 | 49 | { |
| 50 | mail = NULL; | |
| 51 | } | |
| 52 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
53 | static gboolean |
|
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
54 | check_timeout(gpointer data) |
| 1803 | 55 | { |
| 56 | gint count = check_mail(); | |
|
39665
2172e3b8eeef
Rename some buddy list accessor functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38433
diff
changeset
|
57 | PurpleBuddyList *list = purple_blist_get_default(); |
| 6287 | 58 | |
| 1803 | 59 | if (count == -1) |
| 60 | return FALSE; | |
| 61 | ||
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
62 | if (!list || !(PIDGIN_BLIST(list)->vbox)) |
| 1803 | 63 | return TRUE; |
| 64 | ||
| 65 | if (!mail) { | |
| 66 | /* guess we better build it then :P */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
67 | GtkWidget *vbox = PIDGIN_BLIST(list)->vbox; |
| 1803 | 68 | |
| 69 | mail = gtk_label_new("No mail messages."); | |
| 5255 | 70 | gtk_box_pack_start(GTK_BOX(vbox), mail, FALSE, FALSE, 0); |
| 71 | gtk_box_reorder_child(GTK_BOX(vbox), mail, 1); | |
|
5314
56ef6a09fb99
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5255
diff
changeset
|
72 | g_signal_connect(G_OBJECT(mail), "destroy", G_CALLBACK(destroy_cb), NULL); |
| 1803 | 73 | gtk_widget_show(mail); |
| 74 | } | |
| 75 | ||
| 76 | if (count & UNREAD_MAIL) | |
| 77 | gtk_label_set_text(GTK_LABEL(mail), "You have new mail!"); | |
| 78 | else if (count & ANY_MAIL) | |
| 79 | gtk_label_set_text(GTK_LABEL(mail), "You have mail."); | |
| 80 | else | |
| 81 | gtk_label_set_text(GTK_LABEL(mail), "No mail messages."); | |
| 82 | ||
| 83 | return TRUE; | |
| 84 | } | |
| 85 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
86 | static void |
| 15884 | 87 | signon_cb(PurpleConnection *gc) |
| 1803 | 88 | { |
|
39665
2172e3b8eeef
Rename some buddy list accessor functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38433
diff
changeset
|
89 | 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
|
90 | if (list && !timer) { |
| 6287 | 91 | 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
|
92 | timer = g_timeout_add_seconds(2, check_timeout, NULL); |
| 6287 | 93 | } |
| 1803 | 94 | } |
| 95 | ||
|
10218
c93f3fcdb85d
[gaim-migrate @ 11346]
Mark Doliner <markdoliner@pidgin.im>
parents:
9954
diff
changeset
|
96 | static void |
| 15884 | 97 | signoff_cb(PurpleConnection *gc) |
| 1803 | 98 | { |
|
39665
2172e3b8eeef
Rename some buddy list accessor functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38433
diff
changeset
|
99 | 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
|
100 | if ((!list || !PIDGIN_BLIST(list)->vbox) && timer) { |
|
38433
361c801c4536
Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents:
36770
diff
changeset
|
101 | g_source_remove(timer); |
| 2259 | 102 | timer = 0; |
| 103 | } | |
| 1803 | 104 | } |
| 105 | ||
| 5255 | 106 | /* |
| 107 | * EXPORTED FUNCTIONS | |
| 108 | */ | |
| 109 | ||
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
110 | static PidginPluginInfo * |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
111 | 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
|
112 | { |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
113 | 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
|
114 | "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
|
115 | NULL |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
116 | }; |
|
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 | 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
|
119 | "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
|
120 | "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
|
121 | "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
|
122 | "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
|
123 | "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
|
124 | "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
|
125 | "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
|
126 | "authors", authors, |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
127 | "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
|
128 | "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
|
129 | NULL |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
130 | ); |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
131 | } |
|
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
132 | |
| 5255 | 133 | 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
|
134 | plugin_load(PurplePlugin *plugin, GError **error) |
| 1803 | 135 | { |
|
39665
2172e3b8eeef
Rename some buddy list accessor functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38433
diff
changeset
|
136 | PurpleBuddyList *list = purple_blist_get_default(); |
| 15884 | 137 | void *conn_handle = purple_connections_get_handle(); |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
138 | |
| 5255 | 139 | 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
|
140 | 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
|
141 | "or /var/spool/mail/$USER\n")); |
| 5255 | 142 | return FALSE; |
| 143 | } | |
| 144 | ||
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
145 | if (list && PIDGIN_BLIST(list)->vbox) |
|
38433
361c801c4536
Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents:
36770
diff
changeset
|
146 | timer = g_timeout_add_seconds(2, check_timeout, NULL); |
| 5255 | 147 | |
| 15884 | 148 | purple_signal_connect(conn_handle, "signed-on", |
| 149 | plugin, PURPLE_CALLBACK(signon_cb), NULL); | |
| 150 | purple_signal_connect(conn_handle, "signed-off", | |
| 151 | plugin, PURPLE_CALLBACK(signoff_cb), NULL); | |
| 5255 | 152 | |
| 153 | return TRUE; | |
| 1803 | 154 | } |
| 155 | ||
| 5255 | 156 | 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
|
157 | plugin_unload(PurplePlugin *plugin, GError **error) |
| 1803 | 158 | { |
| 159 | if (timer) | |
|
38433
361c801c4536
Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents:
36770
diff
changeset
|
160 | g_source_remove(timer); |
| 1803 | 161 | timer = 0; |
| 162 | if (mail) | |
| 163 | gtk_widget_destroy(mail); | |
| 164 | mail = NULL; | |
| 5255 | 165 | |
| 166 | return TRUE; | |
| 1803 | 167 | } |
| 168 | ||
|
36770
d971efd6f8bd
Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
34726
diff
changeset
|
169 | PURPLE_PLUGIN_INIT(mailchk, plugin_query, plugin_load, plugin_unload); |