Use QProcess::errorString instead
[nomnom.git] / src / feed / nfeeddialog.cpp
blob45c67459a6524153bd3fda5fb89c2644e1b82782
1 /* NomNom
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>
22 #include <QToolBox>
24 #include <NFeedProgressDialog>
25 #include <NFeedDialog>
27 extern nn::feed::NFeedList feedItems; // main.cpp
29 namespace nn
32 NFeedDialog::NFeedDialog(QWidget *parent, const QString& umphPath)
33 : QDialog(parent), _toolbox(NULL)
36 // Toolbox
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"));
49 // Button box
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()));
57 // Layout
59 QVBoxLayout *box = new QVBoxLayout;
60 box->addWidget(_toolbox);
61 box->addWidget(btnBox);
62 setLayout(box);
64 // Window
66 setWindowTitle(tr("YouTube feed"));
67 setMinimumSize(QSize(500,400));
68 foreachWidget();
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"));
82 return;
85 QDialog::done(n);
86 close();
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();
102 return true;
105 void NFeedDialog::parse(QStringList args)
107 _selected.clear();
109 NFeedProgressDialog *d = new NFeedProgressDialog(this);
110 const bool r = d->open(args);
112 if (d->cancelled())
113 return;
115 if (r)
117 QString msg;
118 if (!d->results(feedItems, msg))
119 NFeedDialog::m_info(this, msg);
120 else
122 _toolbox->setCurrentIndex(1);
123 emit parsed();
126 else
127 m_info(this, d->errmsg());
130 void NFeedDialog::selected(QString s)
132 _selected = s;
135 QString NFeedDialog::selected() const
137 return _selected;
140 NFeedWidget::NFeedWidget(QWidget *parent/*=NULL*/)
141 : QWidget(parent)
145 } // namespace nn
147 /* vim: set ts=2 sw=2 tw=72 expandtab: */