hswidgetmodel/src/hswidgetprovidermanifest.cpp
author hgs
Fri, 11 Jun 2010 16:13:51 +0300
changeset 98 d2f833ab7940
parent 85 7feec50967db
permissions -rw-r--r--
201023
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
85
7feec50967db 201003_02
hgs
parents:
diff changeset
     1
/*
7feec50967db 201003_02
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
7feec50967db 201003_02
hgs
parents:
diff changeset
     3
* All rights reserved.
7feec50967db 201003_02
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
7feec50967db 201003_02
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
7feec50967db 201003_02
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
7feec50967db 201003_02
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
7feec50967db 201003_02
hgs
parents:
diff changeset
     8
*
7feec50967db 201003_02
hgs
parents:
diff changeset
     9
* Initial Contributors:
7feec50967db 201003_02
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
7feec50967db 201003_02
hgs
parents:
diff changeset
    11
*
7feec50967db 201003_02
hgs
parents:
diff changeset
    12
* Contributors:
7feec50967db 201003_02
hgs
parents:
diff changeset
    13
*
7feec50967db 201003_02
hgs
parents:
diff changeset
    14
* Description:  HsWidget provider manifest.
7feec50967db 201003_02
hgs
parents:
diff changeset
    15
*
7feec50967db 201003_02
hgs
parents:
diff changeset
    16
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
    17
7feec50967db 201003_02
hgs
parents:
diff changeset
    18
#include <QDomDocument>
7feec50967db 201003_02
hgs
parents:
diff changeset
    19
#include <QFile>
7feec50967db 201003_02
hgs
parents:
diff changeset
    20
7feec50967db 201003_02
hgs
parents:
diff changeset
    21
#include "hswidgetprovidermanifest.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    22
#include "hswidgetprovidermanifest_p.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    23
#include "hstest_global.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    24
7feec50967db 201003_02
hgs
parents:
diff changeset
    25
98
hgs
parents: 85
diff changeset
    26
/*DEPRECATED
85
7feec50967db 201003_02
hgs
parents:
diff changeset
    27
    \class HsWidgetProviderManifest
7feec50967db 201003_02
hgs
parents:
diff changeset
    28
    \ingroup group_hswidgetmodel
7feec50967db 201003_02
hgs
parents:
diff changeset
    29
    \brief Loads home screen widget tokens from an XML manifest file.
7feec50967db 201003_02
hgs
parents:
diff changeset
    30
7feec50967db 201003_02
hgs
parents:
diff changeset
    31
    Used by the HsWidgetFactory for loading widget tokens from an XML
7feec50967db 201003_02
hgs
parents:
diff changeset
    32
    manifest file.
7feec50967db 201003_02
hgs
parents:
diff changeset
    33
 
7feec50967db 201003_02
hgs
parents:
diff changeset
    34
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
    35
7feec50967db 201003_02
hgs
parents:
diff changeset
    36
7feec50967db 201003_02
hgs
parents:
diff changeset
    37
HsWidgetProviderManifestPrivate::HsWidgetProviderManifestPrivate(
7feec50967db 201003_02
hgs
parents:
diff changeset
    38
    HsWidgetProviderManifest *handle):
7feec50967db 201003_02
hgs
parents:
diff changeset
    39
    mPublic(handle),
7feec50967db 201003_02
hgs
parents:
diff changeset
    40
	mLoadOnQuery(false)
7feec50967db 201003_02
hgs
parents:
diff changeset
    41
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    42
}
7feec50967db 201003_02
hgs
parents:
diff changeset
    43
7feec50967db 201003_02
hgs
parents:
diff changeset
    44
7feec50967db 201003_02
hgs
parents:
diff changeset
    45
HsWidgetProviderManifestPrivate::~HsWidgetProviderManifestPrivate()
7feec50967db 201003_02
hgs
parents:
diff changeset
    46
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    47
7feec50967db 201003_02
hgs
parents:
diff changeset
    48
}
7feec50967db 201003_02
hgs
parents:
diff changeset
    49
7feec50967db 201003_02
hgs
parents:
diff changeset
    50
QList<HsWidgetToken> HsWidgetProviderManifestPrivate::widgets() const
7feec50967db 201003_02
hgs
parents:
diff changeset
    51
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    52
    return mWidgetTokens;
7feec50967db 201003_02
hgs
parents:
diff changeset
    53
}
7feec50967db 201003_02
hgs
parents:
diff changeset
    54
7feec50967db 201003_02
hgs
parents:
diff changeset
    55
bool HsWidgetProviderManifestPrivate::loadFromXml(const QString &fileName)
7feec50967db 201003_02
hgs
parents:
diff changeset
    56
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    57
    mWidgetTokens.clear();
7feec50967db 201003_02
hgs
parents:
diff changeset
    58
7feec50967db 201003_02
hgs
parents:
diff changeset
    59
    QFile file(fileName);
7feec50967db 201003_02
hgs
parents:
diff changeset
    60
    if (!file.exists()) {
7feec50967db 201003_02
hgs
parents:
diff changeset
    61
       return false;
7feec50967db 201003_02
hgs
parents:
diff changeset
    62
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    63
7feec50967db 201003_02
hgs
parents:
diff changeset
    64
    QDomDocument document;
7feec50967db 201003_02
hgs
parents:
diff changeset
    65
    if (!document.setContent(&file)) {
7feec50967db 201003_02
hgs
parents:
diff changeset
    66
        return false;
7feec50967db 201003_02
hgs
parents:
diff changeset
    67
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    68
7feec50967db 201003_02
hgs
parents:
diff changeset
    69
    QDomElement element = document.documentElement();
7feec50967db 201003_02
hgs
parents:
diff changeset
    70
    if (element.tagName() != "widgetprovider") {
7feec50967db 201003_02
hgs
parents:
diff changeset
    71
        return false;
7feec50967db 201003_02
hgs
parents:
diff changeset
    72
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    73
	
7feec50967db 201003_02
hgs
parents:
diff changeset
    74
    mLoadOnQuery = false;
7feec50967db 201003_02
hgs
parents:
diff changeset
    75
    QDomAttr attribute = element.attributeNode("loadonquery");
7feec50967db 201003_02
hgs
parents:
diff changeset
    76
	if (attribute.value().toLower() == "true") {
7feec50967db 201003_02
hgs
parents:
diff changeset
    77
        mLoadOnQuery = true;
7feec50967db 201003_02
hgs
parents:
diff changeset
    78
	}
7feec50967db 201003_02
hgs
parents:
diff changeset
    79
7feec50967db 201003_02
hgs
parents:
diff changeset
    80
    QList<HsWidgetToken> tokens;
7feec50967db 201003_02
hgs
parents:
diff changeset
    81
    HsWidgetToken token;
7feec50967db 201003_02
hgs
parents:
diff changeset
    82
7feec50967db 201003_02
hgs
parents:
diff changeset
    83
    QDomNodeList widgets = element.elementsByTagName("widget");
7feec50967db 201003_02
hgs
parents:
diff changeset
    84
	
7feec50967db 201003_02
hgs
parents:
diff changeset
    85
	bool required(true);
7feec50967db 201003_02
hgs
parents:
diff changeset
    86
7feec50967db 201003_02
hgs
parents:
diff changeset
    87
    if (mLoadOnQuery) {
7feec50967db 201003_02
hgs
parents:
diff changeset
    88
		required = false;
7feec50967db 201003_02
hgs
parents:
diff changeset
    89
	}
7feec50967db 201003_02
hgs
parents:
diff changeset
    90
7feec50967db 201003_02
hgs
parents:
diff changeset
    91
    for(int i = 0; i < widgets.count(); ++i) {
7feec50967db 201003_02
hgs
parents:
diff changeset
    92
        element = widgets.at(i).toElement();
7feec50967db 201003_02
hgs
parents:
diff changeset
    93
        token.mLibrary = parseAttribute(element, "library");
7feec50967db 201003_02
hgs
parents:
diff changeset
    94
        token.mUri = parseAttribute(element, "uri");
7feec50967db 201003_02
hgs
parents:
diff changeset
    95
        token.mTitle = parseAttribute(element, "title", required);
7feec50967db 201003_02
hgs
parents:
diff changeset
    96
        token.mIconUri = parseAttribute(element, "iconuri", false);
7feec50967db 201003_02
hgs
parents:
diff changeset
    97
        token.mDescription = parseAttribute(element, "description");
7feec50967db 201003_02
hgs
parents:
diff changeset
    98
        tokens << token;
7feec50967db 201003_02
hgs
parents:
diff changeset
    99
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   100
7feec50967db 201003_02
hgs
parents:
diff changeset
   101
    mWidgetTokens = tokens;
7feec50967db 201003_02
hgs
parents:
diff changeset
   102
    
7feec50967db 201003_02
hgs
parents:
diff changeset
   103
    return true;
7feec50967db 201003_02
hgs
parents:
diff changeset
   104
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   105
7feec50967db 201003_02
hgs
parents:
diff changeset
   106
QString HsWidgetProviderManifestPrivate::parseAttribute(
7feec50967db 201003_02
hgs
parents:
diff changeset
   107
	QDomElement &element, 
7feec50967db 201003_02
hgs
parents:
diff changeset
   108
	const QString &attributeName, 
7feec50967db 201003_02
hgs
parents:
diff changeset
   109
	bool isRequired) const
7feec50967db 201003_02
hgs
parents:
diff changeset
   110
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   111
    QDomAttr attribute = element.attributeNode(attributeName);
7feec50967db 201003_02
hgs
parents:
diff changeset
   112
    if (attribute.isNull() || attribute.value().isEmpty()) {
7feec50967db 201003_02
hgs
parents:
diff changeset
   113
        if (isRequired) {
7feec50967db 201003_02
hgs
parents:
diff changeset
   114
            HSDEBUG("Required attribute missing")
7feec50967db 201003_02
hgs
parents:
diff changeset
   115
			return QString();
7feec50967db 201003_02
hgs
parents:
diff changeset
   116
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
   117
        else {
7feec50967db 201003_02
hgs
parents:
diff changeset
   118
            return QString();
7feec50967db 201003_02
hgs
parents:
diff changeset
   119
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
   120
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   121
    return attribute.value();
7feec50967db 201003_02
hgs
parents:
diff changeset
   122
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   123
7feec50967db 201003_02
hgs
parents:
diff changeset
   124
/*!
7feec50967db 201003_02
hgs
parents:
diff changeset
   125
    \fn HsWidgetProviderManifest::HsWidgetProviderManifest(QObject* aParent)
7feec50967db 201003_02
hgs
parents:
diff changeset
   126
7feec50967db 201003_02
hgs
parents:
diff changeset
   127
    Constructor
7feec50967db 201003_02
hgs
parents:
diff changeset
   128
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
   129
HsWidgetProviderManifest::HsWidgetProviderManifest(QObject *parent)
7feec50967db 201003_02
hgs
parents:
diff changeset
   130
    : QObject(parent),
7feec50967db 201003_02
hgs
parents:
diff changeset
   131
    mD(new HsWidgetProviderManifestPrivate(this))
7feec50967db 201003_02
hgs
parents:
diff changeset
   132
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   133
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   134
7feec50967db 201003_02
hgs
parents:
diff changeset
   135
/*!
7feec50967db 201003_02
hgs
parents:
diff changeset
   136
    \fn HsWidgetProviderManifest::~HsWidgetProviderManifest()
7feec50967db 201003_02
hgs
parents:
diff changeset
   137
7feec50967db 201003_02
hgs
parents:
diff changeset
   138
    Destructor
7feec50967db 201003_02
hgs
parents:
diff changeset
   139
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
   140
HsWidgetProviderManifest::~HsWidgetProviderManifest()
7feec50967db 201003_02
hgs
parents:
diff changeset
   141
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   142
    delete mD;
7feec50967db 201003_02
hgs
parents:
diff changeset
   143
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   144
7feec50967db 201003_02
hgs
parents:
diff changeset
   145
/*!
7feec50967db 201003_02
hgs
parents:
diff changeset
   146
    \fn QList<HsWidgetToken> HsWidgetProviderManifest::widgets() const
7feec50967db 201003_02
hgs
parents:
diff changeset
   147
7feec50967db 201003_02
hgs
parents:
diff changeset
   148
    Returns widget tokens found from manifest
7feec50967db 201003_02
hgs
parents:
diff changeset
   149
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
   150
QList<HsWidgetToken> HsWidgetProviderManifest::widgets() const
7feec50967db 201003_02
hgs
parents:
diff changeset
   151
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   152
    return mD->widgets();
7feec50967db 201003_02
hgs
parents:
diff changeset
   153
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   154
7feec50967db 201003_02
hgs
parents:
diff changeset
   155
/*!
7feec50967db 201003_02
hgs
parents:
diff changeset
   156
    \fn bool HsWidgetProviderManifest::loadOnQuery() const
7feec50967db 201003_02
hgs
parents:
diff changeset
   157
7feec50967db 201003_02
hgs
parents:
diff changeset
   158
    Returns whether widget tokens should be quered dynamically
7feec50967db 201003_02
hgs
parents:
diff changeset
   159
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
   160
bool HsWidgetProviderManifest::loadOnQuery() const
7feec50967db 201003_02
hgs
parents:
diff changeset
   161
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   162
	return mD->mLoadOnQuery;
7feec50967db 201003_02
hgs
parents:
diff changeset
   163
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   164
7feec50967db 201003_02
hgs
parents:
diff changeset
   165
/*!
7feec50967db 201003_02
hgs
parents:
diff changeset
   166
    \fn bool HsWidgetProviderManifest::loadFromXml(const QString& aFileName)
7feec50967db 201003_02
hgs
parents:
diff changeset
   167
7feec50967db 201003_02
hgs
parents:
diff changeset
   168
    Returns true if given \a fileName manifest parsing succeeded
7feec50967db 201003_02
hgs
parents:
diff changeset
   169
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
   170
bool HsWidgetProviderManifest::loadFromXml(const QString &fileName)
7feec50967db 201003_02
hgs
parents:
diff changeset
   171
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   172
    return mD->loadFromXml(fileName);
7feec50967db 201003_02
hgs
parents:
diff changeset
   173
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   174