#include "config.h"
#include <glib.h>
#include <gtk/gtk.h>
#include <signal.h>
#include <unistd.h>
#include <webkit/webkit.h>
#include <libsoup/soup.h>
#include <stdlib.h>
#include <liberutils/display_utils.h>
#include "log.h"
#include "i18n.h"
#include "ipc.h"
#include "main.h"
#include "menu.h"
#include "view.h"
Go to the source code of this file.
Defines | |
#define | UNUSED(x) (void)(x) |
#define | COOKIES_FILE "/home/root/cookies.txt" |
Functions | |
void | main_quit (void) |
static void | on_locale () |
static void | on_connect () |
static void | on_disconnect () |
gboolean | main_request_connection () |
static void | on_terminated (int signo) |
static void | on_segment_fault (int signo) |
static void | on_fpe (int signo) |
static gboolean | show_web_view_cb (BrowserWindow *window, WebKitWebView *web_view) |
int | main (int argc, char *argv[]) |
Variables | |
static const gfloat | zoom_step = 0.20f |
static const gchar * | rc_filename = DATADIR "/" PACKAGE_NAME ".rc" |
static const gchar * | css_uri = "file://" DATADIR "/" PACKAGE_NAME ".css" |
static WebKitWebSettings * | web_settings = NULL |
static gboolean | g_is_connection_requested = FALSE |
static gboolean | g_run_emall = FALSE |
#define COOKIES_FILE "/home/root/cookies.txt" |
Definition at line 68 of file erbrowser/src/main.c.
Referenced by main(), and on_reset_button_clicked().
#define UNUSED | ( | x | ) | (void)(x) |
Copyright (C) 2006, 2007 Apple Inc. Copyright (C) 2007 Alp Toker <alp@atoker.com> Copyright (C) 2008 Collabora Ltd. Copyright (C) 2009 iRex Technologies B.V. All rights reserved.
Definition at line 56 of file erbrowser/src/main.c.
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 244 of file erbrowser/src/main.c.
References COOKIES_FILE, css_uri, display_gain_control(), g_main_window, g_run_emall, GETTEXT_PACKAGE, ipc_set_services(), ipc_sys_disconnect(), ipc_sys_startup_complete(), LOGPRINTF, menu_init(), menu_set_full_screen(), on_connect(), on_disconnect(), on_fpe(), on_locale(), on_segment_fault(), on_terminated(), rc_filename, show_web_view_cb(), view_create(), view_full_screen(), view_open_emall(), view_open_uri(), view_set_text(), WARNPRINTF, web_settings, and zoom_step.
00245 { 00246 GError *error = NULL; 00247 GOptionContext *context = NULL; 00248 gboolean start_fullscreen = FALSE; 00249 gint start_zoom = 100; 00250 gboolean hide_navbar = FALSE; 00251 gboolean hide_scrollbar = FALSE; 00252 gboolean embedded_mode = FALSE; 00253 gchar *application = NULL; 00254 gchar **args = NULL; 00255 struct sigaction action; 00256 00257 GOptionEntry entries[] = 00258 { 00259 { "fullscreen", 'f', 0, G_OPTION_ARG_NONE, &start_fullscreen, "Start browser fullscreen", NULL }, 00260 { "zoom", 'z', 0, G_OPTION_ARG_INT, &start_zoom, "Zoom factor in percent ", NULL }, 00261 { "no-navbar", 'n', 0, G_OPTION_ARG_NONE, &hide_navbar, "Don't show navigation bar", NULL }, 00262 { "no-scrollbars", 's', 0, G_OPTION_ARG_NONE, &hide_scrollbar, "Don't show scroll bars", NULL }, 00263 { "emall", 'm', 0, G_OPTION_ARG_NONE, &g_run_emall, "Open browser with eMall", NULL }, 00264 { "embedded", 'e', 0, G_OPTION_ARG_STRING, &application, "Start browser from other application", 00265 "Application name which launch the browser" }, 00266 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &args, NULL, "[URI]"}, 00267 { NULL, 0, 0, 0, NULL, NULL, NULL } 00268 }; 00269 00270 // catch the SIGTERM signal 00271 memset(&action, 0x00, sizeof(action)); 00272 action.sa_handler = on_terminated; 00273 sigaction(SIGTERM, &action, NULL); 00274 #if LOGGING_ON 00275 sigaction(SIGINT, &action, NULL); 00276 #endif 00277 00278 // Catch the SIGSEGV 00279 memset(&action, 0x00, sizeof(action)); 00280 action.sa_handler = on_segment_fault; 00281 sigaction(SIGSEGV, &action, NULL); 00282 00283 // Catch the SIGFPE 00284 memset(&action, 0x00, sizeof(action)); 00285 action.sa_handler = on_fpe; 00286 sigaction(SIGFPE, &action, NULL); 00287 00288 // init domain for translations 00289 textdomain(GETTEXT_PACKAGE); 00290 00291 // init glib and threading 00292 g_type_init(); 00293 g_thread_init(NULL); 00294 00295 // parse commandline arguments 00296 context = g_option_context_new("- list URIs to open in browser"); 00297 g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); 00298 g_option_context_add_group(context, gtk_get_option_group(TRUE)); 00299 if (!g_option_context_parse(context, &argc, &argv, &error)) 00300 { 00301 WARNPRINTF("Error parsing arguments: %s", error->message); 00302 g_error_free(error); 00303 g_option_context_free(context); 00304 return 1; 00305 } 00306 g_option_context_free(context); 00307 00308 // init rc files 00309 gchar** files = gtk_rc_get_default_files(); 00310 while( *files ) 00311 { 00312 LOGPRINTF("gtk_rc_get_default_files [%s]", *files); 00313 files++; 00314 } 00315 00316 // open the RC file associated with this program 00317 LOGPRINTF("gtk_rc_parse [%s]", rc_filename); 00318 gtk_rc_parse(rc_filename); 00319 00320 // init modules 00321 ipc_set_services(on_connect, on_disconnect, on_locale); 00322 menu_init(); 00323 00324 // setup persistent cookie jar 00325 SoupSession *session = webkit_get_default_session(); 00326 SoupCookieJar *jar = soup_cookie_jar_text_new(COOKIES_FILE, FALSE); 00327 soup_session_add_feature(session, SOUP_SESSION_FEATURE(jar)); 00328 g_object_unref(jar); 00329 00330 // create web view 00331 BrowserWindow *window = view_create(); 00332 g_main_window = window->window; 00333 00334 // set global settings 00335 web_settings = webkit_web_settings_new(); 00336 00337 // add package name to built-in user-agent string 00338 gchar *user_agent = NULL; 00339 g_object_get(G_OBJECT(web_settings), "user-agent", &user_agent, NULL); 00340 user_agent = g_strconcat(user_agent, " ", PACKAGE_NAME, "/", PACKAGE_VERSION, NULL); 00341 LOGPRINTF("user agent [%s]", user_agent); 00342 00343 g_object_set(G_OBJECT(web_settings), 00344 "resizable-text-areas", FALSE, 00345 "user-stylesheet-uri", css_uri, 00346 "zoom-step", zoom_step, 00347 "minimum-font-size", 8, 00348 "minimum-logical-font-size", 8, 00349 "user-agent", user_agent, 00350 NULL); 00351 00352 webkit_web_view_set_settings (WEBKIT_WEB_VIEW (window->web_view), web_settings); 00353 g_free(user_agent); 00354 00355 // set window settings 00356 if (g_run_emall) 00357 { 00358 hide_navbar = TRUE; 00359 } 00360 00361 if (application) 00362 { 00363 embedded_mode = TRUE; 00364 hide_navbar = TRUE; 00365 } 00366 00367 g_object_set_data(G_OBJECT(window->back_listview), "embedded-mode", (gpointer)embedded_mode); 00368 g_object_set_data(G_OBJECT(window->back_listview), "application", g_strdup(application)); 00369 g_object_set(G_OBJECT(webkit_web_view_get_window_features(WEBKIT_WEB_VIEW(window->web_view))), 00370 "toolbar-visible", g_run_emall, NULL); 00371 00372 if (hide_navbar) 00373 { 00374 g_object_set(G_OBJECT(webkit_web_view_get_window_features(WEBKIT_WEB_VIEW(window->web_view))), 00375 "locationbar-visible", FALSE, 00376 "statusbar-visible", FALSE, 00377 NULL); 00378 } 00379 00380 if (hide_scrollbar) 00381 { 00382 g_object_set(G_OBJECT(webkit_web_view_get_window_features(WEBKIT_WEB_VIEW(window->web_view))), 00383 "scrollbar-visible", FALSE, 00384 NULL); 00385 } 00386 00387 if (start_fullscreen) 00388 { 00389 menu_set_full_screen(TRUE); 00390 view_full_screen(TRUE); 00391 } 00392 00393 display_gain_control(); 00394 00395 // show browser window 00396 view_set_text(); 00397 show_web_view_cb(window, WEBKIT_WEB_VIEW(window->web_view)); 00398 gtk_widget_show(g_main_window); 00399 00400 ipc_sys_startup_complete(); 00401 00402 // open url 00403 if (g_run_emall) 00404 { 00405 view_open_emall(); 00406 } 00407 else 00408 { 00409 gchar *uri = NULL; 00410 LOGPRINTF("opening URL: %s", uri); 00411 uri = g_strdup((gchar *) (args ? args[0] : "http://www.google.com/")); 00412 view_open_uri(uri); 00413 g_free(uri); 00414 } 00415 00416 // run the main loop 00417 LOGPRINTF("before gtk_main"); 00418 gdk_threads_enter(); 00419 gtk_main(); 00420 gdk_threads_leave(); 00421 LOGPRINTF("after gtk_main"); 00422 00423 // clean up 00424 ipc_sys_disconnect(); 00425 g_object_unref(web_settings); 00426 00427 return 0; 00428 }
void main_quit | ( | void | ) |
Definition at line 93 of file erbrowser/src/main.c.
References LOGPRINTF, menu_destroy(), and view_destroy().
00094 { 00095 LOGPRINTF("entry"); 00096 00097 view_destroy(); 00098 menu_destroy(); 00099 00100 gtk_main_quit(); 00101 }
gboolean main_request_connection | ( | void | ) |
Definition at line 134 of file erbrowser/src/main.c.
References g_is_connection_requested, ipc_sys_connect(), LOGPRINTF, and WARNPRINTF.
Referenced by navigation_requested_cb().
00135 { 00136 LOGPRINTF("entry"); 00137 00138 if ( !g_is_connection_requested ) 00139 { 00140 #if MACHINE_IS_DR1000SW || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW 00141 if (ipc_sys_connect()) 00142 { 00143 g_is_connection_requested = TRUE; 00144 return TRUE; 00145 } 00146 #else 00147 WARNPRINTF("Connection requested, but device has no wireless capabilities"); 00148 #endif 00149 } 00150 00151 return FALSE; 00152 }
static void on_connect | ( | ) | [static] |
Definition at line 113 of file erbrowser/src/main.c.
References LOGPRINTF, and view_open_last().
Referenced by main().
00114 { 00115 LOGPRINTF("entry"); 00116 00117 view_open_last(); 00118 }
static void on_disconnect | ( | ) | [static] |
Definition at line 121 of file erbrowser/src/main.c.
References g_is_connection_requested, g_run_emall, LOGPRINTF, main_quit(), and view_is_page_loaded().
Referenced by main().
00122 { 00123 LOGPRINTF("entry"); 00124 00125 if ( g_run_emall || !view_is_page_loaded() ) 00126 { 00127 main_quit(); 00128 } 00129 00130 g_is_connection_requested = FALSE; 00131 }
static void on_fpe | ( | int | signo | ) | [static] |
Definition at line 170 of file erbrowser/src/main.c.
References UNUSED, and WARNPRINTF.
Referenced by main().
00171 { 00172 UNUSED(signo); 00173 WARNPRINTF(" -- entry " PACKAGE_NAME ", my pid [%d]", getpid()); 00174 exit(EXIT_FAILURE); 00175 }
static void on_locale | ( | ) | [static] |
Definition at line 104 of file erbrowser/src/main.c.
References LOGPRINTF, menu_set_text(), and view_set_text().
Referenced by main().
00105 { 00106 LOGPRINTF("entry"); 00107 00108 menu_set_text(); 00109 view_set_text(); 00110 }
static void on_segment_fault | ( | int | signo | ) | [static] |
Definition at line 163 of file erbrowser/src/main.c.
References UNUSED, and WARNPRINTF.
Referenced by main().
00164 { 00165 UNUSED(signo); 00166 WARNPRINTF(" -- entry " PACKAGE_NAME ", my pid [%d]", getpid()); 00167 exit(EXIT_FAILURE); 00168 }
static void on_terminated | ( | int | signo | ) | [static] |
Definition at line 156 of file erbrowser/src/main.c.
References main_quit(), UNUSED, and WARNPRINTF.
Referenced by main().
00157 { 00158 UNUSED(signo); 00159 WARNPRINTF(" -- entry " PACKAGE_NAME ", my pid [%d]", getpid()); 00160 main_quit(); 00161 }
static gboolean show_web_view_cb | ( | BrowserWindow * | window, | |
WebKitWebView * | web_view | |||
) | [static] |
Definition at line 178 of file erbrowser/src/main.c.
References LOGPRINTF, and UNUSED.
Referenced by main().
00179 { 00180 UNUSED(web_view); 00181 LOGPRINTF("entry"); 00182 00183 gboolean embedded_mode = FALSE; 00184 gboolean locationbar_visible; 00185 gboolean toolbar_visible; 00186 gboolean statusbar_visible; 00187 gboolean scrollbar_visible; 00188 gint width; 00189 gint height; 00190 GtkPolicyType scrollbar_policy; 00191 00192 embedded_mode = (gboolean)g_object_get_data(G_OBJECT(window->back_listview), "embedded-mode"); 00193 g_object_get(G_OBJECT(webkit_web_view_get_window_features(WEBKIT_WEB_VIEW(window->web_view))), 00194 "locationbar-visible", &locationbar_visible, 00195 "toolbar-visible", &toolbar_visible, 00196 "statusbar-visible", &statusbar_visible, 00197 "scrollbar-visible", &scrollbar_visible, 00198 "width", &width, 00199 "height", &height, 00200 NULL); 00201 00202 gtk_window_set_default_size(GTK_WINDOW(window->window), 00203 width != -1 ? width : 1024, 00204 height != -1 ? height : 1280); 00205 00206 if (scrollbar_visible) 00207 { 00208 scrollbar_policy = GTK_POLICY_AUTOMATIC; 00209 } 00210 else 00211 { 00212 scrollbar_policy = GTK_POLICY_NEVER; 00213 } 00214 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(window->scrolled_window), 00215 scrollbar_policy, scrollbar_policy); 00216 00217 gtk_widget_show(window->vbox); 00218 if (embedded_mode) 00219 { 00220 gtk_widget_show(window->back_listview); 00221 } 00222 00223 if (locationbar_visible) 00224 { 00225 gtk_widget_show_all(window->locationbar); 00226 } 00227 00228 if (toolbar_visible) 00229 { 00230 gtk_widget_show_all(window->toolbar); 00231 // initially hide emall home button 00232 GtkWidget *item = gtk_bin_get_child(GTK_BIN(gtk_toolbar_get_nth_item(GTK_TOOLBAR(window->toolbar), 2))); 00233 gtk_widget_hide(item); 00234 } 00235 00236 gtk_widget_show_all(window->scrolled_window); 00237 00238 return TRUE; 00239 }
const gchar* css_uri = "file://" DATADIR "/" PACKAGE_NAME ".css" [static] |
Definition at line 72 of file erbrowser/src/main.c.
Referenced by main().
gboolean g_is_connection_requested = FALSE [static] |
Definition at line 80 of file erbrowser/src/main.c.
Referenced by main_request_connection(), and on_disconnect().
gboolean g_run_emall = FALSE [static] |
Definition at line 81 of file erbrowser/src/main.c.
Referenced by main(), and on_disconnect().
const gchar* rc_filename = DATADIR "/" PACKAGE_NAME ".rc" [static] |
Definition at line 71 of file erbrowser/src/main.c.
Referenced by main().
WebKitWebSettings* web_settings = NULL [static] |
Definition at line 79 of file erbrowser/src/main.c.
Referenced by main().
const gfloat zoom_step = 0.20f [static] |
Definition at line 70 of file erbrowser/src/main.c.
Referenced by main().