item update code added
[omnplay] / src / ui_buttons.c
1 /*
2 * ui_buttons.h -- 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 #ifndef UI_BUTTONS_H
21 #define UI_BUTTONS_H
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <stdio.h>
32
33 #include <gdk/gdkkeysyms.h>
34 #include <gtk/gtk.h>
35
36 #include "ui.h"
37 #include "ui_utils.h"
38 #include "ui_buttons.h"
39 #include "support.h"
40
41 typedef struct button_desc
42 {
43 control_buttons_t id;
44 char* tooltip;
45 char* stock;
46 char* label;
47 char* hookup;
48 char* filename;
49 } button_desc_t;
50
51 static const button_desc_t buttons[] =
52 {
53 {
54 BUTTON_PLAYLIST_ITEM_ADD,
55 "Add item to playlist",
56 NULL,
57 NULL,
58 "button_playlist_add",
59 "Axialis_Team_item_add_16x116.png"
60 },
61 {
62 BUTTON_PLAYLIST_ITEM_EDIT,
63 "Edit item in playlist",
64 NULL,
65 NULL,
66 "button_playlist_edit",
67 "Axialis_Team_item_edit_16x116.png"
68 },
69 {
70 BUTTON_PLAYLIST_ITEM_DEL,
71 "Delete item from playlist",
72 NULL,
73 NULL,
74 "button_playlist_del",
75 "Axialis_Team_item_delete_16x116.png"
76 },
77 {
78 BUTTON_PLAYLIST_ITEM_UP,
79 "Move item ebove",
80 NULL,
81 NULL,
82 "button_playlist_up",
83 "Axialis_Team_item_move_up_16x116.png"
84 },
85 {
86 BUTTON_PLAYLIST_ITEM_DOWN,
87 "Move item below",
88 NULL,
89 NULL,
90 "button_playlist_down",
91 "Axialis_Team_item_move_down_16x116.png"
92 },
93 {
94 BUTTON_PLAYLIST_LOAD,
95 "Load playlist",
96 NULL,
97 NULL,
98 "button_playlist_load",
99 "Axialis_Team_playlist_open_16x16.png"
100 },
101 {
102 BUTTON_PLAYLIST_SAVE,
103 "Save playlist",
104 NULL,
105 NULL,
106 "button_playlist_load",
107 "Axialis_Team_playlist_save_16x16.png"
108 },
109 {
110 BUTTON_PLAYLIST_BLOCK_LOOP,
111 "Make a loop block",
112 NULL,
113 NULL,
114 "button_playlist_block_loop",
115 "Axialis_Team_item_loop_16x116.png"
116 },
117 {
118 BUTTON_PLAYLIST_BLOCK_SINGLE,
119 "Make a single block",
120 NULL,
121 NULL,
122 "button_playlist_block_single",
123 "Axialis_Team_item_block_16x116.png"
124 },
125 {
126 BUTTON_PLAYER_CUE,
127 "Cue block",
128 NULL,
129 NULL,
130 "button_playlist_cue",
131 "Axialis_Team_player_cue_32x32.png"
132 },
133 {
134 BUTTON_PLAYER_PLAY,
135 "Play",
136 NULL,
137 NULL,
138 "button_playlist_play",
139 "Axialis_Team_player_play_64x32.png"
140 },
141 {
142 BUTTON_PLAYER_PAUSE,
143 "Pause",
144 NULL,
145 NULL,
146 "button_playlist_pause",
147 "Axialis_Team_player_pause_32x32.png"
148 },
149 {
150 BUTTON_PLAYER_STOP,
151 "STOP",
152 NULL,
153 NULL,
154 "button_playlist_stop",
155 "Axialis_Team_player_stop_32x32.png"
156 },
157 {
158 BUTTON_LIBRARY_ADD,
159 "Add to playlist",
160 NULL,
161 NULL,
162 "button_library_add",
163 "Axialis_Team_item_add_from_library_16x16.png"
164 },
165 {
166 BUTTON_LIBRARY_REFRESH,
167 "Refresh library",
168 NULL,
169 NULL,
170 "button_library_refresh",
171 "Axialis_Team_library_refresh_16x16.png"
172 },
173
174
175 {
176 BUTTON_LAST,
177 }
178 };
179
180 GtkWidget* ui_create_button(GtkWidget* top, omnplay_instance_t* app, control_buttons_t id)
181 {
182 int idx;
183 GtkWidget *button, *alignment, *hbox, *image = NULL, *label;
184 const button_desc_t* info = NULL;
185
186 for(idx = 0; !info && buttons[idx].id != BUTTON_LAST; idx++)
187 if(buttons[idx].id == id)
188 info = &buttons[idx];
189
190 if(!info)
191 return NULL;
192
193 button = gtk_button_new();
194 gtk_widget_show(button);
195 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
196 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
197 gtk_button_set_relief(GTK_BUTTON (button), GTK_RELIEF_NONE);
198 if(info->tooltip)
199 gtk_widget_set_tooltip_text(button, info->tooltip);
200
201 alignment = gtk_alignment_new(0, 0.5, 0, 0);
202 gtk_widget_show(alignment);
203 gtk_container_add(GTK_CONTAINER (button), alignment);
204
205 hbox = gtk_hbox_new(FALSE, 2);
206 gtk_widget_show(hbox);
207 gtk_container_add(GTK_CONTAINER(alignment), hbox);
208
209 if(info->stock)
210 image = gtk_image_new_from_stock(info->stock, GTK_ICON_SIZE_MENU);
211 else if(info->filename)
212 image = gtk_image_new_from_pixbuf(create_pixbuf(info->filename));
213 if(image)
214 {
215 gtk_widget_show(image);
216 gtk_box_pack_start(GTK_BOX (hbox), image, FALSE, FALSE, 0);
217 }
218
219 label = gtk_label_new_with_mnemonic("");
220 if(info->label)
221 gtk_label_set_text(GTK_LABEL (label), info->label);
222 gtk_widget_show(label);
223 gtk_box_pack_start(GTK_BOX (hbox), label, FALSE, FALSE, 0);
224 gtk_label_set_justify(GTK_LABEL (label), GTK_JUSTIFY_LEFT);
225
226 if(info->hookup)
227 GLADE_HOOKUP_OBJECT (top, button, info->hookup);
228
229 app->buttons[id] = button;
230
231 return button;
232 }
233
234
235 #endif /* UI_BUTTONS_H */