diff --git a/ChangeLog b/ChangeLog index b2d662f3bfd4b83dc4534df70d117eb4f78bcbc4..25850df1073cc63c6a8b853d52cca704c3969d4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2005-09-13 Benedikt Meurer <benny@xfce.org> + + * thunar-vfs/thunar-vfs-info.c, thunar-vfs/thunar-vfs-mime-database.c, + thunar-vfs/thunar-vfs-mime-info.{c,h}, thunar-vfs/thunar-vfs-thumb.c, + thunar-vfs/thunar-vfs.symbols: Turn ThunarVfsMimeInfo into a boxed + type. + * thunar-vfs/thunar-vfs-mime-provider.c: No need to provide fallback + implementations for the virtual methods, as both providers implement + all virtual methods. + * thunar-vfs/thunar-vfs-mime-provider.{c,h}, + thunar-vfs/thunar-vfs-mime-cache.c, + thunar-vfs/thunar-vfs-mime-legacy.c, + thunar-vfs/thunar-vfs-mime-database.c: Derive the MIME providers from + GObject instead of ExoObject. + * thunar-vfs/thunar-vfs-mime-database.c, thunar-vfs/thunar-vfs-info.c, + thunar-vfs/thunar-vfs-thumb.c, thunar-vfs/thunar-vfs.c, + thunar/thunar-computer-folder.c, thunar/thunar-file.c, + thunar/thunar-open-with-action.c, thunar/thunar-trash-folder.c: + Derive ThunarVfsMimeDatabase from GObject instead of ExoObject. + 2005-09-13 Benedikt Meurer <benny@xfce.org> * thunar-vfs/thunar-vfs-sysdep.h: Add inline atomic operations. diff --git a/thunar-vfs/thunar-vfs-info.c b/thunar-vfs/thunar-vfs-info.c index 0d84df487a51f29bbe8a70fa1661ddfb5558c5a5..afb62883cad56dae455a339aab3491386d291778 100644 --- a/thunar-vfs/thunar-vfs-info.c +++ b/thunar-vfs/thunar-vfs-info.c @@ -61,6 +61,10 @@ +static ThunarVfsMimeDatabase *mime_database = NULL; + + + GType thunar_vfs_info_get_type (void) { @@ -94,16 +98,14 @@ ThunarVfsInfo* thunar_vfs_info_new_for_uri (ThunarVfsURI *uri, GError **error) { - ThunarVfsMimeDatabase *database; - ThunarVfsMimeInfo *mime_info; - ThunarVfsInfo *info; - const gchar *path; - const gchar *str; - struct stat lsb; - struct stat sb; - XfceRc *rc; - GList *mime_infos; - GList *lp; + ThunarVfsInfo *info; + const gchar *path; + const gchar *str; + struct stat lsb; + struct stat sb; + XfceRc *rc; + GList *mime_infos; + GList *lp; g_return_val_if_fail (error == NULL || *error == NULL, NULL); @@ -170,48 +172,46 @@ thunar_vfs_info_new_for_uri (ThunarVfsURI *uri, } /* determine the file's mime type */ - database = thunar_vfs_mime_database_get_default (); switch (info->type) { case THUNAR_VFS_FILE_TYPE_SOCKET: - info->mime_info = thunar_vfs_mime_database_get_info (database, "inode/socket"); + info->mime_info = thunar_vfs_mime_database_get_info (mime_database, "inode/socket"); break; case THUNAR_VFS_FILE_TYPE_SYMLINK: - info->mime_info = thunar_vfs_mime_database_get_info (database, "inode/symlink"); + info->mime_info = thunar_vfs_mime_database_get_info (mime_database, "inode/symlink"); break; case THUNAR_VFS_FILE_TYPE_BLOCKDEV: - info->mime_info = thunar_vfs_mime_database_get_info (database, "inode/blockdevice"); + info->mime_info = thunar_vfs_mime_database_get_info (mime_database, "inode/blockdevice"); break; case THUNAR_VFS_FILE_TYPE_DIRECTORY: - info->mime_info = thunar_vfs_mime_database_get_info (database, "inode/directory"); + info->mime_info = thunar_vfs_mime_database_get_info (mime_database, "inode/directory"); break; case THUNAR_VFS_FILE_TYPE_CHARDEV: - info->mime_info = thunar_vfs_mime_database_get_info (database, "inode/chardevice"); + info->mime_info = thunar_vfs_mime_database_get_info (mime_database, "inode/chardevice"); break; case THUNAR_VFS_FILE_TYPE_FIFO: - info->mime_info = thunar_vfs_mime_database_get_info (database, "inode/fifo"); + info->mime_info = thunar_vfs_mime_database_get_info (mime_database, "inode/fifo"); break; case THUNAR_VFS_FILE_TYPE_REGULAR: /* determine the MIME-type for the regular file */ - info->mime_info = thunar_vfs_mime_database_get_info_for_file (database, path, info->display_name); + info->mime_info = thunar_vfs_mime_database_get_info_for_file (mime_database, path, info->display_name); /* check if the file is executable (for security reasons * we only allow execution of well known file types). */ if ((info->mode & 0444) != 0 && g_access (path, X_OK) == 0) { - mime_infos = thunar_vfs_mime_database_get_infos_for_info (database, info->mime_info); + mime_infos = thunar_vfs_mime_database_get_infos_for_info (mime_database, info->mime_info); for (lp = mime_infos; lp != NULL; lp = lp->next) { - mime_info = THUNAR_VFS_MIME_INFO (lp->data); - if (strcmp (mime_info->name, "application/x-executable") == 0 - || strcmp (mime_info->name, "application/x-shellscript") == 0) + if (strcmp (thunar_vfs_mime_info_get_name (lp->data), "application/x-executable") == 0 + || strcmp (thunar_vfs_mime_info_get_name (lp->data), "application/x-shellscript") == 0) { info->flags |= THUNAR_VFS_FILE_FLAGS_EXECUTABLE; break; @@ -221,7 +221,7 @@ thunar_vfs_info_new_for_uri (ThunarVfsURI *uri, } /* check whether we have a .desktop file here */ - if (G_UNLIKELY (strcmp (info->mime_info->name, "application/x-desktop") == 0)) + if (G_UNLIKELY (strcmp (thunar_vfs_mime_info_get_name (info->mime_info), "application/x-desktop") == 0)) { /* try to query the hints from the .desktop file */ rc = xfce_rc_simple_open (path, TRUE); @@ -263,7 +263,6 @@ thunar_vfs_info_new_for_uri (ThunarVfsURI *uri, g_assert_not_reached (); break; } - exo_object_unref (EXO_OBJECT (database)); return info; } @@ -371,7 +370,7 @@ thunar_vfs_info_execute (const ThunarVfsInfo *info, path = thunar_vfs_uri_get_path (info->uri); /* check if we have a .desktop file here */ - if (G_UNLIKELY (strcmp (info->mime_info->name, "application/x-desktop") == 0)) + if (G_UNLIKELY (strcmp (thunar_vfs_mime_info_get_name (info->mime_info), "application/x-desktop") == 0)) { rc = xfce_rc_simple_open (path, TRUE); if (G_LIKELY (rc != NULL)) @@ -457,18 +456,17 @@ thunar_vfs_info_rename (ThunarVfsInfo *info, const gchar *name, GError **error) { - ThunarVfsMimeDatabase *database; - const gchar * const *locale; - const gchar *src_path; - GKeyFile *key_file; - gsize data_length; - gchar *data; - gchar *key; - gchar *dir_name; - gchar *dst_name; - gchar *dst_path; + const gchar * const *locale; + const gchar *src_path; + GKeyFile *key_file; + gsize data_length; + gchar *data; + gchar *key; + gchar *dir_name; + gchar *dst_name; + gchar *dst_path; #if !GLIB_CHECK_VERSION(2,8,0) - FILE *fp; + FILE *fp; #endif g_return_val_if_fail (info != NULL, FALSE); @@ -487,7 +485,7 @@ thunar_vfs_info_rename (ThunarVfsInfo *info, src_path = thunar_vfs_uri_get_path (info->uri); /* check whether we have a .desktop file here */ - if (G_UNLIKELY (strcmp (info->mime_info->name, "application/x-desktop") == 0)) + if (G_UNLIKELY (strcmp (thunar_vfs_mime_info_get_name (info->mime_info), "application/x-desktop") == 0)) { /* try to open the .desktop file */ key_file = g_key_file_new (); @@ -600,9 +598,7 @@ thunar_vfs_info_rename (ThunarVfsInfo *info, if (G_LIKELY (info->type == THUNAR_VFS_FILE_TYPE_REGULAR)) { thunar_vfs_mime_info_unref (info->mime_info); - database = thunar_vfs_mime_database_get_default (); - info->mime_info = thunar_vfs_mime_database_get_info_for_file (database, dst_path, info->display_name); - exo_object_unref (EXO_OBJECT (database)); + info->mime_info = thunar_vfs_mime_database_get_info_for_file (mime_database, dst_path, info->display_name); } /* clean up */ @@ -703,5 +699,36 @@ thunar_vfs_info_list_free (GList *info_list) +/** + * _thunar_vfs_info_init: + * + * Initializes the info component of the Thunar-VFS + * library. + **/ +void +_thunar_vfs_info_init (void) +{ + /* grab a reference on the mime database */ + mime_database = thunar_vfs_mime_database_get_default (); +} + + + +/** + * _thunar_vfs_info_shutdown: + * + * Shuts down the info component of the Thunar-VFS + * library. + **/ +void +_thunar_vfs_info_shutdown (void) +{ + /* release the reference on the mime database */ + g_object_unref (G_OBJECT (mime_database)); + mime_database = NULL; +} + + + #define __THUNAR_VFS_INFO_C__ #include <thunar-vfs/thunar-vfs-aliasdef.c> diff --git a/thunar-vfs/thunar-vfs-mime-cache.c b/thunar-vfs/thunar-vfs-mime-cache.c index 5f64db3a3885c2a331f9f6d87e89970f28770ccd..806a65cb5f19c03b9a85ae7a28df5f4f5cb73837 100644 --- a/thunar-vfs/thunar-vfs-mime-cache.c +++ b/thunar-vfs/thunar-vfs-mime-cache.c @@ -70,7 +70,7 @@ static void thunar_vfs_mime_cache_class_init (ThunarVfsMimeCacheClass *klass); -static void thunar_vfs_mime_cache_finalize (ExoObject *object); +static void thunar_vfs_mime_cache_finalize (GObject *object); static const gchar *thunar_vfs_mime_cache_lookup_data (ThunarVfsMimeProvider *provider, gconstpointer data, gsize length, @@ -108,7 +108,7 @@ struct _ThunarVfsMimeCache -static ExoObjectClass *thunar_vfs_mime_cache_parent_class; +static GObjectClass *thunar_vfs_mime_cache_parent_class; @@ -146,12 +146,12 @@ static void thunar_vfs_mime_cache_class_init (ThunarVfsMimeCacheClass *klass) { ThunarVfsMimeProviderClass *thunarvfs_mime_provider_class; - ExoObjectClass *exoobject_class; + GObjectClass *gobject_class; thunar_vfs_mime_cache_parent_class = g_type_class_peek_parent (klass); - exoobject_class = EXO_OBJECT_CLASS (klass); - exoobject_class->finalize = thunar_vfs_mime_cache_finalize; + gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = thunar_vfs_mime_cache_finalize; thunarvfs_mime_provider_class = THUNAR_VFS_MIME_PROVIDER_CLASS (klass); thunarvfs_mime_provider_class->lookup_data = thunar_vfs_mime_cache_lookup_data; @@ -167,7 +167,7 @@ thunar_vfs_mime_cache_class_init (ThunarVfsMimeCacheClass *klass) static void -thunar_vfs_mime_cache_finalize (ExoObject *object) +thunar_vfs_mime_cache_finalize (GObject *object) { ThunarVfsMimeCache *cache = THUNAR_VFS_MIME_CACHE (object); @@ -176,7 +176,7 @@ thunar_vfs_mime_cache_finalize (ExoObject *object) munmap (cache->buffer, cache->bufsize); #endif - (*EXO_OBJECT_CLASS (thunar_vfs_mime_cache_parent_class)->finalize) (object); + (*G_OBJECT_CLASS (thunar_vfs_mime_cache_parent_class)->finalize) (object); } @@ -515,7 +515,7 @@ thunar_vfs_mime_cache_get_max_buffer_extents (ThunarVfsMimeProvider *provider) * %NULL if for some reason, @directory could not be opened * as a #ThunarVfsMimeCache. * - * The caller is responsible to call #exo_object_unref() + * The caller is responsible to call g_object_unref() * on the returned instance. * * Return value: a #ThunarVfsMimeCache for @directory or %NULL. @@ -556,7 +556,7 @@ thunar_vfs_mime_cache_new (const gchar *directory) } /* allocate a new cache provider */ - cache = exo_object_new (THUNAR_VFS_TYPE_MIME_CACHE); + cache = g_object_new (THUNAR_VFS_TYPE_MIME_CACHE, NULL); cache->buffer = buffer; cache->bufsize = stat.st_size; diff --git a/thunar-vfs/thunar-vfs-mime-database.c b/thunar-vfs/thunar-vfs-mime-database.c index da8b715d05bfe9339b3f055e7ef98abe96e076fd..e858567d72f189f750705a10c7ec3c5c57386646 100644 --- a/thunar-vfs/thunar-vfs-mime-database.c +++ b/thunar-vfs/thunar-vfs-mime-database.c @@ -77,7 +77,7 @@ typedef struct _ThunarVfsMimeProviderData ThunarVfsMimeProviderData; static void thunar_vfs_mime_database_class_init (ThunarVfsMimeDatabaseClass *klass); static void thunar_vfs_mime_database_init (ThunarVfsMimeDatabase *database); -static void thunar_vfs_mime_database_finalize (ExoObject *object); +static void thunar_vfs_mime_database_finalize (GObject *object); static ThunarVfsMimeApplication *thunar_vfs_mime_database_get_application_locked (ThunarVfsMimeDatabase *database, const gchar *desktop_id); static ThunarVfsMimeInfo *thunar_vfs_mime_database_get_info_locked (ThunarVfsMimeDatabase *database, @@ -107,12 +107,12 @@ static void thunar_vfs_mime_database_store_parse_file struct _ThunarVfsMimeDatabaseClass { - ExoObjectClass __parent__; + GObjectClass __parent__; }; struct _ThunarVfsMimeDatabase { - ExoObject __parent__; + GObject __parent__; GMutex *lock; @@ -154,21 +154,17 @@ struct _ThunarVfsMimeProviderData -static ThunarVfsMimeDatabase *thunar_vfs_mime_database_shared_instance = NULL; - - - -G_DEFINE_TYPE (ThunarVfsMimeDatabase, thunar_vfs_mime_database, EXO_TYPE_OBJECT); +G_DEFINE_TYPE (ThunarVfsMimeDatabase, thunar_vfs_mime_database, G_TYPE_OBJECT); static void thunar_vfs_mime_database_class_init (ThunarVfsMimeDatabaseClass *klass) { - ExoObjectClass *exoobject_class; + GObjectClass *gobject_class; - exoobject_class = EXO_OBJECT_CLASS (klass); - exoobject_class->finalize = thunar_vfs_mime_database_finalize; + gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = thunar_vfs_mime_database_finalize; } @@ -183,7 +179,7 @@ thunar_vfs_mime_database_init (ThunarVfsMimeDatabase *database) database->monitor = thunar_vfs_monitor_get_default (); /* allocate the hash table for the mime infos */ - database->infos = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, exo_object_unref); + database->infos = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) thunar_vfs_mime_info_unref); /* grab references on commonly used mime infos */ database->application_octet_stream = thunar_vfs_mime_database_get_info_locked (database, "application/octet-stream"); @@ -202,7 +198,7 @@ thunar_vfs_mime_database_init (ThunarVfsMimeDatabase *database) static void -thunar_vfs_mime_database_finalize (ExoObject *object) +thunar_vfs_mime_database_finalize (GObject *object) { ThunarVfsMimeDatabase *database = THUNAR_VFS_MIME_DATABASE (object); @@ -216,8 +212,8 @@ thunar_vfs_mime_database_finalize (ExoObject *object) g_hash_table_destroy (database->applications); /* free commonly used mime infos */ - exo_object_unref (database->application_octet_stream); - exo_object_unref (database->text_plain); + thunar_vfs_mime_info_unref (database->application_octet_stream); + thunar_vfs_mime_info_unref (database->text_plain); /* free all mime infos */ g_hash_table_destroy (database->infos); @@ -225,15 +221,11 @@ thunar_vfs_mime_database_finalize (ExoObject *object) /* release the reference on the file alteration monitor */ g_object_unref (G_OBJECT (database->monitor)); - /* reset the shared instance pointer, as we're the last one to release it */ - g_atomic_pointer_compare_and_exchange ((gpointer) &thunar_vfs_mime_database_shared_instance, - (gpointer) database, (gpointer) NULL); - /* release the mutex for this object */ g_mutex_free (database->lock); /* call the parent's finalize method */ - (*EXO_OBJECT_CLASS (thunar_vfs_mime_database_parent_class)->finalize) (object); + (*G_OBJECT_CLASS (thunar_vfs_mime_database_parent_class)->finalize) (object); } @@ -259,7 +251,7 @@ thunar_vfs_mime_database_get_application_locked (ThunarVfsMimeDatabase *database /* take an additional reference for the caller */ if (G_LIKELY (application != NULL)) - exo_object_ref (EXO_OBJECT (application)); + g_object_ref (EXO_OBJECT (application)); return application; } @@ -302,19 +294,17 @@ thunar_vfs_mime_database_get_info_locked (ThunarVfsMimeDatabase *database, /* fallback to 'application/octet-stream' if the type is invalid */ if (G_UNLIKELY (n != 1)) - return exo_object_ref (database->application_octet_stream); + return thunar_vfs_mime_info_ref (database->application_octet_stream); /* allocate the MIME info instance */ - info = exo_object_new (THUNAR_VFS_TYPE_MIME_INFO); - info->name = g_new (gchar, (p - mime_type) + 1); - memcpy (info->name, mime_type, (p - mime_type) + 1); + info = thunar_vfs_mime_info_new (mime_type, (p - mime_type)); - /* insert the mime type into the cache */ - g_hash_table_insert (database->infos, info->name, info); + /* insert the mime type into the cache (w/o taking a copy on the name) */ + g_hash_table_insert (database->infos, (gpointer) thunar_vfs_mime_info_get_name (info), info); } /* take a reference for the caller */ - return exo_object_ref (info); + return thunar_vfs_mime_info_ref (info); } @@ -357,7 +347,7 @@ thunar_vfs_mime_database_get_info_for_data_locked (ThunarVfsMimeDatabase *databa else if (g_utf8_validate (data, length, NULL)) { /* we have valid UTF-8 text here! */ - info = exo_object_ref (database->text_plain); + info = thunar_vfs_mime_info_ref (database->text_plain); } } @@ -472,7 +462,7 @@ thunar_vfs_mime_database_get_infos_for_info_locked (ThunarVfsMimeDatabase *datab } /* all text/xxxx types are subtype of text/plain */ - if (G_UNLIKELY (strncmp ("text/", info->name, 5) == 0)) + if (G_UNLIKELY (strncmp ("text/", thunar_vfs_mime_info_get_name (info), 5) == 0)) { /* append text/plain if we don't have it already */ if (g_list_find (infos, database->text_plain) == NULL) @@ -569,7 +559,7 @@ thunar_vfs_mime_database_shutdown_providers (ThunarVfsMimeDatabase *database) for (lp = database->providers; lp != NULL; lp = lp->next) { if (G_LIKELY (THUNAR_VFS_MIME_PROVIDER_DATA (lp->data)->provider != NULL)) - exo_object_unref (THUNAR_VFS_MIME_PROVIDER_DATA (lp->data)->provider); + g_object_unref (THUNAR_VFS_MIME_PROVIDER_DATA (lp->data)->provider); thunar_vfs_uri_unref (THUNAR_VFS_MIME_PROVIDER_DATA (lp->data)->uri); g_free (THUNAR_VFS_MIME_PROVIDER_DATA (lp->data)); } @@ -605,7 +595,7 @@ thunar_vfs_mime_database_initialize_stores (ThunarVfsMimeDatabase *database) path = g_build_filename (basedirs[n], "applications" G_DIR_SEPARATOR_S "defaults.list", NULL); store->defaults_list = g_hash_table_new_full (thunar_vfs_mime_info_hash, thunar_vfs_mime_info_equal, - thunar_vfs_mime_info_unref, + (GDestroyNotify) thunar_vfs_mime_info_unref, (GDestroyNotify) g_strfreev); store->defaults_list_uri = thunar_vfs_uri_new_for_path (path); store->defaults_list_handle = thunar_vfs_monitor_add_file (database->monitor, store->defaults_list_uri, @@ -617,7 +607,7 @@ thunar_vfs_mime_database_initialize_stores (ThunarVfsMimeDatabase *database) path = g_build_filename (basedirs[n], "applications" G_DIR_SEPARATOR_S "mimeinfo.cache", NULL); store->mimeinfo_cache = g_hash_table_new_full (thunar_vfs_mime_info_hash, thunar_vfs_mime_info_equal, - thunar_vfs_mime_info_unref, + (GDestroyNotify) thunar_vfs_mime_info_unref, (GDestroyNotify) g_strfreev); store->mimeinfo_cache_uri = thunar_vfs_uri_new_for_path (path); store->mimeinfo_cache_handle = thunar_vfs_monitor_add_file (database->monitor, store->mimeinfo_cache_uri, @@ -790,7 +780,7 @@ thunar_vfs_mime_database_store_parse_file (ThunarVfsMimeDatabase *database, * thunar_vfs_mime_database_get_default: * * Returns a reference on the shared #ThunarVfsMimeDatabase - * instance. The caller is responsible to call #exo_object_unref() + * instance. The caller is responsible to call g_object_unref() * on the returned object when no longer needed. * * Return value: the shared #ThunarVfsMimeDatabase. @@ -798,12 +788,19 @@ thunar_vfs_mime_database_store_parse_file (ThunarVfsMimeDatabase *database, ThunarVfsMimeDatabase* thunar_vfs_mime_database_get_default (void) { - if (G_UNLIKELY (thunar_vfs_mime_database_shared_instance == NULL)) - thunar_vfs_mime_database_shared_instance = exo_object_new (THUNAR_VFS_TYPE_MIME_DATABASE); + static ThunarVfsMimeDatabase *database = NULL; + + if (G_UNLIKELY (database == NULL)) + { + database = g_object_new (THUNAR_VFS_TYPE_MIME_DATABASE, NULL); + g_object_add_weak_pointer (G_OBJECT (database), (gpointer) &database); + } else - exo_object_ref (EXO_OBJECT (thunar_vfs_mime_database_shared_instance)); + { + g_object_ref (G_OBJECT (database)); + } - return thunar_vfs_mime_database_shared_instance; + return database; } @@ -814,7 +811,7 @@ thunar_vfs_mime_database_get_default (void) * @mime_type : the string representation of the mime type. * * Determines the #ThunarVfsMimeInfo which corresponds to @mime_type - * in database. The caller is responsible to call #exo_object_unref() + * in database. The caller is responsible to call thunar_vfs_mime_info_unref() * on the returned instance. * * Return value: the #ThunarVfsMimeInfo corresponding to @mime_type in @database. @@ -844,8 +841,8 @@ thunar_vfs_mime_database_get_info (ThunarVfsMimeDatabase *database, * @length : the length of @data in bytes. * * Determines the #ThunarVfsMimeInfo for @data in @database. The - * caller is responsible to call #exo_object_unref() on the - * returned instance. + * caller is responsible to call thunar_vfs_mime_info_unref() on + * the returned instance. * * Return value: the #ThunarVfsMimeInfo determined for @data. **/ @@ -865,7 +862,7 @@ thunar_vfs_mime_database_get_info_for_data (ThunarVfsMimeDatabase *database, /* fallback to 'application/octet-stream' if we could not determine any type */ if (G_UNLIKELY (info == NULL)) - info = exo_object_ref (database->application_octet_stream); + info = thunar_vfs_mime_info_ref (database->application_octet_stream); return info; } @@ -879,7 +876,7 @@ thunar_vfs_mime_database_get_info_for_data (ThunarVfsMimeDatabase *database, * * Determines the #ThunarVfsMimeInfo for the filename given * in @name from @database. The caller is responsible to - * call #exo_object_unref() on the returned instance. + * call thunar_vfs_mime_info_unref() on the returned instance. * * The @name must be a valid filename in UTF-8 encoding * and it may not contained any slashes! @@ -904,7 +901,7 @@ thunar_vfs_mime_database_get_info_for_name (ThunarVfsMimeDatabase *database, /* fallback to 'application/octet-stream' */ if (G_UNLIKELY (info == NULL)) - info = exo_object_ref (database->application_octet_stream); + info = thunar_vfs_mime_info_ref (database->application_octet_stream); /* we got it */ return info; @@ -920,7 +917,7 @@ thunar_vfs_mime_database_get_info_for_name (ThunarVfsMimeDatabase *database, * * Determines the #ThunarVfsMimeInfo for @path in @database. The * caller is responsible to free the returned instance using - * #exo_object_unref(). + * thunar_vfs_mime_info_unref(). * * The @name parameter is optional. If the caller already knows the * basename of @path in UTF-8 encoding, it should be specified here @@ -1121,7 +1118,6 @@ thunar_vfs_mime_database_get_infos_for_info (ThunarVfsMimeDatabase *database, GList *infos; g_return_val_if_fail (THUNAR_VFS_IS_MIME_DATABASE (database), NULL); - g_return_val_if_fail (THUNAR_VFS_IS_MIME_INFO (info), NULL); g_mutex_lock (database->lock); infos = thunar_vfs_mime_database_get_infos_for_info_locked (database, info); @@ -1160,7 +1156,6 @@ thunar_vfs_mime_database_get_applications (ThunarVfsMimeDatabase *database, guint n; g_return_val_if_fail (THUNAR_VFS_IS_MIME_DATABASE (database), NULL); - g_return_val_if_fail (THUNAR_VFS_IS_MIME_INFO (info), NULL); g_mutex_lock (database->lock); @@ -1211,7 +1206,7 @@ thunar_vfs_mime_database_get_applications (ThunarVfsMimeDatabase *database, * is set for @info. * * The caller is responsible to free the returned instance - * using #exo_object_unref(). + * using exo_object_unref(). * * Return value: the default #ThunarVfsMimeApplication for * @info or %NULL. @@ -1229,7 +1224,6 @@ thunar_vfs_mime_database_get_default_application (ThunarVfsMimeDatabase *databas guint n; g_return_val_if_fail (THUNAR_VFS_IS_MIME_DATABASE (database), NULL); - g_return_val_if_fail (THUNAR_VFS_IS_MIME_INFO (info), NULL); g_mutex_lock (database->lock); diff --git a/thunar-vfs/thunar-vfs-mime-info.c b/thunar-vfs/thunar-vfs-mime-info.c index b3a31ab8692ddfa7becb3c96087a5cea0deaad3a..9cbddfe34f7ef9e4fba87e3fe2735eac1358cd82 100644 --- a/thunar-vfs/thunar-vfs-mime-info.c +++ b/thunar-vfs/thunar-vfs-mime-info.c @@ -31,6 +31,7 @@ #include <thunar-vfs/thunar-vfs-mime-info.h> #include <thunar-vfs/thunar-vfs-mime-parser.h> +#include <thunar-vfs/thunar-vfs-sysdep.h> #include <thunar-vfs/thunar-vfs-alias.h> @@ -50,17 +51,22 @@ static const struct -static void thunar_vfs_mime_info_register_type (GType *type); -static void thunar_vfs_mime_info_class_init (ThunarVfsMimeInfoClass *klass); -static void thunar_vfs_mime_info_finalize (ExoObject *object); static void thunar_vfs_mime_info_icon_theme_changed (GtkIconTheme *icon_theme, ThunarVfsMimeInfo *info); +struct _ThunarVfsMimeInfo +{ + gint ref_count; + gchar *comment; + gchar *name; -static ExoObjectClass *thunar_vfs_mime_info_parent_class; + gchar *icon_name; + gboolean icon_name_static : 1; + GtkIconTheme *icon_theme; +}; @@ -68,10 +74,13 @@ GType thunar_vfs_mime_info_get_type (void) { static GType type = G_TYPE_INVALID; - static GOnce once = G_ONCE_INIT; - /* thread-safe type registration */ - g_once (&once, (GThreadFunc) thunar_vfs_mime_info_register_type, &type); + if (G_UNLIKELY (type == G_TYPE_INVALID)) + { + type = g_boxed_type_register_static ("ThunarVfsMimeInfo", + (GBoxedCopyFunc) thunar_vfs_mime_info_ref, + (GBoxedFreeFunc) thunar_vfs_mime_info_unref); + } return type; } @@ -79,100 +88,136 @@ thunar_vfs_mime_info_get_type (void) static void -thunar_vfs_mime_info_register_type (GType *type) +thunar_vfs_mime_info_icon_theme_changed (GtkIconTheme *icon_theme, + ThunarVfsMimeInfo *info) { - static const GTypeInfo info = - { - sizeof (ThunarVfsMimeInfoClass), - NULL, - NULL, - (GClassInitFunc) thunar_vfs_mime_info_class_init, - NULL, - NULL, - sizeof (ThunarVfsMimeInfo), - 128u, - NULL, - NULL, - }; - - *type = g_type_register_static (EXO_TYPE_OBJECT, "ThunarVfsMimeInfo", &info, 0); + g_return_if_fail (GTK_IS_ICON_THEME (icon_theme)); + g_return_if_fail (info->icon_theme == icon_theme); + + /* drop the cached icon name, so the next lookup + * call will perform a lookup again. + */ + if (G_LIKELY (!info->icon_name_static)) + { + g_free (info->icon_name); + info->icon_name = NULL; + } } -static void -thunar_vfs_mime_info_class_init (ThunarVfsMimeInfoClass *klass) +/** + * thunar_vfs_mime_info_new: + * @name : the mime type name. + * @len : the length of @name or %-1 if zero-terminated. + * + * Allocates a new #ThunarVfsMimeInfo object with an + * initial reference count of one and sets it to the + * given @name. + * + * Note that no checking is performed on the given @name. + * You should not normally use this function, but use + * thunar_vfs_mime_database_get_info() instead. + * + * In addition, if you allocate #ThunarVfsMimeInfo<!---->s + * using this function, you cannot mix them with the objects + * allocated in a #ThunarVfsMimeDatabase, because the + * #ThunarVfsMimeDatabase and associated functions assume + * that #ThunarVfsMimeInfo objects are unique. + * + * Return value: the newly allocated #ThunarVfsMimeInfo. + **/ +ThunarVfsMimeInfo* +thunar_vfs_mime_info_new (const gchar *name, + gssize len) { - ExoObjectClass *exoobject_class; + ThunarVfsMimeInfo *info; + + if (G_UNLIKELY (len < 0)) + len = strlen (name); - thunar_vfs_mime_info_parent_class = g_type_class_peek_parent (klass); + /* allocate the new object */ + info = g_new (ThunarVfsMimeInfo, 1); + info->ref_count = 1; + info->comment = NULL; + info->icon_name = NULL; + info->icon_theme = NULL; + info->icon_name_static = FALSE; + + /* set the name */ + info->name = g_new (gchar, len + 1); + memcpy (info->name, name, len + 1); - exoobject_class = EXO_OBJECT_CLASS (klass); - exoobject_class->finalize = thunar_vfs_mime_info_finalize; + return info; } -static void -thunar_vfs_mime_info_finalize (ExoObject *object) +/** + * thunar_vfs_mime_info_ref: + * @info : a #ThunarVfsMimeInfo. + * + * Increments the reference count on @info and returns + * the reference to @info. + * + * Return value: a reference to @info. + **/ +ThunarVfsMimeInfo* +thunar_vfs_mime_info_ref (ThunarVfsMimeInfo *info) { - ThunarVfsMimeInfo *info = THUNAR_VFS_MIME_INFO (object); + _thunar_vfs_sysdep_inc (&info->ref_count); + return info; +} + - g_return_if_fail (THUNAR_VFS_IS_MIME_INFO (info)); - /* free the comment */ - if (info->comment != NULL && info->comment != info->name) +/** + * thunar_vfs_mime_info_unref: + * @info : a #ThunarVfsMimeInfo. + * + * Decrements the reference count on @info and releases + * the resources allocated for @info once the reference + * count drops to zero. + **/ +void +thunar_vfs_mime_info_unref (ThunarVfsMimeInfo *info) +{ + if (_thunar_vfs_sysdep_dec (&info->ref_count)) { + /* free the comment */ + if (info->comment != NULL && info->comment != info->name) + { #ifndef G_DISABLE_CHECKS - memset (info->comment, 0xaa, strlen (info->comment) + 1); + memset (info->comment, 0xaa, strlen (info->comment) + 1); #endif - g_free (info->comment); - } + g_free (info->comment); + } - /* free the name */ + /* free the name */ #ifndef G_DISABLE_CHECKS - if (G_LIKELY (info->name != NULL)) - memset (info->name, 0xaa, strlen (info->name) + 1); + if (G_LIKELY (info->name != NULL)) + memset (info->name, 0xaa, strlen (info->name) + 1); #endif - g_free (info->name); + g_free (info->name); - /* disconnect from the icon theme (if any) */ - if (G_LIKELY (info->icon_theme != NULL)) - { - g_signal_handlers_disconnect_by_func (G_OBJECT (info->icon_theme), thunar_vfs_mime_info_icon_theme_changed, info); - g_object_unref (G_OBJECT (info->icon_theme)); - } + /* disconnect from the icon theme (if any) */ + if (G_LIKELY (info->icon_theme != NULL)) + { + g_signal_handlers_disconnect_by_func (G_OBJECT (info->icon_theme), thunar_vfs_mime_info_icon_theme_changed, info); + g_object_unref (G_OBJECT (info->icon_theme)); + } - /* free the icon name if it isn't one of the statics */ - if (G_LIKELY (!info->icon_name_static && info->icon_name != NULL)) - { + /* free the icon name if it isn't one of the statics */ + if (G_LIKELY (!info->icon_name_static && info->icon_name != NULL)) + { #ifndef G_DISABLE_CHECKS - memset (info->icon_name, 0xaa, strlen (info->icon_name) + 1); + memset (info->icon_name, 0xaa, strlen (info->icon_name) + 1); #endif - g_free (info->icon_name); - } - - /* invoke the parent's finalize method */ - (*EXO_OBJECT_CLASS (thunar_vfs_mime_info_parent_class)->finalize) (object); -} - - - -static void -thunar_vfs_mime_info_icon_theme_changed (GtkIconTheme *icon_theme, - ThunarVfsMimeInfo *info) -{ - g_return_if_fail (GTK_IS_ICON_THEME (icon_theme)); - g_return_if_fail (THUNAR_VFS_IS_MIME_INFO (info)); - g_return_if_fail (info->icon_theme == icon_theme); + g_free (info->icon_name); + } - /* drop the cached icon name, so the next lookup - * call will perform a lookup again. - */ - if (G_LIKELY (!info->icon_name_static)) - { - g_free (info->icon_name); - info->icon_name = NULL; + /* free the info struct */ + g_free (info); } } @@ -196,8 +241,6 @@ thunar_vfs_mime_info_get_comment (ThunarVfsMimeInfo *info) gchar *path; gchar *spec; - g_return_val_if_fail (THUNAR_VFS_IS_MIME_INFO (info), NULL); - if (G_UNLIKELY (info->comment == NULL)) { spec = g_strdup_printf ("mime/%s.xml", info->name); @@ -237,7 +280,6 @@ thunar_vfs_mime_info_get_comment (ThunarVfsMimeInfo *info) const gchar* thunar_vfs_mime_info_get_name (const ThunarVfsMimeInfo *info) { - g_return_val_if_fail (THUNAR_VFS_IS_MIME_INFO (info), NULL); return info->name; } @@ -261,8 +303,6 @@ thunar_vfs_mime_info_get_media (const ThunarVfsMimeInfo *info) { const gchar *p; - g_return_val_if_fail (THUNAR_VFS_IS_MIME_INFO (info), NULL); - /* lookup the slash character */ for (p = info->name; *p != '/' && *p != '\0'; ++p) ; @@ -290,8 +330,6 @@ thunar_vfs_mime_info_get_subtype (const ThunarVfsMimeInfo *info) { const gchar *p; - g_return_val_if_fail (THUNAR_VFS_IS_MIME_INFO (info), NULL); - /* lookup the slash character */ for (p = info->name; *p != '/' && *p != '\0'; ++p) ; @@ -316,12 +354,11 @@ thunar_vfs_mime_info_get_subtype (const ThunarVfsMimeInfo *info) guint thunar_vfs_mime_info_hash (gconstpointer info) { - const gchar *p; - guint h; - - g_return_val_if_fail (THUNAR_VFS_IS_MIME_INFO (info), 0); + const ThunarVfsMimeInfo *infop = info; + const gchar *p; + guint h; - for (h = THUNAR_VFS_MIME_INFO (info)->name[0], p = THUNAR_VFS_MIME_INFO (info)->name + 1; *p != '\0'; ++p) + for (h = infop->name[0], p = infop->name + 1; *p != '\0'; ++p) h = (h << 5) - h + *p; return h; @@ -343,10 +380,10 @@ gboolean thunar_vfs_mime_info_equal (gconstpointer a, gconstpointer b) { - g_return_val_if_fail (THUNAR_VFS_IS_MIME_INFO (a), FALSE); - g_return_val_if_fail (THUNAR_VFS_IS_MIME_INFO (b), FALSE); + const ThunarVfsMimeInfo *a_info = a; + const ThunarVfsMimeInfo *b_info = b; - return (a == b) || G_UNLIKELY (strcmp (THUNAR_VFS_MIME_INFO (a)->name, THUNAR_VFS_MIME_INFO (b)->name) == 0); + return (a == b) || G_UNLIKELY (strcmp (a_info->name, b_info->name) == 0); } @@ -358,8 +395,8 @@ thunar_vfs_mime_info_equal (gconstpointer a, * * Tries to determine the name of a suitable icon for @info * in @icon_theme. The returned icon name can then be used - * in calls to #gtk_icon_theme_lookup_icon() or - * #gtk_icon_theme_load_icon(). + * in calls to gtk_icon_theme_lookup_icon() or + * gtk_icon_theme_load_icon(). * * Note that this method MUST NOT be called from threads other than * the main thread, because it's not thread-safe! @@ -375,7 +412,6 @@ thunar_vfs_mime_info_lookup_icon_name (ThunarVfsMimeInfo *info, gchar *media; gsize n; - g_return_val_if_fail (THUNAR_VFS_IS_MIME_INFO (info), NULL); g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL); /* check if our cached name will suffice */ diff --git a/thunar-vfs/thunar-vfs-mime-info.h b/thunar-vfs/thunar-vfs-mime-info.h index b469de499d789ca9188408daea9c1002bcc110a8..804baead248d791c2a3d5ab19a31db4aa3d86a42 100644 --- a/thunar-vfs/thunar-vfs-mime-info.h +++ b/thunar-vfs/thunar-vfs-mime-info.h @@ -21,41 +21,21 @@ #ifndef __THUNAR_VFS_MIME_INFO_H__ #define __THUNAR_VFS_MIME_INFO_H__ -#include <exo/exo.h> +#include <gtk/gtk.h> G_BEGIN_DECLS; -typedef struct _ThunarVfsMimeInfoClass ThunarVfsMimeInfoClass; -typedef struct _ThunarVfsMimeInfo ThunarVfsMimeInfo; +typedef struct _ThunarVfsMimeInfo ThunarVfsMimeInfo; -#define THUNAR_VFS_TYPE_MIME_INFO (thunar_vfs_mime_info_get_type ()) -#define THUNAR_VFS_MIME_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_VFS_TYPE_MIME_INFO, ThunarVfsMimeInfo)) -#define THUNAR_VFS_MIME_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), THUNAR_VFS_TYPE_MIME_INFO, ThunarVfsMimeInfoClass)) -#define THUNAR_VFS_IS_MIME_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THUNAR_VFS_TYPE_MIME_INFO)) -#define THUNAR_VFS_IS_MIME_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_VFS_TYPE_MIME_INFO)) -#define THUNAR_VFS_MIME_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_VFS_TYPE_MIME_INFO, ThunarVfsMimeInfoClass)) - -struct _ThunarVfsMimeInfoClass -{ - ExoObjectClass __parent__; -}; - -struct _ThunarVfsMimeInfo -{ - ExoObject __parent__; - - gchar *comment; - gchar *name; - - gchar *icon_name; - gboolean icon_name_static : 1; - GtkIconTheme *icon_theme; -}; +#define THUNAR_VFS_TYPE_MIME_INFO (thunar_vfs_mime_info_get_type ()) GType thunar_vfs_mime_info_get_type (void) G_GNUC_CONST; -#define thunar_vfs_mime_info_ref exo_object_ref -#define thunar_vfs_mime_info_unref exo_object_unref +ThunarVfsMimeInfo *thunar_vfs_mime_info_new (const gchar *name, + gssize len) G_GNUC_MALLOC; + +ThunarVfsMimeInfo *thunar_vfs_mime_info_ref (ThunarVfsMimeInfo *info); +void thunar_vfs_mime_info_unref (ThunarVfsMimeInfo *info); const gchar *thunar_vfs_mime_info_get_comment (ThunarVfsMimeInfo *info) G_GNUC_PURE; const gchar *thunar_vfs_mime_info_get_name (const ThunarVfsMimeInfo *info) G_GNUC_PURE; diff --git a/thunar-vfs/thunar-vfs-mime-legacy.c b/thunar-vfs/thunar-vfs-mime-legacy.c index c1d7dc91b6f6dd1162f8bafa77bbd677d2d9ca5c..9099c7e7e0719f3f51a6fd30f24cfc011d2fa6e3 100644 --- a/thunar-vfs/thunar-vfs-mime-legacy.c +++ b/thunar-vfs/thunar-vfs-mime-legacy.c @@ -31,6 +31,7 @@ #ifdef HAVE_MEMORY_H #include <memory.h> #endif +#include <stdio.h> #ifdef HAVE_STRING_H #include <string.h> #endif @@ -51,7 +52,7 @@ typedef struct _ThunarVfsMimeLegacySuffix ThunarVfsMimeLegacySuffix; static void thunar_vfs_mime_legacy_class_init (ThunarVfsMimeLegacyClass *klass); static void thunar_vfs_mime_legacy_init (ThunarVfsMimeLegacy *legacy); -static void thunar_vfs_mime_legacy_finalize (ExoObject *object); +static void thunar_vfs_mime_legacy_finalize (GObject *object); static const gchar *thunar_vfs_mime_legacy_lookup_data (ThunarVfsMimeProvider *provider, gconstpointer data, gsize length, @@ -117,7 +118,7 @@ struct _ThunarVfsMimeLegacySuffix -static ExoObjectClass *thunar_vfs_mime_legacy_parent_class; +static GObjectClass *thunar_vfs_mime_legacy_parent_class; @@ -155,12 +156,12 @@ static void thunar_vfs_mime_legacy_class_init (ThunarVfsMimeLegacyClass *klass) { ThunarVfsMimeProviderClass *thunarvfs_mime_provider_class; - ExoObjectClass *exoobject_class; + GObjectClass *gobject_class; thunar_vfs_mime_legacy_parent_class = g_type_class_peek_parent (klass); - exoobject_class = EXO_OBJECT_CLASS (klass); - exoobject_class->finalize = thunar_vfs_mime_legacy_finalize; + gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = thunar_vfs_mime_legacy_finalize; thunarvfs_mime_provider_class = THUNAR_VFS_MIME_PROVIDER_CLASS (klass); thunarvfs_mime_provider_class->lookup_data = thunar_vfs_mime_legacy_lookup_data; @@ -191,7 +192,7 @@ thunar_vfs_mime_legacy_init (ThunarVfsMimeLegacy *legacy) static void -thunar_vfs_mime_legacy_finalize (ExoObject *object) +thunar_vfs_mime_legacy_finalize (GObject *object) { ThunarVfsMimeLegacy *legacy = THUNAR_VFS_MIME_LEGACY (object); @@ -212,7 +213,7 @@ thunar_vfs_mime_legacy_finalize (ExoObject *object) g_mem_chunk_destroy (legacy->suffix_chunk); g_mem_chunk_destroy (legacy->glob_chunk); - (*EXO_OBJECT_CLASS (thunar_vfs_mime_legacy_parent_class)->finalize) (object); + (*G_OBJECT_CLASS (thunar_vfs_mime_legacy_parent_class)->finalize) (object); } @@ -608,7 +609,7 @@ thunar_vfs_mime_legacy_parse_subclasses (ThunarVfsMimeLegacy *legacy, * returns the instance on success, or %NULL on error. * * The caller is responsible to free the returned instance - * using #exo_object_unref(). + * using g_object_unref(). * * Return value: the newly allocated #ThunarVfsMimeLegacy * instance or %NULL on error. @@ -619,12 +620,12 @@ thunar_vfs_mime_legacy_new (const gchar *directory) ThunarVfsMimeLegacy *legacy; /* allocate the new object */ - legacy = exo_object_new (THUNAR_VFS_TYPE_MIME_LEGACY); + legacy = g_object_new (THUNAR_VFS_TYPE_MIME_LEGACY, NULL); /* try to parse the globs file */ if (!thunar_vfs_mime_legacy_parse_globs (legacy, directory)) { - exo_object_unref (legacy); + g_object_unref (legacy); return NULL; } diff --git a/thunar-vfs/thunar-vfs-mime-provider.c b/thunar-vfs/thunar-vfs-mime-provider.c index 6f12052edfc1b9b4413b09c40a8511192f00c1f7..e1b4b8a3a4ceac1cbe0e6cc95515c8d16c8d95b4 100644 --- a/thunar-vfs/thunar-vfs-mime-provider.c +++ b/thunar-vfs/thunar-vfs-mime-provider.c @@ -26,61 +26,30 @@ -static void thunar_vfs_mime_provider_register_type (GType *type); -static void thunar_vfs_mime_provider_class_init (ThunarVfsMimeProviderClass *klass); - - - GType thunar_vfs_mime_provider_get_type (void) { static GType type = G_TYPE_INVALID; - static GOnce once = G_ONCE_INIT; - /* thread-safe type registration */ - g_once (&once, (GThreadFunc) thunar_vfs_mime_provider_register_type, &type); + if (G_UNLIKELY (type == G_TYPE_INVALID)) + { + static const GTypeInfo info = + { + sizeof (ThunarVfsMimeProviderClass), + NULL, + NULL, + NULL, + NULL, + NULL, + sizeof (ThunarVfsMimeProvider), + 0, + NULL, + NULL, + }; + + type = g_type_register_static (G_TYPE_OBJECT, "ThunarVfsMimeProvider", &info, G_TYPE_FLAG_ABSTRACT); + } return type; } - - -static void -thunar_vfs_mime_provider_register_type (GType *type) -{ - static const GTypeInfo info = - { - sizeof (ThunarVfsMimeProviderClass), - NULL, - NULL, - (GClassInitFunc) thunar_vfs_mime_provider_class_init, - NULL, - NULL, - sizeof (ThunarVfsMimeProvider), - 0, - NULL, - NULL, - }; - - *type = g_type_register_static (EXO_TYPE_OBJECT, "ThunarVfsMimeProvider", &info, G_TYPE_FLAG_ABSTRACT); -} - - - -static void -thunar_vfs_mime_provider_class_init (ThunarVfsMimeProviderClass *klass) -{ - /* We install noops for every virtual method here, - * so derived classes don't need to implement - * each and every method if desired. - */ - klass->lookup_data = (gpointer) exo_noop_null; - klass->lookup_literal = (gpointer) exo_noop_null; - klass->lookup_suffix = (gpointer) exo_noop_null; - klass->lookup_glob = (gpointer) exo_noop_null; - klass->lookup_alias = (gpointer) exo_noop_null; - klass->lookup_parents = (gpointer) exo_noop_zero; - klass->get_stop_characters = (gpointer) exo_noop_null; - klass->get_max_buffer_extents = (gpointer) exo_noop_zero; -} - diff --git a/thunar-vfs/thunar-vfs-mime-provider.h b/thunar-vfs/thunar-vfs-mime-provider.h index 50cc921cc92dc24a290c8d7ae13f60c744bd9664..3de333a387463e98708f888cef0f202b320bfd54 100644 --- a/thunar-vfs/thunar-vfs-mime-provider.h +++ b/thunar-vfs/thunar-vfs-mime-provider.h @@ -21,7 +21,7 @@ #ifndef __THUNAR_VFS_MIME_PROVIDER_H__ #define __THUNAR_VFS_MIME_PROVIDER_H__ -#include <exo/exo.h> +#include <glib-object.h> G_BEGIN_DECLS; @@ -37,7 +37,7 @@ typedef struct _ThunarVfsMimeProvider ThunarVfsMimeProvider; struct _ThunarVfsMimeProviderClass { - ExoObjectClass __parent__; + GObjectClass __parent__; const gchar *(*lookup_data) (ThunarVfsMimeProvider *provider, gconstpointer data, @@ -66,7 +66,7 @@ struct _ThunarVfsMimeProviderClass struct _ThunarVfsMimeProvider { - ExoObject __parent__; + GObject __parent__; }; GType thunar_vfs_mime_provider_get_type (void) G_GNUC_CONST; @@ -152,7 +152,7 @@ GType thunar_vfs_mime_provider_get_type (void) G_GNUC_CONST; * * Returns the list of stop characters for all suffix entries in @provider as * a #GList of #gunichar<!---->s. The caller is responsible to free the list - * using #g_list_free(). + * using g_list_free(). * * Return value: the list of stop characters for the suffix entries in @provider. **/ diff --git a/thunar-vfs/thunar-vfs-thumb.c b/thunar-vfs/thunar-vfs-thumb.c index ae4bcb11164b89338577cffda787de5f9180fd96..c8f19121cbebc39529d9cd8c252a464c56212236 100644 --- a/thunar-vfs/thunar-vfs-thumb.c +++ b/thunar-vfs/thunar-vfs-thumb.c @@ -152,7 +152,7 @@ thunar_vfs_thumb_factory_init (ThunarVfsThumbFactory *factory) factory->size = THUNAR_VFS_THUMB_SIZE_NORMAL; /* determine the MIME types supported by GdkPixbuf */ - factory->pixbuf_mime_infos = g_hash_table_new_full (g_direct_hash, g_direct_equal, exo_object_unref, NULL); + factory->pixbuf_mime_infos = g_hash_table_new_full (g_direct_hash, g_direct_equal, (GDestroyNotify) thunar_vfs_mime_info_unref, NULL); formats = gdk_pixbuf_get_formats (); for (lp = formats; lp != NULL; lp = lp->next) if (!gdk_pixbuf_format_is_disabled (lp->data)) @@ -177,7 +177,7 @@ thunar_vfs_thumb_factory_finalize (GObject *object) ThunarVfsThumbFactory *factory = THUNAR_VFS_THUMB_FACTORY (object); /* release the reference on the mime database */ - exo_object_unref (EXO_OBJECT (factory->mime_database)); + g_object_unref (G_OBJECT (factory->mime_database)); /* destroy the hash table with mime infos supported by GdkPixbuf */ g_hash_table_destroy (factory->pixbuf_mime_infos); @@ -324,7 +324,6 @@ thunar_vfs_thumb_factory_can_thumbnail (ThunarVfsThumbFactory *factory, ThunarVfsFileTime mtime) { g_return_val_if_fail (THUNAR_VFS_IS_THUMB_FACTORY (factory), FALSE); - g_return_val_if_fail (THUNAR_VFS_IS_MIME_INFO (mime_info), FALSE); /* we support only local files for thumbnail generation */ if (G_UNLIKELY (thunar_vfs_uri_get_scheme (uri) != THUNAR_VFS_URI_SCHEME_FILE)) @@ -406,7 +405,6 @@ thunar_vfs_thumb_factory_generate_thumbnail (ThunarVfsThumbFactory *factory, gint size; g_return_val_if_fail (THUNAR_VFS_IS_THUMB_FACTORY (factory), NULL); - g_return_val_if_fail (THUNAR_VFS_IS_MIME_INFO (mime_info), NULL); /* we can only generate thumbnails for local files */ if (G_UNLIKELY (thunar_vfs_uri_get_scheme (uri) != THUNAR_VFS_URI_SCHEME_FILE)) diff --git a/thunar-vfs/thunar-vfs.c b/thunar-vfs/thunar-vfs.c index 804f01b74ff8b6cc506d973f4102148a04f291df..441cce218f5073b7ff69983576a75fc6b53c5d5f 100644 --- a/thunar-vfs/thunar-vfs.c +++ b/thunar-vfs/thunar-vfs.c @@ -30,8 +30,7 @@ -static ThunarVfsMimeDatabase *thunar_vfs_mime_database = NULL; -static gint thunar_vfs_ref_count = 0; +static gint thunar_vfs_ref_count = 0; @@ -43,18 +42,17 @@ static gint thunar_vfs_ref_count = 0; void thunar_vfs_init (void) { - extern void _thunar_vfs_job_init (); - extern void _thunar_vfs_uri_init (); + extern void _thunar_vfs_info_init (void); + extern void _thunar_vfs_job_init (void); + extern void _thunar_vfs_uri_init (void); if (g_atomic_int_exchange_and_add (&thunar_vfs_ref_count, 1) == 0) { /* initialize the URIs module */ _thunar_vfs_uri_init (); - /* grab a reference on the mime database, so the global - * instance stays alive while we use the ThunarVFS library. - */ - thunar_vfs_mime_database = thunar_vfs_mime_database_get_default (); + /* initialize the info module */ + _thunar_vfs_info_init (); /* initialize the jobs framework */ _thunar_vfs_job_init (); @@ -71,17 +69,17 @@ thunar_vfs_init (void) void thunar_vfs_shutdown (void) { - extern void _thunar_vfs_job_shutdown (); - extern void _thunar_vfs_uri_shutdown (); + extern void _thunar_vfs_info_shutdown (void); + extern void _thunar_vfs_job_shutdown (void); + extern void _thunar_vfs_uri_shutdown (void); if (g_atomic_int_dec_and_test (&thunar_vfs_ref_count)) { /* shutdown the jobs framework */ _thunar_vfs_job_shutdown (); - /* drop our reference on the global mime database */ - exo_object_unref (EXO_OBJECT (thunar_vfs_mime_database)); - thunar_vfs_mime_database = NULL; + /* release the info module */ + _thunar_vfs_info_shutdown (); /* shutdown the URIs module */ _thunar_vfs_uri_shutdown (); diff --git a/thunar-vfs/thunar-vfs.symbols b/thunar-vfs/thunar-vfs.symbols index 242c27cc2c740db7b27492cd3ccacae39fc1f3c5..3ff25f47f26f9e4bfc4b990f9aed865623d048b8 100644 --- a/thunar-vfs/thunar-vfs.symbols +++ b/thunar-vfs/thunar-vfs.symbols @@ -128,6 +128,9 @@ thunar_vfs_mime_database_get_default_application #if IN_HEADER(__THUNAR_VFS_MIME_INFO_H__) #if IN_SOURCE(__THUNAR_VFS_MIME_INFO_C__) thunar_vfs_mime_info_get_type G_GNUC_CONST +thunar_vfs_mime_info_new G_GNUC_MALLOC +thunar_vfs_mime_info_ref +thunar_vfs_mime_info_unref thunar_vfs_mime_info_get_comment G_GNUC_PURE thunar_vfs_mime_info_get_name G_GNUC_PURE thunar_vfs_mime_info_get_media G_GNUC_MALLOC diff --git a/thunar/thunar-computer-folder.c b/thunar/thunar-computer-folder.c index fda619c878d7f6ba723d140561b90b7c96d36585..9621f688f17130f70b0408d0fdd57ee2a3b1e1a8 100644 --- a/thunar/thunar-computer-folder.c +++ b/thunar/thunar-computer-folder.c @@ -204,7 +204,7 @@ thunar_computer_folder_get_mime_info (ThunarFile *file) database = thunar_vfs_mime_database_get_default (); info = thunar_vfs_mime_database_get_info (database, "inode/directory"); - exo_object_unref (EXO_OBJECT (database)); + g_object_unref (G_OBJECT (database)); return info; } diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 4a7db988228a497d0cb65de895bd2471b76ace47..836d7b6e4d5b7553376054d2f090583b084ec8ff 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -425,7 +425,7 @@ thunar_file_info_has_mime_type (ThunarxFileInfo *file_info, mime_infos = thunar_vfs_mime_database_get_infos_for_info (mime_database, mime_info); for (lp = mime_infos; lp != NULL && !valid; lp = lp->next) valid = (strcmp (thunar_vfs_mime_info_get_name (lp->data), mime_type) == 0); - exo_object_unref (EXO_OBJECT (mime_database)); + g_object_unref (G_OBJECT (mime_database)); thunar_vfs_mime_info_list_free (mime_infos); thunar_vfs_mime_info_unref (mime_info); diff --git a/thunar/thunar-open-with-action.c b/thunar/thunar-open-with-action.c index 89ce38d5c88557b39bd45186c0e1a1787279ed8d..2d3d0a6571e134a9c913d52f1c39da9abf4023b0 100644 --- a/thunar/thunar-open-with-action.c +++ b/thunar/thunar-open-with-action.c @@ -191,7 +191,7 @@ thunar_open_with_action_finalize (GObject *object) { ThunarOpenWithAction *open_with_action = THUNAR_OPEN_WITH_ACTION (object); - exo_object_unref (EXO_OBJECT (open_with_action->mime_database)); + g_object_unref (G_OBJECT (open_with_action->mime_database)); (*G_OBJECT_CLASS (thunar_open_with_action_parent_class)->finalize) (object); } diff --git a/thunar/thunar-trash-folder.c b/thunar/thunar-trash-folder.c index 0e168b098703d0f7cda057c6cb6e96c0fa017c50..7afa5bc37a70d191a34f1f6a412a6895b79278f0 100644 --- a/thunar/thunar-trash-folder.c +++ b/thunar/thunar-trash-folder.c @@ -227,7 +227,7 @@ thunar_trash_folder_get_mime_info (ThunarFile *file) database = thunar_vfs_mime_database_get_default (); info = thunar_vfs_mime_database_get_info (database, "inode/directory"); - exo_object_unref (EXO_OBJECT (database)); + g_object_unref (G_OBJECT (database)); return info; }