radioapp/radioapplication/src/testwindow_win32.cpp
changeset 57 21be958eb3ce
parent 34 bc10a61bd7d3
equal deleted inserted replaced
56:04837bf3a628 57:21be958eb3ce
    37 #include "radio_global.h"
    37 #include "radio_global.h"
    38 #include "radioenginewrapper_win32_p.h"
    38 #include "radioenginewrapper_win32_p.h"
    39 
    39 
    40 const int WINDOW_WIDTH = 360;
    40 const int WINDOW_WIDTH = 360;
    41 const int WINDOW_HEIGHT = 640;
    41 const int WINDOW_HEIGHT = 640;
    42 const int TOOLBAR_HEIGHT = 120;
    42 const int TOOLBAR_HEIGHT = 140;
    43 const int WINDOW_EXTRA_WIDTH = 5;
    43 const int WINDOW_EXTRA_WIDTH = 5;
    44 
    44 
    45 const QString KBtnDisconnectHeadset = "Disconnect Headset";
    45 const QString KBtnDisconnectHeadset = "Disconnect Headset";
    46 const QString KBtnConnectHeadset = "Connect Headset";
    46 const QString KBtnConnectHeadset = "Connect Headset";
    47 
    47 
    48 const QString KBtnGoOffline = "Go Offline";
    48 const QString KBtnGoOffline = "Go Offline";
    49 const QString KBtnGoOnline = "Go Online";
    49 const QString KBtnGoOnline = "Go Online";
    50 
    50 
    51 struct Song
    51 const int LAYOUT_MARGIN = 5;
    52 {
    52 const int LAYOUT_SPACING = 5;
       
    53 const int THEME_CHANGE_CONNECT_WAIT = 3000;
       
    54 const int THEME_CHANGE_REQUEST = 4;
       
    55 
       
    56 class Song
       
    57 {
       
    58 public:
    53     const char* mArtist;
    59     const char* mArtist;
    54     const char* mTitle;
    60     const char* mTitle;
    55 };
    61 };
    56 
    62 
    57 const Song KRecognizedSongs[] = {
    63 const Song KRecognizedSongs[] = {
    73     mOrientationButton( new QPushButton( "Change Orientation", this ) ),
    79     mOrientationButton( new QPushButton( "Change Orientation", this ) ),
    74     mVolUpButton( new QPushButton( "Volume Up", this ) ),
    80     mVolUpButton( new QPushButton( "Volume Up", this ) ),
    75     mVolDownButton( new QPushButton( "Volume Down", this ) ),
    81     mVolDownButton( new QPushButton( "Volume Down", this ) ),
    76     mAddSongButton( new QPushButton( "Add Song", this ) ),
    82     mAddSongButton( new QPushButton( "Add Song", this ) ),
    77     mClearSongButton( new QPushButton( "Clear Song", this ) ),
    83     mClearSongButton( new QPushButton( "Clear Song", this ) ),
       
    84     mAddRadiotextButton( new QPushButton( "Add Radiotext", this ) ),
       
    85     mClearRadiotextButton( new QPushButton( "Clear Radiotext", this ) ),
    78     mHeadsetButton( new QPushButton( KBtnDisconnectHeadset, this ) ),
    86     mHeadsetButton( new QPushButton( KBtnDisconnectHeadset, this ) ),
    79     mHeadsetConnected( true ),
    87     mHeadsetConnected( true ),
    80     mOfflineButton( new QPushButton( KBtnGoOffline, this ) ),
    88     mOfflineButton( new QPushButton( KBtnGoOffline, this ) ),
    81     mThemeBox( new QComboBox( this ) ),
    89     mThemeBox( new QComboBox( this ) ),
    82     mToolbarLayout( 0 ),
    90     mToolbarLayout( 0 ),
    92     Radio::connect( mVolUpButton, SIGNAL(clicked()), this, SLOT(volumeUp()) );
   100     Radio::connect( mVolUpButton, SIGNAL(clicked()), this, SLOT(volumeUp()) );
    93     Radio::connect( mVolDownButton, SIGNAL(clicked()), this, SLOT(volumeDown()) );
   101     Radio::connect( mVolDownButton, SIGNAL(clicked()), this, SLOT(volumeDown()) );
    94     Radio::connect( mHeadsetButton, SIGNAL(clicked()), this, SLOT(toggleHeadsetStatus()) );
   102     Radio::connect( mHeadsetButton, SIGNAL(clicked()), this, SLOT(toggleHeadsetStatus()) );
    95     Radio::connect( mAddSongButton, SIGNAL(clicked()), this, SLOT(addSong()) );
   103     Radio::connect( mAddSongButton, SIGNAL(clicked()), this, SLOT(addSong()) );
    96     Radio::connect( mClearSongButton, SIGNAL(clicked()), this, SLOT(clearSong()) );
   104     Radio::connect( mClearSongButton, SIGNAL(clicked()), this, SLOT(clearSong()) );
       
   105     Radio::connect( mAddRadiotextButton, SIGNAL(clicked()), this, SLOT(addRadiotext()) );
       
   106     Radio::connect( mClearRadiotextButton, SIGNAL(clicked()), this, SLOT(clearRadiotext()) );
    97     Radio::connect( mOfflineButton, SIGNAL(clicked()), this, SLOT(toggleOffline()) );
   107     Radio::connect( mOfflineButton, SIGNAL(clicked()), this, SLOT(toggleOffline()) );
    98     Radio::connect( mThemeBox, SIGNAL(activated(QString)), this, SLOT(changeTheme(QString)) );
   108     Radio::connect( mThemeBox, SIGNAL(activated(QString)), this, SLOT(changeTheme(QString)) );
    99 
   109 
   100     QTimer::singleShot( 0, this, SLOT(updateWindowSize()) );
   110     QTimer::singleShot( 0, this, SLOT(updateWindowSize()) );
   101 }
   111 }
   115     mRadioWindow = radioWindow;
   125     mRadioWindow = radioWindow;
   116     mOrientation = mRadioWindow->orientation();
   126     mOrientation = mRadioWindow->orientation();
   117     updateWindowSize();
   127     updateWindowSize();
   118 
   128 
   119     QVBoxLayout* layout = new QVBoxLayout( this );
   129     QVBoxLayout* layout = new QVBoxLayout( this );
   120     layout->setMargin( 5 );
   130     layout->setMargin( LAYOUT_MARGIN );
   121     layout->setSpacing( 5 );
   131     layout->setSpacing( LAYOUT_SPACING );
   122 
   132 
   123     mToolbarLayout = new QGridLayout( this );
   133     mToolbarLayout = new QGridLayout( this );
   124     mToolbarLayout->setHorizontalSpacing( 5 );
   134     mToolbarLayout->setHorizontalSpacing( LAYOUT_SPACING );
   125     mToolbarLayout->setVerticalSpacing( 5 );
   135     mToolbarLayout->setVerticalSpacing( LAYOUT_SPACING );
   126 
   136 
   127     mToolbarLayout->addWidget( mOrientationButton, 0, 0 );
   137     mToolbarLayout->addWidget( mOrientationButton, 0, 0 );
   128     mToolbarLayout->addWidget( mVolUpButton, 0, 1 );
   138     mToolbarLayout->addWidget( mVolUpButton, 0, 1 );
   129     mToolbarLayout->addWidget( mVolDownButton, 1, 1 );
   139     mToolbarLayout->addWidget( mVolDownButton, 1, 1 );
   130     mToolbarLayout->addWidget( mHeadsetButton, 1, 0 );
   140     mToolbarLayout->addWidget( mHeadsetButton, 1, 0 );
   131     mToolbarLayout->addWidget( mAddSongButton, 2, 0 );
   141     mToolbarLayout->addWidget( mAddSongButton, 2, 0 );
   132     mToolbarLayout->addWidget( mClearSongButton, 2, 1 );
   142     mToolbarLayout->addWidget( mClearSongButton, 2, 1 );
   133     mToolbarLayout->addWidget( mOfflineButton, 3, 0 );
   143     mToolbarLayout->addWidget( mAddRadiotextButton, 3, 0 );
       
   144     mToolbarLayout->addWidget( mClearRadiotextButton, 3, 1 );
       
   145     mToolbarLayout->addWidget( mOfflineButton, 4, 0 );
   134 
   146 
   135     QGridLayout* themeLayout = new QGridLayout( this );
   147     QGridLayout* themeLayout = new QGridLayout( this );
   136     themeLayout->addWidget( new QLabel( "Theme:", this ), 0, 0 );
   148     themeLayout->addWidget( new QLabel( "Theme:", this ), 0, 0 );
   137     themeLayout->addWidget( mThemeBox, 0, 1 );
   149     themeLayout->addWidget( mThemeBox, 0, 1 );
   138     themeLayout->setColumnStretch( 1, 2 );
   150     themeLayout->setColumnStretch( 1, 2 );
   139 
   151 
   140     mToolbarLayout->addLayout( themeLayout, 3, 1 );
   152     mToolbarLayout->addLayout( themeLayout, 4, 1 );
   141     mToolbarLayout->setColumnStretch( 0, 1 );
   153     mToolbarLayout->setColumnStretch( 0, 1 );
   142     mToolbarLayout->setColumnStretch( 1, 1 );
   154     mToolbarLayout->setColumnStretch( 1, 1 );
   143 
   155 
   144     layout->addItem( mToolbarLayout );
   156     layout->addItem( mToolbarLayout );
   145     layout->addWidget( radioWindow );
   157     layout->addWidget( radioWindow );
   250 }
   262 }
   251 
   263 
   252 /*!
   264 /*!
   253  * Private slot
   265  * Private slot
   254  */
   266  */
       
   267 void Win32Window::addRadiotext()
       
   268 {
       
   269     RadioEngineWrapperPrivate::instance()->addRadiotext( "This is a long bit of radio text that spans multiple lines." );
       
   270 }
       
   271 
       
   272 /*!
       
   273  * Private slot
       
   274  */
       
   275 void Win32Window::clearRadiotext()
       
   276 {
       
   277     RadioEngineWrapperPrivate::instance()->clearRadiotext();
       
   278 }
       
   279 
       
   280 /*!
       
   281  * Private slot
       
   282  */
   255 void Win32Window::toggleOffline()
   283 void Win32Window::toggleOffline()
   256 {
   284 {
   257     bool offline = !RadioEngineWrapperPrivate::instance()->isOffline();
   285     bool offline = !RadioEngineWrapperPrivate::instance()->isOffline();
   258     RadioEngineWrapperPrivate::instance()->setOffline( offline );
   286     RadioEngineWrapperPrivate::instance()->setOffline( offline );
   259     if ( offline ) {
   287     if ( offline ) {
   269 void Win32Window::changeTheme( const QString& theme )
   297 void Win32Window::changeTheme( const QString& theme )
   270 {
   298 {
   271     LOG_FORMAT( "Changing to theme %s", GETSTRING( theme ) );
   299     LOG_FORMAT( "Changing to theme %s", GETSTRING( theme ) );
   272     QLocalSocket socket;
   300     QLocalSocket socket;
   273     socket.connectToServer( "hbthemeserver" );
   301     socket.connectToServer( "hbthemeserver" );
   274     if ( socket.waitForConnected( 3000 ) ) {
   302     if ( socket.waitForConnected( THEME_CHANGE_CONNECT_WAIT ) ) {
   275         QByteArray outputByteArray;
   303         QByteArray outputByteArray;
   276         QDataStream outputDataStream( &outputByteArray, QIODevice::WriteOnly );
   304         QDataStream outputDataStream( &outputByteArray, QIODevice::WriteOnly );
   277         outputDataStream << 4; // EThemeSelection from HbThemeServerRequest in hbthemecommon_p.h
   305         outputDataStream << THEME_CHANGE_REQUEST; // EThemeSelection from HbThemeServerRequest in hbthemecommon_p.h
   278         outputDataStream << theme;
   306         outputDataStream << theme;
   279         socket.write( outputByteArray );
   307         socket.write( outputByteArray );
   280         socket.flush();
   308         socket.flush();
   281     }
   309     }
   282 }
   310 }