aboutsummaryrefslogtreecommitdiff
path: root/src/corelib/theme/mtheme_p.h
blob: a624bc3ed25992073b5425da6a4598c10ec150f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#ifndef MTHEME_P_H
#define MTHEME_P_H

class IMThemeDaemon;
class MWidgetController;
class MStyleSheet;
class QPixmap;
class MTheme;
class MScalableImage;
class MLibrary;

#include <QSet>
#include <QSize>
#include <QHash>
#include <QLibrary>
#include <QAtomicInt>

#include "massembly.h"
#include "mlogicalvalues.h"
#include "mpalette.h"
#include "mdefaultfonts.h"
#include "mtheme.h"

// TODO: remove this with style profiling
#ifndef Q_OS_WIN
#include <sys/time.h>
#endif

#ifdef HAVE_GCONF
#include "mgconfitem.h"
#endif

//! \cond
struct CachedStyle {
    CachedStyle(MStyle *d) : data(d), refcount(1) {};

    MStyle *data;
    int refcount;
};
//! \endcond

//! \cond
struct CachedPixmap {
    CachedPixmap(const QPixmap *p, const QString &imageId, const QSize &size) : pixmap(p), refcount(1), imageId(imageId), size(size) {};

    const QPixmap *pixmap;
    QAtomicInt refcount;
    QString imageId;
    QSize size;
};

struct CachedScalableImage {
    CachedScalableImage(const MScalableImage *p) : image(p), refcount(1) {};

    const MScalableImage *image;
    QAtomicInt refcount;
};
//! \endcond

class MThemePrivate : public QObject
{
    Q_OBJECT
    Q_DECLARE_PUBLIC(MTheme)
public:
    MThemePrivate(const QString &applicationName, MTheme::ThemeService themeService);
    virtual ~MThemePrivate();

    typedef QHash<MStyleContainer *, MStyleContainer *> RegisteredStyleContainers;
    static RegisteredStyleContainers styleContainers;

    //remote theme cache, not used by default
    IMThemeDaemon *themeDaemon;

    // Identifier that is used to separate applications on theme daemon
    QString applicationName;

    //stores pixmap identifier and corresponding daemon handle
    QHash<QString, CachedPixmap> pixmapIdentifiers;

    //stores pixmap identifier and corresponding daemon handle
    QHash<QString, CachedScalableImage> scalableImageIdentifiers;

    MStyleSheet *customStylesheet;

    QPixmap *invalidPixmap;

    MTheme *q_ptr;

    static QHash<QString, MLibrary *>* libraries;

    MAssembly *application;

    MLogicalValues logicalValues;

    MPalette palette;
    MDefaultFonts fonts;

    QSet<QLibrary*> openedThemeLibraries;

#ifdef HAVE_GCONF
    MGConfItem locale;
    MGConfItem showAsyncRequestsItem;
#endif
    bool showAsyncRequests;

public:
    /*!
     * Check if the theme has defined a view for this controller, if not, go towards base class
     * to find one.
     */
    QString determineViewClassForController(const MWidgetController *controller);

    /*!
     * Tries to find pixmap from cache with given identifier
     * if found return the pixmap otherwise return NULL
     */
    const QPixmap *fetchPixmapFromCache(const QString &identifier);

    /*!
     * Theme daemon notifies MTheme of a theme change. In this method MTheme
     * will change the views and styles of all widgets.
     */
    void themeChangedSlot(const QStringList &themeInheritance, const QStringList& libraryNames);

    /*!
     * Finalize pixmap change or creation by updating the scene and/or emitting a signal
     */
    void pixmapRequestFinished();

    /*!
     * Theme daemon notifies pixmap updates to to this slot
     * In here MTheme will fetch the new pixmap data from X-Server and provide it to the widgets.
     */
    void pixmapCreatedOrChangedSlot(const QString &imageId, const QSize &size, Qt::HANDLE pixmapHandle);

    /*!
     * GConf item change signals that locale is changed. Logical values & icons are reloaded.
     */
    void localeChangedSlot();

    bool loadCSS(const QString &filename, MTheme::InsertMode mode = MTheme::Append);

    void refreshLocalThemeConfiguration(const QStringList &themeInheritance);
    void reloadThemeLibraries(const QStringList& libraryNames);

    /*!
     * Reinitializes the theme to correspond to the new application name
     */
    void reinit(const QString &applicationName, const QString &imglistFilename = QString(), MTheme::ThemeService themeService = MTheme::AnyTheme);

    static void registerStyleContainer(MStyleContainer *container);
    static void unregisterStyleContainer(MStyleContainer *container);

    static void registerLibrary(MLibrary *library);
    static void unregisterLibrary(MLibrary *library);

    static void addLeakedStyle(MStyle *style, const QString &id);
    static void removeLeakedStyle(MStyle *style);

#ifdef HAVE_GCONF
public slots:
    void updateShowAsyncRequests();
#endif

private:
    class LeakedStyles {
    public:
        void insert(MStyle* style, const QString &id) { styles.insert(style, id); }
        void remove(MStyle* style) { styles.remove(style); }
        ~LeakedStyles();
    private:
        QHash<MStyle*, QString> styles;
    };
    // this class must be static as it needs to be destroyed as late as possible
    // to not ignore classes which free their styles after the destrutction of
    // MTheme
    static LeakedStyles leakedStyles;
};

#endif