Hiroyuki Ikezoe
ikezo****@users*****
Sun Dec 31 10:36:03 JST 2006
Index: kazehakase/src/Makefile.am diff -u kazehakase/src/Makefile.am:1.122 kazehakase/src/Makefile.am:1.123 --- kazehakase/src/Makefile.am:1.122 Wed Dec 6 20:04:24 2006 +++ kazehakase/src/Makefile.am Sun Dec 31 10:36:03 2006 @@ -57,6 +57,7 @@ libkazehakase_public_h_sources = \ kazehakase.h \ + kz-app.h \ kz-embed.h \ kz-embed-event.h \ kz-gesture.h \ @@ -93,6 +94,7 @@ $(libkazehakase_public_h_sources) libkazehakase_la_SOURCES = \ + kz-app.c \ kz-embed.c \ kz-embed-event.c \ kz-gesture.c \ Index: kazehakase/src/kazehakase.h diff -u kazehakase/src/kazehakase.h:1.41 kazehakase/src/kazehakase.h:1.42 --- kazehakase/src/kazehakase.h:1.41 Sat Dec 30 21:51:02 2006 +++ kazehakase/src/kazehakase.h Sun Dec 31 10:36:03 2006 @@ -27,12 +27,8 @@ #include <string.h> #include <glib.h> +#include "kz-app.h" #include "kz-profile.h" -#include "kz-search.h" -#include "bookmarks/kz-root-bookmark.h" -#if USE_MIGEMO -#include "migemo.h" -#endif G_BEGIN_DECLS #define KAZEHAKASE_URI "http://kazehakase.sourceforge.jp/" @@ -55,33 +51,36 @@ KzUILevel kz_ui_level_from_str (const gchar *level); const gchar *kz_ui_level_to_str (KzUILevel level); - -extern KzProfile *kz_global_profile; -extern KzProfile *kz_proxy; -extern KzRootBookmark *kz_bookmarks; -#if USE_MIGEMO -extern Migemo *migemo; -#endif +extern KzApp *kz_app; extern gboolean is_restoring_session; -extern KzSearch *kz_search; - #define KZ_CONF_GET(s, k, v, t) \ - kz_profile_get_value(kz_global_profile, \ + kz_profile_get_value(kz_app_get_profile(kz_app), \ s, k, &(v), sizeof(v), \ KZ_PROFILE_VALUE_TYPE_##t) #define KZ_CONF_SET(s, k, v, t) \ - kz_profile_set_value(kz_global_profile, \ + kz_profile_set_value(kz_app_get_profile(kz_app), \ s, k, &(v), sizeof(v), \ KZ_PROFILE_VALUE_TYPE_##t) #define KZ_CONF_GET_STR(s, k) \ - kz_profile_get_string(kz_global_profile, s, k) + kz_profile_get_string(kz_app_get_profile(kz_app), s, k) #define KZ_CONF_SET_STR(s, k, v) \ - kz_profile_set_value(kz_global_profile, \ + kz_profile_set_value(kz_app_get_profile(kz_app), \ s, k, \ (gchar *)v, \ strlen((gchar *)v) + 1, \ KZ_PROFILE_VALUE_TYPE_STRING) +#define KZ_GET_GLOBAL_PROFILE kz_app_get_profile(kz_app) +#define KZ_GET_PROXY kz_app_get_proxy(kz_app) +#define KZ_GET_ROOT_BOOKMARK kz_app_get_root_bookmark(kz_app) +#define KZ_GET_CURRENT_SESSION kz_app_get_root_bookmark(kz_app)->current_session +#define KZ_GET_MENU_BOOKMARK kz_app_get_root_bookmark(kz_app)->menu +#define KZ_GET_SMART_BOOKMARK kz_app_get_root_bookmark(kz_app)->smarts +#define KZ_GET_BAR_BOOKMARK kz_app_get_root_bookmark(kz_app)->bookmark_bars +#define KZ_GET_CLIP_BOOKMARK kz_app_get_root_bookmark(kz_app)->clip +#define KZ_GET_SEARCH kz_app_get_search(kz_app) +#define KZ_GET_WINDOW_LIST kz_app_get_window_list(kz_app) +#define KZ_GET_MIGEMO kz_app_get_migemo(kz_app) G_END_DECLS Index: kazehakase/src/kz-app.c diff -u /dev/null kazehakase/src/kz-app.c:1.1 --- /dev/null Sun Dec 31 10:36:03 2006 +++ kazehakase/src/kz-app.c Sun Dec 31 10:36:03 2006 @@ -0,0 +1,374 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* + * Copyright (C) 2004 Hiroyuki Ikezoe + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <stdlib.h> +#ifdef USE_SSL +#include <gcrypt.h> +#include <gnutls/gnutls.h> +#include <errno.h> +#include <pthread.h> +GCRY_THREAD_OPTION_PTHREAD_IMPL; +#endif + +#include "kazehakase.h" +#include "kz-app.h" +#include "kz-actions-tab.h" +#include "kz-ext.h" +#include "kz-icons.h" +#include "kz-tab-label.h" +#include "mozilla.h" +#include "glib-utils.h" +#include "utils.h" + +typedef struct _KzAppPrivate KzAppPrivate; +struct _KzAppPrivate +{ + GList *window_list; + KzFavicon *favicon; + KzSearch *search; + KzRootBookmark *bookmarks; + KzProfile *profile; + KzProfile *proxy; +#if USE_MIGEMO + Migemo *migemo; +#endif +}; + +#define KZ_APP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), KZ_TYPE_APP, KzAppPrivate)) + +static GObject *constructor (GType type, + guint n_props, + GObjectConstructParam *props); +static void dispose (GObject *object); + +static KzApp *the_kzapp = NULL; + +G_DEFINE_TYPE(KzApp, kz_app, G_TYPE_OBJECT) + +static void +kz_app_class_init (KzAppClass *klass) +{ + GObjectClass *object_class; + + kz_app_parent_class = g_type_class_peek_parent (klass); + object_class = (GObjectClass *) klass; + + object_class->constructor = constructor; + object_class->dispose = dispose; + + g_type_class_add_private (object_class, sizeof(KzAppPrivate)); +} + +static GObject * +constructor (GType type, + guint n_props, + GObjectConstructParam *props) +{ + GObject *object; + + if (!the_kzapp) + { + GObjectClass *klass = G_OBJECT_CLASS(kz_app_parent_class); + object = klass->constructor(type, n_props, props); + the_kzapp = KZ_APP(object); + } + else + { + object = g_object_ref(G_OBJECT(the_kzapp)); + } + return object; +} + +static void +prepare_dir (void) +{ + /* for thumbnails */ + make_thumbnails_dir(); + + /* for favicon */ + make_dir("favicon"); + + /* for popup */ + make_dir("popup"); + + /* for smart bookmark input history */ + make_dir("smartbookmark_history"); + + /* for storing form data */ + make_dir("form_data"); +} + +static void +kz_app_init (KzApp *kzapp) +{ + gchar *sysconf_file, *conf_file; + gchar *bookmark_file, *sys_bookmark_file; + gchar *clip_file, *current_session_file; + gchar *bookmark_bar_file, *sys_bookmark_bar_file; + gchar *smartbookmark_file, *sys_smartbookmark_file; + gchar *accel_prefs_file; + gchar *proxy_file, *sysproxy_file; + gchar *search_engine; + KzAppPrivate *priv = KZ_APP_GET_PRIVATE (kzapp); + + priv->window_list = NULL; + + /* load prefs */ + sysconf_file = g_strdup(KZ_SYSCONFDIR G_DIR_SEPARATOR_S"kzrc"); + conf_file = g_build_filename(g_get_home_dir(), + "."PACKAGE, + "kzrc", NULL); + + priv->profile = kz_profile_open(conf_file, sysconf_file); + + /* prepare history search engine */ + search_engine = kz_profile_get_string(priv->profile, "History" , "search_engine"); + if (search_engine) + { + if (!strcmp(search_engine, "hyperestraier") || + !strcmp(search_engine, "rast")) + priv->search = kz_search_new(search_engine); + + if (priv->search) + { + if (!kz_search_exist_index_dir(priv->search)) + kz_search_make_index(priv->search); + } + g_free(search_engine); + } + + /* load bookmarks */ + bookmark_file = g_build_filename(g_get_home_dir(), + "."PACKAGE, + "bookmarks.xml", + NULL); + sys_bookmark_file = g_build_filename(KZ_SYSCONFDIR, + "bookmarks.xml", + NULL); + + bookmark_bar_file = g_build_filename(g_get_home_dir(), + "."PACKAGE, + "bookmarkbar.xml", + NULL); + sys_bookmark_bar_file = g_build_filename(KZ_SYSCONFDIR, + "bookmarkbar.xml", + NULL); + clip_file = g_build_filename(g_get_home_dir(), + "."PACKAGE, + "clip.xml", + NULL); + smartbookmark_file = g_build_filename(g_get_home_dir(), + "."PACKAGE, + "smartbookmarks.xml", + NULL); + sys_smartbookmark_file= g_build_filename(KZ_SYSCONFDIR, + "smartbookmarks.xml", + NULL); + current_session_file = g_build_filename(g_get_home_dir(), + "."PACKAGE, + "current_session.xml", + NULL); + + priv->bookmarks = kz_root_bookmark_new(bookmark_file, sys_bookmark_file, + clip_file, NULL); + + kz_root_bookmark_add_smartbookmark_file(priv->bookmarks, + smartbookmark_file, + sys_smartbookmark_file); + kz_root_bookmark_add_bookmark_bar_file(priv->bookmarks, + bookmark_bar_file, + sys_bookmark_bar_file); + kz_root_bookmark_add_current_session_file(priv->bookmarks, + current_session_file); + + /* Load other prefs... */ + accel_prefs_file = g_build_filename (g_get_home_dir(), + "."PACKAGE, + "keyaccelrc", + NULL); + gtk_accel_map_load (accel_prefs_file); + + sysproxy_file = g_build_filename(KZ_SYSCONFDIR, "proxyrc", NULL); + proxy_file = g_build_filename (g_get_home_dir(), + "."PACKAGE, + "proxyrc", NULL); + priv->proxy = kz_profile_open(proxy_file, sysproxy_file); + + kz_icons_init(); + +#ifdef USE_SSL + /* initialize gnutls. this function should be called once. */ + gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); + gnutls_global_init (); +#endif + + kz_ext_init(); + + /* make dirs */ + prepare_dir(); + + g_free(sysconf_file); + g_free(conf_file); + g_free(bookmark_file); + g_free(sys_bookmark_file); + g_free(clip_file); + g_free(current_session_file); + g_free(bookmark_bar_file); + g_free(sys_bookmark_bar_file); + g_free(smartbookmark_file); + g_free(sys_smartbookmark_file); + g_free(accel_prefs_file); + g_free(sysproxy_file); + g_free(proxy_file); +} + + +static void +clean_history_cache (void) +{ + guint limit_days = 30; + gboolean limit = FALSE; + time_t limit_seconds; + + KZ_CONF_GET("History", "limit_days", limit_days, INT); + KZ_CONF_GET("History", "limit_cache", limit, BOOL); + if (limit) + { + gchar *history_timestamp, *image_dir; + limit_seconds = limit_days * 86400; + history_timestamp = g_build_filename(g_get_home_dir(), + HISTORY_DIR, + "timestamp", + NULL); + purge_history_file_by_timestamp(history_timestamp, limit_seconds); + g_free(history_timestamp); + + /* parge popup files */ + image_dir = g_build_filename(g_get_home_dir(), + IMAGE_DIR, + NULL); + purge_history_file(image_dir, limit_seconds); + g_free(image_dir); + } +} + +static void +dispose (GObject *object) +{ + gchar *accel_prefs_file; + KzAppPrivate *priv = KZ_APP_GET_PRIVATE(object); + + kz_ext_exit(); + + accel_prefs_file = g_build_filename(g_get_home_dir(), + "."PACKAGE, + "keyaccelrc", + NULL); + + gtk_accel_map_save(accel_prefs_file); + g_free(accel_prefs_file); + + mozilla_exit(); + + /* clean history cache */ + clean_history_cache(); + + kz_root_bookmark_save_all(priv->bookmarks); + g_object_unref(G_OBJECT(priv->bookmarks)); + + kz_profile_close(priv->profile); + kz_profile_close(priv->proxy); + + if (priv->search) + g_object_unref(priv->search); + +#if USE_MIGEMO + if (priv->migemo) + { + migemo_exit(); + priv->migemo = NULL; + } +#endif + priv->profile = NULL; + priv->proxy = NULL; + priv->bookmarks = NULL; + priv->search = NULL; + + if (G_OBJECT_CLASS (kz_app_parent_class)->dispose) + G_OBJECT_CLASS (kz_app_parent_class)->dispose(object); +} + + +KzApp * +kz_app_new (void) +{ + KzApp *kzapp = g_object_new(KZ_TYPE_APP, NULL); + + return kzapp; +} + + +KzFavicon * +kz_app_get_favicon (KzApp *app) +{ + return KZ_APP_GET_PRIVATE(app)->favicon; +} + +KzSearch * +kz_app_get_search (KzApp *app) +{ + return KZ_APP_GET_PRIVATE(app)->search; +} + +KzRootBookmark * +kz_app_get_root_bookmark (KzApp *app) +{ + return KZ_APP_GET_PRIVATE(app)->bookmarks; +} + +KzProfile * +kz_app_get_profile (KzApp *app) +{ + return KZ_APP_GET_PRIVATE(app)->profile; +} + +KzProfile * +kz_app_get_proxy (KzApp *app) +{ + return KZ_APP_GET_PRIVATE(app)->proxy; +} + +const GList * +kz_app_get_window_list (KzApp *app) +{ + return KZ_APP_GET_PRIVATE(app)->window_list; +} + +#if USE_MIGEMO +Migemo * +kz_app_get_migemo (KzApp *app) +{ + return KZ_APP_GET_PRIVATE(app)->migemo; +} +#endif Index: kazehakase/src/kz-app.h diff -u /dev/null kazehakase/src/kz-app.h:1.1 --- /dev/null Sun Dec 31 10:36:03 2006 +++ kazehakase/src/kz-app.h Sun Dec 31 10:36:03 2006 @@ -0,0 +1,66 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* + * Copyright (C) 2004 Hiroyuki Ikezoe + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __KZ_APP_H__ +#define __KZ_APP_H__ + +#include <gtk/gtk.h> + +#include "kz-favicon.h" +#include "kz-search.h" +#include "kz-profile.h" +#include "kz-root-bookmark.h" + +G_BEGIN_DECLS + +#define KZ_TYPE_APP (kz_app_get_type ()) +#define KZ_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KZ_TYPE_APP, KzApp)) +#define KZ_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KZ_TYPE_APP, KzAppClass)) +#define KZ_IS_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KZ_TYPE_APP)) +#define KZ_IS_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KZ_TYPE_APP)) +#define KZ_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KZ_TYPE_APP, KzAppClass)) + +typedef struct _KzApp KzApp; +typedef struct _KzAppClass KzAppClass; + +struct _KzApp +{ + GObject parent; +}; + +struct _KzAppClass +{ + GObjectClass parent_class; +}; + +GType kz_app_get_type (void) G_GNUC_CONST; + +KzApp *kz_app_new (void); + +KzFavicon *kz_app_get_favicon (KzApp *app); +KzSearch *kz_app_get_search (KzApp *app); +KzRootBookmark *kz_app_get_root_bookmark (KzApp *app); +KzProfile *kz_app_get_profile (KzApp *app); +KzProfile *kz_app_get_proxy (KzApp *app); +const GList *kz_app_get_window_list (KzApp *app); + +G_END_DECLS + +#endif /* __KZ_APP_H__ */ Index: kazehakase/src/kz-navi.c diff -u kazehakase/src/kz-navi.c:1.5 kazehakase/src/kz-navi.c:1.6 --- kazehakase/src/kz-navi.c:1.5 Sat Dec 2 15:37:45 2006 +++ kazehakase/src/kz-navi.c Sun Dec 31 10:36:03 2006 @@ -119,7 +119,7 @@ g_return_if_fail(navi); g_return_if_fail(navi->uri); - bars = kz_bookmark_get_children(kz_bookmarks->bookmark_bars); + bars = kz_bookmark_get_children(KZ_GET_BAR_BOOKMARK); g_return_if_fail(bars); folder = bars->data; Index: kazehakase/src/kz-prefs-win.c diff -u kazehakase/src/kz-prefs-win.c:1.33 kazehakase/src/kz-prefs-win.c:1.34 --- kazehakase/src/kz-prefs-win.c:1.33 Sat Dec 2 18:55:54 2006 +++ kazehakase/src/kz-prefs-win.c Sun Dec 31 10:36:03 2006 @@ -202,7 +202,7 @@ kz_prefs_win_reset_nav_tree(win); /* observe UI Level */ - g_signal_connect(kz_global_profile, + g_signal_connect(KZ_GET_GLOBAL_PROFILE, "changed::Global", G_CALLBACK(cb_profile_global_changed), win); } @@ -214,7 +214,7 @@ KzPrefsWinPrivate *priv = KZ_PREFS_WIN_GET_PRIVATE (object); g_signal_handlers_disconnect_by_func - (kz_global_profile, + (KZ_GET_GLOBAL_PROFILE, G_CALLBACK(cb_profile_global_changed), win); if (priv->page_list) Index: kazehakase/src/kz-proxy-item.c diff -u kazehakase/src/kz-proxy-item.c:1.10 kazehakase/src/kz-proxy-item.c:1.11 --- kazehakase/src/kz-proxy-item.c:1.10 Sat Dec 2 18:55:54 2006 +++ kazehakase/src/kz-proxy-item.c Sun Dec 31 10:36:03 2006 @@ -281,7 +281,7 @@ } #define KZ_CONF_PROXY_GET(s, k, v, t) \ - kz_profile_get_value(kz_proxy, \ + kz_profile_get_value(KZ_GET_PROXY, \ s, k, &(v), sizeof(v), \ KZ_PROFILE_VALUE_TYPE_##t) @@ -346,7 +346,7 @@ { GList *list, *node, *r; - list = kz_profile_enum_section(kz_proxy); + list = kz_profile_enum_section(KZ_GET_PROXY); r = NULL; for (node = list; node; node = g_list_next(node)) r = g_list_append(r, kz_proxy_find(node->data)); Index: kazehakase/src/kz-tab-label.c diff -u kazehakase/src/kz-tab-label.c:1.79 kazehakase/src/kz-tab-label.c:1.80 --- kazehakase/src/kz-tab-label.c:1.79 Sat Dec 2 18:55:54 2006 +++ kazehakase/src/kz-tab-label.c Sun Dec 31 10:36:03 2006 @@ -295,7 +295,7 @@ url_drag_types,n_url_drag_types, GDK_ACTION_MOVE); - g_signal_connect(kz_global_profile, "changed::Tab", + g_signal_connect(KZ_GET_GLOBAL_PROFILE, "changed::Tab", G_CALLBACK(cb_profile_changed), kztab); kz_tab_label_sync_to_profile(kztab); kz_tab_label_set_text(kztab, NULL); @@ -346,7 +346,7 @@ kztab = KZ_TAB_LABEL(object); priv = KZ_TAB_LABEL_GET_PRIVATE (kztab); - g_signal_handlers_disconnect_by_func(kz_global_profile, + g_signal_handlers_disconnect_by_func(KZ_GET_GLOBAL_PROFILE, G_CALLBACK(cb_profile_changed), kztab); if (kztab->kzembed) @@ -387,7 +387,7 @@ KZ_CONF_GET("Session", "save", save_session, BOOL); if (save_session && !kztab->kz->is_closing_all) - kz_bookmark_file_save(KZ_BOOKMARK_FILE(kz_bookmarks->current_session)); + kz_bookmark_file_save(KZ_BOOKMARK_FILE(KZ_GET_CURRENT_SESSION)); } if (kztab->kz) @@ -398,7 +398,7 @@ if (kztab->tooltips) { - gtk_object_sink(GTK_OBJECT(kztab->tooltips)); + g_object_ref_sink(GTK_OBJECT(kztab->tooltips)); kztab->tooltips = NULL; } @@ -1067,7 +1067,7 @@ /* save session */ KZ_CONF_GET("Session", "save", save_session, BOOL); if (save_session && !kztab->kz->is_closing_all) - kz_bookmark_file_save(KZ_BOOKMARK_FILE(kz_bookmarks->current_session)); + kz_bookmark_file_save(KZ_BOOKMARK_FILE(KZ_GET_CURRENT_SESSION)); note = GTK_NOTEBOOK(kztab->kz->notebook); if(gtk_notebook_page_num(note, GTK_WIDGET(embed)) == @@ -1203,7 +1203,7 @@ kz_bookmark_set_lock(kztab->history, lock); KZ_CONF_GET("Session", "save", save, BOOL); if (save) - kz_bookmark_file_save(KZ_BOOKMARK_FILE(kz_bookmarks->current_session)); + kz_bookmark_file_save(KZ_BOOKMARK_FILE(KZ_GET_CURRENT_SESSION)); kz_tab_label_sync_to_profile(kztab); } @@ -1233,7 +1233,7 @@ kz_bookmark_set_javascript(kztab->history, javascript); KZ_CONF_GET("Session", "save", save, BOOL); if (save) - kz_bookmark_file_save(KZ_BOOKMARK_FILE(kz_bookmarks->current_session)); + kz_bookmark_file_save(KZ_BOOKMARK_FILE(KZ_GET_CURRENT_SESSION)); kz_tab_label_sync_to_profile(kztab); } @@ -1304,7 +1304,7 @@ kz_bookmark_set_auto_refresh(kztab->history, auto_refresh); KZ_CONF_GET("Session", "save", save, BOOL); if (save) - kz_bookmark_file_save(KZ_BOOKMARK_FILE(kz_bookmarks->current_session)); + kz_bookmark_file_save(KZ_BOOKMARK_FILE(KZ_GET_CURRENT_SESSION)); kz_tab_label_sync_to_profile(kztab); } @@ -1362,11 +1362,11 @@ /* save session */ KZ_CONF_GET("Session", "save", save_session, BOOL); if (save_session && !kztab->kz->is_closing_all) - kz_bookmark_file_save(KZ_BOOKMARK_FILE(kz_bookmarks->current_session)); + kz_bookmark_file_save(KZ_BOOKMARK_FILE(KZ_GET_CURRENT_SESSION)); } /* find the bookmark which has the same uri from the system bookmark */ uri = kz_embed_get_location(kztab->kzembed); - bookmark = kz_bookmark_find_bookmark_from_uri(kz_bookmarks->menu, + bookmark = kz_bookmark_find_bookmark_from_uri(KZ_GET_MENU_BOOKMARK, uri); if (bookmark) kz_bookmark_set_last_visited(bookmark, now.tv_sec); Index: kazehakase/src/kz-window.c diff -u kazehakase/src/kz-window.c:1.276 kazehakase/src/kz-window.c:1.277 --- kazehakase/src/kz-window.c:1.276 Sat Dec 2 15:23:06 2006 +++ kazehakase/src/kz-window.c Sun Dec 31 10:36:03 2006 @@ -423,7 +423,7 @@ kz->top_vbox = gtk_vbox_new(FALSE, 0); kz->bookmark_bars_area = gtk_vbox_new(FALSE, 0); - children = kz_bookmark_get_children(kz_bookmarks->bookmark_bars); + children = kz_bookmark_get_children(KZ_GET_BAR_BOOKMARK); for (node = children; node; node = g_list_next(node)) { GtkWidget *bar = GTK_WIDGET(kz_bookmark_bar_new(kz, node->data)); @@ -480,7 +480,7 @@ g_signal_connect(priv->gesture, "stack_motion", G_CALLBACK(cb_gesture_stack_motion), kz); - g_signal_connect(kz_global_profile, + g_signal_connect(KZ_GET_GLOBAL_PROFILE, "changed::Gesture", G_CALLBACK(cb_profile_gesture_changed), kz); g_signal_connect(kz, @@ -519,10 +519,10 @@ kz_window_sync_ui_level(kz); gtk_ui_manager_ensure_update(kz->menu_merge); - g_signal_connect(kz_global_profile, + g_signal_connect(KZ_GET_GLOBAL_PROFILE, "changed::Global", G_CALLBACK(cb_profile_global_changed), kz); - g_signal_connect(kz_proxy, + g_signal_connect(KZ_GET_PROXY, "changed", G_CALLBACK(cb_profile_proxy_changed), kz); @@ -541,16 +541,16 @@ } /* smart bookmark */ - g_signal_connect_after(kz_bookmarks->smarts, + g_signal_connect_after(KZ_GET_SMART_BOOKMARK, "insert-child", G_CALLBACK(cb_smartbookmark_insert_child), kz); - g_signal_connect_after(kz_bookmarks->smarts, + g_signal_connect_after(KZ_GET_SMART_BOOKMARK, "remove-child", G_CALLBACK(cb_smartbookmark_remove_child), kz); - g_signal_connect_after(kz_bookmarks->smarts, + g_signal_connect_after(KZ_GET_SMART_BOOKMARK, "children-reordered", G_CALLBACK(cb_smartbookmark_reordered), kz); - kz_actions_update_smartbookmarks(kz, kz_bookmarks->smarts); + kz_actions_update_smartbookmarks(kz, KZ_GET_SMART_BOOKMARK); /* bookmark bar */ gtk_box_pack_start(GTK_BOX(kz->top_vbox), @@ -566,13 +566,13 @@ gtk_widget_show(node->data); } - g_signal_connect_after(kz_bookmarks->bookmark_bars, + g_signal_connect_after(KZ_GET_BAR_BOOKMARK, "insert-child", G_CALLBACK(cb_bookmark_bars_insert_child), kz); - g_signal_connect_after(kz_bookmarks->bookmark_bars, + g_signal_connect_after(KZ_GET_BAR_BOOKMARK, "remove-child", G_CALLBACK(cb_bookmark_bars_remove_child), kz); - g_signal_connect_after(kz_bookmarks->bookmark_bars, + g_signal_connect_after(KZ_GET_BAR_BOOKMARK, "children-reordered", G_CALLBACK(cb_bookmark_bars_reordered), kz); @@ -641,7 +641,7 @@ window_list = g_list_append(window_list, kz); kz_bookmark_set_title(kz->tabs, "Window"); - kz_bookmark_append(kz_bookmarks->current_session, kz->tabs); + kz_bookmark_append(KZ_GET_CURRENT_SESSION, kz->tabs); /* kz_actions_set_sensitive(kz, KZ_EMBED(curpage)); */ kz_window_restore_state(kz); @@ -742,7 +742,7 @@ gtk_ui_manager_remove_ui(kz->menu_merge, priv->merge_id); priv->merge_id = 0; - kz_actions_remove_smartbookmarks(kz, kz_bookmarks->smarts); + kz_actions_remove_smartbookmarks(kz, KZ_GET_SMART_BOOKMARK); gtk_ui_manager_ensure_update(kz->menu_merge); } @@ -764,7 +764,7 @@ { kz_bookmark_menu_remove_menuitems(GTK_MENU_SHELL(widget), kz); kz_bookmark_menu_append_menuitems(GTK_MENU_SHELL(widget), kz, - kz_bookmarks->menu); + KZ_GET_MENU_BOOKMARK); } /* update clips */ @@ -776,7 +776,7 @@ { kz_bookmark_menu_remove_menuitems(GTK_MENU_SHELL(widget), kz); kz_bookmark_menu_append_menuitems(GTK_MENU_SHELL(widget), kz, - kz_bookmarks->clip); + KZ_GET_CLIP_BOOKMARK); } /* append recent close tab menu */ @@ -819,7 +819,7 @@ kz_actions_set_sensitive(kz, kzembed); /* smart bookmark */ - kz_actions_update_smartbookmarks(kz, kz_bookmarks->smarts); + kz_actions_update_smartbookmarks(kz, KZ_GET_SMART_BOOKMARK); g_free(ui_file); } @@ -1498,11 +1498,11 @@ if (kz->tabs) { - kz_bookmark_remove(kz_bookmarks->current_session, kz->tabs); + kz_bookmark_remove(KZ_GET_CURRENT_SESSION, kz->tabs); g_object_unref(kz->tabs); kz->tabs = NULL; - if (g_list_length(window_list) >0) + if (g_list_length(window_list) > 0) kz_window_store_session(kz); } if (kz->closed_tabs) @@ -1513,33 +1513,33 @@ kz->history_search = NULL; g_signal_handlers_disconnect_by_func - (kz_bookmarks->bookmark_bars, + (KZ_GET_BAR_BOOKMARK, G_CALLBACK(cb_bookmark_bars_insert_child), kz); g_signal_handlers_disconnect_by_func - (kz_bookmarks->bookmark_bars, + (KZ_GET_BAR_BOOKMARK, G_CALLBACK(cb_bookmark_bars_remove_child), kz); g_signal_handlers_disconnect_by_func - (kz_bookmarks->bookmark_bars, + (KZ_GET_BAR_BOOKMARK, G_CALLBACK(cb_bookmark_bars_reordered), kz); g_signal_handlers_disconnect_by_func - (kz_bookmarks->smarts, + (KZ_GET_SMART_BOOKMARK, G_CALLBACK(cb_smartbookmark_insert_child), kz); g_signal_handlers_disconnect_by_func - (kz_bookmarks->smarts, + (KZ_GET_SMART_BOOKMARK, G_CALLBACK(cb_smartbookmark_remove_child), kz); g_signal_handlers_disconnect_by_func - (kz_bookmarks->smarts, + (KZ_GET_SMART_BOOKMARK, G_CALLBACK(cb_smartbookmark_reordered), kz); g_signal_handlers_disconnect_by_func - (kz_global_profile, + (KZ_GET_GLOBAL_PROFILE, G_CALLBACK(cb_profile_global_changed), kz); g_signal_handlers_disconnect_by_func - (kz_global_profile, + (KZ_GET_GLOBAL_PROFILE, G_CALLBACK(cb_profile_gesture_changed), kz); g_signal_handlers_disconnect_by_func - (kz_proxy, + (KZ_GET_PROXY, G_CALLBACK(cb_profile_proxy_changed), kz); if (!kz_window_get_window_list()) @@ -1567,7 +1567,7 @@ items = kz_gesture_items_new(); - list = kz_profile_enum_key(kz_global_profile, "Gesture", FALSE); + list = kz_profile_enum_key(KZ_GET_GLOBAL_PROFILE, "Gesture", FALSE); for (node = list; node; node = g_list_next(node)) { @@ -1617,7 +1617,7 @@ KZ_CONF_GET("Session", "save", save_session, BOOL); if (save_session) - kz_bookmark_file_save(KZ_BOOKMARK_FILE(kz_bookmarks->current_session)); + kz_bookmark_file_save(KZ_BOOKMARK_FILE(KZ_GET_CURRENT_SESSION)); } @@ -1657,7 +1657,7 @@ g_return_if_fail(KZ_IS_WINDOW(kz)); priv = KZ_WINDOW_GET_PRIVATE (kz); - kz_profile_set_save_each_time(kz_global_profile, FALSE); + kz_profile_set_save_each_time(KZ_GET_GLOBAL_PROFILE, FALSE); /* * window size */ @@ -1744,8 +1744,8 @@ } } - kz_profile_set_save_each_time(kz_global_profile, TRUE); - kz_profile_save(kz_global_profile); + kz_profile_set_save_each_time(KZ_GET_GLOBAL_PROFILE, TRUE); + kz_profile_save(KZ_GET_GLOBAL_PROFILE); /* * Session Index: kazehakase/src/main.c diff -u kazehakase/src/main.c:1.126 kazehakase/src/main.c:1.127 --- kazehakase/src/main.c:1.126 Sat Dec 30 21:51:02 2006 +++ kazehakase/src/main.c Sun Dec 31 10:36:03 2006 @@ -50,13 +50,7 @@ #include "mozilla.h" -KzProfile *kz_global_profile = NULL; -KzProfile *kz_proxy = NULL; -KzRootBookmark *kz_bookmarks = NULL; -#if USE_MIGEMO -Migemo *migemo = NULL; -#endif -KzSearch *kz_search = NULL; +KzApp *kz_app = NULL; static gchar** action_array; static gchar* geometry_string; @@ -89,11 +83,11 @@ KzUILevel val; gchar level[16]; - g_return_val_if_fail(KZ_IS_PROFILE(kz_global_profile), + g_return_val_if_fail(KZ_IS_PROFILE(KZ_GET_GLOBAL_PROFILE), KZ_UI_LEVEL_BEGINNER); level[0] = '\0'; - kz_profile_get_value(kz_global_profile, + kz_profile_get_value(KZ_GET_GLOBAL_PROFILE, "Global", "ui_level", level, sizeof(level), KZ_PROFILE_VALUE_TYPE_STRING); @@ -498,227 +492,11 @@ } -static void -clean_history_cache (void) -{ - guint limit_days = 30; - gboolean limit = FALSE; - time_t limit_seconds; - - KZ_CONF_GET("History", "limit_days", limit_days, INT); - KZ_CONF_GET("History", "limit_cache", limit, BOOL); - if (limit) - { - gchar *history_timestamp, *image_dir; - limit_seconds = limit_days * 86400; - history_timestamp = g_build_filename(g_get_home_dir(), - HISTORY_DIR, - "timestamp", - NULL); - purge_history_file_by_timestamp(history_timestamp, limit_seconds); - g_free(history_timestamp); - - /* parge popup files */ - image_dir = g_build_filename(g_get_home_dir(), - IMAGE_DIR, - NULL); - purge_history_file(image_dir, limit_seconds); - g_free(image_dir); - } -} - -static void -prepare_dir (void) -{ - /* for thumbnails */ - make_thumbnails_dir(); - - /* for favicon */ - make_dir("favicon"); - - /* for popup */ - make_dir("popup"); - - /* for smart bookmark input history */ - make_dir("smartbookmark_history"); - - /* for storing form data */ - make_dir("form_data"); -} - /****************************************************************************** * * * Main * * * ******************************************************************************/ -static void -open_app_info (void) -{ - gchar *sysconf_file, *conf_file; - gchar *bookmark_file, *sys_bookmark_file; - gchar *clip_file, *current_session_file; - gchar *bookmark_bar_file, *sys_bookmark_bar_file; - gchar *smartbookmark_file, *sys_smartbookmark_file; - gchar *accel_prefs_file; - gchar *proxy_file, *sysproxy_file; - gchar *search_engine; - - /* load prefs */ - sysconf_file = g_strdup(KZ_SYSCONFDIR "/kzrc"); - conf_file = g_build_filename(g_get_home_dir(), - "."PACKAGE, - "kzrc", NULL); - - kz_global_profile = kz_profile_open(conf_file, sysconf_file); - - /* prepare history search engine */ - search_engine = KZ_CONF_GET_STR("History" , "search_engine"); - if (search_engine) - { - if (!strcmp(search_engine, "hyperestraier") || - !strcmp(search_engine, "rast")) - kz_search = kz_search_new(search_engine); - - if (kz_search) - { - if (!kz_search_exist_index_dir(kz_search)) - kz_search_make_index(kz_search); - } - g_free(search_engine); - } - - /* load bookmarks */ - bookmark_file = g_build_filename(g_get_home_dir(), - "."PACKAGE, - "bookmarks.xml", - NULL); - sys_bookmark_file = g_build_filename(KZ_SYSCONFDIR, - "bookmarks.xml", - NULL); - - bookmark_bar_file = g_build_filename(g_get_home_dir(), - "."PACKAGE, - "bookmarkbar.xml", - NULL); - sys_bookmark_bar_file = g_build_filename(KZ_SYSCONFDIR, - "bookmarkbar.xml", - NULL); - clip_file = g_build_filename(g_get_home_dir(), - "."PACKAGE, - "clip.xml", - NULL); - smartbookmark_file = g_build_filename(g_get_home_dir(), - "."PACKAGE, - "smartbookmarks.xml", - NULL); - sys_smartbookmark_file= g_build_filename(KZ_SYSCONFDIR, - "smartbookmarks.xml", - NULL); - current_session_file = g_build_filename(g_get_home_dir(), - "."PACKAGE, - "current_session.xml", - NULL); - - kz_bookmarks = kz_root_bookmark_new(bookmark_file, sys_bookmark_file, - clip_file, NULL); - - kz_root_bookmark_add_smartbookmark_file(kz_bookmarks, - smartbookmark_file, - sys_smartbookmark_file); - kz_root_bookmark_add_bookmark_bar_file(kz_bookmarks, - bookmark_bar_file, - sys_bookmark_bar_file); - kz_root_bookmark_add_current_session_file(kz_bookmarks, - current_session_file); - - /* Load other prefs... */ - accel_prefs_file = g_build_filename (g_get_home_dir(), - "."PACKAGE, - "keyaccelrc", - NULL); - gtk_accel_map_load (accel_prefs_file); - - sysproxy_file = g_build_filename(KZ_SYSCONFDIR, "proxyrc", NULL); - proxy_file = g_build_filename (g_get_home_dir(), - "."PACKAGE, - "proxyrc", NULL); - kz_proxy = kz_profile_open(proxy_file, sysproxy_file); - - kz_icons_init(); - mozilla_init(); - -#ifdef USE_SSL - /* initialize gnutls. this function should be called once. */ - gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); - gnutls_global_init (); -#endif - - kz_ext_init(); - - /* make dirs */ - prepare_dir(); - - g_free(sysconf_file); - g_free(conf_file); - g_free(bookmark_file); - g_free(sys_bookmark_file); - g_free(clip_file); - g_free(current_session_file); - g_free(bookmark_bar_file); - g_free(sys_bookmark_bar_file); - g_free(smartbookmark_file); - g_free(sys_smartbookmark_file); - g_free(accel_prefs_file); - g_free(sysproxy_file); - g_free(proxy_file); -} - - -static void -close_app_info (void) -{ - gchar *accel_prefs_file; - - kz_ext_exit(); - - accel_prefs_file = g_build_filename (g_get_home_dir(), - "."PACKAGE, - "keyaccelrc", - NULL); - - gtk_accel_map_save(accel_prefs_file); - g_free(accel_prefs_file); - - mozilla_exit(); - - /* clean history cache */ - clean_history_cache(); - - kz_root_bookmark_save_all(kz_bookmarks); - g_object_unref(G_OBJECT(kz_bookmarks)); - - kz_profile_close(kz_global_profile); - kz_profile_close(kz_proxy); - - if (kz_search) - g_object_unref(kz_search); - -#if USE_MIGEMO - if (migemo) - { - migemo_exit(); - migemo = NULL; - } -#endif - kz_global_profile = NULL; - kz_proxy = NULL; - kz_bookmarks = NULL; - kz_search = NULL; - - free_goption(); -} - - int main (int argc, char *argv[]) { @@ -776,8 +554,8 @@ return 0; /* found kazehakase process */ } - /* Load preference */ - open_app_info(); + kz_app = kz_app_new(); + mozilla_init(); /* create window */ kz = KZ_WINDOW(kz_window_new(NULL)); @@ -807,7 +585,7 @@ gnutls_global_deinit (); #endif - close_app_info(); + g_object_unref(kz_app); return 0; }