createStatusBar();
initPhonon();
+ // mediaView->setSlider(slider);
mediaView->setMediaObject(mediaObject);
// remove that useless menu/toolbar context menu
mainToolBar->addWidget(new Spacer());
seekSlider = new Phonon::SeekSlider(this);
+#ifdef Q_WS_X11
+ seekSlider->setDisabled(true);
+#endif
seekSlider->setIconVisible(false);
seekSlider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
mainToolBar->addWidget(seekSlider);
mainToolBar->addWidget(new Spacer());
+/*
+ slider = new QSlider(this);
+ slider->setOrientation(Qt::Horizontal);
+ slider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
+ mainToolBar->addWidget(slider);
+*/
+
+ mainToolBar->addWidget(new Spacer());
+
totalTime = new QLabel(mainToolBar);
totalTime->setFont(smallerFont);
mainToolBar->addWidget(totalTime);
restoreGeometry(settings.value("geometry").toByteArray());
#ifdef APP_MAC
if (!isMaximized())
- move(x(), y() + mainToolBar->height() + 8);
+ move(x(), y() + 10);
#endif
setDefinitionMode(settings.value("definition", VideoDefinition::getDefinitionNames().first()).toString());
audioOutput->setVolume(settings.value("volume", 1).toDouble());
const qint64 remainingTime = mediaObject->remainingTime();
currentTime->setStatusTip(tr("Remaining time: %1").arg(formatTime(remainingTime)));
+ /*
+ slider->blockSignals(true);
+ slider->setValue(time/1000);
+ slider->blockSignals(false);
+ */
}
void MainWindow::totalTimeChanged(qint64 time) {
return;
}
totalTime->setText(formatTime(time));
+
+ /*
+ slider->blockSignals(true);
+ slider->setMaximum(time/1000);
+ slider->blockSignals(false);
+ */
+
}
QString MainWindow::formatTime(qint64 time) {
public:
MainWindow();
~MainWindow();
+ Phonon::SeekSlider* getSeekSlider() { return seekSlider; }
protected:
void closeEvent(QCloseEvent *);
// phonon
Phonon::SeekSlider *seekSlider;
+ // QSlider *slider;
Phonon::VolumeSlider *volumeSlider;
Phonon::MediaObject *mediaObject;
Phonon::AudioOutput *audioOutput;
#include "minisplitter.h"
#include "constants.h"
#include "downloadmanager.h"
+#include "downloaditem.h"
+#include "MainWindow.h"
+
+namespace The {
+ NetworkAccess* http();
+}
namespace The {
QMap<QString, QAction*>* globalActions();
MediaView::MediaView(QWidget *parent) : QWidget(parent) {
reallyStopped = false;
+ downloadItem = 0;
QBoxLayout *layout = new QHBoxLayout();
layout->setMargin(0);
workaroundTimer->stop();
errorTimer->stop();
+ mediaObject->pause();
+ if (downloadItem) {
+ delete downloadItem;
+ downloadItem = 0;
+ }
+
this->searchParams = searchParams;
// start serching for videos
listView->setFocus();
+
+ QString keyword = searchParams->keywords();
+ QString display = keyword;
+ if (keyword.startsWith("http://")) {
+ int separator = keyword.indexOf("|");
+ if (separator > 0 && separator + 1 < keyword.length()) {
+ display = keyword.mid(separator+1);
+ }
+ }
+ // tr("You're watching \"%1\"").arg(searchParams->keywords())
+
}
void MediaView::disappear() {
{
// qDebug() << "Phonon state: " << newState << oldState;
+ // slider->setEnabled(newState == Phonon::PlayingState);
switch (newState) {
case Phonon::ErrorState:
qDebug() << "Phonon error:" << mediaObject->errorString() << mediaObject->errorType();
- handleError(mediaObject->errorString());
+ if (mediaObject->errorType() == Phonon::FatalError)
+ handleError(mediaObject->errorString());
break;
case Phonon::PlayingState:
workaroundTimer->stop();
errorTimer->stop();
listView->selectionModel()->clearSelection();
+ if (downloadItem) {
+ delete downloadItem;
+ downloadItem = 0;
+ }
}
void MediaView::activeRowChanged(int row) {
workaroundTimer->stop();
errorTimer->stop();
+ mediaObject->pause();
+ if (downloadItem) {
+ delete downloadItem;
+ downloadItem = 0;
+ }
+ // slider->setMinimum(0);
+
// immediately show the loading widget
videoAreaWidget->showLoading(video);
}
video->disconnect(this);
+ QString tempDir = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
+ QString tempFile = tempDir + "/minitube.mp4";
+ if (!QFile::remove(tempFile)) {
+ qDebug() << "Cannot remove temp file";
+ }
+
+ Video *videoCopy = video->clone();
+ if (downloadItem) delete downloadItem;
+ downloadItem = new DownloadItem(videoCopy, streamUrl, tempFile, this);
+ connect(downloadItem, SIGNAL(statusChanged()), SLOT(downloadStatusChanged()));
+ // connect(downloadItem, SIGNAL(progress(int)), SLOT(downloadProgress(int)));
+ // connect(downloadItem, SIGNAL(finished()), SLOT(itemFinished()));
+ downloadItem->start();
+
+}
+
+/*
+void MediaView::downloadProgress(int percent) {
+ MainWindow* mainWindow = dynamic_cast<MainWindow*>(window());
+
+ mainWindow->getSeekSlider()->setStyleSheet(" QSlider::groove:horizontal {"
+ "border: 1px solid #999999;"
+ // "border-left: 50px solid rgba(255, 0, 0, 128);"
+ "height: 8px;"
+ "background: qlineargradient(x1:0, y1:0, x2:.5, y2:0, stop:0 rgba(255, 0, 0, 92), stop:"
+ + QString::number(percent/100.0) +
+
+ " rgba(255, 0, 0, 92), stop:" + QString::number((percent+1)/100.0) + " transparent, stop:1 transparent);"
+ "margin: 2px 0;"
+ "}"
+ "QSlider::handle:horizontal {"
+ "background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 #8f8f8f);"
+ "border: 1px solid #5c5c5c;"
+ "width: 16px;"
+ "height: 16px;"
+ "margin: -2px 0;"
+ "border-radius: 8px;"
+ "}"
+
+ );
+}
+
+*/
+
+void MediaView::downloadStatusChanged() {
+ switch(downloadItem->status()) {
+ case Downloading:
+ startPlaying();
+ break;
+ case Starting:
+ qDebug() << "Starting";
+ break;
+ case Finished:
+ qDebug() << "Finished";
+ break;
+ case Failed:
+ qDebug() << "Failed";
+ case Idle:
+ qDebug() << "Idle";
+ break;
+ }
+}
+
+void MediaView::startPlaying() {
+ if (reallyStopped) return;
+
// go!
- qDebug() << "Playing" << streamUrl.toString();
- mediaObject->setCurrentSource(streamUrl);
+ qDebug() << "Playing" << downloadItem->currentFilename();
+ mediaObject->setCurrentSource(downloadItem->currentFilename());
mediaObject->play();
// ensure we always have 10 videos ahead
void MediaView::copyVideoLink() {
Video* video = listModel->activeVideo();
if (!video) return;
- QApplication::clipboard()->setText(video->getStreamUrl().toString());
+ QApplication::clipboard()->setText(video->getStreamUrl().toEncoded());
QString message = tr("You can now paste the video stream URL into another application")
+ ". " + tr("The link will be valid only for a limited time.");
QMainWindow* mainWindow = dynamic_cast<QMainWindow*>(window());
videoAreaWidget->setParent(0);
videoAreaWidget->showFullScreen();
}
+
+/*
+void MediaView::setSlider(QSlider *slider) {
+ this->slider = slider;
+ // slider->setEnabled(false);
+ slider->setTracking(false);
+ // connect(slider, SIGNAL(valueChanged(int)), SLOT(sliderMoved(int)));
+}
+
+void MediaView::sliderMoved(int value) {
+ qDebug() << __func__;
+ int sliderPercent = (value * 100) / (slider->maximum() - slider->minimum());
+ qDebug() << slider->minimum() << value << slider->maximum();
+ if (sliderPercent <= downloadItem->currentPercent()) {
+ qDebug() << sliderPercent << downloadItem->currentPercent();
+ mediaObject->seek(value);
+ } else {
+ seekTo(value);
+ }
+}
+
+void MediaView::seekTo(int value) {
+ qDebug() << __func__;
+ mediaObject->pause();
+ workaroundTimer->stop();
+ errorTimer->stop();
+ // mediaObject->clear();
+
+ QString tempDir = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
+ QString tempFile = tempDir + "/minitube" + QString::number(value) + ".mp4";
+ if (!QFile::remove(tempFile)) {
+ qDebug() << "Cannot remove temp file";
+ }
+ Video *videoCopy = downloadItem->getVideo()->clone();
+ QUrl streamUrl = videoCopy->getStreamUrl();
+ streamUrl.addQueryItem("begin", QString::number(value));
+ if (downloadItem) delete downloadItem;
+ downloadItem = new DownloadItem(videoCopy, streamUrl, tempFile, this);
+ connect(downloadItem, SIGNAL(statusChanged()), SLOT(downloadStatusChanged()));
+ // connect(downloadItem, SIGNAL(finished()), SLOT(itemFinished()));
+ downloadItem->start();
+
+ // slider->setMinimum(value);
+
+}
+
+*/
#include "loadingwidget.h"
#include "videoareawidget.h"
+class DownloadItem;
+
namespace The {
QMap<QString, QAction*>* globalActions();
}
QMap<QString, QVariant> metadata() {
QMap<QString, QVariant> metadata;
if (searchParams) {
- metadata.insert("title", searchParams->keywords());
- metadata.insert("description", tr("You're watching \"%1\"").arg(searchParams->keywords()));
+ metadata.insert("title", "");
+ metadata.insert("description", "");
}
return metadata;
}
void setMediaObject(Phonon::MediaObject *mediaObject);
+ void setSlider(QSlider *slider);
public slots:
void search(SearchParams *searchParams);
#ifdef APP_DEMO
void demoMessage();
#endif
+ void startPlaying();
+ void downloadStatusChanged();
+
+ /*
+ void downloadProgress(int percent);
+ void sliderMoved(int value);
+ void seekTo(int value);
+ */
private:
QTimer *demoTimer;
#endif
+ DownloadItem *downloadItem;
+ // QSlider *slider;
+
};
#endif // __MEDIAVIEW_H__
emit statusChanged();
}
- m_status = Downloading;
if (-1 == m_file.write(m_reply->readAll())) {
/*
downloadInfoLabel->setText(tr("Error saving: %1")
*/
} else {
m_startedSaving = true;
- if (m_finishedDownloading)
+ if (m_status != Downloading) {
+ // m_status = Downloading;
+ // emit statusChanged();
+ } else if (m_finishedDownloading)
requestFinished();
}
}
percent = bytesReceived * 100 / bytesTotal;
}
+ // qDebug() << bytesReceived << bytesTotal;
+ if (m_status != Downloading
+ && bytesReceived > 1024 * 512
+ && bytesReceived > bytesTotal * .01) {
+ m_status = Downloading;
+ emit statusChanged();
+ }
+
emit progress(percent);
// emit statusChanged();
}
double currentSpeed() const;
int currentPercent() const { return percent; }
Video* getVideo() const { return video; }
+ QString currentFilename() const { return m_file.fileName(); }
DownloadItemStatus status() const { return m_status; }
static QString formattedFilesize(qint64 size);
static QString formattedSpeed(double speed);
NetworkAccess* http();
}
+/*
const QString USER_AGENT = QString(Constants::APP_NAME)
+ " " + Constants::VERSION
+ " (" + Constants::WEBSITE + ")";
+*/
+
+const QString USER_AGENT = "Mozilla/5.0 (X11; U; Linux x86; en-US; rv:1.9.2.12) Gecko/20101028 Firefox/3.6.12";
NetworkReply::NetworkReply(QNetworkReply *networkReply) : QObject(networkReply) {
this->networkReply = networkReply;
NetworkAccess::NetworkAccess( QObject* parent) : QObject( parent ) {}
-QNetworkReply* NetworkAccess::simpleGet(QUrl url, int operation) {
+QNetworkReply* NetworkAccess::manualGet(QNetworkRequest request, int operation) {
QNetworkAccessManager *manager = The::networkAccessManager();
- QNetworkRequest request(url);
- request.setRawHeader("User-Agent", USER_AGENT.toUtf8());
- request.setRawHeader("Connection", "Keep-Alive");
-
QNetworkReply *networkReply;
switch (operation) {
case QNetworkAccessManager::GetOperation:
- qDebug() << "GET" << url.toString();
+ qDebug() << "GET" << request.url().toEncoded();
networkReply = manager->get(request);
break;
case QNetworkAccessManager::HeadOperation:
- qDebug() << "HEAD" << url.toString();
+ qDebug() << "HEAD" << request.url().toEncoded();
networkReply = manager->head(request);
break;
this, SLOT(error(QNetworkReply::NetworkError)));
return networkReply;
+}
+
+QNetworkReply* NetworkAccess::simpleGet(QUrl url, int operation) {
+
+ QNetworkRequest request(url);
+ request.setRawHeader("User-Agent", USER_AGENT.toUtf8());
+ request.setRawHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
+ request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
+ request.setRawHeader("Accept-Language", "en-us,en;q=0.5");
+ // request.setRawHeader("Connection", "Keep-Alive");
+ return manualGet(request, operation);
}
NetworkReply* NetworkAccess::get(const QUrl url) {
#ifndef NETWORKACCESS_H
#define NETWORKACCESS_H
+#include <QtCore>
#include <QtNetwork>
namespace The {
public:
NetworkAccess( QObject* parent=0);
+ QNetworkReply* manualGet(QNetworkRequest request, int operation = QNetworkAccessManager::GetOperation);
QNetworkReply* simpleGet(QUrl url, int operation = QNetworkAccessManager::GetOperation);
NetworkReply* get(QUrl url);
NetworkReply* head(QUrl url);