2 * ui.c -- GTK+ 2 omnplay
3 * Copyright (C) 2011 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>
30 #include <gdk/gdkkeysyms.h>
35 #include "ui_buttons.h"
39 typedef struct column_desc
45 static const column_desc_t playlist_columns
[] =
81 const static column_desc_t library_columns
[] =
102 static GtkWidget
* create_label(GtkWidget
* top
, char* text
, char* reg
, GtkJustification jtype
)
106 label
= gtk_label_new ("");
107 gtk_widget_show (label
);
110 gtk_label_set_justify (GTK_LABEL (label
), jtype
);
113 GLADE_HOOKUP_OBJECT (top
, label
, reg
);
116 gtk_label_set_text(GTK_LABEL (label
), text
);
121 static GtkWidget
* create_treeview(GtkWidget
* top
, char* name
, const column_desc_t columns
[])
126 GtkTreeSelection
*selection
;
127 GtkCellRenderer
*renderer
;
128 GtkTreeViewColumn
*column
;
129 GtkListStore
*list_store
;
130 GType list_store_types
[32];
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
);
137 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
138 gtk_tree_selection_set_mode(selection
, GTK_SELECTION_MULTIPLE
);
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
;
146 list_store
= gtk_list_store_newv(count
+ 3, list_store_types
);
148 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview
), GTK_TREE_MODEL( list_store
) );
150 for(i
= 0; columns
[i
].title
; i
++)
155 if(columns
[i
].type
== G_TYPE_OBJECT
)
157 renderer
= gtk_cell_renderer_pixbuf_new();
158 gtk_cell_renderer_set_padding(renderer
, 0, 0);
161 else if(columns
[i
].type
== G_TYPE_BOOLEAN
)
163 renderer
= gtk_cell_renderer_toggle_new();
168 renderer
= gtk_cell_renderer_text_new();
171 column
= gtk_tree_view_column_new_with_attributes(
172 columns
[i
].title
, renderer
,
174 "background-set", count
+ 1,
175 "background", count
+ 2,
180 column
= gtk_tree_view_column_new_with_attributes(
181 columns
[i
].title
, renderer
,
185 gtk_tree_view_append_column(GTK_TREE_VIEW( treeview
), column
);
188 g_object_unref(list_store
);
190 GLADE_HOOKUP_OBJECT (top
, treeview
, name
);
195 static GtkWidget
* pane_library_grid(GtkWidget
* top
, omnplay_instance_t
* app
)
197 GtkWidget
*scrolledwindow
;
199 scrolledwindow
= gtk_scrolled_window_new (NULL
, NULL
);
200 gtk_widget_show (scrolledwindow
);
201 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow
),
202 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
204 gtk_container_add (GTK_CONTAINER (scrolledwindow
),
205 app
->library_grid
= create_treeview(top
, "treeview_library", library_columns
));
207 return scrolledwindow
;
210 static GtkWidget
* pane_library_buttons(GtkWidget
* top
, omnplay_instance_t
* app
)
214 hbox
= gtk_hbox_new (FALSE
, 0);
215 gtk_widget_show (hbox
);
217 /* playlist modify buttons */
218 gtk_box_pack_start (GTK_BOX (hbox
),
219 ui_create_button(top
, app
, BUTTON_LIBRARY_ADD
),
221 gtk_box_pack_start (GTK_BOX (hbox
),
222 ui_create_button(top
, app
, BUTTON_LIBRARY_REFRESH
),
226 gtk_box_pack_start (GTK_BOX (hbox
),
227 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
233 static GtkWidget
* pane_library_search_buttons(GtkWidget
* top
, omnplay_instance_t
* app
)
237 hbox
= gtk_hbox_new (FALSE
, 0);
238 gtk_widget_show (hbox
);
241 gtk_box_pack_start (GTK_BOX (hbox
),
242 app
->library
.search
= gtk_entry_new(),
244 gtk_widget_show(app
->library
.search
);
246 /* playlist modify buttons */
247 gtk_box_pack_start (GTK_BOX (hbox
),
248 ui_create_button(top
, app
, BUTTON_LIBRARY_FIND
),
250 gtk_box_pack_start (GTK_BOX (hbox
),
251 ui_create_button(top
, app
, BUTTON_LIBRARY_FIND_NEXT
),
257 static GtkWidget
* pane_library(GtkWidget
* top
, omnplay_instance_t
* app
)
261 vbox
= gtk_vbox_new (FALSE
, 0);
262 gtk_widget_show (vbox
);
263 gtk_widget_set_size_request(vbox
, 300, -1);
265 /* add buttons box */
266 gtk_box_pack_start (GTK_BOX (vbox
),
267 pane_library_buttons(top
, app
),
271 gtk_box_pack_start (GTK_BOX (vbox
),
272 pane_library_grid(top
, app
),
275 /* add search buttons */
276 gtk_box_pack_start (GTK_BOX (vbox
),
277 pane_library_search_buttons(top
, app
),
283 static GtkWidget
* create_channel_status(GtkWidget
* top
, omnplay_instance_t
* app
, int idx
)
289 omnplay_player_t
* player
;
291 player
= &app
->players
.item
[idx
];
293 snprintf(name
, sizeof(name
), "%c [%s]", idx
+ 'A', player
->name
);
295 frame
= gtk_frame_new(name
);
296 gtk_widget_show(frame
);
298 vbox
= gtk_vbox_new(FALSE
, 0);
299 gtk_container_add(GTK_CONTAINER(frame
), vbox
);
300 gtk_widget_show(vbox
);
303 gtk_box_pack_start(GTK_BOX (vbox
),
304 player
->label_status
= create_label(top
, "OFFLINE", NULL
, GTK_JUSTIFY_LEFT
),
308 gtk_box_pack_start(GTK_BOX (vbox
),
309 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
313 gtk_box_pack_start (GTK_BOX (vbox
),
314 player
->label_clip
= create_label(top
, "U0002323", NULL
, GTK_JUSTIFY_LEFT
),
317 /* block state/current timecode */
318 gtk_box_pack_start(GTK_BOX (vbox
),
319 hbox
= gtk_hbox_new(TRUE
, 0),
321 gtk_widget_show(hbox
);
325 gtk_box_pack_start(GTK_BOX (hbox
),
326 player
->label_state
= create_label(top
, "PLAYING", NULL
, GTK_JUSTIFY_LEFT
),
329 /* current timecode */
330 gtk_box_pack_start(GTK_BOX (hbox
),
331 player
->label_tc_cur
= create_label(top
, "00:00:00:00", NULL
, GTK_JUSTIFY_LEFT
),
335 /* block remain label/remain timecode */
336 gtk_box_pack_start(GTK_BOX (vbox
),
337 hbox
= gtk_hbox_new(TRUE
, 0),
339 gtk_widget_show (hbox
);
343 gtk_box_pack_start(GTK_BOX (hbox
),
344 create_label(top
, "remain:", NULL
, GTK_JUSTIFY_LEFT
),
347 /* remaining timecode */
348 gtk_box_pack_start(GTK_BOX (hbox
),
349 player
->label_tc_rem
= create_label(top
, "00:00:00:00", NULL
, GTK_JUSTIFY_LEFT
),
356 static GtkWidget
* pane_operate_status(GtkWidget
* top
, omnplay_instance_t
* app
)
361 vbox
= gtk_vbox_new (FALSE
, 0);
362 gtk_widget_show (vbox
);
363 gtk_widget_set_size_request(vbox
, 250, -1);
365 for(i
= 0; i
< app
->players
.count
; i
++)
367 gtk_box_pack_start (GTK_BOX (vbox
),
368 create_channel_status(top
, app
, i
),
372 gtk_box_pack_start (GTK_BOX (vbox
),
373 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
378 gtk_box_pack_start (GTK_BOX (vbox
),
379 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
385 static GtkWidget
* pane_operate_buttons_playlist(GtkWidget
* top
, omnplay_instance_t
* app
)
389 hbox
= gtk_hbox_new (FALSE
, 0);
390 gtk_widget_show (hbox
);
392 /* playlist load/save buttons */
393 gtk_box_pack_start (GTK_BOX (hbox
),
394 ui_create_button(top
, app
, BUTTON_PLAYLIST_LOAD
),
396 gtk_box_pack_start (GTK_BOX (hbox
),
397 ui_create_button(top
, app
, BUTTON_PLAYLIST_SAVE
),
401 gtk_box_pack_start (GTK_BOX (hbox
),
402 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
405 /* playlist modify buttons */
406 gtk_box_pack_start (GTK_BOX (hbox
),
407 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_ADD
),
409 gtk_box_pack_start (GTK_BOX (hbox
),
410 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_EDIT
),
412 gtk_box_pack_start (GTK_BOX (hbox
),
413 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_DEL
),
417 gtk_box_pack_start (GTK_BOX (hbox
),
418 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
421 /* playlist block buttons */
422 gtk_box_pack_start (GTK_BOX (hbox
),
423 ui_create_button(top
, app
, BUTTON_PLAYLIST_BLOCK_SINGLE
),
425 gtk_box_pack_start (GTK_BOX (hbox
),
426 ui_create_button(top
, app
, BUTTON_PLAYLIST_BLOCK_LOOP
),
430 gtk_box_pack_start (GTK_BOX (hbox
),
431 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
434 /* playlist move items buttons */
435 gtk_box_pack_start (GTK_BOX (hbox
),
436 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_UP
),
438 gtk_box_pack_start (GTK_BOX (hbox
),
439 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_DOWN
),
443 gtk_box_pack_start (GTK_BOX (hbox
),
444 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
447 /* playlist relink */
448 gtk_box_pack_start (GTK_BOX (hbox
),
449 ui_create_button(top
, app
, BUTTON_PLAYLIST_RELINK
),
455 static GtkWidget
* pane_operate_grid(GtkWidget
* top
, omnplay_instance_t
* app
)
457 GtkWidget
*scrolledwindow
;
459 scrolledwindow
= gtk_scrolled_window_new (NULL
, NULL
);
460 gtk_widget_show (scrolledwindow
);
461 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow
),
462 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
464 gtk_container_add (GTK_CONTAINER (scrolledwindow
),
465 app
->playlist_grid
= create_treeview(top
, "treeview_playlist", playlist_columns
));
467 return scrolledwindow
;
470 static GtkWidget
* pane_operate_buttons_operate(GtkWidget
* top
, omnplay_instance_t
* app
)
474 hbox
= gtk_hbox_new (FALSE
, 0);
475 gtk_widget_show (hbox
);
478 gtk_box_pack_start (GTK_BOX (hbox
),
479 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
482 /* playlist modify buttons */
483 gtk_box_pack_start (GTK_BOX (hbox
),
484 ui_create_button(top
, app
, BUTTON_PLAYER_CUE
),
486 gtk_box_pack_start (GTK_BOX (hbox
),
487 ui_create_button(top
, app
, BUTTON_PLAYER_PLAY
),
489 gtk_box_pack_start (GTK_BOX (hbox
),
490 ui_create_button(top
, app
, BUTTON_PLAYER_PAUSE
),
492 gtk_box_pack_start (GTK_BOX (hbox
),
493 ui_create_button(top
, app
, BUTTON_PLAYER_STOP
),
497 gtk_box_pack_start (GTK_BOX (hbox
),
498 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
504 static GtkWidget
* pane_operate_operate(GtkWidget
* top
, omnplay_instance_t
* app
)
508 vbox
= gtk_vbox_new (FALSE
, 0);
509 gtk_widget_show (vbox
);
511 /* add buttons box #1 */
512 gtk_box_pack_start (GTK_BOX (vbox
),
513 pane_operate_buttons_playlist(top
, app
),
516 /* add buttons box */
517 gtk_box_pack_start (GTK_BOX (vbox
),
518 pane_operate_grid(top
, app
),
521 /* add buttons box #1 */
522 gtk_box_pack_start (GTK_BOX (vbox
),
523 pane_operate_buttons_operate(top
, app
),
530 static GtkWidget
* pane_operate(GtkWidget
* top
, omnplay_instance_t
* app
)
534 hbox
= gtk_hbox_new (FALSE
, 0);
535 gtk_widget_show (hbox
);
537 /* add buttons box */
538 gtk_box_pack_start (GTK_BOX (hbox
),
539 pane_operate_status(top
, app
),
542 /* add buttons box */
543 gtk_box_pack_start (GTK_BOX (hbox
),
544 pane_operate_operate(top
, app
),
551 static GtkWidget
* pane_top(GtkWidget
* top
, omnplay_instance_t
* app
)
555 pane
= gtk_hpaned_new ();
556 gtk_widget_show (pane
);
558 gtk_paned_set_position (GTK_PANED (pane
), 800);
560 gtk_paned_pack1 (GTK_PANED (pane
),
561 pane_operate(top
, app
),
564 gtk_paned_pack2 (GTK_PANED (pane
),
565 pane_library(top
, app
),
571 GtkWidget
* ui_omnplay (omnplay_instance_t
* app
)
576 wnd
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
577 GLADE_HOOKUP_OBJECT_NO_REF (wnd
, wnd
, "omnplay_window");
579 gtk_window_set_title (GTK_WINDOW (wnd
), _("Omneon Player"));
580 gtk_window_set_default_size (GTK_WINDOW (wnd
), 1024, 768);
582 vbox
= gtk_vbox_new(FALSE
, 0);
583 gtk_widget_show(vbox
);
585 gtk_container_add(GTK_CONTAINER(wnd
), vbox
);
587 gtk_box_pack_start (GTK_BOX (vbox
),
590 gtk_box_pack_start (GTK_BOX (vbox
),
591 app
->status_label
= create_label(wnd
, "omnplay started", NULL
, GTK_JUSTIFY_LEFT
),
594 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_BLOCK_BEGIN
] =
595 create_pixbuf2("block_type_block_start_16x16.png");
596 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_BLOCK_BODY
] =
597 create_pixbuf2("block_type_block_middle_16x16.png");
598 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_BLOCK_END
] =
599 create_pixbuf2("block_type_block_end_16x16.png");
600 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE
] =
601 create_pixbuf2("block_type_block_single_16x16.png");
602 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_LOOP_BEGIN
] =
603 create_pixbuf2("block_type_loop_start_16x16.png");
604 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_LOOP_BODY
] =
605 create_pixbuf2("block_type_loop_middle_16x16.png");
606 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_LOOP_END
] =
607 create_pixbuf2("block_type_loop_end_16x16.png");
608 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_LOOP_SINGLE
] =
609 create_pixbuf2("block_type_block_loop_16x16.png");
614 int ui_playlist_item_dialog(omnplay_instance_t
* app
, playlist_item_t
* item
)
620 GtkWidget
*box
, *table
;
621 GtkWidget
*entry
[4], *combo
;
623 dlg
= gtk_dialog_new_with_buttons(
625 GTK_WINDOW(app
->window
),
627 GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
,
628 GTK_STOCK_CANCEL
, GTK_RESPONSE_REJECT
,
631 box
= gtk_dialog_get_content_area(GTK_DIALOG(dlg
));
633 table
= gtk_table_new(5, 2, TRUE
);
634 gtk_widget_show(table
);
635 gtk_box_pack_start(GTK_BOX(box
), table
, TRUE
, TRUE
, 0);
637 gtk_table_attach(GTK_TABLE(table
),
638 create_label(NULL
, "ID:", NULL
, 0),
640 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
642 gtk_table_attach(GTK_TABLE(table
),
643 create_label(NULL
, "IN:", NULL
, GTK_JUSTIFY_RIGHT
),
645 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
647 gtk_table_attach(GTK_TABLE(table
),
648 create_label(NULL
, "DUR:", NULL
, GTK_JUSTIFY_RIGHT
),
650 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
652 gtk_table_attach(GTK_TABLE(table
),
653 create_label(NULL
, "TITLE:", NULL
, GTK_JUSTIFY_RIGHT
),
655 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
657 gtk_table_attach(GTK_TABLE(table
),
658 create_label(NULL
, "CHANNEL:", NULL
, GTK_JUSTIFY_RIGHT
),
660 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
663 gtk_table_attach(GTK_TABLE(table
),
664 entry
[0] = gtk_entry_new_with_max_length(32),
666 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
668 gtk_table_attach(GTK_TABLE(table
),
669 entry
[1] = gtk_entry_new_with_max_length(12),
671 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
673 gtk_table_attach(GTK_TABLE(table
),
674 entry
[2] = gtk_entry_new_with_max_length(12),
676 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
678 gtk_table_attach(GTK_TABLE(table
),
679 entry
[3] = gtk_entry_new_with_max_length(128),
681 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
683 gtk_table_attach(GTK_TABLE(table
),
684 combo
= gtk_combo_box_new_text(),
686 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
690 gtk_entry_set_text(GTK_ENTRY(entry
[0]), item
->id
);
691 gtk_entry_set_text(GTK_ENTRY(entry
[1]), frames2tc(item
->in
, 25.0, tc
));
692 gtk_entry_set_text(GTK_ENTRY(entry
[2]), frames2tc(item
->dur
, 25.0, tc
));
693 gtk_entry_set_text(GTK_ENTRY(entry
[3]), item
->title
);
694 gtk_combo_box_append_text(GTK_COMBO_BOX(combo
), "A");
695 gtk_combo_box_append_text(GTK_COMBO_BOX(combo
), "B");
696 gtk_combo_box_append_text(GTK_COMBO_BOX(combo
), "C");
697 gtk_combo_box_append_text(GTK_COMBO_BOX(combo
), "D");
698 gtk_combo_box_set_active(GTK_COMBO_BOX(combo
), item
->player
);
700 gtk_widget_show_all(dlg
);
705 response
= gtk_dialog_run(GTK_DIALOG(dlg
));
707 if( GTK_RESPONSE_REJECT
== response
||
708 GTK_RESPONSE_DELETE_EVENT
== response
||
709 GTK_RESPONSE_CANCEL
== response
)
718 /* get item data back */
719 strncpy(item
->id
, gtk_entry_get_text(GTK_ENTRY(entry
[0])), PATH_MAX
);
720 tc2frames((char*)gtk_entry_get_text(GTK_ENTRY(entry
[1])), 25.0, &item
->in
);
721 tc2frames((char*)gtk_entry_get_text(GTK_ENTRY(entry
[2])), 25.0, &item
->dur
);
722 strncpy(item
->title
, gtk_entry_get_text(GTK_ENTRY(entry
[3])), PATH_MAX
);
723 item
->player
= gtk_combo_box_get_active(GTK_COMBO_BOX(combo
));
725 /* check if all data entered correctly */
731 gtk_widget_hide(dlg
);
732 gtk_widget_destroy(dlg
);