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
|
|
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"
|
9943
|
39 #include "version.h"
|
7543
|
40
|
|
41 /* 1 day */
|
|
42 #define MIN_CHECK_INTERVAL 60 * 60 * 24
|
|
43
|
|
44 static void
|
|
45 version_fetch_cb(void *ud, const char *data, size_t len)
|
|
46 {
|
|
47 const char *changelog = data;
|
|
48 char *cur_ver, *formatted;
|
|
49 GString *message;
|
|
50 int i=0;
|
|
51
|
|
52 if(!changelog || !len)
|
|
53 return;
|
|
54
|
|
55 while(changelog[i] && changelog[i] != '\n') i++;
|
|
56
|
|
57 cur_ver = g_strndup(changelog, i);
|
|
58 changelog += i;
|
|
59
|
|
60 while(*changelog == '\n') changelog++;
|
|
61
|
|
62 message = g_string_new("");
|
|
63 g_string_append_printf(message, _("You are using Gaim version %s. The "
|
|
64 "current version is %s.<hr>"),
|
|
65 gaim_core_get_version(), cur_ver);
|
|
66
|
|
67 if(*changelog) {
|
|
68 formatted = gaim_strdup_withhtml(changelog);
|
|
69 g_string_append_printf(message, _("<b>ChangeLog:</b>\n%s<br><br>"),
|
|
70 formatted);
|
|
71 g_free(formatted);
|
|
72 }
|
|
73
|
|
74 g_string_append_printf(message, _("You can get version %s from:<br>"
|
|
75 "<a href=\"http://gaim.sourceforge.net/\">"
|
|
76 "http://gaim.sourceforge.net</a>."), cur_ver);
|
|
77
|
|
78 gaim_notify_formatted(NULL, _("New Version Available"),
|
|
79 _("New Version Available"), NULL, message->str,
|
|
80 NULL, NULL);
|
|
81
|
|
82 g_string_free(message, TRUE);
|
7599
|
83 g_free(cur_ver);
|
7543
|
84 }
|
|
85
|
|
86 static void
|
|
87 do_check(void)
|
|
88 {
|
|
89 int last_check = gaim_prefs_get_int("/plugins/gtk/relnot/last_check");
|
|
90 if(!last_check || time(NULL) - last_check > MIN_CHECK_INTERVAL) {
|
7546
|
91 char *url = g_strdup_printf("http://gaim.sourceforge.net/version.php?version=%s&build=%s", gaim_core_get_version(),
|
7543
|
92 #ifdef _WIN32
|
7546
|
93 "gaim-win32"
|
7543
|
94 #else
|
7546
|
95 "gaim"
|
7543
|
96 #endif
|
7546
|
97 );
|
7543
|
98 gaim_url_fetch(url, TRUE, NULL, FALSE, version_fetch_cb, NULL);
|
|
99 gaim_prefs_set_int("/plugins/gtk/relnot/last_check", time(NULL));
|
7545
|
100 g_free(url);
|
7543
|
101 }
|
|
102 }
|
|
103
|
|
104 static void
|
|
105 signed_on_cb(GaimConnection *gc, void *data) {
|
|
106 do_check();
|
|
107 }
|
|
108
|
|
109 /**************************************************************************
|
|
110 * Plugin stuff
|
|
111 **************************************************************************/
|
|
112 static gboolean
|
|
113 plugin_load(GaimPlugin *plugin)
|
|
114 {
|
|
115 gaim_signal_connect(gaim_connections_get_handle(), "signed-on",
|
|
116 plugin, GAIM_CALLBACK(signed_on_cb), NULL);
|
|
117
|
|
118 /* we don't check if we're offline */
|
|
119 if(gaim_connections_get_all())
|
|
120 do_check();
|
|
121
|
|
122 return TRUE;
|
|
123 }
|
|
124
|
|
125 static GaimPluginInfo info =
|
|
126 {
|
9943
|
127 GAIM_PLUGIN_MAGIC,
|
|
128 GAIM_MAJOR_VERSION,
|
|
129 GAIM_MINOR_VERSION,
|
7543
|
130 GAIM_PLUGIN_STANDARD, /**< type */
|
|
131 NULL, /**< ui_requirement */
|
|
132 0, /**< flags */
|
|
133 NULL, /**< dependencies */
|
|
134 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
135
|
|
136 "gtk-relnot", /**< id */
|
|
137 N_("Release Notification"), /**< name */
|
|
138 VERSION, /**< version */
|
|
139 /** summary */
|
|
140 N_("Checks periodically for new releases."),
|
|
141 /** description */
|
|
142 N_("Checks periodically for new releases and notifies the user "
|
|
143 "with the ChangeLog."),
|
|
144 "Nathan Walp <faceprint@faceprint.com>", /**< author */
|
|
145 GAIM_WEBSITE, /**< homepage */
|
|
146
|
|
147 plugin_load, /**< load */
|
|
148 NULL, /**< unload */
|
|
149 NULL, /**< destroy */
|
|
150
|
|
151 NULL, /**< ui_info */
|
8993
|
152 NULL, /**< extra_info */
|
|
153 NULL,
|
|
154 NULL
|
7543
|
155 };
|
|
156
|
|
157 static void
|
|
158 init_plugin(GaimPlugin *plugin)
|
|
159 {
|
|
160 gaim_prefs_add_none("/plugins/gtk/relnot");
|
|
161 gaim_prefs_add_int("/plugins/gtk/relnot/last_check", 0);
|
|
162 }
|
|
163
|
7769
|
164 GAIM_INIT_PLUGIN(relnot, init_plugin, info)
|