This commit is contained in:
Yevgen Muntyan 2016-01-19 03:54:06 -08:00
parent 7e468b2810
commit c640dc0edf
52 changed files with 904 additions and 907 deletions

View File

@ -1,6 +1,6 @@
#include <errno.h>
#include <mooedit/mooeditfileinfo.h>
#include <moocpp/gobjectutils.h>
#include "moocpp/gobjtypes.h"
static MooOpenInfo *
parse_filename (const char *filename)

View File

@ -566,7 +566,7 @@ gboolean App::Private::check_signal ()
static gboolean
emit_started (App *app)
{
g_signal_emit_by_name (app, "started");
app->signal_emit_by_name ("started");
return FALSE;
}
@ -853,36 +853,30 @@ void App::Private::save_session ()
void App::Private::write_session ()
{
char *filename;
GError *error = NULL;
MooFileWriter *writer;
if (session_file.empty())
return;
filename = moo_get_user_cache_file (session_file);
gstr filename = gstr::wrap_new (moo_get_user_cache_file (session_file));
if (!session)
{
mgw_errno_t err;
mgw_unlink (filename, &err);
g_free (filename);
return;
}
if ((writer = moo_config_writer_new (filename, FALSE, &error)))
gerrp error;
if ((writer = moo_config_writer_new (filename, FALSE, error)))
{
moo_markup_write_pretty (session.gobj(), writer, 1);
moo_file_writer_close (writer, &error);
moo_file_writer_close (writer, error);
}
if (error)
{
g_critical ("could not save session file %s: %s", filename, error->message);
g_error_free (error);
}
g_free (filename);
}
void App::load_session ()
@ -1122,14 +1116,13 @@ void App::Private::report_bug (GtkWidget *window)
void App::Private::save_prefs ()
{
GError *error = NULL;
gerrp error;
if (!moo_prefs_save (rc_files[MOO_PREFS_RC],
rc_files[MOO_PREFS_STATE],
&error))
error))
{
g_warning ("could not save config files: %s", moo_error_message (error));
g_error_free (error);
}
}
@ -1172,7 +1165,7 @@ void App::Private::prefs_dialog (GtkWidget *parent)
void App::Private::load_prefs ()
{
GError *error = NULL;
gerrp error;
char **sys_files;
rc_files[MOO_PREFS_RC].take(moo_get_user_data_file (MOO_PREFS_XML_FILE_NAME));
@ -1183,10 +1176,9 @@ void App::Private::load_prefs ()
if (!moo_prefs_load (sys_files,
rc_files[MOO_PREFS_RC],
rc_files[MOO_PREFS_STATE],
&error))
error))
{
g_warning ("could not read config files: %s", moo_error_message (error));
g_error_free (error);
}
g_strfreev (sys_files);

View File

@ -18,7 +18,7 @@
#include "marshals.h"
#include "mooutils/mooutils-misc.h"
#include "mooutils/moocompat.h"
#include "moocpp/gobjectutils.h"
#include "moocpp/gobjtypes.h"
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <mooglib/moo-glib.h>

View File

@ -160,16 +160,4 @@ struct class_helper
} // namespace moo
MOO_DEFINE_FLAGS(GSignalFlags);
MOO_DEFINE_FLAGS(GdkEventMask);
MOO_DEFINE_FLAGS(GdkModifierType);
MOO_DEFINE_FLAGS(GtkCellRendererState);
MOO_DEFINE_FLAGS(GtkAttachOptions);
MOO_DEFINE_FLAGS(GdkDragAction);
MOO_DEFINE_FLAGS(GConnectFlags);
MOO_DEFINE_FLAGS(GSpawnFlags);
MOO_DEFINE_FLAGS(GIOCondition);
MOO_DEFINE_FLAGS(GLogLevelFlags);
MOO_DEFINE_FLAGS(GRegexCompileFlags);
#endif // __cplusplus

View File

@ -96,7 +96,7 @@ public:
operator const Object* () const { return gobj(); }
operator ref_type*() const { return m_ref.self(); }
ref_type* operator->() const { return m_ref.self(); }
ref_type& operator*() const { return m_ref; }
ref_type operator*() const { return m_ref; }
// These are nasty. Because of ref_type* conversion this can be converted to void*,
// which in turn can be passed to g_object_ref or g_free, etc.

View File

@ -85,67 +85,6 @@ private:
mutable gobj_ref<Object> m_ref;
};
template<typename Object>
class gobj_raw_ptr<const Object>
{
using ref_type = gobj_ref<Object>;
public:
gobj_raw_ptr(const Object* obj = nullptr) { m_ref._set_gobj(const_cast<Object*>(obj)); }
operator const Object*() const { return gobj(); }
operator const GTypeInstance*() const { return reinterpret_cast<GTypeInstance*>(gobj()); }
operator const void*() const { return gobj(); }
operator const gobj_ref<Object>*() const { return m_ref.self(); }
const ref_type* operator->() const { return m_ref.self(); }
const ref_type& operator*() const { return m_ref; }
const Object* gobj() const { return m_ref.gobj(); }
void set(const Object* p) { m_ref._set_gobj(p); }
template<typename Super>
const Super* gobj() const
{
return gobj_is_subclass<Object, Super>::down_cast(m_ref.gobj());
}
template<typename Subclass>
void set(const Subclass* p)
{
set(gobj_is_subclass<Subclass, Object>::down_cast(p));
}
operator bool() const { return gobj() != nullptr; }
bool operator!() const { return gobj() == nullptr; }
gobj_raw_ptr(const gobj_raw_ptr& other) = default;
gobj_raw_ptr& operator=(const gobj_raw_ptr& other) = default;
gobj_raw_ptr(gobj_raw_ptr&& other)
: m_ref(other.gobj())
{
other = nullptr;
}
gobj_raw_ptr& operator=(gobj_raw_ptr&& other)
{
m_ref._set_gobj(other.gobj());
other.m_ref._set_gobj(nullptr);
return *this;
}
template<typename T>
gobj_raw_ptr& operator=(const T* p)
{
set(p);
return *this;
}
private:
mutable gobj_ref<Object> m_ref;
};
} // namespace moo
template<typename X>

View File

@ -56,12 +56,9 @@ public:
return *this;
}
GObject* gobj() { return m_gobj; }
const GObject* gobj() const { return m_gobj; }
operator GObject&() { return *m_gobj; }
operator const GObject&() const { return *m_gobj; }
operator GTypeInstance&() { return *reinterpret_cast<GTypeInstance*>(m_gobj); }
operator const GTypeInstance&() const { return *reinterpret_cast<const GTypeInstance*>(m_gobj); }
GObject* gobj() const { return m_gobj; }
operator GObject&() const { return *m_gobj; }
operator GTypeInstance&() const { return *reinterpret_cast<GTypeInstance*>(m_gobj); }
protected:
GObject* raw_gobj() const { return const_cast<GObject*>(m_gobj); }
@ -93,7 +90,6 @@ class gobj_ref<GObject>; // : public gobj_ref_base
protected: \
friend class gobj_ptr<object_type>; \
friend class gobj_raw_ptr<object_type>; \
friend class gobj_raw_ptr<const object_type>; \
\
gobj_ref() {} \
\
@ -103,24 +99,13 @@ public:
_set_gobj(&gobj); \
} \
\
object_type* gobj() \
object_type* gobj() const \
{ \
return reinterpret_cast<object_type*>(raw_gobj()); \
} \
\
const object_type* gobj() const \
{ \
return reinterpret_cast<const object_type*>(raw_gobj()); \
} \
\
template<typename X> \
X* gobj() \
{ \
return nc_gobj<X>(); \
} \
\
template<typename X> \
const X* gobj() const \
X* gobj() const \
{ \
return nc_gobj<X>(); \
} \
@ -140,10 +125,8 @@ public:
gobj_ref* self() { return this; } \
const gobj_ref* self() const { return this; } \
\
operator object_type&() { return *gobj(); } \
operator const object_type&() const { return *gobj(); } \
gobj_raw_ptr<object_type> operator&() { return nc_gobj(); } \
gobj_raw_ptr<const object_type> operator&() const { return nc_gobj(); } \
operator object_type&() const { return *gobj(); } \
gobj_raw_ptr<object_type> operator&() const { return nc_gobj(); } \
\
gobj_ref(const gobj_ref&) = default; \
gobj_ref& operator=(const gobj_ref&) = default; \

View File

@ -21,7 +21,7 @@ using namespace moo::g;
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// gobj_ref<GFile>
// GFile
//
FilePtr File::new_for_path(const char* path)
@ -89,9 +89,9 @@ FilePtr File::get_child(const char* name)
return FilePtr::wrap_new(g_file_get_child(nc_gobj(), name));
}
FilePtr File::get_child_for_display_name(const char* display_name, GError** error)
FilePtr File::get_child_for_display_name(const char* display_name, gerrp& error)
{
return FilePtr::wrap_new(g_file_get_child_for_display_name(nc_gobj(), display_name, error));
return FilePtr::wrap_new(g_file_get_child_for_display_name(nc_gobj(), display_name, &error));
}
bool File::has_prefix(File prefix)
@ -124,6 +124,41 @@ gstr File::get_uri_scheme()
return gstr::wrap_new(g_file_get_uri_scheme(nc_gobj()));
}
g::FileInputStreamPtr File::read(GCancellable* cancellable, gerrp& error)
{
return wrap_new (g_file_read(gobj(), cancellable, &error));
}
g::FileOutputStreamPtr File::append_to(GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
{
return wrap_new (g_file_append_to(gobj(), flags, cancellable, &error));
}
g::FileOutputStreamPtr File::create(GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
{
return wrap_new (g_file_create(gobj(), flags, cancellable, &error));
}
g::FileOutputStreamPtr File::replace(const char* etag, gboolean make_backup, GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
{
return wrap_new (g_file_replace(gobj(), etag, make_backup, flags, cancellable, &error));
}
g::FileIOStreamPtr File::open_readwrite(GCancellable* cancellable, gerrp& error)
{
return wrap_new (g_file_open_readwrite(gobj(), cancellable, &error));
}
g::FileIOStreamPtr File::create_readwrite(GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
{
return wrap_new (g_file_create_readwrite(gobj(), flags, cancellable, &error));
}
g::FileIOStreamPtr File::replace_readwrite(const char* etag, gboolean make_backup, GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
{
return wrap_new (g_file_replace_readwrite(gobj(), etag, make_backup, flags, cancellable, &error));
}
bool File::query_exists(GCancellable* cancellable)
{
return g_file_query_exists(nc_gobj(), cancellable);
@ -134,67 +169,163 @@ GFileType File::query_file_type(GFileQueryInfoFlags flags, GCancellable* cancell
return g_file_query_file_type(nc_gobj(), flags, cancellable);
}
GFileInfo* File::query_info(const char *attributes, GFileQueryInfoFlags flags, GCancellable* cancellable, GError** error)
FileInfoPtr File::query_info(const char *attributes, GFileQueryInfoFlags flags, GCancellable* cancellable, gerrp& error)
{
return g_file_query_info(nc_gobj(), attributes, flags, cancellable, error);
return wrap_new(g_file_query_info(nc_gobj(), attributes, flags, cancellable, &error));
}
GFileInfo* File::query_filesystem_info(const char *attributes, GCancellable* cancellable, GError** error)
FileInfoPtr File::query_filesystem_info(const char *attributes, GCancellable* cancellable, gerrp& error)
{
return g_file_query_filesystem_info(nc_gobj(), attributes, cancellable, error);
return wrap_new(g_file_query_filesystem_info(nc_gobj(), attributes, cancellable, &error));
}
GFileEnumerator* File::enumerate_children(const char *attributes, GFileQueryInfoFlags flags, GCancellable* cancellable, GError** error)
GFileEnumerator* File::enumerate_children(const char *attributes, GFileQueryInfoFlags flags, GCancellable* cancellable, gerrp& error)
{
return g_file_enumerate_children(nc_gobj(), attributes, flags, cancellable, error);
return g_file_enumerate_children(nc_gobj(), attributes, flags, cancellable, &error);
}
FilePtr File::set_display_name(const char* display_name, GCancellable* cancellable, GError** error)
FilePtr File::set_display_name(const char* display_name, GCancellable* cancellable, gerrp& error)
{
return FilePtr::wrap_new(g_file_set_display_name(nc_gobj(), display_name, cancellable, error));
return FilePtr::wrap_new(g_file_set_display_name(nc_gobj(), display_name, cancellable, &error));
}
bool File::delete_(GCancellable* cancellable, GError** error)
bool File::delete_(GCancellable* cancellable, gerrp& error)
{
return g_file_delete(nc_gobj(), cancellable, error);
return g_file_delete(nc_gobj(), cancellable, &error);
}
bool File::trash(GCancellable* cancellable, GError** error)
bool File::trash(GCancellable* cancellable, gerrp& error)
{
return g_file_trash(nc_gobj(), cancellable, error);
return g_file_trash(nc_gobj(), cancellable, &error);
}
bool File::copy(File destination, GFileCopyFlags flags, GCancellable* cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, GError** error)
bool File::copy(File destination, GFileCopyFlags flags, GCancellable* cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, gerrp& error)
{
return g_file_copy(nc_gobj(), destination.gobj(), flags, cancellable, progress_callback, progress_callback_data, error);
return g_file_copy(nc_gobj(), destination.gobj(), flags, cancellable, progress_callback, progress_callback_data, &error);
}
bool File::move(File destination, GFileCopyFlags flags, GCancellable* cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, GError** error)
bool File::move(File destination, GFileCopyFlags flags, GCancellable* cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, gerrp& error)
{
return g_file_move(nc_gobj(), destination.gobj(), flags, cancellable, progress_callback, progress_callback_data, error);
return g_file_move(nc_gobj(), destination.gobj(), flags, cancellable, progress_callback, progress_callback_data, &error);
}
bool File::make_directory(GCancellable* cancellable, GError** error)
bool File::make_directory(GCancellable* cancellable, gerrp& error)
{
return g_file_make_directory(nc_gobj(), cancellable, error);
return g_file_make_directory(nc_gobj(), cancellable, &error);
}
bool File::make_directory_with_parents(GCancellable* cancellable, GError** error)
bool File::make_directory_with_parents(GCancellable* cancellable, gerrp& error)
{
return g_file_make_directory_with_parents(nc_gobj(), cancellable, error);
return g_file_make_directory_with_parents(nc_gobj(), cancellable, &error);
}
bool File::make_symbolic_link(const char *symlink_value, GCancellable* cancellable, GError** error)
bool File::make_symbolic_link(const char *symlink_value, GCancellable* cancellable, gerrp& error)
{
return g_file_make_symbolic_link(nc_gobj(), symlink_value, cancellable, error);
return g_file_make_symbolic_link(nc_gobj(), symlink_value, cancellable, &error);
}
bool File::load_contents(GCancellable* cancellable, char** contents, gsize* length, char** etag_out, GError** error)
bool File::load_contents(GCancellable* cancellable, char** contents, gsize* length, char** etag_out, gerrp& error)
{
return g_file_load_contents(nc_gobj(), cancellable, contents, length, etag_out, error);
return g_file_load_contents(nc_gobj(), cancellable, contents, length, etag_out, &error);
}
bool File::replace_contents(const char* contents, gsize length, const char* etag, gboolean make_backup, GFileCreateFlags flags, char** new_etag, GCancellable* cancellable, GError** error)
bool File::replace_contents(const char* contents, gsize length, const char* etag, gboolean make_backup, GFileCreateFlags flags, char** new_etag, GCancellable* cancellable, gerrp& error)
{
return g_file_replace_contents(nc_gobj(), contents, length, etag, make_backup, flags, new_etag, cancellable, error);
return g_file_replace_contents(nc_gobj(), contents, length, etag, make_backup, flags, new_etag, cancellable, &error);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// GOutputStream
//
gssize OutputStream::write(const void* buffer, gsize count, GCancellable* cancellable, gerrp& error)
{
return g_output_stream_write(gobj(), buffer, count, cancellable, &error);
}
bool OutputStream::write_all(const void* buffer, gsize count, gsize* bytes_written, GCancellable* cancellable, gerrp& error)
{
return g_output_stream_write_all(gobj(), buffer, count, bytes_written, cancellable, &error);
}
gssize OutputStream::splice(g::InputStream source, GOutputStreamSpliceFlags flags, GCancellable* cancellable, gerrp& error)
{
return g_output_stream_splice(gobj(), source.gobj(), flags, cancellable, &error);
}
bool OutputStream::flush(GCancellable* cancellable, gerrp& error)
{
return g_output_stream_flush(gobj(), cancellable, &error);
}
bool OutputStream::close(GCancellable* cancellable, gerrp& error)
{
return g_output_stream_close(gobj(), cancellable, &error);
}
void OutputStream::write_async(const void* buffer, gsize count, int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
{
g_output_stream_write_async(gobj(), buffer, count, io_priority, cancellable, callback, user_data);
}
gssize OutputStream::write_finish(GAsyncResult* result, gerrp& error)
{
return g_output_stream_write_finish(gobj(), result, &error);
}
void OutputStream::splice_async(g::InputStream source, GOutputStreamSpliceFlags flags, int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
{
g_output_stream_splice_async(gobj(), source.gobj(), flags, io_priority, cancellable, callback, user_data);
}
gssize OutputStream::splice_finish(GAsyncResult* result, gerrp& error)
{
return g_output_stream_splice_finish(gobj(), result, &error);
}
void OutputStream::flush_async(int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
{
g_output_stream_flush_async(gobj(), io_priority, cancellable, callback, user_data);
}
bool OutputStream::flush_finish(GAsyncResult* result, gerrp& error)
{
return g_output_stream_flush_finish(gobj(), result, &error);
}
void OutputStream::close_async(int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
{
g_output_stream_close_async(gobj(), io_priority, cancellable, callback, user_data);
}
bool OutputStream::close_finish(GAsyncResult* result, gerrp& error)
{
return g_output_stream_close_finish(gobj(), result, &error);
}
bool OutputStream::is_closed()
{
return g_output_stream_is_closed(gobj());
}
bool OutputStream::is_closing()
{
return g_output_stream_is_closing(gobj());
}
bool OutputStream::has_pending()
{
return g_output_stream_has_pending(gobj());
}
bool OutputStream::set_pending(gerrp& error)
{
return g_output_stream_set_pending(gobj(), &error);
}
void OutputStream::clear_pending()
{
g_output_stream_clear_pending(gobj());
}

View File

@ -24,13 +24,30 @@
#include "moocpp/strutils.h"
MOO_DEFINE_GOBJ_TYPE(GFile, GObject, G_TYPE_FILE)
MOO_DEFINE_GOBJ_TYPE(GFileInfo, GObject, G_TYPE_FILE_INFO)
MOO_DEFINE_GOBJ_TYPE(GOutputStream, GObject, G_TYPE_OUTPUT_STREAM)
MOO_DEFINE_GOBJ_TYPE(GFileOutputStream, GOutputStream, G_TYPE_FILE_OUTPUT_STREAM)
MOO_DEFINE_GOBJ_TYPE(GInputStream, GObject, G_TYPE_INPUT_STREAM)
MOO_DEFINE_GOBJ_TYPE(GFileInputStream, GInputStream, G_TYPE_FILE_INPUT_STREAM)
MOO_DEFINE_GOBJ_TYPE(GIOStream, GObject, G_TYPE_IO_STREAM)
MOO_DEFINE_GOBJ_TYPE(GFileIOStream, GIOStream, G_TYPE_FILE_IO_STREAM)
MOO_DECLARE_CUSTOM_GOBJ_TYPE(GFile)
MOO_DECLARE_CUSTOM_GOBJ_TYPE(GOutputStream)
namespace moo {
namespace g {
MOO_GOBJ_TYPEDEFS(File, GFile);
MOO_GOBJ_TYPEDEFS(FileInfo, GFileInfo);
MOO_GOBJ_TYPEDEFS(OutputStream, GOutputStream);
MOO_GOBJ_TYPEDEFS(FileOutputStream, GFileOutputStream);
MOO_GOBJ_TYPEDEFS(InputStream, GInputStream);
MOO_GOBJ_TYPEDEFS(FileInputStream, GFileInputStream);
MOO_GOBJ_TYPEDEFS(IOStream, GIOStream);
MOO_GOBJ_TYPEDEFS(FileIOStream, GFileIOStream);
} // namespace g
@ -56,82 +73,82 @@ public:
bool has_parent (g::File parent);
g::FilePtr get_child (const char* name);
g::FilePtr get_child_for_display_name (const char* display_name,
GError** error);
gerrp& error);
bool has_prefix (g::File prefix);
gstr get_relative_path (g::File descendant);
g::FilePtr resolve_relative_path (const char *relative_path);
bool is_native ();
bool has_uri_scheme (const char *uri_scheme);
gstr get_uri_scheme ();
GFileInputStream* read (GCancellable* cancellable,
GError** error);
GFileOutputStream* append_to (GFileCreateFlags flags,
g::FileInputStreamPtr read (GCancellable* cancellable,
gerrp& error);
g::FileOutputStreamPtr append_to (GFileCreateFlags flags,
GCancellable* cancellable,
GError** error);
GFileOutputStream* create (GFileCreateFlags flags,
gerrp& error);
g::FileOutputStreamPtr create (GFileCreateFlags flags,
GCancellable* cancellable,
GError** error);
GFileOutputStream* replace (const char *etag,
gerrp& error);
g::FileOutputStreamPtr replace (const char *etag,
gboolean make_backup,
GFileCreateFlags flags,
GCancellable* cancellable,
GError** error);
GFileIOStream* open_readwrite (GCancellable* cancellable,
GError** error);
GFileIOStream* create_readwrite (GFileCreateFlags flags,
gerrp& error);
g::FileIOStreamPtr open_readwrite (GCancellable* cancellable,
gerrp& error);
g::FileIOStreamPtr create_readwrite (GFileCreateFlags flags,
GCancellable* cancellable,
GError** error);
GFileIOStream* replace_readwrite (const char *etag,
gerrp& error);
g::FileIOStreamPtr replace_readwrite (const char *etag,
gboolean make_backup,
GFileCreateFlags flags,
GCancellable* cancellable,
GError** error);
gerrp& error);
bool query_exists (GCancellable* cancellable);
GFileType query_file_type (GFileQueryInfoFlags flags,
GCancellable* cancellable);
GFileInfo* query_info (const char *attributes,
g::FileInfoPtr query_info (const char *attributes,
GFileQueryInfoFlags flags,
GCancellable* cancellable,
GError** error);
GFileInfo* query_filesystem_info (const char *attributes,
gerrp& error);
g::FileInfoPtr query_filesystem_info (const char *attributes,
GCancellable* cancellable,
GError** error);
gerrp& error);
GFileEnumerator* enumerate_children (const char *attributes,
GFileQueryInfoFlags flags,
GCancellable* cancellable,
GError** error);
gerrp& error);
g::FilePtr set_display_name (const char* display_name,
GCancellable* cancellable,
GError** error);
gerrp& error);
bool delete_ (GCancellable* cancellable,
GError** error);
gerrp& error);
bool trash (GCancellable* cancellable,
GError** error);
gerrp& error);
bool copy (g::File destination,
GFileCopyFlags flags,
GCancellable* cancellable,
GFileProgressCallback progress_callback,
gpointer progress_callback_data,
GError** error);
gerrp& error);
bool move (g::File destination,
GFileCopyFlags flags,
GCancellable* cancellable,
GFileProgressCallback progress_callback,
gpointer progress_callback_data,
GError** error);
gerrp& error);
bool make_directory (GCancellable* cancellable,
GError** error);
gerrp& error);
bool make_directory_with_parents (GCancellable* cancellable,
GError** error);
gerrp& error);
bool make_symbolic_link (const char *symlink_value,
GCancellable* cancellable,
GError** error);
gerrp& error);
bool load_contents (GCancellable* cancellable,
char** contents,
gsize* length,
char** etag_out,
GError** error);
gerrp& error);
bool replace_contents (const char* contents,
gsize length,
const char* etag,
@ -139,11 +156,73 @@ public:
GFileCreateFlags flags,
char** new_etag,
GCancellable* cancellable,
GError** error);
gerrp& error);
};
template<>
class gobj_ref<GOutputStream> : public gobj_ref_parent<GOutputStream>
{
public:
MOO_DEFINE_GOBJREF_METHODS(GOutputStream)
gssize write (const void *buffer,
gsize count,
GCancellable *cancellable,
gerrp& error);
bool write_all (const void *buffer,
gsize count,
gsize *bytes_written,
GCancellable *cancellable,
gerrp& error);
gssize splice (g::InputStream source,
GOutputStreamSpliceFlags flags,
GCancellable *cancellable,
gerrp& error);
bool flush (GCancellable *cancellable,
gerrp& error);
bool close (GCancellable *cancellable,
gerrp& error);
void write_async (const void *buffer,
gsize count,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gssize write_finish (GAsyncResult *result,
gerrp& error);
void splice_async (g::InputStream source,
GOutputStreamSpliceFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gssize splice_finish (GAsyncResult *result,
gerrp& error);
void flush_async (int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
bool flush_finish (GAsyncResult *result,
gerrp& error);
void close_async (int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
bool close_finish (GAsyncResult *result,
gerrp& error);
bool is_closed ();
bool is_closing ();
bool has_pending ();
bool set_pending (gerrp& error);
void clear_pending ();
};
} // namespace moo
MOO_REGISTER_CUSTOM_GOBJ_TYPE(GFile)
MOO_REGISTER_CUSTOM_GOBJ_TYPE(GOutputStream)
#endif // __cplusplus

View File

@ -20,6 +20,7 @@
#include <glib-object.h>
#include <mooglib/moo-glib.h>
#include "moocpp/gobjptr.h"
#include "moocpp/gobjectutils.h"
#include <stdarg.h>
@ -27,7 +28,7 @@
using CppObject = ::moo::gobj_ref<CObject>; \
using CppObject##Ptr = ::moo::gobj_ptr<CObject>; \
using CppObject##RawPtr = ::moo::gobj_raw_ptr<CObject>; \
using Const##CppObject##Ptr = ::moo::gobj_raw_ptr<const CObject>; \
#define MOO_DECLARE_CUSTOM_GOBJ_TYPE(CObject) \
namespace moo { \
@ -39,6 +40,13 @@ template<> class gobj_ref<CObject>; \
"gobj_ref must be bit-compatible with a raw pointer, " \
"otherwise operator& will break"); \
MOO_DEFINE_FLAGS(GSignalFlags);
MOO_DEFINE_FLAGS(GConnectFlags);
MOO_DEFINE_FLAGS(GSpawnFlags);
MOO_DEFINE_FLAGS(GLogLevelFlags);
MOO_DEFINE_FLAGS(GRegexCompileFlags);
MOO_DEFINE_FLAGS(GIOCondition);
namespace moo {
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -35,7 +35,7 @@ void test()
{
gobj_ptr<GtkObject> p;
gobj_ref<GtkObject>& r = *p;
gobj_ref<GtkObject> r = *p;
GtkObject* o1 = r.gobj();
GtkObject* o2 = p->gobj();
g_assert(o1 == o2);
@ -51,7 +51,7 @@ void test()
{
gobj_ptr<GtkWidget> p = wrap_new(gtk_widget_new(0, "blah", nullptr, nullptr));
gobj_ref<GtkWidget>& r = *p;
gobj_ref<GtkWidget> r = *p;
GtkWidget* o1 = r.gobj();
GtkWidget* o2 = p->gobj();
g_assert(o1 == o2);

View File

@ -53,4 +53,10 @@ public:
MOO_REGISTER_CUSTOM_GOBJ_TYPE(GtkTextView);
MOO_DEFINE_FLAGS(GdkEventMask);
MOO_DEFINE_FLAGS(GdkModifierType);
MOO_DEFINE_FLAGS(GtkCellRendererState);
MOO_DEFINE_FLAGS(GtkAttachOptions);
MOO_DEFINE_FLAGS(GdkDragAction);
#endif // __cplusplus

View File

@ -102,4 +102,8 @@ protected:
} // namespace moo
void g_signal_emit_valist(const moo::gobj_wrapper_base*, guint, GQuark, va_list) = delete;
void g_signal_emit(const moo::gobj_wrapper_base*, guint, GQuark, ...) = delete;
void g_signal_emit_by_name(const moo::gobj_wrapper_base*, const gchar*, ...) = delete;
#endif // __cplusplus

View File

@ -15,8 +15,14 @@
#pragma once
#ifdef __cplusplus
#include <mooglib/moo-glib.h>
#include <moocpp/memutils.h>
#include <moocpp/utils.h>
#include <algorithm>
#include <utility>
#include <functional>
namespace moo {
@ -100,6 +106,47 @@ bool operator!=(const gstr& s1, const char* s2);
bool operator!=(const char* s1, const gstr& s2);
bool operator!=(const gstr& s1, const gstr& s2);
class gerrp
{
public:
explicit gerrp(GError** errp = nullptr) : m_errp(errp ? errp : &m_local), m_local(nullptr) {}
~gerrp()
{
if (m_errp != &m_local)
clear();
}
operator bool() const { return (*m_errp) != nullptr; }
bool operator!() const { return (*m_errp) == nullptr; }
GError* get() const { return (*m_errp); }
GError* operator->() const { return (*m_errp); }
GError** operator&() { return m_errp; }
//void propagate(GError** dest) { g_propagate_error(dest, m_err); m_err = nullptr; }
void clear() { if (*m_errp) g_error_free(*m_errp); *m_errp = nullptr; m_local = nullptr; }
MOO_DISABLE_COPY_OPS(gerrp);
gerrp(gerrp&& other) = delete;
gerrp& operator=(gerrp&& other)
{
clear();
g_propagate_error (m_errp, other.get());
other.m_errp = &other.m_local;
other.m_local = nullptr;
return *this;
}
private:
GError** m_errp;
GError* m_local;
};
} // namespace moo
namespace std {
@ -110,4 +157,6 @@ struct hash<moo::gstr>
const size_t operator()(const moo::gstr& s) const;
};
}
} // namespace std
#endif // __cplusplus

View File

@ -20,7 +20,6 @@
#include <list>
#include <vector>
#include <functional>
#include <mooutils/mooutils-misc.h>
#include <mooglib/moo-glib.h>
namespace moo {

View File

@ -53,32 +53,32 @@ MOO_DEFINE_QUARK (MooEditFileErrorQuark, _moo_edit_file_error_quark)
static GSList *UNTITLED = NULL;
static GHashTable *UNTITLED_NO = NULL;
static void block_buffer_signals (Edit& edit);
static void unblock_buffer_signals (Edit& edit);
static void check_file_status (Edit& edit);
static void file_modified_on_disk (Edit& edit);
static void file_deleted (Edit& edit);
static void add_status (Edit& edit,
static void block_buffer_signals (Edit edit);
static void unblock_buffer_signals (Edit edit);
static void check_file_status (Edit edit);
static void file_modified_on_disk (Edit edit);
static void file_deleted (Edit edit);
static void add_status (Edit edit,
MooEditStatus s);
static void moo_edit_load_text (Edit& edit,
const g::File& file,
static void moo_edit_load_text (Edit edit,
g::File file,
const char* encoding,
const char* text);
static bool moo_edit_reload_local (Edit& edit,
static bool moo_edit_reload_local (Edit edit,
const char* encoding,
GError** error);
static bool moo_edit_save_local (Edit& edit,
const g::File& file,
gerrp& error);
static bool moo_edit_save_local (Edit edit,
g::File file,
const char* encoding,
MooEditSaveFlags flags,
GError** error);
static bool moo_edit_save_copy_local (Edit& edit,
const g::File& file,
gerrp& error);
static bool moo_edit_save_copy_local (Edit edit,
g::File file,
const char* encoding,
MooEditSaveFlags flags,
GError** error);
static void _moo_edit_start_file_watch (Edit& edit);
gerrp& error);
static void _moo_edit_start_file_watch (Edit edit);
static char *moo_convert_file_data_to_utf8 (const char *data,
gsize len,
@ -91,11 +91,11 @@ static bool encoding_needs_bom_save (const char *enc,
gsize *bom_len);
static bool encoding_is_utf8 (const char *encoding);
static bool check_regular (const g::File& file,
GError** error);
static bool check_regular (g::File file,
gerrp& error);
bool _moo_is_file_error_cancelled(GError *error)
bool _moo_is_file_error_cancelled(const gerrp& error)
{
return error && error->domain == MOO_EDIT_FILE_ERROR &&
error->code == MOO_EDIT_FILE_ERROR_CANCELLED;
@ -122,7 +122,7 @@ normalize_encoding (const gstr& encoding,
}
bool _moo_edit_file_is_new(const g::File& file)
bool _moo_edit_file_is_new(g::File file)
{
gstr filename = file.get_path();
g_return_val_if_fail(!filename.empty(), FALSE);
@ -131,10 +131,10 @@ bool _moo_edit_file_is_new(const g::File& file)
static gboolean
load_file_contents (const g::File& file,
char** data,
gsize* data_len,
GError** error)
load_file_contents (g::File file,
char** data,
gsize* data_len,
gerrp& error)
{
if (!check_regular (file, error))
return FALSE;
@ -143,19 +143,19 @@ load_file_contents (const g::File& file,
if (path.empty())
{
g_set_error (error, MOO_EDIT_FILE_ERROR,
g_set_error (&error, MOO_EDIT_FILE_ERROR,
MOO_EDIT_FILE_ERROR_NOT_IMPLEMENTED,
"Loading remote files is not implemented");
return FALSE;
}
return g_file_get_contents (path, data, data_len, error);
return g_file_get_contents (path, data, data_len, &error);
}
static char *
convert_file_data_to_utf8_with_prompt (const char* data,
gsize data_len,
const g::File& file,
g::File file,
const char* encoding,
const char* cached_encoding,
/*out*/ gstr& used_encoding)
@ -200,14 +200,13 @@ convert_file_data_to_utf8_with_prompt (const char* data,
}
bool
_moo_edit_load_file (Edit& edit,
const g::File& file,
const gstr& init_encoding,
const gstr& init_cached_encoding,
GError** error)
_moo_edit_load_file (Edit edit,
g::File file,
const gstr& init_encoding,
const gstr& init_cached_encoding,
gerrp& error)
{
bool result = false;
GError *error_here = NULL;
char *data = NULL;
gsize data_len = 0;
char *data_utf8 = NULL;
@ -220,16 +219,14 @@ _moo_edit_load_file (Edit& edit,
if (!init_cached_encoding.empty())
cached_encoding = normalize_encoding(init_cached_encoding, false);
if (!load_file_contents(file, &data, &data_len, &error_here))
if (!load_file_contents(file, &data, &data_len, error))
goto done;
data_utf8 = convert_file_data_to_utf8_with_prompt(data, data_len, file, encoding, cached_encoding, /*out*/ used_encoding);
if (data_utf8 == NULL)
{
error_here = g_error_new(MOO_EDIT_FILE_ERROR,
MOO_EDIT_FILE_ERROR_CANCELLED,
"Cancelled");
g_set_error (&error, MOO_EDIT_FILE_ERROR, MOO_EDIT_FILE_ERROR_CANCELLED, "Cancelled");
goto done;
}
@ -240,9 +237,6 @@ done:
if (!result)
edit._stop_file_watch();
if (error_here)
g_propagate_error(error, error_here);
g_free(data_utf8);
g_free(data);
return result;
@ -252,41 +246,28 @@ done:
bool
_moo_edit_reload_file(Edit edit,
const char* encoding,
GError** error)
gerrp& error)
{
GError *error_here = NULL;
bool result = moo_edit_reload_local(edit, encoding, &error_here);
if (error_here)
g_propagate_error(error, error_here);
return result;
return moo_edit_reload_local(edit, encoding, error);
}
bool _moo_edit_save_file(Edit& edit,
const g::File& file,
bool _moo_edit_save_file(Edit edit,
g::File file,
const char* encoding,
MooEditSaveFlags flags,
GError** error)
gerrp& error)
{
gstr encoding_copy = gstr::make_copy(normalize_encoding(encoding, true));
GError *error_here = NULL;
bool result = moo_edit_save_local(edit, file, encoding_copy, flags, &error_here);
if (error_here)
g_propagate_error(error, error_here);
return result;
return moo_edit_save_local(edit, file, encoding_copy, flags, error);
}
bool _moo_edit_save_file_copy(Edit edit,
const g::File& file,
g::File file,
const char* encoding,
MooEditSaveFlags flags,
GError** error)
gerrp& error)
{
gstr encoding_copy = gstr::make_copy(normalize_encoding(encoding, true));
return moo_edit_save_copy_local(edit, file, encoding_copy, flags, error);
@ -294,14 +275,13 @@ bool _moo_edit_save_file_copy(Edit edit,
static void
set_encoding_error (GError **error)
set_encoding_error (gerrp& error)
{
GError *tmp_error = NULL;
gerrp tmp_error;
g_set_error (&tmp_error, MOO_EDIT_FILE_ERROR,
MOO_EDIT_FILE_ERROR_ENCODING,
"%s", *error ? (*error)->message : "ERROR");
g_clear_error (error);
g_propagate_error (error, tmp_error);
"%s", error ? error->message : "ERROR");
error = std::move(tmp_error);
}
@ -349,7 +329,7 @@ moo_edit_set_line_end_type (MooEdit *edit,
/* File loading
*/
static void do_load_text(Edit& edit,
static void do_load_text(Edit edit,
const char* text);
static std::list<gstr>
@ -395,37 +375,33 @@ get_encodings (void)
}
static bool check_regular (const g::File& file,
GError** error)
static bool check_regular (g::File file, gerrp& error)
{
GFileInfo *info;
GFileType type;
gboolean retval = TRUE;
if (!file.is_native())
return TRUE;
return true;
if (!(info = file.query_info(G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, nullptr, nullptr)))
return TRUE;
gerrp ignored;
g::FileInfoPtr info;
if (!(info = file.query_info(G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, nullptr, ignored)))
return true;
type = g_file_info_get_file_type (info);
GFileType type = g_file_info_get_file_type (info.gobj());
if (type != G_FILE_TYPE_REGULAR && type != G_FILE_TYPE_UNKNOWN)
{
g_set_error (error, MOO_EDIT_FILE_ERROR,
g_set_error (&error, MOO_EDIT_FILE_ERROR,
MOO_EDIT_FILE_ERROR_FAILED,
"%s", D_("Not a regular file", "glib20"));
retval = FALSE;
return false;
}
g_object_unref (info);
return retval;
return true;
}
static void
moo_edit_load_text (Edit& edit,
const g::File& file,
const char* encoding,
const char* text)
moo_edit_load_text (Edit edit,
g::File file,
const char* encoding,
const char* text)
{
MooEditPrivate& priv = edit.get_priv();
@ -473,7 +449,7 @@ moo_edit_load_text (Edit& edit,
}
static void do_load_text(Edit& edit, const char* text)
static void do_load_text(Edit edit, const char* text)
{
MooLineEndType le = MOO_LE_NONE;
@ -550,9 +526,9 @@ static void do_load_text(Edit& edit, const char* text)
/* XXX */
static bool moo_edit_reload_local(Edit& edit,
static bool moo_edit_reload_local(Edit edit,
const char* encoding,
GError** error)
gerrp& error)
{
g::FilePtr file = wrap_new(moo_edit_get_file(&edit));
moo_return_error_if_fail(file != nullptr);
@ -568,7 +544,7 @@ static bool moo_edit_reload_local(Edit& edit,
priv.status = (MooEditStatus) 0;
moo_edit_set_modified(&edit, false);
_moo_edit_start_file_watch(edit);
g_clear_error(error);
g_clear_error (&error);
}
return result;
@ -614,7 +590,7 @@ get_contents_with_fixed_line_end (GtkTextBuffer *buffer, const char *le, gsize l
return g_string_free (contents, FALSE);
}
static gstr get_contents(MooEdit& edit)
static gstr get_contents(MooEdit edit)
{
const char *le = "\n";
gsize le_len = 1;
@ -642,13 +618,13 @@ static gstr get_contents(MooEdit& edit)
return gstr::wrap_new(get_contents_with_fixed_line_end(buffer, le, le_len));
}
static bool do_write(const g::File& file,
static bool do_write(g::File file,
const char* data1,
gsize len1,
const char* data2,
gsize len2,
MooEditSaveFlags flags,
GError** error)
gerrp& error)
{
MooFileWriter *writer;
MooFileWriterFlags writer_flags;
@ -656,7 +632,7 @@ static bool do_write(const g::File& file,
writer_flags = (flags & MOO_EDIT_SAVE_BACKUP) ? MOO_FILE_WRITER_SAVE_BACKUP : (MooFileWriterFlags) 0;
if ((writer = moo_file_writer_new_for_file (file.nc_gobj(), writer_flags, error)))
if ((writer = moo_file_writer_new_for_file (file, writer_flags, error)))
{
success = TRUE;
if (success && len1 > 0)
@ -671,15 +647,14 @@ static bool do_write(const g::File& file,
}
static bool
do_save_local(Edit& edit,
const g::File& file,
do_save_local(Edit edit,
g::File file,
const char* encoding,
MooEditSaveFlags flags,
GError** error)
gerrp& error)
{
const char *to_save;
gsize to_save_size;
GError *encoding_error = NULL;
const char *enc_no_bom = NULL;
const char *bom = NULL;
gsize bom_len = 0;
@ -697,6 +672,7 @@ do_save_local(Edit& edit,
{
gsize bytes_read;
gsize bytes_written;
gerrp encoding_error;
gstr encoded = gstr::wrap_new(g_convert(utf8_contents, -1,
encoding, "UTF-8",
&bytes_read, &bytes_written,
@ -709,8 +685,8 @@ do_save_local(Edit& edit,
}
else
{
g_propagate_error(error, encoding_error);
set_encoding_error(error);
error = std::move (encoding_error);
set_encoding_error (error);
return false;
}
}
@ -728,11 +704,11 @@ do_save_local(Edit& edit,
static bool
moo_edit_save_local(Edit& edit,
const g::File& file,
moo_edit_save_local(Edit edit,
g::File file,
const char* encoding,
MooEditSaveFlags flags,
GError** error)
gerrp& error)
{
if (!do_save_local(edit, file, encoding, flags, error))
return FALSE;
@ -745,11 +721,11 @@ moo_edit_save_local(Edit& edit,
}
static bool moo_edit_save_copy_local(Edit& edit,
const g::File& file,
static bool moo_edit_save_copy_local(Edit edit,
g::File file,
const char* encoding,
MooEditSaveFlags flags,
GError** error)
gerrp& error)
{
return do_save_local(edit, file, encoding, flags, error);
}
@ -760,14 +736,14 @@ static bool moo_edit_save_copy_local(Edit& edit,
*/
static void
block_buffer_signals(Edit& edit)
block_buffer_signals(Edit edit)
{
g_signal_handler_block (moo_edit_get_buffer (&edit), edit.get_priv().modified_changed_handler_id);
}
static void
unblock_buffer_signals(Edit& edit)
unblock_buffer_signals(Edit edit)
{
g_signal_handler_unblock(moo_edit_get_buffer(&edit), edit.get_priv().modified_changed_handler_id);
}
@ -811,7 +787,7 @@ file_watch_callback(G_GNUC_UNUSED MooFileWatch& watch,
}
static void _moo_edit_start_file_watch(Edit& edit)
static void _moo_edit_start_file_watch(Edit edit)
{
auto& priv = edit.get_priv();
@ -853,7 +829,7 @@ void Edit::_stop_file_watch()
}
static void check_file_status(Edit& edit)
static void check_file_status(Edit edit)
{
auto& priv = edit.get_priv();
@ -867,7 +843,7 @@ static void check_file_status(Edit& edit)
}
static void file_modified_on_disk(Edit& edit)
static void file_modified_on_disk(Edit edit)
{
auto& priv = edit.get_priv();
@ -887,7 +863,7 @@ static void file_modified_on_disk(Edit& edit)
}
static void file_deleted (Edit& edit)
static void file_deleted (Edit edit)
{
auto& priv = edit.get_priv();
@ -907,14 +883,14 @@ static void file_deleted (Edit& edit)
}
static void add_status(Edit& edit, MooEditStatus s)
static void add_status(Edit edit, MooEditStatus s)
{
edit.get_priv().status |= s;
edit.signal_emit_by_name("doc-status-changed", NULL);
}
void Edit::_remove_untitled(const Edit& doc)
void Edit::_remove_untitled(Edit doc)
{
gpointer n = g_hash_table_lookup (UNTITLED_NO, &doc);
@ -926,7 +902,7 @@ void Edit::_remove_untitled(const Edit& doc)
}
static int add_untitled(Edit& edit)
static int add_untitled(Edit edit)
{
int n;
@ -948,7 +924,7 @@ static int add_untitled(Edit& edit)
}
static gstr moo_file_get_display_basename(const g::File& file)
static gstr moo_file_get_display_basename(g::File file)
{
const char *slash;
@ -984,7 +960,7 @@ static gstr normalize_filename_for_comparison(const char *filename)
#endif
}
gstr Edit::_get_normalized_name(const g::File& file)
gstr Edit::_get_normalized_name(g::File file)
{
gstr tmp = file.get_path();
@ -1001,8 +977,8 @@ gstr Edit::_get_normalized_name(const g::File& file)
}
}
void Edit::_set_file(gobj_raw_ptr<const GFile> file,
const char* encoding)
void Edit::_set_file(g::FileRawPtr file,
const char* encoding)
{
if (!UNTITLED_NO)
UNTITLED_NO = g_hash_table_new(g_direct_hash, g_direct_equal);

View File

@ -23,6 +23,7 @@
#include <gio/gio.h>
#include "moocpp/utils.h"
#include "moocpp/strutils.h"
#include "mooutils/mooutils-misc.h"
G_BEGIN_DECLS
const char *_moo_get_default_encodings (void);
@ -46,24 +47,24 @@ MOO_DEFINE_FLAGS(MooEditSaveFlags)
GQuark _moo_edit_file_error_quark (void) G_GNUC_CONST;
bool _moo_is_file_error_cancelled (GError* error);
bool _moo_is_file_error_cancelled (const moo::gerrp& error);
bool _moo_edit_file_is_new (const moo::g::File& file);
bool _moo_edit_load_file (Edit& edit,
const moo::g::File& file,
bool _moo_edit_file_is_new (moo::g::File file);
bool _moo_edit_load_file (Edit edit,
moo::g::File file,
const moo::gstr& init_encoding,
const moo::gstr& init_cached_encoding,
GError** error);
moo::gerrp& error);
bool _moo_edit_reload_file (Edit edit,
const char* encoding,
GError** error);
bool _moo_edit_save_file (Edit& edit,
const moo::g::File& floc,
moo::gerrp& error);
bool _moo_edit_save_file (Edit edit,
moo::g::File floc,
const char* encoding,
MooEditSaveFlags flags,
GError** error);
moo::gerrp& error);
bool _moo_edit_save_file_copy (Edit edit,
const moo::g::File& file,
moo::g::File file,
const char* encoding,
MooEditSaveFlags flags,
GError** error);
moo::gerrp& error);

View File

@ -56,9 +56,9 @@ public:
void _closed ();
void _set_file (g::ConstFilePtr file,
void _set_file (g::FileRawPtr file,
const char* encoding);
void _remove_untitled (const Edit& doc);
void _remove_untitled (Edit doc);
void _ensure_newline ();
@ -70,7 +70,7 @@ public:
MooActionCollection& _get_actions ();
static moo::gstr _get_normalized_name (const g::File& file);
static moo::gstr _get_normalized_name (g::File file);
const moo::gstr& _get_normalized_name () const;
MooEditPrivate& get_priv () { return *gobj()->priv; }

View File

@ -55,7 +55,7 @@
#include "mooutils/mooatom.h"
#include "mooutils/moocompat.h"
#include "mooedit/mooeditprogress-gxml.h"
#include "moocpp/gobjectutils.h"
#include "moocpp/gobjtypes.h"
#include <string.h>
#include <stdlib.h>

View File

@ -412,7 +412,7 @@ _moo_edit_save_multiple_changes_dialog (MooEditArray *docs,
/* Error dialogs
*/
void _moo_edit_save_error_dialog(Edit& doc, const g::File& file, GError *error)
void _moo_edit_save_error_dialog(Edit& doc, g::File file, GError *error)
{
gstr filename = moo_file_get_display_name (file);
gstr msg = gstr::wrap_new(g_strdup_printf(_("Could not save file\n%s"), filename));
@ -460,9 +460,9 @@ moo_edit_question_dialog (MooEdit *doc,
return res == GTK_RESPONSE_YES;
}
bool _moo_edit_save_error_enc_dialog(Edit& doc,
const g::File& file,
const char* encoding)
bool _moo_edit_save_error_enc_dialog(Edit& doc,
g::File file,
const char* encoding)
{
g_return_val_if_fail (encoding != NULL, FALSE);
@ -479,9 +479,9 @@ bool _moo_edit_save_error_enc_dialog(Edit& doc,
MooEditTryEncodingResponse
_moo_edit_try_encoding_dialog (const g::File& file,
const char* encoding,
/*out*/ gstr& new_encoding)
_moo_edit_try_encoding_dialog (g::File file,
const char* encoding,
/*out*/ gstr& new_encoding)
{
MooEditWindow *window;
GtkWidget *dialog;
@ -548,28 +548,26 @@ _moo_edit_try_encoding_dialog (const g::File& file,
void
_moo_edit_open_error_dialog (GtkWidget *widget,
GFile *file,
GError *error)
_moo_edit_open_error_dialog (GtkWidget* widget,
g::File* file,
GError* error)
{
char *filename, *msg = NULL;
char *secondary;
gstr msg;
gstr secondary;
filename = moo_file_get_display_name (file);
g_warn_if_fail (file != nullptr);
gstr filename = file ? moo_file_get_display_name (*file) : gstr ();
if (filename)
if (!filename.empty())
/* Could not open file foo.txt */
msg = g_strdup_printf (_("Could not open file\n%s"), filename);
msg.take (g_strdup_printf (_("Could not open file\n%s"), filename.get()));
else
msg = g_strdup (_("Could not open file"));
msg.literal (_("Could not open file"));
secondary = error ? g_strdup (error->message) : NULL;
if (error)
secondary.borrow (error->message);
moo_error_dialog (msg, secondary, widget);
g_free (msg);
g_free (secondary);
g_free (filename);
}

View File

@ -38,9 +38,6 @@ MooSaveChangesResponse _moo_edit_save_multiple_changes_dialog (MooEdit
gboolean _moo_edit_reload_modified_dialog (MooEdit *doc);
gboolean _moo_edit_overwrite_modified_dialog (MooEdit *doc);
void _moo_edit_open_error_dialog (GtkWidget *widget,
GFile *file,
GError *error);
void _moo_edit_reload_error_dialog (MooEdit *doc,
GError *error);
@ -59,14 +56,17 @@ G_END_DECLS
#include <moocpp/strutils.h>
MooEditTryEncodingResponse _moo_edit_try_encoding_dialog (const moo::g::File& file,
MooEditTryEncodingResponse _moo_edit_try_encoding_dialog (moo::g::File file,
const char* encoding,
/*out*/ moo::gstr& new_encoding);
bool _moo_edit_save_error_enc_dialog (Edit& doc,
const moo::g::File& file,
moo::g::File file,
const char* encoding);
void _moo_edit_save_error_dialog (Edit& doc,
const moo::g::File& file,
moo::g::File file,
GError* error);
void _moo_edit_open_error_dialog (GtkWidget* widget,
moo::g::File* file,
GError* error);
#endif // __cplusplus

View File

@ -2,7 +2,7 @@
#include "mooeditfileinfo.h"
#include "moocpp/strutils.h"
#include "moocpp/gobjectutils.h"
#include "moocpp/gobjtypes.h"
using namespace moo;

View File

@ -32,7 +32,7 @@
#include "mooedit/mooedithistoryitem.h"
#include "mooedit/mooedit-ui.h"
#include "mooedit/medit-ui.h"
#include "moocpp/gobjectutils.h"
#include "moocpp/gobjtypes.h"
#include "mooutils/moomenuaction.h"
#include "marshals.h"
#include "mooutils/mooutils-misc.h"
@ -948,13 +948,13 @@ moo_editor_load_file(MooEditor *editor,
GtkWidget *parent,
gboolean silent,
gboolean add_history,
GError **error)
gerrp& error)
{
MooEditView *view = NULL;
gboolean new_doc = FALSE;
gboolean new_object = FALSE;
const char *recent_encoding = NULL;
GError *error_here = NULL;
gerrp error_here;
gboolean success = TRUE;
moo_return_error_if_fail_p(MOO_IS_EDITOR(editor));
@ -1023,7 +1023,7 @@ moo_editor_load_file(MooEditor *editor,
success = _moo_edit_load_file(*doc, *info->file,
gstr::make_borrowed(info->encoding),
gstr::make_borrowed(recent_encoding),
&error_here);
error_here);
}
}
@ -1035,22 +1035,20 @@ moo_editor_load_file(MooEditor *editor,
window = moo_editor_get_active_window (editor);
if (!parent && window)
parent = GTK_WIDGET (window);
_moo_edit_open_error_dialog(parent, info->file.gobj(), error_here);
_moo_edit_open_error_dialog(parent, info->file, error_here.get());
}
g_propagate_error (error, error_here);
error_here = NULL;
error = std::move (error_here);
}
else if (!new_doc && (info->flags & MOO_OPEN_FLAG_RELOAD))
{
success = _moo_edit_reload_file(*doc, info->encoding, &error_here);
success = _moo_edit_reload_file(*doc, info->encoding, error_here);
if (!success)
{
if (!silent && !_moo_is_file_error_cancelled (error_here))
_moo_edit_reload_error_dialog (doc.gobj(), error_here);
g_propagate_error (error, error_here);
error_here = NULL;
_moo_edit_reload_error_dialog (doc.gobj(), error_here.get());
error = std::move (error_here);
}
}
@ -1195,10 +1193,10 @@ moo_editor_load_file(MooEditor *editor,
// }
static MooEditArray *
_moo_editor_open_files (MooEditor *editor,
MooOpenInfoArray *files,
GtkWidget *parent,
GError **error)
_moo_editor_open_files (MooEditor* editor,
MooOpenInfoArray* files,
GtkWidget* parent,
gerrp& error)
{
guint i;
MooEdit *bring_to_front = NULL;
@ -1745,7 +1743,8 @@ load_doc_session (MooEditor *editor,
const char *encoding = moo_markup_get_prop (elm, "encoding");
std::unique_ptr<MooOpenInfo> info(moo_open_info_new_uri(uri, encoding, -1, MOO_OPEN_FLAGS_NONE));
return moo_editor_load_file(editor, info.get(), window, GTK_WIDGET(window), TRUE, FALSE, NULL);
gerrp ignored;
return moo_editor_load_file(editor, info.get(), window, GTK_WIDGET(window), TRUE, FALSE, ignored);
}
static MooMarkupNode *
@ -1975,7 +1974,9 @@ moo_editor_open_files (MooEditor *editor,
moo_return_error_if_fail (MOO_IS_EDITOR (editor));
moo_return_error_if_fail (!moo_open_info_array_is_empty (files));
docs = _moo_editor_open_files (editor, files, parent, error);
gerrp error_here(error);
docs = _moo_editor_open_files (editor, files, parent, error_here);
ret = !moo_edit_array_is_empty (docs);
moo_assert (moo_edit_array_is_empty (docs) ||
@ -2036,7 +2037,8 @@ moo_editor_open_file (MooEditor *editor,
files = moo_open_info_array_new ();
moo_open_info_array_append (files, info);
docs = _moo_editor_open_files (editor, files, parent, error);
gerrp error_here(error);
docs = _moo_editor_open_files (editor, files, parent, error_here);
moo_open_info_array_free (files);
@ -2315,10 +2317,10 @@ gboolean
moo_editor_reload (MooEditor *editor,
MooEdit *doc,
MooReloadInfo *info,
GError **error)
GError **errorp)
{
guint i;
GError *error_here = NULL;
gerrp error(errorp);
MooEditViewArray *views = NULL;
gboolean ret = FALSE;
@ -2326,7 +2328,7 @@ moo_editor_reload (MooEditor *editor,
if (Edit(*doc)._is_busy())
{
g_set_error (error,
g_set_error (&error,
MOO_EDIT_RELOAD_ERROR,
MOO_EDIT_RELOAD_ERROR_BUSY,
"document is busy");
@ -2335,7 +2337,7 @@ moo_editor_reload (MooEditor *editor,
if (moo_edit_is_untitled (doc))
{
g_set_error (error,
g_set_error (&error,
MOO_EDIT_RELOAD_ERROR,
MOO_EDIT_RELOAD_ERROR_UNTITLED,
"document is untitled");
@ -2346,7 +2348,7 @@ moo_editor_reload (MooEditor *editor,
moo_edit_is_modified (doc) &&
!_moo_edit_reload_modified_dialog (doc))
{
g_set_error (error,
g_set_error (&error,
MOO_EDIT_RELOAD_ERROR,
MOO_EDIT_RELOAD_ERROR_CANCELLED,
"cancelled by user");
@ -2375,12 +2377,10 @@ moo_editor_reload (MooEditor *editor,
g_object_set_data (G_OBJECT (view), "moo-reload-cursor-offset", GINT_TO_POINTER (cursor_offset));
}
if (!_moo_edit_reload_file(*doc, info ? (const char*) info->encoding : nullptr, &error_here))
if (!_moo_edit_reload_file(*doc, info ? (const char*) info->encoding : nullptr, error))
{
if (!_moo_is_file_error_cancelled (error_here))
_moo_edit_reload_error_dialog (doc, error_here);
g_propagate_error (error, error_here);
if (!_moo_is_file_error_cancelled (error))
_moo_edit_reload_error_dialog (doc, error.get());
g_object_set_data (G_OBJECT (doc), "moo-scroll-to", NULL);
goto out;
@ -2438,14 +2438,14 @@ moo_editor_will_save (G_GNUC_UNUSED MooEditor *editor,
}
static bool
do_save(MooEditor& editor,
Edit doc,
const g::File& file,
const char* encoding,
GError** error)
do_save(MooEditor& editor,
Edit doc,
g::File file,
const char* encoding,
gerrp& error)
{
int response = MOO_SAVE_RESPONSE_CONTINUE;
GError *error_here = NULL;
gerrp error_here;
gboolean result;
g_signal_emit(&editor, signals[BEFORE_SAVE], 0, doc, file, &response);
@ -2455,7 +2455,7 @@ do_save(MooEditor& editor,
if (response == MOO_SAVE_RESPONSE_CANCEL)
{
g_set_error(error,
g_set_error(&error,
MOO_EDIT_SAVE_ERROR,
MOO_EDIT_SAVE_ERROR_CANCELLED,
"cancelled");
@ -2467,22 +2467,21 @@ do_save(MooEditor& editor,
result = _moo_edit_save_file(doc, file, encoding,
moo_editor_get_save_flags(&editor),
&error_here);
error_here);
if (!result && error_here->domain == MOO_EDIT_FILE_ERROR &&
error_here->code == MOO_EDIT_FILE_ERROR_ENCODING)
{
g_error_free(error_here);
error_here = NULL;
error_here.clear();
if (_moo_edit_save_error_enc_dialog(doc, file, encoding))
{
result = _moo_edit_save_file(doc, file, "UTF-8",
moo_editor_get_save_flags(&editor),
&error_here);
error_here);
}
else
{
g_set_error(error,
g_set_error(&error,
MOO_EDIT_SAVE_ERROR,
MOO_EDIT_SAVE_ERROR_CANCELLED,
"cancelled");
@ -2492,8 +2491,8 @@ do_save(MooEditor& editor,
if (!result)
{
_moo_edit_save_error_dialog(doc, file, error_here);
g_propagate_error(error, error_here);
_moo_edit_save_error_dialog(doc, file, error_here.get());
error = std::move(error_here);
return FALSE;
}
@ -2513,8 +2512,6 @@ moo_editor_save (MooEditor *editor,
MooEdit *doc,
GError **error)
{
gboolean result = FALSE;
moo_return_error_if_fail (MOO_IS_EDITOR (editor));
moo_return_error_if_fail (MOO_IS_EDIT (doc));
@ -2540,14 +2537,11 @@ moo_editor_save (MooEditor *editor,
MOO_EDIT_SAVE_ERROR,
MOO_EDIT_SAVE_ERROR_CANCELLED,
"cancelled by user");
goto out;
return false;
}
result = do_save(*editor, *doc, *file, encoding, error);
/* fall through */
out:
return result;
gerrp error_here(error);
return do_save(*editor, *doc, *file, encoding, error_here);
}
/**
@ -2602,7 +2596,8 @@ moo_editor_save_as (MooEditor *editor,
update_history_item_for_doc(editor, doc, FALSE);
return do_save(*editor, *doc, *info->file, info->encoding, error);
gerrp error_here(error);
return do_save(*editor, *doc, *info->file, info->encoding, error_here);
}
/**
@ -2614,18 +2609,15 @@ moo_editor_save_copy (MooEditor *editor,
MooSaveInfo *info,
GError **error)
{
gboolean retval;
moo_return_error_if_fail (MOO_IS_EDITOR (editor));
moo_return_error_if_fail (MOO_IS_EDIT (doc));
moo_return_error_if_fail (info != nullptr && info->file != nullptr);
retval = _moo_edit_save_file_copy (*doc, *info->file,
!info->encoding.empty() ? info->encoding : moo_edit_get_encoding (doc),
moo_editor_get_save_flags (editor),
error);
return retval;
gerrp error_here(error);
return _moo_edit_save_file_copy (*doc, *info->file,
!info->encoding.empty() ? info->encoding : moo_edit_get_encoding (doc),
moo_editor_get_save_flags (editor),
error_here);
}

View File

@ -24,8 +24,7 @@
#include "mooutils/mooprefs.h"
#include "marshals.h"
#include "mooutils/moo-mime.h"
#include "moocpp/gobjectutils.h"
#include "moocpp/gobjtypes-gio.h"
#include "moocpp/gobjtypes.h"
#include <string.h>
using namespace moo;
@ -371,8 +370,8 @@ file_blacklisted (MooLangMgr* mgr,
MooLang *
moo_lang_mgr_get_lang_for_file (MooLangMgr* mgr,
const g::File& file)
moo_lang_mgr_get_lang_for_file (MooLangMgr* mgr,
g::File file)
{
MooLang *lang = NULL;
const char *mime_type;

View File

@ -43,7 +43,7 @@ MooLang *moo_lang_mgr_get_lang (MooLangMgr* mgr,
const char* lang_id);
#ifdef __cplusplus
MooLang *moo_lang_mgr_get_lang_for_file (MooLangMgr* mgr,
const moo::g::File& file);
moo::g::File file);
#endif // __cplusplus
/* list must be freed, content unref'ed */

View File

@ -17,7 +17,7 @@
#include <gtk/gtk.h>
#include <mooutils/moouixml.h>
#include <moocpp/gobjectutils.h>
#include <moocpp/gobjtypes.h>
G_BEGIN_DECLS

View File

@ -25,7 +25,7 @@
#include "mooutils/mooutils-debug.h"
#include "mooutils/mooaccel.h"
#include "mooutils/moocompat.h"
#include "moocpp/gobjectutils.h"
#include <moocpp/gobjtypes.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

View File

@ -22,7 +22,6 @@
#include "mooutils/mooutils.h"
#include "mooutils/moofilewatch.h"
#include "marshals.h"
#include "moocpp/gobjectutils.h"
#include <gio/gio.h>
#include <stdio.h>
#ifndef __WIN32__

View File

@ -26,7 +26,7 @@
#ifdef __cplusplus
#include "moocpp/grefptr.h"
#include "moocpp/gobjectutils.h"
#include "moocpp/gobjtypes.h"
#include "mooutils/moofilewatch.h"
#endif // __cplusplus

View File

@ -24,7 +24,7 @@
#include "moofileview/moofileprops-gxml.h"
#include "moofileview/moocreatefolder-gxml.h"
#include "moofileview/moofileview-drop-gxml.h"
#include "moocpp/gobjectutils.h"
#include <moocpp/gobjtypes.h>
#include <time.h>
#include <string.h>
#include <gtk/gtk.h>

View File

@ -19,7 +19,7 @@
#include "mooutils/mooutils-gobject.h"
#include "mooutils/mooutils-misc.h"
#include "mooutils/moocompat.h"
#include "moocpp/gobjectutils.h"
#include "moocpp/gobjtypes.h"
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <string.h>

View File

@ -17,6 +17,7 @@
#include "mooutils/mooprefs.h"
#include "mooutils/mooutils-tests.h"
#include "mooutils/moocompat.h"
#include "moocpp/gobjtypes.h"
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <string.h>

View File

@ -21,7 +21,7 @@
#include "mooutils/moocombo.h"
#include "mooutils/mooentry.h"
#include "mooutils/moocompat.h"
#include "moocpp/gobjectutils.h"
#include <moocpp/gobjtypes.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <string.h>

View File

@ -39,7 +39,7 @@ create_message_dialog (GtkWindow *parent,
type,
message_dialog_buttons,
"<span weight=\"bold\" size=\"larger\">%s</span>", text);
if (secondary_text)
if (secondary_text && *secondary_text)
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s", secondary_text);

View File

@ -24,7 +24,7 @@
#include "mooutils/mooutils-gobject.h"
#include "mooutils/mooeditops.h"
#include "mooutils/mooi18n.h"
#include "moocpp/gobjectutils.h"
#include <moocpp/gobjtypes.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <string.h>

View File

@ -1,7 +1,7 @@
/*
* moofilewriter-private.h
*
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
*
* This file is part of medit. medit is free software; you can
* redistribute it and/or modify it under the terms of the
@ -13,74 +13,64 @@
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MOO_FILE_WRITER_PRIVATE_H
#define MOO_FILE_WRITER_PRIVATE_H
#pragma once
#include "mooutils/moofilewriter.h"
G_BEGIN_DECLS
struct MooFileReader
{
MooFileReader();
~MooFileReader();
#define MOO_TYPE_FILE_READER (moo_file_reader_get_type ())
#define MOO_FILE_READER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_FILE_READER, MooFileReader))
#define MOO_FILE_READER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_FILE_READER, MooFileReaderClass))
#define MOO_IS_FILE_READER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_FILE_READER))
#define MOO_IS_FILE_READER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_FILE_READER))
#define MOO_FILE_READER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_FILE_READER, MooFileReaderClass))
void close_file();
typedef struct _MooFileReaderClass MooFileReaderClass;
MOO_DISABLE_COPY_OPS(MooFileReader);
struct _MooFileReaderClass {
GObjectClass base_class;
MGW_FILE *file;
};
struct MooFileWriter
{
virtual ~MooFileWriter() {}
#define MOO_TYPE_FILE_WRITER (moo_file_writer_get_type ())
#define MOO_FILE_WRITER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_FILE_WRITER, MooFileWriter))
#define MOO_FILE_WRITER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_FILE_WRITER, MooFileWriterClass))
#define MOO_IS_FILE_WRITER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_FILE_WRITER))
#define MOO_IS_FILE_WRITER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_FILE_WRITER))
#define MOO_FILE_WRITER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_FILE_WRITER, MooFileWriterClass))
typedef struct _MooFileWriterClass MooFileWriterClass;
struct _MooFileWriter {
GObject base;
virtual bool write (const char* data,
gsize len) = 0;
virtual bool printf (const char* fmt,
va_list args) G_GNUC_PRINTF (2, 0) = 0;
virtual bool close (moo::gerrp& error) = 0;
};
struct _MooFileWriterClass {
GObjectClass base_class;
struct MooLocalFileWriter : public MooFileWriter
{
MooLocalFileWriter();
~MooLocalFileWriter();
gboolean (*meth_write) (MooFileWriter *writer,
const char *data,
gsize len);
gboolean (*meth_printf) (MooFileWriter *writer,
const char *fmt,
va_list args) G_GNUC_PRINTF (2, 0);
gboolean (*meth_close) (MooFileWriter *writer,
GError **error);
bool write (const char* data,
gsize len) override;
bool printf (const char* fmt,
va_list args) G_GNUC_PRINTF (2, 0) override;
bool close (moo::gerrp& error) override;
MOO_DISABLE_COPY_OPS(MooLocalFileWriter);
moo::g::FilePtr file;
moo::g::FileOutputStreamPtr stream;
MooFileWriterFlags flags;
moo::gerrp error;
};
struct MooStringWriter : public MooFileWriter
{
MooStringWriter();
~MooStringWriter();
#define MOO_TYPE_LOCAL_FILE_WRITER (moo_local_file_writer_get_type ())
#define MOO_LOCAL_FILE_WRITER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_LOCAL_FILE_WRITER, MooLocalFileWriter))
bool write (const char* data,
gsize len) override;
bool printf (const char* fmt,
va_list args) G_GNUC_PRINTF (2, 0) override;
bool close (moo::gerrp& error) override;
typedef struct _MooLocalFileWriter MooLocalFileWriter;
typedef struct _MooLocalFileWriterClass MooLocalFileWriterClass;
MOO_DISABLE_COPY_OPS(MooStringWriter);
struct _MooLocalFileWriterClass {
MooFileWriterClass base_class;
GString *string;
};
#define MOO_TYPE_STRING_WRITER (moo_string_writer_get_type ())
typedef struct _MooStringWriter MooStringWriter;
typedef struct _MooStringWriterClass MooStringWriterClass;
struct _MooStringWriterClass {
MooFileWriterClass base_class;
};
G_END_DECLS
#endif /* MOO_FILE_WRITER_PRIVATE_H */

View File

@ -29,59 +29,41 @@
#include <unistd.h>
#endif
using namespace moo;
/************************************************************************/
/* MooFileReader
*/
struct _MooFileReader {
GObject base;
MGW_FILE *file;
};
MOO_DEFINE_TYPE_STATIC (MooFileReader, moo_file_reader, G_TYPE_OBJECT)
static void
moo_file_reader_init (MooFileReader *reader)
MooFileReader::MooFileReader()
: file(nullptr)
{
reader->file = NULL;
}
static void
moo_file_reader_close_file (MooFileReader *reader)
void MooFileReader::close_file ()
{
if (reader->file)
if (file)
{
mgw_fclose (reader->file);
reader->file = NULL;
mgw_fclose (file);
file = nullptr;
}
}
static void
moo_file_reader_dispose (GObject *object)
MooFileReader::~MooFileReader()
{
MooFileReader *reader = MOO_FILE_READER (object);
moo_file_reader_close_file (reader);
G_OBJECT_CLASS (moo_file_reader_parent_class)->dispose (object);
}
static void
moo_file_reader_class_init (MooFileReaderClass *klass)
{
G_OBJECT_CLASS (klass)->dispose = moo_file_reader_dispose;
close_file();
}
void
moo_file_reader_close (MooFileReader *reader)
{
g_return_if_fail (MOO_IS_FILE_READER (reader));
moo_file_reader_close_file (reader);
g_object_unref (reader);
delete reader;
}
static MooFileReader *
moo_file_reader_new_real (const char *filename,
gboolean binary,
GError **error)
gerrp& error)
{
const char *mode = binary ? "rb" : "r";
MGW_FILE *file;
@ -89,33 +71,33 @@ moo_file_reader_new_real (const char *filename,
mgw_errno_t err;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (!error || !*error, NULL);
g_return_val_if_fail (!error, NULL);
if (!(file = mgw_fopen (filename, mode, &err)))
{
g_set_error (error, MOO_FILE_ERROR,
g_set_error (&error, MOO_FILE_ERROR,
_moo_file_error_from_errno (err),
_("Could not open %s: %s"), filename,
mgw_strerror (err));
return NULL;
}
reader = MOO_FILE_READER (g_object_new (MOO_TYPE_FILE_READER, nullptr));
reader = new MooFileReader();
reader->file = file;
return reader;
}
MooFileReader *
moo_file_reader_new (const char *filename,
GError **error)
moo_file_reader_new (const char* filename,
gerrp& error)
{
return moo_file_reader_new_real (filename, TRUE, error);
}
MooFileReader *
moo_text_reader_new (const char *filename,
GError **error)
moo_text_reader_new (const char* filename,
gerrp& error)
{
return moo_file_reader_new_real (filename, FALSE, error);
}
@ -125,14 +107,14 @@ moo_file_reader_read (MooFileReader *reader,
char *buf,
gsize buf_size,
gsize *size_read_p,
GError **error)
gerrp& error)
{
gsize size_read;
mgw_errno_t err;
g_return_val_if_fail (MOO_IS_FILE_READER (reader), FALSE);
g_return_val_if_fail (reader != nullptr, FALSE);
g_return_val_if_fail (size_read_p != NULL, FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
g_return_val_if_fail (!error, FALSE);
g_return_val_if_fail (reader->file != NULL, FALSE);
g_return_val_if_fail (buf_size == 0 || buf != NULL, FALSE);
@ -143,7 +125,7 @@ moo_file_reader_read (MooFileReader *reader,
if (size_read != buf_size && mgw_ferror (reader->file))
{
g_set_error (error, MOO_FILE_ERROR,
g_set_error (&error, MOO_FILE_ERROR,
_moo_file_error_from_errno (err),
"error reading file: %s",
mgw_strerror (err));
@ -159,24 +141,12 @@ moo_file_reader_read (MooFileReader *reader,
/* MooFileWriter
*/
MOO_DEFINE_TYPE_STATIC (MooFileWriter, moo_file_writer, G_TYPE_OBJECT)
static void
moo_file_writer_init (G_GNUC_UNUSED MooFileWriter *writer)
{
}
static void
moo_file_writer_class_init (G_GNUC_UNUSED MooFileWriterClass *klass)
{
}
gboolean
moo_file_writer_write (MooFileWriter *writer,
const char *data,
gssize len)
{
g_return_val_if_fail (MOO_IS_FILE_WRITER (writer), FALSE);
g_return_val_if_fail (writer != nullptr, FALSE);
g_return_val_if_fail (data != NULL, FALSE);
if (len < 0)
@ -184,7 +154,7 @@ moo_file_writer_write (MooFileWriter *writer,
if (!len)
return TRUE;
return MOO_FILE_WRITER_GET_CLASS (writer)->meth_write (writer, data, len);
return writer->write (data, len);
}
gboolean
@ -195,11 +165,11 @@ moo_file_writer_printf (MooFileWriter *writer,
va_list args;
gboolean ret;
g_return_val_if_fail (MOO_IS_FILE_WRITER (writer), FALSE);
g_return_val_if_fail (writer != nullptr, FALSE);
g_return_val_if_fail (fmt != NULL, FALSE);
va_start (args, fmt);
ret = MOO_FILE_WRITER_GET_CLASS (writer)->meth_printf (writer, fmt, args);
ret = writer->printf (fmt, args);
va_end (args);
return ret;
@ -210,38 +180,40 @@ moo_file_writer_printf_markup (MooFileWriter *writer,
const char *fmt,
...)
{
va_list args;
gboolean ret;
char *string;
g_return_val_if_fail (MOO_IS_FILE_WRITER (writer), FALSE);
g_return_val_if_fail (writer != nullptr, FALSE);
g_return_val_if_fail (fmt != NULL, FALSE);
va_list args;
va_start (args, fmt);
string = g_markup_vprintf_escaped (fmt, args);
gstr string = gstr::wrap_new (g_markup_vprintf_escaped (fmt, args));
va_end (args);
g_return_val_if_fail (string != NULL, FALSE);
g_return_val_if_fail (!string.is_null(), FALSE);
ret = moo_file_writer_write (writer, string, -1);
return moo_file_writer_write (writer, string, -1);
}
g_free (string);
gboolean
moo_file_writer_close (MooFileWriter* writer,
gerrp& error)
{
gboolean ret;
g_return_val_if_fail (writer != nullptr, FALSE);
g_return_val_if_fail (!error, FALSE);
ret = writer->close (error);
delete writer;
return ret;
}
gboolean
moo_file_writer_close (MooFileWriter *writer,
GError **error)
GError **errorp)
{
gboolean ret;
g_return_val_if_fail (MOO_IS_FILE_WRITER (writer), FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
ret = MOO_FILE_WRITER_GET_CLASS (writer)->meth_close (writer, error);
g_object_unref (writer);
return ret;
gerrp error(errorp);
return moo_file_writer_close (writer, error);
}
@ -249,113 +221,88 @@ moo_file_writer_close (MooFileWriter *writer,
/* MooLocalFileWriter
*/
struct _MooLocalFileWriter {
MooFileWriter base;
GFile *file;
GOutputStream *stream;
MooFileWriterFlags flags;
GError *error;
};
MooLocalFileWriter::MooLocalFileWriter()
: flags(MOO_FILE_WRITER_FLAGS_NONE)
{
}
MOO_DEFINE_TYPE_STATIC (MooLocalFileWriter, moo_local_file_writer, MOO_TYPE_FILE_WRITER)
MooLocalFileWriter::~MooLocalFileWriter()
{
}
static MooFileWriter *
moo_local_file_writer_new (GFile *file,
MooFileWriterFlags flags,
GError **error)
moo_local_file_writer_new (g::File file,
MooFileWriterFlags flags,
gerrp& error)
{
MooLocalFileWriter *writer = NULL;
GFileOutputStream *stream = NULL;
GFile *file_copy = NULL;
g_return_val_if_fail (G_IS_FILE (file), NULL);
if (flags & MOO_FILE_WRITER_CONFIG_MODE)
{
char *dirname;
char *filename;
mgw_errno_t err;
filename = g_file_get_path (file);
dirname = filename ? g_path_get_dirname (filename) : NULL;
gstr filename = file.get_path ();
gstr dirname = !filename.empty() ? gstr::wrap_new (g_path_get_dirname (filename)) : gstr();
if (dirname && _moo_mkdir_with_parents (dirname, &err) != 0)
if (!dirname.empty() && _moo_mkdir_with_parents (dirname, &err) != 0)
{
char *display_name = g_filename_display_name (dirname);
g_set_error (error, G_FILE_ERROR,
gstr display_name = gstr::wrap_new (g_filename_display_name (dirname));
g_set_error (&error, G_FILE_ERROR,
mgw_file_error_from_errno (err),
_("Could not create folder %s: %s"),
display_name, mgw_strerror (err));
g_free (display_name);
g_free (dirname);
goto error;
return nullptr;
}
g_free (dirname);
g_free (filename);
}
file_copy = g_file_dup (file);
stream = g_file_replace (file_copy, NULL,
(flags & MOO_FILE_WRITER_SAVE_BACKUP) != 0,
G_FILE_CREATE_NONE,
NULL, error);
g::FilePtr file_copy = file.dup ();
g::FileOutputStreamPtr stream = file_copy->replace (NULL,
(flags & MOO_FILE_WRITER_SAVE_BACKUP) != 0,
G_FILE_CREATE_NONE,
NULL, error);
if (!stream)
goto error;
return nullptr;
auto writer = make_unique<MooLocalFileWriter>();
writer = MOO_LOCAL_FILE_WRITER (g_object_new (MOO_TYPE_LOCAL_FILE_WRITER, nullptr));
writer->file = file_copy;
writer->stream = G_OUTPUT_STREAM (stream);
writer->stream = stream;
writer->flags = flags;
return MOO_FILE_WRITER (writer);
error:
if (file_copy)
g_object_unref (file_copy);
if (stream)
g_object_unref (stream);
return NULL;
return writer.release ();
}
MooFileWriter *
moo_file_writer_new (const char *filename,
MooFileWriterFlags flags,
GError **error)
moo_file_writer_new (const char* filename,
MooFileWriterFlags flags,
gerrp& error)
{
GFile *file;
MooFileWriter *writer;
g_return_val_if_fail (filename != nullptr, nullptr);
g_return_val_if_fail (!error, nullptr);
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (!error || !*error, NULL);
g::FilePtr file = g::File::new_for_path (filename);
g_return_val_if_fail (file != nullptr, nullptr);
file = g_file_new_for_path (filename);
writer = moo_local_file_writer_new (file, flags, error);
g_object_unref (file);
return writer;
return moo_local_file_writer_new (*file, flags, error);
}
MooFileWriter *
moo_file_writer_new_for_file (GFile *file,
MooFileWriterFlags flags,
GError **error)
moo_file_writer_new_for_file (g::File file,
MooFileWriterFlags flags,
gerrp& error)
{
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (!error || !*error, NULL);
g_return_val_if_fail (!error, NULL);
return moo_local_file_writer_new (file, flags, error);
}
MooFileWriter *
moo_config_writer_new (const char *filename,
gboolean save_backup,
GError **error)
gerrp& error)
{
MooFileWriterFlags flags;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (!error || !*error, NULL);
g_return_val_if_fail (!error, NULL);
flags = MOO_FILE_WRITER_CONFIG_MODE | MOO_FILE_WRITER_TEXT_MODE;
if (save_backup)
@ -364,15 +311,19 @@ moo_config_writer_new (const char *filename,
return moo_file_writer_new (filename, flags, error);
}
static gboolean
moo_local_file_writer_write (MooFileWriter *fwriter,
const char *data,
gsize len)
MooFileWriter *
moo_config_writer_new (const char *filename,
gboolean save_backup,
GError **errorp)
{
MooLocalFileWriter *writer = (MooLocalFileWriter*) fwriter;
gerrp error(errorp);
return moo_config_writer_new(filename, save_backup, error);
}
if (writer->error)
bool MooLocalFileWriter::write (const char* data, gsize len)
{
if (error)
return FALSE;
while (len > 0)
@ -385,7 +336,7 @@ moo_local_file_writer_write (MooFileWriter *fwriter,
#endif
#ifdef __WIN32__
if (writer->flags & MOO_FILE_WRITER_TEXT_MODE)
if (flags & MOO_FILE_WRITER_TEXT_MODE)
{
gsize le_start, le_len;
if (moo_find_line_end (data, len, &le_start, &le_len))
@ -397,20 +348,18 @@ moo_local_file_writer_write (MooFileWriter *fwriter,
}
#endif
if (!g_output_stream_write_all (writer->stream,
data, chunk_len,
&bytes_written, NULL,
&writer->error))
if (!stream->write_all (data, chunk_len,
&bytes_written, NULL,
error))
return FALSE;
data += next_chunk;
len -= next_chunk;
#ifdef __WIN32__
if (need_le && !g_output_stream_write_all (writer->stream,
"\r\n", 2,
&bytes_written, NULL,
&writer->error))
if (need_le && !stream->write_all ("\r\n", 2,
&bytes_written, NULL,
error))
return FALSE;
#endif
}
@ -418,71 +367,30 @@ moo_local_file_writer_write (MooFileWriter *fwriter,
return TRUE;
}
G_GNUC_PRINTF (2, 0)
static gboolean
moo_local_file_writer_printf (MooFileWriter *fwriter,
const char *fmt,
va_list args)
bool MooLocalFileWriter::printf (const char* fmt, va_list args)
{
MooLocalFileWriter *writer = (MooLocalFileWriter*) fwriter;
char *text;
gboolean retval;
if (writer->error)
if (error)
return FALSE;
text = g_strdup_vprintf (fmt, args);
retval = moo_local_file_writer_write (fwriter, text, strlen (text));
g_free (text);
return retval;
gstr text = gstr::wrap_new (g_strdup_vprintf (fmt, args));
return write (text, strlen (text));
}
static gboolean
moo_local_file_writer_close (MooFileWriter *fwriter,
GError **error)
bool MooLocalFileWriter::close (gerrp& out_error)
{
MooLocalFileWriter *writer = (MooLocalFileWriter*) fwriter;
gboolean retval;
g_return_val_if_fail (stream != nullptr, FALSE);
g_return_val_if_fail (writer->stream != NULL, FALSE);
if (!writer->error)
if (!error)
{
g_output_stream_flush (writer->stream, NULL, &writer->error);
g_output_stream_close (writer->stream, NULL,
writer->error ? NULL : &writer->error);
g_object_unref (writer->stream);
g_object_unref (writer->file);
writer->stream = NULL;
writer->file = NULL;
stream->flush (NULL, error);
gerrp second;
stream->close (NULL, error ? second : error);
stream.reset ();
file.reset ();
}
retval = writer->error == NULL;
if (writer->error)
g_propagate_error (error, writer->error);
writer->error = NULL;
return retval;
}
static void
moo_local_file_writer_class_init (MooLocalFileWriterClass *klass)
{
MooFileWriterClass *writer_class = MOO_FILE_WRITER_CLASS (klass);
writer_class->meth_write = moo_local_file_writer_write;
writer_class->meth_printf = moo_local_file_writer_printf;
writer_class->meth_close = moo_local_file_writer_close;
}
static void
moo_local_file_writer_init (MooLocalFileWriter *writer)
{
writer->file = NULL;
writer->stream = NULL;
writer->error = NULL;
out_error = std::move (error);
return !out_error;
}
@ -490,88 +398,44 @@ moo_local_file_writer_init (MooLocalFileWriter *writer)
/* MooStringWriter
*/
struct _MooStringWriter {
MooFileWriter base;
GString *string;
};
MOO_DEFINE_TYPE_STATIC (MooStringWriter, moo_string_writer, MOO_TYPE_FILE_WRITER)
static gboolean
moo_string_writer_write (MooFileWriter *fwriter,
const char *data,
gsize len)
bool MooStringWriter::write (const char* data, gsize len)
{
MooStringWriter *writer = (MooStringWriter*) fwriter;
g_string_append_len (writer->string, data, len);
g_string_append_len (string, data, len);
return TRUE;
}
G_GNUC_PRINTF (2, 0)
static gboolean
moo_string_writer_printf (MooFileWriter *fwriter,
const char *fmt,
va_list args)
bool MooStringWriter::printf (const char* fmt, va_list args)
{
char *buf;
gint len;
MooStringWriter *writer = (MooStringWriter*) fwriter;
len = g_vasprintf (&buf, fmt, args);
strp buf;
gint len = g_vasprintf (buf.pp(), fmt, args);
if (len >= 0)
{
g_string_append_len (writer->string, buf, len);
g_free (buf);
}
g_string_append_len (string, buf.get(), len);
return TRUE;
}
static gboolean
moo_string_writer_close (MooFileWriter *fwriter,
G_GNUC_UNUSED GError **error)
bool MooStringWriter::close (G_GNUC_UNUSED gerrp& error)
{
MooStringWriter *writer = (MooStringWriter*) fwriter;
g_string_free (writer->string, TRUE);
writer->string = NULL;
g_string_free (string, TRUE);
string = NULL;
return TRUE;
}
static void
moo_string_writer_class_init (MooStringWriterClass *klass)
MooStringWriter::MooStringWriter()
: string (g_string_new (NULL))
{
MooFileWriterClass *writer_class = MOO_FILE_WRITER_CLASS (klass);
writer_class->meth_write = moo_string_writer_write;
writer_class->meth_printf = moo_string_writer_printf;
writer_class->meth_close = moo_string_writer_close;
}
static void
moo_string_writer_init (MooStringWriter *writer)
MooStringWriter::~MooStringWriter()
{
writer->string = g_string_new (NULL);
g_assert (!string);
}
MooFileWriter *
moo_string_writer_new (void)
{
return MOO_FILE_WRITER (g_object_new (MOO_TYPE_STRING_WRITER, nullptr));
}
const char *
moo_string_writer_get_string (MooFileWriter *fwriter,
gsize *len)
{
MooStringWriter *writer = (MooStringWriter*) fwriter;
g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE ((writer), MOO_TYPE_STRING_WRITER), NULL);
g_return_val_if_fail (writer->string != NULL, NULL);
if (len)
*len = writer->string->len;
return writer->string->str;
return new MooStringWriter();
}
@ -628,7 +492,7 @@ test_moo_file_writer (void)
const char *dir;
char *my_dir, *filename, *bak_filename;
MooFileWriter *writer;
GError *error = NULL;
gerrp error;
dir = moo_test_get_working_dir ();
my_dir = g_build_filename (dir, "cfg-writer", NULL);
@ -639,11 +503,7 @@ test_moo_file_writer (void)
TEST_ASSERT_MSG (writer != NULL,
"moo_cfg_writer_new failed: %s",
moo_error_message (error));
if (error)
{
g_error_free (error);
error = NULL;
}
error.clear ();
if (writer)
{
@ -653,11 +513,7 @@ test_moo_file_writer (void)
TEST_ASSERT_MSG (moo_file_writer_close (writer, &error),
"moo_file_writer_close failed: %s",
moo_error_message (error));
if (error)
{
g_error_free (error);
error = NULL;
}
error.clear ();
#ifdef __WIN32__
#define LE "\r\n"
@ -682,11 +538,7 @@ test_moo_file_writer (void)
TEST_ASSERT_MSG (moo_file_writer_close (writer, &error),
"moo_file_writer_close failed: %s",
moo_error_message (error));
if (error)
{
g_error_free (error);
error = NULL;
}
error.clear ();
TEST_ASSERT (g_file_test (filename, G_FILE_TEST_EXISTS));
TEST_ASSERT (g_file_test (bak_filename, G_FILE_TEST_EXISTS));
@ -703,11 +555,7 @@ test_moo_file_writer (void)
writer = moo_config_writer_new ("K:\\nowayyouhaveit\\file.ini", TRUE, &error);
#endif
TEST_ASSERT (writer == NULL);
TEST_ASSERT (error != NULL);
if (error)
g_error_free (error);
error = NULL;
TEST_ASSERT (error);
g_free (bak_filename);
g_free (filename);

View File

@ -15,44 +15,65 @@
#pragma once
#include <gio/gio.h>
#include <mooutils/mooutils-misc.h>
G_BEGIN_DECLS
#ifdef __cplusplus
#include <moocpp/gobjtypes-gio.h>
typedef struct _MooFileReader MooFileReader;
struct MooFileReader;
struct MooFileWriter;
void g_object_ref(MooFileReader*) = delete;
void g_object_unref(MooFileReader*) = delete;
void g_object_ref(MooFileWriter*) = delete;
void g_object_unref(MooFileWriter*) = delete;
MooFileReader *moo_file_reader_new (const char *filename,
GError **error);
moo::gerrp& error);
MooFileReader *moo_text_reader_new (const char *filename,
GError **error);
moo::gerrp& error);
gboolean moo_file_reader_read (MooFileReader *reader,
char *buf,
gsize buf_size,
gsize *size_read,
GError **error);
moo::gerrp& error);
void moo_file_reader_close (MooFileReader *reader);
typedef struct _MooFileWriter MooFileWriter;
typedef enum /*< flags >*/
{
MOO_FILE_WRITER_FLAGS_NONE = 0,
MOO_FILE_WRITER_SAVE_BACKUP = 1 << 0,
MOO_FILE_WRITER_CONFIG_MODE = 1 << 1,
MOO_FILE_WRITER_TEXT_MODE = 1 << 2
} MooFileWriterFlags;
MOO_DEFINE_FLAGS(MooFileWriterFlags);
MooFileWriter *moo_file_writer_new (const char *filename,
MooFileWriterFlags flags,
GError **error);
MooFileWriter *moo_file_writer_new_for_file (GFile *file,
moo::gerrp& error);
MooFileWriter *moo_file_writer_new_for_file (moo::g::File file,
MooFileWriterFlags flags,
GError **error);
moo::gerrp& error);
MooFileWriter *moo_config_writer_new (const char *filename,
gboolean save_backup,
moo::gerrp& error);
MooFileWriter *moo_string_writer_new (void);
gboolean moo_file_writer_close (MooFileWriter *writer,
moo::gerrp& error);
#endif // __cplusplus
G_BEGIN_DECLS
typedef struct MooFileWriter MooFileWriter;
MooFileWriter *moo_config_writer_new (const char *filename,
gboolean save_backup,
GError **error);
MooFileWriter *moo_string_writer_new (void);
gboolean moo_file_writer_write (MooFileWriter *writer,
const char *data,
gssize len);
@ -65,13 +86,4 @@ gboolean moo_file_writer_printf_markup (MooFileWriter *writer,
gboolean moo_file_writer_close (MooFileWriter *writer,
GError **error);
const char *moo_string_writer_get_string (MooFileWriter *writer,
gsize *len);
G_END_DECLS
#ifdef __cplusplus
#include <moocpp/gobjectutils.h>
MOO_DEFINE_FLAGS(MooFileWriterFlags);
#endif

View File

@ -33,6 +33,8 @@
#include <stdarg.h>
#include <string.h>
using namespace moo;
#define N_MENU_ITEMS 10
#define MAX_ITEM_NUMBER 5000
@ -794,7 +796,7 @@ static void
moo_history_mgr_save (MooHistoryMgr *mgr)
{
const char *filename;
GError *error = NULL;
gerrp error;
MooFileWriter *writer;
g_return_if_fail (MOO_IS_HISTORY_MGR (mgr));
@ -811,7 +813,7 @@ moo_history_mgr_save (MooHistoryMgr *mgr)
return;
}
if ((writer = moo_config_writer_new (filename, FALSE, &error)))
if ((writer = moo_config_writer_new (filename, FALSE, error)))
{
GString *string;
MooHistoryItemList *l;
@ -833,14 +835,13 @@ moo_history_mgr_save (MooHistoryMgr *mgr)
g_string_free (string, TRUE);
moo_file_writer_write (writer, "</" ELM_ROOT ">\n", -1);
moo_file_writer_close (writer, &error);
moo_file_writer_close (writer, error);
}
if (error)
{
g_critical ("could not save file '%s': %s",
filename, moo_error_message (error));
g_error_free (error);
}
}

View File

@ -21,6 +21,7 @@
#include <string.h>
#include <mooglib/moo-glib.h>
using namespace moo;
typedef struct {
MooMarkupDoc *doc;
@ -1297,7 +1298,7 @@ gboolean
moo_parse_markup_file (const char *filename,
const GMarkupParser *parser,
gpointer data,
GError **error)
GError **errorp)
{
GMarkupParseContext *ctx;
MooFileReader *reader;
@ -1307,7 +1308,9 @@ moo_parse_markup_file (const char *filename,
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (parser != NULL, FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
g_return_val_if_fail (!errorp || !*errorp, FALSE);
gerrp error(errorp);
if (!(reader = moo_text_reader_new (filename, error)))
return FALSE;
@ -1325,14 +1328,14 @@ moo_parse_markup_file (const char *filename,
if (!size)
break;
if (!g_markup_parse_context_parse (ctx, buf, size, error))
if (!g_markup_parse_context_parse (ctx, buf, size, &error))
{
seen_error = TRUE;
break;
}
}
if (!seen_error && !g_markup_parse_context_end_parse (ctx, error))
if (!seen_error && !g_markup_parse_context_end_parse (ctx, &error))
seen_error = TRUE;
g_markup_parse_context_free (ctx);

View File

@ -38,7 +38,6 @@
#include "mooutils-gobject.h"
#include "mooi18n.h"
#include "moocpp/gobjectutils.h"
#include "moocpp/gobjtypes.h"
using namespace moo;

View File

@ -37,7 +37,7 @@
#include <gtk/gtk.h>
#include "mooutils-misc.h"
#include "moocpp/gobjectutils.h"
#include "moocpp/gobjtypes.h"
#include "moocompat.h"

View File

@ -24,6 +24,8 @@
#include <gobject/gvaluecollector.h>
#include <mooglib/moo-glib.h>
using namespace moo;
#define MOO_PREFS_ELEMENT "moo-prefs"
#define PROP_VERSION "version"
#define MOO_PREFS_VERSION "1.0"
@ -597,7 +599,7 @@ process_item (MooMarkupElement *elm,
static gboolean
load_file (const char *file,
int prefs_kind,
GError **error)
moo::gerrp& error)
{
MooMarkupDoc *xml;
MooMarkupNode *root;
@ -625,7 +627,7 @@ load_file (const char *file,
if (!g_file_test (file, G_FILE_TEST_EXISTS))
return TRUE;
xml = moo_markup_parse_file (file, error);
xml = moo_markup_parse_file (file, &error);
if (!xml)
return FALSE;
@ -679,11 +681,11 @@ load_file (const char *file,
}
gboolean
bool
moo_prefs_load (char **sys_files,
const char *file_rc,
const char *file_state,
GError **error)
moo::gerrp& error)
{
moo_prefs_set_modified (FALSE);
@ -846,9 +848,9 @@ check_modified (MooPrefsKind prefs_kind)
}
static gboolean
save_file (const char *file,
MooPrefsKind prefs_kind,
GError **error)
save_file (const char* file,
MooPrefsKind prefs_kind,
gerrp& error)
{
MooMarkupDoc *xml = NULL;
MooMarkupNode *node;
@ -899,10 +901,10 @@ save_file (const char *file,
}
gboolean
moo_prefs_save (const char *file_rc,
const char *file_state,
GError **error)
bool
moo_prefs_save (const char* file_rc,
const char* file_state,
gerrp& error)
{
PrefsStore *prefs = prefs_instance ();

View File

@ -13,27 +13,19 @@
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MOO_PREFS_H
#define MOO_PREFS_H
#pragma once
#include <glib-object.h>
#include <mooutils/moomarkup.h>
#include <mooutils/mooutils-file.h>
G_BEGIN_DECLS
#include <moocpp/strutils.h>
typedef enum {
MOO_PREFS_RC,
MOO_PREFS_STATE
} MooPrefsKind;
gboolean moo_prefs_load (char **sys_files,
const char *file_rc,
const char *file_state,
GError **error);
gboolean moo_prefs_save (const char *file_rc,
const char *file_state,
GError **error);
G_BEGIN_DECLS
MooMarkupNode *moo_prefs_get_markup (MooPrefsKind prefs_kind);
@ -91,4 +83,14 @@ void moo_prefs_set_bool (const char *key,
G_END_DECLS
#endif /* MOO_PREFS_H */
#ifdef __cplusplus
bool moo_prefs_load (char** sys_files,
const char* file_rc,
const char* file_state,
moo::gerrp& error);
bool moo_prefs_save (const char* file_rc,
const char* file_state,
moo::gerrp& error);
#endif // __cplusplus

View File

@ -16,7 +16,7 @@
#include "mooutils/moospawn.h"
#include "marshals.h"
#include "mooutils/mooutils-misc.h"
#include "moocpp/gobjectutils.h"
#include "moocpp/gobjtypes.h"
#include <string.h>
#ifndef __WIN32__

View File

@ -15,7 +15,7 @@
#include "mooutils/mooundo.h"
#include "marshals.h"
#include "moocpp/gobjectutils.h"
#include "moocpp/gobjtypes.h"
#include <string.h>

View File

@ -7,17 +7,10 @@ using namespace moo;
MOO_DEFINE_OBJECT_ARRAY_FULL (MooFileArray, moo_file_array, GFile)
char *
moo_file_get_display_name (GFile *file)
{
g_return_val_if_fail (G_IS_FILE (file), NULL);
return g_file_get_parse_name (file);
}
gstr
moo_file_get_display_name(const g::File& file)
moo_file_get_display_name(g::File file)
{
return gstr::wrap_new(moo_file_get_display_name(file.nc_gobj()));
return file.get_parse_name();
}
gboolean

View File

@ -16,7 +16,6 @@ moo_file_free (GFile *file)
gboolean moo_file_fnmatch (GFile* file,
const char* glob);
char *moo_file_get_display_name (GFile* file);
G_END_DECLS
@ -25,6 +24,6 @@ G_END_DECLS
#include <moocpp/strutils.h>
#include <moocpp/gobjtypes-gio.h>
moo::gstr moo_file_get_display_name (const moo::g::File& file);
moo::gstr moo_file_get_display_name (moo::g::File file);
#endif // __cplusplus

View File

@ -130,42 +130,6 @@ MOO_STMT_START { \
#define moo_return_if_reached() moo_return_val_if_reached(;)
GQuark moo_error_quark (void) G_GNUC_CONST;
#define MOO_ERROR (moo_error_quark ())
enum {
MOO_ERROR_UNEXPECTED = 1
};
#define moo_return_error_if_fail_val(cond, val) \
MOO_STMT_START { \
if (cond) \
{ \
} \
else \
{ \
moo_critical("Condition '%s' failed", #cond); \
g_set_error (error, MOO_ERROR, MOO_ERROR_UNEXPECTED,\
"unexpected error"); \
return val; \
} \
} MOO_STMT_END
#ifdef __cplusplus
#define moo_err_false_ret__ false
#define moo_err_null_ret__ nullptr
#else
#define moo_err_false_ret__ FALSE
#define moo_err_null_ret__ NULL
#endif
#define moo_return_error_if_fail(cond) \
moo_return_error_if_fail_val (cond, moo_err_false_ret__)
#define moo_return_error_if_fail_p(cond) \
moo_return_error_if_fail_val (cond, moo_err_null_ret__)
/*
* Suppress warnings when GCC is in -pedantic mode and not -std=c99
*/

View File

@ -53,6 +53,8 @@
#include <shlobj.h>
#endif
using namespace moo;
MOO_DEFINE_QUARK(moo - error, moo_error_quark)
static gpointer copy_pointer(gpointer p)
@ -1703,24 +1705,23 @@ moo_get_user_cache_file (const char *basename)
static gboolean
save_config_file (const char *filename,
const char *content,
gssize len,
GError **error)
save_config_file (const char *filename,
const char *content,
gssize len,
GError **error)
{
MooFileWriter *writer;
gboolean retval;
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (content != NULL, FALSE);
if (!(writer = moo_config_writer_new (filename, TRUE, error)))
gerrp error_here(error);
if (!(writer = moo_config_writer_new (filename, TRUE, error_here)))
return FALSE;
moo_file_writer_write (writer, content, len);
retval = moo_file_writer_close (writer, error);
return retval;
return moo_file_writer_close (writer, error_here);
}
static gboolean
@ -1730,21 +1731,17 @@ save_user_data_file (const char *basename,
gssize len,
GError **error)
{
char *file;
gboolean result;
g_return_val_if_fail (basename != NULL, FALSE);
g_return_val_if_fail (content != NULL, FALSE);
gstr file;
if (cache)
file = moo_get_user_cache_file (basename);
file.take (moo_get_user_cache_file (basename));
else
file = moo_get_user_data_file (basename);
file.take (moo_get_user_data_file (basename));
result = save_config_file (file, content, len, error);
g_free (file);
return result;
return save_config_file (file, content, len, error);
}
gboolean
@ -2231,6 +2228,12 @@ moo_error_message (GError *error)
return error->message;
}
moo::gstr
moo_error_message(const moo::gerrp& err)
{
return gstr::make_borrowed (moo_error_message (err.get ()));
}
gboolean
moo_signal_accumulator_continue_cancel (G_GNUC_UNUSED GSignalInvocationHint *ihint,

View File

@ -267,29 +267,66 @@ moo_os_win32 (void)
#include <moocpp/strutils.h>
#include <vector>
namespace moo
{
class gerrp
{
public:
gerrp();
~gerrp();
operator bool() const { return m_err != nullptr; }
bool operator!() const { return m_err == nullptr; }
GError* get() const { return m_err; }
GError* operator->() const { return m_err; }
GError** operator&() { return &m_err; }
private:
GError* m_err;
};
} // namespace moo
std::vector<moo::gstr> moo_get_data_subdirs(const moo::gstr& subdir);
moo::gstr moo_error_message(const moo::gerrp& err);
#endif // __cplusplus
G_BEGIN_DECLS
GQuark moo_error_quark (void) G_GNUC_CONST;
#define MOO_ERROR (moo_error_quark ())
enum {
MOO_ERROR_UNEXPECTED = 1
};
G_END_DECLS
#ifdef __cplusplus
#define moo_err_false_ret__ false
#define moo_err_null_ret__ nullptr
inline void moo_err_set_unexpected_error(GError** error)
{
g_set_error (error, MOO_ERROR, MOO_ERROR_UNEXPECTED, "unexpected error");
}
inline void moo_err_set_unexpected_error(moo::gerrp& error)
{
moo_err_set_unexpected_error(&error);
}
#else // !__cplusplus
#define moo_err_false_ret__ FALSE
#define moo_err_null_ret__ NULL
#define moo_err_set_unexpected_error(error) \
g_set_error (error, \
MOO_ERROR, \
MOO_ERROR_UNEXPECTED, \
"unexpected error")
#endif // !__cplusplus
#define moo_return_error_if_fail_val(cond, val) \
MOO_STMT_START { \
if (cond) \
{ \
} \
else \
{ \
moo_critical("Condition '%s' failed", #cond); \
moo_err_set_unexpected_error(error); \
return val; \
} \
} MOO_STMT_END
#define moo_return_error_if_fail(cond) \
moo_return_error_if_fail_val (cond, moo_err_false_ret__)
#define moo_return_error_if_fail_p(cond) \
moo_return_error_if_fail_val (cond, moo_err_null_ret__)

View File

@ -18,7 +18,7 @@
#include "mooutils/mooutils-gobject.h"
#include "mooutils/moocompat.h"
#include "mooutils/mootype-macros.h"
#include "moocpp/gobjectutils.h"
#include "moocpp/gobjtypes.h"
#include "marshals.h"
#include <string.h>
#include <gobject/gvaluecollector.h>