From: Flavio Tordini Date: Mon, 8 Sep 2014 13:29:47 +0000 (+0200) Subject: Qt5 fixes X-Git-Tag: 2.3~28 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=bb7d7e58b8342dd088d4eeb80333f9c0555d08f3;p=minitube Qt5 fixes --- diff --git a/src/channelaggregator.cpp b/src/channelaggregator.cpp index f27f23e..092a993 100644 --- a/src/channelaggregator.cpp +++ b/src/channelaggregator.cpp @@ -119,7 +119,7 @@ void ChannelAggregator::finish() { if (t != s[0]) return; */ -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC if (newVideoCount > 0 && unwatchedCount > 0 && mac::canNotify()) { QString channelNames; const int total = updatedChannels.size(); diff --git a/src/channelmodel.cpp b/src/channelmodel.cpp index fb8cbdb..e51e4dc 100644 --- a/src/channelmodel.cpp +++ b/src/channelmodel.cpp @@ -73,6 +73,7 @@ ChannelModel::ItemTypes ChannelModel::typeForIndex(const QModelIndex &index) con } void ChannelModel::setQuery(const QString &query, const QSqlDatabase &db) { + beginResetModel(); channels.clear(); sqlError = QSqlError(); @@ -90,8 +91,7 @@ void ChannelModel::setQuery(const QString &query, const QSqlDatabase &db) { connect(user, SIGNAL(destroyed(QObject *)), SLOT(removeChannel(QObject *)), Qt::UniqueConnection); channels << user; } - - reset(); + endResetModel(); } QSqlError ChannelModel::lastError() const { diff --git a/src/channelsuggest.cpp b/src/channelsuggest.cpp index 6d0d1ff..00f6e90 100644 --- a/src/channelsuggest.cpp +++ b/src/channelsuggest.cpp @@ -31,8 +31,17 @@ ChannelSuggest::ChannelSuggest(QObject *parent) : Suggester(parent) { void ChannelSuggest::suggest(QString query) { QUrl url("http://www.youtube.com/results"); +#if QT_VERSION >= 0x050000 + { + QUrl &u = url; + QUrlQuery url; +#endif url.addQueryItem("search_type", "search_users"); url.addQueryItem("search_query", query); +#if QT_VERSION >= 0x050000 + u.setQuery(url); + } +#endif QObject *reply = The::http()->get(url); connect(reply, SIGNAL(data(QByteArray)), SLOT(handleNetworkData(QByteArray))); } diff --git a/src/database.cpp b/src/database.cpp index 37e8433..5d8a482 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -27,8 +27,12 @@ static const QString dbName = QLatin1String(Constants::UNIX_NAME) + ".db"; static Database *databaseInstance = 0; Database::Database() { - +#if QT_VERSION >= 0x050000 + QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation); +#else QString dataLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation); +#endif + QDir().mkpath(dataLocation); dbLocation = dataLocation + "/" + dbName; @@ -94,8 +98,11 @@ void Database::createDatabase() { } QString Database::getDbLocation() { - static QString dataLocation = QDesktopServices::storageLocation( - QDesktopServices::DataLocation); +#if QT_VERSION >= 0x050000 + static const QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation); +#else + static const QString dataLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation); +#endif return dataLocation + "/" + dbName; } diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 33d2ada..c42b074 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -161,17 +161,17 @@ void DownloadManager::gotStreamUrl(QUrl url) { void DownloadManager::itemFinished() { if (activeItems() == 0) emit finished(); #ifdef APP_EXTRA - DownloadItem *item = static_cast(sender()); - if (!item) { - qDebug() << "Cannot get item in" << __FUNCTION__; - return; - } - Video *video = item->getVideo(); - if (!video) return; - QString stats = tr("%1 downloaded in %2").arg( - DownloadItem::formattedFilesize(item->bytesTotal()), - DownloadItem::formattedTime(item->totalTime(), false)); - Extra::notify(tr("Download finished"), video->title(), stats); + DownloadItem *item = static_cast(sender()); + if (!item) { + qDebug() << "Cannot get item in" << __FUNCTION__; + return; + } + Video *video = item->getVideo(); + if (!video) return; + QString stats = tr("%1 downloaded in %2").arg( + DownloadItem::formattedFilesize(item->bytesTotal()), + DownloadItem::formattedTime(item->totalTime(), false)); + Extra::notify(tr("Download finished"), video->title(), stats); #endif } @@ -182,16 +182,29 @@ void DownloadManager::updateStatusMessage() { QString DownloadManager::defaultDownloadFolder() { // download in the Movies system folder +#if QT_VERSION >= 0x050000 + QString path = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation); +#else QString path = QDesktopServices::storageLocation(QDesktopServices::MoviesLocation); +#endif + QDir moviesDir(path); if (!moviesDir.exists()) { // fallback to Desktop +#if QT_VERSION >= 0x050000 + path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); +#else path = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation); +#endif QDir desktopDir(path); if (!desktopDir.exists()) { // fallback to Home +#if QT_VERSION >= 0x050000 + path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); +#else path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation); +#endif } } return path; diff --git a/src/downloadmodel.cpp b/src/downloadmodel.cpp index d5d36e9..89a5eb0 100644 --- a/src/downloadmodel.cpp +++ b/src/downloadmodel.cpp @@ -65,7 +65,8 @@ QVariant DownloadModel::data(const QModelIndex &index, int role) const { } void DownloadModel::sendReset() { - reset(); + beginResetModel(); + endResetModel(); } void DownloadModel::setHoveredRow(int row) { diff --git a/src/downloadsettings.cpp b/src/downloadsettings.cpp index 1afb2d5..333f8e1 100644 --- a/src/downloadsettings.cpp +++ b/src/downloadsettings.cpp @@ -61,12 +61,18 @@ void DownloadSettings::changeFolder() { QFileDialog* dialog = new QFileDialog(this); dialog->setFileMode(QFileDialog::Directory); dialog->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly); - dialog->setDirectory(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)); + QString path; +#if QT_VERSION >= 0x050000 + path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); +#else + path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation); +#endif + dialog->setDirectory(path); dialog->open(this, SLOT(folderChosen(const QString &))); #else QString folder = QFileDialog::getExistingDirectory(window(), tr("Choose the download location"), - QDesktopServices::storageLocation(QDesktopServices::HomeLocation), - QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly); + QDesktopServices::storageLocation(QDesktopServices::HomeLocation), + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly); folderChosen(folder); #endif } @@ -85,11 +91,15 @@ void DownloadSettings::folderChosen(const QString &dir) { void DownloadSettings::updateMessage() { QString path = DownloadManager::instance()->currentDownloadFolder(); - QString home = QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/"; +#if QT_VERSION >= 0x050000 + QString home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); +#else + QString home = QDesktopServices::storageLocation(QDesktopServices::HomeLocation); +#endif QString displayPath = path; - displayPath = displayPath.remove(home); + displayPath = displayPath.remove(home + "/"); message->setText( - tr("Downloading to: %1") - .arg("%2") - .arg(path, displayPath)); + tr("Downloading to: %1") + .arg("%2") + .arg(path, displayPath)); } diff --git a/src/global.h b/src/global.h index 5bac445..e54b5d5 100644 --- a/src/global.h +++ b/src/global.h @@ -148,8 +148,11 @@ namespace The { maybeSetSystemProxy(); nam = new QNetworkAccessManager(); QNetworkDiskCache *cache = new DiskCache(); - QString cacheLocation = QDesktopServices::storageLocation( - QDesktopServices::DataLocation); +#if QT_VERSION >= 0x050000 + QString cacheLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/qt5"; +#else + QString cacheLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation); +#endif cache->setCacheDirectory(cacheLocation); nam->setCache(cache); } diff --git a/src/jsfunctions.cpp b/src/jsfunctions.cpp index 45070f1..961d3f6 100644 --- a/src/jsfunctions.cpp +++ b/src/jsfunctions.cpp @@ -64,7 +64,11 @@ const QLatin1String & JsFunctions::jsFilename() { const QString & JsFunctions::jsPath() { static const QString path( + #if QT_VERSION >= 0x050000 + QStandardPaths::writableLocation(QStandardPaths::DataLocation) + #else QDesktopServices::storageLocation(QDesktopServices::DataLocation) + #endif + "/" + jsFilename()); return path; } diff --git a/src/main.cpp b/src/main.cpp index a9717af..a1232c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,13 +30,13 @@ $END_LICENSE */ #ifdef APP_EXTRA #include "extra.h" #endif -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC #include "mac_startup.h" #endif int main(int argc, char **argv) { -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC mac::MacMain(); // https://bugreports.qt-project.org/browse/QTBUG-32789 QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande"); @@ -92,7 +92,9 @@ int main(int argc, char **argv) { QTranslator translator; translator.load(QLocale::system(), QString(), QString(), localeDir); app.installTranslator(&translator); +#if QT_VERSION < 0x050000 QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8")); +#endif MainWindow mainWin; mainWin.show(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index df64261..e0a0fb8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -34,10 +34,10 @@ $END_LICENSE */ #include "searchparams.h" #include "videosource.h" #include "ytsearch.h" -#ifdef Q_WS_X11 +#ifdef Q_OS_LINUX #include "gnomeglobalshortcutbackend.h" #endif -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC #include "mac_startup.h" #include "macfullscreen.h" #include "macsupport.h" @@ -83,8 +83,10 @@ MainWindow::MainWindow() : aboutView(0), downloadView(0), regionsView(0), + #ifdef APP_PHONON mediaObject(0), audioOutput(0), + #endif m_fullscreen(false), m_compact(false) { @@ -150,9 +152,13 @@ MainWindow::~MainWindow() { } void MainWindow::lazyInit() { +#ifdef APP_PHONON initPhonon(); +#endif mediaView->initialize(); +#ifdef APP_PHONON mediaView->setMediaObject(mediaObject); +#endif qApp->processEvents(); // CLI @@ -170,11 +176,11 @@ void MainWindow::lazyInit() { // Global shortcuts GlobalShortcuts &shortcuts = GlobalShortcuts::instance(); -#ifdef Q_WS_X11 +#ifdef Q_OS_LINUX if (GnomeGlobalShortcutBackend::IsGsdAvailable()) shortcuts.setBackend(new GnomeGlobalShortcutBackend(&shortcuts)); #endif -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC mac::MacSetup(); #endif connect(&shortcuts, SIGNAL(PlayPause()), pauseAct, SLOT(trigger())); @@ -430,7 +436,7 @@ void MainWindow::createActions() { addAction(volumeMuteAct); QAction *definitionAct = new QAction(this); -#ifdef Q_WS_X11 +#ifdef Q_OS_LINUX definitionAct->setIcon(Utils::tintedIcon("video-display", QColor(0, 0, 0), QList() << QSize(16, 16))); #else @@ -571,6 +577,12 @@ void MainWindow::createActions() { actions->insert("open-in-browser", action); connect(action, SIGNAL(triggered()), mediaView, SLOT(openInBrowser())); +#ifdef APP_MAC_STORE + action = new QAction(tr("&Love %1? Rate it!").arg(Constants::NAME), this); + actions->insert("app-store", action); + connect(action, SIGNAL(triggered()), SLOT(rateOnAppStore())); +#endif + #ifdef APP_ACTIVATION Extra::createActivationAction(tr("Buy %1...").arg(Constants::NAME)); #endif @@ -667,6 +679,11 @@ void MainWindow::createMenus() { #endif helpMenu->addAction(The::globalActions()->value("report-issue")); helpMenu->addAction(aboutAct); + +#ifdef APP_MAC_STORE + helpMenu->addSeparator(); + helpMenu->addAction(The::globalActions()->value("app-store")); +#endif } void MainWindow::createToolBars() { @@ -690,7 +707,7 @@ void MainWindow::createToolBars() { mainToolBar->addAction(The::globalActions()->value("download")); bool addFullScreenAct = true; -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC addFullScreenAct = !mac::CanGoFullScreen(winId()); #endif if (addFullScreenAct) mainToolBar->addAction(fullscreenAct); @@ -730,6 +747,7 @@ void MainWindow::createToolBars() { mainToolBar->addAction(volumeMuteAct); +#ifdef APP_PHONON volumeSlider = new Phonon::VolumeSlider(this); volumeSlider->setMuteVisible(false); // qDebug() << volumeSlider->children(); @@ -741,6 +759,7 @@ void MainWindow::createToolBars() { // this makes the volume slider smaller volumeSlider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); mainToolBar->addWidget(volumeSlider); +#endif mainToolBar->addWidget(new Spacer()); @@ -759,9 +778,7 @@ void MainWindow::createToolBars() { mainToolBar->addWidget(searchWrapper); #else mainToolBar->addWidget(toolbarSearch); - Spacer* spacer = new Spacer(); - // spacer->setWidth(4); - mainToolBar->addWidget(spacer); + mainToolBar->addWidget(new Spacer()); #endif addToolBar(mainToolBar); @@ -842,8 +859,12 @@ void MainWindow::writeSettings() { settings.setValue("geometry", saveGeometry()); mediaView->saveSplitterState(); - settings.setValue("volume", audioOutput->volume()); - settings.setValue("volumeMute", audioOutput->isMuted()); +#ifdef APP_PHONON + if (audioOutput->volume() > 0.1) + settings.setValue("volume", audioOutput->volume()); + // settings.setValue("volumeMute", audioOutput->isMuted()); +#endif + settings.setValue("manualplay", The::globalActions()->value("manualplay")->isChecked()); } @@ -1013,6 +1034,7 @@ void MainWindow::showMedia(VideoSource *videoSource) { mediaView->setVideoSource(videoSource); } +#ifdef APP_PHONON void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */) { // qDebug() << "Phonon state: " << newState; @@ -1062,6 +1084,7 @@ void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState ; } } +#endif void MainWindow::stop() { mediaView->stop(); @@ -1069,7 +1092,7 @@ void MainWindow::stop() { } void MainWindow::resizeEvent(QResizeEvent*) { -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC if (mac::CanGoFullScreen(winId())) { bool isFullscreen = mac::IsFullScreen(winId()); if (isFullscreen != m_fullscreen) { @@ -1089,7 +1112,7 @@ void MainWindow::fullscreen() { if (compactViewAct->isChecked()) compactViewAct->toggle(); -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC WId handle = winId(); if (mac::CanGoFullScreen(handle)) { mainToolBar->setVisible(true); @@ -1109,7 +1132,7 @@ void MainWindow::fullscreen() { // geometry won't be saved writeSettings(); -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC MacSupport::enterFullScreen(this, views); #else mainToolBar->hide(); @@ -1119,7 +1142,7 @@ void MainWindow::fullscreen() { } else { // Exit full screen -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC MacSupport::exitFullScreen(this, views); #else mainToolBar->show(); @@ -1171,7 +1194,7 @@ void MainWindow::updateUIForFullscreen() { stopAct->setShortcuts(QList() << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::Key_MediaStop)); } -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC MacSupport::fullScreenActions(The::globalActions()->values(), m_fullscreen); #endif @@ -1187,7 +1210,7 @@ void MainWindow::updateUIForFullscreen() { } bool MainWindow::isReallyFullScreen() { -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC WId handle = winId(); if (mac::CanGoFullScreen(handle)) return mac::IsFullScreen(handle); else return isFullScreen(); @@ -1211,7 +1234,7 @@ void MainWindow::compactView(bool enable) { if (enable) { setMinimumSize(320, 180); -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC mac::RemoveFullScreenWindow(winId()); #endif writeSettings(); @@ -1240,7 +1263,7 @@ void MainWindow::compactView(bool enable) { } else { // unset minimum size setMinimumSize(0, 0); -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC mac::SetupFullScreenWindow(winId()); #endif settings.setValue(key, saveGeometry()); @@ -1256,7 +1279,7 @@ void MainWindow::compactView(bool enable) { // auto float on top floatOnTop(enable); -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC mac::compactMode(winId(), enable); #endif } @@ -1266,6 +1289,7 @@ void MainWindow::searchFocus() { toolbarSearch->setFocus(); } +#ifdef APP_PHONON void MainWindow::initPhonon() { // Phonon initialization if (mediaObject) delete mediaObject; @@ -1288,6 +1312,7 @@ void MainWindow::initPhonon() { audioOutput->setVolume(settings.value("volume", 1).toDouble()); // audioOutput->setMuted(settings.value("volumeMute").toBool()); } +#endif void MainWindow::tick(qint64 time) { if (time <= 0) { @@ -1300,6 +1325,7 @@ void MainWindow::tick(qint64 time) { currentTime->setText(formatTime(time)); // remaining time +#ifdef APP_PHONON const qint64 remainingTime = mediaObject->remainingTime(); currentTime->setStatusTip(tr("Remaining time: %1").arg(formatTime(remainingTime))); @@ -1309,6 +1335,7 @@ void MainWindow::tick(qint64 time) { if (totalTime > 0 && time > 0 && !slider->isSliderDown() && mediaObject->state() == Phonon::PlayingState) slider->setValue(time * slider->maximum() / totalTime); slider->blockSignals(false); +#endif } void MainWindow::totalTimeChanged(qint64 time) { @@ -1339,27 +1366,35 @@ QString MainWindow::formatTime(qint64 time) { } void MainWindow::volumeUp() { +#ifdef APP_PHONON qreal newVolume = volumeSlider->audioOutput()->volume() + .1; if (newVolume > volumeSlider->maximumVolume()) newVolume = volumeSlider->maximumVolume(); volumeSlider->audioOutput()->setVolume(newVolume); +#endif } void MainWindow::volumeDown() { +#ifdef APP_PHONON qreal newVolume = volumeSlider->audioOutput()->volume() - .1; if (newVolume < 0) newVolume = 0; volumeSlider->audioOutput()->setVolume(newVolume); +#endif } void MainWindow::volumeMute() { +#ifdef APP_PHONON volumeSlider->audioOutput()->setMuted(!volumeSlider->audioOutput()->isMuted()); +#endif } void MainWindow::volumeChanged(qreal newVolume) { +#ifdef APP_PHONON // automatically unmute when volume changes if (volumeSlider->audioOutput()->isMuted()) volumeSlider->audioOutput()->setMuted(false); +#endif statusBar()->showMessage(tr("Volume at %1%").arg((int)(newVolume*100))); } @@ -1603,6 +1638,14 @@ void MainWindow::hideMouse() { #endif } +#ifdef APP_MAC_STORE +void MainWindow::rateOnAppStore() { + QDesktopServices::openUrl(QUrl("macappstore://userpub.itunes.apple.com" + "/WebObjects/MZUserPublishing.woa/wa/addUserReview" + "?id=422006190&type=Purple+Software")); +} +#endif + void MainWindow::printHelp() { QString msg = QString("%1 %2\n\n").arg(Constants::NAME, Constants::VERSION); msg += "Usage: minitube [options]\n"; diff --git a/src/mainwindow.h b/src/mainwindow.h index e20bae0..67bb0c4 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -25,10 +25,12 @@ $END_LICENSE */ #if QT_VERSION >= 0x050000 #include #endif +#ifdef APP_PHONON #include #include #include #include +#endif #include "view.h" class HomeView; @@ -99,7 +101,9 @@ private slots: void updateUIForFullscreen(); void compactView(bool enable); void stop(); +#ifdef APP_PHONON void stateChanged(Phonon::State newState, Phonon::State oldState); +#endif void searchFocus(); void tick(qint64 time); void totalTimeChanged(qint64 time); @@ -128,8 +132,14 @@ private slots: void hideMouse(); +#ifdef APP_MAC_STORE + void rateOnAppStore(); +#endif + private: +#ifdef APP_PHONON void initPhonon(); +#endif void createActions(); void createMenus(); void createToolBars(); @@ -198,12 +208,14 @@ private: // phonon QSlider *slider; +#ifdef APP_PHONON #ifdef APP_PHONON_SEEK Phonon::SeekSlider *seekSlider; #endif Phonon::VolumeSlider *volumeSlider; Phonon::MediaObject *mediaObject; Phonon::AudioOutput *audioOutput; +#endif QLabel *currentTime; QLabel *totalTime; diff --git a/src/mediaview.cpp b/src/mediaview.cpp index c1a0846..5287af0 100644 --- a/src/mediaview.cpp +++ b/src/mediaview.cpp @@ -24,7 +24,6 @@ $END_LICENSE */ #include "loadingwidget.h" #include "videoareawidget.h" #include "networkaccess.h" -#include "videowidget.h" #include "minisplitter.h" #include "constants.h" #include "downloadmanager.h" @@ -101,8 +100,11 @@ void MediaView::initialize() { videoAreaWidget = new VideoAreaWidget(this); // videoAreaWidget->setMinimumSize(320,240); + +#ifdef APP_PHONON videoWidget = new Phonon::VideoWidget(this); videoAreaWidget->setVideoWidget(videoWidget); +#endif videoAreaWidget->setListModel(playlistModel); loadingWidget = new LoadingWidget(this); @@ -158,6 +160,7 @@ void MediaView::initialize() { connect(slider, SIGNAL(valueChanged(int)), SLOT(sliderMoved(int))); } +#ifdef APP_PHONON void MediaView::setMediaObject(Phonon::MediaObject *mediaObject) { this->mediaObject = mediaObject; Phonon::createPath(mediaObject, videoWidget); @@ -166,6 +169,7 @@ void MediaView::setMediaObject(Phonon::MediaObject *mediaObject) { SLOT(stateChanged(Phonon::State, Phonon::State))); connect(mediaObject, SIGNAL(aboutToFinish()), SLOT(aboutToFinish())); } +#endif SearchParams* MediaView::getSearchParams() { VideoSource *videoSource = playlistModel->getVideoSource(); @@ -282,6 +286,7 @@ void MediaView::handleError(QString /* message */) { QTimer::singleShot(500, this, SLOT(startPlaying())); } +#ifdef APP_PHONON void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) { if (newState == Phonon::PlayingState) videoAreaWidget->showVideo(); @@ -291,8 +296,10 @@ void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) handleError(mediaObject->errorString()); } } +#endif void MediaView::pause() { +#ifdef APP_PHONON switch( mediaObject->state() ) { case Phonon::PlayingState: mediaObject->pause(); @@ -301,6 +308,7 @@ void MediaView::pause() { mediaObject->play(); break; } +#endif } QRegExp MediaView::wordRE(QString s) { @@ -339,7 +347,9 @@ void MediaView::stop() { a->setEnabled(false); a->setVisible(false); +#ifdef APP_PHONON mediaObject->stop(); +#endif currentVideoId.clear(); QSlider *slider = MainWindow::instance()->getSlider(); @@ -356,7 +366,9 @@ void MediaView::activeRowChanged(int row) { errorTimer->stop(); +#ifdef APP_PHONON mediaObject->stop(); +#endif if (downloadItem) { downloadItem->stop(); delete downloadItem; @@ -433,7 +445,7 @@ void MediaView::gotStreamUrl(QUrl streamUrl) { currentVideoId = video->id(); -#ifdef Q_WS_X11_NO +#ifdef Q_OS_LINUX_NO mediaObject->setCurrentSource(streamUrl); mediaObject->play(); #else @@ -469,9 +481,11 @@ void MediaView::downloadStatusChanged() { // qDebug() << "Downloading"; if (downloadItem->offset() == 0) startPlaying(); else { +#ifdef APP_PHONON // qDebug() << "Seeking to" << downloadItem->offset(); mediaObject->seek(offsetToTime(downloadItem->offset())); mediaObject->play(); +#endif } break; case Starting: @@ -479,7 +493,7 @@ void MediaView::downloadStatusChanged() { break; case Finished: // qDebug() << "Finished" << mediaObject->state(); -#ifdef Q_WS_X11 +#ifdef Q_OS_LINUX // MainWindow::instance()->getSeekSlider()->setEnabled(mediaObject->isSeekable()); #endif break; @@ -509,9 +523,11 @@ void MediaView::startPlaying() { // go! QString source = downloadItem->currentFilename(); qDebug() << "Playing" << source << QFile::exists(source); +#ifdef APP_PHONON mediaObject->setCurrentSource(source); mediaObject->play(); -#ifdef Q_WS_X11 +#endif +#ifdef Q_OS_LINUX // MainWindow::instance()->getSeekSlider()->setEnabled(false); #endif @@ -528,7 +544,9 @@ void MediaView::itemActivated(const QModelIndex &index) { if (activeVideo && video && activeVideo == video) { // mediaObject->seek(0); sliderMoved(0); +#ifdef APP_PHONON mediaObject->play(); +#endif } else playlistModel->setActiveRow(index.row()); // the user doubleclicked on the "Search More" item @@ -567,6 +585,7 @@ void MediaView::skipBackward() { } void MediaView::aboutToFinish() { +#ifdef APP_PHONON qint64 currentTime = mediaObject->currentTime(); qint64 totalTime = mediaObject->totalTime(); qDebug() << __PRETTY_FUNCTION__ << currentTime << totalTime; @@ -575,10 +594,13 @@ void MediaView::aboutToFinish() { mediaObject->seek(currentTime); mediaObject->play(); } +#endif } void MediaView::playbackFinished() { if (stopped) return; + +#ifdef APP_PHONON const qint64 totalTime = mediaObject->totalTime(); const qint64 currentTime = mediaObject->currentTime(); qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime() << totalTime; @@ -592,21 +614,26 @@ void MediaView::playbackFinished() { stopAfterThisAction->setChecked(false); } else skip(); } +#endif } void MediaView::playbackResume() { if (stopped) return; +#ifdef APP_PHONON const qint64 currentTime = mediaObject->currentTime(); qDebug() << __PRETTY_FUNCTION__ << currentTime; if (currentTime > 0) mediaObject->seek(currentTime); mediaObject->play(); +#endif } void MediaView::openWebPage() { Video* video = playlistModel->activeVideo(); if (!video) return; +#ifdef APP_PHONON mediaObject->pause(); +#endif QDesktopServices::openUrl(video->webpage()); } @@ -631,7 +658,9 @@ void MediaView::copyVideoLink() { void MediaView::openInBrowser() { Video* video = playlistModel->activeVideo(); if (!video) return; +#ifdef APP_PHONON mediaObject->pause(); +#endif QDesktopServices::openUrl(video->getStreamUrl()); } @@ -704,8 +733,10 @@ void MediaView::saveSplitterState() { static QPushButton *continueButton; void MediaView::demoMessage() { +#ifdef APP_PHONON if (mediaObject->state() != Phonon::PlayingState) return; mediaObject->pause(); +#endif QMessageBox msgBox(this); msgBox.setIconPixmap(QPixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation)); @@ -730,7 +761,9 @@ void MediaView::demoMessage() { if (msgBox.clickedButton() == buyButton) { MainWindow::instance()->showActivationView(); } else { +#ifdef APP_PHONON mediaObject->play(); +#endif demoTimer->start(600000); } @@ -797,6 +830,7 @@ void MediaView::startDownloading() { } void MediaView::sliderMoved(int value) { +#ifdef APP_PHONON if (currentVideoSize <= 0 || !downloadItem || !mediaObject->isSeekable()) return; @@ -820,11 +854,14 @@ void MediaView::sliderMoved(int value) { // qDebug() << "simple seek"; mediaObject->seek(offsetToTime(offset)); } +#endif } qint64 MediaView::offsetToTime(qint64 offset) { +#ifdef APP_PHONON const qint64 totalTime = mediaObject->totalTime(); return ((offset * totalTime) / currentVideoSize); +#endif } void MediaView::findVideoParts() { @@ -901,9 +938,18 @@ void MediaView::shareViaTwitter() { Video* video = playlistModel->activeVideo(); if (!video) return; QUrl url("https://twitter.com/intent/tweet"); - url.addQueryItem("via", "minitubeapp"); - url.addQueryItem("text", video->title()); - url.addQueryItem("url", video->webpage().toString()); +#if QT_VERSION >= 0x050000 + { + QUrl &u = url; + QUrlQuery url; +#endif + url.addQueryItem("via", "minitubeapp"); + url.addQueryItem("text", video->title()); + url.addQueryItem("url", video->webpage().toString()); +#if QT_VERSION >= 0x050000 + u.setQuery(url); + } +#endif QDesktopServices::openUrl(url); } @@ -911,8 +957,17 @@ void MediaView::shareViaFacebook() { Video* video = playlistModel->activeVideo(); if (!video) return; QUrl url("https://www.facebook.com/sharer.php"); - url.addQueryItem("t", video->title()); - url.addQueryItem("u", video->webpage().toString()); +#if QT_VERSION >= 0x050000 + { + QUrl &u = url; + QUrlQuery url; +#endif + url.addQueryItem("t", video->title()); + url.addQueryItem("u", video->webpage().toString()); +#if QT_VERSION >= 0x050000 + u.setQuery(url); + } +#endif QDesktopServices::openUrl(url); } @@ -920,10 +975,19 @@ void MediaView::shareViaBuffer() { Video* video = playlistModel->activeVideo(); if (!video) return; QUrl url("http://bufferapp.com/add"); - url.addQueryItem("via", "minitubeapp"); - url.addQueryItem("text", video->title()); - url.addQueryItem("url", video->webpage().toString()); - url.addQueryItem("picture", video->thumbnailUrl()); +#if QT_VERSION >= 0x050000 + { + QUrl &u = url; + QUrlQuery url; +#endif + url.addQueryItem("via", "minitubeapp"); + url.addQueryItem("text", video->title()); + url.addQueryItem("url", video->webpage().toString()); + url.addQueryItem("picture", video->thumbnailUrl()); +#if QT_VERSION >= 0x050000 + u.setQuery(url); + } +#endif QDesktopServices::openUrl(url); } @@ -931,12 +995,21 @@ void MediaView::shareViaEmail() { Video* video = playlistModel->activeVideo(); if (!video) return; QUrl url("mailto:"); - url.addQueryItem("subject", video->title()); - QString body = video->title() + "\n" + - video->webpage().toString() + "\n\n" + - tr("Sent from %1").arg(Constants::NAME) + "\n" + - Constants::WEBSITE; - url.addQueryItem("body", body); +#if QT_VERSION >= 0x050000 + { + QUrl &u = url; + QUrlQuery url; +#endif + url.addQueryItem("subject", video->title()); + QString body = video->title() + "\n" + + video->webpage().toString() + "\n\n" + + tr("Sent from %1").arg(Constants::NAME) + "\n" + + Constants::WEBSITE; + url.addQueryItem("body", body); +#if QT_VERSION >= 0x050000 + u.setQuery(url); + } +#endif QDesktopServices::openUrl(url); } @@ -977,7 +1050,7 @@ void MediaView::updateSubscriptionAction(Video *video, bool subscribed) { subscribeAction->setStatusTip(subscribeTip); if (subscribed) { -#ifdef Q_WS_X11 +#ifdef Q_OS_LINUX static QIcon tintedIcon; if (tintedIcon.isNull()) { QList sizes; diff --git a/src/mediaview.h b/src/mediaview.h index 15e9a8d..29dcc5b 100644 --- a/src/mediaview.h +++ b/src/mediaview.h @@ -26,9 +26,11 @@ $END_LICENSE */ #include #endif #include +#ifdef APP_PHONON #include #include #include +#endif #include "view.h" class Video; @@ -42,7 +44,7 @@ class SidebarWidget; class VideoSource; namespace The { - QHash* globalActions(); +QHash* globalActions(); } class MediaView : public QWidget, public View { @@ -56,7 +58,9 @@ public: void appear(); void disappear(); +#ifdef APP_PHONON void setMediaObject(Phonon::MediaObject *mediaObject); +#endif const QList & getHistory() { return history; } int getHistoryIndex(); PlaylistModel* getPlaylistModel() { return playlistModel; } @@ -106,7 +110,9 @@ private slots: void gotStreamUrl(QUrl streamUrl); void handleError(QString message); // phonon +#ifdef APP_PHONON void stateChanged(Phonon::State newState, Phonon::State oldState); +#endif void aboutToFinish(); #ifdef APP_ACTIVATION void demoMessage(); @@ -135,9 +141,10 @@ private: VideoAreaWidget *videoAreaWidget; LoadingWidget *loadingWidget; - // phonon +#ifdef APP_PHONON Phonon::MediaObject *mediaObject; Phonon::VideoWidget *videoWidget; +#endif bool stopped; QTimer *errorTimer; diff --git a/src/minisplitter.cpp b/src/minisplitter.cpp index 02fdacf..8232da8 100644 --- a/src/minisplitter.cpp +++ b/src/minisplitter.cpp @@ -29,9 +29,9 @@ #include "minisplitter.h" -#include -#include -#include +#include +#include +#include class MiniSplitterHandle : public QSplitterHandle { diff --git a/src/minisplitter.h b/src/minisplitter.h index 51a1c01..23204ae 100644 --- a/src/minisplitter.h +++ b/src/minisplitter.h @@ -30,7 +30,7 @@ #ifndef MINISPLITTER_H #define MINISPLITTER_H -#include +#include QT_BEGIN_NAMESPACE class QSplitterHandle; diff --git a/src/networkaccess.cpp b/src/networkaccess.cpp index 98e44ca..6ed3e73 100644 --- a/src/networkaccess.cpp +++ b/src/networkaccess.cpp @@ -35,7 +35,7 @@ const QString USER_AGENT = QString(Constants::NAME) + " (" + Constants::WEBSITE + ")"; */ -const QString USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36"; +const QString USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36"; NetworkReply::NetworkReply(QNetworkReply *networkReply) : QObject(networkReply), diff --git a/src/painterutils.cpp b/src/painterutils.cpp index 54ee39e..8dcfdf4 100644 --- a/src/painterutils.cpp +++ b/src/painterutils.cpp @@ -90,7 +90,7 @@ void PainterUtils::paintBadge(QPainter *painter, const QString &text, bool cente #ifdef APP_WIN rect.adjust(0, -2, 0, 0); #endif -#ifdef Q_WS_X11 +#ifdef Q_OS_LINUX rect.adjust(0, -1, 0, 0); #endif painter->save(); diff --git a/src/playlistmodel.cpp b/src/playlistmodel.cpp index b3bf4cf..a3cad08 100644 --- a/src/playlistmodel.cpp +++ b/src/playlistmodel.cpp @@ -164,13 +164,13 @@ Video* PlaylistModel::activeVideo() const { } void PlaylistModel::setVideoSource(VideoSource *videoSource) { + beginResetModel(); while (!videos.isEmpty()) delete videos.takeFirst(); - m_activeVideo = 0; m_activeRow = -1; skip = 1; - reset(); + endResetModel(); this->videoSource = videoSource; connect(videoSource, SIGNAL(gotVideos(QList)), @@ -205,14 +205,15 @@ void PlaylistModel::searchNeeded() { } void PlaylistModel::abortSearch() { + beginResetModel(); while (!videos.isEmpty()) delete videos.takeFirst(); - reset(); // if (videoSource) videoSource->abort(); searching = false; m_activeRow = -1; m_activeVideo = 0; skip = 1; + endResetModel(); } void PlaylistModel::searchFinished(int total) { diff --git a/src/playlistview.cpp b/src/playlistview.cpp index 83c812e..2391f9f 100644 --- a/src/playlistview.cpp +++ b/src/playlistview.cpp @@ -136,7 +136,7 @@ bool PlaylistView::isShowMoreItem(const QModelIndex &index) { void PlaylistView::paintEvent(QPaintEvent *event) { QListView::paintEvent(event); -#ifndef Q_WS_X11 +#ifndef Q_OS_LINUX PainterUtils::topShadow(viewport()); #endif } diff --git a/src/qtsingleapplication/qtsingleapplication.cpp b/src/qtsingleapplication/qtsingleapplication.cpp index 2ab0bbd..3840ad8 100644 --- a/src/qtsingleapplication/qtsingleapplication.cpp +++ b/src/qtsingleapplication/qtsingleapplication.cpp @@ -47,7 +47,7 @@ #include "qtsingleapplication.h" #include "qtlocalpeer.h" -#include +#include /*! @@ -182,14 +182,16 @@ QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char * will be QCoreApplication::applicationFilePath(). \a argc, \a argv, and \a type are passed on to the QAppliation constructor. */ +/* QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type) : QApplication(argc, argv, type) { sysInit(); } +*/ -#if defined(Q_WS_X11) +#if defined(Q_OS_LINUX) /*! Special constructor for X11, ref. the documentation of QApplication's corresponding constructor. The application identifier diff --git a/src/qtsingleapplication/qtsingleapplication.h b/src/qtsingleapplication/qtsingleapplication.h index b73f5d6..29a4182 100644 --- a/src/qtsingleapplication/qtsingleapplication.h +++ b/src/qtsingleapplication/qtsingleapplication.h @@ -45,11 +45,11 @@ ****************************************************************************/ -#include +#include class QtLocalPeer; -#if defined(Q_WS_WIN) +#if defined(Q_OS_WIN) # if !defined(QT_QTSINGLEAPPLICATION_EXPORT) && !defined(QT_QTSINGLEAPPLICATION_IMPORT) # define QT_QTSINGLEAPPLICATION_EXPORT # elif defined(QT_QTSINGLEAPPLICATION_IMPORT) @@ -72,8 +72,8 @@ class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication public: QtSingleApplication(int &argc, char **argv, bool GUIenabled = true); QtSingleApplication(const QString &id, int &argc, char **argv); - QtSingleApplication(int &argc, char **argv, Type type); -#if defined(Q_WS_X11) + // QtSingleApplication(int &argc, char **argv, Type type); +#if defined(Q_OS_LINUX) QtSingleApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0); QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); diff --git a/src/searchlineedit.cpp b/src/searchlineedit.cpp index abd33ad..93008d0 100644 --- a/src/searchlineedit.cpp +++ b/src/searchlineedit.cpp @@ -41,11 +41,11 @@ #include "searchlineedit.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "autocomplete.h" diff --git a/src/searchlineedit.h b/src/searchlineedit.h index 9094435..3403df4 100644 --- a/src/searchlineedit.h +++ b/src/searchlineedit.h @@ -45,8 +45,8 @@ #include "urllineedit.h" #include "autocomplete.h" -#include -#include +#include +#include QT_BEGIN_NAMESPACE class QMenu; diff --git a/src/temporary.cpp b/src/temporary.cpp index 3f29d70..40bd542 100644 --- a/src/temporary.cpp +++ b/src/temporary.cpp @@ -22,19 +22,22 @@ $END_LICENSE */ #include "constants.h" static QList paths; -#ifdef Q_WS_X11 +#ifdef Q_OS_LINUX static QString userName; #endif Temporary::Temporary() { } QString Temporary::filename() { - +#if QT_VERSION >= 0x050000 + static const QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation); +#else static const QString tempDir = QDesktopServices::storageLocation(QDesktopServices::TempLocation); +#endif QString tempFile = tempDir + "/" + Constants::UNIX_NAME + "-" + QString::number(qrand()); -#ifdef Q_WS_X11 +#ifdef Q_OS_LINUX if (userName.isNull()) { userName = QString(getenv("USERNAME")); if (userName.isEmpty()) diff --git a/src/updatechecker.cpp b/src/updatechecker.cpp index af7c349..247fb53 100644 --- a/src/updatechecker.cpp +++ b/src/updatechecker.cpp @@ -26,7 +26,7 @@ $END_LICENSE */ #endif namespace The { - NetworkAccess* http(); +NetworkAccess* http(); } UpdateChecker::UpdateChecker() { @@ -34,35 +34,47 @@ UpdateChecker::UpdateChecker() { } void UpdateChecker::checkForUpdate() { - QUrl updateUrl(QLatin1String(Constants::WEBSITE) + "-ws/release.xml"); - updateUrl.addQueryItem("v", Constants::VERSION); + QUrl url(QLatin1String(Constants::WEBSITE) + "-ws/release.xml"); + +#if QT_VERSION >= 0x050000 + { + QUrl &u = url; + QUrlQuery url; +#endif + + url.addQueryItem("v", Constants::VERSION); #ifdef APP_MAC - updateUrl.addQueryItem("os", "mac"); + url.addQueryItem("os", "mac"); #endif #ifdef APP_WIN - updateUrl.addQueryItem("os", "win"); + url.addQueryItem("os", "win"); #endif #ifdef APP_ACTIVATION - QString t = "demo"; - if (Activation::instance().isActivated()) t = "active"; - updateUrl.addQueryItem("t", t); + QString t = "demo"; + if (Activation::instance().isActivated()) t = "active"; + url.addQueryItem("t", t); #endif #ifdef APP_MAC_STORE - updateUrl.addQueryItem("store", "mac"); + url.addQueryItem("store", "mac"); +#endif + +#if QT_VERSION >= 0x050000 + u.setQuery(url); + } #endif - QObject *reply = The::http()->get(updateUrl); + QObject *reply = The::http()->get(url); connect(reply, SIGNAL(data(QByteArray)), SLOT(requestFinished(QByteArray))); } void UpdateChecker::requestFinished(QByteArray data) { - UpdateCheckerStreamReader reader; - reader.read(data); - m_needUpdate = reader.needUpdate(); - m_remoteVersion = reader.remoteVersion(); - if (m_needUpdate && !m_remoteVersion.isEmpty()) emit newVersion(m_remoteVersion); + UpdateCheckerStreamReader reader; + reader.read(data); + m_needUpdate = reader.needUpdate(); + m_remoteVersion = reader.remoteVersion(); + if (m_needUpdate && !m_remoteVersion.isEmpty()) emit newVersion(m_remoteVersion); } QString UpdateChecker::remoteVersion() { diff --git a/src/urllineedit.cpp b/src/urllineedit.cpp index e7e5064..1b79fd0 100644 --- a/src/urllineedit.cpp +++ b/src/urllineedit.cpp @@ -42,17 +42,17 @@ #include "urllineedit.h" #include "searchlineedit.h" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include #include diff --git a/src/urllineedit.h b/src/urllineedit.h index a8e4a12..3cda04c 100644 --- a/src/urllineedit.h +++ b/src/urllineedit.h @@ -62,10 +62,10 @@ $END_LICENSE */ #ifndef URLLINEEDIT_H #define URLLINEEDIT_H -#include -#include -#include -#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE class QLineEdit; diff --git a/src/video.cpp b/src/video.cpp index ce35110..3c15efd 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -29,7 +29,7 @@ NetworkAccess* http(); } namespace { - static const QString jsNameChars = "a-zA-Z0-9\\$_"; +static const QString jsNameChars = "a-zA-Z0-9\\$_"; } Video::Video() : m_duration(0), @@ -70,7 +70,7 @@ void Video::setWebpage(QUrl webpage) { // QRegExp re("^((?:http://)?(?:\\w+\\.)?youtube\\.com/(?:(?:v/)|(?:(?:watch(?:\\.php)?)?\\?(?:.+&)?v=)))?([0-9A-Za-z_-]+)(?(1).+)?$"); QRegExp re("^https?://www\\.youtube\\.com/watch\\?v=([0-9A-Za-z_-]+).*"); bool match = re.exactMatch(m_webpage.toString()); - if (!match || re.numCaptures() < 1) { + if (!match) { qWarning() << QString("Cannot get video id for %1").arg(m_webpage.toString()); // emit errorStreamUrl(QString("Cannot get video id for %1").arg(m_webpage.toString())); // loadingStreamUrl = false; @@ -115,18 +115,29 @@ void Video::loadStreamUrl() { void Video::getVideoInfo() { static const QStringList elTypes = QStringList() << "&el=embedded" << "&el=detailpage" << "&el=vevo" << ""; - QUrl videoInfoUrl; + QUrl url; if (elIndex == elTypes.size()) { // qDebug() << "Trying special embedded el param"; - videoInfoUrl = QUrl("http://www.youtube.com/get_video_info"); - videoInfoUrl.addQueryItem("video_id", videoId); - videoInfoUrl.addQueryItem("el", "embedded"); - videoInfoUrl.addQueryItem("gl", "US"); - videoInfoUrl.addQueryItem("hl", "en"); - videoInfoUrl.addQueryItem("eurl", "https://youtube.googleapis.com/v/" + videoId); - videoInfoUrl.addQueryItem("asv", "3"); - videoInfoUrl.addQueryItem("sts", "1588"); + url = QUrl("http://www.youtube.com/get_video_info"); + +#if QT_VERSION >= 0x050000 + { + QUrl &u = url; + QUrlQuery url; +#endif + url.addQueryItem("video_id", videoId); + url.addQueryItem("el", "embedded"); + url.addQueryItem("gl", "US"); + url.addQueryItem("hl", "en"); + url.addQueryItem("eurl", "https://youtube.googleapis.com/v/" + videoId); + url.addQueryItem("asv", "3"); + url.addQueryItem("sts", "1588"); +#if QT_VERSION >= 0x050000 + u.setQuery(url); + } +#endif + } else if (elIndex > elTypes.size() - 1) { qWarning() << "Cannot get video info"; loadingStreamUrl = false; @@ -134,12 +145,12 @@ void Video::getVideoInfo() { return; } else { // qDebug() << "Trying el param:" << elTypes.at(elIndex) << elIndex; - videoInfoUrl = QUrl(QString( - "http://www.youtube.com/get_video_info?video_id=%1%2&ps=default&eurl=&gl=US&hl=en" - ).arg(videoId, elTypes.at(elIndex))); + url = QUrl(QString( + "http://www.youtube.com/get_video_info?video_id=%1%2&ps=default&eurl=&gl=US&hl=en" + ).arg(videoId, elTypes.at(elIndex))); } - QObject *reply = The::http()->get(videoInfoUrl); + QObject *reply = The::http()->get(url); connect(reply, SIGNAL(data(QByteArray)), SLOT(gotVideoInfo(QByteArray))); connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(errorVideoInfo(QNetworkReply*))); @@ -154,7 +165,7 @@ void Video::gotVideoInfo(QByteArray data) { QRegExp re = QRegExp("^.*&token=([^&]+).*$"); bool match = re.exactMatch(videoInfo); // handle regexp failure - if (!match || re.numCaptures() < 1) { + if (!match) { // qDebug() << "Cannot get token. Trying next el param"; // Don't panic! We're gonna try another magic "el" param elIndex++; @@ -164,7 +175,7 @@ void Video::gotVideoInfo(QByteArray data) { QString videoToken = re.cap(1); while (videoToken.contains('%')) - videoToken = QByteArray::fromPercentEncoding(videoToken.toAscii()); + videoToken = QByteArray::fromPercentEncoding(videoToken.toLatin1()); // qDebug() << "videoToken" << videoToken; this->videoToken = videoToken; @@ -172,7 +183,7 @@ void Video::gotVideoInfo(QByteArray data) { re = QRegExp("^.*&url_encoded_fmt_stream_map=([^&]+).*$"); match = re.exactMatch(videoInfo); // handle regexp failure - if (!match || re.numCaptures() < 1) { + if (!match) { // qDebug() << "Cannot get urlMap. Trying next el param"; // Don't panic! We're gonna try another magic "el" param elIndex++; @@ -231,10 +242,20 @@ void Video::parseFmtUrlMap(const QString &fmtUrlMap, bool fromWebPage) { } else { // qDebug() << "Loading webpage"; QUrl url("http://www.youtube.com/watch"); - url.addQueryItem("v", videoId); - url.addQueryItem("gl", "US"); - url.addQueryItem("hl", "en"); - url.addQueryItem("has_verified", "1"); + +#if QT_VERSION >= 0x050000 + { + QUrl &u = url; + QUrlQuery url; +#endif + url.addQueryItem("v", videoId); + url.addQueryItem("gl", "US"); + url.addQueryItem("hl", "en"); + url.addQueryItem("has_verified", "1"); +#if QT_VERSION >= 0x050000 + u.setQuery(url); + } +#endif QObject *reply = The::http()->get(url); connect(reply, SIGNAL(data(QByteArray)), SLOT(scrapeWebPage(QByteArray))); connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(errorVideoInfo(QNetworkReply*))); @@ -320,7 +341,7 @@ void Video::scrapeWebPage(QByteArray data) { QRegExp re(".*\"url_encoded_fmt_stream_map\":\\s+\"([^\"]+)\".*"); bool match = re.exactMatch(html); // on regexp failure, stop and report error - if (!match || re.numCaptures() < 1) { + if (!match) { qWarning() << "Error parsing video page"; // emit errorStreamUrl("Error parsing video page"); // loadingStreamUrl = false; diff --git a/src/videoareawidget.cpp b/src/videoareawidget.cpp index 14a5718..ee64a20 100644 --- a/src/videoareawidget.cpp +++ b/src/videoareawidget.cpp @@ -24,11 +24,11 @@ $END_LICENSE */ #ifdef APP_EXTRA #include "extra.h" #endif -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC #include "macutils.h" #endif -VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) { +VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent), videoWidget(0) { QBoxLayout *vLayout = new QVBoxLayout(this); vLayout->setMargin(0); vLayout->setSpacing(0); @@ -73,7 +73,8 @@ void VideoAreaWidget::setLoadingWidget(LoadingWidget *loadingWidget) { } void VideoAreaWidget::showVideo() { - stackedLayout->setCurrentWidget(videoWidget); + if (videoWidget) + stackedLayout->setCurrentWidget(videoWidget); loadingWidget->clear(); } @@ -140,7 +141,7 @@ void VideoAreaWidget::mouseMoveEvent(QMouseEvent *event) { !MainWindow::instance()->isReallyFullScreen(); if (event->buttons() & Qt::LeftButton && isNormalWindow) { QPoint p = event->globalPos() - dragPosition; -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC mac::moveWindowTo(window()->winId(), p.x(), p.y()); #else window()->move(p); diff --git a/src/ytsearch.cpp b/src/ytsearch.cpp index 010cbd5..68b22c6 100644 --- a/src/ytsearch.cpp +++ b/src/ytsearch.cpp @@ -42,8 +42,13 @@ void YTSearch::loadVideos(int max, int skip) { aborted = false; QUrl url("http://gdata.youtube.com/feeds/api/videos/"); - url.addQueryItem("v", "2"); +#if QT_VERSION >= 0x050000 +{ + QUrl &u = url; + QUrlQuery url; +#endif + url.addQueryItem("v", "2"); url.addQueryItem("max-results", QString::number(max)); url.addQueryItem("start-index", QString::number(skip)); @@ -99,6 +104,10 @@ void YTSearch::loadVideos(int max, int skip) { break; } +#if QT_VERSION >= 0x050000 + u.setQuery(url); + } +#endif QObject *reply = The::http()->get(url); connect(reply, SIGNAL(data(QByteArray)), SLOT(parseResults(QByteArray))); connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(requestError(QNetworkReply*))); diff --git a/src/ytsinglevideosource.cpp b/src/ytsinglevideosource.cpp index b4f4d30..05e5a32 100644 --- a/src/ytsinglevideosource.cpp +++ b/src/ytsinglevideosource.cpp @@ -42,6 +42,11 @@ void YTSingleVideoSource::loadVideos(int max, int skip) { if (skip == 1) s = "http://gdata.youtube.com/feeds/api/videos/" + videoId; else s = QString("http://gdata.youtube.com/feeds/api/videos/%1/related").arg(videoId); QUrl url(s); +#if QT_VERSION >= 0x050000 +{ + QUrl &u = url; + QUrlQuery url; +#endif url.addQueryItem("v", "2"); if (skip != 1) { @@ -49,6 +54,10 @@ void YTSingleVideoSource::loadVideos(int max, int skip) { url.addQueryItem("start-index", QString::number(skip-1)); } +#if QT_VERSION >= 0x050000 + u.setQuery(url); + } +#endif QObject *reply = The::http()->get(url); connect(reply, SIGNAL(data(QByteArray)), SLOT(parse(QByteArray))); connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(requestError(QNetworkReply*))); diff --git a/src/ytstandardfeed.cpp b/src/ytstandardfeed.cpp index 50e0674..ee5e003 100644 --- a/src/ytstandardfeed.cpp +++ b/src/ytstandardfeed.cpp @@ -41,6 +41,11 @@ void YTStandardFeed::loadVideos(int max, int skip) { if (!category.isEmpty()) s += "_" + category; QUrl url(s); +#if QT_VERSION >= 0x050000 +{ + QUrl &u = url; + QUrlQuery url; +#endif url.addQueryItem("v", "2"); if (feedId != "most_shared" && feedId != "on_the_web") { @@ -52,6 +57,10 @@ void YTStandardFeed::loadVideos(int max, int skip) { url.addQueryItem("max-results", QString::number(max)); url.addQueryItem("start-index", QString::number(skip)); +#if QT_VERSION >= 0x050000 + u.setQuery(url); + } +#endif QObject *reply = The::http()->get(url); connect(reply, SIGNAL(data(QByteArray)), SLOT(parse(QByteArray))); connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(requestError(QNetworkReply*))); diff --git a/src/ytuser.cpp b/src/ytuser.cpp index 5098f3f..29f851d 100644 --- a/src/ytuser.cpp +++ b/src/ytuser.cpp @@ -83,7 +83,16 @@ void YTUser::maybeLoadfromAPI() { loading = true; QUrl url("http://gdata.youtube.com/feeds/api/users/" + userId); - url.addQueryItem("v", "2"); +#if QT_VERSION >= 0x050000 + { + QUrl &u = url; + QUrlQuery url; +#endif + url.addQueryItem("v", "2"); +#if QT_VERSION >= 0x050000 + u.setQuery(url); + } +#endif QObject *reply = The::http()->get(url); connect(reply, SIGNAL(data(QByteArray)), SLOT(parseResponse(QByteArray))); connect(reply, SIGNAL(error(QNetworkReply*)), SLOT(requestError(QNetworkReply*))); @@ -122,7 +131,7 @@ void YTUser::loadThumbnail() { if (thumbnailUrl.isEmpty()) return; loadingThumbnail = true; -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN thumbnailUrl.replace(QLatin1String("https://"), QLatin1String("http://")); #endif @@ -133,8 +142,13 @@ void YTUser::loadThumbnail() { } const QString & YTUser::getThumbnailDir() { - static const QString thumbDir = QDesktopServices::storageLocation( - QDesktopServices::DataLocation) + "/channels/"; + static const QString thumbDir = + #if QT_VERSION >= 0x050000 + QStandardPaths::writableLocation(QStandardPaths::DataLocation); +#else + QDesktopServices::storageLocation(QDesktopServices::DataLocation); +#endif + + "/channels/"; return thumbDir; }