phonebookui/cntcommonui/views/cntimageeditorview.cpp
changeset 81 640d30f4fb64
parent 72 6abfb1094884
equal deleted inserted replaced
77:c18f9fa7f42e 81:640d30f4fb64
    19 #include "cntthumbnailmanager.h"
    19 #include "cntthumbnailmanager.h"
    20 #include "cntimageutility.h"
    20 #include "cntimageutility.h"
    21 #include "cntsavemanager.h"
    21 #include "cntsavemanager.h"
    22 #include "cntimagelabel.h"
    22 #include "cntimagelabel.h"
    23 
    23 
    24 #include <hblabel.h>
       
    25 #include <xqaiwrequest.h>
       
    26 #include <xqaiwdecl.h>
       
    27 
       
    28 #include "cntdebug.h"
    24 #include "cntdebug.h"
    29 #include "cntglobal.h"
    25 #include "cntglobal.h"
    30 
    26 
    31 #include <hbaction.h>
    27 #include <hbaction.h>
    32 #include <hbview.h>
    28 #include <hbview.h>
    35 #include <hblistviewitem.h>
    31 #include <hblistviewitem.h>
    36 #include <hbframebackground.h>
    32 #include <hbframebackground.h>
    37 #include <hbdevicenotificationdialog.h>
    33 #include <hbdevicenotificationdialog.h>
    38 #include <hbparameterlengthlimiter.h>
    34 #include <hbparameterlengthlimiter.h>
    39 
    35 
       
    36 #include <xqaiwrequest.h>
       
    37 #include <xqaiwdecl.h>
       
    38 
    40 #include <QStandardItemModel>
    39 #include <QStandardItemModel>
    41 #include <QApplication>
    40 #include <QApplication>
    42 
    41 
    43 const char *CNT_IMAGE_XML = ":/xml/contacts_if.docml";
    42 const char *CNT_IMAGE_XML = ":/xml/contacts_if.docml";
    44 
    43 
    50     mAvatar(NULL),
    49     mAvatar(NULL),
    51     mImageLabel(NULL),
    50     mImageLabel(NULL),
    52     mRequest(NULL),
    51     mRequest(NULL),
    53     mViewManager(NULL),
    52     mViewManager(NULL),
    54     mListView(NULL),
    53     mListView(NULL),
    55     mModel(NULL),
    54     mModel(NULL)
    56     mSaveManager(NULL)
       
    57 {
    55 {
    58     bool ok = false;
    56     bool ok = false;
    59     mDocumentLoader.load(CNT_IMAGE_XML, &ok);
    57     mDocumentLoader.load(CNT_IMAGE_XML, &ok);
    60 
    58 
    61     if (ok)
    59     if (ok)
    87     CNT_ENTRY
    85     CNT_ENTRY
    88     
    86     
    89     mView->deleteLater();
    87     mView->deleteLater();
    90 
    88 
    91     delete mAvatar;
    89     delete mAvatar;
    92     mAvatar = NULL;
       
    93     delete mContact;
    90     delete mContact;
    94     mContact = NULL;
       
    95     delete mRequest;
    91     delete mRequest;
    96     mRequest = NULL;
       
    97     delete mRemoveImage;
    92     delete mRemoveImage;
    98     mRemoveImage = NULL;
       
    99     delete mModel;
    93     delete mModel;
   100     mModel = NULL;
       
   101     delete mSaveManager;
       
   102     mSaveManager = NULL;
       
   103     
    94     
   104     CNT_EXIT
    95     CNT_EXIT
   105 }
    96 }
   106 
    97 
   107 /*!
    98 /*!
   134     if ( mArgs.contains(ESelectedGroupContact) && !mContact ) 
   125     if ( mArgs.contains(ESelectedGroupContact) && !mContact ) 
   135     {
   126     {
   136         mContact = new QContact(mArgs.value(ESelectedGroupContact).value<QContact>());
   127         mContact = new QContact(mArgs.value(ESelectedGroupContact).value<QContact>());
   137     }
   128     }
   138     
   129     
   139     QString myCard = mArgs.value( EMyCard ).toString();
       
   140     QContactLocalId localId = mContact->localId();
       
   141     QContactLocalId selfContactId = mEngine->contactManager(SYMBIAN_BACKEND).selfContactId();
       
   142     bool isMyCard = ( localId == selfContactId && localId != 0 ) || !myCard.isEmpty();
       
   143     
       
   144     if (isMyCard)
       
   145     {
       
   146         mSaveManager = new CntSaveManager(CntSaveManager::EMyCard);
       
   147     }
       
   148     else if (mContact->type() == QContactType::TypeGroup)
       
   149     {
       
   150         mSaveManager = new CntSaveManager(CntSaveManager::EGroup);
       
   151     }
       
   152     else
       
   153     {
       
   154         mSaveManager = new CntSaveManager();
       
   155     }
       
   156     
       
   157     // set the correct image if the contact already has an image set
   130     // set the correct image if the contact already has an image set
   158     mImageLabel = static_cast<CntImageLabel*>(mDocumentLoader.findWidget(QString("cnt_image_label")));
   131     mImageLabel = static_cast<CntImageLabel*>(mDocumentLoader.findWidget(QString("cnt_image_label")));
   159     mImageLabel->ungrabGesture(Qt::TapGesture);
   132     mImageLabel->ungrabGesture(Qt::TapGesture);
   160     QList<QContactAvatar> details = mContact->details<QContactAvatar>();
   133     QList<QContactAvatar> details = mContact->details<QContactAvatar>();
   161     if (details.count() > 0)
   134     if (details.count() > 0)
   162         {
   135     {
   163         for (int i = 0;i < details.count();i++)
   136         for (int i = 0;i < details.count();i++)
       
   137         {
       
   138             if (details.at(i).imageUrl().isValid())
   164             {
   139             {
   165                 if (details.at(i).imageUrl().isValid())
   140                 mAvatar = new QContactAvatar(details.at(i));
   166                     {
   141                 mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString());
   167                     mAvatar = new QContactAvatar(details.at(i));
   142                 break;
   168                     mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString());
       
   169                     break;
       
   170                     }
       
   171             }
   143             }
   172         }
   144         }
       
   145     }
   173     else
   146     else
   174         {
   147     {
   175         mAvatar = new QContactAvatar();
   148         mAvatar = new QContactAvatar();
   176         mRemoveImage->setEnabled(false);
   149         mRemoveImage->setEnabled(false);
   177         if (mContact->type() == QContactType::TypeGroup)
   150         if (mContact->type() == QContactType::TypeGroup)
   178             {
   151         {
   179             mImageLabel->setAvatarIcon(HbIcon("qtg_large_add_group_picture"));
   152             mImageLabel->setAvatarIcon(HbIcon("qtg_large_add_group_picture"));
   180             }
   153         }
   181         }
   154     }
   182     
   155     
   183     // set up the list
   156     // set up the list
   184     mListView = static_cast<HbListView*>(mDocumentLoader.findWidget(QString("cnt_listview")));
   157     mListView = static_cast<HbListView*>(mDocumentLoader.findWidget(QString("cnt_listview")));
   185     
   158     
   186     connect(mListView, SIGNAL(activated(const QModelIndex&)), this,
   159     connect(mListView, SIGNAL(activated(const QModelIndex&)), this,
   202 void CntImageEditorView::deactivate()
   175 void CntImageEditorView::deactivate()
   203 {
   176 {
   204 
   177 
   205 }
   178 }
   206 
   179 
       
   180 /*!
       
   181 Populate the list model
       
   182 */
   207 void CntImageEditorView::populateModel(QStandardItemModel *model)
   183 void CntImageEditorView::populateModel(QStandardItemModel *model)
   208 {
   184 {
   209     QStandardItem *newPhoto = new QStandardItem();
   185     QStandardItem *newPhoto = new QStandardItem();
   210     newPhoto->setText(hbTrId("txt_phob_list_take_a_new_photo"));
   186     newPhoto->setText(hbTrId("txt_phob_list_take_a_new_photo"));
   211     newPhoto->setData(HbIcon("qtg_large_camera"), Qt::DecorationRole);
   187     newPhoto->setData(HbIcon("qtg_large_camera"), Qt::DecorationRole);
   227     if (mRequest)
   203     if (mRequest)
   228     {
   204     {
   229         delete mRequest;
   205         delete mRequest;
   230         mRequest = 0;
   206         mRequest = 0;
   231     }
   207     }
   232     
   208   
   233     mRequest = mAppManager.create(XQI_CAMERA_CAPTURE, XQOP_CAMERA_CAPTURE, false);
   209     mRequest = mAppManager.create(XQI_CAMERA_CAPTURE, XQOP_CAMERA_CAPTURE, false);
       
   210 
   234     if ( mRequest ) 
   211     if ( mRequest ) 
   235     {
   212     {
   236         int mode = 0; //image mode
   213         int mode = 0; //image mode
   237         
   214         
   238         QVariantMap map;
   215         QVariantMap map;
   245         // Set function parameters
   222         // Set function parameters
   246         QList<QVariant> args;
   223         QList<QVariant> args;
   247         args << mode;
   224         args << mode;
   248         args << map;
   225         args << map;
   249         mRequest->setArguments(args);
   226         mRequest->setArguments(args);
       
   227         mRequest->setSynchronous(false);    // this must be an Asynchronus request, If symchronous it crashes
   250         
   228         
   251         connect(mRequest, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleImageChange(const QVariant&)));
   229         connect(mRequest, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleImageChange(const QVariant&)));
   252         connect(mRequest, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&)));
   230         
   253 
       
   254         mRequest->send();
   231         mRequest->send();
   255     }
   232     }
   256     
   233     
   257     CNT_EXIT
   234     CNT_EXIT
   258 }
   235 }
   269     }
   246     }
   270     
   247     
   271     mRequest = mAppManager.create(XQI_IMAGE_FETCH, XQOP_IMAGE_FETCH, true);
   248     mRequest = mAppManager.create(XQI_IMAGE_FETCH, XQOP_IMAGE_FETCH, true);
   272     if ( mRequest ) 
   249     if ( mRequest ) 
   273     {
   250     {
       
   251         mRequest->setSynchronous(false);
   274         connect(mRequest, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleImageChange(const QVariant&)));
   252         connect(mRequest, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleImageChange(const QVariant&)));
   275         mRequest->send();
   253         mRequest->send();
   276     }
   254     }
   277 }
   255 }
   278 
   256 
   305     
   283     
   306     mArgs.insert(ECustomParam, viewId());
   284     mArgs.insert(ECustomParam, viewId());
   307     mViewManager->back( mArgs );
   285     mViewManager->back( mArgs );
   308 }
   286 }
   309 
   287 
       
   288 /*!
       
   289 Called when user selects to remove the image
       
   290 */
   310 void CntImageEditorView::removeImage()
   291 void CntImageEditorView::removeImage()
   311 {
   292 {
   312     QString filePath=mAvatar->imageUrl().toString();
   293     QString filePath = mAvatar->imageUrl().toString();
   313     if(!filePath.isEmpty())
   294     if(!filePath.isEmpty())
   314     {
   295     {
   315         // Check if image removable.
   296         // Check if image removable.
   316         CntImageUtility imageUtility;
   297         CntImageUtility imageUtility;
   317         if(imageUtility.isImageRemovable(filePath))
   298         if(imageUtility.isImageRemovable(filePath))
   372     }
   353     }
   373     
   354     
   374     CNT_EXIT
   355     CNT_EXIT
   375 }
   356 }
   376 
   357 
       
   358 /*!
       
   359 Called when thumbnailmanager is ready with the icon handling
       
   360 */
   377 void CntImageEditorView::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error)
   361 void CntImageEditorView::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error)
   378 {
   362 {
   379     CNT_ENTRY_ARGS("error code = " << error)
   363     CNT_ENTRY_ARGS("error code = " << error)
   380     
   364     
   381     Q_UNUSED(data);
   365     Q_UNUSED(data);
   387     }
   371     }
   388     
   372     
   389     CNT_EXIT
   373     CNT_EXIT
   390 }
   374 }
   391 
   375 
       
   376 /*!
       
   377 Load the layout according to orientation
       
   378 */
   392 void CntImageEditorView::setOrientation(Qt::Orientation orientation)
   379 void CntImageEditorView::setOrientation(Qt::Orientation orientation)
   393 {
   380 {
   394     if (orientation == Qt::Vertical) 
   381     if (orientation == Qt::Vertical) 
   395     {
   382     {
   396         // reading "portrait" section
   383         // reading "portrait" section
   423             break;
   410             break;
   424         }
   411         }
   425     }
   412     }
   426 }
   413 }
   427 
   414 
   428 void CntImageEditorView::handleError(int errorCode, const QString& errorMessage)
   415 /*!
   429 {
   416 Saves the whole contact, called when user exits phonebook (via task switcher or end key)
   430     Q_UNUSED(errorCode);
   417 */
   431     Q_UNUSED(errorMessage);
       
   432     CNT_LOG_ARGS("error code = " << errorCode << "errorMessage=" << errorMessage)
       
   433 }
       
   434 
       
   435 void CntImageEditorView::saveContact()
   418 void CntImageEditorView::saveContact()
   436 {
   419 {
   437     mContact->saveDetail(mAvatar);
   420     mContact->saveDetail(mAvatar);
   438 
   421 
   439     if ( mAvatar->imageUrl().isEmpty())
   422     if ( mAvatar->imageUrl().isEmpty())
   440     {
   423     {
   441         mContact->removeDetail(mAvatar);
   424         mContact->removeDetail(mAvatar);
   442     }
   425     }
   443     
   426     
   444     QString name = mEngine->contactManager(SYMBIAN_BACKEND).synthesizedContactDisplayLabel(*mContact);
   427     QContactManager& mgr = mEngine->contactManager( SYMBIAN_BACKEND );
       
   428     QString name = mgr.synthesizedContactDisplayLabel(*mContact);
   445     
   429     
   446     if (name.isEmpty())
   430     if (name.isEmpty())
   447     {
   431     {
   448         name = hbTrId("txt_phob_list_unnamed");
   432         name = hbTrId("txt_phob_list_unnamed");
   449     }
   433     }
   450     
   434     
   451     CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mContact, &mEngine->contactManager(SYMBIAN_BACKEND));
   435     QString myCard = mArgs.value( EMyCard ).toString();
   452     
   436     QContactLocalId localId = mContact->localId();
       
   437     QContactLocalId selfContactId = mgr.selfContactId();
       
   438     bool isMyCard = ( localId == selfContactId && localId != 0 ) || !myCard.isEmpty();
       
   439     
       
   440     CntSaveManager::CntSaveResult result;
       
   441     CntSaveManager& save = mEngine->saveManager();
       
   442     
       
   443     if (isMyCard)
       
   444     {
       
   445         result = save.saveMyCard( mContact, &mgr );
       
   446     }
       
   447     else if (mContact->type() == QContactType::TypeGroup)
       
   448     {
       
   449         result = save.saveGroup( mContact, &mgr );
       
   450     }
       
   451     else
       
   452     {
       
   453         result = save.saveContact( mContact, &mgr );
       
   454     }
       
   455        
   453     if (mContact->type() != QContactType::TypeGroup)
   456     if (mContact->type() != QContactType::TypeGroup)
   454     {
   457     {
   455         switch (result)
   458         switch (result)
   456         {
   459         {
   457         case CntSaveManager::ESaved:
   460         case CntSaveManager::ESaved:
   458             HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contact_1_saved")).arg(name));
   461             HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter("txt_phob_dpophead_contact_1_saved").arg(name));
   459             break;
   462             break;
   460         case CntSaveManager::EUpdated:
   463         case CntSaveManager::EUpdated:
   461             HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contacts_1_updated")).arg(name));
   464             HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter("txt_phob_dpophead_contacts_1_updated").arg(name));
   462             break;
   465             break;
   463         case CntSaveManager::EFailed:
   466         case CntSaveManager::EFailed:
   464             HbDeviceNotificationDialog::notification(QString(),hbTrId("SAVING FAILED!"));
   467             HbDeviceNotificationDialog::notification(QString(),hbTrId("SAVING FAILED!"));
   465             break;
   468             break;
   466         case CntSaveManager::EDeleted:
   469         case CntSaveManager::EDeleted: