tsdevicedialog/tsdevicedialogplugin/src/tsdevicedialogcontainer.cpp
author hgs
Wed, 18 Aug 2010 10:39:24 +0300
changeset 112 dbfb5e38438b
parent 107 b34d53f6acdf
child 116 305818acdca4
permissions -rw-r--r--
201033
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
99
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
107
hgs
parents: 102
diff changeset
    14
* Description:
99
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
112
hgs
parents: 107
diff changeset
    18
#include "tsdevicedialogcontainer.h"
hgs
parents: 107
diff changeset
    19
99
hgs
parents:
diff changeset
    20
#include <QAbstractListModel>
112
hgs
parents: 107
diff changeset
    21
99
hgs
parents:
diff changeset
    22
#include <HbDialog>
hgs
parents:
diff changeset
    23
#include <HbMainWindow>
107
hgs
parents: 102
diff changeset
    24
#include <HbLabel>
112
hgs
parents: 107
diff changeset
    25
99
hgs
parents:
diff changeset
    26
#include <tspropertydefs.h>
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
#include "tstasksgrid.h"
hgs
parents:
diff changeset
    29
#include "tstasksgriditem.h"
hgs
parents:
diff changeset
    30
hgs
parents:
diff changeset
    31
namespace {
hgs
parents:
diff changeset
    32
    const char KDocmlPath[] = ":/resource/layout.docml";
hgs
parents:
diff changeset
    33
}
hgs
parents:
diff changeset
    34
107
hgs
parents: 102
diff changeset
    35
TsDeviceDialogContainer::TsDeviceDialogContainer(QAbstractListModel *model, 
hgs
parents: 102
diff changeset
    36
                                                 QObject *parent)
hgs
parents: 102
diff changeset
    37
:
hgs
parents: 102
diff changeset
    38
    QObject(parent), 
112
hgs
parents: 107
diff changeset
    39
    mVisibilityPublisher(TsProperty::KTsPath),
hgs
parents: 107
diff changeset
    40
    mDismissRequestSubscriber(QString("%1/%2").arg(TsProperty::KTsPath).arg(TsProperty::KDismissRequestPath))
99
hgs
parents:
diff changeset
    41
{
hgs
parents:
diff changeset
    42
    bool ok(true);
hgs
parents:
diff changeset
    43
    mLoader.load(KDocmlPath, &ok);
hgs
parents:
diff changeset
    44
    Q_ASSERT(ok);
hgs
parents:
diff changeset
    45
107
hgs
parents: 102
diff changeset
    46
    HbDialog *dialog = 
hgs
parents: 102
diff changeset
    47
        qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog"));
hgs
parents: 102
diff changeset
    48
    TsTasksGrid *grid = 
hgs
parents: 102
diff changeset
    49
        qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid"));
99
hgs
parents:
diff changeset
    50
    Q_ASSERT(dialog);
hgs
parents:
diff changeset
    51
    Q_ASSERT(grid);
hgs
parents:
diff changeset
    52
107
hgs
parents: 102
diff changeset
    53
    grid->setModel(model);
99
hgs
parents:
diff changeset
    54
107
hgs
parents: 102
diff changeset
    55
    changeOrientation(dialog->mainWindow()->orientation());
hgs
parents: 102
diff changeset
    56
    switchViewOnModelChange();
99
hgs
parents:
diff changeset
    57
hgs
parents:
diff changeset
    58
    // needed because of Qt::QueuedConnection used below
hgs
parents:
diff changeset
    59
    // @todo: check if we actually need queued connections
hgs
parents:
diff changeset
    60
    qRegisterMetaType<QModelIndex>("QModelIndex");
hgs
parents:
diff changeset
    61
hgs
parents:
diff changeset
    62
    // connect the grid and model
107
hgs
parents: 102
diff changeset
    63
    connect(grid, 
hgs
parents: 102
diff changeset
    64
            SIGNAL(activated(QModelIndex)), 
hgs
parents: 102
diff changeset
    65
            model, 
hgs
parents: 102
diff changeset
    66
            SLOT(openApplication(QModelIndex)));
hgs
parents: 102
diff changeset
    67
    connect(grid, 
hgs
parents: 102
diff changeset
    68
            SIGNAL(activated(QModelIndex)), 
hgs
parents: 102
diff changeset
    69
            dialog, 
hgs
parents: 102
diff changeset
    70
            SLOT(close()));
hgs
parents: 102
diff changeset
    71
    connect(grid, 
hgs
parents: 102
diff changeset
    72
            SIGNAL(deleteButtonClicked(QModelIndex)), 
hgs
parents: 102
diff changeset
    73
            model, SLOT(closeApplication(QModelIndex)), 
hgs
parents: 102
diff changeset
    74
            Qt::QueuedConnection);
99
hgs
parents:
diff changeset
    75
107
hgs
parents: 102
diff changeset
    76
    connect(dialog->mainWindow(), 
hgs
parents: 102
diff changeset
    77
            SIGNAL(orientationChanged(Qt::Orientation)), 
hgs
parents: 102
diff changeset
    78
            this, 
hgs
parents: 102
diff changeset
    79
            SLOT(changeOrientation(Qt::Orientation)));
hgs
parents: 102
diff changeset
    80
    connect(dialog, 
hgs
parents: 102
diff changeset
    81
            SIGNAL(aboutToClose()), 
hgs
parents: 102
diff changeset
    82
            this, 
hgs
parents: 102
diff changeset
    83
            SIGNAL(deviceDialogClosed()));
99
hgs
parents:
diff changeset
    84
107
hgs
parents: 102
diff changeset
    85
    // note: connect to more signals when partial model updates are implemented
hgs
parents: 102
diff changeset
    86
    connect(model, 
hgs
parents: 102
diff changeset
    87
            SIGNAL(modelReset()), 
hgs
parents: 102
diff changeset
    88
            this, 
hgs
parents: 102
diff changeset
    89
            SLOT(switchViewOnModelChange()));
hgs
parents: 102
diff changeset
    90
hgs
parents: 102
diff changeset
    91
    connect(this, 
hgs
parents: 102
diff changeset
    92
            SIGNAL(deviceDialogClosed()), 
hgs
parents: 102
diff changeset
    93
            this, 
hgs
parents: 102
diff changeset
    94
            SLOT(notifyDialogClosed()));
hgs
parents: 102
diff changeset
    95
    mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, 
hgs
parents: 102
diff changeset
    96
                                  static_cast<int>(true));
99
hgs
parents:
diff changeset
    97
    mVisibilityPublisher.sync();
112
hgs
parents: 107
diff changeset
    98
    
hgs
parents: 107
diff changeset
    99
    connect(&mDismissRequestSubscriber,
hgs
parents: 107
diff changeset
   100
            SIGNAL(contentsChanged()),
hgs
parents: 107
diff changeset
   101
            this,
hgs
parents: 107
diff changeset
   102
            SLOT(handleDismissRequest()));
99
hgs
parents:
diff changeset
   103
}
hgs
parents:
diff changeset
   104
107
hgs
parents: 102
diff changeset
   105
TsDeviceDialogContainer::~TsDeviceDialogContainer()
hgs
parents: 102
diff changeset
   106
{
99
hgs
parents:
diff changeset
   107
    delete deviceDialogWidget();
hgs
parents:
diff changeset
   108
}
hgs
parents:
diff changeset
   109
107
hgs
parents: 102
diff changeset
   110
bool TsDeviceDialogContainer::setDeviceDialogParameters(
hgs
parents: 102
diff changeset
   111
                                  const QVariantMap &parameters)
99
hgs
parents:
diff changeset
   112
{
hgs
parents:
diff changeset
   113
    Q_UNUSED(parameters);
hgs
parents:
diff changeset
   114
    return false;
hgs
parents:
diff changeset
   115
}
hgs
parents:
diff changeset
   116
hgs
parents:
diff changeset
   117
int TsDeviceDialogContainer::deviceDialogError() const
hgs
parents:
diff changeset
   118
{
hgs
parents:
diff changeset
   119
    return 0;
hgs
parents:
diff changeset
   120
}
hgs
parents:
diff changeset
   121
hgs
parents:
diff changeset
   122
void TsDeviceDialogContainer::closeDeviceDialog(bool byClient)
hgs
parents:
diff changeset
   123
{
hgs
parents:
diff changeset
   124
    Q_UNUSED(byClient)
hgs
parents:
diff changeset
   125
    // @todo: should there be hide calls? deviceDialogWidget->hide();
hgs
parents:
diff changeset
   126
    emit deviceDialogClosed();
hgs
parents:
diff changeset
   127
}
hgs
parents:
diff changeset
   128
hgs
parents:
diff changeset
   129
HbPopup *TsDeviceDialogContainer::deviceDialogWidget() const
hgs
parents:
diff changeset
   130
{
107
hgs
parents: 102
diff changeset
   131
    HbDialog *widget = 
hgs
parents: 102
diff changeset
   132
        qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog"));
99
hgs
parents:
diff changeset
   133
    Q_ASSERT(widget);
hgs
parents:
diff changeset
   134
    return widget;
hgs
parents:
diff changeset
   135
}
hgs
parents:
diff changeset
   136
hgs
parents:
diff changeset
   137
QObject *TsDeviceDialogContainer::signalSender() const
hgs
parents:
diff changeset
   138
{
hgs
parents:
diff changeset
   139
    return const_cast<TsDeviceDialogContainer*>(this);
hgs
parents:
diff changeset
   140
}
hgs
parents:
diff changeset
   141
hgs
parents:
diff changeset
   142
void TsDeviceDialogContainer::changeOrientation(Qt::Orientation orientation)
hgs
parents:
diff changeset
   143
{
hgs
parents:
diff changeset
   144
    bool ok(true);
hgs
parents:
diff changeset
   145
    if (orientation == Qt::Horizontal) {
hgs
parents:
diff changeset
   146
        mLoader.load(KDocmlPath, "landscape", &ok);
hgs
parents:
diff changeset
   147
    } else {
hgs
parents:
diff changeset
   148
        mLoader.load(KDocmlPath, "portrait", &ok);
hgs
parents:
diff changeset
   149
    }
hgs
parents:
diff changeset
   150
    Q_ASSERT(ok);
hgs
parents:
diff changeset
   151
}
hgs
parents:
diff changeset
   152
hgs
parents:
diff changeset
   153
void TsDeviceDialogContainer::notifyDialogClosed()
hgs
parents:
diff changeset
   154
{
107
hgs
parents: 102
diff changeset
   155
    mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, 
hgs
parents: 102
diff changeset
   156
                                  static_cast<int>(false));
99
hgs
parents:
diff changeset
   157
    mVisibilityPublisher.sync();
hgs
parents:
diff changeset
   158
}
107
hgs
parents: 102
diff changeset
   159
hgs
parents: 102
diff changeset
   160
void TsDeviceDialogContainer::switchViewOnModelChange()
hgs
parents: 102
diff changeset
   161
{
hgs
parents: 102
diff changeset
   162
    TsTasksGrid *grid = 
hgs
parents: 102
diff changeset
   163
        qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid"));
112
hgs
parents: 107
diff changeset
   164
    HbWidget *noItemsWidget = 
hgs
parents: 107
diff changeset
   165
        qobject_cast<HbWidget *>(mLoader.findWidget("noitemswidget"));
107
hgs
parents: 102
diff changeset
   166
    Q_ASSERT(grid);
112
hgs
parents: 107
diff changeset
   167
    Q_ASSERT(noItemsWidget);
107
hgs
parents: 102
diff changeset
   168
hgs
parents: 102
diff changeset
   169
    if (grid->model()->rowCount()) {
112
hgs
parents: 107
diff changeset
   170
        noItemsWidget->hide();
107
hgs
parents: 102
diff changeset
   171
        grid->show();
hgs
parents: 102
diff changeset
   172
    } else {
112
hgs
parents: 107
diff changeset
   173
        noItemsWidget->show();
107
hgs
parents: 102
diff changeset
   174
        grid->hide();
hgs
parents: 102
diff changeset
   175
    }
hgs
parents: 102
diff changeset
   176
}
112
hgs
parents: 107
diff changeset
   177
hgs
parents: 107
diff changeset
   178
void TsDeviceDialogContainer::handleDismissRequest()
hgs
parents: 107
diff changeset
   179
{
hgs
parents: 107
diff changeset
   180
    if (mDismissRequestSubscriber.value().toBool()) {
hgs
parents: 107
diff changeset
   181
        emit deviceDialogClosed();
hgs
parents: 107
diff changeset
   182
    }
hgs
parents: 107
diff changeset
   183
}