emailuis/nmailui/src/nmattachmentpicker.cpp
author hgs
Thu, 24 Jun 2010 14:32:18 +0300
changeset 47 f83bd4ae1fe3
parent 43 99bcbff212ad
child 56 15bc1d5d6267
permissions -rw-r--r--
201025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies).
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* Description: Utility class for launching different file pickers
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
*
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
*/
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
#include "nmuiheaders.h"
47
hgs
parents: 43
diff changeset
    19
hgs
parents: 43
diff changeset
    20
static const int NmAttachmentPickerStillMode = 0;
hgs
parents: 43
diff changeset
    21
static const int NmAttachmentPickerVideoMode = 1;
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
/*!
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
    \class NmAttachmentPicker
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    25
    \brief Attachment picker for mail editor
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
*/
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
/*!
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
    Constructor
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
*/
47
hgs
parents: 43
diff changeset
    31
NmAttachmentPicker::NmAttachmentPicker(QObject *parent):
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
    QObject(parent),
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
    mRequest(NULL)
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
{
43
hgs
parents: 23
diff changeset
    35
    NM_FUNCTION;
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
}
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
/*!
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
    Destructor
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
*/
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
NmAttachmentPicker::~NmAttachmentPicker()
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
{
43
hgs
parents: 23
diff changeset
    43
    NM_FUNCTION;
hgs
parents: 23
diff changeset
    44
    
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
    delete mRequest;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
}
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
/*!
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
    Send request to start Photo picker 
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
*/
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
void NmAttachmentPicker::fetchImage()
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    52
{
43
hgs
parents: 23
diff changeset
    53
    NM_FUNCTION;
hgs
parents: 23
diff changeset
    54
    
hgs
parents: 23
diff changeset
    55
    fetch(XQI_IMAGE_FETCH, XQOP_IMAGE_FETCH);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    56
}
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    57
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
/*!
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    59
    Send request to start Music picker 
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
*/
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
void NmAttachmentPicker::fetchAudio()
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    62
{
43
hgs
parents: 23
diff changeset
    63
    NM_FUNCTION;
hgs
parents: 23
diff changeset
    64
    
hgs
parents: 23
diff changeset
    65
    fetch(XQI_MUSIC_FETCH, XQOP_MUSIC_FETCH);    
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
}
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
/*!
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
    Send request to start Video picker 
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
*/
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
void NmAttachmentPicker::fetchVideo()
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
{
43
hgs
parents: 23
diff changeset
    73
    NM_FUNCTION;
hgs
parents: 23
diff changeset
    74
    fetch(XQI_VIDEO_FETCH, XQOP_VIDEO_FETCH);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    75
}
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    76
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
/*!
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
    Send request to start general file picker 
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
*/
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
void NmAttachmentPicker::fetchOther()
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    81
{
43
hgs
parents: 23
diff changeset
    82
    NM_FUNCTION;
hgs
parents: 23
diff changeset
    83
    
hgs
parents: 23
diff changeset
    84
    QString path;
hgs
parents: 23
diff changeset
    85
    path = FmFileDialog::getSaveFileName(0, hbTrId("txt_mail_dialog_select_file"));
hgs
parents: 23
diff changeset
    86
    
47
hgs
parents: 43
diff changeset
    87
    if (!path.isEmpty()) {
43
hgs
parents: 23
diff changeset
    88
        QString temp = QDir::toNativeSeparators(path);
hgs
parents: 23
diff changeset
    89
        emit attachmentsFetchOk(QVariant(temp));    
hgs
parents: 23
diff changeset
    90
    }
hgs
parents: 23
diff changeset
    91
}
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    92
43
hgs
parents: 23
diff changeset
    93
/*!
hgs
parents: 23
diff changeset
    94
    Send request to retrieve image from camera
hgs
parents: 23
diff changeset
    95
*/
hgs
parents: 23
diff changeset
    96
void NmAttachmentPicker::fetchCameraStill()
hgs
parents: 23
diff changeset
    97
{
hgs
parents: 23
diff changeset
    98
    NM_FUNCTION;
hgs
parents: 23
diff changeset
    99
    fetchFromCamera(NmAttachmentPickerStillMode);
hgs
parents: 23
diff changeset
   100
}
hgs
parents: 23
diff changeset
   101
hgs
parents: 23
diff changeset
   102
/*!
hgs
parents: 23
diff changeset
   103
    Send request to retrieve video from camera
hgs
parents: 23
diff changeset
   104
*/
hgs
parents: 23
diff changeset
   105
void NmAttachmentPicker::fetchCameraVideo()
hgs
parents: 23
diff changeset
   106
{
hgs
parents: 23
diff changeset
   107
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   108
    fetchFromCamera(NmAttachmentPickerVideoMode);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   109
}
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   110
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   111
/*!
43
hgs
parents: 23
diff changeset
   112
    Send request to retrieve image/video from camera
hgs
parents: 23
diff changeset
   113
*/
hgs
parents: 23
diff changeset
   114
void NmAttachmentPicker::fetchFromCamera(int mode)
hgs
parents: 23
diff changeset
   115
{
hgs
parents: 23
diff changeset
   116
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   117
47
hgs
parents: 43
diff changeset
   118
    int cameraIndex(0);            //primary camera
hgs
parents: 43
diff changeset
   119
    int quality(0);                //default
hgs
parents: 43
diff changeset
   120
    bool allowModeSwitch(false);   //not allowed to change
hgs
parents: 43
diff changeset
   121
    bool allowCameraSwitch(true);  //allow changes
hgs
parents: 43
diff changeset
   122
    bool allowQualityChange(true); //allow changes
43
hgs
parents: 23
diff changeset
   123
    
hgs
parents: 23
diff changeset
   124
    QVariantMap parameters;
hgs
parents: 23
diff changeset
   125
    parameters.insert(XQCAMERA_INDEX, cameraIndex);
hgs
parents: 23
diff changeset
   126
    parameters.insert(XQCAMERA_QUALITY, quality);
hgs
parents: 23
diff changeset
   127
    parameters.insert(XQCAMERA_MODE_SWITCH, allowModeSwitch);
hgs
parents: 23
diff changeset
   128
    parameters.insert(XQCAMERA_INDEX_SWITCH, allowCameraSwitch);
hgs
parents: 23
diff changeset
   129
    parameters.insert(XQCAMERA_QUALITY_CHANGE, allowQualityChange); 
hgs
parents: 23
diff changeset
   130
 
hgs
parents: 23
diff changeset
   131
    QList<QVariant> args;
hgs
parents: 23
diff changeset
   132
    args << mode;
hgs
parents: 23
diff changeset
   133
    args << parameters;
hgs
parents: 23
diff changeset
   134
    
hgs
parents: 23
diff changeset
   135
    fetch(XQI_CAMERA_CAPTURE, "capture(int,QVariantMap)", &args);
hgs
parents: 23
diff changeset
   136
}
hgs
parents: 23
diff changeset
   137
/*!
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   138
    Construct & send appmgr request to start appropriate picker   
43
hgs
parents: 23
diff changeset
   139
    param <interface> the interface to be connected to
hgs
parents: 23
diff changeset
   140
    param <operation> the operation of the interface
hgs
parents: 23
diff changeset
   141
    param <args> the arguments that needed by the operation
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   142
*/
47
hgs
parents: 43
diff changeset
   143
void NmAttachmentPicker::fetch(const QString &interface, 
hgs
parents: 43
diff changeset
   144
    const QString &operation, const QList<QVariant> *args)
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   145
{
43
hgs
parents: 23
diff changeset
   146
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   147
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   148
    delete mRequest;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   149
    mRequest = NULL;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   150
    XQApplicationManager appMgr;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   151
    mRequest = appMgr.create(interface, operation, true);
43
hgs
parents: 23
diff changeset
   152
   
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   153
    if (mRequest) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   154
        mRequest->setSynchronous(false);
43
hgs
parents: 23
diff changeset
   155
        if (args) {
hgs
parents: 23
diff changeset
   156
            mRequest->setArguments(*args);
hgs
parents: 23
diff changeset
   157
        }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   158
        connect(mRequest, SIGNAL(requestOk(const QVariant&)),
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   159
                this, SIGNAL(attachmentsFetchOk(const QVariant&)));
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   160
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   161
        connect(mRequest, SIGNAL(requestError(int, const QString&)),
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   162
                this, SIGNAL(attachmentsFetchError(int, const QString&)));
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   163
        
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   164
        mRequest->send();
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   165
    } 
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   166
}