2 * Copyright (C) 2011 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <QCoreApplication>
19 #include <QDialogButtonBox>
20 #include <QMessageBox>
21 #include <QVBoxLayout>
24 #include <NFeedProgressDialog>
25 #include <NFeedDialog>
27 extern nn::feed::NFeedList feedItems
; // main.cpp
32 NFeedDialog::NFeedDialog(QWidget
*parent
, const QString
& umphPath
)
33 : QDialog(parent
), _toolbox(NULL
)
38 NFeedInfo
*info
= new NFeedInfo(umphPath
);
39 connect(info
, SIGNAL(parse(QStringList
)), this, SLOT(parse(QStringList
)));
41 NFeedItems
*items
= new NFeedItems
;
42 connect(this, SIGNAL(parsed()), items
, SLOT(update()));
43 connect(items
, SIGNAL(selected(QString
)), this, SLOT(selected(QString
)));
45 _toolbox
= new QToolBox
;
46 _toolbox
->addItem(info
, tr("&Information"));
47 _toolbox
->addItem(items
, tr("I&tems"));
51 QDialogButtonBox
*btnBox
= new QDialogButtonBox(
52 QDialogButtonBox::Ok
| QDialogButtonBox::Cancel
);
54 connect(btnBox
, SIGNAL(accepted()), this, SLOT(accept()));
55 connect(btnBox
, SIGNAL(rejected()), this, SLOT(reject()));
59 QVBoxLayout
*box
= new QVBoxLayout
;
60 box
->addWidget(_toolbox
);
61 box
->addWidget(btnBox
);
66 setWindowTitle(tr("YouTube feed"));
67 setMinimumSize(QSize(500,400));
70 if (feedItems
.count() > 0)
71 _toolbox
->setCurrentIndex(1);
74 void NFeedDialog::done(int n
)
76 if (n
== QDialog::Accepted
)
78 if (_selected
.isEmpty())
80 _toolbox
->setCurrentIndex(1);
81 m_info(this, tr("Please select an item from the list"));
89 void NFeedDialog::m_info(QWidget
*parent
, const QString
& msg
)
91 QMessageBox::information(parent
, QCoreApplication::applicationName(), msg
);
94 bool NFeedDialog::foreachWidget()
96 const int c
= _toolbox
->count();
97 for (int i
=0; i
<c
; ++i
)
99 QWidget
*w
= _toolbox
->widget(i
);
100 dynamic_cast<NFeedWidget
*>(w
)->init();
105 void NFeedDialog::parse(QStringList args
)
109 NFeedProgressDialog
*d
= new NFeedProgressDialog(this);
110 const bool r
= d
->open(args
);
118 if (!d
->results(feedItems
, msg
))
119 NFeedDialog::m_info(this, msg
);
122 _toolbox
->setCurrentIndex(1);
127 m_info(this, d
->errmsg());
130 void NFeedDialog::selected(QString s
)
135 QString
NFeedDialog::selected() const
140 NFeedWidget::NFeedWidget(QWidget
*parent
/*=NULL*/)
147 /* vim: set ts=2 sw=2 tw=72 expandtab: */