main.cpp File Reference

#include <cstdio>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include "config.h"
#include "i18n.h"
#include "notepad_utils.h"
#include "notepad_window.h"
#include "log.h"
#include "notepad_ipc.h"
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

static gboolean sys_startup_complete (gpointer data)
int main (int argc, char *argv[])

Variables

static const char * CREATESTR = "/new"
static gchar * filename = 0
static gchar * label = 0

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 59 of file main.cpp.

References CREATESTR, filename, GETTEXT_PACKAGE, notepad::CNotepadWindow::init(), ipc_set_services(), ipc_sys_is_in_portrait_mode(), ipc_sys_is_pageturn_inverted(), ipc_unset_services(), label, LOGPRINTF, menu_destroy(), menu_init(), notepad::CNotepadWindow::set_pageturn_inverted(), sys_startup_complete(), and WARNPRINTF.

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 }

Here is the call graph for this function:

static gboolean sys_startup_complete ( gpointer  data  )  [static]

Definition at line 49 of file main.cpp.

References filename, notepad::ipc_change_filename(), ipc_sys_startup_complete(), and label.

Referenced by main().

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 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char* CREATESTR = "/new" [static]

Definition at line 44 of file main.cpp.

Referenced by main().

gchar* filename = 0 [static]

Definition at line 46 of file main.cpp.

gchar* label = 0 [static]
Generated by  doxygen 1.6.2-20100208