comparison src/streambrowser/gui/streambrowser_win.c @ 2889:6c53f9fa9029

Backed out changeset 59ff744e1e23
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 12 Aug 2008 20:29:49 +0300
parents e883536cefe0
children 113454baecf8
comparison
equal deleted inserted replaced
2856:59ff744e1e23 2889:6c53f9fa9029
17 GtkWidget* tree_view; 17 GtkWidget* tree_view;
18 18
19 } streamdir_gui_t; 19 } streamdir_gui_t;
20 20
21 21
22 void (* update_function) (streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo); 22 void (* update_function) (streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo, gboolean add_to_playlist);
23 23
24 static GtkWidget* gtk_label_new_with_icon(gchar *icon_filename, gchar *label_text); 24 static GtkWidget* gtk_label_new_with_icon(gchar *icon_filename, gchar *label_text);
25 static GtkWidget* gtk_streamdir_tree_view_new(); 25 static GtkWidget* gtk_streamdir_tree_view_new();
26 static GtkWidget* gtk_streamdir_table_new(GtkWidget *tree_view); 26 static GtkWidget* gtk_streamdir_table_new(GtkWidget *tree_view);
27 27
31 static gboolean on_search_entry_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data); 31 static gboolean on_search_entry_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data);
32 static gboolean on_tree_view_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data); 32 static gboolean on_tree_view_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data);
33 static gboolean on_tree_view_button_pressed(GtkWidget *widget, GdkEventButton *event, gpointer data); 33 static gboolean on_tree_view_button_pressed(GtkWidget *widget, GdkEventButton *event, gpointer data);
34 34
35 static streamdir_gui_t* find_streamdir_gui_by_name(gchar *name); 35 static streamdir_gui_t* find_streamdir_gui_by_name(gchar *name);
36 static streamdir_gui_t* find_streamdir_gui_by_tree_view(GtkTreeView *tree_view); 36 //static streamdir_gui_t* find_streamdir_gui_by_tree_view(GtkTreeView *tree_view); todo: remove this
37 static streamdir_gui_t* find_streamdir_gui_by_table(GtkTable *table); 37 static streamdir_gui_t* find_streamdir_gui_by_table(GtkTable *table);
38 static streamdir_gui_t* find_streamdir_gui_by_streamdir(streamdir_t *streamdir); 38 static streamdir_gui_t* find_streamdir_gui_by_streamdir(streamdir_t *streamdir);
39 static gboolean tree_view_search_equal_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer data); 39 static gboolean tree_view_search_equal_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer data);
40 40
41 static GtkWidget* notebook; 41 static GtkWidget* notebook;
43 static GtkWidget* add_button; 43 static GtkWidget* add_button;
44 static GtkWidget* streambrowser_window; 44 static GtkWidget* streambrowser_window;
45 static GList* streamdir_gui_list; 45 static GList* streamdir_gui_list;
46 static GtkCellRenderer* cell_renderer_pixbuf; 46 static GtkCellRenderer* cell_renderer_pixbuf;
47 static GtkCellRenderer* cell_renderer_text; 47 static GtkCellRenderer* cell_renderer_text;
48
49 static gboolean tree_view_button_pressed = FALSE;
50
48 51
49 52
50 void streambrowser_win_init() 53 void streambrowser_win_init()
51 { 54 {
52 /* notebook */ 55 /* notebook */
184 streaminfo_t *streaminfo; 187 streaminfo_t *streaminfo;
185 for (i = 0; i < count; i++) { 188 for (i = 0; i < count; i++) {
186 streaminfo = streaminfo_get_by_index(category, i); 189 streaminfo = streaminfo_get_by_index(category, i);
187 190
188 gtk_tree_store_append(store, &new_iter, &iter); 191 gtk_tree_store_append(store, &new_iter, &iter);
189 gtk_tree_store_set(store, &new_iter, 0, "gtk-directory", 1, streaminfo->name, 2, streaminfo->current_track, -1); 192 gtk_tree_store_set(store, &new_iter, 0, "gtk-media-play", 1, streaminfo->name, 2, streaminfo->current_track, -1);
190 } 193 }
191 194
192 gtk_tree_path_free(path); 195 gtk_tree_path_free(path);
193 } 196 }
194 197
195 void streambrowser_win_set_update_function(void (*function) (streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo)) 198 void streambrowser_win_set_streaminfo(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo)
199 {
200 streamdir_gui_t *streamdir_gui = find_streamdir_gui_by_name(streamdir->name);
201 if (streamdir_gui == NULL) {
202 failure("gui: streambrowser_win_set_category() called with non-existent streamdir\n");
203 return;
204 }
205
206 GtkTreeView *tree_view = GTK_TREE_VIEW(streamdir_gui->tree_view);
207 GtkTreeStore *store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)));
208 GtkTreePath *path;
209 GtkTreeIter iter, new_iter;
210
211 /* find the corresponding streaminfo tree iter */
212 path = gtk_tree_path_new_from_indices(category_get_index(streamdir, category), streaminfo_get_index(category, streaminfo), -1);
213 if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path))
214 return;
215
216 /* update the streaminfo*/
217 gtk_tree_store_set(store, &new_iter, 0, "gtk-media-play", 1, streaminfo->name, 2, streaminfo->current_track, -1);
218
219 gtk_tree_path_free(path);
220 }
221
222 void streambrowser_win_set_update_function(void (*function) (streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo, gboolean add_to_playlist))
196 { 223 {
197 update_function = function; 224 update_function = function;
198 } 225 }
199 226
200 void streambrowser_win_set_category_state(streamdir_t *streamdir, category_t *category, gboolean fetching) 227 void streambrowser_win_set_category_state(streamdir_t *streamdir, category_t *category, gboolean fetching)
238 sprintf(temp, "<span style='italic' weight='heavy'>%s</span>", streaminfo->name); 265 sprintf(temp, "<span style='italic' weight='heavy'>%s</span>", streaminfo->name);
239 266
240 gtk_tree_store_set(store, &iter, 0, "gtk-refresh", 1, temp, 2, streaminfo->current_track, -1); 267 gtk_tree_store_set(store, &iter, 0, "gtk-refresh", 1, temp, 2, streaminfo->current_track, -1);
241 } 268 }
242 else { 269 else {
243 gtk_tree_store_set(store, &iter, 0, "gtk-directory", 1, streaminfo->name, 2, streaminfo->current_track, -1); 270 gtk_tree_store_set(store, &iter, 0, "gtk-media-play", 1, streaminfo->name, 2, streaminfo->current_track, -1);
244 } 271 }
245 } 272 }
246 273
247 static GtkWidget* gtk_label_new_with_icon(gchar *icon_filename, gchar *label_text) 274 static GtkWidget* gtk_label_new_with_icon(gchar *icon_filename, gchar *label_text)
248 { 275 {
328 gtk_entry_set_text(GTK_ENTRY(search_entry), ""); 355 gtk_entry_set_text(GTK_ENTRY(search_entry), "");
329 356
330 return TRUE; 357 return TRUE;
331 } 358 }
332 359
360
333 static gboolean on_tree_view_cursor_changed(GtkTreeView *tree_view, gpointer data) 361 static gboolean on_tree_view_cursor_changed(GtkTreeView *tree_view, gpointer data)
334 { 362 {
363 /* only do the refresh if this cursor change occured due to a mouse click */
364 if (!tree_view_button_pressed)
365 return FALSE;
366
367 tree_view_button_pressed = FALSE;
368
335 GtkTreePath *path; 369 GtkTreePath *path;
336 GtkTreeIter iter; 370 GtkTreeViewColumn *focus_column;
337 GtkTreeModel *model; 371
338 372 /* get the currently selected tree view */
339 /* obtain the current category */ 373 GtkWidget *table = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
340 gtk_tree_view_get_cursor(tree_view, &path, NULL); 374 streamdir_gui_t *streamdir_gui = find_streamdir_gui_by_table(GTK_TABLE(table));
341 375 if (streamdir_gui == NULL)
342 if (path == NULL) 376 return FALSE;
343 return TRUE; 377
344 378 /* get the currently selected path in the tree */
379 gtk_tree_view_get_cursor(tree_view, &path, &focus_column);
380
381 if (path == NULL || gtk_tree_path_get_depth(path) == 0)
382 return FALSE;
383
345 gint *indices = gtk_tree_path_get_indices(path); 384 gint *indices = gtk_tree_path_get_indices(path);
346 if (gtk_tree_path_get_depth(path) != 1) { 385 int category_index = indices[0];
386 streamdir_t *streamdir = streamdir_gui->streamdir;
387 category_t *category = category_get_by_index(streamdir_gui->streamdir, category_index);
388
389 /* if the selected item is a category */
390 if (gtk_tree_path_get_depth(path) == 1) {
391 if (!gtk_tree_view_row_expanded(tree_view, path)) {
392 gtk_entry_set_text(GTK_ENTRY(search_entry), "");
393 update_function(streamdir, category, NULL, FALSE);
394 }
395
347 gtk_tree_path_free(path); 396 gtk_tree_path_free(path);
348 return TRUE; 397 }
349 } 398 /* if the selected item is a streaminfo */
350 399 else {
351 model = gtk_tree_view_get_model(tree_view); 400 int streaminfo_index = indices[1];
352 gtk_tree_model_get_iter(model, &iter, path); 401
353
354 /* don't fetch a category that has been already fetched */
355 if (gtk_tree_model_iter_has_child(model, &iter)) {
356 gtk_tree_path_free(path); 402 gtk_tree_path_free(path);
357 return TRUE; 403
358 } 404 /* get the currently selected stream (info) */
359 405 streaminfo_t *streaminfo = streaminfo_get_by_index(category, streaminfo_index);
360 int category_index = indices[0]; 406
361 407 gtk_entry_set_text(GTK_ENTRY(search_entry), "");
362 gtk_tree_path_free(path); 408 update_function(streamdir, category, streaminfo, FALSE);
363 409 }
364 streamdir_gui_t *streamdir_gui = find_streamdir_gui_by_tree_view(tree_view); 410
365 if (streamdir_gui == NULL) 411 return FALSE;
366 return TRUE;
367
368 /* issue an update on the current category */
369 update_function(streamdir_gui->streamdir, category_get_by_index(streamdir_gui->streamdir, category_index), NULL);
370
371 return TRUE;
372 } 412 }
373 413
374 static gboolean on_tree_view_button_pressed(GtkWidget *widget, GdkEventButton *event, gpointer data) 414 static gboolean on_tree_view_button_pressed(GtkWidget *widget, GdkEventButton *event, gpointer data)
375 { 415 {
376 /* double click adds the currently selected stream to the playlist */ 416 /* double click adds the currently selected stream to the playlist */
377 if (event->type == GDK_2BUTTON_PRESS) { 417 if (event->type == GDK_2BUTTON_PRESS) {
418 tree_view_button_pressed = FALSE;
378 on_add_button_clicked(NULL, NULL); 419 on_add_button_clicked(NULL, NULL);
379 } 420 }
421 /* single click triggers a refresh of the selected item */
422 else {
423 // todo: separate single from double click somehow
424 tree_view_button_pressed = TRUE;
425 }
380 426
381 return FALSE; 427 return FALSE;
382 } 428 }
383 429
384 static gboolean on_add_button_clicked(GtkButton *button, gpointer data) 430 static gboolean on_add_button_clicked(GtkButton *button, gpointer data)
385 { 431 {
386 GtkTreePath *path; 432 GtkTreePath *path;
387 GtkTreeViewColumn *focus_column; 433 GtkTreeViewColumn *focus_column;
388 434
435 /* get the currently selected tree view */
389 GtkWidget *table = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook))); 436 GtkWidget *table = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
390 streamdir_gui_t *streamdir_gui = find_streamdir_gui_by_table(GTK_TABLE(table)); 437 streamdir_gui_t *streamdir_gui = find_streamdir_gui_by_table(GTK_TABLE(table));
391 if (streamdir_gui == NULL) 438 if (streamdir_gui == NULL)
392 return TRUE; 439 return TRUE;
393 440
394 GtkTreeView *tree_view = GTK_TREE_VIEW(streamdir_gui->tree_view); 441 GtkTreeView *tree_view = GTK_TREE_VIEW(streamdir_gui->tree_view);
395 442
443 /* get the currently selected path in the tree */
396 gtk_tree_view_get_cursor(tree_view, &path, &focus_column); 444 gtk_tree_view_get_cursor(tree_view, &path, &focus_column);
397 445
398 if (path == NULL) 446 if (path == NULL)
399 return TRUE; 447 return TRUE;
400 448
412 int category_index = indices[0]; 460 int category_index = indices[0];
413 int streaminfo_index = indices[1]; 461 int streaminfo_index = indices[1];
414 462
415 gtk_tree_path_free(path); 463 gtk_tree_path_free(path);
416 464
465 /* get the currently selected stream (info) */
417 streamdir_t *streamdir = streamdir_gui->streamdir; 466 streamdir_t *streamdir = streamdir_gui->streamdir;
418 category_t *category = category_get_by_index(streamdir_gui->streamdir, category_index); 467 category_t *category = category_get_by_index(streamdir_gui->streamdir, category_index);
419 streaminfo_t *streaminfo = streaminfo_get_by_index(category, streaminfo_index); 468 streaminfo_t *streaminfo = streaminfo_get_by_index(category, streaminfo_index);
420 469
421 gtk_entry_set_text(GTK_ENTRY(search_entry), ""); 470 gtk_entry_set_text(GTK_ENTRY(search_entry), "");
422 update_function(streamdir, category, streaminfo); 471 update_function(streamdir, category, streaminfo, TRUE);
423 472
424 return TRUE; 473 return TRUE;
425 } 474 }
426 475
427 static gboolean on_search_entry_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data) 476 static gboolean on_search_entry_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
468 } 517 }
469 518
470 return NULL; 519 return NULL;
471 } 520 }
472 521
522 /* todo: remove this
473 static streamdir_gui_t *find_streamdir_gui_by_tree_view(GtkTreeView *tree_view) 523 static streamdir_gui_t *find_streamdir_gui_by_tree_view(GtkTreeView *tree_view)
474 { 524 {
475 GList *iterator; 525 GList *iterator;
476 streamdir_gui_t *streamdir_gui; 526 streamdir_gui_t *streamdir_gui;
477 527
482 return streamdir_gui; 532 return streamdir_gui;
483 } 533 }
484 534
485 return NULL; 535 return NULL;
486 } 536 }
537 */
487 538
488 static streamdir_gui_t *find_streamdir_gui_by_table(GtkTable *table) 539 static streamdir_gui_t *find_streamdir_gui_by_table(GtkTable *table)
489 { 540 {
490 GList *iterator; 541 GList *iterator;
491 streamdir_gui_t *streamdir_gui; 542 streamdir_gui_t *streamdir_gui;