[Xfce4-commits] r29112 - in thunar/branches/port-to-gio: . thunar
Jannis Pohlmann
jannis at xfce.org
Wed Jan 7 00:03:23 CET 2009
Author: jannis
Date: 2009-01-06 23:03:23 +0000 (Tue, 06 Jan 2009)
New Revision: 29112
Added:
thunar/branches/port-to-gio/thunar/thunar-user.c
thunar/branches/port-to-gio/thunar/thunar-user.h
Modified:
thunar/branches/port-to-gio/ChangeLog
thunar/branches/port-to-gio/thunar/Makefile.am
thunar/branches/port-to-gio/thunar/thunar-file.c
thunar/branches/port-to-gio/thunar/thunar-file.h
thunar/branches/port-to-gio/thunar/thunar-list-model.c
thunar/branches/port-to-gio/thunar/thunar-permissions-chooser.c
Log:
* thunar/Makefile.am, thunar-file.{c,h}, thunar-list-model.c,
thunar-permissions-chooser.c, thunar/thunar-user.{c,h}, : Copy
ThunarUser, ThunarGroup and ThunarUserManager from ThunarVfsUser
etc. as GIO provides no alternative. Also copy ThunarFileMode from
ThunarVfsFileMode for convenience reasons. Add "time::*" namespace
to the ones used for GFileInfo objects. Implement
thunar_file_launch(), thunar_file_get_date(),
thunar_file_get_mode_string(), thunar_file_get_group() and
thunar_file_get_user() based on GIO and the user management / mode
code mentioned above.
Modified: thunar/branches/port-to-gio/ChangeLog
===================================================================
--- thunar/branches/port-to-gio/ChangeLog 2009-01-06 16:54:33 UTC (rev 29111)
+++ thunar/branches/port-to-gio/ChangeLog 2009-01-06 23:03:23 UTC (rev 29112)
@@ -1,5 +1,18 @@
2009-01-06 Jannis Pohlmann <jannis at xfce.org>
+ * thunar/Makefile.am, thunar-file.{c,h}, thunar-list-model.c,
+ thunar-permissions-chooser.c, thunar/thunar-user.{c,h}, : Copy
+ ThunarUser, ThunarGroup and ThunarUserManager from ThunarVfsUser
+ etc. as GIO provides no alternative. Also copy ThunarFileMode from
+ ThunarVfsFileMode for convenience reasons. Add "time::*" namespace
+ to the ones used for GFileInfo objects. Implement
+ thunar_file_launch(), thunar_file_get_date(),
+ thunar_file_get_mode_string(), thunar_file_get_group() and
+ thunar_file_get_user() based on GIO and the user management / mode
+ code mentioned above.
+
+2009-01-06 Jannis Pohlmann <jannis at xfce.org>
+
* thunar/thunar-file.{c,h}: Port thunar_file_to_path_list() to GIO by
returning a list with GFile elements instead of ThunarVfsPath
elements. Add methods thunar_path_list_copy() and
Modified: thunar/branches/port-to-gio/thunar/Makefile.am
===================================================================
--- thunar/branches/port-to-gio/thunar/Makefile.am 2009-01-06 16:54:33 UTC (rev 29111)
+++ thunar/branches/port-to-gio/thunar/Makefile.am 2009-01-06 23:03:23 UTC (rev 29112)
@@ -180,6 +180,8 @@
thunar-tree-pane.h \
thunar-tree-view.c \
thunar-tree-view.h \
+ thunar-user.c \
+ thunar-user.h \
thunar-util.c \
thunar-util.h \
thunar-view.c \
Modified: thunar/branches/port-to-gio/thunar/thunar-file.c
===================================================================
--- thunar/branches/port-to-gio/thunar/thunar-file.c 2009-01-06 16:54:33 UTC (rev 29111)
+++ thunar/branches/port-to-gio/thunar/thunar-file.c 2009-01-06 23:03:23 UTC (rev 29112)
@@ -52,11 +52,12 @@
#include <thunar/thunar-gobject-extensions.h>
#include <thunar/thunar-private.h>
#include <thunar/thunar-util.h>
+#include <thunar/thunar-user.h>
/* Namespaces to use for GFileInfo objects */
-#define THUNAR_FILE_G_FILE_INFO_NAMESPACE "standard::*,unix::*,access::*"
+#define THUNAR_FILE_G_FILE_INFO_NAMESPACE "standard::*,unix::*,access::*,time::*"
#define THUNAR_FILE_G_FILE_INFO_FILESYSTEM_NAMESPACE "filesystem::*"
@@ -99,9 +100,9 @@
static ThunarVfsInfo *thunar_file_info_get_vfs_info (ThunarxFileInfo *file_info);
static void thunar_file_info_changed (ThunarxFileInfo *file_info);
static gboolean thunar_file_denies_access_permission (const ThunarFile *file,
- ThunarVfsFileMode usr_permissions,
- ThunarVfsFileMode grp_permissions,
- ThunarVfsFileMode oth_permissions);
+ ThunarFileMode usr_permissions,
+ ThunarFileMode grp_permissions,
+ ThunarFileMode oth_permissions);
static ThunarMetafile *thunar_file_get_metafile (ThunarFile *file);
static void thunar_file_monitor (ThunarVfsMonitor *monitor,
ThunarVfsMonitorHandle *handle,
@@ -113,17 +114,17 @@
-static ThunarVfsUserManager *user_manager;
-static ThunarVfsMonitor *monitor;
-static ThunarVfsUserId effective_user_id;
-static ThunarMetafile *metafile;
-static GObjectClass *thunar_file_parent_class;
-static GHashTable *file_cache;
-static GQuark thunar_file_thumb_path_quark;
-static GQuark thunar_file_watch_count_quark;
-static GQuark thunar_file_watch_handle_quark;
-static GQuark thunar_file_emblem_names_quark;
-static guint file_signals[LAST_SIGNAL];
+static ThunarUserManager *user_manager;
+static ThunarVfsMonitor *monitor;
+static guint32 effective_user_id;
+static ThunarMetafile *metafile;
+static GObjectClass *thunar_file_parent_class;
+static GHashTable *file_cache;
+static GQuark thunar_file_thumb_path_quark;
+static GQuark thunar_file_watch_count_quark;
+static GQuark thunar_file_watch_handle_quark;
+static GQuark thunar_file_emblem_names_quark;
+static guint file_signals[LAST_SIGNAL];
@@ -219,7 +220,7 @@
thunar_file_parent_class = g_type_class_peek_parent (klass);
/* grab a reference on the user manager */
- user_manager = thunar_vfs_user_manager_get_default ();
+ user_manager = thunar_user_manager_get_default ();
/* determine the effective user id of the process */
effective_user_id = geteuid ();
@@ -420,17 +421,21 @@
static gboolean
thunar_file_denies_access_permission (const ThunarFile *file,
- ThunarVfsFileMode usr_permissions,
- ThunarVfsFileMode grp_permissions,
- ThunarVfsFileMode oth_permissions)
+ ThunarFileMode usr_permissions,
+ ThunarFileMode grp_permissions,
+ ThunarFileMode oth_permissions)
{
- ThunarVfsFileMode mode;
- ThunarVfsGroup *group;
- ThunarVfsUser *user;
- gboolean result;
- GList *groups;
- GList *lp;
+ ThunarFileMode mode;
+ ThunarGroup *group;
+ ThunarUser *user;
+ gboolean result;
+ GList *groups;
+ GList *lp;
+ /* root is allowed to do everything */
+ if (G_UNLIKELY (effective_user_id == 0))
+ return FALSE;
+
/* query the file mode */
mode = thunar_file_get_mode (file);
@@ -442,11 +447,7 @@
if (G_UNLIKELY (user == NULL))
return FALSE;
- /* root is allowed to do everything */
- if (G_UNLIKELY (effective_user_id == 0))
- return FALSE;
-
- if (thunar_vfs_user_is_me (user))
+ if (thunar_user_is_me (user))
{
/* we're the owner, so the usr permissions must be granted */
result = ((mode & usr_permissions) == 0);
@@ -463,13 +464,13 @@
g_object_unref (G_OBJECT (user));
/* determine the effective user */
- user = thunar_vfs_user_manager_get_user_by_id (user_manager, effective_user_id);
+ user = thunar_user_manager_get_user_by_id (user_manager, effective_user_id);
if (G_LIKELY (user != NULL))
{
/* check the group permissions */
- groups = thunar_vfs_user_get_groups (user);
+ groups = thunar_user_get_groups (user);
for (lp = groups; lp != NULL; lp = lp->next)
- if (THUNAR_VFS_GROUP (lp->data) == group)
+ if (THUNAR_GROUP (lp->data) == group)
{
g_object_unref (G_OBJECT (user));
g_object_unref (G_OBJECT (group));
@@ -836,12 +837,13 @@
gpointer parent,
GError **error)
{
- ThunarVfsMimeApplication *handler;
- ThunarVfsMimeDatabase *database;
- ThunarApplication *application;
- GdkScreen *screen;
- gboolean succeed;
- GList path_list;
+ GdkAppLaunchContext *context;
+ ThunarApplication *application;
+ GdkScreen *screen;
+ GAppInfo *app_info;
+ gboolean succeed;
+ GList path_list;
+ gchar *content_type;
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
_thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -868,27 +870,34 @@
if (thunar_file_is_executable (file))
return thunar_file_execute (file, screen, NULL, error);
- /* determine the default handler for the file */
- database = thunar_vfs_mime_database_get_default ();
- handler = thunar_vfs_mime_database_get_default_application (database, thunar_file_get_mime_info (file));
- g_object_unref (G_OBJECT (database));
+ /* determine the default application for the file */
+ content_type = thunarx_file_info_get_mime_type (THUNARX_FILE_INFO (file));
+ app_info = g_app_info_get_default_for_type (content_type, FALSE);
+ g_free (content_type);
- /* if we don't have any default handler, just popup the application chooser */
- if (G_UNLIKELY (handler == NULL))
+ /* if we don't have a default application for the type, just popup the application chooser */
+ if (G_UNLIKELY (app_info == NULL))
{
thunar_show_chooser_dialog (parent, file, TRUE);
return TRUE;
}
/* fake a path list */
- path_list.data = thunar_file_get_path (file);
+ path_list.data = thunar_file_get_gfile (file);
path_list.next = path_list.prev = NULL;
+ /* create a launch context */
+ context = gdk_app_launch_context_new ();
+ gdk_app_launch_context_set_screen (context, screen);
+
/* otherwise try to execute the application */
- succeed = thunar_vfs_mime_handler_exec (THUNAR_VFS_MIME_HANDLER (handler), screen, &path_list, error);
+ succeed = g_app_info_launch (app_info, &path_list, G_APP_LAUNCH_CONTEXT (context), error);
+ /* destroy the launch context */
+ g_object_unref (context);
+
/* release the handler reference */
- g_object_unref (G_OBJECT (handler));
+ g_object_unref (app_info);
return succeed;
}
@@ -1122,7 +1131,7 @@
*
* Return value: the time for @file of the given @date_type.
**/
-ThunarVfsFileTime
+guint64
thunar_file_get_date (const ThunarFile *file,
ThunarFileDateType date_type)
{
@@ -1130,13 +1139,13 @@
switch (date_type)
{
- case THUNAR_FILE_DATE_ACCESSED: return file->info->atime;
- case THUNAR_FILE_DATE_CHANGED: return file->info->ctime;
- case THUNAR_FILE_DATE_MODIFIED: return file->info->mtime;
+ case THUNAR_FILE_DATE_ACCESSED: return g_file_info_get_attribute_uint64 (file->ginfo, G_FILE_ATTRIBUTE_TIME_ACCESS);
+ case THUNAR_FILE_DATE_CHANGED: return g_file_info_get_attribute_uint64 (file->ginfo, G_FILE_ATTRIBUTE_TIME_CHANGED);
+ case THUNAR_FILE_DATE_MODIFIED: return g_file_info_get_attribute_uint64 (file->ginfo, G_FILE_ATTRIBUTE_TIME_MODIFIED);
default: _thunar_assert_not_reached ();
}
- return (ThunarVfsFileTime) -1;
+ return -1;
}
@@ -1176,9 +1185,9 @@
gchar*
thunar_file_get_mode_string (const ThunarFile *file)
{
- ThunarVfsFileType kind;
- ThunarVfsFileMode mode;
- gchar *text;
+ ThunarFileMode mode;
+ GFileType kind;
+ gchar *text;
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
@@ -1189,36 +1198,38 @@
/* file type */
switch (kind)
{
+#if 0 /* FIXME: There's no replacement for these yet */
case THUNAR_VFS_FILE_TYPE_PORT: text[0] = 'P'; break;
case THUNAR_VFS_FILE_TYPE_DOOR: text[0] = 'D'; break;
case THUNAR_VFS_FILE_TYPE_SOCKET: text[0] = 's'; break;
- case THUNAR_VFS_FILE_TYPE_SYMLINK: text[0] = 'l'; break;
- case THUNAR_VFS_FILE_TYPE_REGULAR: text[0] = '-'; break;
case THUNAR_VFS_FILE_TYPE_BLOCKDEV: text[0] = 'b'; break;
- case THUNAR_VFS_FILE_TYPE_DIRECTORY: text[0] = 'd'; break;
case THUNAR_VFS_FILE_TYPE_CHARDEV: text[0] = 'c'; break;
case THUNAR_VFS_FILE_TYPE_FIFO: text[0] = 'f'; break;
- case THUNAR_VFS_FILE_TYPE_UNKNOWN: text[0] = ' '; break;
+#endif
+ case G_FILE_TYPE_SYMBOLIC_LINK: text[0] = 'l'; break;
+ case G_FILE_TYPE_REGULAR: text[0] = '-'; break;
+ case G_FILE_TYPE_DIRECTORY: text[0] = 'd'; break;
+ case G_FILE_TYPE_UNKNOWN: text[0] = ' '; break;
default: _thunar_assert_not_reached ();
}
/* permission flags */
- text[1] = (mode & THUNAR_VFS_FILE_MODE_USR_READ) ? 'r' : '-';
- text[2] = (mode & THUNAR_VFS_FILE_MODE_USR_WRITE) ? 'w' : '-';
- text[3] = (mode & THUNAR_VFS_FILE_MODE_USR_EXEC) ? 'x' : '-';
- text[4] = (mode & THUNAR_VFS_FILE_MODE_GRP_READ) ? 'r' : '-';
- text[5] = (mode & THUNAR_VFS_FILE_MODE_GRP_WRITE) ? 'w' : '-';
- text[6] = (mode & THUNAR_VFS_FILE_MODE_GRP_EXEC) ? 'x' : '-';
- text[7] = (mode & THUNAR_VFS_FILE_MODE_OTH_READ) ? 'r' : '-';
- text[8] = (mode & THUNAR_VFS_FILE_MODE_OTH_WRITE) ? 'w' : '-';
- text[9] = (mode & THUNAR_VFS_FILE_MODE_OTH_EXEC) ? 'x' : '-';
+ text[1] = (mode & THUNAR_FILE_MODE_USR_READ) ? 'r' : '-';
+ text[2] = (mode & THUNAR_FILE_MODE_USR_WRITE) ? 'w' : '-';
+ text[3] = (mode & THUNAR_FILE_MODE_USR_EXEC) ? 'x' : '-';
+ text[4] = (mode & THUNAR_FILE_MODE_GRP_READ) ? 'r' : '-';
+ text[5] = (mode & THUNAR_FILE_MODE_GRP_WRITE) ? 'w' : '-';
+ text[6] = (mode & THUNAR_FILE_MODE_GRP_EXEC) ? 'x' : '-';
+ text[7] = (mode & THUNAR_FILE_MODE_OTH_READ) ? 'r' : '-';
+ text[8] = (mode & THUNAR_FILE_MODE_OTH_WRITE) ? 'w' : '-';
+ text[9] = (mode & THUNAR_FILE_MODE_OTH_EXEC) ? 'x' : '-';
/* special flags */
- if (G_UNLIKELY (mode & THUNAR_VFS_FILE_MODE_SUID))
+ if (G_UNLIKELY (mode & THUNAR_FILE_MODE_SUID))
text[3] = 's';
- if (G_UNLIKELY (mode & THUNAR_VFS_FILE_MODE_SGID))
+ if (G_UNLIKELY (mode & THUNAR_FILE_MODE_SGID))
text[6] = 's';
- if (G_UNLIKELY (mode & THUNAR_VFS_FILE_MODE_STICKY))
+ if (G_UNLIKELY (mode & THUNAR_FILE_MODE_STICKY))
text[9] = 't';
text[10] = '\0';
@@ -1276,20 +1287,24 @@
* thunar_file_get_group:
* @file : a #ThunarFile instance.
*
- * Determines the #ThunarVfsGroup for @file. If there's no
+ * Determines the #ThunarGroup for @file. If there's no
* group associated with @file or if the system is unable to
* determine the group, %NULL will be returned.
*
* The caller is responsible for freeing the returned object
* using g_object_unref().
*
- * Return value: the #ThunarVfsGroup for @file or %NULL.
+ * Return value: the #ThunarGroup for @file or %NULL.
**/
-ThunarVfsGroup*
+ThunarGroup*
thunar_file_get_group (const ThunarFile *file)
{
+ guint32 gid;
+
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
- return thunar_vfs_user_manager_get_group_by_id (user_manager, file->info->gid);
+
+ gid = g_file_info_get_attribute_uint32 (file->ginfo, G_FILE_ATTRIBUTE_UNIX_GID);
+ return thunar_user_manager_get_group_by_id (user_manager, file->info->gid);
}
@@ -1298,20 +1313,24 @@
* thunar_file_get_user:
* @file : a #ThunarFile instance.
*
- * Determines the #ThunarVfsUser for @file. If there's no
+ * Determines the #ThunarUser for @file. If there's no
* user associated with @file or if the system is unable
* to determine the user, %NULL will be returned.
*
* The caller is responsible for freeing the returned object
* using g_object_unref().
*
- * Return value: the #ThunarVfsUser for @file or %NULL.
+ * Return value: the #ThunarUser for @file or %NULL.
**/
-ThunarVfsUser*
+ThunarUser*
thunar_file_get_user (const ThunarFile *file)
{
+ guint32 uid;
+
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
- return thunar_vfs_user_manager_get_user_by_id (user_manager, file->info->uid);
+
+ uid = g_file_info_get_attribute_uint32 (file->ginfo, G_FILE_ATTRIBUTE_UNIX_UID);
+ return thunar_user_manager_get_user_by_id (user_manager, uid);
}
@@ -1645,7 +1664,7 @@
*
* Return value: the permission bits of @file.
**/
-guint32
+ThunarFileMode
thunar_file_get_mode (const ThunarFile *file)
{
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), 0);
@@ -2473,14 +2492,13 @@
* thunar_file_list_get_applications:
* @file_list : a #GList of #ThunarFile<!---->s.
*
- * Returns the #GList of #ThunarVfsMimeApplication<!---->s
- * that can be used to open all #ThunarFile<!---->s in the
- * given @file_list.
+ * Returns the #GList of #GAppInfo<!---->s that can be used to
+ * open all #ThunarFile<!---->s in the given @file_list.
*
* The caller is responsible to free the returned list using
* something like:
* <informalexample><programlisting>
- * g_list_foreach (list, (GFunc) thunar_vfs_mime_application_unref, NULL);
+ * g_list_foreach (list, (GFunc) g_object_unref, NULL);
* g_list_free (list);
* </programlisting></informalexample>
*
Modified: thunar/branches/port-to-gio/thunar/thunar-file.h
===================================================================
--- thunar/branches/port-to-gio/thunar/thunar-file.h 2009-01-06 16:54:33 UTC (rev 29111)
+++ thunar/branches/port-to-gio/thunar/thunar-file.h 2009-01-06 23:03:23 UTC (rev 29112)
@@ -1,7 +1,7 @@
/* $Id$ */
/*-
* Copyright (c) 2005-2007 Benedikt Meurer <benny at xfce.org>
- * Copyright (c) 2008 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2008-2009 Jannis Pohlmann <jannis at xfce.org>
*
* 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
@@ -23,6 +23,7 @@
#include <thunar/thunar-enum-types.h>
#include <thunar/thunar-metafile.h>
+#include <thunar/thunar-user.h>
#include <thunarx/thunarx.h>
#include <glib.h>
@@ -58,6 +59,45 @@
} ThunarFileDateType;
/**
+ * ThunarFileMode:
+ * @THUNAR_FILE_MODE_SUID : SUID bit.
+ * @THUNAR_FILE_MODE_SGID : SGID bit.
+ * @THUNAR_FILE_MODE_STICKY : Sticky bit.
+ * @THUNAR_FILE_MODE_USR_ALL : Owner can do everything.
+ * @THUNAR_FILE_MODE_USR_READ : Owner can read the file.
+ * @THUNAR_FILE_MODE_USR_WRITE: Owner can write the file.
+ * @THUNAR_FILE_MODE_USR_EXEC : Owner can execute the file.
+ * @THUNAR_FILE_MODE_GRP_ALL : Owner group can do everything.
+ * @THUNAR_FILE_MODE_GRP_READ : Owner group can read the file.
+ * @THUNAR_FILE_MODE_GRP_WRITE: Owner group can write the file.
+ * @THUNAR_FILE_MODE_GRP_EXEC : Owner group can execute the file.
+ * @THUNAR_FILE_MODE_OTH_ALL : Others can do everything.
+ * @THUNAR_FILE_MODE_OTH_READ : Others can read the file.
+ * @THUNAR_FILE_MODE_OTH_WRITE: Others can write the file.
+ * @THUNAR_FILE_MODE_OTH_EXEC : Others can execute the file.
+ *
+ * Special flags and permissions of a filesystem entity.
+ **/
+typedef enum /*< flags >*/
+{
+ THUNAR_FILE_MODE_SUID = 04000,
+ THUNAR_FILE_MODE_SGID = 02000,
+ THUNAR_FILE_MODE_STICKY = 01000,
+ THUNAR_FILE_MODE_USR_ALL = 00700,
+ THUNAR_FILE_MODE_USR_READ = 00400,
+ THUNAR_FILE_MODE_USR_WRITE = 00200,
+ THUNAR_FILE_MODE_USR_EXEC = 00100,
+ THUNAR_FILE_MODE_GRP_ALL = 00070,
+ THUNAR_FILE_MODE_GRP_READ = 00040,
+ THUNAR_FILE_MODE_GRP_WRITE = 00020,
+ THUNAR_FILE_MODE_GRP_EXEC = 00010,
+ THUNAR_FILE_MODE_OTH_ALL = 00007,
+ THUNAR_FILE_MODE_OTH_READ = 00004,
+ THUNAR_FILE_MODE_OTH_WRITE = 00002,
+ THUNAR_FILE_MODE_OTH_EXEC = 00001,
+} ThunarFileMode;
+
+/**
* ThunarFileIconState:
* @THUNAR_FILE_ICON_STATE_DEFAULT : the default icon for the file.
* @THUNAR_FILE_ICON_STATE_DROP : the drop accept icon for the file.
@@ -148,7 +188,7 @@
const gchar *thunar_file_get_display_name (const ThunarFile *file);
-ThunarVfsFileTime thunar_file_get_date (const ThunarFile *file,
+guint64 thunar_file_get_date (const ThunarFile *file,
ThunarFileDateType date_type);
gchar *thunar_file_get_date_string (const ThunarFile *file,
@@ -160,8 +200,8 @@
ThunarVfsVolume *thunar_file_get_volume (const ThunarFile *file,
ThunarVfsVolumeManager *volume_manager);
-ThunarVfsGroup *thunar_file_get_group (const ThunarFile *file);
-ThunarVfsUser *thunar_file_get_user (const ThunarFile *file);
+ThunarGroup *thunar_file_get_group (const ThunarFile *file);
+ThunarUser *thunar_file_get_user (const ThunarFile *file);
gchar *thunar_file_get_deletion_date (const ThunarFile *file,
ThunarDateStyle date_style) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
@@ -215,7 +255,7 @@
gboolean thunar_file_is_desktop (const ThunarFile *file);
gboolean thunar_file_has_parent (const ThunarFile *file);
-guint32 thunar_file_get_mode (const ThunarFile *file);
+ThunarFileMode thunar_file_get_mode (const ThunarFile *file);
GFileType thunar_file_get_kind (const ThunarFile *file);
guint64 thunar_file_get_size (const ThunarFile *file);
gboolean thunar_file_get_free_space (const ThunarFile *file,
Modified: thunar/branches/port-to-gio/thunar/thunar-list-model.c
===================================================================
--- thunar/branches/port-to-gio/thunar/thunar-list-model.c 2009-01-06 16:54:33 UTC (rev 29111)
+++ thunar/branches/port-to-gio/thunar/thunar-list-model.c 2009-01-06 23:03:23 UTC (rev 29112)
@@ -1,6 +1,7 @@
/* $Id$ */
/*-
* Copyright (c) 2004-2007 Benedikt Meurer <benny at xfce.org>
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
*
* 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
@@ -32,6 +33,7 @@
#include <thunar/thunar-gobject-extensions.h>
#include <thunar/thunar-list-model.h>
#include <thunar/thunar-private.h>
+#include <thunar/thunar-user.h>
@@ -698,8 +700,8 @@
GValue *value)
{
ThunarVfsMimeInfo *mime_info;
- ThunarVfsGroup *group;
- ThunarVfsUser *user;
+ ThunarGroup *group;
+ ThunarUser *user;
const gchar *name;
const gchar *real_name;
ThunarFile *file;
@@ -729,7 +731,7 @@
group = thunar_file_get_group (file);
if (G_LIKELY (group != NULL))
{
- g_value_set_string (value, thunar_vfs_group_get_name (group));
+ g_value_set_string (value, thunar_group_get_name (group));
g_object_unref (G_OBJECT (group));
}
else
@@ -755,8 +757,8 @@
if (G_LIKELY (user != NULL))
{
/* determine sane display name for the owner */
- name = thunar_vfs_user_get_name (user);
- real_name = thunar_vfs_user_get_real_name (user);
+ name = thunar_user_get_name (user);
+ real_name = thunar_user_get_real_name (user);
str = G_LIKELY (real_name != NULL) ? g_strdup_printf ("%s (%s)", real_name, name) : g_strdup (name);
g_value_take_string (value, str);
g_object_unref (G_OBJECT (user));
Modified: thunar/branches/port-to-gio/thunar/thunar-permissions-chooser.c
===================================================================
--- thunar/branches/port-to-gio/thunar/thunar-permissions-chooser.c 2009-01-06 16:54:33 UTC (rev 29111)
+++ thunar/branches/port-to-gio/thunar/thunar-permissions-chooser.c 2009-01-06 23:03:23 UTC (rev 29112)
@@ -1,6 +1,7 @@
/* $Id$ */
/*-
* Copyright (c) 2005-2006 Benedikt Meurer <benny at xfce.org>
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
*
* 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
@@ -39,6 +40,7 @@
#include <thunar/thunar-permissions-chooser.h>
#include <thunar/thunar-preferences.h>
#include <thunar/thunar-private.h>
+#include <thunar/thunar-user.h>
@@ -80,12 +82,12 @@
GParamSpec *pspec);
static gint thunar_permissions_chooser_ask_recursive (ThunarPermissionsChooser *chooser);
static void thunar_permissions_chooser_change_group (ThunarPermissionsChooser *chooser,
- ThunarVfsGroupId gid);
+ guint32 gid);
static void thunar_permissions_chooser_change_mode (ThunarPermissionsChooser *chooser,
- ThunarVfsFileMode dir_mask,
- ThunarVfsFileMode dir_mode,
- ThunarVfsFileMode file_mask,
- ThunarVfsFileMode file_mode);
+ guint32 dir_mask,
+ guint32 dir_mode,
+ guint32 file_mask,
+ guint32 file_mode);
static void thunar_permissions_chooser_access_changed (ThunarPermissionsChooser *chooser,
GtkWidget *combo);
static void thunar_permissions_chooser_file_changed (ThunarPermissionsChooser *chooser,
@@ -628,7 +630,7 @@
static void
thunar_permissions_chooser_change_group (ThunarPermissionsChooser *chooser,
- ThunarVfsGroupId gid)
+ guint32 gid)
{
ThunarVfsJob *job;
gboolean recursive = FALSE;
@@ -678,10 +680,10 @@
static void
thunar_permissions_chooser_change_mode (ThunarPermissionsChooser *chooser,
- ThunarVfsFileMode dir_mask,
- ThunarVfsFileMode dir_mode,
- ThunarVfsFileMode file_mask,
- ThunarVfsFileMode file_mode)
+ guint32 dir_mask,
+ guint32 dir_mode,
+ guint32 file_mask,
+ guint32 file_mode)
{
ThunarVfsJob *job;
gboolean recursive = FALSE;
@@ -733,11 +735,11 @@
thunar_permissions_chooser_access_changed (ThunarPermissionsChooser *chooser,
GtkWidget *combo)
{
- ThunarVfsFileMode file_mask;
- ThunarVfsFileMode file_mode;
- ThunarVfsFileMode dir_mask;
- ThunarVfsFileMode dir_mode;
- guint n;
+ guint32 file_mask;
+ guint32 file_mode;
+ guint32 dir_mask;
+ guint32 dir_mode;
+ guint n;
_thunar_return_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser));
_thunar_return_if_fail (GTK_IS_COMBO_BOX (combo));
@@ -771,9 +773,9 @@
gconstpointer group_b,
gpointer group_primary)
{
- ThunarVfsGroupId group_primary_id = thunar_vfs_group_get_id (THUNAR_VFS_GROUP (group_primary));
- ThunarVfsGroupId group_a_id = thunar_vfs_group_get_id (THUNAR_VFS_GROUP (group_a));
- ThunarVfsGroupId group_b_id = thunar_vfs_group_get_id (THUNAR_VFS_GROUP (group_b));
+ guint32 group_primary_id = thunar_group_get_id (THUNAR_GROUP (group_primary));
+ guint32 group_a_id = thunar_group_get_id (THUNAR_GROUP (group_a));
+ guint32 group_b_id = thunar_group_get_id (THUNAR_GROUP (group_b));
/* check if the groups are equal */
if (group_a_id == group_b_id)
@@ -792,7 +794,7 @@
return -1;
/* otherwise just sort by name */
- return g_ascii_strcasecmp (thunar_vfs_group_get_name (THUNAR_VFS_GROUP (group_a)), thunar_vfs_group_get_name (THUNAR_VFS_GROUP (group_b)));
+ return g_ascii_strcasecmp (thunar_group_get_name (THUNAR_GROUP (group_a)), thunar_group_get_name (THUNAR_GROUP (group_b)));
}
@@ -801,18 +803,18 @@
thunar_permissions_chooser_file_changed (ThunarPermissionsChooser *chooser,
ThunarFile *file)
{
- ThunarVfsUserManager *user_manager;
- ThunarVfsFileMode mode;
- ThunarVfsGroup *group;
- ThunarVfsUser *user;
- GtkListStore *store;
- GtkTreeIter iter;
- const gchar *user_name;
- const gchar *real_name;
- GList *groups;
- GList *lp;
- gchar buffer[1024];
- guint n;
+ ThunarUserManager *user_manager;
+ ThunarGroup *group;
+ ThunarUser *user;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ const gchar *user_name;
+ const gchar *real_name;
+ GList *groups;
+ GList *lp;
+ guint32 mode;
+ gchar buffer[1024];
+ guint n;
_thunar_return_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser));
_thunar_return_if_fail (THUNAR_IS_FILE (file));
@@ -835,14 +837,14 @@
if (G_UNLIKELY (geteuid () == 0))
{
/* determine all groups in the system */
- user_manager = thunar_vfs_user_manager_get_default ();
- groups = thunar_vfs_user_manager_get_all_groups (user_manager);
+ user_manager = thunar_user_manager_get_default ();
+ groups = thunar_user_manager_get_all_groups (user_manager);
g_object_unref (G_OBJECT (user_manager));
}
else
{
/* determine the groups for the user and take a copy */
- groups = g_list_copy (thunar_vfs_user_get_groups (user));
+ groups = g_list_copy (thunar_user_get_groups (user));
g_list_foreach (groups, (GFunc) g_object_ref, NULL);
}
@@ -857,12 +859,12 @@
for (lp = groups, n = 0; lp != NULL; lp = lp->next)
{
/* append a separator after the primary group and after the user-groups (not system groups) */
- if (thunar_vfs_group_get_id (groups->data) == thunar_vfs_group_get_id (group) && lp != groups && n == 0)
+ if (thunar_group_get_id (groups->data) == thunar_group_get_id (group) && lp != groups && n == 0)
{
gtk_list_store_append (store, &iter);
n += 1;
}
- else if (lp != groups && thunar_vfs_group_get_id (lp->data) < 100 && n == 1)
+ else if (lp != groups && thunar_group_get_id (lp->data) < 100 && n == 1)
{
gtk_list_store_append (store, &iter);
n += 1;
@@ -871,8 +873,8 @@
/* append a new item for the group */
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
- THUNAR_PERMISSIONS_STORE_COLUMN_NAME, thunar_vfs_group_get_name (lp->data),
- THUNAR_PERMISSIONS_STORE_COLUMN_GID, thunar_vfs_group_get_id (lp->data),
+ THUNAR_PERMISSIONS_STORE_COLUMN_NAME, thunar_group_get_name (lp->data),
+ THUNAR_PERMISSIONS_STORE_COLUMN_GID, thunar_group_get_id (lp->data),
-1);
/* set the active iter for the combo box if this group is the primary group */
@@ -887,8 +889,8 @@
}
/* determine sane display name for the owner */
- user_name = thunar_vfs_user_get_name (user);
- real_name = thunar_vfs_user_get_real_name (user);
+ user_name = thunar_user_get_name (user);
+ real_name = thunar_user_get_real_name (user);
if (G_LIKELY (real_name != NULL))
g_snprintf (buffer, sizeof (buffer), "%s (%s)", real_name, user_name);
else
@@ -948,9 +950,9 @@
thunar_permissions_chooser_group_changed (ThunarPermissionsChooser *chooser,
GtkWidget *combo)
{
- ThunarVfsGroupId gid;
- GtkTreeModel *model;
- GtkTreeIter iter;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ guint32 gid;
_thunar_return_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser));
_thunar_return_if_fail (chooser->group_combo == combo);
@@ -980,7 +982,7 @@
thunar_permissions_chooser_program_toggled (ThunarPermissionsChooser *chooser,
GtkWidget *button)
{
- ThunarVfsFileMode mode;
+ guint32 mode;
_thunar_return_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser));
_thunar_return_if_fail (chooser->program_button == button);
@@ -1003,12 +1005,12 @@
thunar_permissions_chooser_fixperm_clicked (ThunarPermissionsChooser *chooser,
GtkWidget *button)
{
- ThunarVfsFileMode mode;
- ThunarVfsJob *job;
- GtkWidget *dialog;
- GtkWidget *window;
- GError *error = NULL;
- gint response;
+ ThunarVfsJob *job;
+ GtkWidget *dialog;
+ GtkWidget *window;
+ GError *error = NULL;
+ guint32 mode;
+ gint response;
_thunar_return_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser));
_thunar_return_if_fail (chooser->fixperm_button == button);
Added: thunar/branches/port-to-gio/thunar/thunar-user.c
===================================================================
--- thunar/branches/port-to-gio/thunar/thunar-user.c (rev 0)
+++ thunar/branches/port-to-gio/thunar/thunar-user.c 2009-01-06 23:03:23 UTC (rev 29112)
@@ -0,0 +1,831 @@
+/* $Id$ */
+/*-
+ * Copyright (c) 2005-2006 Benedikt Meurer <benny at xfce.org>
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_GRP_H
+#include <grp.h>
+#endif
+#ifdef HAVE_MEMORY_H
+#include <memory.h>
+#endif
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <exo/exo.h>
+
+#include <thunar-user.h>
+
+
+
+/* the interval in which the user/group cache is flushed (in ms) */
+#define THUNAR_USER_MANAGER_FLUSH_INTERVAL (10 * 60 * 1000)
+
+
+
+
+static void thunar_group_class_init (ThunarGroupClass *klass);
+static void thunar_group_finalize (GObject *object);
+static ThunarGroup *thunar_group_new (guint32 id);
+
+
+
+struct _ThunarGroupClass
+{
+ GObjectClass __parent__;
+};
+
+struct _ThunarGroup
+{
+ GObject __parent__;
+
+ guint32 id;
+ gchar *name;
+};
+
+
+
+static GObjectClass *thunar_group_parent_class;
+
+
+
+GType
+thunar_group_get_type (void)
+{
+ static GType type = G_TYPE_INVALID;
+
+ if (G_UNLIKELY (type == G_TYPE_INVALID))
+ {
+ type = g_type_register_static_simple (G_TYPE_OBJECT,
+ "ThunarGroup",
+ sizeof (ThunarGroupClass),
+ (GClassInitFunc) thunar_group_class_init,
+ sizeof (ThunarGroup),
+ NULL,
+ 0);
+ }
+
+ return type;
+}
+
+
+
+static void
+thunar_group_class_init (ThunarGroupClass *klass)
+{
+ GObjectClass *gobject_class;
+
+ /* determine the parent class */
+ thunar_group_parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->finalize = thunar_group_finalize;
+}
+
+
+
+static void
+thunar_group_finalize (GObject *object)
+{
+ ThunarGroup *group = THUNAR_GROUP (object);
+
+ /* release the group's name */
+ g_free (group->name);
+
+ (*G_OBJECT_CLASS (thunar_group_parent_class)->finalize) (object);
+}
+
+
+
+static ThunarGroup*
+thunar_group_new (guint32 id)
+{
+ ThunarGroup *group;
+
+ group = g_object_new (THUNAR_TYPE_GROUP, NULL);
+ group->id = id;
+
+ return group;
+}
+
+
+
+/**
+ * thunar_group_get_id:
+ * @group : a #ThunarGroup.
+ *
+ * Returns the unique id of the given @group.
+ *
+ * Return value: the unique id of @group.
+ **/
+guint32
+thunar_group_get_id (ThunarGroup *group)
+{
+ g_return_val_if_fail (THUNAR_IS_GROUP (group), 0);
+ return group->id;
+}
+
+
+
+/**
+ * thunar_group_get_name:
+ * @group : a #ThunarGroup.
+ *
+ * Returns the name of the @group. If the system is
+ * unable to determine the name of @group, it'll
+ * return the group id as string.
+ *
+ * Return value: the name of @group.
+ **/
+const gchar*
+thunar_group_get_name (ThunarGroup *group)
+{
+ struct group *grp;
+
+ g_return_val_if_fail (THUNAR_IS_GROUP (group), NULL);
+
+ /* determine the name on-demand */
+ if (G_UNLIKELY (group->name == NULL))
+ {
+ grp = getgrgid (group->id);
+ if (G_LIKELY (grp != NULL))
+ group->name = g_strdup (grp->gr_name);
+ else
+ group->name = g_strdup_printf ("%u", (guint) group->id);
+ }
+
+ return group->name;
+}
+
+
+
+
+static void thunar_user_class_init (ThunarUserClass *klass);
+static void thunar_user_finalize (GObject *object);
+static void thunar_user_load (ThunarUser *user);
+static ThunarUser *thunar_user_new (guint32 id);
+
+
+
+struct _ThunarUserClass
+{
+ GObjectClass __parent__;
+};
+
+struct _ThunarUser
+{
+ GObject __parent__;
+
+ GList *groups;
+ ThunarGroup *primary_group;
+ guint32 id;
+ gchar *name;
+ gchar *real_name;
+};
+
+
+
+static guint32 thunar_user_effective_uid;
+static GObjectClass *thunar_user_parent_class;
+
+
+
+GType
+thunar_user_get_type (void)
+{
+ static GType type = G_TYPE_INVALID;
+
+ if (G_UNLIKELY (type == G_TYPE_INVALID))
+ {
+ type = g_type_register_static_simple (G_TYPE_OBJECT,
+ "ThunarUser",
+ sizeof (ThunarUserClass),
+ (GClassInitFunc) thunar_user_class_init,
+ sizeof (ThunarUser),
+ NULL,
+ 0);
+ }
+
+ return type;
+}
+
+
+
+static void
+thunar_user_class_init (ThunarUserClass *klass)
+{
+ GObjectClass *gobject_class;
+
+ /* determine the parent class */
+ thunar_user_parent_class = g_type_class_peek_parent (klass);
+
+ /* determine the current process' effective user id, we do
+ * this only once to avoid the syscall overhead on every
+ * is_me() invokation.
+ */
+ thunar_user_effective_uid = geteuid ();
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->finalize = thunar_user_finalize;
+}
+
+
+
+static void
+thunar_user_finalize (GObject *object)
+{
+ ThunarUser *user = THUNAR_USER (object);
+
+ /* unref the associated groups */
+ g_list_foreach (user->groups, (GFunc) g_object_unref, NULL);
+ g_list_free (user->groups);
+
+ /* drop the reference on the primary group */
+ if (G_LIKELY (user->primary_group != NULL))
+ g_object_unref (G_OBJECT (user->primary_group));
+
+ /* release the names */
+ g_free (user->real_name);
+ g_free (user->name);
+
+ (*G_OBJECT_CLASS (thunar_user_parent_class)->finalize) (object);
+}
+
+
+
+static void
+thunar_user_load (ThunarUser *user)
+{
+ ThunarUserManager *manager;
+ struct passwd *pw;
+ const gchar *s;
+ gchar *name;
+ gchar *t;
+
+ g_return_if_fail (user->name == NULL);
+
+ pw = getpwuid (user->id);
+ if (G_LIKELY (pw != NULL))
+ {
+ manager = thunar_user_manager_get_default ();
+
+ /* query name and primary group */
+ user->name = g_strdup (pw->pw_name);
+ user->primary_group = thunar_user_manager_get_group_by_id (manager, pw->pw_gid);
+
+ /* try to figure out the real name */
+ s = strchr (pw->pw_gecos, ',');
+ if (s != NULL)
+ user->real_name = g_strndup (pw->pw_gecos, s - pw->pw_gecos);
+ else if (pw->pw_gecos[0] != '\0')
+ user->real_name = g_strdup (pw->pw_gecos);
+
+ /* substitute '&' in the real_name with the account name */
+ if (G_LIKELY (user->real_name != NULL && strchr (user->real_name, '&') != NULL))
+ {
+ /* generate a version of the username with the first char upper'd */
+ name = g_strdup (user->name);
+ name[0] = g_ascii_toupper (name[0]);
+
+ /* replace all occurances of '&' */
+ t = exo_str_replace (user->real_name, "&", name);
+ g_free (user->real_name);
+ user->real_name = t;
+
+ /* clean up */
+ g_free (name);
+ }
+
+ g_object_unref (G_OBJECT (manager));
+ }
+ else
+ {
+ user->name = g_strdup_printf ("%u", (guint) user->id);
+ }
+}
+
+
+
+static ThunarUser*
+thunar_user_new (guint32 id)
+{
+ ThunarUser *user;
+
+ user = g_object_new (THUNAR_TYPE_USER, NULL);
+ user->id = id;
+
+ return user;
+}
+
+
+
+/**
+ * thunar_user_get_groups:
+ * @user : a #ThunarUser.
+ *
+ * Returns all #ThunarGroup<!---->s that @user
+ * belongs to. The returned list and the #ThunarGroup<!---->s
+ * contained within the list are owned by @user and must not be
+ * freed or altered by the caller.
+ *
+ * Note that if @user has a primary group, this group will
+ * also be contained in the returned list.
+ *
+ * Return value: the groups that @user belongs to.
+ **/
+GList*
+thunar_user_get_groups (ThunarUser *user)
+{
+ ThunarUserManager *manager;
+ ThunarGroup *primary_group;
+ ThunarGroup *group;
+ gid_t gidset[NGROUPS_MAX];
+ gint gidsetlen;
+ gint n;
+
+ g_return_val_if_fail (THUNAR_IS_USER (user), NULL);
+
+ /* load the groups on-demand */
+ if (G_UNLIKELY (user->groups == NULL))
+ {
+ primary_group = thunar_user_get_primary_group (user);
+
+ /* we can only determine the groups list for the current
+ * process owner in a portable fashion, and in fact, we
+ * only need the list for the current user.
+ */
+ if (thunar_user_is_me (user))
+ {
+ manager = thunar_user_manager_get_default ();
+
+ /* add all supplementary groups */
+ gidsetlen = getgroups (G_N_ELEMENTS (gidset), gidset);
+ for (n = 0; n < gidsetlen; ++n)
+ if (primary_group == NULL || thunar_group_get_id (primary_group) != gidset[n])
+ {
+ group = thunar_user_manager_get_group_by_id (manager, gidset[n]);
+ if (G_LIKELY (group != NULL))
+ user->groups = g_list_append (user->groups, group);
+ }
+
+ g_object_unref (G_OBJECT (manager));
+ }
+
+ /* prepend the primary group (if any) */
+ if (G_LIKELY (primary_group != NULL))
+ {
+ user->groups = g_list_prepend (user->groups, primary_group);
+ g_object_ref (G_OBJECT (primary_group));
+ }
+ }
+
+ return user->groups;
+}
+
+
+
+/**
+ * thunar_user_get_primary_group:
+ * @user : a #ThunarUser.
+ *
+ * Returns the primary group of @user or %NULL if @user
+ * has no primary group.
+ *
+ * No reference is taken for the caller, so you must
+ * not call g_object_unref() on the returned object.
+ *
+ * Return value: the primary group of @user or %NULL.
+ **/
+ThunarGroup*
+thunar_user_get_primary_group (ThunarUser *user)
+{
+ g_return_val_if_fail (THUNAR_IS_USER (user), NULL);
+
+ /* load the user data on-demand */
+ if (G_UNLIKELY (user->name == NULL))
+ thunar_user_load (user);
+
+ return user->primary_group;
+}
+
+
+
+/**
+ * thunar_user_get_id:
+ * @user : a #ThunarUser.
+ *
+ * Returns the unique id of @user.
+ *
+ * Return value: the unique id of @user.
+ **/
+guint32
+thunar_user_get_id (ThunarUser *user)
+{
+ g_return_val_if_fail (THUNAR_IS_USER (user), 0);
+ return user->id;
+}
+
+
+
+/**
+ * thunar_user_get_name:
+ * @user : a #ThunarUser.
+ *
+ * Returns the name of @user. If the system is
+ * unable to determine the account name of @user,
+ * it'll return the user id as string.
+ *
+ * Return value: the name of @user.
+ **/
+const gchar*
+thunar_user_get_name (ThunarUser *user)
+{
+ g_return_val_if_fail (THUNAR_IS_USER (user), 0);
+
+ /* load the user's data on-demand */
+ if (G_UNLIKELY (user->name == NULL))
+ thunar_user_load (user);
+
+ return user->name;
+}
+
+
+
+/**
+ * thunar_user_get_real_name:
+ * @user : a #ThunarUser.
+ *
+ * Returns the real name of @user or %NULL if the
+ * real name for @user is not known to the underlying
+ * system.
+ *
+ * Return value: the real name for @user or %NULL.
+ **/
+const gchar*
+thunar_user_get_real_name (ThunarUser *user)
+{
+ g_return_val_if_fail (THUNAR_IS_USER (user), 0);
+
+ /* load the user's data on-demand */
+ if (G_UNLIKELY (user->name == NULL))
+ thunar_user_load (user);
+
+ return user->real_name;
+}
+
+
+
+/**
+ * thunar_user_is_me:
+ * @user : a #ThunarUser.
+ *
+ * Checks whether the owner of the current process is
+ * described by @user.
+ *
+ * Return value: %TRUE if @user is the owner of the current
+ * process, else %FALSE.
+ **/
+gboolean
+thunar_user_is_me (ThunarUser *user)
+{
+ g_return_val_if_fail (THUNAR_IS_USER (user), FALSE);
+ return (user->id == thunar_user_effective_uid);
+}
+
+
+
+
+static void thunar_user_manager_class_init (ThunarUserManagerClass *klass);
+static void thunar_user_manager_init (ThunarUserManager *manager);
+static void thunar_user_manager_finalize (GObject *object);
+static gboolean thunar_user_manager_flush_timer (gpointer user_data);
+static void thunar_user_manager_flush_timer_destroy (gpointer user_data);
+
+
+
+struct _ThunarUserManagerClass
+{
+ GObjectClass __parent__;
+};
+
+struct _ThunarUserManager
+{
+ GObject __parent__;
+
+ GHashTable *groups;
+ GHashTable *users;
+
+ gint flush_timer_id;
+};
+
+
+
+static GObjectClass *thunar_user_manager_parent_class;
+
+
+
+GType
+thunar_user_manager_get_type (void)
+{
+ static GType type = G_TYPE_INVALID;
+
+ if (G_UNLIKELY (type == G_TYPE_INVALID))
+ {
+ type = g_type_register_static_simple (G_TYPE_OBJECT,
+ "ThunarUserManager",
+ sizeof (ThunarUserManagerClass),
+ (GClassInitFunc) thunar_user_manager_class_init,
+ sizeof (ThunarUserManager),
+ (GInstanceInitFunc) thunar_user_manager_init,
+ 0);
+ }
+
+ return type;
+}
+
+
+
+static void
+thunar_user_manager_class_init (ThunarUserManagerClass *klass)
+{
+ GObjectClass *gobject_class;
+
+ /* determine the parent type class */
+ thunar_user_manager_parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->finalize = thunar_user_manager_finalize;
+}
+
+
+
+static void
+thunar_user_manager_init (ThunarUserManager *manager)
+{
+ manager->groups = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
+ manager->users = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
+
+ /* keep the groups file in memory if possible */
+#ifdef HAVE_SETGROUPENT
+ setgroupent (TRUE);
+#endif
+
+ /* keep the passwd file in memory if possible */
+#ifdef HAVE_SETPASSENT
+ setpassent (TRUE);
+#endif
+
+ /* start the flush timer */
+ manager->flush_timer_id = g_timeout_add_full (G_PRIORITY_LOW, THUNAR_USER_MANAGER_FLUSH_INTERVAL,
+ thunar_user_manager_flush_timer, manager,
+ thunar_user_manager_flush_timer_destroy);
+}
+
+
+
+static void
+thunar_user_manager_finalize (GObject *object)
+{
+ ThunarUserManager *manager = THUNAR_USER_MANAGER (object);
+
+ /* stop the flush timer */
+ if (G_LIKELY (manager->flush_timer_id >= 0))
+ g_source_remove (manager->flush_timer_id);
+
+ /* destroy the hash tables */
+ g_hash_table_destroy (manager->groups);
+ g_hash_table_destroy (manager->users);
+
+ /* unload the groups file */
+ endgrent ();
+
+ /* unload the passwd file */
+ endpwent ();
+
+ (*G_OBJECT_CLASS (thunar_user_manager_parent_class)->finalize) (object);
+}
+
+
+
+static gboolean
+thunar_user_manager_flush_timer (gpointer user_data)
+{
+ ThunarUserManager *manager = THUNAR_USER_MANAGER (user_data);
+ guint size = 0;
+
+ GDK_THREADS_ENTER ();
+
+ /* drop all cached groups */
+ size += g_hash_table_foreach_remove (manager->groups, (GHRFunc) gtk_true, NULL);
+
+ /* drop all cached users */
+ size += g_hash_table_foreach_remove (manager->users, (GHRFunc) gtk_true, NULL);
+
+ /* reload groups and passwd files if we had cached entities */
+ if (G_LIKELY (size > 0))
+ {
+ endgrent ();
+ endpwent ();
+
+#ifdef HAVE_SETGROUPENT
+ setgroupent (TRUE);
+#endif
+
+#ifdef HAVE_SETPASSENT
+ setpassent (TRUE);
+#endif
+ }
+
+ GDK_THREADS_LEAVE ();
+
+ return TRUE;
+}
+
+
+
+static void
+thunar_user_manager_flush_timer_destroy (gpointer user_data)
+{
+ THUNAR_USER_MANAGER (user_data)->flush_timer_id = -1;
+}
+
+
+
+/**
+ * thunar_user_manager_get_default:
+ *
+ * Returns the default #ThunarUserManager instance, which is shared
+ * by all modules using the user module. Call g_object_unref() on the
+ * returned object when you are done with it.
+ *
+ * Return value: the default #ThunarUserManager instance.
+ **/
+ThunarUserManager*
+thunar_user_manager_get_default (void)
+{
+ static ThunarUserManager *manager = NULL;
+
+ if (G_UNLIKELY (manager == NULL))
+ {
+ manager = g_object_new (THUNAR_TYPE_USER_MANAGER, NULL);
+ g_object_add_weak_pointer (G_OBJECT (manager), (gpointer) &manager);
+ }
+ else
+ {
+ g_object_ref (G_OBJECT (manager));
+ }
+
+ return manager;
+}
+
+
+
+/**
+ * thunar_user_manager_get_group_by_id:
+ * @manager : a #ThunarUserManager.
+ * @id : the group id.
+ *
+ * Looks up the #ThunarGroup corresponding to @id in @manager. Returns
+ * %NULL if @manager is unable to determine the #ThunarGroup for @id,
+ * else a pointer to the corresponding #ThunarGroup. The caller is
+ * responsible for freeing the returned object using g_object_unref().
+ *
+ * Return value: the #ThunarGroup corresponding to @id or %NULL.
+ **/
+ThunarGroup*
+thunar_user_manager_get_group_by_id (ThunarUserManager *manager,
+ guint32 id)
+{
+ ThunarGroup *group;
+
+ g_return_val_if_fail (THUNAR_IS_USER_MANAGER (manager), NULL);
+
+ /* lookup/load the group corresponding to id */
+ group = g_hash_table_lookup (manager->groups, GINT_TO_POINTER (id));
+ if (group == NULL)
+ {
+ group = thunar_group_new (id);
+ g_hash_table_insert (manager->groups, GINT_TO_POINTER (id), group);
+ }
+
+ /* take a reference for the caller */
+ g_object_ref (G_OBJECT (group));
+
+ return group;
+}
+
+
+
+/**
+ * thunar_user_manager_get_user_by_id:
+ * @manager : a #ThunarUserManager.
+ * @id : the user id.
+ *
+ * Looks up the #ThunarUser corresponding to @id in @manager. Returns
+ * %NULL if @manager is unable to determine the #ThunarUser for @id,
+ * else a pointer to the corresponding #ThunarUser. The caller is
+ * responsible for freeing the returned object using g_object_unref().
+ *
+ * Return value: the #ThunarUser corresponding to @id or %NULL.
+ **/
+ThunarUser*
+thunar_user_manager_get_user_by_id (ThunarUserManager *manager,
+ guint32 id)
+{
+ ThunarUser *user;
+
+ g_return_val_if_fail (THUNAR_IS_USER_MANAGER (manager), NULL);
+
+ /* lookup/load the user corresponding to id */
+ user = g_hash_table_lookup (manager->users, GINT_TO_POINTER (id));
+ if (user == NULL)
+ {
+ user = thunar_user_new (id);
+ g_hash_table_insert (manager->users, GINT_TO_POINTER (id), user);
+ }
+
+ /* take a reference for the caller */
+ g_object_ref (G_OBJECT (user));
+
+ return user;
+}
+
+
+
+/**
+ * thunar_user_manager_get_all_groups:
+ * @manager : a #ThunarUserManager.
+ *
+ * Returns the list of all #ThunarGroup<!---->s in the system
+ * that are known to the @manager.
+ *
+ * The caller is responsible to free the returned list using:
+ * <informalexample><programlisting>
+ * g_list_foreach (list, (GFunc) g_object_unref, NULL);
+ * g_list_free (list);
+ * </programlisting></informalexample>
+ *
+ * Return value: the list of all groups known to the @manager.
+ **/
+GList*
+thunar_user_manager_get_all_groups (ThunarUserManager *manager)
+{
+ ThunarGroup *group;
+ struct group *grp;
+ GList *groups = NULL;
+
+ g_return_val_if_fail (THUNAR_IS_USER_MANAGER (manager), NULL);
+
+ /* make sure we reload the groups list */
+ endgrent ();
+
+ /* iterate through all groups in the system */
+ for (;;)
+ {
+ /* lookup the next group */
+ grp = getgrent ();
+ if (G_UNLIKELY (grp == NULL))
+ break;
+
+ /* lookup our version of the group */
+ group = thunar_user_manager_get_group_by_id (manager, grp->gr_gid);
+ if (G_LIKELY (group != NULL))
+ groups = g_list_append (groups, group);
+ }
+
+ return groups;
+}
Added: thunar/branches/port-to-gio/thunar/thunar-user.h
===================================================================
--- thunar/branches/port-to-gio/thunar/thunar-user.h (rev 0)
+++ thunar/branches/port-to-gio/thunar/thunar-user.h 2009-01-06 23:03:23 UTC (rev 29112)
@@ -0,0 +1,88 @@
+/* $Id$ */
+/*-
+ * Copyright (c) 2005-2006 Benedikt Meurer <benny at xfce.org>
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __THUNAR_USER_H__
+#define __THUNAR_USER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS;
+
+typedef struct _ThunarGroupClass ThunarGroupClass;
+typedef struct _ThunarGroup ThunarGroup;
+
+#define THUNAR_TYPE_GROUP (thunar_group_get_type ())
+#define THUNAR_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_TYPE_GROUP, ThunarGroup))
+#define THUNAR_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), THUNAR_TYPE_GROUP, ThunarGroupClass))
+#define THUNAR_IS_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THUNAR_TYPE_GROUP))
+#define THUNAR_IS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_GROUP))
+#define THUNAR_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_GROUP, ThunarGroupClass))
+
+GType thunar_group_get_type (void) G_GNUC_CONST;
+
+guint32 thunar_group_get_id (ThunarGroup *group);
+const gchar *thunar_group_get_name (ThunarGroup *group);
+
+
+typedef struct _ThunarUserClass ThunarUserClass;
+typedef struct _ThunarUser ThunarUser;
+
+#define THUNAR_TYPE_USER (thunar_user_get_type ())
+#define THUNAR_USER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_TYPE_USER, ThunarUser))
+#define THUNAR_USER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), THUNAR_TYPE_USER, ThunarUserClass))
+#define THUNAR_IS_USER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THUNAR_TYPE_USER))
+#define THUNAR_IS_USER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_USER))
+#define THUNAR_USER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_USER, ThunarUserClass))
+
+GType thunar_user_get_type (void) G_GNUC_CONST;
+
+GList *thunar_user_get_groups (ThunarUser *user);
+ThunarGroup *thunar_user_get_primary_group (ThunarUser *user);
+guint32 thunar_user_get_id (ThunarUser *user);
+const gchar *thunar_user_get_name (ThunarUser *user);
+const gchar *thunar_user_get_real_name (ThunarUser *user);
+gboolean thunar_user_is_me (ThunarUser *user);
+
+
+typedef struct _ThunarUserManagerClass ThunarUserManagerClass;
+typedef struct _ThunarUserManager ThunarUserManager;
+
+#define THUNAR_TYPE_USER_MANAGER (thunar_user_manager_get_type ())
+#define THUNAR_USER_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_TYPE_USER_MANAGER, ThunarUserManager))
+#define THUNAR_USER_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), THUNAR_TYPE_USER_MANAGER, ThunarUserManagerClass))
+#define THUNAR_IS_USER_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THUNAR_TYPE_USER_MANAGER))
+#define THUNAR_IS_USER_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_USER_MANAGER))
+#define THUNAR_USER_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_USER_MANAGER, ThunarUserManagerClass))
+
+GType thunar_user_manager_get_type (void) G_GNUC_CONST;
+
+ThunarUserManager *thunar_user_manager_get_default (void) G_GNUC_WARN_UNUSED_RESULT;
+
+ThunarGroup *thunar_user_manager_get_group_by_id (ThunarUserManager *manager,
+ guint32 id) G_GNUC_WARN_UNUSED_RESULT;
+ThunarUser *thunar_user_manager_get_user_by_id (ThunarUserManager *manager,
+ guint32 id) G_GNUC_WARN_UNUSED_RESULT;
+
+GList *thunar_user_manager_get_all_groups (ThunarUserManager *manager) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+
+G_END_DECLS;
+
+#endif /* !__THUNAR_USER_H__ */
More information about the Xfce4-commits
mailing list