Changeset 4


Ignore:
Timestamp:
02/05/10 00:24:31 (2 years ago)
Author:
roeland
Message:

Parsing some more contact data.
Added doxygen comments. A lot of cleaning up or design choises are
needed. But lets first get a working prototype.

Location:
libQtGdata/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • libQtGdata/trunk/qtgdata.cpp

    r3 r4  
    2323                 const QString service, 
    2424                 const QString loginURL, 
    25                  const GDATA_ACCOUNT_TYPE accountType) 
     25                 const QtGdata::TYPE accountType) 
    2626{ 
    2727  login(email, password, service, loginURL, accountType); 
     
    4040                    const QString service, 
    4141                    const QString loginURL, 
    42                     const GDATA_ACCOUNT_TYPE accountType, 
     42                    const QtGdata::TYPE accountType, 
    4343                    const QString loginToken, 
    4444                    const QString loginCaptcha) 
     
    5858  /* Request the right access */ 
    5959  switch(accountType) { 
    60     case QtGdata::GDATA_ACCOUNT_TYPE_GOOGLE: 
     60    case QtGdata::TYPE_GOOGLE: 
    6161      data = "accountType=GOOGLE"; 
    6262      break; 
    63     case QtGdata::GDATA_ACCOUNT_TYPE_HOSTED: 
     63    case QtGdata::TYPE_HOSTED: 
    6464      data = "accountType=HOSTED"; 
    6565      break; 
    66     case QtGdata::GDATA_ACCOUNT_TYPE_HOSTED_OR_GOOGLE: 
     66    case QtGdata::TYPE_HOSTED_OR_GOOGLE: 
    6767      data = "accountType=HOSTED_OR_GOOGLE"; 
    6868      break; 
  • libQtGdata/trunk/qtgdata.h

    r3 r4  
    1414 
    1515  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 
    2520    }; 
    2621 
     
    3227            const QString service, 
    3328            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); 
    3530 
    3631    QByteArray getFeed(const QString url, const QString version = "2"); 
     
    4439                 const QString service, 
    4540                 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, 
    4742                 const QString loginToken = QString(), 
    4843                 const QString loginCaptcha = QString()); 
  • libQtGdata/trunk/qtgdata_contact.cpp

    r3 r4  
    11#include "qtgdata_contacts.h" 
     2 
     3#include <QUrl> 
    24 
    35QtGdata_contact::QtGdata_contact() 
     
    68} 
    79 
    8 void QtGdata_contact::setName(const QString name) 
     10void QtGdata_contact::setTitle(const QString name) 
    911{ 
    10   this->name = name; 
     12  names.title = name; 
     13} 
     14 
     15void QtGdata_contact::setFullName(const QString name) 
     16{ 
     17  names.fullName = name; 
     18} 
     19 
     20void QtGdata_contact::setGivenName(const QString name) 
     21{ 
     22  names.givenName = name; 
     23} 
     24 
     25void QtGdata_contact::setFamilyName(const QString name) 
     26{ 
     27  names.familyName = name; 
    1128} 
    1229 
     
    2037 * @param type What kind of email (home/work/other) 
    2138 * @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 
    2242 */ 
    2343void QtGdata_contact::addEmail(const QString email, 
    24                                const QtGdata_contact::GDATA_CONTACT_EMAIL type, 
     44                               const QtGdata_contact::EMAIL type, 
    2545                               const bool primary) 
    2646{ 
    27   this->email.insert(email, type); 
     47  QtGdata_contact::email e; 
     48  e.email = email; 
     49  e.type = type; 
     50  e.primary = primary; 
    2851 
    29   if (primary) { 
    30     primary_email = email; 
    31   } 
     52  emails.append(e); 
    3253} 
    3354 
     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 */ 
    3461void QtGdata_contact::addPhone(const QString phonenumber, 
    35                                const QtGdata_contact::GDATA_CONTACT_PHONE type) 
     62                               const QtGdata_contact::PHONE type) 
    3663{ 
    37   phone.insert(phonenumber, type); 
     64  QtGdata_contact::phone p; 
     65  p.phonenumber = phonenumber; 
     66  p.type = type; 
     67 
     68  phones.append(p); 
    3869} 
    3970 
    40  
     71/** 
     72 * @param gender The gender of the contact 
     73 * 
     74 * @todo Make sure this is valid (better of with enum) 
     75 */ 
    4176void QtGdata_contact::setGender(const QString gender) 
    4277{ 
     
    4479} 
    4580 
     81/** 
     82 * @param link The link to the contact 
     83 * 
     84 * @todo Check if this is a valid url 
     85 */ 
     86void 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 */ 
     96void 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 */ 
     104void 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 
    46121QString QtGdata_contact::getName() 
    47122{ 
    48   return name; 
     123  return QString(); 
    49124} 
    50125 
  • libQtGdata/trunk/qtgdata_contacts.cpp

    r3 r4  
    88QtGdata(username, password, "cp") 
    99{ 
    10  
    1110} 
    1211 
     12/** 
     13 * Retrieve all contacts and parse them 
     14 */ 
    1315void QtGdata_contacts::getAllContacts() 
    1416{ 
     
    2931} 
    3032 
    31 /* 
     33/** 
    3234 * Parse an XML file with contact info 
    3335 */ 
     
    3739 
    3840  if (!document.setContent(xml)) { 
    39     qDebug() << "O_NO!"; 
     41    qDebug() << "Could not parse xml"; 
     42    return; 
    4043  } 
    4144 
     
    4346 
    4447  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 */ 
    5253  next = QString(); 
    5354 
    5455  /* 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(); 
    5962 
    6063    /* Parese update element */ 
    61     if (n.tagName() == "updated") { 
    62       QDateTime t = QDateTime::fromString(n.text()); 
    63  
    64       /* Check if we need to updaet the 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 */ 
    6568      if (!update.isValid() || t > update) { 
    6669        update = t; 
     
    6871    } 
    6972    /* 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"); 
    7275      if (attribute == "next") { 
    73         next = QUrl::fromEncoded(n.attribute("href").toAscii()).toString(); 
     76        next = QUrl::fromEncoded(child.attribute("href").toAscii()).toString(); 
    7477      } 
    7578    } 
     
    7780 
    7881  /* 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++) { 
    8184    QtGdata_contact c; 
    8285 
    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      } 
    89124      /* 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"); 
    92127 
    93128        /* TODO parse birthday 
     
    96131      } 
    97132      /* 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; 
    104139        if (rel == "http://schemas.google.com/g/2005#home") { 
    105           type = QtGdata_contact::GDATA_CONTACT_EMAIL_HOME; 
     140          type = QtGdata_contact::EMAIL_HOME; 
    106141        } else if (rel == "http://schemas.google.com/g/2005#work") { 
    107           type = QtGdata_contact::GDATA_CONTACT_EMAIL_WORK; 
     142          type = QtGdata_contact::EMAIL_WORK; 
    108143        } 
    109144 
    110145        c.addEmail(email, type, primary); 
    111146      } 
     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      } 
    112173      /* 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; 
    118179        if (ref == "http://schemas.google.com/g/2005#mobile") { 
    119           type = QtGdata_contact::GDATA_CONTACT_PHONE_MOBILE; 
     180          type = QtGdata_contact::PHONE_MOBILE; 
    120181        } 
    121182        /* Add other */ 
     
    123184        c.addPhone(number, type); 
    124185      } 
     186      /* Title */ 
     187      else if (element.tagName() == "title") { 
     188        c.setTitle(element.text()); 
     189      } 
    125190      /* 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"); 
    128193        updated.setTimeSpec(Qt::UTC); 
    129194        c.setUpdated(updated); 
  • libQtGdata/trunk/qtgdata_contacts.h

    r3 r4  
    88#include <QDateTime> 
    99#include <QMap> 
     10#include <QUrl> 
     11#include <QList> 
    1012 
    1113class QtGdata_contact 
    1214{ 
    1315  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 
    1818    }; 
    1919 
    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, 
    2824    }; 
     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; 
    2970 
    3071    QtGdata_contact(); 
     
    3778    /* Adders */ 
    3879    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, 
    4081                  const bool primary = false); 
    4182    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); 
    4384 
    4485    /* 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); 
    4592    void setGender(const QString gender); 
     93    void setLinkEdit(const QString link); 
     94    void setLinkSelf(const QString link); 
    4695    void setName(const QString name); 
    4796    void setUpdated(const QDateTime updated); 
    4897 
     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 
    49104  private: 
    50105    //QDate birthday; 
    51     QMap<QString, QtGdata_contact::GDATA_CONTACT_EMAIL> email; 
    52     QString primary_email; 
     106    QList<address> addresses; 
     107    QList<email> emails; 
    53108    QString gender; 
    54     QString name; 
    55     QMap<QString, QtGdata_contact::GDATA_CONTACT_PHONE> phone; 
     109    name names; 
     110    QList<phone> phones; 
    56111    QDateTime updated; 
     112 
     113 
     114    QUrl linkEdit; 
     115    QUrl linkSelf; 
    57116}; 
    58117 
Note: See TracChangeset for help on using the changeset viewer.