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