static void gedit_dict_panel_init(GeditDictPanel *panel) { gchar * data_dir; GeditDictPanelPrivate *priv; GError *gconf_error; panel->priv = GEDIT_DICT_PANEL_GET_PRIVATE (panel); priv = panel->priv; if (!priv->loader) panel->priv->loader = gdict_source_loader_new (); /* add our data dir inside $HOME to the loader's search paths */ data_dir = gdict_get_data_dir (); gdict_source_loader_add_search_path (priv->loader, data_dir); g_free (data_dir); /* get the default gconf client */ if (!priv->gconf_client) priv->gconf_client = gconf_client_get_default (); gconf_error = NULL; gconf_client_add_dir (priv->gconf_client, GDICT_GCONF_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, &gconf_error); if (gconf_error) { /*gdict_show_gerror_dialog (NULL, _("Unable to connect to GConf"), gconf_error);*/ gconf_error = NULL; } priv->notify_id = gconf_client_notify_add (priv->gconf_client, GDICT_GCONF_DIR, gedit_dict_panel_gconf_notify_cb, panel, NULL, &gconf_error); if (gconf_error) { /*gdict_show_gerror_dialog (NULL, _("Unable to get notification for preferences"), gconf_error);*/ gconf_error = NULL; } /* force retrieval of the configuration from GConf */ gedit_dict_panel_set_source_name (panel, NULL); /* Draw widgets */ gedit_dict_panel_draw(panel); }
static void gdict_applet_init (GdictApplet *applet) { GdictAppletPrivate *priv; gchar *data_dir; priv = GDICT_APPLET_GET_PRIVATE (applet); applet->priv = priv; if (!priv->loader) priv->loader = gdict_source_loader_new (); /* add our data dir inside $HOME to the loader's search paths */ data_dir = gdict_get_data_dir (); gdict_source_loader_add_search_path (priv->loader, data_dir); g_free (data_dir); gtk_window_set_default_icon_name ("accessories-dictionary"); mate_panel_applet_set_flags (MATE_PANEL_APPLET (applet), MATE_PANEL_APPLET_EXPAND_MINOR); priv->settings = g_settings_new (GDICT_SETTINGS_SCHEMA); priv->desktop_settings = g_settings_new (DESKTOP_SETTINGS_SCHEMA); g_signal_connect (priv->settings, "changed", G_CALLBACK (gdict_applet_settings_changed_cb), applet); g_signal_connect (priv->desktop_settings, "changed", G_CALLBACK (gdict_applet_settings_changed_cb), applet); mate_panel_applet_set_background_widget (MATE_PANEL_APPLET (applet), GTK_WIDGET (applet)); priv->size = mate_panel_applet_get_size (MATE_PANEL_APPLET (applet)); switch (mate_panel_applet_get_orient (MATE_PANEL_APPLET (applet))) { case MATE_PANEL_APPLET_ORIENT_LEFT: case MATE_PANEL_APPLET_ORIENT_RIGHT: priv->orient = GTK_ORIENTATION_VERTICAL; break; case MATE_PANEL_APPLET_ORIENT_UP: case MATE_PANEL_APPLET_ORIENT_DOWN: priv->orient = GTK_ORIENTATION_HORIZONTAL; break; } priv->icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "accessories-dictionary", 48, 0, NULL); /* force first draw */ gdict_applet_draw (applet); /* force retrieval of the configuration from settings */ gdict_applet_set_source_name (applet, NULL); gdict_applet_set_defbox_font (applet, NULL); gdict_applet_set_print_font (applet, NULL); }
static void gtr_dict_panel_init (GtrDictPanel * panel) { GtrDictPanelPrivate *priv; GtkWidget *vbox; GtkWidget *hbox; panel->priv = GTR_DICT_PANEL_GET_PRIVATE (panel); priv = panel->priv; priv->status = NULL; if (!priv->loader) panel->priv->loader = gdict_source_loader_new (); gtk_orientable_set_orientation (GTK_ORIENTABLE (panel), GTK_ORIENTATION_VERTICAL); /* add our data dir inside $HOME to the loader's search paths */ gdict_source_loader_add_search_path (priv->loader, gtr_dirs_get_user_config_dir ()); /* settings */ priv->settings = g_settings_new ("org.gnome.gtranslator.plugins.dictionary"); g_signal_connect (priv->settings, "changed", G_CALLBACK (on_settings_changed), panel); /* force retrieval of the configuration from gsettings */ gtr_dict_panel_set_source_name (panel, NULL); /* Draw widgets */ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); gtk_widget_show (vbox); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); gtk_widget_show (hbox); /* Look up Button */ panel->priv->button = gtk_button_new_with_mnemonic (_("Look _up:")); g_signal_connect (panel->priv->button, "clicked", G_CALLBACK (gtr_dict_panel_entry_activate_cb), panel); gtk_button_set_relief (GTK_BUTTON (panel->priv->button), GTK_RELIEF_NONE); gtk_box_pack_start (GTK_BOX (hbox), panel->priv->button, FALSE, FALSE, 0); gtk_widget_show (panel->priv->button); /* Entry */ panel->priv->entry = gtk_entry_new (); if (panel->priv->word) gtk_entry_set_text (GTK_ENTRY (panel->priv->entry), panel->priv->word); g_signal_connect (panel->priv->entry, "activate", G_CALLBACK (gtr_dict_panel_entry_activate_cb), panel); gtk_box_pack_start (GTK_BOX (hbox), panel->priv->entry, TRUE, TRUE, 0); gtk_widget_show (panel->priv->entry); /* Defbox */ panel->priv->defbox = gdict_defbox_new (); if (panel->priv->context) gdict_defbox_set_context (GDICT_DEFBOX (panel->priv->defbox), panel->priv->context); g_signal_connect (panel->priv->defbox, "link-clicked", G_CALLBACK (gtr_dict_panel_link_clicked), panel); gtk_container_add (GTK_CONTAINER (vbox), panel->priv->defbox); gtk_widget_show (panel->priv->defbox); /* Sidebar */ panel->priv->sidebar = gdict_sidebar_new (); g_signal_connect (panel->priv->sidebar, "page-changed", G_CALLBACK (sidebar_page_changed_cb), panel); /* Paned */ panel->priv->paned = GTK_PANED (gtk_paned_new (GTK_ORIENTATION_VERTICAL)); gtk_box_pack_start (GTK_BOX (panel), GTK_WIDGET (panel->priv->paned), TRUE, TRUE, 0); gtk_paned_pack1 (panel->priv->paned, vbox, FALSE, TRUE); gtk_paned_pack2 (panel->priv->paned, panel->priv->sidebar, TRUE, TRUE); gtk_widget_show (GTK_WIDGET (panel->priv->paned)); g_settings_bind (panel->priv->settings, DICTIONARY_SETTINGS_POSITION_KEY, panel->priv->paned, "position", G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); /* Speller */ panel->priv->speller = gdict_speller_new (); if (panel->priv->context) gdict_speller_set_context (GDICT_SPELLER (panel->priv->speller), panel->priv->context); g_signal_connect (panel->priv->speller, "word-activated", G_CALLBACK (speller_word_activated_cb), panel); gdict_sidebar_add_page (GDICT_SIDEBAR (panel->priv->sidebar), GDICT_SIDEBAR_SPELLER_PAGE, _("Similar words"), panel->priv->speller); gtk_widget_show (panel->priv->speller); /* db chooser */ panel->priv->db_chooser = gdict_database_chooser_new (); if (panel->priv->context) gdict_database_chooser_set_context (GDICT_DATABASE_CHOOSER (panel->priv->db_chooser), panel->priv->context); g_signal_connect (panel->priv->db_chooser, "database-activated", G_CALLBACK (database_activated_cb), panel); gdict_sidebar_add_page (GDICT_SIDEBAR (panel->priv->sidebar), GDICT_SIDEBAR_DATABASES_PAGE, _("Available dictionaries"), panel->priv->db_chooser); gtk_widget_show (panel->priv->db_chooser); /* Strategy chooser */ panel->priv->strat_chooser = gdict_strategy_chooser_new (); if (panel->priv->context) gdict_strategy_chooser_set_context (GDICT_STRATEGY_CHOOSER (panel->priv->strat_chooser), panel->priv->context); g_signal_connect (panel->priv->strat_chooser, "strategy-activated", G_CALLBACK (strategy_activated_cb), panel); gdict_sidebar_add_page (GDICT_SIDEBAR (panel->priv->sidebar), GDICT_SIDEBAR_STRATEGIES_PAGE, _("Available strategies"), panel->priv->strat_chooser); gtk_widget_show (panel->priv->strat_chooser); /* Source chooser */ panel->priv->source_chooser = gdict_source_chooser_new_with_loader (panel->priv->loader); g_signal_connect (panel->priv->source_chooser, "source-activated", G_CALLBACK (source_activated_cb), panel); gdict_sidebar_add_page (GDICT_SIDEBAR (panel->priv->sidebar), GDICT_SIDEBAR_SOURCES_PAGE, _("Dictionary sources"), panel->priv->source_chooser); gtk_widget_show (panel->priv->source_chooser); gtk_widget_show (panel->priv->sidebar); }
void gdict_init (int *argc, char ***argv) { GError *err = NULL; GOptionContext *context; gchar *loader_path; gchar **lookup_words = NULL; gchar **match_words = NULL; gchar *database = NULL; gchar *strategy = NULL; gchar *source_name = NULL; gboolean no_window = FALSE; gboolean list_sources = FALSE; const GOptionEntry gdict_app_goptions[] = { { "look-up", 0, 0, G_OPTION_ARG_STRING_ARRAY, &lookup_words, N_("Words to look up"), N_("word") }, { "match", 0, 0, G_OPTION_ARG_STRING_ARRAY, &match_words, N_("Words to match"), N_("word") }, { "source", 's', 0, G_OPTION_ARG_STRING, &source_name, N_("Dictionary source to use"), N_("source") }, { "list-sources", 'l', 0, G_OPTION_ARG_NONE, &list_sources, N_("Show available dictionary sources"), NULL }, { "no-window", 'n', 0, G_OPTION_ARG_NONE, &no_window, N_("Print result to the console"), NULL }, { "database", 'D', 0, G_OPTION_ARG_STRING, &database, N_("Database to use"), N_("db") }, { "strategy", 'S', 0, G_OPTION_ARG_STRING, &strategy, N_("Strategy to use"), N_("strat") }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &lookup_words, N_("Words to look up"), N_("word") }, { NULL }, }; g_assert (singleton == NULL); singleton = GDICT_APP (g_object_new (GDICT_TYPE_APP, NULL)); g_assert (GDICT_IS_APP (singleton)); /* create the new option context */ context = g_option_context_new (_(" - Look up words in dictionaries")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, gdict_app_goptions, GETTEXT_PACKAGE); g_option_context_add_group (context, gdict_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, argc, argv, &err); if (err) { g_critical ("Failed to parse argument: %s", err->message); g_error_free (err); g_option_context_free (context); gdict_cleanup (); exit (1); } g_set_application_name (_("Dictionary")); gtk_window_set_default_icon_name ("accessories-dictionary"); if (!gdict_create_data_dir ()) { gdict_cleanup (); exit (1); } singleton->settings = g_settings_new ("org.mate.dictionary"); /* add user's path for fetching dictionary sources */ singleton->loader = gdict_source_loader_new (); loader_path = gdict_get_data_dir (); gdict_source_loader_add_search_path (singleton->loader, loader_path); g_free (loader_path); if (lookup_words) { gsize i; gsize length = g_strv_length (lookup_words); for (i = 0; i < length; i++) singleton->lookup_words = g_slist_prepend (singleton->lookup_words, g_strdup (lookup_words[i])); } if (match_words) { gsize i; gsize length = g_strv_length (match_words); for (i = 0; i < length; i++) singleton->match_words = g_slist_prepend (singleton->match_words, g_strdup (match_words[i])); } if (database) singleton->database = g_strdup (database); if (source_name) singleton->source_name = g_strdup (source_name); if (no_window) singleton->no_window = TRUE; if (list_sources) singleton->list_sources = TRUE; }