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
26 #ifndef PURPLE_PLUGINS
27 #define PURPLE_PLUGINS
34 #include "connection.h"
40 #include "pidginstock.h"
48 #define MIN_CHECK_INTERVAL 60 * 60 * 24
53 /* No-op. We may use this method in the future to avoid showing
60 purple_notify_uri(NULL
, PURPLE_WEBSITE
);
64 version_fetch_cb(PurpleUtilFetchUrlData
*url_data
, gpointer user_data
,
65 const gchar
*response
, size_t len
, const gchar
*error_message
)
68 const char *tmp
, *changelog
;
69 char response_code
[4];
70 GtkWidget
*release_dialog
;
75 if(error_message
|| !response
|| !len
)
78 memset(response_code
, '\0', sizeof(response_code
));
79 /* Parse the status code - the response should be in the form of "HTTP/?.? 200 ..." */
80 if ((tmp
= strstr(response
, " ")) != NULL
) {
82 /* Read the 3 digit status code */
83 if (len
- (tmp
- response
) > 3) {
84 memcpy(response_code
, tmp
, 3);
88 if (!purple_strequal(response_code
, "200")) {
89 purple_debug_error("relnot", "Didn't recieve a HTTP status code of 200.\n");
93 /* Go to the start of the data */
94 if((changelog
= strstr(response
, "\r\n\r\n")) == NULL
) {
95 purple_debug_error("relnot", "Unable to find start of HTTP response data.\n");
100 while(changelog
[i
] && changelog
[i
] != '\n') i
++;
102 /* this basically means the version thing wasn't in the format we were
103 * looking for so sourceforge is probably having web server issues, and
104 * we should try again later */
108 cur_ver
= g_strndup(changelog
, i
);
110 message
= g_string_new("");
111 g_string_append_printf(message
, _("You can upgrade to %s %s today."),
112 PIDGIN_NAME
, cur_ver
);
114 release_dialog
= pidgin_make_mini_dialog(
115 NULL
, PIDGIN_STOCK_DIALOG_INFO
,
116 _("New Version Available"),
119 _("Later"), PURPLE_CALLBACK(release_hide
),
120 _("Download Now"), PURPLE_CALLBACK(release_show
),
123 pidgin_blist_add_alert(release_dialog
);
125 g_string_free(message
, TRUE
);
132 int last_check
= purple_prefs_get_int("/plugins/gtk/relnot/last_check");
133 if(!last_check
|| time(NULL
) - last_check
> MIN_CHECK_INTERVAL
) {
134 gchar
*url
, *request
;
135 const char *host
= "pidgin.im";
137 url
= g_strdup_printf("https://%s/version.php?version=%s&build=%s",
139 purple_core_get_version(),
147 request
= g_strdup_printf(
148 "GET %s HTTP/1.0\r\n"
149 "Connection: close\r\n"
155 purple_util_fetch_url_request_len(url
, TRUE
, NULL
, FALSE
,
156 request
, TRUE
, -1, version_fetch_cb
, NULL
);
161 purple_prefs_set_int("/plugins/gtk/relnot/last_check", time(NULL
));
167 signed_on_cb(PurpleConnection
*gc
, void *data
) {
171 /**************************************************************************
173 **************************************************************************/
175 plugin_load(PurplePlugin
*plugin
)
177 purple_signal_connect(purple_connections_get_handle(), "signed-on",
178 plugin
, PURPLE_CALLBACK(signed_on_cb
), NULL
);
180 /* we don't check if we're offline */
181 if(purple_connections_get_all())
187 static PurplePluginInfo info
=
190 PURPLE_MAJOR_VERSION
,
191 PURPLE_MINOR_VERSION
,
192 PURPLE_PLUGIN_STANDARD
, /**< type */
193 NULL
, /**< ui_requirement */
195 NULL
, /**< dependencies */
196 PURPLE_PRIORITY_DEFAULT
, /**< priority */
198 "gtk-relnot", /**< id */
199 N_("Release Notification"), /**< name */
200 DISPLAY_VERSION
, /**< version */
202 N_("Checks periodically for new releases."),
204 N_("Checks periodically for new releases and notifies the user "
205 "with the ChangeLog."),
206 "Nathan Walp <faceprint@faceprint.com>", /**< author */
207 PURPLE_WEBSITE
, /**< homepage */
209 plugin_load
, /**< load */
211 NULL
, /**< destroy */
213 NULL
, /**< ui_info */
214 NULL
, /**< extra_info */
226 init_plugin(PurplePlugin
*plugin
)
228 purple_prefs_add_none("/plugins/gtk/relnot");
229 purple_prefs_add_int("/plugins/gtk/relnot/last_check", 0);
232 PURPLE_INIT_PLUGIN(relnot
, init_plugin
, info
)