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