+ GritsPlugin *plugin = grits_plugins_enable(self->plugins, name,
+ self->viewer, self->prefs);
+ GtkWidget *body = grits_plugin_get_config(plugin);
+ if (body) {
+ GtkWidget *config = aweather_gui_get_widget(self, "main_tabs");
+ GtkWidget *tab = gtk_label_new(name);
+ gtk_notebook_append_page(GTK_NOTEBOOK(config), body, tab);
+ gtk_widget_show_all(config);
+ }
+ gtk_widget_queue_draw(GTK_WIDGET(self->viewer));
+}
+void aweather_gui_deattach_plugin(AWeatherGui *self, const gchar *name)
+{
+ GtkWidget *config = aweather_gui_get_widget(self, "main_tabs");
+ guint n_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(config));
+ for (int i = 0; i < n_pages; i++) {
+ g_debug("testing tab %d", i);
+ GtkWidget *body = gtk_notebook_get_nth_page(GTK_NOTEBOOK(config), i);
+ if (!body) continue;
+ GtkWidget *tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(config), body);
+ if (!tab) continue;
+ const gchar *tab_name = gtk_label_get_text(GTK_LABEL(tab));
+ if (tab_name && g_str_equal(name, tab_name))
+ gtk_notebook_remove_page(GTK_NOTEBOOK(config), i);
+ }
+ grits_plugins_disable(self->plugins, name);
+ gtk_widget_queue_draw(GTK_WIDGET(self->viewer));
+}
+void aweather_gui_load_plugins(AWeatherGui *self)
+{
+ g_debug("AWeatherGui: load_plugins");
+ GtkTreeIter iter;
+ for (GList *cur = grits_plugins_available(self->plugins); cur; cur = cur->next) {
+ gchar *name = cur->data;
+ GError *error = NULL;
+ 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);
+ gtk_list_store_set(self->gtk_plugins, &iter, 0, name, 1, enabled, -1);
+ if (enabled)
+ aweather_gui_attach_plugin(self, name);
+ }
+}