phoneplugins/dialerwidgetplugin/src/dialerwidget.cpp
branchGCC_SURGE
changeset 51 f39ed5e045e0
parent 46 bc5a64e5bc3c
child 50 377c906a8701
child 56 5bcb308bd24d
equal deleted inserted replaced
40:bab96b7ed1a4 51:f39ed5e045e0
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <HbStyle>
       
    19 #include <HbStyleLoader>
       
    20 #include <HbFrameItem>
       
    21 #include <HbFrameDrawer>
       
    22 #include <HbIconItem>
       
    23 #include <HbTextItem>
       
    24 #include <HbTouchArea>
       
    25 #include "dialerwidgetengine.h"
       
    26 #include "dialerwidget.h"
       
    27 #include "qtphonelog.h"
       
    28 
       
    29 #ifdef Q_OS_SYMBIAN
       
    30 #include "qtphonelog.h"
       
    31 #include <xqappmgr.h>
       
    32 #include <xqservicerequest.h>
       
    33 #include <xqcallinfo.h>
       
    34 #include <xqpublishandsubscribeutils.h>
       
    35 #include <logsservices.h>
       
    36 #include <xqrequestinfo.h>
       
    37 #endif
       
    38 
       
    39 namespace
       
    40 {
       
    41     const char KDialerWidgetIcon[] = ":/icons/resource/qtg_graf_hs_dialer";
       
    42     const char KMissedCallShortcutBadge[] = ":/icons/resource/qtg_fr_shortcut_badge_bg";
       
    43     const char KDialerWidgetWidgetml[] = ":/data/resource/dialerwidget.widgetml";
       
    44     const char KDialerWidgetCss[] = ":/data/resource/dialerwidget.css";
       
    45 }
       
    46 
       
    47 /*!
       
    48     \class DialerWidget
       
    49 
       
    50     \ingroup group_dialerwidgetplugin
       
    51     \brief Implementation for the homescreen dialer launcher.
       
    52 
       
    53 */
       
    54 
       
    55 /*!
       
    56     Constructs dialer widget with given \a parent and given window \a flags.
       
    57 */
       
    58 DialerWidget::DialerWidget(QGraphicsItem *parent, Qt::WindowFlags flags)
       
    59   : HsWidget(parent, flags),
       
    60     m_background(0), m_badgeBackground(0), m_text(0), m_touchArea(0)
       
    61 {   
       
    62     PHONE_TRACE 
       
    63 }
       
    64 
       
    65 /*!
       
    66     Destructor.
       
    67 */
       
    68 DialerWidget::~DialerWidget()
       
    69 {
       
    70 }
       
    71 
       
    72 /*!
       
    73     \fn void DialerWidget::startDialer()
       
    74 
       
    75     Starts dialer widget via view activation service.
       
    76 */
       
    77 void DialerWidget::startDialer()
       
    78 {
       
    79     PHONE_TRACE
       
    80 #ifdef Q_OS_SYMBIAN
       
    81     PHONE_DEBUG("DialerWidget::startDialer");
       
    82     
       
    83     QList<CallInfo> calls;
       
    84     QScopedPointer<XQCallInfo> callInfo(XQCallInfo::create());
       
    85     callInfo->getCalls(calls);
       
    86     QList<QVariant> args;
       
    87     QString service;
       
    88     QString interface;
       
    89     QString operation;
       
    90 
       
    91     if (0 < calls.count()) {
       
    92         PHONE_DEBUG("call ongoing, bring Telephone to foreground");
       
    93         service = "phoneui";
       
    94         interface = "com.nokia.symbian.IStart";
       
    95         operation = "start(int)";
       
    96         int openDialer(0);
       
    97         args << openDialer;
       
    98     } else {
       
    99         PHONE_DEBUG("no calls, open Dialer");
       
   100         service = "logs";
       
   101         interface = "com.nokia.symbian.ILogsView";
       
   102         operation = "show(QVariantMap)";
       
   103         QVariantMap map;
       
   104         map.insert("view_index", QVariant(int(LogsServices::ViewAll)));
       
   105         map.insert("show_dialpad", QVariant(true));
       
   106         map.insert("dialpad_text", QVariant(QString()));
       
   107         args.append(QVariant(map));
       
   108     }
       
   109 
       
   110     XQApplicationManager appManager;
       
   111     QScopedPointer<XQAiwRequest> request(appManager.create(service, interface, operation, false));
       
   112     if (request == NULL) {
       
   113         return;
       
   114     }
       
   115     request->setArguments(args);
       
   116     XQRequestInfo info;
       
   117     info.setForeground(true);
       
   118     request->setInfo(info);
       
   119     bool ret = request->send();
       
   120     PHONE_TRACE2("request sent successfully:", ret);
       
   121 #endif
       
   122 
       
   123 }
       
   124 
       
   125 void DialerWidget::onInitialize()
       
   126 {
       
   127     PHONE_TRACE
       
   128     QT_TRY{
       
   129         // basic ui
       
   130         createPrimitives();
       
   131         Q_ASSERT(HbStyleLoader::registerFilePath(KDialerWidgetWidgetml));
       
   132         Q_ASSERT(HbStyleLoader::registerFilePath(KDialerWidgetCss));
       
   133         // Engine construction is 2 phased 
       
   134         m_engine = new DialerWidgetEngine();
       
   135         connect(m_engine, SIGNAL( exceptionOccured(const int&) )
       
   136                 ,this, SLOT( onEngineException(const int&) ) );
       
   137         
       
   138         if(!m_engine->initialize()){
       
   139             //engine construction failed. Give up.
       
   140             emit error();
       
   141             return;
       
   142             }
       
   143         connect( m_engine, SIGNAL(missedCallsCountChanged(const int&)),
       
   144                 this, SLOT(onMissedCallsCountChange(const int&)));
       
   145     }
       
   146     QT_CATCH(...){
       
   147         emit error();
       
   148     }
       
   149 }
       
   150 
       
   151 /*!
       
   152     \fn void DialerWidget::onShow()
       
   153 
       
   154     Shows the widget
       
   155 */
       
   156 void DialerWidget::onShow()
       
   157 {
       
   158     PHONE_TRACE
       
   159     updatePrimitives();
       
   160 }
       
   161 
       
   162 /*!
       
   163     \fn void DialerWidget::onHide()
       
   164 
       
   165     Hides the widget
       
   166 */
       
   167 void DialerWidget::onHide()
       
   168 {
       
   169     PHONE_TRACE
       
   170 }
       
   171 
       
   172 void DialerWidget::onUninitialize()
       
   173 {
       
   174     PHONE_TRACE
       
   175     HbStyleLoader::unregisterFilePath(KDialerWidgetWidgetml);
       
   176     HbStyleLoader::unregisterFilePath(KDialerWidgetCss);
       
   177 }
       
   178 
       
   179 void DialerWidget::onEngineException(const int& exc)
       
   180 {
       
   181     Q_UNUSED(exc);
       
   182     emit error();
       
   183 }
       
   184 
       
   185 void DialerWidget::onMissedCallsCountChange(const int& count)
       
   186 {
       
   187     m_text->setText( QLocale::system().toString(count));
       
   188     if ( count ){
       
   189         m_text->setVisible(true);
       
   190         m_badgeBackground->setVisible(true);
       
   191     } else {
       
   192         m_text->setVisible(false);
       
   193         m_badgeBackground->setVisible(false);
       
   194     }
       
   195 }
       
   196 
       
   197 /*!
       
   198     \fn void DialerWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
       
   199 
       
   200     Dialer widget start is triggered from release \a event.
       
   201     \sa startDialer()
       
   202 */
       
   203 void DialerWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
       
   204 {   
       
   205     Q_UNUSED(event);
       
   206     startDialer();
       
   207 }
       
   208 
       
   209 HsWidget::StartResult DialerWidget::onStart()
       
   210 {
       
   211     return StartResultRunning;
       
   212 }
       
   213 HsWidget::StopResult DialerWidget::onStop()
       
   214 {
       
   215     return StopResultFinished;
       
   216 }
       
   217 HsWidget::SuspendResult DialerWidget::onSuspend()
       
   218 {
       
   219     return SuspendResultSuspended;
       
   220 }
       
   221 HsWidget::ResumeResult DialerWidget::onResume()
       
   222 {
       
   223     return ResumeResultRunning;
       
   224 }
       
   225 
       
   226 void DialerWidget::createPrimitives()
       
   227 {   
       
   228     setPreferredSize(100,100);
       
   229     // Background
       
   230     if (!m_background) {
       
   231         HbFrameDrawer *drawer = new HbFrameDrawer(
       
   232                 KDialerWidgetIcon, HbFrameDrawer::OnePiece);
       
   233         m_background = new HbFrameItem(drawer, this);
       
   234         style()->setItemName(m_background, /*QLatin1String(*/"background"/*)*/);
       
   235         m_background->moveBy(0,10);
       
   236         m_background->resize(81,81);
       
   237     }
       
   238     
       
   239     // Badge background
       
   240     if (!m_badgeBackground) {
       
   241         HbFrameDrawer *badgedrawer = new HbFrameDrawer(
       
   242                 KMissedCallShortcutBadge, HbFrameDrawer::ThreePiecesHorizontal);
       
   243         m_badgeBackground = new HbFrameItem(badgedrawer, this);
       
   244         style()->setItemName(m_background, QLatin1String("badgeBackground"));
       
   245         m_badgeBackground->resize(20,20);
       
   246         m_badgeBackground->moveBy(70,0);
       
   247         m_badgeBackground->setVisible(true);
       
   248         m_badgeBackground->setVisible( false );
       
   249     }
       
   250 
       
   251     // Text
       
   252     if (!m_text) {
       
   253         m_text = new HbTextItem(this);
       
   254         style()->setItemName(m_text, QLatin1String("text"));
       
   255         m_text->resize(20,20);
       
   256         m_text->moveBy(76,0);
       
   257         m_text->setVisible(true);
       
   258         HbFontSpec *textFont = new HbFontSpec(HbFontSpec::Primary);
       
   259         textFont->setTextHeight(3*HbDeviceProfile::current().unitValue());
       
   260         m_text->setFontSpec(*textFont);
       
   261         m_text->setText("0");
       
   262         m_text->setVisible( false);
       
   263     }
       
   264 
       
   265     // Touch Area
       
   266     if (!m_touchArea) {
       
   267         m_touchArea = new HbTouchArea(this);
       
   268         m_touchArea->installEventFilter(this);
       
   269         style()->setItemName(m_touchArea, QLatin1String("touch_area"));
       
   270         m_touchArea->moveBy(0,10);
       
   271         m_touchArea->resize(81,81);
       
   272     }
       
   273 }
       
   274