svnno****@sourc*****
svnno****@sourc*****
Mon Mar 26 10:27:55 JST 2007
Revision: 3008 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=kazehakase&view=rev&rev=3008 Author: kous Date: 2007-03-26 10:27:54 +0900 (Mon, 26 Mar 2007) Log Message: ----------- * src/main.c: called kz_app_init_dependencies() and kz_app_quit_dependencies() instead of kz_XXX_init() and kz_XXX_exit(). * src/kz-app.c: - moved module related codes to kz_app_init_dependencies() and kz_app_quit_dependencies(). - generate timestamp if not exists. * src/utils/utils.[ch]: - timestamp -> time_stamp. - defined make_history_time_stamp(). Modified Paths: -------------- kazehakase/trunk/ChangeLog kazehakase/trunk/src/kz-app.c kazehakase/trunk/src/kz-app.h kazehakase/trunk/src/main.c kazehakase/trunk/src/utils/utils.c kazehakase/trunk/src/utils/utils.h Modified: kazehakase/trunk/ChangeLog =================================================================== --- kazehakase/trunk/ChangeLog 2007-03-25 10:24:26 UTC (rev 3007) +++ kazehakase/trunk/ChangeLog 2007-03-26 01:27:54 UTC (rev 3008) @@ -1,3 +1,16 @@ +2007-03-26 Kouhei Sutou <kou****@cozmi*****> + + * src/main.c: called kz_app_init_dependencies() and + kz_app_quit_dependencies() instead of kz_XXX_init() and + kz_XXX_exit(). + * src/kz-app.c: + - moved module related codes to kz_app_init_dependencies() and + kz_app_quit_dependencies(). + - generate timestamp if not exists. + * src/utils/utils.[ch]: + - timestamp -> time_stamp. + - defined make_history_time_stamp(). + 2007-03-25 Hiroyuki Ikezoe <poinc****@ikezo*****> * module/embed/khtml/kz-khtml.c: Handle req-new-window and Modified: kazehakase/trunk/src/kz-app.c =================================================================== --- kazehakase/trunk/src/kz-app.c 2007-03-25 10:24:26 UTC (rev 3007) +++ kazehakase/trunk/src/kz-app.c 2007-03-26 01:27:54 UTC (rev 3008) @@ -239,7 +239,6 @@ gchar *smartbookmark_file, *sys_smartbookmark_file; gchar *accel_prefs_file; gchar *proxy_file, *sysproxy_file; - gchar *search_engine; KzAppPrivate *priv = KZ_APP_GET_PRIVATE(app); priv->window_list = NULL; @@ -253,14 +252,6 @@ 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) - { - kz_app_set_search(app, search_engine); - g_free(search_engine); - } - /* load bookmarks */ bookmark_file = g_build_filename(g_get_home_dir(), "."PACKAGE, @@ -363,19 +354,25 @@ KZ_CONF_GET("History", "limit_cache", limit, BOOL); if (limit) { - gchar *history_timestamp, *image_dir; + gchar *history_dir, *history_time_stamp, *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); + history_dir = g_build_filename(g_get_home_dir(), HISTORY_DIR, + NULL); + history_time_stamp = g_build_filename(history_dir, + "timestamp", + NULL); + if (!g_file_test(history_time_stamp, G_FILE_TEST_EXISTS)) + make_history_time_stamp(history_dir, history_time_stamp); + purge_history_file_by_time_stamp(history_time_stamp, + limit_seconds); + g_free(history_dir); + g_free(history_time_stamp); - /* parge popup files */ + /* purge popup files */ image_dir = g_build_filename(g_get_home_dir(), - IMAGE_DIR, - NULL); + IMAGE_DIR, + NULL); purge_history_file(image_dir, limit_seconds); g_free(image_dir); } @@ -395,9 +392,6 @@ gtk_accel_map_save(accel_prefs_file); g_free(accel_prefs_file); - /* clean history cache */ - clean_history_cache(); - kz_root_bookmark_save_all(priv->bookmarks); /* freeze session for storing last saving session */ kz_session_freeze(KZ_SESSION(priv->bookmarks->current_session)); @@ -406,8 +400,6 @@ kz_profile_close(priv->profile); kz_profile_close(priv->proxy); - if (priv->search) - g_object_unref(priv->search); if (priv->favicon) g_object_unref(priv->favicon); @@ -434,7 +426,6 @@ priv->profile = NULL; priv->proxy = NULL; priv->bookmarks = NULL; - priv->search = NULL; priv->favicon = NULL; priv->argv = NULL; @@ -442,7 +433,6 @@ G_OBJECT_CLASS (kz_app_parent_class)->dispose(object); } - KzApp * kz_app_new (gint argc, gchar **argv) { @@ -454,6 +444,47 @@ return kzapp; } +void +kz_app_init_dependencies (KzApp *app, gpointer initial_address) +{ + KzAppPrivate *priv; + gchar *search_engine; + + g_return_if_fail(KZ_IS_APP(app)); + + priv = KZ_APP_GET_PRIVATE(app); + + search_engine = kz_profile_get_string(priv->profile, + "History", "search_engine"); + if (search_engine) + { + kz_app_set_search(app, search_engine); + g_free(search_engine); + } + + kz_ext_init(&initial_address); +} + +void +kz_app_quit_dependencies (KzApp *app) +{ + KzAppPrivate *priv; + + g_return_if_fail(KZ_IS_APP(app)); + + + priv = KZ_APP_GET_PRIVATE(app); + + kz_ext_exit(); + kz_embed_exit(); + + clean_history_cache(); + if (priv->search) + g_object_unref(priv->search); + priv->search = NULL; + kz_search_exit(); +} + static void cb_window_map (KzWindow *kz, GtkAction *action) { Modified: kazehakase/trunk/src/kz-app.h =================================================================== --- kazehakase/trunk/src/kz-app.h 2007-03-25 10:24:26 UTC (rev 3007) +++ kazehakase/trunk/src/kz-app.h 2007-03-26 01:27:54 UTC (rev 3008) @@ -60,6 +60,9 @@ GtkWidget *kz_app_restore_session (KzApp *app); void kz_app_save_session (KzApp *app); +void kz_app_init_dependencies (KzApp *app, gpointer initial_address); +void kz_app_quit_dependencies (KzApp *app); + typedef enum { KZ_UI_LEVEL_INVALID = 0, KZ_UI_LEVEL_BEGINNER = 1, Modified: kazehakase/trunk/src/main.c =================================================================== --- kazehakase/trunk/src/main.c 2007-03-25 10:24:26 UTC (rev 3007) +++ kazehakase/trunk/src/main.c 2007-03-26 01:27:54 UTC (rev 3008) @@ -472,10 +472,10 @@ return 0; /* found kazehakase process */ } - kz_app = kz_app_new(argc, argv); - kz_ext_init(&initial_address); + kz_app = kz_app_new(argc, argv); + kz_app_init_dependencies(kz_app, &initial_address); - /* create window */ + /* create window */ KZ_CONF_GET("Session", "restore", restore, BOOL); if (restore) { @@ -486,10 +486,10 @@ else window = kz_app_create_new_window(kz_app, NULL); - /* - * gtk_window_pargse_geometry() needs to be called + /* + * gtk_window_pargse_geometry() needs to be called * before gtk_widget_show(). - */ + */ if(geometry_string) { gtk_window_parse_geometry(GTK_WINDOW(window), @@ -508,8 +508,7 @@ gtk_widget_destroy(dupl_check_server); dupl_check_server = NULL; - kz_ext_exit(); - kz_embed_exit(); + kz_app_quit_dependencies(kz_app); g_object_unref(kz_app); return 0; Modified: kazehakase/trunk/src/utils/utils.c =================================================================== --- kazehakase/trunk/src/utils/utils.c 2007-03-25 10:24:26 UTC (rev 3007) +++ kazehakase/trunk/src/utils/utils.c 2007-03-26 01:27:54 UTC (rev 3008) @@ -545,7 +545,52 @@ } +static void +_make_history_time_stamp (const gchar *dir, FILE *time_stamp, + const gchar *time_stamp_path) +{ + GDir *gdir; + const gchar *entry; + + gdir = g_dir_open(dir, 0, NULL); + if (!gdir) return; + + while ((entry = g_dir_read_name(gdir))) + { + gchar *file_name; + file_name = g_build_filename(dir, entry, NULL); + + if (g_file_test(file_name, G_FILE_TEST_IS_DIR)) + { + _make_history_time_stamp(file_name, time_stamp, + time_stamp_path); + } + else if (strcmp(file_name, time_stamp_path) != 0) + { + struct stat st; + + if (g_stat(file_name, &st) == 0) + g_fprintf(time_stamp, "%ld,%s\n", + st.st_mtime, file_name); + } + g_free(file_name); + } + g_dir_close(gdir); +} + void +make_history_time_stamp (const gchar *history_dir, const gchar *time_stamp_path) +{ + FILE *fp; + + fp = g_fopen(time_stamp_path, "w"); + if (!fp) + return; + + _make_history_time_stamp(history_dir, fp, time_stamp_path); +} + +void purge_history_file(const gchar *path, time_t limit_seconds) { GDir *gdir; @@ -583,78 +628,79 @@ } void -purge_history_file_by_timestamp(const gchar *timestamp_path, time_t limit_seconds) +purge_history_file_by_time_stamp(const gchar *time_stamp_path, + time_t limit_seconds) { gchar buf[BUFFER_SIZE]; gchar *tmp_file; gint fd; - gint i; FILE *fp; GTimeVal now; time_t t; KzSearch *search; - search = KZ_GET_SEARCH; - g_get_current_time(&now); - t = now.tv_sec; + fp = g_fopen(time_stamp_path, "a+"); + if (!fp) + { + g_unlink(time_stamp_path); + return; + } + fd = g_file_open_tmp("kzXXXXXX", &tmp_file, NULL); + if (fd == -1) + return; - fp = g_fopen(timestamp_path, "a+"); - if(fp) + search = KZ_GET_SEARCH; + g_get_current_time(&now); + t = now.tv_sec; + while (fgets(buf, sizeof(buf), fp)) { - while(fgets(buf, sizeof(buf), fp)) - { - gchar *pos; - gchar *time , *path; - gint time_int; - struct stat st; + gchar *pos; + gchar *time, *path, *path_end; + gint time_int; + struct stat st; - pos = strstr(buf, ","); - time = g_strndup(buf, pos - buf); - path = g_strdup(pos+1); + pos = strstr(buf, ","); + time = g_strndup(buf, pos - buf); + path = g_strdup(pos+1); - for(i = 0;i <= strlen(path);i++) - if(path[i] == '\n') - path[i] = '\0'; + path_end = strstr(path, "\n"); + if (path_end) + path[path_end - path] = '\0'; - time_int = atoi(time); - - if(t - time_int > limit_seconds) + time_int = atoi(time); + if (t - time_int > limit_seconds && + g_stat(path, &st) == 0 && + t - st.st_mtime > limit_seconds) + { + if (search) { - if (g_stat(path, &st) == 0 && - t - st.st_mtime > limit_seconds) - { - if (search) - { - gchar *filename; - filename = g_strdup_printf("file://%s", path); - kz_search_unregister_document(search, filename); - g_free(filename); - } - /* remove file over storage period */ - g_unlink(path); - g_free(time); - g_free(path); - continue; - } + gchar *filename; + filename = g_strdup_printf("file://%s", path); + kz_search_unregister_document(search, filename); + g_free(filename); } - + /* remove file over storage period */ + g_unlink(path); + } + else + { write(fd, buf, strlen(buf)); + } - g_free(time); - g_free(path); - } - close(fd); - fclose(fp); + g_free(time); + g_free(path); } + close(fd); + fclose(fp); - g_unlink(timestamp_path); - g_rename(tmp_file, timestamp_path); + g_unlink(time_stamp_path); + g_rename(tmp_file, time_stamp_path); } gchar * -ensure_encode_string(const gchar *text, +ensure_encode_string(const gchar *text, const gchar *encode, gboolean urlencode) { Modified: kazehakase/trunk/src/utils/utils.h =================================================================== --- kazehakase/trunk/src/utils/utils.h 2007-03-25 10:24:26 UTC (rev 3007) +++ kazehakase/trunk/src/utils/utils.h 2007-03-26 01:27:54 UTC (rev 3008) @@ -55,10 +55,12 @@ gchar *xml_get_content (const gchar *buffer); gchar *xml_get_attr (const gchar *buffer, const gchar *attr_name); -void purge_history_file (const gchar *path, - time_t limit_seconds); -void purge_history_file_by_timestamp (const gchar *timestamp_path, - time_t limit_seconds); +void make_history_time_stamp (const gchar *history_dir, + const gchar *time_stamp_path); +void purge_history_file (const gchar *path, + time_t limit_seconds); +void purge_history_file_by_time_stamp (const gchar *time_stamp_path, + time_t limit_seconds); void convert_image (const gchar *ps_file, const gchar *png_file); gboolean str_isdigit (const gchar *str);