Yasumichi Akahoshi
yasum****@users*****
2005年 4月 8日 (金) 19:53:45 JST
Index: libcxp/src/cxp-handler.c diff -u libcxp/src/cxp-handler.c:1.7 libcxp/src/cxp-handler.c:1.8 --- libcxp/src/cxp-handler.c:1.7 Fri Apr 1 23:42:52 2005 +++ libcxp/src/cxp-handler.c Fri Apr 8 19:53:45 2005 @@ -36,11 +36,13 @@ * @brief private member of CxpHandler */ -struct _CxpHandlerPrivate +typedef struct { CxpProfile *profile; gboolean dispose_has_run; /**< Is dispose funciton executed */ -}; +} CxpHandlerPrivate; + +#define CXP_HANDLER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CXP_TYPE_HANDLER, CxpHandlerPrivate)) static GObjectClass *parent_class = NULL; @@ -86,16 +88,13 @@ */ static void cxp_handler_init (GTypeInstance * instance, gpointer g_class) { + CxpHandlerPrivate *priv = CXP_HANDLER_GET_PRIVATE(instance); + bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - CxpHandler *self = CXP_HANDLER (instance); - - self->priv = g_new (CxpHandlerPrivate, 1); - self->priv->profile = cxp_profile_new ("common", "handler"); - self->priv->dispose_has_run = FALSE; - - parent_class = g_type_class_peek_parent (g_class); + priv->profile = cxp_profile_new ("common", "handler"); + priv->dispose_has_run = FALSE; } /** @@ -108,29 +107,29 @@ gobject_class->dispose = cxp_handler_dispose; gobject_class->finalize = cxp_handler_finalize; + + g_type_class_add_private (g_class, sizeof (CxpHandlerPrivate)); + + parent_class = g_type_class_peek_parent (g_class); } static void cxp_handler_dispose (GObject * obj) { - CxpHandler *self = CXP_HANDLER (obj); + CxpHandlerPrivate *priv = CXP_HANDLER_GET_PRIVATE(obj); - if (self->priv->dispose_has_run) + if (priv->dispose_has_run) { return; } - self->priv->dispose_has_run = TRUE; - g_object_unref (self->priv->profile); + priv->dispose_has_run = TRUE; + g_object_unref (priv->profile); G_OBJECT_CLASS (parent_class)->dispose (obj); } static void cxp_handler_finalize (GObject * obj) { - CxpHandler *self = CXP_HANDLER (obj); - - g_free (self->priv); - G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -145,6 +144,7 @@ void cxp_handler_launch (CxpHandler * handler, const gchar * fullpath) { + CxpHandlerPrivate *priv = CXP_HANDLER_GET_PRIVATE(handler); gchar *filename; gchar *suffix = NULL; gchar *cmd = NULL; @@ -158,7 +158,7 @@ filename = g_path_get_basename (fullpath); if ((suffix = g_strrstr (filename, ".")) != NULL) { - cmd = cxp_profile_get_string (handler->priv->profile, suffix); + cmd = cxp_profile_get_string (priv->profile, suffix); if (cmd == NULL) { message = @@ -174,9 +174,7 @@ (CXP_ENTRY_DIALOG (dialog)); if ((cmd != NULL) && (strlen (cmd) > 0)) { - cxp_profile_set_string (handler->priv-> - profile, suffix, - cmd); + cxp_profile_set_string (priv-> profile, suffix, cmd); } } gtk_widget_destroy (dialog); Index: libcxp/src/cxp-profile.c diff -u libcxp/src/cxp-profile.c:1.6 libcxp/src/cxp-profile.c:1.7 --- libcxp/src/cxp-profile.c:1.6 Fri Apr 1 23:10:51 2005 +++ libcxp/src/cxp-profile.c Fri Apr 8 19:53:45 2005 @@ -36,13 +36,15 @@ * @brief private member of CxpProfile */ -struct _CxpProfilePrivate +typedef struct { gchar *appname; /**< application name */ gchar *section; /**< section name */ GHashTable *config; /**< hash table of configuration */ gboolean dispose_has_run; /**< Is dispose funciton executed */ -}; +} CxpProfilePrivate; + +#define CXP_PROFILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CXP_TYPE_PROFILE, CxpProfilePrivate)) static GObjectClass *parent_class = NULL; @@ -90,16 +92,12 @@ */ static void cxp_profile_init (GTypeInstance * instance, gpointer g_class) { - CxpProfile *self = CXP_PROFILE (instance); - - self->priv = g_new (CxpProfilePrivate, 1); - self->priv->appname = NULL; - self->priv->section = NULL; - self->priv->config = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - self->priv->dispose_has_run = FALSE; + CxpProfilePrivate *priv = CXP_PROFILE_GET_PRIVATE(instance); - parent_class = g_type_class_peek_parent (g_class); + priv->appname = NULL; + priv->section = NULL; + priv->config = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + priv->dispose_has_run = FALSE; } /** @@ -112,27 +110,32 @@ gobject_class->dispose = cxp_profile_dispose; gobject_class->finalize = cxp_profile_finalize; + + g_type_class_add_private (g_class, sizeof (CxpProfilePrivate)); + + parent_class = g_type_class_peek_parent (g_class); } static void cxp_profile_dispose (GObject * obj) { CxpProfile *self = CXP_PROFILE (obj); + CxpProfilePrivate *priv = CXP_PROFILE_GET_PRIVATE(obj); GIOChannel *channel; gchar *filename; - if (self->priv->dispose_has_run) + if (priv->dispose_has_run) { return; } - self->priv->dispose_has_run = TRUE; + priv->dispose_has_run = TRUE; filename = g_build_filename (g_get_home_dir (), ".cxp", - self->priv->appname, - self->priv->section, NULL); + priv->appname, + priv->section, NULL); if ((channel = g_io_channel_new_file (filename, "w", NULL)) != NULL) { - g_hash_table_foreach (self->priv->config, cxp_profile_save_file, + g_hash_table_foreach (priv->config, cxp_profile_save_file, channel); g_io_channel_flush (channel, NULL); @@ -145,12 +148,11 @@ static void cxp_profile_finalize (GObject * obj) { - CxpProfile *self = CXP_PROFILE (obj); + CxpProfilePrivate *priv = CXP_PROFILE_GET_PRIVATE(obj); - g_free (self->priv->appname); - g_free (self->priv->section); - g_hash_table_destroy (self->priv->config); - g_free (self->priv); + g_free (priv->appname); + g_free (priv->section); + g_hash_table_destroy (priv->config); G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -160,10 +162,12 @@ CxpProfile *profile; gchar *cxpdir; gchar *appdir; + CxpProfilePrivate *priv; profile = CXP_PROFILE (g_object_new (CXP_TYPE_PROFILE, NULL)); - profile->priv->appname = g_strdup (appname); - profile->priv->section = g_strdup (section); + priv = CXP_PROFILE_GET_PRIVATE(profile); + priv->appname = g_strdup (appname); + priv->section = g_strdup (section); cxpdir = g_build_filename (g_get_home_dir (), ".cxp", NULL); if (!g_file_test (cxpdir, G_FILE_TEST_EXISTS)) { @@ -191,12 +195,13 @@ { gint retval; gchar *value; + CxpProfilePrivate *priv = CXP_PROFILE_GET_PRIVATE(profile); - value = (gchar *) g_hash_table_lookup (profile->priv->config, name); + value = (gchar *) g_hash_table_lookup (priv->config, name); if (value == NULL) { retval = 0; - g_hash_table_replace (profile->priv->config, g_strdup (name), + g_hash_table_replace (priv->config, g_strdup (name), g_strdup ("0")); } else @@ -210,8 +215,9 @@ gchar *cxp_profile_get_string (CxpProfile * profile, const gchar * name) { gchar *value; + CxpProfilePrivate *priv = CXP_PROFILE_GET_PRIVATE(profile); - value = (gchar *) g_hash_table_lookup (profile->priv->config, name); + value = (gchar *) g_hash_table_lookup (priv->config, name); return g_strdup (value); } @@ -219,14 +225,18 @@ void cxp_profile_set_integer (CxpProfile * profile, const gchar * key, gint value) { - g_hash_table_replace (profile->priv->config, g_strdup (key), + CxpProfilePrivate *priv = CXP_PROFILE_GET_PRIVATE(profile); + + g_hash_table_replace (priv->config, g_strdup (key), g_strdup_printf ("%d", value)); } void cxp_profile_set_string (CxpProfile * profile, const gchar * key, const gchar * value) { - g_hash_table_replace (profile->priv->config, g_strdup (key), + CxpProfilePrivate *priv = CXP_PROFILE_GET_PRIVATE(profile); + + g_hash_table_replace (priv->config, g_strdup (key), g_strdup (value)); } @@ -234,7 +244,8 @@ static void cxp_profile_load_file (CxpProfile * profile) { gchar *filename; - GHashTable *config = profile->priv->config; + CxpProfilePrivate *priv = CXP_PROFILE_GET_PRIVATE(profile); + GHashTable *config = priv->config; gchar *line; gchar **array; gchar *name; @@ -243,15 +254,15 @@ filename = g_build_filename (g_get_home_dir (), ".cxp", - profile->priv->appname, - profile->priv->section, NULL); + priv->appname, + priv->section, NULL); if ((channel = g_io_channel_new_file (filename, "r", NULL)) == NULL) { g_free (filename); filename = g_build_filename (PACKAGE_CONF_DIR, - profile->priv->appname, - profile->priv->section, NULL); + priv->appname, + priv->section, NULL); channel = g_io_channel_new_file (filename, "r", NULL); }