diff --git a/CMakeLists.txt b/CMakeLists.txt index 95c01c49..3f821906 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,333 +1,333 @@ cmake_minimum_required(VERSION 3.0) # KDE Application Version, managed by release script set(KDE_APPLICATIONS_VERSION_MAJOR "19") set(KDE_APPLICATIONS_VERSION_MINOR "07") set(KDE_APPLICATIONS_VERSION_MICRO "70") set(KDE_APPLICATIONS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATIONS_VERSION_MINOR}.${KDE_APPLICATIONS_VERSION_MICRO}") project(kget VERSION ${KDE_APPLICATIONS_VERSION}) -set(KF5_VERSION "5.44.0") +set(KF5_VERSION "5.55.0") set(REQUIRED_QT_VERSION "5.7.0") find_package(ECM ${KF5_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} "${CMAKE_SOURCE_DIR}/cmake") find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED CONFIG COMPONENTS DBus Gui Network Sql Test Widgets Xml) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(ECMInstallIcons) include(ECMMarkAsTest) include(GenerateExportHeader) include(ECMQtDeclareLoggingCategory) include(ECMSetupVersion) ecm_setup_version(PROJECT VARIABLE_PREFIX KGET VERSION_HEADER "kget_version.h") find_package(KF5 ${KF5_VERSION} REQUIRED Completion Config ConfigWidgets CoreAddons Crash DBusAddons DocTools I18n IconThemes ItemViews KCMUtils KIO Notifications NotifyConfig Parts Service TextWidgets Wallet WidgetsAddons WindowSystem XmlGui KDELibs4Support # KLocale ) #include(CheckIncludeFile) #include(CheckIncludeFiles) #include(CheckSymbolExists) #include(CheckFunctionExists) #include(CheckLibraryExists) #include(CheckPrototypeExists) #include(CheckTypeSize) #set(CMAKE_REQUIRED_DEFINITIONS ${_KDE4_PLATFORM_DEFINITIONS}) if(WIN32) set(CMAKE_REQUIRED_LIBRARIES ${KDEWIN32_LIBRARIES}) set(CMAKE_REQUIRED_INCLUDES ${KDEWIN32_INCLUDES}) endif(WIN32) #add_definitions(${QT_DEFINITIONS} ${QT_QTDBUS_DEFINITIONS} ${KDE4_DEFINITIONS}) #add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH}) find_package(Sqlite QUIET) set_package_properties(SQLITE_FOUND PROPERTIES DESCRIPTION "SQLite is a Binary-Database" TYPE RECOMMENDED PURPOSE "Needed for the SQLite-Backend of the KGet-History") find_package(Qca-qt5 2.1.0) set_package_properties(Qca PROPERTIES DESCRIPTION "Support for encryption" URL "http://delta.affinix.com/qca" TYPE REQUIRED) find_package(Gpgmepp 1.7.0) set_package_properties(Gpgmepp_FOUND PROPERTIES DESCRIPTION "The GpgME++ library" URL "http://www.gnupg.org" TYPE RECOMMENDED PURPOSE "GpgME++ is required to have signature verifying support in KGet.") find_package(KF5Torrent 2.1) set_package_properties(KF5Torrent_FOUND PROPERTIES DESCRIPTION "Backend Library of KTorrent" TYPE RECOMMENDED PURPOSE "Needed to build KGet bittorrent support.") find_package(LibMms QUIET) set_package_properties(LIBMMS_FOUND PROPERTIES DESCRIPTION "Library to read mms streams" TYPE RECOMMENDED PURPOSE "Needed to build KGet mms support.") set(kget_adaptor_SRCS dbus/dbuskgetwrapper.cpp ) # set(kget_transfer_adaptor_SRCS # core/transferhandler.cpp # core/transfertreemodel.cpp # ) #add_definitions(-DKDE_DEFAULT_DEBUG_AREA=5001) //TODO: PORT THIS!! if(CMAKE_BUILD_TYPE MATCHES debugfull) add_definitions(-DDEBUG) endif(CMAKE_BUILD_TYPE MATCHES debugfull) if (Qca-qt5_FOUND) add_definitions(-DHAVE_QCA2) MESSAGE(STATUS "QCA found") endif() find_package(Boost REQUIRED) if(Gpgmepp_FOUND) find_package(QGpgme REQUIRED) add_definitions(-DHAVE_QGPGME) endif() set (KGET_PLUGIN_INSTALL_DIR ${PLUGIN_INSTALL_DIR}/kget) add_subdirectory(conf) add_subdirectory(core) add_subdirectory(ui) add_subdirectory(transfer-plugins) add_subdirectory(extensions) add_subdirectory(sounds) add_subdirectory(desktop) #add_subdirectory(plasma) TODO PORT TO KF5/QML add_subdirectory(tests) add_subdirectory(doc) find_package(LibKWorkspace CONFIG) set_package_properties(LibKWorkspace PROPERTIES TYPE OPTIONAL PURPOSE "Allows 'shutdown after downloads completed' in kget") if(LibKWorkspace_FOUND) add_definitions(-DHAVE_KWORKSPACE) endif() include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/core/ ${CMAKE_CURRENT_BINARY_DIR}/core/ ${CMAKE_CURRENT_BINARY_DIR} ) if(SQLITE_FOUND) add_definitions(-DHAVE_SQLITE) endif(SQLITE_FOUND) remove_definitions(-DQT_NO_HTTP) # kgetcore set(kgetcore_SRCS core/job.cpp core/jobqueue.cpp core/kget.cpp core/scheduler.cpp core/transfertreemodel.cpp core/transfertreeselectionmodel.cpp core/transfer.cpp core/transfergroup.cpp core/transfergrouphandler.cpp core/transferhandler.cpp core/handler.cpp core/transfergroupscheduler.cpp core/plugin/plugin.cpp core/plugin/transferfactory.cpp core/transferdatasource.cpp core/datasourcefactory.cpp core/kgetkjobadapter.cpp core/kuiserverjobs.cpp core/kgetglobaljob.cpp core/bitset.cpp core/download.cpp core/transferhistorystore.cpp core/transferhistorystore_xml.cpp core/transferhistorystore_sqlite.cpp core/linkimporter.cpp dbus/dbustransferwrapper.cpp dbus/dbusverifierwrapper.cpp core/filemodel.cpp core/verifier.cpp core/verificationthread.cpp core/verificationmodel.cpp core/verificationdelegate.cpp core/signature.cpp core/signaturethread.cpp core/keydownloader.cpp core/urlchecker.cpp core/basedialog.cpp core/mostlocalurl.cpp core/filedeleter.cpp ) ecm_qt_declare_logging_category(kgetcore_SRCS HEADER kget_debug.h IDENTIFIER KGET_DEBUG CATEGORY_NAME kget) kconfig_add_kcfg_files(kgetcore_SRCS conf/settings.kcfgc) qt5_add_dbus_adaptor(kgetcore_SRCS dbus/org.kde.kget.transfer.xml dbus/dbustransferwrapper.h DBusTransferWrapper) qt5_add_dbus_adaptor(kgetcore_SRCS dbus/org.kde.kget.verifier.xml dbus/dbusverifierwrapper.h DBusVerifierWrapper) add_library(kgetcore SHARED ${kgetcore_SRCS}) generate_export_header(kgetcore BASE_NAME kget) target_link_libraries(kgetcore Qt5::Core Qt5::Widgets Qt5::Sql Qt5::Network Qt5::DBus KF5::ConfigGui KF5::CoreAddons KF5::DBusAddons KF5::I18n KF5::IconThemes KF5::KIOCore KF5::KIOWidgets KF5::Notifications KF5::Service KF5::XmlGui) if(LibKWorkspace_FOUND) target_link_libraries(kgetcore PW::KWorkspace) endif() if (SQLITE_FOUND) target_link_libraries(kgetcore ${QT_QTSQL_LIBRARY}) endif (SQLITE_FOUND) if (Qca-qt5_FOUND) target_link_libraries(kgetcore qca-qt5) endif () if (Gpgmepp_FOUND) target_link_libraries(kgetcore QGpgme Gpgmepp) kde_enable_exceptions() endif() set_target_properties(kgetcore PROPERTIES VERSION 5.0.0 SOVERSION 5 ) install(TARGETS kgetcore ${INSTALL_TARGETS_DEFAULT_ARGS}) # kget set(kget_SRCS ${kget_adaptor_SRCS} ${kget_transfer_adaptor_SRCS} kget_debug.cpp conf/autopastemodel.cpp conf/integrationpreferences.cpp conf/dlgwebinterface.cpp conf/preferencesdialog.cpp conf/transfersgrouptree.cpp conf/transfersgroupwidget.cpp conf/pluginselector.cpp conf/verificationpreferences.cpp ui/droptarget.cpp ui/transfersview.cpp ui/transfersviewdelegate.cpp ui/transferdetails.cpp ui/viewscontainer.cpp ui/newtransferdialog.cpp ui/groupsettingsdialog.cpp ui/transfersettingsdialog.cpp ui/contextmenu.cpp ui/tray.cpp ui/history/rangetreewidget.cpp ui/history/transferhistory.cpp ui/history/transferhistoryitemdelegate.cpp ui/history/transferhistorycategorizeddelegate.cpp ui/history/transferhistorycategorizedview.cpp ui/linkview/kget_linkview.cpp ui/linkview/kget_sortfilterproxymodel.cpp ui/mirror/mirrorsettings.cpp ui/mirror/mirrormodel.cpp ui/renamefile.cpp ui/verificationdialog.cpp ui/metalinkcreator/metalinkcreator.cpp ui/metalinkcreator/generalwidget.cpp ui/metalinkcreator/metalinker.cpp ui/metalinkcreator/filedlg.cpp ui/metalinkcreator/localemodels.cpp ui/metalinkcreator/dragdlg.cpp ui/metalinkcreator/urlwidget.cpp ui/metalinkcreator/filehandler.cpp ui/signaturedlg.cpp mainwindow.cpp main.cpp #extensions/webinterface/httpserver.cpp ) qt5_add_dbus_adaptor(kget_SRCS dbus/org.kde.kget.main.xml dbus/dbuskgetwrapper.h DBusKGetWrapper) ki18n_wrap_ui(kget_SRCS conf/dlgadvanced.ui conf/dlgappearance.ui conf/dlggroups.ui conf/dlgintegration.ui conf/dlgwebinterface.ui conf/dlgnetwork.ui conf/verificationpreferences.ui ui/transferdetailsfrm.ui ui/newtransferwidget.ui ui/history/transferhistory.ui ui/groupsettingsdialog.ui ui/transfersettingsdialog.ui ui/linkview/importlinkdialog.ui ui/mirror/mirrorsettings.ui ui/mirror/mirroradddlg.ui ui/renamefile.ui ui/verificationdialog.ui ui/verificationadddlg.ui ui/metalinkcreator/introduction.ui ui/metalinkcreator/generalwidget.ui ui/metalinkcreator/files.ui ui/metalinkcreator/filedlg.ui ui/metalinkcreator/dragdlg.ui ui/metalinkcreator/urlwidget.ui ui/metalinkcreator/commondata.ui ui/signaturedlg.ui ) #kde4_add_app_icon(kget_SRCS "ui/icons/hi*-apps-kget.png") add_executable(kget ${kget_SRCS}) target_link_libraries(kget Qt5::Core Qt5::Widgets Qt5::Sql Qt5::Network Qt5::DBus KF5::Crash KF5::Wallet KF5::DBusAddons KF5::I18n KF5::Completion KF5::CoreAddons KF5::IconThemes KF5::ItemViews KF5::KCMUtils KF5::NotifyConfig KF5::WindowSystem KF5::KDELibs4Support kgetcore) if(Qca_FOUND) target_link_libraries(kget qca) endif() if(CMAKE_BUILD_TYPE MATCHES debugfull) target_link_libraries(kget Qt5::Test) endif() if (QGpgme_FOUND) target_link_libraries(kget QGpgme) endif() install(TARGETS kget ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES kget.categories DESTINATION ${KDE_INSTALL_CONFDIR}) install(FILES org.kde.kget.appdata.xml DESTINATION ${CMAKE_INSTALL_METAINFODIR}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/ui/metalinkcreator/localemodels.cpp b/ui/metalinkcreator/localemodels.cpp index 93918f17..c6960971 100644 --- a/ui/metalinkcreator/localemodels.cpp +++ b/ui/metalinkcreator/localemodels.cpp @@ -1,153 +1,152 @@ /*************************************************************************** * Copyright (C) 2009 Matthias Fuchs * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "localemodels.h" +#include #include + #include #include CountryModel::CountryModel(QObject *parent) : QAbstractListModel(parent) { } QVariant CountryModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } if (role == Qt::DisplayRole) { return m_countryNames.value(index.row()); } else if (role == Qt::DecorationRole) { return m_countryIcons.value(index.row()); } else if (role == Qt::UserRole) { return m_countryCodes.value(index.row()); } return QVariant(); } int CountryModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) { return 0; } return m_countryCodes.count(); } void CountryModel::setupModelData() { - for (int c = 1; c <= QLocale::LastCountry; c++) { + for (int c = 1; c <= QLocale::LastCountry; ++c) + { QString countryCode; const auto country = static_cast(c); QLocale locale(QLocale::AnyLanguage, country); - if (locale.country() == country) { + if (locale.country() == country) + { const QString localeName = locale.name(); const auto idx = localeName.indexOf(QLatin1Char('_')); - if (idx != -1) { + if (idx != -1) + { countryCode = localeName.mid(idx + 1); } } const QString countryName = KLocale::global()->countryCodeToName(countryCode); if (!countryName.isEmpty()) { m_countryCodes.append(countryCode); m_countryNames.append(countryName); QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("locale/") + QString::fromLatin1("l10n/%1/flag.png").arg(countryCode)); if (path.isEmpty()) { m_countryIcons.append(QIcon()); } else { m_countryIcons.append(QIcon::fromTheme(path)); } } } reset(); } LanguageModel::LanguageModel(QObject *parent) : QAbstractListModel(parent) { } QVariant LanguageModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } - - if (role == Qt::DisplayRole) + else if (role == Qt::DisplayRole) { return m_languageNames.value(index.row()); } - else if (role == Qt::UserRole) - { - return m_languageCodes.value(index.row()); - } return QVariant(); } int LanguageModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) { return 0; } - return m_languageCodes.count(); + return m_languageNames.count(); } -void LanguageModel::setupModelData(const QStringList &languageCodes) +void LanguageModel::setupModelData() { - for (const QString &languageCode : languageCodes) + for (int l = 1; l <= QLocale::LastLanguage; ++l) { - //no KDE-custom language-codes - if (languageCode.contains('@')) - { - continue; - } - - QString languageName = KLocale::global()->languageCodeToName(languageCode); - if (!languageName.isEmpty()) + const auto lang = static_cast(l); + QLocale locale(lang); + if (locale.language() == lang) { - m_languageCodes.append(languageCode); - m_languageNames.append(languageName); + const QString localeName = locale.name(); + const QString languageName = KLanguageName::nameForCode(localeName); + if (!languageName.isEmpty()) + { + m_languageNames.append(languageName); + } } } reset(); } diff --git a/ui/metalinkcreator/localemodels.h b/ui/metalinkcreator/localemodels.h index 8736afd2..2a259da4 100644 --- a/ui/metalinkcreator/localemodels.h +++ b/ui/metalinkcreator/localemodels.h @@ -1,73 +1,73 @@ /*************************************************************************** * Copyright (C) 2009 Matthias Fuchs * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef LOCALEMODELS_H #define LOCALEMODELS_H #include #include /** * The following models are there to store the localized names and the codes of languages and countries * Only codes supported by KDE are supported by these models */ /** * The CountryModel stores localized names as well as the codes and the corresponding icons of countries */ class CountryModel : public QAbstractListModel { Q_OBJECT public: CountryModel(QObject *parent = nullptr); int rowCount (const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; void setupModelData(); private: QStringList m_countryCodes; QStringList m_countryNames; QList m_countryIcons; }; /** * The LanguageModel stores localized names as well as the codes of languages */ class LanguageModel : public QAbstractListModel { Q_OBJECT public: LanguageModel(QObject *parent = nullptr); int rowCount (const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - void setupModelData(const QStringList &languageCodes); + void setupModelData(); private: QStringList m_languageCodes; QStringList m_languageNames; }; #endif diff --git a/ui/metalinkcreator/metalinkcreator.cpp b/ui/metalinkcreator/metalinkcreator.cpp index e23c0791..46bcabd6 100644 --- a/ui/metalinkcreator/metalinkcreator.cpp +++ b/ui/metalinkcreator/metalinkcreator.cpp @@ -1,397 +1,396 @@ /*************************************************************************** * Copyright (C) 2009 Matthias Fuchs * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "metalinkcreator.h" #include "filedlg.h" #include "dragdlg.h" #include "localemodels.h" #include "generalwidget.h" #include #include #include #include #include #include #include -#include #include #include //TODO for 4.4 look at the changes of the newest Draft --> what elements have to be added/removed FileWidget::FileWidget(QWidget *parent) : QWidget(parent) { setAcceptDrops(true); } void FileWidget::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasUrls()) { event->acceptProposedAction(); } } void FileWidget::dropEvent(QDropEvent *event) { QList urls = event->mimeData()->urls(); event->acceptProposedAction(); if (!urls.isEmpty()) { emit urlsDropped(urls); } } MetalinkCreator::MetalinkCreator(QWidget *parent) : KAssistantDialog(parent), m_needUrlCount(0), m_countrySort(nullptr), m_languageModel(nullptr), m_languageSort(nullptr), m_introduction(nullptr), m_generalPage(nullptr), m_filesModel(nullptr) { create(); connect(finishButton(), &QPushButton::clicked, this, &MetalinkCreator::slotSave); connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), this, SLOT(slotUpdateAssistantButtons(KPageWidgetItem*,KPageWidgetItem*))); qRegisterMetaType("KGetMetalink::File"); connect(&m_thread, SIGNAL(fileResult(KGetMetalink::File)), this, SLOT(slotAddFile(KGetMetalink::File))); connect(&m_thread, SIGNAL(finished()), this, SLOT(slotThreadFinished())); setWindowTitle(i18n("Create a Metalink")); } MetalinkCreator::~MetalinkCreator() { } void MetalinkCreator::slotUpdateAssistantButtons(KPageWidgetItem *to, KPageWidgetItem *from) { //once we leave the introduction page the data is being loaded if (m_introduction && m_generalPage && (from == m_introduction) && (to == m_generalPage)) { load(); } //it is impossible to return to the introduction page backButton()->setEnabled(to != m_generalPage); if (!m_filesModel->rowCount()) { uiFiles.infoWidget->setText(i18n("Add at least one file.")); } else if (m_needUrlCount) { uiFiles.infoWidget->setText(i18n("You need to set mirrors for the entries with an icon.")); } uiFiles.infoWidget->setVisible(!m_filesModel->rowCount() || m_needUrlCount); //only enable finish when the metalink is valid (i.e. no required data missing) //and the thread is not running finishButton()->setEnabled(metalink.isValid() && !m_thread.isRunning()); } void MetalinkCreator::create() { createIntroduction(); m_general = new GeneralWidget(this); m_generalPage = addPage(m_general, i18n("General optional information for the metalink.")); QTimer::singleShot(0, this, &MetalinkCreator::slotDelayedCreation); } void MetalinkCreator::slotDelayedCreation() { CountryModel *countryModel = new CountryModel(this); countryModel->setupModelData(); m_countrySort = new QSortFilterProxyModel(this); m_countrySort->setSourceModel(countryModel); m_countrySort->setSortLocaleAware(true); m_countrySort->sort(0); m_languageModel = new LanguageModel(this); - m_languageModel->setupModelData(KLocale::global()->allLanguagesList()); + m_languageModel->setupModelData(); m_languageSort = new QSortFilterProxyModel(this); m_languageSort->setSourceModel(m_languageModel); m_languageSort->setSortLocaleAware(true); m_languageSort->sort(0); createFiles(); slotUpdateIntroductionNextButton(); } void MetalinkCreator::load() { QUrl url = uiIntroduction.load->url(); if (uiIntroduction.loadButton->isChecked() && url.isValid()) { if (!KGetMetalink::HandleMetalink::load(url, &metalink)) { KMessageBox::error(this, i18n("Unable to load: %1", url.toString()), i18n("Error")); } } m_general->load(metalink); loadFiles(); } void MetalinkCreator::slotSave() { m_general->save(&metalink); QUrl url = uiIntroduction.save->url(); if (url.isValid()) { if(!KGetMetalink::HandleMetalink::save(url, &metalink)) { KMessageBox::error(this, i18n("Unable to save to: %1", url.toString()), i18n("Error")); } } } void MetalinkCreator::createIntroduction() { QWidget *widget = new QWidget(this); uiIntroduction.setupUi(widget); uiIntroduction.save->setFilter("*.meta4|" + i18n("Metalink Version 4.0 file (*.meta4)") + "\n*.metalink|" + i18n("Metalink Version 3.0 file (*.metalink)")); uiIntroduction.save->setAcceptMode(QFileDialog::AcceptSave); connect(uiIntroduction.save, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateIntroductionNextButton())); connect(uiIntroduction.load, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateIntroductionNextButton())); connect(uiIntroduction.loadButton, SIGNAL(toggled(bool)), this, SLOT(slotUpdateIntroductionNextButton())); m_introduction = addPage(widget, i18n("Define the saving location.")); setValid(m_introduction, false); } void MetalinkCreator::slotUpdateIntroductionNextButton() { bool enableNext = false; //check if a save location and if selected if also a load location has been specified and if the m_countrySort has been created enableNext = uiIntroduction.save->url().isValid() && m_countrySort; if (enableNext && uiIntroduction.loadButton->isChecked()) { enableNext = uiIntroduction.load->url().isValid(); } setValid(m_introduction, enableNext); } void MetalinkCreator::createFiles() { m_handler = new DirectoryHandler(this); connect(m_handler, SIGNAL(finished()), this, SLOT(slotOpenDragDlg())); FileWidget *widget = new FileWidget(this); uiFiles.setupUi(widget); m_filesModel = new QStandardItemModel(0, 1, this); uiFiles.files->setModel(m_filesModel); uiFiles.infoWidget->setCloseButtonVisible(false); uiFiles.infoWidget->setMessageType(KMessageWidget::Information); uiFiles.add_local_file->setIcon(QIcon::fromTheme("list-add")); KGuiItem::assign(uiFiles.add_file, KStandardGuiItem::add()); KGuiItem::assign(uiFiles.properties_file, KStandardGuiItem::properties()); uiFiles.properties_file->setEnabled(false); KGuiItem::assign(uiFiles.remove_file, KStandardGuiItem::remove()); uiFiles.remove_file->setEnabled(false); uiFiles.dragDrop->hide(); connect(uiFiles.add_local_file, SIGNAL(clicked(bool)), this, SLOT(slotAddLocalFilesClicked())); connect(uiFiles.add_file, SIGNAL(clicked(bool)), this, SLOT(slotAddClicked())); connect(uiFiles.remove_file, SIGNAL(clicked(bool)), this, SLOT(slotRemoveFile())); connect(uiFiles.properties_file, SIGNAL(clicked(bool)), this, SLOT(slotFileProperties())); connect(uiFiles.files->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotUpdateFilesButtons())); connect(widget, SIGNAL(urlsDropped(QList)), m_handler, SLOT(slotFiles(QList))); addPage(widget, i18nc("file as in file on hard drive", "Files")); } void MetalinkCreator::loadFiles() { foreach (const KGetMetalink::File &file, metalink.files.files) { QStandardItem *item = new QStandardItem(file.name); if (!file.resources.isValid()) { ++m_needUrlCount; item->setIcon(QIcon::fromTheme("edit-delete")); } m_filesModel->insertRow(m_filesModel->rowCount(), item); } } void MetalinkCreator::slotUpdateFilesButtons() { const QModelIndexList indexes = uiFiles.files->selectionModel()->selectedRows(); uiFiles.remove_file->setEnabled(indexes.count()); bool propertiesEnabled = (indexes.count() == 1); uiFiles.properties_file->setEnabled(propertiesEnabled); } void MetalinkCreator::slotAddLocalFilesClicked() { QPointer dialog = new QFileDialog(this); dialog->setFileMode(QFileDialog::ExistingFiles); if (dialog->exec() == QDialog::Accepted) { m_handler->slotFiles(dialog->selectedUrls()); } delete dialog; } void MetalinkCreator::slotAddFile() { QStandardItem *item = new QStandardItem(m_tempFile.name); m_filesModel->insertRow(m_filesModel->rowCount(), item); metalink.files.files.append(m_tempFile); m_tempFile.clear(); slotUpdateAssistantButtons(nullptr, m_files); } void MetalinkCreator::slotAddFile(const KGetMetalink::File &file) { QStandardItem *item = new QStandardItem(file.name); if (!file.resources.isValid()) { ++m_needUrlCount; item->setIcon(QIcon::fromTheme("edit-delete")); } m_filesModel->insertRow(m_filesModel->rowCount(), item); metalink.files.files.append(file); slotUpdateAssistantButtons(nullptr, m_files); } void MetalinkCreator::slotFileEdited(const QString &oldFileName, const QString &newFileName) { Q_UNUSED(oldFileName) const QModelIndex index = uiFiles.files->selectionModel()->selectedRows().first(); QStandardItem *item = m_filesModel->itemFromIndex(index); item->setText(newFileName); //had no url but has it now if (!item->icon().isNull()) { --m_needUrlCount; item->setIcon(QIcon()); } slotUpdateAssistantButtons(nullptr, m_files); } void MetalinkCreator::slotRemoveFile() { while (uiFiles.files->selectionModel()->hasSelection()) { const QModelIndex index = uiFiles.files->selectionModel()->selectedRows().first(); const QString filePath = index.data().toString(); for (int i = 0; i < metalink.files.files.size(); ++i) { if (metalink.files.files.at(i).name == filePath) { //the entry had not url, so do not count it anymore if (!index.data(Qt::DecorationRole).isNull()) { --m_needUrlCount; } metalink.files.files.removeAt(i); break; } } m_filesModel->removeRow(index.row()); } slotUpdateFilesButtons(); slotUpdateAssistantButtons(nullptr, m_files); } void MetalinkCreator::slotAddClicked() { //no old stored data should be used m_tempFile.clear(); fileDlg(&m_tempFile); } void MetalinkCreator::fileDlg(KGetMetalink::File *file, bool edit) { QStringList currentNames; for (int i = 0; i < m_filesModel->rowCount(); ++i) { currentNames.append(m_filesModel->index(i, 0).data().toString()); } FileDlg *fileDlg = new FileDlg(file, currentNames, m_countrySort, m_languageSort, this, edit); fileDlg->setAttribute(Qt::WA_DeleteOnClose); fileDlg->setWindowModality(Qt::ApplicationModal); fileDlg->show(); connect(fileDlg, SIGNAL(addFile()), this, SLOT(slotAddFile())); connect(fileDlg, SIGNAL(fileEdited(QString,QString)), this, SLOT(slotFileEdited(QString,QString))); } void MetalinkCreator::slotFileProperties() { const QModelIndex index = uiFiles.files->selectionModel()->selectedRows().first(); const QString fileName = index.data().toString(); //search the selected file in metalink for (int i = 0; i < metalink.files.files.count(); ++i) { if (metalink.files.files.at(i).name == fileName) { fileDlg(&metalink.files.files[i], true); break; } } } void MetalinkCreator::slotOpenDragDlg() { m_tempResources.clear(); m_tempCommonData.clear(); DragDlg *dragDlg = new DragDlg(&m_tempResources, &m_tempCommonData, m_countrySort, m_languageSort, this); dragDlg->setAttribute(Qt::WA_DeleteOnClose); dragDlg->show(); connect(dragDlg, SIGNAL(usedTypes(QStringList,bool)), this, SLOT(slotHandleDropped(QStringList,bool))); } void MetalinkCreator::slotHandleDropped(const QStringList &types, bool createPartial) { uiFiles.progressBar->setMaximum(0); uiFiles.dragDrop->show(); m_thread.setData(m_handler->takeFiles(), types, createPartial, m_tempResources, m_tempCommonData); } void MetalinkCreator::slotThreadFinished() { uiFiles.progressBar->setMaximum(10); uiFiles.dragDrop->hide(); slotUpdateAssistantButtons(nullptr, m_files); }