File indexing completed on 2023-12-03 08:26:46
0001 /*************************************************************************** 0002 * Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU General Public License as published by * 0006 * the Free Software Foundation; either version 2 of the License, or * 0007 * (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the * 0016 * Free Software Foundation, Inc., * 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * 0018 ***************************************************************************/ 0019 0020 #include "dragdlg.h" 0021 #include "metalinker.h" 0022 #include "urlwidget.h" 0023 0024 #include "core/verifier.h" 0025 0026 #include <QCheckBox> 0027 #include <QSortFilterProxyModel> 0028 0029 #include <KLocalizedString> 0030 0031 DragDlg::DragDlg(KGetMetalink::Resources *resources, 0032 KGetMetalink::CommonData *commonData, 0033 QSortFilterProxyModel *countrySort, 0034 QSortFilterProxyModel *languageSort, 0035 QWidget *parent) 0036 : KGetSaveSizeDialog("DragDlg", parent) 0037 , m_resources(resources) 0038 , m_commonData(commonData) 0039 { 0040 ui.setupUi(this); 0041 0042 m_urlWidget = new UrlWidget(this); 0043 m_urlWidget->init(m_resources, countrySort); 0044 ui.urlLayout->addWidget(m_urlWidget->widget()); 0045 0046 auto *data = new QWidget(this); 0047 uiData.setupUi(data); 0048 ui.dataLayout->addWidget(data); 0049 0050 auto *layout = new QVBoxLayout; 0051 QStringList verifierTypes = Verifier::supportedVerficationTypes(); 0052 verifierTypes.sort(); 0053 0054 // NOTE only supports the types that are supported by the Metalink 4.0 specification -- "Hash Function Textual Names" 0055 foreach (const QString &type, verifierTypes) { 0056 if (type.contains("sha", Qt::CaseInsensitive) || type.contains("md5", Qt::CaseInsensitive)) { 0057 auto *checkBox = new QCheckBox(type, this); 0058 layout->addWidget(checkBox); 0059 m_checkBoxes.append(checkBox); 0060 } 0061 } 0062 0063 ui.groupBox->setLayout(layout); 0064 0065 // create the language selection 0066 uiData.language->setModel(languageSort); 0067 uiData.language->setCurrentIndex(-1); 0068 0069 connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0070 connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0071 connect(this, &DragDlg::accepted, this, &DragDlg::slotFinished); 0072 0073 setWindowTitle(i18n("Import dropped files")); 0074 } 0075 0076 void DragDlg::slotFinished() 0077 { 0078 m_urlWidget->save(); 0079 0080 QStringList used; 0081 foreach (QCheckBox *checkbox, m_checkBoxes) { 0082 if (checkbox->isChecked()) { 0083 used.append(checkbox->text().remove('&')); 0084 } 0085 } 0086 0087 m_commonData->identity = uiData.identity->text(); 0088 m_commonData->version = uiData.version->text(); 0089 m_commonData->description = uiData.description->text(); 0090 m_commonData->logo = QUrl(uiData.logo->text()); 0091 if (uiData.os->text().isEmpty()) { 0092 m_commonData->oses.clear(); 0093 } else { 0094 m_commonData->oses = uiData.os->text().split(i18nc("comma, to separate members of a list", ",")); 0095 } 0096 m_commonData->copyright = uiData.copyright->text(); 0097 m_commonData->publisher.name = uiData.pub_name->text(); 0098 m_commonData->publisher.url = QUrl(uiData.pub_url->text()); 0099 m_commonData->languages << uiData.language->itemData(uiData.language->currentIndex()).toString(); 0100 0101 Q_EMIT usedTypes(used, ui.partialChecksums->isChecked()); 0102 } 0103 0104 #include "moc_dragdlg.cpp"