eclient no_response calls all now have errors reported to the per-call
[disorder] / disobedience / disobedience.h
1 /*
2 * This file is part of DisOrder.
3 * Copyright (C) 2006-2008 Richard Kettlewell
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 2 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, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20 /** @file disobedience/disobedience.h
21 * @brief Header file for Disobedience, the DisOrder GTK+ client
22 */
23
24 #ifndef DISOBEDIENCE_H
25 #define DISOBEDIENCE_H
26
27 #include "common.h"
28
29 #include <time.h>
30 #include <ctype.h>
31 #include <errno.h>
32 #include <math.h>
33
34 #include "mem.h"
35 #include "log.h"
36 #include "eclient.h"
37 #include "printf.h"
38 #include "cache.h"
39 #include "queue.h"
40 #include "printf.h"
41 #include "vector.h"
42 #include "trackname.h"
43 #include "syscalls.h"
44 #include "defs.h"
45 #include "configuration.h"
46 #include "hash.h"
47 #include "selection.h"
48 #include "kvp.h"
49
50 #include <glib.h>
51 #include <gtk/gtk.h>
52 #include <gdk-pixbuf/gdk-pixbuf.h>
53
54 /* Types ------------------------------------------------------------------- */
55
56 struct queuelike;
57 struct choosenode;
58 struct progress_window;
59
60 /** @brief Callback data structure
61 *
62 * This program is extremely heavily callback-driven. Rather than have
63 * numerous different callback structures we have a single one which can be
64 * interpreted adequately both by success and error handlers.
65 */
66 struct callbackdata {
67 void (*onerror)(struct callbackdata *cbd,
68 int code,
69 const char *msg); /* called on error */
70 union {
71 const char *key; /* gtkqueue.c op_part_lookup */
72 struct choosenode *choosenode; /* gtkchoose.c got_files/got_dirs */
73 struct queuelike *ql; /* gtkqueue.c queuelike_completed */
74 struct prefdata *f; /* properties.c */
75 const char *user; /* users.c */
76 struct {
77 const char *user, *email; /* users.c */
78 } edituser;
79 } u;
80 };
81
82 /** @brief Per-tab callbacks
83 *
84 * Some of the options in the main menu depend on which tab is displayed, so we
85 * have some callbacks to set them appropriately.
86 */
87 struct tabtype {
88 int (*properties_sensitive)(GtkWidget *tab);
89 int (*selectall_sensitive)(GtkWidget *tab);
90 int (*selectnone_sensitive)(GtkWidget *tab);
91 void (*properties_activate)(GtkWidget *tab);
92 void (*selectall_activate)(GtkWidget *tab);
93 void (*selectnone_activate)(GtkWidget *tab);
94 };
95
96 /** @brief Button definitions */
97 struct button {
98 const gchar *stock;
99 void (*clicked)(GtkButton *button, gpointer userdata);
100 const char *tip;
101 GtkWidget *widget;
102 };
103
104 /* Variables --------------------------------------------------------------- */
105
106 extern GMainLoop *mainloop;
107 extern GtkWidget *toplevel; /* top level window */
108 extern GtkWidget *report_label; /* label for progress indicator */
109 extern GtkWidget *tabs; /* main tabs */
110 extern disorder_eclient *client; /* main client */
111
112 extern unsigned long last_state; /* last reported state */
113 extern int playing; /* true if playing some track */
114 extern int volume_l, volume_r; /* current volume */
115 extern double goesupto; /* volume upper bound */
116 extern int choosealpha; /* break up choose by letter */
117 extern GtkTooltips *tips;
118 extern int rtp_supported;
119 extern int rtp_is_running;
120 extern GtkItemFactory *mainmenufactory;
121
122 extern const disorder_eclient_log_callbacks log_callbacks;
123
124 typedef void monitor_callback(void *u);
125
126 /* Functions --------------------------------------------------------------- */
127
128 disorder_eclient *gtkclient(void);
129 /* Configure C for use in GTK+ programs */
130
131 void popup_protocol_error(int code,
132 const char *msg);
133 /* Report an error */
134
135 void properties(int ntracks, const char **tracks);
136 /* Pop up a properties window for a list of tracks */
137
138 void properties_reset(void);
139
140 GtkWidget *scroll_widget(GtkWidget *child);
141 /* Wrap a widget up for scrolling */
142
143 GtkWidget *frame_widget(GtkWidget *w, const char *title);
144
145 GdkPixbuf *find_image(const char *name);
146 /* Get the pixbuf for an image. Returns a null pointer if it cannot be
147 * found. */
148
149 void popup_msg(GtkMessageType mt, const char *msg);
150 void popup_submsg(GtkWidget *parent, GtkMessageType mt, const char *msg);
151
152 void fpopup_msg(GtkMessageType mt, const char *fmt, ...);
153
154 struct progress_window *progress_window_new(const char *title);
155 /* Pop up a progress window */
156
157 void progress_window_progress(struct progress_window *pw,
158 int progress,
159 int limit);
160 /* Report current progress */
161
162 GtkWidget *iconbutton(const char *path, const char *tip);
163
164 GtkWidget *create_buttons(struct button *buttons,
165 size_t nbuttons);
166 GtkWidget *create_buttons_box(struct button *buttons,
167 size_t nbuttons,
168 GtkWidget *box);
169
170 void register_monitor(monitor_callback *callback,
171 void *u,
172 unsigned long mask);
173 /* Register a state monitor */
174
175 /** @brief Type signature for a reset callback */
176 typedef void reset_callback(void);
177
178 void register_reset(reset_callback *callback);
179 /* Register a reset callback */
180
181 void reset(void);
182
183 void all_update(void);
184 /* Update everything */
185
186 /* Main menu */
187
188 GtkWidget *menubar(GtkWidget *w);
189 /* Create the menu bar */
190
191 void menu_update(int page);
192 /* Called whenever the main menu might need to change. PAGE is the current
193 * page if known or -1 otherwise. */
194
195 void users_set_sensitive(int sensitive);
196
197 /* Controls */
198
199 GtkWidget *control_widget(void);
200 /* Make the controls widget */
201
202 void volume_update(void);
203 /* Called whenever we think the volume control has changed */
204
205 void control_monitor(void *u);
206
207 extern int suppress_actions;
208
209 /* Queue/Recent/Added */
210
211 GtkWidget *queue_widget(void);
212 GtkWidget *recent_widget(void);
213 GtkWidget *added_widget(void);
214 /* Create widgets for displaying the queue, the recently played list and the
215 * newly added tracks list */
216
217 void queue_update(void);
218 void recent_update(void);
219 void added_update(void);
220 /* Called whenever we think the queue, recent or newly-added list might have
221 * changed */
222
223 void queue_select_all(struct queuelike *ql);
224 void queue_select_none(struct queuelike *ql);
225 /* Select all/none on some queue */
226
227 void queue_properties(struct queuelike *ql);
228 /* Pop up properties of selected items in some queue */
229
230 int queued(const char *track);
231 /* Return nonzero iff TRACK is queued or playing */
232
233 void namepart_update(const char *track,
234 const char *context,
235 const char *part);
236 /* Called when a namepart might have changed */
237
238 /* Choose */
239
240 GtkWidget *choose_widget(void);
241 /* Create a widget for choosing tracks */
242
243 void choose_update(void);
244 /* Called when we think the choose tree might need updating */
245
246 void play_completed(void *v,
247 const char *error);
248
249 /* Login details */
250
251 void login_box(void);
252
253 GtkWidget *login_window;
254
255 /* User management */
256
257 void manage_users(void);
258
259 /* Help */
260
261 void popup_help(void);
262
263 /* RTP */
264
265 int rtp_running(void);
266 void start_rtp(void);
267 void stop_rtp(void);
268
269 /* Settings */
270
271 void init_styles(void);
272 extern GtkStyle *layout_style;
273 extern GtkStyle *title_style;
274 extern GtkStyle *even_style;
275 extern GtkStyle *odd_style;
276 extern GtkStyle *active_style;
277 extern GtkStyle *tool_style;
278 extern GtkStyle *search_style;
279 extern GtkStyle *drag_style;
280
281 extern const char *browser;
282
283 void save_settings(void);
284 void load_settings(void);
285 void set_tool_colors(GtkWidget *w);
286 void popup_settings(void);
287
288 /* Widget leakage debugging rubbish ---------------------------------------- */
289
290 #if MDEBUG
291 #define NW(what) do { \
292 if(++current##what % 100 > max##what) { \
293 fprintf(stderr, "%s:%d: %d %s\n", \
294 __FILE__, __LINE__, current##what, #what); \
295 max##what = current##what; \
296 } \
297 } while(0)
298 #define WT(what) static int current##what, max##what
299 #define DW(what) (--current##what)
300 #else
301 #define NW(what) do { } while(0)
302 #define DW(what) do { } while(0)
303 #define WT(what) struct neverused
304 #endif
305
306 #if MTRACK
307 extern const char *mtag;
308 #define MTAG(x) do { mtag = x; } while(0)
309 #define MTAG_PUSH(x) do { const char *save_mtag = mtag; mtag = x; (void)0
310 #define MTAG_POP() mtag = save_mtag; } while(0)
311 #else
312 #define MTAG(x) do { } while(0)
313 #define MTAG_PUSH(x) do {} while(0)
314 #define MTAG_POP() do {} while(0)
315 #endif
316
317 #endif /* DISOBEDIENCE_H */
318
319 /*
320 Local Variables:
321 c-basic-offset:2
322 comment-column:40
323 fill-column:79
324 indent-tabs-mode:nil
325 End:
326 */