]> git.sur5r.net Git - minitube/blobdiff - src/MediaView.cpp
Imported Upstream version 1.2
[minitube] / src / MediaView.cpp
index 8735f8aaae1ee59ca8f7c952c5bb0224551b0b2f..739c595a048b4bafd7449409c2d1fa57f550f6cf 100644 (file)
@@ -3,7 +3,8 @@
 #include "networkaccess.h"
 #include "videowidget.h"
 #include "minisplitter.h"
-#include "flickcharm.h"
+#include "constants.h"
+#include "downloadmanager.h"
 
 namespace The {
     QMap<QString, QAction*>* globalActions();
@@ -81,7 +82,7 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) {
     videoAreaWidget = new VideoAreaWidget(this);
     videoAreaWidget->setMinimumSize(320,240);
 
-#ifdef Q_WS_MAC
+#ifdef APP_MAC
     // mouse autohide does not work on the Mac (no mouseMoveEvent)
     videoWidget = new Phonon::VideoWidget(this);
 #else
@@ -113,13 +114,12 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) {
     workaroundTimer->setInterval(3000);
     connect(workaroundTimer, SIGNAL(timeout()), SLOT(timerPlay()));
 
-    // TODO Enable this on touch devices
-    // FlickCharm *flickCharm = new FlickCharm(this);
-    // flickCharm->activateOn(listView);
-
-}
-
-MediaView::~MediaView() {
+#ifdef APP_DEMO
+    demoTimer = new QTimer(this);
+    demoTimer->setSingleShot(true);
+    demoTimer->setInterval(60000);
+    connect(demoTimer, SIGNAL(timeout()), SLOT(demoMessage()));
+#endif
 
 }
 
@@ -144,6 +144,10 @@ void MediaView::setMediaObject(Phonon::MediaObject *mediaObject) {
 void MediaView::search(SearchParams *searchParams) {
     reallyStopped = false;
 
+#ifdef APP_DEMO
+    demoTimer->stop();
+#endif
+
     videoAreaWidget->clear();
     workaroundTimer->stop();
     errorTimer->stop();
@@ -194,7 +198,7 @@ void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/)
         // but Phonon on Linux needs a little more help to start playback
         if (!reallyStopped) mediaObject->play();
 
-#ifdef Q_WS_MAC
+#ifdef APP_MAC
         // Workaround for Mac playback start problem
         if (!timerPlayFlag) {
             workaroundTimer->start();
@@ -269,6 +273,8 @@ void MediaView::activeRowChanged(int row) {
     QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(window());
     if (mainWindow) mainWindow->statusBar()->showMessage(video->title());
 
+    The::globalActions()->value("download")->setEnabled(DownloadManager::instance()->itemForVideo(video) == 0);
+
     // see you in gotStreamUrl...
 
 }
@@ -276,7 +282,15 @@ void MediaView::activeRowChanged(int row) {
 void MediaView::gotStreamUrl(QUrl streamUrl) {
     if (reallyStopped) return;
 
+    Video *video = static_cast<Video *>(sender());
+    if (!video) {
+        qDebug() << "Cannot get sender";
+        return;
+    }
+    video->disconnect(this);
+
     // go!
+    qDebug() << "Playing" << streamUrl.toString();
     mediaObject->setCurrentSource(streamUrl);
     mediaObject->play();
 
@@ -289,6 +303,11 @@ void MediaView::gotStreamUrl(QUrl streamUrl) {
         QModelIndex index = listModel->index(row, 0, QModelIndex());
         listView->scrollTo(index, QAbstractItemView::EnsureVisible);
     }
+
+#ifdef APP_DEMO
+    demoTimer->start();
+#endif
+
 }
 
 void MediaView::itemActivated(const QModelIndex &index) {
@@ -298,8 +317,8 @@ void MediaView::itemActivated(const QModelIndex &index) {
     else listModel->searchMore();
 }
 
-void MediaView::currentSourceChanged(const Phonon::MediaSource source) {
-    qDebug() << "Playing" << source.url().toString();
+void MediaView::currentSourceChanged(const Phonon::MediaSource /* source */ ) {
+
 }
 
 void MediaView::skipVideo() {
@@ -375,14 +394,26 @@ void MediaView::selectionChanged(const QItemSelection & /*selected*/, const QIte
 
 void MediaView::moveUpSelected() {
     if (!listView->selectionModel()->hasSelection()) return;
+
     QModelIndexList indexes = listView->selectionModel()->selectedIndexes();
+    qStableSort(indexes.begin(), indexes.end());
     listModel->move(indexes, true);
+
+    // set current index after row moves to something more intuitive
+    int row = indexes.first().row();
+    listView->selectionModel()->setCurrentIndex(listModel->index(row>1?row:1), QItemSelectionModel::NoUpdate);
 }
 
 void MediaView::moveDownSelected() {
     if (!listView->selectionModel()->hasSelection()) return;
+
     QModelIndexList indexes = listView->selectionModel()->selectedIndexes();
+    qStableSort(indexes.begin(), indexes.end(), qGreater<QModelIndex>());
     listModel->move(indexes, false);
+
+    // set current index after row moves to something more intuitive (respect 1 static item on bottom)
+    int row = indexes.first().row()+1, max = listModel->rowCount() - 2;
+    listView->selectionModel()->setCurrentIndex(listModel->index(row>max?max:row), QItemSelectionModel::NoUpdate);
 }
 
 void MediaView::showVideoContextMenu(QPoint point) {
@@ -423,3 +454,49 @@ void MediaView::saveSplitterState() {
     QSettings settings;
     settings.setValue("splitter", splitter->saveState());
 }
+
+#ifdef APP_DEMO
+void MediaView::demoMessage() {
+    if (mediaObject->state() != Phonon::PlayingState) return;
+    mediaObject->pause();
+
+    QMessageBox msgBox;
+    msgBox.setIconPixmap(QPixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+    msgBox.setText(tr("This is just the demo version of %1.").arg(Constants::APP_NAME));
+    msgBox.setInformativeText(tr("It allows you to test the application and see if it works for you."));
+    msgBox.setModal(true);
+
+    QPushButton *quitButton = msgBox.addButton(tr("Continue"), QMessageBox::RejectRole);
+    QPushButton *buyButton = msgBox.addButton(tr("Get the full version"), QMessageBox::ActionRole);
+
+    msgBox.exec();
+
+    if (msgBox.clickedButton() == buyButton) {
+        QDesktopServices::openUrl(QString(Constants::WEBSITE) + "#download");
+    } else {
+        mediaObject->play();
+    }
+}
+#endif
+
+void MediaView::downloadVideo() {
+    Video* video = listModel->activeVideo();
+    if (!video) return;
+
+    DownloadManager::instance()->addItem(video);
+
+    // TODO animate
+
+    The::globalActions()->value("downloads")->setVisible(true);
+
+    // The::globalActions()->value("download")->setEnabled(DownloadManager::instance()->itemForVideo(video) == 0);
+
+    QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(window());
+    QString message = tr("Downloading %1").arg(video->title());
+    if (mainWindow) mainWindow->statusBar()->showMessage(message);
+}
+
+void MediaView::fullscreen() {
+    videoAreaWidget->setParent(0);
+    videoAreaWidget->showFullScreen();
+}