File indexing completed on 2024-05-12 12:20:51
0001 // SPDX-FileCopyrightText: 2021-2023 Tobias Leupold <tl at stonemx dot de> 0002 // 0003 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 0005 // Local includes 0006 #include "CopyLinkEngine.h" 0007 0008 // KDE includes 0009 #include <KIO/CopyJob> 0010 #include <KLocalizedString> 0011 0012 // Qt includes 0013 #include <QDebug> 0014 #include <QFileDialog> 0015 0016 namespace MainWindow 0017 { 0018 0019 CopyLinkEngine::CopyLinkEngine(QObject *parent) 0020 : QObject(parent) 0021 { 0022 } 0023 0024 void CopyLinkEngine::selectTarget(QWidget *parent, const QList<QUrl> &files, Action action) 0025 { 0026 const auto count = files.count(); 0027 if (count == 0) { 0028 return; 0029 } 0030 0031 if (m_lastTarget.isEmpty()) { 0032 m_lastTarget = files.first().adjusted(QUrl::RemoveFilename).path(); 0033 } 0034 0035 QString title; 0036 switch (action) { 0037 case Copy: 0038 title = i18ncp("@title:window", "Copy image to ...", "Copy images to ...", count); 0039 break; 0040 case Link: 0041 title = i18ncp("@title:window", "Link image to ...", "Link images to ...", count); 0042 break; 0043 } 0044 0045 const auto targetDirectory = QUrl::fromLocalFile(QFileDialog::getExistingDirectory(parent, title, m_lastTarget, QFileDialog::ShowDirsOnly)); 0046 0047 if (targetDirectory.isEmpty()) { 0048 return; 0049 } 0050 m_lastTarget = targetDirectory.path(); 0051 0052 KIO::CopyJob *job; 0053 switch (action) { 0054 case Copy: 0055 job = KIO::copy(files, targetDirectory); 0056 break; 0057 case Link: 0058 job = KIO::link(files, targetDirectory); 0059 break; 0060 } 0061 connect(job, &KIO::CopyJob::finished, job, &QObject::deleteLater); 0062 } 0063 0064 } 0065 0066 // vi:expandtab:tabstop=4 shiftwidth=4: 0067 0068 #include "moc_CopyLinkEngine.cpp"