qthighway/examples/serviceclient/src/serviceclient.cpp
branchRCL_3
changeset 9 5d007b20cfd0
equal deleted inserted replaced
8:885c2596c964 9:5d007b20cfd0
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 * 
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not, 
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
       
    19 *
       
    20 */
       
    21 
       
    22 #include "xqservicelog.h"
       
    23 
       
    24 #include <QApplication>
       
    25 #include <QKeyEvent>
       
    26 #include <QLabel>
       
    27 #include <QVBoxLayout>
       
    28 #include <QStackedWidget>
       
    29 #include <QImageReader>
       
    30 #include <QDebug>
       
    31 #include <QTimer>
       
    32 #include <QPushButton>
       
    33 #include <QLineEdit>
       
    34 #include <QDebug>
       
    35 #include <QString>
       
    36 #include <QCheckBox>
       
    37 
       
    38 #include <QListView>
       
    39 
       
    40 #include <xqservicerequest.h>
       
    41 
       
    42 #include "serviceclient.h"
       
    43 
       
    44 ServiceClient::ServiceClient(QWidget *parent, Qt::WFlags f)
       
    45     : QWidget(parent, f)
       
    46 {
       
    47     XQSERVICE_DEBUG_PRINT("ServiceClient::ServiceClient");
       
    48     snd = NULL;
       
    49     /* Adjust the palette */
       
    50 #if defined(Q_WS_S60)
       
    51     QPalette p = qApp->palette();
       
    52     QColor color(80,20,20);
       
    53     QColor bg(256,20,20);
       
    54     p.setColor(QPalette::Highlight, color.lighter(200));
       
    55     p.setColor(QPalette::Text, Qt::white);
       
    56     p.setColor(QPalette::Base, bg);
       
    57     p.setColor(QPalette::WindowText, Qt::white);
       
    58     p.setColor(QPalette::Window, bg);
       
    59     p.setColor(QPalette::ButtonText, Qt::white);
       
    60     p.setColor(QPalette::Button, color.lighter(150));
       
    61     p.setColor(QPalette::Link, QColor(240,40,40));
       
    62 
       
    63     qApp->setPalette(p);
       
    64 #endif
       
    65 
       
    66     QPushButton *quitButton = new QPushButton(tr("quit"));
       
    67     connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
       
    68 
       
    69     QPushButton *callButton = new QPushButton(tr("call"));
       
    70     connect(callButton, SIGNAL(clicked()), this, SLOT(dial()));
       
    71 
       
    72     mCheckSync = new QCheckBox("Synchronous send");
       
    73     mCheckAsyncAnswer = new QCheckBox("Asynchronous Answer");
       
    74     mCheckDeleteRequest = new QCheckBox("Delete request");
       
    75     mCheckDeleteRequest->setCheckState(Qt::Checked);
       
    76     
       
    77     mTextEdit = new QLineEdit("+123456");
       
    78     
       
    79     mTextRetValue = new QLineEdit("no ret value set");
       
    80 
       
    81     QLabel *label = new QLabel("CLIENT TEST");
       
    82 
       
    83     QVBoxLayout *vl = new QVBoxLayout;
       
    84     vl->setMargin(0);
       
    85     vl->setSpacing(0);
       
    86 
       
    87     vl->addWidget(label);
       
    88     vl->addWidget(mCheckSync);
       
    89     vl->addWidget(mCheckAsyncAnswer);
       
    90     vl->addWidget(mCheckDeleteRequest);
       
    91     vl->addWidget(mTextEdit);
       
    92     vl->addWidget(mTextRetValue);
       
    93     vl->addWidget(new QLabel(" "));
       
    94     vl->addWidget(callButton);
       
    95     vl->addWidget(quitButton);
       
    96 
       
    97     setLayout(vl);
       
    98 
       
    99 #if defined(Q_WS_X11) || defined(Q_WS_WIN)
       
   100     setFixedSize(QSize(360,640)); // nHD
       
   101 #elif defined(Q_WS_S60)
       
   102     showMaximized();
       
   103     showFullScreen();
       
   104 #endif
       
   105 }
       
   106 
       
   107 ServiceClient::~ServiceClient()
       
   108 {
       
   109     XQSERVICE_DEBUG_PRINT("ServiceClient::~ServiceClient");
       
   110 }
       
   111 
       
   112 void ServiceClient::dial()
       
   113 {
       
   114     XQSERVICE_DEBUG_PRINT("ServiceClient::dial");
       
   115     if (snd) {
       
   116         delete snd ;
       
   117     }
       
   118     mTextRetValue->setText("no ret value set");
       
   119 
       
   120     bool isSync = (mCheckSync->checkState() == Qt::Checked);
       
   121     bool asyncAnswer = (mCheckAsyncAnswer->checkState() == Qt::Checked);
       
   122     bool deleteRequest = (mCheckDeleteRequest->checkState() == Qt::Checked);
       
   123     snd = new XQServiceRequest("com.nokia.services.serviceapp.Dialer","dial(QString,bool)",isSync);
       
   124     *snd << mTextEdit->text();
       
   125     *snd << asyncAnswer;
       
   126 
       
   127     if (isSync) {
       
   128         int retValue;
       
   129         connect(snd, SIGNAL(requestError(int)), this, SLOT(requestError(int)));
       
   130         bool ret = snd->send(retValue);    
       
   131         mTextRetValue->setText(QString::number(retValue));
       
   132     }
       
   133     else {
       
   134         bool ret = snd->send();    
       
   135         connect(snd, SIGNAL(requestCompleted(QVariant)), this, SLOT(requestCompleted(QVariant)));
       
   136         connect(snd, SIGNAL(requestError(int)), this, SLOT(requestError(int)));
       
   137     }
       
   138     if (deleteRequest) {
       
   139         delete snd;
       
   140         snd = NULL;
       
   141     }
       
   142 }
       
   143 
       
   144 void ServiceClient::requestCompleted(const QVariant& value)
       
   145 {
       
   146     XQSERVICE_DEBUG_PRINT("ServiceClient::requestCompleted");
       
   147     mTextRetValue->setText(value.toString());
       
   148 }
       
   149 
       
   150 void ServiceClient::requestError(int err)
       
   151 {
       
   152     XQSERVICE_DEBUG_PRINT("ServiceClient::requestError");
       
   153     mTextRetValue->setText("error: " + QString::number(err));
       
   154 }