be485aef731794e26a8f16307c58dfadc7bc339b
[omnplay] / src / ui.c
1 /*
2 * ui.c -- GTK+ 2 omnplay
3 * Copyright (C) 2011 Maksym Veremeyenko <verem@m1stereo.tv>
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,
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 this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <unistd.h>
27 #include <string.h>
28 #include <stdio.h>
29
30 #include <gdk/gdkkeysyms.h>
31 #include <gtk/gtk.h>
32
33 #include "ui.h"
34 #include "ui_utils.h"
35 #include "ui_buttons.h"
36 #include "support.h"
37
38 typedef struct column_desc
39 {
40 char* title;
41 GType type;
42 } column_desc_t;
43
44 static const column_desc_t playlist_columns[] =
45 {
46 {
47 "REM",
48 G_TYPE_STRING
49 },
50 {
51 "B",
52 G_TYPE_OBJECT
53 },
54 {
55 "CH",
56 G_TYPE_STRING
57 },
58 {
59 "ID",
60 G_TYPE_STRING
61 },
62 {
63 "IN",
64 G_TYPE_STRING
65 },
66 {
67 "DUR",
68 G_TYPE_STRING
69 },
70 {
71 "TITLE",
72 G_TYPE_STRING
73 },
74 {
75 NULL,
76 G_TYPE_STRING
77 }
78 };
79
80 const static column_desc_t library_columns[] =
81 {
82 {
83 "ID",
84 G_TYPE_STRING
85 },
86 {
87 "DUR",
88 G_TYPE_STRING
89 },
90 {
91 "TITLE",
92 G_TYPE_STRING
93 },
94 {
95 NULL,
96 G_TYPE_STRING
97 }
98 };
99
100
101 static GtkWidget* create_label(GtkWidget* top, char* text, char* reg, GtkJustification jtype)
102 {
103 GtkWidget* label;
104
105 label = gtk_label_new ("");
106 gtk_widget_show (label);
107
108 gtk_label_set_justify (GTK_LABEL (label), jtype);
109
110 if(reg)
111 GLADE_HOOKUP_OBJECT (top, label, reg);
112
113 if(text)
114 gtk_label_set_text(GTK_LABEL (label), text);
115
116 return label;
117 };
118
119 static GtkWidget* create_treeview(GtkWidget* top, char* name, const column_desc_t columns[])
120 {
121 int i, count;
122
123 GtkWidget *treeview;
124 GtkTreeSelection *selection;
125 GtkCellRenderer *renderer;
126 GtkTreeViewColumn *column;
127 GtkListStore *list_store;
128 GType list_store_types[32];
129
130 treeview = gtk_tree_view_new ();
131 gtk_widget_show (treeview);
132
133 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
134 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
135
136 for(i = 0, count = 0; columns[i].title; i++, count++)
137 list_store_types[i] = (columns[i].type == G_TYPE_OBJECT)?GDK_TYPE_PIXBUF:columns[i].type;
138 list_store_types[count] = G_TYPE_INT;
139
140 list_store = gtk_list_store_newv(count + 1, list_store_types);
141
142 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview ), GTK_TREE_MODEL( list_store ) );
143
144 for(i = 0; columns[i].title; i++)
145 {
146 char* prop;
147
148 if(columns[i].type == G_TYPE_OBJECT)
149 {
150 renderer = gtk_cell_renderer_pixbuf_new();
151 gtk_cell_renderer_set_padding(renderer, 0, 0);
152 prop = "pixbuf";
153 }
154 else if(columns[i].type == G_TYPE_BOOLEAN)
155 {
156 renderer = gtk_cell_renderer_toggle_new();
157 prop = "active";
158 }
159 else
160 {
161 renderer = gtk_cell_renderer_text_new();
162 prop = "text";
163 }
164
165 column = gtk_tree_view_column_new_with_attributes(
166 columns[i].title, renderer, prop, i, NULL);
167 gtk_tree_view_append_column(GTK_TREE_VIEW( treeview ), column);
168 };
169
170 g_object_unref(list_store);
171
172 GLADE_HOOKUP_OBJECT (top, treeview, name);
173
174 return treeview;
175 };
176
177 static GtkWidget* pane_library_grid(GtkWidget* top, omnplay_instance_t* app)
178 {
179 GtkWidget *scrolledwindow;
180
181 scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
182 gtk_widget_show (scrolledwindow);
183 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
184 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
185
186 gtk_container_add (GTK_CONTAINER (scrolledwindow),
187 app->library_grid = create_treeview(top, "treeview_library", library_columns));
188
189 return scrolledwindow;
190 }
191
192 static GtkWidget* pane_library_buttons(GtkWidget* top, omnplay_instance_t* app)
193 {
194 GtkWidget* hbox;
195
196 hbox = gtk_hbox_new (FALSE, 0);
197 gtk_widget_show (hbox);
198
199 /* playlist modify buttons */
200 gtk_box_pack_start (GTK_BOX (hbox),
201 ui_create_button(top, app, BUTTON_LIBRARY_ADD),
202 FALSE, FALSE, 0);
203 gtk_box_pack_start (GTK_BOX (hbox),
204 ui_create_button(top, app, BUTTON_LIBRARY_REFRESH),
205 FALSE, FALSE, 0);
206
207 /* spacer */
208 gtk_box_pack_start (GTK_BOX (hbox),
209 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
210 TRUE, TRUE, 0);
211
212 return hbox;
213 }
214
215 static GtkWidget* pane_library(GtkWidget* top, omnplay_instance_t* app)
216 {
217 GtkWidget* vbox;
218
219 vbox = gtk_vbox_new (FALSE, 0);
220 gtk_widget_show (vbox);
221 gtk_widget_set_size_request(vbox, 300, -1);
222
223 /* add buttons box */
224 gtk_box_pack_start (GTK_BOX (vbox),
225 pane_library_buttons(top, app),
226 FALSE, FALSE, 0);
227
228 /* add buttons box */
229 gtk_box_pack_start (GTK_BOX (vbox),
230 pane_library_grid(top, app),
231 TRUE, TRUE, 0);
232
233 return vbox;
234 }
235
236 static GtkWidget* create_channel_status(GtkWidget* top, omnplay_instance_t* app, int idx)
237 {
238 GtkWidget* vbox;
239 GtkWidget* hbox;
240 GtkWidget* frame;
241 omnplay_player_t* player;
242
243 player = &app->players.item[idx];
244
245 frame = gtk_frame_new(player->name);
246 gtk_widget_show(frame);
247
248 vbox = gtk_vbox_new(FALSE, 0);
249 gtk_container_add(GTK_CONTAINER(frame), vbox);
250 gtk_widget_show(vbox);
251
252 /* status label */
253 gtk_box_pack_start(GTK_BOX (vbox),
254 player->label_status = create_label(top, "OFFLINE", NULL, GTK_JUSTIFY_LEFT),
255 FALSE, FALSE, 0);
256
257 /* spacel label */
258 gtk_box_pack_start(GTK_BOX (vbox),
259 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
260 FALSE, FALSE, 0);
261
262 /* clip label */
263 gtk_box_pack_start (GTK_BOX (vbox),
264 player->label_clip = create_label(top, "U0002323", NULL, GTK_JUSTIFY_LEFT),
265 FALSE, FALSE, 0);
266
267 /* block state/current timecode */
268 gtk_box_pack_start(GTK_BOX (vbox),
269 hbox = gtk_hbox_new(TRUE, 0),
270 FALSE, FALSE, 0);
271 gtk_widget_show(hbox);
272
273 {
274 /* clip state */
275 gtk_box_pack_start(GTK_BOX (hbox),
276 player->label_state = create_label(top, "PLAYING", NULL, GTK_JUSTIFY_LEFT),
277 TRUE, TRUE, 0);
278
279 /* current timecode */
280 gtk_box_pack_start(GTK_BOX (hbox),
281 player->label_tc_cur = create_label(top, "00:00:00:00", NULL, GTK_JUSTIFY_LEFT),
282 TRUE, TRUE, 0);
283 };
284
285 /* block remain label/remain timecode */
286 gtk_box_pack_start(GTK_BOX (vbox),
287 hbox = gtk_hbox_new(TRUE, 0),
288 FALSE, FALSE, 0);
289 gtk_widget_show (hbox);
290
291 {
292 /* label */
293 gtk_box_pack_start(GTK_BOX (hbox),
294 create_label(top, "remain:", NULL, GTK_JUSTIFY_LEFT),
295 TRUE, TRUE, 0);
296
297 /* remaining timecode */
298 gtk_box_pack_start(GTK_BOX (hbox),
299 player->label_tc_rem = create_label(top, "00:00:00:00", NULL, GTK_JUSTIFY_LEFT),
300 TRUE, TRUE, 0);
301 };
302
303 return frame;
304 }
305
306 static GtkWidget* pane_operate_status(GtkWidget* top, omnplay_instance_t* app)
307 {
308 int i;
309 GtkWidget* vbox;
310
311 vbox = gtk_vbox_new (FALSE, 0);
312 gtk_widget_show (vbox);
313 gtk_widget_set_size_request(vbox, 250, -1);
314
315 for(i = 0; i < app->players.count; i++)
316 {
317 gtk_box_pack_start (GTK_BOX (vbox),
318 create_channel_status(top, app, i),
319 FALSE, FALSE, 0);
320
321 /* spacer */
322 gtk_box_pack_start (GTK_BOX (vbox),
323 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
324 FALSE, FALSE, 0);
325 }
326
327 /* spacer */
328 gtk_box_pack_start (GTK_BOX (vbox),
329 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
330 TRUE, TRUE, 0);
331
332 return vbox;
333 }
334
335 static GtkWidget* pane_operate_buttons_playlist(GtkWidget* top, omnplay_instance_t* app)
336 {
337 GtkWidget* hbox;
338
339 hbox = gtk_hbox_new (FALSE, 0);
340 gtk_widget_show (hbox);
341
342 /* playlist load/save buttons */
343 gtk_box_pack_start (GTK_BOX (hbox),
344 ui_create_button(top, app, BUTTON_PLAYLIST_LOAD),
345 FALSE, FALSE, 0);
346 gtk_box_pack_start (GTK_BOX (hbox),
347 ui_create_button(top, app, BUTTON_PLAYLIST_SAVE),
348 FALSE, FALSE, 0);
349
350 /* spacer */
351 gtk_box_pack_start (GTK_BOX (hbox),
352 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
353 FALSE, FALSE, 0);
354
355 /* playlist modify buttons */
356 gtk_box_pack_start (GTK_BOX (hbox),
357 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_ADD),
358 FALSE, FALSE, 0);
359 gtk_box_pack_start (GTK_BOX (hbox),
360 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_EDIT),
361 FALSE, FALSE, 0);
362 gtk_box_pack_start (GTK_BOX (hbox),
363 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_DEL),
364 FALSE, FALSE, 0);
365
366 /* spacer */
367 gtk_box_pack_start (GTK_BOX (hbox),
368 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
369 FALSE, FALSE, 0);
370
371 /* playlist block buttons */
372 gtk_box_pack_start (GTK_BOX (hbox),
373 ui_create_button(top, app, BUTTON_PLAYLIST_BLOCK_SINGLE),
374 FALSE, FALSE, 0);
375 gtk_box_pack_start (GTK_BOX (hbox),
376 ui_create_button(top, app, BUTTON_PLAYLIST_BLOCK_LOOP),
377 FALSE, FALSE, 0);
378
379 /* spacer */
380 gtk_box_pack_start (GTK_BOX (hbox),
381 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
382 FALSE, FALSE, 0);
383
384 /* playlist move items buttons */
385 gtk_box_pack_start (GTK_BOX (hbox),
386 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_UP),
387 FALSE, FALSE, 0);
388 gtk_box_pack_start (GTK_BOX (hbox),
389 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_DOWN),
390 FALSE, FALSE, 0);
391
392 return hbox;
393 }
394
395 static GtkWidget* pane_operate_grid(GtkWidget* top, omnplay_instance_t* app)
396 {
397 GtkWidget *scrolledwindow;
398
399 scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
400 gtk_widget_show (scrolledwindow);
401 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
402 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
403
404 gtk_container_add (GTK_CONTAINER (scrolledwindow),
405 app->playlist_grid = create_treeview(top, "treeview_playlist", playlist_columns));
406
407 return scrolledwindow;
408 }
409
410 static GtkWidget* pane_operate_buttons_operate(GtkWidget* top, omnplay_instance_t* app)
411 {
412 GtkWidget* hbox;
413
414 hbox = gtk_hbox_new (FALSE, 0);
415 gtk_widget_show (hbox);
416
417 /* spacer */
418 gtk_box_pack_start (GTK_BOX (hbox),
419 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
420 TRUE, TRUE, 0);
421
422 /* playlist modify buttons */
423 gtk_box_pack_start (GTK_BOX (hbox),
424 ui_create_button(top, app, BUTTON_PLAYER_CUE),
425 FALSE, FALSE, 0);
426 gtk_box_pack_start (GTK_BOX (hbox),
427 ui_create_button(top, app, BUTTON_PLAYER_PLAY),
428 FALSE, FALSE, 0);
429 gtk_box_pack_start (GTK_BOX (hbox),
430 ui_create_button(top, app, BUTTON_PLAYER_PAUSE),
431 FALSE, FALSE, 0);
432 gtk_box_pack_start (GTK_BOX (hbox),
433 ui_create_button(top, app, BUTTON_PLAYER_STOP),
434 FALSE, FALSE, 0);
435
436 /* spacer */
437 gtk_box_pack_start (GTK_BOX (hbox),
438 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
439 TRUE, TRUE, 0);
440
441 return hbox;
442 }
443
444 static GtkWidget* pane_operate_operate(GtkWidget* top, omnplay_instance_t* app)
445 {
446 GtkWidget* vbox;
447
448 vbox = gtk_vbox_new (FALSE, 0);
449 gtk_widget_show (vbox);
450
451 /* add buttons box #1 */
452 gtk_box_pack_start (GTK_BOX (vbox),
453 pane_operate_buttons_playlist(top, app),
454 FALSE, FALSE, 0);
455
456 /* add buttons box */
457 gtk_box_pack_start (GTK_BOX (vbox),
458 pane_operate_grid(top, app),
459 TRUE, TRUE, 0);
460
461 /* add buttons box #1 */
462 gtk_box_pack_start (GTK_BOX (vbox),
463 pane_operate_buttons_operate(top, app),
464 FALSE, FALSE, 0);
465
466 return vbox;
467
468 }
469
470 static GtkWidget* pane_operate(GtkWidget* top, omnplay_instance_t* app)
471 {
472 GtkWidget* hbox;
473
474 hbox = gtk_hbox_new (FALSE, 0);
475 gtk_widget_show (hbox);
476
477 /* add buttons box */
478 gtk_box_pack_start (GTK_BOX (hbox),
479 pane_operate_status(top, app),
480 FALSE, FALSE, 0);
481
482 /* add buttons box */
483 gtk_box_pack_start (GTK_BOX (hbox),
484 pane_operate_operate(top, app),
485 TRUE, TRUE, 0);
486
487 return hbox;
488
489 };
490
491 static GtkWidget* pane_top(GtkWidget* top, omnplay_instance_t* app)
492 {
493 GtkWidget* pane;
494
495 pane = gtk_hpaned_new ();
496 gtk_widget_show (pane);
497
498 gtk_paned_set_position (GTK_PANED (pane), 800);
499
500 gtk_paned_pack1 (GTK_PANED (pane),
501 pane_operate(top, app),
502 TRUE, FALSE);
503
504 gtk_paned_pack2 (GTK_PANED (pane),
505 pane_library(top, app),
506 FALSE, FALSE);
507
508 return pane;
509 }
510
511 GtkWidget* ui_omnplay (omnplay_instance_t* app)
512 {
513 GtkWidget *wnd;
514
515 wnd = gtk_window_new (GTK_WINDOW_TOPLEVEL);
516 GLADE_HOOKUP_OBJECT_NO_REF (wnd, wnd, "omnplay_window");
517
518 gtk_window_set_title (GTK_WINDOW (wnd), _("Omneon Player"));
519 gtk_window_set_default_size (GTK_WINDOW (wnd), 1024, 768);
520
521 gtk_container_add (GTK_CONTAINER (wnd),
522 pane_top(wnd, app));
523
524 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_BLOCK_BEGIN] =
525 create_pixbuf("block_type_block_start_16x16.png");
526 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_BLOCK_BODY] =
527 create_pixbuf("block_type_block_middle_16x16.png");
528 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_BLOCK_END] =
529 create_pixbuf("block_type_block_end_16x16.png");
530 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE] =
531 create_pixbuf("block_type_block_single_16x16.png");
532 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_LOOP_BEGIN] =
533 create_pixbuf("block_type_loop_start_16x16.png");
534 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_LOOP_BODY] =
535 create_pixbuf("block_type_loop_middle_16x16.png");
536 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_LOOP_END] =
537 create_pixbuf("block_type_loop_end_16x16.png");
538 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_LOOP_SINGLE] =
539 create_pixbuf("block_type_block_loop_16x16.png");
540
541 return wnd;
542 }