| |
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 |
| |
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| |
19 * 02111-1307, USA. |
| |
20 */ |
| |
21 |
| |
22 #ifdef HAVE_CONFIG_H |
| |
23 #include <config.h> |
| |
24 #endif |
| |
25 |
| |
26 #ifndef GAIM_PLUGINS |
| |
27 #define GAIM_PLUGINS |
| |
28 #endif |
| |
29 |
| |
30 #include "internal.h" |
| |
31 |
| |
32 #include <string.h> |
| |
33 |
| |
34 #include "connection.h" |
| |
35 #include "core.h" |
| |
36 #include "notify.h" |
| |
37 #include "prefs.h" |
| |
38 #include "util.h" |
| |
39 #include "version.h" |
| |
40 |
| |
41 /* 1 day */ |
| |
42 #define MIN_CHECK_INTERVAL 60 * 60 * 24 |
| |
43 |
| |
44 static void |
| |
45 version_fetch_cb(GaimUtilFetchUrlData *url_data, gpointer user_data, |
| |
46 const gchar *changelog, size_t len, const gchar *error_message) |
| |
47 { |
| |
48 char *cur_ver, *formatted; |
| |
49 GString *message; |
| |
50 int i=0; |
| |
51 |
| |
52 if(error_message || !changelog || !len) |
| |
53 return; |
| |
54 |
| |
55 while(changelog[i] && changelog[i] != '\n') i++; |
| |
56 |
| |
57 /* this basically means the version thing wasn't in the format we were |
| |
58 * looking for so sourceforge is probably having web server issues, and |
| |
59 * we should try again later */ |
| |
60 if(i == 0) |
| |
61 return; |
| |
62 |
| |
63 cur_ver = g_strndup(changelog, i); |
| |
64 changelog += i; |
| |
65 |
| |
66 while(*changelog == '\n') changelog++; |
| |
67 |
| |
68 message = g_string_new(""); |
| |
69 g_string_append_printf(message, _("You are using Gaim version %s. The " |
| |
70 "current version is %s.<hr>"), |
| |
71 gaim_core_get_version(), cur_ver); |
| |
72 |
| |
73 if(*changelog) { |
| |
74 formatted = gaim_strdup_withhtml(changelog); |
| |
75 g_string_append_printf(message, _("<b>ChangeLog:</b>\n%s<br><br>"), |
| |
76 formatted); |
| |
77 g_free(formatted); |
| |
78 } |
| |
79 |
| |
80 g_string_append_printf(message, _("You can get version %s from:<br>" |
| |
81 "<a href=\"http://gaim.sourceforge.net/\">" |
| |
82 "http://gaim.sourceforge.net</a>."), cur_ver); |
| |
83 |
| |
84 gaim_notify_formatted(NULL, _("New Version Available"), |
| |
85 _("New Version Available"), NULL, message->str, |
| |
86 NULL, NULL); |
| |
87 |
| |
88 g_string_free(message, TRUE); |
| |
89 g_free(cur_ver); |
| |
90 } |
| |
91 |
| |
92 static void |
| |
93 do_check(void) |
| |
94 { |
| |
95 int last_check = gaim_prefs_get_int("/plugins/gtk/relnot/last_check"); |
| |
96 if(!last_check || time(NULL) - last_check > MIN_CHECK_INTERVAL) { |
| |
97 char *url = g_strdup_printf("http://gaim.sourceforge.net/version.php?version=%s&build=%s", gaim_core_get_version(), |
| |
98 #ifdef _WIN32 |
| |
99 "gaim-win32" |
| |
100 #else |
| |
101 "gaim" |
| |
102 #endif |
| |
103 ); |
| |
104 gaim_util_fetch_url(url, TRUE, NULL, FALSE, version_fetch_cb, NULL); |
| |
105 gaim_prefs_set_int("/plugins/gtk/relnot/last_check", time(NULL)); |
| |
106 g_free(url); |
| |
107 } |
| |
108 } |
| |
109 |
| |
110 static void |
| |
111 signed_on_cb(GaimConnection *gc, void *data) { |
| |
112 do_check(); |
| |
113 } |
| |
114 |
| |
115 /************************************************************************** |
| |
116 * Plugin stuff |
| |
117 **************************************************************************/ |
| |
118 static gboolean |
| |
119 plugin_load(GaimPlugin *plugin) |
| |
120 { |
| |
121 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", |
| |
122 plugin, GAIM_CALLBACK(signed_on_cb), NULL); |
| |
123 |
| |
124 /* we don't check if we're offline */ |
| |
125 if(gaim_connections_get_all()) |
| |
126 do_check(); |
| |
127 |
| |
128 return TRUE; |
| |
129 } |
| |
130 |
| |
131 static GaimPluginInfo info = |
| |
132 { |
| |
133 GAIM_PLUGIN_MAGIC, |
| |
134 GAIM_MAJOR_VERSION, |
| |
135 GAIM_MINOR_VERSION, |
| |
136 GAIM_PLUGIN_STANDARD, /**< type */ |
| |
137 NULL, /**< ui_requirement */ |
| |
138 0, /**< flags */ |
| |
139 NULL, /**< dependencies */ |
| |
140 GAIM_PRIORITY_DEFAULT, /**< priority */ |
| |
141 |
| |
142 "gtk-relnot", /**< id */ |
| |
143 N_("Release Notification"), /**< name */ |
| |
144 VERSION, /**< version */ |
| |
145 /** summary */ |
| |
146 N_("Checks periodically for new releases."), |
| |
147 /** description */ |
| |
148 N_("Checks periodically for new releases and notifies the user " |
| |
149 "with the ChangeLog."), |
| |
150 "Nathan Walp <faceprint@faceprint.com>", /**< author */ |
| |
151 GAIM_WEBSITE, /**< homepage */ |
| |
152 |
| |
153 plugin_load, /**< load */ |
| |
154 NULL, /**< unload */ |
| |
155 NULL, /**< destroy */ |
| |
156 |
| |
157 NULL, /**< ui_info */ |
| |
158 NULL, /**< extra_info */ |
| |
159 NULL, |
| |
160 NULL |
| |
161 }; |
| |
162 |
| |
163 static void |
| |
164 init_plugin(GaimPlugin *plugin) |
| |
165 { |
| |
166 gaim_prefs_add_none("/plugins/gtk/relnot"); |
| |
167 gaim_prefs_add_int("/plugins/gtk/relnot/last_check", 0); |
| |
168 } |
| |
169 |
| |
170 GAIM_INIT_PLUGIN(relnot, init_plugin, info) |