[glibmm] File, Cancellable: Added some new methods.
- From: Murray Cumming <murrayc src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glibmm] File, Cancellable: Added some new methods.
- Date: Thu, 28 Jan 2010 11:27:52 +0000 (UTC)
commit 27feaaa86cf2205a0e1bae74733d05ba17275258
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Jan 28 11:51:41 2010 +0100
File, Cancellable: Added some new methods.
* gio/src/cancellable.hg: Added release_fd() and make_polldf().
* gio/src/file.[hg|ccg]: Added open_readwrite(), open_readwrite_async()
and finish_readwrite().
Added replace_readwrite(), replace_readwrite_async() and
finish_replace_readwrite().
* tools/m4/convert_gio.m4:Added conversion for FileIOStream.
* glib/src/glib_enums.defs: Fix an #error that enum.pl has put there
for some reason.
ChangeLog | 13 ++++
gio/src/cancellable.hg | 3 +
gio/src/file.ccg | 107 ++++++++++++++++++++++++++++++++++
gio/src/file.hg | 144 ++++++++++++++++++++++++++++++++++++++++++++++
glib/src/glib_enums.defs | 2 +-
tools/m4/convert_gio.m4 | 2 +
6 files changed, 270 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1f7ed41..74fdc76 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2010-01-28 Murray Cumming <murrayc murrayc com>
+
+ File, Cancellable: Added some new methods.
+
+ * gio/src/cancellable.hg: Added release_fd() and make_polldf().
+ * gio/src/file.[hg|ccg]: Added open_readwrite(), open_readwrite_async()
+ and finish_readwrite().
+ Added replace_readwrite(), replace_readwrite_async() and
+ finish_replace_readwrite().
+ * tools/m4/convert_gio.m4:Added conversion for FileIOStream.
+ * glib/src/glib_enums.defs: Fix an #error that enum.pl has put there
+ for some reason.
+
2010-01-05 Daniel Elstner <daniel kitta gmail com>
Fine-tune Doxygen configuration to improve output
diff --git a/gio/src/cancellable.hg b/gio/src/cancellable.hg
index a3ef6ad..33df9ce 100644
--- a/gio/src/cancellable.hg
+++ b/gio/src/cancellable.hg
@@ -50,6 +50,9 @@ public:
//May return -1 if fds not supported, or on errors .
_WRAP_METHOD(int get_fd() const, g_cancellable_get_fd)
+ _WRAP_METHOD(bool make_pollfd(GPollFD* pollfd), g_cancellable_make_pollfd)
+ _WRAP_METHOD(void release_fd(), g_cancellable_release_fd)
+
//This is safe to call from another thread.
_WRAP_METHOD(void cancel(), g_cancellable_cancel)
diff --git a/gio/src/file.ccg b/gio/src/file.ccg
index 3d0bd19..2d38fb4 100644
--- a/gio/src/file.ccg
+++ b/gio/src/file.ccg
@@ -270,6 +270,72 @@ File::replace_async(const SlotAsyncReady& slot, const std::string& etag, bool ma
slot_copy);
}
+void
+File::open_readwrite_async(const SlotAsyncReady& slot, int io_priority)
+{
+ // Create a copy of the slot.
+ // A pointer to it will be passed through the callback's data parameter
+ // and deleted in the callback.
+ SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
+
+ g_file_open_readwrite_async(gobj(),
+ io_priority,
+ NULL,
+ &SignalProxy_async_callback,
+ slot_copy);
+}
+
+void
+File::open_readwrite_async(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, int io_priority)
+{
+ // Create a copy of the slot.
+ // A pointer to it will be passed through the callback's data parameter
+ // and deleted in the callback.
+ SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
+
+ g_file_open_readwrite_async(gobj(),
+ io_priority,
+ cancellable->gobj(),
+ &SignalProxy_async_callback,
+ slot_copy);
+}
+
+void
+File::replace_readwrite_async(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, const std::string& etag, bool make_backup, FileCreateFlags flags, int io_priority)
+{
+ // Create a copy of the slot.
+ // A pointer to it will be passed through the callback's data parameter
+ // and deleted in the callback.
+ SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
+
+ g_file_replace_readwrite_async(gobj(),
+ etag.empty() ? NULL : etag.c_str(),
+ make_backup,
+ static_cast<GFileCreateFlags>(flags),
+ io_priority,
+ cancellable->gobj(),
+ &SignalProxy_async_callback,
+ slot_copy);
+}
+
+void
+File::replace_readwrite_async(const SlotAsyncReady& slot, const std::string& etag, bool make_backup, FileCreateFlags flags, int io_priority)
+{
+ // Create a copy of the slot.
+ // A pointer to it will be passed through the callback's data parameter
+ // and deleted in the callback.
+ SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
+
+ g_file_replace_readwrite_async(gobj(),
+ etag.empty() ? NULL : etag.c_str(),
+ make_backup,
+ static_cast<GFileCreateFlags>(flags),
+ io_priority,
+ NULL, // cancellable
+ &SignalProxy_async_callback,
+ slot_copy);
+}
+
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::RefPtr<FileInfo> File::query_info(const Glib::RefPtr<Cancellable>& cancellable, const std::string& attributes, FileQueryInfoFlags flags) const
#else
@@ -1556,6 +1622,47 @@ Glib::RefPtr<FileOutputStream> File::replace(const std::string& etag, bool make_
return retvalue;
}
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+Glib::RefPtr<FileIOStream> File::replace_readwrite(const Glib::RefPtr<Cancellable>& cancellable, const std::string& etag, bool make_backup, FileCreateFlags flags)
+#else
+Glib::RefPtr<FileIOStream> File::replace_readwrite(const Glib::RefPtr<Cancellable>& cancellable, const std::string& etag, bool make_backup, FileCreateFlags flags, std::auto_ptr<Glib::Error>& error)
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+ GError* gerror = 0;
+ Glib::RefPtr<FileIOStream> retvalue = Glib::wrap(g_file_replace_readwrite(gobj(), etag.empty() ? NULL : etag.c_str(), static_cast<int>(make_backup), ((GFileCreateFlags)(flags)), const_cast<GCancellable*>(Glib::unwrap(cancellable)), &(gerror)));
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ if(gerror)
+ ::Glib::Error::throw_exception(gerror);
+#else
+ if(gerror)
+ error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+ return retvalue;
+}
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+Glib::RefPtr<FileIOStream> File::replace_readwrite(const std::string& etag, bool make_backup, FileCreateFlags flags)
+#else
+Glib::RefPtr<FileIOStream> File::replace_readwrite(const std::string& etag, bool make_backup, FileCreateFlags flags, std::auto_ptr<Glib::Error>& error)
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+ GError* gerror = 0;
+ Glib::RefPtr<FileIOStream> retvalue = Glib::wrap(g_file_replace_readwrite(gobj(), etag.empty() ? NULL : etag.c_str(), static_cast<int>(make_backup), ((GFileCreateFlags)(flags)), NULL, &(gerror)));
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ if(gerror)
+ ::Glib::Error::throw_exception(gerror);
+#else
+ if(gerror)
+ error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+ return retvalue;
+}
+
+
+
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::RefPtr<FileMonitor> File::monitor_directory(const Glib::RefPtr<Cancellable>& cancellable, FileMonitorFlags flags)
#else
diff --git a/gio/src/file.hg b/gio/src/file.hg
index 81d313b..908a3bc 100644
--- a/gio/src/file.hg
+++ b/gio/src/file.hg
@@ -29,6 +29,7 @@
#include <giomm/fileenumerator.h>
#include <giomm/fileinfo.h>
#include <giomm/fileinputstream.h>
+#include <giomm/fileiostream.h>
#include <giomm/filemonitor.h>
#include <giomm/fileoutputstream.h>
#include <giomm/mountoperation.h>
@@ -498,6 +499,149 @@ public:
g_file_replace_finish,
refreturn, errthrow)
+
+ _WRAP_METHOD(Glib::RefPtr<FileIOStream> open_readwrite(const Glib::RefPtr<Cancellable>& cancellable),
+ g_file_open_readwrite,
+ refreturn, errthrow)
+
+ /** Opens an existing file for reading and writing.
+ * The result is a FileIOStream that can be used to read and write the contents of the file.
+ *
+ * For more details, see open_readwrite() which is the synchronous version of this call.
+ * When the operation is finished, @a slot will be called. You can then call open_readwrite_finish() to get the result of the operation.
+ * If the file does not exist, a Gio::Error with NOT_FOUND will be thrown.
+ * If the file is a directory, a Gio::Error with IS_DIRECTORY will be thrown.
+ * Other errors are possible too, and depend on what kind of filesystem the file is on.
+ *
+ * Note that in many non-local file cases read and write streams are not supported,
+ * so make sure you really need to do read and write streaming, rather than
+ * just opening for reading or writing.
+ *
+ * @param slot A callback slot which will be called when the request is satisfied.
+ * @param cancellable A Cancellable object which can be used to cancel the operation.
+ * @param io_priority The I/O priority of the request.
+ *
+ * @newin2p22
+ */
+ void open_readwrite_async(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, int io_priority = Glib::PRIORITY_DEFAULT);
+
+ /** Opens an existing file for reading and writing.
+ * The result is a FileIOStream that can be used to read and write the contents of the file.
+ *
+ * For more details, see open_readwrite() which is the synchronous version of this call.
+ * When the operation is finished, @a slot will be called. You can then call open_readwrite_finish() to get the result of the operation.
+ * If the file does not exist, a Gio::Error with NOT_FOUND will be thrown.
+ * If the file is a directory, a Gio::Error with IS_DIRECTORY will be thrown.
+ * Other errors are possible too, and depend on what kind of filesystem the file is on.
+ *
+ * Note that in many non-local file cases read and write streams are not supported,
+ * so make sure you really need to do read and write streaming, rather than
+ * just opening for reading or writing.
+ *
+ * @param slot A callback slot which will be called when the request is satisfied.
+ * @param io_priority The I/O priority of the request.
+ *
+ * @newin2p22
+ */
+ void open_readwrite_async(const SlotAsyncReady& slot, int io_priority = Glib::PRIORITY_DEFAULT);
+ _IGNORE(g_file_open_readwrite_async)
+
+ _WRAP_METHOD(Glib::RefPtr<FileIOStream> open_readwrite_finish(const Glib::RefPtr<AsyncResult>& result),
+ g_file_replace_readwrite_finish,
+ refreturn, errthrow)
+
+
+ /** Returns an output stream for overwriting the file in readwrite mode, possibly creating a backup copy of the file first.
+ *
+ * If the file doesn't exist, it will be created.
+ *
+ * For details about the behaviour, see replace() which does the same thing but returns an output stream only.
+ *
+ * Note that in many non-local file cases read and write streams are not supported,
+ * so make sure you really need to do read and write streaming,
+ * rather than just opening for reading or writing.
+ *
+ * @param etag An optional entity tag for the current Glib::File.
+ * @param make_backup <tt>true</tt> if a backup should be created.
+ * @param flags A set of FileCreateFlags.
+ * @return A FileOutputStream.
+ *
+ * @newin2p22
+ */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ Glib::RefPtr<FileIOStream> replace_readwrite(const Glib::RefPtr<Cancellable>& cancellable, const std::string& etag = std::string(), bool make_backup = false, FileCreateFlags flags = FILE_CREATE_NONE);
+#else
+ Glib::RefPtr<FileIOStream> replace_readwrite(const Glib::RefPtr<Cancellable>& cancellable, const std::string& etag, bool make_backup, FileCreateFlags flags, std::auto_ptr<Glib::Error>& error);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+
+ /** /** Returns an output stream for overwriting the file in readwrite mode, possibly creating a backup copy of the file first.
+ *
+ * If the file doesn't exist, it will be created.
+ *
+ * For details about the behaviour, see replace() which does the same thing but returns an output stream only.
+ *
+ * Note that in many non-local file cases read and write streams are not supported,
+ * so make sure you really need to do read and write streaming,
+ * rather than just opening for reading or writing.
+ *
+ * @param etag An optional entity tag for the current Glib::File.
+ * @param make_backup <tt>true</tt> if a backup should be created.
+ * @param flags A set of FileCreateFlags.
+ * @return A FileOutputStream.
+ *
+ * @newin2p22
+ */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ Glib::RefPtr<FileIOStream> replace_readwrite(const std::string& etag = std::string(), bool make_backup = false, FileCreateFlags flags = FILE_CREATE_NONE);
+#else
+ Glib::RefPtr<FileIOStream> replace_readwrite(const std::string& etag, bool make_backup, FileCreateFlags flags, std::auto_ptr<Glib::Error>& error);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+ _IGNORE(g_file_replace_readwrite)
+
+
+ /** Asyncronously overwrites the file in read-write mode, replacing the contents, possibly creating a backup copy of the file first.
+ *
+ * For more details, see replace_readwrite() which is the synchronous version of this call.
+ * When the operation is finished, @a slot will be called. You can then call replace_readwrite_finish() to get the result of the operation.
+ *
+ * @param slot A callback slot which will be called when the request is satisfied.
+ * @param cancellable A Cancellable object which can be used to cancel the operation.
+ * @param etag An entity tag for the current Gio::File.
+ * @param make_backup true if a backup of the existing file should be made.
+ * @param flags A set of FileCreateFlags.
+ * @param io_priority The I/O priority of the request.
+ *
+ * @newin2p22
+ */
+ void replace_readwrite_async(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, const std::string& etag = std::string(), bool make_backup = false, FileCreateFlags flags = FILE_CREATE_NONE, int io_priority = Glib::PRIORITY_DEFAULT);
+
+ /** Asyncronously overwrites the file in read-write mode, replacing the contents, possibly creating a backup copy of the file first.
+ *
+ * For more details, see replace_readwrite() which is the synchronous version of this call.
+ * When the operation is finished, @a slot will be called. You can then call replace_readwrite_finish() to get the result of the operation.
+ *
+ * @param slot A callback slot which will be called when the request is satisfied.
+ * @param etag An entity tag for the current Gio::File.
+ * @param make_backup true if a backup of the existing file should be made.
+ * @param flags A set of FileCreateFlags.
+ * @param io_priority The I/O priority of the request.
+ *
+ * @newin2p22
+ */
+ void replace_readwrite_async(const SlotAsyncReady& slot, const std::string& etag = std::string(), bool make_backup = false, FileCreateFlags flags = FILE_CREATE_NONE, int io_priority = Glib::PRIORITY_DEFAULT);
+ _IGNORE(g_file_replace_async)
+
+ _WRAP_METHOD(Glib::RefPtr<FileIOStream> replace_readwrite_finish(const Glib::RefPtr<AsyncResult>& result),
+ g_file_replace_readwrite_finish,
+ refreturn, errthrow)
+
+
+
+
+
+
/** Gets the requested information about the file. The result
* is a FileInfo object that contains key-value attributes (such as the type or size
* of the file).
diff --git a/glib/src/glib_enums.defs b/glib/src/glib_enums.defs
index dc01dbd..e4da8e9 100644
--- a/glib/src/glib_enums.defs
+++ b/glib/src/glib_enums.defs
@@ -795,7 +795,7 @@
(c-name "GNormalizeMode")
(values
'("default" "G_NORMALIZE_DEFAULT" "0")
- '("nfd" "G_NORMALIZE_NFD" "#error")
+ '("nfd" "G_NORMALIZE_NFD" "0")
'("default-compose" "G_NORMALIZE_DEFAULT_COMPOSE" "1")
'("nfc" "G_NORMALIZE_NFC" "1")
'("all" "G_NORMALIZE_ALL" "2")
diff --git a/tools/m4/convert_gio.m4 b/tools/m4/convert_gio.m4
index ac22fda..39547c1 100644
--- a/tools/m4/convert_gio.m4
+++ b/tools/m4/convert_gio.m4
@@ -89,6 +89,8 @@ _CONVERSION(`GFileOutputStream*',`Glib::RefPtr<FileOutputStream>',`Glib::wrap($3
# FilterInputStream
#_CONVERSION(`GFilterInputStream*',`Glib::RefPtr<FilterInputStream>',`Glib::wrap($3)')
+_CONVERSION(`GFileIOStream*',`Glib::RefPtr<FileIOStream>',`Glib::wrap($3)')
+
# Icon
_CONVERSION(`GIcon*',`Glib::RefPtr<Icon>',`Glib::wrap($3)')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]