]> Pileus Git - aweather/blobdiff - src/main.c
Use external link button handler
[aweather] / src / main.c
index 6d335af60e33c2bd83fdbd7ecef018a955a44d72..55d0ad94cc99ef79be4d88adb7fd283e60a44ae4 100644 (file)
@@ -47,6 +47,12 @@ static void log_func(const gchar *log_domain, GLogLevelFlags log_level,
        }
 }
 
+static void xdg_open(GtkLinkButton *button, const gchar *link, gpointer user_data)
+{
+       gchar *argv[] = {"xdg-open", (gchar*)link, NULL};
+       g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
+}
+
 static void on_log_level_changed(GtkSpinButton *spinner, AWeatherGui *self)
 {
        g_message("main: log_level_changed");
@@ -58,9 +64,9 @@ static void set_location_time(AWeatherGui *gui, char *site, char *time)
        /* Set time
         *   Do this before setting setting location
         *   so that it doesn't refresh twice */
-       struct tm tm = {};
-       strptime(time, "%Y-%m-%d %H:%M", &tm);
-       time_t sec = mktime(&tm);
+       int year, mon, day, hour, min;
+       sscanf(time, "%d-%d-%d %d:%d", &year, &mon, &day, &hour, &min);
+       time_t sec = mktime(&(struct tm){0, year-1900, mon-1, day, hour, min});
        if (sec > 0)
                grits_viewer_set_time(gui->viewer, sec);
        g_debug("date = [%s] == %lu\n", time, sec);
@@ -122,6 +128,9 @@ int main(int argc, char *argv[])
                return -1;
        }
 
+       /* Use external handler for link buttons */
+       gtk_link_button_set_uri_hook(xdg_open, NULL, NULL);
+
        /* Setup debug level for aweather_gui_new */
        g_log_set_handler(NULL, G_LOG_LEVEL_MASK, log_func, NULL);
        log_levels = int2log(opt_debug >= 0 ? opt_debug : debug);