contactwidgethsplugin/contactwidgeths/src/contactwidgeths.cpp
changeset 81 640d30f4fb64
parent 72 6abfb1094884
equal deleted inserted replaced
77:c18f9fa7f42e 81:640d30f4fb64
    53 // Preferences properties
    53 // Preferences properties
    54 const QString widgetPrefContactId = "contactId";
    54 const QString widgetPrefContactId = "contactId";
    55 // Docml file
    55 // Docml file
    56 const QString contactWidgetDocml = ":/commlauncherwidget.docml";
    56 const QString contactWidgetDocml = ":/commlauncherwidget.docml";
    57 
    57 
    58 
       
    59 // TODO: THESE STRINGS ARE IN W32 SDK. THESE DEFINITIONS CAN BE REMOVED
       
    60 // WHEN EVERYBODY ARE USING IT OR LATER VERSION
       
    61 #ifndef XQI_CONTACTS_FETCH
       
    62 #define XQI_CONTACTS_FETCH QLatin1String("com.nokia.symbian.IContactsFetch")
       
    63 #endif
       
    64 #ifndef XQOP_CONTACTS_FETCH_SINGLE
       
    65 #define XQOP_CONTACTS_FETCH_SINGLE QLatin1String("singleFetch(QString,QString)")
       
    66 #endif
       
    67 
       
    68 
       
    69 
       
    70 /*!
    58 /*!
    71   \class ContactWidgetHs
    59   \class ContactWidgetHs
    72 */
    60 */
    73 
    61 
    74 /*!
    62 /*!
    90   mMainWindow(0),
    78   mMainWindow(0),
    91   mThumbnailManager(new ThumbnailManager(this)),
    79   mThumbnailManager(new ThumbnailManager(this)),
    92   mThumbnailPixmap(QPixmap()),
    80   mThumbnailPixmap(QPixmap()),
    93   mThumbnailInProgress(false),
    81   mThumbnailInProgress(false),
    94   mTranslator(new HbTranslator(translationsPath, translationsFile)),
    82   mTranslator(new HbTranslator(translationsPath, translationsFile)),
    95   mPendingExit(false)
    83   mPendingExit(false),
       
    84   mNoneContactMessage(0)
    96 {
    85 {
    97     // Localization file loading   		
    86     // Localization file loading   		
    98 	mTranslator->loadCommon();    
    87 	mTranslator->loadCommon();    
    99     
    88     
   100     // UI creation done in onInitialize()
    89     // UI creation done in onInitialize()
   132     mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality);
   121     mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality);
   133     mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailMedium );
   122     mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailMedium );
   134     
   123     
   135     connect(mThumbnailManager.data(), SIGNAL(thumbnailReady(QPixmap, void*, int, int)),
   124     connect(mThumbnailManager.data(), SIGNAL(thumbnailReady(QPixmap, void*, int, int)),
   136         this, SLOT(thumbnailReady(QPixmap, void*, int, int)));
   125         this, SLOT(thumbnailReady(QPixmap, void*, int, int)));
   137     
       
   138 
       
   139       
       
   140 }
   126 }
   141 
   127 
   142 /*!
   128 /*!
   143     Destructor
   129     Destructor
   144 */
   130 */
   351 
   337 
   352 void ContactWidgetHs::setName(const QString &sName)
   338 void ContactWidgetHs::setName(const QString &sName)
   353 {
   339 {
   354     if (mContactNameLabel) {
   340     if (mContactNameLabel) {
   355         mContactNameLabel->setPlainText(sName);
   341         mContactNameLabel->setPlainText(sName);
       
   342         HbFontSpec aFontSpec(HbFontSpec::Secondary);
       
   343 		QFontMetrics aMetrics(aFontSpec.font());
       
   344 		int aTextWidth = aMetrics.width(sName);
       
   345 	    qreal aWidgetWidth = 11 * HbDeviceProfile::current().unitValue();
       
   346 		if (aTextWidth > aWidgetWidth) {
       
   347 		    mContactNameLabel->setAlignment(Qt::AlignLeft);
       
   348 		} else {
       
   349 		    mContactNameLabel->setAlignment(Qt::AlignHCenter);
       
   350 		}
   356     }    
   351     }    
   357 
   352 
   358     update();
   353     update();
   359 }
   354 }
   360 
   355 
   404     style()->parameter("hb-param-text-height-tiny", textHeight);	
   399     style()->parameter("hb-param-text-height-tiny", textHeight);	
   405     if (textHeight > 0) {
   400     if (textHeight > 0) {
   406         fontSpec.setTextHeight(textHeight);
   401         fontSpec.setTextHeight(textHeight);
   407     }
   402     }
   408 
   403 
       
   404     mContactNameLabel = new HbLabel(this);
       
   405     mContactNameLabel->setTextWrapping(Hb::TextNoWrap);
       
   406     mContactNameLabel->setFontSpec(fontSpec);
   409     if (mContactLocalId == unUsedContactId) {
   407     if (mContactLocalId == unUsedContactId) {
   410         mContactNameLabel = new HbLabel("");
   408         setName("");
   411     } else {
   409     } else {
   412 		QString name = getContactDisplayName(mContact);
   410         setName(getContactDisplayName(mContact));
   413         mContactNameLabel = new HbLabel(name);
       
   414     }            
   411     }            
   415     
   412     
   416     mContactNameLabel->setAlignment(Qt::AlignHCenter);
       
   417     mContactNameLabel->setFontSpec(fontSpec);
       
   418     // color from theme
   413     // color from theme
   419     QColor textColor = HbColorScheme::color(normalTextColor);
   414     QColor textColor = HbColorScheme::color(normalTextColor);
   420     if (textColor.isValid()) {
   415     if (textColor.isValid()) {
   421         mContactNameLabel->setTextColor(textColor);
   416         mContactNameLabel->setTextColor(textColor);
   422     } else {
   417     } else {
   482 */
   477 */
   483 void ContactWidgetHs::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
   478 void ContactWidgetHs::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
   484 {
   479 {
   485 	qDebug() << "mouseReleaseEvent event->type() = " << (int)event->type();
   480 	qDebug() << "mouseReleaseEvent event->type() = " << (int)event->type();
   486 
   481 
   487 	//Q_UNUSED(event);
       
   488     if (event && event->type() == QEvent::GraphicsSceneMouseRelease) {
   482     if (event && event->type() == QEvent::GraphicsSceneMouseRelease) {
   489         // If the widget doesn't have contact yet and
   483         // If the widget doesn't have contact yet and
   490         // there are contacts, select one.    
   484         // there are contacts, select one.    
   491         if (mContactLocalId == unUsedContactId) {
   485         if (mContactLocalId == unUsedContactId) {
   492             if (contactsExist()) {				    
   486             if (contactsExist()) {				    
   493                 launchSingleContactSelecting();                  
   487                 launchSingleContactSelecting();                  
   494             } else {
   488             } else {
   495                 // Otherwise ask if user wants to open phonebook
   489             	// otherwise ask user if want create one
   496                 // tmp variable used for title, otherwise parent param is ignored in mb
   490             	showNoneContactMessage();
   497                 QString title = hbTrId("txt_friend_widget_info_you_can_not_use_this_widge");
       
   498                 HbDeviceMessageBox mb( title, HbMessageBox::MessageTypeQuestion, this);
       
   499                 mb.setAction(new QAction(hbTrId("txt_common_button_open"),   &mb), 
       
   500                     HbDeviceMessageBox::AcceptButtonRole);
       
   501                 mb.setAction(new QAction(hbTrId("txt_common_button_cancel"), &mb), 
       
   502                     HbDeviceMessageBox::RejectButtonRole);
       
   503                 mb.setIconVisible(false);
       
   504                 if (mb.exec() == mb.action(HbDeviceMessageBox::AcceptButtonRole)) {				        
       
   505                     mLauncher->openPhonebookCreateNew();
       
   506                 }
       
   507             }
   491             }
   508         } else if (!mLauncher->isVisible()) {
   492         } else if (!mLauncher->isVisible()) {
   509             // Change the frame layout
   493             // Change the frame layout
   510             loadLayout(latchedFrameName, latchedTextColor);
   494             loadLayout(latchedFrameName, latchedTextColor);
   511 
   495 
   677 bool ContactWidgetHs::contactsExist()
   661 bool ContactWidgetHs::contactsExist()
   678 {
   662 {
   679     if (!mContactManager) { 
   663     if (!mContactManager) { 
   680         createContactManager();
   664         createContactManager();
   681     }
   665     }
   682     bool ret=false;
   666     bool aResult = false;
   683     // 
   667 
   684     if (mContactManager) {
   668     if (mContactManager) {
   685         QList<QContactLocalId> contactIds = mContactManager->contactIds();
   669         QList<QContactLocalId> contactIds = mContactManager->contactIds();
   686         qDebug() << "contact count " << contactIds.count();
   670         qDebug() << "contact count " << contactIds.count();
   687         if (contactIds.count() > 0) {
   671     	if (contactIds.count() > 1) {
   688         qDebug() << "first " << contactIds.first();
   672     		aResult = true;
   689         int i;
   673     	} else if (contactIds.count() == 1 &&
   690         for(i=0; i<contactIds.count(); i++) {
   674     			   contactIds.first() != mContactManager->selfContactId()) {
   691 			qDebug() << "contactIds i " << i << " id " << contactIds.at(i);
   675 			aResult = true;
   692         }                        
       
   693             if (contactIds.first() != mContactManager->selfContactId() ||
       
   694                 contactIds.count() > 1) {
       
   695                 ret=true;
       
   696             }
       
   697         }
   676         }
   698     }
   677     }
   699     
   678     
   700     return ret;
   679     return aResult;
   701 }
   680 }
   702 
   681 
   703 /*!
   682 /*!
   704     This launches SINGLE contact selecting.
   683     This launches SINGLE contact selecting.
   705 */
   684 */
   715     mContactLocalId = unUsedContactId;
   694     mContactLocalId = unUsedContactId;
   716     
   695     
   717     mContactSelectRequest = mAppManager->create(XQI_CONTACTS_FETCH,
   696     mContactSelectRequest = mAppManager->create(XQI_CONTACTS_FETCH,
   718                                                 XQOP_CONTACTS_FETCH_SINGLE,
   697                                                 XQOP_CONTACTS_FETCH_SINGLE,
   719                                                 false);
   698                                                 false);
   720     mCleanupHandler.add(mContactSelectRequest);
   699     if (mContactSelectRequest) {
   721     connect(mContactSelectRequest, SIGNAL(requestOk(QVariant)),
   700     	mCleanupHandler.add(mContactSelectRequest);
   722             this, SLOT(onContactSelectCompleted(QVariant)));  
   701 		connect(mContactSelectRequest, SIGNAL(requestOk(QVariant)),
   723     QList<QVariant> args;
   702 				this, SLOT(onContactSelectCompleted(QVariant)));  
   724     args << hbTrId("txt_friend_widget_title_select_contact");
   703 		QList<QVariant> args;
   725     args << KCntActionAll;
   704 		args << hbTrId("txt_friend_widget_title_select_contact");
   726     mContactSelectRequest->setArguments(args);
   705 		args << KCntActionAll;
   727     
   706 		mContactSelectRequest->setArguments(args);
   728     qDebug() << "---- setArgs done ---------------------"; //,,28.5.          
   707 		mContactSelectRequest->setSynchronous(false);
   729     
   708     
   730     result = mContactSelectRequest->send();
   709 		qDebug() << "---- setArgs done ---------------------"; //,,28.5.          
   731     if (!result) {
   710     
   732         qDebug() << "Sending XQServiceRequest failed";
   711 		result = mContactSelectRequest->send();
   733     }  
   712 		if (!result) {
       
   713 			qDebug() << "Sending XQServiceRequest failed";
       
   714 		}
       
   715     } else {
       
   716     	qDebug() << "mContactSelectRequest not created !!!";
       
   717     }
   734     
   718     
   735     qDebug() << "- launchSingleContactSelecting() done"; //,,
   719     qDebug() << "- launchSingleContactSelecting() done"; //,,
   736    
   720    
   737     return result;
   721     return result;
   738 }
   722 }
   880     mContactNameLabel->setTextColor(color);
   864     mContactNameLabel->setTextColor(color);
   881 
   865 
   882     update();
   866     update();
   883 }
   867 }
   884 
   868 
   885 void ContactWidgetHs::onSelfContactIdChanged(const QContactLocalId &theOldId,
   869 /*!
       
   870  * check if local contact was changed to self contact,
       
   871  * if yes remove widget form homescreen 
       
   872  */
       
   873 void ContactWidgetHs::onSelfContactIdChanged(const QContactLocalId & /*theOldId*/,
   886         const QContactLocalId &theNewId) {
   874         const QContactLocalId &theNewId) {
   887     if (0 != theNewId && mContactLocalId == theNewId) {
   875     if (0 != theNewId && mContactLocalId == theNewId) {
   888         qDebug() << "-deleting widget after selfcontact change"
   876         qDebug() << "-deleting widget after selfcontact change"
   889                  << mContactLocalId;
   877                  << mContactLocalId;
   890         finishWidget();
   878         finishWidget();
   891     }
   879     }
   892 }
   880 }
   893 
   881 
       
   882 /*!
       
   883  * function to finish widget and remove widget from homescreen
       
   884  */
   894 void ContactWidgetHs::finishWidget() {
   885 void ContactWidgetHs::finishWidget() {
   895     mAvatarIconItem->deleteLater();
   886     mAvatarIconItem->deleteLater();
   896     mContactNameLabel->deleteLater();
   887     mContactNameLabel->deleteLater();
   897     mContactLocalId = unUsedContactId;
   888     mContactLocalId = unUsedContactId;
   898     mContactHasAvatarDetail = false;
   889     mContactHasAvatarDetail = false;
   901         emit finished();
   892         emit finished();
   902     } else {
   893     } else {
   903     	mPendingExit = true;
   894     	mPendingExit = true;
   904     }
   895     }
   905 }
   896 }
       
   897 
       
   898 /*!
       
   899  * Ask if user wants to open phonebook
       
   900  */
       
   901 void ContactWidgetHs::showNoneContactMessage() {
       
   902 	if (0 == mNoneContactMessage) {
       
   903 	    QString aTitle = hbTrId("txt_friend_widget_info_you_can_not_use_this_widge");
       
   904 		mNoneContactMessage = new HbDeviceMessageBox(aTitle,
       
   905 				HbMessageBox::MessageTypeQuestion,
       
   906 				this);
       
   907 		mNoneContactMessage->setAction(
       
   908 				new QAction(hbTrId("txt_common_button_open"), mNoneContactMessage),
       
   909 		        HbDeviceMessageBox::AcceptButtonRole);
       
   910 		mNoneContactMessage->setAction(
       
   911 				new QAction(hbTrId("txt_common_button_cancel"), mNoneContactMessage),
       
   912 				HbDeviceMessageBox::RejectButtonRole);
       
   913 		mNoneContactMessage->setIconVisible(false);
       
   914 		connect(mNoneContactMessage, SIGNAL(aboutToClose()),
       
   915 				this, SLOT(onAboutCloseNoneContactMessage()));
       
   916 	}
       
   917 	mNoneContactMessage->show();
       
   918 }
       
   919 
       
   920 /*!
       
   921  * if user select open in mNoneContactMessage,
       
   922  * open a phonebook for creating new contact
       
   923  */
       
   924 void ContactWidgetHs::onAboutCloseNoneContactMessage() {
       
   925 	if (mNoneContactMessage) {
       
   926 		const QAction * aResult = mNoneContactMessage->triggeredAction();
       
   927 		bool aCanOpenPhonebook = mNoneContactMessage->isAcceptAction(aResult);
       
   928 		if (aCanOpenPhonebook) {
       
   929 			mLauncher->openPhonebookCreateNew();
       
   930 		}
       
   931 	}
       
   932 }
       
   933 
   906 Q_IMPLEMENT_USER_METATYPE(CntServicesContact)
   934 Q_IMPLEMENT_USER_METATYPE(CntServicesContact)
   907 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList)
   935 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList)