diff options
author | Alexander Larsson <alexl@src.gnome.org> | 2007-09-13 08:58:22 +0000 |
---|---|---|
committer | Alexander Larsson <alexl@src.gnome.org> | 2007-09-13 08:58:22 +0000 |
commit | 0af70d2df7f5ef0e9e472bd495279d5fe56b87df (patch) | |
tree | a123fc6095bc27166a677e5a2f7509733b6771b8 | |
parent | 6182f989b1359cdca4bf3da40d0305dc1ccfef16 (diff) | |
download | gvfs-0af70d2df7f5ef0e9e472bd495279d5fe56b87df.tar.gz |
Add initial GMountOperation
Add custom marshallers as needed.
Original git commit by Alexander Larsson <alex@greebo.(none)> at 1159892908 +0200
svn path=/trunk/; revision=86
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | gvfs/.gitignore | 2 | ||||
-rw-r--r-- | gvfs/Makefile.am | 24 | ||||
-rw-r--r-- | gvfs/gmountoperation.c | 215 | ||||
-rw-r--r-- | gvfs/gmountoperation.h | 95 | ||||
-rw-r--r-- | gvfs/gvfs-marshal.list | 3 | ||||
-rw-r--r-- | txt/ops.txt | 5 |
7 files changed, 351 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index e06a227f..4cf9879c 100644 --- a/configure.ac +++ b/configure.ac @@ -55,9 +55,15 @@ if test "x$enable_selinux" != "xno"; then fi AC_SUBST(SELINUX_LIBS) +dnl ========================================================================== + dnl Globally define_GNU_SOURCE and therefore enable the GNU extensions AC_DEFINE(_GNU_SOURCE, 1, [Enable GNU Extensions]) - + +dnl ========================================================================== + +AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal) + dnl ========================================================================== dnl Turn on the additional warnings last, so -Werror doesn't affect other tests. diff --git a/gvfs/.gitignore b/gvfs/.gitignore index 26e1b556..76cc60cd 100644 --- a/gvfs/.gitignore +++ b/gvfs/.gitignore @@ -7,3 +7,5 @@ test .libs Makefile Makefile.in +gvfs-marshal.c +gvfs-marshal.h diff --git a/gvfs/Makefile.am b/gvfs/Makefile.am index 4b4d6c6a..6d569aef 100644 --- a/gvfs/Makefile.am +++ b/gvfs/Makefile.am @@ -6,6 +6,18 @@ INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/gvfs \ lib_LTLIBRARIES = libgvfs.la +marshal_sources = \ + gvfs-marshal.h \ + gvfs-marshal.c \ + $(NULL) + +gvfs-marshal.h: gvfs-marshal.list $(GLIB_GENMARSHAL) + $(GLIB_GENMARSHAL) --prefix=_gvfs_marshal $(srcdir)/gvfs-marshal.list --header > $@ + +gvfs-marshal.c: gvfs-marshal.h gvfs-marshal.list $(GLIB_GENMARSHAL) + (echo "#include \"gvfs-marshal.h\""; \ + $(GLIB_GENMARSHAL) --prefix=_gvfs_marshal $(srcdir)/gvfs-marshal.list --body) > $@ + libgvfs_la_SOURCES = \ gasynchelper.c \ gasynchelper.h \ @@ -32,6 +44,9 @@ libgvfs_la_SOURCES = \ gvfserror.c \ gvfssimple.c \ gvfssimple.h \ + gmountoperation.c \ + gmountoperation.h \ + $(marshal_sources) \ $(NULL) libgvfs_la_LIBADD = \ @@ -62,3 +77,12 @@ test_SOURCES = \ test_LDADD = \ libgvfs.la \ $(GLIB_LIBS) + +EXTRA_DIST = \ + gvfs-marshal.list \ + $(NULL) + +CLEANFILES = \ + $(marshal_sources) \ + $(NULL) + diff --git a/gvfs/gmountoperation.c b/gvfs/gmountoperation.c new file mode 100644 index 00000000..06d8eebc --- /dev/null +++ b/gvfs/gmountoperation.c @@ -0,0 +1,215 @@ +#include <config.h> + +#include <string.h> + +#include <gvfstypes.h> +#include "gmountoperation.h" +#include "gvfs-marshal.h" +#include <glib/gi18n-lib.h> + +G_DEFINE_TYPE (GMountOperation, g_mount_operation, G_TYPE_OBJECT); + +enum { + ASK_PASSWORD, + ASK_QUESTION, + DONE, + REPLY, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +struct _GMountOperationPrivate { + char *password; + char *user; + char *domain; + gboolean anonymous; + GPasswordSave password_save; + int choice; +}; + +static void +g_mount_operation_finalize (GObject *object) +{ + GMountOperation *operation; + GMountOperationPrivate *priv; + + operation = G_MOUNT_OPERATION (object); + + priv = operation->priv; + + g_free (priv->password); + g_free (priv->user); + g_free (priv->domain); + + if (G_OBJECT_CLASS (g_mount_operation_parent_class)->finalize) + (*G_OBJECT_CLASS (g_mount_operation_parent_class)->finalize) (object); +} + +static gboolean +boolean_handled_accumulator (GSignalInvocationHint *ihint, + GValue *return_accu, + const GValue *handler_return, + gpointer dummy) +{ + gboolean continue_emission; + gboolean signal_handled; + + signal_handled = g_value_get_boolean (handler_return); + g_value_set_boolean (return_accu, signal_handled); + continue_emission = !signal_handled; + + return continue_emission; +} + +static void +g_mount_operation_class_init (GMountOperationClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (GMountOperationPrivate)); + + gobject_class->finalize = g_mount_operation_finalize; + + signals[ASK_PASSWORD] = + g_signal_new (I_("ask_password"), + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GMountOperationClass, ask_password), + boolean_handled_accumulator, NULL, + _gvfs_marshal_BOOLEAN__STRING_STRING_STRING_INT, + G_TYPE_BOOLEAN, 4, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT); + + signals[ASK_QUESTION] = + g_signal_new (I_("ask_question"), + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GMountOperationClass, ask_question), + boolean_handled_accumulator, NULL, + _gvfs_marshal_BOOLEAN__STRING_POINTER, + G_TYPE_NONE, 2, + G_TYPE_STRING, G_TYPE_POINTER); + + signals[REPLY] = + g_signal_new (I_("reply"), + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GMountOperationClass, reply), + NULL, NULL, + _gvfs_marshal_VOID__BOOLEAN_POINTER, + G_TYPE_NONE, 2, + G_TYPE_BOOLEAN, G_TYPE_POINTER); + + signals[DONE] = + g_signal_new (I_("done"), + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GMountOperationClass, done), + NULL, NULL, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, + G_TYPE_BOOLEAN); +} + +static void +g_mount_operation_init (GMountOperation *operation) +{ + operation->priv = G_TYPE_INSTANCE_GET_PRIVATE (operation, + G_TYPE_MOUNT_OPERATION, + GMountOperationPrivate); +} + +GMountOperation * +g_mount_operation_new (void) +{ + return g_object_new (G_TYPE_MOUNT_OPERATION, NULL); +} + +const char * +g_mount_operation_get_username (GMountOperation *op) +{ + return op->priv->user; +} + +void +g_mount_operation_set_username (GMountOperation *op, + const char *username) +{ + g_free (op->priv->user); + op->priv->user = g_strdup (username); +} + +const char * +g_mount_operation_get_password (GMountOperation *op) +{ + return op->priv->password; +} + +void +g_mount_operation_set_password (GMountOperation *op, + const char *password) +{ + g_free (op->priv->password); + op->priv->password = g_strdup (password); +} + +gboolean +g_mount_operation_get_anonymous (GMountOperation *op) +{ + return op->priv->anonymous; +} + +void +g_mount_operation_set_anonymous (GMountOperation *op, + gboolean anonymous) +{ + op->priv->anonymous = anonymous; +} + +const char * +g_mount_operation_get_domain (GMountOperation *op) +{ + return op->priv->password; +} + +void +g_mount_operation_set_domain (GMountOperation *op, + const char *domain) +{ + g_free (op->priv->domain); + op->priv->domain = g_strdup (domain); +} + +GPasswordSave +g_mount_operation_get_password_save (GMountOperation *op) +{ + return op->priv->password_save; +} + +void +g_mount_operation_set_password_save (GMountOperation *op, + GPasswordSave save) +{ + op->priv->password_save = save; +} + +int +g_mount_operation_get_choice (GMountOperation *op) +{ + return op->priv->choice; +} + +void +g_mount_operation_set_choice (GMountOperation *op, + int choice) +{ + op->priv->choice = choice; +} + +void +g_mount_operation_reply (GMountOperation *op, + gboolean abort) +{ + g_signal_emit (op, signals[REPLY], 0, abort); +} diff --git a/gvfs/gmountoperation.h b/gvfs/gmountoperation.h new file mode 100644 index 00000000..7769c90d --- /dev/null +++ b/gvfs/gmountoperation.h @@ -0,0 +1,95 @@ +#ifndef __G_MOUNT_OPERATION_H__ +#define __G_MOUNT_OPERATION_H__ + +#include <sys/stat.h> + +#include <glib-object.h> +#include <gvfs/gvfstypes.h> + +G_BEGIN_DECLS + +#define G_TYPE_MOUNT_OPERATION (g_mount_operation_get_type ()) +#define G_MOUNT_OPERATION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_MOUNT_OPERATION, GMountOperation)) +#define G_MOUNT_OPERATION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_MOUNT_OPERATION, GMountOperationClass)) +#define G_IS_MOUNT_OPERATION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_MOUNT_OPERATION)) +#define G_IS_MOUNT_OPERATION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_MOUNT_OPERATION)) +#define G_MOUNT_OPERATION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_MOUNT_OPERATION, GMountOperationClass)) + +typedef struct _GMountOperation GMountOperation; +typedef struct _GMountOperationClass GMountOperationClass; +typedef struct _GMountOperationPrivate GMountOperationPrivate; + +struct _GMountOperation +{ + GObject parent_instance; + + GMountOperationPrivate *priv; +}; + +typedef enum { + G_PASSWORD_FLAGS_NEED_PASSWORD = 1<<0, + G_PASSWORD_FLAGS_NEED_USERNAME = 1<<1, + G_PASSWORD_FLAGS_NEED_DOMAIN = 1<<2, + G_PASSWORD_FLAGS_SAVING_SUPPORTED = 1<<4, + G_PASSWORD_FLAGS_ANON_SUPPORTED = 1<<5 +} GPasswordFlags; + +typedef enum { + G_PASSWORD_SAVE_NEVER, + G_PASSWORD_SAVE_FOR_SESSION, + G_PASSWORD_SAVE_PERMANENTLY +} GPasswordSave; + +struct _GMountOperationClass +{ + GObjectClass parent_class; + + /* signals: */ + + gboolean (* ask_password) (GMountOperation *op, + const char *message, + const char *default_user, + const char *default_domain, + GPasswordFlags flags); + gboolean (* ask_question) (GMountOperation *op, + const char *message, + const char *choices[]); + + void (* done) (GMountOperation *op, + gboolean succeeded, + GError *error); + + void (* reply) (GMountOperation *op, + gboolean abort); + + +}; + +GType g_mount_operation_get_type (void) G_GNUC_CONST; + +GMountOperation * g_mount_operation_new (void); + +const char * g_mount_operation_get_username (GMountOperation *op); +void g_mount_operation_set_username (GMountOperation *op, + const char *username); +const char * g_mount_operation_get_password (GMountOperation *op); +void g_mount_operation_set_password (GMountOperation *op, + const char *password); +gboolean g_mount_operation_get_anonymous (GMountOperation *op); +void g_mount_operation_set_anonymous (GMountOperation *op, + gboolean anonymous); +const char * g_mount_operation_get_domain (GMountOperation *op); +void g_mount_operation_set_domain (GMountOperation *op, + const char *domain); +GPasswordSave g_mount_operation_get_password_save (GMountOperation *op); +void g_mount_operation_set_password_save (GMountOperation *op, + GPasswordSave save); +int g_mount_operation_get_choice (GMountOperation *op); +void g_mount_operation_set_choice (GMountOperation *op, + int choice); +void g_mount_operation_reply (GMountOperation *op, + gboolean abort); + +G_END_DECLS + +#endif /* __G_MOUNT_OPERATION_H__ */ diff --git a/gvfs/gvfs-marshal.list b/gvfs/gvfs-marshal.list new file mode 100644 index 00000000..31a4e812 --- /dev/null +++ b/gvfs/gvfs-marshal.list @@ -0,0 +1,3 @@ +BOOLEAN:STRING,STRING,STRING,INT +BOOLEAN:STRING,POINTER +VOID:BOOLEAN,POINTER diff --git a/txt/ops.txt b/txt/ops.txt index 757eb131..c1f04c34 100644 --- a/txt/ops.txt +++ b/txt/ops.txt @@ -22,6 +22,11 @@ GFSInfo { char *get_fs_type() gint64 get_free_space() gint64 get_total_space() + char * get_hal_uid() + can_unmount() + can_eject() + must_eject() + } GFile *g_file_for_path (char *path) |