2 #include "playlistview.h"
3 #include "playlist/PrettyItemDelegate.h"
4 #include "networkaccess.h"
5 #include "videowidget.h"
6 #include "minisplitter.h"
8 #include "downloadmanager.h"
9 #include "downloaditem.h"
10 #include "MainWindow.h"
11 #include "temporary.h"
12 #include "sidebarwidget.h"
13 #include "playlistwidget.h"
14 #include "refinesearchwidget.h"
15 #include "sidebarwidget.h"
17 #include "macfullscreen.h"
21 NetworkAccess* http();
25 QMap<QString, QAction*>* globalActions();
26 QMap<QString, QMenu*>* globalMenus();
27 QNetworkAccessManager* networkAccessManager();
30 MediaView::MediaView(QWidget *parent) : QWidget(parent) {
32 reallyStopped = false;
35 QBoxLayout *layout = new QVBoxLayout();
38 splitter = new MiniSplitter(this);
39 splitter->setChildrenCollapsible(false);
41 listView = new PlaylistView(this);
42 listView->setItemDelegate(new PrettyItemDelegate(this));
43 listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
46 listView->setDragEnabled(true);
47 listView->setAcceptDrops(true);
48 listView->setDropIndicatorShown(true);
49 listView->setDragDropMode(QAbstractItemView::DragDrop);
52 listView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
53 listView->setFrameShape( QFrame::NoFrame );
54 listView->setAttribute(Qt::WA_MacShowFocusRect, false);
55 listView->setMinimumSize(320,240);
56 listView->setUniformItemSizes(true);
58 // respond to the user doubleclicking a playlist item
59 connect(listView, SIGNAL(activated(const QModelIndex &)), this, SLOT(itemActivated(const QModelIndex &)));
61 listModel = new ListModel(this);
62 connect(listModel, SIGNAL(activeRowChanged(int)), this, SLOT(activeRowChanged(int)));
63 // needed to restore the selection after dragndrop
64 connect(listModel, SIGNAL(needSelectionFor(QList<Video*>)), this, SLOT(selectVideos(QList<Video*>)));
65 listView->setModel(listModel);
67 connect(listView->selectionModel(),
68 SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & )),
69 this, SLOT(selectionChanged ( const QItemSelection & , const QItemSelection & )));
71 connect(listView, SIGNAL(authorPushed(QModelIndex)), SLOT(authorPushed(QModelIndex)));
73 sidebar = new SidebarWidget(this);
74 sidebar->setPlaylist(listView);
75 connect(sidebar->getRefineSearchWidget(), SIGNAL(searchRefined()),
77 connect(listModel, SIGNAL(haveSuggestions(const QStringList &)),
78 sidebar, SLOT(showSuggestions(const QStringList &)));
79 connect(sidebar, SIGNAL(suggestionAccepted(QString)),
80 MainWindow::instance(), SLOT(startToolbarSearch(QString)));
81 splitter->addWidget(sidebar);
83 videoAreaWidget = new VideoAreaWidget(this);
84 // videoAreaWidget->setMinimumSize(320,240);
85 videoWidget = new Phonon::VideoWidget(this);
86 videoAreaWidget->setVideoWidget(videoWidget);
87 videoAreaWidget->setListModel(listModel);
89 loadingWidget = new LoadingWidget(this);
90 videoAreaWidget->setLoadingWidget(loadingWidget);
92 splitter->addWidget(videoAreaWidget);
94 layout->addWidget(splitter);
97 splitter->setStretchFactor(0, 1);
98 splitter->setStretchFactor(1, 6);
100 // restore splitter state
102 splitter->restoreState(settings.value("splitter").toByteArray());
104 errorTimer = new QTimer(this);
105 errorTimer->setSingleShot(true);
106 errorTimer->setInterval(3000);
107 connect(errorTimer, SIGNAL(timeout()), SLOT(skipVideo()));
109 workaroundTimer = new QTimer(this);
110 workaroundTimer->setSingleShot(true);
111 workaroundTimer->setInterval(3000);
112 connect(workaroundTimer, SIGNAL(timeout()), SLOT(timerPlay()));
115 demoTimer = new QTimer(this);
116 demoTimer->setSingleShot(true);
117 connect(demoTimer, SIGNAL(timeout()), SLOT(demoMessage()));
122 void MediaView::initialize() {
123 connect(videoAreaWidget, SIGNAL(doubleClicked()), The::globalActions()->value("fullscreen"), SLOT(trigger()));
126 videoAreaWidget->setContextMenuPolicy(Qt::CustomContextMenu);
127 connect(videoAreaWidget, SIGNAL(customContextMenuRequested(QPoint)),
128 this, SLOT(showVideoContextMenu(QPoint)));
131 QAction* refineSearchAction = The::globalActions()->value("refine-search");
132 connect(refineSearchAction, SIGNAL(toggled(bool)),
133 sidebar, SLOT(toggleRefineSearch(bool)));
136 void MediaView::setMediaObject(Phonon::MediaObject *mediaObject) {
137 this->mediaObject = mediaObject;
138 Phonon::createPath(this->mediaObject, videoWidget);
139 connect(mediaObject, SIGNAL(finished()), this, SLOT(playbackFinished()));
140 connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
141 this, SLOT(stateChanged(Phonon::State, Phonon::State)));
142 connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
143 this, SLOT(currentSourceChanged(Phonon::MediaSource)));
144 // connect(mediaObject, SIGNAL(bufferStatus(int)), loadingWidget, SLOT(bufferStatus(int)));
145 connect(mediaObject, SIGNAL(aboutToFinish()), SLOT(aboutToFinish()));
148 void MediaView::search(SearchParams *searchParams) {
149 reallyStopped = false;
154 workaroundTimer->stop();
157 this->searchParams = searchParams;
159 // start serching for videos
160 listModel->search(searchParams);
162 sidebar->showPlaylist();
163 listView->setFocus();
165 QString keyword = searchParams->keywords();
166 QString display = keyword;
167 if (keyword.startsWith("http://") || keyword.startsWith("https://")) {
168 int separator = keyword.indexOf("|");
169 if (separator > 0 && separator + 1 < keyword.length()) {
170 display = keyword.mid(separator+1);
174 sidebar->getRefineSearchWidget()->setSearchParams(searchParams);
175 sidebar->hideSuggestions();
179 void MediaView::searchAgain() {
180 search(searchParams);
183 void MediaView::appear() {
184 listView->setFocus();
187 void MediaView::disappear() {
188 timerPlayFlag = true;
191 void MediaView::handleError(QString /* message */) {
193 QTimer::singleShot(500, this, SLOT(startPlaying()));
196 videoAreaWidget->showError(message);
197 skippedVideo = listModel->activeVideo();
198 // recover from errors by skipping to the next video
199 errorTimer->start(2000);
203 void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) {
204 // qDebug() << "Phonon state: " << newState;
205 // slider->setEnabled(newState == Phonon::PlayingState);
209 case Phonon::ErrorState:
210 qDebug() << "Phonon error:" << mediaObject->errorString() << mediaObject->errorType();
211 if (mediaObject->errorType() == Phonon::FatalError)
212 handleError(mediaObject->errorString());
215 case Phonon::PlayingState:
216 // qDebug("playing");
217 videoAreaWidget->showVideo();
220 case Phonon::StoppedState:
221 // qDebug("stopped");
222 // play() has already been called when setting the source
223 // but Phonon on Linux needs a little more help to start playback
224 // if (!reallyStopped) mediaObject->play();
227 // Workaround for Mac playback start problem
228 if (!timerPlayFlag) {
229 // workaroundTimer->start();
235 case Phonon::PausedState:
239 case Phonon::BufferingState:
243 case Phonon::LoadingState:
250 void MediaView::pause() {
251 // qDebug() << "pause() called" << mediaObject->state();
253 switch( mediaObject->state() ) {
254 case Phonon::PlayingState:
255 mediaObject->pause();
264 QRegExp MediaView::wordRE(QString s) {
265 return QRegExp("\\W" + s + "\\W?", Qt::CaseInsensitive);
268 void MediaView::stop() {
269 listModel->abortSearch();
270 reallyStopped = true;
272 videoAreaWidget->clear();
273 workaroundTimer->stop();
275 listView->selectionModel()->clearSelection();
277 downloadItem->stop();
281 The::globalActions()->value("refine-search")->setChecked(false);
284 void MediaView::activeRowChanged(int row) {
285 if (reallyStopped) return;
287 Video *video = listModel->videoAt(row);
290 // now that we have a new video to play
291 // stop all the timers
292 workaroundTimer->stop();
297 downloadItem->stop();
301 // slider->setMinimum(0);
303 // immediately show the loading widget
304 videoAreaWidget->showLoading(video);
306 connect(video, SIGNAL(gotStreamUrl(QUrl)), SLOT(gotStreamUrl(QUrl)), Qt::UniqueConnection);
307 // TODO handle signal in a proper slot and impl item error status
308 connect(video, SIGNAL(errorStreamUrl(QString)), SLOT(handleError(QString)), Qt::UniqueConnection);
310 video->loadStreamUrl();
312 // reset the timer flag
313 timerPlayFlag = false;
315 // video title in the statusbar
316 QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(window());
317 if (mainWindow) mainWindow->statusBar()->showMessage(video->title());
320 // ensure active item is visible
321 // int row = listModel->activeRow();
323 QModelIndex index = listModel->index(row, 0, QModelIndex());
324 listView->scrollTo(index, QAbstractItemView::EnsureVisible);
327 // enable/disable actions
328 The::globalActions()->value("download")->setEnabled(DownloadManager::instance()->itemForVideo(video) == 0);
329 The::globalActions()->value("skip")->setEnabled(true);
330 The::globalActions()->value("previous")->setEnabled(row > 0);
331 The::globalActions()->value("stopafterthis")->setEnabled(true);
333 // see you in gotStreamUrl...
337 void MediaView::gotStreamUrl(QUrl streamUrl) {
338 if (reallyStopped) return;
340 Video *video = static_cast<Video *>(sender());
342 qDebug() << "Cannot get sender";
345 video->disconnect(this);
347 QString tempFile = Temporary::filename();
349 Video *videoCopy = video->clone();
351 downloadItem->stop();
354 downloadItem = new DownloadItem(videoCopy, streamUrl, tempFile, this);
355 connect(downloadItem, SIGNAL(statusChanged()), SLOT(downloadStatusChanged()), Qt::UniqueConnection);
356 // connect(downloadItem, SIGNAL(progress(int)), SLOT(downloadProgress(int)));
357 connect(downloadItem, SIGNAL(bufferProgress(int)), loadingWidget, SLOT(bufferStatus(int)), Qt::UniqueConnection);
358 // connect(downloadItem, SIGNAL(finished()), SLOT(itemFinished()));
359 connect(video, SIGNAL(errorStreamUrl(QString)), SLOT(handleError(QString)), Qt::UniqueConnection);
360 connect(downloadItem, SIGNAL(error(QString)), SLOT(handleError(QString)), Qt::UniqueConnection);
361 downloadItem->start();
366 void MediaView::downloadProgress(int percent) {
367 MainWindow* mainWindow = dynamic_cast<MainWindow*>(window());
369 mainWindow->getSeekSlider()->setStyleSheet(" QSlider::groove:horizontal {"
370 "border: 1px solid #999999;"
371 // "border-left: 50px solid rgba(255, 0, 0, 128);"
373 "background: qlineargradient(x1:0, y1:0, x2:.5, y2:0, stop:0 rgba(255, 0, 0, 92), stop:"
374 + QString::number(percent/100.0) +
376 " rgba(255, 0, 0, 92), stop:" + QString::number((percent+1)/100.0) + " transparent, stop:1 transparent);"
379 "QSlider::handle:horizontal {"
380 "background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 #8f8f8f);"
381 "border: 1px solid #5c5c5c;"
385 "border-radius: 8px;"
393 void MediaView::downloadStatusChanged() {
394 switch(downloadItem->status()) {
399 // qDebug() << "Starting";
402 // qDebug() << "Finished" << mediaObject->state();
403 // if (mediaObject->state() == Phonon::StoppedState) startPlaying();
405 seekSlider->setEnabled(mediaObject->isSeekable());
409 // qDebug() << "Failed";
411 // qDebug() << "Idle";
416 void MediaView::startPlaying() {
417 if (reallyStopped) return;
424 QString source = downloadItem->currentFilename();
425 qDebug() << "Playing" << source;
426 mediaObject->setCurrentSource(source);
429 seekSlider->setEnabled(false);
432 // ensure we always have 10 videos ahead
433 listModel->searchNeeded();
435 // ensure active item is visible
436 int row = listModel->activeRow();
438 QModelIndex index = listModel->index(row, 0, QModelIndex());
439 listView->scrollTo(index, QAbstractItemView::EnsureVisible);
443 demoTimer->start(60000);
448 void MediaView::itemActivated(const QModelIndex &index) {
449 if (listModel->rowExists(index.row())) {
451 // if it's the current video, just rewind and play
452 Video *activeVideo = listModel->activeVideo();
453 Video *video = listModel->videoAt(index.row());
454 if (activeVideo && video && activeVideo == video) {
455 mediaObject->seek(0);
457 } else listModel->setActiveRow(index.row());
459 // the user doubleclicked on the "Search More" item
461 listModel->searchMore();
462 listView->selectionModel()->clearSelection();
466 void MediaView::currentSourceChanged(const Phonon::MediaSource /* source */ ) {
470 void MediaView::skipVideo() {
471 // skippedVideo is useful for DELAYED skip operations
472 // in order to be sure that we're skipping the video we wanted
473 // and not another one
475 if (listModel->activeVideo() != skippedVideo) {
476 qDebug() << "Skip of video canceled";
479 int nextRow = listModel->rowForVideo(skippedVideo);
481 if (nextRow == -1) return;
482 listModel->setActiveRow(nextRow);
486 void MediaView::skip() {
487 int nextRow = listModel->nextRow();
488 if (nextRow == -1) return;
489 listModel->setActiveRow(nextRow);
492 void MediaView::skipBackward() {
493 int prevRow = listModel->previousRow();
494 if (prevRow == -1) return;
495 listModel->setActiveRow(prevRow);
498 void MediaView::aboutToFinish() {
499 qint64 currentTime = mediaObject->currentTime();
500 qDebug() << __PRETTY_FUNCTION__ << currentTime;
501 if (currentTime + 10000 < mediaObject->totalTime()) {
502 // mediaObject->seek(mediaObject->currentTime());
503 // QTimer::singleShot(500, this, SLOT(playbackResume()));
504 mediaObject->seek(currentTime);
509 void MediaView::playbackFinished() {
510 qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime();
511 // qDebug() << "finished" << mediaObject->currentTime() << mediaObject->totalTime();
512 // add 10 secs for imprecise Phonon backends (VLC, Xine)
513 if (mediaObject->currentTime() + 10000 < mediaObject->totalTime()) {
514 // mediaObject->seek(mediaObject->currentTime());
515 QTimer::singleShot(500, this, SLOT(playbackResume()));
517 QAction* stopAfterThisAction = The::globalActions()->value("stopafterthis");
518 if (stopAfterThisAction->isChecked()) {
519 stopAfterThisAction->setChecked(false);
524 void MediaView::playbackResume() {
525 qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime();
526 mediaObject->seek(mediaObject->currentTime());
530 void MediaView::openWebPage() {
531 Video* video = listModel->activeVideo();
533 mediaObject->pause();
534 QDesktopServices::openUrl(video->webpage());
537 void MediaView::copyWebPage() {
538 Video* video = listModel->activeVideo();
540 QString address = video->webpage().toString();
541 QApplication::clipboard()->setText(address);
542 QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(window());
543 QString message = tr("You can now paste the YouTube link into another application");
544 if (mainWindow) mainWindow->statusBar()->showMessage(message);
547 void MediaView::copyVideoLink() {
548 Video* video = listModel->activeVideo();
550 QApplication::clipboard()->setText(video->getStreamUrl().toEncoded());
551 QString message = tr("You can now paste the video stream URL into another application")
552 + ". " + tr("The link will be valid only for a limited time.");
553 QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(window());
554 if (mainWindow) mainWindow->statusBar()->showMessage(message);
557 void MediaView::removeSelected() {
558 if (!listView->selectionModel()->hasSelection()) return;
559 QModelIndexList indexes = listView->selectionModel()->selectedIndexes();
560 listModel->removeIndexes(indexes);
563 void MediaView::selectVideos(QList<Video*> videos) {
564 foreach (Video *video, videos) {
565 QModelIndex index = listModel->indexForVideo(video);
566 listView->selectionModel()->select(index, QItemSelectionModel::Select);
567 listView->scrollTo(index, QAbstractItemView::EnsureVisible);
571 void MediaView::selectionChanged(const QItemSelection & /*selected*/, const QItemSelection & /*deselected*/) {
572 const bool gotSelection = listView->selectionModel()->hasSelection();
573 The::globalActions()->value("remove")->setEnabled(gotSelection);
574 The::globalActions()->value("moveUp")->setEnabled(gotSelection);
575 The::globalActions()->value("moveDown")->setEnabled(gotSelection);
578 void MediaView::moveUpSelected() {
579 if (!listView->selectionModel()->hasSelection()) return;
581 QModelIndexList indexes = listView->selectionModel()->selectedIndexes();
582 qStableSort(indexes.begin(), indexes.end());
583 listModel->move(indexes, true);
585 // set current index after row moves to something more intuitive
586 int row = indexes.first().row();
587 listView->selectionModel()->setCurrentIndex(listModel->index(row>1?row:1), QItemSelectionModel::NoUpdate);
590 void MediaView::moveDownSelected() {
591 if (!listView->selectionModel()->hasSelection()) return;
593 QModelIndexList indexes = listView->selectionModel()->selectedIndexes();
594 qStableSort(indexes.begin(), indexes.end(), qGreater<QModelIndex>());
595 listModel->move(indexes, false);
597 // set current index after row moves to something more intuitive (respect 1 static item on bottom)
598 int row = indexes.first().row()+1, max = listModel->rowCount() - 2;
599 listView->selectionModel()->setCurrentIndex(listModel->index(row>max?max:row), QItemSelectionModel::NoUpdate);
602 void MediaView::showVideoContextMenu(QPoint point) {
603 The::globalMenus()->value("video")->popup(videoWidget->mapToGlobal(point));
606 void MediaView::searchMostRelevant() {
607 searchParams->setSortBy(SearchParams::SortByRelevance);
608 search(searchParams);
611 void MediaView::searchMostRecent() {
612 searchParams->setSortBy(SearchParams::SortByNewest);
613 search(searchParams);
616 void MediaView::searchMostViewed() {
617 searchParams->setSortBy(SearchParams::SortByViewCount);
618 search(searchParams);
621 void MediaView::setPlaylistVisible(bool visible) {
622 if (splitter->widget(0)->isVisible() == visible) return;
623 splitter->widget(0)->setVisible(visible);
624 listView->setFocus();
627 bool MediaView::isPlaylistVisible() {
628 return splitter->widget(0)->isVisible();
631 void MediaView::timerPlay() {
632 // Workaround Phonon bug on Mac OSX
633 // qDebug() << mediaObject->currentTime();
634 if (mediaObject->currentTime() <= 0 && mediaObject->state() == Phonon::PlayingState) {
635 // qDebug() << "Mac playback workaround";
636 mediaObject->pause();
637 // QTimer::singleShot(1000, mediaObject, SLOT(play()));
642 void MediaView::saveSplitterState() {
644 settings.setValue("splitter", splitter->saveState());
649 static QPushButton *continueButton;
651 void MediaView::demoMessage() {
652 if (mediaObject->state() != Phonon::PlayingState) return;
653 mediaObject->pause();
655 QMessageBox msgBox(this);
656 msgBox.setIconPixmap(QPixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
657 msgBox.setText(tr("This is just the demo version of %1.").arg(Constants::NAME));
658 msgBox.setInformativeText(tr("It allows you to test the application and see if it works for you."));
659 msgBox.setModal(true);
660 // make it a "sheet" on the Mac
661 msgBox.setWindowModality(Qt::WindowModal);
663 continueButton = msgBox.addButton("5", QMessageBox::RejectRole);
664 continueButton->setEnabled(false);
665 QPushButton *buyButton = msgBox.addButton(tr("Get the full version"), QMessageBox::ActionRole);
667 QTimeLine *timeLine = new QTimeLine(6000, this);
668 timeLine->setCurveShape(QTimeLine::LinearCurve);
669 timeLine->setFrameRange(5, 0);
670 connect(timeLine, SIGNAL(frameChanged(int)), SLOT(updateContinueButton(int)));
675 if (msgBox.clickedButton() == buyButton) {
676 QDesktopServices::openUrl(QUrl(QString(Constants::WEBSITE) + "#download"));
679 demoTimer->start(600000);
686 void MediaView::updateContinueButton(int value) {
688 continueButton->setText(tr("Continue"));
689 continueButton->setEnabled(true);
691 continueButton->setText(QString::number(value));
697 void MediaView::downloadVideo() {
698 Video* video = listModel->activeVideo();
701 DownloadManager::instance()->addItem(video);
705 The::globalActions()->value("downloads")->setVisible(true);
707 // The::globalActions()->value("download")->setEnabled(DownloadManager::instance()->itemForVideo(video) == 0);
709 QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(window());
710 QString message = tr("Downloading %1").arg(video->title());
711 if (mainWindow) mainWindow->statusBar()->showMessage(message);
714 void MediaView::snapshot() {
715 QImage image = videoWidget->snapshot();
716 qDebug() << image.size();
718 const QPixmap& pixmap = QPixmap::grabWindow(videoWidget->winId());
719 // qDebug() << pixmap.size();
720 videoAreaWidget->showSnapshotPreview(pixmap);
723 void MediaView::fullscreen() {
724 videoAreaWidget->setParent(0);
725 videoAreaWidget->showFullScreen();
729 void MediaView::setSlider(QSlider *slider) {
730 this->slider = slider;
731 // slider->setEnabled(false);
732 slider->setTracking(false);
733 // connect(slider, SIGNAL(valueChanged(int)), SLOT(sliderMoved(int)));
736 void MediaView::sliderMoved(int value) {
737 qDebug() << __func__;
738 int sliderPercent = (value * 100) / (slider->maximum() - slider->minimum());
739 qDebug() << slider->minimum() << value << slider->maximum();
740 if (sliderPercent <= downloadItem->currentPercent()) {
741 qDebug() << sliderPercent << downloadItem->currentPercent();
742 mediaObject->seek(value);
748 void MediaView::seekTo(int value) {
749 qDebug() << __func__;
750 mediaObject->pause();
751 workaroundTimer->stop();
753 // mediaObject->clear();
755 QString tempDir = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
756 QString tempFile = tempDir + "/minitube" + QString::number(value) + ".mp4";
757 if (!QFile::remove(tempFile)) {
758 qDebug() << "Cannot remove temp file";
760 Video *videoCopy = downloadItem->getVideo()->clone();
761 QUrl streamUrl = videoCopy->getStreamUrl();
762 streamUrl.addQueryItem("begin", QString::number(value));
763 if (downloadItem) delete downloadItem;
764 downloadItem = new DownloadItem(videoCopy, streamUrl, tempFile, this);
765 connect(downloadItem, SIGNAL(statusChanged()), SLOT(downloadStatusChanged()));
766 // connect(downloadItem, SIGNAL(finished()), SLOT(itemFinished()));
767 downloadItem->start();
769 // slider->setMinimum(value);
775 void MediaView::findVideoParts() {
778 Video* video = listModel->activeVideo();
781 QString query = video->title();
783 static QString optionalSpace = "\\s*";
784 static QString staticCounterSeparators = "[\\/\\-]";
785 QString counterSeparators = "( of | " +
786 tr("of", "Used in video parts, as in '2 of 3'") +
787 " |" + staticCounterSeparators + ")";
789 // numbers from 1 to 15
790 static QString counterNumber = "([1-9]|1[0-5])";
792 // query.remove(QRegExp(counterSeparators + optionalSpace + counterNumber));
793 query.remove(QRegExp(counterNumber + optionalSpace + counterSeparators + optionalSpace + counterNumber));
794 query.remove(wordRE("pr?t\\.?" + optionalSpace + counterNumber));
795 query.remove(wordRE("ep\\.?" + optionalSpace + counterNumber));
796 query.remove(wordRE("part" + optionalSpace + counterNumber));
797 query.remove(wordRE("episode" + optionalSpace + counterNumber));
798 query.remove(wordRE(tr("part", "This is for video parts, as in 'Cool video - part 1'") +
799 optionalSpace + counterNumber));
800 query.remove(wordRE(tr("episode", "This is for video parts, as in 'Cool series - episode 1'") +
801 optionalSpace + counterNumber));
802 query.remove(QRegExp("[\\(\\)\\[\\]]"));
804 #define NUMBERS "one|two|three|four|five|six|seven|eight|nine|ten"
806 QRegExp englishNumberRE = QRegExp(QLatin1String(".*(") + NUMBERS + ").*", Qt::CaseInsensitive);
807 // bool numberAsWords = englishNumberRE.exactMatch(query);
808 query.remove(englishNumberRE);
810 QRegExp localizedNumberRE = QRegExp(QLatin1String(".*(") + tr(NUMBERS) + ").*", Qt::CaseInsensitive);
811 // if (!numberAsWords) numberAsWords = localizedNumberRE.exactMatch(query);
812 query.remove(localizedNumberRE);
814 SearchParams *searchParams = new SearchParams();
815 searchParams->setTransient(true);
816 searchParams->setKeywords(query);
817 searchParams->setAuthor(video->author());
820 if (!numberAsWords) {
821 qDebug() << "We don't have number as words";
822 // searchParams->setSortBy(SearchParams::SortByNewest);
823 // TODO searchParams->setReverseOrder(true);
824 // TODO searchParams->setMax(50);
828 search(searchParams);
832 void MediaView::shareViaTwitter() {
833 Video* video = listModel->activeVideo();
835 QUrl url("https://twitter.com/intent/tweet");
836 url.addQueryItem("via", "minitubeapp");
837 url.addQueryItem("text", video->title());
838 url.addQueryItem("url", video->webpage().toString());
839 QDesktopServices::openUrl(url);
842 void MediaView::shareViaFacebook() {
843 Video* video = listModel->activeVideo();
845 QUrl url("https://www.facebook.com/sharer.php");
846 url.addQueryItem("t", video->title());
847 url.addQueryItem("u", video->webpage().toString());
848 QDesktopServices::openUrl(url);
851 void MediaView::shareViaBuffer() {
852 Video* video = listModel->activeVideo();
854 QUrl url("http://bufferapp.com/add");
855 url.addQueryItem("via", "minitubeapp");
856 url.addQueryItem("text", video->title());
857 url.addQueryItem("url", video->webpage().toString());
858 if (!video->thumbnailUrls().isEmpty())
859 url.addQueryItem("picture", video->thumbnailUrls().first().toString());
860 QDesktopServices::openUrl(url);
863 void MediaView::shareViaEmail() {
864 Video* video = listModel->activeVideo();
867 url.addQueryItem("subject", video->title());
868 QString body = video->title() + "\n" +
869 video->webpage().toString() + "\n\n" +
870 tr("Sent from %1").arg(Constants::NAME) + "\n" +
872 url.addQueryItem("body", body);
873 QDesktopServices::openUrl(url);
876 void MediaView::authorPushed(QModelIndex index) {
877 Video* video = listModel->videoAt(index.row());
880 QString channel = video->author();
881 if (channel.isEmpty()) return;
883 SearchParams *searchParams = new SearchParams();
884 searchParams->setAuthor(channel);
885 searchParams->setSortBy(SearchParams::SortByNewest);
888 search(searchParams);