File indexing completed on 2025-01-05 03:51:14

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2002-16-10
0007  * Description : main digiKam interface implementation - Import tools
0008  *
0009  * SPDX-FileCopyrightText: 2002-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "digikamapp_p.h"
0016 
0017 namespace Digikam
0018 {
0019 
0020 void DigikamApp::slotImportedImagefromScanner(const QUrl& url)
0021 {
0022     ScanController::instance()->scannedInfo(url.toLocalFile());
0023 }
0024 
0025 void DigikamApp::updateQuickImportAction()
0026 {
0027     d->quickImportMenu->clear();
0028 
0029     Q_FOREACH (QAction* const action, d->solidCameraActionGroup->actions())
0030     {
0031         d->quickImportMenu->addAction(action);
0032     }
0033 
0034     Q_FOREACH (QAction* const action, d->solidUsmActionGroup->actions())
0035     {
0036         d->quickImportMenu->addAction(action);
0037     }
0038 
0039     Q_FOREACH (QAction* const action, d->manualCameraActionGroup->actions())
0040     {
0041         d->quickImportMenu->addAction(action);
0042     }
0043 
0044     if (d->quickImportMenu->actions().isEmpty())
0045     {
0046         d->quickImportMenu->setEnabled(false);
0047     }
0048     else
0049     {
0050         disconnect(d->quickImportMenu->menuAction(), SIGNAL(triggered()), nullptr, nullptr);
0051 
0052         QAction*  primaryAction = nullptr;
0053         QDateTime latest;
0054 
0055         Q_FOREACH (QAction* const action, d->quickImportMenu->actions())
0056         {
0057             QDateTime appearanceTime = d->cameraAppearanceTimes.value(action->data().toString());
0058 
0059             if (latest.isNull() || (appearanceTime > latest))
0060             {
0061                 primaryAction = action;
0062                 latest        = appearanceTime;
0063             }
0064         }
0065 
0066         if (!primaryAction)
0067         {
0068             primaryAction = d->quickImportMenu->actions().constFirst();
0069         }
0070 
0071         connect(d->quickImportMenu->menuAction(), SIGNAL(triggered()),
0072                 primaryAction, SLOT(trigger()));
0073 
0074         d->quickImportMenu->setEnabled(true);
0075     }
0076 }
0077 
0078 void DigikamApp::slotImportAddImages()
0079 {
0080     QString startingPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
0081     QUrl url             = DFileDialog::getExistingDirectoryUrl(this, i18nc("@title:window", "Select Folder to Parse"),
0082                                                                 QUrl::fromLocalFile(startingPath));
0083 
0084     if (url.isEmpty() || !url.isLocalFile())
0085     {
0086         return;
0087     }
0088 
0089     // The folder contents will be parsed by Camera interface in "Directory Browse" mode.
0090 
0091     downloadFrom(url.toLocalFile());
0092 }
0093 
0094 void DigikamApp::slotImportAddFolders()
0095 {
0096     // NOTE: QFileDialog don't have an option to allow multiple selection of directories.
0097     // This work around is inspired from https://www.qtcentre.org/threads/34226-QFileDialog-select-multiple-directories
0098     // Check Later Qt 5.4 if a new native Qt way have been introduced.
0099 
0100     QPointer<DFileDialog> dlg = new DFileDialog(this);
0101     dlg->setWindowTitle(i18nc("@title:window", "Select Folders to Import into Album"));
0102     dlg->setFileMode(QFileDialog::Directory);
0103     dlg->setOptions(QFileDialog::ShowDirsOnly);
0104 
0105     QListView* const l = dlg->findChild<QListView*>(QLatin1String("listView"));
0106 
0107     if (l)
0108     {
0109         l->setSelectionMode(QAbstractItemView::MultiSelection);
0110     }
0111 
0112     QTreeView* const t = dlg->findChild<QTreeView*>();
0113 
0114     if (t)
0115     {
0116         t->setSelectionMode(QAbstractItemView::MultiSelection);
0117     }
0118 
0119     dlg->exec();
0120 
0121     if (!dlg->hasAcceptedUrls())
0122     {
0123         delete dlg;
0124         return;
0125     }
0126 
0127     QList<QUrl> urls = dlg->selectedUrls();
0128     delete dlg;
0129 
0130     QList<Album*> albumList = AlbumManager::instance()->currentAlbums();
0131     Album* album            = nullptr;
0132 
0133     if (!albumList.isEmpty())
0134     {
0135         album = albumList.first();
0136     }
0137 
0138     if (album && (album->type() != Album::PHYSICAL))
0139     {
0140         album = nullptr;
0141     }
0142 
0143     QString header(i18n("<p>Please select the destination album from the digiKam library to "
0144                         "import folders into.</p>"));
0145 
0146     album = AlbumSelectDialog::selectAlbum(this, static_cast<PAlbum*>(album), header);
0147 
0148     if (!album)
0149     {
0150         return;
0151     }
0152 
0153     PAlbum* const pAlbum = dynamic_cast<PAlbum*>(album);
0154 
0155     if (!pAlbum)
0156     {
0157         return;
0158     }
0159 
0160     QString albumRootPath = pAlbum->albumRootPath() + QLatin1Char('/');
0161 
0162     Q_FOREACH (const QUrl& url, urls)
0163     {
0164         QString destPath = url.toLocalFile() + QLatin1Char('/');
0165 
0166         if (albumRootPath.contains(destPath) ||
0167             destPath.contains(albumRootPath))
0168         {   // cppcheck-suppress useStlAlgorithm
0169             QMessageBox::warning(this, qApp->applicationName(),
0170                                  i18n("The folder %1 is part of the album "
0171                                       "path and cannot be imported recursively!",
0172                                       QDir::toNativeSeparators(url.toLocalFile())));
0173             return;
0174         }
0175     }
0176 
0177     DIO::copy(urls, pAlbum);
0178 }
0179 
0180 } // namespace Digikam