~michael-sheldon/ubuntu/utopic/maliit-framework/fix-orientation-updates

« back to all changes in this revision

Viewing changes to maliit/attributeextension.cpp

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo, Sergio Schvezov, Ricardo Salveti de Araujo
  • Date: 2013-07-23 19:47:04 UTC
  • mfrom: (1.1.2) (1.2.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130723194704-1lsy1kmlda069cea
Tags: 0.99.0+git20130615+97e8335-0ubuntu1
[ Sergio Schvezov ]
* New build from HEAD 97e8335.
* Packaging import from lp:phablet-extras/maliit-framework.

[ Ricardo Salveti de Araujo ]
* debian/control: adding vcs and fixing dependencies
* General package cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* * This file is part of Maliit framework *
2
 
 *
3
 
 * Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies).
4
 
 * All rights reserved.
5
 
 *
6
 
 * Contact: maliit-discuss@lists.maliit.org
7
 
 *
8
 
 * This library is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU Lesser General Public
10
 
 * License version 2.1 as published by the Free Software Foundation
11
 
 * and appearing in the file LICENSE.LGPL included in the packaging
12
 
 * of this file.
13
 
 */
14
 
 
15
 
// Based on minputmethodstate.cpp from libmeegotouch
16
 
 
17
 
#include "attributeextension.h"
18
 
#include "attributeextension_p.h"
19
 
 
20
 
#include "attributeextensionregistry.h"
21
 
#include "inputmethod.h"
22
 
 
23
 
#include <QDebug>
24
 
 
25
 
namespace Maliit {
26
 
 
27
 
AttributeExtensionPrivate::AttributeExtensionPrivate(const QString &fileName) :
28
 
    id(createId()),
29
 
    fileName(fileName),
30
 
    values(),
31
 
    registry(AttributeExtensionRegistry::instance())
32
 
{
33
 
}
34
 
 
35
 
AttributeExtensionPrivate::AttributeExtensionPrivate(int id) :
36
 
    id(id),
37
 
    fileName(),
38
 
    values(),
39
 
    registry(AttributeExtensionRegistry::instance())
40
 
{
41
 
}
42
 
 
43
 
AttributeExtensionPrivate::~AttributeExtensionPrivate()
44
 
{
45
 
}
46
 
 
47
 
int AttributeExtensionPrivate::createId()
48
 
{
49
 
    static int idCounter = 0;
50
 
    // generate an application local unique identifier for the extension.
51
 
    int result = idCounter;
52
 
    idCounter++;
53
 
    return result;
54
 
}
55
 
 
56
 
AttributeExtension::AttributeExtension(const QString &fileName)
57
 
    : QObject(),
58
 
      d_ptr(new AttributeExtensionPrivate(fileName))
59
 
{
60
 
    Q_D(AttributeExtension);
61
 
 
62
 
    if (AttributeExtensionRegistry *r = d->registry.data()) {
63
 
        r->addExtension(this);
64
 
    }
65
 
}
66
 
 
67
 
AttributeExtension::AttributeExtension(int id, bool registerExtension)
68
 
    : QObject(),
69
 
      d_ptr(new AttributeExtensionPrivate(id))
70
 
{
71
 
    Q_D(AttributeExtension);
72
 
 
73
 
    AttributeExtensionRegistry *r = d->registry.data();
74
 
 
75
 
    if (r && registerExtension) {
76
 
        r->addExtension(this);
77
 
    }
78
 
}
79
 
 
80
 
QSharedPointer<AttributeExtension> AttributeExtension::create(int id)
81
 
{
82
 
    QSharedPointer<AttributeExtension> res(new AttributeExtension(id, false));
83
 
 
84
 
    AttributeExtensionRegistry::instance()->addExtension(res);
85
 
 
86
 
    return res;
87
 
}
88
 
 
89
 
AttributeExtension::~AttributeExtension()
90
 
{
91
 
    Q_D(AttributeExtension);
92
 
 
93
 
    if (AttributeExtensionRegistry *r = d->registry.data()) {
94
 
        r->removeExtension(this);
95
 
    }
96
 
}
97
 
 
98
 
AttributeExtension::ExtendedAttributeMap AttributeExtension::attributes() const
99
 
{
100
 
    Q_D(const AttributeExtension);
101
 
 
102
 
    return d->values;
103
 
}
104
 
 
105
 
QString AttributeExtension::fileName() const
106
 
{
107
 
    Q_D(const AttributeExtension);
108
 
 
109
 
    return d->fileName;
110
 
}
111
 
 
112
 
int AttributeExtension::id() const
113
 
{
114
 
    Q_D(const AttributeExtension);
115
 
 
116
 
    return d->id;
117
 
}
118
 
 
119
 
QString AttributeExtension::key(const QString &target,
120
 
                                const QString &targetItem,
121
 
                                const QString &attribute)
122
 
{
123
 
    return QString::fromLatin1("%1/%2/%3").arg(target, targetItem, attribute);
124
 
}
125
 
 
126
 
void AttributeExtension::updateAttribute(const QString &key,
127
 
                                         const QVariant &value)
128
 
{
129
 
    Q_D(AttributeExtension);
130
 
 
131
 
    d->values[key] = value;
132
 
 
133
 
    Q_EMIT extendedAttributeChanged(key, value);
134
 
}
135
 
 
136
 
void AttributeExtension::setAttribute(const QString &key, const QVariant &value)
137
 
{
138
 
    Q_D(AttributeExtension);
139
 
 
140
 
    if (!d->values.contains(key) ||
141
 
        d->values.value(key) != value)
142
 
    {
143
 
        d->values.insert(key, value);
144
 
        if (AttributeExtensionRegistry *r = d->registry.data()) {
145
 
            r->extensionChanged(this, key, value);
146
 
        }
147
 
    }
148
 
}
149
 
 
150
 
} // namespace Maliit