I have made the following changes intended for :
  CE:MW:Shared / nemo-qml-plugins

Please review and accept or decline.
BOSS has already run some checks on this request.
See the "Messages from BOSS" section below.

https://build.pub.meego.com//request/show/7150

Thank You,
Islam Amer

[This message was auto-generated]

---

Request # 7150:

Messages from BOSS:

State: review at 2012-10-26T12:08:23 by bossbot

Reviews:
       accepted by bossbot : Prechecks succeeded.
       new for CE-maintainers : Please replace this text with a review and 
approve/reject the review (not the SR). BOSS will take care of the rest

Changes:
  submit: Project:MTF:MW / nemo-qml-plugins -> CE:MW:Shared / nemo-qml-plugins
  
changes files:
--------------
--- nemo-qml-plugins.changes
+++ nemo-qml-plugins.changes
@@ -0,0 +1,4 @@
+* Tue Oct 26 2012 Johan Paul <[email protected]> - 0.1.2
+- Add support for email types (from Johan)
+- Make contact detail types, that are exposed to UI, enums. (from Johan)
+

old:
----
  nemo-qml-plugins-0.1.1.tar.bz2

new:
----
  nemo-qml-plugins-0.1.2.tar.bz2

spec files:
-----------
--- nemo-qml-plugins.spec
+++ nemo-qml-plugins.spec
@@ -9,7 +9,7 @@
 # << macros
 
 Summary:    Nemo QML plugins source package.
-Version:    0.1.1
+Version:    0.1.2
 Release:    1
 Group:      System/Libraries
 License:    BSD

other changes:
--------------

++++++ nemo-qml-plugins-0.1.1.tar.bz2 -> nemo-qml-plugins-0.1.2.tar.bz2
--- contacts/src/seasideperson.cpp
+++ contacts/src/seasideperson.cpp
@@ -42,22 +42,6 @@
 
 #include "seasideperson.h"
 
-/**
- * String identifying the contact detail from the UI.
- */
-const char *SeasidePerson::SP_CONTEXT_PHONE_HOME   = "phone_home";
-const char *SeasidePerson::SP_CONTEXT_PHONE_WORK   = "phone_work";
-const char *SeasidePerson::SP_CONTEXT_PHONE_MOBILE = "phone_mobile";
-const char *SeasidePerson::SP_CONTEXT_PHONE_FAX    = "phone_fax";
-const char *SeasidePerson::SP_CONTEXT_PHONE_PAGER  = "phone_pager";
-
-/**
- * String identifying the context when saving the contact.
- */
-const char *SeasidePerson::QTCONTACTS_CONTEXT_HOME = "Home";
-const char *SeasidePerson::QTCONTACTS_CONTEXT_WORK = "Work";
-
-
 SeasidePerson::SeasidePerson(QObject *parent)
     : QObject(parent)
 {
@@ -275,77 +259,68 @@
     emit phoneNumbersChanged();
 }
 
-void SeasidePerson::setPhoneContexts(const QStringList &phoneContexts)
+QList<int> SeasidePerson::phoneNumberTypes() const
 {
     const QList<QContactPhoneNumber> &numbers = 
mContact.details<QContactPhoneNumber>();
-    int i=0;
-    QContactPhoneNumber number;
-
-    if (phoneContexts.length() != numbers.length()) {
-        qWarning() << "Number of phone numbers does not match the number of 
contexts being stored. Aborting.";
-        return;
-    }
+    QList<int> types;
+    types.reserve((numbers.length()));
 
-    foreach(const QString &context, phoneContexts) {
-        number = numbers.at(i);
-
-        if (context == SeasidePerson::SP_CONTEXT_PHONE_HOME) {
-            number.setSubTypes(QContactPhoneNumber::SubTypeLandline);
-            number.setContexts(SeasidePerson::QTCONTACTS_CONTEXT_HOME);
-        }  else if (context == SeasidePerson::SP_CONTEXT_PHONE_WORK) {
-            number.setSubTypes(QContactPhoneNumber::SubTypeVoice);
-            number.setContexts(SeasidePerson::QTCONTACTS_CONTEXT_WORK);
-        } else if (context == SeasidePerson::SP_CONTEXT_PHONE_MOBILE) {
-            number.setSubTypes(QContactPhoneNumber::SubTypeMobile);
-            number.setContexts(SeasidePerson::QTCONTACTS_CONTEXT_HOME);
-        } else if (context == SeasidePerson::SP_CONTEXT_PHONE_FAX) {
-            number.setSubTypes(QContactPhoneNumber::SubTypeFax);
-            number.setContexts(SeasidePerson::QTCONTACTS_CONTEXT_HOME);
-        } else if (context == SeasidePerson::SP_CONTEXT_PHONE_PAGER) {
-            number.setSubTypes(QContactPhoneNumber::SubTypePager);
-            number.setContexts(SeasidePerson::QTCONTACTS_CONTEXT_HOME);
+    foreach(const QContactPhoneNumber &number, numbers) {
+        if (number.contexts().contains(QContactDetail::ContextHome)
+            && 
number.subTypes().contains(QContactPhoneNumber::SubTypeLandline)) {
+            types.push_back(SeasidePerson::PhoneHomeType);
+        } else if (number.contexts().contains(QContactDetail::ContextWork)
+            && 
number.subTypes().contains(QContactPhoneNumber::SubTypeLandline)) {
+            types.push_back(SeasidePerson::PhoneWorkType);
+        } else if (number.contexts().contains(QContactDetail::ContextHome)
+            && number.subTypes().contains(QContactPhoneNumber::SubTypeMobile)) 
{
+            types.push_back(SeasidePerson::PhoneMobileType);
+        } else if (number.contexts().contains(QContactDetail::ContextHome)
+            && number.subTypes().contains(QContactPhoneNumber::SubTypeFax)) {
+            types.push_back(SeasidePerson::PhoneFaxType);
+        } else if (number.contexts().contains(QContactDetail::ContextHome)
+            && number.subTypes().contains(QContactPhoneNumber::SubTypePager)) {
+            types.push_back(SeasidePerson::PhonePagerType);
         } else {
-            qWarning() << "Warning: Could not save phone type '" << context << 
"'";
+            qWarning() << "Warning: Could not get phone type for '" << 
number.contexts() << "'";
         }
-
-        mContact.saveDetail(&number);
-        i++;
     }
 
-    emit phoneContextsChanged();
+    return types;
 }
 
-QStringList SeasidePerson::phoneContexts() const
+void SeasidePerson::setPhoneNumberType(int which, SeasidePerson::DetailTypes 
type)
 {
     const QList<QContactPhoneNumber> &numbers = 
mContact.details<QContactPhoneNumber>();
-    QStringList contexts;
-    contexts.reserve((numbers.length()));
+    if (which >= numbers.length()) {
+        qWarning() << "Unable to set type for phone number: invalid index 
specified. Aborting.";
+        return;
+    }
 
-    foreach(const QContactPhoneNumber number, numbers) {
-        if (number.contexts().contains(QTCONTACTS_CONTEXT_HOME)
-            && 
number.subTypes().contains(QContactPhoneNumber::SubTypeLandline)) {
-            contexts.push_back(SP_CONTEXT_PHONE_HOME);
-        } else if (number.contexts().contains(QTCONTACTS_CONTEXT_WORK)
-            && number.subTypes().contains(QContactPhoneNumber::SubTypeVoice)) {
-            contexts.push_back(SP_CONTEXT_PHONE_WORK);
-        } else if (number.contexts().contains(QTCONTACTS_CONTEXT_HOME)
-            && number.subTypes().contains(QContactPhoneNumber::SubTypeMobile)) 
{
-            contexts.push_back(SP_CONTEXT_PHONE_MOBILE);
-        } else if (number.contexts().contains(QTCONTACTS_CONTEXT_HOME)
-            && number.subTypes().contains(QContactPhoneNumber::SubTypeFax)) {
-            contexts.push_back(SP_CONTEXT_PHONE_FAX);
-        } else if (number.contexts().contains(QTCONTACTS_CONTEXT_HOME)
-            && number.subTypes().contains(QContactPhoneNumber::SubTypePager)) {
-            contexts.push_back(SP_CONTEXT_PHONE_PAGER);
-        } else {
-            qWarning() << "Warning: Could not get phone context '" << 
number.contexts() << "'";
-        }
+    QContactPhoneNumber number = numbers.at(which);
+    if (type == SeasidePerson::PhoneHomeType) {
+        number.setSubTypes(QContactPhoneNumber::SubTypeLandline);
+        number.setContexts(QContactDetail::ContextHome);
+    }  else if (type == SeasidePerson::PhoneWorkType) {
+        number.setSubTypes(QContactPhoneNumber::SubTypeLandline);
+        number.setContexts(QContactDetail::ContextWork);
+    } else if (type == SeasidePerson::PhoneMobileType) {
+        number.setSubTypes(QContactPhoneNumber::SubTypeMobile);
+        number.setContexts(QContactDetail::ContextHome);
+    } else if (type == SeasidePerson::PhoneFaxType) {
+        number.setSubTypes(QContactPhoneNumber::SubTypeFax);
+        number.setContexts(QContactDetail::ContextHome);
+    } else if (type == SeasidePerson::PhonePagerType) {
+        number.setSubTypes(QContactPhoneNumber::SubTypePager);
+        number.setContexts(QContactDetail::ContextHome);
+    } else {
+        qWarning() << "Warning: Could not save phone type '" << type << "'";
     }
 
-    return contexts;
+    mContact.saveDetail(&number);
+    emit phoneNumberTypesChanged();
 }
 
-
 QStringList SeasidePerson::emailAddresses() const
 {
     LIST_PROPERTY_FROM_DETAIL_FIELD(QContactEmailAddress, emailAddress);
@@ -357,6 +332,51 @@
     emit emailAddressesChanged();
 }
 
+QList<int> SeasidePerson::emailAddressTypes() const
+{
+    const QList<QContactEmailAddress> &emails = 
mContact.details<QContactEmailAddress>();
+    QList<int> types;
+    types.reserve((emails.length()));
+
+    foreach(const QContactEmailAddress &email, emails) {
+        if (email.contexts().contains(QContactDetail::ContextHome)) {
+            types.push_back(SeasidePerson::EmailHomeType);
+        } else if (email.contexts().contains(QContactDetail::ContextWork)) {
+            types.push_back(SeasidePerson::EmailWorkType);
+        } else if (email.contexts().contains(QContactDetail::ContextOther)) {
+            types.push_back(SeasidePerson::EmailOtherType);
+        } else {
+            qWarning() << "Warning: Could not get email type '" << 
email.contexts() << "'";
+        }
+    }
+
+    return types;
+}
+
+void SeasidePerson::setEmailAddressType(int which, SeasidePerson::DetailTypes 
type)
+{
+    const QList<QContactEmailAddress> &emails = 
mContact.details<QContactEmailAddress>();
+
+    if (which >= emails.length()) {
+        qWarning() << "Unable to set type for email address: invalid index 
specified. Aborting.";
+        return;
+    }
+
+    QContactEmailAddress email = emails.at(which);
+    if (type == SeasidePerson::EmailHomeType) {
+        email.setContexts(QContactDetail::ContextHome);
+    }  else if (type == SeasidePerson::EmailWorkType) {
+        email.setContexts(QContactDetail::ContextWork);
+    } else if (type == SeasidePerson::EmailOtherType) {
+        email.setContexts(QContactDetail::ContextOther);
+    } else {
+        qWarning() << "Warning: Could not save email type '" << type << "'";
+    }
+
+    mContact.saveDetail(&email);
+    emit emailAddressTypesChanged();
+}
+
 // TODO: merge with LIST_PROPERTY_FROM_DETAIL_FIELD
 #define LIST_PROPERTY_FROM_FIELD_NAME(detailType, fieldName) \
     QStringList list; \
--- contacts/src/seasideperson.h
+++ contacts/src/seasideperson.h
@@ -44,22 +44,31 @@
 class SeasidePerson : public QObject
 {
     Q_OBJECT
-public:
-    /**
-     * String identifying the contact detail from the UI.
-     */
-    static const char *SP_CONTEXT_PHONE_HOME;
-    static const char *SP_CONTEXT_PHONE_WORK;
-    static const char *SP_CONTEXT_PHONE_MOBILE;
-    static const char *SP_CONTEXT_PHONE_FAX;
-    static const char *SP_CONTEXT_PHONE_PAGER;
+    Q_ENUMS(DetailTypes)
 
+public:
     /**
-     * String identifying the context when saving the contact.
+     * Identifiers of contact details for the UI.
      */
-    static const char *QTCONTACTS_CONTEXT_HOME;
-    static const char *QTCONTACTS_CONTEXT_WORK;
-
+    enum DetailTypes {
+        // Name
+        FirstNameType,
+        LastNameType,
+        MiddleNameType,
+        CompanyType,
+        NickType,
+        TitleType,
+        // Phone
+        PhoneHomeType,
+        PhoneWorkType,
+        PhoneMobileType,
+        PhoneFaxType,
+        PhonePagerType,
+        // Email
+        EmailHomeType,
+        EmailWorkType,
+        EmailOtherType
+    };
 
     explicit SeasidePerson(QObject *parent = 0);
     ~SeasidePerson();
@@ -96,14 +105,18 @@
     QStringList phoneNumbers() const;
     void setPhoneNumbers(const QStringList &phoneNumbers);
 
-    Q_PROPERTY(QStringList phoneContexts READ phoneContexts WRITE 
setPhoneContexts NOTIFY phoneContextsChanged)
-    QStringList phoneContexts() const;
-    void setPhoneContexts(const QStringList &phoneContexts);
+    Q_PROPERTY(QList<int> phoneNumberTypes READ phoneNumberTypes NOTIFY 
phoneNumberTypesChanged)
+    QList<int> phoneNumberTypes() const;
+    Q_INVOKABLE void setPhoneNumberType(int which, DetailTypes type);
 
     Q_PROPERTY(QStringList emailAddresses READ emailAddresses WRITE 
setEmailAddresses NOTIFY emailAddressesChanged)
     QStringList emailAddresses() const;
     void setEmailAddresses(const QStringList &emailAddresses);
 
+    Q_PROPERTY(QList<int> emailAddressTypes READ emailAddressTypes NOTIFY 
emailAddressTypesChanged)
+    QList<int> emailAddressTypes() const;
+    Q_INVOKABLE void setEmailAddressType(int which, DetailTypes type);
+
     Q_PROPERTY(QStringList accountUris READ accountUris NOTIFY 
accountUrisChanged)
     QStringList accountUris() const;
 
@@ -125,8 +138,9 @@
     void avatarPathChanged();
     void birthdayChanged();
     void phoneNumbersChanged();
-    void phoneContextsChanged();
+    void phoneNumberTypesChanged();
     void emailAddressesChanged();
+    void emailAddressTypesChanged();
     void accountUrisChanged();
     void accountPathsChanged();
 
--- contacts/tests/tst_seasideperson/tst_seasideperson.cpp
+++ contacts/tests/tst_seasideperson/tst_seasideperson.cpp
@@ -52,8 +52,9 @@
     void favorite();
     void avatarPath();
     void phoneNumbers();
-    void phoneContexts();
+    void phoneTypes();
     void emailAddresses();
+    void emailTypes();
     void marshalling();
     void setContact();
 };
@@ -157,27 +158,69 @@
     QCOMPARE(person->phoneNumbers(), QStringList() << "1234" << "5678" << 
"9101112");
 }
 
-void tst_SeasidePerson::phoneContexts() {
+void tst_SeasidePerson::phoneTypes()
+{
     QScopedPointer<SeasidePerson> person(new SeasidePerson);
 
-    QCOMPARE(person->phoneContexts(), QStringList());
+    QCOMPARE(person->phoneNumberTypes(), QList<int>());
     QCOMPARE(person->phoneNumbers(), QStringList());
 
     person->setPhoneNumbers(QStringList() << "111" << "222"<< "333"<< "444"<< 
"555");
 
-    QSignalSpy spy(person.data(), SIGNAL(phoneContextsChanged()));
-    person->setPhoneContexts(QStringList() << 
SeasidePerson::SP_CONTEXT_PHONE_HOME
-                                           << 
SeasidePerson::SP_CONTEXT_PHONE_WORK
-                                           << 
SeasidePerson::SP_CONTEXT_PHONE_MOBILE
-                                           << 
SeasidePerson::SP_CONTEXT_PHONE_FAX
-                                           << 
SeasidePerson::SP_CONTEXT_PHONE_PAGER);
-    QCOMPARE(spy.count(), 1);
-    QCOMPARE(person->phoneContexts(), QStringList() << 
SeasidePerson::SP_CONTEXT_PHONE_HOME
-                                                    << 
SeasidePerson::SP_CONTEXT_PHONE_WORK
-                                                    << 
SeasidePerson::SP_CONTEXT_PHONE_MOBILE
-                                                    << 
SeasidePerson::SP_CONTEXT_PHONE_FAX
-                                                    << 
SeasidePerson::SP_CONTEXT_PHONE_PAGER);
+    QSignalSpy spy(person.data(), SIGNAL(phoneNumberTypesChanged()));
+
+    QList<SeasidePerson::DetailTypes> phoneTypes;
+    phoneTypes.append(SeasidePerson::PhoneHomeType);
+    phoneTypes.append(SeasidePerson::PhoneWorkType);
+    phoneTypes.append(SeasidePerson::PhoneMobileType);
+    phoneTypes.append(SeasidePerson::PhonePagerType);
+    phoneTypes.append(SeasidePerson::PhoneFaxType);
+
+    QStringList numbers = person->phoneNumbers();
+    QCOMPARE(numbers.count(), 5);
+    for (int i=0; i<numbers.count(); i++) {
+        person->setPhoneNumberType(i, phoneTypes.at(i));
+    }
+
+    QCOMPARE(spy.count(), 5);
     QCOMPARE(person->phoneNumbers().count(), 5);
+    QCOMPARE(person->phoneNumberTypes().count(), 5);
+
+    QList<int> contactsPhoneTypes = person->phoneNumberTypes();
+    for (int i=0; i<contactsPhoneTypes.count(); i++) {
+        QVERIFY(contactsPhoneTypes.at(i) == phoneTypes.at(i));
+    }
+}
+
+void tst_SeasidePerson::emailTypes()
+{
+    QScopedPointer<SeasidePerson> person(new SeasidePerson);
+
+    QCOMPARE(person->emailAddressTypes(), QList<int>());
+    QCOMPARE(person->emailAddresses(), QStringList());
+
+    person->setEmailAddresses(QStringList() << "foo@bar" << "bar@foo"<< 
"foo@baz");
+    QSignalSpy spy(person.data(), SIGNAL(emailAddressTypesChanged()));
+
+    QList<SeasidePerson::DetailTypes> emailTypes;
+    emailTypes.append(SeasidePerson::EmailHomeType);
+    emailTypes.append(SeasidePerson::EmailWorkType);
+    emailTypes.append(SeasidePerson::EmailOtherType);
+
+    QStringList emails = person->emailAddresses();
+    QCOMPARE(emails.count(), 3);
+    for (int i=0; i<emails.count(); i++) {
+        person->setEmailAddressType(i, emailTypes.at(i));
+    }
+
+    QCOMPARE(spy.count(), 3);
+    QCOMPARE(person->emailAddresses().count(), 3);
+    QCOMPARE(person->emailAddressTypes().count(), 3);
+
+    QList<int> contactsSmailTypes = person->emailAddressTypes();
+    for (int i=0; i<contactsSmailTypes.count(); i++) {
+        QVERIFY(contactsSmailTypes.at(i) == emailTypes.at(i));
+    }
 }
 
 void tst_SeasidePerson::emailAddresses()

++++++ nemo-qml-plugins.yaml
--- nemo-qml-plugins.yaml
+++ nemo-qml-plugins.yaml
@@ -2,7 +2,7 @@
 Summary: Nemo QML plugins source package.
 Group: System/Libraries
 Description: Do not install this, install the subpackaged plugins.
-Version: 0.1.1
+Version: 0.1.2
 Release: 1
 Sources:
     - "%{name}-%{version}.tar.bz2"



Reply via email to