qthighway/examples/notifications/client/src/serviceclient.cpp
changeset 26 3d09643def13
equal deleted inserted replaced
24:9d760f716ca8 26:3d09643def13
       
     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 <QApplication>
       
    23 #include <QKeyEvent>
       
    24 #include <QLabel>
       
    25 #include <QVBoxLayout>
       
    26 #include <QStackedWidget>
       
    27 #include <QImageReader>
       
    28 #include <QDebug>
       
    29 #include <QTimer>
       
    30 #include <QPushButton>
       
    31 #include <QLineEdit>
       
    32 #include <QDebug>
       
    33 #include <QString>
       
    34 #include <QCheckBox>
       
    35 
       
    36 #include <QListView>
       
    37 
       
    38 #include <xqservicerequest.h>
       
    39 #include <xqservicelog.h>
       
    40 
       
    41 #include <xqappmgr.h>
       
    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     mEmb = new QCheckBox("Embedded");
       
    74     mCheckAsyncAnswer = new QCheckBox("Asynchronous Answer");
       
    75     mCheckDeleteRequest = new QCheckBox("Delete request");
       
    76     mCheckDeleteRequest->setCheckState(Qt::Checked);
       
    77     
       
    78     mTextEdit = new QLineEdit("+123456");
       
    79     
       
    80     mTextRetValue = new QLineEdit("no ret value set");
       
    81 
       
    82     QLabel *label = new QLabel("CLIENT TEST");
       
    83 
       
    84     QLabel *status = new QLabel("-- status --");
       
    85 
       
    86     QVBoxLayout *vl = new QVBoxLayout;
       
    87     vl->setMargin(0);
       
    88     vl->setSpacing(0);
       
    89 
       
    90     vl->addWidget(label);
       
    91     vl->addWidget(mCheckSync);
       
    92     vl->addWidget(mCheckAsyncAnswer);
       
    93     vl->addWidget(mEmb);
       
    94     vl->addWidget(mCheckDeleteRequest);
       
    95     vl->addWidget(mTextEdit);
       
    96     vl->addWidget(mTextRetValue);
       
    97     vl->addWidget(status);
       
    98     vl->addStretch(10);
       
    99     vl->addWidget(callButton);
       
   100     vl->addWidget(quitButton);
       
   101 
       
   102     setLayout(vl);
       
   103 
       
   104 #if defined(Q_WS_X11) || defined(Q_WS_WIN)
       
   105     setFixedSize(QSize(360,640)); // nHD
       
   106 #elif defined(Q_WS_S60)
       
   107     showMaximized();
       
   108     showFullScreen();
       
   109 #endif
       
   110 }
       
   111 
       
   112 ServiceClient::~ServiceClient()
       
   113 {
       
   114     XQSERVICE_DEBUG_PRINT("ServiceClient::~ServiceClient");
       
   115 }
       
   116 
       
   117 void ServiceClient::dial()
       
   118 {
       
   119     XQSERVICE_DEBUG_PRINT("ServiceClient::dial");
       
   120     if (snd) {
       
   121         delete snd ;
       
   122     }
       
   123     mTextRetValue->setText("no ret value set");
       
   124 
       
   125     bool isSync = (mCheckSync->checkState() == Qt::Checked);
       
   126     bool asyncAnswer = (mCheckAsyncAnswer->checkState() == Qt::Checked);
       
   127     bool deleteRequest = (mCheckDeleteRequest->checkState() == Qt::Checked);
       
   128     
       
   129     snd = mgr.create("com.nokia.services.hbserviceprovider", "dialer", "dial(QString,bool)", isSync);
       
   130     
       
   131     QList<QVariant> args;
       
   132     
       
   133     args << QVariant(mTextEdit->text());
       
   134     args << QVariant(asyncAnswer);
       
   135     
       
   136     snd->setArguments(args);
       
   137     
       
   138     snd->setEmbedded(mEmb->checkState());
       
   139 
       
   140     if (isSync) {
       
   141         QVariant retValue;
       
   142         connect(snd, SIGNAL(requestError(int)), this, SLOT(requestError(int)));
       
   143         bool ret = snd->send(retValue);    
       
   144         mTextRetValue->setText(retValue.toString());
       
   145     } else {
       
   146         bool ret = snd->send();    
       
   147         connect(snd, SIGNAL(requestCompleted(QVariant)), this, SLOT(requestCompleted(QVariant)));
       
   148         connect(snd, SIGNAL(requestError(int)), this, SLOT(requestError(int)));
       
   149     }
       
   150     
       
   151     if (deleteRequest) {
       
   152         delete snd;
       
   153         snd = NULL;
       
   154     }
       
   155 }
       
   156 
       
   157 void ServiceClient::requestCompleted(const QVariant& value)
       
   158 {
       
   159     XQSERVICE_DEBUG_PRINT("ServiceClient::requestCompleted");
       
   160     mTextRetValue->setText(value.toString());
       
   161 }
       
   162 
       
   163 void ServiceClient::requestError(int err)
       
   164 {
       
   165     XQSERVICE_DEBUG_PRINT("ServiceClient::requestError");
       
   166     mTextRetValue->setText("error: " + QString::number(err));
       
   167 }