Fri, 09 Aug 2013 13:03:26 +0200
HTTP: successful is spelled with one l
| 7543 | 1 | /* |
| 2 | * Release Notification Plugin | |
| 3 | * | |
| 4 | * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or | |
| 7 | * modify it under the terms of the GNU General Public License as | |
| 8 | * published by the Free Software Foundation; either version 2 of the | |
| 9 | * License, or (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, but | |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 | * General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18169
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18169
diff
changeset
|
19 | * 02111-1301, USA. |
| 7543 | 20 | */ |
| 21 | ||
| 22 | #ifdef HAVE_CONFIG_H | |
| 23 | #include <config.h> | |
| 24 | #endif | |
| 25 | ||
| 15884 | 26 | #ifndef PURPLE_PLUGINS |
| 27 | #define PURPLE_PLUGINS | |
| 7543 | 28 | #endif |
| 29 | ||
| 30 | #include "internal.h" | |
| 31 | ||
| 32 | #include <string.h> | |
| 33 | ||
| 34 | #include "connection.h" | |
| 35 | #include "core.h" | |
|
24247
9f640ea2ab9f
Parse the HTTP status code in the release notification plugin and only display
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
36 | #include "debug.h" |
|
24768
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
37 | #include "gtkblist.h" |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
38 | #include "gtkutils.h" |
|
33441
b69cd2bfe289
Migrate relnot plugin to new HTTP API
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33424
diff
changeset
|
39 | #include "http.h" |
| 7543 | 40 | #include "notify.h" |
|
24768
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
41 | #include "pidginstock.h" |
| 7543 | 42 | #include "prefs.h" |
| 43 | #include "util.h" | |
| 9943 | 44 | #include "version.h" |
| 7543 | 45 | |
| 15577 | 46 | #include "pidgin.h" |
|
15442
2ff7f5308727
I think this is all the instances of 'Gaim' within pidgin/
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
47 | |
| 7543 | 48 | /* 1 day */ |
| 49 | #define MIN_CHECK_INTERVAL 60 * 60 * 24 | |
| 50 | ||
| 51 | static void | |
|
24768
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
52 | release_hide() |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
53 | { |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
54 | /* No-op. We may use this method in the future to avoid showing |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
55 | * the popup twice */ |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
56 | } |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
57 | |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
58 | static void |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
59 | release_show() |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
60 | { |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
61 | purple_notify_uri(NULL, PURPLE_WEBSITE); |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
62 | } |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
63 | |
|
33441
b69cd2bfe289
Migrate relnot plugin to new HTTP API
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33424
diff
changeset
|
64 | static void version_fetch_cb(PurpleHttpConnection *hc, |
|
b69cd2bfe289
Migrate relnot plugin to new HTTP API
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33424
diff
changeset
|
65 | PurpleHttpResponse *response, gpointer user_data) |
| 7543 | 66 | { |
|
24768
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
67 | gchar *cur_ver; |
|
33441
b69cd2bfe289
Migrate relnot plugin to new HTTP API
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33424
diff
changeset
|
68 | const char *changelog; |
|
24768
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
69 | GtkWidget *release_dialog; |
|
24247
9f640ea2ab9f
Parse the HTTP status code in the release notification plugin and only display
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
70 | |
| 7543 | 71 | GString *message; |
|
24247
9f640ea2ab9f
Parse the HTTP status code in the release notification plugin and only display
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
72 | int i = 0; |
|
9f640ea2ab9f
Parse the HTTP status code in the release notification plugin and only display
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
73 | |
|
34287
6cd0c77b1f6a
HTTP: successful is spelled with one l
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
34233
diff
changeset
|
74 | if(!purple_http_response_is_successful(response)) |
|
24247
9f640ea2ab9f
Parse the HTTP status code in the release notification plugin and only display
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
75 | return; |
| 7543 | 76 | |
|
33626
2522d124d883
update purple_http_response_get_data to take a second parameter that is a return address for the size of the data
Gary Kramlich <grim@reaperworld.com>
parents:
33598
diff
changeset
|
77 | changelog = purple_http_response_get_data(response, NULL); |
| 7543 | 78 | |
| 79 | while(changelog[i] && changelog[i] != '\n') i++; | |
| 80 | ||
| 14281 | 81 | /* this basically means the version thing wasn't in the format we were |
| 82 | * looking for so sourceforge is probably having web server issues, and | |
| 83 | * we should try again later */ | |
| 84 | if(i == 0) | |
| 85 | return; | |
| 86 | ||
| 7543 | 87 | cur_ver = g_strndup(changelog, i); |
| 88 | ||
| 89 | message = g_string_new(""); | |
|
24768
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
90 | g_string_append_printf(message, _("You can upgrade to %s %s today."), |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
91 | PIDGIN_NAME, cur_ver); |
| 7543 | 92 | |
|
24768
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
93 | release_dialog = pidgin_make_mini_dialog( |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
94 | NULL, PIDGIN_STOCK_DIALOG_INFO, |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
95 | _("New Version Available"), |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
96 | message->str, |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
97 | NULL, |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
98 | _("Later"), PURPLE_CALLBACK(release_hide), |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
99 | _("Download Now"), PURPLE_CALLBACK(release_show), |
|
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
100 | NULL); |
| 7543 | 101 | |
|
24768
c9d1cfe1d89c
A patch from Casey Ho to move the release notification to a mini-dialog in the buddy list. The change log is no longer displayed, but will open a webbrowser to show it.
Casey Ho <caseyho@pidgin.im>
parents:
24247
diff
changeset
|
102 | pidgin_blist_add_alert(release_dialog); |
| 7543 | 103 | |
| 104 | g_string_free(message, TRUE); | |
| 7599 | 105 | g_free(cur_ver); |
| 7543 | 106 | } |
| 107 | ||
| 108 | static void | |
| 109 | do_check(void) | |
| 110 | { | |
| 15884 | 111 | int last_check = purple_prefs_get_int("/plugins/gtk/relnot/last_check"); |
| 7543 | 112 | if(!last_check || time(NULL) - last_check > MIN_CHECK_INTERVAL) { |
|
33441
b69cd2bfe289
Migrate relnot plugin to new HTTP API
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33424
diff
changeset
|
113 | gchar *url; |
|
24247
9f640ea2ab9f
Parse the HTTP status code in the release notification plugin and only display
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
114 | const char *host = "pidgin.im"; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
24768
diff
changeset
|
115 | |
|
33397
15591913dd85
Use https to check for updates in the Release Notification plugin. Refs #15276
Daniel Atallah <datallah@pidgin.im>
parents:
31294
diff
changeset
|
116 | url = g_strdup_printf("https://%s/version.php?version=%s&build=%s", |
|
24247
9f640ea2ab9f
Parse the HTTP status code in the release notification plugin and only display
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
117 | host, |
|
9f640ea2ab9f
Parse the HTTP status code in the release notification plugin and only display
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
118 | purple_core_get_version(), |
| 7543 | 119 | #ifdef _WIN32 |
| 15884 | 120 | "purple-win32" |
| 7543 | 121 | #else |
| 15884 | 122 | "purple" |
| 7543 | 123 | #endif |
| 7546 | 124 | ); |
|
24247
9f640ea2ab9f
Parse the HTTP status code in the release notification plugin and only display
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
125 | |
|
34233
8bdcc4f84a5e
HTTP: introduce purple_http_get_printf, make purple_http_get consistent with it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33626
diff
changeset
|
126 | purple_http_get(NULL, version_fetch_cb, NULL, url); |
|
24247
9f640ea2ab9f
Parse the HTTP status code in the release notification plugin and only display
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
127 | |
|
9f640ea2ab9f
Parse the HTTP status code in the release notification plugin and only display
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
128 | g_free(url); |
|
9f640ea2ab9f
Parse the HTTP status code in the release notification plugin and only display
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
129 | |
| 15884 | 130 | purple_prefs_set_int("/plugins/gtk/relnot/last_check", time(NULL)); |
|
24247
9f640ea2ab9f
Parse the HTTP status code in the release notification plugin and only display
Daniel Atallah <datallah@pidgin.im>
parents:
20288
diff
changeset
|
131 | |
| 7543 | 132 | } |
| 133 | } | |
| 134 | ||
| 135 | static void | |
| 15884 | 136 | signed_on_cb(PurpleConnection *gc, void *data) { |
| 7543 | 137 | do_check(); |
| 138 | } | |
| 139 | ||
| 140 | /************************************************************************** | |
| 141 | * Plugin stuff | |
| 142 | **************************************************************************/ | |
| 143 | static gboolean | |
| 15884 | 144 | plugin_load(PurplePlugin *plugin) |
| 7543 | 145 | { |
| 15884 | 146 | purple_signal_connect(purple_connections_get_handle(), "signed-on", |
| 147 | plugin, PURPLE_CALLBACK(signed_on_cb), NULL); | |
| 7543 | 148 | |
| 149 | /* we don't check if we're offline */ | |
| 15884 | 150 | if(purple_connections_get_all()) |
| 7543 | 151 | do_check(); |
| 152 | ||
| 153 | return TRUE; | |
| 154 | } | |
| 155 | ||
| 15884 | 156 | static PurplePluginInfo info = |
| 7543 | 157 | { |
| 15884 | 158 | PURPLE_PLUGIN_MAGIC, |
| 159 | PURPLE_MAJOR_VERSION, | |
| 160 | PURPLE_MINOR_VERSION, | |
| 161 | PURPLE_PLUGIN_STANDARD, /**< type */ | |
| 7543 | 162 | NULL, /**< ui_requirement */ |
| 163 | 0, /**< flags */ | |
| 164 | NULL, /**< dependencies */ | |
| 15884 | 165 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 7543 | 166 | |
| 167 | "gtk-relnot", /**< id */ | |
| 168 | N_("Release Notification"), /**< name */ | |
|
20288
5ca925a094e2
applied changes from 03b709ec2a153e7e82719df0ba4635108bb1d3c6
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
169 | DISPLAY_VERSION, /**< version */ |
| 7543 | 170 | /** summary */ |
| 171 | N_("Checks periodically for new releases."), | |
| 172 | /** description */ | |
| 173 | N_("Checks periodically for new releases and notifies the user " | |
| 174 | "with the ChangeLog."), | |
| 175 | "Nathan Walp <faceprint@faceprint.com>", /**< author */ | |
| 15884 | 176 | PURPLE_WEBSITE, /**< homepage */ |
| 7543 | 177 | |
| 178 | plugin_load, /**< load */ | |
| 179 | NULL, /**< unload */ | |
| 180 | NULL, /**< destroy */ | |
| 181 | ||
| 182 | NULL, /**< ui_info */ | |
| 8993 | 183 | NULL, /**< extra_info */ |
| 184 | NULL, | |
|
16749
14a3fdc0aed7
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
parents:
16073
diff
changeset
|
185 | NULL, |
|
14a3fdc0aed7
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
parents:
16073
diff
changeset
|
186 | |
|
14a3fdc0aed7
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
parents:
16073
diff
changeset
|
187 | /* padding */ |
|
14a3fdc0aed7
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
parents:
16073
diff
changeset
|
188 | NULL, |
|
14a3fdc0aed7
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
parents:
16073
diff
changeset
|
189 | NULL, |
|
14a3fdc0aed7
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
parents:
16073
diff
changeset
|
190 | NULL, |
| 8993 | 191 | NULL |
| 7543 | 192 | }; |
| 193 | ||
| 194 | static void | |
| 15884 | 195 | init_plugin(PurplePlugin *plugin) |
| 7543 | 196 | { |
| 15884 | 197 | purple_prefs_add_none("/plugins/gtk/relnot"); |
| 198 | purple_prefs_add_int("/plugins/gtk/relnot/last_check", 0); | |
| 7543 | 199 | } |
| 200 | ||
| 15884 | 201 | PURPLE_INIT_PLUGIN(relnot, init_plugin, info) |