UI' basic canvases added
[omnplay] / src / ui.c
1 /*
2 * ui.c -- GTK+ 2 omnplay
3 * Copyright (C) 2011 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
30 #include <gdk/gdkkeysyms.h>
31 #include <gtk/gtk.h>
32
33 #include "ui.h"
34 #include "support.h"
35
36 #define GLADE_HOOKUP_OBJECT(component,widget,name) \
37 g_object_set_data_full (G_OBJECT (component), name, \
38 gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)
39
40 #define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
41 g_object_set_data (G_OBJECT (component), name, widget)
42
43 static GtkWidget* create_label(GtkWidget* top, char* text, char* reg, GtkJustification jtype)
44 {
45 GtkWidget* label;
46
47 label = gtk_label_new ("");
48 gtk_widget_show (label);
49
50 gtk_label_set_justify (GTK_LABEL (label), jtype);
51
52 if(reg)
53 GLADE_HOOKUP_OBJECT (top, label, reg);
54
55 if(text)
56 gtk_label_set_text(GTK_LABEL (label), text);
57
58 return label;
59 };
60
61 static GtkWidget* create_treeview(GtkWidget* top, char* name, const char* columns[])
62 {
63 int i;
64
65 GtkWidget *treeview;
66 GtkCellRenderer *renderer;
67 GtkTreeViewColumn *column;
68 GtkListStore *list_store;
69
70 treeview = gtk_tree_view_new ();
71 gtk_widget_show (treeview);
72
73 list_store = gtk_list_store_new(7,
74 G_TYPE_STRING,
75 G_TYPE_STRING,
76 G_TYPE_STRING,
77 G_TYPE_STRING,
78 G_TYPE_STRING,
79 G_TYPE_STRING,
80 G_TYPE_STRING);
81 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview ), GTK_TREE_MODEL( list_store ) );
82
83 for(i = 0; columns[i]; i++)
84 {
85 renderer = gtk_cell_renderer_toggle_new();
86 column = gtk_tree_view_column_new_with_attributes(
87 columns[i], renderer, "text", i, NULL);
88 gtk_tree_view_append_column(GTK_TREE_VIEW( treeview ), column);
89 };
90
91 GLADE_HOOKUP_OBJECT (top, treeview, name);
92
93 return treeview;
94 };
95
96 static GtkWidget* pane_library_grid(GtkWidget* top, omnplay_instance_t* app)
97 {
98 // static const char* columns[] = {"REM", "B", "CH", "ID", "IN", "DUR", "TITLE", NULL};
99 static const char* columns[] = {"ID", "DUR", "TITLE", NULL};
100 GtkWidget *scrolledwindow;
101
102 scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
103 gtk_widget_show (scrolledwindow);
104 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
105 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
106
107 gtk_container_add (GTK_CONTAINER (scrolledwindow),
108 create_treeview(top, "treeview_library", columns));
109
110 return scrolledwindow;
111 }
112
113 static GtkWidget* pane_library_buttons(GtkWidget* top, omnplay_instance_t* app)
114 {
115 GtkWidget* hbox;
116
117 hbox = gtk_vbox_new (FALSE, 0);
118 gtk_widget_show (hbox);
119
120 /* add buttons here: */
121 gtk_box_pack_start (GTK_BOX (hbox),
122 create_label(top, "BUTTONS HERE", NULL, GTK_JUSTIFY_LEFT),
123 FALSE, TRUE, 0);
124
125 return hbox;
126 }
127
128 static GtkWidget* pane_library(GtkWidget* top, omnplay_instance_t* app)
129 {
130 GtkWidget* vbox;
131
132 vbox = gtk_vbox_new (FALSE, 0);
133 gtk_widget_show (vbox);
134
135 /* add buttons box */
136 gtk_box_pack_start (GTK_BOX (vbox),
137 pane_library_buttons(top, app),
138 FALSE, FALSE, 0);
139
140 /* add buttons box */
141 gtk_box_pack_start (GTK_BOX (vbox),
142 pane_library_grid(top, app),
143 TRUE, TRUE, 0);
144
145 return vbox;
146 }
147
148 static GtkWidget* pane_operate_status(GtkWidget* top, omnplay_instance_t* app)
149 {
150 GtkWidget* frame;
151
152 frame = gtk_frame_new ("STATUS");
153 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
154 gtk_widget_show(frame);
155
156 gtk_container_add(GTK_CONTAINER(frame),
157 create_label(top, "status here", NULL, GTK_JUSTIFY_CENTER));
158
159 return frame;
160 }
161
162 static GtkWidget* pane_operate_operate(GtkWidget* top, omnplay_instance_t* app)
163 {
164 return create_label(top, "pane_operate", NULL, GTK_JUSTIFY_CENTER);
165 }
166
167 static GtkWidget* pane_operate(GtkWidget* top, omnplay_instance_t* app)
168 {
169 GtkWidget* hbox;
170
171 hbox = gtk_hbox_new (FALSE, 0);
172 gtk_widget_show (hbox);
173
174 /* add buttons box */
175 gtk_box_pack_start (GTK_BOX (hbox),
176 pane_operate_status(top, app),
177 FALSE, FALSE, 0);
178
179 /* add buttons box */
180 gtk_box_pack_start (GTK_BOX (hbox),
181 pane_operate_operate(top, app),
182 TRUE, TRUE, 0);
183
184 return hbox;
185
186 };
187
188 static GtkWidget* pane_top(GtkWidget* top, omnplay_instance_t* app)
189 {
190 GtkWidget* pane;
191
192 pane = gtk_hpaned_new ();
193 gtk_widget_show (pane);
194
195 gtk_paned_set_position (GTK_PANED (pane), 300);
196
197 gtk_paned_pack1 (GTK_PANED (pane),
198 pane_operate(top, app),
199 TRUE, FALSE);
200
201 gtk_paned_pack2 (GTK_PANED (pane),
202 pane_library(top, app),
203 FALSE, FALSE);
204
205 return pane;
206 }
207
208 GtkWidget* ui_omnplay (omnplay_instance_t* app)
209 {
210 GtkWidget *wnd;
211
212 wnd = gtk_window_new (GTK_WINDOW_TOPLEVEL);
213 GLADE_HOOKUP_OBJECT_NO_REF (wnd, wnd, "omnplay_window");
214
215 gtk_window_set_title (GTK_WINDOW (wnd), _("Omneon Player"));
216 gtk_window_set_default_size (GTK_WINDOW (wnd), 1024, 768);
217
218 gtk_container_add (GTK_CONTAINER (wnd),
219 pane_top(wnd, app));
220
221 return wnd;
222 }