File indexing completed on 2024-05-12 05:17:28
0001 /* 0002 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "settingsdialog.h" 0008 #include "ui_settingsdialog.h" 0009 0010 #include <KItinerary/ExtractorRepository> 0011 0012 #include <QSettings> 0013 #include <QStringListModel> 0014 0015 using namespace KItinerary; 0016 0017 SettingsDialog::SettingsDialog(QWidget *parent) 0018 : QDialog(parent) 0019 , ui(new Ui::SettingsDialog) 0020 , m_searchPathModel(new QStringListModel(this)) 0021 { 0022 ui->setupUi(this); 0023 0024 ui->searchPathView->setModel(m_searchPathModel); 0025 0026 ExtractorRepository repo; 0027 m_searchPathModel->setStringList(repo.additionalSearchPaths()); 0028 0029 connect(ui->searchPathAddButton, &QPushButton::clicked, this, [this]() { 0030 if (!ui->searchPathRequester->url().isValid()) { 0031 return; 0032 } 0033 const auto idx = m_searchPathModel->rowCount(); 0034 m_searchPathModel->insertRows(idx, 1); 0035 m_searchPathModel->setData(m_searchPathModel->index(idx, 0), ui->searchPathRequester->url().toLocalFile()); 0036 ui->searchPathRequester->clear(); 0037 }); 0038 0039 connect(ui->searchPathRemoveButton, &QPushButton::clicked, this, [this]() { 0040 const auto sel = ui->searchPathView->selectionModel()->selection(); 0041 if (sel.isEmpty()) { 0042 return; 0043 } 0044 m_searchPathModel->removeRows(sel.first().topLeft().row(), 1); 0045 }); 0046 } 0047 0048 SettingsDialog::~SettingsDialog() = default; 0049 0050 void SettingsDialog::accept() 0051 { 0052 ExtractorRepository repo; 0053 repo.setAdditionalSearchPaths(m_searchPathModel->stringList()); 0054 0055 QSettings settings; 0056 settings.beginGroup(QStringLiteral("Extractor Repository")); 0057 settings.setValue(QStringLiteral("SearchPaths"), repo.additionalSearchPaths()); 0058 0059 QDialog::accept(); 0060 }