Revision: 2000 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=2000&view=re... Author: frlan Date: 2011-03-27 09:55:45 +0000 (Sun, 27 Mar 2011)
Log Message: ----------- Updatechcker: Check and init threads as a workaround for old GTK/glib versions
Modified Paths: -------------- trunk/geany-plugins/updatechecker/src/updatechecker.c
Modified: trunk/geany-plugins/updatechecker/src/updatechecker.c =================================================================== --- trunk/geany-plugins/updatechecker/src/updatechecker.c 2011-03-22 15:36:59 UTC (rev 1999) +++ trunk/geany-plugins/updatechecker/src/updatechecker.c 2011-03-27 09:55:45 UTC (rev 2000) @@ -31,21 +31,21 @@ PLUGIN_VERSION_CHECK(188)
PLUGIN_SET_TRANSLATABLE_INFO( - LOCALEDIR, - GETTEXT_PACKAGE, - _("Updatechecker"), - _("A plugin which is checking whether there are updates for Geany available."), - VERSION, - "Frank Lanitz frank@frank.uvena.de") + LOCALEDIR, + GETTEXT_PACKAGE, + _("Updatechecker"), + _("A plugin which is checking whether there are updates for Geany available."), + VERSION, + "Frank Lanitz frank@frank.uvena.de")
enum { - UPDATECHECK_MANUAL, - UPDATECHECK_STARTUP + UPDATECHECK_MANUAL, + UPDATECHECK_STARTUP };
static GtkWidget *main_menu_item = NULL; static void update_check_result_cb(SoupSession *session, - SoupMessage *msg, gpointer user_data); + SoupMessage *msg, gpointer user_data);
static gboolean check_on_startup = FALSE;
@@ -55,48 +55,48 @@
static struct { - GtkWidget *run_on_startup; + GtkWidget *run_on_startup; } config_widgets;
typedef struct { - gint major; - gint minor; - gint mini; - gchar *extra; + gint major; + gint minor; + gint mini; + gchar *extra; } version_struct;
static void update_check(gint type) { - SoupSession *soup; - SoupMessage *msg; - gchar *user_agent = g_strconcat("Updatechecker ", VERSION, " at Geany ", - GEANY_VERSION, NULL); + SoupSession *soup; + SoupMessage *msg; + gchar *user_agent = g_strconcat("Updatechecker ", VERSION, " at Geany ", + GEANY_VERSION, NULL);
- g_message("Starting checking for updates"); - soup = soup_session_async_new_with_options(SOUP_SESSION_USER_AGENT, - user_agent, NULL); + g_message("Starting checking for updates"); + 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"); - - soup_session_queue_message (soup, msg, update_check_result_cb, GINT_TO_POINTER(type)); + g_free(user_agent); + + msg = soup_message_new ("GET", "http://geany.org/service/version.php"); + + soup_session_queue_message (soup, msg, update_check_result_cb, GINT_TO_POINTER(type)); }
static void on_geany_startup_complete(G_GNUC_UNUSED GObject *obj, - G_GNUC_UNUSED gpointer user_data) + G_GNUC_UNUSED gpointer user_data) { - if (check_on_startup == TRUE) - { - update_check(UPDATECHECK_STARTUP); - } + if (check_on_startup == TRUE) + { + update_check(UPDATECHECK_STARTUP); + } }
@@ -104,43 +104,43 @@ * http://sylpheed.sraoss.jp/en/ * GPL FTW! */ static void parse_version_string(const gchar *ver, gint *major, gint *minor, - gint *micro, gchar **extra) + gint *micro, gchar **extra) { - gchar **vers; - vers = g_strsplit(ver, ".", 4); - if (vers[0]) - { - *major = atoi(vers[0]); - if (vers[1]) - { - *minor = atoi(vers[1]); - if (vers[2]) - { - *micro = atoi(vers[2]); - if (vers[3]) - { - *extra = g_strdup(vers[3]); - } - else - { - *extra = NULL; - } - } - else - { - *micro = 0; - } - } - else - { - *minor = 0; - } - } - else - { - major = 0; - } - g_strfreev(vers); + gchar **vers; + vers = g_strsplit(ver, ".", 4); + if (vers[0]) + { + *major = atoi(vers[0]); + if (vers[1]) + { + *minor = atoi(vers[1]); + if (vers[2]) + { + *micro = atoi(vers[2]); + if (vers[3]) + { + *extra = g_strdup(vers[3]); + } + else + { + *extra = NULL; + } + } + else + { + *micro = 0; + } + } + else + { + *minor = 0; + } + } + else + { + major = 0; + } + g_strfreev(vers); }
@@ -149,167 +149,175 @@ static gboolean version_compare(const gchar *current_version) { - version_struct geany_running; - version_struct geany_current; - - parse_version_string(GEANY_VERSION, &geany_running.major, - &geany_running.minor, &geany_running.mini, &geany_running.extra); + version_struct geany_running; + version_struct geany_current;
- parse_version_string(current_version, &geany_current.major, - &geany_current.minor, &geany_current.mini, &geany_current.extra); + parse_version_string(GEANY_VERSION, &geany_running.major, + &geany_running.minor, &geany_running.mini, &geany_running.extra);
- if ((geany_running.major < geany_current.major) || - (geany_running.minor < geany_current.minor) || - (geany_running.minor < geany_current.minor)) - { - return TRUE; - } - else - { - return FALSE; - } + parse_version_string(current_version, &geany_current.major, + &geany_current.minor, &geany_current.mini, &geany_current.extra); + + if ((geany_running.major < geany_current.major) || + (geany_running.minor < geany_current.minor) || + (geany_running.minor < geany_current.minor)) + { + return TRUE; + } + else + { + return FALSE; + } }
static void update_check_result_cb(SoupSession *session, - SoupMessage *msg, gpointer user_data) + SoupMessage *msg, gpointer user_data) { - gint type = GPOINTER_TO_INT(user_data); - - /* Checking whether we did get a valid (200) result */ - if (msg->status_code == 200) - { - if (version_compare(msg->response_body->data) == TRUE) - { - dialogs_show_msgbox(GTK_MESSAGE_INFO, - _("There is a more recent version available")); - g_message("There is a more recent version available"); - } - else - { - if (type == UPDATECHECK_MANUAL) - { - dialogs_show_msgbox(GTK_MESSAGE_INFO, - _("No update available")); - } + gint type = GPOINTER_TO_INT(user_data);
- g_message("No update available"); + /* Checking whether we did get a valid (200) result */ + if (msg->status_code == 200) + { + if (version_compare(msg->response_body->data) == TRUE) + { + dialogs_show_msgbox(GTK_MESSAGE_INFO, + _("There is a more recent version available")); + g_message("There is a more recent version available"); + } + else + { + if (type == UPDATECHECK_MANUAL) + { + dialogs_show_msgbox(GTK_MESSAGE_INFO, + _("No update available")); + }
- } - } - else - { - 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); - } - g_warning("Connection error. Code: %d; Message: %s", - msg->status_code, msg->reason_phrase); - } + g_message("No update available"); + + } + } + else + { + 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); + } + g_warning("Connection error. Code: %d; Message: %s", + msg->status_code, msg->reason_phrase); + } }
static void manual_check_activated_cb(GtkMenuItem *menuitem, gpointer gdata) { - update_check(UPDATECHECK_MANUAL); + update_check(UPDATECHECK_MANUAL); }
static void on_configure_response(G_GNUC_UNUSED GtkDialog *dialog, gint response, - G_GNUC_UNUSED gpointer user_data) + G_GNUC_UNUSED gpointer user_data) { - if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) - { - GKeyFile *config = g_key_file_new(); - gchar *data; - gchar *config_dir = g_path_get_dirname(config_file); + if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) + { + GKeyFile *config = g_key_file_new(); + gchar *data; + gchar *config_dir = g_path_get_dirname(config_file);
- config_file = g_strconcat(geany->app->configdir, - G_DIR_SEPARATOR_S, "plugins", G_DIR_SEPARATOR_S, - "updatechecker", G_DIR_SEPARATOR_S, "general.conf", NULL); + config_file = g_strconcat(geany->app->configdir, + G_DIR_SEPARATOR_S, "plugins", G_DIR_SEPARATOR_S, + "updatechecker", G_DIR_SEPARATOR_S, "general.conf", NULL);
- /* Crabbing options that has been set */ - check_on_startup = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(config_widgets.run_on_startup)); + /* Crabbing options that has been set */ + check_on_startup = + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(config_widgets.run_on_startup));
- /* write stuff to file */ - g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL); + /* write stuff to file */ + g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);
- g_key_file_set_boolean(config, "general", "check_for_updates_on_startup", - check_on_startup); + g_key_file_set_boolean(config, "general", "check_for_updates_on_startup", + check_on_startup);
- if (!g_file_test(config_dir, G_FILE_TEST_IS_DIR) - && utils_mkdir(config_dir, TRUE) != 0) - { - dialogs_show_msgbox(GTK_MESSAGE_ERROR, - _("Plugin configuration directory could not be created.")); - } - else - { - /* write config to file */ - data = g_key_file_to_data(config, NULL, NULL); - utils_write_file(config_file, data); - g_free(data); - } + if (!g_file_test(config_dir, G_FILE_TEST_IS_DIR) + && utils_mkdir(config_dir, TRUE) != 0) + { + dialogs_show_msgbox(GTK_MESSAGE_ERROR, + _("Plugin configuration directory could not be created.")); + } + else + { + /* write config to file */ + data = g_key_file_to_data(config, NULL, NULL); + utils_write_file(config_file, data); + g_free(data); + }
- g_free(config_dir); - g_key_file_free(config); - } + g_free(config_dir); + g_key_file_free(config); + } }
GtkWidget * plugin_configure(GtkDialog * dialog) { - GtkWidget *vbox; - vbox = gtk_vbox_new(FALSE, 6); + GtkWidget *vbox; + vbox = gtk_vbox_new(FALSE, 6);
- config_widgets.run_on_startup = gtk_check_button_new_with_label( - _("Run updatecheck on startup")); + config_widgets.run_on_startup = gtk_check_button_new_with_label( + _("Run updatecheck on startup"));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(config_widgets.run_on_startup), - check_on_startup); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(config_widgets.run_on_startup), + check_on_startup);
- gtk_box_pack_start(GTK_BOX(vbox), config_widgets.run_on_startup, FALSE, FALSE, 2); - gtk_widget_show_all(vbox); - g_signal_connect(dialog, "response", G_CALLBACK(on_configure_response), NULL); - return vbox; + gtk_box_pack_start(GTK_BOX(vbox), config_widgets.run_on_startup, FALSE, FALSE, 2); + gtk_widget_show_all(vbox); + g_signal_connect(dialog, "response", G_CALLBACK(on_configure_response), NULL); + return vbox; }
/* Registering of callbacks for Geany events */ PluginCallback plugin_callbacks[] = { - { "geany-startup-complete", (GCallback) &on_geany_startup_complete, FALSE, NULL }, - { NULL, NULL, FALSE, NULL } + { "geany-startup-complete", (GCallback) &on_geany_startup_complete, FALSE, NULL }, + { NULL, NULL, FALSE, NULL } };
static void init_configuration() { - GKeyFile *config = g_key_file_new(); + GKeyFile *config = g_key_file_new();
- /* loading configurations from file ...*/ - config_file = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S, - "plugins", G_DIR_SEPARATOR_S, - "updatechecker", G_DIR_SEPARATOR_S, "general.conf", NULL); + /* loading configurations from file ...*/ + config_file = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S, + "plugins", G_DIR_SEPARATOR_S, + "updatechecker", G_DIR_SEPARATOR_S, "general.conf", NULL);
- /* ... and Initialising options from config file */ - g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL); + /* ... and Initialising options from config file */ + g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);
- check_on_startup = utils_get_setting_boolean(config, "general", - "check_for_updates_on_startup", FALSE); + check_on_startup = utils_get_setting_boolean(config, "general", + "check_for_updates_on_startup", FALSE);
- g_key_file_free(config); + g_key_file_free(config); }
void plugin_init(GeanyData *data) { - init_configuration(); + init_configuration(); + /* soup uses threads but it seems to don't initialize the thread system + * Work around baesed on a patch Colomban Wendling and Matthew Brush */ + + if (! g_thread_supported ()) + { + g_thread_init (NULL); + } + main_menu_item = gtk_menu_item_new_with_mnemonic(_("Check for Updates")); gtk_widget_show(main_menu_item); gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu),
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.