[Kazehakase-cvs] kazehakase-svn [3035] * src/utils/utils.[ch]: clean-up history purging related API.

Back to archive index

svnno****@sourc***** svnno****@sourc*****
Tue Mar 27 09:46:36 JST 2007


Revision: 3035
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=kazehakase&view=rev&rev=3035
Author:   kous
Date:     2007-03-27 09:46:36 +0900 (Tue, 27 Mar 2007)

Log Message:
-----------
* src/utils/utils.[ch]: clean-up history purging related API.

* src/utils/Makefile.am, src/utils/kz-history-utils.[ch]: added.

* src/kz-app.c: used kz-history-utils API.
* src/kz-app.[ch]: managed history related file name.

* src/kazehakase.h (KZ_GET_HISTORY_DIR, KZ_GET_HISTORY_TIME_STAMP):
  added.

Modified Paths:
--------------
    kazehakase/trunk/ChangeLog
    kazehakase/trunk/src/kazehakase.h
    kazehakase/trunk/src/kz-app.c
    kazehakase/trunk/src/kz-app.h
    kazehakase/trunk/src/utils/Makefile.am
    kazehakase/trunk/src/utils/utils.c
    kazehakase/trunk/src/utils/utils.h

Added Paths:
-----------
    kazehakase/trunk/src/utils/kz-history-utils.c
    kazehakase/trunk/src/utils/kz-history-utils.h

Modified: kazehakase/trunk/ChangeLog
===================================================================
--- kazehakase/trunk/ChangeLog	2007-03-27 00:03:35 UTC (rev 3034)
+++ kazehakase/trunk/ChangeLog	2007-03-27 00:46:36 UTC (rev 3035)
@@ -1,5 +1,15 @@
 2007-03-27  Kouhei Sutou  <kou****@cozmi*****>
 
+	* src/utils/utils.[ch]: clean-up history purging related API.
+
+	* src/utils/Makefile.am, src/utils/kz-history-utils.[ch]: added.
+
+	* src/kz-app.c: used kz-history-utils API.
+	* src/kz-app.[ch]: managed history related file name.
+
+	* src/kazehakase.h (KZ_GET_HISTORY_DIR, KZ_GET_HISTORY_TIME_STAMP):
+	added.
+
 	* src/utils/utils.c (_make_history_time_stamp): don't treat
 	time-stamp file as special.
 

Modified: kazehakase/trunk/src/kazehakase.h
===================================================================
--- kazehakase/trunk/src/kazehakase.h	2007-03-27 00:03:35 UTC (rev 3034)
+++ kazehakase/trunk/src/kazehakase.h	2007-03-27 00:46:36 UTC (rev 3035)
@@ -69,8 +69,13 @@
 #define KZ_GET_WINDOW_LIST     kz_app_get_window_list(kz_app)
 #define KZ_GET_MIGEMO          kz_app_get_migemo(kz_app)
 
+#define KZ_GET_HISTORY_DIR	kz_app_get_history_dir(kz_app)
+#define KZ_GET_HISTORY_TIME_STAMP	kz_app_get_history_time_stamp(kz_app)
+
+
 #define KZ_SET_SEARCH(engine_name)	kz_app_set_search(kz_app, engine_name)
 
+
 G_END_DECLS
 
 #endif /* __KAZEAKASE_H__ */

Modified: kazehakase/trunk/src/kz-app.c
===================================================================
--- kazehakase/trunk/src/kz-app.c	2007-03-27 00:03:35 UTC (rev 3034)
+++ kazehakase/trunk/src/kz-app.c	2007-03-27 00:46:36 UTC (rev 3035)
@@ -51,6 +51,7 @@
 #include "kz-session.h"
 #include "kz-tab-label.h"
 #include "kz-window.h"
+#include "kz-history-utils.h"
 #include "glib-utils.h"
 #include "utils.h"
 
@@ -78,6 +79,9 @@
 	gpointer        smc_conn;
 	gchar          *session_id;
 #endif /* HAVE_LIBSM */
+
+	gchar		*history_dir;
+	gchar		*history_time_stamp;
 };
 
 #define KZ_APP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), KZ_TYPE_APP, KzAppPrivate))
@@ -241,6 +245,12 @@
 	gchar *proxy_file, *sysproxy_file;
 	KzAppPrivate *priv = KZ_APP_GET_PRIVATE(app);
 
+	priv->history_dir = g_build_filename(g_get_home_dir(), HISTORY_DIR,
+					     NULL);
+	priv->history_time_stamp = g_build_filename(priv->history_dir,
+						    "time-stamp",
+						    NULL);
+
 	priv->window_list = NULL;
 	priv->favicon = kz_favicon_get_instance();
 
@@ -354,27 +364,18 @@
 	KZ_CONF_GET("History", "limit_cache", limit, BOOL);
 	if (limit)
 	{
-		gchar *history_dir, *history_time_stamp, *image_dir;
+		gchar *image_dir;
 
 		limit_seconds = limit_days * 86400;
-		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_dir,
-						 history_time_stamp,
-						 limit_seconds);
-		g_free(history_dir);
-		g_free(history_time_stamp);
+		if (!kz_history_time_stamp_exists())
+			kz_history_make_time_stamp();
+		kz_history_purge_by_time_stamp(limit_seconds);
 
 		/* purge popup files */
 		image_dir = g_build_filename(g_get_home_dir(),
 					     IMAGE_DIR,
 					     NULL);
-		purge_history_file(image_dir, limit_seconds);
+		kz_utils_purge_files(image_dir, limit_seconds);
 		g_free(image_dir);
 	}
 }
@@ -424,12 +425,18 @@
 		SmcCloseConnection ((SmcConn) priv->smc_conn, 0, NULL);
 #endif /* HAVE_LIBSM */
 
+	g_free(priv->history_dir);
+	g_free(priv->history_time_stamp);
+
+	priv->history_dir = NULL;
+	priv->history_time_stamp = NULL;
+
 	priv->profile   = NULL;
 	priv->proxy     = NULL;
 	priv->bookmarks = NULL;
 	priv->favicon   = NULL;
 	priv->argv	= NULL;
-	
+
 	if (G_OBJECT_CLASS (kz_app_parent_class)->dispose)
 		G_OBJECT_CLASS (kz_app_parent_class)->dispose(object);
 }
@@ -453,6 +460,9 @@
 
 	g_return_if_fail(KZ_IS_APP(app));
 
+	if (!kz_history_time_stamp_exists())
+		kz_history_make_time_stamp();
+
 	priv = KZ_APP_GET_PRIVATE(app);
 
 	search_engine = kz_profile_get_string(priv->profile,
@@ -1012,3 +1022,20 @@
 	}
 }
 #endif /* HAVE_LIBSM */
+
+const gchar *
+kz_app_get_history_dir (KzApp *app)
+{
+	g_return_val_if_fail(KZ_IS_APP(app), NULL);
+
+	return KZ_APP_GET_PRIVATE(app)->history_dir;
+}
+
+const gchar *
+kz_app_get_history_time_stamp (KzApp *app)
+{
+	g_return_val_if_fail(KZ_IS_APP(app), NULL);
+
+	return KZ_APP_GET_PRIVATE(app)->history_time_stamp;
+}
+

Modified: kazehakase/trunk/src/kz-app.h
===================================================================
--- kazehakase/trunk/src/kz-app.h	2007-03-27 00:03:35 UTC (rev 3034)
+++ kazehakase/trunk/src/kz-app.h	2007-03-27 00:46:36 UTC (rev 3035)
@@ -85,6 +85,9 @@
 KzMigemo       *kz_app_get_migemo          (KzApp *app);
 #endif
 
+const gchar	*kz_app_get_history_dir		(KzApp *app);
+const gchar	*kz_app_get_history_time_stamp	(KzApp *app);
+
 G_END_DECLS
 
 #endif /* __KZ_APP_H__ */

Modified: kazehakase/trunk/src/utils/Makefile.am
===================================================================
--- kazehakase/trunk/src/utils/Makefile.am	2007-03-27 00:03:35 UTC (rev 3034)
+++ kazehakase/trunk/src/utils/Makefile.am	2007-03-27 00:46:36 UTC (rev 3035)
@@ -22,6 +22,7 @@
 	gtk-utils.c gtk-utils.h \
 	gobject-utils.h \
 	kz-base64.h kz-base64.c \
+	kz-history-utils.h kz-history-utils.c \
 	utils.c utils.h
 
 if GLIB_HAS_NO_REGEX

Added: kazehakase/trunk/src/utils/kz-history-utils.c
===================================================================
--- kazehakase/trunk/src/utils/kz-history-utils.c	2007-03-27 00:03:35 UTC (rev 3034)
+++ kazehakase/trunk/src/utils/kz-history-utils.c	2007-03-27 00:46:36 UTC (rev 3035)
@@ -0,0 +1,44 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  Copyright (C) 2007 Kouhei Sutou <kou****@cozmi*****>
+ *
+ *  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.
+ */
+
+#include "kz-history-utils.h"
+
+#include "kazehakase.h"
+#include "utils.h"
+
+gboolean
+kz_history_time_stamp_exists(void)
+{
+	return g_file_test(KZ_GET_HISTORY_DIR, G_FILE_TEST_EXISTS);
+}
+
+void
+kz_history_make_time_stamp (void)
+{
+	kz_utils_make_time_stamp(KZ_GET_HISTORY_DIR, KZ_GET_HISTORY_TIME_STAMP);
+}
+
+void
+kz_history_purge_by_time_stamp(time_t limit_seconds)
+{
+	kz_utils_purge_files_by_time_stamp(KZ_GET_HISTORY_DIR,
+					   KZ_GET_HISTORY_TIME_STAMP,
+					   limit_seconds);
+}

Added: kazehakase/trunk/src/utils/kz-history-utils.h
===================================================================
--- kazehakase/trunk/src/utils/kz-history-utils.h	2007-03-27 00:03:35 UTC (rev 3034)
+++ kazehakase/trunk/src/utils/kz-history-utils.h	2007-03-27 00:46:36 UTC (rev 3035)
@@ -0,0 +1,34 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  Copyright (C) 2007 Kouhei Sutou <kou****@cozmi*****>
+ *
+ *  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_HISTORY_UTILS_H__
+#define __KZ_HISTORY_UTILS_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gboolean	 kz_history_time_stamp_exists	(void);
+void		 kz_history_make_time_stamp	(void);
+void		 kz_history_purge_by_time_stamp	(time_t limit_seconds);
+
+G_END_DECLS
+
+#endif /* __KZ_HISTORY_UTILS_H__ */

Modified: kazehakase/trunk/src/utils/utils.c
===================================================================
--- kazehakase/trunk/src/utils/utils.c	2007-03-27 00:03:35 UTC (rev 3034)
+++ kazehakase/trunk/src/utils/utils.c	2007-03-27 00:46:36 UTC (rev 3035)
@@ -546,7 +546,7 @@
 
 
 static void
-_make_history_time_stamp (const gchar *dir, FILE *time_stamp)
+_make_time_stamp (const gchar *dir, FILE *time_stamp)
 {
 	GDir *gdir;
 	const gchar *entry;
@@ -561,7 +561,7 @@
 
 		if (g_file_test(file_name, G_FILE_TEST_IS_DIR))
 		{
-			_make_history_time_stamp(file_name, time_stamp);
+			_make_time_stamp(file_name, time_stamp);
 		}
 		else
 		{
@@ -577,7 +577,7 @@
 }
 
 void
-make_history_time_stamp (const gchar *history_dir, const gchar *time_stamp_path)
+kz_utils_make_time_stamp (const gchar *target_dir, const gchar *time_stamp_path)
 {
 	FILE *fp;
 
@@ -585,27 +585,27 @@
 	if (!fp)
 		return;
 
-	_make_history_time_stamp(history_dir, fp);
+	_make_time_stamp(target_dir, fp);
 }
 
 void
-purge_history_file(const gchar *path, time_t limit_seconds)
+kz_utils_purge_files(const gchar *target_dir, time_t limit_seconds)
 {
-	GDir *gdir;
-	const gchar *dir;
+	GDir *dir;
+	const gchar *entry;
 
-	gdir = g_dir_open(path, 0, NULL);
+	dir = g_dir_open(target_dir, 0, NULL);
 
-	if (!gdir) return;
+	if (!dir) return;
 
-	while ((dir = g_dir_read_name(gdir)))
+	while ((entry = g_dir_read_name(dir)))
 	{
-		gchar *dirname;
-		dirname = g_build_filename(path, dir, NULL);
+		gchar *file_name;
+		file_name = g_build_filename(target_dir, entry, NULL);
 
-		if (g_file_test(dirname, G_FILE_TEST_IS_DIR))
+		if (g_file_test(file_name, G_FILE_TEST_IS_DIR))
 		{
-			purge_history_file(dirname, limit_seconds);
+			kz_utils_purge_files(file_name, limit_seconds);
 		}
 		else
 		{
@@ -616,23 +616,23 @@
 			g_get_current_time(&now);
 			t = (time_t)now.tv_sec;
 
-			if (g_stat(dirname, &st) == 0 &&
+			if (g_stat(file_name, &st) == 0 &&
 			    st.st_mtime < t - limit_seconds)
-				g_unlink(dirname);
+				g_unlink(file_name);
 		}
-		g_free(dirname);
+		g_free(file_name);
 	}
-	g_dir_close(gdir);
+	g_dir_close(dir);
 }
 
 void
-purge_history_file_by_time_stamp(const gchar *history_dir,
-				 const gchar *time_stamp_path,
-				 time_t limit_seconds)
+kz_utils_purge_files_by_time_stamp(const gchar *target_dir,
+				   const gchar *time_stamp_path,
+				   time_t limit_seconds)
 {
 	gchar buf[BUFFER_SIZE];
 	gchar *tmp_file;
-	gint fd, history_dir_len;
+	gint fd, target_dir_len;
 	FILE *fp;
 	GTimeVal now;
 	time_t t;
@@ -653,7 +653,7 @@
 	search = KZ_GET_SEARCH;
 	g_get_current_time(&now);
 	t = now.tv_sec;
-	history_dir_len = strlen(history_dir);
+	target_dir_len = strlen(target_dir);
 	while (fgets(buf, sizeof(buf), fp))
 	{
 		gchar *pos;
@@ -676,12 +676,12 @@
 		{
 			gchar *dir_name;
 
-			if (search && strlen(path) > history_dir_len)
+			if (search && strlen(path) > target_dir_len)
 			{
 				gchar *uri;
 				gchar *relative_path;
 
-				relative_path = path + history_dir_len;
+				relative_path = path + target_dir_len;
 				uri = create_uri_from_filename(relative_path);
 				kz_search_unregister_document(search, uri);
 				g_free(uri);

Modified: kazehakase/trunk/src/utils/utils.h
===================================================================
--- kazehakase/trunk/src/utils/utils.h	2007-03-27 00:03:35 UTC (rev 3034)
+++ kazehakase/trunk/src/utils/utils.h	2007-03-27 00:46:36 UTC (rev 3035)
@@ -55,13 +55,13 @@
 gchar   *xml_get_content	     (const gchar *buffer);
 gchar   *xml_get_attr		     (const gchar *buffer, const gchar *attr_name);
 
-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 *history_dir,
-						 const gchar *time_stamp_path,
-						 time_t limit_seconds);
+void     kz_utils_make_time_stamp	(const gchar	*target_dir,
+					 const gchar	*time_stamp_path);
+void     kz_utils_purge_files		(const gchar	*path,
+					 time_t		 limit_seconds);
+void     kz_utils_purge_files_by_time_stamp	(const gchar	*target_dir,
+						 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);




More information about the Kazehakase-cvs mailing list
Back to archive index