2 * ui.c -- GTK+ 2 melted gui
3 * Copyright (C) 2012 Maksym Veremeyenko <verem@m1stereo.tv>
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.
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.
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.
24 #include <sys/types.h>
31 #include <gdk/gdkkeysyms.h>
36 #include "ui_buttons.h"
41 typedef struct column_desc
47 static const column_desc_t playlist_columns
[] =
83 const static column_desc_t library_columns
[] =
104 static GtkWidget
* create_label(GtkWidget
* top
, char* text
, char* reg
, GtkJustification jtype
)
108 label
= gtk_label_new ("");
109 gtk_widget_show (label
);
112 gtk_label_set_justify (GTK_LABEL (label
), jtype
);
115 GLADE_HOOKUP_OBJECT (top
, label
, reg
);
118 gtk_label_set_text(GTK_LABEL (label
), text
);
123 static GtkWidget
* create_treeview_list(GtkWidget
* top
, char* name
, const column_desc_t columns
[])
128 GtkTreeSelection
*selection
;
129 GtkCellRenderer
*renderer
;
130 GtkTreeViewColumn
*column
;
131 GtkListStore
*list_store
;
132 GType list_store_types
[32];
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
);
139 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
140 gtk_tree_selection_set_mode(selection
, GTK_SELECTION_MULTIPLE
);
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
;
148 list_store
= gtk_list_store_newv(count
+ 3, list_store_types
);
150 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview
), GTK_TREE_MODEL( list_store
) );
152 for(i
= 0; columns
[i
].title
; i
++)
157 if(columns
[i
].type
== G_TYPE_OBJECT
)
159 renderer
= gtk_cell_renderer_pixbuf_new();
160 gtk_cell_renderer_set_padding(renderer
, 0, 0);
163 else if(columns
[i
].type
== G_TYPE_BOOLEAN
)
165 renderer
= gtk_cell_renderer_toggle_new();
170 renderer
= gtk_cell_renderer_text_new();
173 column
= gtk_tree_view_column_new_with_attributes(
174 columns
[i
].title
, renderer
,
176 "background-set", count
+ 1,
177 "background", count
+ 2,
182 column
= gtk_tree_view_column_new_with_attributes(
183 columns
[i
].title
, renderer
,
187 gtk_tree_view_append_column(GTK_TREE_VIEW( treeview
), column
);
190 g_object_unref(list_store
);
192 GLADE_HOOKUP_OBJECT (top
, treeview
, name
);
197 static GtkWidget
* create_treeview_tree(GtkWidget
* top
, char* name
, const column_desc_t columns
[])
202 GtkTreeSelection
*selection
;
203 GtkCellRenderer
*renderer
;
204 GtkTreeViewColumn
*column
;
205 GtkTreeStore
*tree_store
;
206 GType tree_store_types
[32];
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
);
213 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
214 gtk_tree_selection_set_mode(selection
, GTK_SELECTION_MULTIPLE
);
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
;
223 tree_store
= gtk_tree_store_newv(count
+ 4, tree_store_types
);
225 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview
), GTK_TREE_MODEL( tree_store
) );
227 for(i
= 0; columns
[i
].title
; i
++)
232 if(columns
[i
].type
== G_TYPE_OBJECT
)
234 renderer
= gtk_cell_renderer_pixbuf_new();
235 gtk_cell_renderer_set_padding(renderer
, 0, 0);
238 else if(columns
[i
].type
== G_TYPE_BOOLEAN
)
240 renderer
= gtk_cell_renderer_toggle_new();
245 renderer
= gtk_cell_renderer_text_new();
248 column
= gtk_tree_view_column_new_with_attributes(
249 columns
[i
].title
, renderer
,
251 "background-set", count
+ 2,
252 "background", count
+ 3,
257 column
= gtk_tree_view_column_new_with_attributes(
258 columns
[i
].title
, renderer
,
262 gtk_tree_view_append_column(GTK_TREE_VIEW( treeview
), column
);
265 g_object_unref(tree_store
);
267 GLADE_HOOKUP_OBJECT (top
, treeview
, name
);
272 static GtkWidget
* pane_library_tree(GtkWidget
* top
, instance_t
* app
)
274 GtkWidget
*scrolledwindow
;
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
);
281 gtk_container_add (GTK_CONTAINER (scrolledwindow
),
282 app
->library_tree
= create_treeview_tree(top
, "treeview_library", library_columns
));
284 return scrolledwindow
;
287 static GtkWidget
* pane_library_buttons(GtkWidget
* top
, instance_t
* app
)
291 hbox
= gtk_hbox_new (FALSE
, 0);
292 gtk_widget_show (hbox
);
294 /* playlist modify buttons */
295 gtk_box_pack_start (GTK_BOX (hbox
),
296 ui_create_button(top
, app
, BUTTON_LIBRARY_ADD
),
298 gtk_box_pack_start (GTK_BOX (hbox
),
299 ui_create_button(top
, app
, BUTTON_LIBRARY_REFRESH
),
303 gtk_box_pack_start (GTK_BOX (hbox
),
304 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
310 static GtkWidget
* pane_library_search_buttons(GtkWidget
* top
, instance_t
* app
)
314 hbox
= gtk_hbox_new (FALSE
, 0);
315 gtk_widget_show (hbox
);
318 gtk_box_pack_start (GTK_BOX (hbox
),
319 app
->library
.search
= gtk_entry_new(),
321 gtk_widget_show(app
->library
.search
);
323 /* playlist modify buttons */
324 gtk_box_pack_start (GTK_BOX (hbox
),
325 ui_create_button(top
, app
, BUTTON_LIBRARY_FIND
),
327 gtk_box_pack_start (GTK_BOX (hbox
),
328 ui_create_button(top
, app
, BUTTON_LIBRARY_FIND_NEXT
),
334 static GtkWidget
* pane_library(GtkWidget
* top
, instance_t
* app
)
338 vbox
= gtk_vbox_new (FALSE
, 0);
339 gtk_widget_show (vbox
);
340 gtk_widget_set_size_request(vbox
, 300, -1);
342 /* add buttons box */
343 gtk_box_pack_start (GTK_BOX (vbox
),
344 pane_library_buttons(top
, app
),
348 gtk_box_pack_start (GTK_BOX (vbox
),
349 pane_library_tree(top
, app
),
352 /* add search buttons */
353 gtk_box_pack_start (GTK_BOX (vbox
),
354 pane_library_search_buttons(top
, app
),
360 static GtkWidget
* create_channel_status(GtkWidget
* top
, instance_t
* app
, int idx
)
368 player
= &app
->players
.item
[idx
];
370 snprintf(name
, sizeof(name
), "unit %d [%c]", player
->unit
, idx
+ 'A');
372 frame
= gtk_frame_new(name
);
373 gtk_widget_show(frame
);
375 vbox
= gtk_vbox_new(FALSE
, 0);
376 gtk_container_add(GTK_CONTAINER(frame
), vbox
);
377 gtk_widget_show(vbox
);
380 gtk_box_pack_start(GTK_BOX (vbox
),
381 player
->label_status
= create_label(top
, "OFFLINE", NULL
, GTK_JUSTIFY_LEFT
),
385 gtk_box_pack_start(GTK_BOX (vbox
),
386 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
390 gtk_box_pack_start (GTK_BOX (vbox
),
391 player
->label_clip
= create_label(top
, "U0002323", NULL
, GTK_JUSTIFY_LEFT
),
394 /* block state/current timecode */
395 gtk_box_pack_start(GTK_BOX (vbox
),
396 hbox
= gtk_hbox_new(TRUE
, 0),
398 gtk_widget_show(hbox
);
402 gtk_box_pack_start(GTK_BOX (hbox
),
403 player
->label_state
= create_label(top
, "PLAYING", NULL
, GTK_JUSTIFY_LEFT
),
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
),
412 /* block remain label/remain timecode */
413 gtk_box_pack_start(GTK_BOX (vbox
),
414 hbox
= gtk_hbox_new(TRUE
, 0),
416 gtk_widget_show (hbox
);
420 gtk_box_pack_start(GTK_BOX (hbox
),
421 create_label(top
, "remain:", NULL
, GTK_JUSTIFY_LEFT
),
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
),
433 static GtkWidget
* pane_operate_status(GtkWidget
* top
, instance_t
* app
)
438 vbox
= gtk_vbox_new (FALSE
, 0);
439 gtk_widget_show (vbox
);
440 gtk_widget_set_size_request(vbox
, 250, -1);
442 for(i
= 0; i
< app
->players
.count
; i
++)
444 gtk_box_pack_start (GTK_BOX (vbox
),
445 create_channel_status(top
, app
, i
),
449 gtk_box_pack_start (GTK_BOX (vbox
),
450 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
455 gtk_box_pack_start (GTK_BOX (vbox
),
456 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
462 static GtkWidget
* pane_operate_buttons_playlist(GtkWidget
* top
, instance_t
* app
)
466 hbox
= gtk_hbox_new (FALSE
, 0);
467 gtk_widget_show (hbox
);
469 /* playlist load/save buttons */
470 gtk_box_pack_start (GTK_BOX (hbox
),
471 ui_create_button(top
, app
, BUTTON_PLAYLIST_LOAD
),
473 gtk_box_pack_start (GTK_BOX (hbox
),
474 ui_create_button(top
, app
, BUTTON_PLAYLIST_SAVE
),
478 gtk_box_pack_start (GTK_BOX (hbox
),
479 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
482 /* playlist modify buttons */
483 gtk_box_pack_start (GTK_BOX (hbox
),
484 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_ADD
),
486 gtk_box_pack_start (GTK_BOX (hbox
),
487 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_EDIT
),
489 gtk_box_pack_start (GTK_BOX (hbox
),
490 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_DEL
),
494 gtk_box_pack_start (GTK_BOX (hbox
),
495 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
498 /* playlist block buttons */
499 gtk_box_pack_start (GTK_BOX (hbox
),
500 ui_create_button(top
, app
, BUTTON_PLAYLIST_BLOCK_SINGLE
),
502 gtk_box_pack_start (GTK_BOX (hbox
),
503 ui_create_button(top
, app
, BUTTON_PLAYLIST_BLOCK_LOOP
),
507 gtk_box_pack_start (GTK_BOX (hbox
),
508 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
511 /* playlist move items buttons */
512 gtk_box_pack_start (GTK_BOX (hbox
),
513 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_UP
),
515 gtk_box_pack_start (GTK_BOX (hbox
),
516 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_DOWN
),
520 gtk_box_pack_start (GTK_BOX (hbox
),
521 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
524 /* playlist relink */
525 gtk_box_pack_start (GTK_BOX (hbox
),
526 ui_create_button(top
, app
, BUTTON_PLAYLIST_RELINK
),
532 static GtkWidget
* pane_operate_grid(GtkWidget
* top
, instance_t
* app
)
534 GtkWidget
*scrolledwindow
;
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
);
541 gtk_container_add (GTK_CONTAINER (scrolledwindow
),
542 app
->playlist_grid
= create_treeview_list(top
, "treeview_playlist", playlist_columns
));
544 return scrolledwindow
;
547 static GtkWidget
* pane_operate_buttons_operate(GtkWidget
* top
, instance_t
* app
)
551 hbox
= gtk_hbox_new (FALSE
, 0);
552 gtk_widget_show (hbox
);
555 gtk_box_pack_start (GTK_BOX (hbox
),
556 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
559 /* playlist modify buttons */
560 gtk_box_pack_start (GTK_BOX (hbox
),
561 ui_create_button(top
, app
, BUTTON_PLAYER_CUE
),
563 gtk_box_pack_start (GTK_BOX (hbox
),
564 ui_create_button(top
, app
, BUTTON_PLAYER_PLAY
),
566 gtk_box_pack_start (GTK_BOX (hbox
),
567 ui_create_button(top
, app
, BUTTON_PLAYER_PAUSE
),
569 gtk_box_pack_start (GTK_BOX (hbox
),
570 ui_create_button(top
, app
, BUTTON_PLAYER_STOP
),
574 gtk_box_pack_start (GTK_BOX (hbox
),
575 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
581 static GtkWidget
* pane_operate_operate(GtkWidget
* top
, instance_t
* app
)
585 vbox
= gtk_vbox_new (FALSE
, 0);
586 gtk_widget_show (vbox
);
588 /* add buttons box #1 */
589 gtk_box_pack_start (GTK_BOX (vbox
),
590 pane_operate_buttons_playlist(top
, app
),
593 /* add buttons box */
594 gtk_box_pack_start (GTK_BOX (vbox
),
595 pane_operate_grid(top
, app
),
598 /* add buttons box #1 */
599 gtk_box_pack_start (GTK_BOX (vbox
),
600 pane_operate_buttons_operate(top
, app
),
607 static GtkWidget
* pane_operate(GtkWidget
* top
, instance_t
* app
)
611 hbox
= gtk_hbox_new (FALSE
, 0);
612 gtk_widget_show (hbox
);
614 /* add buttons box */
615 gtk_box_pack_start (GTK_BOX (hbox
),
616 pane_operate_status(top
, app
),
619 /* add buttons box */
620 gtk_box_pack_start (GTK_BOX (hbox
),
621 pane_operate_operate(top
, app
),
628 static GtkWidget
* pane_top(GtkWidget
* top
, instance_t
* app
)
632 pane
= gtk_hpaned_new ();
633 gtk_widget_show (pane
);
635 gtk_paned_set_position (GTK_PANED (pane
), 800);
637 gtk_paned_pack1 (GTK_PANED (pane
),
638 pane_operate(top
, app
),
641 gtk_paned_pack2 (GTK_PANED (pane
),
642 pane_library(top
, app
),
648 GtkWidget
* ui_create(instance_t
* app
)
653 wnd
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
654 GLADE_HOOKUP_OBJECT_NO_REF (wnd
, wnd
, PACKAGE
"_window");
656 gtk_window_set_title (GTK_WINDOW (wnd
), _(PRODUCT_NAME
));
657 gtk_window_set_default_size (GTK_WINDOW (wnd
), 1024, 768);
659 vbox
= gtk_vbox_new(FALSE
, 0);
660 gtk_widget_show(vbox
);
662 gtk_container_add(GTK_CONTAINER(wnd
), vbox
);
664 gtk_box_pack_start (GTK_BOX (vbox
),
667 gtk_box_pack_start (GTK_BOX (vbox
),
668 app
->status_label
= create_label(wnd
, "started", NULL
, GTK_JUSTIFY_LEFT
),
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");
691 int ui_playlist_item_dialog(instance_t
* app
, playlist_item_t
* item
)
697 GtkWidget
*box
, *table
;
698 GtkWidget
*entry
[4], *combo
;
700 dlg
= gtk_dialog_new_with_buttons(
702 GTK_WINDOW(app
->window
),
704 GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
,
705 GTK_STOCK_CANCEL
, GTK_RESPONSE_REJECT
,
708 box
= gtk_dialog_get_content_area(GTK_DIALOG(dlg
));
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);
714 gtk_table_attach(GTK_TABLE(table
),
715 create_label(NULL
, "ID:", NULL
, 0),
717 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
719 gtk_table_attach(GTK_TABLE(table
),
720 create_label(NULL
, "IN:", NULL
, GTK_JUSTIFY_RIGHT
),
722 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
724 gtk_table_attach(GTK_TABLE(table
),
725 create_label(NULL
, "DUR:", NULL
, GTK_JUSTIFY_RIGHT
),
727 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
729 gtk_table_attach(GTK_TABLE(table
),
730 create_label(NULL
, "TITLE:", NULL
, GTK_JUSTIFY_RIGHT
),
732 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
734 gtk_table_attach(GTK_TABLE(table
),
735 create_label(NULL
, "CHANNEL:", NULL
, GTK_JUSTIFY_RIGHT
),
737 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
740 gtk_table_attach(GTK_TABLE(table
),
741 entry
[0] = gtk_entry_new_with_max_length(32),
743 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
745 gtk_table_attach(GTK_TABLE(table
),
746 entry
[1] = gtk_entry_new_with_max_length(12),
748 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
750 gtk_table_attach(GTK_TABLE(table
),
751 entry
[2] = gtk_entry_new_with_max_length(12),
753 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
755 gtk_table_attach(GTK_TABLE(table
),
756 entry
[3] = gtk_entry_new_with_max_length(128),
758 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
760 gtk_table_attach(GTK_TABLE(table
),
761 combo
= gtk_combo_box_new_text(),
763 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
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
);
777 gtk_widget_show_all(dlg
);
782 response
= gtk_dialog_run(GTK_DIALOG(dlg
));
784 if( GTK_RESPONSE_REJECT
== response
||
785 GTK_RESPONSE_DELETE_EVENT
== response
||
786 GTK_RESPONSE_CANCEL
== response
)
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
));
802 /* check if all data entered correctly */
808 gtk_widget_hide(dlg
);
809 gtk_widget_destroy(dlg
);
814 /********************************************************************************/
816 void ui_update_player(player_t
* player
, char *tc_cur
, char *tc_rem
, char *state
, char *status
, char *clip
)
818 /* update status in status page */
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
);
829 static gboolean
ui_playlist_draw_item_rem_proc(
830 GtkTreeModel
*model
, GtkTreePath
*path
, GtkTreeIter
*iter
, gpointer user_data
)
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];
838 gtk_tree_model_get(model
, iter
, 7, &i
, -1);
840 if(i
!= idx
) return FALSE
;
842 gtk_list_store_set(list_store
, iter
, 0, rem
, -1);
847 void ui_playlist_draw_item_rem(instance_t
* app
, int idx
, char* rem
)
850 GtkListStore
*list_store
;
854 list_store
= GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app
->playlist_grid
)));
856 item
[0] = (void*)app
;
857 item
[1] = (void*)list_store
;
858 item
[2] = (void*)idx
;
859 item
[3] = (void*)rem
;
861 gtk_tree_model_foreach(GTK_TREE_MODEL(list_store
), ui_playlist_draw_item_rem_proc
, item
);
867 void ui_playlist_select_item(instance_t
* app
, int idx
)
871 path
= gtk_tree_path_new_from_indices(idx
, -1);
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
);
878 void ui_playlist_draw(instance_t
* app
)
882 char tc1
[12], tc2
[12];
883 GtkListStore
*list_store
;
886 sel
= playlist_get_first_selected_item_idx(app
);
888 list_store
= GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app
->playlist_grid
)));
889 gtk_list_store_clear(list_store
);
891 pthread_mutex_lock(&app
->playlist
.lock
);
893 for(i
= 0;i
< app
->playlist
.count
; i
++)
897 if(PLAYLIST_BLOCK_BEGIN
& app
->playlist
.item
[i
].type
)
898 snprintf(ch
, sizeof(ch
), "%c", 'A' + app
->playlist
.item
[i
].player
);
902 gtk_list_store_append(list_store
, &iter
);
904 gtk_list_store_set(list_store
, &iter
,
906 1, app
->playlist
.block_icons
[app
->playlist
.item
[i
].type
],
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
,
913 8, (app
->playlist
.item
[i
].error
!= 0),
914 9, (app
->playlist
.item
[i
].error
& PLAYLIST_ITEM_ERROR_LIB
)?
"red":"orange",
918 app
->playlist
.ver_prev
= app
->playlist
.ver_curr
;
921 ui_playlist_select_item(app
, sel
);
923 pthread_mutex_unlock(&app
->playlist
.lock
);
926 typedef struct ui_playlist_draw_item_desc
928 GtkListStore
*list_store
;
931 } ui_playlist_draw_item_t
;
933 static gboolean ui_playlist_draw_item_iter
942 char tc1
[12], tc2
[12];
944 ui_playlist_draw_item_t
* item
= (ui_playlist_draw_item_t
*)user_data
;
945 instance_t
* app
= item
->app
;
947 gtk_tree_model_get(model
, iter
, 7, &i
, -1);
949 if(i
!= item
->idx
) return FALSE
;
951 if(PLAYLIST_BLOCK_BEGIN
& app
->playlist
.item
[i
].type
)
952 snprintf(ch
, sizeof(ch
), "%c", 'A' + app
->playlist
.item
[i
].player
);
956 gtk_list_store_set(item
->list_store
, iter
,
958 1, app
->playlist
.block_icons
[app
->playlist
.item
[i
].type
],
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
,
965 8, (app
->playlist
.item
[i
].error
!= 0),
966 9, (app
->playlist
.item
[i
].error
& PLAYLIST_ITEM_ERROR_LIB
)?
"red":"orange",
972 void ui_playlist_draw_item(instance_t
* app
, int idx
)
974 GtkListStore
*list_store
;
975 ui_playlist_draw_item_t item
;
977 list_store
= GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app
->playlist_grid
)));
979 pthread_mutex_lock(&app
->playlist
.lock
);
983 item
.list_store
= list_store
;
984 gtk_tree_model_foreach(GTK_TREE_MODEL(list_store
), ui_playlist_draw_item_iter
, &item
);
986 pthread_mutex_unlock(&app
->playlist
.lock
);
989 void ui_set_status(instance_t
* app
, char* str
, int lock
)
993 gtk_label_set_text(GTK_LABEL(app
->status_label
), str
);
999 void ui_show_error(GtkWidget
*window
, char* title
, char* message
)
1002 dialog
= gtk_message_dialog_new
1005 GTK_DIALOG_DESTROY_WITH_PARENT
,
1011 gtk_window_set_title(GTK_WINDOW(dialog
), title
);
1012 gtk_dialog_run(GTK_DIALOG(dialog
));
1013 gtk_widget_destroy(dialog
);
1016 int ui_playlist_load(instance_t
* app
, char* path
, struct ui_playlist_io_funcs
* procs
)
1020 GtkFileFilter
*filter
;
1021 char error_message
[1024];
1023 dialog
= gtk_file_chooser_dialog_new("Open File",
1024 GTK_WINDOW (app
->window
),
1025 GTK_FILE_CHOOSER_ACTION_OPEN
,
1026 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
1027 GTK_STOCK_OPEN
, GTK_RESPONSE_ACCEPT
,
1030 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog
), path
);
1032 for(i
= 0; procs
[i
].title
; i
++)
1034 filter
= gtk_file_filter_new();
1035 gtk_file_filter_set_name(filter
, procs
[i
].title
);
1036 gtk_file_filter_add_pattern(filter
, procs
[i
].ext
);
1037 g_object_set_data(G_OBJECT(filter
), "id", GINT_TO_POINTER(i
));
1038 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog
), filter
);
1041 r
= gtk_dialog_run(GTK_DIALOG(dialog
));
1043 if(r
== GTK_RESPONSE_ACCEPT
)
1046 char *filename
, *filename2
;
1048 filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog
));
1050 i
= GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog
))), "id"));
1052 filename2
= (char*)malloc(PATH_MAX
);
1053 strncpy(filename2
, filename
, PATH_MAX
);
1054 l
= strlen(filename2
);
1055 if(l
< 4 || strcasecmp(filename2
+ l
- 4, procs
[i
].ext
+ 1))
1056 strcat(filename2
, procs
[i
].ext
+ 1);
1058 r
= procs
[i
].load(app
, filename2
, error_message
, sizeof(error_message
));
1061 ui_show_error(dialog
, "Playlist loading error", error_message
);
1065 ui_playlist_draw(app
);
1067 if(app
->playlist
.path
)
1068 g_free(app
->playlist
.path
);
1069 if((app
->playlist
.path
= filename
))
1071 char* e
= strrchr(app
->playlist
.path
, '/');
1078 gtk_widget_destroy (dialog
);
1083 int ui_playlist_save(instance_t
* app
, char* path
, struct ui_playlist_io_funcs
* procs
)
1087 GtkFileFilter
*filter
;
1088 char error_message
[1024];
1090 dialog
= gtk_file_chooser_dialog_new("Save File",
1091 GTK_WINDOW (app
->window
),
1092 GTK_FILE_CHOOSER_ACTION_SAVE
,
1093 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
1094 GTK_STOCK_SAVE
, GTK_RESPONSE_ACCEPT
,
1097 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog
), TRUE
);
1099 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog
), path
);
1101 for(i
= 0; procs
[i
].title
; i
++)
1103 filter
= gtk_file_filter_new();
1104 gtk_file_filter_set_name(filter
, procs
[i
].title
);
1105 gtk_file_filter_add_pattern(filter
, procs
[i
].ext
);
1106 g_object_set_data(G_OBJECT(filter
), "id", GINT_TO_POINTER(i
));
1107 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog
), filter
);
1110 r
= gtk_dialog_run(GTK_DIALOG(dialog
));
1112 if(r
== GTK_RESPONSE_ACCEPT
)
1115 char *filename
, *filename2
;
1117 filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog
));
1119 i
= GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog
))), "id"));
1121 filename2
= (char*)malloc(PATH_MAX
);
1122 strncpy(filename2
, filename
, PATH_MAX
);
1123 l
= strlen(filename2
);
1124 if(l
< 4 || strcasecmp(filename2
+ l
- 4, procs
[i
].ext
+ 1))
1125 strcat(filename2
, procs
[i
].ext
+ 1);
1127 r
= procs
[i
].save(app
, filename2
, error_message
, sizeof(error_message
));
1130 ui_show_error(dialog
, "Playlist saving error", error_message
);
1134 if(app
->playlist
.path
)
1135 g_free(app
->playlist
.path
);
1136 if((app
->playlist
.path
= filename
))
1138 char* e
= strrchr(app
->playlist
.path
, '/');
1145 gtk_widget_destroy (dialog
);