diff options
Diffstat (limited to 'lumina-fm')
-rw-r--r-- | lumina-fm/BackgroundWorker.cpp | 11 | ||||
-rw-r--r-- | lumina-fm/MainUI.cpp | 120 | ||||
-rw-r--r-- | lumina-fm/MainUI.h | 26 | ||||
-rw-r--r-- | lumina-fm/lumina-fm.pro | 9 | ||||
-rw-r--r-- | lumina-fm/main.cpp | 23 |
5 files changed, 106 insertions, 83 deletions
diff --git a/lumina-fm/BackgroundWorker.cpp b/lumina-fm/BackgroundWorker.cpp index 1e6ef28d..9b3804d5 100644 --- a/lumina-fm/BackgroundWorker.cpp +++ b/lumina-fm/BackgroundWorker.cpp @@ -1,7 +1,7 @@ #include "BackgroundWorker.h" #include <LuminaXDG.h> -#include <Phonon/BackendCapabilities> +#include <QMediaServiceSupportedFormatsInterface> #include <QImageReader> BackgroundWorker::BackgroundWorker() : QObject(){ @@ -26,12 +26,9 @@ void BackgroundWorker::startDirChecks(QString path){ //Now check for multimedia files if(multiFilter.isEmpty()){ - //Initial Run - load supported multimedia extensions - QStringList mimes = Phonon::BackendCapabilities::availableMimeTypes(); - mimes = mimes.filter("audio/") + mimes.filter("video/"); - for(int i=0; i<mimes.length(); i++){ - multiFilter << LXDG::findFilesForMime(mimes[i]); - } + //Initial Run - load supported multimedia extensions + // (Auto-detection of supported types broken in Qt5 - just use everythings for now) + multiFilter = LXDG::findAVFileExtensions(); multiFilter.removeDuplicates(); qDebug() << "Supported Multimedia Formats:" << multiFilter; } diff --git a/lumina-fm/MainUI.cpp b/lumina-fm/MainUI.cpp index 6b369e9b..03e7a533 100644 --- a/lumina-fm/MainUI.cpp +++ b/lumina-fm/MainUI.cpp @@ -65,20 +65,20 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->menuView->addAction(listWA); ui->menuView->addAction(icoWA); //Setup the special Phonon widgets - mediaObj = new Phonon::MediaObject(this); - mediaObj->setTickInterval(200); //1/5 second ticks for updates - videoDisplay = new Phonon::VideoWidget(this); + mediaObj = new QMediaPlayer(this); + mediaObj->setVolume(100); + mediaObj->setNotifyInterval(500); //only every 1/2 second update + videoDisplay = new QVideoWidget(this); videoDisplay->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); ui->videoLayout->addWidget(videoDisplay); - Phonon::createPath(mediaObj, videoDisplay); + mediaObj->setVideoOutput(videoDisplay); videoDisplay->setVisible(false); - audioOut = new Phonon::AudioOutput(Phonon::VideoCategory, this); - Phonon::createPath(mediaObj, audioOut); - playerSlider = new Phonon::SeekSlider(this); - playerSlider->setMediaObject(mediaObj); + playerSlider = new QSlider(this); + playerSlider->setOrientation(Qt::Horizontal); ui->videoControlLayout->insertWidget(4, playerSlider); ui->tool_player_stop->setEnabled(false); //nothing to stop yet ui->tool_player_pause->setVisible(false); //nothing to pause yet + playerSlider->setEnabled(false); //nothing to seek yet //Setup any specialty keyboard shortcuts nextTabLShort = new QShortcut( QKeySequence(tr("Shift+Left")), this); nextTabRShort = new QShortcut( QKeySequence(tr("Shift+Right")), this); @@ -232,10 +232,16 @@ void MainUI::setupConnections(){ connect(ui->tool_player_play, SIGNAL(clicked()), this, SLOT(playerStart())); connect(ui->tool_player_stop, SIGNAL(clicked()), this, SLOT(playerStop())); connect(ui->combo_player_list, SIGNAL(currentIndexChanged(int)), this, SLOT(playerFileChanged()) ); - connect(mediaObj, SIGNAL(finished()), this, SLOT(playerFinished()) ); - connect(mediaObj, SIGNAL(tick(qint64)), this, SLOT(playerTimeChanged(qint64)) ); - connect(mediaObj, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(playerStateChanged(Phonon::State, Phonon::State)) ); - connect(mediaObj, SIGNAL(hasVideoChanged(bool)), this, SLOT(playerVideoAvailable(bool)) ); + connect(playerSlider, SIGNAL(sliderPressed()), this, SLOT(playerSliderHeld()) ); + connect(playerSlider, SIGNAL(sliderReleased()), this, SLOT(playerSliderChanged()) ); + connect(playerSlider, SIGNAL(valueChanged(int)), this, SLOT(playerSliderMoved(int)) ); + connect(mediaObj, SIGNAL(durationChanged(qint64)), this, SLOT(playerDurationChanged(qint64)) ); + connect(mediaObj, SIGNAL(seekableChanged(bool)), playerSlider, SLOT(setEnabled(bool)) ); + connect(mediaObj, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(playerStatusChanged(QMediaPlayer::MediaStatus)) ); + connect(mediaObj, SIGNAL(positionChanged(qint64)), this, SLOT(playerTimeChanged(qint64)) ); + connect(mediaObj, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(playerStateChanged(QMediaPlayer::State)) ); + connect(mediaObj, SIGNAL(videoAvailableChanged(bool)), this, SLOT(playerVideoAvailable(bool)) ); + connect(mediaObj, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(playerError()) ); //Special Keyboard Shortcuts connect(nextTabLShort, SIGNAL(activated()), this, SLOT( prevTab() ) ); connect(nextTabRShort, SIGNAL(activated()), this, SLOT( nextTab() ) ); @@ -391,7 +397,7 @@ void MainUI::setCurrentDir(QString dir){ ui->tool_goToPlayer->setVisible(false); ui->tool_goToRestore->setVisible(false); ui->tool_goToImages->setVisible(false); - if(olddir==rawdir){ + if(olddir!=rawdir){ emit DirChanged(rawdir); //This will be automatically run when a new dir is loaded } if(isUserWritable){ ui->label_dir_stats->setText(""); } @@ -937,24 +943,29 @@ void MainUI::restoreItems(){ void MainUI::playerStart(){ if(ui->stackedWidget->currentWidget()!=ui->page_audioPlayer){ return; } //don't play if not in the player - if(mediaObj->state()==Phonon::PausedState){ + if(mediaObj->state()==QMediaPlayer::PausedState \ + && mediaObj->currentMedia().canonicalUrl().fileName()==ui->combo_player_list->currentText() ){ mediaObj->play(); - }else{ // if(mediaObj->state()==Phonon::StoppedState || mediaObj->state()==Phonon::ErrorState || (playerFile->fileName().section("/",-1) != ui->combo_player_list->currentText()) || playerFile->isOpen() ){ + }else{ mediaObj->stop(); //Get the selected file path QString filePath = getCurrentDir(); if(!filePath.endsWith("/")){ filePath.append("/"); } filePath.append( ui->combo_player_list->currentText() ); - //if(playerFile->isOpen()){ playerFile->close(); } - //playerFile->setFileName(filePath); - //if(playerFile->open(QIODevice::ReadOnly)){ - mediaObj->setCurrentSource( QUrl(filePath) ); - playerSlider->setMediaObject(mediaObj); + mediaObj->setMedia( QUrl::fromLocalFile(filePath) ); + playerTTime.clear(); + playerSlider->setEnabled(mediaObj->isSeekable()); mediaObj->play(); - //} } } +void MainUI::playerError(){ + QString msg = QString(tr("Error Playing File: %1")); + msg = msg.arg( mediaObj->currentMedia().canonicalUrl().fileName() ); + msg.append("\n"+mediaObj->errorString()); + ui->label_player_novideo->setText(msg); +} + void MainUI::playerStop(){ mediaObj->stop(); } @@ -965,51 +976,48 @@ void MainUI::playerPause(){ void MainUI::playerNext(){ ui->combo_player_list->setCurrentIndex( ui->combo_player_list->currentIndex()+1); + if(mediaObj->state()!=QMediaPlayer::StoppedState){ playerStart(); } } void MainUI::playerPrevious(){ ui->combo_player_list->setCurrentIndex( ui->combo_player_list->currentIndex()-1); + if(mediaObj->state()!=QMediaPlayer::StoppedState){ playerStart(); } } void MainUI::playerFinished(){ - //playerFile->close(); if(ui->combo_player_list->currentIndex()<(ui->combo_player_list->count()-1) && ui->check_player_gotonext->isChecked()){ ui->combo_player_list->setCurrentIndex( ui->combo_player_list->currentIndex()+1 ); + QTimer::singleShot(0,this,SLOT(playerStart())); }else{ ui->label_player_novideo->setText(tr("Finished")); } } -void MainUI::playerStateChanged(Phonon::State newstate, Phonon::State oldstate){ +void MainUI::playerStatusChanged(QMediaPlayer::MediaStatus stat){ + //Only use this for end-of-file detection - use the state detection otherwise + if(stat == QMediaPlayer::EndOfMedia){ + if(!mediaObj->isMuted()){ playerFinished(); } //make sure it is not being seeked right now + } +} + +void MainUI::playerStateChanged(QMediaPlayer::State newstate){ //This function keeps track of updating the visuals of the player bool running = false; bool showVideo = false; QString msg; switch(newstate){ - case Phonon::LoadingState: + case QMediaPlayer::PlayingState: running=true; - ui->label_player_novideo->setText(tr("Loading File...")); - break; - case Phonon::PlayingState: - running=true; - showVideo = mediaObj->hasVideo(); - msg = mediaObj->metaData(Phonon::TitleMetaData).join(" "); + showVideo = mediaObj->isVideoAvailable(); + msg = "";//mediaObj->metaData(Phonon::TitleMetaData).join(" "); if(msg.simplified().isEmpty()){ msg = ui->combo_player_list->currentText(); } ui->label_player_novideo->setText(tr("Playing:")+"\n"+msg); break; - case Phonon::BufferingState: - running=true; - showVideo=true; //don't blank the screen - break; - case Phonon::PausedState: + case QMediaPlayer::PausedState: showVideo=videoDisplay->isVisible(); //don't change the screen break; - case Phonon::StoppedState: - if(oldstate==Phonon::LoadingState){ mediaObj->play(); } - else{ ui->label_player_novideo->setText(tr("Stopped")); } - break; - case Phonon::ErrorState: - ui->label_player_novideo->setText(tr("Error Playing File")+"\n("+mediaObj->errorString()+")"); + case QMediaPlayer::StoppedState: + ui->label_player_novideo->setText(tr("Stopped")); break; } ui->tool_player_play->setVisible(!running); @@ -1024,20 +1032,34 @@ void MainUI::playerVideoAvailable(bool showVideo){ videoDisplay->setVisible(showVideo); } +void MainUI::playerDurationChanged(qint64 dur){ + if(dur < 0){ return; } //not ready yet + playerSlider->setMaximum(mediaObj->duration()); + playerTTime = msToText(dur); +} + void MainUI::playerTimeChanged(qint64 ctime){ - if(playerTTime=="0:00" || playerTTime.isEmpty()){ playerTTime = msToText(mediaObj->totalTime()); } //only calculate as necessary - //qDebug() << "Time:" << msToText(ctime) << playerTTime << mediaObj->isSeekable() << mediaObj->hasVideo(); - ui->label_player_runstats->setText( msToText(ctime)+"/"+playerTTime ); + if(mediaObj->isMuted() || playerTTime.isEmpty() ){ return; } //currently being moved + playerSlider->setSliderPosition(ctime); +} + +void MainUI::playerSliderMoved(int val){ + ui->label_player_runstats->setText( msToText(val)+"/"+playerTTime ); + if(mediaObj->isMuted()){ mediaObj->setPosition(playerSlider->value()); } //currently seeking +} + +void MainUI::playerSliderHeld(){ + mediaObj->setMuted(true); + mediaObj->pause(); +} +void MainUI::playerSliderChanged(){ + if(mediaObj->state()==QMediaPlayer::PausedState){ mediaObj->play(); } + mediaObj->setMuted(false); } void MainUI::playerFileChanged(){ ui->tool_player_next->setEnabled( ui->combo_player_list->count() > (ui->combo_player_list->currentIndex()+1) ); ui->tool_player_prev->setEnabled( (ui->combo_player_list->currentIndex()-1) >= 0 ); - if(ui->stackedWidget->currentWidget()!=ui->page_audioPlayer){ return; } //don't play if not in the player - //If one is playing, so ahead and start playing the new selection - if(ui->check_player_gotonext->isChecked() ){ - QTimer::singleShot(0,this,SLOT(playerStart())); - } } //---------------------------------- diff --git a/lumina-fm/MainUI.h b/lumina-fm/MainUI.h index 87a52668..1cc26830 100644 --- a/lumina-fm/MainUI.h +++ b/lumina-fm/MainUI.h @@ -40,13 +40,9 @@ #include <QUrl> #include <QThread> -//Phonon widgets -//#include <Phonon/BackendCapabilities> -#include <Phonon/MediaObject> -#include <Phonon/VideoWidget> -#include <Phonon/AudioOutput> -#include <Phonon/SeekSlider> -#include <Phonon/MediaSource> +//Multimedia Widgets +#include <QVideoWidget> +#include <QMediaPlayer> // libLumina includes #include <LuminaXDG.h> @@ -89,10 +85,10 @@ private: QString favdir; //Phonon Widgets for the multimedia player - Phonon::MediaObject *mediaObj; - Phonon::VideoWidget *videoDisplay; - Phonon::AudioOutput *audioOut; - Phonon::SeekSlider *playerSlider; + QMediaPlayer *mediaObj; + QVideoWidget *videoDisplay; + //Phonon::AudioOutput *audioOut; + QSlider *playerSlider; QString playerTTime; //total time - to prevent recalculation every tick //Internal variables @@ -184,14 +180,20 @@ private slots: //Multimedia Player Functions void playerStart(); + void playerError(); void playerStop(); void playerPause(); void playerNext(); void playerPrevious(); void playerFinished(); //automatically called by the media object - void playerStateChanged(Phonon::State newstate, Phonon::State oldstate); //automatically called by the media object + void playerStatusChanged(QMediaPlayer::MediaStatus stat); //automatically called + void playerStateChanged(QMediaPlayer::State newstate); //automatically called by the media object void playerVideoAvailable(bool showVideo); //automatically called by the media object + void playerDurationChanged(qint64); void playerTimeChanged(qint64 ctime); //automatically called by the media object + void playerSliderMoved(int); + void playerSliderHeld(); + void playerSliderChanged(); void playerFileChanged(); //Context Menu Actions diff --git a/lumina-fm/lumina-fm.pro b/lumina-fm/lumina-fm.pro index cc9ad275..d0fb713b 100644 --- a/lumina-fm/lumina-fm.pro +++ b/lumina-fm/lumina-fm.pro @@ -1,5 +1,6 @@ -QT += core gui phonon +QT += core gui +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets multimedia multimediawidgets TARGET = lumina-fm isEmpty(PREFIX) { @@ -30,14 +31,14 @@ FORMS += MainUI.ui \ INCLUDEPATH += ../libLumina $$PREFIX/include LIBS += -L../libLumina -lLuminaUtils -freebsd-* { +/*freebsd-* { LIBS += -lQtSolutions_SingleApplication-head -} +}*/ openbsd-g++4 { LRELEASE = lrelease4 } else { - LRELEASE = lrelease-qt4 + LRELEASE = $$PREFIX/lib/qt5/bin/lrelease } QMAKE_LIBDIR = ../libLumina diff --git a/lumina-fm/main.cpp b/lumina-fm/main.cpp index e2f70bc1..760ca7ad 100644 --- a/lumina-fm/main.cpp +++ b/lumina-fm/main.cpp @@ -1,11 +1,12 @@ #include <QTranslator> -#ifdef __FreeBSD__ +/*#ifdef __FreeBSD__ #include <qtsingleapplication.h> -#endif -#include <QtGui/QApplication> +#endif*/ +#include <QApplication> #include <QDebug> #include <QFile> -#include <QTextCodec> +#include <QStringList> +//#include <QTextCodec> #include "MainUI.h" #include <LuminaOS.h> @@ -25,32 +26,32 @@ int main(int argc, char ** argv) } } if(in.isEmpty()){ in << QDir::homePath(); } - #ifdef __FreeBSD__ + /*#ifdef __FreeBSD__ QtSingleApplication a(argc, argv); if( a.isRunning() ){ return !(a.sendMessage(in.join("\n"))); } - #else + #else*/ QApplication a(argc, argv); - #endif + qDebug() << "Loaded QApplication"; + //#endif a.setApplicationName("Insight File Manager"); LuminaThemeEngine themes(&a); //Load current Locale QTranslator translator; QLocale mylocale; QString langCode = mylocale.name(); - if ( ! QFile::exists(LOS::LuminaShare()+"i18n/lumina-fm_" + langCode + ".qm" ) ) langCode.truncate(langCode.indexOf("_")); translator.load( QString("lumina-fm_") + langCode, LOS::LuminaShare()+"i18n/" ); a.installTranslator( &translator ); qDebug() << "Locale:" << langCode; //Load current encoding for this locale - QTextCodec::setCodecForTr( QTextCodec::codecForLocale() ); //make sure to use the same codec - qDebug() << "Locale Encoding:" << QTextCodec::codecForLocale()->name(); + //QTextCodec::setCodecForTr( QTextCodec::codecForLocale() ); //make sure to use the same codec + //qDebug() << "Locale Encoding:" << QTextCodec::codecForLocale()->name(); MainUI w; - QObject::connect(&a, SIGNAL(messageReceived(const QString&)), &w, SLOT(slotSingleInstance(const QString&)) ); + //QObject::connect(&a, SIGNAL(messageReceived(const QString&)), &w, SLOT(slotSingleInstance(const QString&)) ); QObject::connect(&themes, SIGNAL(updateIcons()), &w, SLOT(setupIcons()) ); w.OpenDirs(in); w.show(); |