calendarwidgetplugin/src/saxhandler.cpp
changeset 0 db1bf15cefff
equal deleted inserted replaced
-1:000000000000 0:db1bf15cefff
       
     1 /*
       
     2 * Copyright (c) 2009 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: Calendar widget XML reader/parser
       
    15 *
       
    16 */
       
    17 #include <QObject>
       
    18 #include <QMetaMethod>
       
    19 #include <HbDocumentLoader>
       
    20 #include <HbWidget>
       
    21 
       
    22 #include "saxhandler.h"
       
    23 #include "calendarwidgetdebug.h"
       
    24 #include "contentlayoutgesture.h"
       
    25 
       
    26 SaxHandler::SaxHandler(QObject* caller, HbDocumentLoader &loader) : mLoader(loader)
       
    27 {
       
    28     LOGS("SaxHandler::SaxHandler");
       
    29     mCaller = caller;
       
    30     mArgumentValue = false;
       
    31 }
       
    32 
       
    33 SaxHandler::~SaxHandler()
       
    34 {
       
    35     LOGS("SaxHandler::~SaxHandler");
       
    36 }
       
    37 
       
    38 bool SaxHandler::startElement(const QString &namespaceURI,
       
    39     const QString &localName,
       
    40     const QString &qName,
       
    41     const QXmlAttributes &attributes)
       
    42 {
       
    43     LOGS("SaxHandler::startElement");
       
    44     qDebug() << "namespaceURI: " << namespaceURI << " localName: " << localName << " qName: "
       
    45         << qName;
       
    46     
       
    47     for (int i = 0; i < attributes.length(); i++) {
       
    48         qDebug() << "attribute type: " << attributes.type(i) << " attribute qname: "
       
    49             << attributes.qName(i) << "attribute localname: " << attributes.localName(i)
       
    50             << " attribute value: " << attributes.value(i);
       
    51         
       
    52         if (attributes.qName(i) == "type") {
       
    53             mGestureType = attributes.value(i);
       
    54             mArgumentValue = false;
       
    55         }
       
    56         
       
    57         if (attributes.qName(i) == "layout") {
       
    58             mLayout = attributes.value(i);
       
    59             mArgumentValue = false;
       
    60         }
       
    61         
       
    62         if (attributes.qName(i) == "action") {
       
    63             mAction = attributes.value(i);
       
    64         }
       
    65         
       
    66         if (localName == "argument") {
       
    67             mArgumentValue = true;
       
    68         }
       
    69         
       
    70         if (localName == "parameter") {
       
    71             mParameters.append(attributes.value(i));
       
    72             mArgumentValue = false;
       
    73         }
       
    74     }
       
    75     
       
    76     return true;
       
    77 }
       
    78     
       
    79 bool SaxHandler::endElement(const QString &namespaceURI,
       
    80     const QString &localName,
       
    81     const QString &qName)
       
    82 {
       
    83     LOGS("HsSaxHandler::endElement");
       
    84     qDebug() << "namespaceURI: " << namespaceURI << " localName: " << localName << " qName: "
       
    85         << qName;
       
    86     if (localName == "gesture") {
       
    87         QObject* gesture = mCaller->findChild<QObject*>(mLayout);
       
    88         if (!gesture) {
       
    89             HbWidget* layout = qobject_cast<HbWidget*> (mLoader.findWidget(mLayout));
       
    90             gesture = new ContentLayoutGesture(layout, mParameters, mLayout, mGestureType, mAction,
       
    91                 mCaller);
       
    92         }
       
    93         else {
       
    94             int methodIndex = gesture->metaObject()-> indexOfSlot(
       
    95                 "addGesture(QList<QString>,QString&,QString&)");
       
    96             if (methodIndex >= 0) {
       
    97                 gesture->metaObject()->method(methodIndex).invoke(gesture,
       
    98                     Q_ARG(QList<QString>, mParameters), Q_ARG(QString, mGestureType),
       
    99                     Q_ARG(QString, mAction));
       
   100             }
       
   101         }
       
   102 
       
   103         connectObject(gesture);
       
   104         
       
   105         //remove parameters
       
   106         mParameters.clear();
       
   107     }
       
   108     return true;
       
   109 }
       
   110     
       
   111 bool SaxHandler::characters(const QString &str)
       
   112 {
       
   113     LOGS("HsSaxHandler::characters");
       
   114     qDebug() << "characters: " << str;
       
   115     if (mArgumentValue) {
       
   116         mParameters.append(str);
       
   117         mArgumentValue = false;
       
   118         // set mGestureAction
       
   119     }
       
   120     return true;
       
   121 }
       
   122     
       
   123 bool SaxHandler::fatalError(const QXmlParseException &exception)
       
   124 {
       
   125     Q_UNUSED(exception);
       
   126     LOGS("HsSaxHandler::fatalError");
       
   127     return true;
       
   128 }
       
   129 
       
   130 void SaxHandler::connectObject(QObject* object)
       
   131 {
       
   132     LOGS("SaxHandler::connectObject");
       
   133     if (mGestureType == "onTap") {
       
   134         QObject::connect(mCaller, SIGNAL(tapGesture(QPointF&)), object, SLOT(onTap(QPointF&)));
       
   135         //connect contentlayouthandler to this gesture object to update the current date
       
   136         QObject* contentLayoutHandler = mCaller->findChild<QObject*> ("contentlayouthandler");
       
   137         if (contentLayoutHandler) {
       
   138             QObject::connect(contentLayoutHandler, SIGNAL(currentDate(QDateTime&)), object,
       
   139                 SLOT(updateDate(QDateTime&)));
       
   140         }
       
   141     }
       
   142     
       
   143     if (mGestureType == "onSwipe") {
       
   144         //connect(mCaller, SIGNAL(swipeGesture()), object, SLOT(onSwipe));
       
   145     }
       
   146     
       
   147     //complete with all supported gestures
       
   148 }