qthighway/tests/testapps/testapp2/testapp2.cpp
changeset 1 2b40d63a9c3d
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 /*
       
     2 #
       
     3 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 # All rights reserved.
       
     5 #
       
     6 # This program is free software: you can redistribute it and/or modify
       
     7 # it under the terms of the GNU Lesser General Public License as published by
       
     8 # the Free Software Foundation, version 2.1 of the License.
       
     9 #
       
    10 # This program is distributed in the hope that it will be useful,
       
    11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13 # GNU Lesser General Public License for more details.
       
    14 #
       
    15 # You should have received a copy of the GNU Lesser General Public License
       
    16 # along with this program.  If not,
       
    17 # see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    18 #
       
    19 # Description:
       
    20 #
       
    21 */
       
    22 
       
    23 #include <QDebug>
       
    24 #include <xqservicelog.h>
       
    25 #include <QApplication>
       
    26 #include <QKeyEvent>
       
    27 #include <QLabel>
       
    28 #include <QVBoxLayout>
       
    29 #include <QStackedWidget>
       
    30 #include <QImageReader>
       
    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 "testapp2.h"
       
    41 
       
    42 TestApp2::TestApp2(QWidget *parent, Qt::WFlags f) :
       
    43     QWidget(parent, f)
       
    44     {
       
    45     QPalette p = qApp->palette();
       
    46     QColor color(80, 20, 20);
       
    47     QColor bg(256, 20, 20);
       
    48     p.setColor(QPalette::Highlight, color.lighter(200));
       
    49     p.setColor(QPalette::Text, Qt::white);
       
    50     p.setColor(QPalette::Base, bg);
       
    51     p.setColor(QPalette::WindowText, Qt::white);
       
    52     p.setColor(QPalette::Window, bg);
       
    53     p.setColor(QPalette::ButtonText, Qt::white);
       
    54     p.setColor(QPalette::Button, color.lighter(150));
       
    55     p.setColor(QPalette::Link, QColor(240, 40, 40));
       
    56 
       
    57     qApp->setPalette(p);
       
    58 
       
    59     QPushButton *quitButton = new QPushButton(tr("quit"));
       
    60     connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
       
    61 
       
    62     QPushButton *sendButton = new QPushButton(tr("asynsend 10 times"));
       
    63 
       
    64     connect(sendButton, SIGNAL(clicked()), this, SLOT(asyncsend()));
       
    65 
       
    66     label = new QLabel("Test App2");
       
    67 
       
    68     QVBoxLayout *vl = new QVBoxLayout;
       
    69     vl->setMargin(0);
       
    70     vl->setSpacing(0);
       
    71 
       
    72     vl->addWidget(label);
       
    73     vl->addWidget(sendButton);
       
    74     vl->addWidget(quitButton);
       
    75 
       
    76     setLayout(vl);
       
    77     //showMaximized();
       
    78     showFullScreen();
       
    79 
       
    80     i = 0;
       
    81     request = NULL;
       
    82     asyncsend();
       
    83     }
       
    84 
       
    85 void TestApp2::requestCompleted(const QVariant& data)
       
    86     {
       
    87     i++;
       
    88     qDebug() << "[QTH] [TestApp2] result: " << data.toString() << "Times" << i;
       
    89 
       
    90     if (i <= 10)
       
    91         {
       
    92         qDebug() << "[QTH] [TestApp2] trigger again()";
       
    93         QString string;
       
    94         string.append("Test app2 -->");
       
    95         string.append(48 + i);
       
    96         string.append("times");
       
    97         label->setText(string);
       
    98         asyncsend();
       
    99         }
       
   100     else
       
   101         {
       
   102         label->setText("Test app2 DONE!");
       
   103         /*if(request)
       
   104          {
       
   105          delete request;
       
   106          request=NULL;
       
   107          }*/
       
   108         qDebug() << "[QTH] [TestApp2] DONE 10-time sending !!!!!!!!!!!";
       
   109         }
       
   110     }
       
   111 
       
   112 void TestApp2::asyncsend()
       
   113     {
       
   114     qDebug() << "[QTH] [TestApp2] asyncsend";
       
   115 
       
   116     QString service(
       
   117             "com.nokia.services.testservice.TestService");
       
   118     QString method("asyncNoParams()");
       
   119 
       
   120     if (!request)
       
   121         {
       
   122         request = new XQServiceRequest(service, method, false);
       
   123         connect(request, SIGNAL(requestCompleted(QVariant)), this,
       
   124                 SLOT(requestCompleted(QVariant)));
       
   125         }
       
   126 
       
   127     bool res = request->send();
       
   128     }
       
   129 
       
   130 int main(int argc, char* argv[])
       
   131     {
       
   132     qInstallMsgHandler(XQSERVICEMESSAGEHANDLER);
       
   133     qDebug() << "[QTH] [TestApp2] App2 started";
       
   134     QApplication a(argc, argv);
       
   135 
       
   136     TestApp2* tester = new TestApp2();
       
   137 
       
   138     int rv = a.exec();
       
   139     qDebug() << "[QTH] [TestApp2] App2 exits";
       
   140     delete tester;
       
   141     return rv;
       
   142     }
       
   143