appfoundation/appruntimemodel/src/hsruntimeprovidermanifest.cpp
author hgs
Fri, 16 Apr 2010 14:45:49 +0300
changeset 92 782e3408c2ab
parent 85 7feec50967db
permissions -rw-r--r--
201015
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:  HsRuntime 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
7feec50967db 201003_02
hgs
parents:
diff changeset
    19
#include "hsruntimeprovidermanifest.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    20
#include "hsruntimeprovidermanifest_p.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    21
#include "hstest_global.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    22
7feec50967db 201003_02
hgs
parents:
diff changeset
    23
#include <QDomDocument>
7feec50967db 201003_02
hgs
parents:
diff changeset
    24
#include <QFile>
7feec50967db 201003_02
hgs
parents:
diff changeset
    25
7feec50967db 201003_02
hgs
parents:
diff changeset
    26
HsRuntimeProviderManifestPrivate::HsRuntimeProviderManifestPrivate(HsRuntimeProviderManifest* aPublic)
7feec50967db 201003_02
hgs
parents:
diff changeset
    27
    : QObject(aPublic),
7feec50967db 201003_02
hgs
parents:
diff changeset
    28
      mQ(aPublic),
7feec50967db 201003_02
hgs
parents:
diff changeset
    29
      mLoadOnQuery(false)
7feec50967db 201003_02
hgs
parents:
diff changeset
    30
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    31
7feec50967db 201003_02
hgs
parents:
diff changeset
    32
}
7feec50967db 201003_02
hgs
parents:
diff changeset
    33
7feec50967db 201003_02
hgs
parents:
diff changeset
    34
HsRuntimeProviderManifestPrivate::~HsRuntimeProviderManifestPrivate()
7feec50967db 201003_02
hgs
parents:
diff changeset
    35
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    36
7feec50967db 201003_02
hgs
parents:
diff changeset
    37
}
7feec50967db 201003_02
hgs
parents:
diff changeset
    38
7feec50967db 201003_02
hgs
parents:
diff changeset
    39
bool HsRuntimeProviderManifestPrivate::loadFromXml(const QString& aFileName)
7feec50967db 201003_02
hgs
parents:
diff changeset
    40
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    41
    mRuntimeTokens.clear();
7feec50967db 201003_02
hgs
parents:
diff changeset
    42
7feec50967db 201003_02
hgs
parents:
diff changeset
    43
    QFile file(aFileName);
7feec50967db 201003_02
hgs
parents:
diff changeset
    44
    if(!file.exists())
7feec50967db 201003_02
hgs
parents:
diff changeset
    45
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
    46
        return false;
7feec50967db 201003_02
hgs
parents:
diff changeset
    47
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    48
7feec50967db 201003_02
hgs
parents:
diff changeset
    49
    QDomDocument document;
7feec50967db 201003_02
hgs
parents:
diff changeset
    50
    if(!document.setContent(&file))
7feec50967db 201003_02
hgs
parents:
diff changeset
    51
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
    52
        return false;
7feec50967db 201003_02
hgs
parents:
diff changeset
    53
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    54
7feec50967db 201003_02
hgs
parents:
diff changeset
    55
    QDomElement element = document.documentElement();
7feec50967db 201003_02
hgs
parents:
diff changeset
    56
    if(element.tagName() != "runtimeprovider")
7feec50967db 201003_02
hgs
parents:
diff changeset
    57
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
    58
        return false;
7feec50967db 201003_02
hgs
parents:
diff changeset
    59
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    60
7feec50967db 201003_02
hgs
parents:
diff changeset
    61
    mLoadOnQuery = false;
7feec50967db 201003_02
hgs
parents:
diff changeset
    62
    QDomAttr attribute = element.attributeNode("loadonquery");
7feec50967db 201003_02
hgs
parents:
diff changeset
    63
	if(attribute.value().toLower() == "true")
7feec50967db 201003_02
hgs
parents:
diff changeset
    64
	{
7feec50967db 201003_02
hgs
parents:
diff changeset
    65
        mLoadOnQuery = true;
7feec50967db 201003_02
hgs
parents:
diff changeset
    66
	}
7feec50967db 201003_02
hgs
parents:
diff changeset
    67
7feec50967db 201003_02
hgs
parents:
diff changeset
    68
    QList<HsRuntimeToken> tokens;
7feec50967db 201003_02
hgs
parents:
diff changeset
    69
    HsRuntimeToken token;
7feec50967db 201003_02
hgs
parents:
diff changeset
    70
7feec50967db 201003_02
hgs
parents:
diff changeset
    71
    QDomNodeList runtimes = element.elementsByTagName("runtime");
7feec50967db 201003_02
hgs
parents:
diff changeset
    72
7feec50967db 201003_02
hgs
parents:
diff changeset
    73
    for(int i = 0; i < runtimes.count(); ++i)
7feec50967db 201003_02
hgs
parents:
diff changeset
    74
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
    75
        element = runtimes.at(i).toElement();
7feec50967db 201003_02
hgs
parents:
diff changeset
    76
        token.mLibrary = parseAttribute(element, "library");
7feec50967db 201003_02
hgs
parents:
diff changeset
    77
        token.mUri = parseAttribute(element, "uri");
7feec50967db 201003_02
hgs
parents:
diff changeset
    78
        tokens << token;
7feec50967db 201003_02
hgs
parents:
diff changeset
    79
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    80
7feec50967db 201003_02
hgs
parents:
diff changeset
    81
    mRuntimeTokens = tokens;
7feec50967db 201003_02
hgs
parents:
diff changeset
    82
    return true;
7feec50967db 201003_02
hgs
parents:
diff changeset
    83
}
7feec50967db 201003_02
hgs
parents:
diff changeset
    84
7feec50967db 201003_02
hgs
parents:
diff changeset
    85
QList<HsRuntimeToken> HsRuntimeProviderManifestPrivate::runtimes() const
7feec50967db 201003_02
hgs
parents:
diff changeset
    86
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    87
    return mRuntimeTokens;
7feec50967db 201003_02
hgs
parents:
diff changeset
    88
}
7feec50967db 201003_02
hgs
parents:
diff changeset
    89
7feec50967db 201003_02
hgs
parents:
diff changeset
    90
// ---------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
    91
// ---------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
    92
//
7feec50967db 201003_02
hgs
parents:
diff changeset
    93
QString HsRuntimeProviderManifestPrivate::parseAttribute(QDomElement& aElement, 
7feec50967db 201003_02
hgs
parents:
diff changeset
    94
                                                       const QString& aAttributeName, 
7feec50967db 201003_02
hgs
parents:
diff changeset
    95
                                                       bool aIsRequired) const
7feec50967db 201003_02
hgs
parents:
diff changeset
    96
{
7feec50967db 201003_02
hgs
parents:
diff changeset
    97
    QDomAttr attribute = aElement.attributeNode(aAttributeName);
7feec50967db 201003_02
hgs
parents:
diff changeset
    98
    if(attribute.isNull() || attribute.value().isEmpty())
7feec50967db 201003_02
hgs
parents:
diff changeset
    99
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   100
        if(aIsRequired)
7feec50967db 201003_02
hgs
parents:
diff changeset
   101
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
   102
            HSDEBUG("Required attribute missing")
7feec50967db 201003_02
hgs
parents:
diff changeset
   103
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
   104
        else
7feec50967db 201003_02
hgs
parents:
diff changeset
   105
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
   106
            HSDEBUG("Attribute missing")
7feec50967db 201003_02
hgs
parents:
diff changeset
   107
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
   108
7feec50967db 201003_02
hgs
parents:
diff changeset
   109
        return QString();        
7feec50967db 201003_02
hgs
parents:
diff changeset
   110
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   111
7feec50967db 201003_02
hgs
parents:
diff changeset
   112
    return attribute.value();
7feec50967db 201003_02
hgs
parents:
diff changeset
   113
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   114
7feec50967db 201003_02
hgs
parents:
diff changeset
   115
7feec50967db 201003_02
hgs
parents:
diff changeset
   116
/*!
7feec50967db 201003_02
hgs
parents:
diff changeset
   117
    \class HsRuntimeProviderManifest
7feec50967db 201003_02
hgs
parents:
diff changeset
   118
    \ingroup group_hsruntimemodel
7feec50967db 201003_02
hgs
parents:
diff changeset
   119
    \brief Loads home screen HsRuntime tokens from an XML manifest file.
7feec50967db 201003_02
hgs
parents:
diff changeset
   120
    Used by the HsRuntimeFactory for loading HsRuntime tokens from an XML
7feec50967db 201003_02
hgs
parents:
diff changeset
   121
    manifest file.
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
/*!
7feec50967db 201003_02
hgs
parents:
diff changeset
   126
    Constructor. Loads runtimes as HsRuntime tokens from the given
7feec50967db 201003_02
hgs
parents:
diff changeset
   127
    manifest file.
7feec50967db 201003_02
hgs
parents:
diff changeset
   128
    \a aParent Parent object.
7feec50967db 201003_02
hgs
parents:
diff changeset
   129
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
   130
HsRuntimeProviderManifest::HsRuntimeProviderManifest(QObject* aParent)
7feec50967db 201003_02
hgs
parents:
diff changeset
   131
    : QObject(aParent)
7feec50967db 201003_02
hgs
parents:
diff changeset
   132
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   133
    mD = new HsRuntimeProviderManifestPrivate(this);
7feec50967db 201003_02
hgs
parents:
diff changeset
   134
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   135
7feec50967db 201003_02
hgs
parents:
diff changeset
   136
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
HsRuntimeProviderManifest::~HsRuntimeProviderManifest()
7feec50967db 201003_02
hgs
parents:
diff changeset
   141
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   142
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
    return loaded runtimes as HsRuntime tokens.    
7feec50967db 201003_02
hgs
parents:
diff changeset
   147
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
   148
QList<HsRuntimeToken> HsRuntimeProviderManifest::runtimes() const
7feec50967db 201003_02
hgs
parents:
diff changeset
   149
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   150
    return mD->runtimes();
7feec50967db 201003_02
hgs
parents:
diff changeset
   151
}
7feec50967db 201003_02
hgs
parents:
diff changeset
   152
7feec50967db 201003_02
hgs
parents:
diff changeset
   153
/*!
7feec50967db 201003_02
hgs
parents:
diff changeset
   154
    Tells if the HsRuntime tokens must be asked from plugin
7feec50967db 201003_02
hgs
parents:
diff changeset
   155
    instead of manifest file. 
7feec50967db 201003_02
hgs
parents:
diff changeset
   156
7feec50967db 201003_02
hgs
parents:
diff changeset
   157
    return True if loading required, false otherwise.
7feec50967db 201003_02
hgs
parents:
diff changeset
   158
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
   159
bool HsRuntimeProviderManifest::loadOnQuery() const
7feec50967db 201003_02
hgs
parents:
diff changeset
   160
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   161
	return mD->mLoadOnQuery;
7feec50967db 201003_02
hgs
parents:
diff changeset
   162
}
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
    Loads runtimes as HsRuntime tokens from a manifest file.    
7feec50967db 201003_02
hgs
parents:
diff changeset
   167
    \a aFileName Manifest file name.
7feec50967db 201003_02
hgs
parents:
diff changeset
   168
7feec50967db 201003_02
hgs
parents:
diff changeset
   169
    return true if load was succesfull, false otherwise
7feec50967db 201003_02
hgs
parents:
diff changeset
   170
*/
7feec50967db 201003_02
hgs
parents:
diff changeset
   171
bool HsRuntimeProviderManifest::loadFromXml(const QString& aFileName) const
7feec50967db 201003_02
hgs
parents:
diff changeset
   172
{
7feec50967db 201003_02
hgs
parents:
diff changeset
   173
	return mD->loadFromXml(aFileName);
7feec50967db 201003_02
hgs
parents:
diff changeset
   174
}