mark PurpleImageClass as private
[pidgin-git.git] / pidgin / plugins / relnot.c
blob53a7532bba16353c2c1603b46d1e09c7e0b79a05
1 /*
2 * Release Notification Plugin
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
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.
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.
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
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02111-1301, USA.
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
26 #include "internal.h"
28 #include <string.h>
30 #include "connection.h"
31 #include "core.h"
32 #include "debug.h"
33 #include "gtkblist.h"
34 #include "gtkplugin.h"
35 #include "gtkutils.h"
36 #include "http.h"
37 #include "notify.h"
38 #include "pidginicon.h"
39 #include "prefs.h"
40 #include "util.h"
41 #include "version.h"
43 #include "pidgin.h"
45 /* 1 day */
46 #define MIN_CHECK_INTERVAL 60 * 60 * 24
48 static void
49 release_hide()
51 /* No-op. We may use this method in the future to avoid showing
52 * the popup twice */
55 static void
56 release_show()
58 purple_notify_uri(NULL, PURPLE_WEBSITE);
61 static void version_fetch_cb(PurpleHttpConnection *hc,
62 PurpleHttpResponse *response, gpointer user_data)
64 gchar *cur_ver;
65 const char *changelog;
66 GtkWidget *release_dialog;
68 GString *message;
69 int i = 0;
71 if(!purple_http_response_is_successful(response))
72 return;
74 changelog = purple_http_response_get_data(response, NULL);
76 while(changelog[i] && changelog[i] != '\n') i++;
78 /* this basically means the version thing wasn't in the format we were
79 * looking for so sourceforge is probably having web server issues, and
80 * we should try again later */
81 if(i == 0)
82 return;
84 cur_ver = g_strndup(changelog, i);
86 message = g_string_new("");
87 g_string_append_printf(message, _("You can upgrade to %s %s today."),
88 PIDGIN_NAME, cur_ver);
90 release_dialog = pidgin_make_mini_dialog(
91 NULL, "dialog-information",
92 _("New Version Available"),
93 message->str,
94 NULL,
95 _("Later"), PURPLE_CALLBACK(release_hide),
96 _("Download Now"), PURPLE_CALLBACK(release_show),
97 NULL);
99 pidgin_blist_add_alert(release_dialog);
101 g_string_free(message, TRUE);
102 g_free(cur_ver);
105 static void
106 do_check(void)
108 int last_check = purple_prefs_get_int("/plugins/gtk/relnot/last_check");
109 if(!last_check || time(NULL) - last_check > MIN_CHECK_INTERVAL) {
110 gchar *url;
111 const char *host = "pidgin.im";
113 url = g_strdup_printf("https://%s/version.php?version=%s&build=%s",
114 host,
115 purple_core_get_version(),
116 #ifdef _WIN32
117 "purple-win32"
118 #else
119 "purple"
120 #endif
123 purple_http_get(NULL, version_fetch_cb, NULL, url);
125 g_free(url);
127 purple_prefs_set_int("/plugins/gtk/relnot/last_check", time(NULL));
132 static void
133 signed_on_cb(PurpleConnection *gc, void *data) {
134 do_check();
137 /**************************************************************************
138 * Plugin stuff
139 **************************************************************************/
140 static PidginPluginInfo *
141 plugin_query(GError **error)
143 const gchar * const authors[] = {
144 "Nathan Walp <faceprint@faceprint.com>",
145 NULL
148 return pidgin_plugin_info_new(
149 "id", "gtk-relnot",
150 "name", N_("Release Notification"),
151 "version", DISPLAY_VERSION,
152 "category", N_("Notification"),
153 "summary", N_("Checks periodically for new releases."),
154 "description", N_("Checks periodically for new releases and notifies "
155 "the user with the ChangeLog."),
156 "authors", authors,
157 "website", PURPLE_WEBSITE,
158 "abi-version", PURPLE_ABI_VERSION,
159 NULL
163 static gboolean
164 plugin_load(PurplePlugin *plugin, GError **error)
166 purple_prefs_add_none("/plugins/gtk/relnot");
167 purple_prefs_add_int("/plugins/gtk/relnot/last_check", 0);
169 purple_signal_connect(purple_connections_get_handle(), "signed-on",
170 plugin, PURPLE_CALLBACK(signed_on_cb), NULL);
172 /* we don't check if we're offline */
173 if(purple_connections_get_all())
174 do_check();
176 return TRUE;
179 static gboolean
180 plugin_unload(PurplePlugin *plugin, GError **error)
182 return TRUE;
185 PURPLE_PLUGIN_INIT(relnot, plugin_query, plugin_load, plugin_unload);