commit 53dce2a028dec9698a73e8ef6cf75bb49375b04e Author: phantomjinx <p.g.richard...@phantomjinx.co.uk> Date: Sun Jan 23 23:02:07 2011 +0000
Remove superfluous functions * fileselection.c * Left over and copied elsewhere * repository_editor.c * Only thing that uses functions so seems appropriate to move them out to plugin. libgtkpod/fileselection.c | 372 ------------------------- plugins/repository_editor/repository_editor.c | 91 ++++++ 2 files changed, 91 insertions(+), 372 deletions(-) --- diff --git a/libgtkpod/fileselection.c b/libgtkpod/fileselection.c index f7bc243..56c0927 100644 --- a/libgtkpod/fileselection.c +++ b/libgtkpod/fileselection.c @@ -51,220 +51,6 @@ #include "misc_track.h" #include "fileselection.h" -/* Open a modal file selection dialog with multiple selction enabled */ -GSList* fileselection_get_files(const gchar *title) { - GtkWidget* fc; /* The file chooser dialog */ - gint response; /* The response of the filechooser */ - gchar *last_dir, *new_dir; - GSList * files = NULL; - - fc - = gtk_file_chooser_dialog_new(title, NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); - - /* allow multiple selection of files */ - gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER (fc), TRUE); - - /* set same directory as last time */ - last_dir = prefs_get_string("last_dir_browsed"); - if (last_dir) { - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (fc), last_dir); - g_free(last_dir); - } - - /* Run the dialog */ - response = gtk_dialog_run(GTK_DIALOG(fc)); - - /* Handle the response */ - switch (response) { - case GTK_RESPONSE_ACCEPT: - new_dir = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER (fc)); - prefs_set_string("last_dir_browsed", new_dir); - g_free(new_dir); - files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER (fc)); - break; - case GTK_RESPONSE_CANCEL: - break; - default: /* Fall through */ - break; - } - gtk_widget_destroy(fc); - - return files; -} - -static void fileselection_add_files(GSList* names, Playlist *playlist) { - GSList* gsl; /* Current node in list */ - gboolean result = TRUE; /* Result of file adding */ - - /* If we don't have a playlist to add to, don't add anything */ - g_return_if_fail (playlist); - - block_widgets(); - - /* Get the filenames and add them */ - for (gsl = names; gsl; gsl = gsl->next) { - result - &= add_track_by_filename(playlist->itdb, gsl->data, playlist, prefs_get_int("add_recursively"), NULL, NULL); - } - - /* clear log of non-updated tracks */ - display_non_updated((void *) -1, NULL); - - /* display log of updated tracks */ - display_updated(NULL, NULL); - - /* display log of detected duplicates */ - gp_duplicate_remove(NULL, NULL); - - /* Were all files successfully added? */ - if (result == TRUE) - gtkpod_statusbar_message(_("Successfully added files")); - else - gtkpod_statusbar_message(_("Some files were not added successfully")); - - release_widgets(); -} - -/* - * Add Files Dialog - */ -/* ATTENTION: directly used as callback in gtkpod.glade -- if you - change the arguments of this function make sure you define a - separate callback for gtkpod.glade */ -G_MODULE_EXPORT void create_add_files_callback(void) { - Playlist *pl; - - pl = gtkpod_get_current_playlist(); - - create_add_files_dialog(pl); -} - -/* Open a modal file selection dialog for adding individual files */ -void create_add_files_dialog(Playlist *pl) { - gchar *str; - GSList *names; - iTunesDB *itdb; - ExtraiTunesDBData *eitdb; - Playlist *mpl; - - if (!pl) { - gtkpod_warning_simple(_("Please select a playlist or repository before adding tracks.")); - return; - } - - itdb = pl->itdb; - g_return_if_fail (itdb); - eitdb = itdb->userdata; - g_return_if_fail (eitdb); - - if (!eitdb->itdb_imported) { - gtkpod_warning_simple(_("Please load the iPod before adding tracks.")); - return; - } - - mpl = itdb_playlist_mpl(itdb); - g_return_if_fail (mpl); - - /* Create window title */ - if (mpl == pl) { - str = g_strdup_printf(_("Add files to '%s'"), mpl->name); - } - else { - str = g_strdup_printf(_("Add files to '%s/%s'"), mpl->name, pl->name); - } - - names = fileselection_get_files(str); - g_free(str); - - if (!names) - return; - - fileselection_add_files(names, pl); - - g_slist_foreach(names, (GFunc) g_free, NULL); - g_slist_free(names); -} - -/* OK Button */ -static void fileselection_add_playlists(GSList* names, iTunesDB *itdb) { - GSList* gsl; - - /* Get the names of the playlist(s) and add them */ - - g_return_if_fail (itdb); - - block_widgets(); - - for (gsl = names; gsl; gsl = gsl->next) { - add_playlist_by_filename(itdb, gsl->data, NULL, -1, NULL, NULL); - } - - release_widgets(); - - /* clear log of non-updated tracks */ - display_non_updated((void *) -1, NULL); - - /* display log of updated tracks */ - display_updated(NULL, NULL); - - /* display log of detected duplicates */ - gp_duplicate_remove(NULL, NULL); - - gtkpod_tracks_statusbar_update(); -} - -/* - * Add Playlist Dialog - */ -/* ATTENTION: directly used as callback in gtkpod.glade -- if you - change the arguments of this function make sure you define a - separate callback for gtkpod.glade */ -G_MODULE_EXPORT void create_add_playlists_callback(void) { - iTunesDB *itdb; - - itdb = gp_get_selected_itdb(); - - create_add_playlists_dialog(itdb); -} - -/* Open a modal file selection dialog for adding playlist files */ -void create_add_playlists_dialog(iTunesDB *itdb) { - gchar *str; - GSList *names; - ExtraiTunesDBData *eitdb; - Playlist *mpl; - - if (!itdb) { - gtkpod_warning_simple(_("Please select a playlist or repository before adding tracks.")); - return; - } - - eitdb = itdb->userdata; - g_return_if_fail (eitdb); - - if (!eitdb->itdb_imported) { - gtkpod_warning_simple(_("Please load the iPod before adding tracks.")); - return; - } - - mpl = itdb_playlist_mpl(itdb); - g_return_if_fail (mpl); - - /* Create window title */ - str = g_strdup_printf(_("Add playlist files to '%s'"), mpl->name); - - names = fileselection_get_files(str); - g_free(str); - - if (!names) - return; - - fileselection_add_playlists(names, itdb); - - g_slist_foreach(names, (GFunc) g_free, NULL); - g_slist_free(names); -} - /* * Add Cover Art */ @@ -379,162 +165,4 @@ gchar *fileselection_get_file_or_dir(const gchar *title, const gchar *cur_file, return new_file; } -/* BY JCS */ - -/* Used by the prefs system (prefs_windows.c, repository.c) when a - * script should be selected. Takes into account that command line - * arguments can be present - * - * @opath: the current path to the script including command line - * arguments. May be NULL. - * @fallback: default dir in case @opath is not set. - * @title: title of the file selection window. - * @additional_text: additional explanotary text to be displayed - * - * Return value: The new script including command line arguments. NULL - * if the selection was aborted. - */ -gchar *fileselection_select_script(const gchar *opath, const gchar *fallback, const gchar *title, const gchar *additional_text) { - gchar *npath = NULL; - gchar *buf, *fbuf; - const gchar *opathp; - GtkFileChooser *fc; - gint response; /* The response of the filechooser */ - - fc = GTK_FILE_CHOOSER (gtk_file_chooser_dialog_new ( - title, - NULL, - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, - NULL)); - - /* find first whitespace separating path from command line - * arguments */ - - if (opath) - opathp = strchr(opath, ' '); - else - opathp = NULL; - - if (opathp) - buf = g_strndup(opath, opathp - opath); - else - buf = g_strdup(opath); - - /* get full path -- if the file cannot be found it can't be - * selected in the filechooser */ - if (buf) { - fbuf = g_find_program_in_path(buf); - g_free(buf); - } - else { - fbuf = NULL; - } - - if (!fbuf) { /* set default */ - fbuf = g_strdup(fallback); - } - - if (fbuf && *fbuf) { - gchar *fbuf_utf8 = g_filename_from_utf8(fbuf, -1, NULL, NULL, NULL); - if (g_file_test(fbuf, G_FILE_TEST_IS_DIR)) { - gtk_file_chooser_set_current_folder(fc, fbuf_utf8); - } - else { - gtk_file_chooser_set_filename(fc, fbuf_utf8); - } - g_free(fbuf_utf8); - } - g_free(fbuf); - - response = gtk_dialog_run(GTK_DIALOG(fc)); - - switch (response) { - case GTK_RESPONSE_ACCEPT: - buf = gtk_file_chooser_get_filename(fc); - /* attach command line arguments if present */ - if (opathp) - npath = g_strdup_printf("%s%s", buf, opathp); - else - npath = g_strdup(buf); - g_free(buf); - break; - case GTK_RESPONSE_CANCEL: - break; - default: /* Fall through */ - break; - } - gtk_widget_destroy(GTK_WIDGET (fc)); - - return npath; -} - -/* Callback after directories to add have been selected */ -static void add_selected_dirs(GSList *names, Playlist *db_active_pl) { - gboolean result = TRUE; - - g_return_if_fail (names); - g_return_if_fail (db_active_pl); - - if (names) { - GSList* currentnode; - 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); - /* display log of updated tracks */ - display_updated(NULL, NULL); - /* display log of detected duplicates */ - gp_duplicate_remove(NULL, NULL); - - if (result == TRUE) - gtkpod_statusbar_message(_("Successfully added files")); - else - gtkpod_statusbar_message(_("Some files were not added successfully")); - } -} - -/* ATTENTION: directly used as callback in gtkpod.glade -- if you - change the arguments of this function make sure you define a - separate callback for gtkpod.glade */ -G_MODULE_EXPORT void dirbrowser_create_callback(void) { - 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); -} diff --git a/plugins/repository_editor/repository_editor.c b/plugins/repository_editor/repository_editor.c index 43a7ae8..6a7ab55 100644 --- a/plugins/repository_editor/repository_editor.c +++ b/plugins/repository_editor/repository_editor.c @@ -257,6 +257,97 @@ static gint get_current_prefs_int(const gchar *key) { return value; } +/* BY JCS */ + +/* Used by the prefs system (prefs_windows.c, repository.c) when a + * script should be selected. Takes into account that command line + * arguments can be present + * + * @opath: the current path to the script including command line + * arguments. May be NULL. + * @fallback: default dir in case @opath is not set. + * @title: title of the file selection window. + * @additional_text: additional explanotary text to be displayed + * + * Return value: The new script including command line arguments. NULL + * if the selection was aborted. + */ +gchar *fileselection_select_script(const gchar *opath, const gchar *fallback, const gchar *title, const gchar *additional_text) { + gchar *npath = NULL; + gchar *buf, *fbuf; + const gchar *opathp; + GtkFileChooser *fc; + gint response; /* The response of the filechooser */ + + fc = GTK_FILE_CHOOSER (gtk_file_chooser_dialog_new ( + title, + NULL, + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + NULL)); + + /* find first whitespace separating path from command line + * arguments */ + + if (opath) + opathp = strchr(opath, ' '); + else + opathp = NULL; + + if (opathp) + buf = g_strndup(opath, opathp - opath); + else + buf = g_strdup(opath); + + /* get full path -- if the file cannot be found it can't be + * selected in the filechooser */ + if (buf) { + fbuf = g_find_program_in_path(buf); + g_free(buf); + } + else { + fbuf = NULL; + } + + if (!fbuf) { /* set default */ + fbuf = g_strdup(fallback); + } + + if (fbuf && *fbuf) { + gchar *fbuf_utf8 = g_filename_from_utf8(fbuf, -1, NULL, NULL, NULL); + if (g_file_test(fbuf, G_FILE_TEST_IS_DIR)) { + gtk_file_chooser_set_current_folder(fc, fbuf_utf8); + } + else { + gtk_file_chooser_set_filename(fc, fbuf_utf8); + } + g_free(fbuf_utf8); + } + g_free(fbuf); + + response = gtk_dialog_run(GTK_DIALOG(fc)); + + switch (response) { + case GTK_RESPONSE_ACCEPT: + buf = gtk_file_chooser_get_filename(fc); + /* attach command line arguments if present */ + if (opathp) + npath = g_strdup_printf("%s%s", buf, opathp); + else + npath = g_strdup(buf); + g_free(buf); + break; + case GTK_RESPONSE_CANCEL: + break; + default: /* Fall through */ + break; + } + gtk_widget_destroy(GTK_WIDGET (fc)); + + return npath; +} + /* Render apply insensitive when no changes were made. When an itdb is marked for deletion, make entries insensitive */ static void update_buttons() { ------------------------------------------------------------------------------ Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d _______________________________________________ gtkpod-cvs2 mailing list gtkpod-cvs2@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2