00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00026
00027
00028
00029
00030 #include <gtk/gtk.h>
00031 #include <gdk/gdkkeysyms.h>
00032 #include "browserTypes.h"
00033 #include <pthread.h>
00034 #include "pagebar.h"
00035 #include <liberdm/display.h>
00036 #include "browser.h"
00037 #include "mozilla_api.h"
00038 #include "selection.h"
00039 #include "find.h"
00040 #include "timingInfo.h"
00041 #include "browserSettings.h"
00042 #include "find.h"
00043 #include "languages.h"
00044 #include "ipcServer.h"
00045 #include "toolbar.h"
00046 #include <liberipc/eripcbusyd.h>
00047 #include <liberipc/eripccontentlister.h>
00048 #include "contentLister.h"
00049 #include "displayUpdate.h"
00050 #include "browserLog.h"
00051 #include "erbusy.h"
00052
00053
00054 static Ereader *gEreader;
00055
00056
00057 guint on_mainWindow_keypress(GtkWidget * widget, GdkEventKey * event, Ereader * reader);
00058
00067 int main(int argc, char **argv)
00068 {
00069 bool initialized;
00070 char *input_URL = NULL;
00071 char *manifest = NULL;
00072 int returnValue = 0;
00073
00074
00075 g_thread_init(NULL);
00076 gdk_threads_init();
00077
00078 BR_LOGPRINTF("gtk threads init");
00079
00080 #ifdef TIMING_INFORMATION_ENABLED
00081 timing_init();
00082 #endif //TIMING_INFORMATION_ENABLED
00083
00084 gtk_init(&argc, &argv);
00085
00086 languagesInit();
00087
00088
00089 erbusy_init();
00090
00091 if (argc > 1)
00092 {
00093 BR_LOGPRINTF("argc = %d argv[1] = %s", argc, argv[1]);
00094 if (argv[1] && strlen(argv[1]))
00095 {
00096 manifest = g_strdup(argv[1]);
00097 }
00098 }
00099
00100 if (argc > 2)
00101 {
00102 BR_LOGPRINTF("argc = %d argv[2] = %s\n", argc, argv[2]);
00103 input_URL = g_strdup(argv[2]);
00104 }
00105
00106 gEreader = new_gtk_ereader(manifest, input_URL);
00107
00108 if (gEreader)
00109 {
00110 BR_LOGPRINTF("ereader_init gEreader 0x%x gEreader->pageStatus 0x%x", gEreader, gEreader->pageStatus);
00111
00112
00113 initialized = browser_settings_init(GTK_MOZ_EMBED(gEreader->mozEmbed));
00114
00115 BR_LOGPRINTF("main -- browser_settings_init returned %s", (initialized == TRUE) ? "TRUE" : "FALSE");
00116
00117 if (initialized == TRUE)
00118 {
00119 if (ipc_InstallIpcServer(gEreader) == TRUE)
00120 {
00121
00122 contentlister_init();
00123
00124 toolbar_init();
00125
00126
00127 erbusy_blink();
00128
00129
00130 pagebar_init();
00131
00132
00133 BR_LOGPRINTF("ereader_init gEreader 0x%x gEreader->pageStatus 0x%x", gEreader, gEreader->pageStatus);
00134 gdk_threads_enter();
00135 gtk_main();
00136 gdk_threads_leave();
00137 }
00138 else
00139 {
00140 BR_ERRORPRINTF("browser_toolbar_start_listening returned FALSE");
00141 returnValue = 1;
00142 }
00143 }
00144 else
00145 {
00146 BR_ERRORPRINTF("browser_settings_init returned FALSE");
00147 returnValue = 1;
00148 }
00149 }
00150 else
00151 {
00152 BR_ERRORPRINTF("new_gtk_ereader returned NULL");
00153 returnValue = 1;
00154 }
00155
00156 if (input_URL)
00157 {
00158 g_free(input_URL);
00159 }
00160
00161 #ifdef TIMING_INFORMATION_ENABLED
00162 timing_destroy();
00163 #endif //TIMING_INFORMATION_ENABLED
00164
00165 return returnValue;
00166 }
00167
00168
00169
00170
00171 guint on_mainWindow_keypress(GtkWidget * widget, GdkEventKey * event, Ereader * reader)
00172 {
00173 GtkWidget *mozEmbed;
00174 int returnValue = 0;
00175
00176 int pagecount;
00177 int currentpage;
00178 int newpage;
00179 int offset;
00180
00181 BR_LOGPRINTF("on_mainWindow_keypress - event 0x%xn", event->keyval);
00182
00183 mozEmbed = gEreader->mozEmbed;
00184
00185 switch (event->keyval)
00186 {
00187 case GDK_Page_Up:
00188 BR_LOGPRINTF("jumping to the next page");
00189 if (mozilla_scrollable(pageUp_t, GTK_MOZ_EMBED(mozEmbed)) == FALSE)
00190 {
00191 if (mozilla_previous_page(GTK_MOZ_EMBED(mozEmbed)) == TRUE)
00192 {
00193 BR_LOGPRINTF("BUSY ON");
00194 erbusy_blink();
00195 }
00196 else
00197 {
00198 BR_LOGPRINTF("mozilla_previous_page returend FALSE");
00199 erbusy_off();
00200 }
00201 }
00202 else
00203 {
00204 if (mozilla_scroll(-1, GTK_MOZ_EMBED(mozEmbed)) == TRUE)
00205 {
00206 offset = mozilla_determine_page_offset(GTK_MOZ_EMBED(mozEmbed));
00207 pagebar_set_offset(offset);
00208 pagebar_redraw();
00209 display_update_request_screen_refresh(MOZEMBED_UPDATE_LEVEL, NULL);
00210 }
00211 }
00212
00213 returnValue = 1;
00214 break;
00215
00216 case GDK_F1:
00217 BR_LOGPRINTF("PAGETURN_FORWARD LONG");
00218
00219 pagecount = reader->pageStatus->pageCount;
00220 currentpage = reader->pageStatus->currentPage;
00221 newpage = ((currentpage + 5) <= pagecount) ? (currentpage + 5) : pagecount;
00222
00223 printf("NEWPAGE: %d (%d, %d)\n", newpage, currentpage, pagecount);
00224
00225 browser_pagebar_page_selected(newpage, gEreader);
00226
00227
00228 returnValue = 1;
00229 break;
00230
00231 case GDK_Page_Down:
00232 BR_LOGPRINTF("jumping to the previous page");
00233 if (mozilla_scrollable(pageDown_t, GTK_MOZ_EMBED(mozEmbed)) == FALSE)
00234 {
00235 if (mozilla_next_page(GTK_MOZ_EMBED(mozEmbed)) == TRUE)
00236 {
00237 BR_LOGPRINTF("BUSY ON");
00238 erbusy_blink();
00239 }
00240 else
00241 {
00242 BR_LOGPRINTF("mozilla_next_page returend FALSE");
00243 erbusy_off();
00244 }
00245 }
00246 else
00247 {
00248 if (mozilla_scroll(1, GTK_MOZ_EMBED(mozEmbed)) == TRUE)
00249 {
00250 offset = mozilla_determine_page_offset(GTK_MOZ_EMBED(mozEmbed));
00251 pagebar_set_offset(offset);
00252 pagebar_redraw();
00253 display_update_request_screen_refresh(MOZEMBED_UPDATE_LEVEL, NULL);
00254 }
00255 }
00256
00257
00258 returnValue = 1;
00259 break;
00260
00261 case GDK_F2:
00262 BR_LOGPRINTF("PAGETURN_BACK LONG");
00263
00264 pagecount = reader->pageStatus->pageCount;
00265 currentpage = reader->pageStatus->currentPage;
00266 newpage = ((currentpage - 5) < 1) ? (1) : (currentpage - 5);
00267
00268 printf("NEWPAGE: %d (%d, %d)\n", newpage, currentpage, pagecount);
00269
00270
00271 browser_pagebar_page_selected(newpage, gEreader);
00272
00273
00274 returnValue = 1;
00275 break;
00276
00277 case GDK_Up:
00278 BR_LOGPRINTF("jumping to the previous link");
00279
00280 if (mozilla_previous_link(GTK_MOZ_EMBED(mozEmbed)) == TRUE)
00281 {
00282
00283 display_update_request_screen_refresh(MOZEMBED_UPDATE_LEVEL, (gpointer) DM_QUALITY_TYPING);
00284 }
00285 else
00286 {
00287 BR_LOGPRINTF("mozilla_previous_link returend FALSE");
00288 erbusy_off();
00289 }
00290
00291 returnValue = 1;
00292 break;
00293
00294 case GDK_Down:
00295 BR_LOGPRINTF("jumping to the next link");
00296
00297 if (mozilla_next_link(GTK_MOZ_EMBED(mozEmbed)) == TRUE)
00298 {
00299
00300 display_update_request_screen_refresh(MOZEMBED_UPDATE_LEVEL, (gpointer) DM_QUALITY_TYPING);
00301 }
00302 else
00303 {
00304 BR_LOGPRINTF("mozilla_next_link returend FALSE");
00305 erbusy_off();
00306 }
00307
00308
00309 returnValue = 1;
00310 break;
00311
00312 case GDK_F5:
00313 BR_LOGPRINTF("up key (F5) pressed... history.go(-1)");
00314 if (mozilla_back(GTK_MOZ_EMBED(mozEmbed)) == TRUE)
00315 {
00316 BR_LOGPRINTF("BUSY ON");
00317 erbusy_blink();
00318 }
00319 else
00320 {
00321 BR_ERRORPRINTF("mozilla_back returend FALSE (we are home), exit the app");
00322 erbusy_blink();
00323 browser_quit();
00324 gtk_main_quit();
00325 }
00326
00327 returnValue = 1;
00328 break;
00329
00330 case GDK_F6:
00331 BR_LOGPRINTF("long confirm key (F6) pressed... goto ALT page");
00332 if (mozilla_alt_page(GTK_MOZ_EMBED(mozEmbed)) == TRUE)
00333 {
00334 BR_LOGPRINTF("BUSY ON");
00335 erbusy_blink();
00336 }
00337 else
00338 {
00339 BR_LOGPRINTF("mozilla_back returend FALSE");
00340 erbusy_off();
00341 }
00342
00343 returnValue = 1;
00344 break;
00345
00346 case GDK_Home:
00347 BR_LOGPRINTF("long up key (Home) pressed... goto INDEX page");
00348 if (mozilla_overview_page(GTK_MOZ_EMBED(mozEmbed)) == TRUE)
00349 {
00350
00351
00352 }
00353 else
00354 {
00355 BR_LOGPRINTF("mozilla_overview_page returend FALSE");
00356 erbusy_off();
00357 }
00358
00359 returnValue = 1;
00360 break;
00361
00362 case GDK_Return:
00363 BR_LOGPRINTF("handle the current link");
00364 if (mozilla_handle_link(GTK_MOZ_EMBED(mozEmbed)) == TRUE)
00365 {
00366 BR_LOGPRINTF("BUSY ON");
00367 erbusy_blink();
00368 }
00369 break;
00370
00371
00372
00373
00374 #ifdef SELECTION_ENABLED
00375 case GDK_p:
00376 char filename[256];
00377
00378
00379 sprintf(filename, "/home/ann/temp_files/selection.html");
00380 BR_LOGPRINTF("p key pressed => mozilla_save page in %s!!!", filename);
00381 if (mozilla_save(GTK_MOZ_EMBED(mozEmbed), filename, 1) == FALSE)
00382 {
00383 BR_LOGPRINTF("mozilla_save returned FALSE");
00384 }
00385 break;
00386
00387 case GDK_i:
00388 BR_LOGPRINTF("identify_selection key pressed...");
00389 selection_identify_and_store_selection(GTK_MOZ_EMBED(mozEmbed));
00390 break;
00391
00392 case GDK_r:
00393 BR_LOGPRINTF("r pressed ==> clear selections");
00394 selection_clear_current_page_selections(GTK_MOZ_EMBED(mozEmbed));
00395 break;
00396 #endif //SELECTION_ENABLED
00397
00398
00399
00400
00401
00402
00403
00404
00405 #ifdef FIND_DIALOG_ENABLED
00406 case GDK_f:
00407 BR_LOGPRINTF("f pressed => INVOKE FIND DIALOG");
00408 browser_find_dialog_create(reader);
00409 break;
00410 #endif //FIND_DIALOG_ENABLED
00411
00412 default:
00413
00414 erbusy_off();
00415 break;
00416
00417 }
00418
00419 return returnValue;
00420 }