README: update cclive prereq.
[abby.git] / src / feedmgrdlg.cpp
blob43e14da2a2088b1d2b7c8c4cc6bdf82a23ce26e5
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>
22 #include "feedmgrdlg.h"
24 FeedMgrDialog::FeedMgrDialog(QWidget *parent)
25 : QDialog(parent)
27 setupUi(this);
28 readSettings();
31 void
32 FeedMgrDialog::onAdd() {
33 QString lnk = QInputDialog::getText(this,
34 tr("Add new RSS feed link"), tr("Enter link:"));
36 if (lnk.isEmpty())
37 return;
39 lnk = lnk.trimmed();
41 if (!lnk.startsWith("http://",Qt::CaseInsensitive))
42 lnk.insert(0,"http://");
44 QList<QListWidgetItem *> found
45 = feedsList->findItems(lnk, Qt::MatchExactly);
47 if (found.size() == 0)
48 feedsList->addItem(lnk);
51 void
52 FeedMgrDialog::onRemove() {
53 QList<QListWidgetItem*> sel = feedsList->selectedItems();
54 for (register int i=0; i<sel.size(); ++i) {
55 const int row = feedsList->row(sel[i]);
56 delete feedsList->takeItem(row);
60 void
61 FeedMgrDialog::writeSettings() {
62 QSettings s;
64 s.beginGroup("FeedMgrDialog");
65 s.setValue("size", size());
67 s.beginWriteArray("feeds");
68 for (register int i=0; i<feedsList->count(); ++i) {
69 s.setArrayIndex(i);
70 QListWidgetItem *item = feedsList->item(i);
71 s.setValue("link",item->text());
73 s.endArray();
75 s.endGroup();
78 void
79 FeedMgrDialog::readSettings() {
80 QSettings s;
82 s.beginGroup("FeedMgrDialog");
83 resize( s.value("size", QSize(505,255)).toSize() );
84 const int size = s.beginReadArray("feeds");
85 for (register int i=0; i<size; ++i) {
86 s.setArrayIndex(i);
87 feedsList->addItem(s.value("link").toString());
89 s.endArray();
90 s.endGroup();