23 #include "cfgwadseekersites.h"
24 #include "configuration/doomseekerconfig.h"
25 #include "ui_cfgwadseekersites.h"
26 #include "wadseeker/wadseeker.h"
29 #include <QFileDialog>
30 #include <QMessageBox>
31 #include <QStandardItemModel>
34 DClass<CFGWadseekerSites> :
public Ui::CFGWadseekerSites
45 d->lstUrls->setModel(
new QStandardItemModel());
47 connect(d->btnUrlAdd, SIGNAL(clicked()),
this, SLOT(btnUrlAddClicked()));
48 connect(d->btnUrlDefault, SIGNAL(clicked()),
this, SLOT(btnUrlDefaultClicked()));
49 connect(d->btnUrlRemove, SIGNAL(clicked()),
this, SLOT(btnUrlRemoveClicked()));
50 connect(d->leUrl, SIGNAL(returnPressed()),
this, SLOT(btnUrlAddClicked()));
53 CFGWadseekerSites::~CFGWadseekerSites()
57 void CFGWadseekerSites::btnUrlAddClicked()
59 insertUrl(d->leUrl->text());
62 void CFGWadseekerSites::btnUrlDefaultClicked()
64 for (
int i = 0; !Wadseeker::defaultSites[i].isEmpty(); ++i)
65 insertUrl(Wadseeker::defaultSites[i]);
68 void CFGWadseekerSites::btnUrlRemoveClicked()
70 QItemSelectionModel *selModel = d->lstUrls->selectionModel();
71 QModelIndexList indexList = selModel->selectedIndexes();
74 auto model =
static_cast<QStandardItemModel *
>(d->lstUrls->model());
75 QList<QStandardItem *> itemList;
76 for (
int i = 0; i < indexList.count(); ++i)
77 itemList << model->itemFromIndex(indexList[i]);
79 for (
int i = 0; i < itemList.count(); ++i)
81 QModelIndex index = model->indexFromItem(itemList[i]);
82 model->removeRow(index.row());
86 void CFGWadseekerSites::insertUrl(
const QString &url)
92 auto model =
static_cast<QStandardItemModel *
>(d->lstUrls->model());
93 for (
int i = 0; i < model->rowCount(); ++i)
95 QUrl existingUrl(model->item(i)->text());
96 if (existingUrl == url)
100 auto it =
new QStandardItem(url);
102 it->setDragEnabled(
true);
103 it->setDropEnabled(
false);
106 model->appendRow(it);
111 const QStringList &urlList = gConfig.wadseeker.searchURLs;
112 for (
const QString &url : urlList)
114 this->insertUrl(url);
116 d->cbAlwaysUseDefaultSites->setChecked(gConfig.wadseeker.bAlwaysUseDefaultSites);
122 auto model =
static_cast<QStandardItemModel *
>(d->lstUrls->model());
123 for (
int i = 0; i < model->rowCount(); ++i)
124 urlList << model->item(i)->text();
126 gConfig.wadseeker.searchURLs = urlList;
127 gConfig.wadseeker.bAlwaysUseDefaultSites = d->cbAlwaysUseDefaultSites->isChecked();