cfgwadseekersites.cpp
1 //------------------------------------------------------------------------------
2 // cfgwadseekersites.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "cfgwadseekersites.h"
24 #include "ui_cfgwadseekersites.h"
25 #include "configuration/doomseekerconfig.h"
26 #include "wadseeker/wadseeker.h"
27 #include <QCompleter>
28 #include <QDebug>
29 #include <QDirModel>
30 #include <QFileDialog>
31 #include <QMessageBox>
32 #include <QStandardItemModel>
33 #include <QUrl>
34 
35 DClass<CFGWadseekerSites> : public Ui::CFGWadseekerSites
36 {
37 };
38 
39 DPointered(CFGWadseekerSites)
40 
41 CFGWadseekerSites::CFGWadseekerSites(QWidget* parent)
42 : ConfigPage(parent)
43 {
44  d->setupUi(this);
45 
46  d->lstUrls->setModel(new QStandardItemModel());
47 
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()));
52 }
53 
54 CFGWadseekerSites::~CFGWadseekerSites()
55 {
56 }
57 
58 void CFGWadseekerSites::btnUrlAddClicked()
59 {
60  insertUrl(d->leUrl->text());
61 }
62 
63 void CFGWadseekerSites::btnUrlDefaultClicked()
64 {
65  for (int i = 0; !Wadseeker::defaultSites[i].isEmpty(); ++i)
66  {
67  insertUrl(Wadseeker::defaultSites[i]);
68  }
69 }
70 
71 void CFGWadseekerSites::btnUrlRemoveClicked()
72 {
73  QItemSelectionModel* selModel = d->lstUrls->selectionModel();
74  QModelIndexList indexList = selModel->selectedIndexes();
75  selModel->clear();
76 
77  QStandardItemModel* model = static_cast<QStandardItemModel*>(d->lstUrls->model());
78  QList<QStandardItem*> itemList;
79  for (int i = 0; i < indexList.count(); ++i)
80  {
81  itemList << model->itemFromIndex(indexList[i]);
82  }
83 
84  for (int i = 0; i < itemList.count(); ++i)
85  {
86  QModelIndex index = model->indexFromItem(itemList[i]);
87  model->removeRow(index.row());
88  }
89 }
90 
91 void CFGWadseekerSites::insertUrl(const QString& url)
92 {
93  if (url.isEmpty())
94  {
95  return;
96  }
97 
98  // first we check whether the URL is already in the box.
99  QStandardItemModel* model = static_cast<QStandardItemModel*>(d->lstUrls->model());
100  for (int i = 0; i < model->rowCount(); ++i)
101  {
102  QUrl existingUrl( model->item(i)->text() );
103  if (existingUrl == url)
104  {
105  return;
106  }
107  }
108 
109  QStandardItem* it = new QStandardItem(url);
110 
111  it->setDragEnabled(true);
112  it->setDropEnabled(false);
113  it->setToolTip(url);
114 
115  model->appendRow(it);
116 }
117 
119 {
120  const QStringList& urlList = gConfig.wadseeker.searchURLs;
121  foreach (const QString& url, urlList)
122  {
123  this->insertUrl(url);
124  }
125  d->cbAlwaysUseDefaultSites->setChecked(gConfig.wadseeker.bAlwaysUseDefaultSites);
126 }
127 
129 {
130  QStringList urlList;
131  QStandardItemModel* model = static_cast<QStandardItemModel*>(d->lstUrls->model());
132  for (int i = 0; i < model->rowCount(); ++i)
133  {
134  urlList << model->item(i)->text();
135  }
136 
137  gConfig.wadseeker.searchURLs = urlList;
138  gConfig.wadseeker.bAlwaysUseDefaultSites = d->cbAlwaysUseDefaultSites->isChecked();
139 }
void saveSettings()
Reimplement this to write settings to config from widgets.
void readSettings()
Reimplement this to read settings from config into widgets.
Base class for configuration pages.
Definition: configpage.h:43