1 #include "MainWindow.h"
4 #include "iconloader/qticonloader.h"
7 MainWindow::MainWindow() {
13 history = new QStack<QWidget*>();
14 views = new QStackedWidget(this);
17 searchView = new SearchView(this);
18 connect(searchView, SIGNAL(search(QString)), this, SLOT(showMedia(QString)));
19 views->addWidget(searchView);
20 mediaView = new MediaView(this);
21 views->addWidget(mediaView);
23 // lazily initialized views
27 toolbarSearch = new SearchLineEdit(this);
28 toolbarSearch->setFont(qApp->font());
29 connect(toolbarSearch, SIGNAL(search(const QString&)), searchView, SLOT(watch(const QString&)));
37 // remove that useless menu/toolbar context menu
38 this->setContextMenuPolicy(Qt::NoContextMenu);
40 // mediaView init stuff thats needs actions
41 mediaView->initialize();
43 // restore window position
46 // show the initial view
47 showWidget(searchView);
49 setCentralWidget(views);
52 MainWindow::~MainWindow() {
56 void MainWindow::createActions() {
58 QMap<QString, QAction*> *actions = The::globalActions();
61 settingsAct = new QAction(tr("&Preferences..."), this);
62 settingsAct->setStatusTip(tr(QString("Configure ").append(Constants::APP_NAME).toUtf8()));
64 settingsAct->setMenuRole(QAction::PreferencesRole);
65 actions->insert("settings", settingsAct);
66 connect(settingsAct, SIGNAL(triggered()), this, SLOT(showSettings()));
69 backAct = new QAction(QIcon(":/images/go-previous.png"), tr("&Back"), this);
70 backAct->setEnabled(false);
71 backAct->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Left));
72 backAct->setStatusTip(tr("Go to the previous view"));
73 actions->insert("back", backAct);
74 connect(backAct, SIGNAL(triggered()), this, SLOT(goBack()));
76 stopAct = new QAction(QtIconLoader::icon("media-stop", QIcon(":/images/stop.png")), tr("&Stop"), this);
77 stopAct->setStatusTip(tr("Stop playback and go back to the search view"));
78 stopAct->setShortcut(QKeySequence(Qt::Key_Escape));
79 actions->insert("stop", stopAct);
80 connect(stopAct, SIGNAL(triggered()), this, SLOT(stop()));
82 skipAct = new QAction(QtIconLoader::icon("media-skip-forward", QIcon(":/images/skip.png")), tr("S&kip"), this);
83 skipAct->setStatusTip(tr("Skip to the next video"));
84 skipAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
85 skipAct->setEnabled(false);
86 actions->insert("skip", skipAct);
87 connect(skipAct, SIGNAL(triggered()), mediaView, SLOT(skip()));
89 pauseAct = new QAction(QtIconLoader::icon("media-pause", QIcon(":/images/pause.png")), tr("&Pause"), this);
90 pauseAct->setStatusTip(tr("Pause playback"));
91 pauseAct->setShortcut(QKeySequence(Qt::Key_Space));
92 pauseAct->setEnabled(false);
93 actions->insert("pause", pauseAct);
94 connect(pauseAct, SIGNAL(triggered()), mediaView, SLOT(pause()));
96 fullscreenAct = new QAction(QtIconLoader::icon("view-fullscreen", QIcon(":/images/view-fullscreen.png")), tr("&Full Screen"), this);
97 fullscreenAct->setStatusTip(tr("Go full screen"));
98 fullscreenAct->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Return));
99 fullscreenAct->setShortcutContext(Qt::ApplicationShortcut);
100 actions->insert("fullscreen", fullscreenAct);
101 connect(fullscreenAct, SIGNAL(triggered()), this, SLOT(fullscreen()));
103 compactViewAct = new QAction(tr("&Compact mode"), this);
104 compactViewAct->setStatusTip(tr("Hide the playlist and the toolbar"));
105 compactViewAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return));
106 compactViewAct->setCheckable(true);
107 compactViewAct->setChecked(false);
108 compactViewAct->setEnabled(false);
109 actions->insert("compactView", compactViewAct);
110 connect(compactViewAct, SIGNAL(toggled(bool)), this, SLOT(compactView(bool)));
112 // icon should be document-save but it is ugly
113 downloadAct = new QAction(QtIconLoader::icon("go-down", QIcon(":/images/go-down.png")), tr("&Download"), this);
114 downloadAct->setStatusTip(tr("Download this video"));
115 downloadAct->setShortcut(tr("Ctrl+S"));
116 downloadAct->setEnabled(false);
117 actions->insert("download", downloadAct);
118 connect(downloadAct, SIGNAL(triggered()), this, SLOT(download()));
120 webPageAct = new QAction(QtIconLoader::icon("internet-web-browser", QIcon(":/images/internet-web-browser.png")), tr("&YouTube"), this);
121 webPageAct->setStatusTip(tr("Open the YouTube video page"));
122 webPageAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Y));
123 webPageAct->setEnabled(false);
124 actions->insert("webpage", webPageAct);
125 connect(webPageAct, SIGNAL(triggered()), mediaView, SLOT(openWebPage()));
127 removeAct = new QAction(tr("&Remove"), this);
128 removeAct->setStatusTip(tr("Remove the selected videos from the playlist"));
129 QList<QKeySequence> shortcuts;
130 shortcuts << QKeySequence("Del") << QKeySequence("Backspace");
131 removeAct->setShortcuts(shortcuts);
132 removeAct->setEnabled(false);
133 actions->insert("remove", removeAct);
134 connect(removeAct, SIGNAL(triggered()), mediaView, SLOT(removeSelected()));
136 moveUpAct = new QAction(QtIconLoader::icon("go-up", QIcon(":/images/go-up.png")), tr("Move &Up"), this);
137 moveUpAct->setStatusTip(tr("Move up the selected videos in the playlist"));
138 moveUpAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
139 moveUpAct->setEnabled(false);
140 actions->insert("moveUp", moveUpAct);
141 connect(moveUpAct, SIGNAL(triggered()), mediaView, SLOT(moveUpSelected()));
143 moveDownAct = new QAction(QtIconLoader::icon("go-down", QIcon(":/images/go-down.png")), tr("Move &Down"), this);
144 moveDownAct->setStatusTip(tr("Move down the selected videos in the playlist"));
145 moveDownAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
146 moveDownAct->setEnabled(false);
147 actions->insert("moveDown", moveDownAct);
148 connect(moveDownAct, SIGNAL(triggered()), mediaView, SLOT(moveDownSelected()));
150 quitAct = new QAction(tr("&Quit"), this);
151 quitAct->setMenuRole(QAction::QuitRole);
152 quitAct->setShortcut(tr("Ctrl+Q"));
153 quitAct->setStatusTip(tr("Bye"));
154 actions->insert("quit", quitAct);
155 connect(quitAct, SIGNAL(triggered()), this, SLOT(quit()));
157 siteAct = new QAction(tr("&Website"), this);
158 siteAct->setShortcut(QKeySequence::HelpContents);
159 siteAct->setStatusTip(tr("%1 on the Web").arg(Constants::APP_NAME));
160 actions->insert("site", siteAct);
161 connect(siteAct, SIGNAL(triggered()), this, SLOT(visitSite()));
163 donateAct = new QAction(tr("&Donate via PayPal"), this);
164 donateAct->setStatusTip(tr("Please support the continued development of %1").arg(Constants::APP_NAME));
165 actions->insert("donate", donateAct);
166 connect(donateAct, SIGNAL(triggered()), this, SLOT(donate()));
168 aboutAct = new QAction(tr("&About"), this);
169 aboutAct->setMenuRole(QAction::AboutRole);
170 aboutAct->setStatusTip(tr("Info about %1").arg(Constants::APP_NAME));
171 actions->insert("about", aboutAct);
172 connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
174 searchFocusAct = new QAction(tr("&Search"), this);
175 searchFocusAct->setShortcut(QKeySequence::Find);
176 actions->insert("search", searchFocusAct);
177 connect(searchFocusAct, SIGNAL(triggered()), this, SLOT(searchFocus()));
178 addAction(searchFocusAct);
180 // common action properties
181 foreach (QAction *action, actions->values()) {
183 // add actions to the MainWindow so that they work
184 // when the menu is hidden
188 // unexperienced users tend to keep keys pressed for a "long" time
189 action->setAutoRepeat(false);
190 action->setToolTip(action->statusTip());
192 // make the actions work when video is fullscreen
193 action->setShortcutContext(Qt::ApplicationShortcut);
196 // OSX does not use icons in menus
197 action->setIconVisibleInMenu(false);
204 void MainWindow::createMenus() {
206 QMap<QString, QMenu*> *menus = The::globalMenus();
208 fileMenu = menuBar()->addMenu(tr("&Application"));
209 // menus->insert("file", fileMenu);
211 fileMenu->addAction(settingsAct);
212 fileMenu->addSeparator();
214 fileMenu->addAction(quitAct);
216 playlistMenu = menuBar()->addMenu(tr("&Playlist"));
217 menus->insert("playlist", playlistMenu);
218 playlistMenu->addAction(removeAct);
219 playlistMenu->addSeparator();
220 playlistMenu->addAction(moveUpAct);
221 playlistMenu->addAction(moveDownAct);
223 viewMenu = menuBar()->addMenu(tr("&Video"));
224 menus->insert("video", viewMenu);
225 // viewMenu->addAction(backAct);
226 viewMenu->addAction(stopAct);
227 viewMenu->addAction(pauseAct);
228 viewMenu->addAction(skipAct);
229 viewMenu->addSeparator();
230 viewMenu->addAction(webPageAct);
231 viewMenu->addSeparator();
232 viewMenu->addAction(downloadAct);
233 viewMenu->addAction(compactViewAct);
234 viewMenu->addAction(fullscreenAct);
236 helpMenu = menuBar()->addMenu(tr("&Help"));
237 helpMenu->addAction(siteAct);
238 helpMenu->addAction(donateAct);
239 helpMenu->addAction(aboutAct);
242 void MainWindow::createToolBars() {
244 setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
246 mainToolBar = new QToolBar(this);
247 mainToolBar->setFloatable(false);
248 mainToolBar->setMovable(false);
251 smallerFont.setPointSize(smallerFont.pointSize()*.85);
252 mainToolBar->setFont(smallerFont);
254 mainToolBar->setIconSize(QSize(32,32));
255 // mainToolBar->addAction(backAct);
256 mainToolBar->addAction(stopAct);
257 mainToolBar->addAction(pauseAct);
258 mainToolBar->addAction(skipAct);
259 mainToolBar->addAction(fullscreenAct);
261 seekSlider = new Phonon::SeekSlider(this);
262 seekSlider->setIconVisible(false);
263 Spacer *seekSliderSpacer = new Spacer(mainToolBar, seekSlider);
264 seekSliderSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
265 mainToolBar->addWidget(seekSliderSpacer);
267 volumeSlider = new Phonon::VolumeSlider(this);
268 // this makes the volume slider smaller
269 volumeSlider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
270 mainToolBar->addWidget(new Spacer(mainToolBar, volumeSlider));
272 mainToolBar->addWidget(new Spacer(mainToolBar, toolbarSearch));
274 addToolBar(mainToolBar);
277 void MainWindow::createStatusBar() {
278 currentTime = new QLabel(this);
279 statusBar()->addPermanentWidget(currentTime);
281 totalTime = new QLabel(this);
282 statusBar()->addPermanentWidget(totalTime);
284 // remove ugly borders on OSX
285 statusBar()->setStyleSheet("::item{border:0 solid}");
290 void MainWindow::readSettings() {
292 restoreGeometry(settings.value("geometry").toByteArray());
295 void MainWindow::writeSettings() {
296 // do not save geometry when in full screen
300 settings.setValue("geometry", saveGeometry());
303 void MainWindow::goBack() {
304 if ( history->size() > 1 ) {
306 QWidget *widget = history->pop();
311 void MainWindow::showWidget ( QWidget* widget ) {
313 setUpdatesEnabled(false);
315 // call hide method on the current view
316 View* oldView = dynamic_cast<View *> (views->currentWidget());
317 if (oldView != NULL) {
318 oldView->disappear();
321 // call show method on the new view
322 View* newView = dynamic_cast<View *> (widget);
323 if (newView != NULL) {
325 QMap<QString,QVariant> metadata = newView->metadata();
326 QString windowTitle = metadata.value("title").toString();
327 if (windowTitle.length())
328 windowTitle += " - ";
329 setWindowTitle(windowTitle + Constants::APP_NAME);
330 statusBar()->showMessage((metadata.value("description").toString()));
334 // backAct->setEnabled(history->size() > 1);
335 // settingsAct->setEnabled(widget != settingsView);
336 stopAct->setEnabled(widget == mediaView);
337 fullscreenAct->setEnabled(widget == mediaView);
338 compactViewAct->setEnabled(widget == mediaView);
339 webPageAct->setEnabled(widget == mediaView);
340 aboutAct->setEnabled(widget != aboutView);
341 // this is not the best place to enable downloads, but the user is informed
342 // if there really is no video is playing
343 downloadAct->setEnabled(widget == mediaView);
345 // cool toolbar on the Mac
346 // setUnifiedTitleAndToolBarOnMac(widget == mediaView);
348 // toolbar only for the mediaView
349 mainToolBar->setVisible(widget == mediaView && !compactViewAct->isChecked());
351 history->push(widget);
354 // crossfade only on OSX
355 // where we can be sure of video performance
356 fadeInWidget(views->currentWidget(), widget);
359 views->setCurrentWidget(widget);
361 setUpdatesEnabled(true);
364 void MainWindow::fadeInWidget(QWidget *oldWidget, QWidget *newWidget) {
365 if (faderWidget) faderWidget->close();
366 if (!oldWidget || !newWidget || oldWidget == mediaView || newWidget == mediaView) return;
367 QPixmap frozenView = QPixmap::grabWidget(oldWidget);
368 faderWidget = new FaderWidget(newWidget);
369 faderWidget->start(frozenView);
372 void MainWindow::about() {
374 aboutView = new AboutView(this);
375 views->addWidget(aboutView);
377 showWidget(aboutView);
380 void MainWindow::visitSite() {
381 QUrl url(Constants::WEBSITE);
382 statusBar()->showMessage(QString(tr("Opening %1").arg(url.toString())));
383 QDesktopServices::openUrl(url);
386 void MainWindow::donate() {
387 QUrl url(QString(Constants::WEBSITE) + "#donate");
388 statusBar()->showMessage(QString(tr("Opening %1").arg(url.toString())));
389 QDesktopServices::openUrl(url);
392 void MainWindow::quit() {
397 void MainWindow::closeEvent(QCloseEvent *event) {
399 QWidget::closeEvent(event);
402 void MainWindow::showSettings() {
404 settingsView = new SettingsView(this);
405 views->addWidget(settingsView);
407 showWidget(settingsView);
410 void MainWindow::showSearch() {
411 showWidget(searchView);
412 currentTime->clear();
416 void MainWindow::showMedia(QString query) {
418 mediaView->setMediaObject(mediaObject);
419 SearchParams *searchParams = new SearchParams();
420 searchParams->setKeywords(query);
421 mediaView->search(searchParams);
422 showWidget(mediaView);
425 void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */) {
427 // qDebug() << "Phonon state: " << newState;
431 case Phonon::ErrorState:
432 if (mediaObject->errorType() == Phonon::FatalError) {
433 statusBar()->showMessage(tr("Fatal error: %1").arg(mediaObject->errorString()));
435 statusBar()->showMessage(tr("Error: %1").arg(mediaObject->errorString()));
439 case Phonon::PlayingState:
440 pauseAct->setEnabled(true);
441 pauseAct->setIcon(QtIconLoader::icon("media-pause", QIcon(":/images/pause.png")));
442 pauseAct->setText(tr("&Pause"));
443 pauseAct->setStatusTip(tr("Pause playback"));
444 skipAct->setEnabled(true);
447 case Phonon::StoppedState:
448 pauseAct->setEnabled(false);
449 skipAct->setEnabled(false);
452 case Phonon::PausedState:
453 skipAct->setEnabled(true);
454 pauseAct->setEnabled(true);
455 pauseAct->setIcon(QtIconLoader::icon("media-play", QIcon(":/images/play.png")));
456 pauseAct->setText(tr("&Play"));
457 pauseAct->setStatusTip(tr("Resume playback"));
460 case Phonon::BufferingState:
461 case Phonon::LoadingState:
462 skipAct->setEnabled(true);
463 pauseAct->setEnabled(false);
464 currentTime->clear();
473 void MainWindow::stop() {
478 void MainWindow::fullscreen() {
480 setUpdatesEnabled(false);
483 // use setShortucs instead of setShortcut
484 // the latter seems not to work
485 QList<QKeySequence> shortcuts;
486 shortcuts << QKeySequence(Qt::ALT + Qt::Key_Return);
487 fullscreenAct->setShortcuts(shortcuts);
488 fullscreenAct->setText(tr("&Full Screen"));
489 stopAct->setShortcut(QKeySequence(Qt::Key_Escape));
490 if (m_maximized) showMaximized();
493 stopAct->setShortcut(QString(""));
494 QList<QKeySequence> shortcuts;
495 // for some reason it is important that ESC comes first
496 shortcuts << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::ALT + Qt::Key_Return);
497 fullscreenAct->setShortcuts(shortcuts);
498 fullscreenAct->setText(tr("Exit &Full Screen"));
499 m_maximized = isMaximized();
501 // save geometry now, if the user quits when in full screen
502 // geometry won't be saved
508 // No compact view action when in full screen
509 compactViewAct->setVisible(m_fullscreen);
510 // Also no Youtube action since it opens a new window
511 webPageAct->setVisible(m_fullscreen);
513 // Hide anything but the video
514 mediaView->setPlaylistVisible(m_fullscreen);
515 mainToolBar->setVisible(m_fullscreen);
516 statusBar()->setVisible(m_fullscreen);
517 menuBar()->setVisible(m_fullscreen);
519 m_fullscreen = !m_fullscreen;
521 setUpdatesEnabled(true);
524 void MainWindow::compactView(bool enable) {
526 setUpdatesEnabled(false);
528 // setUnifiedTitleAndToolBarOnMac(!enable);
529 mediaView->setPlaylistVisible(!enable);
530 mainToolBar->setVisible(!enable);
531 statusBar()->setVisible(!enable);
533 // ensure focus does not end up to the search box
534 // as it would steal the Space shortcut
535 toolbarSearch->setEnabled(!enable);
538 stopAct->setShortcut(QString(""));
539 QList<QKeySequence> shortcuts;
540 // for some reason it is important that ESC comes first
541 shortcuts << QKeySequence(Qt::CTRL + Qt::Key_Return) << QKeySequence(Qt::Key_Escape);
542 compactViewAct->setShortcuts(shortcuts);
544 compactViewAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return));
545 stopAct->setShortcut(QKeySequence(Qt::Key_Escape));
548 setUpdatesEnabled(true);
551 void MainWindow::searchFocus() {
552 QWidget *view = views->currentWidget();
553 if (view == mediaView) {
554 toolbarSearch->setFocus();
558 void MainWindow::initPhonon() {
559 // Phonon initialization
560 if (mediaObject) delete mediaObject;
561 if (audioOutput) delete audioOutput;
562 mediaObject = new Phonon::MediaObject(this);
563 mediaObject->setTickInterval(100);
564 connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
565 this, SLOT(stateChanged(Phonon::State, Phonon::State)));
566 connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
567 connect(mediaObject, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64)));
568 seekSlider->setMediaObject(mediaObject);
569 audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
570 volumeSlider->setAudioOutput(audioOutput);
571 Phonon::createPath(mediaObject, audioOutput);
574 void MainWindow::tick(qint64 time) {
579 QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60);
580 currentTime->setText(displayTime.toString("mm:ss"));
581 // qDebug() << "currentTime" << time << displayTime.toString("mm:ss");
584 void MainWindow::totalTimeChanged(qint64 time) {
589 QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60);
590 totalTime->setText(displayTime.toString("/ mm:ss"));
591 // qDebug() << "totalTime" << time << displayTime.toString("mm:ss");
594 void MainWindow::abortDownload() {
595 QProgressDialog* dlg = dynamic_cast<QProgressDialog*>(this->sender());
596 QMap<QNetworkReply*, DownloadResource>::iterator cur;
597 QMap<QNetworkReply*, DownloadResource>::iterator end;
598 // locate the DownloadResource by its dialog address and trigger abortion
599 for(cur=m_downloads.begin(), end=m_downloads.end(); cur!=end; cur++){
600 if(cur.value().dialog == dlg) cur.key()->abort();
604 void MainWindow::download() {
605 if(mediaObject == NULL || mediaObject->currentSource().url().isEmpty()){
606 // complain unless video source apperas to be valid
607 QMessageBox::critical(this, tr("No Video playing"), tr("You must first play the video you intent to download !"));
610 QString filename = QFileDialog::getSaveFileName(this,
611 tr("Save video as..."),
612 tr("minitube video.mp4"),
613 "Video File(*.avi *.mp4)"
615 if(!filename.isNull()) {
616 // open destination file and initialize download
617 DownloadResource res;
618 res.file = new QFile(filename);
619 if(res.file->open(QFile::WriteOnly) == true) {
620 res.dialog = new QProgressDialog(tr("Downloading: ") + res.file->fileName(),
621 tr("Abort Download"), 0, 100, this);
622 connect(res.dialog, SIGNAL(canceled()), this, SLOT(abortDownload()));
623 download(mediaObject->currentSource().url(), res);
625 QMessageBox::critical(this, tr("File creation failed"), res.file->errorString());
631 void MainWindow::download(const QUrl& url, const DownloadResource& res) {
632 // create and store request and connect the reply signals
633 QNetworkReply *r = The::networkAccessManager()->get(QNetworkRequest(url));
634 m_downloads.insert(r, res);
635 connect(r, SIGNAL(finished()), this, SLOT(replyFinished()));
636 connect(r, SIGNAL(readyRead()), this, SLOT(replyReadyRead()));
637 connect(r, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(replyError(QNetworkReply::NetworkError)));
638 connect(r, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(replyDownloadProgress(qint64,qint64)));
639 connect(r, SIGNAL(metaDataChanged()), this, SLOT(replyMetaDataChanged()));
642 void MainWindow::replyReadyRead() {
643 QNetworkReply* r = dynamic_cast<QNetworkReply*>(this->sender());
644 m_downloads[r].file->write(r->readAll());
647 void MainWindow::replyDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
648 QNetworkReply* r = dynamic_cast<QNetworkReply*>(this->sender());
649 if (bytesTotal > 0 && bytesReceived >0)
650 m_downloads[r].dialog->setValue( double(100.0/bytesTotal)*bytesReceived ); // pssst :-X
653 void MainWindow::replyError(QNetworkReply::NetworkError code) {
654 QNetworkReply* r = dynamic_cast<QNetworkReply*>(this->sender());
655 QMessageBox::critical(this, tr("Download failed"), r->errorString());
658 void MainWindow::replyFinished() {
659 QNetworkReply* r = dynamic_cast<QNetworkReply*>(this->sender());
660 m_downloads[r].dialog->close();
661 m_downloads[r].file->close();
662 delete m_downloads[r].file;
663 m_downloads.remove(r);
666 void MainWindow::replyMetaDataChanged() {
667 QNetworkReply* r = dynamic_cast<QNetworkReply*>(this->sender());
668 QUrl url = r->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
670 // redirect - request new url, but keep the resources
671 qDebug() << "redirecting to: " << url.toString();
672 download(url, m_downloads[r]);
673 m_downloads.remove(r);