commit a86f816552d8ebb18899a5edcd7e6b2d74b99114
parent 3ad1f7a60c2f4a8fda16b4343ede3c03d5a424e0
Author: Kyle Milz <kmilz@ucalgary.ca>
Date: Sat, 6 Oct 2012 16:09:12 -0600
move entire config function into main
Diffstat:
M | src/main.c | | | 118 | +++++++++++++++++++++++++++++++++++++------------------------------------------ |
1 file changed, 55 insertions(+), 63 deletions(-)
diff --git a/src/main.c b/src/main.c
@@ -142,15 +142,38 @@ uri_sanitize(const char *uri) {
return NULL;
}
-static void
-setup_config(App_Data *ad, int argc, char **argv)
+static Eina_Bool
+session_restore(void)
+{
+ return EINA_FALSE;
+}
+
+static URIHandler uri_handlers[] = {
+ { "mailto:", "x-terminal-emulator -e mutt %s" },
+ { "ftp://", "x-terminal-emulator -e wget ftp://%s" },
+};
+
+/* search engines */
+static Searchengine searchengines[] = {
+ { "d", "https://duckduckgo.com/?q=%s&t=Vimprobable" },
+ { "i", "http://ixquick.com/do/metasearch.pl?query=%s" },
+ { "w", "https://secure.wikimedia.org/wikipedia/en/w/index.php?title=Special%%3ASearch&search=%s&go=Go" },
+ { "wd", "https://secure.wikimedia.org/wikipedia/de/w/index.php?title=Special%%3ASearch&search=%s&go=Go" },
+ { "dd", "https://duckduckgo.com/html/?q=%s&t=Vimprobable" },
+};
+
+EAPI_MAIN int
+elm_main(int argc, char *argv[])
{
+ App_Data *ad;
char *basename, *uri, path[PATH_MAX];
Config *config;
Hist *hist;
Session *session;
size_t dirlen;
int args;
+ Ewk_Context *ewk_context;
+ Ewk_Cookie_Manager *cookie_manager;
Ecore_Timer *session_save_timer = NULL;
Eina_Bool quit_option = EINA_FALSE;
@@ -166,13 +189,21 @@ setup_config(App_Data *ad, int argc, char **argv)
if (args < 0)
ERR("Could not parse command line options.");
+
+ if (!elm_need_web())
+ return -1;
+
viking_state_init();
- dirlen = snprintf(path, sizeof(path), "%s/viking", efreet_config_home_get());
+ /* calloc zeros the memory!! */
+ ad = calloc(1, sizeof(App_Data));
+ if (!ad) return -1;
+
+ /* see if ~/.config/viking exists and create it if not */
+ dirlen = snprintf(path, sizeof(path), "%s/viking", efreet_config_home_get());
if (dirlen >= sizeof(path))
ERR("Path is too long: %s/viking", efreet_config_home_get());
-
if (!ecore_file_mkpath(path))
ERR("Could not create %s", path);
@@ -181,11 +212,13 @@ setup_config(App_Data *ad, int argc, char **argv)
basename++;
dirlen++;
+ ewk_context = ewk_context_default_get();
+
eina_strlcpy(basename, "cookies.txt", sizeof(path) - dirlen);
- printf("cookie path = %s\n", path);
- ewk_cookie_manager_persistent_storage_set(ad->cookie_manager, path,
+ cookie_manager = ewk_context_cookie_manager_get(ewk_context);
+ ewk_cookie_manager_persistent_storage_set(cookie_manager, path,
EWK_COOKIE_PERSISTENT_STORAGE_TEXT);
- ewk_cookie_manager_accept_policy_set(ad->cookie_manager,
+ ewk_cookie_manager_accept_policy_set(cookie_manager,
EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY);
eina_strlcpy(basename, "config.eet", sizeof(path) - dirlen);
@@ -224,68 +257,34 @@ setup_config(App_Data *ad, int argc, char **argv)
ERR("Could not save new session file at %s", path);
}
- session_save_timer = ecore_timer_loop_add(15, _cb_session_save, NULL);
+ session_save_timer = ecore_timer_loop_add(30, _cb_session_save, NULL);
if (!session_save_timer)
ERR("Could not register session save timer");
+ /* url included on command line */
if (args < argc) {
uri = uri_sanitize(argv[args]);
printf("setup_config() cmd line uri = %s\n", uri);
free(uri);
}
+ make_searchengines_list(searchengines, LENGTH(searchengines));
+ make_uri_handlers_list(uri_handlers, LENGTH(uri_handlers));
+
+ setup_modkeys(ad);
ad->config = config;
ad->history = hist;
ad->session = session;
ad->session_save_timer = session_save_timer;
-}
-
-static Eina_Bool
-session_restore(void)
-{
- return EINA_FALSE;
-}
-
-static URIHandler uri_handlers[] = {
- { "mailto:", "x-terminal-emulator -e mutt %s" },
- { "ftp://", "x-terminal-emulator -e wget ftp://%s" },
-};
-
-/* search engines */
-static Searchengine searchengines[] = {
- { "d", "https://duckduckgo.com/?q=%s&t=Vimprobable" },
- { "i", "http://ixquick.com/do/metasearch.pl?query=%s" },
- { "w", "https://secure.wikimedia.org/wikipedia/en/w/index.php?title=Special%%3ASearch&search=%s&go=Go" },
- { "wd", "https://secure.wikimedia.org/wikipedia/de/w/index.php?title=Special%%3ASearch&search=%s&go=Go" },
- { "dd", "https://duckduckgo.com/html/?q=%s&t=Vimprobable" },
-};
-
-EAPI_MAIN int
-elm_main(int argc, char *argv[])
-{
- App_Data *ad;
+ ad->ewk_context = ewk_context;
+ ad->cookie_manager = cookie_manager;
- if (!elm_need_web())
- return -1;
-
- /* calloc zeros the memory!! */
- ad = calloc(1, sizeof(App_Data));
- if (!ad) return -1;
-
- 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);
-
- // 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);
+ /* initialize fields that are non-zero */
+ ad->keylistroot = make_keyslist();
+ ad->zoomstep = 0.1f;
- if (config_restore_state_get(ad->config) && session_windows_count(ad->session) > 0
+ /* try to restore session */
+ if (config_restore_state_get(config) && session_windows_count(session) > 0
&& session_restore()) {
printf("main() session restored successfully.\n");
}
@@ -295,13 +294,6 @@ elm_main(int argc, char *argv[])
window_add(&arg, ad);
}
- make_searchengines_list(searchengines, LENGTH(searchengines));
- make_uri_handlers_list(uri_handlers, LENGTH(uri_handlers));
-
- /* initialize fields that are non-zero */
- ad->keylistroot = make_keyslist();
- ad->zoomstep = 0.1f;
-
/* main loop */
elm_run();
@@ -311,8 +303,8 @@ 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_List *w;
void *data;