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/>.
20 #include <QInputDialog>
21 #include <QMessageBox>
24 #include "feedmgrdlg.h"
26 typedef unsigned int _uint
;
28 FeedMgrDialog::FeedMgrDialog(QWidget
*parent
)
34 connect(feedsList
, SIGNAL(itemDoubleClicked(QListWidgetItem
*)),
35 this, SLOT(onItemDoubleClicked(QListWidgetItem
*)));
39 FeedMgrDialog::onAdd() {
40 QString lnk
= QInputDialog::getText(this,
41 QCoreApplication::applicationName(), tr("Add link:"));
46 FeedMgrDialog::onPaste() {
47 QClipboard
*cb
= QApplication::clipboard();
48 addLink( cb
->text().split("\n")[0] );
52 FeedMgrDialog::onRemove() {
54 QList
<QListWidgetItem
*> sel
= feedsList
->selectedItems();
59 if (QMessageBox::warning(this, QCoreApplication::applicationName(),
60 tr("Really remove the selected links?"),
61 QMessageBox::Yes
|QMessageBox::No
, QMessageBox::No
)
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
);
75 FeedMgrDialog::onClear() {
77 if (feedsList
->count() == 0)
80 if (QMessageBox::warning(this, QCoreApplication::applicationName(),
81 tr("Really clear list?"),
82 QMessageBox::Yes
|QMessageBox::No
, QMessageBox::No
)
90 FeedMgrDialog::writeSettings() {
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
) {
100 QListWidgetItem
*item
= feedsList
->item(i
);
101 s
.setValue("link",item
->text());
109 FeedMgrDialog::readSettings() {
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
) {
117 feedsList
->addItem(s
.value("link").toString());
124 FeedMgrDialog::onItemDoubleClicked(QListWidgetItem
*item
) {
127 QString lnk
= QInputDialog::getText(this,
128 QCoreApplication::applicationName(), tr("Edit link:"),
129 QLineEdit::Normal
, item
->text(), &ok
);
131 if (ok
&& !lnk
.isEmpty())
136 FeedMgrDialog::addLink(QString
& lnk
) {
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
);