1 /* gdict-app.c - main application class
3 * This file is part of GNOME Dictionary
5 * Copyright (C) 2005 Emmanuele Bassi
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
35 #include <glib/gi18n.h>
37 #include "gdict-common.h"
38 #include "gdict-pref-dialog.h"
39 #include "gdict-app.h"
41 static GdictApp
*singleton
= NULL
;
45 GObjectClass parent_class
;
48 G_DEFINE_TYPE (GdictApp
, gdict_app
, G_TYPE_OBJECT
);
50 static gchar
**gdict_lookup_words
= NULL
;
51 static gchar
**gdict_match_words
= NULL
;
53 static gchar
*gdict_source_name
= NULL
;
54 static gchar
*gdict_database_name
= NULL
;
55 static gchar
*gdict_strategy_name
= NULL
;
57 static GOptionEntry gdict_app_goptions
[] = {
61 G_OPTION_ARG_STRING_ARRAY
, &gdict_lookup_words
,
62 N_("Words to look up"), N_("WORD")
67 G_OPTION_ARG_STRING_ARRAY
, &gdict_match_words
,
68 N_("Words to match"), N_("WORD")
73 G_OPTION_ARG_STRING
, &gdict_source_name
,
74 N_("Dictionary source to use"), N_("NAME")
79 G_OPTION_ARG_STRING
, &gdict_database_name
,
80 N_("Database to use"), N_("NAME")
85 G_OPTION_ARG_STRING
, &gdict_strategy_name
,
86 N_("Strategy to use"), N_("NAME")
89 G_OPTION_REMAINING
, 0, 0,
90 G_OPTION_ARG_STRING_ARRAY
, &gdict_lookup_words
,
91 N_("Words to look up"), N_("WORDS")
97 gdict_app_finalize (GObject
*object
)
99 GdictApp
*app
= GDICT_APP (object
);
102 g_object_unref (app
->loader
);
104 G_OBJECT_CLASS (gdict_app_parent_class
)->finalize (object
);
108 gdict_app_class_init (GdictAppClass
*klass
)
110 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
112 gobject_class
->finalize
= gdict_app_finalize
;
116 gdict_app_init (GdictApp
*app
)
121 gdict_activate (GApplication
*application
,
129 gdict_command_line (GApplication
*application
,
130 GApplicationCommandLine
*cmd_line
,
133 GOptionContext
*context
;
140 argv
= g_application_command_line_get_arguments (cmd_line
, &argc
);
142 /* create the new option context */
143 context
= g_option_context_new (N_(" - Look up words in dictionaries"));
145 g_option_context_set_translation_domain (context
, GETTEXT_PACKAGE
);
146 g_option_context_add_main_entries (context
, gdict_app_goptions
, GETTEXT_PACKAGE
);
147 g_option_context_add_group (context
, gdict_get_option_group ());
148 g_option_context_add_group (context
, gtk_get_option_group (FALSE
));
151 if (!g_option_context_parse (context
, &argc
, &argv
, &error
))
153 g_critical ("Failed to parse argument: %s", error
->message
);
154 g_error_free (error
);
155 g_option_context_free (context
);
159 g_option_context_free (context
);
161 if (gdict_lookup_words
== NULL
&&
162 gdict_match_words
== NULL
)
164 GtkWidget
*window
= gdict_window_new (GDICT_WINDOW_ACTION_CLEAR
,
170 gtk_window_set_application (GTK_WINDOW (window
), singleton
->app
);
171 gtk_widget_show (window
);
176 if (gdict_lookup_words
!= NULL
)
177 words_len
= g_strv_length (gdict_lookup_words
);
181 for (i
= 0; i
< words_len
; i
++)
183 const gchar
*word
= gdict_lookup_words
[i
];
186 window
= gdict_window_new (GDICT_WINDOW_ACTION_LOOKUP
,
193 gtk_window_set_application (GTK_WINDOW (window
), singleton
->app
);
194 gtk_widget_show (window
);
197 if (gdict_match_words
!= NULL
)
198 words_len
= g_strv_length (gdict_match_words
);
202 for (i
= 0; i
< words_len
; i
++)
204 const gchar
*word
= gdict_match_words
[i
];
207 window
= gdict_window_new (GDICT_WINDOW_ACTION_MATCH
,
214 gtk_window_set_application (GTK_WINDOW (window
), singleton
->app
);
215 gtk_widget_show (window
);
222 gdict_main (int *argc
,
227 if (!gdict_create_data_dir ())
231 gtk_init (argc
, argv
);
233 g_set_application_name (_("Dictionary"));
234 gtk_window_set_default_icon_name ("accessories-dictionary");
236 /* the main application instance */
237 singleton
= g_object_new (gdict_app_get_type (), NULL
);
239 /* add user's path for fetching dictionary sources */
240 singleton
->loader
= gdict_source_loader_new ();
241 loader_path
= gdict_get_data_dir ();
242 gdict_source_loader_add_search_path (singleton
->loader
, loader_path
);
243 g_free (loader_path
);
245 singleton
->app
= gtk_application_new ("org.gnome.Dictionary", G_APPLICATION_HANDLES_COMMAND_LINE
);
246 g_signal_connect (singleton
->app
, "command-line", G_CALLBACK (gdict_command_line
), singleton
);
248 g_application_run (G_APPLICATION (singleton
->app
), *argc
, *argv
);
256 g_warning ("You must initialize GdictApp using gdict_init()\n");
260 g_object_unref (singleton
->app
);
261 g_object_unref (singleton
);