Changeset 4
- Timestamp:
- 02/05/10 00:24:31 (2 years ago)
- Location:
- libQtGdata/trunk
- Files:
-
- 5 edited
-
qtgdata.cpp (modified) (3 diffs)
-
qtgdata.h (modified) (3 diffs)
-
qtgdata_contact.cpp (modified) (4 diffs)
-
qtgdata_contacts.cpp (modified) (8 diffs)
-
qtgdata_contacts.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libQtGdata/trunk/qtgdata.cpp
r3 r4 23 23 const QString service, 24 24 const QString loginURL, 25 const GDATA_ACCOUNT_TYPE accountType)25 const QtGdata::TYPE accountType) 26 26 { 27 27 login(email, password, service, loginURL, accountType); … … 40 40 const QString service, 41 41 const QString loginURL, 42 const GDATA_ACCOUNT_TYPE accountType,42 const QtGdata::TYPE accountType, 43 43 const QString loginToken, 44 44 const QString loginCaptcha) … … 58 58 /* Request the right access */ 59 59 switch(accountType) { 60 case QtGdata:: GDATA_ACCOUNT_TYPE_GOOGLE:60 case QtGdata::TYPE_GOOGLE: 61 61 data = "accountType=GOOGLE"; 62 62 break; 63 case QtGdata:: GDATA_ACCOUNT_TYPE_HOSTED:63 case QtGdata::TYPE_HOSTED: 64 64 data = "accountType=HOSTED"; 65 65 break; 66 case QtGdata:: GDATA_ACCOUNT_TYPE_HOSTED_OR_GOOGLE:66 case QtGdata::TYPE_HOSTED_OR_GOOGLE: 67 67 data = "accountType=HOSTED_OR_GOOGLE"; 68 68 break; -
libQtGdata/trunk/qtgdata.h
r3 r4 14 14 15 15 public: 16 enum GDATA_ACCOUNT_TYPE { 17 GDATA_ACCOUNT_TYPE_GOOGLE, 18 GDATA_ACCOUNT_TYPE_HOSTED, 19 GDATA_ACCOUNT_TYPE_HOSTED_OR_GOOGLE 20 }; 21 22 enum GDATA_REQUEST { 23 GDATA_REQUEST_SUCCESS, 24 GDATA_REQUEST_AUTH_ERR 16 enum TYPE { 17 TYPE_GOOGLE, 18 TYPE_HOSTED, 19 TYPE_HOSTED_OR_GOOGLE 25 20 }; 26 21 … … 32 27 const QString service, 33 28 const QString loginURL = "https://www.google.com/accounts/ClientLogin", 34 const GDATA_ACCOUNT_TYPE accountType = QtGdata::GDATA_ACCOUNT_TYPE_HOSTED_OR_GOOGLE);29 const QtGdata::TYPE accountType = QtGdata::TYPE_HOSTED_OR_GOOGLE); 35 30 36 31 QByteArray getFeed(const QString url, const QString version = "2"); … … 44 39 const QString service, 45 40 const QString loginURL = "https://www.google.com/accounts/ClientLogin", 46 const GDATA_ACCOUNT_TYPE accountType = QtGdata::GDATA_ACCOUNT_TYPE_HOSTED_OR_GOOGLE,41 const QtGdata::TYPE accountType = QtGdata::TYPE_HOSTED_OR_GOOGLE, 47 42 const QString loginToken = QString(), 48 43 const QString loginCaptcha = QString()); -
libQtGdata/trunk/qtgdata_contact.cpp
r3 r4 1 1 #include "qtgdata_contacts.h" 2 3 #include <QUrl> 2 4 3 5 QtGdata_contact::QtGdata_contact() … … 6 8 } 7 9 8 void QtGdata_contact::set Name(const QString name)10 void QtGdata_contact::setTitle(const QString name) 9 11 { 10 this->name = name; 12 names.title = name; 13 } 14 15 void QtGdata_contact::setFullName(const QString name) 16 { 17 names.fullName = name; 18 } 19 20 void QtGdata_contact::setGivenName(const QString name) 21 { 22 names.givenName = name; 23 } 24 25 void QtGdata_contact::setFamilyName(const QString name) 26 { 27 names.familyName = name; 11 28 } 12 29 … … 20 37 * @param type What kind of email (home/work/other) 21 38 * @param primary Boolean indicating if this is the primary email 39 * 40 * @todo make sure there is exactly 1 primary email address 41 * @todo find out what to do with duplicated emails 22 42 */ 23 43 void QtGdata_contact::addEmail(const QString email, 24 const QtGdata_contact:: GDATA_CONTACT_EMAIL type,44 const QtGdata_contact::EMAIL type, 25 45 const bool primary) 26 46 { 27 this->email.insert(email, type); 47 QtGdata_contact::email e; 48 e.email = email; 49 e.type = type; 50 e.primary = primary; 28 51 29 if (primary) { 30 primary_email = email; 31 } 52 emails.append(e); 32 53 } 33 54 55 /** 56 * @param phonenumber The phone number to add 57 * @param type The type of phone number (home/work/pager/fax...) 58 * 59 * @todo Find out if duplicated numbers can occure (currently not posible) 60 */ 34 61 void QtGdata_contact::addPhone(const QString phonenumber, 35 const QtGdata_contact:: GDATA_CONTACT_PHONE type)62 const QtGdata_contact::PHONE type) 36 63 { 37 phone.insert(phonenumber, type); 64 QtGdata_contact::phone p; 65 p.phonenumber = phonenumber; 66 p.type = type; 67 68 phones.append(p); 38 69 } 39 70 40 71 /** 72 * @param gender The gender of the contact 73 * 74 * @todo Make sure this is valid (better of with enum) 75 */ 41 76 void QtGdata_contact::setGender(const QString gender) 42 77 { … … 44 79 } 45 80 81 /** 82 * @param link The link to the contact 83 * 84 * @todo Check if this is a valid url 85 */ 86 void QtGdata_contact::setLinkEdit(const QString link) 87 { 88 linkEdit = QUrl(link); 89 } 90 91 /** 92 * @param link The link to edit the contact 93 * 94 * @todo Check if this is a valid url 95 */ 96 void QtGdata_contact::setLinkSelf(const QString link) 97 { 98 linkSelf = QUrl(link); 99 } 100 101 /** 102 * Fill an address struct and add it to the list 103 */ 104 void QtGdata_contact::setAddress(const QString street, 105 const QString postcode, 106 const QString city, 107 const QString region, 108 const QString country, 109 const QtGdata_contact::ADDRESS type) 110 { 111 QtGdata_contact::address a; 112 a.street = street; 113 a.postcode = postcode; 114 a.city = city; 115 a.region = region; 116 a.country = country; 117 118 addresses.append(a); 119 } 120 46 121 QString QtGdata_contact::getName() 47 122 { 48 return name;123 return QString(); 49 124 } 50 125 -
libQtGdata/trunk/qtgdata_contacts.cpp
r3 r4 8 8 QtGdata(username, password, "cp") 9 9 { 10 11 10 } 12 11 12 /** 13 * Retrieve all contacts and parse them 14 */ 13 15 void QtGdata_contacts::getAllContacts() 14 16 { … … 29 31 } 30 32 31 /* 33 /** 32 34 * Parse an XML file with contact info 33 35 */ … … 37 39 38 40 if (!document.setContent(xml)) { 39 qDebug() << "O_NO!"; 41 qDebug() << "Could not parse xml"; 42 return; 40 43 } 41 44 … … 43 46 44 47 if (root.tagName() != "feed") { 45 qDebug() << "other root tag"; 46 } 47 48 QDomElement n; 49 QDomNodeList nl; 50 51 /* Reset */ 48 qDebug() << "invalid root tag"; 49 return; 50 } 51 52 /* Reset */ 52 53 next = QString(); 53 54 54 55 /* Parse children */ 55 nl = root.childNodes(); 56 57 for (int i = 0; i < nl.size(); i++) { 58 n = nl.at(i).toElement(); 56 QDomNodeList children = root.childNodes(); 57 QDomElement child; 58 59 /* Loop over children to parse "general" data */ 60 for (int i = 0; i < children.size(); i++) { 61 child = children.at(i).toElement(); 59 62 60 63 /* Parese update element */ 61 if ( n.tagName() == "updated") {62 QDateTime t = QDateTime::fromString( n.text());63 64 /* Check if we need to upda etthe update variable */64 if (child.tagName() == "updated") { 65 QDateTime t = QDateTime::fromString(child.text()); 66 67 /* Check if we need to update the update variable */ 65 68 if (!update.isValid() || t > update) { 66 69 update = t; … … 68 71 } 69 72 /* Parse link elements */ 70 else if ( n.tagName() == "link") {71 QString attribute = n.attribute("rel");73 else if (child.tagName() == "link") { 74 QString attribute = child.attribute("rel"); 72 75 if (attribute == "next") { 73 next = QUrl::fromEncoded( n.attribute("href").toAscii()).toString();76 next = QUrl::fromEncoded(child.attribute("href").toAscii()).toString(); 74 77 } 75 78 } … … 77 80 78 81 /* Parse actual contacts */ 79 nl= root.elementsByTagName("entry");80 for (int i = 0; i < nl.size(); i++) {82 QDomNodeList entries = root.elementsByTagName("entry"); 83 for (int i = 0; i < entries.size(); i++) { 81 84 QtGdata_contact c; 82 85 83 n = nl.at(i).toElement(); 84 QDomNodeList nl2 = n.childNodes(); 85 86 for (int j = 0; j < nl2.size(); j++) { 87 n = nl2.at(j).toElement(); 88 86 QDomNodeList entry = entries.at(i).toElement().childNodes(); 87 88 /* Parse all children of a contact */ 89 for (int j = 0; j < entry.size(); j++) { 90 QDomElement element = entry.at(j).toElement(); 91 92 /* Address */ 93 if (element.tagName() == "gd:structuredPostalAddress") { 94 QDomNodeList tmp_nl = element.childNodes(); 95 96 /** @todo this can be done way more elegant */ 97 /** @todo Get type of address */ 98 QString street; 99 QString postcode; 100 QString city; 101 QString region; 102 QString country; 103 104 for (int k = 0; k < tmp_nl.size(); k++) { 105 QDomElement tmp_e = tmp_nl.at(i).toElement(); 106 107 if (tmp_e.tagName() == "gd:formattedAddress") { 108 /* Do we need this one? */ 109 } else if (tmp_e.tagName() == "gd:street") { 110 street = tmp_e.text(); 111 } else if (tmp_e.tagName() == "gd:postcode") { 112 postcode = tmp_e.text(); 113 } else if (tmp_e.tagName() == "gd:city") { 114 city = tmp_e.text(); 115 } else if (tmp_e.tagName() == "gd:region") { 116 region = tmp_e.text(); 117 } else if (tmp_e.tagName() == "gd:country") { 118 country = tmp_e.text(); 119 } 120 } 121 122 c.setAddress(street, postcode, city, region, country); 123 } 89 124 /* Birthday */ 90 if (n.tagName() == "gContact:birthday") {91 QString birthday = n.attribute("when");125 else if (element.tagName() == "gContact:birthday") { 126 QString birthday = element.attribute("when"); 92 127 93 128 /* TODO parse birthday … … 96 131 } 97 132 /* Email */ 98 else if ( n.tagName() == "gd:email") {99 QString email = n.attribute("address");100 QString rel = n.attribute("rel");101 bool primary = ( n.hasAttribute("primary") && n.attribute("primary") == "yes");102 103 QtGdata_contact:: GDATA_CONTACT_EMAIL type = QtGdata_contact::GDATA_CONTACT_EMAIL_OTHER;133 else if (element.tagName() == "gd:email") { 134 QString email = element.attribute("address"); 135 QString rel = element.attribute("rel"); 136 bool primary = (element.hasAttribute("primary") && element.attribute("primary") == "yes"); 137 138 QtGdata_contact::EMAIL type = QtGdata_contact::EMAIL_OTHER; 104 139 if (rel == "http://schemas.google.com/g/2005#home") { 105 type = QtGdata_contact:: GDATA_CONTACT_EMAIL_HOME;140 type = QtGdata_contact::EMAIL_HOME; 106 141 } else if (rel == "http://schemas.google.com/g/2005#work") { 107 type = QtGdata_contact:: GDATA_CONTACT_EMAIL_WORK;142 type = QtGdata_contact::EMAIL_WORK; 108 143 } 109 144 110 145 c.addEmail(email, type, primary); 111 146 } 147 /* Link */ 148 else if(element.tagName() == "link") { 149 QString rel = element.attribute("rel"); 150 151 if (rel == "self") { 152 c.setLinkSelf(element.text()); 153 } else if (rel == "edit") { 154 c.setLinkEdit(element.text()); 155 } 156 } 157 /* Parse name(s) */ 158 else if (element.tagName() == "gd:name") { 159 QDomNodeList tmp_nl = element.childNodes(); 160 161 for (int k = 0; k < tmp_nl.size(); k++) { 162 QDomElement tmp_e = tmp_nl.at(i).toElement(); 163 if (tmp_e.tagName() == "gd:fullName") { 164 c.setFullName(tmp_e.text()); 165 } else if (tmp_e.tagName() == "gd:givenName") { 166 c.setGivenName(tmp_e.text()); 167 } else if (tmp_e.tagName() == "gd:familyName") { 168 c.setFamilyName(tmp_e.text()); 169 } 170 /** @todo Other name stuff */ 171 } 172 } 112 173 /* Phone number */ 113 else if( n.tagName() == "gd:phoneNumber") {114 QString ref = n.attribute("rel");115 QString number = n.text();116 117 QtGdata_contact:: GDATA_CONTACT_PHONE type = QtGdata_contact::GDATA_CONTACT_PHONE_OTHER;174 else if(element.tagName() == "gd:phoneNumber") { 175 QString ref = element.attribute("rel"); 176 QString number = element.text(); 177 178 QtGdata_contact::PHONE type = QtGdata_contact::PHONE_OTHER; 118 179 if (ref == "http://schemas.google.com/g/2005#mobile") { 119 type = QtGdata_contact:: GDATA_CONTACT_PHONE_MOBILE;180 type = QtGdata_contact::PHONE_MOBILE; 120 181 } 121 182 /* Add other */ … … 123 184 c.addPhone(number, type); 124 185 } 186 /* Title */ 187 else if (element.tagName() == "title") { 188 c.setTitle(element.text()); 189 } 125 190 /* Update */ 126 else if ( n.tagName() == "updated") {127 QDateTime updated = QDateTime::fromString( n.text(), "yyyy-M-ddThh:mm:ss.zzzZ");191 else if (element.tagName() == "updated") { 192 QDateTime updated = QDateTime::fromString(element.text(), "yyyy-M-ddThh:mm:ss.zzzZ"); 128 193 updated.setTimeSpec(Qt::UTC); 129 194 c.setUpdated(updated); -
libQtGdata/trunk/qtgdata_contacts.h
r3 r4 8 8 #include <QDateTime> 9 9 #include <QMap> 10 #include <QUrl> 11 #include <QList> 10 12 11 13 class QtGdata_contact 12 14 { 13 15 public: 14 enum GDATA_CONTACT_EMAIL { 15 GDATA_CONTACT_EMAIL_OTHER, 16 GDATA_CONTACT_EMAIL_HOME, 17 GDATA_CONTACT_EMAIL_WORK, 16 enum ADDRESS { 17 ADDRESS_OTHER 18 18 }; 19 19 20 enum GDATA_CONTACT_PHONE { 21 GDATA_CONTACT_PHONE_OTHER, 22 GDATA_CONTACT_PHONE_HOME, 23 GDATA_CONTACT_PHONE_HOME_FAX, 24 GDATA_CONTACT_PHONE_WORK, 25 GDATA_CONTACT_PHONE_WORK_FAX, 26 GDATA_CONTACT_PHONE_MOBILE, 27 GDATA_CONTACT_PHONE_PAGER 20 enum EMAIL { 21 EMAIL_OTHER, 22 EMAIL_HOME, 23 EMAIL_WORK, 28 24 }; 25 26 enum GENDER { 27 GENDER_MALE, 28 GENDER_FEMALE 29 }; 30 31 enum PHONE { 32 PHONE_OTHER, 33 PHONE_HOME, 34 PHONE_HOME_FAX, 35 PHONE_WORK, 36 PHONE_WORK_FAX, 37 PHONE_MOBILE, 38 PHONE_PAGER 39 }; 40 41 typedef struct address { 42 QString street; 43 QString postcode; 44 QString city; 45 QString region; 46 QString country; 47 48 QString formattedAddress; /* Overkill?*/ 49 50 QtGdata_contact::ADDRESS type; 51 } address; 52 53 typedef struct email { 54 QString email; 55 QtGdata_contact::EMAIL type; 56 bool primary; 57 } email; 58 59 typedef struct name { 60 QString title; 61 QString fullName; 62 QString givenName; 63 QString familyName; 64 } name; 65 66 typedef struct phone { 67 QString phonenumber; 68 QtGdata_contact::PHONE type; 69 } phone; 29 70 30 71 QtGdata_contact(); … … 37 78 /* Adders */ 38 79 void addEmail(const QString email, 39 const QtGdata_contact:: GDATA_CONTACT_EMAIL type = QtGdata_contact::GDATA_CONTACT_EMAIL_OTHER,80 const QtGdata_contact::EMAIL type = QtGdata_contact::EMAIL_OTHER, 40 81 const bool primary = false); 41 82 void addPhone(const QString phonenumber, 42 const QtGdata_contact:: GDATA_CONTACT_PHONE type = QtGdata_contact::GDATA_CONTACT_PHONE_OTHER);83 const QtGdata_contact::PHONE type = QtGdata_contact::PHONE_OTHER); 43 84 44 85 /* Setters */ 86 void setAddress(const QString street, 87 const QString postcode, 88 const QString city, 89 const QString region, 90 const QString country, 91 const QtGdata_contact::ADDRESS type = QtGdata_contact::ADDRESS_OTHER); 45 92 void setGender(const QString gender); 93 void setLinkEdit(const QString link); 94 void setLinkSelf(const QString link); 46 95 void setName(const QString name); 47 96 void setUpdated(const QDateTime updated); 48 97 98 /* Set names */ 99 void setTitle(const QString name); 100 void setFullName(const QString name); 101 void setGivenName(const QString name); 102 void setFamilyName(const QString name); 103 49 104 private: 50 105 //QDate birthday; 51 Q Map<QString, QtGdata_contact::GDATA_CONTACT_EMAIL> email;52 Q String primary_email;106 QList<address> addresses; 107 QList<email> emails; 53 108 QString gender; 54 QString name;55 Q Map<QString, QtGdata_contact::GDATA_CONTACT_PHONE> phone;109 name names; 110 QList<phone> phones; 56 111 QDateTime updated; 112 113 114 QUrl linkEdit; 115 QUrl linkSelf; 57 116 }; 58 117
Note: See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)