Use QProcess::errorString instead
[nomnom.git] / src / feed / nfeeddialog_info.cpp
blobb81c2bc1c37388744e30f69e2427b8c7e6b825f8
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 <QDialogButtonBox>
19 #include <QButtonGroup>
20 #include <QRadioButton>
21 #include <QPushButton>
22 #include <QHBoxLayout>
23 #include <QVBoxLayout>
24 #include <QGridLayout>
25 #include <QLineEdit>
26 #include <QComboBox>
27 #include <QGroupBox>
28 #include <QSpinBox>
29 #include <QLabel>
31 #include <NFeedDialog>
32 #include <NFeed>
34 extern bool have_umph_feature_all; // main.cpp
36 namespace nn
39 enum { StartIndexTooltip=0x00, MaxResultsTooltip };
41 static const char *tooltips[] =
43 QT_TRANSLATE_NOOP("Tooltip",
44 "The start index parameter specifies the index of the first matching\n"
45 "result that should be included in the result set. This parameter uses\n"
46 "a one-based index, meaning the first result is 1, the second result\n"
47 "is 2 and so forth.\n\n"
48 "This parameter works in conjunction with the \"max. results\"\n"
49 "parameter to determine which results to return. For example, to\n"
50 "request the second set of 10 results, i.e. results 11-20, set the\n"
51 "start index parameter to 11 and the max results parameter to 10.\n"
52 " -- YouTube Developer's Guide: Data API Protocol"
54 QT_TRANSLATE_NOOP("Tooltip",
55 "The max results parameter specifies the maximum number of\n"
56 "results that should be included in the result set.\n\n"
57 "This parameter works in conjunction with the start index parameter\n"
58 "to determine which results to return. For example, to request the\n"
59 "second set of 10 results, i.e. results 11-20, set the max results\n"
60 "parameter to 10 and the start index parameter to 11.\n\n"
61 "The default value of this parameter is 25, and the maximum value\n"
62 "is 50. However, for displaying lists of videos, we recommend that\n"
63 "you set the max results parameter to 10.\n"
64 " -- YouTube Developer's Guide: Data API Protocol"
68 typedef enum { Uploads=0x00, Favorites, Playlist } Type;
69 typedef enum { All=0x00, Select } Mode;
71 NFeedInfo::NFeedInfo(const QString& umphPath, QWidget *parent/*=NULL*/)
72 : NFeedWidget(parent),
73 _rangeGroup(NULL),
74 _typeCombo(NULL),
75 _identEdit(NULL),
76 _bgroup(NULL),
77 _indexSpin(NULL),
78 _identLabel(NULL),
79 _maxSpin(NULL),
80 _umphPath(umphPath)
83 // Widgets
85 _typeCombo = new QComboBox;
86 _typeCombo->addItem(tr("Uploads"), Uploads);
87 _typeCombo->addItem(tr("Favorites"), Favorites);
88 _typeCombo->addItem(tr("Playlist"), Playlist);
90 connect(_typeCombo, SIGNAL(currentIndexChanged(int)),
91 this, SLOT(typeChanged(int)));
93 _identEdit = new QLineEdit;
94 _identEdit->setToolTip(
95 tr("YouTube username or playlist ID depending on your selection"));
96 _identLabel = new QLabel;
97 _identLabel->setBuddy(_identEdit);
99 QHBoxLayout *identBox = new QHBoxLayout;
100 identBox->addWidget(_typeCombo);
101 identBox->addWidget(_identLabel);
102 identBox->addWidget(_identEdit);
104 QRadioButton *all = new QRadioButton(tr("&Get the entire feed"));
105 QRadioButton *select =
106 new QRadioButton(tr("G&et the specified range from the feed"));
108 if (!have_umph_feature_all)
110 all->setToolTip(tr("Please install umph 0.2.0 or later to enable"));
111 all->setEnabled(false);
112 select->toggle();
114 else
115 all->toggle();
117 _bgroup = new QButtonGroup;
118 _bgroup->addButton(all, All);
119 _bgroup->addButton(select, Select);
121 connect(_bgroup, SIGNAL(buttonClicked(int)), this, SLOT(modeChanged(int)));
123 // Select range
125 QLabel *l = new QLabel(tr("St&art index:"));
126 _indexSpin = new QSpinBox;
127 _indexSpin->setToolTip(tooltips[StartIndexTooltip]);
128 _indexSpin->setMinimum(1);
129 l->setBuddy(_indexSpin);
131 QGridLayout *rangeGrid = new QGridLayout;
132 rangeGrid->addWidget(l, 0, 0);
133 rangeGrid->addWidget(_indexSpin, 0, 1);
135 l = new QLabel(tr("&Max. results:"));
136 _maxSpin = new QSpinBox;
137 _maxSpin->setToolTip(tooltips[MaxResultsTooltip]);
138 _maxSpin->setMinimum(1);
139 _maxSpin->setMaximum(50);
140 l->setBuddy(_maxSpin);
142 rangeGrid->addWidget(l, 1, 0);
143 rangeGrid->addWidget(_maxSpin, 1, 1);
145 _rangeGroup = new QGroupBox(tr("Select range"));
146 _rangeGroup->setLayout(rangeGrid);
148 // Git it.
150 QDialogButtonBox *btnBox = new QDialogButtonBox(
151 QDialogButtonBox::Reset | QDialogButtonBox::Ok);
153 connect(btnBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
154 this, SLOT(reset()));
156 connect(btnBox, SIGNAL(accepted()), this, SLOT(parse()));
158 // Layout
160 QVBoxLayout *box = new QVBoxLayout;
161 box->addLayout(identBox);
162 box->addWidget(all);
163 box->addWidget(select);
164 box->addWidget(_rangeGroup);
165 box->addWidget(btnBox);
166 box->addStretch(0);
167 setLayout(box);
170 void NFeedInfo::init()
172 reset();
173 typeChanged(_typeCombo->currentIndex());
174 modeChanged(_bgroup->checkedId());
177 void NFeedInfo::enableRange(bool state/*=true*/)
179 _rangeGroup->setEnabled(state);
182 void NFeedInfo::modeChanged(int n)
184 enableRange(n == Select);
187 void NFeedInfo::typeChanged(int n)
189 _identLabel->setText(n == 2 ? tr("I&D") : tr("for &user"));
192 void NFeedInfo::parse()
194 if (_identEdit->text().isEmpty())
196 // Potential translation hack-up.
197 QString s = _identLabel->text().remove("&").split(" ").takeLast();
198 NFeedDialog::m_info(this, tr("Please enter %1").arg(s));
199 _identEdit->setFocus();
200 return;
203 QString type;
204 switch (_typeCombo->itemData(_typeCombo->currentIndex()).toInt())
206 case Uploads:
207 default:
208 type = "u";
209 break;
210 case Favorites:
211 type = "f";
212 break;
213 case Playlist:
214 type = "p";
215 break;
218 QStringList args = feed::to_args(_umphPath,
219 type,
220 _identEdit->text(),
221 _indexSpin->value(),
222 _maxSpin->value(),
223 _bgroup->checkedId() == All);
224 emit parse(args);
227 void NFeedInfo::reset()
229 _typeCombo->setCurrentIndex(0);
230 _indexSpin->setValue(1);
231 _maxSpin->setValue(25);
232 _identEdit->clear();
235 } // namespace nn
237 /* vim: set ts=2 sw=2 tw=72 expandtab: */