src/hbcore/devicedialogbase/devicedialogserver/hbdevicedialogscontainer.cpp
changeset 0 16d8024aca5e
child 3 11d3954df52a
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbCore module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include <hbpopup.h>
       
    27 #include <hbdevicedialogplugin.h>
       
    28 #include <hbdevicedialoginterface.h>
       
    29 #include <hbdevicedialogtrace_p.h>
       
    30 #include <hbdevicedialogpluginmanager_p.h>
       
    31 #include "hbdevicedialogscontainer_p.h"
       
    32 
       
    33 #include <QFlags>
       
    34 #include <QtGlobal>
       
    35 
       
    36 HbDeviceDialogsContainer::Dialog::Dialog()
       
    37 {
       
    38     mId = InvalidId;
       
    39     mPtr = 0;
       
    40     mFlags = NoFlags;
       
    41     for(int i = 0; i < NumVariables; i++) {
       
    42         mVariables[i] = 0;
       
    43     }
       
    44     mIndex = InvalidIndex;
       
    45 #ifndef QT_NO_DEBUG
       
    46     mContainer = 0;
       
    47 #endif // QT_NO_DEBUG
       
    48 }
       
    49 
       
    50 bool HbDeviceDialogsContainer::Dialog::operator ==(const Dialog &other) const
       
    51 {
       
    52     return mId == other.mId;
       
    53 }
       
    54 
       
    55 // Verify that Dialog reference is valid
       
    56 bool HbDeviceDialogsContainer::Dialog::verify() const
       
    57 {
       
    58 #ifndef QT_NO_DEBUG
       
    59     return isValid() && mIndex < mContainer->mDialogs.count() &&
       
    60         mId == mContainer->mDialogs.at(mIndex).mId;
       
    61 #else // QT_NO_DEBUG
       
    62     return true;
       
    63 #endif // QT_NO_DEBUG
       
    64 }
       
    65 
       
    66 // Constructor
       
    67 HbDeviceDialogsContainer::HbDeviceDialogsContainer(HbDeviceDialogPluginManager &pluginManager) :
       
    68     mPluginManager(pluginManager), mNextId(1)
       
    69 {
       
    70 }
       
    71 
       
    72 // Destructor
       
    73 HbDeviceDialogsContainer::~HbDeviceDialogsContainer()
       
    74 {
       
    75     int count = mDialogs.count();
       
    76     for(int i = 0; i < count; i++) {
       
    77         mPluginManager.freeWidget(mDialogs.at(i).mPtr);
       
    78     }
       
    79     mDialogs.clear();
       
    80 }
       
    81 
       
    82 // Add dialog to the container. Returns dialog reference.
       
    83 HbDeviceDialogsContainer::Dialog &HbDeviceDialogsContainer::add(HbDeviceDialogInterface *widget,
       
    84     const HbDeviceDialogPlugin::DeviceDialogInfo &deviceDialogInfo)
       
    85 {
       
    86     TRACE_ENTRY
       
    87     Dialog dialog;
       
    88     dialog.mId = mNextId++;
       
    89     dialog.mPtr = widget;
       
    90     switch(deviceDialogInfo.group) {
       
    91     case HbDeviceDialogPlugin::DeviceNotificationDialogGroup:
       
    92         dialog.mFlags |= Dialog::NotificationGroup;
       
    93         break;
       
    94     case HbDeviceDialogPlugin::IndicatorGroup:
       
    95         dialog.mFlags |= Dialog::IndicatorGroup;
       
    96         break;
       
    97     case HbDeviceDialogPlugin::SecurityGroup:
       
    98         dialog.mFlags |= Dialog::SecurityGroup;
       
    99         break;
       
   100     case HbDeviceDialogPlugin::CriticalGroup:
       
   101         dialog.mFlags |= Dialog::CriticalGroup;
       
   102         break;
       
   103     default:
       
   104         dialog.mFlags |= Dialog::GenericGroup;
       
   105     }
       
   106 #ifndef QT_NO_DEBUG
       
   107     dialog.mContainer = this;
       
   108 #endif // QT_NO_DEBUG
       
   109 
       
   110     Q_ASSERT(!mDialogs.contains(dialog));
       
   111     mDialogs.append(dialog);
       
   112 
       
   113     Dialog &ref = mDialogs.last();
       
   114     ref.mIndex = mDialogs.count() - 1;
       
   115 
       
   116     TRACE_EXIT
       
   117     return ref;
       
   118 }
       
   119 
       
   120 // Search dialog by id
       
   121 HbDeviceDialogsContainer::Dialog &HbDeviceDialogsContainer::find(int id)
       
   122 {
       
   123     if (id == Dialog::InvalidId) {
       
   124         return mInvalidDialog;
       
   125     }
       
   126 
       
   127     Dialog search;
       
   128     search.mId = id;
       
   129     int i = mDialogs.indexOf(search);
       
   130     Dialog *dialog;
       
   131     if (i >= 0) {
       
   132         dialog = &mDialogs[i];
       
   133         dialog->mIndex = i;
       
   134     } else {
       
   135         dialog = &mInvalidDialog;
       
   136     }
       
   137     return *dialog;
       
   138 }
       
   139 
       
   140 // Search dialog by popup or widget signal sender
       
   141 HbDeviceDialogsContainer::Dialog &HbDeviceDialogsContainer::find(const QObject *widget)
       
   142 {
       
   143     int count = mDialogs.count();
       
   144     for(int i = 0; i < count; i++) {
       
   145         Dialog &dialog = mDialogs[i];
       
   146         if (dialog.mPtr->deviceDialogWidget() == widget || dialog.mPtr->signalSender() == widget) {
       
   147             dialog.mIndex = i;
       
   148             return dialog;
       
   149         }
       
   150     }
       
   151     return mInvalidDialog;
       
   152 }
       
   153 
       
   154 // Remove dialog from the container
       
   155 void HbDeviceDialogsContainer::remove(Dialog &dialog)
       
   156 {
       
   157     TRACE_ENTRY
       
   158     Q_ASSERT(dialog.isValid());
       
   159     Q_ASSERT(dialog.mId == mDialogs.at(dialog.mIndex).mId);
       
   160     mPluginManager.freeWidget(dialog.mPtr);
       
   161     mDialogs.removeAt(dialog.mIndex);
       
   162     TRACE_EXIT
       
   163 }
       
   164 
       
   165 // Get next dialog with matching flag pattern
       
   166 HbDeviceDialogsContainer::Dialog &HbDeviceDialogsContainer::next(
       
   167     const Dialog &from, Dialog::Flags flags, Dialog::Flags mask)
       
   168 {
       
   169     // With invalid from start from beginning, otherwise start from next
       
   170     int i = from.isValid() ? from.mIndex + 1 : 0;
       
   171     int count = mDialogs.count();
       
   172     if (i >= count) { // at the end
       
   173         return mInvalidDialog;
       
   174     }
       
   175     for(; i < count; i++) {
       
   176         const Dialog &current = mDialogs.at(i);
       
   177         if ((current.mFlags & mask) == flags) {
       
   178             break;
       
   179         }
       
   180     }
       
   181     if (i >= count) { // at the end
       
   182         return mInvalidDialog;
       
   183     }
       
   184     Dialog &dialog = mDialogs[i];
       
   185     dialog.mIndex = i;
       
   186     return dialog;
       
   187 }
       
   188 
       
   189 // Get next dialog with matching variable value
       
   190 HbDeviceDialogsContainer::Dialog &HbDeviceDialogsContainer::next(
       
   191     const Dialog &from, Dialog::Variable variable, quintptr value)
       
   192 {
       
   193     // With invalid from start from beginning, otherwise start from next
       
   194     int i = from.isValid() ? from.mIndex + 1 : 0;
       
   195     int count = mDialogs.count();
       
   196     if (i >= count) { // at the end
       
   197         return mInvalidDialog;
       
   198     }
       
   199     for(; i < count; i++) {
       
   200         const Dialog &current = mDialogs.at(i);
       
   201         if (current.mVariables[variable] == value) {
       
   202             break;
       
   203         }
       
   204     }
       
   205     if (i >= count) { // at the end
       
   206         return mInvalidDialog;
       
   207     }
       
   208     Dialog &dialog = mDialogs[i];
       
   209     dialog.mIndex = i;
       
   210     return dialog;
       
   211 }