tsdevicedialog/tsdevicedialogplugin/src/tsdevicedialogcontainer.cpp
author hgs
Fri, 09 Jul 2010 14:19:08 +0300
changeset 102 8b8b34fa9751
parent 99 7aaf39b772ac
child 107 b34d53f6acdf
permissions -rw-r--r--
201027
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
*
hgs
parents:
diff changeset
    14
* Description: 
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
#include "tsdevicedialogcontainer.h"
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
#include <QAbstractListModel>
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
#include <HbDialog>
hgs
parents:
diff changeset
    22
#include <HbMainWindow>
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
#include <tspropertydefs.h>
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
#include "tstasksgrid.h"
hgs
parents:
diff changeset
    27
#include "tstasksgriditem.h"
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
namespace {
hgs
parents:
diff changeset
    30
    const char KDocmlPath[] = ":/resource/layout.docml";
hgs
parents:
diff changeset
    31
}
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
TsDeviceDialogContainer::TsDeviceDialogContainer(QAbstractListModel *model, QObject *parent) : QObject(parent), mVisibilityPublisher(TsProperty::KTsPath)
hgs
parents:
diff changeset
    34
{
hgs
parents:
diff changeset
    35
    bool ok(true);
hgs
parents:
diff changeset
    36
    mLoader.load(KDocmlPath, &ok);
hgs
parents:
diff changeset
    37
    Q_ASSERT(ok);
hgs
parents:
diff changeset
    38
hgs
parents:
diff changeset
    39
    HbDialog *dialog = qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog"));
hgs
parents:
diff changeset
    40
    TsTasksGrid *grid = qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid"));
hgs
parents:
diff changeset
    41
    Q_ASSERT(dialog);
hgs
parents:
diff changeset
    42
    Q_ASSERT(grid);
hgs
parents:
diff changeset
    43
hgs
parents:
diff changeset
    44
    changeOrientation(dialog->mainWindow()->orientation());
hgs
parents:
diff changeset
    45
hgs
parents:
diff changeset
    46
    grid->setModel(model);
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
    // needed because of Qt::QueuedConnection used below
hgs
parents:
diff changeset
    49
    // @todo: check if we actually need queued connections
hgs
parents:
diff changeset
    50
    qRegisterMetaType<QModelIndex>("QModelIndex");
hgs
parents:
diff changeset
    51
hgs
parents:
diff changeset
    52
    // connect the grid and model
hgs
parents:
diff changeset
    53
    disconnect(grid, SIGNAL(activated(QModelIndex)), model, SLOT(openApplication(QModelIndex)));
hgs
parents:
diff changeset
    54
    disconnect(grid, SIGNAL(activated(QModelIndex)), dialog, SLOT(close()));
hgs
parents:
diff changeset
    55
    disconnect(grid, SIGNAL(deleteButtonClicked(QModelIndex)), model, SLOT(closeApplication(QModelIndex)));
hgs
parents:
diff changeset
    56
hgs
parents:
diff changeset
    57
    connect(grid, SIGNAL(activated(QModelIndex)), model, SLOT(openApplication(QModelIndex)));
hgs
parents:
diff changeset
    58
    connect(grid, SIGNAL(activated(QModelIndex)), dialog, SLOT(close()));
hgs
parents:
diff changeset
    59
    connect(grid, SIGNAL(deleteButtonClicked(QModelIndex)), model, SLOT(closeApplication(QModelIndex)), Qt::QueuedConnection);
hgs
parents:
diff changeset
    60
hgs
parents:
diff changeset
    61
    connect(dialog->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(changeOrientation(Qt::Orientation)));
hgs
parents:
diff changeset
    62
    connect(dialog, SIGNAL(aboutToClose()), this, SIGNAL(deviceDialogClosed()));
hgs
parents:
diff changeset
    63
    
hgs
parents:
diff changeset
    64
    connect(this, SIGNAL(deviceDialogClosed()), this, SLOT(notifyDialogClosed()));    
102
hgs
parents: 99
diff changeset
    65
    mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, static_cast<int>(true));
99
hgs
parents:
diff changeset
    66
    mVisibilityPublisher.sync();
hgs
parents:
diff changeset
    67
}
hgs
parents:
diff changeset
    68
hgs
parents:
diff changeset
    69
TsDeviceDialogContainer::~TsDeviceDialogContainer() 
hgs
parents:
diff changeset
    70
{ 
hgs
parents:
diff changeset
    71
    delete deviceDialogWidget();
hgs
parents:
diff changeset
    72
}
hgs
parents:
diff changeset
    73
hgs
parents:
diff changeset
    74
bool TsDeviceDialogContainer::setDeviceDialogParameters(const QVariantMap &parameters)
hgs
parents:
diff changeset
    75
{
hgs
parents:
diff changeset
    76
    Q_UNUSED(parameters);
hgs
parents:
diff changeset
    77
    return false;
hgs
parents:
diff changeset
    78
}
hgs
parents:
diff changeset
    79
hgs
parents:
diff changeset
    80
int TsDeviceDialogContainer::deviceDialogError() const
hgs
parents:
diff changeset
    81
{
hgs
parents:
diff changeset
    82
    return 0;
hgs
parents:
diff changeset
    83
}
hgs
parents:
diff changeset
    84
hgs
parents:
diff changeset
    85
void TsDeviceDialogContainer::closeDeviceDialog(bool byClient)
hgs
parents:
diff changeset
    86
{
hgs
parents:
diff changeset
    87
    Q_UNUSED(byClient)
hgs
parents:
diff changeset
    88
    // @todo: should there be hide calls? deviceDialogWidget->hide();
hgs
parents:
diff changeset
    89
    emit deviceDialogClosed();
hgs
parents:
diff changeset
    90
}
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
HbPopup *TsDeviceDialogContainer::deviceDialogWidget() const
hgs
parents:
diff changeset
    93
{
hgs
parents:
diff changeset
    94
    HbDialog *widget = qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog"));
hgs
parents:
diff changeset
    95
    Q_ASSERT(widget);
hgs
parents:
diff changeset
    96
    return widget;
hgs
parents:
diff changeset
    97
}
hgs
parents:
diff changeset
    98
hgs
parents:
diff changeset
    99
QObject *TsDeviceDialogContainer::signalSender() const
hgs
parents:
diff changeset
   100
{
hgs
parents:
diff changeset
   101
    return const_cast<TsDeviceDialogContainer*>(this);
hgs
parents:
diff changeset
   102
}
hgs
parents:
diff changeset
   103
hgs
parents:
diff changeset
   104
void TsDeviceDialogContainer::changeOrientation(Qt::Orientation orientation)
hgs
parents:
diff changeset
   105
{
hgs
parents:
diff changeset
   106
    bool ok(true);
hgs
parents:
diff changeset
   107
    if (orientation == Qt::Horizontal) {
hgs
parents:
diff changeset
   108
        mLoader.load(KDocmlPath, "landscape", &ok);
hgs
parents:
diff changeset
   109
    } else {
hgs
parents:
diff changeset
   110
        mLoader.load(KDocmlPath, "portrait", &ok);
hgs
parents:
diff changeset
   111
    }
hgs
parents:
diff changeset
   112
    Q_ASSERT(ok);
hgs
parents:
diff changeset
   113
}
hgs
parents:
diff changeset
   114
hgs
parents:
diff changeset
   115
void TsDeviceDialogContainer::notifyDialogClosed()
hgs
parents:
diff changeset
   116
{
102
hgs
parents: 99
diff changeset
   117
    mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, static_cast<int>(false));
99
hgs
parents:
diff changeset
   118
    mVisibilityPublisher.sync();
hgs
parents:
diff changeset
   119
}