medit/moo/mooutils/mooutils-misc.h

258 lines
9.2 KiB
C
Raw Normal View History

2005-10-31 22:58:01 +00:00
/*
* mooutils-misc.h
*
2016-10-02 21:14:12 -07:00
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
2005-10-31 22:58:01 +00:00
*
* This file is part of medit. medit is free software; you can
* redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License,
* or (at your option) any later version.
2005-10-31 22:58:01 +00:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
2005-10-31 22:58:01 +00:00
*/
2016-10-02 21:14:12 -07:00
#ifndef MOO_UTILS_MISC_H
#define MOO_UTILS_MISC_H
2005-10-31 22:58:01 +00:00
#include <gtk/gtk.h>
2016-10-02 21:14:12 -07:00
#include <mooutils/mooutils-messages.h>
2011-01-14 01:12:19 -08:00
#include <string.h>
2005-10-31 22:58:01 +00:00
G_BEGIN_DECLS
gboolean moo_open_url (const char *url);
gboolean moo_open_email (const char *address,
const char *subject,
const char *body);
2007-05-08 21:47:03 -05:00
gboolean moo_open_file (const char *path);
2005-10-31 22:58:01 +00:00
void moo_window_present (GtkWindow *window,
guint32 stamp);
2006-08-15 03:52:38 -05:00
GtkWindow *_moo_get_top_window (GSList *windows);
2005-10-31 22:58:01 +00:00
2007-05-07 00:26:18 -05:00
void _moo_window_set_icon_from_stock (GtkWindow *window,
const char *name);
2005-10-31 22:58:01 +00:00
void moo_log_window_show (void);
void moo_log_window_hide (void);
2006-03-15 02:16:42 -06:00
void moo_set_log_func_window (gboolean show_now);
2005-10-31 22:58:01 +00:00
void moo_set_log_func_file (const char *log_file);
2006-03-15 02:16:42 -06:00
void moo_set_log_func_silent (void);
2016-10-02 21:14:12 -07:00
void moo_reset_log_func (void);
2005-10-31 22:58:01 +00:00
2009-12-06 13:53:50 -08:00
void MOO_NORETURN moo_segfault (void);
void MOO_NORETURN moo_abort (void);
2005-11-17 07:04:35 +00:00
2013-04-20 22:14:56 -07:00
G_INLINE_FUNC void
2010-08-30 22:19:58 -07:00
seriously_ignore_return_value (G_GNUC_UNUSED int v)
{
/* gcc guys are funny, casting to void is not enough */
}
2013-04-20 22:14:56 -07:00
G_INLINE_FUNC void
2010-08-30 22:19:58 -07:00
seriously_ignore_return_value_p (G_GNUC_UNUSED void *p)
{
}
void moo_disable_win32_error_message (void);
void moo_enable_win32_error_message (void);
2005-10-31 22:58:01 +00:00
void _moo_set_app_instance_name (const char *name);
2008-09-15 00:01:53 -05:00
void moo_set_user_data_dir (const char *path);
void moo_set_user_cache_dir (const char *path);
void moo_set_display_app_name (const char *name);
const char *moo_get_display_app_name (void);
gboolean moo_make_user_data_dir (const char *path);
char *moo_get_user_data_dir (void);
char *moo_get_user_data_file (const char *basename);
char *moo_get_named_user_data_file (const char *basename);
gboolean moo_save_user_data_file (const char *basename,
const char *content,
gssize len,
GError **error);
2016-10-02 21:14:12 -07:00
char *moo_get_user_cache_dir (void);
char *moo_get_user_cache_file (const char *basename);
gboolean moo_save_user_cache_file (const char *basename,
const char *content,
gssize len,
GError **error);
2008-02-12 12:36:08 -06:00
gboolean moo_save_config_file (const char *filename,
const char *content,
gssize len,
GError **error);
/* user data comes first */
char **moo_get_data_dirs (void);
char **moo_get_lib_dirs (void);
char **moo_get_data_subdirs (const char *subdir);
char **moo_get_sys_data_subdirs (const char *subdir);
char **moo_get_lib_subdirs (const char *subdir);
char **moo_get_data_and_lib_subdirs (const char *subdir);
#define moo_get_data_files moo_get_data_subdirs
#define moo_get_sys_data_files moo_get_sys_data_subdirs
2010-11-01 02:39:58 -07:00
gboolean moo_getenv_bool (const char *var);
const char *moo_get_locale_dir (void);
void moo_selection_data_set_pointer (GtkSelectionData *data,
GdkAtom type,
gpointer ptr);
gpointer moo_selection_data_get_pointer (GtkSelectionData *data,
GdkAtom type);
2006-08-15 03:52:38 -05:00
GdkModifierType _moo_get_modifiers (GtkWidget *widget);
2007-12-03 22:08:34 -06:00
void _moo_menu_item_set_accel_label (GtkWidget *menu_item,
const char *label);
2007-12-03 22:08:34 -06:00
void _moo_menu_item_set_label (GtkWidget *menu_item,
const char *label,
gboolean mnemonic);
2007-12-03 22:08:34 -06:00
void _moo_widget_set_tooltip (GtkWidget *widget,
2006-04-26 18:14:18 -05:00
const char *tip);
2008-02-03 02:02:26 -06:00
typedef struct {
const char *text;
gsize len;
} MooLineReader;
void moo_line_reader_init (MooLineReader *lr,
const char *text,
gssize len);
const char *moo_line_reader_get_line (MooLineReader *lr,
gsize *line_len,
gsize *lt_len);
gboolean moo_find_line_end (const char *string,
gssize len,
gsize *le_start,
gsize *le_len);
char **moo_strnsplit_lines (const char *string,
gssize len,
guint *n_tokens);
2007-12-03 22:08:34 -06:00
char **moo_splitlines (const char *string);
2008-02-03 02:02:26 -06:00
2007-12-03 22:08:34 -06:00
char **_moo_strv_reverse (char **str_array);
2006-06-10 03:33:42 -05:00
2013-04-20 22:14:56 -07:00
G_INLINE_FUNC gboolean
2011-01-14 01:12:19 -08:00
moo_str_equal (const char *s1,
const char *s2)
{
return strcmp (s1 ? s1 : "", s2 ? s2 : "") == 0;
}
2006-09-02 02:29:39 -05:00
2013-04-20 22:14:56 -07:00
G_INLINE_FUNC const char *
2011-01-14 01:31:03 -08:00
moo_nonnull_str (const char *s)
{
return s ? s : "";
}
#define MOO_NZS(s) (moo_nonnull_str (s))
2013-04-20 22:14:56 -07:00
G_INLINE_FUNC void
2007-12-19 14:02:42 -06:00
moo_assign_string (char **where,
const char *value)
{
char *tmp = *where;
*where = g_strdup (value);
g_free (tmp);
}
#define MOO_ASSIGN_STRING(where, value) moo_assign_string (&(where), (value))
2013-04-20 22:14:56 -07:00
G_INLINE_FUNC void
2008-09-05 16:26:09 -05:00
moo_assign_strv (char ***where,
char **value)
{
char **tmp = *where;
*where = g_strdupv (value);
g_strfreev (tmp);
}
#define MOO_ASSIGN_STRV(where, value) moo_assign_strv (&(where), (value))
2013-05-04 11:02:59 -07:00
G_INLINE_FUNC void
moo_assign_obj (void** dest, void* src)
{
if (*dest != src)
{
void *tmp = *dest;
*dest = src;
if (src)
g_object_ref (src);
if (tmp)
g_object_unref (tmp);
}
}
#define MOO_ASSIGN_OBJ(dest, src) moo_assign_obj ((void**)&(dest), (src))
2006-08-19 00:20:55 -05:00
const char *_moo_get_pid_string (void);
2016-10-02 21:14:12 -07:00
gboolean _moo_regex_escape (const char *string,
gssize bytes,
GString *dest);
2016-10-02 21:14:12 -07:00
const char *moo_error_message (GError *error);
gboolean moo_signal_accumulator_continue_cancel (GSignalInvocationHint *ihint,
GValue *return_accu,
const GValue *handler_return,
gpointer val_continue);
void moo_thread_init (void);
gboolean moo_is_main_thread (void);
2005-10-31 22:58:01 +00:00
G_END_DECLS
2007-03-24 02:10:43 -05:00
#ifdef G_OS_WIN32
#include <gtk/gtk.h>
#include <string.h>
2016-10-02 21:14:12 -07:00
G_BEGIN_DECLS
2007-03-24 02:10:43 -05:00
2016-10-02 21:14:12 -07:00
char *moo_win32_get_app_dir (void);
char *moo_win32_get_dll_dir (const char *dll);
2007-03-24 02:10:43 -05:00
2016-10-02 21:14:12 -07:00
void _moo_win32_add_data_dirs (GPtrArray *list,
const char *prefix);
2007-03-24 02:10:43 -05:00
2016-10-02 21:14:12 -07:00
const char *_moo_win32_get_locale_dir (void);
2007-03-24 02:10:43 -05:00
gboolean _moo_win32_open_uri (const char *uri);
void _moo_win32_show_fatal_error (const char *domain,
const char *logmsg);
2016-10-02 21:14:12 -07:00
char **_moo_win32_lame_parse_cmd_line (const char *cmd_line,
GError **error);
2009-12-06 13:53:50 -08:00
int _moo_win32_message_box (GtkWidget *parent,
guint type,
const char *title,
const char *format,
...) G_GNUC_PRINTF (4, 5);
2007-03-24 02:10:43 -05:00
G_END_DECLS
#endif /* G_OS_WIN32 */
G_INLINE_FUNC gboolean
moo_os_win32 (void)
{
#ifdef __WIN32__
return TRUE;
#else
return FALSE;
#endif
}
2016-10-02 21:14:12 -07:00
#endif /* MOO_UTILS_MISC_H */