commit 6151739914f757374115c1ae9c6b673c40a37c6e Author: phantomjinx <p.g.richard...@phantomjinx.co.uk> Date: Tue Feb 2 23:04:44 2010 +0000
Dialog threading - gtkpod_app_iface.* - anjuta-app.c Fixes warning and status bar message functions to display text correctly Playlist updated function reselects the given playlist and resets the playlist's tracks as the displayed list - playlist_display_actions.c - display_itbd.c Threading the add file and add directory dialogs. Dialogs disappear and UI is updated visibly. libgtkpod/gtkpod_app_iface.c | 24 ++++- libgtkpod/gtkpod_app_iface.h | 5 +- .../playlist_display/playlist_display_actions.c | 100 ++++++++++++-------- src/anjuta-app.c | 6 +- src/display_itdb.c | 3 + 5 files changed, 90 insertions(+), 48 deletions(-) --- diff --git a/libgtkpod/gtkpod_app_iface.c b/libgtkpod/gtkpod_app_iface.c index 1689ca2..1eb2abf 100644 --- a/libgtkpod/gtkpod_app_iface.c +++ b/libgtkpod/gtkpod_app_iface.c @@ -93,11 +93,14 @@ gchar* gtkpod_get_glade_xml() { void gtkpod_statusbar_message(gchar* message, ...) { g_return_if_fail (GTKPOD_IS_APP(gtkpod_app)); + gchar* msg; va_list args; va_start (args, message); - - GTKPOD_APP_GET_INTERFACE (gtkpod_app)->statusbar_message(gtkpod_app, message, args); + msg = g_strdup_vprintf(message, args); va_end (args); + + GTKPOD_APP_GET_INTERFACE (gtkpod_app)->statusbar_message(gtkpod_app, msg); + g_free(msg); } void gtkpod_tracks_statusbar_update(void) { @@ -121,11 +124,14 @@ void gtkpod_tracks_statusbar_update(void) { void gtkpod_warning(gchar* message, ...) { g_return_if_fail (GTKPOD_IS_APP(gtkpod_app)); + gchar* msg; va_list args; va_start (args, message); - - GTKPOD_APP_GET_INTERFACE (gtkpod_app)->gtkpod_warning(gtkpod_app, message, args); + msg = g_strdup_vprintf(message, args); va_end (args); + + GTKPOD_APP_GET_INTERFACE (gtkpod_app)->gtkpod_warning(gtkpod_app, msg); + g_free(msg); } void gtkpod_warning_simple(const gchar *format, ...) { @@ -194,6 +200,16 @@ void gtkpod_set_current_playlist(Playlist* playlist) { g_signal_emit(gtkpod_app, gtkpod_app_signals[PLAYLIST_SELECTED], 0, playlist); } +void gtkpod_playlist_updated(Playlist *playlist) { + g_return_if_fail (GTKPOD_IS_APP(gtkpod_app)); + g_return_if_fail (playlist); + + if (GTKPOD_APP_GET_INTERFACE (gtkpod_app)->current_playlist == playlist) { + g_signal_emit(gtkpod_app, gtkpod_app_signals[PLAYLIST_SELECTED], 0, playlist); + gtkpod_set_displayed_tracks(playlist->members); + } +} + GList *gtkpod_get_displayed_tracks() { g_return_val_if_fail (GTKPOD_IS_APP(gtkpod_app), NULL); GList *current_tracks = GTKPOD_APP_GET_INTERFACE (gtkpod_app)->displayed_tracks; diff --git a/libgtkpod/gtkpod_app_iface.h b/libgtkpod/gtkpod_app_iface.h index 7a352d6..aafc610 100644 --- a/libgtkpod/gtkpod_app_iface.h +++ b/libgtkpod/gtkpod_app_iface.h @@ -101,8 +101,8 @@ struct _GtkPodAppInterface { gchar *xml_file; void (*itdb_updated)(GtkPodApp *obj, iTunesDB *oldItdb, iTunesDB *newItbd); - void (*statusbar_message)(GtkPodApp *obj, gchar* message, ...); - void (*gtkpod_warning)(GtkPodApp *obj, gchar *message, ...); + void (*statusbar_message)(GtkPodApp *obj, gchar* message); + void (*gtkpod_warning)(GtkPodApp *obj, gchar *message); void (*gtkpod_warning_hig)(GtkPodApp *obj, GtkMessageType icon, const gchar *primary_text, const gchar *secondary_text); gint (*gtkpod_confirmation_hig)(GtkPodApp *obj, GtkMessageType icon, const gchar *primary_text, const gchar *secondary_text, const gchar *accept_button_text, const gchar *cancel_button_text, const gchar *third_button_text, const gchar *help_context); @@ -132,6 +132,7 @@ iTunesDB* gtkpod_get_current_itdb(); void gtkpod_set_current_itdb(iTunesDB* itdb); Playlist* gtkpod_get_current_playlist(); void gtkpod_set_current_playlist(Playlist* playlist); +void gtkpod_playlist_updated(Playlist *playlist); GList *gtkpod_get_displayed_tracks(); void gtkpod_set_displayed_tracks(GList *tracks); GList *gtkpod_get_selected_tracks(); diff --git a/plugins/playlist_display/playlist_display_actions.c b/plugins/playlist_display/playlist_display_actions.c index 4546c3a..bc5a1a3 100644 --- a/plugins/playlist_display/playlist_display_actions.c +++ b/plugins/playlist_display/playlist_display_actions.c @@ -40,6 +40,9 @@ #include "libgtkpod/misc_track.h" #include "libgtkpod/misc_playlist.h" #include "libgtkpod/gp_spl.h" +#include <gdk/gdk.h> + + /* Callback after directories to add have been selected */ static void add_selected_dirs(GSList *names, Playlist *db_active_pl) { @@ -53,11 +56,7 @@ static void add_selected_dirs(GSList *names, Playlist *db_active_pl) { for (currentnode = names; currentnode; currentnode = currentnode->next) { result &= add_directory_by_name(db_active_pl->itdb, currentnode->data, db_active_pl, prefs_get_int("add_recursively"), NULL, NULL); - g_free(currentnode->data); - gtkpod_tracks_statusbar_update(); } - g_slist_free(names); - names = NULL; /* clear log of non-updated tracks */ display_non_updated((void *) -1, NULL); @@ -73,6 +72,50 @@ static void add_selected_dirs(GSList *names, Playlist *db_active_pl) { } } +static gboolean add_selected_dirs_cb(gpointer data) { + GSList *names = data; + Playlist *pl = gtkpod_get_current_playlist(); + add_selected_dirs(names, pl); + + g_slist_foreach(names, (GFunc) g_free, NULL); + g_slist_free(names); + g_warning("add_selected_dir_cb: Finished!!"); + return FALSE; +} + +static void create_add_directories_dialog(Playlist *pl) { + GSList* names = NULL; /* List of selected items */ + GtkWidget *dialog; + + if (!pl) { + gtkpod_warning_simple(_("Please select a playlist or repository before adding tracks.")); + return; + } + + dialog + = gtk_file_chooser_dialog_new(_("Add Folder"), GTK_WINDOW (gtkpod_app), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT, NULL); + + /* Allow multiple selection of directories. */ + gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); + + /* Set same directory as the last browsed directory. */ + gchar *last_dir = prefs_get_string("last_dir_browsed"); + if (last_dir) { + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), last_dir); + g_free(last_dir); + } + + if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) + names = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER (dialog)); + + gtk_widget_destroy(dialog); + + if (names) { + prefs_set_string("last_dir_browsed", gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER (dialog))); + gdk_threads_add_idle((GSourceFunc) add_selected_dirs_cb, names); + } +} + /* OK Button */ static void fileselection_add_playlists(GSList* names, iTunesDB *itdb) { GSList* gsl; @@ -217,6 +260,16 @@ static void fileselection_add_files(GSList* names, Playlist *playlist) { // release_widgets(); } +static gboolean fileselection_add_files_cb(gpointer data) { + GSList *names = data; + Playlist *pl = gtkpod_get_current_playlist(); + fileselection_add_files(names, pl); + + g_slist_foreach(names, (GFunc) g_free, NULL); + g_slist_free(names); + return FALSE; +} + /* Open a modal file selection dialog for adding individual files */ static void create_add_files_dialog(Playlist *pl) { gchar *str; @@ -255,12 +308,10 @@ static void create_add_files_dialog(Playlist *pl) { g_free(str); if (!names) - return; + return; - fileselection_add_files(names, pl); - - g_slist_foreach(names, (GFunc) g_free, NULL); - g_slist_free(names); + // Let the dialog close first and add the tracks in the background + gdk_threads_add_idle((GSourceFunc) fileselection_add_files_cb, names); } void on_load_ipods_mi(GtkAction* action, PlaylistDisplayPlugin* plugin) { @@ -278,37 +329,8 @@ void on_create_add_files(GtkAction *action, PlaylistDisplayPlugin* plugin) { } void on_create_add_directory(GtkAction *action, PlaylistDisplayPlugin* plugin) { - GSList* names = NULL; /* List of selected items */ Playlist *pl = gtkpod_get_current_playlist(); - GtkWidget *dialog; - - if (!pl) { - gtkpod_warning_simple(_("Please select a playlist or repository before adding tracks.")); - return; - } - - dialog - = gtk_file_chooser_dialog_new(_("Add Folder"), GTK_WINDOW (gtkpod_app), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_ADD, GTK_RESPONSE_ACCEPT, NULL); - - /* Allow multiple selection of directories. */ - gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); - - /* Set same directory as the last browsed directory. */ - gchar *last_dir = prefs_get_string("last_dir_browsed"); - if (last_dir) { - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), last_dir); - g_free(last_dir); - } - - if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) - names = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER (dialog)); - - if (names) { - add_selected_dirs(names, pl); - prefs_set_string("last_dir_browsed", gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER (dialog))); - } - - gtk_widget_destroy(dialog); + create_add_directories_dialog(pl); } void on_create_add_playlists(GtkAction *action, PlaylistDisplayPlugin* plugin) { diff --git a/src/anjuta-app.c b/src/anjuta-app.c index 30c438d..e2f7324 100644 --- a/src/anjuta-app.c +++ b/src/anjuta-app.c @@ -897,13 +897,13 @@ static void anjuta_shell_iface_init(AnjutaShellIface *iface) { * -- GtkPodAppInterface implementations -- * ------------------------------------------------------------------------- */ -static void anjuta_gtkpod_app_statusbar_message(GtkPodApp *gtkpod_app, gchar* message, ...) { +static void anjuta_gtkpod_app_statusbar_message(GtkPodApp *gtkpod_app, gchar* message) { g_return_if_fail(ANJUTA_IS_APP(gtkpod_app)); AnjutaStatus *status = anjuta_shell_get_status(ANJUTA_SHELL(gtkpod_app), NULL); - anjuta_status_push(status, "%s", message); + anjuta_status_push(status, message); } -static void anjuta_gtkpod_app_warning(GtkPodApp *gtkpod_app, gchar *message, ...) { +static void anjuta_gtkpod_app_warning(GtkPodApp *gtkpod_app, gchar *message) { g_return_if_fail(GTK_IS_WINDOW(gtkpod_app)); anjuta_util_dialog_warning(GTK_WINDOW(gtkpod_app), message); } diff --git a/src/display_itdb.c b/src/display_itdb.c index 2926da9..45e1231 100644 --- a/src/display_itdb.c +++ b/src/display_itdb.c @@ -653,6 +653,9 @@ void gp_playlist_add_track(Playlist *pl, Track *track, gboolean display) { track->mark_unplayed = 0x02; } + if (display) + gtkpod_playlist_updated(pl); + data_changed(itdb); } ------------------------------------------------------------------------------ The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away. http://p.sf.net/sfu/theplanet-com _______________________________________________ gtkpod-cvs2 mailing list gtkpod-cvs2@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2