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/>.
22 #include <QMessageBox>
29 ScanDialog::ScanDialog(QWidget
*parent
)
30 : QDialog(parent
), errorOccurred(false)
34 itemsTree
->setColumnHidden(1, true);
38 mgr
= new QHttpManager(this);
39 mgr
->setProgressBar(progressBar
);
41 connect(mgr
, SIGNAL(fetchLink(QString
)),
42 this, SLOT(onFetchLink(QString
)));
44 connect(mgr
, SIGNAL(fetchFinished()),
45 this, SLOT(onFetchFinished()));
47 connect(mgr
, SIGNAL(fetchError(QString
)),
48 this, SLOT(onFetchError(QString
)));
52 ScanDialog::updateCount() {
54 QString(tr("Total: %1"))
55 .arg(Util::countItems(itemsTree
))
60 ScanDialog::enableWidgets(const bool state
/*=true*/) {
61 linkEdit
->setEnabled (state
);
62 titlesBox
->setEnabled(state
);
66 ScanDialog::onScan() {
68 if (!linkEdit
->isEnabled()) {
69 // Assumes it is disabled when we're scanning.
77 QString lnk
= linkEdit
->text().simplified();
82 if (!lnk
.startsWith("http://", Qt::CaseInsensitive
))
83 lnk
.insert(0,"http://");
91 progressBar
->setTextVisible(false);
92 scanButton
->setText(tr("&Abort"));
94 errorOccurred
= false;
100 ScanDialog::writeSettings() {
102 s
.beginGroup("ScanDialog");
103 s
.setValue("size", size());
108 ScanDialog::readSettings() {
110 s
.beginGroup("ScanDialog");
111 resize( s
.value("size", QSize(514,295)).toSize() );
116 ScanDialog::resetUI() {
118 scanButton
->setText(tr("&Scan"));
123 ScanDialog::onSelectAll() {
124 Util::checkAllItems(itemsTree
, Qt::Checked
);
128 ScanDialog::onInvert() {
129 Util::invertAllCheckableItems(itemsTree
);
133 ScanDialog::onFetchFinished() {
141 Scan::youtube(mgr
->getData(), found
);
143 const int size
= found
.size();
145 Util::appendLog(logEdit
,
146 QString(tr("Found %1 video links.")).arg(size
));
148 if ( !titlesBox
->checkState() ) {
150 for (int i
=0; i
<size
; ++i
) {
151 QTreeWidgetItem
*item
= new QTreeWidgetItem
;
152 item
->setCheckState(0, Qt::Unchecked
);
153 for (int j
=0; j
<2; ++j
)
154 item
->setText(j
, found
[i
]);
155 itemsTree
->addTopLevelItem(item
);
159 Util::appendLog(logEdit
, tr("Done."));
162 Util::appendLog(logEdit
,
163 tr("Fetch titles for the found videos."));
165 mgrt
= new QHttpManager(this);
167 connect(mgrt
, SIGNAL(fetchLink(QString
)),
168 this, SLOT(onFetchLink(QString
)));
170 connect(mgrt
, SIGNAL(fetchError(QString
)),
171 this, SLOT(onFetchError(QString
)));
173 // Note the use of different slot here.
175 connect(mgrt
, SIGNAL(fetchFinished()),
176 this, SLOT(onFetchTitlesFinished()));
178 // Do not set progressbar for this manager.
179 // We'll use fetched/expected for that instead.
182 expectedTitles
= size
;
184 progressBar
->setValue(fetchedTitles
);
185 progressBar
->setMaximum(expectedTitles
);
189 progressBar
->setTextVisible(true);
191 emit
onFetchTitlesFinished(); // Start iteration.
196 ScanDialog::onFetchTitlesFinished() {
203 if (fetchedTitles
>= 0) {
205 if (!Scan::title(mgrt
->getData(), title
))
206 title
= videoLinks
[fetchedTitles
]; // Fallback to link.
208 QTreeWidgetItem
*item
= new QTreeWidgetItem
;
209 item
->setCheckState(0, Qt::Unchecked
);
210 item
->setText(0, title
);
211 item
->setText(1, videoLinks
[fetchedTitles
]);
212 itemsTree
->addTopLevelItem(item
);
215 progressBar
->setValue(++fetchedTitles
);
217 if (fetchedTitles
== expectedTitles
) {
221 Util::appendLog(logEdit
, tr("Done."));
228 mgrt
->fetch(videoLinks
[fetchedTitles
]);
232 ScanDialog::onFetchError(QString errorString
) {
233 errorOccurred
= true;
234 Util::appendLog(logEdit
, errorString
);
238 ScanDialog::onFetchLink(QString url
) {
239 Util::appendLog(logEdit
, tr("Fetch ... ")+url
);