author | eilers <eilers> | 2003-10-20 15:58:00 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-10-20 15:58:00 (UTC) |
commit | fccc5d110dea3bc32176694c8e5fc7f014706be6 (patch) (side-by-side diff) | |
tree | 6dd44a78cadfd55fc8935dc661318e3ab12dd7b7 | |
parent | 758775c190470e569a0616bbd87d1a378c19b747 (diff) | |
download | opie-fccc5d110dea3bc32176694c8e5fc7f014706be6.zip opie-fccc5d110dea3bc32176694c8e5fc7f014706be6.tar.gz opie-fccc5d110dea3bc32176694c8e5fc7f014706be6.tar.bz2 |
Pushing todo closer to sql support. Recurrances and custom entries still missing.
But before I add this, I have to do some cleanup..
-rw-r--r-- | libopie/pim/ocontactfields.cpp | 233 | ||||
-rw-r--r-- | libopie/pim/ocontactfields.h | 7 | ||||
-rw-r--r-- | libopie/pim/opimnotifymanager.cpp | 72 | ||||
-rw-r--r-- | libopie/pim/opimnotifymanager.h | 24 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 52 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.h | 2 | ||||
-rw-r--r-- | libopie/pim/otodoaccessxml.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 52 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessxml.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimnotifymanager.cpp | 72 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimnotifymanager.h | 24 | ||||
-rw-r--r-- | libopie2/opiepim/ocontactfields.cpp | 233 | ||||
-rw-r--r-- | libopie2/opiepim/ocontactfields.h | 7 |
14 files changed, 520 insertions, 264 deletions
diff --git a/libopie/pim/ocontactfields.cpp b/libopie/pim/ocontactfields.cpp index 7206f0d..0f08a5a 100644 --- a/libopie/pim/ocontactfields.cpp +++ b/libopie/pim/ocontactfields.cpp @@ -1,466 +1,477 @@ #include "ocontactfields.h" #include <qstringlist.h> #include <qobject.h> // We should use our own enum in the future .. #include <qpe/recordfields.h> #include <qpe/config.h> #include <opie/ocontact.h> /*! \internal - Returns a list of details field names for a contact. + Returns a list of personal field names for a contact. */ -QStringList OContactFields::untrdetailsfields( bool sorted ) +QStringList OContactFields::personalfields( bool sorted, bool translated ) { QStringList list; - QMap<int, QString> mapIdToStr = idToUntrFields(); + QMap<int, QString> mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); - list.append( mapIdToStr[ Qtopia::Office ] ); - list.append( mapIdToStr[ Qtopia::Profession ] ); - list.append( mapIdToStr[ Qtopia::Assistant ] ); - list.append( mapIdToStr[ Qtopia::Manager ] ); + list.append( mapIdToStr[ Qtopia::AddressUid ] ); + list.append( mapIdToStr[ Qtopia::AddressCategory ] ); - list.append( mapIdToStr[ Qtopia::Spouse ] ); - list.append( mapIdToStr[ Qtopia::Gender ] ); - list.append( mapIdToStr[ Qtopia::Birthday ] ); - list.append( mapIdToStr[ Qtopia::Anniversary ] ); - list.append( mapIdToStr[ Qtopia::Nickname ] ); - list.append( mapIdToStr[ Qtopia::Children ] ); + list.append( mapIdToStr[ Qtopia::Title ] ); + list.append( mapIdToStr[ Qtopia::FirstName ] ); + list.append( mapIdToStr[ Qtopia::MiddleName ] ); + list.append( mapIdToStr[ Qtopia::LastName ] ); + list.append( mapIdToStr[ Qtopia::Suffix ] ); + list.append( mapIdToStr[ Qtopia::FileAs ] ); + + list.append( mapIdToStr[ Qtopia::JobTitle ] ); + list.append( mapIdToStr[ Qtopia::Department ] ); + list.append( mapIdToStr[ Qtopia::Company ] ); + + list.append( mapIdToStr[ Qtopia::Notes ] ); + list.append( mapIdToStr[ Qtopia::Groups ] ); if (sorted) list.sort(); return list; } /*! \internal - Returns a translated list of details field names for a contact. + Returns a list of details field names for a contact. */ -QStringList OContactFields::trdetailsfields( bool sorted ) +QStringList OContactFields::detailsfields( bool sorted, bool translated ) { QStringList list; - QMap<int, QString> mapIdToStr = idToTrFields(); + QMap<int, QString> mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); - list.append( mapIdToStr[Qtopia::Office] ); - list.append( mapIdToStr[Qtopia::Profession] ); - list.append( mapIdToStr[Qtopia::Assistant] ); - list.append( mapIdToStr[Qtopia::Manager] ); + list.append( mapIdToStr[ Qtopia::Office ] ); + list.append( mapIdToStr[ Qtopia::Profession ] ); + list.append( mapIdToStr[ Qtopia::Assistant ] ); + list.append( mapIdToStr[ Qtopia::Manager ] ); - list.append( mapIdToStr[Qtopia::Spouse] ); - list.append( mapIdToStr[Qtopia::Gender] ); - list.append( mapIdToStr[Qtopia::Birthday] ); - list.append( mapIdToStr[Qtopia::Anniversary] ); - list.append( mapIdToStr[Qtopia::Nickname] ); - list.append( mapIdToStr[Qtopia::Children] ); + list.append( mapIdToStr[ Qtopia::Spouse ] ); + list.append( mapIdToStr[ Qtopia::Gender ] ); + list.append( mapIdToStr[ Qtopia::Birthday ] ); + list.append( mapIdToStr[ Qtopia::Anniversary ] ); + list.append( mapIdToStr[ Qtopia::Nickname ] ); + list.append( mapIdToStr[ Qtopia::Children ] ); if (sorted) list.sort(); return list; } - /*! \internal - Returns a translated list of phone field names for a contact. + Returns a list of phone field names for a contact. */ -QStringList OContactFields::trphonefields( bool sorted ) +QStringList OContactFields::phonefields( bool sorted, bool translated ) { QStringList list; - QMap<int, QString> mapIdToStr = idToTrFields(); + QMap<int, QString> mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); list.append( mapIdToStr[Qtopia::BusinessPhone] ); list.append( mapIdToStr[Qtopia::BusinessFax] ); list.append( mapIdToStr[Qtopia::BusinessMobile] ); list.append( mapIdToStr[Qtopia::BusinessPager] ); list.append( mapIdToStr[Qtopia::BusinessWebPage] ); list.append( mapIdToStr[Qtopia::DefaultEmail] ); list.append( mapIdToStr[Qtopia::Emails] ); list.append( mapIdToStr[Qtopia::HomePhone] ); list.append( mapIdToStr[Qtopia::HomeFax] ); list.append( mapIdToStr[Qtopia::HomeMobile] ); // list.append( mapIdToStr[Qtopia::HomePager] ); list.append( mapIdToStr[Qtopia::HomeWebPage] ); if (sorted) list.sort(); return list; } - /*! \internal - Returns a list of phone field names for a contact. + Returns a list of field names for a contact. */ -QStringList OContactFields::untrphonefields( bool sorted ) +QStringList OContactFields::fields( bool sorted, bool translated ) { QStringList list; - QMap<int, QString> mapIdToStr = idToUntrFields(); - - list.append( mapIdToStr[ Qtopia::BusinessPhone ] ); - list.append( mapIdToStr[ Qtopia::BusinessFax ] ); - list.append( mapIdToStr[ Qtopia::BusinessMobile ] ); - list.append( mapIdToStr[ Qtopia::BusinessPager ] ); - list.append( mapIdToStr[ Qtopia::BusinessWebPage ] ); - - list.append( mapIdToStr[ Qtopia::DefaultEmail ] ); - list.append( mapIdToStr[ Qtopia::Emails ] ); + QMap<int, QString> mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); - list.append( mapIdToStr[ Qtopia::HomePhone ] ); - list.append( mapIdToStr[ Qtopia::HomeFax ] ); - list.append( mapIdToStr[ Qtopia::HomeMobile ] ); - //list.append( mapIdToStr[Qtopia::HomePager] ); - list.append( mapIdToStr[Qtopia::HomeWebPage] ); + list += personalfields( sorted, translated ); - if (sorted) list.sort(); - - return list; -} - - -/*! - \internal - Returns a translated list of field names for a contact. -*/ -QStringList OContactFields::trfields( bool sorted ) -{ - QStringList list; - QMap<int, QString> mapIdToStr = idToTrFields(); - - list.append( mapIdToStr[Qtopia::Title]); - list.append( mapIdToStr[Qtopia::FirstName] ); - list.append( mapIdToStr[Qtopia::MiddleName] ); - list.append( mapIdToStr[Qtopia::LastName] ); - list.append( mapIdToStr[Qtopia::Suffix] ); - list.append( mapIdToStr[Qtopia::FileAs] ); - - list.append( mapIdToStr[Qtopia::JobTitle] ); - list.append( mapIdToStr[Qtopia::Department] ); - list.append( mapIdToStr[Qtopia::Company] ); - - list += trphonefields( sorted ); + list += phonefields( sorted, translated ); list.append( mapIdToStr[Qtopia::BusinessStreet] ); list.append( mapIdToStr[Qtopia::BusinessCity] ); list.append( mapIdToStr[Qtopia::BusinessState] ); list.append( mapIdToStr[Qtopia::BusinessZip] ); list.append( mapIdToStr[Qtopia::BusinessCountry] ); list.append( mapIdToStr[Qtopia::HomeStreet] ); list.append( mapIdToStr[Qtopia::HomeCity] ); list.append( mapIdToStr[Qtopia::HomeState] ); list.append( mapIdToStr[Qtopia::HomeZip] ); list.append( mapIdToStr[Qtopia::HomeCountry] ); - list += trdetailsfields( sorted ); - - list.append( mapIdToStr[Qtopia::Notes] ); - list.append( mapIdToStr[Qtopia::Groups] ); + list += detailsfields( sorted, translated ); if (sorted) list.sort(); return list; } + /*! \internal - Returns an untranslated list of field names for a contact. + Returns an untranslated list of personal field names for a contact. */ -QStringList OContactFields::untrfields( bool sorted ) +QStringList OContactFields::untrpersonalfields( bool sorted ) { - QStringList list; - QMap<int, QString> mapIdToStr = idToUntrFields(); + return personalfields( sorted, false ); +} - list.append( mapIdToStr[ Qtopia::AddressUid ] ); - list.append( mapIdToStr[ Qtopia::AddressCategory ] ); - list.append( mapIdToStr[ Qtopia::Title ] ); - list.append( mapIdToStr[ Qtopia::FirstName ] ); - list.append( mapIdToStr[ Qtopia::MiddleName ] ); - list.append( mapIdToStr[ Qtopia::LastName ] ); - list.append( mapIdToStr[ Qtopia::Suffix ] ); - list.append( mapIdToStr[ Qtopia::FileAs ] ); +/*! + \internal + Returns a translated list of personal field names for a contact. +*/ +QStringList OContactFields::trpersonalfields( bool sorted ) +{ + return personalfields( sorted, true ); +} - list.append( mapIdToStr[ Qtopia::JobTitle ] ); - list.append( mapIdToStr[ Qtopia::Department ] ); - list.append( mapIdToStr[ Qtopia::Company ] ); - list += untrphonefields( sorted ); +/*! + \internal + Returns an untranslated list of details field names for a contact. +*/ +QStringList OContactFields::untrdetailsfields( bool sorted ) +{ + return detailsfields( sorted, false ); +} - list.append( mapIdToStr[ Qtopia::BusinessStreet ] ); - list.append( mapIdToStr[ Qtopia::BusinessCity ] ); - list.append( mapIdToStr[ Qtopia::BusinessState ] ); - list.append( mapIdToStr[ Qtopia::BusinessZip ] ); - list.append( mapIdToStr[ Qtopia::BusinessCountry ] ); - list.append( mapIdToStr[ Qtopia::HomeStreet ] ); - list.append( mapIdToStr[ Qtopia::HomeCity ] ); - list.append( mapIdToStr[ Qtopia::HomeState ] ); - list.append( mapIdToStr[ Qtopia::HomeZip ] ); - list.append( mapIdToStr[ Qtopia::HomeCountry ] ); +/*! + \internal + Returns a translated list of details field names for a contact. +*/ +QStringList OContactFields::trdetailsfields( bool sorted ) +{ + return detailsfields( sorted, true ); +} - list += untrdetailsfields( sorted ); - list.append( mapIdToStr[ Qtopia::Notes ] ); - list.append( mapIdToStr[ Qtopia::Groups ] ); +/*! + \internal + Returns a translated list of phone field names for a contact. +*/ +QStringList OContactFields::trphonefields( bool sorted ) +{ + return phonefields( sorted, true ); +} - if (sorted) list.sort(); +/*! + \internal + Returns an untranslated list of phone field names for a contact. +*/ +QStringList OContactFields::untrphonefields( bool sorted ) +{ + return phonefields( sorted, false ); +} - return list; + +/*! + \internal + Returns a translated list of field names for a contact. +*/ +QStringList OContactFields::trfields( bool sorted ) +{ + return fields( sorted, true ); +} + +/*! + \internal + Returns an untranslated list of field names for a contact. +*/ +QStringList OContactFields::untrfields( bool sorted ) +{ + return fields( sorted, false ); } + QMap<int, QString> OContactFields::idToTrFields() { QMap<int, QString> ret_map; ret_map.insert( Qtopia::AddressUid, QObject::tr( "User Id" ) ); ret_map.insert( Qtopia::AddressCategory, QObject::tr( "Categories" ) ); ret_map.insert( Qtopia::Title, QObject::tr( "Name Title") ); ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) ); ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) ); ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) ); ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" )); ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) ); ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) ); ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) ); ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) ); ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) ); ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) ); ret_map.insert( Qtopia::BusinessMobile, QObject::tr( "Business Mobile" )); // email ret_map.insert( Qtopia::DefaultEmail, QObject::tr( "Default Email" ) ); ret_map.insert( Qtopia::Emails, QObject::tr( "Emails" ) ); ret_map.insert( Qtopia::HomePhone, QObject::tr( "Home Phone" ) ); ret_map.insert( Qtopia::HomeFax, QObject::tr( "Home Fax" ) ); ret_map.insert( Qtopia::HomeMobile, QObject::tr( "Home Mobile" ) ); // business ret_map.insert( Qtopia::BusinessStreet, QObject::tr( "Business Street" ) ); ret_map.insert( Qtopia::BusinessCity, QObject::tr( "Business City" ) ); ret_map.insert( Qtopia::BusinessState, QObject::tr( "Business State" ) ); ret_map.insert( Qtopia::BusinessZip, QObject::tr( "Business Zip" ) ); ret_map.insert( Qtopia::BusinessCountry, QObject::tr( "Business Country" ) ); ret_map.insert( Qtopia::BusinessPager, QObject::tr( "Business Pager" ) ); ret_map.insert( Qtopia::BusinessWebPage, QObject::tr( "Business WebPage" ) ); ret_map.insert( Qtopia::Office, QObject::tr( "Office" ) ); ret_map.insert( Qtopia::Profession, QObject::tr( "Profession" ) ); ret_map.insert( Qtopia::Assistant, QObject::tr( "Assistant" ) ); ret_map.insert( Qtopia::Manager, QObject::tr( "Manager" ) ); // home ret_map.insert( Qtopia::HomeStreet, QObject::tr( "Home Street" ) ); ret_map.insert( Qtopia::HomeCity, QObject::tr( "Home City" ) ); ret_map.insert( Qtopia::HomeState, QObject::tr( "Home State" ) ); ret_map.insert( Qtopia::HomeZip, QObject::tr( "Home Zip" ) ); ret_map.insert( Qtopia::HomeCountry, QObject::tr( "Home Country" ) ); ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) ); //personal ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) ); ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) ); ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) ); ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) ); ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) ); ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) ); // other ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) ); return ret_map; } QMap<int, QString> OContactFields::idToUntrFields() { QMap<int, QString> ret_map; ret_map.insert( Qtopia::AddressUid, "User Id" ); ret_map.insert( Qtopia::AddressCategory, "Categories" ); ret_map.insert( Qtopia::Title, "Name Title" ); ret_map.insert( Qtopia::FirstName, "First Name" ); ret_map.insert( Qtopia::MiddleName, "Middle Name" ); ret_map.insert( Qtopia::LastName, "Last Name" ); ret_map.insert( Qtopia::Suffix, "Suffix" ); ret_map.insert( Qtopia::FileAs, "File As" ); ret_map.insert( Qtopia::JobTitle, "Job Title" ); ret_map.insert( Qtopia::Department, "Department" ); ret_map.insert( Qtopia::Company, "Company" ); ret_map.insert( Qtopia::BusinessPhone, "Business Phone" ); ret_map.insert( Qtopia::BusinessFax, "Business Fax" ); ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" ); // email ret_map.insert( Qtopia::DefaultEmail, "Default Email" ); ret_map.insert( Qtopia::Emails, "Emails" ); ret_map.insert( Qtopia::HomePhone, "Home Phone" ); ret_map.insert( Qtopia::HomeFax, "Home Fax" ); ret_map.insert( Qtopia::HomeMobile, "Home Mobile" ); // business ret_map.insert( Qtopia::BusinessStreet, "Business Street" ); ret_map.insert( Qtopia::BusinessCity, "Business City" ); ret_map.insert( Qtopia::BusinessState, "Business State" ); ret_map.insert( Qtopia::BusinessZip, "Business Zip" ); ret_map.insert( Qtopia::BusinessCountry, "Business Country" ); ret_map.insert( Qtopia::BusinessPager, "Business Pager" ); ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" ); ret_map.insert( Qtopia::Office, "Office" ); ret_map.insert( Qtopia::Profession, "Profession" ); ret_map.insert( Qtopia::Assistant, "Assistant" ); ret_map.insert( Qtopia::Manager, "Manager" ); // home ret_map.insert( Qtopia::HomeStreet, "Home Street" ); ret_map.insert( Qtopia::HomeCity, "Home City" ); ret_map.insert( Qtopia::HomeState, "Home State" ); ret_map.insert( Qtopia::HomeZip, "Home Zip" ); ret_map.insert( Qtopia::HomeCountry, "Home Country" ); ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" ); //personal ret_map.insert( Qtopia::Spouse, "Spouse" ); - ret_map.insert( Qtopia::Gender, "Gender" ); + ret_map.insert( Qtopia::Gender, "Gender" ); ret_map.insert( Qtopia::Birthday, "Birthday" ); ret_map.insert( Qtopia::Anniversary, "Anniversary" ); ret_map.insert( Qtopia::Nickname, "Nickname" ); ret_map.insert( Qtopia::Children, "Children" ); // other ret_map.insert( Qtopia::Notes, "Notes" ); ret_map.insert( Qtopia::Groups, "Groups" ); return ret_map; } QMap<QString, int> OContactFields::trFieldsToId() { QMap<int, QString> idtostr = idToTrFields(); QMap<QString, int> ret_map; QMap<int, QString>::Iterator it; for( it = idtostr.begin(); it != idtostr.end(); ++it ) ret_map.insert( *it, it.key() ); return ret_map; } +/* ======================================================================= */ + QMap<QString, int> OContactFields::untrFieldsToId() { QMap<int, QString> idtostr = idToUntrFields(); QMap<QString, int> ret_map; QMap<int, QString>::Iterator it; for( it = idtostr.begin(); it != idtostr.end(); ++it ) ret_map.insert( *it, it.key() ); return ret_map; } OContactFields::OContactFields(): fieldOrder( DEFAULT_FIELD_ORDER ), changedFieldOrder( false ) { // Get the global field order from the config file and // use it as a start pattern Config cfg ( "AddressBook" ); cfg.setGroup( "ContactFieldOrder" ); globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER ); } OContactFields::~OContactFields(){ // We will store the fieldorder into the config file // to reuse it for the future.. if ( changedFieldOrder ){ Config cfg ( "AddressBook" ); cfg.setGroup( "ContactFieldOrder" ); cfg.writeEntry( "General", globalFieldOrder ); } } void OContactFields::saveToRecord( OContact &cnt ){ qDebug("ocontactfields saveToRecord: >%s<",fieldOrder.latin1()); // Store fieldorder into this contact. cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder ); globalFieldOrder = fieldOrder; changedFieldOrder = true; } void OContactFields::loadFromRecord( const OContact &cnt ){ qDebug("ocontactfields loadFromRecord"); qDebug("loading >%s<",cnt.fullName().latin1()); // Get fieldorder for this contact. If none is defined, // we will use the global one from the config file.. fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME ); qDebug("fieldOrder from contact>%s<",fieldOrder.latin1()); if (fieldOrder.isEmpty()){ fieldOrder = globalFieldOrder; } qDebug("effective fieldOrder in loadFromRecord >%s<",fieldOrder.latin1()); } void OContactFields::setFieldOrder( int num, int index ){ qDebug("qcontactfields setfieldorder pos %i -> %i",num,index); fieldOrder[num] = QString::number( index, 16 )[0]; // We will store this new fieldorder globally to // remember it for contacts which have none globalFieldOrder = fieldOrder; changedFieldOrder = true; qDebug("fieldOrder >%s<",fieldOrder.latin1()); } int OContactFields::getFieldOrder( int num, int defIndex ){ qDebug("ocontactfields getFieldOrder"); qDebug("fieldOrder >%s<",fieldOrder.latin1()); // Get index of combo as char.. QChar poschar = fieldOrder[num]; bool ok; int ret = 0; // Convert char to number.. if ( !( poschar == QChar::null ) ) ret = QString( poschar ).toInt(&ok, 16); else ok = false; // Return default value if index for // num was not set or if anything else happened.. if ( !ok ) ret = defIndex; qDebug("returning >%i<",ret); return ret; } diff --git a/libopie/pim/ocontactfields.h b/libopie/pim/ocontactfields.h index 9f6171b..f105de7 100644 --- a/libopie/pim/ocontactfields.h +++ b/libopie/pim/ocontactfields.h @@ -1,60 +1,67 @@ #ifndef OPIE_CONTACTS_FIELDS #define OPIE_CONTACTS_FIELDS class QStringList; #include <qmap.h> #include <qstring.h> #include <opie/ocontact.h> #define CONTACT_FIELD_ORDER_NAME "opie-contactfield-order" #define DEFAULT_FIELD_ORDER "__________" class OContactFields{ public: OContactFields(); ~OContactFields(); /** Set the index for combo boxes. * Sets the <b>index</b> of combo <b>num</b>. * @param num selects the number of the combo * @param index sets the index in the combo */ void setFieldOrder( int num, int index ); /** Get the index for combo boxes. * Returns the index of combo <b>num</b> or defindex * if none was defined.. * @param num Selects the number of the combo * @param defIndex will be returned if none was defined (either * globally in the config file, nor by the contact which was used * by loadFromRecord() ) */ int getFieldOrder( int num, int defIndex); /** Store fieldorder to contact. */ void saveToRecord( OContact& ); /** Get Fieldorder from contact. */ void loadFromRecord( const OContact& ); private: QString fieldOrder; QString globalFieldOrder; bool changedFieldOrder; public: + static QStringList personalfields( bool sorted = true, bool translated = false ); + static QStringList phonefields( bool sorted = true, bool translated = false ); + static QStringList detailsfields( bool sorted = true, bool translated = false ); + static QStringList fields( bool sorted = true, bool translated = false ); + + static QStringList trpersonalfields( bool sorted = true ); + static QStringList untrpersonalfields( bool sorted = true ); static QStringList trphonefields( bool sorted = true ); static QStringList untrphonefields( bool sorted = true ); static QStringList trdetailsfields( bool sorted = true ); static QStringList untrdetailsfields( bool sorted = true ); static QStringList trfields( bool sorted = true ); static QStringList untrfields( bool sorted = true ); static QMap<int, QString> idToTrFields(); static QMap<QString, int> trFieldsToId(); static QMap<int, QString> idToUntrFields(); static QMap<QString, int> untrFieldsToId(); }; #endif diff --git a/libopie/pim/opimnotifymanager.cpp b/libopie/pim/opimnotifymanager.cpp index 06b5987..53ad4c3 100644 --- a/libopie/pim/opimnotifymanager.cpp +++ b/libopie/pim/opimnotifymanager.cpp @@ -1,74 +1,146 @@ #include "opimnotifymanager.h" +#include "oconversion.h" + +#include <qstringlist.h> + OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al) : m_rem( rem ), m_al( al ) {} OPimNotifyManager::~OPimNotifyManager() { } /* use static_cast and type instead of dynamic... */ void OPimNotifyManager::add( const OPimNotify& noti) { if ( noti.type() == QString::fromLatin1("OPimReminder") ) { const OPimReminder& rem = static_cast<const OPimReminder&>(noti); m_rem.append( rem ); }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); m_al.append( al ); } } void OPimNotifyManager::remove( const OPimNotify& noti) { if ( noti.type() == QString::fromLatin1("OPimReminder") ) { const OPimReminder& rem = static_cast<const OPimReminder&>(noti); m_rem.remove( rem ); }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); m_al.remove( al ); } } void OPimNotifyManager::replace( const OPimNotify& noti) { if ( noti.type() == QString::fromLatin1("OPimReminder") ) { const OPimReminder& rem = static_cast<const OPimReminder&>(noti); m_rem.remove( rem ); m_rem.append( rem ); }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); m_al.remove( al ); m_al.append( al ); } } OPimNotifyManager::Reminders OPimNotifyManager::reminders()const { return m_rem; } OPimNotifyManager::Alarms OPimNotifyManager::alarms()const { return m_al; } void OPimNotifyManager::setAlarms( const Alarms& al) { m_al = al; } void OPimNotifyManager::setReminders( const Reminders& rem) { m_rem = rem; } /* FIXME!!! */ /** * The idea is to check if the provider for our service * is online * if it is we will use QCOP * if not the Factory to get the backend... * Qtopia1.6 services would be kewl to have here.... */ void OPimNotifyManager::registerNotify( const OPimNotify& ) { } /* FIXME!!! */ /** * same as above... * Also implement Url model * have a MainWindow.... */ void OPimNotifyManager::deregister( const OPimNotify& ) { } + bool OPimNotifyManager::isEmpty()const { qWarning("is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() ); if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; else return false; } + +// Taken from otodoaccessxml.. +QString OPimNotifyManager::alarmsToString() const +{ + QString str; + + OPimNotifyManager::Alarms alarms = m_al; + if ( !alarms.isEmpty() ) { + QStringList als; + OPimNotifyManager::Alarms::Iterator it = alarms.begin(); + for ( ; it != alarms.end(); ++it ) { + /* only if time is valid */ + if ( (*it).dateTime().isValid() ) { + als << OConversion::dateTimeToString( (*it).dateTime() ) + + ":" + QString::number( (*it).duration() ) + + ":" + QString::number( (*it).sound() ) + + ":"; + } + } + // now write the list + qWarning("als: %s", als.join("____________").latin1() ); + str = als.join(";"); + } + + return str; +} +QString OPimNotifyManager::remindersToString() const +{ + QString str; + + OPimNotifyManager::Reminders reminders = m_rem; + if (!reminders.isEmpty() ) { + OPimNotifyManager::Reminders::Iterator it = reminders.begin(); + QStringList records; + for ( ; it != reminders.end(); ++it ) { + records << QString::number( (*it).recordUid() ); + } + str = records.join(";"); + } + + return str; +} + +void OPimNotifyManager::alarmsFromString( const QString& str ) +{ + QStringList als = QStringList::split(";", str ); + for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { + QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty + qWarning("alarm: %s", alarm.join("___").latin1() ); + qWarning("alarm[0]: %s %s", alarm[0].latin1(), + OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); + OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), + alarm[1].toInt() ); + add( al ); + } +} + +void OPimNotifyManager::remindersFromString( const QString& str ) +{ + + QStringList rems = QStringList::split(";", str ); + for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { + OPimReminder rem( (*it).toInt() ); + add( rem ); + } + +} diff --git a/libopie/pim/opimnotifymanager.h b/libopie/pim/opimnotifymanager.h index 0ac30a1..48410e7 100644 --- a/libopie/pim/opimnotifymanager.h +++ b/libopie/pim/opimnotifymanager.h @@ -1,54 +1,76 @@ #ifndef OPIE_PIM_NOTIFY_MANAGER_H #define OPIE_PIM_NOTIFY_MANAGER_H #include <qvaluelist.h> #include <opie/opimnotify.h> /** * The notify manager keeps track of the Notifiers.... */ class OPimNotifyManager { public: typedef QValueList<OPimReminder> Reminders; typedef QValueList<OPimAlarm> Alarms; OPimNotifyManager( const Reminders& rems = Reminders(), const Alarms& alarms = Alarms() ); ~OPimNotifyManager(); /* we will cast it for you ;) */ void add( const OPimNotify& ); void remove( const OPimNotify& ); /* replaces all with this one! */ void replace( const OPimNotify& ); Reminders reminders()const; Alarms alarms()const; void setAlarms( const Alarms& ); void setReminders( const Reminders& ); /* register is a Ansi C keyword... */ /** * This function will register the Notify to the Alarm Server * or datebook depending on the type of the notify */ void registerNotify( const OPimNotify& ); /** * this will do the opposite.. */ void deregister( const OPimNotify& ); - bool isEmpty()const; + /** + * Return all alarms as string + */ + QString alarmsToString() const; + /** + * Return all notifiers as string + */ + QString remindersToString() const; + + /** + * Convert string to alarms + * @param str String created by alarmsToString() + */ + void alarmsFromString( const QString& str ); + + /** + * Convert string to reminders + * @param str String created by remindersToString() + */ + void remindersFromString( const QString& str ); + + + private: Reminders m_rem; Alarms m_al; class Private; Private *d; }; #endif diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index d255c66..ebd03bb 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp @@ -1,651 +1,667 @@ #include <qdatetime.h> #include <qpe/global.h> #include <opie2/osqldriver.h> #include <opie2/osqlresult.h> #include <opie2/osqlmanager.h> #include <opie2/osqlquery.h> #include "otodoaccesssql.h" +#include "opimstate.h" +#include "opimnotifymanager.h" +#include "orecur.h" /* * first some query * CREATE query * LOAD query * INSERT * REMOVE * CLEAR */ namespace { /** * CreateQuery for the Todolist Table */ class CreateQuery : public OSQLQuery { public: CreateQuery(); ~CreateQuery(); QString query()const; }; /** * LoadQuery * this one queries for all uids */ class LoadQuery : public OSQLQuery { public: LoadQuery(); ~LoadQuery(); QString query()const; }; /** * inserts/adds a OTodo to the table */ class InsertQuery : public OSQLQuery { public: InsertQuery(const OTodo& ); ~InsertQuery(); QString query()const; private: OTodo m_todo; }; /** * removes one from the table */ class RemoveQuery : public OSQLQuery { public: RemoveQuery(int uid ); ~RemoveQuery(); QString query()const; private: int m_uid; }; /** * Clears (delete) a Table */ class ClearQuery : public OSQLQuery { public: ClearQuery(); ~ClearQuery(); QString query()const; }; /** * a find query */ class FindQuery : public OSQLQuery { public: FindQuery(int uid); FindQuery(const QArray<int>& ); ~FindQuery(); QString query()const; private: QString single()const; QString multi()const; QArray<int> m_uids; int m_uid; }; /** * overdue query */ class OverDueQuery : public OSQLQuery { public: OverDueQuery(); ~OverDueQuery(); QString query()const; }; class EffQuery : public OSQLQuery { public: EffQuery( const QDate&, const QDate&, bool inc ); ~EffQuery(); QString query()const; private: QString with()const; QString out()const; QDate m_start; QDate m_end; bool m_inc :1; }; CreateQuery::CreateQuery() : OSQLQuery() {} CreateQuery::~CreateQuery() {} QString CreateQuery::query()const { QString qu; qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; qu += "description, summary, priority, DueDate, progress , state, "; - qu += "Recurrence, notifiers, maintainer, startdate, completeddate)"; + qu += "Recurrence, reminders, alarms, maintainer, startdate, completeddate);"; + qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; return qu; } LoadQuery::LoadQuery() : OSQLQuery() {} LoadQuery::~LoadQuery() {} QString LoadQuery::query()const { QString qu; // We do not need "distinct" here. The primary key is always unique.. //qu += "select distinct uid from todolist"; qu += "select uid from todolist"; return qu; } InsertQuery::InsertQuery( const OTodo& todo ) : OSQLQuery(), m_todo( todo ) { } InsertQuery::~InsertQuery() { } /* * converts from a OTodo to a query * we leave out X-Ref + Alarms */ QString InsertQuery::query()const{ int year, month, day; year = month = day = 0; if (m_todo.hasDueDate() ) { QDate date = m_todo.dueDate(); year = date.year(); month = date.month(); day = date.day(); } int sYear = 0, sMonth = 0, sDay = 0; if( m_todo.hasStartDate() ){ QDate sDate = m_todo.startDate(); sYear = sDate.year(); sMonth= sDate.month(); sDay = sDate.day(); } int eYear = 0, eMonth = 0, eDay = 0; if( m_todo.hasCompletedDate() ){ QDate eDate = m_todo.completedDate(); eYear = eDate.year(); eMonth= eDate.month(); eDay = eDate.day(); } QString qu; qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + "," + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," + QString::number( m_todo.isCompleted() ) + "," + "'" + m_todo.description() + "'" + "," + "'" + m_todo.summary() + "'" + "," + QString::number(m_todo.priority() ) + "," + "'" + QString::number(year) + "-" + QString::number(month) + "-" + QString::number( day ) + "'" + "," + QString::number( m_todo.progress() ) + "," - + "''" + "," // state (conversion needed) -// + QString::number( m_todo.state() ) + "," - + "''" + "," // Recurrence (conversion needed) - + "''" + "," // Notifiers (conversion needed) - + "''" + "," // Maintainers (conversion needed) + + QString::number( m_todo.state().state() ) + "," + + "'" + m_todo.recurrence().toString() + "'"+ ","; + + if ( m_todo.hasNotifiers() ) { + OPimNotifyManager manager = m_todo.notifiers(); + qu += "'" + manager.remindersToString() + "'" + "," + + "'" + manager.alarmsToString() + "'" + ","; + } + else{ + qu += QString( "''" ) + "," + + "''" + ","; + } + + qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) + "'" + QString::number(sYear) + "-" - + QString::number(sMonth) - + "-" + QString::number(sDay) + "'" + "," + + QString::number(sMonth) + + "-" + QString::number(sDay) + "'" + "," + "'" + QString::number(eYear) + "-" + QString::number(eMonth) + "-"+QString::number(eDay) + "'" + ")"; qWarning("add %s", qu.latin1() ); return qu; } RemoveQuery::RemoveQuery(int uid ) : OSQLQuery(), m_uid( uid ) {} RemoveQuery::~RemoveQuery() {} QString RemoveQuery::query()const { QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); return qu; } ClearQuery::ClearQuery() : OSQLQuery() {} ClearQuery::~ClearQuery() {} QString ClearQuery::query()const { QString qu = "drop table todolist"; return qu; } FindQuery::FindQuery(int uid) : OSQLQuery(), m_uid(uid ) { } FindQuery::FindQuery(const QArray<int>& ints) : OSQLQuery(), m_uids(ints){ } FindQuery::~FindQuery() { } QString FindQuery::query()const{ if (m_uids.count() == 0 ) return single(); else return multi(); } QString FindQuery::single()const{ QString qu = "select * from todolist where uid = " + QString::number(m_uid); return qu; } QString FindQuery::multi()const { QString qu = "select * from todolist where "; for (uint i = 0; i < m_uids.count(); i++ ) { qu += " UID = " + QString::number( m_uids[i] ) + " OR"; } qu.remove( qu.length()-2, 2 ); return qu; } OverDueQuery::OverDueQuery(): OSQLQuery() {} OverDueQuery::~OverDueQuery() {} QString OverDueQuery::query()const { QDate date = QDate::currentDate(); QString str; str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); return str; } EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} EffQuery::~EffQuery() {} QString EffQuery::query()const { return m_inc ? with() : out(); } QString EffQuery::with()const { QString str; str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); return str; } QString EffQuery::out()const { QString str; str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); return str; } }; OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) : OTodoAccessBackend(), m_dict(15), m_dirty(true) { QString fi = file; if ( fi.isEmpty() ) fi = Global::applicationFileName( "todolist", "todolist.db" ); OSQLManager man; m_driver = man.standard(); m_driver->setUrl(fi); // fillDict(); } OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ } bool OTodoAccessBackendSQL::load(){ if (!m_driver->open() ) return false; CreateQuery creat; OSQLResult res = m_driver->query(&creat ); m_dirty = true; return true; } bool OTodoAccessBackendSQL::reload(){ return load(); } bool OTodoAccessBackendSQL::save(){ return m_driver->close(); } QArray<int> OTodoAccessBackendSQL::allRecords()const { if (m_dirty ) update(); return m_uids; } QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int, const QDateTime& ){ QArray<int> ints(0); return ints; } OTodo OTodoAccessBackendSQL::find(int uid ) const{ FindQuery query( uid ); return todo( m_driver->query(&query) ); } OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, uint cur, Frontend::CacheDirection dir ) const{ uint CACHE = readAhead(); qWarning("searching for %d", uid ); QArray<int> search( CACHE ); uint size =0; OTodo to; // we try to cache CACHE items switch( dir ) { /* forward */ case 0: // FIXME: Not a good style to use magic numbers here (eilers) for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { qWarning("size %d %d", size, ints[i] ); search[size] = ints[i]; size++; } break; /* reverse */ case 1: // FIXME: Not a good style to use magic numbers here (eilers) for (uint i = cur; i != 0 && size < CACHE; i-- ) { search[size] = ints[i]; size++; } break; } search.resize( size ); FindQuery query( search ); OSQLResult res = m_driver->query( &query ); if ( res.state() != OSQLResult::Success ) return to; return todo( res ); } void OTodoAccessBackendSQL::clear() { ClearQuery cle; OSQLResult res = m_driver->query( &cle ); CreateQuery qu; res = m_driver->query(&qu); } bool OTodoAccessBackendSQL::add( const OTodo& t) { InsertQuery ins( t ); OSQLResult res = m_driver->query( &ins ); if ( res.state() == OSQLResult::Failure ) return false; int c = m_uids.count(); m_uids.resize( c+1 ); m_uids[c] = t.uid(); return true; } bool OTodoAccessBackendSQL::remove( int uid ) { RemoveQuery rem( uid ); OSQLResult res = m_driver->query(&rem ); if ( res.state() == OSQLResult::Failure ) return false; m_dirty = true; return true; } /* * FIXME better set query * but we need the cache for that * now we remove */ bool OTodoAccessBackendSQL::replace( const OTodo& t) { remove( t.uid() ); bool b= add(t); m_dirty = false; // we changed some stuff but the UID stayed the same return b; } QArray<int> OTodoAccessBackendSQL::overDue() { OverDueQuery qu; return uids( m_driver->query(&qu ) ); } QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, const QDate& t, bool u) { EffQuery ef(s, t, u ); return uids (m_driver->query(&ef) ); } /* * */ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, int sortFilter, int cat ) { qWarning("sorted %d, %d", asc, sortOrder ); QString query; query = "select uid from todolist WHERE "; /* * Sort Filter stuff * not that straight forward * FIXME: Replace magic numbers * */ /* Category */ if ( sortFilter & 1 ) { QString str; if (cat != 0 ) str = QString::number( cat ); query += " categories like '%" +str+"%' AND"; } /* Show only overdue */ if ( sortFilter & 2 ) { QDate date = QDate::currentDate(); QString due; QString base; base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); query += " " + base + " AND"; } /* not show completed */ if ( sortFilter & 4 ) { query += " completed = 0 AND"; }else{ query += " ( completed = 1 OR completed = 0) AND"; } /* srtip the end */ query = query.remove( query.length()-3, 3 ); /* * sort order stuff * quite straight forward */ query += "ORDER BY "; switch( sortOrder ) { /* completed */ case 0: query += "completed"; break; case 1: query += "priority"; break; case 2: query += "summary"; break; case 3: query += "DueDate"; break; } if ( !asc ) { qWarning("not ascending!"); query += " DESC"; } qWarning( query ); OSQLRawQuery raw(query ); return uids( m_driver->query(&raw) ); } bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ if ( str == "0-0-0" ) return false; else{ int day, year, month; QStringList list = QStringList::split("-", str ); year = list[0].toInt(); month = list[1].toInt(); day = list[2].toInt(); da.setYMD( year, month, day ); return true; } } OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ if ( res.state() == OSQLResult::Failure ) { OTodo to; return to; } OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it = list.begin(); qWarning("todo1"); OTodo to = todo( (*it) ); cache( to ); ++it; for ( ; it != list.end(); ++it ) { qWarning("caching"); cache( todo( (*it) ) ); } return to; } OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { qWarning("todo"); bool hasDueDate = false; QDate dueDate = QDate::currentDate(); hasDueDate = date( dueDate, item.data("DueDate") ); QStringList cats = QStringList::split(";", item.data("categories") ); OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), cats, item.data("summary"), item.data("description"), item.data("progress").toUShort(), hasDueDate, dueDate, item.data("uid").toInt() ); bool isOk; int prioInt = QString( item.data("priority") ).toInt( &isOk ); if ( isOk ) to.setPriority( prioInt ); bool hasStartDate = false; QDate startDate = QDate::currentDate(); hasStartDate = date( startDate, item.data("startdate") ); bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); hasCompletedDate = date( completedDate, item.data("completeddate") ); if ( hasStartDate ) to.setStartDate( startDate ); if ( hasCompletedDate ) to.setCompletedDate( completedDate ); + + OPimNotifyManager& manager = to.notifiers(); + manager.alarmsFromString( item.data("alarms") ); + manager.remindersFromString( item.data("reminders") ); + + OPimState pimState; + pimState.setState( QString( item.data("state") ).toInt() ); + to.setState( pimState ); + + // Recurrence not supported yet + // to.setRecurrence( return to; } OTodo OTodoAccessBackendSQL::todo( int uid )const { FindQuery find( uid ); return todo( m_driver->query(&find) ); } /* * update the dict */ void OTodoAccessBackendSQL::fillDict() { /* initialize dict */ /* * UPDATE dict if you change anything!!! * FIXME: Isn't this dict obsolete ? (eilers) */ m_dict.setAutoDelete( TRUE ); m_dict.insert("Categories" , new int(OTodo::Category) ); m_dict.insert("Uid" , new int(OTodo::Uid) ); m_dict.insert("HasDate" , new int(OTodo::HasDate) ); m_dict.insert("Completed" , new int(OTodo::Completed) ); m_dict.insert("Description" , new int(OTodo::Description) ); m_dict.insert("Summary" , new int(OTodo::Summary) ); m_dict.insert("Priority" , new int(OTodo::Priority) ); m_dict.insert("DateDay" , new int(OTodo::DateDay) ); m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); m_dict.insert("DateYear" , new int(OTodo::DateYear) ); m_dict.insert("Progress" , new int(OTodo::Progress) ); m_dict.insert("Completed", new int(OTodo::Completed) ); // Why twice ? (eilers) m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); // m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); // old stuff (eilers) // m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); // old stuff (eilers) } /* * need to be const so let's fool the * compiler :( */ void OTodoAccessBackendSQL::update()const { ((OTodoAccessBackendSQL*)this)->m_dirty = false; LoadQuery lo; OSQLResult res = m_driver->query(&lo); if ( res.state() != OSQLResult::Success ) return; ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); } QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it; QArray<int> ints(list.count() ); qWarning(" count = %d", list.count() ); int i = 0; for (it = list.begin(); it != list.end(); ++it ) { ints[i] = (*it).data("uid").toInt(); i++; } return ints; } QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const { #warning OTodoAccessBackendSQL::matchRegexp() not implemented !! #if 0 Copied from xml-backend by not adapted to sql (eilers) QArray<int> m_currentQuery( m_events.count() ); uint arraycounter = 0; QMap<int, OTodo>::ConstIterator it; for (it = m_events.begin(); it != m_events.end(); ++it ) { if ( it.data().match( r ) ) m_currentQuery[arraycounter++] = it.data().uid(); } // Shrink to fit.. m_currentQuery.resize(arraycounter); return m_currentQuery; #endif QArray<int> empty; return empty; } QBitArray OTodoAccessBackendSQL::supports()const { - QBitArray ar( OTodo::CompletedDate + 1 ); - ar.fill( true ); - ar[OTodo::CrossReference] = false; - ar[OTodo::State ] = false; - ar[OTodo::Reminders] = false; - ar[OTodo::Notifiers] = false; - ar[OTodo::Maintainer] = false; - - return ar; + return sup(); } -QBitArray OTodoAccessBackendSQL::sup() { +QBitArray OTodoAccessBackendSQL::sup() const{ QBitArray ar( OTodo::CompletedDate + 1 ); ar.fill( true ); ar[OTodo::CrossReference] = false; ar[OTodo::State ] = false; ar[OTodo::Reminders] = false; ar[OTodo::Notifiers] = false; ar[OTodo::Maintainer] = false; return ar; } void OTodoAccessBackendSQL::removeAllCompleted(){ #warning OTodoAccessBackendSQL::removeAllCompleted() not implemented !! } diff --git a/libopie/pim/otodoaccesssql.h b/libopie/pim/otodoaccesssql.h index 77d8b77..1c55567 100644 --- a/libopie/pim/otodoaccesssql.h +++ b/libopie/pim/otodoaccesssql.h @@ -1,56 +1,56 @@ #ifndef OPIE_PIM_ACCESS_SQL_H #define OPIE_PIM_ACCESS_SQL_H #include <qasciidict.h> #include "otodoaccessbackend.h" class OSQLDriver; class OSQLResult; class OSQLResultItem; class OTodoAccessBackendSQL : public OTodoAccessBackend { public: OTodoAccessBackendSQL( const QString& file ); ~OTodoAccessBackendSQL(); bool load(); bool reload(); bool save(); QArray<int> allRecords()const; QArray<int> queryByExample( const OTodo& t, int settings, const QDateTime& d = QDateTime() ); OTodo find(int uid)const; OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; void clear(); bool add( const OTodo& t ); bool remove( int uid ); bool replace( const OTodo& t ); QArray<int> overDue(); QArray<int> effectiveToDos( const QDate& start, const QDate& end, bool includeNoDates ); QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); QBitArray supports()const; QArray<int> matchRegexp( const QRegExp &r ) const; void removeAllCompleted(); private: void update()const; void fillDict(); inline bool date( QDate& date, const QString& )const; inline OTodo todo( const OSQLResult& )const; inline OTodo todo( OSQLResultItem& )const; inline QArray<int> uids( const OSQLResult& )const; OTodo todo( int uid )const; - QBitArray sup(); + QBitArray sup() const; QAsciiDict<int> m_dict; OSQLDriver* m_driver; QArray<int> m_uids; bool m_dirty : 1; }; #endif diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp index f688735..4a5cb33 100644 --- a/libopie/pim/otodoaccessxml.cpp +++ b/libopie/pim/otodoaccessxml.cpp @@ -59,818 +59,818 @@ char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) if (hsearch >= haystack + hLen) return (0); } while (haystackChar != needleChar); } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); hsearch--; } return ((char *)hsearch); } } OTodoAccessXML::OTodoAccessXML( const QString& appName, const QString& fileName ) : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) { if (!fileName.isEmpty() ) m_file = fileName; else m_file = Global::applicationFileName( "todolist", "todolist.xml" ); } OTodoAccessXML::~OTodoAccessXML() { } bool OTodoAccessXML::load() { rec = 0; m_opened = true; m_changed = false; /* initialize dict */ /* * UPDATE dict if you change anything!!! */ QAsciiDict<int> dict(26); dict.setAutoDelete( TRUE ); dict.insert("Categories" , new int(OTodo::Category) ); dict.insert("Uid" , new int(OTodo::Uid) ); dict.insert("HasDate" , new int(OTodo::HasDate) ); dict.insert("Completed" , new int(OTodo::Completed) ); dict.insert("Description" , new int(OTodo::Description) ); dict.insert("Summary" , new int(OTodo::Summary) ); dict.insert("Priority" , new int(OTodo::Priority) ); dict.insert("DateDay" , new int(OTodo::DateDay) ); dict.insert("DateMonth" , new int(OTodo::DateMonth) ); dict.insert("DateYear" , new int(OTodo::DateYear) ); dict.insert("Progress" , new int(OTodo::Progress) ); dict.insert("CompletedDate", new int(OTodo::CompletedDate) ); dict.insert("StartDate", new int(OTodo::StartDate) ); dict.insert("CrossReference", new int(OTodo::CrossReference) ); dict.insert("State", new int(OTodo::State) ); dict.insert("Alarms", new int(OTodo::Alarms) ); dict.insert("Reminders", new int(OTodo::Reminders) ); dict.insert("Notifiers", new int(OTodo::Notifiers) ); dict.insert("Maintainer", new int(OTodo::Maintainer) ); dict.insert("rtype", new int(FRType) ); dict.insert("rweekdays", new int(FRWeekdays) ); dict.insert("rposition", new int(FRPosition) ); dict.insert("rfreq", new int(FRFreq) ); dict.insert("start", new int(FRStart) ); dict.insert("rhasenddate", new int(FRHasEndDate) ); dict.insert("enddt", new int(FREndDate) ); // here the custom XML parser from TT it's GPL // but we want to push OpiePIM... to TT..... // mmap part from zecke :) int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); struct stat attribut; if ( fd < 0 ) return false; if ( fstat(fd, &attribut ) == -1 ) { ::close( fd ); return false; } void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); if ( map_addr == ( (caddr_t)-1) ) { ::close(fd ); return false; } /* advise the kernel who we want to read it */ ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); /* we do not the file any more */ ::close( fd ); char* dt = (char*)map_addr; int len = attribut.st_size; int i = 0; char *point; const char* collectionString = "<Task "; int strLen = strlen(collectionString); while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) { i = point -dt; i+= strLen; qWarning("Found a start at %d %d", i, (point-dt) ); OTodo ev; m_year = m_month = m_day = 0; while ( TRUE ) { while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) ++i; if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) break; // we have another attribute, read it. int j = i; while ( j < len && dt[j] != '=' ) ++j; QCString attr( dt+i, j-i+1); i = ++j; // skip = // find the start of quotes while ( i < len && dt[i] != '"' ) ++i; j = ++i; bool haveUtf = FALSE; bool haveEnt = FALSE; while ( j < len && dt[j] != '"' ) { if ( ((unsigned char)dt[j]) > 0x7f ) haveUtf = TRUE; if ( dt[j] == '&' ) haveEnt = TRUE; ++j; } if ( i == j ) { // empty value i = j + 1; continue; } QCString value( dt+i, j-i+1 ); i = j + 1; QString str = (haveUtf ? QString::fromUtf8( value ) : QString::fromLatin1( value ) ); if ( haveEnt ) str = Qtopia::plainString( str ); /* * add key + value */ todo( &dict, ev, attr, str ); } /* * now add it */ qWarning("End at %d", i ); if (m_events.contains( ev.uid() ) || ev.uid() == 0) { ev.setUid( 1 ); m_changed = true; } if ( ev.hasDueDate() ) { ev.setDueDate( QDate(m_year, m_month, m_day) ); } if ( rec && rec->doesRecur() ) { OTimeZone utc = OTimeZone::utc(); ORecur recu( *rec ); // call copy c'tor recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() ); recu.setStart( ev.dueDate() ); ev.setRecurrence( recu ); } m_events.insert(ev.uid(), ev ); m_year = m_month = m_day = -1; delete rec; rec = 0; } munmap(map_addr, attribut.st_size ); qWarning("counts %d records loaded!", m_events.count() ); return true; } bool OTodoAccessXML::reload() { m_events.clear(); return load(); } bool OTodoAccessXML::save() { // qWarning("saving"); if (!m_opened || !m_changed ) { // qWarning("not saving"); return true; } QString strNewFile = m_file + ".new"; QFile f( strNewFile ); if (!f.open( IO_WriteOnly|IO_Raw ) ) return false; int written; QString out; out = "<!DOCTYPE Tasks>\n<Tasks>\n"; // for all todos QMap<int, OTodo>::Iterator it; for (it = m_events.begin(); it != m_events.end(); ++it ) { out+= "<Task " + toString( (*it) ) + " />\n"; QCString cstr = out.utf8(); written = f.writeBlock( cstr.data(), cstr.length() ); /* less written then we wanted */ if ( written != (int)cstr.length() ) { f.close(); QFile::remove( strNewFile ); return false; } out = QString::null; } out += "</Tasks>"; QCString cstr = out.utf8(); written = f.writeBlock( cstr.data(), cstr.length() ); if ( written != (int)cstr.length() ) { f.close(); QFile::remove( strNewFile ); return false; } /* flush before renaming */ f.close(); if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { // qWarning("error renaming"); QFile::remove( strNewFile ); } m_changed = false; return true; } QArray<int> OTodoAccessXML::allRecords()const { QArray<int> ids( m_events.count() ); QMap<int, OTodo>::ConstIterator it; int i = 0; for ( it = m_events.begin(); it != m_events.end(); ++it ) { ids[i] = it.key(); i++; } return ids; } QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int, const QDateTime& ) { QArray<int> ids(0); return ids; } OTodo OTodoAccessXML::find( int uid )const { OTodo todo; todo.setUid( 0 ); // isEmpty() QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); if ( it != m_events.end() ) todo = it.data(); return todo; } void OTodoAccessXML::clear() { if (m_opened ) m_changed = true; m_events.clear(); } bool OTodoAccessXML::add( const OTodo& todo ) { // qWarning("add"); m_changed = true; m_events.insert( todo.uid(), todo ); return true; } bool OTodoAccessXML::remove( int uid ) { m_changed = true; m_events.remove( uid ); return true; } bool OTodoAccessXML::replace( const OTodo& todo) { m_changed = true; m_events.replace( todo.uid(), todo ); return true; } QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, const QDate& end, bool includeNoDates ) { QArray<int> ids( m_events.count() ); QMap<int, OTodo>::Iterator it; int i = 0; for ( it = m_events.begin(); it != m_events.end(); ++it ) { if ( !it.data().hasDueDate() ) { if ( includeNoDates ) { ids[i] = it.key(); i++; } }else if ( it.data().dueDate() >= start && it.data().dueDate() <= end ) { ids[i] = it.key(); i++; } } ids.resize( i ); return ids; } QArray<int> OTodoAccessXML::overDue() { QArray<int> ids( m_events.count() ); int i = 0; QMap<int, OTodo>::Iterator it; for ( it = m_events.begin(); it != m_events.end(); ++it ) { if ( it.data().isOverdue() ) { ids[i] = it.key(); i++; } } ids.resize( i ); return ids; } /* private */ void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, const QCString& attr, const QString& val) { // qWarning("parse to do from XMLElement" ); int *find=0; find = (*dict)[ attr.data() ]; if (!find ) { // qWarning("Unknown option" + it.key() ); ev.setCustomField( attr, val ); return; } switch( *find ) { case OTodo::Uid: ev.setUid( val.toInt() ); break; case OTodo::Category: ev.setCategories( ev.idsFromString( val ) ); break; case OTodo::HasDate: ev.setHasDueDate( val.toInt() ); break; case OTodo::Completed: ev.setCompleted( val.toInt() ); break; case OTodo::Description: ev.setDescription( val ); break; case OTodo::Summary: ev.setSummary( val ); break; case OTodo::Priority: ev.setPriority( val.toInt() ); break; case OTodo::DateDay: m_day = val.toInt(); break; case OTodo::DateMonth: m_month = val.toInt(); break; case OTodo::DateYear: m_year = val.toInt(); break; case OTodo::Progress: ev.setProgress( val.toInt() ); break; case OTodo::CompletedDate: ev.setCompletedDate( OConversion::dateFromString( val ) ); break; case OTodo::StartDate: ev.setStartDate( OConversion::dateFromString( val ) ); break; case OTodo::State: ev.setState( val.toInt() ); break; case OTodo::Alarms:{ OPimNotifyManager &manager = ev.notifiers(); QStringList als = QStringList::split(";", val ); for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty qWarning("alarm: %s", alarm.join("___").latin1() ); qWarning("alarm[0]: %s %s", alarm[0].latin1(), OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() ); manager.add( al ); } } break; case OTodo::Reminders:{ OPimNotifyManager &manager = ev.notifiers(); QStringList rems = QStringList::split(";", val ); for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { OPimReminder rem( (*it).toInt() ); manager.add( rem ); } } break; case OTodo::CrossReference: { /* * A cross refernce looks like * appname,id;appname,id * we need to split it up */ QStringList refs = QStringList::split(';', val ); QStringList::Iterator strIt; for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { int pos = (*strIt).find(','); if ( pos > -1 ) ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); } break; } /* Recurrence stuff below + post processing later */ case FRType: if ( val == "Daily" ) recur()->setType( ORecur::Daily ); else if ( val == "Weekly" ) recur()->setType( ORecur::Weekly); else if ( val == "MonthlyDay" ) recur()->setType( ORecur::MonthlyDay ); else if ( val == "MonthlyDate" ) recur()->setType( ORecur::MonthlyDate ); else if ( val == "Yearly" ) recur()->setType( ORecur::Yearly ); else recur()->setType( ORecur::NoRepeat ); break; case FRWeekdays: recur()->setDays( val.toInt() ); break; case FRPosition: recur()->setPosition( val.toInt() ); break; case FRFreq: recur()->setFrequency( val.toInt() ); break; case FRHasEndDate: recur()->setHasEndDate( val.toInt() ); break; case FREndDate: { rp_end = (time_t) val.toLong(); break; } default: ev.setCustomField( attr, val ); break; } } // from PalmtopRecord... GPL ### FIXME namespace { QString customToXml(const QMap<QString, QString>& customMap ) { //qWarning(QString("writing custom %1").arg(customMap.count())); QString buf(" "); for ( QMap<QString, QString>::ConstIterator cit = customMap.begin(); cit != customMap.end(); ++cit) { // qWarning(".ITEM."); buf += cit.key(); buf += "=\""; buf += Qtopia::escapeString(cit.data()); buf += "\" "; } return buf; } } QString OTodoAccessXML::toString( const OTodo& ev )const { QString str; str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; str += "Categories=\"" + toString( ev.categories() ) + "\" "; str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; if ( ev.hasDueDate() ) { str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; } // qWarning( "Uid %d", ev.uid() ); str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; // append the extra options /* FIXME Qtopia::Record this is currently not * possible you can set custom fields * but don' iterate over the list * I may do #define private protected * for this case - cough --zecke */ /* QMap<QString, QString> extras = ev.extras(); QMap<QString, QString>::Iterator extIt; for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) str += extIt.key() + "=\"" + extIt.data() + "\" "; */ // cross refernce if ( ev.hasRecurrence() ) { str += ev.recurrence().toString(); } if ( ev.hasStartDate() ) str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" "; if ( ev.hasCompletedDate() ) str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" "; if ( ev.hasState() ) str += "State=\""+QString::number( ev.state().state() )+"\" "; /* * save reminders and notifiers! - * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER:DURATION:SOUND:.... + * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER_DURATION:SOUND:.... */ if ( ev.hasNotifiers() ) { OPimNotifyManager manager = ev.notifiers(); OPimNotifyManager::Alarms alarms = manager.alarms(); if (!alarms.isEmpty() ) { QStringList als; OPimNotifyManager::Alarms::Iterator it = alarms.begin(); for ( ; it != alarms.end(); ++it ) { /* only if time is valid */ if ( (*it).dateTime().isValid() ) { als << OConversion::dateTimeToString( (*it).dateTime() ) + ":" + QString::number( (*it).duration() ) + ":" + QString::number( (*it).sound() ) + ":"; } } // now write the list qWarning("als: %s", als.join("____________").latin1() ); str += "Alarms=\""+als.join(";") +"\" "; } /* * now the same for reminders but more easy. We just save the uid of the OEvent. */ OPimNotifyManager::Reminders reminders = manager.reminders(); if (!reminders.isEmpty() ) { OPimNotifyManager::Reminders::Iterator it = reminders.begin(); QStringList records; for ( ; it != reminders.end(); ++it ) { records << QString::number( (*it).recordUid() ); } str += "Reminders=\""+ records.join(";") +"\" "; } } str += customToXml( ev.toExtraMap() ); return str; } QString OTodoAccessXML::toString( const QArray<int>& ints ) const { return Qtopia::Record::idsToString( ints ); } /* internal class for sorting * * Inspired by todoxmlio.cpp from TT */ struct OTodoXMLContainer { OTodo todo; }; namespace { inline QString string( const OTodo& todo) { return todo.summary().isEmpty() ? todo.description().left(20 ) : todo.summary(); } inline int completed( const OTodo& todo1, const OTodo& todo2) { int ret = 0; if ( todo1.isCompleted() ) ret++; if ( todo2.isCompleted() ) ret--; return ret; } inline int priority( const OTodo& t1, const OTodo& t2) { return ( t1.priority() - t2.priority() ); } inline int description( const OTodo& t1, const OTodo& t2) { return QString::compare( string(t1), string(t2) ); } inline int deadline( const OTodo& t1, const OTodo& t2) { int ret = 0; if ( t1.hasDueDate() && t2.hasDueDate() ) ret = t2.dueDate().daysTo( t1.dueDate() ); else if ( t1.hasDueDate() ) ret = -1; else if ( t2.hasDueDate() ) ret = 1; else ret = 0; return ret; } }; /* * Returns: * 0 if item1 == item2 * * non-zero if item1 != item2 * * This function returns int rather than bool so that reimplementations * can return one of three values and use it to sort by: * * 0 if item1 == item2 * * > 0 (positive integer) if item1 > item2 * * < 0 (negative integer) if item1 < item2 * */ class OTodoXMLVector : public QVector<OTodoXMLContainer> { public: OTodoXMLVector(int size, bool asc, int sort) : QVector<OTodoXMLContainer>( size ) { setAutoDelete( true ); m_asc = asc; m_sort = sort; } /* return the summary/description */ QString string( const OTodo& todo) { return todo.summary().isEmpty() ? todo.description().left(20 ) : todo.summary(); } /** * we take the sortorder( switch on it ) * */ int compareItems( Item d1, Item d2 ) { bool seComp, sePrio, seDesc, seDeadline; seComp = sePrio = seDeadline = seDesc = false; int ret =0; OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; /* same item */ if ( con1->todo.uid() == con2->todo.uid() ) return 0; switch ( m_sort ) { /* completed */ case 0: { ret = completed( con1->todo, con2->todo ); seComp = TRUE; break; } /* priority */ case 1: { ret = priority( con1->todo, con2->todo ); sePrio = TRUE; break; } /* description */ case 2: { ret = description( con1->todo, con2->todo ); seDesc = TRUE; break; } /* deadline */ case 3: { ret = deadline( con1->todo, con2->todo ); seDeadline = TRUE; break; } default: ret = 0; break; }; /* * FIXME do better sorting if the first sort criteria * ret equals 0 start with complete and so on... */ /* twist it we're not ascending*/ if (!m_asc) ret = ret * -1; if ( ret ) return ret; // default did not gave difference let's try it other way around /* * General try if already checked if not test * and return * 1.Completed * 2.Priority * 3.Description * 4.DueDate */ if (!seComp ) { if ( (ret = completed( con1->todo, con2->todo ) ) ) { if (!m_asc ) ret *= -1; return ret; } } if (!sePrio ) { if ( (ret = priority( con1->todo, con2->todo ) ) ) { if (!m_asc ) ret *= -1; return ret; } } if (!seDesc ) { if ( (ret = description(con1->todo, con2->todo ) ) ) { if (!m_asc) ret *= -1; return ret; } } if (!seDeadline) { if ( (ret = deadline( con1->todo, con2->todo ) ) ) { if (!m_asc) ret *= -1; return ret; } } return 0; } private: bool m_asc; int m_sort; }; QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, int sortFilter, int cat ) { OTodoXMLVector vector(m_events.count(), asc,sortOrder ); QMap<int, OTodo>::Iterator it; int item = 0; bool bCat = sortFilter & 1 ? true : false; bool bOnly = sortFilter & 2 ? true : false; bool comp = sortFilter & 4 ? true : false; for ( it = m_events.begin(); it != m_events.end(); ++it ) { /* show category */ /* -1 == unfiled */ if ( bCat && cat == -1 ) { if(!(*it).categories().isEmpty() ) continue; }else if ( bCat && cat != 0) if (!(*it).categories().contains( cat ) ) { continue; } /* isOverdue but we should not show overdue - why?*/ /* if ( (*it).isOverdue() && !bOnly ) { qWarning("item is overdue but !bOnly"); continue; } */ if ( !(*it).isOverdue() && bOnly ) { continue; } if ((*it).isCompleted() && comp ) { continue; } OTodoXMLContainer* con = new OTodoXMLContainer(); con->todo = (*it); vector.insert(item, con ); item++; } vector.resize( item ); /* sort it now */ vector.sort(); /* now get the uids */ QArray<int> array( vector.count() ); for (uint i= 0; i < vector.count(); i++ ) { array[i] = ( vector.at(i) )->todo.uid(); } return array; }; void OTodoAccessXML::removeAllCompleted() { QMap<int, OTodo> events = m_events; for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { if ( (*it).isCompleted() ) events.remove( it.key() ); } m_events = events; } QBitArray OTodoAccessXML::supports()const { static QBitArray ar = sup(); return ar; } QBitArray OTodoAccessXML::sup() { QBitArray ar( OTodo::CompletedDate +1 ); ar.fill( true ); ar[OTodo::CrossReference] = false; ar[OTodo::State ] = false; ar[OTodo::Reminders] = false; ar[OTodo::Notifiers] = false; ar[OTodo::Maintainer] = false; return ar; } QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const { QArray<int> m_currentQuery( m_events.count() ); uint arraycounter = 0; QMap<int, OTodo>::ConstIterator it; for (it = m_events.begin(); it != m_events.end(); ++it ) { if ( it.data().match( r ) ) m_currentQuery[arraycounter++] = it.data().uid(); } // Shrink to fit.. m_currentQuery.resize(arraycounter); return m_currentQuery; } diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index d255c66..ebd03bb 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp @@ -1,651 +1,667 @@ #include <qdatetime.h> #include <qpe/global.h> #include <opie2/osqldriver.h> #include <opie2/osqlresult.h> #include <opie2/osqlmanager.h> #include <opie2/osqlquery.h> #include "otodoaccesssql.h" +#include "opimstate.h" +#include "opimnotifymanager.h" +#include "orecur.h" /* * first some query * CREATE query * LOAD query * INSERT * REMOVE * CLEAR */ namespace { /** * CreateQuery for the Todolist Table */ class CreateQuery : public OSQLQuery { public: CreateQuery(); ~CreateQuery(); QString query()const; }; /** * LoadQuery * this one queries for all uids */ class LoadQuery : public OSQLQuery { public: LoadQuery(); ~LoadQuery(); QString query()const; }; /** * inserts/adds a OTodo to the table */ class InsertQuery : public OSQLQuery { public: InsertQuery(const OTodo& ); ~InsertQuery(); QString query()const; private: OTodo m_todo; }; /** * removes one from the table */ class RemoveQuery : public OSQLQuery { public: RemoveQuery(int uid ); ~RemoveQuery(); QString query()const; private: int m_uid; }; /** * Clears (delete) a Table */ class ClearQuery : public OSQLQuery { public: ClearQuery(); ~ClearQuery(); QString query()const; }; /** * a find query */ class FindQuery : public OSQLQuery { public: FindQuery(int uid); FindQuery(const QArray<int>& ); ~FindQuery(); QString query()const; private: QString single()const; QString multi()const; QArray<int> m_uids; int m_uid; }; /** * overdue query */ class OverDueQuery : public OSQLQuery { public: OverDueQuery(); ~OverDueQuery(); QString query()const; }; class EffQuery : public OSQLQuery { public: EffQuery( const QDate&, const QDate&, bool inc ); ~EffQuery(); QString query()const; private: QString with()const; QString out()const; QDate m_start; QDate m_end; bool m_inc :1; }; CreateQuery::CreateQuery() : OSQLQuery() {} CreateQuery::~CreateQuery() {} QString CreateQuery::query()const { QString qu; qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; qu += "description, summary, priority, DueDate, progress , state, "; - qu += "Recurrence, notifiers, maintainer, startdate, completeddate)"; + qu += "Recurrence, reminders, alarms, maintainer, startdate, completeddate);"; + qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; return qu; } LoadQuery::LoadQuery() : OSQLQuery() {} LoadQuery::~LoadQuery() {} QString LoadQuery::query()const { QString qu; // We do not need "distinct" here. The primary key is always unique.. //qu += "select distinct uid from todolist"; qu += "select uid from todolist"; return qu; } InsertQuery::InsertQuery( const OTodo& todo ) : OSQLQuery(), m_todo( todo ) { } InsertQuery::~InsertQuery() { } /* * converts from a OTodo to a query * we leave out X-Ref + Alarms */ QString InsertQuery::query()const{ int year, month, day; year = month = day = 0; if (m_todo.hasDueDate() ) { QDate date = m_todo.dueDate(); year = date.year(); month = date.month(); day = date.day(); } int sYear = 0, sMonth = 0, sDay = 0; if( m_todo.hasStartDate() ){ QDate sDate = m_todo.startDate(); sYear = sDate.year(); sMonth= sDate.month(); sDay = sDate.day(); } int eYear = 0, eMonth = 0, eDay = 0; if( m_todo.hasCompletedDate() ){ QDate eDate = m_todo.completedDate(); eYear = eDate.year(); eMonth= eDate.month(); eDay = eDate.day(); } QString qu; qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + "," + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," + QString::number( m_todo.isCompleted() ) + "," + "'" + m_todo.description() + "'" + "," + "'" + m_todo.summary() + "'" + "," + QString::number(m_todo.priority() ) + "," + "'" + QString::number(year) + "-" + QString::number(month) + "-" + QString::number( day ) + "'" + "," + QString::number( m_todo.progress() ) + "," - + "''" + "," // state (conversion needed) -// + QString::number( m_todo.state() ) + "," - + "''" + "," // Recurrence (conversion needed) - + "''" + "," // Notifiers (conversion needed) - + "''" + "," // Maintainers (conversion needed) + + QString::number( m_todo.state().state() ) + "," + + "'" + m_todo.recurrence().toString() + "'"+ ","; + + if ( m_todo.hasNotifiers() ) { + OPimNotifyManager manager = m_todo.notifiers(); + qu += "'" + manager.remindersToString() + "'" + "," + + "'" + manager.alarmsToString() + "'" + ","; + } + else{ + qu += QString( "''" ) + "," + + "''" + ","; + } + + qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) + "'" + QString::number(sYear) + "-" - + QString::number(sMonth) - + "-" + QString::number(sDay) + "'" + "," + + QString::number(sMonth) + + "-" + QString::number(sDay) + "'" + "," + "'" + QString::number(eYear) + "-" + QString::number(eMonth) + "-"+QString::number(eDay) + "'" + ")"; qWarning("add %s", qu.latin1() ); return qu; } RemoveQuery::RemoveQuery(int uid ) : OSQLQuery(), m_uid( uid ) {} RemoveQuery::~RemoveQuery() {} QString RemoveQuery::query()const { QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); return qu; } ClearQuery::ClearQuery() : OSQLQuery() {} ClearQuery::~ClearQuery() {} QString ClearQuery::query()const { QString qu = "drop table todolist"; return qu; } FindQuery::FindQuery(int uid) : OSQLQuery(), m_uid(uid ) { } FindQuery::FindQuery(const QArray<int>& ints) : OSQLQuery(), m_uids(ints){ } FindQuery::~FindQuery() { } QString FindQuery::query()const{ if (m_uids.count() == 0 ) return single(); else return multi(); } QString FindQuery::single()const{ QString qu = "select * from todolist where uid = " + QString::number(m_uid); return qu; } QString FindQuery::multi()const { QString qu = "select * from todolist where "; for (uint i = 0; i < m_uids.count(); i++ ) { qu += " UID = " + QString::number( m_uids[i] ) + " OR"; } qu.remove( qu.length()-2, 2 ); return qu; } OverDueQuery::OverDueQuery(): OSQLQuery() {} OverDueQuery::~OverDueQuery() {} QString OverDueQuery::query()const { QDate date = QDate::currentDate(); QString str; str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); return str; } EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} EffQuery::~EffQuery() {} QString EffQuery::query()const { return m_inc ? with() : out(); } QString EffQuery::with()const { QString str; str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); return str; } QString EffQuery::out()const { QString str; str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); return str; } }; OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) : OTodoAccessBackend(), m_dict(15), m_dirty(true) { QString fi = file; if ( fi.isEmpty() ) fi = Global::applicationFileName( "todolist", "todolist.db" ); OSQLManager man; m_driver = man.standard(); m_driver->setUrl(fi); // fillDict(); } OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ } bool OTodoAccessBackendSQL::load(){ if (!m_driver->open() ) return false; CreateQuery creat; OSQLResult res = m_driver->query(&creat ); m_dirty = true; return true; } bool OTodoAccessBackendSQL::reload(){ return load(); } bool OTodoAccessBackendSQL::save(){ return m_driver->close(); } QArray<int> OTodoAccessBackendSQL::allRecords()const { if (m_dirty ) update(); return m_uids; } QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int, const QDateTime& ){ QArray<int> ints(0); return ints; } OTodo OTodoAccessBackendSQL::find(int uid ) const{ FindQuery query( uid ); return todo( m_driver->query(&query) ); } OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, uint cur, Frontend::CacheDirection dir ) const{ uint CACHE = readAhead(); qWarning("searching for %d", uid ); QArray<int> search( CACHE ); uint size =0; OTodo to; // we try to cache CACHE items switch( dir ) { /* forward */ case 0: // FIXME: Not a good style to use magic numbers here (eilers) for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { qWarning("size %d %d", size, ints[i] ); search[size] = ints[i]; size++; } break; /* reverse */ case 1: // FIXME: Not a good style to use magic numbers here (eilers) for (uint i = cur; i != 0 && size < CACHE; i-- ) { search[size] = ints[i]; size++; } break; } search.resize( size ); FindQuery query( search ); OSQLResult res = m_driver->query( &query ); if ( res.state() != OSQLResult::Success ) return to; return todo( res ); } void OTodoAccessBackendSQL::clear() { ClearQuery cle; OSQLResult res = m_driver->query( &cle ); CreateQuery qu; res = m_driver->query(&qu); } bool OTodoAccessBackendSQL::add( const OTodo& t) { InsertQuery ins( t ); OSQLResult res = m_driver->query( &ins ); if ( res.state() == OSQLResult::Failure ) return false; int c = m_uids.count(); m_uids.resize( c+1 ); m_uids[c] = t.uid(); return true; } bool OTodoAccessBackendSQL::remove( int uid ) { RemoveQuery rem( uid ); OSQLResult res = m_driver->query(&rem ); if ( res.state() == OSQLResult::Failure ) return false; m_dirty = true; return true; } /* * FIXME better set query * but we need the cache for that * now we remove */ bool OTodoAccessBackendSQL::replace( const OTodo& t) { remove( t.uid() ); bool b= add(t); m_dirty = false; // we changed some stuff but the UID stayed the same return b; } QArray<int> OTodoAccessBackendSQL::overDue() { OverDueQuery qu; return uids( m_driver->query(&qu ) ); } QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, const QDate& t, bool u) { EffQuery ef(s, t, u ); return uids (m_driver->query(&ef) ); } /* * */ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, int sortFilter, int cat ) { qWarning("sorted %d, %d", asc, sortOrder ); QString query; query = "select uid from todolist WHERE "; /* * Sort Filter stuff * not that straight forward * FIXME: Replace magic numbers * */ /* Category */ if ( sortFilter & 1 ) { QString str; if (cat != 0 ) str = QString::number( cat ); query += " categories like '%" +str+"%' AND"; } /* Show only overdue */ if ( sortFilter & 2 ) { QDate date = QDate::currentDate(); QString due; QString base; base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); query += " " + base + " AND"; } /* not show completed */ if ( sortFilter & 4 ) { query += " completed = 0 AND"; }else{ query += " ( completed = 1 OR completed = 0) AND"; } /* srtip the end */ query = query.remove( query.length()-3, 3 ); /* * sort order stuff * quite straight forward */ query += "ORDER BY "; switch( sortOrder ) { /* completed */ case 0: query += "completed"; break; case 1: query += "priority"; break; case 2: query += "summary"; break; case 3: query += "DueDate"; break; } if ( !asc ) { qWarning("not ascending!"); query += " DESC"; } qWarning( query ); OSQLRawQuery raw(query ); return uids( m_driver->query(&raw) ); } bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ if ( str == "0-0-0" ) return false; else{ int day, year, month; QStringList list = QStringList::split("-", str ); year = list[0].toInt(); month = list[1].toInt(); day = list[2].toInt(); da.setYMD( year, month, day ); return true; } } OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ if ( res.state() == OSQLResult::Failure ) { OTodo to; return to; } OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it = list.begin(); qWarning("todo1"); OTodo to = todo( (*it) ); cache( to ); ++it; for ( ; it != list.end(); ++it ) { qWarning("caching"); cache( todo( (*it) ) ); } return to; } OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { qWarning("todo"); bool hasDueDate = false; QDate dueDate = QDate::currentDate(); hasDueDate = date( dueDate, item.data("DueDate") ); QStringList cats = QStringList::split(";", item.data("categories") ); OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), cats, item.data("summary"), item.data("description"), item.data("progress").toUShort(), hasDueDate, dueDate, item.data("uid").toInt() ); bool isOk; int prioInt = QString( item.data("priority") ).toInt( &isOk ); if ( isOk ) to.setPriority( prioInt ); bool hasStartDate = false; QDate startDate = QDate::currentDate(); hasStartDate = date( startDate, item.data("startdate") ); bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); hasCompletedDate = date( completedDate, item.data("completeddate") ); if ( hasStartDate ) to.setStartDate( startDate ); if ( hasCompletedDate ) to.setCompletedDate( completedDate ); + + OPimNotifyManager& manager = to.notifiers(); + manager.alarmsFromString( item.data("alarms") ); + manager.remindersFromString( item.data("reminders") ); + + OPimState pimState; + pimState.setState( QString( item.data("state") ).toInt() ); + to.setState( pimState ); + + // Recurrence not supported yet + // to.setRecurrence( return to; } OTodo OTodoAccessBackendSQL::todo( int uid )const { FindQuery find( uid ); return todo( m_driver->query(&find) ); } /* * update the dict */ void OTodoAccessBackendSQL::fillDict() { /* initialize dict */ /* * UPDATE dict if you change anything!!! * FIXME: Isn't this dict obsolete ? (eilers) */ m_dict.setAutoDelete( TRUE ); m_dict.insert("Categories" , new int(OTodo::Category) ); m_dict.insert("Uid" , new int(OTodo::Uid) ); m_dict.insert("HasDate" , new int(OTodo::HasDate) ); m_dict.insert("Completed" , new int(OTodo::Completed) ); m_dict.insert("Description" , new int(OTodo::Description) ); m_dict.insert("Summary" , new int(OTodo::Summary) ); m_dict.insert("Priority" , new int(OTodo::Priority) ); m_dict.insert("DateDay" , new int(OTodo::DateDay) ); m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); m_dict.insert("DateYear" , new int(OTodo::DateYear) ); m_dict.insert("Progress" , new int(OTodo::Progress) ); m_dict.insert("Completed", new int(OTodo::Completed) ); // Why twice ? (eilers) m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); // m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); // old stuff (eilers) // m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); // old stuff (eilers) } /* * need to be const so let's fool the * compiler :( */ void OTodoAccessBackendSQL::update()const { ((OTodoAccessBackendSQL*)this)->m_dirty = false; LoadQuery lo; OSQLResult res = m_driver->query(&lo); if ( res.state() != OSQLResult::Success ) return; ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); } QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it; QArray<int> ints(list.count() ); qWarning(" count = %d", list.count() ); int i = 0; for (it = list.begin(); it != list.end(); ++it ) { ints[i] = (*it).data("uid").toInt(); i++; } return ints; } QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const { #warning OTodoAccessBackendSQL::matchRegexp() not implemented !! #if 0 Copied from xml-backend by not adapted to sql (eilers) QArray<int> m_currentQuery( m_events.count() ); uint arraycounter = 0; QMap<int, OTodo>::ConstIterator it; for (it = m_events.begin(); it != m_events.end(); ++it ) { if ( it.data().match( r ) ) m_currentQuery[arraycounter++] = it.data().uid(); } // Shrink to fit.. m_currentQuery.resize(arraycounter); return m_currentQuery; #endif QArray<int> empty; return empty; } QBitArray OTodoAccessBackendSQL::supports()const { - QBitArray ar( OTodo::CompletedDate + 1 ); - ar.fill( true ); - ar[OTodo::CrossReference] = false; - ar[OTodo::State ] = false; - ar[OTodo::Reminders] = false; - ar[OTodo::Notifiers] = false; - ar[OTodo::Maintainer] = false; - - return ar; + return sup(); } -QBitArray OTodoAccessBackendSQL::sup() { +QBitArray OTodoAccessBackendSQL::sup() const{ QBitArray ar( OTodo::CompletedDate + 1 ); ar.fill( true ); ar[OTodo::CrossReference] = false; ar[OTodo::State ] = false; ar[OTodo::Reminders] = false; ar[OTodo::Notifiers] = false; ar[OTodo::Maintainer] = false; return ar; } void OTodoAccessBackendSQL::removeAllCompleted(){ #warning OTodoAccessBackendSQL::removeAllCompleted() not implemented !! } diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h index 77d8b77..1c55567 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.h +++ b/libopie2/opiepim/backend/otodoaccesssql.h @@ -1,56 +1,56 @@ #ifndef OPIE_PIM_ACCESS_SQL_H #define OPIE_PIM_ACCESS_SQL_H #include <qasciidict.h> #include "otodoaccessbackend.h" class OSQLDriver; class OSQLResult; class OSQLResultItem; class OTodoAccessBackendSQL : public OTodoAccessBackend { public: OTodoAccessBackendSQL( const QString& file ); ~OTodoAccessBackendSQL(); bool load(); bool reload(); bool save(); QArray<int> allRecords()const; QArray<int> queryByExample( const OTodo& t, int settings, const QDateTime& d = QDateTime() ); OTodo find(int uid)const; OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; void clear(); bool add( const OTodo& t ); bool remove( int uid ); bool replace( const OTodo& t ); QArray<int> overDue(); QArray<int> effectiveToDos( const QDate& start, const QDate& end, bool includeNoDates ); QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); QBitArray supports()const; QArray<int> matchRegexp( const QRegExp &r ) const; void removeAllCompleted(); private: void update()const; void fillDict(); inline bool date( QDate& date, const QString& )const; inline OTodo todo( const OSQLResult& )const; inline OTodo todo( OSQLResultItem& )const; inline QArray<int> uids( const OSQLResult& )const; OTodo todo( int uid )const; - QBitArray sup(); + QBitArray sup() const; QAsciiDict<int> m_dict; OSQLDriver* m_driver; QArray<int> m_uids; bool m_dirty : 1; }; #endif diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp index f688735..4a5cb33 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.cpp +++ b/libopie2/opiepim/backend/otodoaccessxml.cpp @@ -59,818 +59,818 @@ char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) if (hsearch >= haystack + hLen) return (0); } while (haystackChar != needleChar); } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); hsearch--; } return ((char *)hsearch); } } OTodoAccessXML::OTodoAccessXML( const QString& appName, const QString& fileName ) : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) { if (!fileName.isEmpty() ) m_file = fileName; else m_file = Global::applicationFileName( "todolist", "todolist.xml" ); } OTodoAccessXML::~OTodoAccessXML() { } bool OTodoAccessXML::load() { rec = 0; m_opened = true; m_changed = false; /* initialize dict */ /* * UPDATE dict if you change anything!!! */ QAsciiDict<int> dict(26); dict.setAutoDelete( TRUE ); dict.insert("Categories" , new int(OTodo::Category) ); dict.insert("Uid" , new int(OTodo::Uid) ); dict.insert("HasDate" , new int(OTodo::HasDate) ); dict.insert("Completed" , new int(OTodo::Completed) ); dict.insert("Description" , new int(OTodo::Description) ); dict.insert("Summary" , new int(OTodo::Summary) ); dict.insert("Priority" , new int(OTodo::Priority) ); dict.insert("DateDay" , new int(OTodo::DateDay) ); dict.insert("DateMonth" , new int(OTodo::DateMonth) ); dict.insert("DateYear" , new int(OTodo::DateYear) ); dict.insert("Progress" , new int(OTodo::Progress) ); dict.insert("CompletedDate", new int(OTodo::CompletedDate) ); dict.insert("StartDate", new int(OTodo::StartDate) ); dict.insert("CrossReference", new int(OTodo::CrossReference) ); dict.insert("State", new int(OTodo::State) ); dict.insert("Alarms", new int(OTodo::Alarms) ); dict.insert("Reminders", new int(OTodo::Reminders) ); dict.insert("Notifiers", new int(OTodo::Notifiers) ); dict.insert("Maintainer", new int(OTodo::Maintainer) ); dict.insert("rtype", new int(FRType) ); dict.insert("rweekdays", new int(FRWeekdays) ); dict.insert("rposition", new int(FRPosition) ); dict.insert("rfreq", new int(FRFreq) ); dict.insert("start", new int(FRStart) ); dict.insert("rhasenddate", new int(FRHasEndDate) ); dict.insert("enddt", new int(FREndDate) ); // here the custom XML parser from TT it's GPL // but we want to push OpiePIM... to TT..... // mmap part from zecke :) int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); struct stat attribut; if ( fd < 0 ) return false; if ( fstat(fd, &attribut ) == -1 ) { ::close( fd ); return false; } void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); if ( map_addr == ( (caddr_t)-1) ) { ::close(fd ); return false; } /* advise the kernel who we want to read it */ ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); /* we do not the file any more */ ::close( fd ); char* dt = (char*)map_addr; int len = attribut.st_size; int i = 0; char *point; const char* collectionString = "<Task "; int strLen = strlen(collectionString); while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) { i = point -dt; i+= strLen; qWarning("Found a start at %d %d", i, (point-dt) ); OTodo ev; m_year = m_month = m_day = 0; while ( TRUE ) { while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) ++i; if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) break; // we have another attribute, read it. int j = i; while ( j < len && dt[j] != '=' ) ++j; QCString attr( dt+i, j-i+1); i = ++j; // skip = // find the start of quotes while ( i < len && dt[i] != '"' ) ++i; j = ++i; bool haveUtf = FALSE; bool haveEnt = FALSE; while ( j < len && dt[j] != '"' ) { if ( ((unsigned char)dt[j]) > 0x7f ) haveUtf = TRUE; if ( dt[j] == '&' ) haveEnt = TRUE; ++j; } if ( i == j ) { // empty value i = j + 1; continue; } QCString value( dt+i, j-i+1 ); i = j + 1; QString str = (haveUtf ? QString::fromUtf8( value ) : QString::fromLatin1( value ) ); if ( haveEnt ) str = Qtopia::plainString( str ); /* * add key + value */ todo( &dict, ev, attr, str ); } /* * now add it */ qWarning("End at %d", i ); if (m_events.contains( ev.uid() ) || ev.uid() == 0) { ev.setUid( 1 ); m_changed = true; } if ( ev.hasDueDate() ) { ev.setDueDate( QDate(m_year, m_month, m_day) ); } if ( rec && rec->doesRecur() ) { OTimeZone utc = OTimeZone::utc(); ORecur recu( *rec ); // call copy c'tor recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() ); recu.setStart( ev.dueDate() ); ev.setRecurrence( recu ); } m_events.insert(ev.uid(), ev ); m_year = m_month = m_day = -1; delete rec; rec = 0; } munmap(map_addr, attribut.st_size ); qWarning("counts %d records loaded!", m_events.count() ); return true; } bool OTodoAccessXML::reload() { m_events.clear(); return load(); } bool OTodoAccessXML::save() { // qWarning("saving"); if (!m_opened || !m_changed ) { // qWarning("not saving"); return true; } QString strNewFile = m_file + ".new"; QFile f( strNewFile ); if (!f.open( IO_WriteOnly|IO_Raw ) ) return false; int written; QString out; out = "<!DOCTYPE Tasks>\n<Tasks>\n"; // for all todos QMap<int, OTodo>::Iterator it; for (it = m_events.begin(); it != m_events.end(); ++it ) { out+= "<Task " + toString( (*it) ) + " />\n"; QCString cstr = out.utf8(); written = f.writeBlock( cstr.data(), cstr.length() ); /* less written then we wanted */ if ( written != (int)cstr.length() ) { f.close(); QFile::remove( strNewFile ); return false; } out = QString::null; } out += "</Tasks>"; QCString cstr = out.utf8(); written = f.writeBlock( cstr.data(), cstr.length() ); if ( written != (int)cstr.length() ) { f.close(); QFile::remove( strNewFile ); return false; } /* flush before renaming */ f.close(); if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { // qWarning("error renaming"); QFile::remove( strNewFile ); } m_changed = false; return true; } QArray<int> OTodoAccessXML::allRecords()const { QArray<int> ids( m_events.count() ); QMap<int, OTodo>::ConstIterator it; int i = 0; for ( it = m_events.begin(); it != m_events.end(); ++it ) { ids[i] = it.key(); i++; } return ids; } QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int, const QDateTime& ) { QArray<int> ids(0); return ids; } OTodo OTodoAccessXML::find( int uid )const { OTodo todo; todo.setUid( 0 ); // isEmpty() QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); if ( it != m_events.end() ) todo = it.data(); return todo; } void OTodoAccessXML::clear() { if (m_opened ) m_changed = true; m_events.clear(); } bool OTodoAccessXML::add( const OTodo& todo ) { // qWarning("add"); m_changed = true; m_events.insert( todo.uid(), todo ); return true; } bool OTodoAccessXML::remove( int uid ) { m_changed = true; m_events.remove( uid ); return true; } bool OTodoAccessXML::replace( const OTodo& todo) { m_changed = true; m_events.replace( todo.uid(), todo ); return true; } QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, const QDate& end, bool includeNoDates ) { QArray<int> ids( m_events.count() ); QMap<int, OTodo>::Iterator it; int i = 0; for ( it = m_events.begin(); it != m_events.end(); ++it ) { if ( !it.data().hasDueDate() ) { if ( includeNoDates ) { ids[i] = it.key(); i++; } }else if ( it.data().dueDate() >= start && it.data().dueDate() <= end ) { ids[i] = it.key(); i++; } } ids.resize( i ); return ids; } QArray<int> OTodoAccessXML::overDue() { QArray<int> ids( m_events.count() ); int i = 0; QMap<int, OTodo>::Iterator it; for ( it = m_events.begin(); it != m_events.end(); ++it ) { if ( it.data().isOverdue() ) { ids[i] = it.key(); i++; } } ids.resize( i ); return ids; } /* private */ void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, const QCString& attr, const QString& val) { // qWarning("parse to do from XMLElement" ); int *find=0; find = (*dict)[ attr.data() ]; if (!find ) { // qWarning("Unknown option" + it.key() ); ev.setCustomField( attr, val ); return; } switch( *find ) { case OTodo::Uid: ev.setUid( val.toInt() ); break; case OTodo::Category: ev.setCategories( ev.idsFromString( val ) ); break; case OTodo::HasDate: ev.setHasDueDate( val.toInt() ); break; case OTodo::Completed: ev.setCompleted( val.toInt() ); break; case OTodo::Description: ev.setDescription( val ); break; case OTodo::Summary: ev.setSummary( val ); break; case OTodo::Priority: ev.setPriority( val.toInt() ); break; case OTodo::DateDay: m_day = val.toInt(); break; case OTodo::DateMonth: m_month = val.toInt(); break; case OTodo::DateYear: m_year = val.toInt(); break; case OTodo::Progress: ev.setProgress( val.toInt() ); break; case OTodo::CompletedDate: ev.setCompletedDate( OConversion::dateFromString( val ) ); break; case OTodo::StartDate: ev.setStartDate( OConversion::dateFromString( val ) ); break; case OTodo::State: ev.setState( val.toInt() ); break; case OTodo::Alarms:{ OPimNotifyManager &manager = ev.notifiers(); QStringList als = QStringList::split(";", val ); for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty qWarning("alarm: %s", alarm.join("___").latin1() ); qWarning("alarm[0]: %s %s", alarm[0].latin1(), OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() ); manager.add( al ); } } break; case OTodo::Reminders:{ OPimNotifyManager &manager = ev.notifiers(); QStringList rems = QStringList::split(";", val ); for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { OPimReminder rem( (*it).toInt() ); manager.add( rem ); } } break; case OTodo::CrossReference: { /* * A cross refernce looks like * appname,id;appname,id * we need to split it up */ QStringList refs = QStringList::split(';', val ); QStringList::Iterator strIt; for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { int pos = (*strIt).find(','); if ( pos > -1 ) ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); } break; } /* Recurrence stuff below + post processing later */ case FRType: if ( val == "Daily" ) recur()->setType( ORecur::Daily ); else if ( val == "Weekly" ) recur()->setType( ORecur::Weekly); else if ( val == "MonthlyDay" ) recur()->setType( ORecur::MonthlyDay ); else if ( val == "MonthlyDate" ) recur()->setType( ORecur::MonthlyDate ); else if ( val == "Yearly" ) recur()->setType( ORecur::Yearly ); else recur()->setType( ORecur::NoRepeat ); break; case FRWeekdays: recur()->setDays( val.toInt() ); break; case FRPosition: recur()->setPosition( val.toInt() ); break; case FRFreq: recur()->setFrequency( val.toInt() ); break; case FRHasEndDate: recur()->setHasEndDate( val.toInt() ); break; case FREndDate: { rp_end = (time_t) val.toLong(); break; } default: ev.setCustomField( attr, val ); break; } } // from PalmtopRecord... GPL ### FIXME namespace { QString customToXml(const QMap<QString, QString>& customMap ) { //qWarning(QString("writing custom %1").arg(customMap.count())); QString buf(" "); for ( QMap<QString, QString>::ConstIterator cit = customMap.begin(); cit != customMap.end(); ++cit) { // qWarning(".ITEM."); buf += cit.key(); buf += "=\""; buf += Qtopia::escapeString(cit.data()); buf += "\" "; } return buf; } } QString OTodoAccessXML::toString( const OTodo& ev )const { QString str; str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; str += "Categories=\"" + toString( ev.categories() ) + "\" "; str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; if ( ev.hasDueDate() ) { str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; } // qWarning( "Uid %d", ev.uid() ); str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; // append the extra options /* FIXME Qtopia::Record this is currently not * possible you can set custom fields * but don' iterate over the list * I may do #define private protected * for this case - cough --zecke */ /* QMap<QString, QString> extras = ev.extras(); QMap<QString, QString>::Iterator extIt; for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) str += extIt.key() + "=\"" + extIt.data() + "\" "; */ // cross refernce if ( ev.hasRecurrence() ) { str += ev.recurrence().toString(); } if ( ev.hasStartDate() ) str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" "; if ( ev.hasCompletedDate() ) str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" "; if ( ev.hasState() ) str += "State=\""+QString::number( ev.state().state() )+"\" "; /* * save reminders and notifiers! - * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER:DURATION:SOUND:.... + * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER_DURATION:SOUND:.... */ if ( ev.hasNotifiers() ) { OPimNotifyManager manager = ev.notifiers(); OPimNotifyManager::Alarms alarms = manager.alarms(); if (!alarms.isEmpty() ) { QStringList als; OPimNotifyManager::Alarms::Iterator it = alarms.begin(); for ( ; it != alarms.end(); ++it ) { /* only if time is valid */ if ( (*it).dateTime().isValid() ) { als << OConversion::dateTimeToString( (*it).dateTime() ) + ":" + QString::number( (*it).duration() ) + ":" + QString::number( (*it).sound() ) + ":"; } } // now write the list qWarning("als: %s", als.join("____________").latin1() ); str += "Alarms=\""+als.join(";") +"\" "; } /* * now the same for reminders but more easy. We just save the uid of the OEvent. */ OPimNotifyManager::Reminders reminders = manager.reminders(); if (!reminders.isEmpty() ) { OPimNotifyManager::Reminders::Iterator it = reminders.begin(); QStringList records; for ( ; it != reminders.end(); ++it ) { records << QString::number( (*it).recordUid() ); } str += "Reminders=\""+ records.join(";") +"\" "; } } str += customToXml( ev.toExtraMap() ); return str; } QString OTodoAccessXML::toString( const QArray<int>& ints ) const { return Qtopia::Record::idsToString( ints ); } /* internal class for sorting * * Inspired by todoxmlio.cpp from TT */ struct OTodoXMLContainer { OTodo todo; }; namespace { inline QString string( const OTodo& todo) { return todo.summary().isEmpty() ? todo.description().left(20 ) : todo.summary(); } inline int completed( const OTodo& todo1, const OTodo& todo2) { int ret = 0; if ( todo1.isCompleted() ) ret++; if ( todo2.isCompleted() ) ret--; return ret; } inline int priority( const OTodo& t1, const OTodo& t2) { return ( t1.priority() - t2.priority() ); } inline int description( const OTodo& t1, const OTodo& t2) { return QString::compare( string(t1), string(t2) ); } inline int deadline( const OTodo& t1, const OTodo& t2) { int ret = 0; if ( t1.hasDueDate() && t2.hasDueDate() ) ret = t2.dueDate().daysTo( t1.dueDate() ); else if ( t1.hasDueDate() ) ret = -1; else if ( t2.hasDueDate() ) ret = 1; else ret = 0; return ret; } }; /* * Returns: * 0 if item1 == item2 * * non-zero if item1 != item2 * * This function returns int rather than bool so that reimplementations * can return one of three values and use it to sort by: * * 0 if item1 == item2 * * > 0 (positive integer) if item1 > item2 * * < 0 (negative integer) if item1 < item2 * */ class OTodoXMLVector : public QVector<OTodoXMLContainer> { public: OTodoXMLVector(int size, bool asc, int sort) : QVector<OTodoXMLContainer>( size ) { setAutoDelete( true ); m_asc = asc; m_sort = sort; } /* return the summary/description */ QString string( const OTodo& todo) { return todo.summary().isEmpty() ? todo.description().left(20 ) : todo.summary(); } /** * we take the sortorder( switch on it ) * */ int compareItems( Item d1, Item d2 ) { bool seComp, sePrio, seDesc, seDeadline; seComp = sePrio = seDeadline = seDesc = false; int ret =0; OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; /* same item */ if ( con1->todo.uid() == con2->todo.uid() ) return 0; switch ( m_sort ) { /* completed */ case 0: { ret = completed( con1->todo, con2->todo ); seComp = TRUE; break; } /* priority */ case 1: { ret = priority( con1->todo, con2->todo ); sePrio = TRUE; break; } /* description */ case 2: { ret = description( con1->todo, con2->todo ); seDesc = TRUE; break; } /* deadline */ case 3: { ret = deadline( con1->todo, con2->todo ); seDeadline = TRUE; break; } default: ret = 0; break; }; /* * FIXME do better sorting if the first sort criteria * ret equals 0 start with complete and so on... */ /* twist it we're not ascending*/ if (!m_asc) ret = ret * -1; if ( ret ) return ret; // default did not gave difference let's try it other way around /* * General try if already checked if not test * and return * 1.Completed * 2.Priority * 3.Description * 4.DueDate */ if (!seComp ) { if ( (ret = completed( con1->todo, con2->todo ) ) ) { if (!m_asc ) ret *= -1; return ret; } } if (!sePrio ) { if ( (ret = priority( con1->todo, con2->todo ) ) ) { if (!m_asc ) ret *= -1; return ret; } } if (!seDesc ) { if ( (ret = description(con1->todo, con2->todo ) ) ) { if (!m_asc) ret *= -1; return ret; } } if (!seDeadline) { if ( (ret = deadline( con1->todo, con2->todo ) ) ) { if (!m_asc) ret *= -1; return ret; } } return 0; } private: bool m_asc; int m_sort; }; QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, int sortFilter, int cat ) { OTodoXMLVector vector(m_events.count(), asc,sortOrder ); QMap<int, OTodo>::Iterator it; int item = 0; bool bCat = sortFilter & 1 ? true : false; bool bOnly = sortFilter & 2 ? true : false; bool comp = sortFilter & 4 ? true : false; for ( it = m_events.begin(); it != m_events.end(); ++it ) { /* show category */ /* -1 == unfiled */ if ( bCat && cat == -1 ) { if(!(*it).categories().isEmpty() ) continue; }else if ( bCat && cat != 0) if (!(*it).categories().contains( cat ) ) { continue; } /* isOverdue but we should not show overdue - why?*/ /* if ( (*it).isOverdue() && !bOnly ) { qWarning("item is overdue but !bOnly"); continue; } */ if ( !(*it).isOverdue() && bOnly ) { continue; } if ((*it).isCompleted() && comp ) { continue; } OTodoXMLContainer* con = new OTodoXMLContainer(); con->todo = (*it); vector.insert(item, con ); item++; } vector.resize( item ); /* sort it now */ vector.sort(); /* now get the uids */ QArray<int> array( vector.count() ); for (uint i= 0; i < vector.count(); i++ ) { array[i] = ( vector.at(i) )->todo.uid(); } return array; }; void OTodoAccessXML::removeAllCompleted() { QMap<int, OTodo> events = m_events; for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { if ( (*it).isCompleted() ) events.remove( it.key() ); } m_events = events; } QBitArray OTodoAccessXML::supports()const { static QBitArray ar = sup(); return ar; } QBitArray OTodoAccessXML::sup() { QBitArray ar( OTodo::CompletedDate +1 ); ar.fill( true ); ar[OTodo::CrossReference] = false; ar[OTodo::State ] = false; ar[OTodo::Reminders] = false; ar[OTodo::Notifiers] = false; ar[OTodo::Maintainer] = false; return ar; } QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const { QArray<int> m_currentQuery( m_events.count() ); uint arraycounter = 0; QMap<int, OTodo>::ConstIterator it; for (it = m_events.begin(); it != m_events.end(); ++it ) { if ( it.data().match( r ) ) m_currentQuery[arraycounter++] = it.data().uid(); } // Shrink to fit.. m_currentQuery.resize(arraycounter); return m_currentQuery; } diff --git a/libopie2/opiepim/core/opimnotifymanager.cpp b/libopie2/opiepim/core/opimnotifymanager.cpp index 06b5987..53ad4c3 100644 --- a/libopie2/opiepim/core/opimnotifymanager.cpp +++ b/libopie2/opiepim/core/opimnotifymanager.cpp @@ -1,74 +1,146 @@ #include "opimnotifymanager.h" +#include "oconversion.h" + +#include <qstringlist.h> + OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al) : m_rem( rem ), m_al( al ) {} OPimNotifyManager::~OPimNotifyManager() { } /* use static_cast and type instead of dynamic... */ void OPimNotifyManager::add( const OPimNotify& noti) { if ( noti.type() == QString::fromLatin1("OPimReminder") ) { const OPimReminder& rem = static_cast<const OPimReminder&>(noti); m_rem.append( rem ); }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); m_al.append( al ); } } void OPimNotifyManager::remove( const OPimNotify& noti) { if ( noti.type() == QString::fromLatin1("OPimReminder") ) { const OPimReminder& rem = static_cast<const OPimReminder&>(noti); m_rem.remove( rem ); }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); m_al.remove( al ); } } void OPimNotifyManager::replace( const OPimNotify& noti) { if ( noti.type() == QString::fromLatin1("OPimReminder") ) { const OPimReminder& rem = static_cast<const OPimReminder&>(noti); m_rem.remove( rem ); m_rem.append( rem ); }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); m_al.remove( al ); m_al.append( al ); } } OPimNotifyManager::Reminders OPimNotifyManager::reminders()const { return m_rem; } OPimNotifyManager::Alarms OPimNotifyManager::alarms()const { return m_al; } void OPimNotifyManager::setAlarms( const Alarms& al) { m_al = al; } void OPimNotifyManager::setReminders( const Reminders& rem) { m_rem = rem; } /* FIXME!!! */ /** * The idea is to check if the provider for our service * is online * if it is we will use QCOP * if not the Factory to get the backend... * Qtopia1.6 services would be kewl to have here.... */ void OPimNotifyManager::registerNotify( const OPimNotify& ) { } /* FIXME!!! */ /** * same as above... * Also implement Url model * have a MainWindow.... */ void OPimNotifyManager::deregister( const OPimNotify& ) { } + bool OPimNotifyManager::isEmpty()const { qWarning("is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() ); if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; else return false; } + +// Taken from otodoaccessxml.. +QString OPimNotifyManager::alarmsToString() const +{ + QString str; + + OPimNotifyManager::Alarms alarms = m_al; + if ( !alarms.isEmpty() ) { + QStringList als; + OPimNotifyManager::Alarms::Iterator it = alarms.begin(); + for ( ; it != alarms.end(); ++it ) { + /* only if time is valid */ + if ( (*it).dateTime().isValid() ) { + als << OConversion::dateTimeToString( (*it).dateTime() ) + + ":" + QString::number( (*it).duration() ) + + ":" + QString::number( (*it).sound() ) + + ":"; + } + } + // now write the list + qWarning("als: %s", als.join("____________").latin1() ); + str = als.join(";"); + } + + return str; +} +QString OPimNotifyManager::remindersToString() const +{ + QString str; + + OPimNotifyManager::Reminders reminders = m_rem; + if (!reminders.isEmpty() ) { + OPimNotifyManager::Reminders::Iterator it = reminders.begin(); + QStringList records; + for ( ; it != reminders.end(); ++it ) { + records << QString::number( (*it).recordUid() ); + } + str = records.join(";"); + } + + return str; +} + +void OPimNotifyManager::alarmsFromString( const QString& str ) +{ + QStringList als = QStringList::split(";", str ); + for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { + QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty + qWarning("alarm: %s", alarm.join("___").latin1() ); + qWarning("alarm[0]: %s %s", alarm[0].latin1(), + OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); + OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), + alarm[1].toInt() ); + add( al ); + } +} + +void OPimNotifyManager::remindersFromString( const QString& str ) +{ + + QStringList rems = QStringList::split(";", str ); + for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { + OPimReminder rem( (*it).toInt() ); + add( rem ); + } + +} diff --git a/libopie2/opiepim/core/opimnotifymanager.h b/libopie2/opiepim/core/opimnotifymanager.h index 0ac30a1..48410e7 100644 --- a/libopie2/opiepim/core/opimnotifymanager.h +++ b/libopie2/opiepim/core/opimnotifymanager.h @@ -1,54 +1,76 @@ #ifndef OPIE_PIM_NOTIFY_MANAGER_H #define OPIE_PIM_NOTIFY_MANAGER_H #include <qvaluelist.h> #include <opie/opimnotify.h> /** * The notify manager keeps track of the Notifiers.... */ class OPimNotifyManager { public: typedef QValueList<OPimReminder> Reminders; typedef QValueList<OPimAlarm> Alarms; OPimNotifyManager( const Reminders& rems = Reminders(), const Alarms& alarms = Alarms() ); ~OPimNotifyManager(); /* we will cast it for you ;) */ void add( const OPimNotify& ); void remove( const OPimNotify& ); /* replaces all with this one! */ void replace( const OPimNotify& ); Reminders reminders()const; Alarms alarms()const; void setAlarms( const Alarms& ); void setReminders( const Reminders& ); /* register is a Ansi C keyword... */ /** * This function will register the Notify to the Alarm Server * or datebook depending on the type of the notify */ void registerNotify( const OPimNotify& ); /** * this will do the opposite.. */ void deregister( const OPimNotify& ); - bool isEmpty()const; + /** + * Return all alarms as string + */ + QString alarmsToString() const; + /** + * Return all notifiers as string + */ + QString remindersToString() const; + + /** + * Convert string to alarms + * @param str String created by alarmsToString() + */ + void alarmsFromString( const QString& str ); + + /** + * Convert string to reminders + * @param str String created by remindersToString() + */ + void remindersFromString( const QString& str ); + + + private: Reminders m_rem; Alarms m_al; class Private; Private *d; }; #endif diff --git a/libopie2/opiepim/ocontactfields.cpp b/libopie2/opiepim/ocontactfields.cpp index 7206f0d..0f08a5a 100644 --- a/libopie2/opiepim/ocontactfields.cpp +++ b/libopie2/opiepim/ocontactfields.cpp @@ -1,466 +1,477 @@ #include "ocontactfields.h" #include <qstringlist.h> #include <qobject.h> // We should use our own enum in the future .. #include <qpe/recordfields.h> #include <qpe/config.h> #include <opie/ocontact.h> /*! \internal - Returns a list of details field names for a contact. + Returns a list of personal field names for a contact. */ -QStringList OContactFields::untrdetailsfields( bool sorted ) +QStringList OContactFields::personalfields( bool sorted, bool translated ) { QStringList list; - QMap<int, QString> mapIdToStr = idToUntrFields(); + QMap<int, QString> mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); - list.append( mapIdToStr[ Qtopia::Office ] ); - list.append( mapIdToStr[ Qtopia::Profession ] ); - list.append( mapIdToStr[ Qtopia::Assistant ] ); - list.append( mapIdToStr[ Qtopia::Manager ] ); + list.append( mapIdToStr[ Qtopia::AddressUid ] ); + list.append( mapIdToStr[ Qtopia::AddressCategory ] ); - list.append( mapIdToStr[ Qtopia::Spouse ] ); - list.append( mapIdToStr[ Qtopia::Gender ] ); - list.append( mapIdToStr[ Qtopia::Birthday ] ); - list.append( mapIdToStr[ Qtopia::Anniversary ] ); - list.append( mapIdToStr[ Qtopia::Nickname ] ); - list.append( mapIdToStr[ Qtopia::Children ] ); + list.append( mapIdToStr[ Qtopia::Title ] ); + list.append( mapIdToStr[ Qtopia::FirstName ] ); + list.append( mapIdToStr[ Qtopia::MiddleName ] ); + list.append( mapIdToStr[ Qtopia::LastName ] ); + list.append( mapIdToStr[ Qtopia::Suffix ] ); + list.append( mapIdToStr[ Qtopia::FileAs ] ); + + list.append( mapIdToStr[ Qtopia::JobTitle ] ); + list.append( mapIdToStr[ Qtopia::Department ] ); + list.append( mapIdToStr[ Qtopia::Company ] ); + + list.append( mapIdToStr[ Qtopia::Notes ] ); + list.append( mapIdToStr[ Qtopia::Groups ] ); if (sorted) list.sort(); return list; } /*! \internal - Returns a translated list of details field names for a contact. + Returns a list of details field names for a contact. */ -QStringList OContactFields::trdetailsfields( bool sorted ) +QStringList OContactFields::detailsfields( bool sorted, bool translated ) { QStringList list; - QMap<int, QString> mapIdToStr = idToTrFields(); + QMap<int, QString> mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); - list.append( mapIdToStr[Qtopia::Office] ); - list.append( mapIdToStr[Qtopia::Profession] ); - list.append( mapIdToStr[Qtopia::Assistant] ); - list.append( mapIdToStr[Qtopia::Manager] ); + list.append( mapIdToStr[ Qtopia::Office ] ); + list.append( mapIdToStr[ Qtopia::Profession ] ); + list.append( mapIdToStr[ Qtopia::Assistant ] ); + list.append( mapIdToStr[ Qtopia::Manager ] ); - list.append( mapIdToStr[Qtopia::Spouse] ); - list.append( mapIdToStr[Qtopia::Gender] ); - list.append( mapIdToStr[Qtopia::Birthday] ); - list.append( mapIdToStr[Qtopia::Anniversary] ); - list.append( mapIdToStr[Qtopia::Nickname] ); - list.append( mapIdToStr[Qtopia::Children] ); + list.append( mapIdToStr[ Qtopia::Spouse ] ); + list.append( mapIdToStr[ Qtopia::Gender ] ); + list.append( mapIdToStr[ Qtopia::Birthday ] ); + list.append( mapIdToStr[ Qtopia::Anniversary ] ); + list.append( mapIdToStr[ Qtopia::Nickname ] ); + list.append( mapIdToStr[ Qtopia::Children ] ); if (sorted) list.sort(); return list; } - /*! \internal - Returns a translated list of phone field names for a contact. + Returns a list of phone field names for a contact. */ -QStringList OContactFields::trphonefields( bool sorted ) +QStringList OContactFields::phonefields( bool sorted, bool translated ) { QStringList list; - QMap<int, QString> mapIdToStr = idToTrFields(); + QMap<int, QString> mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); list.append( mapIdToStr[Qtopia::BusinessPhone] ); list.append( mapIdToStr[Qtopia::BusinessFax] ); list.append( mapIdToStr[Qtopia::BusinessMobile] ); list.append( mapIdToStr[Qtopia::BusinessPager] ); list.append( mapIdToStr[Qtopia::BusinessWebPage] ); list.append( mapIdToStr[Qtopia::DefaultEmail] ); list.append( mapIdToStr[Qtopia::Emails] ); list.append( mapIdToStr[Qtopia::HomePhone] ); list.append( mapIdToStr[Qtopia::HomeFax] ); list.append( mapIdToStr[Qtopia::HomeMobile] ); // list.append( mapIdToStr[Qtopia::HomePager] ); list.append( mapIdToStr[Qtopia::HomeWebPage] ); if (sorted) list.sort(); return list; } - /*! \internal - Returns a list of phone field names for a contact. + Returns a list of field names for a contact. */ -QStringList OContactFields::untrphonefields( bool sorted ) +QStringList OContactFields::fields( bool sorted, bool translated ) { QStringList list; - QMap<int, QString> mapIdToStr = idToUntrFields(); - - list.append( mapIdToStr[ Qtopia::BusinessPhone ] ); - list.append( mapIdToStr[ Qtopia::BusinessFax ] ); - list.append( mapIdToStr[ Qtopia::BusinessMobile ] ); - list.append( mapIdToStr[ Qtopia::BusinessPager ] ); - list.append( mapIdToStr[ Qtopia::BusinessWebPage ] ); - - list.append( mapIdToStr[ Qtopia::DefaultEmail ] ); - list.append( mapIdToStr[ Qtopia::Emails ] ); + QMap<int, QString> mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); - list.append( mapIdToStr[ Qtopia::HomePhone ] ); - list.append( mapIdToStr[ Qtopia::HomeFax ] ); - list.append( mapIdToStr[ Qtopia::HomeMobile ] ); - //list.append( mapIdToStr[Qtopia::HomePager] ); - list.append( mapIdToStr[Qtopia::HomeWebPage] ); + list += personalfields( sorted, translated ); - if (sorted) list.sort(); - - return list; -} - - -/*! - \internal - Returns a translated list of field names for a contact. -*/ -QStringList OContactFields::trfields( bool sorted ) -{ - QStringList list; - QMap<int, QString> mapIdToStr = idToTrFields(); - - list.append( mapIdToStr[Qtopia::Title]); - list.append( mapIdToStr[Qtopia::FirstName] ); - list.append( mapIdToStr[Qtopia::MiddleName] ); - list.append( mapIdToStr[Qtopia::LastName] ); - list.append( mapIdToStr[Qtopia::Suffix] ); - list.append( mapIdToStr[Qtopia::FileAs] ); - - list.append( mapIdToStr[Qtopia::JobTitle] ); - list.append( mapIdToStr[Qtopia::Department] ); - list.append( mapIdToStr[Qtopia::Company] ); - - list += trphonefields( sorted ); + list += phonefields( sorted, translated ); list.append( mapIdToStr[Qtopia::BusinessStreet] ); list.append( mapIdToStr[Qtopia::BusinessCity] ); list.append( mapIdToStr[Qtopia::BusinessState] ); list.append( mapIdToStr[Qtopia::BusinessZip] ); list.append( mapIdToStr[Qtopia::BusinessCountry] ); list.append( mapIdToStr[Qtopia::HomeStreet] ); list.append( mapIdToStr[Qtopia::HomeCity] ); list.append( mapIdToStr[Qtopia::HomeState] ); list.append( mapIdToStr[Qtopia::HomeZip] ); list.append( mapIdToStr[Qtopia::HomeCountry] ); - list += trdetailsfields( sorted ); - - list.append( mapIdToStr[Qtopia::Notes] ); - list.append( mapIdToStr[Qtopia::Groups] ); + list += detailsfields( sorted, translated ); if (sorted) list.sort(); return list; } + /*! \internal - Returns an untranslated list of field names for a contact. + Returns an untranslated list of personal field names for a contact. */ -QStringList OContactFields::untrfields( bool sorted ) +QStringList OContactFields::untrpersonalfields( bool sorted ) { - QStringList list; - QMap<int, QString> mapIdToStr = idToUntrFields(); + return personalfields( sorted, false ); +} - list.append( mapIdToStr[ Qtopia::AddressUid ] ); - list.append( mapIdToStr[ Qtopia::AddressCategory ] ); - list.append( mapIdToStr[ Qtopia::Title ] ); - list.append( mapIdToStr[ Qtopia::FirstName ] ); - list.append( mapIdToStr[ Qtopia::MiddleName ] ); - list.append( mapIdToStr[ Qtopia::LastName ] ); - list.append( mapIdToStr[ Qtopia::Suffix ] ); - list.append( mapIdToStr[ Qtopia::FileAs ] ); +/*! + \internal + Returns a translated list of personal field names for a contact. +*/ +QStringList OContactFields::trpersonalfields( bool sorted ) +{ + return personalfields( sorted, true ); +} - list.append( mapIdToStr[ Qtopia::JobTitle ] ); - list.append( mapIdToStr[ Qtopia::Department ] ); - list.append( mapIdToStr[ Qtopia::Company ] ); - list += untrphonefields( sorted ); +/*! + \internal + Returns an untranslated list of details field names for a contact. +*/ +QStringList OContactFields::untrdetailsfields( bool sorted ) +{ + return detailsfields( sorted, false ); +} - list.append( mapIdToStr[ Qtopia::BusinessStreet ] ); - list.append( mapIdToStr[ Qtopia::BusinessCity ] ); - list.append( mapIdToStr[ Qtopia::BusinessState ] ); - list.append( mapIdToStr[ Qtopia::BusinessZip ] ); - list.append( mapIdToStr[ Qtopia::BusinessCountry ] ); - list.append( mapIdToStr[ Qtopia::HomeStreet ] ); - list.append( mapIdToStr[ Qtopia::HomeCity ] ); - list.append( mapIdToStr[ Qtopia::HomeState ] ); - list.append( mapIdToStr[ Qtopia::HomeZip ] ); - list.append( mapIdToStr[ Qtopia::HomeCountry ] ); +/*! + \internal + Returns a translated list of details field names for a contact. +*/ +QStringList OContactFields::trdetailsfields( bool sorted ) +{ + return detailsfields( sorted, true ); +} - list += untrdetailsfields( sorted ); - list.append( mapIdToStr[ Qtopia::Notes ] ); - list.append( mapIdToStr[ Qtopia::Groups ] ); +/*! + \internal + Returns a translated list of phone field names for a contact. +*/ +QStringList OContactFields::trphonefields( bool sorted ) +{ + return phonefields( sorted, true ); +} - if (sorted) list.sort(); +/*! + \internal + Returns an untranslated list of phone field names for a contact. +*/ +QStringList OContactFields::untrphonefields( bool sorted ) +{ + return phonefields( sorted, false ); +} - return list; + +/*! + \internal + Returns a translated list of field names for a contact. +*/ +QStringList OContactFields::trfields( bool sorted ) +{ + return fields( sorted, true ); +} + +/*! + \internal + Returns an untranslated list of field names for a contact. +*/ +QStringList OContactFields::untrfields( bool sorted ) +{ + return fields( sorted, false ); } + QMap<int, QString> OContactFields::idToTrFields() { QMap<int, QString> ret_map; ret_map.insert( Qtopia::AddressUid, QObject::tr( "User Id" ) ); ret_map.insert( Qtopia::AddressCategory, QObject::tr( "Categories" ) ); ret_map.insert( Qtopia::Title, QObject::tr( "Name Title") ); ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) ); ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) ); ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) ); ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" )); ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) ); ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) ); ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) ); ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) ); ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) ); ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) ); ret_map.insert( Qtopia::BusinessMobile, QObject::tr( "Business Mobile" )); // email ret_map.insert( Qtopia::DefaultEmail, QObject::tr( "Default Email" ) ); ret_map.insert( Qtopia::Emails, QObject::tr( "Emails" ) ); ret_map.insert( Qtopia::HomePhone, QObject::tr( "Home Phone" ) ); ret_map.insert( Qtopia::HomeFax, QObject::tr( "Home Fax" ) ); ret_map.insert( Qtopia::HomeMobile, QObject::tr( "Home Mobile" ) ); // business ret_map.insert( Qtopia::BusinessStreet, QObject::tr( "Business Street" ) ); ret_map.insert( Qtopia::BusinessCity, QObject::tr( "Business City" ) ); ret_map.insert( Qtopia::BusinessState, QObject::tr( "Business State" ) ); ret_map.insert( Qtopia::BusinessZip, QObject::tr( "Business Zip" ) ); ret_map.insert( Qtopia::BusinessCountry, QObject::tr( "Business Country" ) ); ret_map.insert( Qtopia::BusinessPager, QObject::tr( "Business Pager" ) ); ret_map.insert( Qtopia::BusinessWebPage, QObject::tr( "Business WebPage" ) ); ret_map.insert( Qtopia::Office, QObject::tr( "Office" ) ); ret_map.insert( Qtopia::Profession, QObject::tr( "Profession" ) ); ret_map.insert( Qtopia::Assistant, QObject::tr( "Assistant" ) ); ret_map.insert( Qtopia::Manager, QObject::tr( "Manager" ) ); // home ret_map.insert( Qtopia::HomeStreet, QObject::tr( "Home Street" ) ); ret_map.insert( Qtopia::HomeCity, QObject::tr( "Home City" ) ); ret_map.insert( Qtopia::HomeState, QObject::tr( "Home State" ) ); ret_map.insert( Qtopia::HomeZip, QObject::tr( "Home Zip" ) ); ret_map.insert( Qtopia::HomeCountry, QObject::tr( "Home Country" ) ); ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) ); //personal ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) ); ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) ); ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) ); ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) ); ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) ); ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) ); // other ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) ); return ret_map; } QMap<int, QString> OContactFields::idToUntrFields() { QMap<int, QString> ret_map; ret_map.insert( Qtopia::AddressUid, "User Id" ); ret_map.insert( Qtopia::AddressCategory, "Categories" ); ret_map.insert( Qtopia::Title, "Name Title" ); ret_map.insert( Qtopia::FirstName, "First Name" ); ret_map.insert( Qtopia::MiddleName, "Middle Name" ); ret_map.insert( Qtopia::LastName, "Last Name" ); ret_map.insert( Qtopia::Suffix, "Suffix" ); ret_map.insert( Qtopia::FileAs, "File As" ); ret_map.insert( Qtopia::JobTitle, "Job Title" ); ret_map.insert( Qtopia::Department, "Department" ); ret_map.insert( Qtopia::Company, "Company" ); ret_map.insert( Qtopia::BusinessPhone, "Business Phone" ); ret_map.insert( Qtopia::BusinessFax, "Business Fax" ); ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" ); // email ret_map.insert( Qtopia::DefaultEmail, "Default Email" ); ret_map.insert( Qtopia::Emails, "Emails" ); ret_map.insert( Qtopia::HomePhone, "Home Phone" ); ret_map.insert( Qtopia::HomeFax, "Home Fax" ); ret_map.insert( Qtopia::HomeMobile, "Home Mobile" ); // business ret_map.insert( Qtopia::BusinessStreet, "Business Street" ); ret_map.insert( Qtopia::BusinessCity, "Business City" ); ret_map.insert( Qtopia::BusinessState, "Business State" ); ret_map.insert( Qtopia::BusinessZip, "Business Zip" ); ret_map.insert( Qtopia::BusinessCountry, "Business Country" ); ret_map.insert( Qtopia::BusinessPager, "Business Pager" ); ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" ); ret_map.insert( Qtopia::Office, "Office" ); ret_map.insert( Qtopia::Profession, "Profession" ); ret_map.insert( Qtopia::Assistant, "Assistant" ); ret_map.insert( Qtopia::Manager, "Manager" ); // home ret_map.insert( Qtopia::HomeStreet, "Home Street" ); ret_map.insert( Qtopia::HomeCity, "Home City" ); ret_map.insert( Qtopia::HomeState, "Home State" ); ret_map.insert( Qtopia::HomeZip, "Home Zip" ); ret_map.insert( Qtopia::HomeCountry, "Home Country" ); ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" ); //personal ret_map.insert( Qtopia::Spouse, "Spouse" ); - ret_map.insert( Qtopia::Gender, "Gender" ); + ret_map.insert( Qtopia::Gender, "Gender" ); ret_map.insert( Qtopia::Birthday, "Birthday" ); ret_map.insert( Qtopia::Anniversary, "Anniversary" ); ret_map.insert( Qtopia::Nickname, "Nickname" ); ret_map.insert( Qtopia::Children, "Children" ); // other ret_map.insert( Qtopia::Notes, "Notes" ); ret_map.insert( Qtopia::Groups, "Groups" ); return ret_map; } QMap<QString, int> OContactFields::trFieldsToId() { QMap<int, QString> idtostr = idToTrFields(); QMap<QString, int> ret_map; QMap<int, QString>::Iterator it; for( it = idtostr.begin(); it != idtostr.end(); ++it ) ret_map.insert( *it, it.key() ); return ret_map; } +/* ======================================================================= */ + QMap<QString, int> OContactFields::untrFieldsToId() { QMap<int, QString> idtostr = idToUntrFields(); QMap<QString, int> ret_map; QMap<int, QString>::Iterator it; for( it = idtostr.begin(); it != idtostr.end(); ++it ) ret_map.insert( *it, it.key() ); return ret_map; } OContactFields::OContactFields(): fieldOrder( DEFAULT_FIELD_ORDER ), changedFieldOrder( false ) { // Get the global field order from the config file and // use it as a start pattern Config cfg ( "AddressBook" ); cfg.setGroup( "ContactFieldOrder" ); globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER ); } OContactFields::~OContactFields(){ // We will store the fieldorder into the config file // to reuse it for the future.. if ( changedFieldOrder ){ Config cfg ( "AddressBook" ); cfg.setGroup( "ContactFieldOrder" ); cfg.writeEntry( "General", globalFieldOrder ); } } void OContactFields::saveToRecord( OContact &cnt ){ qDebug("ocontactfields saveToRecord: >%s<",fieldOrder.latin1()); // Store fieldorder into this contact. cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder ); globalFieldOrder = fieldOrder; changedFieldOrder = true; } void OContactFields::loadFromRecord( const OContact &cnt ){ qDebug("ocontactfields loadFromRecord"); qDebug("loading >%s<",cnt.fullName().latin1()); // Get fieldorder for this contact. If none is defined, // we will use the global one from the config file.. fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME ); qDebug("fieldOrder from contact>%s<",fieldOrder.latin1()); if (fieldOrder.isEmpty()){ fieldOrder = globalFieldOrder; } qDebug("effective fieldOrder in loadFromRecord >%s<",fieldOrder.latin1()); } void OContactFields::setFieldOrder( int num, int index ){ qDebug("qcontactfields setfieldorder pos %i -> %i",num,index); fieldOrder[num] = QString::number( index, 16 )[0]; // We will store this new fieldorder globally to // remember it for contacts which have none globalFieldOrder = fieldOrder; changedFieldOrder = true; qDebug("fieldOrder >%s<",fieldOrder.latin1()); } int OContactFields::getFieldOrder( int num, int defIndex ){ qDebug("ocontactfields getFieldOrder"); qDebug("fieldOrder >%s<",fieldOrder.latin1()); // Get index of combo as char.. QChar poschar = fieldOrder[num]; bool ok; int ret = 0; // Convert char to number.. if ( !( poschar == QChar::null ) ) ret = QString( poschar ).toInt(&ok, 16); else ok = false; // Return default value if index for // num was not set or if anything else happened.. if ( !ok ) ret = defIndex; qDebug("returning >%i<",ret); return ret; } diff --git a/libopie2/opiepim/ocontactfields.h b/libopie2/opiepim/ocontactfields.h index 9f6171b..f105de7 100644 --- a/libopie2/opiepim/ocontactfields.h +++ b/libopie2/opiepim/ocontactfields.h @@ -1,60 +1,67 @@ #ifndef OPIE_CONTACTS_FIELDS #define OPIE_CONTACTS_FIELDS class QStringList; #include <qmap.h> #include <qstring.h> #include <opie/ocontact.h> #define CONTACT_FIELD_ORDER_NAME "opie-contactfield-order" #define DEFAULT_FIELD_ORDER "__________" class OContactFields{ public: OContactFields(); ~OContactFields(); /** Set the index for combo boxes. * Sets the <b>index</b> of combo <b>num</b>. * @param num selects the number of the combo * @param index sets the index in the combo */ void setFieldOrder( int num, int index ); /** Get the index for combo boxes. * Returns the index of combo <b>num</b> or defindex * if none was defined.. * @param num Selects the number of the combo * @param defIndex will be returned if none was defined (either * globally in the config file, nor by the contact which was used * by loadFromRecord() ) */ int getFieldOrder( int num, int defIndex); /** Store fieldorder to contact. */ void saveToRecord( OContact& ); /** Get Fieldorder from contact. */ void loadFromRecord( const OContact& ); private: QString fieldOrder; QString globalFieldOrder; bool changedFieldOrder; public: + static QStringList personalfields( bool sorted = true, bool translated = false ); + static QStringList phonefields( bool sorted = true, bool translated = false ); + static QStringList detailsfields( bool sorted = true, bool translated = false ); + static QStringList fields( bool sorted = true, bool translated = false ); + + static QStringList trpersonalfields( bool sorted = true ); + static QStringList untrpersonalfields( bool sorted = true ); static QStringList trphonefields( bool sorted = true ); static QStringList untrphonefields( bool sorted = true ); static QStringList trdetailsfields( bool sorted = true ); static QStringList untrdetailsfields( bool sorted = true ); static QStringList trfields( bool sorted = true ); static QStringList untrfields( bool sorted = true ); static QMap<int, QString> idToTrFields(); static QMap<QString, int> trFieldsToId(); static QMap<int, QString> idToUntrFields(); static QMap<QString, int> untrFieldsToId(); }; #endif |