| 1753 | } |
| 1754 | |
| 1755 | static void |
| 1756 | source_dialog_start_scan (GtkFileChooser *chooser, int title_id) |
| 1757 | { |
| 1758 | gboolean recursive = FALSE; |
| 1759 | g_autoptr(GListModel) files = NULL; |
| 1760 | g_autofree char *def_src = NULL; |
| 1761 | signal_user_data_t *ud = ghb_ud(); |
| 1762 | |
| 1763 | if (gtk_file_chooser_get_action(chooser) == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) |
| 1764 | { |
| 1765 | // The recursive choice only exists in directory mode |
| 1766 | recursive = !g_strcmp0(gtk_file_chooser_get_choice(chooser, "recursive"), "true"); |
| 1767 | ghb_dict_set_bool(ud->prefs, "RecursiveFolderScan", recursive); |
| 1768 | ghb_pref_save(ud->prefs, "RecursiveFolderScan"); |
| 1769 | } |
| 1770 | else if (has_drive) |
| 1771 | { |
| 1772 | // The drive choice only exists in file mode when a DVD drive is detected |
| 1773 | const char *drivename = gtk_file_chooser_get_choice(chooser, "drive"); |
| 1774 | if (drivename && g_strcmp0(drivename, _("Not Selected"))) |
| 1775 | { |
| 1776 | files = G_LIST_MODEL(g_list_store_new(G_TYPE_FILE)); |
| 1777 | g_list_store_append(G_LIST_STORE(files), g_file_new_for_path(drivename)); |
| 1778 | def_src = g_strdup(drivename); |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | if (!def_src) |
| 1783 | { |
| 1784 | g_autoptr(GListModel) selected_files = gtk_file_chooser_get_files(chooser); |
| 1785 | |
| 1786 | if (g_list_model_get_n_items(selected_files)) |
| 1787 | { |
| 1788 | g_autoptr(GFile) file = g_list_model_get_item(selected_files, 0); |
| 1789 | def_src = g_file_get_path(file); |
| 1790 | } |
| 1791 | |
| 1792 | if (recursive) |
| 1793 | { |
| 1794 | // Scan the directories provided for files |
| 1795 | GListStore *out_files = g_list_store_new(G_TYPE_FILE); |
| 1796 | for (guint i = 0; i < g_list_model_get_n_items(selected_files); i++) |
| 1797 | { |
| 1798 | g_autoptr(GFile) dir = g_list_model_get_item(selected_files, i); |
| 1799 | scan_directory(dir, out_files, TRUE); |
| 1800 | } |
| 1801 | files = G_LIST_MODEL(out_files); |
| 1802 | ghb_log("Recursive scan found %u files", g_list_model_get_n_items(files)); |
| 1803 | } |
| 1804 | else |
| 1805 | { |
| 1806 | // Use the list of chosen files or folders directly |
| 1807 | files = g_steal_pointer(&selected_files); |
| 1808 | } |
| 1809 | } |
| 1810 | |
| 1811 | if (def_src != NULL && def_src[0] != '\0') |
| 1812 | { |
no test coverage detected