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 GT_TWITCH_H
20 #define GT_TWITCH_H
21 
22 #include <gtk/gtk.h>
23 
24 G_BEGIN_DECLS
25 
26 #define GT_TYPE_TWITCH (gt_twitch_get_type())
27 
28 G_DECLARE_FINAL_TYPE(GtTwitch, gt_twitch, GT, TWITCH, GObject)
29 
30 #include "gt-app.h"
31 #include "gt-channel.h"
32 #include "gt-game.h"
33 
34 #define NO_GAME ""
35 #define NO_TIMESTAMP -1
36 #define ALL_LANGUAGES ""
37 
38 GQuark gt_spawn_twitch_error_quark();
39 #define GT_TWITCH_ERROR gt_spawn_twitch_error_quark()
40 
41 typedef enum _GtTwitchError
42 {
43     GT_TWITCH_ERROR_JSON,
44     GT_TWITCH_ERROR_MISC,
45     GT_TWITCH_ERROR_SOUP_GENERIC,
46     GT_TWITCH_ERROR_SOUP_NOT_FOUND = 404,
47 } GtTwitchError;
48 
49 #define GT_TWITCH_STREAM_QUALITY_SOURCE "source"
50 #define GT_TWITCH_STREAM_QUALITY_HIGH "high"
51 #define GT_TWITCH_STREAM_QUALITY_MEDIUM "medium"
52 #define GT_TWITCH_STREAM_QUALITY_LOW "low"
53 #define GT_TWITCH_STREAM_QUALITY_MOBILE "mobile"
54 #define GT_TWITCH_STREAM_QUALITY_AUDIO_ONLY "audio_only"
55 
56 struct _GtTwitch
57 {
58     GObject parent_instance;
59 };
60 
61 //TODO: Define an autofree for this
62 typedef struct _GtTwitchStreamAccessToken
63 {
64     gchar* token;
65     gchar* sig;
66 } GtTwitchStreamAccessToken;
67 
68 //NOTE: Default qualities are source, high, medium, low, mobile,
69 //audio_only
70 
71 typedef struct _GtTwitchStreamData
72 {
73     gint width;
74     gint height;
75     glong bandwidth;
76     gchar* quality;
77     gchar* url;
78 } GtTwitchStreamData;
79 
80 
81 typedef struct
82 {
83     gchar* name;
84     gchar* version;
85     GdkPixbuf* pixbuf;
86 } GtChatBadge;
87 
88 typedef struct
89 {
90     gint64 id;
91     gchar* code;
92     gint set;
93     GdkPixbuf* pixbuf;
94 
95     //NOTE: These are only set if coming from GtIrc
96     gint start; // Start of text to replace
97     gint end; // End of text to replace
98 } GtChatEmote;
99 
100 typedef enum _GtTwitchChannelInfoPanelType
101 {
102     GT_TWITCH_CHANNEL_INFO_PANEL_TYPE_DEFAULT,
103     GT_TWITCH_CHANNEL_INFO_PANEL_TYPE_TEESPRING,
104 } GtTwitchChannelInfoPanelType;
105 
106 typedef struct _GtTwitchChannelInfoPanel
107 {
108     GtTwitchChannelInfoPanelType type;
109     gchar* title;
110     gchar* html_description;
111     gchar* markdown_description;
112     GdkPixbuf* image;
113     gchar* link;
114     gint64 order;
115 } GtTwitchChannelInfoPanel;
116 
117 GtTwitch*                  gt_twitch_new();
118 void                       gt_twitch_stream_access_token_free(GtTwitchStreamAccessToken* token);
119 GtTwitchStreamAccessToken* gt_twitch_stream_access_token(GtTwitch* self, const gchar* channel, GError** error);
120 void                       gt_twitch_stream_access_token_async(GtTwitch* self, const gchar* channel, GCancellable* cancel, GAsyncReadyCallback cb, gpointer udata);
121 const GtTwitchStreamData*  gt_twitch_stream_list_filter_quality(GList* list, const gchar* quality);
122 GList*                     gt_twitch_all_streams(GtTwitch* self, const gchar* channel, GError** error);
123 void                       gt_twitch_all_streams_async(GtTwitch* self, const gchar* channel, GCancellable* cancel, GAsyncReadyCallback cb, gpointer udata);
124 GList*                     gt_twitch_all_streams_finish(GtTwitch* self, GAsyncResult* result, GError** error);
125 GList*                     gt_twitch_top_channels(GtTwitch* self, gint n, gint offset, const gchar* game, const gchar* language, GError** error);
126 void                       gt_twitch_top_channels_async(GtTwitch* self, gint n, gint offset, const gchar* game, const gchar* language, GCancellable* cancel, GAsyncReadyCallback cb, gpointer udata);
127 GList*                     gt_twitch_top_games(GtTwitch* self, gint n, gint offset, GError** error);
128 void                       gt_twitch_top_games_async(GtTwitch* self, gint n, gint offset, GCancellable* cancel, GAsyncReadyCallback cb, gpointer udata);
129 GList*                     gt_twitch_top_games_finish(GtTwitch* self, GAsyncResult* result, GError** error);
130 GList*                     gt_twitch_search_channels(GtTwitch* self, const gchar* query, gint n, gint offset, gboolean offline, GError** error);
131 void                       gt_twitch_search_channels_async(GtTwitch* self, const gchar* query, gint n, gint offset, gboolean offline, GCancellable* cancel, GAsyncReadyCallback cb, gpointer udata);
132 GList*                     gt_twitch_search_channels_finish(GtTwitch* self, GAsyncResult* result, GError** error);
133 GList*                     gt_twitch_search_games(GtTwitch* self, const gchar* query, gint n, gint offset, GError** error);
134 void                       gt_twitch_search_games_async(GtTwitch* self, const gchar* query, gint n, gint offset, GCancellable* cancel, GAsyncReadyCallback cb, gpointer udata);
135 GList*                     gt_twitch_search_games_finish(GtTwitch* self, GAsyncResult* result, GError** error);
136 void                       gt_twitch_stream_data_free(GtTwitchStreamData* data);
137 void                       gt_twitch_stream_data_list_free(GList* list);
138 GtChannelData*             gt_twitch_fetch_channel_data(GtTwitch* self, const gchar* id, GError** error);
139 GtChannel*                 gt_twitch_fetch_channel(GtTwitch* self, const gchar* id, GError** error);
140 void                       gt_twitch_fetch_channel_async(GtTwitch* self, const gchar* id, GAsyncReadyCallback cb, GCancellable* cancel, gpointer udata);
141 GtChannel*                 gt_twitch_fetch_channel_finish(GtTwitch* self, GAsyncResult* result, GError** error);
142 void                       gt_twitch_channel_raw_data_async(GtTwitch* self, const gchar* name, GCancellable* cancel, GAsyncReadyCallback cb, gpointer udata);
143 GtGameData*                gt_twitch_game_raw_data(GtTwitch* self, const gchar* name);
144 GdkPixbuf*                 gt_twitch_download_picture(GtTwitch* self, const gchar* url, gint64 timestamp, GError** error);
145 void                       gt_twitch_download_picture_async(GtTwitch* self, const gchar* url, gint64 timestamp, GCancellable* cancel, GAsyncReadyCallback cb, gpointer udata);
146 GdkPixbuf*                 gt_twitch_download_emote(GtTwitch* self, gint id);
147 GList*                     gt_twitch_channel_info(GtTwitch* self, const gchar* chan);
148 void                       gt_twitch_channel_info_panel_free(GtTwitchChannelInfoPanel* panel);
149 void                       gt_twitch_channel_info_async(GtTwitch* self, const gchar* chan, GCancellable* cancel, GAsyncReadyCallback cb, gpointer udata);
150 GList*                     gt_twitch_chat_servers(GtTwitch* self, const gchar* chan, GError** error);
151 GList*                     gt_twitch_fetch_all_followed_channels(GtTwitch* self, const gchar* id, const gchar* oauth_token, GError** error);
152 void                       gt_twitch_fetch_all_followed_channels_async(GtTwitch* self, const gchar* id, const gchar* oauth_token, GCancellable* cancel, GAsyncReadyCallback cb, gpointer udata);
153 GList*                     gt_twitch_fetch_all_followed_channels_finish(GtTwitch* self, GAsyncResult* result, GError** error);
154 void                       gt_twitch_follow_channel(GtTwitch* self, const gchar* chan_name, GError** error);
155 void                       gt_twitch_follow_channel_async(GtTwitch* self, const gchar* chan_name, GAsyncReadyCallback cb, gpointer udata);
156 void                       gt_twitch_follow_channel_finish(GtTwitch* self, GAsyncResult* result, GError** error);
157 void                       gt_twitch_unfollow_channel(GtTwitch* self, const gchar* chan_name, GError** error);
158 void                       gt_twitch_unfollow_channel_async(GtTwitch* self, const gchar* chan_name, GAsyncReadyCallback cb, gpointer udata);
159 void                       gt_twitch_unfollow_channel_finish(GtTwitch* self, GAsyncResult* result, GError** error);
160 GList*                     gt_twitch_emoticons(GtTwitch* self, const gchar* emotesets, GError** error);
161 void                       gt_twitch_emoticons_async(GtTwitch* self, const char* emotesets, GAsyncReadyCallback cb, GCancellable* cancel, gpointer udata);
162 GtChatBadge*               gt_twitch_fetch_chat_badge(GtTwitch* self, const gchar* chan_id, const gchar* badge_name, const gchar* version, GError** err);
163 void                       gt_twitch_fetch_chat_badge_async(GtTwitch* self, const gchar* chan_id, const gchar* badge_name, const gchar* version, GCancellable* cancel, GAsyncReadyCallback cb, gpointer udata);
164 GtChatBadge*               gt_twitch_fetch_chat_badge_finish(GtTwitch* self, GAsyncResult* result, GError** err);
165 void                       gt_twitch_load_chat_badge_sets_for_channel(GtTwitch* self, const gchar* chan_id, GError** err);
166 GtChatBadge*               gt_chat_badge_new();
167 void                       gt_chat_badge_free(GtChatBadge* badge);
168 void                       gt_chat_badge_list_free(GList* list);
169 GtChatEmote*               gt_chat_emote_new();
170 void                       gt_chat_emote_free(GtChatEmote* emote);
171 void                       gt_chat_emote_list_free(GList* list);
172 GtUserInfo*                gt_twitch_fetch_user_info(GtTwitch* self, const gchar* oauth_token, GError** error);
173 void                       gt_twitch_fetch_user_info_async(GtTwitch* self, const gchar* oauth_token, GAsyncReadyCallback cb, GCancellable* cancel, gpointer udata);
174 GtUserInfo*                gt_twitch_fetch_user_info_finish(GtTwitch* self, GAsyncResult* result, GError** error);
175 GtOAuthInfo*               gt_twitch_fetch_oauth_info(GtTwitch* self, const gchar* oauth_token, GError** error);
176 void                       gt_twitch_fetch_oauth_info_async(GtTwitch* self, const gchar* oauth_token, GAsyncReadyCallback cb, GCancellable* cancel, gpointer udata);
177 GtOAuthInfo*               gt_twitch_fetch_oauth_info_finish(GtTwitch* self, GAsyncResult* result, GError** error);
178 
179 G_END_DECLS
180 
181 #endif
182