MediaKeys

Changeset 329a244

Files
  • 7 edited
no avatar
Jacopo Guderzo <crazyhg@…>
Timestamp:
02/04/12 20:35:45 (3 months ago)
Message:

Long press support





Legend:
Unmodified
Added
Removed
  • main.cpp

    r3fc4e8e r329a244  
    25 25    controller.setGconfDownAction( root->findChild<GConfItemQmlProxy*>(QString("volumedown")) ); 
    26 26    controller.setGconfStatus(     root->findChild<GConfItemQmlProxy*>(QString("enabled"))    ); 
     27    controller.setGconfLongPress(  root->findChild<GConfItemQmlProxy*>(QString("longpress"))  ); 
     28    controller.setGconfPressDuration( root->findChild<GConfItemQmlProxy*>(QString("longpressduration")) ); 
    27 29 
    28 30    return app->exec(); 
  • mediakeys.cpp

    r3fc4e8e r329a244  
    2 2 
    3 3namespace { 
    4    const QString DBUS_SERVICE("com.nokia.music-suite"); 
    5    const QString DBUS_PATH("/"); 
    6    const QString DBUS_INTERFACE("com.nokia.maemo.meegotouch.MusicSuiteInterface"); 
     4   const QString DBUS_MUSIC_SERVICE("com.nokia.music-suite"); 
     5   const QString DBUS_MUSIC_PATH("/"); 
     6   const QString DBUS_MUSIC_INTERFACE("com.nokia.maemo.meegotouch.MusicSuiteInterface"); 
    7 7 
    8 8  const QString DBUS_PBSTATE("playbackState"); 
     
    12 12  const QString DBUS_RESUME("resumePlayback"); 
    13 13 
     14  const QString DBUS_MAFW_SERVICE("com.nokia.mafw.plugin.libqmafw_gst_renderer_plugin"); 
     15  const QString DBUS_MAFW_PATH("/com/nokia/mafw/renderer/mafw_gst_renderer"); 
     16  const QString DBUS_MAFW_INTERFACE("com.nokia.mafw.extension"); 
     17 
     18  const QString DBUS_MAFW_GETPROPERTY("get_extension_property"); 
     19  const QString DBUS_MAFW_SETPROPERTY("set_extension_property"); 
     20 
     21 
    14 22  const QString GCONF_VALUE_PLAYPAUSE("playpause"); 
    15 23  const QString GCONF_VALUE_PREVIOUS("previous"); 
     
    28 36    onNextKeyReleased = false; 
    29 37 
     38    useLongPress = true; 
     39    volumeStep = 4; 
     40    longPressDuration = 1000; 
     41 
    30 42    hwkeys = new MeeGo::QmKeys(this); 
    31 43    connect(hwkeys, SIGNAL (keyEvent (MeeGo::QmKeys::Key, MeeGo::QmKeys::State)), 
     
    41 53            this, SLOT(keyResourceAcquired())); 
    42 54} 
    43   
    44   
    45 55 
    46 56 
     
    50 60    // Key pressed 
    51 61    if (state == MeeGo::QmKeys::KeyDown) { 
    52          if (key==MeeGo::QmKeys::VolumeUp) 
    53              volumeUpPressed = true; 
    54          else if (key==MeeGo::QmKeys::VolumeDown) 
    55              volumeDownPressed = true; 
    56   
     62         if (key==MeeGo::QmKeys::VolumeUp) { 
     63             if (!volumeUpPressed) { 
     64                 volUpTime.start(); 
     65                 volumeUpPressed = true; 
     66             } 
     67         } 
     68         else if (key==MeeGo::QmKeys::VolumeDown) { 
     69             if (!volumeDownPressed) { 
     70                 volDownTime.start(); 
     71                 volumeDownPressed = true; 
     72             } 
     73         } 
    57 74        return; 
    58 75    } 
     
    74 91                } 
    75 92//                else if (isMusicSuiteServiceRegistered()) { 
    76                  else { 
     93                 else if (!useLongPress || (useLongPress && volUpTime.elapsed() > longPressDuration) ) { 
    77 94                    switch (volUpAction) { 
    78 95                    case PlayPause: 
     
    83 100                        next(); break; 
    84 101                    } 
     102                } else { 
     103                    increaseVolume(); 
    85 104                } 
    86 105 
     
    111 130                } 
    112 131//                else if (isMusicSuiteServiceRegistered()) { 
    113                  else { 
     132                 else if (!useLongPress || (useLongPress && volDownTime.elapsed() > longPressDuration) ) { 
    114 133                    switch (volDownAction) { 
    115 134                    case PlayPause: 
     
    120 139                        next(); break; 
    121 140                    } 
     141                } else { 
     142                    decreaseVolume(); 
    122 143                } 
    123 144 
     
    163 184} 
    164 185 
    165  void MediaKeys::hwKeyResourceDenied() { 
     186 void MediaKeys::keyResourceDenied() { 
    166 187    MNotification notification(MNotification::DeviceEvent, "", MSG_RES_DENIED); 
    167 188    notification.setImage("icon-m-transfer-error"); 
     
    171 192 
    172 193 
    173   
    174 194// DBUS METHOD CALLS 
    175 195 
    176 196bool MediaKeys::isMusicSuiteServiceRegistered() { 
    177 197    QDBusConnectionInterface *interface = QDBusConnection::sessionBus().interface(); 
    178      QDBusReply<bool> reply = interface->isServiceRegistered(DBUS_SERVICE); 
     198     QDBusReply<bool> reply = interface->isServiceRegistered(DBUS_MUSIC_SERVICE); 
    179 199    if (reply.isValid()) 
    180 200        return reply.value(); 
     
    184 204 
    185 205bool MediaKeys::playbackState() { 
    186      QDBusInterface dbus_iface(DBUS_SERVICE, DBUS_PATH, DBUS_INTERFACE); 
     206     QDBusInterface dbus_iface(DBUS_MUSIC_SERVICE, DBUS_MUSIC_PATH, DBUS_MUSIC_INTERFACE); 
    187 207    QDBusReply<int> reply = dbus_iface.call(DBUS_PBSTATE); 
    188 208    if (reply.isValid()) 
     
    194 214 
    195 215void MediaKeys::previous() { 
    196      QDBusInterface dbus_iface(DBUS_SERVICE, DBUS_PATH, DBUS_INTERFACE); 
     216     QDBusInterface dbus_iface(DBUS_MUSIC_SERVICE, DBUS_MUSIC_PATH, DBUS_MUSIC_INTERFACE); 
    197 217    dbus_iface.call(DBUS_PREVIOUS); 
    198 218} 
    199 219 
    200 220void MediaKeys::next() { 
    201      QDBusInterface dbus_iface(DBUS_SERVICE, DBUS_PATH, DBUS_INTERFACE); 
     221     QDBusInterface dbus_iface(DBUS_MUSIC_SERVICE, DBUS_MUSIC_PATH, DBUS_MUSIC_INTERFACE); 
    202 222    dbus_iface.call(DBUS_NEXT); 
    203 223} 
    204 224 
    205 225void MediaKeys::togglePlayback() { 
    206      QDBusInterface dbus_iface(DBUS_SERVICE, DBUS_PATH, DBUS_INTERFACE); 
     226     QDBusInterface dbus_iface(DBUS_MUSIC_SERVICE, DBUS_MUSIC_PATH, DBUS_MUSIC_INTERFACE); 
    207 227    if (playbackState()) 
    208 228        dbus_iface.call(DBUS_PAUSE); 
     
    210 230        dbus_iface.call(DBUS_RESUME); 
    211 231} 
     232 
     233 
     234 
     235bool MediaKeys::increaseVolume() { 
     236    QDBusInterface dbus_iface(DBUS_MAFW_SERVICE, DBUS_MAFW_PATH, DBUS_MAFW_INTERFACE); 
     237    // get current volume 
     238    QDBusMessage reply = dbus_iface.call(DBUS_MAFW_GETPROPERTY, "volume"); 
     239    if(reply.type() == QDBusMessage::ErrorMessage) 
     240        return false; 
     241    QDBusVariant v = reply.arguments().at(1).value<QDBusVariant>(); 
     242    uint volume = v.variant().toUInt(); 
     243 
     244    uint newvolume = volume + volumeStep; 
     245    if(newvolume > 100) 
     246        newvolume = 100; 
     247 
     248    QDBusReply<bool> r = dbus_iface.call(DBUS_MAFW_SETPROPERTY, "volume", QVariant::fromValue(QDBusVariant(newvolume))); 
     249    return r.value(); 
     250} 
     251 
     252bool MediaKeys::decreaseVolume() { 
     253    QDBusInterface dbus_iface(DBUS_MAFW_SERVICE, DBUS_MAFW_PATH, DBUS_MAFW_INTERFACE); 
     254 
     255    QDBusMessage reply = dbus_iface.call("get_extension_property", "volume"); 
     256    if(reply.type() == QDBusMessage::ErrorMessage) 
     257        return false; 
     258    QDBusVariant v = reply.arguments().at(1).value<QDBusVariant>(); 
     259    uint volume = v.variant().toUInt(); 
     260 
     261    uint newvolume = volume - volumeStep; 
     262    if(newvolume > volume) 
     263        newvolume = 0; 
     264 
     265    QDBusReply<bool> r = dbus_iface.call("set_extension_property", "volume", QVariant::fromValue(QDBusVariant(newvolume))); 
     266    return r.value(); 
     267} 
     268 
    212 269 
    213 270 
     
    232 289    connect(gconfStatus, SIGNAL(valueChanged()), this, SLOT(updateStatus())); 
    233 290    updateStatus(); 
     291} 
     292 
     293void MediaKeys::setGconfLongPress(GConfItemQmlProxy * item) { 
     294    gconfLongPress = item; 
     295    connect(gconfLongPress, SIGNAL(valueChanged()), this, SLOT(updateLongPress())); 
     296    updateLongPress(); 
     297} 
     298 
     299void MediaKeys::setGconfPressDuration(GConfItemQmlProxy * item) { 
     300    gconfPressDuration = item; 
     301    connect(gconfPressDuration, SIGNAL(valueChanged()), this, SLOT(updatePressDuration())); 
     302    updatePressDuration(); 
    234 303} 
    235 304 
     
    263 332        volDownAction = Next; 
    264 333} 
     334 
     335void MediaKeys::updateLongPress() { 
     336    QVariant value = gconfLongPress->value(); 
     337    useLongPress = value.toBool(); 
     338} 
     339 
     340void MediaKeys::updatePressDuration() { 
     341    QVariant value = gconfPressDuration->value(); 
     342    longPressDuration= value.toInt(); 
     343} 
  • mediakeys.h

    r3fc4e8e r329a244  
    4 4#include <QObject> 
    5 5#include <QDebug> 
     6#include <QTime> 
    6 7#include <QtDBus/QDBusConnection> 
    7 8#include <QtDBus/QDBusInterface> 
     
    12 13#include <qmkeys.h> 
    13 14#include "gconfitemqmlproxy.h" 
     15#include <QDir> 
     16#include <QFile> 
    14 17 
    15 18class MediaKeys : public QObject 
     
    22 25    GConfItemQmlProxy* gconfDownAction; 
    23 26    GConfItemQmlProxy* gconfStatus; 
     27    GConfItemQmlProxy* gconfLongPress; 
     28    GConfItemQmlProxy* gconfPressDuration; 
    24 29 
    25 30    void setGconfUpAction(GConfItemQmlProxy*); 
    26 31    void setGconfDownAction(GConfItemQmlProxy*); 
    27 32    void setGconfStatus(GConfItemQmlProxy*); 
     33    void setGconfLongPress(GConfItemQmlProxy*); 
     34    void setGconfPressDuration(GConfItemQmlProxy*); 
    28 35 
    29 36private: 
     
    43 50    bool volumeDownPressed; 
    44 51    bool onNextKeyReleased; 
     52    bool useLongPress; 
     53    int volumeStep; 
     54    int longPressDuration; 
     55    QTime volUpTime; 
     56    QTime volDownTime; 
    45 57 
    46 58 
     
    51 63    void togglePlayback(); 
    52 64 
     65    int getVolume(); 
     66    bool increaseVolume(); 
     67    bool decreaseVolume(); 
     68 
    53 69 
    54 70 
     
    57 73    void keyResourceAcquired(); 
    58 74    void keyResourceReleased(); 
    59      void hwKeyResourceDenied(); 
     75     void keyResourceDenied(); 
    60 76 
    61 77    void updateStatus(); 
    62 78    void updateUpAction(); 
    63 79    void updateDownAction(); 
     80    void updateLongPress(); 
     81    void updatePressDuration(); 
    64 82}; 
    65 83 
  • mediakeys.pro.user

    r3fc4e8e r329a244  
    1 1<?xml version="1.0" encoding="UTF-8"?> 
    2 2<!DOCTYPE QtCreatorProject> 
    3  <!-- Written by Qt Creator 2.4.0, 2012-01-27T23:24:32. --> 
     3 <!-- Written by Qt Creator 2.4.1, 2012-02-04T19:35:29. --> 
    4 4<qtcreator> 
    5 5 <data> 
     
    57 57   <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> 
    58 58   <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> 
    59      <value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">Qt4ProjectManager.ToolChain.Maemo:/home/hg/workspace/QtSDK/Madde/targets/harmattan_10.2011.34-1/bin/gcc.arm-linux-generic-elf-32bit./home/hg/workspace/QtSDK/pythongdb/gdb</value> 
     59     <value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">Qt4ProjectManager.ToolChain.Maemo:/home/hg/workspace/QtSDK/Madde/targets/harmattan_10.2011.34-1/bin/gcc.arm-linux-generic-elf-32bit./home/hg/workspace/QtSDK/debugger/Maemo/gdb</value> 
    60 60    <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> 
    61 61     <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> 
     
    107 107   </valuemap> 
    108 108   <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1"> 
    109      <value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">Qt4ProjectManager.ToolChain.Maemo:/home/hg/workspace/QtSDK/Madde/targets/harmattan_10.2011.34-1/bin/gcc.arm-linux-generic-elf-32bit./home/hg/workspace/QtSDK/pythongdb/gdb</value> 
     109     <value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">Qt4ProjectManager.ToolChain.Maemo:/home/hg/workspace/QtSDK/Madde/targets/harmattan_10.2011.34-1/bin/gcc.arm-linux-generic-elf-32bit./home/hg/workspace/QtSDK/debugger/Maemo/gdb</value> 
    110 110    <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> 
    111 111     <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> 
     
    177 177       <value type="QString">/home/hg/workspace/harmattanProjects/mediakeys2/mediakeys-build-harmattan-Harmattan_Target__Qt_SDK__Debug/mediakeys_0.1.0_armel.deb</value> 
    178 178       <value type="QString">/home/hg/workspace/harmattanProjects/mediakeys2/mediakeys-build-harmattan-Harmattan_Target__Qt_SDK__Release/mediakeys_0.0.1_armel.deb</value> 
     179       <value type="QString">/home/hg/workspace/harmattanProjects/mediakeys2/mediakeys-build-harmattan-Harmattan_Target__Qt_SDK__Release/mediakeys_0.2.0_armel.deb</value> 
    179 180       <value type="QString">/home/hg/workspace/harmattanProjects/mediakeys2/mediakeys-build-harmattan-Harmattan_Target__Qt_SDK__Debug/mediakeys_0.0.1_armel.deb</value> 
     181       <value type="QString">/home/hg/workspace/harmattanProjects/mediakeys2/mediakeys-build-harmattan-Harmattan_Target__Qt_SDK__Debug/mediakeys_0.2.0_armel.deb</value> 
    180 182      </valuelist> 
    181 183      <valuelist type="QVariantList" key="Qt4ProjectManager.MaemoRunConfiguration.LastDeployedHosts"> 
     
    184 186       <value type="QString">192.168.2.15</value> 
    185 187       <value type="QString">192.168.2.15</value> 
     188       <value type="QString">192.168.2.15</value> 
     189       <value type="QString">192.168.2.15</value> 
    186 190      </valuelist> 
    187 191      <valuelist type="QVariantList" key="Qt4ProjectManager.MaemoRunConfiguration.LastDeployedRemotePaths"> 
     
    190 194       <value type="QString"></value> 
    191 195       <value type="QString"></value> 
     196       <value type="QString"></value> 
     197       <value type="QString"></value> 
    192 198      </valuelist> 
    193 199      <valuelist type="QVariantList" key="Qt4ProjectManager.MaemoRunConfiguration.LastDeployedTimes"> 
    194         <value type="QDateTime">2012-01-27T23:16:21</value> 
    195         <value type="QDateTime">2012-01-27T23:03:08</value> 
     200        <value type="QDateTime">2012-02-03T01:37:01</value> 
     201        <value type="QDateTime">2012-02-04T17:44:14</value> 
    196 202       <value type="QDateTime">2012-01-22T17:17:57</value> 
     203       <value type="QDateTime">2012-02-04T19:31:53</value> 
    197 204       <value type="QDateTime">2012-01-26T22:21:51</value> 
     205       <value type="QDateTime">2012-02-04T19:16:48</value> 
    198 206      </valuelist> 
    199 207     </valuemap> 
  • qml/mediakeys/main.qml

    r3fc4e8e r329a244  
    12 12        orientationLock: PageOrientation.LockPortrait 
    13 13 
     14 
     15        Label { 
     16            id: enabled_lbl 
     17            anchors.horizontalCenter: parent.horizontalCenter 
     18            anchors.top: parent.top 
     19            anchors.topMargin: 30 
     20            text: "Status" 
     21        } 
     22        Label { 
     23            id: enabled_lbl_2 
     24            anchors.horizontalCenter: parent.horizontalCenter 
     25            anchors.top: enabled_lbl.bottom 
     26            anchors.topMargin: 5 
     27            font.pixelSize: 18 
     28            text: "You can also use <b>VolumeUp+VolumeDown</b>" 
     29        } 
     30        Button { 
     31            id: status_btn 
     32            anchors.horizontalCenter: parent.horizontalCenter 
     33            anchors.top: enabled_lbl_2.bottom 
     34            anchors.topMargin: 5 
     35            checkable: true 
     36            checked: enabled.value 
     37            text: { 
     38                if(checked) 
     39                    if(long_btn.checked) 
     40                        return "Multimedia + Volume" 
     41                    else return "Multimedia" 
     42                else return "Volume" 
     43            } 
     44            onClicked: enabled.value = checked 
     45        } 
     46 
     47        Label { 
     48            id: long_lbl 
     49            anchors.horizontalCenter: parent.horizontalCenter 
     50            anchors.top: status_btn.bottom 
     51            anchors.topMargin: 30 
     52            text: "Use long press for multimedia" 
     53        } 
     54        Button { 
     55            id: long_btn 
     56            anchors.horizontalCenter: parent.horizontalCenter 
     57            anchors.top: long_lbl.bottom 
     58            anchors.topMargin: 5 
     59            checkable: true 
     60            checked: longpress.value 
     61            text: { 
     62                if(checked) return "Long press" 
     63                else return "Short press" 
     64            } 
     65            onClicked: longpress.value = checked 
     66        } 
     67 
     68        Label { 
     69            id: lpd_lbl 
     70            anchors.horizontalCenter: parent.horizontalCenter 
     71            anchors.top: long_btn.bottom 
     72            anchors.topMargin: 30 
     73            text: "Long press duration" 
     74        } 
     75 
     76        Slider { 
     77             id: longpressduration_sld 
     78             anchors.horizontalCenter: parent.horizontalCenter 
     79             anchors.top: lpd_lbl.bottom 
     80             anchors.topMargin: 5 
     81 
     82             stepSize:100 
     83             valueIndicatorVisible: true 
     84             valueIndicatorText: value/1000 + " s" 
     85             value: longpressduration.value 
     86             minimumValue:100 
     87             maximumValue:2000 
     88 
     89             onPressedChanged: { 
     90                 longpressduration.value = value 
     91             } 
     92         } 
     93 
    14 94        Label { 
    15 95            id: vu_lbl 
    16 96            anchors.horizontalCenter: parent.horizontalCenter 
    17              anchors.top: parent.top 
     97             anchors.top: longpressduration_sld.bottom 
    18 98            anchors.topMargin: 30 
    19 99            text: "VolumeUp action" 
     
    78 158                onClicked: {volumedown.value = "next"} 
    79 159                checked: volumedown.value != "playpause" && volumedown.value != "previous" 
    80              } 
    81          } 
    82   
    83          Label { 
    84              id: enabled_lbl 
    85              anchors.horizontalCenter: parent.horizontalCenter 
    86              anchors.top: vd_buttons.bottom 
    87              anchors.topMargin: 30 
    88              text: "Status" 
    89          } 
    90          Label { 
    91              id: enabled_lbl_2 
    92              anchors.horizontalCenter: parent.horizontalCenter 
    93              anchors.top: enabled_lbl.bottom 
    94              anchors.topMargin: 5 
    95              font.pixelSize: 18 
    96              text: "You can also use <b>VolumeUp+VolumeDown</b>" 
    97          } 
    98          Button { 
    99              id: status_btn 
    100              anchors.horizontalCenter: parent.horizontalCenter 
    101              anchors.top: enabled_lbl_2.bottom 
    102              anchors.topMargin: 5 
    103              checkable: true 
    104              checked: enabled.value 
    105              text: { 
    106                  if(checked) return "Multimedia keys" 
    107                  else return "Volume keys" 
    108              } 
    109              onClicked: { 
    110                  if (checked) enabled.value = true 
    111                  else enabled.value = false 
    112 160            } 
    113 161        } 
     
    136 184    } 
    137 185 
     186    GConfItem { 
     187       id: longpress 
     188       objectName: "longpress" 
     189       key: "/apps/mediakeys/longpress" 
     190       defaultValue: true 
     191    } 
     192 
     193    GConfItem { 
     194       id: longpressduration 
     195       objectName: "longpressduration" 
     196       key: "/apps/mediakeys/longpressduration" 
     197       defaultValue: 800 
     198    } 
     199 
    138 200    function updateStatus() { 
    139 201        if(enabled.value == true) status_btn.checked = true 
  • qtc_packaging/debian_harmattan/changelog

    r3fc4e8e r329a244  
     1mediakeys (0.2.0) unstable; urgency=low 
     2  * Added long press support 
     3 
     4 -- Jacopo Guderzo <crazyhg@gmail.com>  Sat, 04 Feb 2012 17:45:23 +0100 
     5 
    1 6mediakeys (0.1.0) unstable; urgency=low 
    2 7  * <Add change description here> 
  • qtc_packaging/debian_harmattan/control

    r3fc4e8e r329a244  
    5 5Build-Depends: debhelper (>= 5), libqt4-dev 
    6 6Standards-Version: 3.7.3 
    7  Homepage: <insert the upstream URL, if relevant> 
     7 Homepage: http://projects.developer.nokia.com/mediakeys 
    8 8 
    9 9Package: mediakeys 
Note: See TracChangeset for help on using the changeset viewer.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2011 All rights reserved