qthighway/examples/hbserviceprovider/src/hbserviceproviderview.cpp
branchRCL_3
changeset 10 cd2778e5acfe
parent 9 5d007b20cfd0
child 11 19a54be74e5e
equal deleted inserted replaced
9:5d007b20cfd0 10:cd2778e5acfe
     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 <hbapplication.h>
       
    25 #include <hbtoolbar.h>
       
    26 #include <hbaction.h>
       
    27 #include <HbLineEdit.h>
       
    28 #include <QTimer>
       
    29 #include <QGraphicsLinearLayout>
       
    30 
       
    31 #include <hbserviceproviderview.h>
       
    32 #include <xqserviceprovider.h>
       
    33 #include <xqservicerequest.h>
       
    34 #include <xqserviceutil.h>
       
    35 
       
    36 HbDialerView::HbDialerView(DialerService* service,QGraphicsItem *parent)
       
    37     : mService(service),HbView(parent)
       
    38 
       
    39 {
       
    40     XQSERVICE_DEBUG_PRINT("HbDialerView::HbDialerView");
       
    41     sndEmbedded = NULL;
       
    42     if (XQServiceUtil::isService())
       
    43     {
       
    44         setTitle(tr("HB Dialer As Service"));
       
    45     }
       
    46     else
       
    47     {
       
    48         setTitle(tr("HB Dialer As Non-Service"));
       
    49     }
       
    50 
       
    51     HbToolBar* toolBar = this->toolBar();
       
    52     
       
    53     HbAction* endAction = new HbAction("End Call"); 
       
    54     connect(endAction, SIGNAL(triggered()), this, SLOT(quit()));
       
    55     
       
    56     toolBar->addAction(endAction);
       
    57 
       
    58     if (XQServiceUtil::isEmbedded()) {
       
    59         HbAction* embeddedAction = new HbAction("Embed"); 
       
    60         connect(embeddedAction, SIGNAL(triggered()), this, SLOT(embed()));
       
    61         toolBar->addAction(embeddedAction);
       
    62     }
       
    63     
       
    64     QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical,this);
       
    65 
       
    66     mTextEdit = new HbLineEdit(this);
       
    67     mRetValue = new HbLineEdit(this);
       
    68     layout->addItem(mTextEdit);
       
    69     layout->addItem(mRetValue);
       
    70     setLayout(layout);    
       
    71 }
       
    72 
       
    73 HbDialerView::~HbDialerView()
       
    74 {
       
    75     XQSERVICE_DEBUG_PRINT("HbDialerView::~HbDialerView");
       
    76 }
       
    77 
       
    78 void HbDialerView::quit()
       
    79 {
       
    80     XQSERVICE_DEBUG_PRINT("HbDialerView::quit");
       
    81     connect(mService, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
       
    82     mService->complete();
       
    83 }
       
    84 
       
    85 void HbDialerView::embed()
       
    86 {
       
    87     XQSERVICE_DEBUG_PRINT("HbDialerView::embed");
       
    88     if (sndEmbedded)
       
    89         delete sndEmbedded;
       
    90     
       
    91     //XQServiceRequest snd("com.nokia.services.hbserviceprovider.Dialer","dial(QString)",true);
       
    92     sndEmbedded = new XQServiceRequest("com.nokia.services.serviceapp.Dialer","dial(QString,bool)",true);
       
    93     connect(sndEmbedded, SIGNAL(requestCompleted(QVariant)), this, SLOT(requestCompleted(QVariant)));
       
    94     *sndEmbedded << mTextEdit->text();
       
    95     *sndEmbedded << true;
       
    96     QVariant retValue;
       
    97     bool res=sndEmbedded->send();
       
    98     if (!res) {
       
    99         mRetValue->setText("send fail!");
       
   100     }
       
   101 }
       
   102 
       
   103 void HbDialerView::requestCompleted(const QVariant& value)
       
   104 {
       
   105     XQSERVICE_DEBUG_PRINT("HbDialerView::requestCompleted");
       
   106     mRetValue->setText(value.toString());
       
   107 }
       
   108 
       
   109 void HbDialerView::setNumber(const QString& number)
       
   110 {
       
   111     XQSERVICE_DEBUG_PRINT("HbDialerView::setNumber");
       
   112     mTextEdit->setText("Call from " + number);
       
   113 }
       
   114 
       
   115 DialerService::DialerService(QObject* parent)
       
   116 : XQServiceProvider("com.nokia.services.hbserviceprovider.Dialer",parent)
       
   117 {
       
   118     XQSERVICE_DEBUG_PRINT("DialerService::DialerService");
       
   119     publishAll();
       
   120 }
       
   121 
       
   122 DialerService::~DialerService()
       
   123 {
       
   124     XQSERVICE_DEBUG_PRINT("DialerService::~DialerService");
       
   125 }
       
   126 
       
   127 void DialerService::complete()
       
   128 {
       
   129     XQSERVICE_DEBUG_PRINT("DialerService::complete");
       
   130     QString retvalue =  "retValue="+mNumber;
       
   131     completeRequest(1,retvalue);
       
   132 }
       
   133 
       
   134 QString DialerService::dial(const QString& number)
       
   135 {
       
   136     XQSERVICE_DEBUG_PRINT("DialerService::dial");
       
   137     mNumber = number ;
       
   138     emit showView("dialer");
       
   139     emit setNumber(number);
       
   140     setCurrentRequestAsync();
       
   141     return "retValue="+number;
       
   142 }
       
   143 
       
   144 QString DialerService::dial(const QString& number, bool async)
       
   145 {
       
   146     XQSERVICE_DEBUG_PRINT("DialerService::dial (2)");
       
   147     return dial(number);
       
   148 }
       
   149 
       
   150 
       
   151 HbMapView::HbMapView(MapService* service, QGraphicsItem *parent)
       
   152     : mMapService(service), HbView(parent) 
       
   153 
       
   154 {
       
   155     XQSERVICE_DEBUG_PRINT("HbMapView::HbMapView");
       
   156     setTitle(tr("HB Map Service"));
       
   157     
       
   158     HbToolBar* toolBar = this->toolBar();
       
   159     
       
   160     HbAction* endAction = new HbAction("Done"); 
       
   161     connect(endAction, SIGNAL(triggered()), this, SLOT(quit()));
       
   162 
       
   163     HbAction* addAction = new HbAction("Add"); 
       
   164     connect(addAction, SIGNAL(triggered()), this, SLOT(addAddress()));
       
   165 
       
   166     HbAction* embedAction = new HbAction("Embed");
       
   167     connect(embedAction, SIGNAL(triggered()), this, SLOT(embed()));
       
   168 
       
   169     toolBar->addAction(endAction);
       
   170     toolBar->addAction(addAction);
       
   171     toolBar->addAction(embedAction);
       
   172     
       
   173     QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical,this);
       
   174 
       
   175     mTextAddress = new HbLineEdit(this);
       
   176     mTextCity = new HbLineEdit(this);
       
   177     mTextCountry = new HbLineEdit(this);
       
   178     mTextLabel = new HbLineEdit("stefano pironato", this);
       
   179     mTextNumber = new HbLineEdit("+358504876679", this);
       
   180     mRetValue = new HbLineEdit("******", this);
       
   181 
       
   182     layout->addItem(mTextLabel);
       
   183     layout->addItem(mTextNumber);
       
   184     layout->addItem(mTextAddress);
       
   185     layout->addItem(mTextCity);
       
   186     layout->addItem(mTextCountry);
       
   187     layout->addItem(mRetValue);
       
   188     setLayout(layout);
       
   189 }
       
   190 
       
   191 HbMapView::~HbMapView()
       
   192 {
       
   193     XQSERVICE_DEBUG_PRINT("HbMapView::~HbMapView");
       
   194 }
       
   195 
       
   196 void HbMapView::quit()
       
   197 {
       
   198     XQSERVICE_DEBUG_PRINT("HbMapView::quit");
       
   199     mMapService->complete();
       
   200     connect(mMapService, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
       
   201 //  NO quit now... we have to wait the signal that data has been delivered
       
   202 //    qApp->quit();
       
   203 }
       
   204 
       
   205 void HbMapView::embed()
       
   206 {
       
   207     XQSERVICE_DEBUG_PRINT("HbMapView::embed");
       
   208     //XQServiceRequest snd("com.nokia.services.hbserviceprovider.Dialer","dial(QString)",true);
       
   209     XQServiceRequest snd("com.nokia.services.serviceapp.Dialer","dial(QString,bool)",true);
       
   210     snd << mTextNumber->text();
       
   211     snd << true;
       
   212     QVariant retValue;
       
   213     bool res=snd.send(retValue);
       
   214     if (!res) {
       
   215         mRetValue->setText("send fail!");
       
   216     }
       
   217     else {
       
   218         if (retValue.isNull() || !retValue.isValid())
       
   219             mRetValue->setText("ret value null or not valid");
       
   220         else
       
   221             mRetValue->setText(retValue.toString());
       
   222     }
       
   223 }
       
   224 
       
   225 void HbMapView::setAddress(const QString& address,const QString& city,const QString& country)
       
   226 {
       
   227     XQSERVICE_DEBUG_PRINT("HbMapView::setAddress");
       
   228     mTextAddress->setText("Address:" + address);
       
   229     mTextCity->setText("City:" + city);
       
   230     mTextCountry->setText("Country:" + country);
       
   231 }
       
   232 
       
   233 void HbMapView::addAddress()
       
   234 {
       
   235     XQSERVICE_DEBUG_PRINT("HbMapView::addAddress");
       
   236     HbContact cnt;
       
   237     cnt.mLabel = mTextLabel->text();
       
   238     cnt.mNumber = mTextNumber->text();
       
   239     cnt.mAddress = mTextAddress->text();
       
   240     cnt.mCity = mTextCity->text();
       
   241     cnt.mCountry = mTextCountry->text();
       
   242     cnt.mUid = QUuid::createUuid();
       
   243     mMapService->addContact(cnt);
       
   244 }
       
   245 
       
   246 MapService::MapService(QObject* parent)
       
   247 : XQServiceProvider(QLatin1String("com.nokia.services.hbserviceprovider.Map"),parent)
       
   248 {
       
   249     XQSERVICE_DEBUG_PRINT("MapService::MapService");
       
   250     publishAll();
       
   251     mCurrentRequestIndex = 0;
       
   252 }
       
   253 
       
   254 MapService::~MapService()
       
   255 {
       
   256     XQSERVICE_DEBUG_PRINT("MapService::~MapService");
       
   257 }
       
   258 
       
   259 void MapService::complete()
       
   260 {
       
   261     XQSERVICE_DEBUG_PRINT("MapService::complete");
       
   262 //    QVariant retValue;
       
   263 //    retValue.setValue(contactList);
       
   264 //    completeRequest(mCurrentRequestIndex, retValue);
       
   265     completeRequest(mCurrentRequestIndex, contactList);
       
   266     mCurrentRequestIndex = 0;
       
   267 }
       
   268 
       
   269 void MapService::addContact(const HbContact& cnt)
       
   270 {
       
   271     XQSERVICE_DEBUG_PRINT("MapService::addContact");
       
   272     //QVariant v;
       
   273     //v.setValue(cnt);
       
   274     contactList.append(cnt);
       
   275 }
       
   276 
       
   277 HbContactList MapService::showAddresses(const QString& address,const QString& city,const QString& country)
       
   278 {
       
   279     XQSERVICE_DEBUG_PRINT("MapService::showAddresses");
       
   280     emit showView("map");
       
   281     emit setAddress(address,city,country);
       
   282     mCurrentRequestIndex=setCurrentRequestAsync();
       
   283     HbContactList list;
       
   284     return list;
       
   285 }
       
   286 
       
   287 
       
   288 Q_IMPLEMENT_USER_METATYPE(HbContact)
       
   289 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(HbContactList)
       
   290