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"
38 typedef struct column_desc
44 static const column_desc_t playlist_columns
[] =
80 const static column_desc_t library_columns
[] =
101 static GtkWidget
* create_label(GtkWidget
* top
, char* text
, char* reg
, GtkJustification jtype
)
105 label
= gtk_label_new ("");
106 gtk_widget_show (label
);
108 gtk_label_set_justify (GTK_LABEL (label
), jtype
);
111 GLADE_HOOKUP_OBJECT (top
, label
, reg
);
114 gtk_label_set_text(GTK_LABEL (label
), text
);
119 static GtkWidget
* create_treeview(GtkWidget
* top
, char* name
, const column_desc_t columns
[])
124 GtkTreeSelection
*selection
;
125 GtkCellRenderer
*renderer
;
126 GtkTreeViewColumn
*column
;
127 GtkListStore
*list_store
;
128 GType list_store_types
[32];
130 treeview
= gtk_tree_view_new ();
131 gtk_widget_show (treeview
);
133 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
134 gtk_tree_selection_set_mode(selection
, GTK_SELECTION_MULTIPLE
);
136 for(i
= 0, count
= 0; columns
[i
].title
; i
++, count
++)
137 list_store_types
[i
] = (columns
[i
].type
== G_TYPE_OBJECT
)?GDK_TYPE_PIXBUF
:columns
[i
].type
;
138 list_store_types
[count
] = G_TYPE_INT
;
140 list_store
= gtk_list_store_newv(count
+ 1, list_store_types
);
142 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview
), GTK_TREE_MODEL( list_store
) );
144 for(i
= 0; columns
[i
].title
; i
++)
148 if(columns
[i
].type
== G_TYPE_OBJECT
)
150 renderer
= gtk_cell_renderer_pixbuf_new();
151 gtk_cell_renderer_set_padding(renderer
, 0, 0);
154 else if(columns
[i
].type
== G_TYPE_BOOLEAN
)
156 renderer
= gtk_cell_renderer_toggle_new();
161 renderer
= gtk_cell_renderer_text_new();
165 column
= gtk_tree_view_column_new_with_attributes(
166 columns
[i
].title
, renderer
, prop
, i
, NULL
);
167 gtk_tree_view_append_column(GTK_TREE_VIEW( treeview
), column
);
170 g_object_unref(list_store
);
172 GLADE_HOOKUP_OBJECT (top
, treeview
, name
);
177 static GtkWidget
* pane_library_grid(GtkWidget
* top
, omnplay_instance_t
* app
)
179 GtkWidget
*scrolledwindow
;
181 scrolledwindow
= gtk_scrolled_window_new (NULL
, NULL
);
182 gtk_widget_show (scrolledwindow
);
183 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow
),
184 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
186 gtk_container_add (GTK_CONTAINER (scrolledwindow
),
187 app
->library_grid
= create_treeview(top
, "treeview_library", library_columns
));
189 return scrolledwindow
;
192 static GtkWidget
* pane_library_buttons(GtkWidget
* top
, omnplay_instance_t
* app
)
196 hbox
= gtk_hbox_new (FALSE
, 0);
197 gtk_widget_show (hbox
);
199 /* playlist modify buttons */
200 gtk_box_pack_start (GTK_BOX (hbox
),
201 ui_create_button(top
, app
, BUTTON_LIBRARY_ADD
),
203 gtk_box_pack_start (GTK_BOX (hbox
),
204 ui_create_button(top
, app
, BUTTON_LIBRARY_REFRESH
),
208 gtk_box_pack_start (GTK_BOX (hbox
),
209 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
215 static GtkWidget
* pane_library(GtkWidget
* top
, omnplay_instance_t
* app
)
219 vbox
= gtk_vbox_new (FALSE
, 0);
220 gtk_widget_show (vbox
);
221 gtk_widget_set_size_request(vbox
, 300, -1);
223 /* add buttons box */
224 gtk_box_pack_start (GTK_BOX (vbox
),
225 pane_library_buttons(top
, app
),
228 /* add buttons box */
229 gtk_box_pack_start (GTK_BOX (vbox
),
230 pane_library_grid(top
, app
),
236 static GtkWidget
* create_channel_status(GtkWidget
* top
, omnplay_instance_t
* app
, int idx
)
241 omnplay_player_t
* player
;
243 player
= &app
->players
.item
[idx
];
245 frame
= gtk_frame_new(player
->name
);
246 gtk_widget_show(frame
);
248 vbox
= gtk_vbox_new(FALSE
, 0);
249 gtk_container_add(GTK_CONTAINER(frame
), vbox
);
250 gtk_widget_show(vbox
);
253 gtk_box_pack_start(GTK_BOX (vbox
),
254 player
->label_status
= create_label(top
, "OFFLINE", NULL
, GTK_JUSTIFY_LEFT
),
258 gtk_box_pack_start(GTK_BOX (vbox
),
259 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
263 gtk_box_pack_start (GTK_BOX (vbox
),
264 player
->label_clip
= create_label(top
, "U0002323", NULL
, GTK_JUSTIFY_LEFT
),
267 /* block state/current timecode */
268 gtk_box_pack_start(GTK_BOX (vbox
),
269 hbox
= gtk_hbox_new(TRUE
, 0),
271 gtk_widget_show(hbox
);
275 gtk_box_pack_start(GTK_BOX (hbox
),
276 player
->label_state
= create_label(top
, "PLAYING", NULL
, GTK_JUSTIFY_LEFT
),
279 /* current timecode */
280 gtk_box_pack_start(GTK_BOX (hbox
),
281 player
->label_tc_cur
= create_label(top
, "00:00:00:00", NULL
, GTK_JUSTIFY_LEFT
),
285 /* block remain label/remain timecode */
286 gtk_box_pack_start(GTK_BOX (vbox
),
287 hbox
= gtk_hbox_new(TRUE
, 0),
289 gtk_widget_show (hbox
);
293 gtk_box_pack_start(GTK_BOX (hbox
),
294 create_label(top
, "remain:", NULL
, GTK_JUSTIFY_LEFT
),
297 /* remaining timecode */
298 gtk_box_pack_start(GTK_BOX (hbox
),
299 player
->label_tc_rem
= create_label(top
, "00:00:00:00", NULL
, GTK_JUSTIFY_LEFT
),
306 static GtkWidget
* pane_operate_status(GtkWidget
* top
, omnplay_instance_t
* app
)
311 vbox
= gtk_vbox_new (FALSE
, 0);
312 gtk_widget_show (vbox
);
313 gtk_widget_set_size_request(vbox
, 250, -1);
315 for(i
= 0; i
< app
->players
.count
; i
++)
317 gtk_box_pack_start (GTK_BOX (vbox
),
318 create_channel_status(top
, app
, i
),
322 gtk_box_pack_start (GTK_BOX (vbox
),
323 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
328 gtk_box_pack_start (GTK_BOX (vbox
),
329 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
335 static GtkWidget
* pane_operate_buttons_playlist(GtkWidget
* top
, omnplay_instance_t
* app
)
339 hbox
= gtk_hbox_new (FALSE
, 0);
340 gtk_widget_show (hbox
);
342 /* playlist load/save buttons */
343 gtk_box_pack_start (GTK_BOX (hbox
),
344 ui_create_button(top
, app
, BUTTON_PLAYLIST_LOAD
),
346 gtk_box_pack_start (GTK_BOX (hbox
),
347 ui_create_button(top
, app
, BUTTON_PLAYLIST_SAVE
),
351 gtk_box_pack_start (GTK_BOX (hbox
),
352 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
355 /* playlist modify buttons */
356 gtk_box_pack_start (GTK_BOX (hbox
),
357 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_ADD
),
359 gtk_box_pack_start (GTK_BOX (hbox
),
360 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_EDIT
),
362 gtk_box_pack_start (GTK_BOX (hbox
),
363 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_DEL
),
367 gtk_box_pack_start (GTK_BOX (hbox
),
368 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
371 /* playlist block buttons */
372 gtk_box_pack_start (GTK_BOX (hbox
),
373 ui_create_button(top
, app
, BUTTON_PLAYLIST_BLOCK_SINGLE
),
375 gtk_box_pack_start (GTK_BOX (hbox
),
376 ui_create_button(top
, app
, BUTTON_PLAYLIST_BLOCK_LOOP
),
380 gtk_box_pack_start (GTK_BOX (hbox
),
381 create_label(top
, " ", NULL
, GTK_JUSTIFY_CENTER
),
384 /* playlist move items buttons */
385 gtk_box_pack_start (GTK_BOX (hbox
),
386 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_UP
),
388 gtk_box_pack_start (GTK_BOX (hbox
),
389 ui_create_button(top
, app
, BUTTON_PLAYLIST_ITEM_DOWN
),
395 static GtkWidget
* pane_operate_grid(GtkWidget
* top
, omnplay_instance_t
* app
)
397 GtkWidget
*scrolledwindow
;
399 scrolledwindow
= gtk_scrolled_window_new (NULL
, NULL
);
400 gtk_widget_show (scrolledwindow
);
401 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow
),
402 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
404 gtk_container_add (GTK_CONTAINER (scrolledwindow
),
405 app
->playlist_grid
= create_treeview(top
, "treeview_playlist", playlist_columns
));
407 return scrolledwindow
;
410 static GtkWidget
* pane_operate_buttons_operate(GtkWidget
* top
, omnplay_instance_t
* app
)
414 hbox
= gtk_hbox_new (FALSE
, 0);
415 gtk_widget_show (hbox
);
418 gtk_box_pack_start (GTK_BOX (hbox
),
419 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
422 /* playlist modify buttons */
423 gtk_box_pack_start (GTK_BOX (hbox
),
424 ui_create_button(top
, app
, BUTTON_PLAYER_CUE
),
426 gtk_box_pack_start (GTK_BOX (hbox
),
427 ui_create_button(top
, app
, BUTTON_PLAYER_PLAY
),
429 gtk_box_pack_start (GTK_BOX (hbox
),
430 ui_create_button(top
, app
, BUTTON_PLAYER_PAUSE
),
432 gtk_box_pack_start (GTK_BOX (hbox
),
433 ui_create_button(top
, app
, BUTTON_PLAYER_STOP
),
437 gtk_box_pack_start (GTK_BOX (hbox
),
438 create_label(top
, NULL
, NULL
, GTK_JUSTIFY_CENTER
),
444 static GtkWidget
* pane_operate_operate(GtkWidget
* top
, omnplay_instance_t
* app
)
448 vbox
= gtk_vbox_new (FALSE
, 0);
449 gtk_widget_show (vbox
);
451 /* add buttons box #1 */
452 gtk_box_pack_start (GTK_BOX (vbox
),
453 pane_operate_buttons_playlist(top
, app
),
456 /* add buttons box */
457 gtk_box_pack_start (GTK_BOX (vbox
),
458 pane_operate_grid(top
, app
),
461 /* add buttons box #1 */
462 gtk_box_pack_start (GTK_BOX (vbox
),
463 pane_operate_buttons_operate(top
, app
),
470 static GtkWidget
* pane_operate(GtkWidget
* top
, omnplay_instance_t
* app
)
474 hbox
= gtk_hbox_new (FALSE
, 0);
475 gtk_widget_show (hbox
);
477 /* add buttons box */
478 gtk_box_pack_start (GTK_BOX (hbox
),
479 pane_operate_status(top
, app
),
482 /* add buttons box */
483 gtk_box_pack_start (GTK_BOX (hbox
),
484 pane_operate_operate(top
, app
),
491 static GtkWidget
* pane_top(GtkWidget
* top
, omnplay_instance_t
* app
)
495 pane
= gtk_hpaned_new ();
496 gtk_widget_show (pane
);
498 gtk_paned_set_position (GTK_PANED (pane
), 800);
500 gtk_paned_pack1 (GTK_PANED (pane
),
501 pane_operate(top
, app
),
504 gtk_paned_pack2 (GTK_PANED (pane
),
505 pane_library(top
, app
),
511 GtkWidget
* ui_omnplay (omnplay_instance_t
* app
)
515 wnd
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
516 GLADE_HOOKUP_OBJECT_NO_REF (wnd
, wnd
, "omnplay_window");
518 gtk_window_set_title (GTK_WINDOW (wnd
), _("Omneon Player"));
519 gtk_window_set_default_size (GTK_WINDOW (wnd
), 1024, 768);
521 gtk_container_add (GTK_CONTAINER (wnd
),
524 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_BLOCK_BEGIN
] =
525 create_pixbuf("block_type_block_start_16x16.png");
526 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_BLOCK_BODY
] =
527 create_pixbuf("block_type_block_middle_16x16.png");
528 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_BLOCK_END
] =
529 create_pixbuf("block_type_block_end_16x16.png");
530 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE
] =
531 create_pixbuf("block_type_block_single_16x16.png");
532 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_LOOP_BEGIN
] =
533 create_pixbuf("block_type_loop_start_16x16.png");
534 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_LOOP_BODY
] =
535 create_pixbuf("block_type_loop_middle_16x16.png");
536 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_LOOP_END
] =
537 create_pixbuf("block_type_loop_end_16x16.png");
538 app
->playlist
.block_icons
[OMNPLAY_PLAYLIST_ITEM_LOOP_SINGLE
] =
539 create_pixbuf("block_type_block_loop_16x16.png");