2010-08-12 13:08:35 -07:00
/*
* eve
*
* Copyright ( C ) 2009 , Gustavo Sverzut Barbieri < barbieri @ profusion . mobi >
*
* License LGPL - 3 , see COPYING file at project folder .
*/
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
# include <Elementary.h>
# ifndef ELM_LIB_QUICKLAUNCH
2010-09-13 15:34:19 -07:00
# include "prefs.h"
2010-08-12 13:08:35 -07:00
# include "favorite.h"
# include "private.h"
# include <Ecore_Getopt.h>
# include <Ecore_File.h>
# include <stdlib.h>
# include "gettext.h"
int _log_domain = - 1 ;
Fav * fav = NULL ;
Hist * hist = NULL ;
2010-09-13 15:34:19 -07:00
Prefs * prefs = NULL ;
2010-08-12 13:08:35 -07:00
App app ;
static void
2010-08-27 10:51:04 -07:00
del_win ( App * app , Evas_Object * win )
2010-08-12 13:08:35 -07:00
{
Browser_Window * win_data ;
Eina_List * l ;
EINA_LIST_FOREACH ( app - > windows , l , win_data ) if ( win_data - > win = = win )
break ;
evas_object_del ( win ) ;
app - > windows = eina_list_remove ( app - > windows , win_data ) ;
free ( win_data ) ;
if ( ! app - > windows )
elm_exit ( ) ;
}
static void
2010-08-27 10:51:04 -07:00
on_win_del_req ( void * data , Evas_Object * win , void * event_info __UNUSED__ )
2010-08-12 13:08:35 -07:00
{
del_win ( data , win ) ;
}
2010-09-13 15:34:36 -07:00
void
window_mouse_enabled_set ( Evas_Object * win , Eina_Bool setting )
2010-08-12 13:08:35 -07:00
{
2010-09-13 15:34:36 -07:00
if ( ! setting )
{
Evas * e = evas_object_evas_get ( win ) ;
Ecore_Evas * ee = evas_data_attach_get ( e ) ;
Evas_Object * cursor = evas_object_rectangle_add ( e ) ;
evas_object_color_set ( cursor , 0 , 0 , 0 , 0 ) ;
evas_object_resize ( cursor , 1 , 1 ) ;
ecore_evas_object_cursor_set ( ee , cursor , EVAS_LAYER_MIN , 0 , 0 ) ;
}
else
{
/* FIXME Add the default cursor? */
}
2010-08-12 13:08:35 -07:00
}
Eina_Bool
2010-08-27 10:51:04 -07:00
tab_add ( Browser_Window * win , const char * url )
2010-08-12 13:08:35 -07:00
{
Evas_Object * chrome = chrome_add ( win , url ) ;
if ( ! chrome )
{
2010-08-27 10:51:04 -07:00
CRITICAL ( " Could not create chrome. " ) ;
goto error_chrome_create ;
2010-08-12 13:08:35 -07:00
}
2010-08-27 10:51:04 -07:00
2010-08-12 13:08:35 -07:00
evas_object_size_hint_weight_set ( chrome , EVAS_HINT_EXPAND , EVAS_HINT_EXPAND ) ;
evas_object_show ( chrome ) ;
win - > chromes = eina_list_append ( win - > chromes , chrome ) ;
win - > current_chrome = chrome ;
win - > current_view = evas_object_data_get ( chrome , " view " ) ;
win - > current_tab + + ;
return EINA_TRUE ;
2010-08-27 10:51:04 -07:00
error_chrome_create :
2010-08-12 13:08:35 -07:00
evas_object_del ( evas_object_data_get ( chrome , " view " ) ) ;
return EINA_FALSE ;
}
Eina_Bool
2010-08-27 10:51:04 -07:00
tab_focus_chrome ( Browser_Window * win , Evas_Object * chrome )
2010-08-12 13:08:35 -07:00
{
Eina_List * itr ;
int n ;
if ( ! chrome )
return EINA_FALSE ;
2010-08-27 10:51:04 -07:00
for ( n = 0 , itr = win - > chromes ; itr - > data ! = chrome ; n + + , itr = itr - > next ) ;
2010-08-12 13:08:35 -07:00
evas_object_hide ( win - > current_chrome ) ;
win - > current_chrome = chrome ;
win - > current_view = evas_object_data_get ( chrome , " view " ) ;
win - > current_tab = n ;
2010-08-27 10:51:04 -07:00
2010-08-12 13:08:35 -07:00
evas_object_show ( win - > current_chrome ) ;
evas_object_focus_set ( win - > current_view , EINA_TRUE ) ;
elm_pager_content_promote ( win - > pager , win - > current_chrome ) ;
2010-09-07 09:59:40 -07:00
chrome_focused_notify ( win - > current_chrome ) ;
2010-08-12 13:08:35 -07:00
return EINA_TRUE ;
}
Eina_Bool
2010-08-27 10:51:04 -07:00
tab_focus_nth ( Browser_Window * win , unsigned int n )
2010-08-12 13:08:35 -07:00
{
return tab_focus_chrome ( win , eina_list_nth ( win - > chromes , n ) ) ;
}
Eina_Bool
2010-08-27 10:51:04 -07:00
tab_focus_next ( Browser_Window * win )
2010-08-12 13:08:35 -07:00
{
unsigned int n_tabs = eina_list_count ( win - > chromes ) ;
if ( win - > current_tab > n_tabs )
return EINA_FALSE ;
2010-08-27 10:51:04 -07:00
2010-08-12 13:08:35 -07:00
return tab_focus_nth ( win , win - > current_tab + 1 ) ;
}
Eina_Bool
2010-08-27 10:51:04 -07:00
tab_focus_prev ( Browser_Window * win )
2010-08-12 13:08:35 -07:00
{
if ( win - > current_tab = = 0 )
return EINA_FALSE ;
2010-08-27 10:51:04 -07:00
2010-08-12 13:08:35 -07:00
return tab_focus_nth ( win , win - > current_tab - 1 ) ;
}
Eina_Bool
2010-08-27 10:51:04 -07:00
tab_close_chrome ( Browser_Window * win , Evas_Object * chrome )
2010-08-12 13:08:35 -07:00
{
Evas_Object * edje ;
2010-08-27 10:51:04 -07:00
2010-08-12 13:08:35 -07:00
EINA_SAFETY_ON_TRUE_RETURN_VAL ( ! win , EINA_FALSE ) ;
EINA_SAFETY_ON_TRUE_RETURN_VAL ( ! chrome , EINA_FALSE ) ;
2010-08-27 10:51:04 -07:00
2010-09-07 09:11:55 -07:00
evas_object_del ( chrome ) ;
win - > chromes = eina_list_remove ( win - > chromes , chrome ) ;
if ( ! win - > chromes )
2010-08-27 10:51:04 -07:00
{
del_win ( win - > app , win - > win ) ;
return EINA_TRUE ;
}
2010-08-12 13:08:35 -07:00
if ( win - > current_chrome = = chrome )
tab_focus_nth ( win , 0 ) ;
edje = elm_layout_edje_get ( win - > current_chrome ) ;
edje_object_signal_emit ( edje , " hide,tab " , " " ) ;
return EINA_TRUE ;
}
Eina_Bool
2010-08-27 10:51:04 -07:00
tab_close_nth ( Browser_Window * win , int n )
2010-08-12 13:08:35 -07:00
{
return tab_close_chrome ( win , eina_list_nth ( win - > chromes , n ) ) ;
}
Eina_Bool
2010-08-27 10:51:04 -07:00
tab_close_view ( Browser_Window * win , Evas_Object * view )
2010-08-12 13:08:35 -07:00
{
return tab_close_chrome ( win , evas_object_data_get ( view , " chrome " ) ) ;
}
static Browser_Window *
2010-08-27 10:51:04 -07:00
add_win ( App * app , const char * url )
2010-08-12 13:08:35 -07:00
{
Browser_Window * win = malloc ( sizeof ( * win ) ) ;
if ( ! win )
{
2010-08-27 10:51:04 -07:00
CRITICAL ( " Could not create window data. " ) ;
goto error_win_data ;
2010-08-12 13:08:35 -07:00
}
win - > app = app ;
win - > chromes = NULL ;
win - > current_chrome = NULL ;
win - > current_view = NULL ;
win - > current_tab = 0 ;
win - > list_history = NULL ;
win - > list_history_titles = NULL ;
win - > win = elm_win_add ( NULL , " eve " , ELM_WIN_BASIC ) ;
if ( ! win - > win )
{
2010-08-27 10:51:04 -07:00
CRITICAL ( " Could not create window. " ) ;
goto error_win_create ;
2010-08-12 13:08:35 -07:00
}
elm_win_title_set ( win - > win , PACKAGE_STRING ) ;
2010-08-13 12:15:04 -07:00
elm_win_rotation_set ( win - > win , app - > rotate ) ;
2010-08-12 13:08:35 -07:00
elm_win_fullscreen_set ( win - > win , app - > is_fullscreen ) ;
2010-09-13 15:34:36 -07:00
window_mouse_enabled_set ( win - > win , ! app - > disable_mouse ) ;
2010-08-12 13:08:35 -07:00
win - > bg = edje_object_add ( evas_object_evas_get ( win - > win ) ) ;
if ( ! win - > bg )
{
2010-08-27 10:51:04 -07:00
CRITICAL ( " Could not create background. " ) ;
goto error_bg_create ;
2010-08-12 13:08:35 -07:00
}
2010-08-27 10:51:04 -07:00
2010-08-12 13:08:35 -07:00
if ( ! edje_object_file_set ( win - > bg , PACKAGE_DATA_DIR " /default.edj " , " bg " ) )
{
2010-08-27 10:51:04 -07:00
int err = edje_object_load_error_get ( win - > bg ) ;
2010-08-12 13:08:35 -07:00
2010-08-27 10:51:04 -07:00
const char * msg = edje_load_error_str ( err ) ;
2010-08-12 13:08:35 -07:00
2010-08-27 10:51:04 -07:00
CRITICAL ( " Could not load background theme: %s " , msg ) ;
goto error_bg_theme_set ;
2010-08-12 13:08:35 -07:00
}
2010-08-27 10:51:04 -07:00
2010-08-12 13:08:35 -07:00
evas_object_size_hint_weight_set ( win - > bg , EVAS_HINT_EXPAND ,
2010-08-27 10:51:04 -07:00
EVAS_HINT_EXPAND ) ;
2010-08-12 13:08:35 -07:00
elm_win_resize_object_add ( win - > win , win - > bg ) ;
evas_object_layer_set ( win - > bg , EVAS_LAYER_MIN ) ;
evas_object_show ( win - > bg ) ;
2010-08-27 10:51:04 -07:00
2010-08-12 13:08:35 -07:00
win - > pager = elm_pager_add ( win - > win ) ;
if ( ! win - > pager )
2010-08-27 10:51:04 -07:00
{
CRITICAL ( " Could not create pager " ) ;
goto error_pager_create ;
}
2010-08-12 13:08:35 -07:00
elm_object_style_set ( win - > pager , " ewebkit " ) ;
evas_object_size_hint_weight_set ( win - > pager , EVAS_HINT_EXPAND ,
2010-08-27 10:51:04 -07:00
EVAS_HINT_EXPAND ) ;
2010-08-12 13:08:35 -07:00
elm_win_resize_object_add ( win - > win , win - > pager ) ;
evas_object_show ( win - > pager ) ;
if ( ! tab_add ( win , url ) )
goto error_tab_add ;
app - > windows = eina_list_append ( app - > windows , win ) ;
evas_object_smart_callback_add
( win - > win , " delete-request " , on_win_del_req , app ) ;
evas_object_resize ( win - > win , 480 , 800 ) ;
evas_object_show ( win - > win ) ;
return win ;
2010-08-27 10:51:04 -07:00
error_bg_theme_set :
2010-08-12 13:08:35 -07:00
evas_object_del ( win - > bg ) ;
2010-08-27 10:51:04 -07:00
error_bg_create :
2010-08-12 13:08:35 -07:00
evas_object_del ( win - > win ) ;
2010-08-27 10:51:04 -07:00
error_win_create :
2010-08-12 13:08:35 -07:00
free ( win ) ;
2010-08-27 10:51:04 -07:00
error_win_data :
error_tab_add :
error_pager_create :
2010-08-12 13:08:35 -07:00
return NULL ;
}
/**
* Creates a new window , without any url to load , calling add_win ( ) .
*
* @ return If a window was successfully created , it returns the correspondent view
* object .
*/
Evas_Object *
2010-09-07 09:59:40 -07:00
window_create ( void )
2010-08-12 13:08:35 -07:00
{
Browser_Window * win = add_win ( & app , NULL ) ;
if ( ! win )
return NULL ;
return win - > current_view ;
}
2010-09-07 09:59:40 -07:00
void
window_title_set ( Browser_Window * win , const char * title )
{
char buf [ 4096 ] ;
EINA_SAFETY_ON_NULL_RETURN ( win ) ;
if ( ! title )
{
elm_win_title_set ( win - > win , PACKAGE_STRING ) ;
return ;
}
snprintf ( buf , sizeof ( buf ) , " %s - %s " , title , PACKAGE_STRING ) ;
elm_win_title_set ( win - > win , buf ) ;
}
2010-09-02 15:28:35 -07:00
# define stringify(X) #X
2010-08-12 13:08:35 -07:00
static const Ecore_Getopt options = {
PACKAGE_NAME ,
" %prog [options] [url] " ,
2010-09-02 15:28:35 -07:00
PACKAGE_VERSION " Revision: " stringify ( VREV ) ,
" (C) 2010 ProFUSION embedded systems " ,
2010-08-12 13:08:35 -07:00
" LGPL-3 " ,
" WebKit-EFL demo browser for mobile systems with touchscreen. " ,
EINA_TRUE ,
{
2010-08-27 10:51:04 -07:00
ECORE_GETOPT_STORE_DEF_BOOL ( ' F ' , " fullscreen " , " start in fullscreen. " , 1 ) ,
ECORE_GETOPT_STORE_DEF_BOOL ( ' P ' , " disable-plugins " ,
" disable plugins (flash, etc). " , 1 ) ,
ECORE_GETOPT_STORE_DEF_BOOL ( ' M ' , " disable-mouse " ,
" disable mouse (hide it). " , 1 ) ,
ECORE_GETOPT_STORE_STR ( ' U ' , " user-agent " ,
2010-09-07 10:17:42 -07:00
" user agent string to use. Special cases=iphone,safari,chrome,firefox,ie,ie9,ie8,ie7. " ) ,
2010-08-27 10:51:04 -07:00
ECORE_GETOPT_STORE_DEF_UINT ( ' R ' , " rotate " , " Screen Rotation in degrees " , 0 ) ,
ECORE_GETOPT_VERSION ( ' V ' , " version " ) ,
ECORE_GETOPT_COPYRIGHT ( ' C ' , " copyright " ) ,
ECORE_GETOPT_LICENSE ( ' L ' , " license " ) ,
ECORE_GETOPT_HELP ( ' h ' , " help " ) ,
ECORE_GETOPT_SENTINEL
}
2010-08-12 13:08:35 -07:00
} ;
EAPI int
elm_main ( int argc , char * * argv )
{
int r = 0 , args ;
const char * home ;
const char * url ;
char path [ PATH_MAX ] ;
Eina_Bool quit_option = EINA_FALSE ;
char * user_agent = NULL ;
Ecore_Getopt_Value values [ ] = {
ECORE_GETOPT_VALUE_BOOL ( app . is_fullscreen ) ,
ECORE_GETOPT_VALUE_BOOL ( app . disable_plugins ) ,
ECORE_GETOPT_VALUE_BOOL ( app . disable_mouse ) ,
ECORE_GETOPT_VALUE_STR ( user_agent ) ,
2010-08-13 12:15:04 -07:00
ECORE_GETOPT_VALUE_UINT ( app . rotate ) ,
2010-08-12 13:08:35 -07:00
ECORE_GETOPT_VALUE_BOOL ( quit_option ) ,
ECORE_GETOPT_VALUE_BOOL ( quit_option ) ,
ECORE_GETOPT_VALUE_BOOL ( quit_option ) ,
ECORE_GETOPT_VALUE_BOOL ( quit_option ) ,
ECORE_GETOPT_VALUE_NONE
} ;
# if ENABLE_NLS
setlocale ( LC_ALL , " " ) ;
bindtextdomain ( GETTEXT_PACKAGE , LOCALEDIR ) ;
bind_textdomain_codeset ( GETTEXT_PACKAGE , " UTF-8 " ) ;
textdomain ( GETTEXT_PACKAGE ) ;
# endif
_log_domain = eina_log_domain_register ( " eve " , NULL ) ;
if ( _log_domain < 0 )
{
2010-08-27 10:51:04 -07:00
EINA_LOG_CRIT ( " could not create log domain 'eve'. " ) ;
return - 1 ;
2010-08-12 13:08:35 -07:00
}
args = ecore_getopt_parse ( & options , values , argc , argv ) ;
if ( args < 0 )
{
2010-08-27 10:51:04 -07:00
ERR ( " Could not parse command line options. " ) ;
return - 1 ;
2010-08-12 13:08:35 -07:00
}
if ( quit_option )
{
2010-08-27 10:51:04 -07:00
DBG ( " Command lines option requires quit. " ) ;
return 0 ;
2010-08-12 13:08:35 -07:00
}
2010-09-13 15:34:19 -07:00
if ( ! user_agent | | ( user_agent & & strcasecmp ( user_agent , " eve " ) ) )
2010-09-07 10:17:42 -07:00
user_agent = " Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 " PACKAGE_NAME " / " PACKAGE_VERSION ;
else
{
/* http://www.useragentstring.com/ */
if ( strcasecmp ( user_agent , " iphone " ) = = 0 )
user_agent = " Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 " ;
else if ( strcasecmp ( user_agent , " safari " ) = = 0 )
user_agent = " Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-US) AppleWebKit/533.17.8 (KHTML, like Gecko) Version/5.0.1 Safari/533.17.8 " ;
else if ( strcasecmp ( user_agent , " chrome " ) = = 0 )
user_agent = " Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.514.0 Safari/534.7 " ;
else if ( strcasecmp ( user_agent , " firefox " ) = = 0 )
user_agent = " Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.2) Gecko/20121223 Firefox/3.8 " ;
else if ( strcasecmp ( user_agent , " ie " ) = = 0 ) /* last */
user_agent = " Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US) " ;
else if ( strcasecmp ( user_agent , " ie9 " ) = = 0 )
user_agent = " Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US) " ;
else if ( strcasecmp ( user_agent , " ie8 " ) = = 0 )
user_agent = " Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322) " ;
else if ( strcasecmp ( user_agent , " ie7 " ) = = 0 )
user_agent = " Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0) " ;
}
2010-08-12 13:08:35 -07:00
app . user_agent = eina_stringshare_add ( user_agent ) ;
elm_theme_extension_add ( NULL , PACKAGE_DATA_DIR " /default.edj " ) ;
ewk_init ( ) ;
favorite_init ( ) ;
history_init ( ) ;
2010-09-13 15:34:19 -07:00
preferences_init ( ) ;
2010-08-12 13:08:35 -07:00
home = getenv ( " HOME " ) ;
if ( ! home | | ! home [ 0 ] )
{
2010-08-27 10:51:04 -07:00
CRITICAL ( " Could not get $HOME " ) ;
r = - 1 ;
goto end ;
2010-08-12 13:08:35 -07:00
}
snprintf ( path , sizeof ( path ) , " %s/.config/ewebkit " , home ) ;
if ( ! ecore_file_mkpath ( path ) )
{
2010-08-27 10:51:04 -07:00
ERR ( " Could not create %s " , path ) ;
r = - 1 ;
goto end ;
2010-08-12 13:08:35 -07:00
}
2010-08-27 10:51:04 -07:00
2010-08-12 13:08:35 -07:00
if ( ! ewk_settings_icon_database_path_set ( path ) )
{
2010-08-27 10:51:04 -07:00
ERR ( " Could not set icon database path to %s " , path ) ;
r = - 1 ;
goto end ;
2010-08-12 13:08:35 -07:00
}
snprintf ( path , sizeof ( path ) , " %s/.config/ewebkit/favorites.db " , home ) ;
fav = fav_load ( path ) ;
if ( ! fav )
{
2010-08-27 10:51:04 -07:00
fav = fav_new ( 0 ) ;
fav_save ( fav , path ) ;
2010-08-12 13:08:35 -07:00
}
snprintf ( path , sizeof ( path ) , " %s/.config/ewebkit/history.db " , home ) ;
hist = hist_load ( path ) ;
if ( ! hist )
{
2010-08-27 10:51:04 -07:00
hist = hist_new ( 0 ) ;
hist_save ( hist , path ) ;
2010-08-12 13:08:35 -07:00
}
2010-09-13 15:34:19 -07:00
snprintf ( path , sizeof ( path ) , " %s/.config/ewebkit/prefs.db " , home ) ;
prefs = prefs_load ( path ) ;
if ( ! prefs )
{
2010-09-13 15:34:42 -07:00
prefs = prefs_new ( EINA_TRUE , EINA_TRUE , EINA_FALSE ,
2010-09-13 15:34:39 -07:00
EINA_TRUE , " eve " , DEFAULT_URL , NULL ,
2010-09-13 15:34:42 -07:00
EINA_FALSE , EINA_TRUE , EINA_FALSE ,
EINA_TRUE ) ;
2010-09-13 15:34:19 -07:00
prefs_save ( prefs , path ) ;
}
if ( args < argc )
url = argv [ args ] ;
else
url = prefs_home_page_get ( prefs ) ;
2010-08-12 13:08:35 -07:00
if ( ! add_win ( & app , url ) )
{
2010-08-27 10:51:04 -07:00
r = - 1 ;
goto end ;
2010-08-12 13:08:35 -07:00
}
elm_run ( ) ;
2010-08-27 10:51:04 -07:00
end :
2010-08-12 13:08:35 -07:00
fav_save ( fav , NULL ) ;
fav_free ( fav ) ;
hist_save ( hist , NULL ) ;
hist_free ( hist ) ;
2010-09-13 15:34:19 -07:00
prefs_save ( prefs , NULL ) ;
prefs_free ( prefs ) ;
2010-08-12 13:08:35 -07:00
eina_stringshare_del ( app . user_agent ) ;
eina_log_domain_unregister ( _log_domain ) ;
_log_domain = - 1 ;
elm_shutdown ( ) ;
ewk_shutdown ( ) ;
favorite_shutdown ( ) ;
history_shutdown ( ) ;
2010-09-13 15:34:19 -07:00
preferences_shutdown ( ) ;
2010-08-12 13:08:35 -07:00
return r ;
}
2010-08-27 10:51:04 -07:00
2010-08-12 13:08:35 -07:00
# endif
ELM_MAIN ( )