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>
25 #include "feededitdlg.h"
26 #include "feedmgrdlg.h"
28 typedef unsigned int _uint
;
30 FeedMgrDialog::FeedMgrDialog(QWidget
*parent
)
36 connect(itemsTree
, SIGNAL(itemDoubleClicked(QTreeWidgetItem
*,int)),
37 this, SLOT(onItemDoubleClicked(QTreeWidgetItem
*,int)));
39 itemsTree
->setColumnHidden(1, true);
43 FeedMgrDialog::onAdd() {
44 FeedEditDialog
dlg(this);
45 if (dlg
.exec() == QDialog::Accepted
)
46 addLink(dlg
.nameEdit
->text(), dlg
.linkEdit
->text());
50 confirm_remove(QWidget
*parent
) {
51 return QMessageBox::warning(
53 QObject::tr("Warning"),
54 QObject::tr("Really remove the selected links?"),
55 QMessageBox::Yes
|QMessageBox::No
,
61 FeedMgrDialog::onRemove() {
65 QTreeWidgetItemIterator
iter(itemsTree
);
66 QList
<QTreeWidgetItem
*> lst
;
68 if ((*iter
)->checkState(0) == Qt::Checked
) {
70 if (confirm_remove(this) == QMessageBox::No
)
79 QList
<QTreeWidgetItem
*>::const_iterator i
;
80 for (i
=lst
.constBegin(); i
!=lst
.constEnd(); ++i
) {
81 itemsTree
->removeItemWidget((*i
), 0);
87 FeedMgrDialog::onClear() {
89 if (itemsTree
->topLevelItemCount() == 0)
92 if (QMessageBox::warning(this, QCoreApplication::applicationName(),
93 tr("Really clear list?"),
94 QMessageBox::Yes
|QMessageBox::No
, QMessageBox::No
)
104 FeedMgrDialog::writeSettings() {
107 s
.beginGroup("FeedMgrDialog");
108 s
.setValue("size", size());
110 s
.beginWriteArray("feeds");
111 QTreeWidgetItemIterator
iter(itemsTree
);
112 for (register _uint i
=0; (*iter
); ++iter
, ++i
) {
115 QString("%1||%2") // Note: replaces "||" which we'll use as delim
116 .arg((*iter
)->text(0).replace("||","|"))
117 .arg((*iter
)->text(1).replace("||","|"))
126 FeedMgrDialog::readSettings() {
129 s
.beginGroup("FeedMgrDialog");
130 resize( s
.value("size", QSize(505,255)).toSize() );
132 const register _uint size
= s
.beginReadArray("feeds");
133 register _uint unnamed_count
= 1;
135 for (register _uint i
=0; i
<size
; ++i
) {
138 const QString entry
=
139 s
.value("link").toString();
141 QStringList tmp
= entry
.split("||");
143 if (tmp
.size() < 2) {
144 tmp
.prepend( // Name column was added in 0.4.5.
145 QString( tr("Unnamed feed #%1") )
146 .arg(unnamed_count
++)
150 addLink(tmp
[0], tmp
[1]);
158 FeedMgrDialog::onItemDoubleClicked(
159 QTreeWidgetItem
*item
,
162 FeedEditDialog
dlg(this, item
->text(0), item
->text(1));
163 if (dlg
.exec() == QDialog::Accepted
) {
164 item
->setText(0, dlg
.nameEdit
->text());
165 item
->setText(1, dlg
.linkEdit
->text());
170 FeedMgrDialog::addLink(QString name
, QString lnk
) {
172 name
= name
.simplified();
176 lnk
= lnk
.simplified();
180 if (!lnk
.startsWith("http://",Qt::CaseInsensitive
))
181 lnk
.insert(0,"http://");
184 if (itemsTree
->findItems(lnk
, Qt::MatchExactly
, 1).size() == 0) {
185 QTreeWidgetItem
*item
= new QTreeWidgetItem(itemsTree
);
186 item
->setCheckState(0, Qt::Unchecked
);
187 item
->setText(0, name
);
188 item
->setText(1, lnk
);
193 FeedMgrDialog::onSelectAll() {
194 Util::checkAllItems(itemsTree
, Qt::Checked
);
198 FeedMgrDialog::onInvert() {
199 Util::invertAllCheckableItems(itemsTree
);