phoneplugins/dialerwidgetplugin/src/dialerwidget.cpp
branchRCL_3
changeset 61 41a7f70b3818
equal deleted inserted replaced
58:40a3f856b14d 61:41a7f70b3818
       
     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 <QGraphicsSceneMouseEvent>
       
    19 
       
    20 #include <HbStyle>
       
    21 #include <HbStyleLoader>
       
    22 #include <HbFrameItem>
       
    23 #include <HbFrameDrawer>
       
    24 #include <HbIconItem>
       
    25 #include <HbTextItem>
       
    26 #include <HbTouchArea>
       
    27 #include <HbInstantFeedback>
       
    28 #include "dialerwidgetengine.h"
       
    29 #include "dialerwidget.h"
       
    30 #include "qtphonelog.h"
       
    31 
       
    32 #ifdef Q_OS_SYMBIAN
       
    33 #include "qtphonelog.h"
       
    34 #include <xqappmgr.h>
       
    35 #include <xqservicerequest.h>
       
    36 #include <xqcallinfo.h>
       
    37 #include <xqpublishandsubscribeutils.h>
       
    38 #include <xqrequestinfo.h>
       
    39 #include <xqaiwdecl.h>
       
    40 #endif
       
    41 
       
    42 namespace
       
    43 {
       
    44     const char KDialerWidgetIconNormal[] = "qtg_graf_hs_dialer_normal";
       
    45     const char KDialerWidgetIconPressed[] = "qtg_graf_hs_dialer_pressed";
       
    46     const char KMissedCallShortcutBadge[] = "qtg_fr_shortcut_badge_bg";
       
    47     const char KDialerWidgetWidgetml[] = ":/data/resource/dialerwidget.widgetml";
       
    48     const char KDialerWidgetCss[] = ":/data/resource/dialerwidget.css";
       
    49 }
       
    50 
       
    51 /*!
       
    52     \class DialerWidget
       
    53 
       
    54     \ingroup group_dialerwidgetplugin
       
    55     \brief Implementation for the homescreen dialer launcher.
       
    56 
       
    57 */
       
    58 
       
    59 /*!
       
    60     Constructs dialer widget with given \a parent and given window \a flags.
       
    61 */
       
    62 DialerWidget::DialerWidget(QGraphicsItem *parent, Qt::WindowFlags flags)
       
    63   : HsWidget(parent, flags),
       
    64     m_background(0), m_badgeBackground(0), m_text(0), m_touchArea(0),
       
    65     m_engine(0)
       
    66 {   
       
    67     PHONE_TRACE 
       
    68 }
       
    69 
       
    70 /*!
       
    71     Destructor.
       
    72 */
       
    73 DialerWidget::~DialerWidget()
       
    74 {
       
    75 }
       
    76 
       
    77 /*!
       
    78     \fn void DialerWidget::startDialer()
       
    79 
       
    80     Starts dialer widget via view activation service.
       
    81 */
       
    82 void DialerWidget::startDialer()
       
    83 {
       
    84     PHONE_TRACE
       
    85 #ifdef Q_OS_SYMBIAN
       
    86     PHONE_DEBUG("DialerWidget::startDialer");
       
    87     
       
    88     QList<CallInfo> calls;
       
    89     QScopedPointer<XQCallInfo> callInfo(XQCallInfo::create());
       
    90     callInfo->getCalls(calls);
       
    91     QList<QVariant> args;
       
    92     QString service;
       
    93     QString interface;
       
    94     QString operation;
       
    95 
       
    96     if (0 < calls.count()) {
       
    97         PHONE_DEBUG("call ongoing, bring Telephone to foreground");
       
    98         service = "phoneui";
       
    99         interface = "com.nokia.symbian.IStart";
       
   100         operation = "start(int)";
       
   101         int openDialer(0);
       
   102         args << openDialer;
       
   103     } else {
       
   104         PHONE_DEBUG("no calls, open Dialer");
       
   105         service = "logs";
       
   106         interface = XQI_LOGS_VIEW;
       
   107         operation = XQOP_LOGS_SHOW;
       
   108         QVariantMap map;
       
   109         map.insert(XQLOGS_VIEW_INDEX, QVariant(int(XQService::LogsViewAll)));
       
   110         map.insert(XQLOGS_SHOW_DIALPAD, QVariant(true));
       
   111         map.insert(XQLOGS_DIALPAD_TEXT, QVariant(QString()));
       
   112         args.append(QVariant(map));
       
   113     }
       
   114 
       
   115     XQApplicationManager appManager;
       
   116     QScopedPointer<XQAiwRequest> request(appManager.create(service, interface, operation, false));
       
   117     if (request == NULL) {
       
   118         PHONE_TRACE1("service not found");
       
   119         return;
       
   120     }
       
   121     request->setArguments(args);
       
   122     bool ret = request->send();
       
   123     PHONE_TRACE2("request sent successfully:", ret);
       
   124 #endif
       
   125 
       
   126 }
       
   127 
       
   128 void DialerWidget::onInitialize()
       
   129 {
       
   130     PHONE_TRACE
       
   131     QT_TRY{
       
   132         // basic ui
       
   133         createPrimitives();
       
   134         Q_ASSERT(HbStyleLoader::registerFilePath(KDialerWidgetWidgetml));
       
   135         Q_ASSERT(HbStyleLoader::registerFilePath(KDialerWidgetCss));
       
   136         // Engine construction is 2 phased 
       
   137         m_engine = new DialerWidgetEngine();
       
   138         connect(m_engine, SIGNAL( exceptionOccured(const int&) )
       
   139                 ,this, SLOT( onEngineException(const int&) ) );
       
   140         
       
   141         if(!m_engine->initialize()){
       
   142             //engine construction failed. Give up.
       
   143             emit error();
       
   144             return;
       
   145             }
       
   146         connect( m_engine, SIGNAL(missedCallsCountChanged(const int&)),
       
   147                 this, SLOT(onMissedCallsCountChange(const int&)));
       
   148     }
       
   149     QT_CATCH(...){
       
   150         emit error();
       
   151     }
       
   152 }
       
   153 
       
   154 /*!
       
   155     \fn void DialerWidget::onShow()
       
   156 
       
   157     Shows the widget
       
   158 */
       
   159 void DialerWidget::onShow()
       
   160 {
       
   161     PHONE_TRACE
       
   162     updatePrimitives();
       
   163 }
       
   164 
       
   165 /*!
       
   166     \fn void DialerWidget::onHide()
       
   167 
       
   168     Hides the widget
       
   169 */
       
   170 void DialerWidget::onHide()
       
   171 {
       
   172     PHONE_TRACE
       
   173 }
       
   174 
       
   175 void DialerWidget::onUninitialize()
       
   176 {
       
   177     PHONE_TRACE
       
   178     HbStyleLoader::unregisterFilePath(KDialerWidgetWidgetml);
       
   179     HbStyleLoader::unregisterFilePath(KDialerWidgetCss);
       
   180 }
       
   181 
       
   182 void DialerWidget::onEngineException(const int& exc)
       
   183 {
       
   184     Q_UNUSED(exc);
       
   185     emit error();
       
   186 }
       
   187 
       
   188 void DialerWidget::onMissedCallsCountChange(const int& count)
       
   189 {
       
   190     m_text->setText( QLocale::system().toString(count));
       
   191     if ( count ){
       
   192         m_text->setVisible(true);
       
   193         m_badgeBackground->setVisible(true);
       
   194     } else {
       
   195         m_text->setVisible(false);
       
   196         m_badgeBackground->setVisible(false);
       
   197     }
       
   198 }
       
   199 
       
   200 void DialerWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   201 {
       
   202     PHONE_TRACE;
       
   203     Q_UNUSED(event)
       
   204     setBackgroundToPressed();
       
   205 }
       
   206 
       
   207 void DialerWidget::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event)
       
   208 {
       
   209     if (contains(event->pos())) {
       
   210         setBackgroundToPressed();
       
   211     } else {
       
   212         setBackgroundToNormal();
       
   213     }
       
   214 }
       
   215 
       
   216 void DialerWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
       
   217 {
       
   218     PHONE_TRACE;
       
   219     Q_UNUSED(event);
       
   220     HbInstantFeedback::play(HbFeedback::Basic);
       
   221     setBackgroundToNormal();
       
   222     startDialer();    
       
   223 }
       
   224 
       
   225 bool DialerWidget::sceneEvent(QEvent *event)
       
   226 {
       
   227     if (event->type() == QEvent::UngrabMouse) {
       
   228         setBackgroundToNormal();
       
   229     }
       
   230 
       
   231     return HsWidget::sceneEvent(event);;
       
   232 }
       
   233 
       
   234 HsWidget::StartResult DialerWidget::onStart()
       
   235 {
       
   236     return StartResultRunning;
       
   237 }
       
   238 HsWidget::StopResult DialerWidget::onStop()
       
   239 {
       
   240     return StopResultFinished;
       
   241 }
       
   242 HsWidget::SuspendResult DialerWidget::onSuspend()
       
   243 {
       
   244     return SuspendResultSuspended;
       
   245 }
       
   246 HsWidget::ResumeResult DialerWidget::onResume()
       
   247 {
       
   248     return ResumeResultRunning;
       
   249 }
       
   250 
       
   251 void DialerWidget::createPrimitives()
       
   252 {   
       
   253     setPreferredSize(100,100);
       
   254     // Background
       
   255     if (!m_background) {
       
   256         HbFrameDrawer *drawer = new HbFrameDrawer(
       
   257             KDialerWidgetIconNormal, HbFrameDrawer::OnePiece);
       
   258         m_background = new HbFrameItem(drawer, this);
       
   259         style()->setItemName(m_background, QLatin1String("background"));
       
   260         m_background->moveBy(0,10);
       
   261         m_background->resize(81,81);
       
   262     }
       
   263     
       
   264     // Badge background
       
   265     if (!m_badgeBackground) {
       
   266         HbFrameDrawer *badgedrawer = new HbFrameDrawer(
       
   267             KMissedCallShortcutBadge, HbFrameDrawer::ThreePiecesHorizontal);
       
   268         m_badgeBackground = new HbFrameItem(badgedrawer, this);
       
   269         style()->setItemName(m_background, QLatin1String("badgeBackground"));
       
   270         m_badgeBackground->resize(20,20);
       
   271         m_badgeBackground->moveBy(70,0);
       
   272         m_badgeBackground->setVisible(true);
       
   273         m_badgeBackground->setVisible( false );
       
   274     }
       
   275 
       
   276     // Text
       
   277     if (!m_text) {
       
   278         m_text = new HbTextItem(this);
       
   279         style()->setItemName(m_text, QLatin1String("text"));
       
   280         m_text->resize(20,20);
       
   281         m_text->moveBy(76,0);
       
   282         m_text->setVisible(true);
       
   283         HbFontSpec *textFont = new HbFontSpec(HbFontSpec::Primary);
       
   284         textFont->setTextHeight(3*HbDeviceProfile::current().unitValue());
       
   285         m_text->setFontSpec(*textFont);
       
   286         m_text->setText("0");
       
   287         m_text->setVisible( false);
       
   288     }
       
   289 
       
   290     // Touch Area
       
   291     if (!m_touchArea) {
       
   292         m_touchArea = new HbTouchArea(this);
       
   293         m_touchArea->installEventFilter(this);
       
   294         style()->setItemName(m_touchArea, QLatin1String("touch_area"));
       
   295         m_touchArea->moveBy(0,10);
       
   296         m_touchArea->resize(81,81);
       
   297     }
       
   298 }
       
   299 
       
   300 void DialerWidget::setBackgroundToNormal()
       
   301 {
       
   302     if (m_background) {
       
   303         m_background->frameDrawer().
       
   304             setFrameGraphicsName(KDialerWidgetIconNormal);
       
   305     }
       
   306 }
       
   307 
       
   308 void DialerWidget::setBackgroundToPressed()
       
   309 {
       
   310     if (m_background) {
       
   311         m_background->frameDrawer().
       
   312             setFrameGraphicsName(KDialerWidgetIconPressed);
       
   313     }
       
   314 }
       
   315