Update Brazilian Portuguese translation
[dasher.git] / Src / main.cc
blob6020fcc902e9f2be7ca144c849377a773c0ecb26
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4 #include <glib/gi18n.h>
6 #include "Common/Common.h"
8 #include <gdk/gdk.h>
9 #include <gtk/gtk.h>
10 #include <gdk/gdkx.h>
11 #include <signal.h>
12 #include <Gtk2/DasherAppSettings.h>
13 /* Just to make sure the symbols for the editor are visible. */
14 // #include <Gtk2/dasher_editor_internal.h>
16 #ifdef WITH_MAEMO
17 #include <libosso.h>
18 #endif
20 // TODO: This shouldn't need to be here
21 #ifdef USE_CSPI
22 #include <libbonobo.h>
23 #endif
25 #ifdef WITH_GPE
26 #include <gpe/init.h>
27 #endif
29 #include "dasher.h"
30 #include "dasher_main.h"
32 #ifdef WITH_GPE
33 #include "gpesettings_store.h"
34 #endif
36 //extern int optind;
37 //extern const gchar *filename;
39 DasherMain *g_pDasherMain;
42 // Stuff imported from dasher.cc
44 #ifdef WITH_MAEMO
45 osso_context_t *osso_context;
46 #endif
50 //static GtkWidget *vbox; // Main vbox (top level under main window)
51 // GdkPixbuf *p; // Hmm... descriptive names
52 // GtkWidget *pw;
53 // GtkStyle *style;
55 // GtkWidget *dasher_menu_bar;
56 // GtkWidget *open_filesel;
57 // GtkWidget *save_filesel;
58 // GtkWidget *save_and_quit_filesel;
59 // GtkWidget *import_filesel;
60 // GtkWidget *append_filesel;
61 // GtkWidget *g_pHiddenWindow;
62 // GtkWidget *file_selector;
63 //GtkWidget *g_pEditPane = 0;
64 //GtkWidget *g_pActionPane = 0;
66 #ifdef WITH_MAEMO
67 Window g_xOldIMWindow;
68 #endif
70 //DasherAction *g_pAction = 0;
72 // const gchar *filename = NULL; // Filename of file currently being edited
75 // Apparently not obsolete, but should be sorted out
77 // gboolean file_modified = FALSE; // Have unsaved changes been made to the current file
78 // gint outputcharacters;
80 // const char *g_szAccessibleContext = 0;
81 // int g_iExpectedPosition = -1;
82 // int g_iOldPosition = -1;
84 // 'Private' methods
88 // "member" variables for main window "class"
90 // int g_bOnTop = true; // Whether the window should always be on top
91 // int g_bDock = true; // Whether to dock the window
92 // int g_iDockType; // Ignored for now - will determine how the window is docked to the side of the screen
93 // double g_dXFraction = 0.25; // Fraction of the width of the screen to use;
94 // double g_dYFraction = 0.25; // Fraction of the height of the screen to use;
96 /// ---
98 /// Old stuff from edit.cc
100 // GtkWidget *the_text_view;
101 // GtkTextBuffer *the_text_buffer;
103 // KeySym *origkeymap;
104 // int modifiedkey = 0;
105 // int numcodes;
107 /// ---
109 void sigint_handler(int iSigNum);
110 void clean_up();
112 // TODO: reimplement command line parsing - should just be a way of
113 // temporarily overriding parameters
115 // GOption command line parsing variables
116 // gboolean timedata = FALSE;
117 // gboolean preferences = FALSE;
118 // gboolean textentry = FALSE;
119 // gboolean stdoutpipe = FALSE;
122 // TODO: Do we actually need this - gtk should in theory have
123 // functions to prevent windows from taking focus, but maybe they
124 // don't work which is why this is here.
126 // GdkFilterReturn dasher_discard_take_focus_filter(GdkXEvent *xevent, GdkEvent *event, gpointer data) {
127 // XEvent *xev = (XEvent *) xevent;
128 // if(xev->xany.type == ClientMessage && (Atom) xev->xclient.data.l[0] == gdk_x11_atom_to_xatom(gdk_atom_intern("WM_TAKE_FOCUS", False))) {
129 // return GDK_FILTER_REMOVE;
130 // }
131 // else {
132 // return GDK_FILTER_CONTINUE;
133 // }
134 // }
136 extern "C" gint main_key_snooper(GtkWidget *pWidget, GdkEventKey *pEvent, gpointer pUserData);
139 int main(int argc, char *argv[]) {
141 // DasherAppSettings *g_pDasherAppSettings;
142 // GtkWidget *window; // Main window
144 signal(2, sigint_handler);
146 bindtextdomain(PACKAGE, LOCALEDIR);
147 bind_textdomain_codeset(PACKAGE, "UTF-8");
148 textdomain(PACKAGE);
150 // gchar *szOptionAppstyle = NULL;
152 SCommandLine sCommandLine;
154 gboolean do_option_help = false;
155 gboolean do_show_version = false;
156 static const GOptionEntry options[] = {
157 // {"timedata", 'w', 0, G_OPTION_ARG_NONE, &timedata, "Write basic timing information to stdout", NULL},
158 // {"preferences", 'p', 0, G_OPTION_ARG_NONE, &preferences, "Show preferences window only", NULL},
159 // {"textentry", 'o', 0, G_OPTION_ARG_NONE, &textentry, "Onscreen text entry mode", NULL},
160 // {"pipe", 's', 0, G_OPTION_ARG_NONE, &stdoutpipe, "Pipe text to stdout", NULL},
161 /* Note to translators: This is the help string for "--appstyle". The four options in brackets MUST either NOT be translated or at least it MUST be clear that they must be used in english. Otherwise a user running a non-english system will receive an error message when using the translated one instead of the english one and has no chance to find out the correct option. */
162 {"appstyle", 'a', 0, G_OPTION_ARG_STRING, &(sCommandLine.szAppStyle), N_("Application style (traditional, direct, compose or fullscreen)"), "traditional"},
163 // Note to translators: This is the help string for "--options"
164 {"options", 'o', 0, G_OPTION_ARG_STRING, &(sCommandLine.szOptions), N_("Override stored options"), NULL},
165 {"config", 'c', 0, G_OPTION_ARG_STRING, &(sCommandLine.szConfigFile), N_("XML configuration file name"), NULL},
166 // Note to translators: This is the help string for "--help-options"
167 {"help-options", 0, 0, G_OPTION_ARG_NONE, &do_option_help, N_("Describe \"--options\"."), NULL},
168 // Note to translators: This is the help string for "--version"
169 {"version", 'v', 0, G_OPTION_ARG_NONE, &do_show_version, N_("Show the version details."), NULL},
170 {NULL}
173 //parse command line options
174 // Note to translators: This is the "--help" description of dasher.
175 GOptionContext *goptcontext = g_option_context_new(_("- A text input application honouring accessibility"));
176 g_option_context_add_main_entries(goptcontext, options, PACKAGE);
177 g_option_context_add_group(goptcontext, gtk_get_option_group(TRUE));
178 GError *error = nullptr;
179 if (!g_option_context_parse(goptcontext, &argc, &argv, &error)) {
180 g_print("option parsing failed: %s\n", error->message);
181 // Note to translators: This is the help string for unrecognized command line options. Do not translate 'dasher --help' part.
182 g_print("%s\n", _("Try 'dasher --help' for more information."));
183 exit (1);
186 // TODO: Check what happens here when goption has done its stuff
188 if(argc > 1)
189 sCommandLine.szFilename = g_strdup(argv[1]);
190 //later GnomeProgram will call g_option_context_free() when we unref it
191 if (do_option_help)
193 option_help();
194 return 0;
197 if (do_show_version)
199 option_version();
200 return 0;
203 #ifdef WITH_GPE
204 gpe_application_init(&argc, &argv);
205 init_xsettings();
206 #else
207 gtk_init(&argc, &argv);
208 #endif
210 #ifdef WITH_MAEMO
211 osso_context = osso_initialize("dasher", PACKAGE_VERSION, TRUE, NULL);
212 #endif
214 #ifdef USE_CSPI
215 if(!bonobo_is_initialized()) {
216 if(!bonobo_init(&argc, argv)) {
217 g_error("Can't initialize Bonobo...\n");
219 bonobo_activate();
221 #endif
223 g_set_application_name("Dasher");
224 #ifndef WITH_MAEMO
225 gtk_window_set_default_icon_name("dasher");
226 #endif
229 g_pDasherMain = dasher_main_new(&argc, &argv, &sCommandLine);
231 g_free(sCommandLine.szFilename);
232 g_free(sCommandLine.szAppStyle);
233 g_free(sCommandLine.szOptions);
234 g_free(sCommandLine.szConfigFile);
236 if (g_pDasherMain == 0)
237 return 1;
239 dasher_main_show(g_pDasherMain);
241 // This call is just to force the linker to export the following symbols.
242 // dasher_editor_internal_get_type();
244 // 10.
245 gtk_main();
247 // 11.
248 clean_up();
250 return 0;
253 void clean_up() {
254 #ifdef WITH_MAEMO
255 osso_deinitialize(osso_context);
256 #endif
258 /* TODO: check that this really does the right thing with the references counting */
259 if(g_pDasherMain)
260 g_object_unref(G_OBJECT(g_pDasherMain));
263 void sigint_handler(int iSigNum) {
264 if(gtk_main_level() > 0) {
265 gtk_main_quit();
267 else {
268 // This implies that we haven't got as far as setting up the main loop yet
269 clean_up();
270 exit(0);