store index in treeview data
[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 GtkCellRenderer *renderer;
125 GtkTreeViewColumn *column;
126 GtkListStore *list_store;
127 GType list_store_types[32];
128
129 treeview = gtk_tree_view_new ();
130 gtk_widget_show (treeview);
131
132 for(i = 0, count = 0; columns[i].title; i++, count++)
133 list_store_types[i] = (columns[i].type == G_TYPE_OBJECT)?GDK_TYPE_PIXBUF:columns[i].type;
134 list_store_types[count + 1] = G_TYPE_INT;
135
136 list_store = gtk_list_store_newv(count + 1, list_store_types);
137
138 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview ), GTK_TREE_MODEL( list_store ) );
139
140 for(i = 0; columns[i].title; i++)
141 {
142 char* prop;
143
144 if(columns[i].type == G_TYPE_OBJECT)
145 {
146 renderer = gtk_cell_renderer_pixbuf_new();
147 gtk_cell_renderer_set_padding(renderer, 0, 0);
148 prop = "pixbuf";
149 }
150 else if(columns[i].type == G_TYPE_BOOLEAN)
151 {
152 renderer = gtk_cell_renderer_toggle_new();
153 prop = "active";
154 }
155 else
156 {
157 renderer = gtk_cell_renderer_text_new();
158 prop = "text";
159 }
160
161 column = gtk_tree_view_column_new_with_attributes(
162 columns[i].title, renderer, prop, i, NULL);
163 gtk_tree_view_append_column(GTK_TREE_VIEW( treeview ), column);
164 };
165
166 g_object_unref(list_store);
167
168 GLADE_HOOKUP_OBJECT (top, treeview, name);
169
170 return treeview;
171 };
172
173 static GtkWidget* pane_library_grid(GtkWidget* top, omnplay_instance_t* app)
174 {
175 GtkWidget *scrolledwindow;
176
177 scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
178 gtk_widget_show (scrolledwindow);
179 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
180 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
181
182 gtk_container_add (GTK_CONTAINER (scrolledwindow),
183 app->library_grid = create_treeview(top, "treeview_library", library_columns));
184
185 return scrolledwindow;
186 }
187
188 static GtkWidget* pane_library_buttons(GtkWidget* top, omnplay_instance_t* app)
189 {
190 GtkWidget* hbox;
191
192 hbox = gtk_hbox_new (FALSE, 0);
193 gtk_widget_show (hbox);
194
195 /* playlist modify buttons */
196 gtk_box_pack_start (GTK_BOX (hbox),
197 ui_create_button(top, app, BUTTON_LIBRARY_ADD),
198 FALSE, FALSE, 0);
199 gtk_box_pack_start (GTK_BOX (hbox),
200 ui_create_button(top, app, BUTTON_LIBRARY_REFRESH),
201 FALSE, FALSE, 0);
202
203 /* spacer */
204 gtk_box_pack_start (GTK_BOX (hbox),
205 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
206 TRUE, TRUE, 0);
207
208 return hbox;
209 }
210
211 static GtkWidget* pane_library(GtkWidget* top, omnplay_instance_t* app)
212 {
213 GtkWidget* vbox;
214
215 vbox = gtk_vbox_new (FALSE, 0);
216 gtk_widget_show (vbox);
217 gtk_widget_set_size_request(vbox, 300, -1);
218
219 /* add buttons box */
220 gtk_box_pack_start (GTK_BOX (vbox),
221 pane_library_buttons(top, app),
222 FALSE, FALSE, 0);
223
224 /* add buttons box */
225 gtk_box_pack_start (GTK_BOX (vbox),
226 pane_library_grid(top, app),
227 TRUE, TRUE, 0);
228
229 return vbox;
230 }
231
232 static GtkWidget* create_channel_status(GtkWidget* top, omnplay_instance_t* app, int idx)
233 {
234 GtkWidget* vbox;
235 GtkWidget* hbox;
236 GtkWidget* frame;
237 omnplay_player_t* player;
238
239 player = &app->players.item[idx];
240
241 frame = gtk_frame_new(player->name);
242 gtk_widget_show(frame);
243
244 vbox = gtk_vbox_new(FALSE, 0);
245 gtk_container_add(GTK_CONTAINER(frame), vbox);
246 gtk_widget_show(vbox);
247
248 /* status label */
249 gtk_box_pack_start(GTK_BOX (vbox),
250 player->label_status = create_label(top, "OFFLINE", NULL, GTK_JUSTIFY_LEFT),
251 FALSE, FALSE, 0);
252
253 /* spacel label */
254 gtk_box_pack_start(GTK_BOX (vbox),
255 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
256 FALSE, FALSE, 0);
257
258 /* clip label */
259 gtk_box_pack_start (GTK_BOX (vbox),
260 player->label_clip = create_label(top, "U0002323", NULL, GTK_JUSTIFY_LEFT),
261 FALSE, FALSE, 0);
262
263 /* block state/current timecode */
264 gtk_box_pack_start(GTK_BOX (vbox),
265 hbox = gtk_hbox_new(TRUE, 0),
266 FALSE, FALSE, 0);
267 gtk_widget_show(hbox);
268
269 {
270 /* clip state */
271 gtk_box_pack_start(GTK_BOX (hbox),
272 player->label_state = create_label(top, "PLAYING", NULL, GTK_JUSTIFY_LEFT),
273 TRUE, TRUE, 0);
274
275 /* current timecode */
276 gtk_box_pack_start(GTK_BOX (hbox),
277 player->label_tc_cur = create_label(top, "00:00:00:00", NULL, GTK_JUSTIFY_LEFT),
278 TRUE, TRUE, 0);
279 };
280
281 /* block remain label/remain timecode */
282 gtk_box_pack_start(GTK_BOX (vbox),
283 hbox = gtk_hbox_new(TRUE, 0),
284 FALSE, FALSE, 0);
285 gtk_widget_show (hbox);
286
287 {
288 /* label */
289 gtk_box_pack_start(GTK_BOX (hbox),
290 create_label(top, "remain:", NULL, GTK_JUSTIFY_LEFT),
291 TRUE, TRUE, 0);
292
293 /* remaining timecode */
294 gtk_box_pack_start(GTK_BOX (hbox),
295 player->label_tc_rem = create_label(top, "00:00:00:00", NULL, GTK_JUSTIFY_LEFT),
296 TRUE, TRUE, 0);
297 };
298
299 return frame;
300 }
301
302 static GtkWidget* pane_operate_status(GtkWidget* top, omnplay_instance_t* app)
303 {
304 int i;
305 GtkWidget* vbox;
306
307 vbox = gtk_vbox_new (FALSE, 0);
308 gtk_widget_show (vbox);
309 gtk_widget_set_size_request(vbox, 250, -1);
310
311 for(i = 0; i < app->players.count; i++)
312 {
313 gtk_box_pack_start (GTK_BOX (vbox),
314 create_channel_status(top, app, i),
315 FALSE, FALSE, 0);
316
317 /* spacer */
318 gtk_box_pack_start (GTK_BOX (vbox),
319 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
320 FALSE, FALSE, 0);
321 }
322
323 /* spacer */
324 gtk_box_pack_start (GTK_BOX (vbox),
325 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
326 TRUE, TRUE, 0);
327
328 return vbox;
329 }
330
331 static GtkWidget* pane_operate_buttons_playlist(GtkWidget* top, omnplay_instance_t* app)
332 {
333 GtkWidget* hbox;
334
335 hbox = gtk_hbox_new (FALSE, 0);
336 gtk_widget_show (hbox);
337
338 /* playlist load/save buttons */
339 gtk_box_pack_start (GTK_BOX (hbox),
340 ui_create_button(top, app, BUTTON_PLAYLIST_LOAD),
341 FALSE, FALSE, 0);
342 gtk_box_pack_start (GTK_BOX (hbox),
343 ui_create_button(top, app, BUTTON_PLAYLIST_SAVE),
344 FALSE, FALSE, 0);
345
346 /* spacer */
347 gtk_box_pack_start (GTK_BOX (hbox),
348 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
349 FALSE, FALSE, 0);
350
351 /* playlist modify buttons */
352 gtk_box_pack_start (GTK_BOX (hbox),
353 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_ADD),
354 FALSE, FALSE, 0);
355 gtk_box_pack_start (GTK_BOX (hbox),
356 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_EDIT),
357 FALSE, FALSE, 0);
358 gtk_box_pack_start (GTK_BOX (hbox),
359 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_DEL),
360 FALSE, FALSE, 0);
361
362 /* spacer */
363 gtk_box_pack_start (GTK_BOX (hbox),
364 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
365 FALSE, FALSE, 0);
366
367 /* playlist block buttons */
368 gtk_box_pack_start (GTK_BOX (hbox),
369 ui_create_button(top, app, BUTTON_PLAYLIST_BLOCK_SINGLE),
370 FALSE, FALSE, 0);
371 gtk_box_pack_start (GTK_BOX (hbox),
372 ui_create_button(top, app, BUTTON_PLAYLIST_BLOCK_LOOP),
373 FALSE, FALSE, 0);
374
375 /* spacer */
376 gtk_box_pack_start (GTK_BOX (hbox),
377 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
378 FALSE, FALSE, 0);
379
380 /* playlist move items buttons */
381 gtk_box_pack_start (GTK_BOX (hbox),
382 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_UP),
383 FALSE, FALSE, 0);
384 gtk_box_pack_start (GTK_BOX (hbox),
385 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_DOWN),
386 FALSE, FALSE, 0);
387
388 return hbox;
389 }
390
391 static GtkWidget* pane_operate_grid(GtkWidget* top, omnplay_instance_t* app)
392 {
393 GtkWidget *scrolledwindow;
394
395 scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
396 gtk_widget_show (scrolledwindow);
397 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
398 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
399
400 gtk_container_add (GTK_CONTAINER (scrolledwindow),
401 app->playlist_grid = create_treeview(top, "treeview_playlist", playlist_columns));
402
403 return scrolledwindow;
404 }
405
406 static GtkWidget* pane_operate_buttons_operate(GtkWidget* top, omnplay_instance_t* app)
407 {
408 GtkWidget* hbox;
409
410 hbox = gtk_hbox_new (FALSE, 0);
411 gtk_widget_show (hbox);
412
413 /* spacer */
414 gtk_box_pack_start (GTK_BOX (hbox),
415 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
416 TRUE, TRUE, 0);
417
418 /* playlist modify buttons */
419 gtk_box_pack_start (GTK_BOX (hbox),
420 ui_create_button(top, app, BUTTON_PLAYER_CUE),
421 FALSE, FALSE, 0);
422 gtk_box_pack_start (GTK_BOX (hbox),
423 ui_create_button(top, app, BUTTON_PLAYER_PLAY),
424 FALSE, FALSE, 0);
425 gtk_box_pack_start (GTK_BOX (hbox),
426 ui_create_button(top, app, BUTTON_PLAYER_PAUSE),
427 FALSE, FALSE, 0);
428 gtk_box_pack_start (GTK_BOX (hbox),
429 ui_create_button(top, app, BUTTON_PLAYER_STOP),
430 FALSE, FALSE, 0);
431
432 /* spacer */
433 gtk_box_pack_start (GTK_BOX (hbox),
434 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
435 TRUE, TRUE, 0);
436
437 return hbox;
438 }
439
440 static GtkWidget* pane_operate_operate(GtkWidget* top, omnplay_instance_t* app)
441 {
442 GtkWidget* vbox;
443
444 vbox = gtk_vbox_new (FALSE, 0);
445 gtk_widget_show (vbox);
446
447 /* add buttons box #1 */
448 gtk_box_pack_start (GTK_BOX (vbox),
449 pane_operate_buttons_playlist(top, app),
450 FALSE, FALSE, 0);
451
452 /* add buttons box */
453 gtk_box_pack_start (GTK_BOX (vbox),
454 pane_operate_grid(top, app),
455 TRUE, TRUE, 0);
456
457 /* add buttons box #1 */
458 gtk_box_pack_start (GTK_BOX (vbox),
459 pane_operate_buttons_operate(top, app),
460 FALSE, FALSE, 0);
461
462 return vbox;
463
464 }
465
466 static GtkWidget* pane_operate(GtkWidget* top, omnplay_instance_t* app)
467 {
468 GtkWidget* hbox;
469
470 hbox = gtk_hbox_new (FALSE, 0);
471 gtk_widget_show (hbox);
472
473 /* add buttons box */
474 gtk_box_pack_start (GTK_BOX (hbox),
475 pane_operate_status(top, app),
476 FALSE, FALSE, 0);
477
478 /* add buttons box */
479 gtk_box_pack_start (GTK_BOX (hbox),
480 pane_operate_operate(top, app),
481 TRUE, TRUE, 0);
482
483 return hbox;
484
485 };
486
487 static GtkWidget* pane_top(GtkWidget* top, omnplay_instance_t* app)
488 {
489 GtkWidget* pane;
490
491 pane = gtk_hpaned_new ();
492 gtk_widget_show (pane);
493
494 gtk_paned_set_position (GTK_PANED (pane), 800);
495
496 gtk_paned_pack1 (GTK_PANED (pane),
497 pane_operate(top, app),
498 TRUE, FALSE);
499
500 gtk_paned_pack2 (GTK_PANED (pane),
501 pane_library(top, app),
502 FALSE, FALSE);
503
504 return pane;
505 }
506
507 GtkWidget* ui_omnplay (omnplay_instance_t* app)
508 {
509 GtkWidget *wnd;
510
511 wnd = gtk_window_new (GTK_WINDOW_TOPLEVEL);
512 GLADE_HOOKUP_OBJECT_NO_REF (wnd, wnd, "omnplay_window");
513
514 gtk_window_set_title (GTK_WINDOW (wnd), _("Omneon Player"));
515 gtk_window_set_default_size (GTK_WINDOW (wnd), 1024, 768);
516
517 gtk_container_add (GTK_CONTAINER (wnd),
518 pane_top(wnd, app));
519
520 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_BLOCK_BEGIN] =
521 create_pixbuf("block_type_block_start_16x16.png");
522 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_BLOCK_BODY] =
523 create_pixbuf("block_type_block_middle_16x16.png");
524 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_BLOCK_END] =
525 create_pixbuf("block_type_block_end_16x16.png");
526 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE] =
527 create_pixbuf("block_type_block_single_16x16.png");
528 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_LOOP_BEGIN] =
529 create_pixbuf("block_type_loop_start_16x16.png");
530 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_LOOP_BODY] =
531 create_pixbuf("block_type_loop_middle_16x16.png");
532 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_LOOP_END] =
533 create_pixbuf("block_type_loop_end_16x16.png");
534 app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_LOOP_SINGLE] =
535 create_pixbuf("block_type_block_loop_16x16.png");
536
537 return wnd;
538 }