Fix Icon filename in Serbian translations
[dasher.git] / Src / main.cc
blob085a9d9f5fb344b04c6614596c73fc1ff030163f
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 static const GOptionEntry options[] = {
156 // {"timedata", 'w', 0, G_OPTION_ARG_NONE, &timedata, "Write basic timing information to stdout", NULL},
157 // {"preferences", 'p', 0, G_OPTION_ARG_NONE, &preferences, "Show preferences window only", NULL},
158 // {"textentry", 'o', 0, G_OPTION_ARG_NONE, &textentry, "Onscreen text entry mode", NULL},
159 // {"pipe", 's', 0, G_OPTION_ARG_NONE, &stdoutpipe, "Pipe text to stdout", NULL},
160 /* 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. */
161 {"appstyle", 'a', 0, G_OPTION_ARG_STRING, &(sCommandLine.szAppStyle), N_("Application style (traditional, direct, compose or fullscreen)"), "traditional"},
162 // Note to translators: This is the help string for "--options"
163 {"options", 'o', 0, G_OPTION_ARG_STRING, &(sCommandLine.szOptions), N_("Override stored options"), NULL},
164 {"config", 'c', 0, G_OPTION_ARG_STRING, &(sCommandLine.szConfigFile), N_("XML configuration file name"), NULL},
165 // Note to translators: This is the help string for "--help-options"
166 {"help-options", 0, 0, G_OPTION_ARG_NONE, &do_option_help, N_("Describe \"--options\"."), NULL},
167 {NULL}
170 //parse command line options
171 // Note to translators: This is the "--help" description of dasher.
172 GOptionContext *goptcontext = g_option_context_new(_("- A text input application honouring accessibility"));
173 g_option_context_add_main_entries(goptcontext, options, PACKAGE);
174 g_option_context_add_group(goptcontext, gtk_get_option_group(TRUE));
175 GError *error = nullptr;
176 if (!g_option_context_parse(goptcontext, &argc, &argv, &error)) {
177 g_print("option parsing failed: %s\n", error->message);
178 exit (1);
181 // TODO: Check what happens here when goption has done its stuff
183 if(argc > 1)
184 sCommandLine.szFilename = g_strdup(argv[1]);
185 //later GnomeProgram will call g_option_context_free() when we unref it
186 if (do_option_help)
188 option_help();
189 return 0;
192 #ifdef WITH_GPE
193 gpe_application_init(&argc, &argv);
194 init_xsettings();
195 #else
196 gtk_init(&argc, &argv);
197 #endif
199 #ifdef WITH_MAEMO
200 osso_context = osso_initialize("dasher", PACKAGE_VERSION, TRUE, NULL);
201 #endif
203 #ifdef USE_CSPI
204 if(!bonobo_is_initialized()) {
205 if(!bonobo_init(&argc, argv)) {
206 g_error("Can't initialize Bonobo...\n");
208 bonobo_activate();
210 #endif
212 g_set_application_name("Dasher");
213 #ifndef WITH_MAEMO
214 gtk_window_set_default_icon_name("dasher");
215 #endif
218 g_pDasherMain = dasher_main_new(&argc, &argv, &sCommandLine);
220 g_free(sCommandLine.szFilename);
221 g_free(sCommandLine.szAppStyle);
222 g_free(sCommandLine.szOptions);
223 g_free(sCommandLine.szConfigFile);
225 if (g_pDasherMain == 0)
226 return 1;
228 dasher_main_show(g_pDasherMain);
230 // This call is just to force the linker to export the following symbols.
231 // dasher_editor_internal_get_type();
233 // 10.
234 gtk_main();
236 // 11.
237 clean_up();
239 return 0;
242 void clean_up() {
243 #ifdef WITH_MAEMO
244 osso_deinitialize(osso_context);
245 #endif
247 /* TODO: check that this really does the right thing with the references counting */
248 if(g_pDasherMain)
249 g_object_unref(G_OBJECT(g_pDasherMain));
252 void sigint_handler(int iSigNum) {
253 if(gtk_main_level() > 0) {
254 gtk_main_quit();
256 else {
257 // This implies that we haven't got as far as setting up the main loop yet
258 clean_up();
259 exit(0);