src/hbcore/gui/hbglobalstatusbar.cpp
author hgs
Mon, 18 Oct 2010 18:23:13 +0300
changeset 34 ed14f46c0e55
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34
hgs
parents:
diff changeset
     1
/****************************************************************************
hgs
parents:
diff changeset
     2
**
hgs
parents:
diff changeset
     3
** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     4
** All rights reserved.
hgs
parents:
diff changeset
     5
** Contact: Nokia Corporation (developer.feedback@nokia.com)
hgs
parents:
diff changeset
     6
**
hgs
parents:
diff changeset
     7
** This file is part of the HbCore module of the UI Extensions for Mobile.
hgs
parents:
diff changeset
     8
**
hgs
parents:
diff changeset
     9
** GNU Lesser General Public License Usage
hgs
parents:
diff changeset
    10
** This file may be used under the terms of the GNU Lesser General Public
hgs
parents:
diff changeset
    11
** License version 2.1 as published by the Free Software Foundation and
hgs
parents:
diff changeset
    12
** appearing in the file LICENSE.LGPL included in the packaging of this file.
hgs
parents:
diff changeset
    13
** Please review the following information to ensure the GNU Lesser General
hgs
parents:
diff changeset
    14
** Public License version 2.1 requirements will be met:
hgs
parents:
diff changeset
    15
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hgs
parents:
diff changeset
    16
**
hgs
parents:
diff changeset
    17
** In addition, as a special exception, Nokia gives you certain additional
hgs
parents:
diff changeset
    18
** rights.  These rights are described in the Nokia Qt LGPL Exception
hgs
parents:
diff changeset
    19
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
hgs
parents:
diff changeset
    20
**
hgs
parents:
diff changeset
    21
** If you have questions regarding the use of this file, please contact
hgs
parents:
diff changeset
    22
** Nokia at developer.feedback@nokia.com.
hgs
parents:
diff changeset
    23
**
hgs
parents:
diff changeset
    24
****************************************************************************/
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
#include "hbglobalstatusbar_r.h"
hgs
parents:
diff changeset
    27
#include "hbsplashdefs_p.h"
hgs
parents:
diff changeset
    28
#include <QScopedPointer>
hgs
parents:
diff changeset
    29
hgs
parents:
diff changeset
    30
/*!
hgs
parents:
diff changeset
    31
  \class HbGlobalStatusBar
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
  \brief Provides access and change notifications for the image (screenshot) of
hgs
parents:
diff changeset
    34
  the statusbar rendered in background by the hbsplashgenerator process.
hgs
parents:
diff changeset
    35
hgs
parents:
diff changeset
    36
  \internal
hgs
parents:
diff changeset
    37
*/
hgs
parents:
diff changeset
    38
hgs
parents:
diff changeset
    39
#ifdef Q_OS_SYMBIAN
hgs
parents:
diff changeset
    40
#include <e32base.h>
hgs
parents:
diff changeset
    41
#include <fbs.h>
hgs
parents:
diff changeset
    42
#include <e32property.h>
hgs
parents:
diff changeset
    43
hgs
parents:
diff changeset
    44
class BitmapHandleWatcher : public CActive
hgs
parents:
diff changeset
    45
{
hgs
parents:
diff changeset
    46
public:
hgs
parents:
diff changeset
    47
    BitmapHandleWatcher(HbSplashStatusBarKeys key, TCallBack callback);
hgs
parents:
diff changeset
    48
    ~BitmapHandleWatcher();
hgs
parents:
diff changeset
    49
    void DoCancel();
hgs
parents:
diff changeset
    50
    void RunL();
hgs
parents:
diff changeset
    51
    TInt value();
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
private:
hgs
parents:
diff changeset
    54
    RProperty mProperty;
hgs
parents:
diff changeset
    55
    TCallBack mCallback;
hgs
parents:
diff changeset
    56
};
hgs
parents:
diff changeset
    57
hgs
parents:
diff changeset
    58
BitmapHandleWatcher::BitmapHandleWatcher(HbSplashStatusBarKeys key, TCallBack callback)
hgs
parents:
diff changeset
    59
    : CActive(EPriorityStandard)
hgs
parents:
diff changeset
    60
{
hgs
parents:
diff changeset
    61
    CActiveScheduler::Add(this);
hgs
parents:
diff changeset
    62
    if (mProperty.Attach(hbsplash_server_uid3, key) == KErrNone) {
hgs
parents:
diff changeset
    63
        mCallback = callback;
hgs
parents:
diff changeset
    64
        mProperty.Subscribe(iStatus);
hgs
parents:
diff changeset
    65
        SetActive();
hgs
parents:
diff changeset
    66
    }
hgs
parents:
diff changeset
    67
}
hgs
parents:
diff changeset
    68
hgs
parents:
diff changeset
    69
BitmapHandleWatcher::~BitmapHandleWatcher()
hgs
parents:
diff changeset
    70
{
hgs
parents:
diff changeset
    71
    Cancel();
hgs
parents:
diff changeset
    72
    mProperty.Close();
hgs
parents:
diff changeset
    73
}
hgs
parents:
diff changeset
    74
hgs
parents:
diff changeset
    75
void BitmapHandleWatcher::DoCancel()
hgs
parents:
diff changeset
    76
{
hgs
parents:
diff changeset
    77
    mProperty.Cancel();
hgs
parents:
diff changeset
    78
}
hgs
parents:
diff changeset
    79
hgs
parents:
diff changeset
    80
void BitmapHandleWatcher::RunL()
hgs
parents:
diff changeset
    81
{
hgs
parents:
diff changeset
    82
    if (iStatus != KErrCancel) {
hgs
parents:
diff changeset
    83
        mProperty.Subscribe(iStatus);
hgs
parents:
diff changeset
    84
        SetActive();
hgs
parents:
diff changeset
    85
        if (mCallback.iFunction) {
hgs
parents:
diff changeset
    86
            mCallback.CallBack();
hgs
parents:
diff changeset
    87
        }
hgs
parents:
diff changeset
    88
    }
hgs
parents:
diff changeset
    89
}
hgs
parents:
diff changeset
    90
hgs
parents:
diff changeset
    91
TInt BitmapHandleWatcher::value()
hgs
parents:
diff changeset
    92
{
hgs
parents:
diff changeset
    93
    TInt v = 0;
hgs
parents:
diff changeset
    94
    mProperty.Get(v);
hgs
parents:
diff changeset
    95
    return v;
hgs
parents:
diff changeset
    96
}
hgs
parents:
diff changeset
    97
hgs
parents:
diff changeset
    98
class HbGlobalStatusBarPrivate
hgs
parents:
diff changeset
    99
{
hgs
parents:
diff changeset
   100
public:
hgs
parents:
diff changeset
   101
    HbGlobalStatusBarPrivate(HbGlobalStatusBar *q);
hgs
parents:
diff changeset
   102
    ~HbGlobalStatusBarPrivate();
hgs
parents:
diff changeset
   103
    static TInt splashImageChanged(TAny *param);
hgs
parents:
diff changeset
   104
    TInt bitmapHandle(Qt::Orientation orientation);
hgs
parents:
diff changeset
   105
    CFbsBitmap **storedBitmap(Qt::Orientation orientation);
hgs
parents:
diff changeset
   106
hgs
parents:
diff changeset
   107
    CFbsBitmap *mBmpPrt;
hgs
parents:
diff changeset
   108
    CFbsBitmap *mBmpLsc;
hgs
parents:
diff changeset
   109
    QScopedPointer<BitmapHandleWatcher> mPrt;
hgs
parents:
diff changeset
   110
    QScopedPointer<BitmapHandleWatcher> mLsc;
hgs
parents:
diff changeset
   111
};
hgs
parents:
diff changeset
   112
hgs
parents:
diff changeset
   113
HbGlobalStatusBarPrivate::HbGlobalStatusBarPrivate(HbGlobalStatusBar *q)
hgs
parents:
diff changeset
   114
    : mBmpPrt(0), mBmpLsc(0)
hgs
parents:
diff changeset
   115
{
hgs
parents:
diff changeset
   116
    // Don't emit changed() twice, it's enough to have one callback because both
hgs
parents:
diff changeset
   117
    // statusbars are regenerated for every change. Note however that passing
hgs
parents:
diff changeset
   118
    // TCallBack() would cause a compiler warning with armcc because iPtr is
hgs
parents:
diff changeset
   119
    // left uninitialized, so specify 0 explicitly.
hgs
parents:
diff changeset
   120
    mPrt.reset(new BitmapHandleWatcher(HbSplashSbBitmapPrtKey, TCallBack(0, 0)));
hgs
parents:
diff changeset
   121
    mLsc.reset(new BitmapHandleWatcher(HbSplashSbBitmapLscKey, TCallBack(splashImageChanged, q)));
hgs
parents:
diff changeset
   122
}
hgs
parents:
diff changeset
   123
hgs
parents:
diff changeset
   124
HbGlobalStatusBarPrivate::~HbGlobalStatusBarPrivate()
hgs
parents:
diff changeset
   125
{
hgs
parents:
diff changeset
   126
    delete mBmpPrt;
hgs
parents:
diff changeset
   127
    delete mBmpLsc;
hgs
parents:
diff changeset
   128
}
hgs
parents:
diff changeset
   129
hgs
parents:
diff changeset
   130
TInt HbGlobalStatusBarPrivate::splashImageChanged(TAny *param)
hgs
parents:
diff changeset
   131
{
hgs
parents:
diff changeset
   132
    emit static_cast<HbGlobalStatusBar *>(param)->changed();
hgs
parents:
diff changeset
   133
    return 0;
hgs
parents:
diff changeset
   134
}
hgs
parents:
diff changeset
   135
hgs
parents:
diff changeset
   136
TInt HbGlobalStatusBarPrivate::bitmapHandle(Qt::Orientation orientation)
hgs
parents:
diff changeset
   137
{
hgs
parents:
diff changeset
   138
    return orientation == Qt::Vertical ? mPrt->value() : mLsc->value();
hgs
parents:
diff changeset
   139
}
hgs
parents:
diff changeset
   140
hgs
parents:
diff changeset
   141
CFbsBitmap **HbGlobalStatusBarPrivate::storedBitmap(Qt::Orientation orientation)
hgs
parents:
diff changeset
   142
{
hgs
parents:
diff changeset
   143
    return orientation == Qt::Vertical ? &mBmpPrt : &mBmpLsc;
hgs
parents:
diff changeset
   144
}
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
#endif
hgs
parents:
diff changeset
   147
hgs
parents:
diff changeset
   148
HbGlobalStatusBar::HbGlobalStatusBar(QObject *parent)
hgs
parents:
diff changeset
   149
    : QObject(parent), d(0)
hgs
parents:
diff changeset
   150
{
hgs
parents:
diff changeset
   151
#ifdef Q_OS_SYMBIAN
hgs
parents:
diff changeset
   152
    d = new HbGlobalStatusBarPrivate(this);
hgs
parents:
diff changeset
   153
#endif
hgs
parents:
diff changeset
   154
}
hgs
parents:
diff changeset
   155
hgs
parents:
diff changeset
   156
HbGlobalStatusBar::~HbGlobalStatusBar()
hgs
parents:
diff changeset
   157
{
hgs
parents:
diff changeset
   158
#ifdef Q_OS_SYMBIAN
hgs
parents:
diff changeset
   159
    delete d;
hgs
parents:
diff changeset
   160
#endif
hgs
parents:
diff changeset
   161
}
hgs
parents:
diff changeset
   162
hgs
parents:
diff changeset
   163
QImage HbGlobalStatusBar::getImage(Qt::Orientation orientation)
hgs
parents:
diff changeset
   164
{
hgs
parents:
diff changeset
   165
#ifdef Q_OS_SYMBIAN
hgs
parents:
diff changeset
   166
    QImage result;
hgs
parents:
diff changeset
   167
    TInt handle = d->bitmapHandle(orientation);
hgs
parents:
diff changeset
   168
    CFbsBitmap **store = d->storedBitmap(orientation);
hgs
parents:
diff changeset
   169
    if (!*store || (*store)->Handle() != handle) {
hgs
parents:
diff changeset
   170
        delete *store;
hgs
parents:
diff changeset
   171
        *store = 0;
hgs
parents:
diff changeset
   172
        CFbsBitmap *bmp = new CFbsBitmap;
hgs
parents:
diff changeset
   173
        if (bmp->Duplicate(handle) == KErrNone) {
hgs
parents:
diff changeset
   174
            *store = bmp;
hgs
parents:
diff changeset
   175
        } else {
hgs
parents:
diff changeset
   176
            qWarning("HbGlobalStatusBar: Duplicate() failed for handle %d", handle);
hgs
parents:
diff changeset
   177
            delete bmp;
hgs
parents:
diff changeset
   178
        }
hgs
parents:
diff changeset
   179
    }
hgs
parents:
diff changeset
   180
    if (*store) {
hgs
parents:
diff changeset
   181
        CFbsBitmap *bmp = *store;
hgs
parents:
diff changeset
   182
        // Make a deep copy because the bitmap content may change at any time.
hgs
parents:
diff changeset
   183
        uchar *src = reinterpret_cast<uchar *>(bmp->DataAddress());
hgs
parents:
diff changeset
   184
        TSize sz = bmp->SizeInPixels();
hgs
parents:
diff changeset
   185
        int srcBpl = CFbsBitmap::ScanLineLength(sz.iWidth, bmp->DisplayMode());
hgs
parents:
diff changeset
   186
        QImage image(sz.iWidth, sz.iHeight, QImage::Format_ARGB32_Premultiplied);
hgs
parents:
diff changeset
   187
        uchar *dst = image.bits();
hgs
parents:
diff changeset
   188
        if (srcBpl == image.bytesPerLine() && bmp->DisplayMode() == EColor16MAP) {
hgs
parents:
diff changeset
   189
            qMemCopy(dst, src, sz.iHeight * image.bytesPerLine());
hgs
parents:
diff changeset
   190
            result = image;
hgs
parents:
diff changeset
   191
        } else {
hgs
parents:
diff changeset
   192
            qWarning("HbGlobalStatusBar: Bitmap mismatch");
hgs
parents:
diff changeset
   193
        }
hgs
parents:
diff changeset
   194
    }
hgs
parents:
diff changeset
   195
    return result;
hgs
parents:
diff changeset
   196
#else
hgs
parents:
diff changeset
   197
    Q_UNUSED(orientation);
hgs
parents:
diff changeset
   198
    return QImage();
hgs
parents:
diff changeset
   199
#endif
hgs
parents:
diff changeset
   200
}