]> Pileus Git - aweather/blobdiff - src/plugins/alert.c
Fix threading bug in Alert plugin
[aweather] / src / plugins / alert.c
index 4bd68d320dee9638a4538f7c05ad867066fe358e..1f19a45feb9bcc370afc40b1d21b3f2c0e52e477 100644 (file)
@@ -423,7 +423,7 @@ void fips_parse(gchar *text, GTree **_counties, GList **_states)
                GritsPoly *poly = grits_poly_parse(sparts[3], "\t", " ", ",");
 
                /* Insert polys into the tree */
-               gint id = g_ascii_strtoll(sparts[0], NULL, 10);
+               glong id = g_ascii_strtoll(sparts[0], NULL, 10);
                g_tree_insert(counties, (gpointer)id, poly);
 
                /* Insert into states list */
@@ -449,8 +449,8 @@ static GtkWidget *_make_msg_details(AlertMsg *msg)
 {
 
        GtkWidget *title     = gtk_label_new("");
-       gchar     *title_str = g_markup_printf_escaped(
-                       "<big><b>%s</b></big>", msg->title);
+       gchar     *title_str = g_markup_printf_escaped("<big><b>%s</b></big>",
+                       msg->title ?: "No title provided");
        gtk_label_set_use_markup(GTK_LABEL(title), TRUE);
        gtk_label_set_markup(GTK_LABEL(title), title_str);
        gtk_label_set_line_wrap(GTK_LABEL(title), TRUE);
@@ -461,8 +461,9 @@ static GtkWidget *_make_msg_details(AlertMsg *msg)
        GtkWidget     *alert      = gtk_scrolled_window_new(NULL, NULL);
        GtkWidget     *alert_view = gtk_text_view_new();
        GtkTextBuffer *alert_buf  = gtk_text_buffer_new(NULL);
-       gchar         *alert_str  = g_markup_printf_escaped(
-                       "%s\n\n%s", msg->description, msg->instruction);
+       gchar         *alert_str  = g_markup_printf_escaped("%s\n\n%s",
+                       msg->description ?: "No description provided",
+                       msg->instruction ?: "No instructions provided");
        PangoFontDescription *alert_font = pango_font_description_from_string(
                        "monospace");
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(alert),
@@ -584,7 +585,7 @@ static GritsPoly *_load_county_based(GritsPluginAlert *alert, AlertMsg *msg)
        gchar **fipses  = g_strsplit(msg->cap.fips6, " ", -1);
        GList *counties = NULL;
        for (int i = 0; fipses[i]; i++) {
-               gint fips = g_ascii_strtoll(fipses[i], NULL, 10);
+               glong fips = g_ascii_strtoll(fipses[i], NULL, 10);
                GritsPoly *county = g_tree_lookup(alert->counties, (gpointer)fips);
                if (!county)
                        continue;
@@ -717,6 +718,13 @@ static gint _sort_warnings(gconstpointer _a, gconstpointer _b)
               (a->info->prior == b->info->prior) ?  0 : 1;
 }
 
+static gboolean _update_end(gpointer _alert)
+{
+       GritsPluginAlert *alert = _alert;
+       gtk_widget_queue_draw(GTK_WIDGET(alert->viewer));
+       return FALSE;
+}
+
 static void _update_warnings(GritsPluginAlert *alert, GList *old)
 {
        g_debug("GritsPluginAlert: _update_warnings");
@@ -736,11 +744,17 @@ static void _update_warnings(GritsPluginAlert *alert, GList *old)
        }
 
        /* Add new messages */
+       /* Load counties first since it does not require network access */
        for (GList *cur = alert->msgs; cur; cur = cur->next) {
                AlertMsg *msg = cur->data;
                msg->county_based = _load_county_based(alert, msg);
+       }
+       g_idle_add(_update_end, alert);
+       for (GList *cur = alert->msgs; cur; cur = cur->next) {
+               AlertMsg *msg = cur->data;
                msg->storm_based  = _load_storm_based(alert, msg);
        }
+       g_idle_add(_update_end, alert);
 
        g_debug("GritsPluginAlert: _load_warnings - end");
 }
@@ -763,7 +777,6 @@ static void _update(gpointer _, gpointer _alert)
        g_list_foreach(old, (GFunc)msg_free, NULL);
        g_list_free(old);
 
-       gtk_widget_queue_draw(GTK_WIDGET(alert->viewer));
        g_debug("GritsPluginAlert: _update - end");
 }
 
@@ -896,7 +909,7 @@ static void grits_plugin_alert_init(GritsPluginAlert *alert)
 {
        g_debug("GritsPluginAlert: init");
        /* Set defaults */
-       alert->threads = g_thread_pool_new(_update, alert, 1, TRUE, NULL);
+       alert->threads = g_thread_pool_new(_update, alert, 1, FALSE, NULL);
        alert->config  = _make_config();
        alert->http    = grits_http_new(G_DIR_SEPARATOR_S
                        "alerts" G_DIR_SEPARATOR_S