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 "feededitdlg.h"
25 #include "feedmgrdlg.h"
27 typedef unsigned int _uint
;
29 FeedMgrDialog::FeedMgrDialog(QWidget
*parent
)
35 connect(itemsTree
, SIGNAL(itemDoubleClicked(QTreeWidgetItem
*,int)),
36 this, SLOT(onItemDoubleClicked(QTreeWidgetItem
*,int)));
38 itemsTree
->setColumnHidden(1, true);
42 FeedMgrDialog::onAdd() {
43 FeedEditDialog
dlg(this);
44 if (dlg
.exec() == QDialog::Accepted
)
45 addLink(dlg
.nameEdit
->text(), dlg
.linkEdit
->text());
49 confirm_remove(QWidget
*parent
) {
50 return QMessageBox::warning(
52 QObject::tr("Warning"),
53 QObject::tr("Really remove the selected links?"),
54 QMessageBox::Yes
|QMessageBox::No
,
60 FeedMgrDialog::onRemove() {
64 QTreeWidgetItemIterator
iter(itemsTree
);
65 QList
<QTreeWidgetItem
*> lst
;
67 if ((*iter
)->checkState(0) == Qt::Checked
) {
69 if (confirm_remove(this) == QMessageBox::No
)
78 QList
<QTreeWidgetItem
*>::const_iterator i
;
79 for (i
=lst
.constBegin(); i
!=lst
.constEnd(); ++i
) {
80 itemsTree
->removeItemWidget((*i
), 0);
86 FeedMgrDialog::onClear() {
88 if (itemsTree
->topLevelItemCount() == 0)
91 if (QMessageBox::warning(this, QCoreApplication::applicationName(),
92 tr("Really clear list?"),
93 QMessageBox::Yes
|QMessageBox::No
, QMessageBox::No
)
103 FeedMgrDialog::writeSettings() {
106 s
.beginGroup("FeedMgrDialog");
107 s
.setValue("size", size());
109 s
.beginWriteArray("feeds");
110 QTreeWidgetItemIterator
iter(itemsTree
);
111 for (register _uint i
=0; (*iter
); ++iter
, ++i
) {
114 QString("%1||%2") // Note: replaces "||" which we'll use as delim
115 .arg((*iter
)->text(0).replace("||","|"))
116 .arg((*iter
)->text(1).replace("||","|"))
125 FeedMgrDialog::readSettings() {
128 s
.beginGroup("FeedMgrDialog");
129 resize( s
.value("size", QSize(505,255)).toSize() );
131 const register _uint size
= s
.beginReadArray("feeds");
132 register _uint unnamed_count
= 1;
134 for (register _uint i
=0; i
<size
; ++i
) {
137 const QString entry
=
138 s
.value("link").toString();
140 QStringList tmp
= entry
.split("||");
142 if (tmp
.size() < 2) {
143 tmp
.prepend( // Name column was added in 0.4.5.
144 QString( tr("Unnamed feed #%1") )
145 .arg(unnamed_count
++)
149 addLink(tmp
[0], tmp
[1]);
157 FeedMgrDialog::onItemDoubleClicked(
158 QTreeWidgetItem
*item
,
161 FeedEditDialog
dlg(this, item
->text(0), item
->text(1));
162 if (dlg
.exec() == QDialog::Accepted
) {
163 item
->setText(0, dlg
.nameEdit
->text());
164 item
->setText(1, dlg
.linkEdit
->text());
169 FeedMgrDialog::addLink(QString name
, QString lnk
) {
174 name
= name
.trimmed();
181 if (!lnk
.startsWith("http://",Qt::CaseInsensitive
))
182 lnk
.insert(0,"http://");
184 QList
<QTreeWidgetItem
*> found
=
185 itemsTree
->findItems(lnk
, Qt::MatchExactly
, 1); // 1=url column
187 if (found
.size() == 0) {
188 QTreeWidgetItem
*item
= new QTreeWidgetItem
;
189 item
->setCheckState(0, Qt::Unchecked
);
190 item
->setText(0, name
);
191 item
->setText(1, lnk
);
192 itemsTree
->addTopLevelItem(item
);