static GdictContext * get_context_from_loader (GdictApplet *applet) { GdictAppletPrivate *priv = applet->priv; GdictSource *source; GdictContext *retval; if (!priv->source_name) priv->source_name = g_strdup (GDICT_DEFAULT_SOURCE_NAME); source = gdict_source_loader_get_source (priv->loader, priv->source_name); if (!source) { gchar *detail; detail = g_strdup_printf (_("No dictionary source available with name '%s'"), priv->source_name); gdict_show_error_dialog (NULL, _("Unable to find dictionary source"), NULL); g_free (detail); return NULL; } gdict_applet_set_database (applet, gdict_source_get_database (source)); gdict_applet_set_strategy (applet, gdict_source_get_strategy (source)); retval = gdict_source_get_context (source); if (!retval) { gchar *detail; detail = g_strdup_printf (_("No context available for source '%s'"), gdict_source_get_description (source)); gdict_show_error_dialog (NULL, _("Unable to create a context"), detail); g_free (detail); g_object_unref (source); return NULL; } g_object_unref (source); return retval; }
static GdictContext * get_context_from_loader (GtrDictPanel * panel) { GtrDictPanelPrivate *priv = panel->priv; GdictSource *source; GdictContext *retval; if (!priv->source_name) priv->source_name = g_strdup (DICTIONARY_DEFAULT_SOURCE_NAME); source = gdict_source_loader_get_source (priv->loader, priv->source_name); if (!source) { gchar *detail; detail = g_strdup_printf (_("No dictionary source available with name '%s'"), priv->source_name); gtr_dict_panel_create_warning_dialog (_ ("Unable to find dictionary source"), detail); g_free (detail); return NULL; } gtr_dict_panel_set_database (panel, gdict_source_get_database (source)); gtr_dict_panel_set_strategy (panel, gdict_source_get_strategy (source)); retval = gdict_source_get_context (source); if (!retval) { gchar *detail; detail = g_strdup_printf (_("No context available for source '%s'"), gdict_source_get_description (source)); gtr_dict_panel_create_warning_dialog (_ ("Unable to create a context"), detail); g_free (detail); g_object_unref (source); return NULL; } g_object_unref (source); return retval; }
/** * gdict_source_chooser_refresh: * @chooser: a #GdictSourceChooser * * Forces a refresh on the contents of the source chooser widget * * Since: 0.12 */ void gdict_source_chooser_refresh (GdictSourceChooser *chooser) { GdictSourceChooserPrivate *priv; g_return_if_fail (GDICT_IS_SOURCE_CHOOSER (chooser)); priv = chooser->priv; if (priv->loader) { const GSList *sources, *l; if (priv->treeview) gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview), NULL); gtk_list_store_clear (priv->store); sources = gdict_source_loader_get_sources (priv->loader); for (l = sources; l != NULL; l = l->next) { GdictSource *source = l->data; const gchar *name, *description; GdictSourceTransport transport; gint weight; transport = gdict_source_get_transport (source); name = gdict_source_get_name (source); description = gdict_source_get_description (source); weight = PANGO_WEIGHT_NORMAL; if (priv->current_source && !strcmp (priv->current_source, name)) weight = PANGO_WEIGHT_BOLD; gtk_list_store_insert_with_values (priv->store, NULL, -1, SOURCE_TRANSPORT, transport, SOURCE_NAME, name, SOURCE_DESCRIPTION, description, SOURCE_CURRENT, weight, -1); } if (priv->treeview) gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview), GTK_TREE_MODEL (priv->store)); } }
static void update_sources_view (GdictPrefDialog *dialog) { const GSList *sources, *l; gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->sources_view), NULL); gtk_list_store_clear (dialog->sources_list); /* force update of the sources list */ gdict_source_loader_update (dialog->loader); sources = gdict_source_loader_get_sources (dialog->loader); for (l = sources; l != NULL; l = l->next) { GdictSource *source = GDICT_SOURCE (l->data); GtkTreeIter iter; const gchar *name, *description; gboolean is_active = FALSE; name = gdict_source_get_name (source); description = gdict_source_get_description (source); if (!description) description = name; if (strcmp (name, dialog->active_source) == 0) is_active = TRUE; gtk_list_store_append (dialog->sources_list, &iter); gtk_list_store_set (dialog->sources_list, &iter, SOURCES_ACTIVE_COLUMN, is_active, SOURCES_NAME_COLUMN, name, SOURCES_DESCRIPTION_COLUMN, description, -1); } gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->sources_view), GTK_TREE_MODEL (dialog->sources_list)); /* select the currently active source name */ gtk_tree_model_foreach (GTK_TREE_MODEL (dialog->sources_list), select_active_source_name, dialog); }
static void source_activated_cb (GdictSourceChooser * chooser, const gchar * source_name, GdictSource * source, GtrDictPanel * panel) { g_signal_handlers_block_by_func (chooser, source_activated_cb, panel); gtr_dict_panel_set_source_name (panel, source_name); g_signal_handlers_unblock_by_func (chooser, source_activated_cb, panel); if (panel->priv->status) { gchar *message; message = g_strdup_printf (_("Dictionary source '%s' selected"), gdict_source_get_description (source)); gtr_statusbar_flash_message (panel->priv->status, 0, "%s", message); g_free (message); } }
static void update_dialog_ui (GdictSourceDialog *dialog) { GdictSource *source; /* TODO - add code to update the contents of the dialog depending * on the action; if we are in _CREATE, no action is needed */ switch (dialog->action) { case GDICT_SOURCE_DIALOG_VIEW: case GDICT_SOURCE_DIALOG_EDIT: if (!dialog->source_name) { g_warning ("Attempting to retrieve source, but no " "source name has been defined. Aborting..."); return; } source = gdict_source_loader_get_source (dialog->loader, dialog->source_name); if (!source) { g_warning ("Attempting to retrieve source, but no " "source named `%s' was found. Aborting...", dialog->source_name); return; } g_object_ref (source); dialog->source = source; set_text_to_entry (dialog, "description_entry", gdict_source_get_description (source)); dialog->transport = gdict_source_get_transport (source); gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->transport_combo), (gint) dialog->transport); /* set the context for the database and strategy choosers */ dialog->context = gdict_source_get_context (source); if (!dialog->context) { g_warning ("Attempting to retrieve the context, but " "none was found for source `%s'.", dialog->source_name); return; } set_transport_settings (dialog); gdict_database_chooser_set_context (GDICT_DATABASE_CHOOSER (dialog->db_chooser), dialog->context); gdict_database_chooser_refresh (GDICT_DATABASE_CHOOSER (dialog->db_chooser)); gdict_strategy_chooser_set_context (GDICT_STRATEGY_CHOOSER (dialog->strat_chooser), dialog->context); gdict_strategy_chooser_refresh (GDICT_STRATEGY_CHOOSER (dialog->strat_chooser)); break; case GDICT_SOURCE_DIALOG_CREATE: /* DICTD transport is default */ gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->transport_combo), 0); g_signal_emit_by_name (dialog->transport_combo, "changed"); break; default: g_assert_not_reached (); break; } }