gtk/gtkfilesystem: Do not use GET_PRIVATE macro all the time

Use a private pointer instead
This commit is contained in:
Javier Jardón 2010-08-26 15:57:05 +02:00
parent 904769b004
commit 8d983a4547
2 changed files with 62 additions and 86 deletions

View File

@ -38,8 +38,6 @@
#define DEBUG(x) #define DEBUG(x)
#endif #endif
#define GTK_FILE_SYSTEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_FILE_SYSTEM, GtkFileSystemPrivate))
#define GTK_FOLDER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_FOLDER, GtkFolderPrivate))
#define FILES_PER_QUERY 100 #define FILES_PER_QUERY 100
/* The pointers we return for a GtkFileSystemVolume are opaque tokens; they are /* The pointers we return for a GtkFileSystemVolume are opaque tokens; they are
@ -75,11 +73,9 @@ enum {
static guint fs_signals [FS_LAST_SIGNAL] = { 0, }; static guint fs_signals [FS_LAST_SIGNAL] = { 0, };
static guint folder_signals [FOLDER_LAST_SIGNAL] = { 0, }; static guint folder_signals [FOLDER_LAST_SIGNAL] = { 0, };
typedef struct GtkFileSystemPrivate GtkFileSystemPrivate;
typedef struct GtkFolderPrivate GtkFolderPrivate;
typedef struct AsyncFuncData AsyncFuncData; typedef struct AsyncFuncData AsyncFuncData;
struct GtkFileSystemPrivate struct GtkFileSystemPriv
{ {
GVolumeMonitor *volume_monitor; GVolumeMonitor *volume_monitor;
@ -94,7 +90,7 @@ struct GtkFileSystemPrivate
GFileMonitor *bookmarks_monitor; GFileMonitor *bookmarks_monitor;
}; };
struct GtkFolderPrivate struct GtkFolderPriv
{ {
GFile *folder_file; GFile *folder_file;
GHashTable *children; GHashTable *children;
@ -163,12 +159,11 @@ volumes_changed (GVolumeMonitor *volume_monitor,
static void static void
gtk_file_system_dispose (GObject *object) gtk_file_system_dispose (GObject *object)
{ {
GtkFileSystemPrivate *priv; GtkFileSystem *file_system = GTK_FILE_SYSTEM (object);
GtkFileSystemPriv *priv = file_system->priv;
DEBUG ("dispose"); DEBUG ("dispose");
priv = GTK_FILE_SYSTEM_GET_PRIVATE (object);
if (priv->volumes) if (priv->volumes)
{ {
g_slist_foreach (priv->volumes, (GFunc) g_object_unref, NULL); g_slist_foreach (priv->volumes, (GFunc) g_object_unref, NULL);
@ -189,12 +184,11 @@ gtk_file_system_dispose (GObject *object)
static void static void
gtk_file_system_finalize (GObject *object) gtk_file_system_finalize (GObject *object)
{ {
GtkFileSystemPrivate *priv; GtkFileSystem *file_system = GTK_FILE_SYSTEM (object);
GtkFileSystemPriv *priv = file_system->priv;
DEBUG ("finalize"); DEBUG ("finalize");
priv = GTK_FILE_SYSTEM_GET_PRIVATE (object);
if (priv->bookmarks_monitor) if (priv->bookmarks_monitor)
g_object_unref (priv->bookmarks_monitor); g_object_unref (priv->bookmarks_monitor);
@ -233,7 +227,7 @@ _gtk_file_system_class_init (GtkFileSystemClass *class)
g_cclosure_marshal_VOID__VOID, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
g_type_class_add_private (object_class, sizeof (GtkFileSystemPrivate)); g_type_class_add_private (object_class, sizeof (GtkFileSystemPriv));
} }
static GFile * static GFile *
@ -335,9 +329,8 @@ bookmarks_file_changed (GFileMonitor *monitor,
GFileMonitorEvent event, GFileMonitorEvent event,
gpointer data) gpointer data)
{ {
GtkFileSystemPrivate *priv; GtkFileSystem *file_system = GTK_FILE_SYSTEM (data);
GtkFileSystemPriv *priv = file_system->priv;
priv = GTK_FILE_SYSTEM_GET_PRIVATE (data);
switch (event) switch (event)
{ {
@ -396,7 +389,7 @@ mount_referenced_by_volume_activation_root (GList *volumes, GMount *mount)
static void static void
get_volumes_list (GtkFileSystem *file_system) get_volumes_list (GtkFileSystem *file_system)
{ {
GtkFileSystemPrivate *priv; GtkFileSystemPriv *priv = file_system->priv;
GList *l, *ll; GList *l, *ll;
GList *drives; GList *drives;
GList *volumes; GList *volumes;
@ -405,8 +398,6 @@ get_volumes_list (GtkFileSystem *file_system)
GVolume *volume; GVolume *volume;
GMount *mount; GMount *mount;
priv = GTK_FILE_SYSTEM_GET_PRIVATE (file_system);
if (priv->volumes) if (priv->volumes)
{ {
g_slist_foreach (priv->volumes, (GFunc) g_object_unref, NULL); g_slist_foreach (priv->volumes, (GFunc) g_object_unref, NULL);
@ -539,13 +530,16 @@ get_volumes_list (GtkFileSystem *file_system)
static void static void
_gtk_file_system_init (GtkFileSystem *file_system) _gtk_file_system_init (GtkFileSystem *file_system)
{ {
GtkFileSystemPrivate *priv; GtkFileSystemPriv *priv;
GFile *bookmarks_file; GFile *bookmarks_file;
GError *error = NULL; GError *error = NULL;
DEBUG ("init"); DEBUG ("init");
priv = GTK_FILE_SYSTEM_GET_PRIVATE (file_system); file_system->priv = G_TYPE_INSTANCE_GET_PRIVATE (file_system,
GTK_TYPE_FILE_SYSTEM,
GtkFileSystemPriv);
priv = file_system->priv;
/* Volumes */ /* Volumes */
priv->volume_monitor = g_volume_monitor_get (); priv->volume_monitor = g_volume_monitor_get ();
@ -597,15 +591,12 @@ _gtk_file_system_new (void)
GSList * GSList *
_gtk_file_system_list_volumes (GtkFileSystem *file_system) _gtk_file_system_list_volumes (GtkFileSystem *file_system)
{ {
GtkFileSystemPrivate *priv; GtkFileSystemPriv *priv = file_system->priv;
GSList *list; GSList *list;
DEBUG ("list_volumes"); DEBUG ("list_volumes");
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL); get_volumes_list (file_system);
priv = GTK_FILE_SYSTEM_GET_PRIVATE (file_system);
get_volumes_list (GTK_FILE_SYSTEM (file_system));
list = g_slist_copy (priv->volumes); list = g_slist_copy (priv->volumes);
@ -620,12 +611,11 @@ _gtk_file_system_list_volumes (GtkFileSystem *file_system)
GSList * GSList *
_gtk_file_system_list_bookmarks (GtkFileSystem *file_system) _gtk_file_system_list_bookmarks (GtkFileSystem *file_system)
{ {
GtkFileSystemPrivate *priv; GtkFileSystemPriv *priv = file_system->priv;
GSList *bookmarks, *files = NULL; GSList *bookmarks, *files = NULL;
DEBUG ("list_bookmarks"); DEBUG ("list_bookmarks");
priv = GTK_FILE_SYSTEM_GET_PRIVATE (file_system);
bookmarks = priv->bookmarks; bookmarks = priv->bookmarks;
while (bookmarks) while (bookmarks)
@ -1073,13 +1063,12 @@ _gtk_file_system_insert_bookmark (GtkFileSystem *file_system,
gint position, gint position,
GError **error) GError **error)
{ {
GtkFileSystemPrivate *priv; GtkFileSystemPriv *priv = file_system->priv;
GSList *bookmarks; GSList *bookmarks;
GtkFileSystemBookmark *bookmark; GtkFileSystemBookmark *bookmark;
gboolean result = TRUE; gboolean result = TRUE;
GFile *bookmarks_file; GFile *bookmarks_file;
priv = GTK_FILE_SYSTEM_GET_PRIVATE (file_system);
bookmarks = priv->bookmarks; bookmarks = priv->bookmarks;
while (bookmarks) while (bookmarks)
@ -1129,14 +1118,12 @@ _gtk_file_system_remove_bookmark (GtkFileSystem *file_system,
GFile *file, GFile *file,
GError **error) GError **error)
{ {
GtkFileSystemPrivate *priv; GtkFileSystemPriv *priv = file_system->priv;
GtkFileSystemBookmark *bookmark; GtkFileSystemBookmark *bookmark;
GSList *bookmarks; GSList *bookmarks;
gboolean result = FALSE; gboolean result = FALSE;
GFile *bookmarks_file; GFile *bookmarks_file;
priv = GTK_FILE_SYSTEM_GET_PRIVATE (file_system);
if (!priv->bookmarks) if (!priv->bookmarks)
return FALSE; return FALSE;
@ -1186,13 +1173,12 @@ gchar *
_gtk_file_system_get_bookmark_label (GtkFileSystem *file_system, _gtk_file_system_get_bookmark_label (GtkFileSystem *file_system,
GFile *file) GFile *file)
{ {
GtkFileSystemPrivate *priv; GtkFileSystemPriv *priv = file_system->priv;
GSList *bookmarks; GSList *bookmarks;
gchar *label = NULL; gchar *label = NULL;
DEBUG ("get_bookmark_label"); DEBUG ("get_bookmark_label");
priv = GTK_FILE_SYSTEM_GET_PRIVATE (file_system);
bookmarks = priv->bookmarks; bookmarks = priv->bookmarks;
while (bookmarks) while (bookmarks)
@ -1217,14 +1203,13 @@ _gtk_file_system_set_bookmark_label (GtkFileSystem *file_system,
GFile *file, GFile *file,
const gchar *label) const gchar *label)
{ {
GtkFileSystemPrivate *priv; GtkFileSystemPriv *priv = file_system->priv;
gboolean changed = FALSE; gboolean changed = FALSE;
GFile *bookmarks_file; GFile *bookmarks_file;
GSList *bookmarks; GSList *bookmarks;
DEBUG ("set_bookmark_label"); DEBUG ("set_bookmark_label");
priv = GTK_FILE_SYSTEM_GET_PRIVATE (file_system);
bookmarks = priv->bookmarks; bookmarks = priv->bookmarks;
while (bookmarks) while (bookmarks)
@ -1255,12 +1240,10 @@ GtkFileSystemVolume *
_gtk_file_system_get_volume_for_file (GtkFileSystem *file_system, _gtk_file_system_get_volume_for_file (GtkFileSystem *file_system,
GFile *file) GFile *file)
{ {
GtkFileSystemPrivate *priv;
GMount *mount; GMount *mount;
DEBUG ("get_volume_for_file"); DEBUG ("get_volume_for_file");
priv = GTK_FILE_SYSTEM_GET_PRIVATE (file_system);
mount = g_file_find_enclosing_mount (file, NULL, NULL); mount = g_file_find_enclosing_mount (file, NULL, NULL);
if (!mount && g_file_is_native (file)) if (!mount && g_file_is_native (file))
@ -1276,9 +1259,8 @@ gtk_folder_set_property (GObject *object,
const GValue *value, const GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GtkFolderPrivate *priv; GtkFolder *folder = GTK_FOLDER (object);
GtkFolderPriv *priv = folder->priv;
priv = GTK_FOLDER_GET_PRIVATE (object);
switch (prop_id) switch (prop_id)
{ {
@ -1303,9 +1285,8 @@ gtk_folder_get_property (GObject *object,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GtkFolderPrivate *priv; GtkFolder *folder = GTK_FOLDER (object);
GtkFolderPriv *priv = folder->priv;
priv = GTK_FOLDER_GET_PRIVATE (object);
switch (prop_id) switch (prop_id)
{ {
@ -1360,12 +1341,10 @@ directory_monitor_changed (GFileMonitor *monitor,
GFileMonitorEvent event, GFileMonitorEvent event,
gpointer data) gpointer data)
{ {
GtkFolderPrivate *priv; GtkFolder *folder = GTK_FOLDER (data);
GtkFolder *folder; GtkFolderPriv *priv = folder->priv;
GSList *files; GSList *files;
folder = GTK_FOLDER (data);
priv = GTK_FOLDER_GET_PRIVATE (folder);
files = g_slist_prepend (NULL, file); files = g_slist_prepend (NULL, file);
gdk_threads_enter (); gdk_threads_enter ();
@ -1401,9 +1380,9 @@ enumerator_files_callback (GObject *source_object,
GAsyncResult *result, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
GtkFolder *folder = GTK_FOLDER (user_data);
GtkFolderPriv *priv = folder->priv;
GFileEnumerator *enumerator; GFileEnumerator *enumerator;
GtkFolderPrivate *priv;
GtkFolder *folder;
GError *error = NULL; GError *error = NULL;
GSList *files = NULL; GSList *files = NULL;
GList *file_infos, *f; GList *file_infos, *f;
@ -1420,9 +1399,6 @@ enumerator_files_callback (GObject *source_object,
return; return;
} }
folder = GTK_FOLDER (user_data);
priv = GTK_FOLDER_GET_PRIVATE (folder);
if (!file_infos) if (!file_infos)
{ {
g_file_enumerator_close_async (enumerator, g_file_enumerator_close_async (enumerator,
@ -1464,10 +1440,10 @@ enumerator_files_callback (GObject *source_object,
static void static void
gtk_folder_constructed (GObject *object) gtk_folder_constructed (GObject *object)
{ {
GtkFolderPrivate *priv; GtkFolder *folder = GTK_FOLDER (object);
GtkFolderPriv *priv = folder->priv;
GError *error = NULL; GError *error = NULL;
priv = GTK_FOLDER_GET_PRIVATE (object);
priv->directory_monitor = g_file_monitor_directory (priv->folder_file, G_FILE_MONITOR_NONE, NULL, &error); priv->directory_monitor = g_file_monitor_directory (priv->folder_file, G_FILE_MONITOR_NONE, NULL, &error);
if (error) if (error)
@ -1493,9 +1469,8 @@ gtk_folder_constructed (GObject *object)
static void static void
gtk_folder_finalize (GObject *object) gtk_folder_finalize (GObject *object)
{ {
GtkFolderPrivate *priv; GtkFolder *folder = GTK_FOLDER (object);
GtkFolderPriv *priv = folder->priv;
priv = GTK_FOLDER_GET_PRIVATE (object);
g_hash_table_unref (priv->children); g_hash_table_unref (priv->children);
@ -1584,15 +1559,13 @@ _gtk_folder_class_init (GtkFolderClass *class)
g_cclosure_marshal_VOID__VOID, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
g_type_class_add_private (object_class, sizeof (GtkFolderPrivate)); g_type_class_add_private (object_class, sizeof (GtkFolderPriv));
} }
static void static void
_gtk_folder_init (GtkFolder *folder) _gtk_folder_init (GtkFolder *folder)
{ {
GtkFolderPrivate *priv; GtkFolderPriv *priv = folder->priv;
priv = GTK_FOLDER_GET_PRIVATE (folder);
priv->children = g_hash_table_new_full (g_file_hash, priv->children = g_hash_table_new_full (g_file_hash,
(GEqualFunc) g_file_equal, (GEqualFunc) g_file_equal,
@ -1605,9 +1578,8 @@ static void
gtk_folder_set_finished_loading (GtkFolder *folder, gtk_folder_set_finished_loading (GtkFolder *folder,
gboolean finished_loading) gboolean finished_loading)
{ {
GtkFolderPrivate *priv; GtkFolderPriv *priv = folder->priv;
priv = GTK_FOLDER_GET_PRIVATE (folder);
priv->finished_loading = (finished_loading == TRUE); priv->finished_loading = (finished_loading == TRUE);
gdk_threads_enter (); gdk_threads_enter ();
@ -1620,9 +1592,7 @@ gtk_folder_add_file (GtkFolder *folder,
GFile *file, GFile *file,
GFileInfo *info) GFileInfo *info)
{ {
GtkFolderPrivate *priv; GtkFolderPriv *priv = folder->priv;
priv = GTK_FOLDER_GET_PRIVATE (folder);
g_hash_table_insert (priv->children, g_hash_table_insert (priv->children,
g_object_ref (file), g_object_ref (file),
@ -1632,11 +1602,10 @@ gtk_folder_add_file (GtkFolder *folder,
GSList * GSList *
_gtk_folder_list_children (GtkFolder *folder) _gtk_folder_list_children (GtkFolder *folder)
{ {
GtkFolderPrivate *priv; GtkFolderPriv *priv = folder->priv;
GList *files, *elem; GList *files, *elem;
GSList *children = NULL; GSList *children = NULL;
priv = GTK_FOLDER_GET_PRIVATE (folder);
files = g_hash_table_get_keys (priv->children); files = g_hash_table_get_keys (priv->children);
children = NULL; children = NULL;
@ -1652,10 +1621,9 @@ GFileInfo *
_gtk_folder_get_info (GtkFolder *folder, _gtk_folder_get_info (GtkFolder *folder,
GFile *file) GFile *file)
{ {
GtkFolderPrivate *priv; GtkFolderPriv *priv = folder->priv;
GFileInfo *info; GFileInfo *info;
priv = GTK_FOLDER_GET_PRIVATE (folder);
info = g_hash_table_lookup (priv->children, file); info = g_hash_table_lookup (priv->children, file);
if (!info) if (!info)
@ -1667,11 +1635,7 @@ _gtk_folder_get_info (GtkFolder *folder,
gboolean gboolean
_gtk_folder_is_finished_loading (GtkFolder *folder) _gtk_folder_is_finished_loading (GtkFolder *folder)
{ {
GtkFolderPrivate *priv; return folder->priv->finished_loading;
priv = GTK_FOLDER_GET_PRIVATE (folder);
return priv->finished_loading;
} }
/* GtkFileSystemVolume public methods */ /* GtkFileSystemVolume public methods */

View File

@ -33,6 +33,11 @@ G_BEGIN_DECLS
#define GTK_IS_FILE_SYSTEM_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), GTK_TYPE_FILE_SYSTEM)) #define GTK_IS_FILE_SYSTEM_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), GTK_TYPE_FILE_SYSTEM))
#define GTK_FILE_SYSTEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_FILE_SYSTEM, GtkFileSystemClass)) #define GTK_FILE_SYSTEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_FILE_SYSTEM, GtkFileSystemClass))
typedef struct GtkFileSystem GtkFileSystem;
typedef struct GtkFileSystemPriv GtkFileSystemPriv;
typedef struct GtkFileSystemClass GtkFileSystemClass;
#define GTK_TYPE_FOLDER (_gtk_folder_get_type ()) #define GTK_TYPE_FOLDER (_gtk_folder_get_type ())
#define GTK_FOLDER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_FOLDER, GtkFolder)) #define GTK_FOLDER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_FOLDER, GtkFolder))
#define GTK_FOLDER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), GTK_TYPE_FOLDER, GtkFolderClass)) #define GTK_FOLDER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), GTK_TYPE_FOLDER, GtkFolderClass))
@ -40,13 +45,21 @@ G_BEGIN_DECLS
#define GTK_IS_FOLDER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), GTK_TYPE_FOLDER)) #define GTK_IS_FOLDER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), GTK_TYPE_FOLDER))
#define GTK_FOLDER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_FOLDER, GtkFolderClass)) #define GTK_FOLDER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_FOLDER, GtkFolderClass))
typedef struct GtkFileSystemClass GtkFileSystemClass;
typedef struct GtkFileSystem GtkFileSystem;
typedef struct GtkFolderClass GtkFolderClass;
typedef struct GtkFolder GtkFolder; typedef struct GtkFolder GtkFolder;
typedef struct GtkFolderPriv GtkFolderPriv;
typedef struct GtkFolderClass GtkFolderClass;
typedef struct GtkFileSystemVolume GtkFileSystemVolume; /* opaque struct */ typedef struct GtkFileSystemVolume GtkFileSystemVolume; /* opaque struct */
typedef struct GtkFileSystemBookmark GtkFileSystemBookmark; /* opaque struct */ typedef struct GtkFileSystemBookmark GtkFileSystemBookmark; /* opaque struct */
struct GtkFileSystem
{
GObject parent_object;
GtkFileSystemPriv *priv;
};
struct GtkFileSystemClass struct GtkFileSystemClass
{ {
GObjectClass parent_class; GObjectClass parent_class;
@ -55,9 +68,12 @@ struct GtkFileSystemClass
void (*volumes_changed) (GtkFileSystem *file_system); void (*volumes_changed) (GtkFileSystem *file_system);
}; };
struct GtkFileSystem
struct GtkFolder
{ {
GObject parent_object; GObject parent_object;
GtkFolderPriv *priv;
}; };
struct GtkFolderClass struct GtkFolderClass
@ -74,10 +90,6 @@ struct GtkFolderClass
void (*deleted) (GtkFolder *folder); void (*deleted) (GtkFolder *folder);
}; };
struct GtkFolder
{
GObject parent_object;
};
typedef void (* GtkFileSystemGetFolderCallback) (GCancellable *cancellable, typedef void (* GtkFileSystemGetFolderCallback) (GCancellable *cancellable,
GtkFolder *folder, GtkFolder *folder,