radioapp/radioapplication/src/testwindow_win32.cpp
changeset 13 46974bebc798
child 14 63aabac4416d
equal deleted inserted replaced
0:f3d95d9c00ab 13:46974bebc798
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <qpushbutton>
       
    20 #include <qgridlayout>
       
    21 #include <qvboxlayout>
       
    22 #include <hbmainwindow.h>
       
    23 #include <qtimer.h>
       
    24 #include <qmessagebox>
       
    25 
       
    26 // User includes
       
    27 #include "testwindow_win32.h"
       
    28 #include "radioapplication.h"
       
    29 #include "radiologger.h"
       
    30 #include "radio_global.h"
       
    31 #include "radioenginewrapper_win32_p.h"
       
    32 
       
    33 const int KWindowWidth = 360;
       
    34 const int KWindowHeight = 640;
       
    35 
       
    36 const QString KBtnDisconnectHeadset = "Disconnect Headset";
       
    37 const QString KBtnConnectHeadset = "Connect Headset";
       
    38 
       
    39 const QString KBtnGoOffline = "Go Offline";
       
    40 const QString KBtnGoOnline = "Go Online";
       
    41 
       
    42 struct Song
       
    43 {
       
    44     const char* mArtist;
       
    45     const char* mTitle;
       
    46 };
       
    47 
       
    48 const Song KRecognizedSongs[] = {
       
    49     { "Metallica", "One" },
       
    50     { "Madonna", "Like a Virgin" },
       
    51     { "Rammstein", "Der Meister" },
       
    52     { "System of a Down", "Aerials" },
       
    53     { "Buckethead", "Jordan" },
       
    54     { "Faith No More", "Epic" }
       
    55 };
       
    56 const int KSongsCount = sizeof( KRecognizedSongs ) / sizeof( KRecognizedSongs[0] );
       
    57 
       
    58 /*!
       
    59  *
       
    60  */
       
    61 Win32Window::Win32Window() :
       
    62     QWidget( 0 ),
       
    63     mOrientationButton( new QPushButton( "Change Orientation", this ) ),
       
    64     mVolUpButton( new QPushButton( "Volume Up", this ) ),
       
    65     mVolDownButton( new QPushButton( "Volume Down", this ) ),
       
    66     mHeadsetButton( new QPushButton( KBtnDisconnectHeadset, this ) ),
       
    67     mAddSongButton( new QPushButton( "Add Song", this ) ),
       
    68     mClearSongButton( new QPushButton( "Clear Song", this ) ),
       
    69     mOfflineButton( new QPushButton( KBtnGoOffline, this ) ),
       
    70     mHeadsetConnected( true ),
       
    71     mVolume( 5 ),
       
    72     mToolbarHeight( 0 ),
       
    73     mRadioWindow( 0 ),
       
    74     mSongIndex( 0 )
       
    75 {
       
    76     connectAndTest( mOrientationButton, SIGNAL(clicked()), this, SLOT(changeOrientation()) );
       
    77     connectAndTest( mVolUpButton, SIGNAL(clicked()), this, SLOT(volumeUp()) );
       
    78     connectAndTest( mVolDownButton, SIGNAL(clicked()), this, SLOT(volumeDown()) );
       
    79     connectAndTest( mHeadsetButton, SIGNAL(clicked()), this, SLOT(toggleHeadsetStatus()) );
       
    80     connectAndTest( mAddSongButton, SIGNAL(clicked()), this, SLOT(addSong()) );
       
    81     connectAndTest( mClearSongButton, SIGNAL(clicked()), this, SLOT(clearSong()) );
       
    82     connectAndTest( mOfflineButton, SIGNAL(clicked()), this, SLOT(toggleOffline()) );
       
    83 
       
    84     QTimer::singleShot( 0, this, SLOT(updateWindowSize()) );
       
    85 }
       
    86 
       
    87 /*!
       
    88  *
       
    89  */
       
    90 Win32Window::~Win32Window()
       
    91 {
       
    92 }
       
    93 
       
    94 /*!
       
    95  *
       
    96  */
       
    97 void Win32Window::addHbWindow( HbMainWindow* radioWindow )
       
    98 {
       
    99     mRadioWindow = radioWindow;
       
   100     mOrientation = mRadioWindow->orientation();
       
   101     updateWindowSize();
       
   102 
       
   103     QVBoxLayout* layout = new QVBoxLayout( this );
       
   104     layout->setMargin( 5 );
       
   105     layout->setSpacing( 5 );
       
   106 
       
   107     mToolbarLayout = new QGridLayout( this );
       
   108     mToolbarLayout->setHorizontalSpacing( 5 );
       
   109     mToolbarLayout->setVerticalSpacing( 5 );
       
   110 
       
   111     mToolbarLayout->addWidget( mOrientationButton, 0, 0 );
       
   112     mToolbarLayout->addWidget( mVolUpButton, 0, 1 );
       
   113     mToolbarLayout->addWidget( mVolDownButton, 1, 1 );
       
   114     mToolbarLayout->addWidget( mHeadsetButton, 1, 0 );
       
   115     mToolbarLayout->addWidget( mAddSongButton, 2, 0 );
       
   116     mToolbarLayout->addWidget( mClearSongButton, 2, 1 );
       
   117     mToolbarLayout->addWidget( mOfflineButton, 3, 0 );
       
   118 
       
   119     layout->addItem( mToolbarLayout );
       
   120     layout->addWidget( radioWindow );
       
   121 
       
   122     setLayout( layout );
       
   123 }
       
   124 
       
   125 /*!
       
   126  *
       
   127  */
       
   128 void Win32Window::init()
       
   129 {
       
   130     RadioEngineWrapperPrivate* wrapper = RadioEngineWrapperPrivate::instance();
       
   131     if ( wrapper ) {
       
   132         QString error = wrapper->dataParsingError();
       
   133         if ( !error.isEmpty() ) {
       
   134             QMessageBox msg( QMessageBox::Warning, "Unable to parse radio settings", error, QMessageBox::Ok );
       
   135             msg.exec();
       
   136         }
       
   137 
       
   138         if ( wrapper->isOffline() ) {
       
   139             mOfflineButton->setText( KBtnGoOnline );
       
   140         }
       
   141     }
       
   142 }
       
   143 
       
   144 /*!
       
   145  * Private slot
       
   146  */
       
   147 void Win32Window::changeOrientation()
       
   148 {
       
   149     if ( mOrientation == Qt::Horizontal ) {
       
   150         mOrientation = Qt::Vertical;
       
   151     } else {
       
   152         mOrientation = Qt::Horizontal;
       
   153     }
       
   154 
       
   155     mRadioWindow->setOrientation( mOrientation );
       
   156     updateWindowSize();
       
   157 }
       
   158 
       
   159 /*!
       
   160  * Private slot
       
   161  */
       
   162 void Win32Window::volumeUp()
       
   163 {
       
   164     if ( ++mVolume > KMaximumVolumeLevel ) {
       
   165         mVolume = KMaximumVolumeLevel;
       
   166     }
       
   167     RadioEngineWrapperPrivate::instance()->setVolume( mVolume );
       
   168 }
       
   169 
       
   170 /*!
       
   171  * Private slot
       
   172  */
       
   173 void Win32Window::volumeDown()
       
   174 {
       
   175     if ( --mVolume < 0 ) {
       
   176         mVolume = 0;
       
   177     }
       
   178     RadioEngineWrapperPrivate::instance()->setVolume( mVolume );
       
   179 }
       
   180 
       
   181 /*!
       
   182  * Private slot
       
   183  */
       
   184 void Win32Window::toggleHeadsetStatus()
       
   185 {
       
   186     mHeadsetConnected = !mHeadsetConnected;
       
   187     if ( mHeadsetConnected ) {
       
   188         mHeadsetButton->setText( KBtnDisconnectHeadset );
       
   189     } else {
       
   190         mHeadsetButton->setText( KBtnConnectHeadset );
       
   191     }
       
   192     RadioEngineWrapperPrivate::instance()->setHeadsetStatus( mHeadsetConnected );
       
   193 }
       
   194 
       
   195 /*!
       
   196  * Private slot
       
   197  */
       
   198 void Win32Window::updateWindowSize()
       
   199 {
       
   200     if ( mOrientation == Qt::Horizontal ) {
       
   201         resize( KWindowHeight, KWindowWidth + mToolbarHeight );
       
   202     } else {
       
   203         resize( KWindowWidth, KWindowHeight + mToolbarHeight );
       
   204     }
       
   205 }
       
   206 
       
   207 /*!
       
   208  * Private slot
       
   209  */
       
   210 void Win32Window::addSong()
       
   211 {
       
   212     Song song = KRecognizedSongs[mSongIndex++];
       
   213     mSongIndex %= KSongsCount;
       
   214 
       
   215     RadioEngineWrapperPrivate::instance()->addSong( song.mArtist, song.mTitle );
       
   216 }
       
   217 
       
   218 /*!
       
   219  * Private slot
       
   220  */
       
   221 void Win32Window::clearSong()
       
   222 {
       
   223     RadioEngineWrapperPrivate::instance()->clearSong();
       
   224 }
       
   225 
       
   226 /*!
       
   227  * Private slot
       
   228  */
       
   229 void Win32Window::toggleOffline()
       
   230 {
       
   231     bool offline = !RadioEngineWrapperPrivate::instance()->isOffline();
       
   232     RadioEngineWrapperPrivate::instance()->setOffline( offline );
       
   233     if ( offline ) {
       
   234         mOfflineButton->setText( KBtnGoOnline );
       
   235     } else {
       
   236         mOfflineButton->setText( KBtnGoOffline );
       
   237     }
       
   238 }
       
   239 
       
   240 /*!
       
   241  *
       
   242  */
       
   243 void Win32Window::resizeEvent( QResizeEvent* event )
       
   244 {
       
   245     QWidget::resizeEvent( event );
       
   246     mToolbarHeight = mToolbarLayout->contentsRect().height();
       
   247 }