tsdevicedialog/tsdevicedialogplugin/src/tsdevicedialogcontainer.cpp
author hgs
Fri, 06 Aug 2010 13:40:46 +0300
changeset 107 b34d53f6acdf
parent 102 8b8b34fa9751
child 112 dbfb5e38438b
permissions -rw-r--r--
201031
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
hgs
parents:
diff changeset
    18
#include <QAbstractListModel>
hgs
parents:
diff changeset
    19
#include <HbDialog>
hgs
parents:
diff changeset
    20
#include <HbMainWindow>
107
hgs
parents: 102
diff changeset
    21
#include <HbLabel>
99
hgs
parents:
diff changeset
    22
#include <tspropertydefs.h>
hgs
parents:
diff changeset
    23
107
hgs
parents: 102
diff changeset
    24
#include "tsdevicedialogcontainer.h"
99
hgs
parents:
diff changeset
    25
#include "tstasksgrid.h"
hgs
parents:
diff changeset
    26
#include "tstasksgriditem.h"
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
namespace {
hgs
parents:
diff changeset
    29
    const char KDocmlPath[] = ":/resource/layout.docml";
hgs
parents:
diff changeset
    30
}
hgs
parents:
diff changeset
    31
107
hgs
parents: 102
diff changeset
    32
TsDeviceDialogContainer::TsDeviceDialogContainer(QAbstractListModel *model, 
hgs
parents: 102
diff changeset
    33
                                                 QObject *parent)
hgs
parents: 102
diff changeset
    34
:
hgs
parents: 102
diff changeset
    35
    QObject(parent), 
hgs
parents: 102
diff changeset
    36
    mVisibilityPublisher(TsProperty::KTsPath)
99
hgs
parents:
diff changeset
    37
{
hgs
parents:
diff changeset
    38
    bool ok(true);
hgs
parents:
diff changeset
    39
    mLoader.load(KDocmlPath, &ok);
hgs
parents:
diff changeset
    40
    Q_ASSERT(ok);
hgs
parents:
diff changeset
    41
107
hgs
parents: 102
diff changeset
    42
    HbDialog *dialog = 
hgs
parents: 102
diff changeset
    43
        qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog"));
hgs
parents: 102
diff changeset
    44
    TsTasksGrid *grid = 
hgs
parents: 102
diff changeset
    45
        qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid"));
99
hgs
parents:
diff changeset
    46
    Q_ASSERT(dialog);
hgs
parents:
diff changeset
    47
    Q_ASSERT(grid);
hgs
parents:
diff changeset
    48
107
hgs
parents: 102
diff changeset
    49
    grid->setModel(model);
99
hgs
parents:
diff changeset
    50
107
hgs
parents: 102
diff changeset
    51
    changeOrientation(dialog->mainWindow()->orientation());
hgs
parents: 102
diff changeset
    52
    switchViewOnModelChange();
99
hgs
parents:
diff changeset
    53
hgs
parents:
diff changeset
    54
    // needed because of Qt::QueuedConnection used below
hgs
parents:
diff changeset
    55
    // @todo: check if we actually need queued connections
hgs
parents:
diff changeset
    56
    qRegisterMetaType<QModelIndex>("QModelIndex");
hgs
parents:
diff changeset
    57
hgs
parents:
diff changeset
    58
    // connect the grid and model
107
hgs
parents: 102
diff changeset
    59
    connect(grid, 
hgs
parents: 102
diff changeset
    60
            SIGNAL(activated(QModelIndex)), 
hgs
parents: 102
diff changeset
    61
            model, 
hgs
parents: 102
diff changeset
    62
            SLOT(openApplication(QModelIndex)));
hgs
parents: 102
diff changeset
    63
    connect(grid, 
hgs
parents: 102
diff changeset
    64
            SIGNAL(activated(QModelIndex)), 
hgs
parents: 102
diff changeset
    65
            dialog, 
hgs
parents: 102
diff changeset
    66
            SLOT(close()));
hgs
parents: 102
diff changeset
    67
    connect(grid, 
hgs
parents: 102
diff changeset
    68
            SIGNAL(deleteButtonClicked(QModelIndex)), 
hgs
parents: 102
diff changeset
    69
            model, SLOT(closeApplication(QModelIndex)), 
hgs
parents: 102
diff changeset
    70
            Qt::QueuedConnection);
99
hgs
parents:
diff changeset
    71
107
hgs
parents: 102
diff changeset
    72
    connect(dialog->mainWindow(), 
hgs
parents: 102
diff changeset
    73
            SIGNAL(orientationChanged(Qt::Orientation)), 
hgs
parents: 102
diff changeset
    74
            this, 
hgs
parents: 102
diff changeset
    75
            SLOT(changeOrientation(Qt::Orientation)));
hgs
parents: 102
diff changeset
    76
    connect(dialog, 
hgs
parents: 102
diff changeset
    77
            SIGNAL(aboutToClose()), 
hgs
parents: 102
diff changeset
    78
            this, 
hgs
parents: 102
diff changeset
    79
            SIGNAL(deviceDialogClosed()));
99
hgs
parents:
diff changeset
    80
107
hgs
parents: 102
diff changeset
    81
    // note: connect to more signals when partial model updates are implemented
hgs
parents: 102
diff changeset
    82
    connect(model, 
hgs
parents: 102
diff changeset
    83
            SIGNAL(modelReset()), 
hgs
parents: 102
diff changeset
    84
            this, 
hgs
parents: 102
diff changeset
    85
            SLOT(switchViewOnModelChange()));
hgs
parents: 102
diff changeset
    86
hgs
parents: 102
diff changeset
    87
    connect(this, 
hgs
parents: 102
diff changeset
    88
            SIGNAL(deviceDialogClosed()), 
hgs
parents: 102
diff changeset
    89
            this, 
hgs
parents: 102
diff changeset
    90
            SLOT(notifyDialogClosed()));
hgs
parents: 102
diff changeset
    91
    mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, 
hgs
parents: 102
diff changeset
    92
                                  static_cast<int>(true));
99
hgs
parents:
diff changeset
    93
    mVisibilityPublisher.sync();
hgs
parents:
diff changeset
    94
}
hgs
parents:
diff changeset
    95
107
hgs
parents: 102
diff changeset
    96
TsDeviceDialogContainer::~TsDeviceDialogContainer()
hgs
parents: 102
diff changeset
    97
{
99
hgs
parents:
diff changeset
    98
    delete deviceDialogWidget();
hgs
parents:
diff changeset
    99
}
hgs
parents:
diff changeset
   100
107
hgs
parents: 102
diff changeset
   101
bool TsDeviceDialogContainer::setDeviceDialogParameters(
hgs
parents: 102
diff changeset
   102
                                  const QVariantMap &parameters)
99
hgs
parents:
diff changeset
   103
{
hgs
parents:
diff changeset
   104
    Q_UNUSED(parameters);
hgs
parents:
diff changeset
   105
    return false;
hgs
parents:
diff changeset
   106
}
hgs
parents:
diff changeset
   107
hgs
parents:
diff changeset
   108
int TsDeviceDialogContainer::deviceDialogError() const
hgs
parents:
diff changeset
   109
{
hgs
parents:
diff changeset
   110
    return 0;
hgs
parents:
diff changeset
   111
}
hgs
parents:
diff changeset
   112
hgs
parents:
diff changeset
   113
void TsDeviceDialogContainer::closeDeviceDialog(bool byClient)
hgs
parents:
diff changeset
   114
{
hgs
parents:
diff changeset
   115
    Q_UNUSED(byClient)
hgs
parents:
diff changeset
   116
    // @todo: should there be hide calls? deviceDialogWidget->hide();
hgs
parents:
diff changeset
   117
    emit deviceDialogClosed();
hgs
parents:
diff changeset
   118
}
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
HbPopup *TsDeviceDialogContainer::deviceDialogWidget() const
hgs
parents:
diff changeset
   121
{
107
hgs
parents: 102
diff changeset
   122
    HbDialog *widget = 
hgs
parents: 102
diff changeset
   123
        qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog"));
99
hgs
parents:
diff changeset
   124
    Q_ASSERT(widget);
hgs
parents:
diff changeset
   125
    return widget;
hgs
parents:
diff changeset
   126
}
hgs
parents:
diff changeset
   127
hgs
parents:
diff changeset
   128
QObject *TsDeviceDialogContainer::signalSender() const
hgs
parents:
diff changeset
   129
{
hgs
parents:
diff changeset
   130
    return const_cast<TsDeviceDialogContainer*>(this);
hgs
parents:
diff changeset
   131
}
hgs
parents:
diff changeset
   132
hgs
parents:
diff changeset
   133
void TsDeviceDialogContainer::changeOrientation(Qt::Orientation orientation)
hgs
parents:
diff changeset
   134
{
hgs
parents:
diff changeset
   135
    bool ok(true);
hgs
parents:
diff changeset
   136
    if (orientation == Qt::Horizontal) {
hgs
parents:
diff changeset
   137
        mLoader.load(KDocmlPath, "landscape", &ok);
hgs
parents:
diff changeset
   138
    } else {
hgs
parents:
diff changeset
   139
        mLoader.load(KDocmlPath, "portrait", &ok);
hgs
parents:
diff changeset
   140
    }
hgs
parents:
diff changeset
   141
    Q_ASSERT(ok);
hgs
parents:
diff changeset
   142
}
hgs
parents:
diff changeset
   143
hgs
parents:
diff changeset
   144
void TsDeviceDialogContainer::notifyDialogClosed()
hgs
parents:
diff changeset
   145
{
107
hgs
parents: 102
diff changeset
   146
    mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, 
hgs
parents: 102
diff changeset
   147
                                  static_cast<int>(false));
99
hgs
parents:
diff changeset
   148
    mVisibilityPublisher.sync();
hgs
parents:
diff changeset
   149
}
107
hgs
parents: 102
diff changeset
   150
hgs
parents: 102
diff changeset
   151
void TsDeviceDialogContainer::switchViewOnModelChange()
hgs
parents: 102
diff changeset
   152
{
hgs
parents: 102
diff changeset
   153
    TsTasksGrid *grid = 
hgs
parents: 102
diff changeset
   154
        qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid"));
hgs
parents: 102
diff changeset
   155
    HbLabel *noItemsLabel = 
hgs
parents: 102
diff changeset
   156
        qobject_cast<HbLabel *>(mLoader.findWidget("noitemslabel"));
hgs
parents: 102
diff changeset
   157
    Q_ASSERT(grid);
hgs
parents: 102
diff changeset
   158
    Q_ASSERT(noItemsLabel);
hgs
parents: 102
diff changeset
   159
hgs
parents: 102
diff changeset
   160
    if (grid->model()->rowCount()) {
hgs
parents: 102
diff changeset
   161
        noItemsLabel->hide();
hgs
parents: 102
diff changeset
   162
        grid->show();
hgs
parents: 102
diff changeset
   163
    } else {
hgs
parents: 102
diff changeset
   164
        noItemsLabel->show();
hgs
parents: 102
diff changeset
   165
        grid->hide();
hgs
parents: 102
diff changeset
   166
    }
hgs
parents: 102
diff changeset
   167
}