X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Faweather-gui.c;h=59dbfaab6b9cb6aaa0c11c939d67c6a8d7e95662;hb=8cca8454eaaddb82174ebad9d02fa5b3094c89dd;hp=9cf4c8ae833a0e64dc4022bf13160055a3e82205;hpb=a9c7078e69b49d54f86169fde67b7fee55256b52;p=aweather diff --git a/src/aweather-gui.c b/src/aweather-gui.c index 9cf4c8a..59dbfaa 100644 --- a/src/aweather-gui.c +++ b/src/aweather-gui.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -49,16 +50,48 @@ G_MODULE_EXPORT gboolean on_gui_key_press(GtkWidget *widget, GdkEventKey *event, return FALSE; } -G_MODULE_EXPORT void on_help_contents(GtkMenuItem *menu, AWeatherGui *self) +static void cleancache_r(gchar *path) +{ + GDir *dir = g_dir_open(path, 0, NULL); + if (!dir) + return; + const gchar *child; + while ((child = g_dir_read_name(dir))) { + gchar *child_path = g_build_filename(path, child, NULL); + if (g_file_test(child_path, G_FILE_TEST_IS_DIR)) { + cleancache_r(child_path); + } else { + struct stat st; + g_stat(child_path, &st); + if (st.st_atime < time(NULL)-60*60*24) + g_remove(child_path); + } + g_free(child_path); + } + g_dir_close(dir); + g_rmdir(path); +} +G_MODULE_EXPORT void on_cleancache(GtkMenuItem *menu, AWeatherGui *self) +{ + g_debug("AWeatherGui: on_cleancache"); + /* Todo: move this to libgis */ + gchar *cache = g_build_filename(g_get_user_cache_dir(), "libgis", NULL); + cleancache_r(cache); +} + +G_MODULE_EXPORT void on_contents(GtkMenuItem *menu, AWeatherGui *self) { GError *err = NULL; - gchar *argv[] = {BROWSER, HTMLDIR "/aweather.html", NULL}; + gchar *path = g_strdup(HTMLDIR "/aweather.html"); + g_strdelimit(path, "/", G_DIR_SEPARATOR); + gchar *argv[] = {"xdg-open", path, NULL}; g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &err); if (err) { g_warning("Unable to open help page: %s - %s", argv[1], err->message); g_error_free(err); } + g_free(path); } G_MODULE_EXPORT void on_quit(GtkMenuItem *menu, AWeatherGui *self) @@ -261,28 +294,26 @@ static void prefs_setup(AWeatherGui *self) static void time_setup(AWeatherGui *self) { - /* Setup UI */ - GtkCalendar *cal = GTK_CALENDAR(aweather_gui_get_widget(self, "main_date_cal")); - GtkTreeView *view = GTK_TREE_VIEW(aweather_gui_get_widget(self, "main_time")); - GtkCellRenderer *rend = gtk_cell_renderer_text_new(); - GtkTreeViewColumn *col = gtk_tree_view_column_new_with_attributes( - "Time", rend, "text", 0, NULL); - gtk_tree_view_append_column(view, col); - g_object_set(rend, "size-points", 8.0, NULL); - /* Add times */ - GtkListStore *store = GTK_LIST_STORE(aweather_gui_get_object(self, "times")); + GtkTreeStore *store = GTK_TREE_STORE(aweather_gui_get_object(self, "times")); for (int hour = 0; hour < 24; hour++) { - for (int min = 0; min < 60; min += 10) { - GtkTreeIter iter; - gchar *str = g_strdup_printf("%02d:%02d", hour, min); - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, 0, str, 1, hour, 2, min, -1); + GtkTreeIter hour_iter; + gchar *str = g_strdup_printf("%02d:00Z", hour); + gtk_tree_store_append(store, &hour_iter, NULL); + gtk_tree_store_set(store, &hour_iter, 0, str, 1, hour, 2, 0, -1); + g_free(str); + for (int min = 5; min < 60; min += 5) { + GtkTreeIter min_iter; + gchar *str = g_strdup_printf("%02d:%02dZ", hour, min); + gtk_tree_store_append(store, &min_iter, &hour_iter); + gtk_tree_store_set(store, &min_iter, 0, str, 1, hour, 2, min, -1); g_free(str); } } /* Connect signals */ + GtkWidget *cal = aweather_gui_get_widget(self, "main_date_cal"); + GtkWidget *view = aweather_gui_get_widget(self, "main_time"); g_signal_connect_swapped(cal, "day-selected-double-click", G_CALLBACK(on_time_changed), self); g_signal_connect_swapped(view, "row-activated",