mp3splt-gtk

- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

split_files_window.c
Go to the documentation of this file.
1 /**********************************************************
2 *
3 * mp3splt-gtk -- utility based on mp3splt,
4 * for mp3/ogg splitting without decoding
5 *
6 * Copyright: (C) 2005-2013 Alexandru Munteanu
7 * Contact: m@ioalex.net
8 *
9 * http://mp3splt.sourceforge.net/
10 *
11 *********************************************************/
12
13 /**********************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 * USA.
29 *
30 *********************************************************/
31
32 /*!********************************************************
33 * \file
34 * The split tab
35 *
36 * file that handles the split files tab from the main
37 * window
38 **********************************************************/
39
40 #include "split_files_window.h"
41
43 enum
44 {
45 COL_NAME,
46 COL_FILENAME,
47 SPLIT_COLUMNS
48 };
49
51 static GtkTreeModel *create_split_model()
52 {
53 GtkListStore *model = gtk_list_store_new(SPLIT_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
54 return GTK_TREE_MODEL(model);
55 }
56
58 static GtkTreeView *create_split_files_tree()
59 {
60 return GTK_TREE_VIEW(gtk_tree_view_new_with_model(create_split_model()));
61 }
62
64 static void create_split_columns(GtkTreeView *split_tree)
65 {
66 GtkCellRendererText *renderer = GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
67 g_object_set_data(G_OBJECT(renderer), "col", GINT_TO_POINTER(COL_NAME));
68 GtkTreeViewColumn *name_column = gtk_tree_view_column_new_with_attributes
69 (_("Filename"), GTK_CELL_RENDERER(renderer), "text", COL_NAME, NULL);
70
71 gtk_tree_view_insert_column(split_tree, GTK_TREE_VIEW_COLUMN(name_column), COL_NAME);
72
73 gtk_tree_view_column_set_alignment(GTK_TREE_VIEW_COLUMN(name_column), 0.5);
74 gtk_tree_view_column_set_sizing(GTK_TREE_VIEW_COLUMN(name_column),
75 GTK_TREE_VIEW_COLUMN_AUTOSIZE);
76 gtk_tree_view_column_set_resizable(name_column, TRUE);
77 }
78
80 void remove_all_split_rows(ui_state *ui)
81 {
82 GtkTreeModel *model = gtk_tree_view_get_model(ui->gui->split_tree);
83 GtkTreeIter iter;
84 while (gtk_tree_model_get_iter_first(model, &iter))
85 {
86 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
87 }
88 }
89
92 const gchar *get_real_name_from_filename(const gchar *filename)
93 {
94 const gchar *fname = filename;
95 while (strchr(fname, G_DIR_SEPARATOR) != NULL)
96 {
97 fname = strchr(fname, G_DIR_SEPARATOR) + 1;
98 }
99
100 return fname;
101 }
102
104 void add_split_row(const gchar *name, ui_state *ui)
105 {
106 GtkTreeIter iter;
107 GtkTreeModel *model = gtk_tree_view_get_model(ui->gui->split_tree);
108 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
109
110 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
111 COL_NAME, get_real_name_from_filename(name),
112 COL_FILENAME, name, -1);
113 }
114
116 gchar *get_filename_from_split_files(gint number, gui_state *gui)
117 {
118 gchar *filename = NULL;
119
120 GtkTreeModel *model = gtk_tree_view_get_model(gui->split_tree);
121 GtkTreePath *path = gtk_tree_path_new_from_indices(number-1 ,-1);
122
123 GtkTreeIter iter;
124 if (gtk_tree_model_get_iter(model, &iter, path))
125 {
126 gtk_tree_model_get(model, &iter, COL_FILENAME, &filename, -1);
127 }
128 gtk_tree_path_free(path);
129
130 return filename;
131 }
132
134 static void queue_files_button_event(GtkWidget *widget, ui_state *ui)
135 {
136 if (!ui->status->timer_active)
137 {
138 connect_button_event(ui->gui->connect_button, ui);
139 }
140
141 GList *file_list = NULL;
142 GtkTreeModel *model = gtk_tree_view_get_model(ui->gui->split_tree);
143
144 GtkTreeIter iter;
145
146 gboolean valid_row = gtk_tree_model_get_iter_first(model, &iter);
147 while (valid_row)
148 {
149 gchar *filename = NULL;
150 gtk_tree_model_get(model, &iter, COL_FILENAME, &filename, -1);
151 file_list = g_list_append(file_list, strdup(filename));
152 g_free(filename);
153
154 valid_row = gtk_tree_model_iter_next(model, &iter);
155 }
156
157 if (file_list != NULL)
158 {
159 player_add_files(file_list, ui);
160 }
161
162 g_list_foreach(file_list, (GFunc)g_free, NULL);
163 g_list_free(file_list);
164 }
165
167 static void remove_file_button_event(GtkWidget *widget, ui_state *ui)
168 {
169 GtkTreeIter iter;
170 GtkTreeModel *model = gtk_tree_view_get_model(ui->gui->split_tree);
171 GtkTreeSelection *selection = gtk_tree_view_get_selection(ui->gui->split_tree);
172 GList *selected_list = gtk_tree_selection_get_selected_rows(selection, &model);
173
174 while (g_list_length(selected_list) > 0)
175 {
176 GList *current_element = g_list_last(selected_list);
177 GtkTreePath *path = current_element->data;
178
179 gtk_tree_model_get_iter(model, &iter, path);
180
181 gchar *filename = NULL;
182 gtk_tree_model_get(model, &iter, COL_FILENAME, &filename, -1);
183 g_remove(filename);
184
185 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
186 selected_list = g_list_remove(selected_list, path);
187
188 gtk_tree_path_free(path);
189 g_free(filename);
190 }
191
192 if (!gtk_tree_model_get_iter_first(model, &iter))
193 {
194 gtk_widget_set_sensitive(ui->gui->queue_files_button, FALSE);
195 gtk_widget_set_sensitive(ui->gui->remove_all_files_button, FALSE);
196 }
197
198 gtk_widget_set_sensitive(ui->gui->remove_file_button,FALSE);
199
200 g_list_foreach(selected_list, (GFunc)gtk_tree_path_free, NULL);
201 g_list_free(selected_list);
202 }
203
205 static void remove_all_files_button_event(GtkWidget *widget, ui_state *ui)
206 {
207 GtkTreeModel *model = gtk_tree_view_get_model(ui->gui->split_tree);
208 GtkTreeIter iter;
209
210 while (gtk_tree_model_get_iter_first(model, &iter))
211 {
212 gchar *filename;
213 gtk_tree_model_get(model, &iter, COL_FILENAME, &filename, -1);
214 g_remove(filename);
215
216 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
217 g_free(filename);
218 }
219
220 gtk_widget_set_sensitive(ui->gui->remove_all_files_button,FALSE);
221 gtk_widget_set_sensitive(ui->gui->remove_file_button,FALSE);
222 gtk_widget_set_sensitive(ui->gui->queue_files_button,FALSE);
223 }
224
226 static void create_queue_buttons(ui_state *ui)
227 {
228 //button for queueing all files
229 GtkWidget *queue_files_button =
230 wh_create_cool_button(GTK_STOCK_INDEX, _("_Queue to player"),FALSE);
231 ui->gui->queue_files_button = queue_files_button;
232 gtk_widget_set_sensitive(queue_files_button, FALSE);
233 g_signal_connect(G_OBJECT(queue_files_button), "clicked",
234 G_CALLBACK(queue_files_button_event), ui);
235
236 //button for removing a file
237 GtkWidget *remove_file_button =
238 wh_create_cool_button(GTK_STOCK_DELETE, _("_Delete selected"), FALSE);
239 ui->gui->remove_file_button = remove_file_button;
240 gtk_widget_set_sensitive(remove_file_button, FALSE);
241 g_signal_connect(G_OBJECT(remove_file_button), "clicked",
242 G_CALLBACK(remove_file_button_event), ui);
243
244 //button for removing a file
245 GtkWidget *remove_all_files_button =
246 wh_create_cool_button(GTK_STOCK_DELETE, _("D_elete all"), FALSE);
247 ui->gui->remove_all_files_button = remove_all_files_button;
248 gtk_widget_set_sensitive(remove_all_files_button, FALSE);
249 g_signal_connect(G_OBJECT(remove_all_files_button), "clicked",
250 G_CALLBACK(remove_all_files_button_event), ui);
251 }
252
254 void split_tree_row_activated(GtkTreeView *split_tree, GtkTreePath *arg1,
255 GtkTreeViewColumn *arg2, ui_state *ui)
256 {
257 GtkTreeModel *model = gtk_tree_view_get_model(split_tree);
258 GtkTreeSelection *selection = gtk_tree_view_get_selection(split_tree);
259 GList *selected_list = gtk_tree_selection_get_selected_rows(selection, &model);
260
261 GList *current_element = g_list_first(selected_list);
262 GtkTreePath *path = current_element->data;
263
264 GtkTreeIter iter;
265 gtk_tree_model_get_iter(model, &iter, path);
266
267 gchar *filename = NULL;
268 gtk_tree_model_get(model, &iter, COL_FILENAME, &filename, -1);
269
270 connect_button_event(ui->gui->connect_button, ui);
271 change_current_filename(filename, ui);
272 connect_to_player_with_song(0, ui);
273
274 gtk_tree_path_free(path);
275 if (filename)
276 {
277 g_free(filename);
278 }
279 }
280
282 static void split_selection_changed(GtkTreeSelection *selec, ui_state *ui)
283 {
284 GtkTreeModel *model = gtk_tree_view_get_model(ui->gui->split_tree);
285 GtkTreeSelection *selection = gtk_tree_view_get_selection(ui->gui->split_tree);
286 GList *selected_list = gtk_tree_selection_get_selected_rows(selection, &model);
287 if (g_list_length(selected_list) > 0)
288 {
289 gtk_widget_set_sensitive(ui->gui->remove_file_button, TRUE);
290 }
291 else
292 {
293 gtk_widget_set_sensitive(ui->gui->remove_file_button, FALSE);
294 }
295 }
296
298 GtkWidget *create_split_files_frame(ui_state *ui)
299 {
300 GtkWidget *vbox = wh_vbox_new();
301
302 GtkTreeView *split_tree = create_split_files_tree();
303 ui->gui->split_tree = split_tree;
304 GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
305 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_NONE);
306 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
307 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
308 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
309 create_split_columns(split_tree);
310 gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(split_tree));
311 g_signal_connect(G_OBJECT(split_tree), "row-activated", G_CALLBACK(split_tree_row_activated), ui);
312
313 //selection for the tree
314 GtkTreeSelection *split_tree_selection = gtk_tree_view_get_selection(split_tree);
315 g_signal_connect(G_OBJECT(split_tree_selection), "changed",
316 G_CALLBACK(split_selection_changed), ui);
317 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(split_tree_selection), GTK_SELECTION_MULTIPLE);
318
319 create_queue_buttons(ui);
320
321 return vbox;
322 }
323
change_current_filename
void change_current_filename(const gchar *fname, ui_state *ui)
Change the name of the song that is to be cut and played.
Definition: player_window.c:265
connect_to_player_with_song
void connect_to_player_with_song(gint i, ui_state *ui)
connects to player with the song from the filename entry
Definition: player_window.c:531
get_filename_from_split_files
gchar * get_filename_from_split_files(gint number, gui_state *gui)
return the n_th filename from the split files
Definition: split_files_window.c:116
split_tree_row_activated
void split_tree_row_activated(GtkTreeView *split_tree, GtkTreePath *arg1, GtkTreeViewColumn *arg2, ui_state *ui)
Issued when a row is clicked on.
Definition: split_files_window.c:254
ui_state
Definition: ui_types.h:485
connect_button_event
void connect_button_event(GtkWidget *widget, ui_state *ui)
play button event
Definition: player_window.c:537
remove_all_split_rows
void remove_all_split_rows(ui_state *ui)
removes all rows from the split files table
Definition: split_files_window.c:80
create_split_files_frame
GtkWidget * create_split_files_frame(ui_state *ui)
creates the split files tab
Definition: split_files_window.c:298
gui_state
Definition: ui_types.h:202
player_add_files
void player_add_files(GList *list, ui_state *ui)
add files to playlist
Definition: player_control.c:166
add_split_row
void add_split_row(const gchar *name, ui_state *ui)
add a row to the table
Definition: split_files_window.c:104
wh_create_cool_button
GtkWidget * wh_create_cool_button(gchar *stock_id, gchar *label_text, gint toggle_or_not)
creates a cool button with image from stock
Definition: widgets_helper.c:348
get_real_name_from_filename
const gchar * get_real_name_from_filename(const gchar *filename)
finding the real name of the file, without the path
Definition: split_files_window.c:92