add "verify c/clive path" button.
[abby.git] / src / feedmgrdlg.cpp
blobc6dda0b4900a0c98b7553bc2ac51af1184f72e76
1 /*
2 * abby Copyright (C) 2009 Toni Gundogdu.
3 * This file is part of abby.
5 * abby is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * abby 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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <QDialog>
19 #include <QSettings>
20 #include <QInputDialog>
21 #include <QMessageBox>
22 #include <QClipboard>
24 #include "feedmgrdlg.h"
26 typedef unsigned int _uint;
28 FeedMgrDialog::FeedMgrDialog(QWidget *parent)
29 : QDialog(parent)
31 setupUi(this);
32 readSettings();
34 connect(feedsList, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
35 this, SLOT(onItemDoubleClicked(QListWidgetItem*)));
38 void
39 FeedMgrDialog::onAdd() {
40 QString lnk = QInputDialog::getText(this,
41 QCoreApplication::applicationName(), tr("Add link:"));
42 addLink(lnk);
45 void
46 FeedMgrDialog::onPaste() {
47 QClipboard *cb = QApplication::clipboard();
48 addLink( cb->text().split("\n")[0] );
51 void
52 FeedMgrDialog::onRemove() {
54 QList<QListWidgetItem*> sel = feedsList->selectedItems();
56 if (sel.size() == 0)
57 return;
59 if (QMessageBox::warning(this, QCoreApplication::applicationName(),
60 tr("Really remove the selected links?"),
61 QMessageBox::Yes|QMessageBox::No, QMessageBox::No)
62 == QMessageBox::No)
64 return;
67 const register _uint size = sel.size();
68 for (register _uint i=0; i<size; ++i) {
69 const int row = feedsList->row(sel[i]);
70 delete feedsList->takeItem(row);
74 void
75 FeedMgrDialog::onClear() {
77 if (feedsList->count() == 0)
78 return;
80 if (QMessageBox::warning(this, QCoreApplication::applicationName(),
81 tr("Really clear list?"),
82 QMessageBox::Yes|QMessageBox::No, QMessageBox::No)
83 == QMessageBox::No)
85 return;
89 void
90 FeedMgrDialog::writeSettings() {
91 QSettings s;
93 s.beginGroup("FeedMgrDialog");
94 s.setValue("size", size());
96 s.beginWriteArray("feeds");
97 const register _uint count = feedsList->count();
98 for (register _uint i=0; i<count; ++i) {
99 s.setArrayIndex(i);
100 QListWidgetItem *item = feedsList->item(i);
101 s.setValue("link",item->text());
103 s.endArray();
105 s.endGroup();
108 void
109 FeedMgrDialog::readSettings() {
110 QSettings s;
112 s.beginGroup("FeedMgrDialog");
113 resize( s.value("size", QSize(505,255)).toSize() );
114 const register _uint size = s.beginReadArray("feeds");
115 for (register _uint i=0; i<size; ++i) {
116 s.setArrayIndex(i);
117 feedsList->addItem(s.value("link").toString());
119 s.endArray();
120 s.endGroup();
123 void
124 FeedMgrDialog::onItemDoubleClicked(QListWidgetItem *item) {
125 bool ok;
127 QString lnk = QInputDialog::getText(this,
128 QCoreApplication::applicationName(), tr("Edit link:"),
129 QLineEdit::Normal, item->text(), &ok);
131 if (ok && !lnk.isEmpty())
132 item->setText(lnk);
135 void
136 FeedMgrDialog::addLink(QString& lnk) {
138 if (lnk.isEmpty())
139 return;
141 lnk = lnk.trimmed();
143 if (!lnk.startsWith("http://",Qt::CaseInsensitive))
144 lnk.insert(0,"http://");
146 QList<QListWidgetItem *> found
147 = feedsList->findItems(lnk, Qt::MatchExactly);
149 if (found.size() == 0)
150 feedsList->addItem(lnk);