bluetoothengine/btnotif/btdevicedialogplugin/src/btsenddialogwidget.cpp
author hgs
Mon, 17 May 2010 11:06:23 +0300
changeset 31 a0ea99b6fa53
child 40 997690c3397a
child 42 b72428996822
permissions -rw-r--r--
201019_1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     1
/*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     3
 * All rights reserved.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0""
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     8
 *
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     9
 * Initial Contributors:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    11
 *
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    12
 * Contributors:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    13
 *
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    14
 * Description:  
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    15
 *
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    16
 */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    17
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    18
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    19
#include <hblabel.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    20
#include <hblistview.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    21
#include <hbtoolbar.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    22
#include <hblistwidget.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    23
#include <qstandarditemmodel.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    24
#include <hbaction.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    25
#include "btsenddialogwidget.h"
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    26
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    27
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    28
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    29
const char* DOCML_BT_SEND_DIALOG = ":/docml/bt-send-dialog.docml";
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    30
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    31
BTSendDialogWidget::BTSendDialogWidget(const QVariantMap &parameters)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    32
:HbDialog()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    33
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    34
 //   LOG(ELevel1,_L("BTSendDialogWidget::BTSendDialogWidget"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    35
    constructDialog(parameters);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    36
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    37
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    38
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    39
BTSendDialogWidget::~BTSendDialogWidget()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    40
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    41
    if(mLoader)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    42
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    43
        delete mLoader;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    44
        mLoader = NULL;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    45
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    46
    if(mContentItemModel)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    47
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    48
        delete mContentItemModel;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    49
        mContentItemModel = NULL;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    50
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    51
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    52
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    53
bool BTSendDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    54
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    55
 //   LOG(ELevel1,_L("BTSendDialogWidget::setDeviceDialogParameters "));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    56
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    57
    if(mFileIndex != parameters.value("currentFileIdx").toString().toInt() )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    58
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    59
        mLabel->setTextWrapping(Hb::TextWordWrap);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    60
        mLabel->setAlignment(Qt::AlignHCenter);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    61
        //Todo - replace this with the actual text from parameters
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    62
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    63
        QString headLabel;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    64
        headLabel.append(QString("Sending file "));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    65
        headLabel.append(parameters.value("currentFileIdx").toString());
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    66
        headLabel.append('/');
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    67
        headLabel.append(parameters.value("totalFilesCnt").toString());
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    68
        headLabel.append(QString(" to "));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    69
        headLabel.append(parameters.value("destinationName").toString());
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    70
        mLabel->setPlainText(headLabel);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    71
        
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    72
        QStringList info;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    73
        info.append(parameters.value("fileName").toString());
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    74
        info.append(parameters.value("fileSzTxt").toString());
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    75
                    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    76
        QStandardItem* listitem = new QStandardItem();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    77
        // parameters.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    78
        listitem->setData(info, Qt::DisplayRole);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    79
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    80
        //Todo - Insert icons based on the device class        
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    81
        QIcon icon(QString(":/icons/qtg_large_bluetooth.svg"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    82
        listitem->setIcon(icon);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    83
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    84
        delete mContentItemModel;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    85
        mContentItemModel = new QStandardItemModel(this);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    86
        mListView->setModel(mContentItemModel);//, prototype);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    87
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    88
        mContentItemModel->appendRow(listitem);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    89
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    90
        mProgressBar->setMinimum(0);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    91
        mProgressBar->setProgressValue(0);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    92
        mProgressBar->setMaximum(parameters.value("fileSz").toInt());
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    93
        mFileIndex = parameters.value("currentFileIdx").toString().toInt();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    94
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    95
    else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    96
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    97
        mProgressBar->setProgressValue(parameters.value("progressValue").toInt());
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    98
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    99
 //   LOG(ELevel1,_L("BTSendDialogWidget::setDeviceDialogParameters Completed"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   100
    return true;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   101
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   102
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   103
int BTSendDialogWidget::deviceDialogError() const
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   104
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   105
    return 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   106
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   107
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   108
void BTSendDialogWidget::closeDeviceDialog(bool byClient)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   109
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   110
    Q_UNUSED(byClient);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   111
    this->close();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   112
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   113
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   114
HbPopup* BTSendDialogWidget::deviceDialogWidget() const
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   115
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   116
    return const_cast<BTSendDialogWidget*>(this);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   117
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   118
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   119
QObject *BTSendDialogWidget::signalSender() const
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   120
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   121
    return const_cast<BTSendDialogWidget*>(this);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   122
}  
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   123
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   124
bool BTSendDialogWidget::constructDialog(const QVariantMap&/*parameters*/)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   125
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   126
 //   LOG(ELevel1,_L("BTSendDialogWidget::constructDialog "));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   127
    mLoader = new HbDocumentLoader();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   128
    bool ok = false;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   129
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   130
    mLoader->load(DOCML_BT_SEND_DIALOG, &ok);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   131
    if(ok)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   132
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   133
        mLabel = qobject_cast<HbLabel*>(mLoader->findWidget("heading"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   134
        this->setHeadingWidget(mLabel);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   135
        mListView = qobject_cast<HbListView*>(mLoader->findWidget("listView"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   136
        if(mListView)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   137
            {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   138
            //Todo - replace this with the actual text from parameters  
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   139
            mContentItemModel = new QStandardItemModel(this);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   140
            mListView->setModel(mContentItemModel);//, prototype);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   141
            }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   142
         
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   143
        mProgressBar = qobject_cast<HbProgressBar*>(mLoader->findWidget("horizontalProgressBar"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   144
                
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   145
        HbAction* hide = new HbAction("Hide");
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   146
        HbAction* cancel = new HbAction("Cancel");
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   147
        
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   148
        this->addAction(hide);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   149
        this->addAction(cancel);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   150
        
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   151
        QGraphicsWidget *widget = mLoader->findWidget(QString("container"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   152
        this->setContentWidget(widget);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   153
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   154
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   155
    this->setBackgroundFaded(false);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   156
    setDismissPolicy(HbPopup::NoDismiss);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   157
    setTimeout(HbPopup::NoTimeout);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   158
     
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   159
    this->actions().first()->disconnect(this);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   160
    connect(this, SIGNAL(finished(HbAction*)), this, SLOT(inputClosed(HbAction*)));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   161
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   162
    return true;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   163
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   164
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   165
void BTSendDialogWidget::hideEvent(QHideEvent *event)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   166
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   167
    HbDialog::hideEvent(event);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   168
    emit deviceDialogClosed();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   169
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   170
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   171
void BTSendDialogWidget::showEvent(QShowEvent *event)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   172
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   173
    HbDialog::showEvent(event);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   174
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   175
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   176
/*void BTSendDialogWidget::hideClicked()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   177
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   178
    // TODO
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   179
    this->close();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   180
    emit deviceDialogClosed();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   181
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   182
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   183
void BTSendDialogWidget::cancelClicked()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   184
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   185
    // TODO
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   186
    this->close();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   187
    emit deviceDialogClosed();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   188
    }*/
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   189
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   190
void BTSendDialogWidget::inputClosed(HbAction* action)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   191
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   192
    QVariantMap data;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   193
     
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   194
    HbDialog *dlg=static_cast<HbDialog*>(sender());
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   195
    if(dlg->actions().first() == action) {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   196
    } 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   197
    else if(dlg->actions().at(1) == action) {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   198
      }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   199
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   200