[Kazehakase-cvs] CVS update: kazehakase/src/bookmarks

Back to archive index

Hiroyuki Ikezoe ikezo****@users*****
Mon Jan 1 21:17:52 JST 2007


Index: kazehakase/src/bookmarks/kz-session.c
diff -u kazehakase/src/bookmarks/kz-session.c:1.2 kazehakase/src/bookmarks/kz-session.c:1.3
--- kazehakase/src/bookmarks/kz-session.c:1.2	Mon Jan  1 19:35:14 2007
+++ kazehakase/src/bookmarks/kz-session.c	Mon Jan  1 21:17:52 2007
@@ -18,7 +18,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- *  $Id: kz-session.c,v 1.2 2007/01/01 10:35:14 ikezoe Exp $
+ *  $Id: kz-session.c,v 1.3 2007/01/01 12:17:52 ikezoe Exp $
  */
 
 #include "kz-session.h"
@@ -31,6 +31,7 @@
 struct _KzSessionPrivate
 {
 	gboolean auto_save;
+	gboolean frozen;
 };
 
 #define KZ_SESSION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), KZ_TYPE_SESSION, KzSessionPrivate))
@@ -45,19 +46,35 @@
                           GValue              *value,
                           GParamSpec          *pspec);
 
+static void kz_bookmark_insert_child (KzBookmark *bookmark,
+				      KzBookmark *child,
+				      KzBookmark *sibling);
+static void kz_bookmark_remove_child (KzBookmark *bookmark,
+				      KzBookmark *child);
+
+static void cb_profile_changed (KzProfile *profile,
+				const gchar *section, const gchar *key,
+				const gchar *old_value,
+				KzSession *session);
+
 G_DEFINE_TYPE(KzSession, kz_session, KZ_TYPE_BOOKMARK_FILE)
 
 static void
 kz_session_class_init (KzSessionClass *klass)
 {
 	GObjectClass *object_class;
+	KzBookmarkClass *bookmark_class;
 
 	object_class = (GObjectClass *) klass;
+	bookmark_class = (KzBookmarkClass *) klass;
 
 	object_class->dispose      = dispose;
 	object_class->set_property = set_property;
 	object_class->get_property = get_property;
 
+	bookmark_class->insert_child = kz_bookmark_insert_child;
+	bookmark_class->remove_child = kz_bookmark_remove_child;
+
 	g_type_class_add_private(object_class, sizeof(KzSessionPrivate));
 }
 
@@ -68,6 +85,7 @@
 	KzSessionPrivate *priv = KZ_SESSION_GET_PRIVATE(session);
 
 	priv->auto_save = FALSE;
+	priv->frozen    = FALSE;
 }
 
 
@@ -132,3 +150,112 @@
 	priv->auto_save = auto_save;
 }
 
+void
+kz_session_set_profile (KzSession *session, KzProfile *profile)
+{
+	gboolean save_session;
+	KzSessionPrivate *priv = KZ_SESSION_GET_PRIVATE(session);
+
+	kz_profile_get_value(profile, "Session", "save",
+			     &save_session, sizeof(gboolean), KZ_PROFILE_VALUE_TYPE_BOOL);
+	priv->auto_save = save_session;
+	g_signal_connect(profile,
+			 "changed::Session",
+			 G_CALLBACK(cb_profile_changed), session);
+}
+
+static void
+cb_profile_changed (KzProfile *profile,
+		    const gchar *section, const gchar *key,
+		    const gchar *old_value,
+		    KzSession *session)
+{
+	KzSessionPrivate *priv = KZ_SESSION_GET_PRIVATE(session);
+
+	if (key && strcmp(key, "save"))
+	{
+		gboolean save_session;
+		kz_profile_get_value(profile, "Session", "save",
+				&save_session, sizeof(gboolean), KZ_PROFILE_VALUE_TYPE_BOOL);
+		priv->auto_save = save_session;
+	}
+}
+
+static void
+cb_bookmark_notify (GObject *object, GParamSpec *spec, KzBookmark *session)
+{
+	KzSessionPrivate *priv = KZ_SESSION_GET_PRIVATE(session);
+
+	if (priv->frozen)
+		return;
+
+	if (priv->auto_save)
+		kz_bookmark_file_save(KZ_BOOKMARK_FILE(session));
+}
+
+static void
+cb_insert_child (KzBookmark *folder, KzBookmark *child, KzBookmark *sibling, KzBookmark *session)
+{
+	g_signal_connect_after(child, "notify",
+			       G_CALLBACK(cb_bookmark_notify),
+			       session);
+}
+
+static void
+cb_remove_child (KzBookmark *folder, KzBookmark *child, KzBookmark *session)
+{
+	g_signal_handlers_disconnect_by_func
+		(child,
+		 G_CALLBACK(cb_bookmark_notify), session);
+}
+
+static void
+cb_tab_created (KzBookmark *folder, KzBookmark *child, KzBookmark *sibling, KzBookmark *session)
+{
+	g_signal_connect(child, "insert-child",
+			 G_CALLBACK(cb_insert_child),
+			 session);
+	g_signal_connect(child, "remove-child",
+			 G_CALLBACK(cb_remove_child),
+			 session);	
+}
+
+static void
+cb_tab_removed (KzBookmark *folder, KzBookmark *child, KzBookmark *session)
+{
+	g_signal_handlers_disconnect_by_func
+		(child,
+		 G_CALLBACK(cb_insert_child), session);
+	g_signal_handlers_disconnect_by_func
+		(child,
+		 G_CALLBACK(cb_remove_child), session);
+}
+
+static void
+kz_bookmark_insert_child (KzBookmark *bookmark,
+			  KzBookmark *child,
+			  KzBookmark *sibling)
+{
+	/* 
+	 * This session folder contains each tab.
+	 * We have to watch each folder.
+	 */
+	g_signal_connect(child, "insert-child",
+			 G_CALLBACK(cb_tab_created),
+			 bookmark);
+	g_signal_connect(child, "remove-child",
+			 G_CALLBACK(cb_tab_removed),
+			 bookmark);	
+}
+
+static void
+kz_bookmark_remove_child (KzBookmark *bookmark, KzBookmark *child)
+{
+	g_signal_handlers_disconnect_by_func
+		(child,
+		 G_CALLBACK(cb_tab_created), bookmark);
+	g_signal_handlers_disconnect_by_func
+		(child,
+		 G_CALLBACK(cb_tab_removed), bookmark);
+}
+
Index: kazehakase/src/bookmarks/kz-session.h
diff -u kazehakase/src/bookmarks/kz-session.h:1.2 kazehakase/src/bookmarks/kz-session.h:1.3
--- kazehakase/src/bookmarks/kz-session.h:1.2	Mon Jan  1 19:35:14 2007
+++ kazehakase/src/bookmarks/kz-session.h	Mon Jan  1 21:17:52 2007
@@ -18,7 +18,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- *  $Id: kz-session.h,v 1.2 2007/01/01 10:35:14 ikezoe Exp $
+ *  $Id: kz-session.h,v 1.3 2007/01/01 12:17:52 ikezoe Exp $
  */
 
 #ifndef __KZ_SESSION_H__
@@ -26,6 +26,7 @@
 
 #include <glib-object.h>
 #include "kz-bookmark-file.h"
+#include "kz-profile.h"
 
 G_BEGIN_DECLS
 
@@ -53,10 +54,13 @@
 /* GType */
 GType		kz_session_get_type	(void) G_GNUC_CONST;
 
-/* boomark item creating functions */
 KzBookmark     *kz_session_new	(const gchar *location, const gchar *title);
 
 void		kz_session_set_auto_save (KzSession *session, gboolean auto_save);
+void		kz_session_set_profile   (KzSession *session, KzProfile *profile);
+
+void		kz_session_freeze	 (KzSession *session);
+void		kz_session_thaw		 (KzSession *session);
 
 G_END_DECLS
 


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