+#include "aweather-location.h"
+
+static gint log_levels = 0;
+
+static int int2log(int level) {
+ level = G_LOG_LEVEL_ERROR << level;
+ level = (level<<1) - 1;
+ level = level & G_LOG_LEVEL_MASK;
+ return level;
+}
+
+static void log_func(const gchar *log_domain, GLogLevelFlags log_level,
+ const gchar *message, gpointer udata)
+{
+ if (log_level & log_levels) {
+ if (log_level == G_LOG_LEVEL_DEBUG)
+ g_fprintf(stderr, "DEBUG: (%p) %s\n",
+ g_thread_self(), message);
+ else
+ g_log_default_handler(log_domain, log_level, message, udata);
+ }
+}
+
+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");
+ log_levels = int2log(gtk_spin_button_get_value_as_int(spinner));
+}
+
+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 */
+ 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);
+
+ /* Set location */
+ for (city_t *city = cities; city->type; city++) {
+ if (city->type == LOCATION_CITY && g_str_equal(city->code, site)) {
+ grits_viewer_set_location(gui->viewer,
+ city->pos.lat, city->pos.lon, EARTH_R/35);
+ break;
+ }
+ }
+}
+
+static void set_toggle_action(AWeatherGui *gui, const char *action, gboolean enabled)
+{
+ GObject *object = aweather_gui_get_object(gui, action);
+ gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(object), enabled);
+}