add shortcut titles/processing
[melted_gui] / 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 (Insert)",
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 (E)",
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 (Del)",
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 (Ctrl-UP)",
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 (Ctrl-DOWN)",
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 (Ctrl-O)",
96 NULL,
97 NULL,
98 "button_playlist_load",
99 "Axialis_Team_playlist_open_16x16.png"
100 },
101 {
102 BUTTON_PLAYLIST_SAVE,
103 "Save playlist (Ctrl-S)",
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 (Enter)",
128 NULL,
129 NULL,
130 "button_playlist_cue",
131 "Axialis_Team_player_cue_32x32.png"
132 },
133 {
134 BUTTON_PLAYER_PLAY,
135 "Play (Space)",
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 (Enter)",
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 (F5)",
168 NULL,
169 NULL,
170 "button_library_refresh",
171 "Axialis_Team_library_refresh_16x16.png"
172 },
173 {
174 BUTTON_LIBRARY_FIND,
175 "Find item",
176 NULL,
177 NULL,
178 "button_library_find",
179 "Axialis_Team_search_in_library_16x16.png"
180 },
181 {
182 BUTTON_LIBRARY_FIND_NEXT,
183 "Find next item",
184 NULL,
185 NULL,
186 "button_library_find_next",
187 "Axialis_Team_search_next_16x16.png"
188 },
189
190 {
191 BUTTON_LAST,
192 }
193 };
194
195 GtkWidget* ui_create_button(GtkWidget* top, omnplay_instance_t* app, control_buttons_t id)
196 {
197 int idx;
198 GtkWidget *button, *alignment, *hbox, *image = NULL, *label;
199 const button_desc_t* info = NULL;
200
201 for(idx = 0; !info && buttons[idx].id != BUTTON_LAST; idx++)
202 if(buttons[idx].id == id)
203 info = &buttons[idx];
204
205 if(!info)
206 return NULL;
207
208 button = gtk_button_new();
209 gtk_widget_show(button);
210 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
211 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
212 gtk_button_set_relief(GTK_BUTTON (button), GTK_RELIEF_NONE);
213 if(info->tooltip)
214 gtk_widget_set_tooltip_text(button, info->tooltip);
215
216 alignment = gtk_alignment_new(0, 0.5, 0, 0);
217 gtk_widget_show(alignment);
218 gtk_container_add(GTK_CONTAINER (button), alignment);
219
220 hbox = gtk_hbox_new(FALSE, 2);
221 gtk_widget_show(hbox);
222 gtk_container_add(GTK_CONTAINER(alignment), hbox);
223
224 if(info->stock)
225 image = gtk_image_new_from_stock(info->stock, GTK_ICON_SIZE_MENU);
226 else if(info->filename)
227 image = gtk_image_new_from_pixbuf(create_pixbuf(info->filename));
228 if(image)
229 {
230 gtk_widget_show(image);
231 gtk_box_pack_start(GTK_BOX (hbox), image, FALSE, FALSE, 0);
232 }
233
234 label = gtk_label_new_with_mnemonic("");
235 if(info->label)
236 gtk_label_set_text(GTK_LABEL (label), info->label);
237 gtk_widget_show(label);
238 gtk_box_pack_start(GTK_BOX (hbox), label, FALSE, FALSE, 0);
239 gtk_label_set_justify(GTK_LABEL (label), GTK_JUSTIFY_LEFT);
240
241 if(info->hookup)
242 GLADE_HOOKUP_OBJECT (top, button, info->hookup);
243
244 app->buttons[id] = button;
245
246 return button;
247 }
248
249
250 #endif /* UI_BUTTONS_H */