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); }
/* create the data directory inside $HOME, if it doesn't exist yet */ gboolean gdict_create_data_dir (void) { gchar *data_dir_name; data_dir_name = gdict_get_data_dir (); if (g_mkdir_with_parents (data_dir_name, 0700) == -1) { /* this is weird, but sometimes there's a "mate-dictionary" file * inside $HOME/.mate2; see bug #329126. */ if ((errno == EEXIST) && (g_file_test (data_dir_name, G_FILE_TEST_IS_REGULAR))) { gchar *backup = g_strdup_printf ("%s.pre-2-14", data_dir_name); if (g_rename (data_dir_name, backup) == -1) { GtkWidget *error_dialog; error_dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Unable to rename file '%s' to '%s': %s"), data_dir_name, backup, g_strerror (errno)); gtk_dialog_run (GTK_DIALOG (error_dialog)); gtk_widget_destroy (error_dialog); g_free (backup); g_free (data_dir_name); return FALSE; } g_free (backup); if (g_mkdir_with_parents (data_dir_name, 0700) == -1) { GtkWidget *error_dialog; error_dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Unable to create the data directory '%s': %s"), data_dir_name, g_strerror (errno)); gtk_dialog_run (GTK_DIALOG (error_dialog)); gtk_widget_destroy (error_dialog); g_free (data_dir_name); return FALSE; } goto success; } if (errno != EEXIST) { GtkWidget *error_dialog; error_dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Unable to create the data directory '%s': %s"), data_dir_name, g_strerror (errno)); gtk_dialog_run (GTK_DIALOG (error_dialog)); gtk_widget_destroy (error_dialog); g_free (data_dir_name); return FALSE; } } success: g_free (data_dir_name); return TRUE; }
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); }
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; }