viking

webkit based web browser for Enlightenment
Log | Files | Refs | LICENSE

commit eeb7f5cfd504718f6ee730a09a371bd9be149798
parent 3378961a00ec8fa78a1777efb315b4ca5984e5c5
Author: Kyle Milz <kmilz@ucalgary.ca>
Date:   Mon,  1 Oct 2012 16:14:18 -0600

switch to using ewebkit2 library

also remove main.h by moving structs into viking.h and moving main.c
functions into non main.c files

lots of functionality has been cut due to state of the efl webkit2 port.

Diffstat:
MMakefile | 3+++
Msrc/Makefile | 3++-
Msrc/callbacks.c | 210++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
Msrc/callbacks.h | 8++++++--
Msrc/commands.c | 134+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Msrc/commands.h | 1-
Msrc/main.c | 594+++++--------------------------------------------------------------------------
Dsrc/main.h | 113-------------------------------------------------------------------------------
Msrc/utilities.c | 501+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/utilities.h | 10++++++++++
Msrc/viking.h | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11 files changed, 853 insertions(+), 806 deletions(-)

diff --git a/Makefile b/Makefile @@ -4,3 +4,6 @@ all: clean: cd src; make clean + +install: + cd src; make install diff --git a/src/Makefile b/src/Makefile @@ -6,7 +6,7 @@ OBJ = main.o utilities.o commands.o jsmn.o viking_state.o callbacks.o MAN1 = evi2.1 MAN5 = evirc.5 # Used libraries to get needed CFLAGS and LDFLAGS form pkg-config -LIBS = elementary ewebkit +LIBS = elementary ewebkit2 # Files to removo by clean target CLEAN = $(TARGET) $(OBJ) $(DEPS) javascript.h # Files to install by install target or remove by uninstall target @@ -19,6 +19,7 @@ V_DEBUG = 1 CFLAGS += `pkg-config --cflags $(LIBS)` LDFLAGS += `pkg-config --libs $(LIBS)` +# LDFLAGS += `pkg-config --libs $(LIBS) | sed -e "s/-lewebkit //g" -` # TA: This is a pretty stringent list of warnings to bail on! ifeq ($(V_DEBUG),1) diff --git a/src/callbacks.c b/src/callbacks.c @@ -1,10 +1,10 @@ #include <Elementary.h> -#include <EWebKit.h> +#include <EWebKit2.h> +#include <libsoup/soup.h> -#include "viking.h" #include "viking_state.h" -#include "main.h" +#include "viking.h" #include "utilities.h" #include "javascript.h" #include "commands.h" @@ -23,26 +23,33 @@ int download_progress_cb(void*, const char*, long int, long int, long int, long void webview_title_changed_cb(void *data, Evas_Object *obj, void *event_info) { - /* - const char *title = ""; - Ewk_Text_With_Direction *dir_text = event_info; - if (event_info) title = dir_text->string; - char buf[20] = ""; + Buffer_Data *bd = data; + Window_Data *wd = bd->window; + const char *title = event_info; + char buf[128] = ""; if (title) strncpy(buf, title, sizeof(buf) - 1); - elm_object_item_text_set(td->tab, buf); - */ + + elm_win_title_set(wd->win, buf); } void webview_progress_changed_cb(void *data, Evas_Object *obj, void *event_info) { Buffer_Data *td = data; - /* *event_info is a double between 0.0 and 1.0 */ - update_state(td->window); -} + Window_Data *wd = td->window; + double *val = event_info; + + elm_progressbar_value_set(wd->progress_bar, *val); + /* + if (*val == 1.0) + evas_object_hide(wd->progress_bar); + else + evas_object_show(wd->progress_bar); + */ +} void protocol_register_cb(void *data, Evas_Object *obj, void *event_info) @@ -53,6 +60,7 @@ protocol_register_cb(void *data, Evas_Object *obj, void *event_info) void load_error_cb(void *data, Evas_Object *obj, void *event_info) { + /* char *contents; Ewk_Frame_Load_Error *error = event_info; @@ -72,12 +80,14 @@ load_error_cb(void *data, Evas_Object *obj, void *event_info) ewk_frame_contents_set(error->frame, contents, strlen(contents) - 1, "text/html", "UTF-8", NULL); - free(contents); + free(contents);\ + */ } void webview_inspector_cb(void *data, Evas_Object *obj, void *event_info) { + /* Buffer_Data *bd = data; Window_Data *wd = bd->window; @@ -94,11 +104,13 @@ webview_inspector_cb(void *data, Evas_Object *obj, void *event_info) evas_object_size_hint_weight_set(wd->web_inspector, EVAS_HINT_EXPAND, 0.66); evas_object_show(wd->web_inspector); + */ } void webview_inspector_close_cb(void *data, Evas_Object *obj, void *event_info) { + /* Buffer_Data *bd = data; Window_Data *wd = bd->window; @@ -107,6 +119,7 @@ webview_inspector_close_cb(void *data, Evas_Object *obj, void *event_info) ewk_view_web_inspector_view_set(bd->view, NULL); bd->web_inspector = NULL; + */ } void @@ -125,6 +138,7 @@ webview_uri_changed_cb(void *data, Evas_Object *obj, void *event_info) script(&a, bd->window); free(a.s); + /* Evas_Object *frame = ewk_view_frame_main_get(bd->view); FILE *fp = fopen("/home/kyle/.config/viking/userscript/adblockplus/contentScript1.js", "r"); if (!fp) @@ -139,7 +153,6 @@ webview_uri_changed_cb(void *data, Evas_Object *obj, void *event_info) printf("uri_changed() executed %i byte script %s\n", len, "contentScript1.js"); free(buf); - /* Evas_Object *frame = ewk_view_frame_main_get(td->view); char *scripts[15] = { "tampermonkey/src/emulation.js", @@ -188,32 +201,6 @@ webview_uri_changed_cb(void *data, Evas_Object *obj, void *event_info) update_url(uri, bd->window); } -void -webview_document_finished_cb(void *data, Evas_Object *obj, void *event_info) -{ - Hist_Item *item; - Buffer_Data *bd = data; - App_Data *ad = bd->window->app; - Evas_Object *frame = event_info; - const Ewk_Text_With_Direction *txt = ewk_frame_title_get(frame); - const char *url = ewk_frame_uri_get(frame); - const char *title = (txt ? txt->string : ""); - - if (!bd->history_enabled) - return; - - // printf("logging item to history.\n"); - - if ((item = hist_items_get(ad->history, url))) { - hist_item_visit_count_set(item, hist_item_visit_count_get(item) + 1); - hist_item_last_visit_set(item, ecore_time_unix_get()); - hist_item_title_set(item, title); - } - else { - hist_items_add(ad->history, url, hist_item_new(title, url, 1, ecore_time_unix_get())); - } -} - static Eina_Bool escape_input_on_load = TRUE; /* TRUE will disable automatic focusing of input fields via Javascript*/ void @@ -223,12 +210,12 @@ webview_load_finished_cb(void *data, Evas_Object *obj, void *event_info) Buffer_Data *bd = data; Window_Data *wd = bd->window; Eina_Bool scripts = 1; - Elm_Web_Frame_Load_Error *frame_error = event_info; + // Ewk_Frame_Load_Error *frame_error = event_info; - // printf("load_finished()\n"); + printf("load_finished()\n"); - if (frame_error) - return; + // if (frame_error) + // return; /* g_object_get(settings, "enable-scripts", &scripts, NULL); */ if (escape_input_on_load && scripts && !wd->manual_focus && !elm_object_focus_get(wd->url)) { @@ -242,8 +229,31 @@ webview_load_finished_cb(void *data, Evas_Object *obj, void *event_info) update_state(wd); + Hist_Item *item; + // Buffer_Data *bd = data; + App_Data *ad = wd->app; + // Evas_Object *frame = event_info; + const char *title = ewk_view_title_get(bd->view); + + if (!bd->history_enabled) + return; + + // printf("logging item to history.\n"); + + const char *url = ewk_view_uri_get(bd->view); + if ((item = hist_items_get(ad->history, url))) { + hist_item_visit_count_set(item, hist_item_visit_count_get(item) + 1); + hist_item_last_visit_set(item, ecore_time_unix_get()); + hist_item_title_set(item, title); + } + else { + hist_items_add(ad->history, url, hist_item_new(title, url, 1, ecore_time_unix_get())); + } + + // userscript_hooks_end(elm_web_uri_get(td->web)); + /* Evas_Object *frame = ewk_view_frame_main_get(bd->view); FILE *fp = fopen("/home/kyle/.config/viking/userscript/adblockplus/contentScript2.js", "r"); if (!fp) @@ -257,6 +267,7 @@ webview_load_finished_cb(void *data, Evas_Object *obj, void *event_info) ewk_frame_script_execute(frame, buf); printf("load_finished() executed %i byte script\n", len); free(buf); + */ // elm_object_focus_set(td->web, EINA_TRUE); } @@ -307,12 +318,6 @@ webview_mimetype_cb(WebKitWebView *webview, WebKitWebFrame *frame, WebKitNetwork */ void -download_entry_free_cb(void *data) -{ - free(data); -} - -void download_complete_cb(void *data, const char *file, int status) { Window_Data *wd = data; @@ -352,6 +357,7 @@ download_progress_cb(void *data, const char *file, long int dltotal, long int dl void webview_download_cb(void *data, Evas_Object *obj, void *event_info) { + /* Eina_Bool ret; Buffer_Data *bd = data; Window_Data *wd = bd->window; @@ -365,7 +371,7 @@ webview_download_cb(void *data, Evas_Object *obj, void *event_info) ret = ecore_file_download(dl->url, full_path, download_complete_cb, download_progress_cb, wd, NULL); - /* if file already exists, ret == NULL */ + // if file already exists, ret == NULL if (!ret) { Arg a; a.i = Info; @@ -382,6 +388,7 @@ webview_download_cb(void *data, Evas_Object *obj, void *event_info) free(suggested_name); // update_state(ad); + */ } @@ -408,6 +415,9 @@ process_keypress(void *event_info, void *data) // gdk_keymap_translate_keyboard_state(keymap, event->hardware_keycode, // event->state, event->group, &keyval, NULL, NULL, &irrelevant); + //if (elm_object_focus_get(wd->url)) + // return EINA_FALSE; + walk = ad->keylistroot; while (walk != NULL) { key = walk->Element; @@ -422,11 +432,37 @@ process_keypress(void *event_info, void *data) // printf("process_keypress() function for mask = %s modkey = %c key = %s called.\n", key.mask, ad->current_modkey, key.key); wd->current_modkey = wd->count = 0; update_state(data); - return TRUE; + return EINA_TRUE; } walk = walk->next; } - return FALSE; + return EINA_FALSE; +} + +void +webview_focus_in_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + /* + printf("webview_focus_in()\n"); + Buffer_Data *bd = data; + Window_Data *wd = bd->window; + + evas_object_focus_set(bd->view, EINA_TRUE); + elm_win_keyboard_mode_set(wd->win, ELM_WIN_KEYBOARD_ON); + */ +} + +void +webview_focus_out_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + /* + printf("webview_focus_out()\n"); + Buffer_Data *bd = data; + Window_Data *wd = bd->window; + + evas_object_focus_set(bd->view, EINA_FALSE); + elm_win_keyboard_mode_set(wd->win, ELM_WIN_KEYBOARD_OFF); + */ } void @@ -471,7 +507,7 @@ webview_keypress_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) } // } /* keybindings */ - if (process_keypress(event_info, wd) == TRUE) return; + if (process_keypress(event_info, wd) == EINA_TRUE) return; break; case ModeInsert: @@ -515,7 +551,7 @@ void webview_hoverlink_cb(void *data, Evas_Object *obj, void *event_info) { Buffer_Data *td = data; - const char *uri = elm_web_uri_get(td->web); + const char *uri = ewk_view_uri_get(td->view); /* event_info is a char *link[2] where the first string contains the URL * and the second the title of the link */ char **link = event_info; @@ -538,7 +574,7 @@ void webview_hoverlink_out_cb(void *data, Evas_Object *obj, void *event_info) { Buffer_Data *td = data; - update_url(elm_web_uri_get(td->web), td->window); + update_url(ewk_view_uri_get(td->view), td->window); } void @@ -583,11 +619,11 @@ inputbox_activate_cb(void *data, Evas_Object *obj, void *event_info) process_line((text + 1), data); } else if (length > 1 && ((forward = text[0] == '/') || text[0] == '?')) { // webkit_web_view_unmark_text_matches(webview); - elm_web_text_matches_unmark_all(wd->cur_buf->web); + // ewk_view_text_matches_unmark_all(wd->cur_buf->view); // webkit_web_view_mark_text_matches(webview, &text[1], FALSE, 0); // webkit_web_view_set_highlight_text_matches(webview, TRUE); - elm_web_text_matches_mark(wd->cur_buf->web, &text[1], EINA_FALSE, EINA_TRUE, 0); + // ewk_view_text_matches_mark(wd->cur_buf->view, &text[1], EINA_FALSE, EINA_TRUE, 0); wd->count = 0; wd->search_direction = forward; @@ -606,8 +642,9 @@ inputbox_activate_cb(void *data, Evas_Object *obj, void *event_info) // gtk_widget_grab_focus(GTK_WIDGET(webview)); /* process_line above may have deleted the tab, check if its still around */ - if (wd->cur_buf->web) - elm_object_focus_set(wd->cur_buf->web, EINA_TRUE); + if (wd->cur_buf->view) + evas_object_focus_set(wd->cur_buf->view, EINA_TRUE); + // elm_object_focus_set(wd->cur_buf->view, EINA_TRUE); } static Eina_Bool @@ -768,11 +805,13 @@ inputbox_keypress_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) void inputmethod_changed_cb(void *data, Evas_Object *obj, void *event_info) { - const char *value; + const char *value = NULL; Eina_Bool *enabled = event_info; Buffer_Data *bd = data; Window_Data *wd = bd->window; - Evas_Object *frame = ewk_view_frame_main_get(bd->view); + // Evas_Object *frame = ewk_view_frame_main_get(bd->view); + + printf("inputmethod_changed()\n"); if (wd->mode == ModeNormal && enabled) { Arg a = { .i = ModeInsert }; @@ -784,7 +823,7 @@ inputmethod_changed_cb(void *data, Evas_Object *obj, void *event_info) } else { // char *value = NULL, *message = NULL; // jsapi_evaluate_script("window.getSelection().focusNode", &value, &message, ad); - value = ewk_frame_script_execute(frame, "window.getSelection().focusNode"); + // value = ewk_frame_script_execute(frame, "window.getSelection().focusNode"); if (value && !strcmp(value, "[object HTMLFormElement]")) { Arg a = { .i = ModeInsert, .s = NULL }; set(&a, wd); @@ -912,10 +951,10 @@ inputbox_changed_cb(void *data, Evas_Object *obj, void *event_info) // if (gtk_widget_is_focus(GTK_WIDGET(entry)) && length > 1 && ((forward = text[0] == '/') || text[0] == '?')) { if (elm_object_focus_get(wd->url) && length > 1 && ((forward = text[0] == '/') || text[0] == '?')) { // webkit_web_view_unmark_text_matches(webview); - elm_web_text_matches_unmark_all(wd->cur_buf->web); + // ewk_view_text_matches_unmark_all(wd->cur_buf->view); // webkit_web_view_search_text(webview, &text[1], searchoptions & CaseSensitive, forward, searchoptions & Wrapping); - elm_web_text_search(wd->cur_buf->web, &text[1], EINA_TRUE, forward, EINA_FALSE); + // ewk_view_text_search(wd->cur_buf->view, &text[1], EINA_TRUE, forward, EINA_FALSE); return; // } else if (gtk_widget_is_focus(GTK_WIDGET(entry)) && length >= 1 && } else if (elm_object_focus_get(wd->url) && length >= 1 && @@ -996,7 +1035,44 @@ populate_visited_links_cb(void *data, Evas_Object *obj, void *event_info) while (eina_iterator_next(it, &hash_data)) { Eina_Hash_Tuple *t = hash_data; Hist_Item *hist_item = t->data; - ewk_view_visited_link_add(bd->view, hist_item_url_get(hist_item)); + // ewk_view_visited_link_add(bd->view, hist_item_url_get(hist_item)); + } +} + +void +_web_free_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + Buffer_Data *bd = data; + Window_Data *wd = bd->window; + elm_naviframe_item_pop(wd->naviframe); + + if (!wd->app->exiting) + wd->cur_buf->view = NULL; + + wd->buffer_list = eina_list_remove(wd->buffer_list, bd); + + if (eina_list_count(wd->buffer_list)) { + buffer_current_set(eina_list_nth(wd->buffer_list, 0)); } + + free(bd); +} + +void +_win_del_request_cb(void *data, Evas_Object *obj, void *event_info) +{ + Window_Data *wd = data; + printf("window requested deletion ..\n"); + + free(wd); +} + +void +webview_create_window_cb(void *data, Evas_Object *obj, Eina_Bool js, const Elm_Web_Window_Features *wf) +{ + Arg a; + Window_Data *wd = data; + + buffer_add(&a, wd); } diff --git a/src/callbacks.h b/src/callbacks.h @@ -10,7 +10,6 @@ void webview_hoverlink_cb (void *, Evas_Object *, void*); void webview_hoverlink_out_cb (void *, Evas_Object *, void*); void webview_uri_changed_cb (void *, Evas_Object *, void*); void webview_load_finished_cb (void *, Evas_Object *, void*); -void webview_document_finished_cb(void *, Evas_Object *, void*); void webview_progress_changed_cb(void *, Evas_Object *, void *); void webview_title_changed_cb (void *, Evas_Object *, void *); void webview_download_cb (void *, Evas_Object *, void *); @@ -22,11 +21,16 @@ void webview_inspector_close_cb (void *, Evas_Object *, void *); void protocol_register_cb (void *, Evas_Object *, void *); void load_error_cb (void *, Evas_Object *, void *); void webview_keypress_cb (void *, Evas *, Evas_Object *, void *); +void webview_focus_in_cb (void *, Evas *, Evas_Object *, void *); +void webview_focus_out_cb (void *, Evas *, Evas_Object *, void *); void webview_mousewheel_cb (void *, Evas *, Evas_Object *, void *); +void _web_free_cb (void *, Evas *, Evas_Object *, void *); +void _win_del_request_cb (void *, Evas_Object *, void *); +void webview_create_window_cb(void*, Evas_Object*, Eina_Bool, const Elm_Web_Window_Features*); void populate_visited_links_cb(void *data, Evas_Object *obj, void *event_info); -void download_entry_free_cb(void *); +// void download_entry_free_cb(void *); /* static Eina_Bool webview_mimetype_cb(WebKitWebView *webview, WebKitWebFrame *frame, WebKitNetworkRequest *request, char *mime_type, WebKitWebPolicyDecision *decision, gpointer user_data); diff --git a/src/commands.c b/src/commands.c @@ -1,13 +1,12 @@ #include <Elementary.h> -#include <EWebKit.h> +#include <EWebKit2.h> #include <libsoup/soup.h> -#include "viking.h" #include "viking_state.h" +#include "viking.h" #include "commands.h" #include "utilities.h" -#include "main.h" static unsigned int scrollstep = 40; /* cursor difference in pixel */ static unsigned int pagingkeep = 40; /* pixels kept when paging */ @@ -280,7 +279,7 @@ descend(const Arg *arg, void *data) { Window_Data *ad = data; // char *source = (char*)webkit_web_view_get_uri(webview), *p = &source[0], *new; - const char *source = elm_web_uri_get(ad->cur_buf->web); + const char *source = ewk_view_uri_get(ad->cur_buf->view); const char *p = &source[0]; char *new; @@ -312,7 +311,7 @@ descend(const Arg *arg, void *data) memcpy(new, source, len); new[len] = '\0'; // webkit_web_view_load_uri(webview, new); - elm_web_uri_set(ad->cur_buf->web, new); + ewk_view_uri_set(ad->cur_buf->view, new); free(new); return TRUE; } @@ -355,9 +354,10 @@ input(const Arg *arg, void *data) */ elm_entry_entry_set(ad->url, arg->s); - if (arg->i & InsertCurrentURL && (url = elm_web_uri_get(ad->cur_buf->web))) + if (arg->i & InsertCurrentURL && (url = ewk_view_uri_get(ad->cur_buf->view))) elm_entry_entry_append(ad->url, url); + // evas_object_focus_set(ad->cur_buf->view, EINA_FALSE); elm_object_focus_set(ad->url, EINA_TRUE); elm_entry_cursor_end_set(ad->url); @@ -422,16 +422,24 @@ Eina_Bool navigate(const Arg *arg, void *data) { Window_Data *ad = data; - if (arg->i & NavigationForwardBack) - // webkit_web_view_go_back_or_forward(webview, (arg->i == NavigationBack ? -1 : 1) * (count ? count : 1)); - elm_web_navigate(ad->cur_buf->web, (arg->i == NavigationBack ? -1 : 1) * (ad->count ? ad->count : 1)); + + if (arg->i == NavigationBack) + ewk_view_back(ad->cur_buf->view); + else + ewk_view_forward(ad->cur_buf->view); + + /* + if (arg->i & NavigationForwardBack) { + ewk_view_navigate(ad->cur_buf->view, (arg->i == NavigationBack ? -1 : 1) * (ad->count ? ad->count : 1)); + //if (arg->i == NavigationBack) + // ewk_view_reload(ad->cur_buf->view); + } else if (arg->i & NavigationReloadActions) - // (arg->i == NavigationReload ? webkit_web_view_reload : webkit_web_view_reload_bypass_cache)(webview); - (arg->i == NavigationReload ? elm_web_reload : elm_web_reload_full)(ad->cur_buf->web); + (arg->i == NavigationReload ? ewk_view_reload : ewk_view_reload_bypass_cache)(ad->cur_buf->view); else - // webkit_web_view_stop_loading(webview); - elm_web_stop(ad->cur_buf->web); - return TRUE; + ewk_view_stop(ad->cur_buf->view); + */ + return EINA_TRUE; } Eina_Bool @@ -439,7 +447,7 @@ number(const Arg *arg, void *data) { Window_Data *ad = data; // const char *source = webkit_web_view_get_uri(webview); - const char *source = elm_web_uri_get(ad->cur_buf->web); + const char *source = ewk_view_uri_get(ad->cur_buf->view); char *uri, *p, *new; int number, diff = (ad->count ? ad->count : 1) * (arg->i == Increment ? 1 : -1); @@ -460,7 +468,7 @@ number(const Arg *arg, void *data) *p = '\0'; new = strdup_printf("%s%d", uri, number); /* create new uri */ // webkit_web_view_load_uri(webview, new); - elm_web_uri_set(ad->cur_buf->web, new); + ewk_view_uri_set(ad->cur_buf->view, new); free(new); free(uri); return TRUE; @@ -545,11 +553,11 @@ open_arg(const Arg *arg, void *data) } } // webkit_web_view_load_uri(webview, new); - elm_web_uri_set(ad->cur_buf->web, new); + ewk_view_uri_set(ad->cur_buf->view, new); free(new); } else { - Buffer_Data *td = buffer_add(ad); - buffer_current_set(td); + a.i = CreateAndShow; + buffer_add(&a, ad); a.i = TargetCurrent; a.s = strdup(arg->s); // not sure if strdup necessary open_arg(&a, data); @@ -637,7 +645,7 @@ tab_quit(const Arg *arg, void *data) Window_Data *ad = data; /* TODO: save the session information for revival later */ - evas_object_del(ad->cur_buf->web); + evas_object_del(ad->cur_buf->view); return EINA_TRUE; } @@ -647,7 +655,7 @@ quit(const Arg *arg, void *data) Window_Data *wd = data; App_Data *ad = wd->app; ad->exiting = EINA_TRUE; - elm_shutdown(); + elm_exit(); return EINA_TRUE; } @@ -691,11 +699,11 @@ search(const Arg *arg, void *data) direction ^= ad->search_direction; do { // success = webkit_web_view_search_text(webview, search_handle, arg->i & CaseSensitive, direction, FALSE); - success = elm_web_text_search(ad->cur_buf->web, ad->search_handle, arg->i & CaseSensitive, direction, FALSE); + // success = ewk_view_text_search(ad->cur_buf->view, ad->search_handle, arg->i & CaseSensitive, direction, FALSE); if (!success) { if (arg->i & Wrapping) { // success = webkit_web_view_search_text(webview, search_handle, arg->i & CaseSensitive, direction, TRUE); - success = elm_web_text_search(ad->cur_buf->web, ad->search_handle, arg->i & CaseSensitive, direction, EINA_TRUE); + // success = ewk_view_text_search(ad->cur_buf->view, ad->search_handle, arg->i & CaseSensitive, direction, EINA_TRUE); if (success) { a.i = Warning; a.s = strdup_printf("search hit %s, continuing at %s", @@ -729,12 +737,12 @@ set(const Arg *arg, void *data) if (ad->search_handle) { ad->search_handle = NULL; // webkit_web_view_unmark_text_matches(webview); - elm_web_text_matches_unmark_all(ad->cur_buf->web); + // ewk_view_text_matches_unmark_all(ad->cur_buf->view); } // gtk_entry_set_text(GTK_ENTRY(inputbox), ""); // gtk_widget_grab_focus(GTK_WIDGET(webview)); elm_entry_entry_set(ad->url, ""); - elm_object_focus_set(ad->cur_buf->web, EINA_TRUE); + evas_object_focus_set(ad->cur_buf->view, EINA_TRUE); break; case ModePassThrough: a.s = strdup("-- PASS THROUGH --"); @@ -800,13 +808,13 @@ Eina_Bool script(const Arg *arg, void *data) { // gchar *value = NULL, *message = NULL; - const char *value; + const char *value = NULL; char text[1024] = ""; Arg a; // WebKitNetworkRequest *request; // WebKitDownload *download; Window_Data *ad = data; - Evas_Object *frame = ewk_view_frame_main_get(ad->cur_buf->view); + // Evas_Object *frame = ewk_view_frame_main_get(ad->cur_buf->view); if (!arg->s) { set_error("Missing argument.", data); @@ -821,7 +829,7 @@ script(const Arg *arg, void *data) } g_free(message); */ - value = ewk_frame_script_execute(frame, arg->s); + // value = ewk_frame_script_execute(frame, arg->s); if (arg->i != Silent && value) { a.i = arg->i; a.s = strdup(value); @@ -890,6 +898,7 @@ scroll(const Arg *arg, void *data) // int max = gtk_adjustment_get_upper(adjust) - gtk_adjustment_get_page_size(adjust); // float val = gtk_adjustment_get_value(adjust) / max * 100; + /* int x, y, w, h, page_w, page_h; float val; Eina_Bool horizontal = EINA_FALSE; @@ -909,7 +918,7 @@ scroll(const Arg *arg, void *data) if ((direction == 1 && val < 100) || (direction == -1 && val > 0)) { if (arg->i & ScrollMove) { - int total = direction * /* direction */ + int total = direction * ((arg->i & UnitLine || (arg->i & UnitBuffer && ad->count)) ? (scrollstep * (ad->count ? ad->count : 1)) : ( // arg->i & UnitBuffer ? gtk_adjustment_get_page_size(adjust) / 2 : arg->i & UnitBuffer ? (horizontal ? page_w : page_h) / 2 : @@ -935,6 +944,7 @@ scroll(const Arg *arg, void *data) } update_state(data); } + */ return TRUE; } @@ -944,14 +954,25 @@ zoom(const Arg *arg, void *data) Window_Data *wd = data; App_Data *ad = wd->app; + /* + ewk_view_scale_set(wd->cur_buf->view, (arg->i & ZoomOut) ? + // webkit_web_view_get_zoom_level(webview) + + ewk_view_scale_get(wd->cur_buf->view) + + (((double)(wd->count ? wd->count : 1)) * (arg->i & (1 << 1) ? 1.0 : -1.0) * ad->zoomstep) : + (wd->count ? (double)wd->count / 100.0 : 1.0), 0, 0); + + */ + // webkit_web_view_set_full_content_zoom(webview, (arg->i & ZoomFullContent) > 0); // webkit_web_view_set_zoom_level(ad->current_tab->web, (arg->i & ZoomOut) ? - elm_web_zoom_set(wd->cur_buf->web, (arg->i & ZoomOut) ? + /* + ewk_view_text_zoom_set(wd->cur_buf->view, (arg->i & ZoomOut) ? // webkit_web_view_get_zoom_level(webview) + - elm_web_zoom_get(wd->cur_buf->web) + + ewk_view_zoom_get(wd->cur_buf->view) + (((float)(wd->count ? wd->count : 1)) * (arg->i & (1 << 1) ? 1.0 : -1.0) * ad->zoomstep) : (wd->count ? (float)wd->count / 100.0 : 1.0)); - return TRUE; + */ + return EINA_TRUE; } /* @@ -1076,11 +1097,11 @@ proxy(const Arg *arg, void *data) // ewk_network_proxy_uri_set(NULL); g_object_set(ad->app->soup_session, "proxy-uri", NULL, NULL); bd->proxy_enabled = EINA_FALSE; - update_url(elm_web_uri_get(bd->web), data); + update_url(ewk_view_uri_get(bd->view), data); } else if (enable_proxy(ad->cur_buf)) { bd->proxy_enabled = EINA_TRUE; - update_url(elm_web_uri_get(bd->web), data); - elm_web_reload(bd->web); + update_url(ewk_view_uri_get(bd->view), data); + ewk_view_reload(bd->view); } return EINA_TRUE; @@ -1280,7 +1301,7 @@ list(const Arg *arg, void *data) Eina_List *l; Buffer_Data *td; Evas_Object *icon, *row, *label; - Evas *e = evas_object_evas_get(ad->win); + // Evas *e = evas_object_evas_get(ad->win); elm_box_clear(ad->event_box); @@ -1308,20 +1329,22 @@ list(const Arg *arg, void *data) elm_object_text_set(label, status_buf); - icon = ewk_settings_icon_database_icon_object_get(elm_web_uri_get(td->web), e); + /* + icon = ewk_settings_icon_database_icon_object_get(ewk_view_uri_get(td->view), e); // evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(icon, 0.0, EVAS_HINT_FILL); evas_object_size_hint_max_set(icon, 14, 14); evas_object_size_hint_min_set(icon, 14, 14); elm_box_pack_end(row, icon); evas_object_show(icon); + */ label = elm_label_add(ad->win); evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(label, 0.0, EVAS_HINT_FILL); elm_box_pack_end(row, label); evas_object_show(label); - url = strdup_printf("<font=Monospace font_size=12 backing=on backing_color=#FFF>%s", elm_web_uri_get(td->web)); + url = strdup_printf("<font=Monospace font_size=12 backing=on backing_color=#FFF>%s", ewk_view_uri_get(td->view)); elm_object_text_set(label, url); free(url); @@ -1330,9 +1353,13 @@ list(const Arg *arg, void *data) evas_object_size_hint_align_set(label, 1.0, EVAS_HINT_FILL); elm_box_pack_end(row, label); evas_object_show(label); - count_str = strdup_printf("<font=Monospace font_size=12 backing=on backing_color=#FFF>%s", elm_web_title_get(td->web)); + /* + const Ewk_Text_With_Direction *txt = ewk_view_title_get(td->view); + count_str = strdup_printf("<backing=on backing_color=#FFF>%s", txt ? txt->string : ""); + evas_object_text_font_set(label, "Monospace", 12); elm_object_text_set(label, count_str); free(count_str); + */ } evas_object_show(ad->event_box); @@ -1392,6 +1419,7 @@ switch_buffer(const Arg *arg, void *data) Eina_Bool inspector(const Arg *arg, void *data) { + /* Window_Data *ad = data; Buffer_Data *bd = ad->cur_buf; @@ -1399,14 +1427,15 @@ inspector(const Arg *arg, void *data) ewk_view_setting_enable_developer_extras_set(bd->view, EINA_TRUE); ewk_view_web_inspector_show(bd->view); bd->inspector_enabled = EINA_TRUE; - update_url(elm_web_uri_get(bd->web), data); + update_url(ewk_view_uri_get(bd->view), data); } else { ewk_view_web_inspector_close(bd->view); bd->inspector_enabled = EINA_FALSE; ewk_view_setting_enable_developer_extras_set(bd->view, EINA_FALSE); - update_url(elm_web_uri_get(bd->web), data); + update_url(ewk_view_uri_get(bd->view), data); } + */ return EINA_TRUE; } @@ -1419,10 +1448,10 @@ toggle_history(const Arg *arg, void *data) if (bd->history_enabled) { bd->history_enabled = EINA_FALSE; - update_url(elm_web_uri_get(bd->web), data); + update_url(ewk_view_uri_get(bd->view), data); } else { bd->history_enabled = EINA_TRUE; - update_url(elm_web_uri_get(bd->web), data); + update_url(ewk_view_uri_get(bd->view), data); } return EINA_TRUE; @@ -1436,13 +1465,13 @@ toggle_cookies(const Arg *arg, void *data) if (bd->cookies_enabled) { bd->cookies_enabled = EINA_FALSE; - ewk_cookies_policy_set(EWK_COOKIE_JAR_ACCEPT_NEVER); - update_url(elm_web_uri_get(bd->web), data); + // ewk_cookies_policy_set(EWK_COOKIE_JAR_ACCEPT_NEVER); + update_url(ewk_view_uri_get(bd->view), data); } else { bd->cookies_enabled = EINA_TRUE; - ewk_cookies_policy_set(EWK_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY); - update_url(elm_web_uri_get(bd->web), data); + // ewk_cookies_policy_set(EWK_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY); + update_url(ewk_view_uri_get(bd->view), data); } return EINA_TRUE; @@ -1451,16 +1480,13 @@ toggle_cookies(const Arg *arg, void *data) Eina_Bool window(const Arg *arg, void *data) { + Arg a; Window_Data *wd = data; - Window_Data *new = window_add(wd->app); if (arg->i & CreateWindow) { - Buffer_Data *bd = buffer_add(new); - buffer_current_set(bd); - elm_web_uri_set(bd->web, arg->s ? arg->s : config_home_page_get(wd->app->config)); - - evas_object_resize(new->win, 480, 640); - evas_object_show(new->win); + a.i = DefaultBuf; + a.s = (arg->s ? arg->s : config_home_page_get(wd->app->config)); + window_add(&a, wd->app); } else if (arg->i & DeleteWindow) { evas_object_del(wd->win); diff --git a/src/commands.h b/src/commands.h @@ -88,7 +88,6 @@ static Command commands[COMMANDSIZE] = { }; - /* mouse bindings you can use MOUSE_BUTTON_1 to MOUSE_BUTTON_5 */ diff --git a/src/main.c b/src/main.c @@ -11,15 +11,12 @@ */ #include <Elementary.h> -#include <EWebKit.h> +#include <EWebKit2.h> #include <libsoup/soup.h> -#include "javascript.h" -#include "viking.h" #include "viking_state.h" -#include "main.h" +#include "viking.h" #include "utilities.h" -#include "callbacks.h" #include <stdio.h> /* asprintf() */ #include <string.h> /* strcmp */ @@ -29,545 +26,9 @@ EAPI_MAIN int elm_main(int argc, char *argv[]); -Evas_Object *webview_create_window_cb(void*, Evas_Object*, Eina_Bool, const Elm_Web_Window_Features*); - /* functions */ -static void ascii_bar(int total, int state, char *string); char *uri_sanitize(const char *); - -Eina_Bool -enable_proxy(Buffer_Data *bd) -{ - SoupURI *soup_uri; - char *proxy_uri, *new; - - printf("trying to enable proxy .. "); - - proxy_uri = getenv("http_proxy"); - if (proxy_uri == NULL) - proxy_uri = getenv("HTTP_PROXY"); - - if (proxy_uri != NULL && 0 < strlen(proxy_uri)) { - new = strstr(proxy_uri, "http://") ? - strdup(proxy_uri) : strdup_printf("http://%s", proxy_uri); - - soup_uri = soup_uri_new(new); - /* really wish there was per-view proxy support in webkit */ - g_object_set(bd->window->app->soup_session, "proxy-uri", soup_uri, NULL); - - printf("success! (%s)\n", new); - bd->proxy_enabled = EINA_TRUE; - - soup_uri_free(soup_uri); - free(new); - return EINA_TRUE; - } - else { - printf("HTTP_PROXY not set.\n"); - return EINA_FALSE; - } -} - -static const int progressbartick = 10; - -static void -ascii_bar(int total, int state, char *string) -{ - int i; - - for (i = 0; i < state; i++) - string[i] = '='; - string[i++] = '>'; - for (; i < total; i++) - string[i] = ' '; - string[i] = '\0'; -} - -void -update_state(void *data) -{ - // char *markup; - Window_Data *wd = data; - App_Data *ad = wd->app; - Evas_Object *view = wd->cur_buf->view; - Evas_Object *frame = ewk_view_frame_main_get(view); - int download_count = eina_hash_population(ad->downloads); - // GString *status = g_string_new(""); - char status[512] = ""; - - /* construct the status line */ - - strcat(status, "<font=Monospace font_size=12 color=#FFF backing=on backing_color=#000>"); - - /* count, modkey and input buffer */ - // g_string_append_printf(status, "%.0d", count); - char *count_formatted = strdup_printf("%.0d", wd->count); - strcat(status, count_formatted); - free(count_formatted); - - // if (ad->current_modkey) g_string_append_c(status, ad->current_modkey); - if (wd->current_modkey) strcat(status, &wd->current_modkey); - - if (download_count) { - char *download_status = strdup_printf(" %d DL%s", download_count, - (download_count == 1) ? "" : "s"); - strcat(status, download_status); - free(download_status); - } - - /* the progressbar */ - int progress = -1; - char progressbar[progressbartick + 1]; - - if (eina_hash_population(ad->downloads)) { - progress = 0; - - void *hash_data; - struct dl *dload; - Eina_Iterator *it = eina_hash_iterator_tuple_new(ad->downloads); - - while (eina_iterator_next(it, &hash_data)) { - Eina_Hash_Tuple *t = hash_data; - dload = t->data; - - if (dload->dltotal != 0) - progress += 100 * (int) (dload->dlnow / dload->dltotal); - } - eina_iterator_free(it); - - progress /= eina_hash_population(ad->downloads); - - } else if (ewk_view_load_progress_get(view) != 0.0f) { - progress = ewk_view_load_progress_get(view) * 100; - } - - if (progress >= 0) { - ascii_bar(progressbartick, progress * progressbartick / 100, progressbar); - char *load_progress = strdup_printf(" %c%s%c", - '[', progressbar, ']'); - strcat(status, load_progress); - free(load_progress); - } - - /* put a notification if we are zoomed */ - double zoom = elm_web_zoom_get(wd->cur_buf->web); - if (zoom != 1) { - char *zoom_str = strdup_printf(" %0.2lfx", zoom); - strcat(status, zoom_str); - free(zoom_str); - } - - /* always show the current scroll position */ - int x, y, w, h, val; - ewk_frame_scroll_pos_get(frame, &x, &y); - ewk_frame_scroll_size_get(frame, &w, &h); - - val = (int) ((float) y / h * 100); - - if (h == 0) - strcat(status, " All"); - else if (val == 0) - strcat(status, " Top"); - else if (val == 100) - strcat(status, " Bot"); - else { - char *percent_scrolled = strdup_printf(" %d%%", val); - strcat(status, percent_scrolled); - free(percent_scrolled); - } - - elm_object_text_set(wd->status_state, status); - - int state_width, window_width; - evas_object_geometry_get(wd->status_state, NULL, NULL, &state_width, NULL); - evas_object_geometry_get(wd->win, NULL, NULL, &window_width, NULL); - - elm_label_wrap_width_set(wd->status_url, window_width - state_width); - - // update_url(elm_web_uri_get(ad->current_web), data); - // elm_box_recalculate(ad->status_bar); - // recalculate_status_bar(data); -} - -char* -/* must free() the return value */ -status_flags(void *data) -{ - char *end; - Buffer_Data *bd = data; - char *flags = calloc(32, 1); - - strcat(flags, "["); - strcat(flags, bd->proxy_enabled ? "P" : " "); - strcat(flags, bd->inspector_enabled ? "I" : " "); - strcat(flags, bd->history_enabled ? "H" : " "); - strcat(flags, bd->cookies_enabled ? "C" : " "); - end = strdup_printf("] %2i ", bd->buf_number); - strcat(flags, end); - free(end); - - return flags; -} - -void -update_url(const char *uri, void *data) -{ - char *tmp; - char before[] = " ["; - char after[] = "]"; - char url_buf[1024] = ""; - Window_Data *ad = data; - Buffer_Data *bd = ad->cur_buf; - - if (uri == NULL) - return; - - Eina_Bool back = elm_web_back_possible_get(bd->web); - Eina_Bool fwd = elm_web_forward_possible_get(bd->web); - - Evas_Object *frame = ewk_view_frame_main_get(bd->view); - char *url_color = "#FFF"; - - if (!strncmp(uri, "https://", 8)) { - Ewk_Certificate_Status cert_status = ewk_frame_certificate_status_get(frame); - if (cert_status & EWK_CERTIFICATE_STATUS_TRUSTED) - url_color = "#6F6"; - else if (cert_status & EWK_CERTIFICATE_STATUS_UNTRUSTED) - url_color = "#F66"; - } - - if (!back && !fwd) - before[0] = after[0] = '\0'; - - strcat(url_buf, "<font=Monospace font_size=12 color=#FFF>"); - tmp = status_flags(bd); - strcat(url_buf, tmp); - free(tmp); - tmp = strdup_printf("<color=%s>%s<color=#FFF>%s%s%s%s", - url_color, uri, before, back ? "+" : "", fwd ? "-" : "", after); - strcat(url_buf, tmp); - free(tmp); - - int state_width, window_width; - evas_object_geometry_get(ad->status_state, NULL, NULL, &state_width, NULL); - evas_object_geometry_get(ad->win, NULL, NULL, &window_width, NULL); - elm_label_wrap_width_set(ad->status_url, window_width - state_width); - - elm_object_text_set(ad->status_url, url_buf); - // elm_label_line_wrap_set(ad->status_url, ELM_WRAP_CHAR); - // elm_label_ellipsis_set(ad->status_url, EINA_TRUE); -} - -Eina_Bool -echo(const Arg *arg, void *data) -{ - Window_Data *ad = data; - int index = !arg->s ? 0 : arg->i & (~NoAutoHide); - - if (index < Info || index > Error) - return TRUE; - -// printf("echo(%s)\n", arg->s); - // if (!gtk_widget_is_focus(GTK_WIDGET(inputbox))) { - if (!elm_object_focus_get(ad->url)) { - // set_widget_font_and_color(ad->url, urlboxfont[index], urlboxbgcolor[index], urlboxcolor[index]); - // gtk_entry_set_text(GTK_ENTRY(inputbox), !arg->s ? "" : arg->s); - elm_entry_entry_set(ad->url, !arg->s ? "" : arg->s); - } - - return TRUE; -} - - /* -void -set_widget_font_and_color(Evas_Object *widget, const char *font_str, const char *bg_color_str, const char *fg_color_str) -{ - GdkColor fg_color; - GdkColor bg_color; - PangoFontDescription *font; - - font = pango_font_description_from_string(font_str); - gtk_widget_modify_font(widget, font); - pango_font_description_free(font); - - if (fg_color_str) - gdk_color_parse(fg_color_str, &fg_color); - if (bg_color_str) - gdk_color_parse(bg_color_str, &bg_color); - - gtk_widget_modify_text(widget, GTK_STATE_NORMAL, fg_color_str ? &fg_color : NULL); - gtk_widget_modify_base(widget, GTK_STATE_NORMAL, bg_color_str ? &bg_color : NULL); - - return; -} -*/ - - - -Evas_Object * -webview_create_window_cb(void *data, Evas_Object *obj, Eina_Bool js, const Elm_Web_Window_Features *wf) -{ - Window_Data *wd = data; - Buffer_Data *bd = buffer_add(wd); - - return bd->web; -} - -static void -_win_del_request_cb(void *data, Evas_Object *obj, void *event_info) -{ - Window_Data *wd = data; - printf("window requested deletion ..\n"); - - free(wd); -} - -void -buffer_current_set(Buffer_Data *new_buf) -{ - Window_Data *wd = new_buf->window; - Buffer_Data *old_buf = wd->cur_buf; - App_Data *ad = wd->app; - - if (new_buf == old_buf || ad->exiting) - return; - - if (old_buf) { - ewk_view_visibility_state_set(old_buf->view, EWK_PAGE_VISIBILITY_STATE_HIDDEN, 0); - if (old_buf->inspector_enabled) - ewk_view_web_inspector_close(old_buf->view); - // if (old_buf->proxy_enabled) - // g_object_set(ad->soup_session, "proxy-uri", NULL, NULL); - } - - wd->cur_buf = new_buf; - - if (new_buf) { - ewk_view_visibility_state_set(new_buf->view, EWK_PAGE_VISIBILITY_STATE_VISIBLE, 0); - if (new_buf->inspector_enabled) { - ewk_view_web_inspector_show(new_buf->view); - } - - elm_naviframe_item_simple_promote(wd->naviframe, new_buf->web); - /* - if (new_buf->proxy_enabled) - enable_proxy(ad->cur_buf); - - if (new_buf->cookies_enabled) - ewk_cookies_policy_set(EWK_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY); - else - ewk_cookies_policy_set(EWK_COOKIE_JAR_ACCEPT_NEVER); - */ - update_url(elm_web_uri_get(new_buf->web), wd); - } -} - -static void -_web_free_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) -{ - Buffer_Data *bd = data; - Window_Data *wd = bd->window; - elm_naviframe_item_pop(wd->naviframe); - - if (!wd->app->exiting) - wd->cur_buf->web = NULL; - - wd->buffer_list = eina_list_remove(wd->buffer_list, bd); - - if (eina_list_count(wd->buffer_list)) { - buffer_current_set(eina_list_nth(wd->buffer_list, 0)); - } - - free(bd); -} - -Buffer_Data* -buffer_add(Window_Data *wd) -{ - Buffer_Data *td; - - td = calloc(1, sizeof(Buffer_Data)); - if (!td) return NULL; - - wd->buf_total++; - - td->window = wd; - td->web = elm_web_add(wd->win); - td->buf_number = wd->buf_total; - td->inspector_enabled = EINA_FALSE; - td->proxy_enabled = EINA_FALSE; - td->history_enabled = EINA_TRUE; - td->cookies_enabled = EINA_FALSE; - td->view = elm_web_webkit_view_get(td->web); - - wd->buffer_list = eina_list_append(wd->buffer_list, td); - - elm_web_window_create_hook_set(td->web, webview_create_window_cb, wd); - elm_web_console_message_hook_set(td->web, webview_console_cb, td); - elm_web_useragent_set(td->web, "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.514.0 Safari/534.7"); - elm_web_history_enabled_set(td->web, EINA_TRUE); - - elm_web_inwin_mode_set(td->web, EINA_TRUE); - evas_object_size_hint_weight_set(td->web, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(td->web, EVAS_HINT_FILL, EVAS_HINT_FILL); - - elm_naviframe_item_simple_push(wd->naviframe, td->web); - - /* - if (wd->cur_buf) - elm_naviframe_item_insert_after(wd->naviframe, ad->cur_buf->web, ); - else - elm_naviframe_item_simple_push(ad->naviframe, td->web); - */ - - evas_object_data_set(td->web, "buffer_data", td); - - /* signals */ - evas_object_smart_callback_add(td->web, "title,changed", webview_title_changed_cb, td); - evas_object_smart_callback_add(td->web, "uri,changed", webview_uri_changed_cb, td); - evas_object_smart_callback_add(td->web, "load,progress", webview_progress_changed_cb, td); - // evas_object_smart_callback_add(td->web, "load,started", webview_load_committed_cb, td); - evas_object_smart_callback_add(td->web, "load,document,finished", webview_document_finished_cb, td); - evas_object_smart_callback_add(td->web, "load,finished", webview_load_finished_cb, td); - evas_object_smart_callback_add(td->web, "download,request", webview_download_cb, td); - evas_object_smart_callback_add(td->web, "link,hover,in", webview_hoverlink_cb, td); - evas_object_smart_callback_add(td->web, "link,hover,out", webview_hoverlink_out_cb, td); - evas_object_smart_callback_add(td->web, "inputmethod,changed", inputmethod_changed_cb, td); - - /* these signals are not offered by elm_web */ - evas_object_smart_callback_add(td->view, "load,error", load_error_cb, td); - evas_object_smart_callback_add(td->view, "inspector,view,create", webview_inspector_cb, td); - evas_object_smart_callback_add(td->view, "inspector,view,close", webview_inspector_close_cb, td); - evas_object_smart_callback_add(td->view, "protocolhandler,isregistered", protocol_register_cb, td); - evas_object_smart_callback_add(td->view, "icon,received", icon_received_cb, td); - evas_object_smart_callback_add(td->view, "xss,detected", xss_detected_cb, td); - evas_object_smart_callback_add(td->view, "populate,visited,links", populate_visited_links_cb, td); - - evas_object_event_callback_add(td->web, EVAS_CALLBACK_FREE, _web_free_cb, td); - evas_object_event_callback_add(td->web, EVAS_CALLBACK_KEY_DOWN, webview_keypress_cb, td); - // evas_object_event_callback_add(td->web, EVAS_CALLBACK_MOUSE_UP, notify_event_cb, td); - evas_object_event_callback_add(td->web, EVAS_CALLBACK_MOUSE_WHEEL, webview_mousewheel_cb, td); - - return td; -} - -Window_Data * -window_add(App_Data *ad) -{ - Window_Data *wd; - - wd = calloc(1, sizeof(Window_Data)); - if (!wd) return NULL; - - Evas_Object *win, *bg, *box, *status_bar, *url, *naviframe, *status_url; - Evas_Object *status_state, *event_box, *web_inspector; - - elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); - - win = elm_win_add(NULL, "viking", ELM_WIN_BASIC); - elm_win_autodel_set(win, EINA_TRUE); - // elm_win_screen_constrain_set(win, EINA_TRUE); - evas_object_smart_callback_add(win, "delete,request", _win_del_request_cb, wd); - - /* program bacground */ - bg = elm_bg_add(win); - evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_win_resize_object_add(win, bg); - elm_bg_color_set(bg, 0, 0, 0); - evas_object_layer_set(bg, EVAS_LAYER_MIN); - evas_object_show(bg); - - /* main box that everything goes into, resizes with window */ - box = elm_box_add(win); - evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_win_resize_object_add(win, box); - evas_object_show(box); - - /* widget that shows the web pages */ - naviframe = elm_naviframe_add(win); - evas_object_size_hint_weight_set(naviframe, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(naviframe, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_box_pack_end(box, naviframe); - evas_object_show(naviframe); - - /* status bar container */ - status_bar = elm_box_add(win); - elm_box_homogeneous_set(status_bar, EINA_FALSE); - elm_box_horizontal_set(status_bar, EINA_TRUE); - evas_object_size_hint_align_set(status_bar, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_box_pack_end(box, status_bar); - evas_object_show(status_bar); - - /* status bar url */ - status_url = elm_label_add(win); - evas_object_size_hint_weight_set(status_url, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(status_url, 0.0, EVAS_HINT_FILL); - elm_box_pack_end(status_bar, status_url); - evas_object_show(status_url); - - /* status bar state (load progress, mod keys, scroll %) */ - status_state = elm_label_add(win); - evas_object_size_hint_weight_set(status_state, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(status_state, 1.0, EVAS_HINT_FILL); - elm_box_pack_end(status_bar, status_state); - evas_object_show(status_state); - - /* invisible until activated web inspector */ - web_inspector = elm_box_add(win); - evas_object_size_hint_align_set(web_inspector, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_box_pack_end(box, web_inspector); - evas_object_hide(web_inspector); - - /* invisible event box, populated on tab completions and :ls */ - event_box = elm_box_add(win); - evas_object_size_hint_align_set(event_box, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_box_pack_end(box, event_box); -// evas_object_hide(event_box); - - /* main entry widget */ - url = elm_entry_add(win); - elm_entry_single_line_set(url, EINA_TRUE); - elm_entry_scrollable_set(url, EINA_TRUE); - evas_object_size_hint_weight_set(url, EVAS_HINT_EXPAND, 0.0); - evas_object_size_hint_align_set(url, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_box_pack_end(box, url); - elm_entry_text_style_user_push(url, "DEFAULT='font=Monospace font_size=12'"); - evas_object_show(url); - - evas_object_smart_callback_add(url, "activated", inputbox_activate_cb, wd); - evas_object_smart_callback_add(url, "changed", inputbox_changed_cb, wd); - evas_object_event_callback_add(url, EVAS_CALLBACK_KEY_DOWN, inputbox_keypress_cb, wd); - evas_object_event_callback_add(url, EVAS_CALLBACK_KEY_UP, inputbox_keyrelease_cb, wd); - - wd->win = win; - wd->main_box = box; - wd->naviframe = naviframe; - wd->url = url; - wd->status_url = status_url; - wd->status_state = status_state; - wd->event_box = event_box; - wd->web_inspector = web_inspector; - wd->app = ad; - - wd->mode = ModeNormal; - wd->echo_active = EINA_TRUE; - - ad->windows = eina_list_append(ad->windows, wd); - - return wd; -} - -static void -setup_network(App_Data *ad) -{ - static char ca_bundle[MAX_SETTING_SIZE] = "/etc/ssl/certs/ca-certificates.crt"; - - ad->soup_session = ewk_network_default_soup_session_get(); - g_object_set(G_OBJECT(ad->soup_session), "ssl-ca-file", ca_bundle, NULL); - g_object_set(G_OBJECT(ad->soup_session), "ssl-strict", FALSE, NULL); - - // ewk_network_tls_ca_certificates_path_set(ca_bundle); -} +static void download_entry_free_cb(void *data); static Eina_Bool _cb_session_save(void *data) @@ -784,8 +245,8 @@ setup_config(App_Data *ad, int argc, char **argv) if (!ecore_file_mkpath(path)) ERR("Could not create %s", path); - if (!ewk_settings_icon_database_path_set(path)) - ERR("Could not set icon database path to %s", path); + // if (!ewk_settings_icon_database_path_set(path)) + // ERR("Could not set icon database path to %s", path); basename = path + dirlen; basename[0] = '/'; @@ -793,7 +254,7 @@ setup_config(App_Data *ad, int argc, char **argv) dirlen++; eina_strlcpy(basename, "cookies.txt", sizeof(path) - dirlen); - ewk_cookies_file_set(path); + // ewk_cookies_file_set(path); // ewk_cookies_policy_set(EWK_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY); eina_strlcpy(basename, "config.eet", sizeof(path) - dirlen); @@ -824,7 +285,7 @@ setup_config(App_Data *ad, int argc, char **argv) EINA_FALSE /* frame_flattening */, EINA_FALSE /* text_only_zoom */, 12 /* minimum_font_size */, - ewk_cookies_policy_get(), + NULL,//ewk_cookies_policy_get(), backing_store_enum); if (!config_save(config, path)) ERR("Could not save new configuration at %s", path); @@ -914,11 +375,17 @@ fd_handler_cb(void *data, Ecore_Fd_Handler *handler) } */ +static void +download_entry_free_cb(void *data) +{ + free(data); +} + EAPI_MAIN int elm_main(int argc, char *argv[]) { App_Data *ad; - Buffer_Data *bd; + // Buffer_Data *bd; // char path[PATH_MAX]; // int dirlen; @@ -933,8 +400,11 @@ elm_main(int argc, char *argv[]) } */ + /* if (!elm_need_web()) return -1; + */ + ewk_init(); /* calloc zeros the memory!! */ ad = calloc(1, sizeof(App_Data)); @@ -949,23 +419,27 @@ elm_main(int argc, char *argv[]) EINA_LOG_CRIT("could not create log domain 'viking'."); */ + ad->ewk_context = ewk_context_default_get(); + ad->cookie_manager = ewk_context_cookie_manager_get(ad->ewk_context); + setup_config(ad, argc, argv); setup_modkeys(ad); - setup_network(ad); + + // static char ca_bundle[MAX_SETTING_SIZE] = "/etc/ssl/certs/ca-certificates.crt"; + + /* talk to soup directly */ + // ad->soup_session = ewk_network_default_soup_session_get(); + // g_object_set(G_OBJECT(ad->soup_session), "ssl-ca-file", ca_bundle, NULL); + // g_object_set(G_OBJECT(ad->soup_session), "ssl-strict", FALSE, NULL); if (config_restore_state_get(ad->config) && session_windows_count(ad->session) > 0 && session_restore()) { printf("main() session restored successfully.\n"); } else { - Window_Data *wd = window_add(ad); - - bd = buffer_add(wd); - buffer_current_set(bd); - elm_web_uri_set(bd->web, config_home_page_get(ad->config)); - - evas_object_resize(wd->win, 480, 640); - evas_object_show(wd->win); + Arg arg; + arg.i = DefaultBuf; + window_add(&arg, ad); } make_searchengines_list(searchengines, LENGTH(searchengines)); @@ -985,12 +459,13 @@ elm_main(int argc, char *argv[]) hist_free(ad->history); _cb_session_save(ad->session); session_free(ad->session); - if (ad->session_save_timer) ecore_timer_del(ad->session_save_timer); + //if (ad->session_save_timer) + // ecore_timer_del(ad->session_save_timer); // eina_log_domain_unregister(ad->log_domain); // ad->log_domain = -1; - elm_shutdown(); + ewk_shutdown(); // ewk_shutdown(); viking_state_shutdown(); @@ -998,6 +473,9 @@ elm_main(int argc, char *argv[]) // each window needs this done to it // eina_list_free(wd->buffer_list); eina_hash_free(ad->downloads); + eina_list_free(ad->windows); + // eina_list_free(ad->keylistroot; + free(ad); return 0; } diff --git a/src/main.h b/src/main.h @@ -1,113 +0,0 @@ -/* - (c) 2009 by Leon Winter - (c) 2009, 2010 by Hannes Schueller - (c) 2009, 2010 by Matto Fransen - (c) 2010 by Hans-Peter Deifel - (c) 2010 by Thomas Adam - see LICENSE file -*/ - -#ifndef MAIN_H -#define MAIN_H - -typedef struct _Buffer_Data Buffer_Data; - -typedef struct -{ - Eina_List *windows; - - KeyList *keylistroot; - float zoomstep; - char *modkeys; - - Eina_Hash *downloads; - - SoupSession *soup_session; - - Hist *history; - Config *config; - Session *session; - Ecore_Timer *session_save_timer; - int log_domain; - - Eina_Bool exiting : 1; -} App_Data; - -typedef struct -{ - Evas_Object *win; - Evas_Object *main_box; - Evas_Object *naviframe; - Evas_Object *url; /* "inputbox" */ - Evas_Object *event_box; - Evas_Object *status_bar; - Evas_Object *status_url; - Evas_Object *status_state; - Evas_Object *web_inspector; - - Eina_List *commandhistory; - int commandpointer; - - char current_modkey; - - unsigned int mode; - unsigned int count; - char *search_handle; - Eina_Bool search_direction; - Eina_Bool echo_active; - - char rememberedURI[1024]; - char followTarget[8]; - char *error_msg; - Eina_Bool manual_focus; - - unsigned int buf_total; - Eina_List *buffer_list; - // Eina_Hash *downloads; - // Eina_List *commandhistory; - // int commandpointer; - - // SoupSession *soup_session; - Buffer_Data *cur_buf; - App_Data *app; - - // Hist *history; - // Config *config; - // Session *session; - // Ecore_Timer *session_save_timer; - // int log_domain; - - // Eina_Bool exiting : 1; -} Window_Data; - -struct _Buffer_Data -{ - Evas_Object *web; - Evas_Object *view; - Window_Data *window; - unsigned int buf_number; - - Eina_Bool inspector_enabled; - Evas_Object *web_inspector; - - Eina_Bool proxy_enabled; - Eina_Bool history_enabled; - Eina_Bool cookies_enabled; -}; - -struct dl { - long int dltotal; - long int dlnow; -}; - -void update_state(void *); -void update_url(const char *, void *); -Eina_Bool echo(const Arg *arg, void *); -void buffer_current_set(Buffer_Data *td); -Buffer_Data *buffer_add(Window_Data *ad); -Window_Data * window_add(App_Data *ad); -Eina_Bool enable_proxy(Buffer_Data *bd); -char* status_flags(void *data); - -#endif - diff --git a/src/utilities.c b/src/utilities.c @@ -9,6 +9,7 @@ #include <Elementary.h> +#include <EWebKit2.h> #include <libsoup/soup.h> #include <stdlib.h> /* malloc */ @@ -17,12 +18,12 @@ #include <ctype.h> /* tolower */ #include <unistd.h> /* realloc */ -#include "viking.h" #include "viking_state.h" -#include "main.h" -#include "utilities.h" +#include "viking.h" #include "commands.h" +#include "utilities.h" #include "keymap.h" +#include "callbacks.h" #include "jsmn.h" @@ -1080,13 +1081,10 @@ void setup_modkeys(void *data) { App_Data *ad = data; - Evas *e; - Evas_Modifier_Mask mask; unsigned int i; ad->modkeys = calloc(LENGTH(keys) + 1, sizeof(char)); ad->modkeys[0] = '\0'; - // e = evas_object_evas_get(ad->win); for (i = 0; i < LENGTH(keys); i++) { if (keys[i].modkey && !strchr(ad->modkeys, keys[i].modkey)) { @@ -1094,11 +1092,494 @@ setup_modkeys(void *data) ad->modkeys[strlen(ad->modkeys)] = keys[i].modkey; ad->modkeys[strlen(ad->modkeys) + 1] = '\0'; } - - // mask = evas_key_modifier_mask_get(e, keys[i].mask); - // if (keys[i].key && !evas_object_key_grab(ad->win, keys[i].key, mask, 0, EINA_FALSE)) - // fprintf(stderr, "Could not grab trigger for mask = %s, key = %s\n", keys[i].mask , keys[i].key); } // fprintf(stderr, "Modkey array looks like %s\n", ad->modkeys); } +void +buffer_add(const Arg *arg, Window_Data *wd) +{ + // Window_Data *wd = data; + Buffer_Data *td; + + td = calloc(1, sizeof(Buffer_Data)); + if (!td) return; + + wd->buf_total++; + + td->window = wd; + // td->web = elm_web_add(wd->win); + td->buf_number = wd->buf_total; + td->inspector_enabled = EINA_FALSE; + td->proxy_enabled = EINA_FALSE; + td->history_enabled = EINA_TRUE; + td->cookies_enabled = EINA_FALSE; + // td->view = elm_web_webkit_view_get(td->web); + td->view = ewk_view_add_with_context(evas_object_evas_get(wd->win), wd->app->ewk_context); + // ewk_view_theme_set(td->view, "/usr/share/ewebkit-0/themes/default.edj"); + + wd->buffer_list = eina_list_append(wd->buffer_list, td); + + // elm_web_window_create_hook_set(td->web, webview_create_window_cb, wd); + // elm_web_console_message_hook_set(td->web, webview_console_cb, td); + // ewk_view_setting_user_agent_set(td->view, "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.514.0 Safari/534.7"); + // ewk_view_history_enable_set(td->view, EINA_TRUE); + + // elm_web_inwin_mode_set(td->web, EINA_TRUE); + evas_object_size_hint_weight_set(td->view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(td->view, EVAS_HINT_FILL, EVAS_HINT_FILL); + + elm_naviframe_item_simple_push(wd->naviframe, td->view); + + /* + if (wd->cur_buf) + elm_naviframe_item_insert_after(wd->naviframe, ad->cur_buf->view, ); + else + elm_naviframe_item_simple_push(ad->naviframe, td->web); + */ + + evas_object_data_set(td->view, "buffer_data", td); + + /* signals */ + evas_object_smart_callback_add(td->view, "title,changed", webview_title_changed_cb, td); + evas_object_smart_callback_add(td->view, "uri,changed", webview_uri_changed_cb, td); + evas_object_smart_callback_add(td->view, "load,progress", webview_progress_changed_cb, td); + // evas_object_smart_callback_add(td->web, "load,started", webview_load_committed_cb, td); + // evas_object_smart_callback_add(td->view, "load,document,finished", webview_document_finished_cb, td); + evas_object_smart_callback_add(td->view, "load,finished", webview_load_finished_cb, td); + evas_object_smart_callback_add(td->view, "download,request", webview_download_cb, td); + evas_object_smart_callback_add(td->view, "link,hover,in", webview_hoverlink_cb, td); + evas_object_smart_callback_add(td->view, "link,hover,out", webview_hoverlink_out_cb, td); + evas_object_smart_callback_add(td->view, "inputmethod,changed", inputmethod_changed_cb, td); + + /* these signals are not offered by elm_web */ + // evas_object_smart_callback_add(td->view, "load,error", load_error_cb, td); + evas_object_smart_callback_add(td->view, "inspector,view,create", webview_inspector_cb, td); + evas_object_smart_callback_add(td->view, "inspector,view,close", webview_inspector_close_cb, td); + evas_object_smart_callback_add(td->view, "protocolhandler,isregistered", protocol_register_cb, td); + evas_object_smart_callback_add(td->view, "icon,received", icon_received_cb, td); + evas_object_smart_callback_add(td->view, "xss,detected", xss_detected_cb, td); + evas_object_smart_callback_add(td->view, "populate,visited,links", populate_visited_links_cb, td); + + evas_object_event_callback_add(td->view, EVAS_CALLBACK_FREE, _web_free_cb, td); + evas_object_event_callback_add(td->view, EVAS_CALLBACK_KEY_DOWN, webview_keypress_cb, td); + evas_object_event_callback_add(td->view, EVAS_CALLBACK_KEY_DOWN, webview_keypress_cb, td); + evas_object_event_callback_add(td->view, EVAS_CALLBACK_FOCUS_IN, webview_focus_in_cb, td); + evas_object_event_callback_add(td->view, EVAS_CALLBACK_FOCUS_OUT, webview_focus_out_cb, td); + // evas_object_event_callback_add(td->web, EVAS_CALLBACK_MOUSE_UP, notify_event_cb, td); + evas_object_event_callback_add(td->view, EVAS_CALLBACK_MOUSE_WHEEL, webview_mousewheel_cb, td); + + if (arg->i & CustomUrl) + ewk_view_uri_set(td->view, arg->s); + else + ewk_view_uri_set(td->view, config_home_page_get(wd->app->config)); + + if (arg->i & CreateAndShow) + buffer_current_set(td); +} + +void +buffer_current_set(Buffer_Data *new_buf) +{ + Window_Data *wd = new_buf->window; + Buffer_Data *old_buf = wd->cur_buf; + App_Data *ad = wd->app; + + if (new_buf == old_buf || ad->exiting) + return; + + if (old_buf) { + // ewk_view_visibility_state_set(old_buf->view, EWK_PAGE_VISIBILITY_STATE_HIDDEN, 0); + // if (old_buf->inspector_enabled) + // ewk_view_web_inspector_close(old_buf->view); + // if (old_buf->proxy_enabled) + // g_object_set(ad->soup_session, "proxy-uri", NULL, NULL); + } + + wd->cur_buf = new_buf; + + if (new_buf) { + // ewk_view_visibility_state_set(new_buf->view, EWK_PAGE_VISIBILITY_STATE_VISIBLE, 0); + //if (new_buf->inspector_enabled) { + // ewk_view_web_inspector_show(new_buf->view); + //} + + elm_naviframe_item_simple_promote(wd->naviframe, new_buf->view); + /* + if (new_buf->proxy_enabled) + enable_proxy(ad->cur_buf); + + if (new_buf->cookies_enabled) + ewk_cookies_policy_set(EWK_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY); + else + ewk_cookies_policy_set(EWK_COOKIE_JAR_ACCEPT_NEVER); + */ + update_url(ewk_view_uri_get(new_buf->view), wd); + } +} + +void +window_add(const Arg *arg, App_Data *ad) +{ + // App_Data *ad = data; + Window_Data *wd; + Evas_Modifier_Mask mask; + Evas *e; + unsigned int i; + + wd = calloc(1, sizeof(Window_Data)); + if (!wd) return; + + Evas_Object *win, *bg, *box, *status_bar, *url, *naviframe, *status_url; + Evas_Object *status_state, *event_box, *web_inspector, *progress; + + elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); + + win = elm_win_add(NULL, "viking", ELM_WIN_BASIC); + elm_win_autodel_set(win, EINA_TRUE); + // elm_win_screen_constrain_set(win, EINA_TRUE); + evas_object_smart_callback_add(win, "delete,request", _win_del_request_cb, wd); + + // elm_win_keyboard_mode_set(win, ELM_WIN_KEYBOARD_ON); + + e = evas_object_evas_get(win); + for (i = 0; i < LENGTH(keys); i++) { + mask = evas_key_modifier_mask_get(e, keys[i].mask); + if (keys[i].key && !evas_object_key_grab(win, keys[i].key, mask, 0, EINA_FALSE)) + fprintf(stderr, "grab failed mask = %s, key = %s\n", keys[i].mask , keys[i].key); + } + + /* program bacground */ + bg = elm_bg_add(win); + evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, bg); + elm_bg_color_set(bg, 0, 0, 0); + evas_object_layer_set(bg, EVAS_LAYER_MIN); + evas_object_show(bg); + + /* main box that everything goes into, resizes with window */ + box = elm_box_add(win); + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, box); + evas_object_show(box); + + /* widget that shows the web pages */ + naviframe = elm_naviframe_add(win); + evas_object_size_hint_weight_set(naviframe, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(naviframe, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(box, naviframe); + evas_object_show(naviframe); + + /* status bar container */ + status_bar = elm_box_add(win); + elm_box_homogeneous_set(status_bar, EINA_FALSE); + elm_box_horizontal_set(status_bar, EINA_TRUE); + evas_object_size_hint_align_set(status_bar, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(box, status_bar); + evas_object_show(status_bar); + + /* status bar url */ + status_url = elm_label_add(win); + evas_object_size_hint_weight_set(status_url, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(status_url, 0.0, EVAS_HINT_FILL); + elm_box_pack_end(status_bar, status_url); + evas_object_show(status_url); + + /* status bar state (load progress, mod keys, scroll %) */ + status_state = elm_label_add(win); + evas_object_size_hint_weight_set(status_state, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(status_state, 1.0, EVAS_HINT_FILL); + elm_box_pack_end(status_bar, status_state); + evas_object_show(status_state); + + progress = elm_progressbar_add(win); + evas_object_size_hint_align_set(progress, 1.0, EVAS_HINT_FILL); + elm_progressbar_horizontal_set(progress, EINA_TRUE); + elm_box_pack_end(status_bar, progress); + evas_object_show(progress); + + /* invisible until activated web inspector */ + web_inspector = elm_box_add(win); + evas_object_size_hint_align_set(web_inspector, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(box, web_inspector); + evas_object_hide(web_inspector); + + /* invisible event box, populated on tab completions and :ls */ + event_box = elm_box_add(win); + evas_object_size_hint_align_set(event_box, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(box, event_box); +// evas_object_hide(event_box); + + /* main entry widget */ + url = elm_entry_add(win); + elm_entry_single_line_set(url, EINA_TRUE); + elm_entry_scrollable_set(url, EINA_TRUE); + evas_object_size_hint_weight_set(url, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(url, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(box, url); + elm_entry_text_style_user_push(url, "DEFAULT='font=Monospace font_size=12'"); + evas_object_show(url); + + evas_object_smart_callback_add(url, "activated", inputbox_activate_cb, wd); + evas_object_smart_callback_add(url, "changed", inputbox_changed_cb, wd); + evas_object_event_callback_add(url, EVAS_CALLBACK_KEY_DOWN, inputbox_keypress_cb, wd); + evas_object_event_callback_add(url, EVAS_CALLBACK_KEY_UP, inputbox_keyrelease_cb, wd); + + wd->win = win; + wd->main_box = box; + wd->naviframe = naviframe; + wd->url = url; + wd->status_url = status_url; + wd->status_state = status_state; + wd->event_box = event_box; + wd->web_inspector = web_inspector; + wd->progress_bar = progress; + wd->app = ad; + + wd->mode = ModeNormal; + wd->echo_active = EINA_TRUE; + + ad->windows = eina_list_append(ad->windows, wd); + + if (arg->i & DefaultBuf) { + Arg arg; + arg.i = DefaultURL | CreateAndShow; + buffer_add(&arg, wd); + } + + evas_object_resize(wd->win, 1024, 768); + evas_object_show(wd->win); +} + +Eina_Bool +echo(const Arg *arg, void *data) +{ + Window_Data *ad = data; + int index = !arg->s ? 0 : arg->i & (~NoAutoHide); + + if (index < Info || index > Error) + return TRUE; + +// printf("echo(%s)\n", arg->s); + // if (!gtk_widget_is_focus(GTK_WIDGET(inputbox))) { + if (!elm_object_focus_get(ad->url)) { + // set_widget_font_and_color(ad->url, urlboxfont[index], urlboxbgcolor[index], urlboxcolor[index]); + // gtk_entry_set_text(GTK_ENTRY(inputbox), !arg->s ? "" : arg->s); + elm_entry_entry_set(ad->url, !arg->s ? "" : arg->s); + } + + return TRUE; +} + +void +update_state(void *data) +{ + // char *markup; + Window_Data *wd = data; + App_Data *ad = wd->app; + + if (!wd->cur_buf) + return; + + // Evas_Object *view = wd->cur_buf->view; + // Evas_Object *frame = ewk_view_frame_main_get(view); + int download_count = eina_hash_population(ad->downloads); + // GString *status = g_string_new(""); + char status[512] = ""; + + /* construct the status line */ + + strcat(status, "<font=Monospace font_size=12 color=#FFF backing=on backing_color=#000>"); + + /* count, modkey and input buffer */ + // g_string_append_printf(status, "%.0d", count); + char *count_formatted = strdup_printf("%.0d", wd->count); + strcat(status, count_formatted); + free(count_formatted); + + // if (ad->current_modkey) g_string_append_c(status, ad->current_modkey); + if (wd->current_modkey) strcat(status, &wd->current_modkey); + + if (download_count) { + char *download_status = strdup_printf(" %d DL%s", download_count, + (download_count == 1) ? "" : "s"); + strcat(status, download_status); + free(download_status); + } + + /* put a notification if we are zoomed + // double zoom = elm_web_zoom_get(wd->cur_buf->web); + float zoom = ewk_view_zoom_get(wd->cur_buf->view); + if (zoom != 1) { + char *zoom_str = strdup_printf(" %0.2lfx", zoom); + strcat(status, zoom_str); + free(zoom_str); + } + */ + + /* always show the current scroll position + int x, y, w, h, val; + ewk_frame_scroll_pos_get(frame, &x, &y); + ewk_frame_scroll_size_get(frame, &w, &h); + + val = (int) ((float) y / h * 100); + + if (h == 0) + strcat(status, " All"); + else if (val == 0) + strcat(status, " Top"); + else if (val == 100) + strcat(status, " Bot"); + else { + char *percent_scrolled = strdup_printf(" %d%%", val); + strcat(status, percent_scrolled); + free(percent_scrolled); + } + */ + + elm_object_text_set(wd->status_state, status); + + int state_width, window_width; + evas_object_geometry_get(wd->status_state, NULL, NULL, &state_width, NULL); + evas_object_geometry_get(wd->win, NULL, NULL, &window_width, NULL); + + elm_label_wrap_width_set(wd->status_url, window_width - state_width); + + // update_url(elm_web_uri_get(ad->current_web), data); + // elm_box_recalculate(ad->status_bar); + // recalculate_status_bar(data); +} + +char* +/* must free() the return value */ +status_flags(void *data) +{ + char *end; + Buffer_Data *bd = data; + char *flags = calloc(32, 1); + + strcat(flags, "["); + strcat(flags, bd->proxy_enabled ? "P" : " "); + strcat(flags, bd->inspector_enabled ? "I" : " "); + strcat(flags, bd->history_enabled ? "H" : " "); + strcat(flags, bd->cookies_enabled ? "C" : " "); + end = strdup_printf("] %2i ", bd->buf_number); + strcat(flags, end); + free(end); + + return flags; +} + +void +update_url(const char *uri, void *data) +{ + char *tmp; + char before[] = " ["; + char after[] = "]"; + char url_buf[1024] = ""; + Window_Data *ad = data; + Buffer_Data *bd = ad->cur_buf; + + if (uri == NULL) + return; + + Eina_Bool back = ewk_view_back_possible(bd->view); + Eina_Bool fwd = ewk_view_forward_possible(bd->view); + + // Evas_Object *frame = ewk_view_frame_main_get(bd->view); + char *url_color = "#FFF"; + + /* + if (!strncmp(uri, "https://", 8)) { + Ewk_Certificate_Status cert_status = ewk_frame_certificate_status_get(frame); + if (cert_status & EWK_CERTIFICATE_STATUS_TRUSTED) + url_color = "#6F6"; + else if (cert_status & EWK_CERTIFICATE_STATUS_UNTRUSTED) + url_color = "#F66"; + + uri += 8; + } + else + uri += 7; + */ + + if (!back && !fwd) + before[0] = after[0] = '\0'; + + strcat(url_buf, "<font=Monospace font_size=12 color=#FFF>"); + tmp = status_flags(bd); + strcat(url_buf, tmp); + free(tmp); + tmp = strdup_printf("<color=%s>%s<color=#FFF>%s%s%s%s", + url_color, uri, before, back ? "+" : "", fwd ? "-" : "", after); + strcat(url_buf, tmp); + free(tmp); + + int state_width, window_width; + evas_object_geometry_get(ad->status_state, NULL, NULL, &state_width, NULL); + evas_object_geometry_get(ad->win, NULL, NULL, &window_width, NULL); + elm_label_wrap_width_set(ad->status_url, window_width - state_width); + + elm_object_text_set(ad->status_url, url_buf); + // elm_label_line_wrap_set(ad->status_url, ELM_WRAP_CHAR); + // elm_label_ellipsis_set(ad->status_url, EINA_TRUE); +} + +Eina_Bool +enable_proxy(Buffer_Data *bd) +{ + SoupURI *soup_uri; + char *proxy_uri, *new; + + printf("trying to enable proxy .. "); + + proxy_uri = getenv("http_proxy"); + if (proxy_uri == NULL) + proxy_uri = getenv("HTTP_PROXY"); + + if (proxy_uri != NULL && 0 < strlen(proxy_uri)) { + new = strstr(proxy_uri, "http://") ? + strdup(proxy_uri) : strdup_printf("http://%s", proxy_uri); + + soup_uri = soup_uri_new(new); + /* really wish there was per-view proxy support in webkit */ + g_object_set(bd->window->app->soup_session, "proxy-uri", soup_uri, NULL); + + printf("success! (%s)\n", new); + bd->proxy_enabled = EINA_TRUE; + + soup_uri_free(soup_uri); + free(new); + return EINA_TRUE; + } + else { + printf("HTTP_PROXY not set.\n"); + return EINA_FALSE; + } +} + +/* +void +set_widget_font_and_color(Evas_Object *widget, const char *font_str, const char *bg_color_str, const char *fg_color_str) +{ + GdkColor fg_color; + GdkColor bg_color; + PangoFontDescription *font; + + font = pango_font_description_from_string(font_str); + gtk_widget_modify_font(widget, font); + pango_font_description_free(font); + + if (fg_color_str) + gdk_color_parse(fg_color_str, &fg_color); + if (bg_color_str) + gdk_color_parse(bg_color_str, &bg_color); + + gtk_widget_modify_text(widget, GTK_STATE_NORMAL, fg_color_str ? &fg_color : NULL); + gtk_widget_modify_base(widget, GTK_STATE_NORMAL, bg_color_str ? &bg_color : NULL); + + return; +} +*/ + + diff --git a/src/utilities.h b/src/utilities.h @@ -36,9 +36,19 @@ char * search_word(int whichword); void userscript_hooks_start(const char*); void userscript_hooks_end(const char*); void setup_modkeys(void *data); +void buffer_add(const Arg *, Window_Data *); +void window_add(const Arg *, App_Data *); +Eina_Bool echo(const Arg *arg, void *); +void update_state(void *); +void update_url(const char *, void *); +void buffer_current_set(Buffer_Data *td); +char* status_flags(void *data); +Eina_Bool enable_proxy(Buffer_Data *bd); + char *find_uri_for_searchengine(const char *handle); void make_searchengines_list(Searchengine *searchengines, int length); void make_uri_handlers_list(URIHandler *uri_handlers, int length); Eina_Bool open_handler(char *uri); + diff --git a/src/viking.h b/src/viking.h @@ -92,6 +92,9 @@ enum { Wrapping = 1 << 3 }; enum { CreateWindow = 1 << 1, DeleteWindow = 1 << 2}; +enum { DefaultBuf = 1 << 1}; +enum { CustomUrl = 1 << 1, DefaultURL = 1 << 2, CreateAndShow = 1 << 3}; + /* structs here */ typedef struct { @@ -201,3 +204,82 @@ typedef enum BACKING_STORE_TILED } Backing_Store; + +typedef struct _Buffer_Data Buffer_Data; + +typedef struct +{ + Eina_List *windows; + Eina_Hash *downloads; + + KeyList *keylistroot; + float zoomstep; + char *modkeys; + int log_domain; + + SoupSession *soup_session; + Hist *history; + Config *config; + Session *session; + Ecore_Timer *session_save_timer; + Ewk_Context *ewk_context; + Ewk_Cookie_Manager *cookie_manager; + + Eina_Bool exiting : 1; +} App_Data; + +typedef struct +{ + Evas_Object *win; + Evas_Object *main_box; + Evas_Object *naviframe; + Evas_Object *url; /* "inputbox" */ + Evas_Object *event_box; + Evas_Object *status_bar; + Evas_Object *status_url; + Evas_Object *status_state; + Evas_Object *web_inspector; + Evas_Object *progress_bar; + + Eina_List *commandhistory; + Eina_List *buffer_list; + + int commandpointer; + unsigned int mode; + unsigned int count; + unsigned int buf_total; + Eina_Bool search_direction; + Eina_Bool echo_active; + Eina_Bool manual_focus; + + char current_modkey; + char rememberedURI[1024]; + char followTarget[8]; + char *error_msg; + char *search_handle; + + Buffer_Data *cur_buf; + App_Data *app; +} Window_Data; + +struct _Buffer_Data +{ + Evas_Object *view; + unsigned int buf_number; + + Eina_Bool inspector_enabled; + Evas_Object *web_inspector; + + Eina_Bool proxy_enabled; + Eina_Bool history_enabled; + Eina_Bool cookies_enabled; + + Window_Data *window; +}; + +struct dl { + long int dltotal; + long int dlnow; +}; + +