tsdevicedialog/tsdevicedialogplugin/src/tsdevicedialogcontainer.cpp
changeset 109 e0aa398e6810
parent 104 9b022b1f357c
child 115 3ab5c078b490
equal deleted inserted replaced
104:9b022b1f357c 109:e0aa398e6810
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: 
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 #include "tsdevicedialogcontainer.h"
       
    18 
    17 
    19 #include <QAbstractListModel>
    18 #include <QAbstractListModel>
    20 
       
    21 #include <HbDialog>
    19 #include <HbDialog>
    22 #include <HbMainWindow>
    20 #include <HbMainWindow>
    23 
    21 #include <HbLabel>
    24 #include <tspropertydefs.h>
    22 #include <tspropertydefs.h>
    25 
    23 
       
    24 #include "tsdevicedialogcontainer.h"
    26 #include "tstasksgrid.h"
    25 #include "tstasksgrid.h"
    27 #include "tstasksgriditem.h"
    26 #include "tstasksgriditem.h"
    28 
    27 
    29 namespace {
    28 namespace {
    30     const char KDocmlPath[] = ":/resource/layout.docml";
    29     const char KDocmlPath[] = ":/resource/layout.docml";
    31 }
    30 }
    32 
    31 
    33 TsDeviceDialogContainer::TsDeviceDialogContainer(QAbstractListModel *model, QObject *parent) : QObject(parent), mVisibilityPublisher(TsProperty::KTsPath)
    32 TsDeviceDialogContainer::TsDeviceDialogContainer(QAbstractListModel *model, 
       
    33                                                  QObject *parent)
       
    34 :
       
    35     QObject(parent), 
       
    36     mVisibilityPublisher(TsProperty::KTsPath)
    34 {
    37 {
    35     bool ok(true);
    38     bool ok(true);
    36     mLoader.load(KDocmlPath, &ok);
    39     mLoader.load(KDocmlPath, &ok);
    37     Q_ASSERT(ok);
    40     Q_ASSERT(ok);
    38 
    41 
    39     HbDialog *dialog = qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog"));
    42     HbDialog *dialog = 
    40     TsTasksGrid *grid = qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid"));
    43         qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog"));
       
    44     TsTasksGrid *grid = 
       
    45         qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid"));
    41     Q_ASSERT(dialog);
    46     Q_ASSERT(dialog);
    42     Q_ASSERT(grid);
    47     Q_ASSERT(grid);
    43 
    48 
       
    49     grid->setModel(model);
       
    50 
    44     changeOrientation(dialog->mainWindow()->orientation());
    51     changeOrientation(dialog->mainWindow()->orientation());
    45 
    52     switchViewOnModelChange();
    46     grid->setModel(model);
       
    47 
    53 
    48     // needed because of Qt::QueuedConnection used below
    54     // needed because of Qt::QueuedConnection used below
    49     // @todo: check if we actually need queued connections
    55     // @todo: check if we actually need queued connections
    50     qRegisterMetaType<QModelIndex>("QModelIndex");
    56     qRegisterMetaType<QModelIndex>("QModelIndex");
    51 
    57 
    52     // connect the grid and model
    58     // connect the grid and model
    53     disconnect(grid, SIGNAL(activated(QModelIndex)), model, SLOT(openApplication(QModelIndex)));
    59     connect(grid, 
    54     disconnect(grid, SIGNAL(activated(QModelIndex)), dialog, SLOT(close()));
    60             SIGNAL(activated(QModelIndex)), 
    55     disconnect(grid, SIGNAL(deleteButtonClicked(QModelIndex)), model, SLOT(closeApplication(QModelIndex)));
    61             model, 
       
    62             SLOT(openApplication(QModelIndex)));
       
    63     connect(grid, 
       
    64             SIGNAL(activated(QModelIndex)), 
       
    65             dialog, 
       
    66             SLOT(close()));
       
    67     connect(grid, 
       
    68             SIGNAL(deleteButtonClicked(QModelIndex)), 
       
    69             model, SLOT(closeApplication(QModelIndex)), 
       
    70             Qt::QueuedConnection);
    56 
    71 
    57     connect(grid, SIGNAL(activated(QModelIndex)), model, SLOT(openApplication(QModelIndex)));
    72     connect(dialog->mainWindow(), 
    58     connect(grid, SIGNAL(activated(QModelIndex)), dialog, SLOT(close()));
    73             SIGNAL(orientationChanged(Qt::Orientation)), 
    59     connect(grid, SIGNAL(deleteButtonClicked(QModelIndex)), model, SLOT(closeApplication(QModelIndex)), Qt::QueuedConnection);
    74             this, 
       
    75             SLOT(changeOrientation(Qt::Orientation)));
       
    76     connect(dialog, 
       
    77             SIGNAL(aboutToClose()), 
       
    78             this, 
       
    79             SIGNAL(deviceDialogClosed()));
    60 
    80 
    61     connect(dialog->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(changeOrientation(Qt::Orientation)));
    81     // note: connect to more signals when partial model updates are implemented
    62     connect(dialog, SIGNAL(aboutToClose()), this, SIGNAL(deviceDialogClosed()));
    82     connect(model, 
    63     
    83             SIGNAL(modelReset()), 
    64     connect(this, SIGNAL(deviceDialogClosed()), this, SLOT(notifyDialogClosed()));    
    84             this, 
    65     mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, true);
    85             SLOT(switchViewOnModelChange()));
       
    86 
       
    87     connect(this, 
       
    88             SIGNAL(deviceDialogClosed()), 
       
    89             this, 
       
    90             SLOT(notifyDialogClosed()));
       
    91     mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, 
       
    92                                   static_cast<int>(true));
    66     mVisibilityPublisher.sync();
    93     mVisibilityPublisher.sync();
    67 }
    94 }
    68 
    95 
    69 TsDeviceDialogContainer::~TsDeviceDialogContainer() 
    96 TsDeviceDialogContainer::~TsDeviceDialogContainer()
    70 { 
    97 {
    71     delete deviceDialogWidget();
    98     delete deviceDialogWidget();
    72 }
    99 }
    73 
   100 
    74 bool TsDeviceDialogContainer::setDeviceDialogParameters(const QVariantMap &parameters)
   101 bool TsDeviceDialogContainer::setDeviceDialogParameters(
       
   102                                   const QVariantMap &parameters)
    75 {
   103 {
    76     Q_UNUSED(parameters);
   104     Q_UNUSED(parameters);
    77     return false;
   105     return false;
    78 }
   106 }
    79 
   107 
    89     emit deviceDialogClosed();
   117     emit deviceDialogClosed();
    90 }
   118 }
    91 
   119 
    92 HbPopup *TsDeviceDialogContainer::deviceDialogWidget() const
   120 HbPopup *TsDeviceDialogContainer::deviceDialogWidget() const
    93 {
   121 {
    94     HbDialog *widget = qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog"));
   122     HbDialog *widget = 
       
   123         qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog"));
    95     Q_ASSERT(widget);
   124     Q_ASSERT(widget);
    96     return widget;
   125     return widget;
    97 }
   126 }
    98 
   127 
    99 QObject *TsDeviceDialogContainer::signalSender() const
   128 QObject *TsDeviceDialogContainer::signalSender() const
   112     Q_ASSERT(ok);
   141     Q_ASSERT(ok);
   113 }
   142 }
   114 
   143 
   115 void TsDeviceDialogContainer::notifyDialogClosed()
   144 void TsDeviceDialogContainer::notifyDialogClosed()
   116 {
   145 {
   117     mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, false);
   146     mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, 
       
   147                                   static_cast<int>(false));
   118     mVisibilityPublisher.sync();
   148     mVisibilityPublisher.sync();
   119 }
   149 }
       
   150 
       
   151 void TsDeviceDialogContainer::switchViewOnModelChange()
       
   152 {
       
   153     TsTasksGrid *grid = 
       
   154         qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid"));
       
   155     HbLabel *noItemsLabel = 
       
   156         qobject_cast<HbLabel *>(mLoader.findWidget("noitemslabel"));
       
   157     Q_ASSERT(grid);
       
   158     Q_ASSERT(noItemsLabel);
       
   159 
       
   160     if (grid->model()->rowCount()) {
       
   161         noItemsLabel->hide();
       
   162         grid->show();
       
   163     } else {
       
   164         noItemsLabel->show();
       
   165         grid->hide();
       
   166     }
       
   167 }