Safer printf-like functions
This commit is contained in:
parent
4e6cebc487
commit
bde0c7381b
@ -331,7 +331,7 @@ push_appdir_to_path (void)
|
||||
gstr new_path;
|
||||
|
||||
if (path)
|
||||
new_path.set_new (g_strdup_printf ("%s;%s", appdir.get(), path));
|
||||
new_path.set_printf ("%s;%s", appdir, path);
|
||||
else
|
||||
new_path = std::move (appdir);
|
||||
|
||||
|
@ -231,7 +231,7 @@ gstr App::get_system_info ()
|
||||
strbuilder text;
|
||||
|
||||
text.append_printf ("%s-%s\n", MOO_APP_FULL_NAME, MOO_DISPLAY_VERSION);
|
||||
text.append_printf ("OS: %s\n", get_system_name ().get ());
|
||||
text.append_printf ("OS: %s\n", get_system_name ());
|
||||
text.append_printf ("GTK version: %u.%u.%u\n",
|
||||
gtk_major_version,
|
||||
gtk_minor_version,
|
||||
|
@ -107,15 +107,6 @@ gstr utf8_strdown (const char* str)
|
||||
return wrap_new (g_utf8_strdown (str, -1));
|
||||
}
|
||||
|
||||
gstr markup_printf_escaped (const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
gstr result = markup_vprintf_escaped (fmt, args);
|
||||
va_end (args);
|
||||
return result;
|
||||
}
|
||||
|
||||
gstr markup_vprintf_escaped (const char* fmt, va_list args)
|
||||
{
|
||||
return wrap_new (g_markup_vprintf_escaped (fmt, args));
|
||||
|
@ -47,8 +47,13 @@ gstr utf8_normalize(const char* str, GNormalizeMode mode);
|
||||
gstr utf8_strup(const char* str);
|
||||
gstr utf8_strdown(const char* str);
|
||||
|
||||
gstr markup_printf_escaped(const char* fmt, ...) G_GNUC_PRINTF(1, 2);
|
||||
gstr markup_vprintf_escaped(const char* fmt, va_list args);
|
||||
gstr markup_vprintf_escaped(const char* fmt, va_list args) G_GNUC_PRINTF (1, 0);
|
||||
|
||||
template<typename ...Args>
|
||||
inline gstr markup_printf_escaped (const char* format, Args&& ...args) G_GNUC_PRINTF (1, 2)
|
||||
{
|
||||
return wrap_new (printf_helper::callv (g_markup_printf_escaped, format, std::forward<Args> (args)...));
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
gstr win32_error_message(DWORD code);
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "moocpp/strutils.h"
|
||||
#include "mooutils/mooutils-messages.h"
|
||||
#include <string.h>
|
||||
|
||||
using namespace moo;
|
||||
@ -70,7 +71,7 @@ public:
|
||||
|
||||
~StringData()
|
||||
{
|
||||
g_free(m_p);
|
||||
::g_free(m_p);
|
||||
}
|
||||
|
||||
StringData(const StringData&) = delete;
|
||||
@ -127,7 +128,7 @@ gstr::gstr(const char* s, mem_transfer mt)
|
||||
if (*s == 0)
|
||||
{
|
||||
if (mt == mem_transfer::take_ownership)
|
||||
g_free(const_cast<char*>(s));
|
||||
::g_free(const_cast<char*>(s));
|
||||
|
||||
mt = mem_transfer::borrow;
|
||||
s = "";
|
||||
@ -264,7 +265,7 @@ void gstr::clear()
|
||||
moo_assert(m_p != nullptr);
|
||||
|
||||
if (m_is_inline)
|
||||
g_free(m_p);
|
||||
::g_free(m_p);
|
||||
else
|
||||
reinterpret_cast<StringData*>(m_p)->unref();
|
||||
|
||||
@ -347,21 +348,18 @@ char* gstr::release_owned()
|
||||
return p;
|
||||
}
|
||||
|
||||
gstr gstr::printf(const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
gstr result = vprintf(format, args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
gstr gstr::vprintf(const char* format, va_list args)
|
||||
{
|
||||
return gstr::wrap_new(g_strdup_vprintf(format, args));
|
||||
}
|
||||
|
||||
|
||||
const size_t std::hash<moo::gstr>::operator()(const moo::gstr& s) const
|
||||
{
|
||||
return g_str_hash (s.is_null () ? "" : s.get ());
|
||||
}
|
||||
|
||||
|
||||
gstrvec moo::convert(gstrv v)
|
||||
{
|
||||
char** pv = v.release();
|
||||
@ -372,7 +370,7 @@ gstrvec moo::convert(gstrv v)
|
||||
for (gsize i = 0, c = ret.size(); i < c; ++i)
|
||||
ret.emplace_back(gstr::wrap_new(pv[i]));
|
||||
|
||||
g_free(pv);
|
||||
::g_free(pv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -537,30 +535,12 @@ void strbuilder::vprintf(const char* format, va_list args)
|
||||
g_string_vprintf(m_buf, format, args);
|
||||
}
|
||||
|
||||
void strbuilder::printf(const char* format, ...)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
g_string_vprintf(m_buf, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void strbuilder::append_vprintf(const char* format, va_list args)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_append_vprintf(m_buf, format, args);
|
||||
}
|
||||
|
||||
void strbuilder::append_printf(const char* format, ...)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
g_string_append_vprintf(m_buf, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void strbuilder::append_uri_escaped(const char* unescaped, const char* reserved_chars_allowed, bool allow_utf8)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
|
@ -27,10 +27,14 @@
|
||||
#include <vector>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <type_traits>
|
||||
#include <stdarg.h>
|
||||
|
||||
namespace moo {
|
||||
|
||||
class gstr;
|
||||
class gstrp;
|
||||
|
||||
// Replacement for raw char*
|
||||
class gstrp : public gbuf<char>
|
||||
{
|
||||
@ -49,6 +53,77 @@ public:
|
||||
bool operator!=(const char* p) const { return get() != p; }
|
||||
};
|
||||
|
||||
struct printf_helper
|
||||
{
|
||||
template<typename ...Args>
|
||||
struct is_valid_arg
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template<typename T, class... Args>
|
||||
struct is_valid_arg<T, Args...>
|
||||
{
|
||||
static_assert(std::is_trivial<std::remove_reference_t<T>>::value, "An object passed to a printf-like function");
|
||||
static const bool value =
|
||||
std::is_trivial<std::remove_reference_t<T>>::value
|
||||
&& is_valid_arg<Args...>::value;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
static const T& transform_printf_arg (const T& arg);
|
||||
static const char* transform_printf_arg (const gstr& s);
|
||||
static const char* transform_printf_arg (const gstrp& s);
|
||||
|
||||
template<typename Func, typename ...Args>
|
||||
static auto call (const Func& func, const char* format, Args&& ...args) G_GNUC_PRINTF (1, 2)-> decltype(func(""))
|
||||
{
|
||||
g_assert (printf_helper::is_valid_arg<decltype(printf_helper::transform_printf_arg (std::forward<Args> (args)))...>::value);
|
||||
return func(format, printf_helper::transform_printf_arg (std::forward<Args> (args))...);
|
||||
}
|
||||
|
||||
template<typename Func, typename ...Args>
|
||||
static auto callv (const Func& func, const char* format, Args&& ...args) G_GNUC_PRINTF (1, 2)-> decltype(func("", va_list()))
|
||||
{
|
||||
g_assert (printf_helper::is_valid_arg<decltype(printf_helper::transform_printf_arg (std::forward<Args> (args)))...>::value);
|
||||
return call_helper (func, format, printf_helper::transform_printf_arg (std::forward<Args> (args))...);
|
||||
}
|
||||
|
||||
template<typename Func, typename ...Args>
|
||||
static void call_void (const Func& func, const char* format, Args&& ...args) G_GNUC_PRINTF (1, 2)
|
||||
{
|
||||
g_assert (printf_helper::is_valid_arg<decltype(printf_helper::transform_printf_arg (std::forward<Args> (args)))...>::value);
|
||||
func (format, printf_helper::transform_printf_arg (std::forward<Args> (args))...);
|
||||
}
|
||||
|
||||
template<typename Func, typename ...Args>
|
||||
static void callv_void (const Func& func, const char* format, Args&& ...args) G_GNUC_PRINTF (1, 2)
|
||||
{
|
||||
g_assert (printf_helper::is_valid_arg<decltype(printf_helper::transform_printf_arg (std::forward<Args> (args)))...>::value);
|
||||
call_helper_void (func, format, printf_helper::transform_printf_arg (std::forward<Args> (args))...);
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename Func>
|
||||
static auto call_helper (const Func& func, const char* format, ...) G_GNUC_PRINTF (1, 2) -> decltype(func("", va_list()))
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
auto ret = func(format, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename Func>
|
||||
static void call_helper_void (const Func& func, const char* format, ...) G_GNUC_PRINTF (1, 2)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
func (format, args);
|
||||
va_end (args);
|
||||
}
|
||||
};
|
||||
|
||||
class gstr
|
||||
{
|
||||
public:
|
||||
@ -87,6 +162,7 @@ public:
|
||||
|
||||
operator const char*() const;
|
||||
const char* get() const { return static_cast<const char*>(*this); }
|
||||
const char* get_non_null() const { return is_null() ? "" : get(); }
|
||||
|
||||
char* get_mutable();
|
||||
char* release_owned();
|
||||
@ -100,8 +176,19 @@ public:
|
||||
operator bool() const = delete;
|
||||
bool operator!() const = delete;
|
||||
|
||||
static gstr printf(const char* format, ...) G_GNUC_PRINTF(1, 2);
|
||||
static gstr vprintf(const char* format, va_list args);
|
||||
static gstr vprintf(const char* format, va_list args) G_GNUC_PRINTF (1, 0);
|
||||
|
||||
template<typename ...Args>
|
||||
static gstr printf(const char* format, Args&& ...args) G_GNUC_PRINTF (1, 2)
|
||||
{
|
||||
return printf_helper::callv(g_strdup_vprintf, format, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
void set_printf (const char* format, Args&& ...args) G_GNUC_PRINTF (1, 2)
|
||||
{
|
||||
set_new (printf_helper::callv (g_strdup_vprintf, format, std::forward<Args> (args)...));
|
||||
}
|
||||
|
||||
private:
|
||||
void assign(const char* s, mem_transfer mt);
|
||||
@ -113,6 +200,24 @@ private:
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline const T& printf_helper::transform_printf_arg (const T& arg)
|
||||
{
|
||||
g_assert (is_valid_arg<T>::value);
|
||||
return arg;
|
||||
}
|
||||
|
||||
inline const char* printf_helper::transform_printf_arg (const gstr& s)
|
||||
{
|
||||
return s.get ();
|
||||
}
|
||||
|
||||
inline const char* printf_helper::transform_printf_arg (const gstrp& s)
|
||||
{
|
||||
return s.get ();
|
||||
}
|
||||
|
||||
|
||||
inline gstr wrap (const char *s) { return gstr::wrap (s); }
|
||||
inline gstr wrap_new (char *s) { return gstr::wrap_new (s); }
|
||||
inline gstr wrap_const (const char *s) { return gstr::wrap_const (s); }
|
||||
@ -238,12 +343,26 @@ public:
|
||||
void erase(gssize pos = 0, gssize len = -1);
|
||||
void ascii_down();
|
||||
void ascii_up();
|
||||
void vprintf(const char* format, va_list args);
|
||||
void printf(const char* format, ...) G_GNUC_PRINTF(1, 2);
|
||||
void append_vprintf(const char* format, va_list args);
|
||||
void append_printf(const char* format, ...) G_GNUC_PRINTF(1, 2);
|
||||
void vprintf(const char* format, va_list args) G_GNUC_PRINTF (1, 0);
|
||||
void append_vprintf(const char* format, va_list args) G_GNUC_PRINTF (1, 0);
|
||||
void append_uri_escaped(const char* unescaped, const char* reserved_chars_allowed = nullptr, bool allow_utf8 = false);
|
||||
|
||||
template<typename ...Args>
|
||||
void printf (const char* format, Args&& ...args) G_GNUC_PRINTF (1, 2)
|
||||
{
|
||||
g_return_if_fail (m_buf);
|
||||
printf_helper::callv_void ([&] (const char* format, va_list args) { g_string_vprintf (m_buf, format, args); },
|
||||
format, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
void append_printf (const char* format, Args&& ...args) G_GNUC_PRINTF (1, 2)
|
||||
{
|
||||
g_return_if_fail (m_buf);
|
||||
printf_helper::callv_void ([&] (const char* format, va_list args) { g_string_append_vprintf (m_buf, format, args); },
|
||||
format, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
mutable GString* m_buf;
|
||||
mutable gstrp m_result;
|
||||
@ -251,21 +370,40 @@ private:
|
||||
|
||||
//gstrvec convert(gstrv v);
|
||||
|
||||
} // namespace moo
|
||||
void g_free(const gstr&) = delete;
|
||||
void g_free(const gstrp&) = delete;
|
||||
void g_free(const gstrv&) = delete;
|
||||
void g_strfreev(const gstrv&) = delete;
|
||||
|
||||
void g_free(const moo::gstr&) = delete;
|
||||
void g_free(const moo::gstrp&) = delete;
|
||||
void g_free(const moo::gstrv&) = delete;
|
||||
void g_strfreev(const moo::gstrv&) = delete;
|
||||
} // namespace moo
|
||||
|
||||
namespace std {
|
||||
|
||||
template<>
|
||||
struct hash<moo::gstr>
|
||||
struct hash<::moo::gstr>
|
||||
{
|
||||
const size_t operator()(const moo::gstr& s) const;
|
||||
const size_t operator()(const ::moo::gstr& s) const;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
template<typename ...Args>
|
||||
inline void moo_g_print(const char* format, Args&& ...args)
|
||||
{
|
||||
static_assert(moo::printf_helper::is_valid_arg<Args...>::value, "Passed an object to g_strdup_printf");
|
||||
g_print (format, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
inline char* moo_g_strdup_printf (const char* format, Args&& ...args)
|
||||
{
|
||||
static_assert(moo::printf_helper::is_valid_arg<Args...>::value, "Passed an object to g_strdup_printf");
|
||||
return g_strdup_printf (format, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
#undef g_strdup_printf
|
||||
#undef g_print
|
||||
#define g_strdup_printf moo_g_strdup_printf
|
||||
#define g_print moo_g_print
|
||||
|
||||
#endif // __cplusplus
|
||||
|
@ -18,10 +18,12 @@
|
||||
#ifndef __cplusplus
|
||||
|
||||
#define MOO_CPP_DECLS(code)
|
||||
#define MOO_CPP_DFLT_PARAM(val)
|
||||
|
||||
#else // __cplusplus
|
||||
|
||||
#define MOO_CPP_DECLS(code) G_END_DECLS code G_BEGIN_DECLS
|
||||
#define MOO_CPP_DFLT_PARAM(val) = val
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
@ -29,7 +31,6 @@
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <mooglib/moo-glib.h>
|
||||
#include <mooutils/mooutils-messages.h>
|
||||
|
||||
namespace moo {
|
||||
|
||||
|
@ -534,8 +534,8 @@ _moo_edit_try_encoding_dialog (g::File file,
|
||||
if (!filename.empty())
|
||||
{
|
||||
/* Could not open file foo.txt */
|
||||
gstr tmp = gstr::printf(_("Could not open file\n%s"), filename.get());
|
||||
msg = g::markup_printf_escaped("<b><big>%s</big></b>", tmp.get());
|
||||
gstr tmp = gstr::printf(_("Could not open file\n%s"), filename);
|
||||
msg = g::markup_printf_escaped("<b><big>%s</big></b>", tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -599,7 +599,7 @@ _moo_edit_open_error_dialog (GtkWidget* widget,
|
||||
|
||||
if (!filename.empty())
|
||||
/* Could not open file foo.txt */
|
||||
msg.set_new (g_strdup_printf (_("Could not open file\n%s"), filename.get()));
|
||||
msg.set_printf (_("Could not open file\n%s"), filename);
|
||||
else
|
||||
msg.set_const (_("Could not open file"));
|
||||
|
||||
|
@ -34,13 +34,10 @@
|
||||
|
||||
using namespace moo;
|
||||
|
||||
#if 0 && MOO_DEBUG
|
||||
#define DEBUG_MESSAGE g_message
|
||||
#else
|
||||
static void G_GNUC_PRINTF(1,2) DEBUG_MESSAGE (G_GNUC_UNUSED const char *format, ...)
|
||||
template<typename ...Args>
|
||||
static void DEBUG_MESSAGE (const char*, Args&& ...args) G_GNUC_PRINTF (1, 2)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#define BROKEN_NAME "<" "????" ">"
|
||||
#define FOLDERS_CACHE_SIZE 10
|
||||
|
@ -48,7 +48,8 @@ G_STMT_START { \
|
||||
#if 0
|
||||
#define PRINT_TIMES g_print
|
||||
#else
|
||||
static void G_GNUC_PRINTF(1,2) PRINT_TIMES (G_GNUC_UNUSED const char *format, ...)
|
||||
template<typename ...Args>
|
||||
static void PRINT_TIMES (const char*, Args&& ...) G_GNUC_PRINTF (1, 2)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
@ -761,7 +761,7 @@ fam_thread_check_dir (FAMThread *thr,
|
||||
if (!FindNextChangeNotification (thr->events[idx]))
|
||||
{
|
||||
gstr win_msg = g::win32_error_message(GetLastError());
|
||||
gstr msg = gstr::printf("Error in FindNextChangeNotification: %s", win_msg.get());
|
||||
gstr msg = gstr::printf("Error in FindNextChangeNotification: %s", win_msg);
|
||||
|
||||
fam_thread_event (MOO_FILE_WATCH_ERROR_FAILED, TRUE, msg,
|
||||
thr->watches[idx].watch_id,
|
||||
|
@ -34,9 +34,7 @@ struct MooFileWriter
|
||||
virtual ~MooFileWriter() {}
|
||||
|
||||
virtual bool write (const char* data,
|
||||
gsize len) = 0;
|
||||
virtual bool printf (const char* fmt,
|
||||
va_list args) G_GNUC_PRINTF (2, 0) = 0;
|
||||
gssize len = -1) = 0;
|
||||
virtual bool close (moo::gerrp& error) = 0;
|
||||
};
|
||||
|
||||
@ -46,9 +44,7 @@ struct MooLocalFileWriter : public MooFileWriter
|
||||
~MooLocalFileWriter();
|
||||
|
||||
bool write (const char* data,
|
||||
gsize len) override;
|
||||
bool printf (const char* fmt,
|
||||
va_list args) G_GNUC_PRINTF (2, 0) override;
|
||||
gssize len = -1) override;
|
||||
bool close (moo::gerrp& error) override;
|
||||
|
||||
MOO_DISABLE_COPY_OPS(MooLocalFileWriter);
|
||||
@ -65,9 +61,7 @@ struct MooStringWriter : public MooFileWriter
|
||||
~MooStringWriter();
|
||||
|
||||
bool write (const char* data,
|
||||
gsize len) override;
|
||||
bool printf (const char* fmt,
|
||||
va_list args) G_GNUC_PRINTF (2, 0) override;
|
||||
gssize len = -1) override;
|
||||
bool close (moo::gerrp& error) override;
|
||||
|
||||
MOO_DISABLE_COPY_OPS(MooStringWriter);
|
||||
|
@ -159,27 +159,26 @@ moo_file_writer_write (MooFileWriter *writer,
|
||||
}
|
||||
|
||||
gboolean
|
||||
moo_file_writer_printf (MooFileWriter *writer,
|
||||
const char *fmt,
|
||||
...)
|
||||
moo_file_writer_printf_c (MooFileWriter *writer,
|
||||
const char *fmt,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
gboolean ret;
|
||||
|
||||
g_return_val_if_fail (writer != nullptr, FALSE);
|
||||
g_return_val_if_fail (fmt != NULL, FALSE);
|
||||
|
||||
va_start (args, fmt);
|
||||
ret = writer->printf (fmt, args);
|
||||
gstr s = gstr::vprintf (fmt, args);
|
||||
va_end (args);
|
||||
|
||||
return ret;
|
||||
return writer->write (s);
|
||||
}
|
||||
|
||||
gboolean
|
||||
moo_file_writer_printf_markup (MooFileWriter *writer,
|
||||
const char *fmt,
|
||||
...)
|
||||
moo_file_writer_printf_markup_c (MooFileWriter *writer,
|
||||
const char *fmt,
|
||||
...)
|
||||
{
|
||||
g_return_val_if_fail (writer != nullptr, FALSE);
|
||||
g_return_val_if_fail (fmt != NULL, FALSE);
|
||||
@ -322,11 +321,14 @@ moo_config_writer_new (const char *filename,
|
||||
}
|
||||
|
||||
|
||||
bool MooLocalFileWriter::write (const char* data, gsize len)
|
||||
bool MooLocalFileWriter::write (const char* data, gssize len)
|
||||
{
|
||||
if (error)
|
||||
return FALSE;
|
||||
|
||||
if (len < 0)
|
||||
len = strlen(data);
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
gsize chunk_len = len;
|
||||
@ -368,15 +370,6 @@ bool MooLocalFileWriter::write (const char* data, gsize len)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool MooLocalFileWriter::printf (const char* fmt, va_list args)
|
||||
{
|
||||
if (error)
|
||||
return FALSE;
|
||||
|
||||
gstr text = gstr::vprintf (fmt, args);
|
||||
return write (text, strlen (text));
|
||||
}
|
||||
|
||||
bool MooLocalFileWriter::close (gerrp& out_error)
|
||||
{
|
||||
g_return_val_if_fail (stream != nullptr, FALSE);
|
||||
@ -399,23 +392,12 @@ bool MooLocalFileWriter::close (gerrp& out_error)
|
||||
/* MooStringWriter
|
||||
*/
|
||||
|
||||
bool MooStringWriter::write (const char* data, gsize len)
|
||||
bool MooStringWriter::write (const char* data, gssize len)
|
||||
{
|
||||
g_string_append_len (string, data, len);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool MooStringWriter::printf (const char* fmt, va_list args)
|
||||
{
|
||||
gstrp buf;
|
||||
gint len = g_vasprintf (buf.pp(), fmt, args);
|
||||
|
||||
if (len >= 0)
|
||||
g_string_append_len (string, buf.get(), len);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool MooStringWriter::close (G_GNUC_UNUSED gerrp& error)
|
||||
{
|
||||
g_string_free (string, TRUE);
|
||||
|
@ -76,14 +76,41 @@ MooFileWriter *moo_config_writer_new (const char *filename,
|
||||
GError **error);
|
||||
gboolean moo_file_writer_write (MooFileWriter *writer,
|
||||
const char *data,
|
||||
gssize len);
|
||||
gboolean moo_file_writer_printf (MooFileWriter *writer,
|
||||
gssize len MOO_CPP_DFLT_PARAM(-1));
|
||||
gboolean moo_file_writer_printf_c (MooFileWriter *writer,
|
||||
const char *fmt,
|
||||
...) G_GNUC_PRINTF (2, 3);
|
||||
gboolean moo_file_writer_printf_markup (MooFileWriter *writer,
|
||||
gboolean moo_file_writer_printf_markup_c (MooFileWriter *writer,
|
||||
const char *fmt,
|
||||
...) G_GNUC_PRINTF (2, 3);
|
||||
gboolean moo_file_writer_close (MooFileWriter *writer,
|
||||
GError **error);
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
||||
#define moo_file_writer_printf moo_file_writer_printf_c
|
||||
#define moo_file_writer_printf_markup moo_file_writer_printf_markup_c
|
||||
|
||||
#endif // !__cplusplus
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
template<typename ...Args>
|
||||
inline bool moo_file_writer_printf (MooFileWriter *writer, const char* fmt, Args&& ...args) G_GNUC_PRINTF (2, 3)
|
||||
{
|
||||
gstr s = gstr::printf (fmt, std::forward<Args> (args)...);
|
||||
return moo_file_writer_write (writer, s);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
inline bool moo_file_writer_printf_markup (MooFileWriter *writer,
|
||||
const char *fmt,
|
||||
Args&&... args) G_GNUC_PRINTF (2, 3)
|
||||
{
|
||||
gstr s = g::markup_printf_escaped (fmt, std::forward<Args> (args)...);
|
||||
return moo_file_writer_write (writer, s);
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
@ -1786,6 +1786,7 @@ parse_property (GParamSpec *param_spec,
|
||||
param_spec->value_type == G_TYPE_LONG ||
|
||||
param_spec->value_type == G_TYPE_INT64) /* XXX */
|
||||
{
|
||||
errno = 0;
|
||||
long val = strtol (value, NULL, 0);
|
||||
|
||||
if (errno)
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <mooutils/mooutils-macros.h>
|
||||
#include <stdarg.h>
|
||||
#include <moocpp/strutils.h>
|
||||
#include <mooglib/moo-glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
@ -105,10 +106,38 @@ moo_make_code_loc (const char *file, const char *func, int line, int counter)
|
||||
return loc;
|
||||
}
|
||||
|
||||
void _moo_log (MooCodeLoc loc, GLogLevelFlags flags, const char *format, ...) G_GNUC_PRINTF (3, 4);
|
||||
void _moo_logv (MooCodeLoc loc, GLogLevelFlags flags, const char *format, va_list args) G_GNUC_PRINTF(3, 0);
|
||||
void MOO_NORETURN _moo_error (MooCodeLoc loc, const char *format, ...) G_GNUC_PRINTF (2, 3);
|
||||
void MOO_NORETURN _moo_errorv (MooCodeLoc loc, const char *format, va_list args) G_GNUC_PRINTF(2, 0);
|
||||
void _moo_log_c (MooCodeLoc loc, GLogLevelFlags flags, const char *format, ...) G_GNUC_PRINTF (3, 4);
|
||||
void _moo_logv (MooCodeLoc loc, GLogLevelFlags flags, const char *format, va_list args) G_GNUC_PRINTF (3, 0);
|
||||
void MOO_NORETURN _moo_error_c (MooCodeLoc loc, const char *format, ...) G_GNUC_PRINTF (2, 3);
|
||||
void MOO_NORETURN _moo_errorv (MooCodeLoc loc, const char *format, va_list args) G_GNUC_PRINTF (2, 0);
|
||||
|
||||
#ifndef __cplusplus
|
||||
#define _moo_log _moo_log_c
|
||||
#define _moo_error _moo_error_c
|
||||
#else // __cplusplus
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
void _moo_log_impl (MooCodeLoc loc, GLogLevelFlags flags, moo::gstr message);
|
||||
void MOO_NORETURN _moo_error_impl (MooCodeLoc loc, moo::gstr message);
|
||||
|
||||
template<typename ...Args>
|
||||
inline void _moo_log (MooCodeLoc loc, GLogLevelFlags flags, const char *format, Args&& ...args) G_GNUC_PRINTF (3, 4)
|
||||
{
|
||||
moo::gstr message = moo::gstr::printf (format, std::forward<Args> (args)...);
|
||||
_moo_log_impl (loc, flags, std::move (message));
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
inline void MOO_NORETURN _moo_error (MooCodeLoc loc, const char *format, Args&& ...args) G_GNUC_PRINTF (2, 3)
|
||||
{
|
||||
moo::gstr message = moo::gstr::printf (format, std::forward<Args> (args)...);
|
||||
_moo_error_impl (loc, std::move (message));
|
||||
}
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
void MOO_NORETURN _moo_assert_message (MooCodeLoc loc, const char *message);
|
||||
|
||||
@ -262,3 +291,17 @@ _MOO_DEFINE_LOG_FUNC (debug, DEBUG)
|
||||
#define g_return_val_if_reached moo_return_val_if_reached
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
template<typename ...Args>
|
||||
inline void moo_g_log_checked (const char* domain, GLogLevelFlags flags, const char* format, Args&& ...args) G_GNUC_PRINTF (3, 4)
|
||||
{
|
||||
static_assert(moo::printf_helper::is_valid_arg<Args...>::value, "Passed an object to g_log");
|
||||
g_log (domain, flags, format, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
#undef g_log
|
||||
#define g_log moo_g_log_checked
|
||||
|
||||
#endif // __cplusplus
|
@ -59,7 +59,7 @@
|
||||
|
||||
using namespace moo;
|
||||
|
||||
MOO_DEFINE_QUARK(moo - error, moo_error_quark)
|
||||
MOO_DEFINE_QUARK(moo-error, moo_error_quark)
|
||||
|
||||
static gpointer copy_pointer(gpointer p)
|
||||
{
|
||||
@ -1810,27 +1810,46 @@ moo_log_debug_enabled (void)
|
||||
return enabled;
|
||||
}
|
||||
|
||||
void _moo_logv (MooCodeLoc loc, GLogLevelFlags flags, const char *format, va_list args)
|
||||
void _moo_log_impl (MooCodeLoc loc, GLogLevelFlags flags, moo::gstr message)
|
||||
{
|
||||
char *message;
|
||||
|
||||
if (flags >= G_LOG_LEVEL_DEBUG && !moo_log_debug_enabled ())
|
||||
return;
|
||||
|
||||
message = g_strdup_vprintf (format, args);
|
||||
|
||||
if (!loc.empty())
|
||||
g_log (G_LOG_DOMAIN, flags,
|
||||
/* Translators: remove the part before and including | */
|
||||
Q_("console message|in file %s, line %d, function %s: %s"),
|
||||
loc.file, loc.line, loc.func, message);
|
||||
loc.file, loc.line, loc.func, message.get ());
|
||||
else
|
||||
g_log (G_LOG_DOMAIN, flags, "%s", message);
|
||||
|
||||
g_free (message);
|
||||
g_log (G_LOG_DOMAIN, flags, "%s", message.get ());
|
||||
}
|
||||
|
||||
void MOO_NORETURN _moo_error (MooCodeLoc loc, const char *format, ...)
|
||||
void _moo_log_c (MooCodeLoc loc, GLogLevelFlags flags, const char *format, ...)
|
||||
{
|
||||
if (flags >= G_LOG_LEVEL_DEBUG && !moo_log_debug_enabled ())
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
_moo_log_impl (loc, flags, gstr::vprintf (format, args));
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
void _moo_logv (MooCodeLoc loc, GLogLevelFlags flags, const char *format, va_list args)
|
||||
{
|
||||
if (flags >= G_LOG_LEVEL_DEBUG && !moo_log_debug_enabled ())
|
||||
return;
|
||||
|
||||
_moo_log_impl (loc, flags, gstr::vprintf (format, args));
|
||||
}
|
||||
|
||||
void MOO_NORETURN _moo_error_impl (MooCodeLoc, moo::gstr message)
|
||||
{
|
||||
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, "%s", message.get_non_null ());
|
||||
moo_abort ();
|
||||
}
|
||||
|
||||
void MOO_NORETURN _moo_error_c (MooCodeLoc loc, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
|
@ -39,16 +39,16 @@
|
||||
|
||||
using namespace moo;
|
||||
|
||||
#define PREFS_REMEMBER_SIZE "window/remember_size"
|
||||
#define PREFS_X "window/x"
|
||||
#define PREFS_Y "window/y"
|
||||
#define PREFS_WIDTH "window/width"
|
||||
#define PREFS_HEIGHT "window/height"
|
||||
#define PREFS_MAXIMIZED "window/maximized"
|
||||
#define PREFS_SHOW_TOOLBAR "window/show_toolbar"
|
||||
#define PREFS_SHOW_MENUBAR "window/show_menubar"
|
||||
#define PREFS_SHOW_STATUSBAR "window/show_statusbar"
|
||||
#define PREFS_TOOLBAR_STYLE "window/toolbar_style"
|
||||
const gstr PREFS_REMEMBER_SIZE = gstr::wrap_const ("window/remember_size");
|
||||
const gstr PREFS_X = gstr::wrap_const ("window/x");
|
||||
const gstr PREFS_Y = gstr::wrap_const ("window/y");
|
||||
const gstr PREFS_WIDTH = gstr::wrap_const ("window/width");
|
||||
const gstr PREFS_HEIGHT = gstr::wrap_const ("window/height");
|
||||
const gstr PREFS_MAXIMIZED = gstr::wrap_const ("window/maximized");
|
||||
const gstr PREFS_SHOW_TOOLBAR = gstr::wrap_const ("window/show_toolbar");
|
||||
const gstr PREFS_SHOW_MENUBAR = gstr::wrap_const ("window/show_menubar");
|
||||
const gstr PREFS_SHOW_STATUSBAR = gstr::wrap_const ("window/show_statusbar");
|
||||
const gstr PREFS_TOOLBAR_STYLE = gstr::wrap_const ("window/toolbar_style");
|
||||
|
||||
#define DEFAULT_X -1000000 // an impossible window position
|
||||
#define DEFAULT_Y -1000000 // an impossible window position
|
||||
@ -59,33 +59,41 @@ static char *default_geometry = NULL;
|
||||
|
||||
static GSList *window_instances = NULL;
|
||||
|
||||
struct MooWindowPrivate {
|
||||
guint save_size_id;
|
||||
struct MooWindowPrivate
|
||||
{
|
||||
MooWindowPrivate()
|
||||
{
|
||||
global_accels_mode = false;
|
||||
}
|
||||
|
||||
char *toolbar_ui_name;
|
||||
GtkWidget *toolbar_holder;
|
||||
guint save_size_id = 0;
|
||||
|
||||
gstr toolbar_ui_name;
|
||||
GtkWidget *toolbar_holder = nullptr;
|
||||
gboolean toolbar_visible;
|
||||
|
||||
char *menubar_ui_name;
|
||||
GtkWidget *menubar_holder;
|
||||
gstr menubar_ui_name;
|
||||
GtkWidget *menubar_holder = nullptr;
|
||||
gboolean menubar_visible;
|
||||
|
||||
gboolean statusbar_visible;
|
||||
|
||||
MooUiXml *ui_xml;
|
||||
MooActionCollection *actions;
|
||||
char *name;
|
||||
char *id;
|
||||
gobj_ptr<MooUiXml> ui_xml;
|
||||
gobj_ptr<MooActionCollection> actions;
|
||||
gstr name;
|
||||
gstr id;
|
||||
|
||||
GSList *global_accels;
|
||||
guint update_accels_idle;
|
||||
GSList *global_accels = nullptr;
|
||||
guint update_accels_idle = 0;
|
||||
|
||||
GtkWidget *eo_widget;
|
||||
GtkWidget *default_eo_widget;
|
||||
GtkWidget *uo_widget;
|
||||
GtkWidget *default_uo_widget;
|
||||
GtkWidget *eo_widget = nullptr;
|
||||
GtkWidget *default_eo_widget = nullptr;
|
||||
GtkWidget *uo_widget = nullptr;
|
||||
GtkWidget *default_uo_widget = nullptr;
|
||||
|
||||
guint global_accels_mode : 1;
|
||||
|
||||
gstrmap settings;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@ -94,19 +102,23 @@ typedef struct {
|
||||
GtkAction *action;
|
||||
} AccelEntry;
|
||||
|
||||
static const char *setting (MooWindow *window, const char *s)
|
||||
static const gstr& setting (MooWindow *window, const gstr& s)
|
||||
{
|
||||
static GString *key = NULL;
|
||||
g_return_val_if_fail (!s.empty(), gstr::null);
|
||||
|
||||
if (!key)
|
||||
key = g_string_new (NULL);
|
||||
auto itr = window->priv->settings.find(s);
|
||||
if (itr != window->priv->settings.end())
|
||||
return itr->second;
|
||||
|
||||
if (window->priv->id)
|
||||
g_string_printf (key, "%s/%s", window->priv->id, s);
|
||||
gstr key;
|
||||
|
||||
if (!window->priv->id.empty())
|
||||
key = gstr::printf ("%s/%s", window->priv->id, s);
|
||||
else
|
||||
g_string_assign (key, s);
|
||||
key = s;
|
||||
|
||||
return key->str;
|
||||
auto pr = window->priv->settings.insert (std::make_pair (s, std::move (key)));
|
||||
return pr.first->second;
|
||||
}
|
||||
|
||||
static void init_prefs (MooWindow *window);
|
||||
@ -581,7 +593,7 @@ moo_window_init (MooWindow *window)
|
||||
{
|
||||
GtkWidget *rg;
|
||||
|
||||
window->priv = g_new0 (MooWindowPrivate, 1);
|
||||
window->priv = new (MooWindowPrivate);
|
||||
|
||||
window->vbox = gtk_vbox_new (FALSE, 0);
|
||||
gtk_widget_show (window->vbox);
|
||||
@ -637,13 +649,10 @@ moo_window_dispose (GObject *object)
|
||||
window->priv->default_uo_widget = NULL;
|
||||
moo_window_disconnect_uo_widget (window);
|
||||
|
||||
if (window->priv->ui_xml)
|
||||
g_object_unref (window->priv->ui_xml);
|
||||
|
||||
if (window->priv->actions)
|
||||
{
|
||||
_moo_action_collection_set_window (window->priv->actions, NULL);
|
||||
g_object_unref (window->priv->actions);
|
||||
_moo_action_collection_set_window (window->priv->actions.gobj (), NULL);
|
||||
window->priv->actions.reset ();
|
||||
}
|
||||
|
||||
g_slist_foreach (window->priv->global_accels,
|
||||
@ -653,11 +662,6 @@ moo_window_dispose (GObject *object)
|
||||
if (window->priv->update_accels_idle)
|
||||
g_source_remove (window->priv->update_accels_idle);
|
||||
|
||||
g_free (window->priv->name);
|
||||
g_free (window->priv->id);
|
||||
g_free (window->priv->menubar_ui_name);
|
||||
g_free (window->priv->toolbar_ui_name);
|
||||
|
||||
if (window->accel_group)
|
||||
g_object_unref (window->accel_group);
|
||||
|
||||
@ -665,7 +669,7 @@ moo_window_dispose (GObject *object)
|
||||
g_source_remove (window->priv->save_size_id);
|
||||
window->priv->save_size_id = 0;
|
||||
|
||||
g_free (window->priv);
|
||||
delete window->priv;
|
||||
window->priv = NULL;
|
||||
}
|
||||
|
||||
@ -716,7 +720,7 @@ update_accels (MooWindow *window)
|
||||
g_slist_free (window->priv->global_accels);
|
||||
window->priv->global_accels = NULL;
|
||||
|
||||
for (l = moo_action_collection_get_groups (window->priv->actions); l != NULL; l = l->next)
|
||||
for (l = moo_action_collection_get_groups (window->priv->actions.gobj ()); l != NULL; l = l->next)
|
||||
{
|
||||
GtkActionGroup *group = GTK_ACTION_GROUP (l->data);
|
||||
GList *actions;
|
||||
@ -919,13 +923,13 @@ moo_window_set_property (GObject *object,
|
||||
{
|
||||
case PROP_TOOLBAR_UI_NAME:
|
||||
name = g_value_get_string (value);
|
||||
MOO_ASSIGN_STRING (window->priv->toolbar_ui_name, MOO_NZS (name));
|
||||
window->priv->toolbar_ui_name.set (name);
|
||||
g_object_notify (object, "toolbar-ui-name");
|
||||
break;
|
||||
|
||||
case PROP_MENUBAR_UI_NAME:
|
||||
name = g_value_get_string (value);
|
||||
MOO_ASSIGN_STRING (window->priv->menubar_ui_name, MOO_NZS (name));
|
||||
window->priv->menubar_ui_name.set (name);
|
||||
g_object_notify (object, "menubar-ui-name");
|
||||
break;
|
||||
|
||||
@ -982,7 +986,7 @@ moo_window_get_property (GObject *object,
|
||||
break;
|
||||
|
||||
case PROP_UI_XML:
|
||||
g_value_set_object (value, window->priv->ui_xml);
|
||||
g_value_set_object (value, window->priv->ui_xml.gobj ());
|
||||
break;
|
||||
|
||||
case PROP_MENUBAR:
|
||||
@ -1066,15 +1070,13 @@ moo_window_update_toolbar (MooWindow *window)
|
||||
{
|
||||
MooUiXml *xml;
|
||||
GtkToolbarStyle style;
|
||||
char *ui_name;
|
||||
MooActionCollection *actions;
|
||||
|
||||
g_return_if_fail (MOO_IS_WINDOW (window));
|
||||
|
||||
actions = moo_window_get_actions (window);
|
||||
xml = moo_window_get_ui_xml (window);
|
||||
ui_name = window->priv->toolbar_ui_name;
|
||||
ui_name = ui_name && ui_name[0] ? ui_name : NULL;
|
||||
const gstr& ui_name = window->priv->toolbar_ui_name;
|
||||
|
||||
if (window->toolbar)
|
||||
{
|
||||
@ -1084,14 +1086,14 @@ moo_window_update_toolbar (MooWindow *window)
|
||||
old_xml = object_cast_opt<MooUiXml> (g_object_get_data (G_OBJECT (window->toolbar), "moo-window-ui-xml"));
|
||||
old_name = reinterpret_cast<char*> (g_object_get_data (G_OBJECT (window->toolbar), "moo-window-ui-name"));
|
||||
|
||||
if (!old_xml || old_xml != xml || !ui_name || strcmp (ui_name, old_name))
|
||||
if (!old_xml || old_xml != xml || ui_name != old_name)
|
||||
{
|
||||
gtk_widget_destroy (window->toolbar);
|
||||
window->toolbar = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (window->toolbar || !xml || !ui_name)
|
||||
if (window->toolbar || !xml || ui_name.empty())
|
||||
return;
|
||||
|
||||
window->toolbar = moo_ui_xml_create_widget (xml, MOO_UI_TOOLBAR,
|
||||
@ -1118,15 +1120,13 @@ static void
|
||||
moo_window_update_menubar (MooWindow *window)
|
||||
{
|
||||
MooUiXml *xml;
|
||||
char *ui_name;
|
||||
MooActionCollection *actions;
|
||||
|
||||
g_return_if_fail (MOO_IS_WINDOW (window));
|
||||
|
||||
actions = moo_window_get_actions (window);
|
||||
xml = moo_window_get_ui_xml (window);
|
||||
ui_name = window->priv->menubar_ui_name;
|
||||
ui_name = ui_name && ui_name[0] ? ui_name : NULL;
|
||||
const gstr& ui_name = window->priv->menubar_ui_name;
|
||||
|
||||
if (window->menubar)
|
||||
{
|
||||
@ -1136,14 +1136,14 @@ moo_window_update_menubar (MooWindow *window)
|
||||
old_xml = object_cast_opt<MooUiXml> (g_object_get_data (G_OBJECT (window->menubar), "moo-window-ui-xml"));
|
||||
old_name = reinterpret_cast<char*> (g_object_get_data (G_OBJECT (window->menubar), "moo-window-ui-name"));
|
||||
|
||||
if (!old_xml || old_xml != xml || !ui_name || strcmp (ui_name, old_name))
|
||||
if (!old_xml || old_xml != xml || ui_name != old_name)
|
||||
{
|
||||
gtk_widget_destroy (window->menubar);
|
||||
window->menubar = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (window->menubar || !xml || !ui_name)
|
||||
if (window->menubar || !xml || ui_name.empty ())
|
||||
return;
|
||||
|
||||
window->menubar = moo_ui_xml_create_widget (xml, MOO_UI_MENUBAR,
|
||||
@ -1184,7 +1184,7 @@ static void
|
||||
set_ui_elm_visible (MooWindow *window,
|
||||
gboolean *flag,
|
||||
const char *prop,
|
||||
const char *prefs_key,
|
||||
const gstr& prefs_key,
|
||||
GtkWidget *widget,
|
||||
gboolean visible)
|
||||
{
|
||||
@ -1740,7 +1740,7 @@ moo_window_class_new_group (MooWindowClass *klass,
|
||||
if (g_type_is_a (G_OBJECT_TYPE (l->data), type))
|
||||
{
|
||||
MooWindow *window = MOO_WINDOW (l->data);
|
||||
moo_action_collection_add_group (window->priv->actions, name, display_name);
|
||||
moo_action_collection_add_group (window->priv->actions.gobj (), name, display_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1785,9 +1785,9 @@ moo_window_class_remove_group (MooWindowClass *klass,
|
||||
if (g_type_is_a (G_OBJECT_TYPE (l->data), type))
|
||||
{
|
||||
MooWindow *window = MOO_WINDOW (l->data);
|
||||
GtkActionGroup *group = moo_action_collection_get_group (window->priv->actions, name);
|
||||
GtkActionGroup *group = moo_action_collection_get_group (window->priv->actions.gobj (), name);
|
||||
if (group)
|
||||
moo_action_collection_remove_group (window->priv->actions, group);
|
||||
moo_action_collection_remove_group (window->priv->actions.gobj (), group);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1797,7 +1797,7 @@ MooUiXml*
|
||||
moo_window_get_ui_xml (MooWindow *window)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_WINDOW (window), NULL);
|
||||
return window->priv->ui_xml;
|
||||
return window->priv->ui_xml.gobj ();
|
||||
}
|
||||
|
||||
|
||||
@ -1811,10 +1811,7 @@ moo_window_set_ui_xml (MooWindow *window,
|
||||
if (xml && xml == window->priv->ui_xml)
|
||||
return;
|
||||
|
||||
if (window->priv->ui_xml)
|
||||
g_object_unref (window->priv->ui_xml);
|
||||
|
||||
window->priv->ui_xml = xml ? object_ref (xml) : moo_ui_xml_new ();
|
||||
window->priv->ui_xml.set_new (xml ? object_ref (xml) : moo_ui_xml_new ());
|
||||
|
||||
g_object_notify (G_OBJECT (window), "ui-xml");
|
||||
}
|
||||
@ -1824,7 +1821,7 @@ MooActionCollection *
|
||||
moo_window_get_actions (MooWindow *window)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_WINDOW (window), NULL);
|
||||
return window->priv->actions;
|
||||
return window->priv->actions.gobj ();
|
||||
}
|
||||
|
||||
|
||||
@ -1834,7 +1831,7 @@ moo_window_get_action (MooWindow *window,
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_WINDOW (window), NULL);
|
||||
g_return_val_if_fail (action != NULL, NULL);
|
||||
return moo_action_collection_get_action (window->priv->actions, action);
|
||||
return moo_action_collection_get_action (window->priv->actions.gobj (), action);
|
||||
}
|
||||
|
||||
|
||||
@ -1843,10 +1840,7 @@ moo_window_set_id (MooWindow *window,
|
||||
const char *id)
|
||||
{
|
||||
if (id)
|
||||
{
|
||||
g_free (window->priv->id);
|
||||
window->priv->id = g_strdup (id);
|
||||
}
|
||||
window->priv->id.set (id);
|
||||
}
|
||||
|
||||
|
||||
@ -1869,7 +1863,7 @@ add_group (const char *name,
|
||||
const char *display_name,
|
||||
MooWindow *window)
|
||||
{
|
||||
moo_action_collection_add_group (window->priv->actions, name, display_name);
|
||||
moo_action_collection_add_group (window->priv->actions.gobj (), name, display_name);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1879,9 +1873,9 @@ moo_window_create_class_actions (MooWindow *window)
|
||||
|
||||
g_return_if_fail (MOO_IS_WINDOW (window));
|
||||
|
||||
window->priv->actions = moo_action_collection_new (window->priv->id,
|
||||
window->priv->name);
|
||||
_moo_action_collection_set_window (window->priv->actions, window);
|
||||
window->priv->actions.set_new (moo_action_collection_new (window->priv->id,
|
||||
window->priv->name));
|
||||
_moo_action_collection_set_window (window->priv->actions.gobj (), window);
|
||||
|
||||
type = G_OBJECT_TYPE (window);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user