2005-10-31 22:58:01 +00:00
|
|
|
/*
|
|
|
|
* mooutils-misc.h
|
|
|
|
*
|
2008-02-03 02:02:26 -06:00
|
|
|
* Copyright (C) 2004-2008 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
2005-10-31 22:58:01 +00:00
|
|
|
*
|
2007-06-24 12:56:20 -05:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
2007-09-23 11:47:28 -05:00
|
|
|
* License version 2.1 as published by the Free Software Foundation.
|
2005-10-31 22:58:01 +00:00
|
|
|
*
|
|
|
|
* See COPYING file that comes with this distribution.
|
|
|
|
*/
|
|
|
|
|
2007-04-12 10:31:28 -05:00
|
|
|
#ifndef MOO_UTILS_MISC_H
|
|
|
|
#define MOO_UTILS_MISC_H
|
2005-10-31 22:58:01 +00:00
|
|
|
|
2006-03-21 03:23:37 -06:00
|
|
|
#include <gtk/gtk.h>
|
2006-09-02 02:29:39 -05: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);
|
2007-09-07 23:59:37 -05:00
|
|
|
char *_moo_find_script (const char *name,
|
|
|
|
gboolean search_path);
|
2005-10-31 22:58:01 +00:00
|
|
|
|
2007-02-09 20:28:28 -06:00
|
|
|
void moo_window_present (GtkWindow *window,
|
2006-07-05 14:16:29 -05:00
|
|
|
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);
|
|
|
|
void moo_reset_log_func (void);
|
2005-10-31 22:58:01 +00:00
|
|
|
|
2005-11-17 07:04:35 +00:00
|
|
|
void moo_segfault (void);
|
|
|
|
|
2006-11-23 23:08:22 -06:00
|
|
|
void moo_disable_win32_error_message (void);
|
|
|
|
void moo_enable_win32_error_message (void);
|
2005-10-31 22:58:01 +00:00
|
|
|
|
2006-03-29 02:04:18 -06:00
|
|
|
typedef enum {
|
|
|
|
MOO_DATA_SHARE,
|
|
|
|
MOO_DATA_LIB
|
|
|
|
} MooDataDirType;
|
|
|
|
|
2008-01-06 14:39:44 -06:00
|
|
|
void _moo_set_app_instance_name (const char *name);
|
|
|
|
void _moo_set_user_data_dir (const char *path);
|
|
|
|
|
2006-03-29 02:04:18 -06:00
|
|
|
/* ~/.appname */
|
2006-08-23 05:30:23 -05:00
|
|
|
gboolean moo_make_user_data_dir (const char *path);
|
2006-04-09 04:00:52 -05:00
|
|
|
char *moo_get_user_data_dir (void);
|
|
|
|
char *moo_get_user_data_file (const char *basename);
|
2008-01-06 14:39:44 -06:00
|
|
|
char *moo_get_named_user_data_file (const char *basename);
|
2006-04-09 04:00:52 -05:00
|
|
|
gboolean moo_save_user_data_file (const char *basename,
|
|
|
|
const char *content,
|
|
|
|
gssize len,
|
|
|
|
GError **error);
|
2007-06-10 03:39:26 -05:00
|
|
|
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);
|
2006-04-09 04:00:52 -05:00
|
|
|
|
2007-04-21 08:15:52 -05:00
|
|
|
/* user data comes first; MOO_DATA_DIR comes last */
|
2006-03-29 02:04:18 -06:00
|
|
|
/* $MOO_APP_DIR:$MOO_DATA_DIRS:$prefix/share/appname or
|
|
|
|
$MOO_APP_DIR:$MOO_LIB_DIRS:$prefix/lib/appname */
|
2006-04-09 04:00:52 -05:00
|
|
|
char **moo_get_data_dirs (MooDataDirType type,
|
2006-03-29 02:04:18 -06:00
|
|
|
guint *n_dirs);
|
2006-04-09 04:00:52 -05:00
|
|
|
char **moo_get_data_subdirs (const char *subdir,
|
2006-03-29 02:04:18 -06:00
|
|
|
MooDataDirType type,
|
|
|
|
guint *n_dirs);
|
2006-04-09 04:00:52 -05:00
|
|
|
#define moo_get_data_files moo_get_data_subdirs
|
2006-03-29 02:04:18 -06:00
|
|
|
|
2007-12-06 10:23:15 -06:00
|
|
|
char *moo_tempnam (void);
|
|
|
|
void moo_cleanup (void);
|
|
|
|
|
2007-05-08 20:26:03 -05:00
|
|
|
const char *moo_get_locale_dir (void);
|
2007-03-31 00:31:18 -05:00
|
|
|
const char *const *_moo_get_shared_data_dirs (void);
|
|
|
|
|
2006-03-29 02:04:18 -06:00
|
|
|
|
2008-02-02 20:44:46 -06:00
|
|
|
void moo_selection_data_set_pointer (GtkSelectionData *data,
|
2005-11-27 14:03:12 +00:00
|
|
|
GdkAtom type,
|
|
|
|
gpointer ptr);
|
2008-02-02 20:44:46 -06:00
|
|
|
gpointer moo_selection_data_get_pointer (GtkSelectionData *data,
|
2005-11-27 14:03:12 +00:00
|
|
|
GdkAtom type);
|
|
|
|
|
2006-08-15 03:52:38 -05:00
|
|
|
GdkModifierType _moo_get_modifiers (GtkWidget *widget);
|
2005-11-28 04:36:58 +00:00
|
|
|
|
2007-12-03 22:08:34 -06:00
|
|
|
void _moo_menu_item_set_accel_label (GtkWidget *menu_item,
|
2005-11-28 04:36:58 +00:00
|
|
|
const char *label);
|
2007-12-03 22:08:34 -06:00
|
|
|
void _moo_menu_item_set_label (GtkWidget *menu_item,
|
2005-12-02 17:50:28 +00:00
|
|
|
const char *label,
|
|
|
|
gboolean mnemonic);
|
2005-11-28 04:36:58 +00:00
|
|
|
|
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);
|
2007-05-20 04:36:05 -05:00
|
|
|
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
|
|
|
|
2006-09-02 02:29:39 -05:00
|
|
|
static inline gboolean
|
2008-02-03 02:02:26 -06:00
|
|
|
_moo_str_equal (const char *s1,
|
|
|
|
const char *s2)
|
2006-09-02 02:29:39 -05:00
|
|
|
{
|
|
|
|
return !strcmp (s1 ? s1 : "", s2 ? s2 : "");
|
|
|
|
}
|
|
|
|
|
2007-12-19 14:02:42 -06:00
|
|
|
static inline void
|
|
|
|
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))
|
|
|
|
|
2006-08-19 00:20:55 -05:00
|
|
|
const char *_moo_get_pid_string (void);
|
|
|
|
|
2007-06-14 00:00:30 -05:00
|
|
|
const char *_moo_intern_string (const char *string);
|
|
|
|
|
2008-02-02 20:44:46 -06:00
|
|
|
guint moo_idle_add_full (gint priority,
|
2007-01-19 20:47:59 -06:00
|
|
|
GSourceFunc function,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify notify);
|
2007-05-20 04:36:05 -05:00
|
|
|
guint moo_idle_add (GSourceFunc function,
|
2007-01-19 20:47:59 -06:00
|
|
|
gpointer data);
|
|
|
|
guint _moo_timeout_add_full (gint priority,
|
|
|
|
guint interval,
|
|
|
|
GSourceFunc function,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify notify);
|
|
|
|
guint _moo_timeout_add (guint interval,
|
|
|
|
GSourceFunc function,
|
|
|
|
gpointer data);
|
|
|
|
guint _moo_io_add_watch (GIOChannel *channel,
|
|
|
|
GIOCondition condition,
|
|
|
|
GIOFunc func,
|
|
|
|
gpointer data);
|
|
|
|
guint _moo_io_add_watch_full (GIOChannel *channel,
|
|
|
|
int priority,
|
|
|
|
GIOCondition condition,
|
|
|
|
GIOFunc func,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify notify);
|
|
|
|
|
2005-11-27 14:03:12 +00:00
|
|
|
|
2007-05-30 04:37:41 -05:00
|
|
|
gboolean _moo_regex_escape (const char *string,
|
|
|
|
int bytes,
|
|
|
|
GString *dest);
|
|
|
|
|
|
|
|
|
2007-03-13 01:29:55 -05:00
|
|
|
#if GLIB_CHECK_VERSION(2,10,0)
|
2008-02-03 02:10:35 -06:00
|
|
|
#define moo_new g_slice_new
|
|
|
|
#define moo_new0 g_slice_new0
|
|
|
|
#define moo_free g_slice_free
|
2007-03-13 01:29:55 -05:00
|
|
|
#else
|
2008-02-03 02:10:35 -06:00
|
|
|
#define moo_new(type) g_new (type, 1)
|
|
|
|
#define moo_new0(type) g_new0 (type, 1)
|
|
|
|
#define moo_free(type,mem) g_free (mem)
|
2007-03-13 01:29:55 -05:00
|
|
|
#endif
|
|
|
|
|
2007-12-19 14:02:42 -06:00
|
|
|
#if GLIB_CHECK_VERSION(2,10,0)
|
2008-04-13 18:26:40 -05:00
|
|
|
#define MOO_OBJECT_REF_SINK(obj) (void) g_object_ref_sink (obj)
|
2007-12-19 14:02:42 -06:00
|
|
|
#else
|
|
|
|
#define MOO_OBJECT_REF_SINK(obj) gtk_object_sink (g_object_ref (obj))
|
|
|
|
#endif
|
|
|
|
|
2007-03-13 01:29:55 -05:00
|
|
|
|
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>
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
|
2008-01-15 00:43:03 -06: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
|
|
|
|
2007-04-21 08:15:52 -05:00
|
|
|
void _moo_win32_add_data_dirs (GPtrArray *list,
|
2007-03-24 02:10:43 -05:00
|
|
|
const char *prefix);
|
|
|
|
|
|
|
|
const char *_moo_win32_get_locale_dir (void);
|
|
|
|
|
|
|
|
gboolean _moo_win32_open_uri (const char *uri);
|
|
|
|
void _moo_win32_show_fatal_error (const char *domain,
|
|
|
|
const char *logmsg);
|
|
|
|
|
2008-02-02 20:44:46 -06:00
|
|
|
char **_moo_win32_lame_parse_cmd_line (const char *cmd_line,
|
2008-01-17 07:58:58 -06:00
|
|
|
GError **error);
|
|
|
|
|
2007-03-24 02:10:43 -05:00
|
|
|
|
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* G_OS_WIN32 */
|
|
|
|
|
2007-04-12 10:31:28 -05:00
|
|
|
#endif /* MOO_UTILS_MISC_H */
|