Changeset 3


Ignore:
Timestamp:
02/03/10 23:56:22 (2 years ago)
Author:
roeland
Message:

Retrieving contact info works.
Parsing XML data and adding contacts to the list is work in progress.

Location:
libQtGdata/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • libQtGdata/trunk/QtGdata.pro

    r2 r3  
    1212    qtgdata_calendar.cpp \ 
    1313    helper/syncnetworkaccessmanager.cpp \ 
    14     qtgdata_contacts.cpp 
     14    qtgdata_contacts.cpp \ 
     15    qtgdata_contact.cpp 
    1516HEADERS += qtgdata.h \ 
    1617    QtGdata_global.h \ 
  • libQtGdata/trunk/qtgdata.cpp

    r2 r3  
    114114} 
    115115 
    116 QByteArray QtGdata::getFeed(const QString url) 
     116QByteArray QtGdata::getFeed(const QString url, const QString version) 
    117117{ 
    118118  QNetworkRequest request; 
    119119  request.setUrl(QUrl(url)); 
    120120  request.setRawHeader("User-Agent", "QtGdata 0.0.1"); 
    121   request.setRawHeader("GData-Version", "2"); 
     121  request.setRawHeader("GData-Version", version.toAscii()); 
    122122 
    123123  QString authHeader = "GoogleLogin auth=" + Auth; 
  • libQtGdata/trunk/qtgdata.h

    r2 r3  
    3434            const GDATA_ACCOUNT_TYPE accountType = QtGdata::GDATA_ACCOUNT_TYPE_HOSTED_OR_GOOGLE); 
    3535 
    36     QByteArray getFeed(const QString url); 
     36    QByteArray getFeed(const QString url, const QString version = "2"); 
    3737 
    3838    QString email; 
  • libQtGdata/trunk/qtgdata_calendar.cpp

    r2 r3  
    88 
    99} 
    10  
    11 QStringList QtGdata_calendar::getCalendars() 
    12 { 
    13  
    14 } 
  • libQtGdata/trunk/qtgdata_calendar.h

    r2 r3  
    1212    QtGdata_calendar(const QString username, const QString password); 
    1313 
    14     QStringList getCalendars(); 
    1514}; 
    1615 
  • libQtGdata/trunk/qtgdata_contact.cpp

    r2 r3  
    1 #include "qtgdata_contact.h" 
     1#include "qtgdata_contacts.h" 
    22 
     3QtGdata_contact::QtGdata_contact() 
     4{ 
     5 
     6} 
     7 
     8void QtGdata_contact::setName(const QString name) 
     9{ 
     10  this->name = name; 
     11} 
     12 
     13void QtGdata_contact::setUpdated(const QDateTime updated) 
     14{ 
     15  this->updated = updated; 
     16} 
     17 
     18/** 
     19 * @param email Email address 
     20 * @param type What kind of email (home/work/other) 
     21 * @param primary Boolean indicating if this is the primary email 
     22 */ 
     23void QtGdata_contact::addEmail(const QString email, 
     24                               const QtGdata_contact::GDATA_CONTACT_EMAIL type, 
     25                               const bool primary) 
     26{ 
     27  this->email.insert(email, type); 
     28 
     29  if (primary) { 
     30    primary_email = email; 
     31  } 
     32} 
     33 
     34void QtGdata_contact::addPhone(const QString phonenumber, 
     35                               const QtGdata_contact::GDATA_CONTACT_PHONE type) 
     36{ 
     37  phone.insert(phonenumber, type); 
     38} 
     39 
     40 
     41void QtGdata_contact::setGender(const QString gender) 
     42{ 
     43  this->gender = gender; 
     44} 
     45 
     46QString QtGdata_contact::getName() 
     47{ 
     48  return name; 
     49} 
     50 
     51QString QtGdata_contact::getGender() 
     52{ 
     53  return gender; 
     54} 
     55 
     56QDateTime QtGdata_contact::getUpdated() 
     57{ 
     58  return updated; 
     59} 
  • libQtGdata/trunk/qtgdata_contacts.cpp

    r2 r3  
    1919 
    2020 
    21   xml = getFeed(url); 
     21  xml = getFeed(url, "3"); 
    2222  parseContacts(xml); 
    2323 
    2424  while(!next.isEmpty()) { 
    25     xml = getFeed(next); 
     25    xml = getFeed(next, "3"); 
    2626    parseContacts(xml); 
    2727  } 
     
    2929} 
    3030 
     31/* 
     32 * Parse an XML file with contact info 
     33 */ 
    3134void QtGdata_contacts::parseContacts(QByteArray xml) 
    3235{ 
     
    7376  } 
    7477 
    75   QDomNodeList contacts = root.elementsByTagName("entry"); 
     78  /* Parse actual contacts */ 
     79  nl = root.elementsByTagName("entry"); 
     80  for (int i = 0; i < nl.size(); i++) { 
     81    QtGdata_contact c; 
    7682 
    77   for (int i = 0; i < contacts.size(); i++) { 
    78     n = contacts.at(i).toElement(); 
     83    n = nl.at(i).toElement(); 
     84    QDomNodeList nl2 = n.childNodes(); 
    7985 
    80     nl = n.elementsByTagName("title"); 
     86    for (int j = 0; j < nl2.size(); j++) { 
     87      n = nl2.at(j).toElement(); 
    8188 
    82     if (nl.size() == 1) { 
    83       qDebug() << nl.at(0).toElement().text(); 
     89      /* Birthday */ 
     90      if (n.tagName() == "gContact:birthday") { 
     91        QString birthday = n.attribute("when"); 
     92 
     93        /* TODO parse birthday 
     94           see: http://code.google.com/apis/contacts/docs/3.0/reference.html#gcBirthday 
     95         */ 
     96      } 
     97      /* 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; 
     104        if (rel == "http://schemas.google.com/g/2005#home") { 
     105          type = QtGdata_contact::GDATA_CONTACT_EMAIL_HOME; 
     106        } else if (rel == "http://schemas.google.com/g/2005#work") { 
     107          type = QtGdata_contact::GDATA_CONTACT_EMAIL_WORK; 
     108        } 
     109 
     110        c.addEmail(email, type, primary); 
     111      } 
     112      /* 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; 
     118        if (ref == "http://schemas.google.com/g/2005#mobile") { 
     119          type = QtGdata_contact::GDATA_CONTACT_PHONE_MOBILE; 
     120        } 
     121        /* Add other */ 
     122 
     123        c.addPhone(number, type); 
     124      } 
     125      /* Update */ 
     126      else if (n.tagName() == "updated") { 
     127        QDateTime updated = QDateTime::fromString(n.text(), "yyyy-M-ddThh:mm:ss.zzzZ"); 
     128        updated.setTimeSpec(Qt::UTC); 
     129        c.setUpdated(updated); 
     130      } 
    84131    } 
     132 
     133    contacts.append(c); 
    85134  } 
    86135} 
  • libQtGdata/trunk/qtgdata_contacts.h

    r2 r3  
    1 #ifndef QTGDATA_CONTACT_H 
    2 #define QTGDATA_CONTACT_H 
     1#ifndef QTGDATA_CONTACTS_H 
     2#define QTGDATA_CONTACTS_H 
    33 
    44#include <qtgdata.h> 
     
    77#include <QByteArray> 
    88#include <QDateTime> 
    9 #include <QUrl> 
     9#include <QMap> 
     10 
     11class QtGdata_contact 
     12{ 
     13  public: 
     14    enum GDATA_CONTACT_EMAIL { 
     15      GDATA_CONTACT_EMAIL_OTHER, 
     16      GDATA_CONTACT_EMAIL_HOME, 
     17      GDATA_CONTACT_EMAIL_WORK, 
     18    }; 
     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 
     28    }; 
     29 
     30    QtGdata_contact(); 
     31 
     32    /* Getters */ 
     33    QString getGender(); 
     34    QString getName(); 
     35    QDateTime getUpdated(); 
     36 
     37    /* Adders */ 
     38    void addEmail(const QString email, 
     39                  const QtGdata_contact::GDATA_CONTACT_EMAIL type = QtGdata_contact::GDATA_CONTACT_EMAIL_OTHER, 
     40                  const bool primary = false); 
     41    void addPhone(const QString phonenumber, 
     42                  const QtGdata_contact::GDATA_CONTACT_PHONE type = QtGdata_contact::GDATA_CONTACT_PHONE_OTHER); 
     43 
     44    /* Setters */ 
     45    void setGender(const QString gender); 
     46    void setName(const QString name); 
     47    void setUpdated(const QDateTime updated); 
     48 
     49  private: 
     50    //QDate birthday; 
     51    QMap<QString, QtGdata_contact::GDATA_CONTACT_EMAIL> email; 
     52    QString primary_email; 
     53    QString gender; 
     54    QString name; 
     55    QMap<QString, QtGdata_contact::GDATA_CONTACT_PHONE> phone; 
     56    QDateTime updated; 
     57}; 
    1058 
    1159class QtGdata_contacts : public QtGdata 
     
    2169    QDateTime update; 
    2270    QString next; 
     71 
     72    QList<QtGdata_contact> contacts; 
    2373}; 
    2474 
    25 #endif // QTGDATA_CONTACT_H 
     75 
     76#endif // QTGDATA_CONTACTS_H 
Note: See TracChangeset for help on using the changeset viewer.