minimal working library
[melted_gui] / src / ui.c
1 /*
2 * ui.c -- GTK+ 2 melted gui
3 * Copyright (C) 2012 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 #include "timecode.h"
38
39 typedef struct column_desc
40 {
41 char* title;
42 GType type;
43 } column_desc_t;
44
45 static const column_desc_t playlist_columns[] =
46 {
47 {
48 "REM",
49 G_TYPE_STRING
50 },
51 {
52 "B",
53 G_TYPE_OBJECT
54 },
55 {
56 "CH",
57 G_TYPE_STRING
58 },
59 {
60 "ID",
61 G_TYPE_STRING
62 },
63 {
64 "IN",
65 G_TYPE_STRING
66 },
67 {
68 "DUR",
69 G_TYPE_STRING
70 },
71 {
72 "TITLE",
73 G_TYPE_STRING
74 },
75 {
76 NULL,
77 G_TYPE_STRING
78 }
79 };
80
81 const static column_desc_t library_columns[] =
82 {
83 {
84 "TYPE",
85 G_TYPE_OBJECT
86 },
87 {
88 "DUR",
89 G_TYPE_STRING
90 },
91 {
92 "NAME",
93 G_TYPE_STRING
94 },
95 {
96 NULL,
97 G_TYPE_STRING
98 }
99 };
100
101
102 static GtkWidget* create_label(GtkWidget* top, char* text, char* reg, GtkJustification jtype)
103 {
104 GtkWidget* label;
105
106 label = gtk_label_new ("");
107 gtk_widget_show (label);
108
109 if(jtype)
110 gtk_label_set_justify (GTK_LABEL (label), jtype);
111
112 if(reg)
113 GLADE_HOOKUP_OBJECT (top, label, reg);
114
115 if(text)
116 gtk_label_set_text(GTK_LABEL (label), text);
117
118 return label;
119 };
120
121 static GtkWidget* create_treeview_list(GtkWidget* top, char* name, const column_desc_t columns[])
122 {
123 int i, count;
124
125 GtkWidget *treeview;
126 GtkTreeSelection *selection;
127 GtkCellRenderer *renderer;
128 GtkTreeViewColumn *column;
129 GtkListStore *list_store;
130 GType list_store_types[32];
131
132 treeview = gtk_tree_view_new ();
133 gtk_widget_show (treeview);
134 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
135 gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(treeview), GTK_TREE_VIEW_GRID_LINES_BOTH);
136
137 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
138 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
139
140 for(i = 0, count = 0; columns[i].title; i++, count++)
141 list_store_types[i] = (columns[i].type == G_TYPE_OBJECT)?GDK_TYPE_PIXBUF:columns[i].type;
142 list_store_types[count] = G_TYPE_INT;
143 list_store_types[count + 1] = G_TYPE_BOOLEAN;
144 list_store_types[count + 2] = G_TYPE_STRING;
145
146 list_store = gtk_list_store_newv(count + 3, list_store_types);
147
148 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview ), GTK_TREE_MODEL( list_store ) );
149
150 for(i = 0; columns[i].title; i++)
151 {
152 char* prop;
153 column = NULL;
154
155 if(columns[i].type == G_TYPE_OBJECT)
156 {
157 renderer = gtk_cell_renderer_pixbuf_new();
158 gtk_cell_renderer_set_padding(renderer, 0, 0);
159 prop = "pixbuf";
160 }
161 else if(columns[i].type == G_TYPE_BOOLEAN)
162 {
163 renderer = gtk_cell_renderer_toggle_new();
164 prop = "active";
165 }
166 else
167 {
168 renderer = gtk_cell_renderer_text_new();
169 prop = "text";
170
171 column = gtk_tree_view_column_new_with_attributes(
172 columns[i].title, renderer,
173 prop, i,
174 "background-set", count + 1,
175 "background", count + 2,
176 NULL);
177 }
178
179 if(!column)
180 column = gtk_tree_view_column_new_with_attributes(
181 columns[i].title, renderer,
182 prop, i,
183 NULL);
184
185 gtk_tree_view_append_column(GTK_TREE_VIEW( treeview ), column);
186 };
187
188 g_object_unref(list_store);
189
190 GLADE_HOOKUP_OBJECT (top, treeview, name);
191
192 return treeview;
193 };
194
195 static GtkWidget* create_treeview_tree(GtkWidget* top, char* name, const column_desc_t columns[])
196 {
197 int i, count;
198
199 GtkWidget *treeview;
200 GtkTreeSelection *selection;
201 GtkCellRenderer *renderer;
202 GtkTreeViewColumn *column;
203 GtkTreeStore *tree_store;
204 GType tree_store_types[32];
205
206 treeview = gtk_tree_view_new ();
207 gtk_widget_show (treeview);
208 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
209 gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(treeview), GTK_TREE_VIEW_GRID_LINES_BOTH);
210
211 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
212 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
213
214 for(i = 0, count = 0; columns[i].title; i++, count++)
215 tree_store_types[i] = (columns[i].type == G_TYPE_OBJECT)?GDK_TYPE_PIXBUF:columns[i].type;
216 tree_store_types[count + 0] = G_TYPE_POINTER;
217 tree_store_types[count + 1] = G_TYPE_POINTER;
218 tree_store_types[count + 2] = G_TYPE_BOOLEAN;
219 tree_store_types[count + 3] = G_TYPE_STRING;
220
221 tree_store = gtk_tree_store_newv(count + 4, tree_store_types);
222
223 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview ), GTK_TREE_MODEL( tree_store ) );
224
225 for(i = 0; columns[i].title; i++)
226 {
227 char* prop;
228 column = NULL;
229
230 if(columns[i].type == G_TYPE_OBJECT)
231 {
232 renderer = gtk_cell_renderer_pixbuf_new();
233 gtk_cell_renderer_set_padding(renderer, 0, 0);
234 prop = "pixbuf";
235 }
236 else if(columns[i].type == G_TYPE_BOOLEAN)
237 {
238 renderer = gtk_cell_renderer_toggle_new();
239 prop = "active";
240 }
241 else
242 {
243 renderer = gtk_cell_renderer_text_new();
244 prop = "text";
245
246 column = gtk_tree_view_column_new_with_attributes(
247 columns[i].title, renderer,
248 prop, i,
249 "background-set", count + 2,
250 "background", count + 3,
251 NULL);
252 }
253
254 if(!column)
255 column = gtk_tree_view_column_new_with_attributes(
256 columns[i].title, renderer,
257 prop, i,
258 NULL);
259
260 gtk_tree_view_append_column(GTK_TREE_VIEW( treeview ), column);
261 };
262
263 g_object_unref(tree_store);
264
265 GLADE_HOOKUP_OBJECT (top, treeview, name);
266
267 return treeview;
268 };
269
270 static GtkWidget* pane_library_tree(GtkWidget* top, instance_t* app)
271 {
272 GtkWidget *scrolledwindow;
273
274 scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
275 gtk_widget_show (scrolledwindow);
276 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
277 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
278
279 gtk_container_add (GTK_CONTAINER (scrolledwindow),
280 app->library_tree = create_treeview_tree(top, "treeview_library", library_columns));
281
282 return scrolledwindow;
283 }
284
285 static GtkWidget* pane_library_buttons(GtkWidget* top, instance_t* app)
286 {
287 GtkWidget* hbox;
288
289 hbox = gtk_hbox_new (FALSE, 0);
290 gtk_widget_show (hbox);
291
292 /* playlist modify buttons */
293 gtk_box_pack_start (GTK_BOX (hbox),
294 ui_create_button(top, app, BUTTON_LIBRARY_ADD),
295 FALSE, FALSE, 0);
296 gtk_box_pack_start (GTK_BOX (hbox),
297 ui_create_button(top, app, BUTTON_LIBRARY_REFRESH),
298 FALSE, FALSE, 0);
299
300 /* spacer */
301 gtk_box_pack_start (GTK_BOX (hbox),
302 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
303 TRUE, TRUE, 0);
304
305 return hbox;
306 }
307
308 static GtkWidget* pane_library_search_buttons(GtkWidget* top, instance_t* app)
309 {
310 GtkWidget* hbox;
311
312 hbox = gtk_hbox_new (FALSE, 0);
313 gtk_widget_show (hbox);
314
315 /* text entry */
316 gtk_box_pack_start (GTK_BOX (hbox),
317 app->library.search = gtk_entry_new(),
318 TRUE, TRUE, 0);
319 gtk_widget_show(app->library.search);
320
321 /* playlist modify buttons */
322 gtk_box_pack_start (GTK_BOX (hbox),
323 ui_create_button(top, app, BUTTON_LIBRARY_FIND),
324 FALSE, FALSE, 0);
325 gtk_box_pack_start (GTK_BOX (hbox),
326 ui_create_button(top, app, BUTTON_LIBRARY_FIND_NEXT),
327 FALSE, FALSE, 0);
328
329 return hbox;
330 }
331
332 static GtkWidget* pane_library(GtkWidget* top, instance_t* app)
333 {
334 GtkWidget* vbox;
335
336 vbox = gtk_vbox_new (FALSE, 0);
337 gtk_widget_show (vbox);
338 gtk_widget_set_size_request(vbox, 300, -1);
339
340 /* add buttons box */
341 gtk_box_pack_start (GTK_BOX (vbox),
342 pane_library_buttons(top, app),
343 FALSE, FALSE, 0);
344
345 /* add grid */
346 gtk_box_pack_start (GTK_BOX (vbox),
347 pane_library_tree(top, app),
348 TRUE, TRUE, 0);
349
350 /* add search buttons */
351 gtk_box_pack_start (GTK_BOX (vbox),
352 pane_library_search_buttons(top, app),
353 FALSE, FALSE, 0);
354
355 return vbox;
356 }
357
358 static GtkWidget* create_channel_status(GtkWidget* top, instance_t* app, int idx)
359 {
360 GtkWidget* vbox;
361 GtkWidget* hbox;
362 GtkWidget* frame;
363 char name[PATH_MAX];
364 player_t* player;
365
366 player = &app->players.item[idx];
367
368 snprintf(name, sizeof(name), "unit %d [%c]", player->unit, idx + 'A');
369
370 frame = gtk_frame_new(name);
371 gtk_widget_show(frame);
372
373 vbox = gtk_vbox_new(FALSE, 0);
374 gtk_container_add(GTK_CONTAINER(frame), vbox);
375 gtk_widget_show(vbox);
376
377 /* status label */
378 gtk_box_pack_start(GTK_BOX (vbox),
379 player->label_status = create_label(top, "OFFLINE", NULL, GTK_JUSTIFY_LEFT),
380 FALSE, FALSE, 0);
381
382 /* spacel label */
383 gtk_box_pack_start(GTK_BOX (vbox),
384 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
385 FALSE, FALSE, 0);
386
387 /* clip label */
388 gtk_box_pack_start (GTK_BOX (vbox),
389 player->label_clip = create_label(top, "U0002323", NULL, GTK_JUSTIFY_LEFT),
390 FALSE, FALSE, 0);
391
392 /* block state/current timecode */
393 gtk_box_pack_start(GTK_BOX (vbox),
394 hbox = gtk_hbox_new(TRUE, 0),
395 FALSE, FALSE, 0);
396 gtk_widget_show(hbox);
397
398 {
399 /* clip state */
400 gtk_box_pack_start(GTK_BOX (hbox),
401 player->label_state = create_label(top, "PLAYING", NULL, GTK_JUSTIFY_LEFT),
402 TRUE, TRUE, 0);
403
404 /* current timecode */
405 gtk_box_pack_start(GTK_BOX (hbox),
406 player->label_tc_cur = create_label(top, "00:00:00:00", NULL, GTK_JUSTIFY_LEFT),
407 TRUE, TRUE, 0);
408 };
409
410 /* block remain label/remain timecode */
411 gtk_box_pack_start(GTK_BOX (vbox),
412 hbox = gtk_hbox_new(TRUE, 0),
413 FALSE, FALSE, 0);
414 gtk_widget_show (hbox);
415
416 {
417 /* label */
418 gtk_box_pack_start(GTK_BOX (hbox),
419 create_label(top, "remain:", NULL, GTK_JUSTIFY_LEFT),
420 TRUE, TRUE, 0);
421
422 /* remaining timecode */
423 gtk_box_pack_start(GTK_BOX (hbox),
424 player->label_tc_rem = create_label(top, "00:00:00:00", NULL, GTK_JUSTIFY_LEFT),
425 TRUE, TRUE, 0);
426 };
427
428 return frame;
429 }
430
431 static GtkWidget* pane_operate_status(GtkWidget* top, instance_t* app)
432 {
433 int i;
434 GtkWidget* vbox;
435
436 vbox = gtk_vbox_new (FALSE, 0);
437 gtk_widget_show (vbox);
438 gtk_widget_set_size_request(vbox, 250, -1);
439
440 for(i = 0; i < app->players.count; i++)
441 {
442 gtk_box_pack_start (GTK_BOX (vbox),
443 create_channel_status(top, app, i),
444 FALSE, FALSE, 0);
445
446 /* spacer */
447 gtk_box_pack_start (GTK_BOX (vbox),
448 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
449 FALSE, FALSE, 0);
450 }
451
452 /* spacer */
453 gtk_box_pack_start (GTK_BOX (vbox),
454 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
455 TRUE, TRUE, 0);
456
457 return vbox;
458 }
459
460 static GtkWidget* pane_operate_buttons_playlist(GtkWidget* top, instance_t* app)
461 {
462 GtkWidget* hbox;
463
464 hbox = gtk_hbox_new (FALSE, 0);
465 gtk_widget_show (hbox);
466
467 /* playlist load/save buttons */
468 gtk_box_pack_start (GTK_BOX (hbox),
469 ui_create_button(top, app, BUTTON_PLAYLIST_LOAD),
470 FALSE, FALSE, 0);
471 gtk_box_pack_start (GTK_BOX (hbox),
472 ui_create_button(top, app, BUTTON_PLAYLIST_SAVE),
473 FALSE, FALSE, 0);
474
475 /* spacer */
476 gtk_box_pack_start (GTK_BOX (hbox),
477 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
478 FALSE, FALSE, 0);
479
480 /* playlist modify buttons */
481 gtk_box_pack_start (GTK_BOX (hbox),
482 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_ADD),
483 FALSE, FALSE, 0);
484 gtk_box_pack_start (GTK_BOX (hbox),
485 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_EDIT),
486 FALSE, FALSE, 0);
487 gtk_box_pack_start (GTK_BOX (hbox),
488 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_DEL),
489 FALSE, FALSE, 0);
490
491 /* spacer */
492 gtk_box_pack_start (GTK_BOX (hbox),
493 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
494 FALSE, FALSE, 0);
495
496 /* playlist block buttons */
497 gtk_box_pack_start (GTK_BOX (hbox),
498 ui_create_button(top, app, BUTTON_PLAYLIST_BLOCK_SINGLE),
499 FALSE, FALSE, 0);
500 gtk_box_pack_start (GTK_BOX (hbox),
501 ui_create_button(top, app, BUTTON_PLAYLIST_BLOCK_LOOP),
502 FALSE, FALSE, 0);
503
504 /* spacer */
505 gtk_box_pack_start (GTK_BOX (hbox),
506 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
507 FALSE, FALSE, 0);
508
509 /* playlist move items buttons */
510 gtk_box_pack_start (GTK_BOX (hbox),
511 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_UP),
512 FALSE, FALSE, 0);
513 gtk_box_pack_start (GTK_BOX (hbox),
514 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_DOWN),
515 FALSE, FALSE, 0);
516
517 /* spacer */
518 gtk_box_pack_start (GTK_BOX (hbox),
519 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
520 FALSE, FALSE, 0);
521
522 /* playlist relink */
523 gtk_box_pack_start (GTK_BOX (hbox),
524 ui_create_button(top, app, BUTTON_PLAYLIST_RELINK),
525 FALSE, FALSE, 0);
526
527 return hbox;
528 }
529
530 static GtkWidget* pane_operate_grid(GtkWidget* top, instance_t* app)
531 {
532 GtkWidget *scrolledwindow;
533
534 scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
535 gtk_widget_show (scrolledwindow);
536 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
537 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
538
539 gtk_container_add (GTK_CONTAINER (scrolledwindow),
540 app->playlist_grid = create_treeview_list(top, "treeview_playlist", playlist_columns));
541
542 return scrolledwindow;
543 }
544
545 static GtkWidget* pane_operate_buttons_operate(GtkWidget* top, instance_t* app)
546 {
547 GtkWidget* hbox;
548
549 hbox = gtk_hbox_new (FALSE, 0);
550 gtk_widget_show (hbox);
551
552 /* spacer */
553 gtk_box_pack_start (GTK_BOX (hbox),
554 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
555 TRUE, TRUE, 0);
556
557 /* playlist modify buttons */
558 gtk_box_pack_start (GTK_BOX (hbox),
559 ui_create_button(top, app, BUTTON_PLAYER_CUE),
560 FALSE, FALSE, 0);
561 gtk_box_pack_start (GTK_BOX (hbox),
562 ui_create_button(top, app, BUTTON_PLAYER_PLAY),
563 FALSE, FALSE, 0);
564 gtk_box_pack_start (GTK_BOX (hbox),
565 ui_create_button(top, app, BUTTON_PLAYER_PAUSE),
566 FALSE, FALSE, 0);
567 gtk_box_pack_start (GTK_BOX (hbox),
568 ui_create_button(top, app, BUTTON_PLAYER_STOP),
569 FALSE, FALSE, 0);
570
571 /* spacer */
572 gtk_box_pack_start (GTK_BOX (hbox),
573 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
574 TRUE, TRUE, 0);
575
576 return hbox;
577 }
578
579 static GtkWidget* pane_operate_operate(GtkWidget* top, instance_t* app)
580 {
581 GtkWidget* vbox;
582
583 vbox = gtk_vbox_new (FALSE, 0);
584 gtk_widget_show (vbox);
585
586 /* add buttons box #1 */
587 gtk_box_pack_start (GTK_BOX (vbox),
588 pane_operate_buttons_playlist(top, app),
589 FALSE, FALSE, 0);
590
591 /* add buttons box */
592 gtk_box_pack_start (GTK_BOX (vbox),
593 pane_operate_grid(top, app),
594 TRUE, TRUE, 0);
595
596 /* add buttons box #1 */
597 gtk_box_pack_start (GTK_BOX (vbox),
598 pane_operate_buttons_operate(top, app),
599 FALSE, FALSE, 0);
600
601 return vbox;
602
603 }
604
605 static GtkWidget* pane_operate(GtkWidget* top, instance_t* app)
606 {
607 GtkWidget* hbox;
608
609 hbox = gtk_hbox_new (FALSE, 0);
610 gtk_widget_show (hbox);
611
612 /* add buttons box */
613 gtk_box_pack_start (GTK_BOX (hbox),
614 pane_operate_status(top, app),
615 FALSE, FALSE, 0);
616
617 /* add buttons box */
618 gtk_box_pack_start (GTK_BOX (hbox),
619 pane_operate_operate(top, app),
620 TRUE, TRUE, 0);
621
622 return hbox;
623
624 };
625
626 static GtkWidget* pane_top(GtkWidget* top, instance_t* app)
627 {
628 GtkWidget* pane;
629
630 pane = gtk_hpaned_new ();
631 gtk_widget_show (pane);
632
633 gtk_paned_set_position (GTK_PANED (pane), 800);
634
635 gtk_paned_pack1 (GTK_PANED (pane),
636 pane_operate(top, app),
637 TRUE, FALSE);
638
639 gtk_paned_pack2 (GTK_PANED (pane),
640 pane_library(top, app),
641 FALSE, FALSE);
642
643 return pane;
644 }
645
646 GtkWidget* ui_create(instance_t* app)
647 {
648 GtkWidget *wnd;
649 GtkWidget* vbox;
650
651 wnd = gtk_window_new (GTK_WINDOW_TOPLEVEL);
652 GLADE_HOOKUP_OBJECT_NO_REF (wnd, wnd, PACKAGE "_window");
653
654 gtk_window_set_title (GTK_WINDOW (wnd), _(PRODUCT_NAME));
655 gtk_window_set_default_size (GTK_WINDOW (wnd), 1024, 768);
656
657 vbox = gtk_vbox_new(FALSE, 0);
658 gtk_widget_show(vbox);
659
660 gtk_container_add(GTK_CONTAINER(wnd), vbox);
661
662 gtk_box_pack_start (GTK_BOX (vbox),
663 pane_top(wnd, app),
664 TRUE, TRUE, 0);
665 gtk_box_pack_start (GTK_BOX (vbox),
666 app->status_label = create_label(wnd, "started", NULL, GTK_JUSTIFY_LEFT),
667 FALSE, FALSE, 0);
668
669 app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_BEGIN] =
670 create_pixbuf("block_type_block_start_16x16.png");
671 app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_BODY] =
672 create_pixbuf("block_type_block_middle_16x16.png");
673 app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_END] =
674 create_pixbuf("block_type_block_end_16x16.png");
675 app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_SINGLE] =
676 create_pixbuf("block_type_block_single_16x16.png");
677 app->playlist.block_icons[PLAYLIST_ITEM_LOOP_BEGIN] =
678 create_pixbuf("block_type_loop_start_16x16.png");
679 app->playlist.block_icons[PLAYLIST_ITEM_LOOP_BODY] =
680 create_pixbuf("block_type_loop_middle_16x16.png");
681 app->playlist.block_icons[PLAYLIST_ITEM_LOOP_END] =
682 create_pixbuf("block_type_loop_end_16x16.png");
683 app->playlist.block_icons[PLAYLIST_ITEM_LOOP_SINGLE] =
684 create_pixbuf("block_type_block_loop_16x16.png");
685
686 return wnd;
687 }
688
689 int ui_playlist_item_dialog(instance_t* app, playlist_item_t* item)
690 {
691 int r, c;
692 char tc[32];
693 GtkWidget *dlg;
694 gint response;
695 GtkWidget *box, *table;
696 GtkWidget *entry[4], *combo;
697
698 dlg = gtk_dialog_new_with_buttons(
699 "Playlist item",
700 GTK_WINDOW(app->window),
701 GTK_DIALOG_MODAL,
702 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
703 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
704 NULL);
705
706 box = gtk_dialog_get_content_area(GTK_DIALOG(dlg));
707
708 table = gtk_table_new(5, 2, TRUE);
709 gtk_widget_show(table);
710 gtk_box_pack_start(GTK_BOX(box), table, TRUE, TRUE, 0);
711
712 gtk_table_attach(GTK_TABLE(table),
713 create_label(NULL, "ID:", NULL, 0),
714 0, 1, 0, 1,
715 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
716
717 gtk_table_attach(GTK_TABLE(table),
718 create_label(NULL, "IN:", NULL, GTK_JUSTIFY_RIGHT),
719 0, 1, 1, 2,
720 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
721
722 gtk_table_attach(GTK_TABLE(table),
723 create_label(NULL, "DUR:", NULL, GTK_JUSTIFY_RIGHT),
724 0, 1, 2, 3,
725 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
726
727 gtk_table_attach(GTK_TABLE(table),
728 create_label(NULL, "TITLE:", NULL, GTK_JUSTIFY_RIGHT),
729 0, 1, 3, 4,
730 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
731
732 gtk_table_attach(GTK_TABLE(table),
733 create_label(NULL, "CHANNEL:", NULL, GTK_JUSTIFY_RIGHT),
734 0, 1, 4, 5,
735 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
736
737
738 gtk_table_attach(GTK_TABLE(table),
739 entry[0] = gtk_entry_new_with_max_length(32),
740 1, 2, 0, 1,
741 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
742
743 gtk_table_attach(GTK_TABLE(table),
744 entry[1] = gtk_entry_new_with_max_length(12),
745 1, 2, 1, 2,
746 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
747
748 gtk_table_attach(GTK_TABLE(table),
749 entry[2] = gtk_entry_new_with_max_length(12),
750 1, 2, 2, 3,
751 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
752
753 gtk_table_attach(GTK_TABLE(table),
754 entry[3] = gtk_entry_new_with_max_length(128),
755 1, 2, 3, 4,
756 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
757
758 gtk_table_attach(GTK_TABLE(table),
759 combo = gtk_combo_box_new_text(),
760 1, 2, 4, 5,
761 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
762
763
764 /* setup data */
765 gtk_entry_set_text(GTK_ENTRY(entry[0]), item->id);
766 gtk_entry_set_text(GTK_ENTRY(entry[1]), frames2tc(item->in, 25.0, tc));
767 gtk_entry_set_text(GTK_ENTRY(entry[2]), frames2tc(item->dur, 25.0, tc));
768 gtk_entry_set_text(GTK_ENTRY(entry[3]), item->title);
769 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "A");
770 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "B");
771 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "C");
772 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "D");
773 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), item->player);
774
775 gtk_widget_show_all(dlg);
776
777 /* Run dialog */
778 for(c = 1; c;)
779 {
780 response = gtk_dialog_run(GTK_DIALOG(dlg));
781
782 if( GTK_RESPONSE_REJECT == response ||
783 GTK_RESPONSE_DELETE_EVENT == response ||
784 GTK_RESPONSE_CANCEL == response)
785 {
786 r = 0;
787 c = 0;
788 }
789 else
790 {
791 r = 1;
792
793 /* get item data back */
794 strncpy(item->id, gtk_entry_get_text(GTK_ENTRY(entry[0])), PATH_MAX);
795 tc2frames((char*)gtk_entry_get_text(GTK_ENTRY(entry[1])), 25.0, &item->in);
796 tc2frames((char*)gtk_entry_get_text(GTK_ENTRY(entry[2])), 25.0, &item->dur);
797 strncpy(item->title, gtk_entry_get_text(GTK_ENTRY(entry[3])), PATH_MAX);
798 item->player = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
799
800 /* check if all data entered correctly */
801 if(item->id[0])
802 c = 0;
803 };
804 };
805
806 gtk_widget_hide(dlg);
807 gtk_widget_destroy(dlg);
808
809 return r;
810 };
811
812 /********************************************************************************/
813
814 void ui_update_player(player_t* player, char *tc_cur, char *tc_rem, char *state, char *status, char *clip)
815 {
816 /* update status in status page */
817 gdk_threads_enter();
818 gtk_label_set_text(GTK_LABEL (player->label_tc_cur), tc_cur);
819 gtk_label_set_text(GTK_LABEL (player->label_tc_rem), tc_rem);
820 gtk_label_set_text(GTK_LABEL (player->label_state), state);
821 gtk_label_set_text(GTK_LABEL (player->label_status), status);
822 gtk_label_set_text(GTK_LABEL (player->label_clip), clip);
823 gdk_flush();
824 gdk_threads_leave();
825 };
826
827 static gboolean ui_playlist_draw_item_rem_proc(
828 GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
829 {
830 int i;
831 void** args = (void**)user_data;
832 GtkListStore *list_store = (GtkListStore *)args[1];
833 int idx = (int)args[2];
834 char* rem = (char*)args[3];
835
836 gtk_tree_model_get(model, iter, 7, &i, -1);
837
838 if(i != idx) return FALSE;
839
840 gtk_list_store_set(list_store, iter, 0, rem, -1);
841
842 return TRUE;
843 };
844
845 void ui_playlist_draw_item_rem(instance_t* app, int idx, char* rem)
846 {
847 void* item[4];
848 GtkListStore *list_store;
849
850 gdk_threads_enter();
851
852 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app->playlist_grid)));
853
854 item[0] = (void*)app;
855 item[1] = (void*)list_store;
856 item[2] = (void*)idx;
857 item[3] = (void*)rem;
858
859 gtk_tree_model_foreach(GTK_TREE_MODEL(list_store), ui_playlist_draw_item_rem_proc, item);
860
861 gdk_flush();
862 gdk_threads_leave();
863 };