emailuis/nmailui/src/nmattachmentpicker.cpp
branchRCL_3
changeset 63 d189ee25cf9d
equal deleted inserted replaced
61:dcf0eedfc1a3 63:d189ee25cf9d
       
     1 /*
       
     2 * Copyright (c) 2009 - 2010 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: Utility class for launching different file pickers
       
    15 *
       
    16 */
       
    17 
       
    18 #include "nmuiheaders.h"
       
    19 
       
    20 static const int NmAttachmentPickerStillMode = 0;
       
    21 static const int NmAttachmentPickerVideoMode = 1;
       
    22 
       
    23 /*!
       
    24     \class NmAttachmentPicker
       
    25     \brief Attachment picker for mail editor
       
    26 */
       
    27 
       
    28 /*!
       
    29     Constructor
       
    30 */
       
    31 NmAttachmentPicker::NmAttachmentPicker(QObject *parent):
       
    32     QObject(parent),
       
    33     mRequest(NULL)
       
    34 {
       
    35     NM_FUNCTION;
       
    36 }
       
    37 
       
    38 /*!
       
    39     Destructor
       
    40 */
       
    41 NmAttachmentPicker::~NmAttachmentPicker()
       
    42 {
       
    43     NM_FUNCTION;
       
    44 
       
    45     delete mRequest;
       
    46 }
       
    47 
       
    48 /*!
       
    49     Send request to start Photo picker
       
    50 */
       
    51 void NmAttachmentPicker::fetchImage()
       
    52 {
       
    53     NM_FUNCTION;
       
    54 
       
    55     fetch(XQI_IMAGE_FETCH, XQOP_IMAGE_FETCH);
       
    56 }
       
    57 
       
    58 /*!
       
    59     Send request to start Music picker
       
    60 */
       
    61 void NmAttachmentPicker::fetchAudio()
       
    62 {
       
    63     NM_FUNCTION;
       
    64 
       
    65     fetch(XQI_MUSIC_FETCH, XQOP_MUSIC_FETCH);
       
    66 }
       
    67 
       
    68 /*!
       
    69     Send request to start Video picker
       
    70 */
       
    71 void NmAttachmentPicker::fetchVideo()
       
    72 {
       
    73     NM_FUNCTION;
       
    74 
       
    75     fetch(XQI_VIDEO_FETCH, XQOP_VIDEO_FETCH);
       
    76 }
       
    77 
       
    78 /*!
       
    79     Send request to start general file picker
       
    80 */
       
    81 void NmAttachmentPicker::fetchOther()
       
    82 {
       
    83     NM_FUNCTION;
       
    84 
       
    85     QString path;
       
    86     path = FmFileDialog::getOpenFileName(0, hbTrId("txt_mail_dialog_select_file"));
       
    87 
       
    88     QString temp = QDir::toNativeSeparators(path);
       
    89     emit attachmentsFetchOk(QVariant(temp));
       
    90 }
       
    91 
       
    92 /*!
       
    93     Send request to retrieve image from camera
       
    94 */
       
    95 void NmAttachmentPicker::fetchCameraStill()
       
    96 {
       
    97     NM_FUNCTION;
       
    98 
       
    99     fetchFromCamera(NmAttachmentPickerStillMode);
       
   100 }
       
   101 
       
   102 /*!
       
   103     Send request to retrieve video from camera
       
   104 */
       
   105 void NmAttachmentPicker::fetchCameraVideo()
       
   106 {
       
   107     NM_FUNCTION;
       
   108 
       
   109     fetchFromCamera(NmAttachmentPickerVideoMode);
       
   110 }
       
   111 
       
   112 /*!
       
   113     Send request to retrieve image/video from camera
       
   114 */
       
   115 void NmAttachmentPicker::fetchFromCamera(int mode)
       
   116 {
       
   117     NM_FUNCTION;
       
   118 
       
   119     int cameraIndex(0);            //primary camera
       
   120     int quality(0);                //default
       
   121     bool allowModeSwitch(false);   //not allowed to change
       
   122     bool allowCameraSwitch(true);  //allow changes
       
   123     bool allowQualityChange(true); //allow changes
       
   124 
       
   125     QVariantMap parameters;
       
   126     parameters.insert(XQCAMERA_INDEX, cameraIndex);
       
   127     parameters.insert(XQCAMERA_QUALITY, quality);
       
   128     parameters.insert(XQCAMERA_MODE_SWITCH, allowModeSwitch);
       
   129     parameters.insert(XQCAMERA_INDEX_SWITCH, allowCameraSwitch);
       
   130     parameters.insert(XQCAMERA_QUALITY_CHANGE, allowQualityChange);
       
   131 
       
   132     QList<QVariant> args;
       
   133     args << mode;
       
   134     args << parameters;
       
   135 
       
   136     fetch(XQI_CAMERA_CAPTURE, "capture(int,QVariantMap)", &args);
       
   137 }
       
   138 /*!
       
   139     Construct & send appmgr request to start appropriate picker
       
   140     param <interface> the interface to be connected to
       
   141     param <operation> the operation of the interface
       
   142     param <args> the arguments that needed by the operation
       
   143 */
       
   144 void NmAttachmentPicker::fetch(const QString &interface,
       
   145     const QString &operation, const QList<QVariant> *args)
       
   146 {
       
   147     NM_FUNCTION;
       
   148 
       
   149     delete mRequest;
       
   150     mRequest = NULL;
       
   151     XQApplicationManager appMgr;
       
   152     mRequest = appMgr.create(interface, operation, true);
       
   153 
       
   154     if (mRequest) {
       
   155         mRequest->setSynchronous(false);
       
   156         if (args) {
       
   157             mRequest->setArguments(*args);
       
   158         }
       
   159         // Set the title for the picker window
       
   160         // Title setting disabled
       
   161         //QVariant title(mTitle);
       
   162         //XQRequestInfo info;
       
   163         //info.setInfo(XQINFO_KEY_WINDOW_TITLE, title);
       
   164         //mRequest->setInfo(info);
       
   165 
       
   166         connect(mRequest, SIGNAL(requestOk(const QVariant&)),
       
   167                 this, SIGNAL(attachmentsFetchOk(const QVariant&)));
       
   168 
       
   169         connect(mRequest, SIGNAL(requestError(int, const QString&)),
       
   170                 this, SIGNAL(attachmentsFetchError(int, const QString&)));
       
   171 
       
   172         mRequest->send();
       
   173     }
       
   174 }
       
   175 
       
   176 /*!
       
   177 	Launch the correct fetcher based on the clicked list item.
       
   178 */
       
   179 void NmAttachmentPicker::selectFetcher(HbListWidgetItem *listItem)
       
   180 {
       
   181     NM_FUNCTION;
       
   182 
       
   183     QString itemText = listItem->text();
       
   184     if (itemText == hbTrId("txt_mail_list_photo")) {
       
   185         fetchImage();
       
   186     }
       
   187     else if (itemText == hbTrId("txt_mail_list_music")) {
       
   188         fetchAudio();
       
   189 	}
       
   190     else if (itemText == hbTrId("txt_mail_list_video")) {
       
   191         fetchVideo();
       
   192 	}
       
   193     else if (itemText == hbTrId("txt_mail_list_other")) {
       
   194         QMetaObject::invokeMethod(this, "fetchOther", Qt::QueuedConnection);
       
   195 	}
       
   196     else if (itemText == hbTrId("txt_mail_list_new_photo")) {
       
   197         fetchCameraStill();
       
   198 	}
       
   199     else if (itemText == hbTrId("txt_mail_list_new_video")) {
       
   200         fetchCameraVideo();
       
   201     }
       
   202 }
       
   203 
       
   204 /*!
       
   205     Sets the title used in the picker views
       
   206 */
       
   207 void NmAttachmentPicker::setTitle(const QString &title)
       
   208 {
       
   209     NM_FUNCTION;
       
   210     
       
   211     mTitle = title;
       
   212 }