23 #include "cfgwadseekersites.h" 24 #include "configuration/doomseekerconfig.h" 25 #include "ui_cfgwadseekersites.h" 26 #include "wadseeker/wadseeker.h" 30 #include <QFileDialog> 31 #include <QMessageBox> 32 #include <QStandardItemModel> 35 DClass<CFGWadseekerSites> :
public Ui::CFGWadseekerSites
46 d->lstUrls->setModel(
new QStandardItemModel());
48 connect(d->btnUrlAdd, SIGNAL(clicked()),
this, SLOT(btnUrlAddClicked()));
49 connect(d->btnUrlDefault, SIGNAL(clicked()),
this, SLOT(btnUrlDefaultClicked()));
50 connect(d->btnUrlRemove, SIGNAL(clicked()),
this, SLOT(btnUrlRemoveClicked()));
51 connect(d->leUrl, SIGNAL(returnPressed()),
this, SLOT(btnUrlAddClicked()));
54 CFGWadseekerSites::~CFGWadseekerSites()
58 void CFGWadseekerSites::btnUrlAddClicked()
60 insertUrl(d->leUrl->text());
63 void CFGWadseekerSites::btnUrlDefaultClicked()
65 for (
int i = 0; !Wadseeker::defaultSites[i].isEmpty(); ++i)
66 insertUrl(Wadseeker::defaultSites[i]);
69 void CFGWadseekerSites::btnUrlRemoveClicked()
71 QItemSelectionModel *selModel = d->lstUrls->selectionModel();
72 QModelIndexList indexList = selModel->selectedIndexes();
75 auto model =
static_cast<QStandardItemModel *
>(d->lstUrls->model());
76 QList<QStandardItem *> itemList;
77 for (
int i = 0; i < indexList.count(); ++i)
78 itemList << model->itemFromIndex(indexList[i]);
80 for (
int i = 0; i < itemList.count(); ++i)
82 QModelIndex index = model->indexFromItem(itemList[i]);
83 model->removeRow(index.row());
87 void CFGWadseekerSites::insertUrl(
const QString &url)
93 auto model =
static_cast<QStandardItemModel *
>(d->lstUrls->model());
94 for (
int i = 0; i < model->rowCount(); ++i)
96 QUrl existingUrl(model->item(i)->text());
97 if (existingUrl == url)
101 auto it =
new QStandardItem(url);
103 it->setDragEnabled(
true);
104 it->setDropEnabled(
false);
107 model->appendRow(it);
112 const QStringList &urlList = gConfig.wadseeker.searchURLs;
113 for (
const QString &url : urlList)
115 this->insertUrl(url);
117 d->cbAlwaysUseDefaultSites->setChecked(gConfig.wadseeker.bAlwaysUseDefaultSites);
123 auto model =
static_cast<QStandardItemModel *
>(d->lstUrls->model());
124 for (
int i = 0; i < model->rowCount(); ++i)
125 urlList << model->item(i)->text();
127 gConfig.wadseeker.searchURLs = urlList;
128 gConfig.wadseeker.bAlwaysUseDefaultSites = d->cbAlwaysUseDefaultSites->isChecked();
void saveSettings() override
Reimplement this to write settings to config from widgets.
void readSettings() override
Reimplement this to read settings from config into widgets.
Base class for configuration pages.