From: Elias Woods Date: Sun, 20 Jun 2010 21:51:29 +0000 (-0400) Subject: Add (better) portrait mode support. This commit will temporarily break X-Git-Url: http://vcs.maemo.org/git/?p=groove;a=commitdiff_plain;h=4359db0c4594f697e955c3bcfa5c0f1523682781 Add (better) portrait mode support. This commit will temporarily break building on non-mamemo platofrms --- diff --git a/Groove.pro b/Groove.pro index 719fe07..b1a84df 100644 --- a/Groove.pro +++ b/Groove.pro @@ -28,7 +28,8 @@ SOURCES += main.cpp \ streamio.cpp \ playlist.cpp \ downloadmanager.cpp \ - grooveprogressbar.cpp + grooveprogressbar.cpp \ + qmaemo5rotator.cpp HEADERS += \ groove.h \ @@ -37,4 +38,5 @@ HEADERS += \ streamio.h \ playlist.h \ downloadmanager.h \ - grooveprogressbar.h + grooveprogressbar.h \ + qmaemo5rotator.h diff --git a/Groove.pro.user b/Groove.pro.user index b68c481..2e2f61c 100644 --- a/Groove.pro.user +++ b/Groove.pro.user @@ -194,7 +194,7 @@ 1 - 2010-06-19T01:08:31 + 2010-06-20T16:49:36 diff --git a/Makefile b/Makefile index 308dfaa..bf9883d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: groove -# Generated by qmake (2.01a) (Qt 4.6.2) on: Sat Jun 19 00:00:46 2010 +# Generated by qmake (2.01a) (Qt 4.6.2) on: Sun Jun 20 16:58:17 2010 # Project: Groove.pro # Template: app # Command: /usr/bin/qmake -unix -o Makefile Groove.pro @@ -49,12 +49,16 @@ SOURCES = main.cpp \ splayer.cpp \ streamio.cpp \ playlist.cpp \ - downloadmanager.cpp moc_groove.cpp \ + downloadmanager.cpp \ + grooveprogressbar.cpp \ + qmaemo5rotator.cpp moc_groove.cpp \ moc_gscom.cpp \ moc_splayer.cpp \ moc_streamio.cpp \ moc_playlist.cpp \ - moc_downloadmanager.cpp + moc_downloadmanager.cpp \ + moc_grooveprogressbar.cpp \ + moc_qmaemo5rotator.cpp OBJECTS = main.o \ groove.o \ gscom.o \ @@ -62,12 +66,16 @@ OBJECTS = main.o \ streamio.o \ playlist.o \ downloadmanager.o \ + grooveprogressbar.o \ + qmaemo5rotator.o \ moc_groove.o \ moc_gscom.o \ moc_splayer.o \ moc_streamio.o \ moc_playlist.o \ - moc_downloadmanager.o + moc_downloadmanager.o \ + moc_grooveprogressbar.o \ + moc_qmaemo5rotator.o DIST = /usr/share/qt4/mkspecs/common/g++.conf \ /usr/share/qt4/mkspecs/common/unix.conf \ /usr/share/qt4/mkspecs/common/linux.conf \ @@ -171,7 +179,7 @@ qmake: FORCE dist: @$(CHK_DIR_EXISTS) .tmp/groove1.0.0 || $(MKDIR) .tmp/groove1.0.0 - $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/groove1.0.0/ && $(COPY_FILE) --parents groove.h gscom.h splayer.h streamio.h playlist.h downloadmanager.h .tmp/groove1.0.0/ && $(COPY_FILE) --parents main.cpp groove.cpp gscom.cpp splayer.cpp streamio.cpp playlist.cpp downloadmanager.cpp .tmp/groove1.0.0/ && (cd `dirname .tmp/groove1.0.0` && $(TAR) groove1.0.0.tar groove1.0.0 && $(COMPRESS) groove1.0.0.tar) && $(MOVE) `dirname .tmp/groove1.0.0`/groove1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/groove1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/groove1.0.0/ && $(COPY_FILE) --parents groove.h gscom.h splayer.h streamio.h playlist.h downloadmanager.h grooveprogressbar.h qmaemo5rotator.h .tmp/groove1.0.0/ && $(COPY_FILE) --parents main.cpp groove.cpp gscom.cpp splayer.cpp streamio.cpp playlist.cpp downloadmanager.cpp grooveprogressbar.cpp qmaemo5rotator.cpp .tmp/groove1.0.0/ && (cd `dirname .tmp/groove1.0.0` && $(TAR) groove1.0.0.tar groove1.0.0 && $(COMPRESS) groove1.0.0.tar) && $(MOVE) `dirname .tmp/groove1.0.0`/groove1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/groove1.0.0 clean:compiler_clean @@ -190,12 +198,14 @@ mocclean: compiler_moc_header_clean compiler_moc_source_clean mocables: compiler_moc_header_make_all compiler_moc_source_make_all -compiler_moc_header_make_all: moc_groove.cpp moc_gscom.cpp moc_splayer.cpp moc_streamio.cpp moc_playlist.cpp moc_downloadmanager.cpp +compiler_moc_header_make_all: moc_groove.cpp moc_gscom.cpp moc_splayer.cpp moc_streamio.cpp moc_playlist.cpp moc_downloadmanager.cpp moc_grooveprogressbar.cpp moc_qmaemo5rotator.cpp compiler_moc_header_clean: - -$(DEL_FILE) moc_groove.cpp moc_gscom.cpp moc_splayer.cpp moc_streamio.cpp moc_playlist.cpp moc_downloadmanager.cpp + -$(DEL_FILE) moc_groove.cpp moc_gscom.cpp moc_splayer.cpp moc_streamio.cpp moc_playlist.cpp moc_downloadmanager.cpp moc_grooveprogressbar.cpp moc_qmaemo5rotator.cpp moc_groove.cpp: gscom.h \ splayer.h \ streamio.h \ + grooveprogressbar.h \ + qmaemo5rotator.h \ groove.h /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) groove.h -o moc_groove.cpp @@ -204,11 +214,15 @@ moc_gscom.cpp: gscom.h moc_splayer.cpp: streamio.h \ splayer.h \ + grooveprogressbar.h \ + qmaemo5rotator.h \ splayer.h /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) splayer.h -o moc_splayer.cpp moc_streamio.cpp: splayer.h \ streamio.h \ + grooveprogressbar.h \ + qmaemo5rotator.h \ streamio.h /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) streamio.h -o moc_streamio.cpp @@ -218,6 +232,13 @@ moc_playlist.cpp: playlist.h moc_downloadmanager.cpp: downloadmanager.h /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) downloadmanager.h -o moc_downloadmanager.cpp +moc_grooveprogressbar.cpp: qmaemo5rotator.h \ + grooveprogressbar.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) grooveprogressbar.h -o moc_grooveprogressbar.cpp + +moc_qmaemo5rotator.cpp: qmaemo5rotator.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) qmaemo5rotator.h -o moc_qmaemo5rotator.cpp + compiler_rcc_make_all: compiler_rcc_clean: compiler_image_collection_make_all: qmake_image_collection.cpp @@ -240,24 +261,32 @@ compiler_clean: compiler_moc_header_clean main.o: main.cpp groove.h \ gscom.h \ splayer.h \ - streamio.h + streamio.h \ + grooveprogressbar.h \ + qmaemo5rotator.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp groove.o: groove.cpp groove.h \ gscom.h \ splayer.h \ - streamio.h + streamio.h \ + grooveprogressbar.h \ + qmaemo5rotator.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o groove.o groove.cpp gscom.o: gscom.cpp gscom.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o gscom.o gscom.cpp splayer.o: splayer.cpp splayer.h \ - streamio.h + streamio.h \ + grooveprogressbar.h \ + qmaemo5rotator.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o splayer.o splayer.cpp streamio.o: streamio.cpp streamio.h \ - splayer.h + splayer.h \ + grooveprogressbar.h \ + qmaemo5rotator.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o streamio.o streamio.cpp playlist.o: playlist.cpp playlist.h @@ -266,6 +295,13 @@ playlist.o: playlist.cpp playlist.h downloadmanager.o: downloadmanager.cpp downloadmanager.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o downloadmanager.o downloadmanager.cpp +grooveprogressbar.o: grooveprogressbar.cpp grooveprogressbar.h \ + qmaemo5rotator.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o grooveprogressbar.o grooveprogressbar.cpp + +qmaemo5rotator.o: qmaemo5rotator.cpp qmaemo5rotator.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qmaemo5rotator.o qmaemo5rotator.cpp + moc_groove.o: moc_groove.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_groove.o moc_groove.cpp @@ -284,6 +320,12 @@ moc_playlist.o: moc_playlist.cpp moc_downloadmanager.o: moc_downloadmanager.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_downloadmanager.o moc_downloadmanager.cpp +moc_grooveprogressbar.o: moc_grooveprogressbar.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_grooveprogressbar.o moc_grooveprogressbar.cpp + +moc_qmaemo5rotator.o: moc_qmaemo5rotator.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_qmaemo5rotator.o moc_qmaemo5rotator.cpp + ####### Install install_target: first FORCE diff --git a/groove.cpp b/groove.cpp index 102c369..a63602d 100644 --- a/groove.cpp +++ b/groove.cpp @@ -1,5 +1,5 @@ #include "groove.h" - +#include "qmaemo5rotator.h" groove::groove(QWidget *parent) : @@ -51,11 +51,9 @@ groove::groove(QWidget *parent) : /*QPalette pal = resultView->palette(); pal.setBrush(QPalette::Highlight,QBrush(Qt::transparent,Qt::NoBrush)); resultView->setPalette(pal);*/ - + portrait = false; layout->addWidget(sMethod); -#ifdef Q_WS_MAEMO_5 - setAttribute(Qt::WA_Maemo5AutoOrientation,true); -#endif + rot = new QMaemo5Rotator(QMaemo5Rotator::AutomaticBehavior,this); layout->addWidget(lineEdit); layout->addWidget(button); vlayout->addLayout(layout); @@ -78,6 +76,7 @@ groove::groove(QWidget *parent) : connect(stopButton,SIGNAL(clicked()),this,SLOT(stop())); connect(gs,SIGNAL(sKeyFound()),this,SLOT(startP())); connect(moreButton,SIGNAL(clicked()),this,SLOT(moreB())); + //connect(rotator,SIGNAL(orientationChanged(Orientation)),this,SLOT(orientationChanged())); } void groove::search() { @@ -144,8 +143,11 @@ void groove::startP() return; player->~sPlayer(); player = new sPlayer(); +#ifdef Q_WS_MAEMO_5 + player->play(gs->streamID,gs->sku,rot->currentOrientation()); +#else player->play(gs->streamID,gs->sku); - +#endif } void groove::stop() { @@ -155,3 +157,13 @@ void groove::moreB() { qDebug() << "He pressed the button"; } +void groove::orientationChanged() +{ +#ifdef Q_WS_MAEMO_5 + QRect screenGeometry = QApplication::desktop()->screenGeometry(); + if (screenGeometry.width() > screenGeometry.height()) + portrait = false; + else + portrait = true; +#endif +} diff --git a/groove.h b/groove.h index 100bc6e..9a473c8 100644 --- a/groove.h +++ b/groove.h @@ -3,6 +3,7 @@ #include #include "gscom.h" #include "splayer.h" +#include "qmaemo5rotator.h" #include class groove : public QWidget @@ -21,6 +22,7 @@ public slots: void startP(); void stop(); void moreB(); + void orientationChanged(); private: sPlayer *player; @@ -30,7 +32,9 @@ private: QLineEdit *lineEdit; QTableView *resultView; QPushButton *button; + bool portrait; gscom *gs; + QMaemo5Rotator *rot; }; diff --git a/grooveprogressbar.cpp b/grooveprogressbar.cpp index dc130bd..82650a1 100644 --- a/grooveprogressbar.cpp +++ b/grooveprogressbar.cpp @@ -1,5 +1,5 @@ #include "grooveprogressbar.h" - +#include "qmaemo5rotator.h" grooveProgressBar::grooveProgressBar(QDialog *parent) : QDialog(parent) { @@ -10,6 +10,7 @@ grooveProgressBar::grooveProgressBar(QDialog *parent) : lay->addWidget(bar); this->setLayout(lay); this->setWindowTitle("Downloading / Buffering"); + rot = new QMaemo5Rotator(QMaemo5Rotator::AutomaticBehavior,this); } void grooveProgressBar::setMaximum(int maximum) { diff --git a/grooveprogressbar.h b/grooveprogressbar.h index 770e1b1..f8f1989 100644 --- a/grooveprogressbar.h +++ b/grooveprogressbar.h @@ -3,6 +3,7 @@ #include #include +#include "qmaemo5rotator.h" class grooveProgressBar : public QDialog { @@ -12,6 +13,7 @@ public: void setMaximum(int maximum); void setValue(int position); int maximum(); + QMaemo5Rotator *rot; signals: diff --git a/main.cpp b/main.cpp index d282f2a..e186556 100755 --- a/main.cpp +++ b/main.cpp @@ -6,6 +6,10 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setApplicationName("Groove"); groove gs; //create Groove! +#ifdef Q_WS_MAEMO_5 + //setAttribute(Qt::WA_Maemo5AutoOrientation,true); + //a.setAttribute(Qt::WA_Maemo5AutoOrientation,true); +#endif #if defined(Q_WS_S60) gs.showMaximized(); #else diff --git a/qmaemo5rotator.cpp b/qmaemo5rotator.cpp new file mode 100644 index 0000000..78cbe6a --- /dev/null +++ b/qmaemo5rotator.cpp @@ -0,0 +1,106 @@ + +#include "qmaemo5rotator.h" +#if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON) +#include +#include +#include +#include +#endif + +QMaemo5Rotator::QMaemo5Rotator(RotationBehavior behavior, QWidget *parent) + : QObject(parent), + isSetUp(false) +{ + setCurrentBehavior(behavior); +} + +QMaemo5Rotator::~QMaemo5Rotator() +{ +#if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON) + QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ)); +#endif +} + +const QMaemo5Rotator::RotationBehavior QMaemo5Rotator::currentBehavior() +{ + return _currentBehavior; +} + +const QMaemo5Rotator::Orientation QMaemo5Rotator::currentOrientation() +{ + return _currentOrientation; +} + +void QMaemo5Rotator::setCurrentBehavior(QMaemo5Rotator::RotationBehavior value) +{ +#if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON) + if (value == _currentBehavior && isSetUp) + return; + + isSetUp = true; + _currentBehavior = value; + + if (value == QMaemo5Rotator::AutomaticBehavior) + { + QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ)); + QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF, MCE_DEVICE_ORIENTATION_SIG, this, SLOT(on_orientation_changed(QString))); + } + else + { + QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ)); + + if (value == QMaemo5Rotator::PortraitBehavior) + { + setCurrentOrientation(QMaemo5Rotator::PortraitOrientation); + } + else + { + setCurrentOrientation(QMaemo5Rotator::LandscapeOrientation); + } + } +#endif +} + +void QMaemo5Rotator::setCurrentOrientation(QMaemo5Rotator::Orientation value) +{ + _currentOrientation = value; + QWidget *par = (QWidget*)parent(); + + switch (value) + { + case QMaemo5Rotator::PortraitOrientation: + if (par != NULL) + { +#if defined(Q_WS_MAEMO_5) + par->setAttribute(Qt::WA_Maemo5LandscapeOrientation, false); + par->setAttribute(Qt::WA_Maemo5PortraitOrientation, true); +#endif + } + orientationChanged(QMaemo5Rotator::PortraitOrientation); + break; + case QMaemo5Rotator::LandscapeOrientation: + if (par != NULL) + { +#if defined(Q_WS_MAEMO_5) + par->setAttribute(Qt::WA_Maemo5PortraitOrientation, false); + par->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true); +#endif + } + orientationChanged(QMaemo5Rotator::LandscapeOrientation); + + break; + } +} + +void QMaemo5Rotator::on_orientation_changed(const QString& newOrientation) +{ + if (newOrientation == QLatin1String(MCE_ORIENTATION_PORTRAIT) || newOrientation == QLatin1String(MCE_ORIENTATION_PORTRAIT_INVERTED)) + { + setCurrentOrientation(QMaemo5Rotator::PortraitOrientation); + } + else + { + setCurrentOrientation(QMaemo5Rotator::LandscapeOrientation); + } + QApplication::desktop()->updateGeometry(); +} diff --git a/qmaemo5rotator.h b/qmaemo5rotator.h new file mode 100644 index 0000000..0e63bf7 --- /dev/null +++ b/qmaemo5rotator.h @@ -0,0 +1,58 @@ +#ifndef QMAEMO5ROTATOR_H +#define QMAEMO5ROTATOR_H + +//---------- +// Provides a means of WORKING automatic rotation for Maemo 5 apps. (The default Qt solution is buggy.) +//---------- + +#include +#include +#include + +class QMaemo5Rotator : private QObject +{ + + Q_OBJECT + +public: + + enum RotationBehavior + { + AutomaticBehavior = 0, + LandscapeBehavior = 1, + PortraitBehavior = 2 + }; + + enum Orientation + { + LandscapeOrientation = 0, + PortraitOrientation = 1 + }; + +private: + + bool isSetUp; + RotationBehavior _currentBehavior; + Orientation _currentOrientation; + +public: + + explicit QMaemo5Rotator(RotationBehavior behavior = LandscapeBehavior, QWidget *parent = NULL); + ~QMaemo5Rotator(); + + const RotationBehavior currentBehavior(); + const Orientation currentOrientation(); + void setCurrentBehavior(RotationBehavior value); + void setCurrentOrientation(Orientation value); + +private slots: + + void on_orientation_changed(const QString& newOrienation); + +signals: + + void orientationChanged(Orientation orientation); + +}; + +#endif // QMAEMO5ROTATOR_H diff --git a/splayer.cpp b/splayer.cpp index dae3fcc..4b6b07e 100644 --- a/splayer.cpp +++ b/splayer.cpp @@ -25,6 +25,15 @@ void sPlayer::abortDownload() //pd->hide(); //reply->abort(); } +void sPlayer::play(QString StreamKey, QUrl server, QMaemo5Rotator::Orientation orientation) +{ + this->play(StreamKey, server); +#ifdef Q_WS_MAEMO_5 + if(orientation == QMaemo5Rotator::PortraitOrientation) + pd->rot->setCurrentOrientation(orientation); +#endif + //isPortrait = false; //just make the compilier happy on non-maemo +} void sPlayer::play(QString StreamKey,QUrl server) { @@ -34,11 +43,6 @@ void sPlayer::play(QString StreamKey,QUrl server) } pd = new grooveProgressBar(); //pd->setAttribute(); - -#ifdef Q_WS_MAEMO_5 - pd->setAttribute(Qt::WA_Maemo5AutoOrientation,true); - //pd->setModal(false); -#endif pd->show(); pd->setValue(0); QNetworkRequest req; @@ -73,6 +77,7 @@ void sPlayer::start() playing = true; media->setCurrentSource(Phonon::MediaSource(buffer)); media->play(); + pd->hide(); qDebug() << "Playing"; } } @@ -137,7 +142,7 @@ void sPlayer::putb(qint64 b, qint64 t) buffer->seek(last); //buffer->data().append(reply->readAll());*/ //qDebug() << "Download speed (KB/S): " << b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024; - if ( b >= t*0.05 && !playing && b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024 >= 25) + if ( b >= t*0.05 && !playing && b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024 >= 10) { pd->hide(); playing = true; diff --git a/splayer.h b/splayer.h index fe3a5ec..239df92 100644 --- a/splayer.h +++ b/splayer.h @@ -14,6 +14,7 @@ class sPlayer : public QObject public: explicit sPlayer(QObject *parent = 0); void play(QString StreamKey, QUrl server); + void play(QString StreamKey, QUrl server,QMaemo5Rotator::Orientation orientation); void stop(); ~sPlayer();