change id,title order. playlist load implement
[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 #include <stdlib.h>
30
31 #include <gdk/gdkkeysyms.h>
32 #include <gtk/gtk.h>
33
34 #include "ui.h"
35 #include "ui_utils.h"
36 #include "ui_buttons.h"
37 #include "support.h"
38 #include "timecode.h"
39 #include "playlist.h"
40
41 typedef struct column_desc
42 {
43 char* title;
44 GType type;
45 } column_desc_t;
46
47 static const column_desc_t playlist_columns[] =
48 {
49 {
50 "REM",
51 G_TYPE_STRING
52 },
53 {
54 "B",
55 G_TYPE_OBJECT
56 },
57 {
58 "CH",
59 G_TYPE_STRING
60 },
61 {
62 "TITLE",
63 G_TYPE_STRING
64 },
65 {
66 "IN",
67 G_TYPE_STRING
68 },
69 {
70 "DUR",
71 G_TYPE_STRING
72 },
73 {
74 "ID",
75 G_TYPE_STRING
76 },
77 {
78 NULL,
79 G_TYPE_STRING
80 }
81 };
82
83 const static column_desc_t library_columns[] =
84 {
85 {
86 "TYPE",
87 G_TYPE_OBJECT
88 },
89 {
90 "DUR",
91 G_TYPE_STRING
92 },
93 {
94 "NAME",
95 G_TYPE_STRING
96 },
97 {
98 NULL,
99 G_TYPE_STRING
100 }
101 };
102
103
104 static GtkWidget* create_label(GtkWidget* top, char* text, char* reg, GtkJustification jtype)
105 {
106 GtkWidget* label;
107
108 label = gtk_label_new ("");
109 gtk_widget_show (label);
110
111 if(jtype)
112 gtk_label_set_justify (GTK_LABEL (label), jtype);
113
114 if(reg)
115 GLADE_HOOKUP_OBJECT (top, label, reg);
116
117 if(text)
118 gtk_label_set_text(GTK_LABEL (label), text);
119
120 return label;
121 };
122
123 static GtkWidget* create_treeview_list(GtkWidget* top, char* name, const column_desc_t columns[])
124 {
125 int i, count;
126
127 GtkWidget *treeview;
128 GtkTreeSelection *selection;
129 GtkCellRenderer *renderer;
130 GtkTreeViewColumn *column;
131 GtkListStore *list_store;
132 GType list_store_types[32];
133
134 treeview = gtk_tree_view_new ();
135 gtk_widget_show (treeview);
136 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
137 gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(treeview), GTK_TREE_VIEW_GRID_LINES_BOTH);
138
139 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
140 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
141
142 for(i = 0, count = 0; columns[i].title; i++, count++)
143 list_store_types[i] = (columns[i].type == G_TYPE_OBJECT)?GDK_TYPE_PIXBUF:columns[i].type;
144 list_store_types[count] = G_TYPE_INT;
145 list_store_types[count + 1] = G_TYPE_BOOLEAN;
146 list_store_types[count + 2] = G_TYPE_STRING;
147
148 list_store = gtk_list_store_newv(count + 3, list_store_types);
149
150 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview ), GTK_TREE_MODEL( list_store ) );
151
152 for(i = 0; columns[i].title; i++)
153 {
154 char* prop;
155 column = NULL;
156
157 if(columns[i].type == G_TYPE_OBJECT)
158 {
159 renderer = gtk_cell_renderer_pixbuf_new();
160 gtk_cell_renderer_set_padding(renderer, 0, 0);
161 prop = "pixbuf";
162 }
163 else if(columns[i].type == G_TYPE_BOOLEAN)
164 {
165 renderer = gtk_cell_renderer_toggle_new();
166 prop = "active";
167 }
168 else
169 {
170 renderer = gtk_cell_renderer_text_new();
171 prop = "text";
172
173 column = gtk_tree_view_column_new_with_attributes(
174 columns[i].title, renderer,
175 prop, i,
176 "background-set", count + 1,
177 "background", count + 2,
178 NULL);
179 }
180
181 if(!column)
182 column = gtk_tree_view_column_new_with_attributes(
183 columns[i].title, renderer,
184 prop, i,
185 NULL);
186
187 gtk_tree_view_append_column(GTK_TREE_VIEW( treeview ), column);
188 };
189
190 g_object_unref(list_store);
191
192 GLADE_HOOKUP_OBJECT (top, treeview, name);
193
194 return treeview;
195 };
196
197 static GtkWidget* create_treeview_tree(GtkWidget* top, char* name, const column_desc_t columns[])
198 {
199 int i, count;
200
201 GtkWidget *treeview;
202 GtkTreeSelection *selection;
203 GtkCellRenderer *renderer;
204 GtkTreeViewColumn *column;
205 GtkTreeStore *tree_store;
206 GType tree_store_types[32];
207
208 treeview = gtk_tree_view_new ();
209 gtk_widget_show (treeview);
210 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
211 gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(treeview), GTK_TREE_VIEW_GRID_LINES_BOTH);
212
213 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
214 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
215
216 for(i = 0, count = 0; columns[i].title; i++, count++)
217 tree_store_types[i] = (columns[i].type == G_TYPE_OBJECT)?GDK_TYPE_PIXBUF:columns[i].type;
218 tree_store_types[count + 0] = G_TYPE_POINTER;
219 tree_store_types[count + 1] = G_TYPE_POINTER;
220 tree_store_types[count + 2] = G_TYPE_BOOLEAN;
221 tree_store_types[count + 3] = G_TYPE_STRING;
222
223 tree_store = gtk_tree_store_newv(count + 4, tree_store_types);
224
225 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview ), GTK_TREE_MODEL( tree_store ) );
226
227 for(i = 0; columns[i].title; i++)
228 {
229 char* prop;
230 column = NULL;
231
232 if(columns[i].type == G_TYPE_OBJECT)
233 {
234 renderer = gtk_cell_renderer_pixbuf_new();
235 gtk_cell_renderer_set_padding(renderer, 0, 0);
236 prop = "pixbuf";
237 }
238 else if(columns[i].type == G_TYPE_BOOLEAN)
239 {
240 renderer = gtk_cell_renderer_toggle_new();
241 prop = "active";
242 }
243 else
244 {
245 renderer = gtk_cell_renderer_text_new();
246 prop = "text";
247
248 column = gtk_tree_view_column_new_with_attributes(
249 columns[i].title, renderer,
250 prop, i,
251 "background-set", count + 2,
252 "background", count + 3,
253 NULL);
254 }
255
256 if(!column)
257 column = gtk_tree_view_column_new_with_attributes(
258 columns[i].title, renderer,
259 prop, i,
260 NULL);
261
262 gtk_tree_view_append_column(GTK_TREE_VIEW( treeview ), column);
263 };
264
265 g_object_unref(tree_store);
266
267 GLADE_HOOKUP_OBJECT (top, treeview, name);
268
269 return treeview;
270 };
271
272 static GtkWidget* pane_library_tree(GtkWidget* top, instance_t* app)
273 {
274 GtkWidget *scrolledwindow;
275
276 scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
277 gtk_widget_show (scrolledwindow);
278 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
279 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
280
281 gtk_container_add (GTK_CONTAINER (scrolledwindow),
282 app->library_tree = create_treeview_tree(top, "treeview_library", library_columns));
283
284 return scrolledwindow;
285 }
286
287 static GtkWidget* pane_library_buttons(GtkWidget* top, instance_t* app)
288 {
289 GtkWidget* hbox;
290
291 hbox = gtk_hbox_new (FALSE, 0);
292 gtk_widget_show (hbox);
293
294 /* playlist modify buttons */
295 gtk_box_pack_start (GTK_BOX (hbox),
296 ui_create_button(top, app, BUTTON_LIBRARY_ADD),
297 FALSE, FALSE, 0);
298 gtk_box_pack_start (GTK_BOX (hbox),
299 ui_create_button(top, app, BUTTON_LIBRARY_REFRESH),
300 FALSE, FALSE, 0);
301
302 /* spacer */
303 gtk_box_pack_start (GTK_BOX (hbox),
304 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
305 TRUE, TRUE, 0);
306
307 return hbox;
308 }
309
310 static GtkWidget* pane_library_search_buttons(GtkWidget* top, instance_t* app)
311 {
312 GtkWidget* hbox;
313
314 hbox = gtk_hbox_new (FALSE, 0);
315 gtk_widget_show (hbox);
316
317 /* text entry */
318 gtk_box_pack_start (GTK_BOX (hbox),
319 app->library.search = gtk_entry_new(),
320 TRUE, TRUE, 0);
321 gtk_widget_show(app->library.search);
322
323 /* playlist modify buttons */
324 gtk_box_pack_start (GTK_BOX (hbox),
325 ui_create_button(top, app, BUTTON_LIBRARY_FIND),
326 FALSE, FALSE, 0);
327 gtk_box_pack_start (GTK_BOX (hbox),
328 ui_create_button(top, app, BUTTON_LIBRARY_FIND_NEXT),
329 FALSE, FALSE, 0);
330
331 return hbox;
332 }
333
334 static GtkWidget* pane_library(GtkWidget* top, instance_t* app)
335 {
336 GtkWidget* vbox;
337
338 vbox = gtk_vbox_new (FALSE, 0);
339 gtk_widget_show (vbox);
340 gtk_widget_set_size_request(vbox, 300, -1);
341
342 /* add buttons box */
343 gtk_box_pack_start (GTK_BOX (vbox),
344 pane_library_buttons(top, app),
345 FALSE, FALSE, 0);
346
347 /* add grid */
348 gtk_box_pack_start (GTK_BOX (vbox),
349 pane_library_tree(top, app),
350 TRUE, TRUE, 0);
351
352 /* add search buttons */
353 gtk_box_pack_start (GTK_BOX (vbox),
354 pane_library_search_buttons(top, app),
355 FALSE, FALSE, 0);
356
357 return vbox;
358 }
359
360 static GtkWidget* create_channel_status(GtkWidget* top, instance_t* app, int idx)
361 {
362 GtkWidget* vbox;
363 GtkWidget* hbox;
364 GtkWidget* frame;
365 char name[PATH_MAX];
366 player_t* player;
367
368 player = &app->players.item[idx];
369
370 snprintf(name, sizeof(name), "unit %d [%c]", player->unit, idx + 'A');
371
372 frame = gtk_frame_new(name);
373 gtk_widget_show(frame);
374
375 vbox = gtk_vbox_new(FALSE, 0);
376 gtk_container_add(GTK_CONTAINER(frame), vbox);
377 gtk_widget_show(vbox);
378
379 /* status label */
380 gtk_box_pack_start(GTK_BOX (vbox),
381 player->label_status = create_label(top, "OFFLINE", NULL, GTK_JUSTIFY_LEFT),
382 FALSE, FALSE, 0);
383
384 /* spacel label */
385 gtk_box_pack_start(GTK_BOX (vbox),
386 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
387 FALSE, FALSE, 0);
388
389 /* clip label */
390 gtk_box_pack_start (GTK_BOX (vbox),
391 player->label_clip = create_label(top, "U0002323", NULL, GTK_JUSTIFY_LEFT),
392 FALSE, FALSE, 0);
393
394 /* block state/current timecode */
395 gtk_box_pack_start(GTK_BOX (vbox),
396 hbox = gtk_hbox_new(TRUE, 0),
397 FALSE, FALSE, 0);
398 gtk_widget_show(hbox);
399
400 {
401 /* clip state */
402 gtk_box_pack_start(GTK_BOX (hbox),
403 player->label_state = create_label(top, "PLAYING", NULL, GTK_JUSTIFY_LEFT),
404 TRUE, TRUE, 0);
405
406 /* current timecode */
407 gtk_box_pack_start(GTK_BOX (hbox),
408 player->label_tc_cur = create_label(top, "00:00:00:00", NULL, GTK_JUSTIFY_LEFT),
409 TRUE, TRUE, 0);
410 };
411
412 /* block remain label/remain timecode */
413 gtk_box_pack_start(GTK_BOX (vbox),
414 hbox = gtk_hbox_new(TRUE, 0),
415 FALSE, FALSE, 0);
416 gtk_widget_show (hbox);
417
418 {
419 /* label */
420 gtk_box_pack_start(GTK_BOX (hbox),
421 create_label(top, "remain:", NULL, GTK_JUSTIFY_LEFT),
422 TRUE, TRUE, 0);
423
424 /* remaining timecode */
425 gtk_box_pack_start(GTK_BOX (hbox),
426 player->label_tc_rem = create_label(top, "00:00:00:00", NULL, GTK_JUSTIFY_LEFT),
427 TRUE, TRUE, 0);
428 };
429
430 return frame;
431 }
432
433 static GtkWidget* pane_operate_status(GtkWidget* top, instance_t* app)
434 {
435 int i;
436 GtkWidget* vbox;
437
438 vbox = gtk_vbox_new (FALSE, 0);
439 gtk_widget_show (vbox);
440 gtk_widget_set_size_request(vbox, 250, -1);
441
442 for(i = 0; i < app->players.count; i++)
443 {
444 gtk_box_pack_start (GTK_BOX (vbox),
445 create_channel_status(top, app, i),
446 FALSE, FALSE, 0);
447
448 /* spacer */
449 gtk_box_pack_start (GTK_BOX (vbox),
450 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
451 FALSE, FALSE, 0);
452 }
453
454 /* spacer */
455 gtk_box_pack_start (GTK_BOX (vbox),
456 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
457 TRUE, TRUE, 0);
458
459 return vbox;
460 }
461
462 static GtkWidget* pane_operate_buttons_playlist(GtkWidget* top, instance_t* app)
463 {
464 GtkWidget* hbox;
465
466 hbox = gtk_hbox_new (FALSE, 0);
467 gtk_widget_show (hbox);
468
469 /* playlist load/save buttons */
470 gtk_box_pack_start (GTK_BOX (hbox),
471 ui_create_button(top, app, BUTTON_PLAYLIST_LOAD),
472 FALSE, FALSE, 0);
473 gtk_box_pack_start (GTK_BOX (hbox),
474 ui_create_button(top, app, BUTTON_PLAYLIST_SAVE),
475 FALSE, FALSE, 0);
476
477 /* spacer */
478 gtk_box_pack_start (GTK_BOX (hbox),
479 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
480 FALSE, FALSE, 0);
481
482 /* playlist modify buttons */
483 gtk_box_pack_start (GTK_BOX (hbox),
484 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_ADD),
485 FALSE, FALSE, 0);
486 gtk_box_pack_start (GTK_BOX (hbox),
487 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_EDIT),
488 FALSE, FALSE, 0);
489 gtk_box_pack_start (GTK_BOX (hbox),
490 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_DEL),
491 FALSE, FALSE, 0);
492
493 /* spacer */
494 gtk_box_pack_start (GTK_BOX (hbox),
495 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
496 FALSE, FALSE, 0);
497
498 /* playlist block buttons */
499 gtk_box_pack_start (GTK_BOX (hbox),
500 ui_create_button(top, app, BUTTON_PLAYLIST_BLOCK_SINGLE),
501 FALSE, FALSE, 0);
502 gtk_box_pack_start (GTK_BOX (hbox),
503 ui_create_button(top, app, BUTTON_PLAYLIST_BLOCK_LOOP),
504 FALSE, FALSE, 0);
505
506 /* spacer */
507 gtk_box_pack_start (GTK_BOX (hbox),
508 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
509 FALSE, FALSE, 0);
510
511 /* playlist move items buttons */
512 gtk_box_pack_start (GTK_BOX (hbox),
513 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_UP),
514 FALSE, FALSE, 0);
515 gtk_box_pack_start (GTK_BOX (hbox),
516 ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_DOWN),
517 FALSE, FALSE, 0);
518
519 /* spacer */
520 gtk_box_pack_start (GTK_BOX (hbox),
521 create_label(top, " ", NULL, GTK_JUSTIFY_CENTER),
522 FALSE, FALSE, 0);
523
524 /* playlist relink */
525 gtk_box_pack_start (GTK_BOX (hbox),
526 ui_create_button(top, app, BUTTON_PLAYLIST_RELINK),
527 FALSE, FALSE, 0);
528
529 return hbox;
530 }
531
532 static GtkWidget* pane_operate_grid(GtkWidget* top, instance_t* app)
533 {
534 GtkWidget *scrolledwindow;
535
536 scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
537 gtk_widget_show (scrolledwindow);
538 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
539 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
540
541 gtk_container_add (GTK_CONTAINER (scrolledwindow),
542 app->playlist_grid = create_treeview_list(top, "treeview_playlist", playlist_columns));
543
544 return scrolledwindow;
545 }
546
547 static GtkWidget* pane_operate_buttons_operate(GtkWidget* top, instance_t* app)
548 {
549 GtkWidget* hbox;
550
551 hbox = gtk_hbox_new (FALSE, 0);
552 gtk_widget_show (hbox);
553
554 /* spacer */
555 gtk_box_pack_start (GTK_BOX (hbox),
556 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
557 TRUE, TRUE, 0);
558
559 /* playlist modify buttons */
560 gtk_box_pack_start (GTK_BOX (hbox),
561 ui_create_button(top, app, BUTTON_PLAYER_CUE),
562 FALSE, FALSE, 0);
563 gtk_box_pack_start (GTK_BOX (hbox),
564 ui_create_button(top, app, BUTTON_PLAYER_PLAY),
565 FALSE, FALSE, 0);
566 gtk_box_pack_start (GTK_BOX (hbox),
567 ui_create_button(top, app, BUTTON_PLAYER_PAUSE),
568 FALSE, FALSE, 0);
569 gtk_box_pack_start (GTK_BOX (hbox),
570 ui_create_button(top, app, BUTTON_PLAYER_STOP),
571 FALSE, FALSE, 0);
572
573 /* spacer */
574 gtk_box_pack_start (GTK_BOX (hbox),
575 create_label(top, NULL, NULL, GTK_JUSTIFY_CENTER),
576 TRUE, TRUE, 0);
577
578 return hbox;
579 }
580
581 static GtkWidget* pane_operate_operate(GtkWidget* top, instance_t* app)
582 {
583 GtkWidget* vbox;
584
585 vbox = gtk_vbox_new (FALSE, 0);
586 gtk_widget_show (vbox);
587
588 /* add buttons box #1 */
589 gtk_box_pack_start (GTK_BOX (vbox),
590 pane_operate_buttons_playlist(top, app),
591 FALSE, FALSE, 0);
592
593 /* add buttons box */
594 gtk_box_pack_start (GTK_BOX (vbox),
595 pane_operate_grid(top, app),
596 TRUE, TRUE, 0);
597
598 /* add buttons box #1 */
599 gtk_box_pack_start (GTK_BOX (vbox),
600 pane_operate_buttons_operate(top, app),
601 FALSE, FALSE, 0);
602
603 return vbox;
604
605 }
606
607 static GtkWidget* pane_operate(GtkWidget* top, instance_t* app)
608 {
609 GtkWidget* hbox;
610
611 hbox = gtk_hbox_new (FALSE, 0);
612 gtk_widget_show (hbox);
613
614 /* add buttons box */
615 gtk_box_pack_start (GTK_BOX (hbox),
616 pane_operate_status(top, app),
617 FALSE, FALSE, 0);
618
619 /* add buttons box */
620 gtk_box_pack_start (GTK_BOX (hbox),
621 pane_operate_operate(top, app),
622 TRUE, TRUE, 0);
623
624 return hbox;
625
626 };
627
628 static GtkWidget* pane_top(GtkWidget* top, instance_t* app)
629 {
630 GtkWidget* pane;
631
632 pane = gtk_hpaned_new ();
633 gtk_widget_show (pane);
634
635 gtk_paned_set_position (GTK_PANED (pane), 800);
636
637 gtk_paned_pack1 (GTK_PANED (pane),
638 pane_operate(top, app),
639 TRUE, FALSE);
640
641 gtk_paned_pack2 (GTK_PANED (pane),
642 pane_library(top, app),
643 FALSE, FALSE);
644
645 return pane;
646 }
647
648 GtkWidget* ui_create(instance_t* app)
649 {
650 GtkWidget *wnd;
651 GtkWidget* vbox;
652
653 wnd = gtk_window_new (GTK_WINDOW_TOPLEVEL);
654 GLADE_HOOKUP_OBJECT_NO_REF (wnd, wnd, PACKAGE "_window");
655
656 gtk_window_set_title (GTK_WINDOW (wnd), _(PRODUCT_NAME));
657 gtk_window_set_default_size (GTK_WINDOW (wnd), 1024, 768);
658
659 vbox = gtk_vbox_new(FALSE, 0);
660 gtk_widget_show(vbox);
661
662 gtk_container_add(GTK_CONTAINER(wnd), vbox);
663
664 gtk_box_pack_start (GTK_BOX (vbox),
665 pane_top(wnd, app),
666 TRUE, TRUE, 0);
667 gtk_box_pack_start (GTK_BOX (vbox),
668 app->status_label = create_label(wnd, "started", NULL, GTK_JUSTIFY_LEFT),
669 FALSE, FALSE, 0);
670
671 app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_BEGIN] =
672 create_pixbuf("block_type_block_start_16x16.png");
673 app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_BODY] =
674 create_pixbuf("block_type_block_middle_16x16.png");
675 app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_END] =
676 create_pixbuf("block_type_block_end_16x16.png");
677 app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_SINGLE] =
678 create_pixbuf("block_type_block_single_16x16.png");
679 app->playlist.block_icons[PLAYLIST_ITEM_LOOP_BEGIN] =
680 create_pixbuf("block_type_loop_start_16x16.png");
681 app->playlist.block_icons[PLAYLIST_ITEM_LOOP_BODY] =
682 create_pixbuf("block_type_loop_middle_16x16.png");
683 app->playlist.block_icons[PLAYLIST_ITEM_LOOP_END] =
684 create_pixbuf("block_type_loop_end_16x16.png");
685 app->playlist.block_icons[PLAYLIST_ITEM_LOOP_SINGLE] =
686 create_pixbuf("block_type_block_loop_16x16.png");
687
688 return wnd;
689 }
690
691 int ui_playlist_item_dialog(instance_t* app, playlist_item_t* item)
692 {
693 int r, c;
694 char tc[32];
695 GtkWidget *dlg;
696 gint response;
697 GtkWidget *box, *table;
698 GtkWidget *entry[4], *combo;
699
700 dlg = gtk_dialog_new_with_buttons(
701 "Playlist item",
702 GTK_WINDOW(app->window),
703 GTK_DIALOG_MODAL,
704 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
705 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
706 NULL);
707
708 box = gtk_dialog_get_content_area(GTK_DIALOG(dlg));
709
710 table = gtk_table_new(5, 2, TRUE);
711 gtk_widget_show(table);
712 gtk_box_pack_start(GTK_BOX(box), table, TRUE, TRUE, 0);
713
714 gtk_table_attach(GTK_TABLE(table),
715 create_label(NULL, "ID:", NULL, 0),
716 0, 1, 0, 1,
717 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
718
719 gtk_table_attach(GTK_TABLE(table),
720 create_label(NULL, "IN:", NULL, GTK_JUSTIFY_RIGHT),
721 0, 1, 1, 2,
722 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
723
724 gtk_table_attach(GTK_TABLE(table),
725 create_label(NULL, "DUR:", NULL, GTK_JUSTIFY_RIGHT),
726 0, 1, 2, 3,
727 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
728
729 gtk_table_attach(GTK_TABLE(table),
730 create_label(NULL, "TITLE:", NULL, GTK_JUSTIFY_RIGHT),
731 0, 1, 3, 4,
732 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
733
734 gtk_table_attach(GTK_TABLE(table),
735 create_label(NULL, "CHANNEL:", NULL, GTK_JUSTIFY_RIGHT),
736 0, 1, 4, 5,
737 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
738
739
740 gtk_table_attach(GTK_TABLE(table),
741 entry[0] = gtk_entry_new_with_max_length(32),
742 1, 2, 0, 1,
743 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
744
745 gtk_table_attach(GTK_TABLE(table),
746 entry[1] = gtk_entry_new_with_max_length(12),
747 1, 2, 1, 2,
748 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
749
750 gtk_table_attach(GTK_TABLE(table),
751 entry[2] = gtk_entry_new_with_max_length(12),
752 1, 2, 2, 3,
753 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
754
755 gtk_table_attach(GTK_TABLE(table),
756 entry[3] = gtk_entry_new_with_max_length(128),
757 1, 2, 3, 4,
758 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
759
760 gtk_table_attach(GTK_TABLE(table),
761 combo = gtk_combo_box_new_text(),
762 1, 2, 4, 5,
763 GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5);
764
765
766 /* setup data */
767 gtk_entry_set_text(GTK_ENTRY(entry[0]), item->id);
768 gtk_entry_set_text(GTK_ENTRY(entry[1]), frames2tc(item->in, 25.0, tc));
769 gtk_entry_set_text(GTK_ENTRY(entry[2]), frames2tc(item->dur, 25.0, tc));
770 gtk_entry_set_text(GTK_ENTRY(entry[3]), item->title);
771 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "A");
772 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "B");
773 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "C");
774 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "D");
775 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), item->player);
776
777 gtk_widget_show_all(dlg);
778
779 /* Run dialog */
780 for(c = 1; c;)
781 {
782 response = gtk_dialog_run(GTK_DIALOG(dlg));
783
784 if( GTK_RESPONSE_REJECT == response ||
785 GTK_RESPONSE_DELETE_EVENT == response ||
786 GTK_RESPONSE_CANCEL == response)
787 {
788 r = 0;
789 c = 0;
790 }
791 else
792 {
793 r = 1;
794
795 /* get item data back */
796 strncpy(item->id, gtk_entry_get_text(GTK_ENTRY(entry[0])), PATH_MAX);
797 tc2frames((char*)gtk_entry_get_text(GTK_ENTRY(entry[1])), 25.0, &item->in);
798 tc2frames((char*)gtk_entry_get_text(GTK_ENTRY(entry[2])), 25.0, &item->dur);
799 strncpy(item->title, gtk_entry_get_text(GTK_ENTRY(entry[3])), PATH_MAX);
800 item->player = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
801
802 /* check if all data entered correctly */
803 if(item->id[0])
804 c = 0;
805 };
806 };
807
808 gtk_widget_hide(dlg);
809 gtk_widget_destroy(dlg);
810
811 return r;
812 };
813
814 /********************************************************************************/
815
816 void ui_update_player(player_t* player, char *tc_cur, char *tc_rem, char *state, char *status, char *clip)
817 {
818 /* update status in status page */
819 gdk_threads_enter();
820 gtk_label_set_text(GTK_LABEL (player->label_tc_cur), tc_cur);
821 gtk_label_set_text(GTK_LABEL (player->label_tc_rem), tc_rem);
822 gtk_label_set_text(GTK_LABEL (player->label_state), state);
823 gtk_label_set_text(GTK_LABEL (player->label_status), status);
824 gtk_label_set_text(GTK_LABEL (player->label_clip), clip);
825 gdk_flush();
826 gdk_threads_leave();
827 };
828
829 static gboolean ui_playlist_draw_item_rem_proc(
830 GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
831 {
832 int i;
833 void** args = (void**)user_data;
834 GtkListStore *list_store = (GtkListStore *)args[1];
835 int idx = (int)args[2];
836 char* rem = (char*)args[3];
837
838 gtk_tree_model_get(model, iter, 7, &i, -1);
839
840 if(i != idx) return FALSE;
841
842 gtk_list_store_set(list_store, iter, 0, rem, -1);
843
844 return TRUE;
845 };
846
847 void ui_playlist_draw_item_rem(instance_t* app, int idx, char* rem)
848 {
849 void* item[4];
850 GtkListStore *list_store;
851
852 gdk_threads_enter();
853
854 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app->playlist_grid)));
855
856 item[0] = (void*)app;
857 item[1] = (void*)list_store;
858 item[2] = (void*)idx;
859 item[3] = (void*)rem;
860
861 gtk_tree_model_foreach(GTK_TREE_MODEL(list_store), ui_playlist_draw_item_rem_proc, item);
862
863 gdk_flush();
864 gdk_threads_leave();
865 };
866
867 void ui_playlist_select_item(instance_t* app, int idx)
868 {
869 GtkTreePath* path;
870
871 path = gtk_tree_path_new_from_indices(idx, -1);
872
873 gtk_tree_selection_select_path(gtk_tree_view_get_selection(GTK_TREE_VIEW(app->playlist_grid)), path);
874 gtk_tree_view_set_cursor(GTK_TREE_VIEW(app->playlist_grid), path, NULL, FALSE);
875 gtk_tree_path_free(path);
876 };
877
878 void ui_playlist_draw(instance_t* app)
879 {
880 int i;
881 int sel;
882 char tc1[12], tc2[12];
883 GtkListStore *list_store;
884 GtkTreeIter iter;
885
886 sel = playlist_get_first_selected_item_idx(app);
887
888 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app->playlist_grid)));
889 gtk_list_store_clear(list_store);
890
891 pthread_mutex_lock(&app->playlist.lock);
892
893 for(i = 0;i < app->playlist.count; i++)
894 {
895 char ch[3];
896
897 if(PLAYLIST_BLOCK_BEGIN & app->playlist.item[i].type)
898 snprintf(ch, sizeof(ch), "%c", 'A' + app->playlist.item[i].player);
899 else
900 ch[0] = 0;
901
902 gtk_list_store_append(list_store, &iter);
903
904 gtk_list_store_set(list_store, &iter,
905 0, "",
906 1, app->playlist.block_icons[app->playlist.item[i].type],
907 2, ch,
908 3, app->playlist.item[i].title,
909 4, frames2tc(app->playlist.item[i].in, 25.0, tc1),
910 5, frames2tc(app->playlist.item[i].dur, 25.0, tc2),
911 6, app->playlist.item[i].id,
912 7, i,
913 8, (app->playlist.item[i].error != 0),
914 9, (app->playlist.item[i].error & PLAYLIST_ITEM_ERROR_LIB)?"red":"orange",
915 -1 );
916 }
917
918 app->playlist.ver_prev = app->playlist.ver_curr;
919
920 if(sel >= 0)
921 ui_playlist_select_item(app, sel);
922
923 pthread_mutex_unlock(&app->playlist.lock);
924 };
925
926 typedef struct ui_playlist_draw_item_desc
927 {
928 GtkListStore *list_store;
929 instance_t* app;
930 int idx;
931 } ui_playlist_draw_item_t;
932
933 static gboolean ui_playlist_draw_item_iter
934 (
935 GtkTreeModel *model,
936 GtkTreePath *path,
937 GtkTreeIter *iter,
938 gpointer user_data
939 )
940 {
941 int i;
942 char tc1[12], tc2[12];
943 char ch[3];
944 ui_playlist_draw_item_t* item = (ui_playlist_draw_item_t*)user_data;
945 instance_t* app = item->app;
946
947 gtk_tree_model_get(model, iter, 7, &i, -1);
948
949 if(i != item->idx) return FALSE;
950
951 if(PLAYLIST_BLOCK_BEGIN & app->playlist.item[i].type)
952 snprintf(ch, sizeof(ch), "%c", 'A' + app->playlist.item[i].player);
953 else
954 ch[0] = 0;
955
956 gtk_list_store_set(item->list_store, iter,
957 0, "",
958 1, app->playlist.block_icons[app->playlist.item[i].type],
959 2, ch,
960 3, app->playlist.item[i].title,
961 4, frames2tc(app->playlist.item[i].in, 25.0, tc1),
962 5, frames2tc(app->playlist.item[i].dur, 25.0, tc2),
963 6, app->playlist.item[i].id,
964 7, i,
965 8, (app->playlist.item[i].error != 0),
966 9, (app->playlist.item[i].error & PLAYLIST_ITEM_ERROR_LIB)?"red":"orange",
967 -1 );
968
969 return TRUE;
970 };
971
972 void ui_playlist_draw_item(instance_t* app, int idx)
973 {
974 GtkListStore *list_store;
975 ui_playlist_draw_item_t item;
976
977 list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app->playlist_grid)));
978
979 pthread_mutex_lock(&app->playlist.lock);
980
981 item.idx = idx;
982 item.app = app;
983 item.list_store = list_store;
984 gtk_tree_model_foreach(GTK_TREE_MODEL(list_store), ui_playlist_draw_item_iter, &item);
985
986 pthread_mutex_unlock(&app->playlist.lock);
987 };
988
989 void ui_set_status(instance_t* app, char* str)
990 {
991 gdk_threads_enter();
992 gtk_label_set_text(GTK_LABEL(app->status_label), str);
993 gdk_flush();
994 gdk_threads_leave();
995 };
996
997 void ui_show_error(GtkWidget *window, char* title, char* message)
998 {
999 GtkWidget *dialog;
1000 dialog = gtk_message_dialog_new
1001 (
1002 GTK_WINDOW(window),
1003 GTK_DIALOG_DESTROY_WITH_PARENT,
1004 GTK_MESSAGE_ERROR,
1005 GTK_BUTTONS_OK,
1006 message
1007 );
1008
1009 gtk_window_set_title(GTK_WINDOW(dialog), title);
1010 gtk_dialog_run(GTK_DIALOG(dialog));
1011 gtk_widget_destroy(dialog);
1012 };
1013
1014 int ui_playlist_load(instance_t* app, char* path, struct ui_playlist_io_funcs* procs)
1015 {
1016 int r, i;
1017 GtkWidget *dialog;
1018 GtkFileFilter *filter;
1019 char error_message[1024];
1020
1021 dialog = gtk_file_chooser_dialog_new("Open File",
1022 GTK_WINDOW (app->window),
1023 GTK_FILE_CHOOSER_ACTION_OPEN,
1024 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1025 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1026 NULL);
1027
1028 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);
1029
1030 for(i = 0; procs[i].title; i++)
1031 {
1032 filter = gtk_file_filter_new();
1033 gtk_file_filter_set_name(filter, procs[i].title);
1034 gtk_file_filter_add_pattern(filter, procs[i].ext);
1035 g_object_set_data(G_OBJECT(filter), "id", GINT_TO_POINTER(i));
1036 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filter);
1037 };
1038
1039 r = gtk_dialog_run(GTK_DIALOG(dialog));
1040
1041 if(r == GTK_RESPONSE_ACCEPT)
1042 {
1043 int l;
1044 char *filename, *filename2;
1045
1046 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
1047
1048 i = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog))), "id"));
1049
1050 filename2 = (char*)malloc(PATH_MAX);
1051 strncpy(filename2, filename, PATH_MAX);
1052 l = strlen(filename2);
1053 if(l < 4 || strcasecmp(filename2 + l - 4, procs[i].ext + 1))
1054 strcat(filename2, procs[i].ext + 1);
1055
1056 r = procs[i].load(app, filename2, error_message, sizeof(error_message));
1057
1058 if(r)
1059 ui_show_error(dialog, "Playlist loading error", error_message);
1060
1061 free(filename2);
1062
1063 ui_playlist_draw(app);
1064
1065 if(app->playlist.path)
1066 g_free(app->playlist.path);
1067 if((app->playlist.path = filename))
1068 {
1069 char* e = strrchr(app->playlist.path, '/');
1070 if(e) *e = 0;
1071 }
1072 }
1073 else
1074 r = -1;
1075
1076 gtk_widget_destroy (dialog);
1077
1078 return r;
1079 };
1080
1081 int ui_playlist_save(instance_t* app, char* path, struct ui_playlist_io_funcs* procs)
1082 {
1083 int r, i;
1084 GtkWidget *dialog;
1085 GtkFileFilter *filter;
1086 char error_message[1024];
1087
1088 dialog = gtk_file_chooser_dialog_new("Save File",
1089 GTK_WINDOW (app->window),
1090 GTK_FILE_CHOOSER_ACTION_SAVE,
1091 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1092 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1093 NULL);
1094
1095 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
1096
1097 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);
1098
1099 for(i = 0; procs[i].title; i++)
1100 {
1101 filter = gtk_file_filter_new();
1102 gtk_file_filter_set_name(filter, procs[i].title);
1103 gtk_file_filter_add_pattern(filter, procs[i].ext);
1104 g_object_set_data(G_OBJECT(filter), "id", GINT_TO_POINTER(i));
1105 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filter);
1106 };
1107
1108 r = gtk_dialog_run(GTK_DIALOG(dialog));
1109
1110 if(r == GTK_RESPONSE_ACCEPT)
1111 {
1112 int l;
1113 char *filename, *filename2;
1114
1115 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
1116
1117 i = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog))), "id"));
1118
1119 filename2 = (char*)malloc(PATH_MAX);
1120 strncpy(filename2, filename, PATH_MAX);
1121 l = strlen(filename2);
1122 if(l < 4 || strcasecmp(filename2 + l - 4, procs[i].ext + 1))
1123 strcat(filename2, procs[i].ext + 1);
1124
1125 r = procs[i].save(app, filename2, error_message, sizeof(error_message));
1126
1127 if(r)
1128 ui_show_error(dialog, "Playlist saving error", error_message);
1129
1130 free(filename2);
1131
1132 if(app->playlist.path)
1133 g_free(app->playlist.path);
1134 if((app->playlist.path = filename))
1135 {
1136 char* e = strrchr(app->playlist.path, '/');
1137 if(e) *e = 0;
1138 }
1139 }
1140 else
1141 r = -1;
1142
1143 gtk_widget_destroy (dialog);
1144
1145 return r;
1146 };