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
);
135 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
136 gtk_tree_selection_set_mode(selection
, GTK_SELECTION_MULTIPLE
);
138 for(i
= 0, count
= 0; columns
[i
].title
; i
++, count
++)
139 list_store_types
[i
] = (columns
[i
].type
== G_TYPE_OBJECT
)?GDK_TYPE_PIXBUF
:columns
[i
].type
;
140 list_store_types
[count
] = G_TYPE_INT
;
142 list_store
= gtk_list_store_newv(count
+ 1, list_store_types
);
144 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview
), GTK_TREE_MODEL( list_store
) );
146 for(i
= 0; columns
[i
].title
; i
++)
150 if(columns
[i
].type
== G_TYPE_OBJECT
)
152 renderer
= gtk_cell_renderer_pixbuf_new();
153 gtk_cell_renderer_set_padding(renderer
, 0, 0);
156 else if(columns
[i
].type
== G_TYPE_BOOLEAN
)
158 renderer
= gtk_cell_renderer_toggle_new();
163 renderer
= gtk_cell_renderer_text_new();
167 column
= gtk_tree_view_column_new_with_attributes(
168 columns
[i
].title
, renderer
, prop
, i
, NULL
);
169 gtk_tree_view_append_column(GTK_TREE_VIEW( treeview
), column
);
172 g_object_unref(list_store
);
174 GLADE_HOOKUP_OBJECT (top
, treeview
, name
);
179 static GtkWidget
* pane_library_grid(GtkWidget
* top
, omnplay_instance_t
* app
)
181 GtkWidget
*scrolledwindow
;
183 scrolledwindow
= gtk_scrolled_window_new (NULL
, NULL
);
184 gtk_widget_show (scrolledwindow
);
185 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow
),
186 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
188 gtk_container_add (GTK_CONTAINER (scrolledwindow
),
189 app
->library_grid
= create_treeview(top
, "treeview_library", library_columns
));
191 return scrolledwindow
;
194 static GtkWidget
* pane_library_buttons(GtkWidget
* top
, omnplay_instance_t
* app
)
198 hbox
= gtk_hbox_new (FALSE
, 0);
199 gtk_widget_show (hbox
);
201 /* playlist modify buttons */
202 gtk_box_pack_start (GTK_BOX (hbox
),
203 ui_create_button(top
, app
, BUTTON_LIBRARY_ADD
),
205 gtk_box_pack_start (GTK_BOX (hbox
),
206 ui_create_button(top
, app
, BUTTON_LIBRARY_REFRESH
),
210 gtk_box_pack_start (GTK_BOX (hbox
),
211 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
217 static GtkWidget
* pane_library(GtkWidget
* top
, omnplay_instance_t
* app
)
221 vbox
= gtk_vbox_new (FALSE
, 0);
222 gtk_widget_show (vbox
);
223 gtk_widget_set_size_request(vbox
, 300, -1);
225 /* add buttons box */
226 gtk_box_pack_start (GTK_BOX (vbox
),
227 pane_library_buttons(top
, app
),
230 /* add buttons box */
231 gtk_box_pack_start (GTK_BOX (vbox
),
232 pane_library_grid(top
, app
),
238 static GtkWidget
* create_channel_status(GtkWidget
* top
, omnplay_instance_t
* app
, int idx
)
243 omnplay_player_t
* player
;
245 player
= &app
->players
.item
[idx
];
247 frame
= gtk_frame_new(player
->name
);
248 gtk_widget_show(frame
);
250 vbox
= gtk_vbox_new(FALSE
, 0);
251 gtk_container_add(GTK_CONTAINER(frame
), vbox
);
252 gtk_widget_show(vbox
);
255 gtk_box_pack_start(GTK_BOX (vbox
),
256 player
->label_status
= create_label(top
, "OFFLINE", NULL
, GTK_JUSTIFY_LEFT
),
260 gtk_box_pack_start(GTK_BOX (vbox
),
261 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
265 gtk_box_pack_start (GTK_BOX (vbox
),
266 player
->label_clip
= create_label(top
, "U0002323", NULL
, GTK_JUSTIFY_LEFT
),
269 /* block state/current timecode */
270 gtk_box_pack_start(GTK_BOX (vbox
),
271 hbox
= gtk_hbox_new(TRUE
, 0),
273 gtk_widget_show(hbox
);
277 gtk_box_pack_start(GTK_BOX (hbox
),
278 player
->label_state
= create_label(top
, "PLAYING", NULL
, GTK_JUSTIFY_LEFT
),
281 /* current timecode */
282 gtk_box_pack_start(GTK_BOX (hbox
),
283 player
->label_tc_cur
= create_label(top
, "00:00:00:00", NULL
, GTK_JUSTIFY_LEFT
),
287 /* block remain label/remain timecode */
288 gtk_box_pack_start(GTK_BOX (vbox
),
289 hbox
= gtk_hbox_new(TRUE
, 0),
291 gtk_widget_show (hbox
);
295 gtk_box_pack_start(GTK_BOX (hbox
),
296 create_label(top
, "remain:", NULL
, GTK_JUSTIFY_LEFT
),
299 /* remaining timecode */
300 gtk_box_pack_start(GTK_BOX (hbox
),
301 player
->label_tc_rem
= create_label(top
, "00:00:00:00", NULL
, GTK_JUSTIFY_LEFT
),
308 static GtkWidget
* pane_operate_status(GtkWidget
* top
, omnplay_instance_t
* app
)
313 vbox
= gtk_vbox_new (FALSE
, 0);
314 gtk_widget_show (vbox
);
315 gtk_widget_set_size_request(vbox
, 250, -1);
317 for(i
= 0; i
< app
->players
.count
; i
++)
319 gtk_box_pack_start (GTK_BOX (vbox
),
320 create_channel_status(top
, app
, i
),
324 gtk_box_pack_start (GTK_BOX (vbox
),
325 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
330 gtk_box_pack_start (GTK_BOX (vbox
),
331 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
337 static GtkWidget
* pane_operate_buttons_playlist(GtkWidget
* top
, omnplay_instance_t
* app
)
341 hbox
= gtk_hbox_new (FALSE
, 0);
342 gtk_widget_show (hbox
);
344 /* playlist load/save buttons */
345 gtk_box_pack_start (GTK_BOX (hbox
),
346 ui_create_button(top
, app
, BUTTON_PLAYLIST_LOAD
),
348 gtk_box_pack_start (GTK_BOX (hbox
),
349 ui_create_button(top
, app
, BUTTON_PLAYLIST_SAVE
),
353 gtk_box_pack_start (GTK_BOX (hbox
),
354 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
357 /* playlist modify buttons */
358 gtk_box_pack_start (GTK_BOX (hbox
),
359 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_ADD
),
361 gtk_box_pack_start (GTK_BOX (hbox
),
362 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_EDIT
),
364 gtk_box_pack_start (GTK_BOX (hbox
),
365 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_DEL
),
369 gtk_box_pack_start (GTK_BOX (hbox
),
370 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
373 /* playlist block buttons */
374 gtk_box_pack_start (GTK_BOX (hbox
),
375 ui_create_button(top
, app
, BUTTON_PLAYLIST_BLOCK_SINGLE
),
377 gtk_box_pack_start (GTK_BOX (hbox
),
378 ui_create_button(top
, app
, BUTTON_PLAYLIST_BLOCK_LOOP
),
382 gtk_box_pack_start (GTK_BOX (hbox
),
383 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
386 /* playlist move items buttons */
387 gtk_box_pack_start (GTK_BOX (hbox
),
388 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_UP
),
390 gtk_box_pack_start (GTK_BOX (hbox
),
391 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_DOWN
),
397 static GtkWidget
* pane_operate_grid(GtkWidget
* top
, omnplay_instance_t
* app
)
399 GtkWidget
*scrolledwindow
;
401 scrolledwindow
= gtk_scrolled_window_new (NULL
, NULL
);
402 gtk_widget_show (scrolledwindow
);
403 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow
),
404 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
406 gtk_container_add (GTK_CONTAINER (scrolledwindow
),
407 app
->playlist_grid
= create_treeview(top
, "treeview_playlist", playlist_columns
));
409 return scrolledwindow
;
412 static GtkWidget
* pane_operate_buttons_operate(GtkWidget
* top
, omnplay_instance_t
* app
)
416 hbox
= gtk_hbox_new (FALSE
, 0);
417 gtk_widget_show (hbox
);
420 gtk_box_pack_start (GTK_BOX (hbox
),
421 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
424 /* playlist modify buttons */
425 gtk_box_pack_start (GTK_BOX (hbox
),
426 ui_create_button(top
, app
, BUTTON_PLAYER_CUE
),
428 gtk_box_pack_start (GTK_BOX (hbox
),
429 ui_create_button(top
, app
, BUTTON_PLAYER_PLAY
),
431 gtk_box_pack_start (GTK_BOX (hbox
),
432 ui_create_button(top
, app
, BUTTON_PLAYER_PAUSE
),
434 gtk_box_pack_start (GTK_BOX (hbox
),
435 ui_create_button(top
, app
, BUTTON_PLAYER_STOP
),
439 gtk_box_pack_start (GTK_BOX (hbox
),
440 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
446 static GtkWidget
* pane_operate_operate(GtkWidget
* top
, omnplay_instance_t
* app
)
450 vbox
= gtk_vbox_new (FALSE
, 0);
451 gtk_widget_show (vbox
);
453 /* add buttons box #1 */
454 gtk_box_pack_start (GTK_BOX (vbox
),
455 pane_operate_buttons_playlist(top
, app
),
458 /* add buttons box */
459 gtk_box_pack_start (GTK_BOX (vbox
),
460 pane_operate_grid(top
, app
),
463 /* add buttons box #1 */
464 gtk_box_pack_start (GTK_BOX (vbox
),
465 pane_operate_buttons_operate(top
, app
),
472 static GtkWidget
* pane_operate(GtkWidget
* top
, omnplay_instance_t
* app
)
476 hbox
= gtk_hbox_new (FALSE
, 0);
477 gtk_widget_show (hbox
);
479 /* add buttons box */
480 gtk_box_pack_start (GTK_BOX (hbox
),
481 pane_operate_status(top
, app
),
484 /* add buttons box */
485 gtk_box_pack_start (GTK_BOX (hbox
),
486 pane_operate_operate(top
, app
),
493 static GtkWidget
* pane_top(GtkWidget
* top
, omnplay_instance_t
* app
)
497 pane
= gtk_hpaned_new ();
498 gtk_widget_show (pane
);
500 gtk_paned_set_position (GTK_PANED (pane
), 800);
502 gtk_paned_pack1 (GTK_PANED (pane
),
503 pane_operate(top
, app
),
506 gtk_paned_pack2 (GTK_PANED (pane
),
507 pane_library(top
, app
),
513 GtkWidget
* ui_omnplay (omnplay_instance_t
* app
)
517 wnd
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
518 GLADE_HOOKUP_OBJECT_NO_REF (wnd
, wnd
, "omnplay_window");
520 gtk_window_set_title (GTK_WINDOW (wnd
), _("Omneon Player"));
521 gtk_window_set_default_size (GTK_WINDOW (wnd
), 1024, 768);
523 gtk_container_add (GTK_CONTAINER (wnd
),
526 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_BLOCK_BEGIN
] =
527 create_pixbuf("block_type_block_start_16x16.png");
528 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_BLOCK_BODY
] =
529 create_pixbuf("block_type_block_middle_16x16.png");
530 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_BLOCK_END
] =
531 create_pixbuf("block_type_block_end_16x16.png");
532 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE
] =
533 create_pixbuf("block_type_block_single_16x16.png");
534 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_LOOP_BEGIN
] =
535 create_pixbuf("block_type_loop_start_16x16.png");
536 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_LOOP_BODY
] =
537 create_pixbuf("block_type_loop_middle_16x16.png");
538 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_LOOP_END
] =
539 create_pixbuf("block_type_loop_end_16x16.png");
540 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_LOOP_SINGLE
] =
541 create_pixbuf("block_type_block_loop_16x16.png");
546 int ui_playlist_item_dialog(omnplay_instance_t
* app
, playlist_item_t
* item
)
552 GtkWidget
*box
, *table
;
553 GtkWidget
*entry
[4], *combo
;
555 dlg
= gtk_dialog_new_with_buttons(
557 GTK_WINDOW(app
->window
),
559 GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
,
560 GTK_STOCK_CANCEL
, GTK_RESPONSE_REJECT
,
563 box
= gtk_dialog_get_content_area(GTK_DIALOG(dlg
));
565 table
= gtk_table_new(5, 2, TRUE
);
566 gtk_widget_show(table
);
567 gtk_box_pack_start(GTK_BOX(box
), table
, TRUE
, TRUE
, 0);
569 gtk_table_attach(GTK_TABLE(table
),
570 create_label(NULL
, "ID:", NULL
, 0),
572 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
574 gtk_table_attach(GTK_TABLE(table
),
575 create_label(NULL
, "IN:", NULL
, GTK_JUSTIFY_RIGHT
),
577 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
579 gtk_table_attach(GTK_TABLE(table
),
580 create_label(NULL
, "DUR:", NULL
, GTK_JUSTIFY_RIGHT
),
582 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
584 gtk_table_attach(GTK_TABLE(table
),
585 create_label(NULL
, "TITLE:", NULL
, GTK_JUSTIFY_RIGHT
),
587 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
589 gtk_table_attach(GTK_TABLE(table
),
590 create_label(NULL
, "CHANNEL:", NULL
, GTK_JUSTIFY_RIGHT
),
592 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
595 gtk_table_attach(GTK_TABLE(table
),
596 entry
[0] = gtk_entry_new_with_max_length(32),
598 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
600 gtk_table_attach(GTK_TABLE(table
),
601 entry
[1] = gtk_entry_new_with_max_length(12),
603 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
605 gtk_table_attach(GTK_TABLE(table
),
606 entry
[2] = gtk_entry_new_with_max_length(12),
608 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
610 gtk_table_attach(GTK_TABLE(table
),
611 entry
[3] = gtk_entry_new_with_max_length(128),
613 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
615 gtk_table_attach(GTK_TABLE(table
),
616 combo
= gtk_combo_box_new_text(),
618 GTK_FILL
/* | GTK_SHRINK */, GTK_FILL
| GTK_SHRINK
, 5, 5);
622 gtk_entry_set_text(GTK_ENTRY(entry
[0]), item
->id
);
623 gtk_entry_set_text(GTK_ENTRY(entry
[1]), frames2tc(item
->in
, 25.0, tc
));
624 gtk_entry_set_text(GTK_ENTRY(entry
[2]), frames2tc(item
->dur
, 25.0, tc
));
625 gtk_entry_set_text(GTK_ENTRY(entry
[3]), item
->title
);
626 gtk_combo_box_append_text(GTK_COMBO_BOX(combo
), "A");
627 gtk_combo_box_append_text(GTK_COMBO_BOX(combo
), "B");
628 gtk_combo_box_append_text(GTK_COMBO_BOX(combo
), "C");
629 gtk_combo_box_append_text(GTK_COMBO_BOX(combo
), "D");
630 gtk_combo_box_set_active(GTK_COMBO_BOX(combo
), item
->player
);
632 gtk_widget_show_all(dlg
);
637 response
= gtk_dialog_run(GTK_DIALOG(dlg
));
639 if(GTK_RESPONSE_REJECT
== response
)
648 /* get item data back */
649 strncpy(item
->id
, gtk_entry_get_text(GTK_ENTRY(entry
[0])), PATH_MAX
);
650 tc2frames((char*)gtk_entry_get_text(GTK_ENTRY(entry
[1])), 25.0, &item
->in
);
651 tc2frames((char*)gtk_entry_get_text(GTK_ENTRY(entry
[2])), 25.0, &item
->dur
);
652 strncpy(item
->title
, gtk_entry_get_text(GTK_ENTRY(entry
[3])), PATH_MAX
);
653 item
->player
= gtk_combo_box_get_active(GTK_COMBO_BOX(combo
));
655 /* check if all data entered correctly */
656 if(item
->dur
&& item
->id
[0])
661 gtk_widget_hide(dlg
);
662 gtk_widget_destroy(dlg
);