Prepare windows 4.10.1 - there are a few Gtk-only and solaris
[dasher.git] / Src / main.cc
blob8e94b0ef0cd365f21899a5b96f0d572904e193a8
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4 #ifdef GNOME_LIBS
5 #include <glib/gi18n.h>
6 #endif
8 #include "Common/Common.h"
10 #include <gdk/gdk.h>
11 #include <gtk/gtk.h>
12 #include <gdk/gdkx.h>
13 #include <glade/glade.h>
14 #include <signal.h>
15 #if GLIB_CHECK_VERSION(2,6,0)
16 #include <Gtk2/DasherAppSettings.h>
17 #endif
19 #ifdef WITH_MAEMO
20 #include <libosso.h>
21 #endif
23 // TODO: This shouldn't need to be here
24 #if (defined GNOME_SPEECH || defined GNOME_A11Y)
25 //#include <gnome.h>
26 #include <libbonobo.h>
27 #endif
29 #ifdef WITH_GPE
30 #include <gpe/init.h>
31 #endif
33 #ifdef GNOME_LIBS
34 #include <libgnome/libgnome.h>
35 #include <libgnomeui/libgnomeui.h>
36 #endif
38 // #include <libintl.h>
39 // #include <locale.h>
40 // #include <stdio.h>
41 // #include <stdlib.h>
42 // #include <iostream>
44 #include "dasher.h"
45 //#include "DasherControl.h"
46 #include "dasher_lock_dialogue.h"
47 #include "dasher_main.h"
49 #ifdef WITH_GPE
50 #include "gpesettings_store.h"
51 #endif
53 //extern int optind;
54 //extern const gchar *filename;
56 DasherMain *g_pDasherMain;
59 // Stuff imported from dasher.cc
61 #ifdef WITH_MAEMO
62 osso_context_t *osso_context;
63 #endif
67 //static GtkWidget *vbox; // Main vbox (top level under main window)
68 // GdkPixbuf *p; // Hmm... descriptive names
69 // GtkWidget *pw;
70 // GtkStyle *style;
72 // GtkWidget *dasher_menu_bar;
73 // GtkWidget *open_filesel;
74 // GtkWidget *save_filesel;
75 // GtkWidget *save_and_quit_filesel;
76 // GtkWidget *import_filesel;
77 // GtkWidget *append_filesel;
78 // GtkWidget *g_pHiddenWindow;
79 // GtkWidget *file_selector;
80 //GtkWidget *g_pEditPane = 0;
81 //GtkWidget *g_pActionPane = 0;
83 #ifdef WITH_MAEMO
84 Window g_xOldIMWindow;
85 #endif
87 //DasherAction *g_pAction = 0;
89 // const gchar *filename = NULL; // Filename of file currently being edited
91 //static DasherEditor *g_pEditor = 0;
94 // Apparently not obsolete, but should be sorted out
96 // gboolean file_modified = FALSE; // Have unsaved changes been made to the current file
97 // gint outputcharacters;
99 // const char *g_szAccessibleContext = 0;
100 // int g_iExpectedPosition = -1;
101 // int g_iOldPosition = -1;
103 // 'Private' methods
107 // "member" variables for main window "class"
109 // int g_bOnTop = true; // Whether the window should always be on top
110 // int g_bDock = true; // Whether to dock the window
111 // int g_iDockType; // Ignored for now - will determine how the window is docked to the side of the screen
112 // double g_dXFraction = 0.25; // Fraction of the width of the screen to use;
113 // double g_dYFraction = 0.25; // Fraction of the height of the screen to use;
115 /// ---
117 /// Old stuff from edit.cc
119 // DasherEditor *g_pEditor = 0;
121 // GtkWidget *the_text_view;
122 // GtkTextBuffer *the_text_buffer;
124 // KeySym *origkeymap;
125 // int modifiedkey = 0;
126 // int numcodes;
128 /// ---
130 void sigint_handler(int iSigNum);
131 void clean_up();
133 // TODO: reimplement command line parsing - should just be a way of
134 // temporarily overriding parameters
136 // GOption command line parsing variables
137 // gboolean timedata = FALSE;
138 // gboolean preferences = FALSE;
139 // gboolean textentry = FALSE;
140 // gboolean stdoutpipe = FALSE;
143 // TODO: Do we actually need this - gtk should in theory have
144 // functions to prevent windows from taking focus, but maybe they
145 // don't work which is why this is here.
147 // GdkFilterReturn dasher_discard_take_focus_filter(GdkXEvent *xevent, GdkEvent *event, gpointer data) {
148 // XEvent *xev = (XEvent *) xevent;
149 // if(xev->xany.type == ClientMessage && (Atom) xev->xclient.data.l[0] == gdk_x11_atom_to_xatom(gdk_atom_intern("WM_TAKE_FOCUS", False))) {
150 // return GDK_FILTER_REMOVE;
151 // }
152 // else {
153 // return GDK_FILTER_CONTINUE;
154 // }
155 // }
158 extern "C" gint main_key_snooper(GtkWidget *pWidget, GdkEventKey *pEvent, gpointer pUserData);
161 int main(int argc, char *argv[]) {
163 // DasherAppSettings *g_pDasherAppSettings;
164 // GtkWidget *window; // Main window
166 signal(2, sigint_handler);
168 bindtextdomain(PACKAGE, LOCALEDIR);
169 bind_textdomain_codeset(PACKAGE, "UTF-8");
170 textdomain(PACKAGE);
172 // gchar *szOptionAppstyle = NULL;
174 SCommandLine sCommandLine;
176 sCommandLine.szFilename = NULL;
177 sCommandLine.szAppStyle = NULL;
178 sCommandLine.szOptions = NULL;
180 // TODO: It would be nice to have command line parsing in version prior to goption (eg in Solaris 10)...
181 #if GLIB_CHECK_VERSION(2,6,0)
182 gboolean do_option_help = false;
183 static const GOptionEntry options[] = {
184 // {"timedata", 'w', 0, G_OPTION_ARG_NONE, &timedata, "Write basic timing information to stdout", NULL},
185 // {"preferences", 'p', 0, G_OPTION_ARG_NONE, &preferences, "Show preferences window only", NULL},
186 // {"textentry", 'o', 0, G_OPTION_ARG_NONE, &textentry, "Onscreen text entry mode", NULL},
187 // {"pipe", 's', 0, G_OPTION_ARG_NONE, &stdoutpipe, "Pipe text to stdout", NULL},
188 /* 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. */
189 {"appstyle", 'a', 0, G_OPTION_ARG_STRING, &(sCommandLine.szAppStyle), N_("Application style (traditional, direct, compose or fullscreen)"), "traditional"},
190 // Note to translators: This is the help string for "--options"
191 {"options", 'o', 0, G_OPTION_ARG_STRING, &(sCommandLine.szOptions), N_("Override stored options"), NULL},
192 // Note to translators: This is the help string for "--help-options"
193 {"help-options", 0, 0, G_OPTION_ARG_NONE, &do_option_help, N_("Describe \"--options\"."), NULL},
194 {NULL}
197 //parse command line options
198 GOptionContext *goptcontext;
199 // Note to translators: This is the "--help" description of dasher.
200 goptcontext = g_option_context_new(_("- A text input application honouring accessibility"));
201 g_option_context_add_main_entries(goptcontext, options, GETTEXT_PACKAGE);
202 g_option_context_add_group(goptcontext, gtk_get_option_group (TRUE));
203 g_option_context_parse(goptcontext, &argc, &argv, NULL);
205 // TODO: Check what happens here when goption has done its stuff
207 if(argc > 1)
208 sCommandLine.szFilename = g_strdup(argv[1]);
209 //later GnomeProgram will call g_option_context_free() when we unref it
210 if (do_option_help)
212 option_help();
213 return 0;
215 #endif
217 #ifdef WITH_GPE
218 gpe_application_init(&argc, &argv);
219 init_xsettings();
220 #else
221 gtk_init(&argc, &argv);
222 #endif
224 #ifdef WITH_MAEMO
225 osso_context = osso_initialize("dasher", PACKAGE_VERSION, TRUE, NULL);
226 #endif
228 #ifdef GNOME_LIBS
229 GnomeProgram *program = 0;
230 #if GLIB_CHECK_VERSION(2,14,0)
231 program = gnome_program_init
232 (argv[0], PACKAGE_VERSION, LIBGNOMEUI_MODULE,
233 argc, argv,
234 GNOME_PARAM_GOPTION_CONTEXT, goptcontext, GNOME_PARAM_NONE);
235 #else
236 program = gnome_program_init
237 (argv[0], PACKAGE_VERSION, LIBGNOMEUI_MODULE,
238 argc, argv,
239 GNOME_PARAM_NONE);
240 #endif
241 #endif /* GNOME_LIBS */
243 #if (defined GNOME_SPEECH || defined GNOME_A11Y)
244 if(!bonobo_is_initialized()) {
245 if(!bonobo_init(&argc, argv)) {
246 g_error("Can't initialize Bonobo...\n");
248 bonobo_activate();
250 #endif
252 g_set_application_name("Dasher");
253 #if (!defined WITH_MAEMO) && GTK_CHECK_VERSION(2,6,0)
254 gtk_window_set_default_icon_name("dasher");
255 #endif
258 g_pDasherMain = dasher_main_new(&argc, &argv, &sCommandLine);
260 g_free(sCommandLine.szFilename);
261 g_free(sCommandLine.szAppStyle);
262 g_free(sCommandLine.szOptions);
264 if (g_pDasherMain == 0)
265 return 1;
267 dasher_main_show(g_pDasherMain);
269 // 10.
270 gtk_main();
272 // 11.
273 clean_up();
275 return 0;
278 void clean_up() {
279 #ifdef WITH_MAEMO
280 osso_deinitialize(osso_context);
281 #endif
283 /* TODO: check that this really does the right thing with the references counting */
284 if(g_pDasherMain)
285 g_object_unref(G_OBJECT(g_pDasherMain));
288 void sigint_handler(int iSigNum) {
289 if(gtk_main_level() > 0) {
290 gtk_main_quit();
292 else {
293 // This implies that we haven't got as far as setting up the main loop yet
294 clean_up();
295 exit(0);