Updated Polish translation
[dasher.git] / Src / main.cc
blob06bdf9546bb5ff6f28fca3b1957589a13b9fe47d
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 #include <Gtk2/dasher_editor_internal.h>
15 #ifdef WITH_MAEMO
16 #include <libosso.h>
17 #endif
19 // TODO: This shouldn't need to be here
20 #if (defined GNOME_SPEECH || defined GNOME_A11Y)
21 #include <libbonobo.h>
22 #endif
24 #ifdef WITH_GPE
25 #include <gpe/init.h>
26 #endif
28 #include "dasher.h"
29 #include "dasher_main.h"
31 #ifdef WITH_GPE
32 #include "gpesettings_store.h"
33 #endif
35 //extern int optind;
36 //extern const gchar *filename;
38 DasherMain *g_pDasherMain;
41 // Stuff imported from dasher.cc
43 #ifdef WITH_MAEMO
44 osso_context_t *osso_context;
45 #endif
49 //static GtkWidget *vbox; // Main vbox (top level under main window)
50 // GdkPixbuf *p; // Hmm... descriptive names
51 // GtkWidget *pw;
52 // GtkStyle *style;
54 // GtkWidget *dasher_menu_bar;
55 // GtkWidget *open_filesel;
56 // GtkWidget *save_filesel;
57 // GtkWidget *save_and_quit_filesel;
58 // GtkWidget *import_filesel;
59 // GtkWidget *append_filesel;
60 // GtkWidget *g_pHiddenWindow;
61 // GtkWidget *file_selector;
62 //GtkWidget *g_pEditPane = 0;
63 //GtkWidget *g_pActionPane = 0;
65 #ifdef WITH_MAEMO
66 Window g_xOldIMWindow;
67 #endif
69 //DasherAction *g_pAction = 0;
71 // const gchar *filename = NULL; // Filename of file currently being edited
73 //static DasherEditor *g_pEditor = 0;
76 // Apparently not obsolete, but should be sorted out
78 // gboolean file_modified = FALSE; // Have unsaved changes been made to the current file
79 // gint outputcharacters;
81 // const char *g_szAccessibleContext = 0;
82 // int g_iExpectedPosition = -1;
83 // int g_iOldPosition = -1;
85 // 'Private' methods
89 // "member" variables for main window "class"
91 // int g_bOnTop = true; // Whether the window should always be on top
92 // int g_bDock = true; // Whether to dock the window
93 // int g_iDockType; // Ignored for now - will determine how the window is docked to the side of the screen
94 // double g_dXFraction = 0.25; // Fraction of the width of the screen to use;
95 // double g_dYFraction = 0.25; // Fraction of the height of the screen to use;
97 /// ---
99 /// Old stuff from edit.cc
101 // DasherEditor *g_pEditor = 0;
103 // GtkWidget *the_text_view;
104 // GtkTextBuffer *the_text_buffer;
106 // KeySym *origkeymap;
107 // int modifiedkey = 0;
108 // int numcodes;
110 /// ---
112 void sigint_handler(int iSigNum);
113 void clean_up();
115 // TODO: reimplement command line parsing - should just be a way of
116 // temporarily overriding parameters
118 // GOption command line parsing variables
119 // gboolean timedata = FALSE;
120 // gboolean preferences = FALSE;
121 // gboolean textentry = FALSE;
122 // gboolean stdoutpipe = FALSE;
125 // TODO: Do we actually need this - gtk should in theory have
126 // functions to prevent windows from taking focus, but maybe they
127 // don't work which is why this is here.
129 // GdkFilterReturn dasher_discard_take_focus_filter(GdkXEvent *xevent, GdkEvent *event, gpointer data) {
130 // XEvent *xev = (XEvent *) xevent;
131 // if(xev->xany.type == ClientMessage && (Atom) xev->xclient.data.l[0] == gdk_x11_atom_to_xatom(gdk_atom_intern("WM_TAKE_FOCUS", False))) {
132 // return GDK_FILTER_REMOVE;
133 // }
134 // else {
135 // return GDK_FILTER_CONTINUE;
136 // }
137 // }
140 extern "C" gint main_key_snooper(GtkWidget *pWidget, GdkEventKey *pEvent, gpointer pUserData);
143 int main(int argc, char *argv[]) {
145 // DasherAppSettings *g_pDasherAppSettings;
146 // GtkWidget *window; // Main window
148 signal(2, sigint_handler);
150 bindtextdomain(PACKAGE, LOCALEDIR);
151 bind_textdomain_codeset(PACKAGE, "UTF-8");
152 textdomain(PACKAGE);
154 // gchar *szOptionAppstyle = NULL;
156 SCommandLine sCommandLine;
158 sCommandLine.szFilename = NULL;
159 sCommandLine.szAppStyle = NULL;
160 sCommandLine.szOptions = NULL;
162 gboolean do_option_help = false;
163 static const GOptionEntry options[] = {
164 // {"timedata", 'w', 0, G_OPTION_ARG_NONE, &timedata, "Write basic timing information to stdout", NULL},
165 // {"preferences", 'p', 0, G_OPTION_ARG_NONE, &preferences, "Show preferences window only", NULL},
166 // {"textentry", 'o', 0, G_OPTION_ARG_NONE, &textentry, "Onscreen text entry mode", NULL},
167 // {"pipe", 's', 0, G_OPTION_ARG_NONE, &stdoutpipe, "Pipe text to stdout", NULL},
168 /* 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. */
169 {"appstyle", 'a', 0, G_OPTION_ARG_STRING, &(sCommandLine.szAppStyle), N_("Application style (traditional, direct, compose or fullscreen)"), "traditional"},
170 // Note to translators: This is the help string for "--options"
171 {"options", 'o', 0, G_OPTION_ARG_STRING, &(sCommandLine.szOptions), N_("Override stored options"), NULL},
172 // Note to translators: This is the help string for "--help-options"
173 {"help-options", 0, 0, G_OPTION_ARG_NONE, &do_option_help, N_("Describe \"--options\"."), NULL},
174 {NULL}
177 //parse command line options
178 GOptionContext *goptcontext;
179 // Note to translators: This is the "--help" description of dasher.
180 goptcontext = g_option_context_new(_("- A text input application honouring accessibility"));
181 g_option_context_add_main_entries(goptcontext, options, GETTEXT_PACKAGE);
182 g_option_context_add_group(goptcontext, gtk_get_option_group (TRUE));
183 g_option_context_parse(goptcontext, &argc, &argv, NULL);
185 // TODO: Check what happens here when goption has done its stuff
187 if(argc > 1)
188 sCommandLine.szFilename = g_strdup(argv[1]);
189 //later GnomeProgram will call g_option_context_free() when we unref it
190 if (do_option_help)
192 option_help();
193 return 0;
196 #ifdef WITH_GPE
197 gpe_application_init(&argc, &argv);
198 init_xsettings();
199 #else
200 gtk_init(&argc, &argv);
201 #endif
203 #ifdef WITH_MAEMO
204 osso_context = osso_initialize("dasher", PACKAGE_VERSION, TRUE, NULL);
205 #endif
207 #if (defined GNOME_SPEECH || defined GNOME_A11Y)
208 if(!bonobo_is_initialized()) {
209 if(!bonobo_init(&argc, argv)) {
210 g_error("Can't initialize Bonobo...\n");
212 bonobo_activate();
214 #endif
216 g_set_application_name("Dasher");
217 #ifndef WITH_MAEMO
218 gtk_window_set_default_icon_name("dasher");
219 #endif
222 g_pDasherMain = dasher_main_new(&argc, &argv, &sCommandLine);
224 g_free(sCommandLine.szFilename);
225 g_free(sCommandLine.szAppStyle);
226 g_free(sCommandLine.szOptions);
228 if (g_pDasherMain == 0)
229 return 1;
231 dasher_main_show(g_pDasherMain);
233 // This call is just to force the linker to export the following symbol.
234 dasher_editor_internal_get_type();
236 // 10.
237 gtk_main();
239 // 11.
240 clean_up();
242 return 0;
245 void clean_up() {
246 #ifdef WITH_MAEMO
247 osso_deinitialize(osso_context);
248 #endif
250 /* TODO: check that this really does the right thing with the references counting */
251 if(g_pDasherMain)
252 g_object_unref(G_OBJECT(g_pDasherMain));
255 void sigint_handler(int iSigNum) {
256 if(gtk_main_level() > 0) {
257 gtk_main_quit();
259 else {
260 // This implies that we haven't got as far as setting up the main loop yet
261 clean_up();
262 exit(0);