main.cpp

Go to the documentation of this file.
00001 /*
00002  * File Name: main.cpp
00003  */
00004 
00005 /*
00006  * This file is part of notepad.
00007  *
00008  * notepad is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * notepad is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2010 IREX Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #include <cstdio>
00028 #include <sys/types.h>
00029 #include <unistd.h>
00030 #include <cstring>
00031 
00032 #include <gtk/gtk.h>
00033 #include <gdk/gdkx.h>
00034 
00035 #include "config.h"
00036 #include "i18n.h"
00037 #include "notepad_utils.h"
00038 #include "notepad_window.h"
00039 #include "log.h" 
00040 #include "notepad_ipc.h"
00041 
00042 using namespace notepad;
00043 
00044 static const char* CREATESTR =  "/new";
00045 
00046 static gchar* filename = 0;
00047 static gchar* label = 0;
00048 
00049 static gboolean sys_startup_complete(gpointer data)
00050 {
00051     GtkWidget* window = (GtkWidget*)data;
00052     int xid = GDK_WINDOW_XID(window->window);
00053     ipc_sys_startup_complete(xid);
00054     ipc_change_filename(filename, label);
00055     return FALSE;
00056 }
00057 
00058 
00059 int main(int argc, char* argv[])
00060 {
00061     textdomain(GETTEXT_PACKAGE);
00062 
00063     bool docreate = false;
00064 
00065     GOptionEntry entries[] = 
00066     {
00067         { "file",   'f', 0, G_OPTION_ARG_FILENAME, &filename, "Open file FILE",    "FILE" },
00068         { NULL,      0,  0, G_OPTION_ARG_NONE,     NULL,      NULL,                 NULL  }
00069     };
00070     GError* error = NULL;
00071     GOptionContext* context = g_option_context_new ("- create notes using the stylus");
00072     g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
00073     g_option_context_add_group (context, gtk_get_option_group (TRUE));
00074     gboolean parse_ok = g_option_context_parse (context, &argc, &argv, &error);
00075     g_option_context_free(context);
00076 
00077     if ( ! parse_ok )
00078     {
00079         fprintf(stderr, "Invalid option! '%s --help' prints usage.\n", argv[0]);
00080         return -1;
00081     }
00082 
00083     // generates file if -f .../new is given
00084     if (filename)
00085     {
00086         if (  (strlen(filename) >= strlen(CREATESTR))
00087            && (g_strcasecmp(filename+strlen(filename)-strlen(CREATESTR), CREATESTR) == 0) )
00088         {
00089             LOGPRINTF("Option: '-f /new'. Will create new file with timestamp\n");
00090             g_free(filename);
00091             filename = 0;
00092         }
00093     }
00094 
00095     if (filename == 0)
00096     {
00097         docreate = true;
00098     }
00099 
00100     g_type_init();
00101     if (!g_thread_supported ()) g_thread_init (NULL);
00102     gdk_threads_init();
00103     gtk_init(&argc, &argv);
00104     GDK_THREADS_ENTER();
00105     
00106     if (ipc_set_services() == FALSE)
00107     {
00108         WARNPRINTF("ipc_set_services failed.\n");
00109         return -1;
00110     }
00111     
00112     CNotepadWindow theAppWindow;
00113 #if MACHINE_IS_DR800S || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00114     if (ipc_sys_is_in_portrait_mode())
00115     {
00116         gboolean is_inverted = ipc_sys_is_pageturn_inverted();
00117         LOGPRINTF("Setting pageturning in inverted mode = %d", is_inverted);
00118         theAppWindow.set_pageturn_inverted(is_inverted);
00119     }
00120 #endif 
00121     if (!theAppWindow.init(docreate, filename))
00122     {
00123         return -1;
00124     }
00125     
00126     menu_init(getpid(), (gpointer)&theAppWindow);
00127     theAppWindow.show(TRUE);
00128     label = theAppWindow.getLabel();
00129     filename = g_strdup(theAppWindow.getFilename());
00130     g_idle_add( sys_startup_complete, static_cast<gpointer> (theAppWindow.getWindow()) );
00131         
00132     gtk_main();
00133     GDK_THREADS_LEAVE();
00134     
00135     menu_destroy();
00136     ipc_unset_services();
00137 
00138     g_free(filename);
00139     g_free(label);
00140 
00141     return 0;
00142 }
00143 
00144 
Generated by  doxygen 1.6.2-20100208