qthighway/tests/testapps/testapp/testapp.cpp
changeset 18 1b485afba084
parent 16 19b186e43276
child 28 19321a443c34
equal deleted inserted replaced
16:19b186e43276 18:1b485afba084
     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 <QDebug>
       
    32 #include <QTimer>
       
    33 #include <QPushButton>
       
    34 #include <QLineEdit>
       
    35 #include <QDebug>
       
    36 #include <QString>
       
    37 #include <QCheckBox>
       
    38 
       
    39 #include <QListView>
       
    40 
       
    41 #include "testapp.h"
       
    42 
       
    43 TestApp1::TestApp1( QWidget *parent, Qt::WFlags f ) : QWidget( parent,f )
       
    44     {
       
    45     qDebug() << "[QTH] [TestApp1] TestApp1: START";
       
    46     QPalette p = qApp->palette();
       
    47     QColor color(80,20,20);
       
    48     QColor bg(256,20,20);
       
    49     p.setColor(QPalette::Highlight, color.lighter(200));
       
    50     p.setColor(QPalette::Text, Qt::white);
       
    51     p.setColor(QPalette::Base, bg);
       
    52     p.setColor(QPalette::WindowText, Qt::white);
       
    53     p.setColor(QPalette::Window, bg);
       
    54     p.setColor(QPalette::ButtonText, Qt::white);
       
    55     p.setColor(QPalette::Button, color.lighter(150));
       
    56     p.setColor(QPalette::Link, QColor(240,40,40));
       
    57 
       
    58     qApp->setPalette(p);
       
    59 
       
    60     QPushButton *quitButton = new QPushButton(tr("quit"));
       
    61     connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
       
    62 
       
    63     QPushButton *sendButton = new QPushButton(tr("asynsend 10 times"));
       
    64     connect(sendButton, SIGNAL(clicked()), this, SLOT(asyncsend()));
       
    65 
       
    66     label = new QLabel("Test App1");
       
    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     qDebug() << "[QTH] [TestApp1] TestApp1: END";
       
    84     }
       
    85 
       
    86 void TestApp1::requestCompletedWithError(int err)
       
    87     {
       
    88     qDebug() << "[QTH] [TestApp1] requestCompletedWithError START ";
       
    89     qDebug() << "[QTH] [TestApp1] error = " << err << " !!!";
       
    90     qDebug() << "[QTH] [TestApp1] requestCompletedWithError END ";
       
    91     }
       
    92 
       
    93 void TestApp1::requestCompleted(const QVariant& data)
       
    94 {
       
    95     i++;
       
    96     qDebug() << "[QTH] [TestApp1] requestCompleted START ";
       
    97 	qDebug() << "[QTH] [TestApp1] \t data: " << data.toString() << ", i: " << i;
       
    98     
       
    99     if ( i <= 20 )
       
   100         {
       
   101         qDebug() << "[QTH] [TestApp1] \t i <= 20 trigger again()";
       
   102         QString string;
       
   103         string.append("Test app1 -->");
       
   104         string.append(48+i);
       
   105         string.append("times");
       
   106         label->setText(string);
       
   107         asyncsend();
       
   108         }
       
   109     else
       
   110         {
       
   111 		/*qDebug() << "[QTH] [TestApp1] \t i > 20, setText()";
       
   112         label->setText("Test app1 Done!");
       
   113         if(request)
       
   114             {
       
   115 			qDebug() << "[QTH] [TestApp1] \t \t request != null, delete request";
       
   116             delete request;
       
   117             request=NULL;
       
   118             }*/
       
   119 		qDebug() << "[QTH] [TestApp1] \t request sent 20 times!!!";
       
   120         }
       
   121 
       
   122 	qDebug() << "[QTH] [TestApp1] requestCompleted STOP";
       
   123 }
       
   124 
       
   125 
       
   126 
       
   127 void TestApp1::asyncsend()
       
   128 {
       
   129 	qDebug() << "[QTH] [TestApp1] asyncsend: START";
       
   130 
       
   131 	QString testString("Test Application 1");
       
   132 	int testInt(112233);
       
   133 
       
   134 	QString service("com.nokia.services.testservice.TestService");
       
   135 	QString method("asyncWithParams(QString,int)");
       
   136 
       
   137 	if (!request)
       
   138 		{
       
   139 		qDebug() << "[QTH] [TestApp1] \t creating request";
       
   140 		request = new XQServiceRequest(service, method, false);
       
   141 		qDebug() << "[QTH] [TestApp1] \t connecting signal request->requestCompleted to slot this.requestCompleted";
       
   142 		bool res = connect(request, SIGNAL(requestCompleted(QVariant)), this, SLOT(requestCompleted(QVariant)) );
       
   143 		qDebug() << "[QTH] [TestApp1] \t connect = " << res;
       
   144 		qDebug() << "[QTH] [TestApp1] \t connecting signal request->requestError to slot this.requestCompletedWithError";
       
   145 		res = connect(request, SIGNAL(requestError(int)), this, SLOT(requestCompletedWithError(int)) );
       
   146 		qDebug() << "[QTH] [TestApp1] \t connect = " << res;
       
   147 		*request << testString;
       
   148 		*request << testInt;
       
   149 		qDebug() << "[QTH] [TestApp1] \t request: " << testString << ", " << testInt;
       
   150 		}
       
   151 
       
   152 	qDebug() << "[QTH] [TestApp1] \t before request->send()";
       
   153 	bool res = request->send();
       
   154 	qDebug() << "[QTH] [TestApp1] \t after request->send()";
       
   155 	qDebug() << "[QTH] [TestApp1] asyncsend: STOP";
       
   156 }
       
   157 
       
   158 int main(int argc, char* argv[])
       
   159    {
       
   160     qInstallMsgHandler(XQSERVICEMESSAGEHANDLER);
       
   161     qDebug() << "[QTH] [TestApp1] main START";
       
   162     QApplication a(argc, argv);
       
   163 
       
   164     TestApp1* tester = new TestApp1();
       
   165     
       
   166     int rv = a.exec();    
       
   167     qDebug() << "[QTH] [TestApp1] App1 exits";
       
   168     delete tester;
       
   169     qDebug() << "[QTH] [TestApp1] main END";
       
   170 	return rv;    
       
   171     }
       
   172