src/mn-util.h (7538B) - raw
1 /* 2 * Mail Notification 3 * Copyright (C) 2003-2008 Jean-Yves Lefort <jylefort@brutele.be> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 #ifndef _MN_UTIL_H 21 #define _MN_UTIL_H 22 23 #include <stdarg.h> 24 #include <time.h> 25 #include <gtk/gtk.h> 26 27 void mn_info (const char *format, 28 ...) G_GNUC_PRINTF(1, 2); 29 30 #define MN_LIST_FOREACH(var, head) \ 31 for ((var) = (head); \ 32 (var); \ 33 (var) = (var)->next) 34 35 void mn_g_list_free_deep_custom (GList *list, 36 GFunc element_free_func, 37 gpointer user_data); 38 39 GSList *mn_g_slist_append_elements (GSList *list, 40 gpointer data, 41 ...) G_GNUC_NULL_TERMINATED; 42 void mn_g_slist_free_deep (GSList *list); 43 void mn_g_slist_free_deep_custom (GSList *list, 44 GFunc element_free_func, 45 gpointer user_data); 46 void mn_g_slist_clear (GSList **list); 47 void mn_g_slist_clear_deep (GSList **list); 48 void mn_g_slist_clear_deep_custom (GSList **list, 49 GFunc element_free_func, 50 gpointer user_data); 51 GSList *mn_g_slist_delete_link_deep_custom (GSList *list, 52 GSList *link_, 53 GFunc element_free_func, 54 gpointer user_data); 55 56 GSList *mn_g_str_slist_find (GSList *list, 57 const char *str); 58 59 void mn_g_object_list_free (GList *list); 60 61 GSList *mn_g_object_slist_ref (GSList *list); 62 GSList *mn_g_object_slist_copy (GSList *list); 63 void mn_g_object_slist_free (GSList *list); 64 void mn_g_object_slist_clear (GSList **list); 65 66 #define MN_QUEUE_FOREACH(var, queue) \ 67 for ((var) = (queue)->head; \ 68 (var); \ 69 (var) = (var)->next) 70 71 gboolean mn_str_isnumeric (const char *str); 72 gboolean mn_str_ishex (const char *str); 73 char *mn_strstr_span (const char *big, 74 const char *little); 75 76 GdkPixbuf *mn_pixbuf_new (const char *filename); 77 78 void mn_container_create_interface (GtkContainer *container, 79 const char *filename, 80 const char *child_name, 81 const char *callback_prefix, 82 ...) G_GNUC_NULL_TERMINATED; 83 84 GtkWindow *mn_widget_get_parent_window (GtkWidget *widget); 85 86 void mn_file_chooser_dialog_allow_select_folder (GtkFileChooserDialog *dialog, 87 int accept_id); 88 89 void mn_setup_dnd (GtkWidget *widget); 90 91 typedef enum 92 { 93 MN_GNOME_COPIED_FILES_CUT, 94 MN_GNOME_COPIED_FILES_COPY 95 } MNGnomeCopiedFilesType; 96 97 gboolean mn_parse_gnome_copied_files (const char *gnome_copied_files, 98 MNGnomeCopiedFilesType *type, 99 GSList **uri_list); 100 101 void mn_show_help (GtkWindow *parent, 102 const char *link_id); 103 void mn_open_link (GtkWindow *parent, 104 const char *url); 105 106 void mn_thread_create (GThreadFunc func, 107 gpointer data); 108 109 GtkWidget *mn_menu_shell_append (GtkMenuShell *shell, 110 const char *stock_id, 111 const char *mnemonic); 112 GtkWidget *mn_menu_shell_prepend (GtkMenuShell *shell, 113 const char *stock_id, 114 const char *mnemonic); 115 116 void mn_show_error_dialog (GtkWindow *parent, 117 const char *primary, 118 const char *format, 119 ...) G_GNUC_PRINTF(3, 4); 120 void mn_show_error_dialog_with_markup (GtkWindow *parent, 121 const char *primary, 122 const char *format, 123 ...) G_GNUC_PRINTF(3, 4); 124 void mn_show_invalid_uri_dialog (GtkWindow *parent, 125 const char *primary, 126 const char *invalid_uri); 127 void mn_show_invalid_uri_list_dialog (GtkWindow *parent, 128 const char *primary, 129 GSList *invalid_uri_list); 130 void mn_show_fatal_error_dialog (GtkWindow *parent, 131 const char *format, 132 ...) G_GNUC_PRINTF(2, 3) G_GNUC_NORETURN; 133 134 typedef enum 135 { 136 MN_DIALOG_BLOCKING = 1 << 0, 137 MN_DIALOG_MARKUP = 1 << 1 138 } MNDialogFlags; 139 140 GtkWidget *mn_alert_dialog_new (GtkWindow *parent, 141 GtkMessageType type, 142 MNDialogFlags flags, 143 const char *primary, 144 const char *secondary); 145 146 #define MN_SECS(n) (n) 147 #define MN_MINS(n) ((n) * 60) 148 #define MN_HOURS(n) ((n) * 3600) 149 #define MN_DAYS(n) ((n) * 86400) 150 151 time_t mn_time (void); 152 char *mn_strftime (const char *format, 153 const struct tm *timeptr); 154 char *mn_format_past_time (time_t past_time, 155 time_t now); 156 char *mn_format_seconds (int seconds); 157 158 void mn_g_object_null_unref (gpointer object); 159 gpointer mn_g_object_connect (gpointer object, 160 gpointer instance, 161 const char *signal_spec, 162 ...) G_GNUC_NULL_TERMINATED; 163 gpointer mn_g_object_clone (gpointer object, 164 const char *property_name, 165 ...) G_GNUC_NULL_TERMINATED; 166 167 #define MN_STRDUP_VPRINTF(result, format) \ 168 G_STMT_START{ \ 169 va_list _mn_strdup_vprintf_args; \ 170 \ 171 va_start(_mn_strdup_vprintf_args, format); \ 172 result = g_strdup_vprintf(format, _mn_strdup_vprintf_args); \ 173 va_end(_mn_strdup_vprintf_args); \ 174 }G_STMT_END 175 176 int mn_utf8_strcasecmp (const char *s1, 177 const char *s2); 178 gboolean mn_utf8_str_case_has_suffix (const char *str, 179 const char *suffix); 180 char *mn_utf8_escape (const char *str); 181 182 int mn_dialog_run_nonmodal (GtkDialog *dialog); 183 184 void mn_source_clear (unsigned int *tag); 185 186 gboolean mn_ascii_str_case_has_prefix (const char *str, 187 const char *prefix); 188 char *mn_ascii_strcasestr (const char *big, 189 const char *little); 190 char *mn_ascii_strcasestr_span (const char *big, 191 const char *little); 192 193 typedef gboolean (*MNSubstCommandFunction) (const char *name, 194 char **value, 195 gpointer data); 196 char *mn_subst_command (const char *command, 197 MNSubstCommandFunction subst, 198 gpointer data, 199 GError **err); 200 201 void mn_execute_command (const char *command); 202 void mn_execute_command_in_terminal (const char *command); 203 204 char *mn_shell_quote_safe (const char *unquoted_string); 205 206 GtkWidget *mn_hig_section_new (const char *title, 207 GtkWidget **label, 208 GtkWidget **alignment); 209 GtkWidget *mn_hig_section_new_with_box (const char *title, 210 GtkWidget **label, 211 GtkWidget **vbox); 212 213 char *mn_g_value_to_string (const GValue *value); 214 gboolean mn_g_value_from_string (GValue *value, 215 const char *str); 216 217 void mn_window_present_from_event (GtkWindow *window); 218 219 void mn_add_weak_pointer (gpointer object_location); 220 void mn_remove_weak_pointer (gpointer object_location); 221 222 int mn_strv_find (char **strv, 223 const char *elem); 224 225 #define MN_ARRAY_FOREACH(var, array) \ 226 for ((var) = 0; (var) < (array)->len; (var)++) 227 228 GSList *mn_g_ptr_array_to_slist (GPtrArray *array); 229 void mn_g_ptr_array_free_deep_custom (GPtrArray *array, 230 GFunc element_free_func, 231 gpointer user_data); 232 233 void mn_g_object_ptr_array_free (GPtrArray *array); 234 235 #define MN_TREE_MODEL_FOREACH(valid, iter, model) \ 236 for ((valid) = gtk_tree_model_get_iter_first((model), (iter)); \ 237 (valid); \ 238 (valid) = gtk_tree_model_iter_next((model), (iter))) 239 240 const char *mn_enum_get_value_nick (GType type, 241 int value); 242 243 #endif /* _MN_UTIL_H */