1 /* 2 * This file is part of GNOME Twitch - 'Enjoy Twitch on your GNU/Linux desktop' 3 * Copyright © 2017 Vincent Szolnoky <vinszent@vinszent.com> 4 * 5 * GNOME Twitch 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 * GNOME Twitch 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 16 * along with GNOME Twitch. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef _UTILS_H 20 #define _UTILS_H 21 22 #include "gt-channel.h" 23 #include "gt-game.h" 24 #include "gt-vod.h" 25 #include <gtk/gtk.h> 26 #include <json-glib/json-glib.h> 27 28 #define REMOVE_STYLE_CLASS(w, n) gtk_style_context_remove_class(gtk_widget_get_style_context(GTK_WIDGET(w)), n) 29 #define ADD_STYLE_CLASS(w, n) gtk_style_context_add_class(gtk_widget_get_style_context(GTK_WIDGET(w)), n) 30 #define ROUND(x) ((gint) ((x) + 0.5)) 31 #define PRINT_BOOL(b) b ? "true" : "false" 32 #define STRING_EQUALS(a, b) (g_strcmp0(a, b) == 0) 33 34 #define GT_UTILS_ERROR g_quark_from_static_string("gt-utils-error-quark") 35 36 typedef enum 37 { 38 GT_UTILS_ERROR_PARSING_PLAYLIST, 39 GT_UTILS_ERROR_PARSING_TIME, 40 GT_UTILS_ERROR_JSON, 41 GT_UTILS_ERROR_SOUP, 42 } GtUtilsError; 43 44 typedef struct 45 { 46 gint64 int_1; 47 gint64 int_2; 48 gint64 int_3; 49 50 gchar* str_1; 51 gchar* str_2; 52 gchar* str_3; 53 54 gboolean bool_1; 55 gboolean bool_2; 56 gboolean bool_3; 57 } GenericTaskData; 58 59 typedef struct 60 { 61 gchar* name; 62 gchar* resolution; 63 gchar* uri; 64 } GtPlaylistEntry; 65 66 typedef GList GtPlaylistEntryList; 67 68 gpointer utils_value_ref_sink_object(const GValue* val); 69 gchar* utils_value_dup_string_allow_null(const GValue* val); 70 void utils_container_clear(GtkContainer* cont); 71 guint64 utils_timestamp_filename(const gchar* filename, GError** error); 72 guint64 utils_timestamp_file(GFile* file, GError** error); 73 gint64 utils_timestamp_now(void); 74 guint64 utils_http_full_date_to_timestamp(const char* string); 75 void utils_pixbuf_scale_simple(GdkPixbuf** pixbuf, gint width, gint height, GdkInterpType interp); 76 const gchar* utils_search_key_value_strv(gchar** strv, const gchar* key); 77 gboolean utils_str_empty(const gchar* str); 78 gchar* utils_str_capitalise(const gchar* str); 79 void utils_signal_connect_oneshot(gpointer instance, const gchar* signal, GCallback cb, gpointer udata); 80 void utils_signal_connect_oneshot_swapped(gpointer instance, const gchar* signal, GCallback cb, gpointer udata); 81 void utils_refresh_cancellable(GCancellable** cancel); 82 GDateTime* utils_parse_time_iso_8601(const gchar* time, GError** error); 83 GenericTaskData* generic_task_data_new(); 84 void generic_task_data_free(GenericTaskData* data); 85 GWeakRef* utils_weak_ref_new(gpointer obj); 86 void utils_weak_ref_free(GWeakRef* ref); 87 JsonReader* utils_parse_json(const gchar* data, GError** error); 88 GtChannelData* utils_parse_stream_from_json(JsonReader* reader, GError** error); 89 GtChannelData* utils_parse_channel_from_json(JsonReader* reader, GError** error); 90 GtGameData* utils_parse_game_from_json(JsonReader* reader, GError** error); 91 GtVODData* utils_parse_vod_from_json(JsonReader* reader, GError** error); 92 GtPlaylistEntryList* utils_parse_playlist(const gchar* str, GError** error); 93 void gt_playlist_entry_free(GtPlaylistEntry* entry); 94 void gt_playlist_entry_list_free(GtPlaylistEntryList* list); 95 96 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GWeakRef, utils_weak_ref_free); 97 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtPlaylistEntry, gt_playlist_entry_free); 98 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtPlaylistEntryList, gt_playlist_entry_list_free); 99 100 #endif 101