From fe7b3a17f38803da03e9b0973ad573842dfd93d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 19 Oct 2014 16:48:08 +0200 Subject: [PATCH 1/2] Improve logging and notifications of update check results When checking for updates on program start, also log the results to the status messages to make the result more visible to the user. While at it, changed the wording of a few messages and made the version check URL a constant. --- updatechecker/src/updatechecker.c | 46 +++++++++++++++++++------------ 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/updatechecker/src/updatechecker.c b/updatechecker/src/updatechecker.c index 6fa8c2a77..37e648f34 100644 --- a/updatechecker/src/updatechecker.c +++ b/updatechecker/src/updatechecker.c @@ -48,6 +48,8 @@ enum { UPDATECHECK_STARTUP }; +#define UPDATE_CHECK_URL "http://geany.org/service/version.php" + static GtkWidget *main_menu_item = NULL; static void update_check_result_cb(SoupSession *session, SoupMessage *msg, gpointer user_data); @@ -81,13 +83,13 @@ static void update_check(gint type) gchar *user_agent = g_strconcat("Updatechecker ", VERSION, " at Geany ", GEANY_VERSION, NULL); - g_message("Checking for updates"); + g_message("Checking for updates (querying URL \"%s\")", UPDATE_CHECK_URL); soup = soup_session_async_new_with_options(SOUP_SESSION_USER_AGENT, user_agent, NULL); g_free(user_agent); - msg = soup_message_new ("GET", "http://geany.org/service/version.php"); + msg = soup_message_new ("GET", UPDATE_CHECK_URL); soup_session_queue_message (soup, msg, update_check_result_cb, GINT_TO_POINTER(type)); } @@ -184,35 +186,45 @@ static void update_check_result_cb(SoupSession *session, /* Checking whether we did get a valid (200) result */ if (msg->status_code == 200) { - if (version_compare(msg->response_body->data) == TRUE) + const gchar *remote_version = msg->response_body->data; + if (version_compare(remote_version) == TRUE) { - dialogs_show_msgbox(GTK_MESSAGE_INFO, - _("There is a more recent version of Geany available")); - g_message(_("There is a more recent version of Geany available")); + gchar *update_msg = g_strdup_printf( + _("There is a more recent version of Geany available: %s"), + remote_version); + dialogs_show_msgbox(GTK_MESSAGE_INFO, "%s", update_msg); + g_message("%s", update_msg); + g_free(update_msg); } else { + const gchar *no_update_msg = _("No newer Geany version available"); if (type == UPDATECHECK_MANUAL) { - dialogs_show_msgbox(GTK_MESSAGE_INFO, - _("No update available")); + dialogs_show_msgbox(GTK_MESSAGE_INFO, "%s", no_update_msg); } - - g_message("No update available"); - + else + { + msgwin_status_add("%s", no_update_msg); + } + g_message("%s", no_update_msg); } } else { + gchar *error_message = g_strdup_printf( + _("Unable to perform version check.\nError code: %d \nError message: »%s«"), + msg->status_code, msg->reason_phrase); if (type == UPDATECHECK_MANUAL) { - dialogs_show_msgbox(GTK_MESSAGE_ERROR, - _("Wasn't able to catch some version information.\n" - "Error code: %d \n" - "Error message: »%s«"), msg->status_code, msg->reason_phrase); + dialogs_show_msgbox(GTK_MESSAGE_ERROR, "%s", error_message); } - g_warning("Connection error. Code: %d; Message: %s", - msg->status_code, msg->reason_phrase); + else + { + msgwin_status_add("%s", error_message); + } + g_warning("Connection error: Code: %d; Message: %s", msg->status_code, msg->reason_phrase); + g_free(error_message); } } From 1e234a4f770061d37b97880729857ca4d7af4c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 19 Oct 2014 16:56:11 +0200 Subject: [PATCH 2/2] Set a timeout of ten seconds instead of waiting for the default timeout Ten seconds should be enough for this simple request. The default timeout is OS-depent and might be much higher so better set a reasonable value. --- updatechecker/src/updatechecker.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/updatechecker/src/updatechecker.c b/updatechecker/src/updatechecker.c index 37e648f34..64ab54008 100644 --- a/updatechecker/src/updatechecker.c +++ b/updatechecker/src/updatechecker.c @@ -84,8 +84,10 @@ static void update_check(gint type) GEANY_VERSION, NULL); g_message("Checking for updates (querying URL \"%s\")", UPDATE_CHECK_URL); - soup = soup_session_async_new_with_options(SOUP_SESSION_USER_AGENT, - user_agent, NULL); + soup = soup_session_async_new_with_options( + SOUP_SESSION_USER_AGENT, user_agent, + SOUP_SESSION_TIMEOUT, 10, + NULL); g_free(user_agent);