tsdevicedialog/tsdevicedialogplugin/src/tsdevicedialogcontainer.cpp
changeset 116 305818acdca4
parent 112 dbfb5e38438b
equal deleted inserted replaced
112:dbfb5e38438b 116:305818acdca4
    20 #include <QAbstractListModel>
    20 #include <QAbstractListModel>
    21 
    21 
    22 #include <HbDialog>
    22 #include <HbDialog>
    23 #include <HbMainWindow>
    23 #include <HbMainWindow>
    24 #include <HbLabel>
    24 #include <HbLabel>
       
    25 #include <HbFrameDrawer>
       
    26 #include <HbFrameItem>
       
    27 #include <HbStyleLoader>
    25 
    28 
    26 #include <tspropertydefs.h>
    29 #include <tspropertydefs.h>
    27 
    30 
    28 #include "tstasksgrid.h"
    31 #include "tstasksgrid.h"
    29 #include "tstasksgriditem.h"
    32 #include "tstasksgriditem.h"
    30 
    33 
    31 namespace {
    34 namespace
       
    35 {
    32     const char KDocmlPath[] = ":/resource/layout.docml";
    36     const char KDocmlPath[] = ":/resource/layout.docml";
    33 }
    37 }
    34 
    38 
    35 TsDeviceDialogContainer::TsDeviceDialogContainer(QAbstractListModel *model, 
    39 TsDeviceDialogContainer::TsDeviceDialogContainer(QAbstractListModel *model,
    36                                                  QObject *parent)
    40                                                  QObject *parent)
    37 :
    41     :
    38     QObject(parent), 
    42     QObject(parent),
    39     mVisibilityPublisher(TsProperty::KTsPath),
    43     mVisibilityPublisher(TsProperty::KTsPath),
    40     mDismissRequestSubscriber(QString("%1/%2").arg(TsProperty::KTsPath).arg(TsProperty::KDismissRequestPath))
    44     mDismissRequestSubscriber(QString("%1/%2").arg(TsProperty::KTsPath).arg(TsProperty::KDismissRequestPath))
    41 {
    45 {
    42     bool ok(true);
    46     bool ok(true);
    43     mLoader.load(KDocmlPath, &ok);
    47     mLoader.load(KDocmlPath, &ok);
    44     Q_ASSERT(ok);
    48     Q_ASSERT(ok);
    45 
    49 
    46     HbDialog *dialog = 
    50     HbDialog *dialog =
    47         qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog"));
    51         qobject_cast<HbDialog *>(mLoader.findWidget("tsdevicedialog"));
    48     TsTasksGrid *grid = 
    52     TsTasksGrid *grid =
    49         qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid"));
    53         qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid"));
    50     Q_ASSERT(dialog);
    54     Q_ASSERT(dialog);
    51     Q_ASSERT(grid);
    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     }
    52 
    65 
       
    66     grid->setEnabledAnimations(HbAbstractItemView::None);
    53     grid->setModel(model);
    67     grid->setModel(model);
    54 
    68 
    55     changeOrientation(dialog->mainWindow()->orientation());
    69     changeOrientation(dialog->mainWindow()->orientation());
    56     switchViewOnModelChange();
    70     switchViewOnModelChange();
    57 
    71 
    58     // needed because of Qt::QueuedConnection used below
    72     // needed because of Qt::QueuedConnection used below
    59     // @todo: check if we actually need queued connections
    73     // @todo: check if we actually need queued connections
    60     qRegisterMetaType<QModelIndex>("QModelIndex");
    74     qRegisterMetaType<QModelIndex>("QModelIndex");
    61 
    75 
    62     // connect the grid and model
    76     // connect the grid and model
    63     connect(grid, 
    77     connect(grid,
    64             SIGNAL(activated(QModelIndex)), 
    78             SIGNAL(activated(QModelIndex)),
    65             model, 
    79             model,
    66             SLOT(openApplication(QModelIndex)));
    80             SLOT(openApplication(QModelIndex)));
    67     connect(grid, 
    81     connect(grid,
    68             SIGNAL(activated(QModelIndex)), 
    82             SIGNAL(activated(QModelIndex)),
    69             dialog, 
    83             dialog,
    70             SLOT(close()));
    84             SLOT(close()));
    71     connect(grid, 
    85     connect(grid,
    72             SIGNAL(deleteButtonClicked(QModelIndex)), 
    86             SIGNAL(deleteButtonClicked(QModelIndex)),
    73             model, SLOT(closeApplication(QModelIndex)), 
    87             model, SLOT(closeApplication(QModelIndex)),
    74             Qt::QueuedConnection);
    88             Qt::QueuedConnection);
    75 
    89 
    76     connect(dialog->mainWindow(), 
    90     connect(dialog->mainWindow(),
    77             SIGNAL(orientationChanged(Qt::Orientation)), 
    91             SIGNAL(orientationChanged(Qt::Orientation)),
    78             this, 
    92             this,
    79             SLOT(changeOrientation(Qt::Orientation)));
    93             SLOT(changeOrientation(Qt::Orientation)));
    80     connect(dialog, 
    94     connect(dialog,
    81             SIGNAL(aboutToClose()), 
    95             SIGNAL(aboutToClose()),
    82             this, 
    96             this,
    83             SIGNAL(deviceDialogClosed()));
    97             SIGNAL(deviceDialogClosed()));
    84 
    98 
    85     // note: connect to more signals when partial model updates are implemented
    99     // switch between grid and "no items" label when model is updated
    86     connect(model, 
   100     connect(model, SIGNAL(modelReset()), this, SLOT(switchViewOnModelChange()));
    87             SIGNAL(modelReset()), 
   101     connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(switchViewOnModelChange()));
    88             this, 
   102     connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(switchViewOnModelChange()));
    89             SLOT(switchViewOnModelChange()));
       
    90 
   103 
    91     connect(this, 
   104     connect(this,
    92             SIGNAL(deviceDialogClosed()), 
   105             SIGNAL(deviceDialogClosed()),
    93             this, 
   106             this,
    94             SLOT(notifyDialogClosed()));
   107             SLOT(notifyDialogClosed()));
    95     mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, 
   108     mVisibilityPublisher.setValue(TsProperty::KVisibilityPath,
    96                                   static_cast<int>(true));
   109                                   static_cast<int>(true));
    97     mVisibilityPublisher.sync();
   110     mVisibilityPublisher.sync();
    98     
   111 
    99     connect(&mDismissRequestSubscriber,
   112     connect(&mDismissRequestSubscriber,
   100             SIGNAL(contentsChanged()),
   113             SIGNAL(contentsChanged()),
   101             this,
   114             this,
   102             SLOT(handleDismissRequest()));
   115             SLOT(handleDismissRequest()));
   103 }
   116 }
   106 {
   119 {
   107     delete deviceDialogWidget();
   120     delete deviceDialogWidget();
   108 }
   121 }
   109 
   122 
   110 bool TsDeviceDialogContainer::setDeviceDialogParameters(
   123 bool TsDeviceDialogContainer::setDeviceDialogParameters(
   111                                   const QVariantMap &parameters)
   124     const QVariantMap &parameters)
   112 {
   125 {
   113     Q_UNUSED(parameters);
   126     Q_UNUSED(parameters);
   114     return false;
   127     return false;
   115 }
   128 }
   116 
   129 
   126     emit deviceDialogClosed();
   139     emit deviceDialogClosed();
   127 }
   140 }
   128 
   141 
   129 HbPopup *TsDeviceDialogContainer::deviceDialogWidget() const
   142 HbPopup *TsDeviceDialogContainer::deviceDialogWidget() const
   130 {
   143 {
   131     HbDialog *widget = 
   144     HbDialog *widget =
   132         qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog"));
   145         qobject_cast<HbDialog *>(mLoader.findWidget("tsdevicedialog"));
   133     Q_ASSERT(widget);
   146     Q_ASSERT(widget);
   134     return widget;
   147     return widget;
   135 }
   148 }
   136 
   149 
   137 QObject *TsDeviceDialogContainer::signalSender() const
   150 QObject *TsDeviceDialogContainer::signalSender() const
   138 {
   151 {
   139     return const_cast<TsDeviceDialogContainer*>(this);
   152     return const_cast<TsDeviceDialogContainer *>(this);
   140 }
   153 }
   141 
   154 
   142 void TsDeviceDialogContainer::changeOrientation(Qt::Orientation orientation)
   155 void TsDeviceDialogContainer::changeOrientation(Qt::Orientation orientation)
   143 {
   156 {
   144     bool ok(true);
   157     bool ok(true);
   150     Q_ASSERT(ok);
   163     Q_ASSERT(ok);
   151 }
   164 }
   152 
   165 
   153 void TsDeviceDialogContainer::notifyDialogClosed()
   166 void TsDeviceDialogContainer::notifyDialogClosed()
   154 {
   167 {
   155     mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, 
   168     mVisibilityPublisher.setValue(TsProperty::KVisibilityPath,
   156                                   static_cast<int>(false));
   169                                   static_cast<int>(false));
   157     mVisibilityPublisher.sync();
   170     mVisibilityPublisher.sync();
   158 }
   171 }
   159 
   172 
   160 void TsDeviceDialogContainer::switchViewOnModelChange()
   173 void TsDeviceDialogContainer::switchViewOnModelChange()
   161 {
   174 {
   162     TsTasksGrid *grid = 
   175     TsTasksGrid *grid =
   163         qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid"));
   176         qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid"));
   164     HbWidget *noItemsWidget = 
   177     HbWidget *noItemsWidget =
   165         qobject_cast<HbWidget *>(mLoader.findWidget("noitemswidget"));
   178         qobject_cast<HbWidget *>(mLoader.findWidget("noitemswidget"));
   166     Q_ASSERT(grid);
   179     Q_ASSERT(grid);
   167     Q_ASSERT(noItemsWidget);
   180     Q_ASSERT(noItemsWidget);
   168 
   181 
   169     if (grid->model()->rowCount()) {
   182     if (grid->model() && grid->model()->rowCount()) {
   170         noItemsWidget->hide();
   183         noItemsWidget->hide();
   171         grid->show();
   184         grid->show();
   172     } else {
   185     } else {
   173         noItemsWidget->show();
   186         noItemsWidget->show();
   174         grid->hide();
   187         grid->hide();