X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Faweather-gui.c;h=7b42818d912452dc08c0a344c45e8d549ec62db4;hb=4e582af3ff02eebe2c5a1172dbd3052a0fafcf60;hp=41069b0c2603360b4cc04f818116ee748bfeac78;hpb=ed2fbc45c1cf58bc1e3427fca0522b688da0e07f;p=aweather diff --git a/src/aweather-gui.c b/src/aweather-gui.c index 41069b0..7b42818 100644 --- a/src/aweather-gui.c +++ b/src/aweather-gui.c @@ -18,9 +18,10 @@ #include #include #include +#include #include -#include +#include #include "aweather-gui.h" #include "aweather-location.h" @@ -33,10 +34,15 @@ G_MODULE_EXPORT gboolean on_gui_key_press(GtkWidget *widget, GdkEventKey *event, { g_debug("AWeatherGui: on_gui_key_press - key=%x, state=%x", event->keyval, event->state); + GObject *action = aweather_gui_get_object(self, "fullscreen"); + gboolean full = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)); if (event->keyval == GDK_q) gtk_widget_destroy(GTK_WIDGET(self)); + else if (event->keyval == GDK_F11 || + (event->keyval == GDK_Escape && full)) + gtk_action_activate(GTK_ACTION(action)); else if (event->keyval == GDK_r && event->state & GDK_CONTROL_MASK) - gis_viewer_refresh(self->viewer); + grits_viewer_refresh(self->viewer); else if (event->keyval == GDK_Tab || event->keyval == GDK_ISO_Left_Tab) { GtkNotebook *tabs = GTK_NOTEBOOK(aweather_gui_get_widget(self, "main_tabs")); gint num_tabs = gtk_notebook_get_n_pages(tabs); @@ -49,7 +55,36 @@ 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 grits */ + gchar *cache = g_build_filename(g_get_user_cache_dir(), "grits", NULL); + cleancache_r(cache); +} + +G_MODULE_EXPORT void on_contents(GtkMenuItem *menu, AWeatherGui *self) { GError *err = NULL; gchar *path = g_strdup(HTMLDIR "/aweather.html"); @@ -71,17 +106,32 @@ G_MODULE_EXPORT void on_quit(GtkMenuItem *menu, AWeatherGui *self) G_MODULE_EXPORT void on_zoomin(GtkAction *action, AWeatherGui *self) { - gis_viewer_zoom(self->viewer, 3./4); + grits_viewer_zoom(self->viewer, 3./4); } G_MODULE_EXPORT void on_zoomout(GtkAction *action, AWeatherGui *self) { - gis_viewer_zoom(self->viewer, 4./3); + grits_viewer_zoom(self->viewer, 4./3); +} + +G_MODULE_EXPORT void on_fullscreen(GtkToggleAction *action, AWeatherGui *self) +{ + g_message("fullscreen"); + gchar *hide[] = {"main_menu", "main_sidebar", "main_tabs"}; + if (gtk_toggle_action_get_active(action)) { + gtk_window_fullscreen(GTK_WINDOW(self)); + for (int i = 0; i < G_N_ELEMENTS(hide); i++) + gtk_widget_hide(aweather_gui_get_widget(self, hide[i])); + } else { + gtk_window_unfullscreen(GTK_WINDOW(self)); + for (int i = 0; i < G_N_ELEMENTS(hide); i++) + gtk_widget_show(aweather_gui_get_widget(self, hide[i])); + } } G_MODULE_EXPORT void on_refresh(GtkAction *action, AWeatherGui *self) { - gis_viewer_refresh(self->viewer); + grits_viewer_refresh(self->viewer); } G_MODULE_EXPORT void on_plugin_toggled(GtkCellRendererToggle *cell, gchar *path_str, AWeatherGui *self) @@ -105,7 +155,7 @@ G_MODULE_EXPORT void on_plugin_toggled(GtkCellRendererToggle *cell, gchar *path_ G_MODULE_EXPORT void on_time_changed(AWeatherGui *self) { g_debug("AWeatherGui: on_time_changed"); - struct tm tm = {}; + struct tm tm = {.tm_isdst = -1}; GtkWidget *cal = aweather_gui_get_widget(self, "main_date_cal"); gtk_calendar_get_date(GTK_CALENDAR(cal), (guint*)&tm.tm_year, @@ -120,7 +170,7 @@ G_MODULE_EXPORT void on_time_changed(AWeatherGui *self) gtk_tree_model_get_iter(model, &iter, path); gtk_tree_model_get(model, &iter, 1, &tm.tm_hour, 2, &tm.tm_min, -1); - gis_viewer_set_time(self->viewer, mktime(&tm)); + grits_viewer_set_time(self->viewer, mktime(&tm)); } static gboolean gtk_tree_model_find_string(GtkTreeModel *model, @@ -146,7 +196,7 @@ static gboolean gtk_tree_model_find_string(GtkTreeModel *model, return FALSE; } -static void update_time_widget(GisViewer *viewer, time_t time, AWeatherGui *self) +static void update_time_widget(GritsViewer *viewer, time_t time, AWeatherGui *self) { g_debug("AWeatherGui: update_time_widget - time=%u", (guint)time); // FIXME @@ -165,7 +215,7 @@ G_MODULE_EXPORT void on_offline(GtkToggleAction *action, AWeatherGui *self) { gboolean value = gtk_toggle_action_get_active(action); g_debug("AWeatherGui: on_offline - offline=%d", value); - gis_viewer_set_offline(self->viewer, value); + grits_viewer_set_offline(self->viewer, value); } G_MODULE_EXPORT void on_initial_site_changed(GtkComboBox *combo, AWeatherGui *self) @@ -176,7 +226,7 @@ G_MODULE_EXPORT void on_initial_site_changed(GtkComboBox *combo, AWeatherGui *se gtk_combo_box_get_active_iter(combo, &iter); gtk_tree_model_get(model, &iter, 0, &code, -1); g_debug("AWeatherGui: on_initial_site_changed - code=%s", code); - gis_prefs_set_string(self->prefs, "aweather/initial_site", code); + grits_prefs_set_string(self->prefs, "aweather/initial_site", code); g_free(code); } @@ -184,14 +234,14 @@ G_MODULE_EXPORT void on_nexrad_url_changed(GtkEntry *entry, AWeatherGui *self) { const gchar *text = gtk_entry_get_text(entry); g_debug("AWeatherGui: on_nexrad_url_changed - url=%s", text); - gis_prefs_set_string(self->prefs, "aweather/nexrad_url", text); + grits_prefs_set_string(self->prefs, "aweather/nexrad_url", text); } G_MODULE_EXPORT int on_log_level_changed(GtkSpinButton *spinner, AWeatherGui *self) { gint value = gtk_spin_button_get_value_as_int(spinner); g_debug("AWeatherGui: on_log_level_changed - %p, level=%d", self, value); - gis_prefs_set_integer(self->prefs, "aweather/log_level", value); + grits_prefs_set_integer(self->prefs, "aweather/log_level", value); return TRUE; } @@ -232,9 +282,9 @@ static void site_setup(AWeatherGui *self) static void prefs_setup(AWeatherGui *self) { /* Set values */ - gchar *nu = gis_prefs_get_string (self->prefs, "aweather/nexrad_url", NULL); - gint ll = gis_prefs_get_integer(self->prefs, "aweather/log_level", NULL); - gchar *is = gis_prefs_get_string (self->prefs, "aweather/initial_site", NULL); + gchar *nu = grits_prefs_get_string (self->prefs, "aweather/nexrad_url", NULL); + gint ll = grits_prefs_get_integer(self->prefs, "aweather/log_level", NULL); + gchar *is = grits_prefs_get_string (self->prefs, "aweather/initial_site", NULL); GtkWidget *nuw = aweather_gui_get_widget(self, "prefs_general_url"); GtkWidget *llw = aweather_gui_get_widget(self, "prefs_general_log"); GtkWidget *isw = aweather_gui_get_widget(self, "prefs_general_site"); @@ -255,7 +305,7 @@ static void prefs_setup(AWeatherGui *self) "Plugin", rend1, "text", 0, NULL); GtkTreeViewColumn *col2 = gtk_tree_view_column_new_with_attributes( "Enabled", rend2, "active", 1, NULL); - g_object_set(rend2, "xalign", 0, NULL); + g_object_set(rend2, "xalign", 0.0, NULL); gtk_tree_view_append_column(tview, col1); gtk_tree_view_append_column(tview, col2); g_signal_connect(rend2, "toggled", G_CALLBACK(on_plugin_toggled), self); @@ -301,7 +351,7 @@ AWeatherGui *aweather_gui_new() g_debug("AWeatherGui: new"); return g_object_new(AWEATHER_TYPE_GUI, NULL); } -GisViewer *aweather_gui_get_viewer(AWeatherGui *self) +GritsViewer *aweather_gui_get_viewer(AWeatherGui *self) { g_assert(AWEATHER_IS_GUI(self)); return self->viewer; @@ -329,9 +379,9 @@ GObject *aweather_gui_get_object(AWeatherGui *self, const gchar *name) } void aweather_gui_attach_plugin(AWeatherGui *self, const gchar *name) { - GisPlugin *plugin = gis_plugins_enable(self->plugins, name, + GritsPlugin *plugin = grits_plugins_enable(self->plugins, name, self->viewer, self->prefs); - GtkWidget *body = gis_plugin_get_config(plugin); + GtkWidget *body = grits_plugin_get_config(plugin); if (body) { GtkWidget *config = aweather_gui_get_widget(self, "main_tabs"); GtkWidget *tab = gtk_label_new(name); @@ -354,7 +404,7 @@ void aweather_gui_deattach_plugin(AWeatherGui *self, const gchar *name) if (tab_name && g_str_equal(name, tab_name)) gtk_notebook_remove_page(GTK_NOTEBOOK(config), i); } - gis_plugins_disable(self->plugins, name); + grits_plugins_disable(self->plugins, name); gtk_widget_queue_draw(GTK_WIDGET(self->viewer)); } @@ -371,20 +421,20 @@ static void aweather_gui_parser_finished(GtkBuildable *_self, GtkBuilder *builde /* Simple things */ gchar *config = g_build_filename(g_get_user_config_dir(), PACKAGE, "config.ini", NULL); gchar *defaults = g_build_filename(PKGDATADIR, "defaults.ini", NULL); - self->prefs = gis_prefs_new(config, defaults); - self->plugins = gis_plugins_new(PLUGINSDIR, self->prefs); - self->viewer = GIS_VIEWER(aweather_gui_get_widget(self, "main_viewer")); - gis_viewer_setup(self->viewer, self->plugins, self->prefs); + self->prefs = grits_prefs_new(config, defaults); + self->plugins = grits_plugins_new(PLUGINSDIR, self->prefs); + self->viewer = GRITS_VIEWER(aweather_gui_get_widget(self, "main_viewer")); + grits_viewer_setup(self->viewer, self->plugins, self->prefs); g_free(config); g_free(defaults); /* Plugins */ GtkTreeIter iter; self->gtk_plugins = GTK_LIST_STORE(aweather_gui_get_object(self, "plugins")); - for (GList *cur = gis_plugins_available(self->plugins); cur; cur = cur->next) { + for (GList *cur = grits_plugins_available(self->plugins); cur; cur = cur->next) { gchar *name = cur->data; GError *error = NULL; - gboolean enabled = gis_prefs_get_boolean_v(self->prefs, "plugins", cur->data, &error); + gboolean enabled = grits_prefs_get_boolean_v(self->prefs, "plugins", cur->data, &error); if (error && error->code == G_KEY_FILE_ERROR_GROUP_NOT_FOUND) enabled = TRUE; gtk_list_store_append(self->gtk_plugins, &iter); @@ -430,7 +480,7 @@ static void aweather_gui_dispose(GObject *_self) g_debug("AWeatherGui: dispose"); AWeatherGui *self = AWEATHER_GUI(_self); if (self->plugins) { - gis_plugins_free(self->plugins); + grits_plugins_free(self->plugins); self->plugins = NULL; } if (self->builder) {