From 911473db35a9fce5f3589f03c27210456faaba86 Mon Sep 17 00:00:00 2001 From: mickeyl Date: Tue, 24 Feb 2004 12:46:23 +0000 Subject: *phew* here is the class and file rename patch. not converted yet: backend, but that will be not visible to application classes so we can change it later. --- (limited to 'libopie2/opiepim/core') diff --git a/libopie2/opiepim/core/core.pro b/libopie2/opiepim/core/core.pro index 0473622..597b1e8 100644 --- a/libopie2/opiepim/core/core.pro +++ b/libopie2/opiepim/core/core.pro @@ -1,4 +1,5 @@ -HEADERS += core/oconversion.h \ +HEADERS += \ + core/opimdateconversion.h \ core/opimcache.h \ core/opimmaintainer.h \ core/opimresolver.h \ @@ -6,16 +7,17 @@ HEADERS += core/oconversion.h \ core/opimxref.h \ core/opimxrefmanager.h \ core/opimxrefpartner.h \ - core/orecur.h \ - core/otemplatebase.h \ - core/otimezone.h + core/opimrecurrence.h \ + core/opimtemplatebase.h \ + core/opimtimezone.h -SOURCES += core/oconversion.cpp \ +SOURCES += \ + core/opimdateconversion.cpp \ core/opimmaintainer.cpp \ core/opimresolver.cpp \ core/opimstate.cpp \ core/opimxref.cpp \ core/opimxrefmanager.cpp \ core/opimxrefpartner.cpp \ - core/orecur.cpp \ - core/otimezone.cpp + core/opimrecurrence.cpp \ + core/opimtimezone.cpp diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp index f67a40c..c12e138 100644 --- a/libopie2/opiepim/core/ocontactaccess.cpp +++ b/libopie2/opiepim/core/ocontactaccess.cpp @@ -55,20 +55,20 @@ namespace Opie { -OContactAccess::OContactAccess ( const QString appname, const QString , - OContactAccessBackend* end, bool autosync ): - OPimAccessTemplate( end ) +OPimContactAccess::OPimContactAccess ( const QString appname, const QString , + OPimContactAccessBackend* end, bool autosync ): + OPimAccessTemplate( end ) { /* take care of the backend. If there is no one defined, we * will use the XML-Backend as default (until we have a cute SQL-Backend..). */ if( end == 0 ) { qWarning ("Using BackendFactory !"); - end = OBackendFactory::Default( "contact", appname ); + end = OBackendFactory::Default( "contact", appname ); } // Set backend locally and in template m_backEnd = end; - OPimAccessTemplate::setBackEnd (end); + OPimAccessTemplate::setBackEnd (end); /* Connect signal of external db change to function */ @@ -83,7 +83,7 @@ OContactAccess::OContactAccess ( const QString appname, const QString , } -OContactAccess::~OContactAccess () +OPimContactAccess::~OPimContactAccess () { /* The user may forget to save the changed database, therefore try to * do it for him.. @@ -93,16 +93,16 @@ OContactAccess::~OContactAccess () } -bool OContactAccess::save () +bool OPimContactAccess::save () { /* If the database was changed externally, we could not save the * Data. This will remove added items which is unacceptable ! * Therefore: Reload database and merge the data... */ - if ( OPimAccessTemplate::wasChangedExternally() ) + if ( OPimAccessTemplate::wasChangedExternally() ) reload(); - bool status = OPimAccessTemplate::save(); + bool status = OPimAccessTemplate::save(); if ( !status ) return false; /* Now tell everyone that new data is available. @@ -112,38 +112,38 @@ bool OContactAccess::save () return true; } -const uint OContactAccess::querySettings() +const uint OPimContactAccess::querySettings() { return ( m_backEnd->querySettings() ); } -bool OContactAccess::hasQuerySettings ( int querySettings ) const +bool OPimContactAccess::hasQuerySettings ( int querySettings ) const { return ( m_backEnd->hasQuerySettings ( querySettings ) ); } -ORecordList OContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const +OPimRecordList OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const { QArray matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); - return ( ORecordList(matchingContacts, this) ); + return ( OPimRecordList(matchingContacts, this) ); } -bool OContactAccess::wasChangedExternally()const +bool OPimContactAccess::wasChangedExternally()const { return ( m_backEnd->wasChangedExternally() ); } -void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) +void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) { if ( msg == "addressbookUpdated()" ){ - qWarning ("OContactAccess: Received addressbokUpdated()"); + qWarning ("OPimContactAccess: Received addressbokUpdated()"); emit signalChanged ( this ); } else if ( msg == "flush()" ) { - qWarning ("OContactAccess: Received flush()"); + qWarning ("OPimContactAccess: Received flush()"); save (); } else if ( msg == "reload()" ) { - qWarning ("OContactAccess: Received reload()"); + qWarning ("OPimContactAccess: Received reload()"); reload (); emit signalChanged ( this ); } diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h index 505c87b..cf5333a 100644 --- a/libopie2/opiepim/core/ocontactaccess.h +++ b/libopie2/opiepim/core/ocontactaccess.h @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include @@ -55,7 +55,7 @@ namespace Opie { * @author Stefan Eilers, Holger Freyther * @see OPimAccessTemplate */ -class OContactAccess: public QObject, public OPimAccessTemplate +class OPimContactAccess: public QObject, public OPimAccessTemplate { Q_OBJECT @@ -72,11 +72,11 @@ class OContactAccess: public QObject, public OPimAccessTemplate * automatically if it receives the signals flush() and reload() * which are used before and after synchronisation. If the application wants * to react itself, it should be disabled by setting it to false - * @see OContactAccessBackend + * @see OPimContactAccessBackend */ - OContactAccess (const QString appname, const QString filename = 0l, - OContactAccessBackend* backend = 0l, bool handlesync = true); - ~OContactAccess (); + OPimContactAccess (const QString appname, const QString filename = 0l, + OPimContactAccessBackend* backend = 0l, bool handlesync = true); + ~OPimContactAccess (); /** Constants for query. * Use this constants to set the query parameters. @@ -135,13 +135,13 @@ class OContactAccess: public QObject, public OPimAccessTemplate * is useful if an application has to handle multiple databases at the same time. * @see reload() */ - void signalChanged ( const OContactAccess *which ); + void signalChanged ( const OPimContactAccess *which ); private: - // class OContactAccessPrivate; - // OContactAccessPrivate* d; - OContactAccessBackend *m_backEnd; + // class OPimContactAccessPrivate; + // OPimContactAccessPrivate* d; + OPimContactAccessBackend *m_backEnd; bool m_loading:1; private slots: diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp index 8c527f6..ac310c1 100644 --- a/libopie2/opiepim/core/odatebookaccess.cpp +++ b/libopie2/opiepim/core/odatebookaccess.cpp @@ -38,7 +38,7 @@ namespace Opie { * @param ac What kind of access is intended */ ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) - : OPimAccessTemplate( back ) + : OPimAccessTemplate( back ) { if (!back ) back = OBackendFactory::Default("datebook", QString::null ); diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h index 38dc754..6c9290f 100644 --- a/libopie2/opiepim/core/odatebookaccess.h +++ b/libopie2/opiepim/core/odatebookaccess.h @@ -32,7 +32,7 @@ #include "odatebookaccessbackend.h" #include "opimaccesstemplate.h" -#include +#include namespace Opie { /** @@ -44,7 +44,7 @@ namespace Opie { * * @author Holger Freyther, Stefan Eilers */ -class ODateBookAccess : public OPimAccessTemplate { +class ODateBookAccess : public OPimAccessTemplate { public: ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); ~ODateBookAccess(); diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 5826cbc..f1bcc44 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h @@ -33,10 +33,10 @@ #include #include -#include +#include #include -#include +#include namespace Opie { @@ -57,7 +57,7 @@ public: Random = 0, SortedAccess }; - typedef ORecordList List; + typedef OPimRecordList List; typedef OPimAccessBackend BackEnd; typedef OPimCache Cache; diff --git a/libopie2/opiepim/core/opimcontact.cpp b/libopie2/opiepim/core/opimcontact.cpp new file mode 100644 index 0000000..a5df597 --- a/dev/null +++ b/libopie2/opiepim/core/opimcontact.cpp @@ -0,0 +1,1293 @@ +/* + This file is part of the Opie Project + Copyright (C) Stefan Eilers + =. Copyright (C) The Opie Team + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#define QTOPIA_INTERNAL_CONTACT_MRE + +#include "opimcontact.h" + +/* OPIE */ +#include +#include +#include +#include +#include + +/* QT */ +#include +#include +#include +#include +#include + +/* STD */ +#include + +/*! + \class Contact contact.h + \brief The Contact class holds the data of an address book entry. + + This data includes information the name of the person, contact + information, and business information such as deparment and job title. + + \ingroup qtopiaemb + \ingroup qtopiadesktop +*/ + + +namespace Opie +{ +/*! + Creates a new, empty contact. +*/ +OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 ) +{} + +/*! + \internal + Creates a new contact. The properties of the contact are + set from \a fromMap. +*/ +OPimContact::OPimContact( const QMap &fromMap ):OPimRecord(), mMap( fromMap ), d( 0 ) +{ + QString cats = mMap[ Qtopia::AddressCategory ]; + if ( !cats.isEmpty() ) + setCategories( idsFromString( cats ) ); + + QString uidStr = find( Qtopia::AddressUid ); + + if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) ) + { + qWarning( "Invalid UID found. Generate new one.." ); + setUid( uidGen().generate() ); + } + else + setUid( uidStr.toInt() ); + + // if ( !uidStr.isEmpty() ) + // setUid( uidStr.toInt() ); +} + +/*! + Destroys a contact. +*/ +OPimContact::~OPimContact() +{} + +/*! \fn void OPimContact::setTitle( const QString &str ) + Sets the title of the contact to \a str. +*/ + +/*! \fn void OPimContact::setFirstName( const QString &str ) + Sets the first name of the contact to \a str. +*/ + +/*! \fn void OPimContact::setMiddleName( const QString &str ) + Sets the middle name of the contact to \a str. +*/ + +/*! \fn void OPimContact::setLastName( const QString &str ) + Sets the last name of the contact to \a str. +*/ + +/*! \fn void OPimContact::setSuffix( const QString &str ) + Sets the suffix of the contact to \a str. +*/ + +/*! \fn void OPimContact::setFileAs( const QString &str ) + Sets the contact to filed as \a str. +*/ + +/*! \fn void OPimContact::setDefaultEmail( const QString &str ) + Sets the default email of the contact to \a str. +*/ + +/*! \fn void OPimContact::setHomeStreet( const QString &str ) + Sets the home street address of the contact to \a str. +*/ + +/*! \fn void OPimContact::setHomeCity( const QString &str ) + Sets the home city of the contact to \a str. +*/ + +/*! \fn void OPimContact::setHomeState( const QString &str ) + Sets the home state of the contact to \a str. +*/ + +/*! \fn void OPimContact::setHomeZip( const QString &str ) + Sets the home zip code of the contact to \a str. +*/ + +/*! \fn void OPimContact::setHomeCountry( const QString &str ) + Sets the home country of the contact to \a str. +*/ + +/*! \fn void OPimContact::setHomePhone( const QString &str ) + Sets the home phone number of the contact to \a str. +*/ + +/*! \fn void OPimContact::setHomeFax( const QString &str ) + Sets the home fax number of the contact to \a str. +*/ + +/*! \fn void OPimContact::setHomeMobile( const QString &str ) + Sets the home mobile phone number of the contact to \a str. +*/ + +/*! \fn void OPimContact::setHomeWebpage( const QString &str ) + Sets the home webpage of the contact to \a str. +*/ + +/*! \fn void OPimContact::setCompany( const QString &str ) + Sets the company for contact to \a str. +*/ + +/*! \fn void OPimContact::setJobTitle( const QString &str ) + Sets the job title of the contact to \a str. +*/ + +/*! \fn void OPimContact::setDepartment( const QString &str ) + Sets the department for contact to \a str. +*/ + +/*! \fn void OPimContact::setOffice( const QString &str ) + Sets the office for contact to \a str. +*/ + +/*! \fn void OPimContact::setBusinessStreet( const QString &str ) + Sets the business street address of the contact to \a str. +*/ + +/*! \fn void OPimContact::setBusinessCity( const QString &str ) + Sets the business city of the contact to \a str. +*/ + +/*! \fn void OPimContact::setBusinessState( const QString &str ) + Sets the business state of the contact to \a str. +*/ + +/*! \fn void OPimContact::setBusinessZip( const QString &str ) + Sets the business zip code of the contact to \a str. +*/ + +/*! \fn void OPimContact::setBusinessCountry( const QString &str ) + Sets the business country of the contact to \a str. +*/ + +/*! \fn void OPimContact::setBusinessPhone( const QString &str ) + Sets the business phone number of the contact to \a str. +*/ + +/*! \fn void OPimContact::setBusinessFax( const QString &str ) + Sets the business fax number of the contact to \a str. +*/ + +/*! \fn void OPimContact::setBusinessMobile( const QString &str ) + Sets the business mobile phone number of the contact to \a str. +*/ + +/*! \fn void OPimContact::setBusinessPager( const QString &str ) + Sets the business pager number of the contact to \a str. +*/ + +/*! \fn void OPimContact::setBusinessWebpage( const QString &str ) + Sets the business webpage of the contact to \a str. +*/ + +/*! \fn void OPimContact::setProfession( const QString &str ) + Sets the profession of the contact to \a str. +*/ + +/*! \fn void OPimContact::setAssistant( const QString &str ) + Sets the assistant of the contact to \a str. +*/ + +/*! \fn void OPimContact::setManager( const QString &str ) + Sets the manager of the contact to \a str. +*/ + +/*! \fn void OPimContact::setSpouse( const QString &str ) + Sets the spouse of the contact to \a str. +*/ + +/*! \fn void OPimContact::setGender( const QString &str ) + Sets the gender of the contact to \a str. +*/ + +/*! \fn void OPimContact::setNickname( const QString &str ) + Sets the nickname of the contact to \a str. +*/ + +/*! \fn void OPimContact::setNotes( const QString &str ) + Sets the notes about the contact to \a str. +*/ + +/*! \fn QString OPimContact::title() const + Returns the title of the contact. +*/ + +/*! \fn QString OPimContact::firstName() const + Returns the first name of the contact. +*/ + +/*! \fn QString OPimContact::middleName() const + Returns the middle name of the contact. +*/ + +/*! \fn QString OPimContact::lastName() const + Returns the last name of the contact. +*/ + +/*! \fn QString OPimContact::suffix() const + Returns the suffix of the contact. +*/ + +/*! \fn QString OPimContact::fileAs() const + Returns the string the contact is filed as. +*/ + +/*! \fn QString OPimContact::defaultEmail() const + Returns the default email address of the contact. +*/ + +/*! \fn QString OPimContact::emails() const + Returns the list of email address for a contact separated by ';'s in a single + string. +*/ + +/*! \fn QString OPimContact::homeStreet() const + Returns the home street address of the contact. +*/ + +/*! \fn QString OPimContact::homeCity() const + Returns the home city of the contact. +*/ + +/*! \fn QString OPimContact::homeState() const + Returns the home state of the contact. +*/ + +/*! \fn QString OPimContact::homeZip() const + Returns the home zip of the contact. +*/ + +/*! \fn QString OPimContact::homeCountry() const + Returns the home country of the contact. +*/ + +/*! \fn QString OPimContact::homePhone() const + Returns the home phone number of the contact. +*/ + +/*! \fn QString OPimContact::homeFax() const + Returns the home fax number of the contact. +*/ + +/*! \fn QString OPimContact::homeMobile() const + Returns the home mobile number of the contact. +*/ + +/*! \fn QString OPimContact::homeWebpage() const + Returns the home webpage of the contact. +*/ + +/*! \fn QString OPimContact::company() const + Returns the company for the contact. +*/ + +/*! \fn QString OPimContact::department() const + Returns the department for the contact. +*/ + +/*! \fn QString OPimContact::office() const + Returns the office for the contact. +*/ + +/*! \fn QString OPimContact::jobTitle() const + Returns the job title of the contact. +*/ + +/*! \fn QString OPimContact::profession() const + Returns the profession of the contact. +*/ + +/*! \fn QString OPimContact::assistant() const + Returns the assistant of the contact. +*/ + +/*! \fn QString OPimContact::manager() const + Returns the manager of the contact. +*/ + +/*! \fn QString OPimContact::businessStreet() const + Returns the business street address of the contact. +*/ + +/*! \fn QString OPimContact::businessCity() const + Returns the business city of the contact. +*/ + +/*! \fn QString OPimContact::businessState() const + Returns the business state of the contact. +*/ + +/*! \fn QString OPimContact::businessZip() const + Returns the business zip of the contact. +*/ + +/*! \fn QString OPimContact::businessCountry() const + Returns the business country of the contact. +*/ + +/*! \fn QString OPimContact::businessPhone() const + Returns the business phone number of the contact. +*/ + +/*! \fn QString OPimContact::businessFax() const + Returns the business fax number of the contact. +*/ + +/*! \fn QString OPimContact::businessMobile() const + Returns the business mobile number of the contact. +*/ + +/*! \fn QString OPimContact::businessPager() const + Returns the business pager number of the contact. +*/ + +/*! \fn QString OPimContact::businessWebpage() const + Returns the business webpage of the contact. +*/ + +/*! \fn QString OPimContact::spouse() const + Returns the spouse of the contact. +*/ + +/*! \fn QString OPimContact::gender() const + Returns the gender of the contact. +*/ + +/*! \fn QString OPimContact::nickname() const + Returns the nickname of the contact. +*/ + +/*! \fn QString OPimContact::children() const + Returns the children of the contact. +*/ + +/*! \fn QString OPimContact::notes() const + Returns the notes relating to the the contact. +*/ + +/*! \fn QString OPimContact::groups() const + \internal + Returns the groups for the contact. +*/ + +/*! \fn QStringList OPimContact::groupList() const + \internal +*/ + +/*! \fn QString OPimContact::field(int) const + \internal +*/ + +/*! \fn void OPimContact::saveJournal( journal_action, const QString & = QString::null ) + \internal +*/ + +/*! \fn void OPimContact::setUid( int id ) + \internal + Sets the uid for this record to \a id. +*/ + +/*! \enum OPimContact::journal_action + \internal +*/ + +/*! + \internal +*/ +QMap OPimContact::toMap() const +{ + QMap map = mMap; + QString cats = idsToString( categories() ); + if ( !cats.isEmpty() ) + map.insert( Qtopia::AddressCategory, cats ); + return map; +} + +/*! + Returns a rich text formatted QString representing the contents the contact. +*/ +QString OPimContact::toRichText() const +{ + QString text; + QString value, comp, state; + QString str; + bool marker = false; + + Config cfg( "qpe" ); + cfg.setGroup( "Appearance" ); + int addressformat = cfg.readNumEntry( "AddressFormat", Zip_City_State ); + + // name, jobtitle and company + if ( !( value = fullName() ).isEmpty() ) + text += "

" + Qtopia::escapeString( value ) + "

"; + + if ( !( value = jobTitle() ).isEmpty() ) + text += Qtopia::escapeString( value ) + " "; + + comp = company(); + if ( !( value = department() ).isEmpty() ) + { + text += Qtopia::escapeString( value ); + if ( comp ) + text += ", " + Qtopia::escapeString( comp ); + } + else if ( comp ) + text += "
" + Qtopia::escapeString( comp ); + text += "

"; + + // defailt email + QString defEmail = defaultEmail(); + if ( !defEmail.isEmpty() ) + { + text += " " + QObject::tr( "Default Email: " ) + "" + + Qtopia::escapeString( defEmail ); + marker = true; + } + + // business address + if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || + !businessZip().isEmpty() || !businessCountry().isEmpty() ) + { + text += QObject::tr( "
Work Address:" ); + marker = true; + } + + if ( !( value = businessStreet() ).isEmpty() ) + { + text += "
" + Qtopia::escapeString( value ); + marker = true; + } + + switch ( addressformat ) + { + case Zip_City_State: + { // Zip_Code City, State + state = businessState(); + if ( !( value = businessZip() ).isEmpty() ) + { + text += "
" + Qtopia::escapeString( value ) + " "; + marker = true; + + } + if ( !( value = businessCity() ).isEmpty() ) + { + marker = true; + if ( businessZip().isEmpty() && !businessStreet().isEmpty() ) + text += "
"; + text += Qtopia::escapeString( value ); + if ( state ) + text += ", " + Qtopia::escapeString( state ); + } + else if ( !state.isEmpty() ) + { + text += "
" + Qtopia::escapeString( state ); + marker = true; + } + break; + } + case City_State_Zip: + { // City, State Zip_Code + state = businessState(); + if ( !( value = businessCity() ).isEmpty() ) + { + marker = true; + text += "
" + Qtopia::escapeString( value ); + if ( state ) + text += ", " + Qtopia::escapeString( state ); + } + else if ( !state.isEmpty() ) + { + text += "
" + Qtopia::escapeString( state ); + marker = true; + } + if ( !( value = businessZip() ).isEmpty() ) + { + text += " " + Qtopia::escapeString( value ); + marker = true; + } + break; + } + } + + if ( !( value = businessCountry() ).isEmpty() ) + { + text += "
" + Qtopia::escapeString( value ); + marker = true; + } + + // rest of Business data + str = office(); + if ( !str.isEmpty() ) + { + text += "
" + QObject::tr( "Office: " ) + "" + + Qtopia::escapeString( str ); + marker = true; + } + str = businessWebpage(); + if ( !str.isEmpty() ) + { + text += "
" + QObject::tr( "Business Web Page: " ) + "" + + Qtopia::escapeString( str ); + marker = true; + } + str = businessPhone(); + if ( !str.isEmpty() ) + { + text += "
" + QObject::tr( "Business Phone: " ) + "" + + Qtopia::escapeString( str ); + marker = true; + } + str = businessFax(); + if ( !str.isEmpty() ) + { + text += "
" + QObject::tr( "Business Fax: " ) + "" + + Qtopia::escapeString( str ); + marker = true; + } + str = businessMobile(); + if ( !str.isEmpty() ) + { + text += "
" + QObject::tr( "Business Mobile: " ) + "" + + Qtopia::escapeString( str ); + marker = true; + } + str = businessPager(); + if ( !str.isEmpty() ) + { + text += "
" + QObject::tr( "Business Pager: " ) + "" + + Qtopia::escapeString( str ); + marker = true; + } + + // text += "
"; + + // home address + if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || + !homeZip().isEmpty() || !homeCountry().isEmpty() ) + { + text += QObject::tr( "
Home Address:" ); + marker = true; + } + + if ( !( value = homeStreet() ).isEmpty() ) + { + text += "
" + Qtopia::escapeString( value ); + marker = true; + } + + switch ( addressformat ) + { + case Zip_City_State: + { // Zip_Code City, State + state = homeState(); + if ( !( value = homeZip() ).isEmpty() ) + { + text += "
" + Qtopia::escapeString( value ) + " "; + marker = true; + } + if ( !( value = homeCity() ).isEmpty() ) + { + marker = true; + if ( homeZip().isEmpty() && !homeStreet().isEmpty() ) + text += "
"; + text += Qtopia::escapeString( value ); + if ( !state.isEmpty() ) + text += ", " + Qtopia::escapeString( state ); + } + else if ( !state.isEmpty() ) + { + text += "
" + Qtopia::escapeString( state ); + marker = true; + } + break; + } + case City_State_Zip: + { // City, State Zip_Code + state = homeState(); + if ( !( value = homeCity() ).isEmpty() ) + { + marker = true; + text += "
" + Qtopia::escapeString( value ); + if ( state ) + text += ", " + Qtopia::escapeString( state ); + } + else if ( !state.isEmpty() ) + { + text += "
" + Qtopia::escapeString( state ); + marker = true; + } + if ( !( value = homeZip() ).isEmpty() ) + { + text += " " + Qtopia::escapeString( value ); + marker = true; + } + break; + } + } + + if ( !( value = homeCountry() ).isEmpty() ) + { + text += "
" + Qtopia::escapeString( value ); + marker = true; + } + + // rest of Home data + str = homeWebpage(); + if ( !str.isEmpty() ) + { + text += "
" + QObject::tr( "Home Web Page: " ) + "" + + Qtopia::escapeString( str ); + marker = true; + } + str = homePhone(); + if ( !str.isEmpty() ) + { + text += "
" + QObject::tr( "Home Phone: " ) + "" + + Qtopia::escapeString( str ); + marker = true; + } + str = homeFax(); + if ( !str.isEmpty() ) + { + text += "
" + QObject::tr( "Home Fax: " ) + "" + + Qtopia::escapeString( str ); + marker = true; + } + str = homeMobile(); + if ( !str.isEmpty() ) + { + text += "
" + QObject::tr( "Home Mobile: " ) + "" + + Qtopia::escapeString( str ); + marker = true; + } + + if ( marker ) + text += "

"; + + // the rest... + str = emails(); + if ( !str.isEmpty() && ( str != defEmail ) ) + text += "
" + QObject::tr( "All Emails: " ) + "" + + Qtopia::escapeString( str ); + str = profession(); + if ( !str.isEmpty() ) + text += "
" + QObject::tr( "Profession: " ) + "" + + Qtopia::escapeString( str ); + str = assistant(); + if ( !str.isEmpty() ) + text += "
" + QObject::tr( "Assistant: " ) + "" + + Qtopia::escapeString( str ); + str = manager(); + if ( !str.isEmpty() ) + text += "
" + QObject::tr( "Manager: " ) + "" + + Qtopia::escapeString( str ); + str = gender(); + if ( !str.isEmpty() && str.toInt() != 0 ) + { + text += "
"; + if ( str.toInt() == 1 ) + str = QObject::tr( "Male" ); + else if ( str.toInt() == 2 ) + str = QObject::tr( "Female" ); + text += "" + QObject::tr( "Gender: " ) + "" + str; + } + str = spouse(); + if ( !str.isEmpty() ) + text += "
" + QObject::tr( "Spouse: " ) + "" + + Qtopia::escapeString( str ); + if ( birthday().isValid() ) + { + str = TimeString::numberDateString( birthday() ); + text += "
" + QObject::tr( "Birthday: " ) + "" + + Qtopia::escapeString( str ); + } + if ( anniversary().isValid() ) + { + str = TimeString::numberDateString( anniversary() ); + text += "
" + QObject::tr( "Anniversary: " ) + "" + + Qtopia::escapeString( str ); + } + str = children(); + if ( !str.isEmpty() ) + text += "
" + QObject::tr( "Children: " ) + "" + + Qtopia::escapeString( str ); + + str = nickname(); + if ( !str.isEmpty() ) + text += "
" + QObject::tr( "Nickname: " ) + "" + + Qtopia::escapeString( str ); + + // categories + if ( categoryNames( "Contacts" ).count() ) + { + text += "
" + QObject::tr( "Category:" ) + " "; + text += categoryNames( "Contacts" ).join( ", " ); + } + + // notes last + if ( !( value = notes() ).isEmpty() ) + { + text += "

" + QObject::tr( "Notes:" ) + " "; + QRegExp reg( "\n" ); + + //QString tmp = Qtopia::escapeString(value); + QString tmp = QStyleSheet::convertFromPlainText( value ); + //tmp.replace( reg, "
" ); + text += "
" + tmp + "
"; + } + return text; +} + +/*! + \internal +*/ +void OPimContact::insert( int key, const QString &v ) +{ + QString value = v.stripWhiteSpace(); + if ( value.isEmpty() ) + mMap.remove( key ); + else + mMap.insert( key, value ); +} + +/*! + \internal +*/ +void OPimContact::replace( int key, const QString & v ) +{ + QString value = v.stripWhiteSpace(); + if ( value.isEmpty() ) + mMap.remove( key ); + else + mMap.replace( key, value ); +} + +/*! + \internal +*/ +QString OPimContact::find( int key ) const +{ + return mMap[ key ]; +} + +/*! + \internal +*/ +QString OPimContact::displayAddress( const QString &street, + const QString &city, + const QString &state, + const QString &zip, + const QString &country ) const +{ + QString s = street; + if ( !street.isEmpty() ) + s += "\n"; + s += city; + if ( !city.isEmpty() && !state.isEmpty() ) + s += ", "; + s += state; + if ( !state.isEmpty() && !zip.isEmpty() ) + s += " "; + s += zip; + if ( !country.isEmpty() && !s.isEmpty() ) + s += "\n"; + s += country; + return s; +} + +/*! + \internal +*/ +QString OPimContact::displayBusinessAddress() const +{ + return displayAddress( businessStreet(), businessCity(), + businessState(), businessZip(), + businessCountry() ); +} + +/*! + \internal +*/ +QString OPimContact::displayHomeAddress() const +{ + return displayAddress( homeStreet(), homeCity(), + homeState(), homeZip(), + homeCountry() ); +} + +/*! + Returns the full name of the contact +*/ +QString OPimContact::fullName() const +{ + QString title = find( Qtopia::Title ); + QString firstName = find( Qtopia::FirstName ); + QString middleName = find( Qtopia::MiddleName ); + QString lastName = find( Qtopia::LastName ); + QString suffix = find( Qtopia::Suffix ); + + QString name = title; + if ( !firstName.isEmpty() ) + { + if ( !name.isEmpty() ) + name += " "; + name += firstName; + } + if ( !middleName.isEmpty() ) + { + if ( !name.isEmpty() ) + name += " "; + name += middleName; + } + if ( !lastName.isEmpty() ) + { + if ( !name.isEmpty() ) + name += " "; + name += lastName; + } + if ( !suffix.isEmpty() ) + { + if ( !name.isEmpty() ) + name += " "; + name += suffix; + } + return name.simplifyWhiteSpace(); +} + +/*! + Returns a list of the names of the children of the contact. +*/ +QStringList OPimContact::childrenList() const +{ + return QStringList::split( " ", find( Qtopia::Children ) ); +} + +/*! \fn void OPimContact::insertEmail( const QString &email ) + + Insert \a email into the email list. Ensures \a email can only be added + once. If there is no default email address set, it sets it to the \a email. +*/ + +/*! \fn void OPimContact::removeEmail( const QString &email ) + + Removes the \a email from the email list. If the default email was \a email, + then the default email address is assigned to the first email in the + email list +*/ + +/*! \fn void OPimContact::clearEmails() + + Clears the email list. + */ + +/*! \fn void OPimContact::insertEmails( const QStringList &emailList ) + + Appends the \a emailList to the exiting email list + */ + +/*! + Returns a list of email addresses belonging to the contact, including + the default email address. +*/ +QStringList OPimContact::emailList() const +{ + QString emailStr = emails(); + + QStringList r; + if ( !emailStr.isEmpty() ) + { + qDebug( " emailstr " ); + QStringList l = QStringList::split( emailSeparator(), emailStr ); + for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) + r += ( *it ).simplifyWhiteSpace(); + } + + return r; +} + +/*! + \overload + + Generates the string for the contact to be filed as from the first, + middle and last name of the contact. +*/ +void OPimContact::setFileAs() +{ + QString lastName, firstName, middleName, fileas; + + lastName = find( Qtopia::LastName ); + firstName = find( Qtopia::FirstName ); + middleName = find( Qtopia::MiddleName ); + if ( !lastName.isEmpty() && !firstName.isEmpty() + && !middleName.isEmpty() ) + fileas = lastName + ", " + firstName + " " + middleName; + else if ( !lastName.isEmpty() && !firstName.isEmpty() ) + fileas = lastName + ", " + firstName; + else if ( !lastName.isEmpty() || !firstName.isEmpty() || + !middleName.isEmpty() ) + fileas = firstName + ( firstName.isEmpty() ? "" : " " ) + + middleName + ( middleName.isEmpty() ? "" : " " ) + + lastName; + + replace( Qtopia::FileAs, fileas ); +} + +/*! + \internal + Appends the contact information to \a buf. +*/ +void OPimContact::save( QString &buf ) const +{ + static const QStringList SLFIELDS = fields(); + // I'm expecting "::ConstIterator it = mMap.begin(); + it != mMap.end(); ++it ) + { + const QString &value = it.data(); + int key = it.key(); + if ( !value.isEmpty() ) + { + if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid ) + continue; + + key -= Qtopia::AddressCategory + 1; + buf += SLFIELDS[ key ]; + buf += "=\"" + Qtopia::escapeString( value ) + "\" "; + } + } + buf += customToXml(); + if ( categories().count() > 0 ) + buf += "Categories=\"" + idsToString( categories() ) + "\" "; + buf += "Uid=\"" + QString::number( uid() ) + "\" "; + // You need to close this yourself +} + + +/*! + \internal + Returns the list of fields belonging to a contact + Never change order of this list ! It has to be regarding + enum AddressBookFields !! +*/ +QStringList OPimContact::fields() +{ + QStringList list; + + list.append( "Title" ); // Not Used! + list.append( "FirstName" ); + list.append( "MiddleName" ); + list.append( "LastName" ); + list.append( "Suffix" ); + list.append( "FileAs" ); + + list.append( "JobTitle" ); + list.append( "Department" ); + list.append( "Company" ); + list.append( "BusinessPhone" ); + list.append( "BusinessFax" ); + list.append( "BusinessMobile" ); + + list.append( "DefaultEmail" ); + list.append( "Emails" ); + + list.append( "HomePhone" ); + list.append( "HomeFax" ); + list.append( "HomeMobile" ); + + list.append( "BusinessStreet" ); + list.append( "BusinessCity" ); + list.append( "BusinessState" ); + list.append( "BusinessZip" ); + list.append( "BusinessCountry" ); + list.append( "BusinessPager" ); + list.append( "BusinessWebPage" ); + + list.append( "Office" ); + list.append( "Profession" ); + list.append( "Assistant" ); + list.append( "Manager" ); + + list.append( "HomeStreet" ); + list.append( "HomeCity" ); + list.append( "HomeState" ); + list.append( "HomeZip" ); + list.append( "HomeCountry" ); + list.append( "HomeWebPage" ); + + list.append( "Spouse" ); + list.append( "Gender" ); + list.append( "Birthday" ); + list.append( "Anniversary" ); + list.append( "Nickname" ); + list.append( "Children" ); + + list.append( "Notes" ); + list.append( "Groups" ); + + return list; +} + + +/*! + Sets the list of email address for contact to those contained in \a str. + Email address should be separated by ';'s. +*/ +void OPimContact::setEmails( const QString &str ) +{ + replace( Qtopia::Emails, str ); + if ( str.isEmpty() ) + setDefaultEmail( QString::null ); +} + +/*! + Sets the list of children for the contact to those contained in \a str. +*/ +void OPimContact::setChildren( const QString &str ) +{ + replace( Qtopia::Children, str ); +} + +/*! + \overload + Returns TRUE if the contact matches the regular expression \a regexp. + Otherwise returns FALSE. +*/ +bool OPimContact::match( const QRegExp &r ) const +{ + setLastHitField( -1 ); + bool match; + match = false; + QMap::ConstIterator it; + for ( it = mMap.begin(); it != mMap.end(); ++it ) + { + if ( ( *it ).find( r ) > -1 ) + { + setLastHitField( it.key() ); + match = true; + break; + } + } + return match; +} + + +QString OPimContact::toShortText() const +{ + return ( fullName() ); +} + + +QString OPimContact::type() const +{ + return QString::fromLatin1( "OPimContact" ); +} + + +class QString OPimContact::recordField( int pos ) const +{ + QStringList SLFIELDS = fields(); // ?? why this ? (se) + return SLFIELDS[ pos ]; +} + +// In future releases, we should store birthday and anniversary +// internally as QDate instead of QString ! +// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) + +/*! \fn void OPimContact::setBirthday( const QDate& date ) + Sets the birthday for the contact to \a date. If date is null + the current stored date will be removed. +*/ +void OPimContact::setBirthday( const QDate &v ) +{ + if ( v.isNull() ) + { + qWarning( "Remove Birthday" ); + replace( Qtopia::Birthday, QString::null ); + return ; + } + + if ( v.isValid() ) + replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) ); + +} + + +/*! \fn void OPimContact::setAnniversary( const QDate &date ) + Sets the anniversary of the contact to \a date. If date is + null, the current stored date will be removed. +*/ +void OPimContact::setAnniversary( const QDate &v ) +{ + if ( v.isNull() ) + { + qWarning( "Remove Anniversary" ); + replace( Qtopia::Anniversary, QString::null ); + return ; + } + + if ( v.isValid() ) + replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) ); +} + + +/*! \fn QDate OPimContact::birthday() const + Returns the birthday of the contact. +*/ +QDate OPimContact::birthday() const +{ + QString str = find( Qtopia::Birthday ); + // qWarning ("Birthday %s", str.latin1() ); + if ( !str.isEmpty() ) + return OPimDateConversion::dateFromString ( str ); + else + return QDate(); +} + + +/*! \fn QDate OPimContact::anniversary() const + Returns the anniversary of the contact. +*/ +QDate OPimContact::anniversary() const +{ + QDate empty; + QString str = find( Qtopia::Anniversary ); + // qWarning ("Anniversary %s", str.latin1() ); + if ( !str.isEmpty() ) + return OPimDateConversion::dateFromString ( str ); + else + return empty; +} + + +void OPimContact::insertEmail( const QString &v ) +{ + //qDebug("insertEmail %s", v.latin1()); + QString e = v.simplifyWhiteSpace(); + QString def = defaultEmail(); + + // if no default, set it as the default email and don't insert + if ( def.isEmpty() ) + { + setDefaultEmail( e ); // will insert into the list for us + return ; + } + + // otherwise, insert assuming doesn't already exist + QString emailsStr = find( Qtopia::Emails ); + if ( emailsStr.contains( e ) ) + return ; + if ( !emailsStr.isEmpty() ) + emailsStr += emailSeparator(); + emailsStr += e; + replace( Qtopia::Emails, emailsStr ); +} + + + void OPimContact::removeEmail( const QString &v ) +{ + QString e = v.simplifyWhiteSpace(); + QString def = defaultEmail(); + QString emailsStr = find( Qtopia::Emails ); + QStringList emails = emailList(); + + // otherwise, must first contain it + if ( !emailsStr.contains( e ) ) + return ; + + // remove it + //qDebug(" removing email from list %s", e.latin1()); + emails.remove( e ); + // reset the string + emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator + replace( Qtopia::Emails, emailsStr ); + + // if default, then replace the default email with the first one + if ( def == e ) + { + //qDebug("removeEmail is default; setting new default"); + if ( !emails.count() ) + clearEmails(); + else // setDefaultEmail will remove e from the list + setDefaultEmail( emails.first() ); + } +} + + +void OPimContact::clearEmails() +{ + mMap.remove( Qtopia::DefaultEmail ); + mMap.remove( Qtopia::Emails ); +} + + +void OPimContact::setDefaultEmail( const QString &v ) +{ + QString e = v.simplifyWhiteSpace(); + + //qDebug("OPimContact::setDefaultEmail %s", e.latin1()); + replace( Qtopia::DefaultEmail, e ); + + if ( !e.isEmpty() ) + insertEmail( e ); + +} + + +void OPimContact::insertEmails( const QStringList &v ) +{ + for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) + insertEmail( *it ); +} + + +int OPimContact::rtti() +{ + return OPimResolver::AddressBook; +} + + +void OPimContact::setUid( int i ) +{ + OPimRecord::setUid( i ); + replace( Qtopia::AddressUid , QString::number( i ) ); +} +} diff --git a/libopie2/opiepim/core/opimcontact.h b/libopie2/opiepim/core/opimcontact.h new file mode 100644 index 0000000..c08f7ed --- a/dev/null +++ b/libopie2/opiepim/core/opimcontact.h @@ -0,0 +1,256 @@ +/* + This file is part of the Opie Project + Copyright (C) The Main Author + =. Copyright (C) The Opie Team + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef OCONTACT_H +#define OCONTACT_H + +/* OPIE */ +#include +#include + +/* QT */ +#include +#include + +#if defined(QPC_TEMPLATEDLL) +// MOC_SKIP_BEGIN +QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap; +// MOC_SKIP_END +#endif + +namespace Opie +{ +class OPimContactPrivate; + +/** + * OPimContact class represents a specialised PIM Record for contacts. + * It does store all kind of persopn related information. + * + * @short Contact Container + * @author TT, Stefan Eiler, Holger Freyther + */ +class QPC_EXPORT OPimContact : public OPimRecord +{ + friend class DataSet; + + public: + OPimContact(); + OPimContact( const QMap &fromMap ); + virtual ~OPimContact(); + + enum DateFormat{ + Zip_City_State = 0, + City_State_Zip + }; + + /* + * do we need to inline them + * if yes do we need to inline them this way? + * -zecke + */ + void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } + void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } + void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } + void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } + void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } + void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } + void setFileAs(); + + // default email address + void setDefaultEmail( const QString &v ); + // inserts email to list and ensure's doesn't already exist + void insertEmail( const QString &v ); + void removeEmail( const QString &v ); + void clearEmails(); + void insertEmails( const QStringList &v ); + + // home + void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } + void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } + void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } + void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } + void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } + void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } + void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } + void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } + void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } + + // business + void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } + void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } + void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } + void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } + void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } + void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } + void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } + void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } + void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } + void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } + void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } + void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } + void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } + void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } + void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } + void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } + void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } + + // personal + void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } + void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } + void setBirthday( const QDate &v ); + void setAnniversary( const QDate &v ); + void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } + void setChildren( const QString &v ); + + // other + void setNotes( const QString &v ) { replace( Qtopia::Notes, v ); } + + virtual bool match( const QRegExp ®exp ) const; + + // // custom + // void setCustomField( const QString &key, const QString &v ) + // { replace(Custom- + key, v ); } + + // name + QString fullName() const; + QString title() const { return find( Qtopia::Title ); } + QString firstName() const { return find( Qtopia::FirstName ); } + QString middleName() const { return find( Qtopia::MiddleName ); } + QString lastName() const { return find( Qtopia::LastName ); } + QString suffix() const { return find( Qtopia::Suffix ); } + QString fileAs() const { return find( Qtopia::FileAs ); } + + // email + QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } + QStringList emailList() const; + + // home + /* + * OPimAddress address(enum Location)const; + * would be some how nicer... + * -zecke + */ + QString homeStreet() const { return find( Qtopia::HomeStreet ); } + QString homeCity() const { return find( Qtopia::HomeCity ); } + QString homeState() const { return find( Qtopia::HomeState ); } + QString homeZip() const { return find( Qtopia::HomeZip ); } + QString homeCountry() const { return find( Qtopia::HomeCountry ); } + QString homePhone() const { return find( Qtopia::HomePhone ); } + QString homeFax() const { return find( Qtopia::HomeFax ); } + QString homeMobile() const { return find( Qtopia::HomeMobile ); } + QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } + /** Multi line string containing all non-empty address info in the form + * Street + * City, State Zip + * Country + */ + QString displayHomeAddress() const; + + // business + QString company() const { return find( Qtopia::Company ); } + QString businessStreet() const { return find( Qtopia::BusinessStreet ); } + QString businessCity() const { return find( Qtopia::BusinessCity ); } + QString businessState() const { return find( Qtopia::BusinessState ); } + QString businessZip() const { return find( Qtopia::BusinessZip ); } + QString businessCountry() const { return find( Qtopia::BusinessCountry ); } + QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } + QString jobTitle() const { return find( Qtopia::JobTitle ); } + QString department() const { return find( Qtopia::Department ); } + QString office() const { return find( Qtopia::Office ); } + QString businessPhone() const { return find( Qtopia::BusinessPhone ); } + QString businessFax() const { return find( Qtopia::BusinessFax ); } + QString businessMobile() const { return find( Qtopia::BusinessMobile ); } + QString businessPager() const { return find( Qtopia::BusinessPager ); } + QString profession() const { return find( Qtopia::Profession ); } + QString assistant() const { return find( Qtopia::Assistant ); } + QString manager() const { return find( Qtopia::Manager ); } + /** Multi line string containing all non-empty address info in the form + * Street + * City, State Zip + * Country + */ + QString displayBusinessAddress() const; + + //personal + QString spouse() const { return find( Qtopia::Spouse ); } + QString gender() const { return find( Qtopia::Gender ); } + QDate birthday() const; + QDate anniversary() const; + QString nickname() const { return find( Qtopia::Nickname ); } + QString children() const { return find( Qtopia::Children ); } + QStringList childrenList() const; + + // other + QString notes() const { return find( Qtopia::Notes ); } + QString groups() const { return find( Qtopia::Groups ); } + QStringList groupList() const; + + QString toRichText() const; + QMap toMap() const; + QString field( int key ) const { return find( key ); } + + + void setUid( int i ); + + QString toShortText() const; + QString type() const; + class QString recordField( int ) const; + + // Why private ? (eilers,se) + QString emailSeparator() const { return " "; } + + // the emails should be seperated by a comma + void setEmails( const QString &v ); + QString emails() const { return find( Qtopia::Emails ); } + static int rtti(); + + private: + // The XML Backend needs some access to the private functions + friend class OPimContactAccessBackend_XML; + + void insert( int key, const QString &value ); + void replace( int key, const QString &value ); + QString find( int key ) const; + static QStringList fields(); + + void save( QString &buf ) const; + + QString displayAddress( const QString &street, + const QString &city, + const QString &state, + const QString &zip, + const QString &country ) const; + + QMap mMap; + OPimContactPrivate *d; +}; + +} + +#endif diff --git a/libopie2/opiepim/core/opimcontactfields.cpp b/libopie2/opiepim/core/opimcontactfields.cpp new file mode 100644 index 0000000..4b0ba3b --- a/dev/null +++ b/libopie2/opiepim/core/opimcontactfields.cpp @@ -0,0 +1,518 @@ +/* + This file is part of the Opie Project + Copyright (C) Stefan Eilers + =. Copyright (C) The Opie Team + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include "opimcontactfields.h" + +/* OPIE */ +#include +#include // We should use our own enum in the future .. +#include + +/* QT */ +#include +#include + + +namespace Opie +{ +/*! + \internal + Returns a list of personal field names for a contact. +*/ +QStringList OPimContactFields::personalfields( bool sorted, bool translated ) +{ + QStringList list; + QMap mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); + + 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 ] ); + + 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 list of details field names for a contact. +*/ +QStringList OPimContactFields::detailsfields( bool sorted, bool translated ) +{ + QStringList list; + QMap 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::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 list of phone field names for a contact. +*/ +QStringList OPimContactFields::phonefields( bool sorted, bool translated ) +{ + QStringList list; + QMap 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 field names for a contact. +*/ +QStringList OPimContactFields::fields( bool sorted, bool translated ) +{ + QStringList list; + QMap mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); + + list += personalfields( sorted, translated ); + + 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 += detailsfields( sorted, translated ); + + if ( sorted ) list.sort(); + + return list; +} + + +/*! + \internal + Returns an untranslated list of personal field names for a contact. +*/ +QStringList OPimContactFields::untrpersonalfields( bool sorted ) +{ + return personalfields( sorted, false ); +} + + +/*! + \internal + Returns a translated list of personal field names for a contact. +*/ +QStringList OPimContactFields::trpersonalfields( bool sorted ) +{ + return personalfields( sorted, true ); +} + + +/*! + \internal + Returns an untranslated list of details field names for a contact. +*/ +QStringList OPimContactFields::untrdetailsfields( bool sorted ) +{ + return detailsfields( sorted, false ); +} + + +/*! + \internal + Returns a translated list of details field names for a contact. +*/ +QStringList OPimContactFields::trdetailsfields( bool sorted ) +{ + return detailsfields( sorted, true ); +} + + +/*! + \internal + Returns a translated list of phone field names for a contact. +*/ +QStringList OPimContactFields::trphonefields( bool sorted ) +{ + return phonefields( sorted, true ); +} + +/*! + \internal + Returns an untranslated list of phone field names for a contact. +*/ +QStringList OPimContactFields::untrphonefields( bool sorted ) +{ + return phonefields( sorted, false ); +} + + +/*! + \internal + Returns a translated list of field names for a contact. +*/ +QStringList OPimContactFields::trfields( bool sorted ) +{ + return fields( sorted, true ); +} + +/*! + \internal + Returns an untranslated list of field names for a contact. +*/ +QStringList OPimContactFields::untrfields( bool sorted ) +{ + return fields( sorted, false ); +} + +QMap OPimContactFields::idToTrFields() +{ + QMap 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 OPimContactFields::idToUntrFields() +{ + QMap 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::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 OPimContactFields::trFieldsToId() +{ + QMap idtostr = idToTrFields(); + QMap ret_map; + + + QMap::Iterator it; + for ( it = idtostr.begin(); it != idtostr.end(); ++it ) + ret_map.insert( *it, it.key() ); + + + return ret_map; +} + +/* ======================================================================= */ + +QMap OPimContactFields::untrFieldsToId() +{ + QMap idtostr = idToUntrFields(); + QMap ret_map; + + + QMap::Iterator it; + for ( it = idtostr.begin(); it != idtostr.end(); ++it ) + ret_map.insert( *it, it.key() ); + + + return ret_map; +} + + +OPimContactFields::OPimContactFields() : + 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 ); +} + +OPimContactFields::~OPimContactFields() +{ + + // 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 OPimContactFields::saveToRecord( OPimContact &cnt ) +{ + + qDebug( "ocontactfields saveToRecord: >%s<", fieldOrder.latin1() ); + + // Store fieldorder into this contact. + cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder ); + + globalFieldOrder = fieldOrder; + changedFieldOrder = true; + +} + +void OPimContactFields::loadFromRecord( const OPimContact &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 OPimContactFields::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 OPimContactFields::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/core/opimcontactfields.h b/libopie2/opiepim/core/opimcontactfields.h new file mode 100644 index 0000000..3aa3894 --- a/dev/null +++ b/libopie2/opiepim/core/opimcontactfields.h @@ -0,0 +1,102 @@ +/* + This file is part of the Opie Project + Copyright (C) The Main Author + =. Copyright (C) The Opie Team + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef OCONTACTFIELDS_H +#define OCONTACTFIELDS_H + +class QStringList; + +/* OPIE */ +#include + +/* QT */ +#include +#include + +#define CONTACT_FIELD_ORDER_NAME "opie-contactfield-order" +#define DEFAULT_FIELD_ORDER "__________" + +namespace Opie +{ +class OPimContactFields +{ + + public: + OPimContactFields(); + ~OPimContactFields(); + /** Set the index for combo boxes. + * Sets the index of combo num. + * @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 num 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( OPimContact& ); + /** Get Fieldorder from contact. */ + void loadFromRecord( const OPimContact& ); + + 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 idToTrFields(); + static QMap trFieldsToId(); + static QMap idToUntrFields(); + static QMap untrFieldsToId(); + +}; +} +#endif diff --git a/libopie2/opiepim/core/oconversion.cpp b/libopie2/opiepim/core/opimdateconversion.cpp index 160c2c6..8bf891b 100644 --- a/libopie2/opiepim/core/oconversion.cpp +++ b/libopie2/opiepim/core/opimdateconversion.cpp @@ -27,13 +27,13 @@ _;:, .> :=|. This program is free software; you can */ /* OPIE */ -#include +#include #include namespace Opie { -QString OConversion::dateToString( const QDate &d ) +QString OPimDateConversion::dateToString( const QDate &d ) { if ( d.isNull() || !d.isValid() ) return QString::null; @@ -52,7 +52,7 @@ QString OConversion::dateToString( const QDate &d ) } -QDate OConversion::dateFromString( const QString& s ) +QDate OPimDateConversion::dateFromString( const QString& s ) { QDate date; @@ -99,7 +99,7 @@ QDate OConversion::dateFromString( const QString& s ) } -QString OConversion::dateTimeToString( const QDateTime& dt ) +QString OPimDateConversion::dateTimeToString( const QDateTime& dt ) { if ( !dt.isValid() || dt.isNull() ) return QString::null; @@ -122,7 +122,7 @@ QString OConversion::dateTimeToString( const QDateTime& dt ) } -QDateTime OConversion::dateTimeFromString( const QString& str ) +QDateTime OPimDateConversion::dateTimeFromString( const QString& str ) { if ( str.isEmpty() ) diff --git a/libopie2/opiepim/core/oconversion.h b/libopie2/opiepim/core/opimdateconversion.h index eeb97e5..45536da 100644 --- a/libopie2/opiepim/core/oconversion.h +++ b/libopie2/opiepim/core/opimdateconversion.h @@ -35,7 +35,7 @@ namespace Opie { -class OConversion +class OPimDateConversion { public: static QString dateToString( const QDate &d ); diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp new file mode 100644 index 0000000..3ddbf85 --- a/dev/null +++ b/libopie2/opiepim/core/opimevent.cpp @@ -0,0 +1,1025 @@ +/* + This file is part of the Opie Project + Copyright (C) Stefan Eilers + =. Copyright (C) The Opie Team + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include "opimevent.h" + +/* OPIE */ +#include +#include +#include +#include +#include +#include + +/* QT */ +#include +#include + +namespace Opie +{ + +int OCalendarHelper::week( const QDate& date ) +{ + // Calculates the week this date is in within that + // month. Equals the "row" is is in in the month view + int week = 1; + QDate tmp( date.year(), date.month(), 1 ); + if ( date.dayOfWeek() < tmp.dayOfWeek() ) + ++week; + + week += ( date.day() - 1 ) / 7; + + return week; +} + + +int OCalendarHelper::ocurrence( const QDate& date ) +{ + // calculates the number of occurrances of this day of the + // week till the given date (e.g 3rd Wednesday of the month) + return ( date.day() - 1 ) / 7 + 1; +} + + +int OCalendarHelper::dayOfWeek( char day ) +{ + int dayOfWeek = 1; + char i = OPimRecurrence::MON; + while ( !( i & day ) && i <= OPimRecurrence::SUN ) + { + i <<= 1; + ++dayOfWeek; + } + return dayOfWeek; +} + + +int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) +{ + return ( second.year() - first.year() ) * 12 + + second.month() - first.month(); +} + + +struct OPimEvent::Data : public QShared +{ + Data() : QShared() + { + child = 0; + recur = 0; + manager = 0; + isAllDay = false; + parent = 0; + } + ~Data() + { + delete manager; + delete recur; + } + QString description; + QString location; + OPimNotifyManager* manager; + OPimRecurrence* recur; + QString note; + QDateTime created; + QDateTime start; + QDateTime end; +bool isAllDay : 1; + QString timezone; + QArray* child; + int parent; +}; + + +OPimEvent::OPimEvent( int uid ) + : OPimRecord( uid ) +{ + data = new Data; +} + + +OPimEvent::OPimEvent( const OPimEvent& ev ) + : OPimRecord( ev ), data( ev.data ) +{ + data->ref(); +} + + +OPimEvent::OPimEvent( const QMap map ) + : OPimRecord( 0 ) +{ + data = new Data; + + fromMap( map ); +} + + +OPimEvent::~OPimEvent() +{ + if ( data->deref() ) + { + delete data; + data = 0; + } +} + + +OPimEvent& OPimEvent::operator=( const OPimEvent& ev ) +{ + if ( this == &ev ) return * this; + + OPimRecord::operator=( ev ); + ev.data->ref(); + deref(); + data = ev.data; + + + return *this; +} + + +QString OPimEvent::description() const +{ + return data->description; +} + + +void OPimEvent::setDescription( const QString& description ) +{ + changeOrModify(); + data->description = description; +} + + +void OPimEvent::setLocation( const QString& loc ) +{ + changeOrModify(); + data->location = loc; +} + + +QString OPimEvent::location() const +{ + return data->location; +} + + +OPimNotifyManager &OPimEvent::notifiers() const +{ + // I hope we can skip the changeOrModify here + // the notifier should take care of it + // and OPimNotify is shared too + if ( !data->manager ) + data->manager = new OPimNotifyManager; + + return *data->manager; +} + + +bool OPimEvent::hasNotifiers() const +{ + if ( !data->manager ) + return false; + if ( data->manager->reminders().isEmpty() && + data->manager->alarms().isEmpty() ) + return false; + + return true; +} + + +OPimRecurrence OPimEvent::recurrence() const +{ + if ( !data->recur ) + data->recur = new OPimRecurrence; + + return *data->recur; +} + + +void OPimEvent::setRecurrence( const OPimRecurrence& rec ) +{ + changeOrModify(); + if ( data->recur ) + ( *data->recur ) = rec; + else + data->recur = new OPimRecurrence( rec ); +} + + +bool OPimEvent::hasRecurrence() const +{ + if ( !data->recur ) return false; + return data->recur->doesRecur(); +} + + +QString OPimEvent::note() const +{ + return data->note; +} + + +void OPimEvent::setNote( const QString& note ) +{ + changeOrModify(); + data->note = note; +} + + +QDateTime OPimEvent::createdDateTime() const +{ + return data->created; +} + + +void OPimEvent::setCreatedDateTime( const QDateTime& time ) +{ + changeOrModify(); + data->created = time; +} + + +QDateTime OPimEvent::startDateTime() const +{ + if ( data->isAllDay ) + return QDateTime( data->start.date(), QTime( 0, 0, 0 ) ); + return data->start; +} + + +QDateTime OPimEvent::startDateTimeInZone() const +{ + /* if no timezone, or all day event or if the current and this timeZone match... */ + if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return startDateTime(); + + OPimTimeZone zone( data->timezone ); + return zone.toDateTime( data->start, OPimTimeZone::current() ); +} + + +void OPimEvent::setStartDateTime( const QDateTime& dt ) +{ + changeOrModify(); + data->start = dt; +} + + +QDateTime OPimEvent::endDateTime() const +{ + /* + * if all Day event the end time needs + * to be on the same day as the start + */ + if ( data->isAllDay ) + return QDateTime( data->start.date(), QTime( 23, 59, 59 ) ); + return data->end; +} + + +QDateTime OPimEvent::endDateTimeInZone() const +{ + /* if no timezone, or all day event or if the current and this timeZone match... */ + if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return endDateTime(); + + OPimTimeZone zone( data->timezone ); + return zone.toDateTime( data->end, OPimTimeZone::current() ); +} + + +void OPimEvent::setEndDateTime( const QDateTime& dt ) +{ + changeOrModify(); + data->end = dt; +} + + +bool OPimEvent::isMultipleDay() const +{ + return data->end.date().day() - data->start.date().day(); +} + + +bool OPimEvent::isAllDay() const +{ + return data->isAllDay; +} + + +void OPimEvent::setAllDay( bool allDay ) +{ + changeOrModify(); + data->isAllDay = allDay; + if ( allDay ) data->timezone = "UTC"; +} + + +void OPimEvent::setTimeZone( const QString& tz ) +{ + changeOrModify(); + data->timezone = tz; +} + + +QString OPimEvent::timeZone() const +{ + if ( data->isAllDay ) return QString::fromLatin1( "UTC" ); + return data->timezone; +} + + +bool OPimEvent::match( const QRegExp& re ) const +{ + if ( re.match( data->description ) != -1 ) + { + setLastHitField( Qtopia::DatebookDescription ); + return true; + } + if ( re.match( data->note ) != -1 ) + { + setLastHitField( Qtopia::Note ); + return true; + } + if ( re.match( data->location ) != -1 ) + { + setLastHitField( Qtopia::Location ); + return true; + } + if ( re.match( data->start.toString() ) != -1 ) + { + setLastHitField( Qtopia::StartDateTime ); + return true; + } + if ( re.match( data->end.toString() ) != -1 ) + { + setLastHitField( Qtopia::EndDateTime ); + return true; + } + return false; +} + + +QString OPimEvent::toRichText() const +{ + QString text, value; + + // description + text += "

"; + if ( !description().isEmpty() ) + { + text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" ); + } + text += "




"; + + // location + if ( !( value = location() ).isEmpty() ) + { + text += "" + QObject::tr( "Location:" ) + " "; + text += Qtopia::escapeString( value ) + "
"; + } + + // all day event + if ( isAllDay() ) + { + text += "" + QObject::tr( "This is an all day event" ) + "
"; + } + // multiple day event + else if ( isMultipleDay () ) + { + text += "" + QObject::tr( "This is a multiple day event" ) + "
"; + } + // start & end times + else + { + // start time + if ( startDateTime().isValid() ) + { + text += "" + QObject::tr( "Start:" ) + " "; + text += Qtopia::escapeString( startDateTime().toString() ). + replace( QRegExp( "[\n]" ), "
" ) + "
"; + } + + // end time + if ( endDateTime().isValid() ) + { + text += "" + QObject::tr( "End:" ) + " "; + text += Qtopia::escapeString( endDateTime().toString() ). + replace( QRegExp( "[\n]" ), "
" ) + "
"; + } + } + + // categories + if ( categoryNames( "Calendar" ).count() ) + { + text += "" + QObject::tr( "Category:" ) + " "; + text += categoryNames( "Calendar" ).join( ", " ); + text += "
"; + } + + //notes + if ( !note().isEmpty() ) + { + text += "" + QObject::tr( "Note:" ) + "
"; + text += note(); + // text += Qtopia::escapeString(note() ). + // replace(QRegExp( "[\n]"), "
" ) + "
"; + } + return text; +} + + +QString OPimEvent::toShortText() const +{ + QString text; + text += QString::number( startDateTime().date().day() ); + text += "."; + text += QString::number( startDateTime().date().month() ); + text += "."; + text += QString::number( startDateTime().date().year() ); + text += " "; + text += QString::number( startDateTime().time().hour() ); + text += ":"; + text += QString::number( startDateTime().time().minute() ); + text += " - "; + text += description(); + return text; +} + + +QString OPimEvent::type() const +{ + return QString::fromLatin1( "OPimEvent" ); +} + + +QString OPimEvent::recordField( int /*id */ ) const +{ + return QString::null; +} + + +int OPimEvent::rtti() +{ + return OPimResolver::DateBook; +} + + +bool OPimEvent::loadFromStream( QDataStream& ) +{ + return true; +} + + +bool OPimEvent::saveToStream( QDataStream& ) const +{ + return true; +} + + +void OPimEvent::changeOrModify() +{ + if ( data->count != 1 ) + { + data->deref(); + Data* d2 = new Data; + d2->description = data->description; + d2->location = data->location; + + if ( data->manager ) + d2->manager = new OPimNotifyManager( *data->manager ); + + if ( data->recur ) + d2->recur = new OPimRecurrence( *data->recur ); + + d2->note = data->note; + d2->created = data->created; + d2->start = data->start; + d2->end = data->end; + d2->isAllDay = data->isAllDay; + d2->timezone = data->timezone; + d2->parent = data->parent; + + if ( data->child ) + { + d2->child = new QArray( *data->child ); + d2->child->detach(); + } + + data = d2; + } +} + + +void OPimEvent::deref() +{ + if ( data->deref() ) + { + delete data; + data = 0; + } +} +// Exporting Event data to map. Using the same +// encoding as ODateBookAccessBackend_xml does.. +// Thus, we could remove the stuff there and use this +// for it and for all other places.. +// Encoding should happen at one place, only ! (eilers) +QMap OPimEvent::toMap() const +{ + QMap retMap; + + retMap.insert( OPimEvent::FUid, QString::number( uid() ) ); + retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) ); + retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) ); + retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) ); + retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" ); + OPimAlarm alarm = notifiers().alarms() [ 0 ]; + retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); + retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" ); + + OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); + retMap.insert( OPimEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OPimTimeZone::utc() ) ) ) ); + retMap.insert( OPimEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OPimTimeZone::utc() ) ) ) ); + retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) ); + retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() ); + if ( parent() ) + retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) ); + if ( children().count() ) + { + QArray childr = children(); + QString buf; + for ( uint i = 0; i < childr.count(); i++ ) + { + if ( i != 0 ) buf += " "; + buf += QString::number( childr[ i ] ); + } + retMap.insert( OPimEvent::FRecChildren, buf ); + } + + // Add recurrence stuff + if ( hasRecurrence() ) + { + OPimRecurrence recur = recurrence(); + QMap recFields = recur.toMap(); + retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); + retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] ); + retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] ); + retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] ); + retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] ); + retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] ); + retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] ); + retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] ); + } + else + { + OPimRecurrence recur = recurrence(); + QMap recFields = recur.toMap(); + retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); + } + + return retMap; +} + + +void OPimEvent::fromMap( const QMap& map ) +{ + + // We just want to set the UID if it is really stored. + if ( !map[ OPimEvent::FUid ].isEmpty() ) + setUid( map[ OPimEvent::FUid ].toInt() ); + + setCategories( idsFromString( map[ OPimEvent::FCategories ] ) ); + setDescription( map[ OPimEvent::FDescription ] ); + setLocation( map[ OPimEvent::FLocation ] ); + + if ( map[ OPimEvent::FType ] == "AllDay" ) + setAllDay( true ); + else + setAllDay( false ); + + int alarmTime = -1; + if ( !map[ OPimEvent::FAlarm ].isEmpty() ) + alarmTime = map[ OPimEvent::FAlarm ].toInt(); + + int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); + if ( ( alarmTime != -1 ) ) + { + QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 ); + OPimAlarm al( sound , dt ); + notifiers().add( al ); + } + if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) ) + { + setTimeZone( map[ OPimEvent::FTimeZone ] ); + } + + time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong(); + time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong(); + + /* AllDay is always in UTC */ + if ( isAllDay() ) + { + OPimTimeZone utc = OPimTimeZone::utc(); + setStartDateTime( utc.fromUTCDateTime( start ) ); + setEndDateTime ( utc.fromUTCDateTime( end ) ); + setTimeZone( "UTC" ); // make sure it is really utc + } + else + { + /* to current date time */ + // qWarning(" Start is %d", start ); + OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); + QDateTime date = zone.toDateTime( start ); + qWarning( " Start is %s", date.toString().latin1() ); + setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) ); + + date = zone.toDateTime( end ); + setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); + } + + if ( !map[ OPimEvent::FRecParent ].isEmpty() ) + setParent( map[ OPimEvent::FRecParent ].toInt() ); + + if ( !map[ OPimEvent::FRecChildren ].isEmpty() ) + { + QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] ); + for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) + { + addChild( ( *it ).toInt() ); + } + } + + // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap.. + if ( !map[ OPimEvent::FRType ].isEmpty() ) + { + QMap recFields; + recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] ); + recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] ); + recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] ); + recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] ); + recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] ); + recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] ); + recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] ); + recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] ); + OPimRecurrence recur( recFields ); + setRecurrence( recur ); + } + +} + + +int OPimEvent::parent() const +{ + return data->parent; +} + + +void OPimEvent::setParent( int uid ) +{ + changeOrModify(); + data->parent = uid; +} + + +QArray OPimEvent::children() const +{ + if ( !data->child ) return QArray(); + else + return data->child->copy(); +} + + +void OPimEvent::setChildren( const QArray& arr ) +{ + changeOrModify(); + if ( data->child ) delete data->child; + + data->child = new QArray( arr ); + data->child->detach(); +} + + +void OPimEvent::addChild( int uid ) +{ + changeOrModify(); + if ( !data->child ) + { + data->child = new QArray( 1 ); + ( *data->child ) [ 0 ] = uid; + } + else + { + int count = data->child->count(); + data->child->resize( count + 1 ); + ( *data->child ) [ count ] = uid; + } +} + + +void OPimEvent::removeChild( int uid ) +{ + if ( !data->child || !data->child->contains( uid ) ) return ; + changeOrModify(); + QArray newAr( data->child->count() - 1 ); + int j = 0; + uint count = data->child->count(); + for ( uint i = 0; i < count; i++ ) + { + if ( ( *data->child ) [ i ] != uid ) + { + newAr[ j ] = ( *data->child ) [ i ]; + j++; + } + } + ( *data->child ) = newAr; +} + + +struct OEffectiveEvent::Data : public QShared +{ + Data() : QShared() + {} + OPimEvent event; + QDate date; + QTime start, end; + QDate startDate, endDate; +bool dates : 1; +}; + + +OEffectiveEvent::OEffectiveEvent() +{ + data = new Data; + data->date = QDate::currentDate(); + data->start = data->end = QTime::currentTime(); + data->dates = false; +} + + +OEffectiveEvent::OEffectiveEvent( const OPimEvent& ev, const QDate& startDate, + Position pos ) +{ + data = new Data; + data->event = ev; + data->date = startDate; + if ( pos & Start ) + data->start = ev.startDateTime().time(); + else + data->start = QTime( 0, 0, 0 ); + + if ( pos & End ) + data->end = ev.endDateTime().time(); + else + data->end = QTime( 23, 59, 59 ); + + data->dates = false; +} + + +OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev ) +{ + data = ev.data; + data->ref(); +} + + +OEffectiveEvent::~OEffectiveEvent() +{ + if ( data->deref() ) + { + delete data; + data = 0; + } +} + + +OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) +{ + if ( *this == ev ) return * this; + + ev.data->ref(); + deref(); + data = ev.data; + + return *this; +} + + +void OEffectiveEvent::setStartTime( const QTime& ti ) +{ + changeOrModify(); + data->start = ti; +} + + +void OEffectiveEvent::setEndTime( const QTime& en ) +{ + changeOrModify(); + data->end = en; +} + + +void OEffectiveEvent::setEvent( const OPimEvent& ev ) +{ + changeOrModify(); + data->event = ev; +} + + +void OEffectiveEvent::setDate( const QDate& da ) +{ + changeOrModify(); + data->date = da; +} + + +void OEffectiveEvent::setEffectiveDates( const QDate& from, + const QDate& to ) +{ + if ( !from.isValid() ) + { + data->dates = false; + return ; + } + + data->startDate = from; + data->endDate = to; +} + + +QString OEffectiveEvent::description() const +{ + return data->event.description(); +} + + +QString OEffectiveEvent::location() const +{ + return data->event.location(); +} + + +QString OEffectiveEvent::note() const +{ + return data->event.note(); +} + + +OPimEvent OEffectiveEvent::event() const +{ + return data->event; +} + + +QTime OEffectiveEvent::startTime() const +{ + return data->start; +} + + +QTime OEffectiveEvent::endTime() const +{ + return data->end; +} + + +QDate OEffectiveEvent::date() const +{ + return data->date; +} + + +int OEffectiveEvent::length() const +{ + return ( data->end.hour() * 60 - data->start.hour() * 60 ) + + QABS( data->start.minute() - data->end.minute() ); +} + + +int OEffectiveEvent::size() const +{ + return ( data->end.hour() - data->start.hour() ) * 3600 + + ( data->end.minute() - data->start.minute() * 60 + + data->end.second() - data->start.second() ); +} + + +QDate OEffectiveEvent::startDate() const +{ + if ( data->dates ) + return data->startDate; + else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer + return data->date; + else + return data->event.startDateTime().date(); +} + + +QDate OEffectiveEvent::endDate() const +{ + if ( data->dates ) + return data->endDate; + else if ( data->event.hasRecurrence() ) + return data->date; + else + return data->event.endDateTime().date(); +} + + +void OEffectiveEvent::deref() +{ + if ( data->deref() ) + { + delete data; + data = 0; + } +} + + +void OEffectiveEvent::changeOrModify() +{ + if ( data->count != 1 ) + { + data->deref(); + Data* d2 = new Data; + d2->event = data->event; + d2->date = data->date; + d2->start = data->start; + d2->end = data->end; + d2->startDate = data->startDate; + d2->endDate = data->endDate; + d2->dates = data->dates; + data = d2; + } +} + + +bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const +{ + if ( data->date < e.date() ) + return TRUE; + if ( data->date == e.date() ) + return ( startTime() < e.startTime() ); + else + return FALSE; +} + + +bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const +{ + return ( data->date <= e.date() ); +} + + +bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const +{ + return ( date() == e.date() + && startTime() == e.startTime() + && endTime() == e.endTime() + && event() == e.event() ); +} + + +bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const +{ + return !( *this == e ); +} + + +bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const +{ + return !( *this <= e ); +} + + +bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const +{ + return !( *this < e ); +} + +} diff --git a/libopie2/opiepim/core/opimevent.h b/libopie2/opiepim/core/opimevent.h new file mode 100644 index 0000000..949f263 --- a/dev/null +++ b/libopie2/opiepim/core/opimevent.h @@ -0,0 +1,275 @@ +/* + This file is part of the Opie Project + Copyright (C) Stefan Eilers + =. Copyright (C) The Opie Team + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +// CONTAINS GPLed code of TT + +#ifndef OEVENT_H +#define OEVENT_H + +/* OPIE */ +#include +#include +#include +#include + +/* QT */ +#include +#include +#include + +namespace Opie +{ +struct OCalendarHelper +{ + /** calculate the week number of the date */ + static int week( const QDate& ); + /** calculate the occurence of week days since the start of the month */ + static int ocurrence( const QDate& ); + + // returns the dayOfWeek for the *first* day it finds (ignores + // any further days!). Returns 1 (Monday) if there isn't any day found + static int dayOfWeek( char day ); + + /** returns the diff of month */ + static int monthDiff( const QDate& first, const QDate& second ); + +}; + +class OPimNotifyManager; +class OPimRecurrence; + +/** + * This is the container for all Events. It encapsules all + * available information for a single Event + * @short container for events. + */ +class OPimEvent : public OPimRecord +{ + public: + typedef QValueList ValueList; + /** + * RecordFields contain possible attributes + * used in the Results of toMap().. + */ + enum RecordFields { + FUid = Qtopia::UID_ID, + FCategories = Qtopia::CATEGORY_ID, + FDescription = 0, + FLocation, + FType, + FAlarm, + FSound, + FRType, + FRWeekdays, + FRPosition, + FRFreq, + FRHasEndDate, + FREndDate, + FRCreated, + FRExceptions, + FStart, + FEnd, + FNote, + FTimeZone, + FRecParent, + FRecChildren, + }; + + /** + * Start with an Empty OPimEvent. UID == 0 means that it is empty + */ + OPimEvent( int uid = 0 ); + + /** + * copy c'tor + */ + OPimEvent( const OPimEvent& ); + + /** + * Create OPimEvent, initialized by map + * @see enum RecordFields + */ + OPimEvent( const QMap map ); + ~OPimEvent(); + OPimEvent &operator=( const OPimEvent& ); + + QString description() const; + void setDescription( const QString& description ); + + QString location() const; + void setLocation( const QString& loc ); + + bool hasNotifiers() const; + OPimNotifyManager ¬ifiers() const; + + OPimRecurrence recurrence() const; + void setRecurrence( const OPimRecurrence& ); + bool hasRecurrence() const; + + QString note() const; + void setNote( const QString& note ); + + + QDateTime createdDateTime() const; + void setCreatedDateTime( const QDateTime& dt ); + + /** set the date to dt. dt is the QDateTime in localtime */ + void setStartDateTime( const QDateTime& ); + /** returns the datetime in the local timeZone */ + QDateTime startDateTime() const; + + /** returns the start datetime in the current zone */ + QDateTime startDateTimeInZone() const; + + /** in current timezone */ + void setEndDateTime( const QDateTime& ); + /** in current timezone */ + QDateTime endDateTime() const; + QDateTime endDateTimeInZone() const; + + bool isMultipleDay() const; + bool isAllDay() const; + void setAllDay( bool isAllDay ); + + /* pin this event to a timezone! FIXME */ + void setTimeZone( const QString& timeZone ); + QString timeZone() const; + + + virtual bool match( const QRegExp& ) const; + + /** For exception to recurrence here is a list of children... */ + QArray children() const; + void setChildren( const QArray& ); + void addChild( int uid ); + void removeChild( int uid ); + + /** return the parent OPimEvent */ + int parent() const; + void setParent( int uid ); + + + /* needed reimp */ + QString toRichText() const; + QString toShortText() const; + QString type() const; + + QMap toMap() const; + void fromMap( const QMap& map ); + QString recordField( int ) const; + + static int rtti(); + + bool loadFromStream( QDataStream& ); + bool saveToStream( QDataStream& ) const; + + /* bool operator==( const OPimEvent& ); + bool operator!=( const OPimEvent& ); + bool operator<( const OPimEvent& ); + bool operator<=( const OPimEvent& ); + bool operator>( const OPimEvent& ); + bool operator>=(const OPimEvent& ); + */ + + private: + inline void changeOrModify(); + void deref(); + struct Data; + Data* data; + class Private; + Private* priv; + +}; + +/** + * AN Event can span through multiple days. We split up a multiday eve + */ +class OEffectiveEvent +{ + + public: + typedef QValueList ValueList; + enum Position { MidWay, Start, End, StartEnd }; + // If we calculate the effective event of a multi-day event + // we have to figure out whether we are at the first day, + // at the end, or anywhere else ("middle"). This is important + // for the start/end times (00:00/23:59) + // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi- + // day event + // Start: start time -> 23:59 + // End: 00:00 -> end time + // Start | End == StartEnd: for single-day events (default) + // here we draw start time -> end time + OEffectiveEvent(); + OEffectiveEvent( const OPimEvent& event, const QDate& startDate, Position pos = StartEnd ); + OEffectiveEvent( const OEffectiveEvent& ); + OEffectiveEvent &operator=( const OEffectiveEvent& ); + ~OEffectiveEvent(); + + void setStartTime( const QTime& ); + void setEndTime( const QTime& ); + void setEvent( const OPimEvent& ); + void setDate( const QDate& ); + + void setEffectiveDates( const QDate& from, const QDate& to ); + + QString description() const; + QString location() const; + QString note() const; + OPimEvent event() const; + QTime startTime() const; + QTime endTime() const; + QDate date() const; + + /* return the length in hours */ + int length() const; + int size() const; + + QDate startDate() const; + QDate endDate() const; + + bool operator<( const OEffectiveEvent &e ) const; + bool operator<=( const OEffectiveEvent &e ) const; + bool operator==( const OEffectiveEvent &e ) const; + bool operator!=( const OEffectiveEvent &e ) const; + bool operator>( const OEffectiveEvent &e ) const; + bool operator>= ( const OEffectiveEvent &e ) const; + + private: + void deref(); + inline void changeOrModify(); + class Private; + Private* priv; + struct Data; + Data* data; + +}; + +} + +#endif diff --git a/libopie2/opiepim/core/opimnotify.h b/libopie2/opiepim/core/opimnotify.h index d0e40ca..4f74d2e 100644 --- a/libopie2/opiepim/core/opimnotify.h +++ b/libopie2/opiepim/core/opimnotify.h @@ -138,7 +138,7 @@ class OPimAlarm : public OPimNotify * A Reminder will be put into the * datebook * Note that the returned dateTime() may be not valid. - * In these cases one must resolve the uid and get the OEvent + * In these cases one must resolve the uid and get the OPimEvent */ class OPimReminder : public OPimNotify { diff --git a/libopie2/opiepim/core/opimnotifymanager.cpp b/libopie2/opiepim/core/opimnotifymanager.cpp index a54d597..573340a 100644 --- a/libopie2/opiepim/core/opimnotifymanager.cpp +++ b/libopie2/opiepim/core/opimnotifymanager.cpp @@ -30,7 +30,7 @@ #include "opimnotifymanager.h" /* OPIE */ -#include +#include /* QT */ #include @@ -184,7 +184,7 @@ QString OPimNotifyManager::alarmsToString() const /* only if time is valid */ if ( ( *it ).dateTime().isValid() ) { - als << OConversion::dateTimeToString( ( *it ).dateTime() ) + als << OPimDateConversion::dateTimeToString( ( *it ).dateTime() ) + ":" + QString::number( ( *it ).duration() ) + ":" + QString::number( ( *it ).sound() ) + ":"; @@ -227,8 +227,8 @@ void OPimNotifyManager::alarmsFromString( const QString& str ) 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 ] ), + OPimDateConversion::dateTimeFromString( alarm[ 0 ] ).toString().latin1() ); + OPimAlarm al( alarm[ 2 ].toInt(), OPimDateConversion::dateTimeFromString( alarm[ 0 ] ), alarm[ 1 ].toInt() ); add( al ); } diff --git a/libopie2/opiepim/core/opimrecordlist.h b/libopie2/opiepim/core/opimrecordlist.h new file mode 100644 index 0000000..b23138d --- a/dev/null +++ b/libopie2/opiepim/core/opimrecordlist.h @@ -0,0 +1,402 @@ +/* + This file is part of the Opie Project + Copyright (C) The Main Author + =. Copyright (C) The Opie Team + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef ORECORDLIST_H +#define ORECORDLIST_H + +/* OPIE */ +#include +#include + +/* QT */ +#include + +namespace Opie +{ + +class OPimRecordListIteratorPrivate; +/** + * Our List Iterator + * it behaves like STL or Qt + * + * for(it = list.begin(); it != list.end(); ++it ) + * doSomeCoolStuff( (*it) ); + */ +template class OPimRecordList; +template +class OPimRecordListIterator +{ + friend class OPimRecordList; + + public: + typedef OTemplateBase Base; + + /** + * The c'tor used internally from + * OPimRecordList + */ + OPimRecordListIterator( const QArray, const Base* ); + + /** + * The standard c'tor + */ + OPimRecordListIterator(); + ~OPimRecordListIterator(); + + OPimRecordListIterator( const OPimRecordListIterator& ); + OPimRecordListIterator &operator=( const OPimRecordListIterator& ); + + /** + * a * operator ;) + * use it like this T = (*it); + */ + T operator*(); + OPimRecordListIterator &operator++(); + OPimRecordListIterator &operator--(); + + bool operator==( const OPimRecordListIterator& it ); + bool operator!=( const OPimRecordListIterator& it ); + + /** + * the current item + */ + uint current() const; + + /** + * the number of items + */ + uint count() const; + + /** + * sets the current item + */ + void setCurrent( uint cur ); + + private: + QArray m_uids; + uint m_current; + const Base* m_temp; + bool m_end : 1; + T m_record; + bool m_direction : 1; + + /* d pointer for future versions */ + OPimRecordListIteratorPrivate *d; +}; + + +class OPimRecordListPrivate; +/** + * The recordlist used as a return type + * from OPimAccessTemplate + */ +template +class OPimRecordList +{ + public: + typedef OTemplateBase Base; + typedef OPimRecordListIterator Iterator; + + /** + * c'tor + */ + OPimRecordList () + {} + OPimRecordList( const QArray& ids, + const Base* ); + ~OPimRecordList(); + + /** + * the first iterator + */ + Iterator begin(); + + /** + * the end + */ + Iterator end(); + + /** + * the number of items in the list + */ + uint count() const; + + T operator[] ( uint i ); + int uidAt( uint i ); + + /** + * Remove the contact with given uid + */ + bool remove( int uid ); + + /* + ConstIterator begin()const; + ConstIterator end()const; + */ + private: + QArray m_ids; + const Base* m_acc; + OPimRecordListPrivate *d; +}; + + +/* ok now implement it */ +template +OPimRecordListIterator::OPimRecordListIterator() +{ + m_current = 0; + m_temp = 0l; + m_end = true; + m_record = T(); + /* forward */ + m_direction = TRUE; +} + + +template +OPimRecordListIterator::~OPimRecordListIterator() +{ + /* nothing to delete */ +} + + +template +OPimRecordListIterator::OPimRecordListIterator( const OPimRecordListIterator& it ) +{ + // qWarning("OPimRecordListIterator copy c'tor"); + m_uids = it.m_uids; + m_current = it.m_current; + m_temp = it.m_temp; + m_end = it.m_end; + m_record = it.m_record; + m_direction = it.m_direction; +} + + +template +OPimRecordListIterator &OPimRecordListIterator::operator=( const OPimRecordListIterator& it ) +{ + m_uids = it.m_uids; + m_current = it.m_current; + m_temp = it.m_temp; + m_end = it.m_end; + m_record = it.m_record; + + return *this; +} + + +template +T OPimRecordListIterator::operator*() +{ + //qWarning("operator* %d %d", m_current, m_uids[m_current] ); + if ( !m_end ) + m_record = m_temp->find( m_uids[ m_current ], m_uids, m_current, + m_direction ? Base::Forward : + Base::Reverse ); + else + m_record = T(); + + return m_record; +} + + +template +OPimRecordListIterator &OPimRecordListIterator::operator++() +{ + m_direction = true; + if ( m_current < m_uids.count() ) + { + m_end = false; + ++m_current; + } + else + m_end = true; + + return *this; +} + + +template +OPimRecordListIterator &OPimRecordListIterator::operator--() +{ + m_direction = false; + if ( m_current > 0 ) + { + --m_current; + m_end = false; + } + else + m_end = true; + + return *this; +} + + +template +bool OPimRecordListIterator::operator==( const OPimRecordListIterator& it ) +{ + + /* if both are at we're the same.... */ + if ( m_end == it.m_end ) return true; + + if ( m_uids != it.m_uids ) return false; + if ( m_current != it.m_current ) return false; + if ( m_temp != it.m_temp ) return false; + + return true; +} + + +template +bool OPimRecordListIterator::operator!=( const OPimRecordListIterator& it ) +{ + return !( *this == it ); +} + + +template +OPimRecordListIterator::OPimRecordListIterator( const QArray uids, + const Base* t ) + : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), + m_direction( false ) +{ + /* if the list is empty we're already at the end of the list */ + if ( uids.count() == 0 ) + m_end = true; +} + + +template +uint OPimRecordListIterator::current() const +{ + return m_current; +} + + +template +void OPimRecordListIterator::setCurrent( uint cur ) +{ + if ( cur < m_uids.count() ) + { + m_end = false; + m_current = cur; + } +} +template +uint OPimRecordListIterator::count() const +{ + return m_uids.count(); +} + + +template +OPimRecordList::OPimRecordList( const QArray& ids, + const Base* acc ) + : m_ids( ids ), m_acc( acc ) +{} + + +template +OPimRecordList::~OPimRecordList() +{ + /* nothing to do here */ +} + + +template +typename OPimRecordList::Iterator OPimRecordList::begin() +{ + Iterator it( m_ids, m_acc ); + return it; +} + + +template +typename OPimRecordList::Iterator OPimRecordList::end() +{ + Iterator it( m_ids, m_acc ); + it.m_end = true; + it.m_current = m_ids.count(); + + return it; +} + + +template +uint OPimRecordList::count() const +{ + return m_ids.count(); +} + + +template +T OPimRecordList::operator[] ( uint i ) +{ + if ( i >= m_ids.count() ) + return T(); + /* forward */ + return m_acc->find( m_ids[ i ], m_ids, i ); +} + + +template +int OPimRecordList::uidAt( uint i ) +{ + return m_ids[ i ]; +} + + +template +bool OPimRecordList::remove( int uid ) +{ + QArray copy( m_ids.count() ); + int counter = 0; + bool ret_val = false; + + for ( uint i = 0; i < m_ids.count(); i++ ) + { + if ( m_ids[ i ] != uid ) + { + copy[ counter++ ] = m_ids[ i ]; + + } + else + ret_val = true; + } + + copy.resize( counter ); + m_ids = copy; + + + return ret_val; +} + +} +#endif diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/opimrecurrence.cpp index 5e2da25..98bd647 100644 --- a/libopie2/opiepim/core/orecur.cpp +++ b/libopie2/opiepim/core/opimrecurrence.cpp @@ -27,10 +27,10 @@ Boston, MA 02111-1307, USA. */ -#include "orecur.h" +#include "opimrecurrence.h" /* OPIE */ -#include +#include #include /* QT */ @@ -41,9 +41,9 @@ namespace Opie { -struct ORecur::Data : public QShared { +struct OPimRecurrence::Data : public QShared { Data() : QShared() { - type = ORecur::NoRepeat; + type = OPimRecurrence::NoRepeat; freq = -1; days = 0; pos = 0; @@ -52,7 +52,7 @@ struct ORecur::Data : public QShared { end = QDate::currentDate(); } char days; // Q_UINT8 for 8 seven days;) - ORecur::RepeatType type; + OPimRecurrence::RepeatType type; int freq; int pos; bool hasEnd : 1; @@ -65,25 +65,25 @@ struct ORecur::Data : public QShared { }; -ORecur::ORecur() { +OPimRecurrence::OPimRecurrence() { data = new Data; } -ORecur::ORecur( const QMap& map ) +OPimRecurrence::OPimRecurrence( const QMap& map ) { - ORecur(); + OPimRecurrence(); fromMap( map ); } -ORecur::ORecur( const ORecur& rec) +OPimRecurrence::OPimRecurrence( const OPimRecurrence& rec) : data( rec.data ) { data->ref(); } -ORecur::~ORecur() { +OPimRecurrence::~OPimRecurrence() { if ( data->deref() ) { delete data; data = 0l; @@ -91,7 +91,7 @@ ORecur::~ORecur() { } -void ORecur::deref() { +void OPimRecurrence::deref() { if ( data->deref() ) { delete data; data = 0l; @@ -99,12 +99,12 @@ void ORecur::deref() { } -bool ORecur::operator==( const ORecur& )const { +bool OPimRecurrence::operator==( const OPimRecurrence& )const { return false; } -ORecur &ORecur::operator=( const ORecur& re) { +OPimRecurrence &OPimRecurrence::operator=( const OPimRecurrence& re) { if ( *this == re ) return *this; re.data->ref(); @@ -115,7 +115,7 @@ ORecur &ORecur::operator=( const ORecur& re) { } -bool ORecur::doesRecur()const { +bool OPimRecurrence::doesRecur()const { return !( type() == NoRepeat ); } @@ -124,7 +124,7 @@ bool ORecur::doesRecur()const { * we try to be smart here * */ -bool ORecur::doesRecur( const QDate& date ) { +bool OPimRecurrence::doesRecur( const QDate& date ) { /* the day before the recurrance */ QDate da = date.addDays(-1); @@ -139,7 +139,7 @@ bool ORecur::doesRecur( const QDate& date ) { // FIXME unuglify! // GPL from Datebookdb.cpp // FIXME exception list! -bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { +bool OPimRecurrence::nextOcurrence( const QDate& from, QDate& next ) { bool stillLooking; stillLooking = p_nextOccurrence( from, next ); while ( stillLooking && data->list.contains(next) ) @@ -149,7 +149,7 @@ bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { } -bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) { +bool OPimRecurrence::p_nextOccurrence( const QDate& from, QDate& next ) { // easy checks, first are we too far in the future or too far in the past? QDate tmpDate; @@ -423,122 +423,122 @@ bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) { } -ORecur::RepeatType ORecur::type()const{ +OPimRecurrence::RepeatType OPimRecurrence::type()const{ return data->type; } -int ORecur::frequency()const { +int OPimRecurrence::frequency()const { return data->freq; } -int ORecur::position()const { +int OPimRecurrence::position()const { return data->pos; } -char ORecur::days() const{ +char OPimRecurrence::days() const{ return data->days; } -bool ORecur::hasEndDate()const { +bool OPimRecurrence::hasEndDate()const { return data->hasEnd; } -QDate ORecur::endDate()const { +QDate OPimRecurrence::endDate()const { return data->end; } -QDate ORecur::start()const{ +QDate OPimRecurrence::start()const{ return data->start; } -QDateTime ORecur::createdDateTime()const { +QDateTime OPimRecurrence::createdDateTime()const { return data->create; } -int ORecur::repetition()const { +int OPimRecurrence::repetition()const { return data->rep; } -QString ORecur::service()const { +QString OPimRecurrence::service()const { return data->app; } -ORecur::ExceptionList& ORecur::exceptions() { +OPimRecurrence::ExceptionList& OPimRecurrence::exceptions() { return data->list; } -void ORecur::setType( const RepeatType& z) { +void OPimRecurrence::setType( const RepeatType& z) { checkOrModify(); data->type = z; } -void ORecur::setFrequency( int freq ) { +void OPimRecurrence::setFrequency( int freq ) { checkOrModify(); data->freq = freq; } -void ORecur::setPosition( int pos ) { +void OPimRecurrence::setPosition( int pos ) { checkOrModify(); data->pos = pos; } -void ORecur::setDays( char c ) { +void OPimRecurrence::setDays( char c ) { checkOrModify(); data->days = c; } -void ORecur::setEndDate( const QDate& dt) { +void OPimRecurrence::setEndDate( const QDate& dt) { checkOrModify(); data->end = dt; } -void ORecur::setCreatedDateTime( const QDateTime& t) { +void OPimRecurrence::setCreatedDateTime( const QDateTime& t) { checkOrModify(); data->create = t; } -void ORecur::setHasEndDate( bool b) { +void OPimRecurrence::setHasEndDate( bool b) { checkOrModify(); data->hasEnd = b; } -void ORecur::setRepitition( int rep ) { +void OPimRecurrence::setRepitition( int rep ) { checkOrModify(); data->rep = rep; } -void ORecur::setService( const QString& app ) { +void OPimRecurrence::setService( const QString& app ) { checkOrModify(); data->app = app; } -void ORecur::setStart( const QDate& dt ) { +void OPimRecurrence::setStart( const QDate& dt ) { checkOrModify(); data->start = dt; } -void ORecur::checkOrModify() { +void OPimRecurrence::checkOrModify() { if ( data->count != 1 ) { data->deref(); Data* d2 = new Data; @@ -558,51 +558,51 @@ void ORecur::checkOrModify() { } -QString ORecur::toString()const { +QString OPimRecurrence::toString()const { QString buf; QMap recMap = toMap(); buf += " rtype=\""; - buf += recMap[ORecur::RType]; + buf += recMap[OPimRecurrence::RType]; buf += "\""; if (data->days > 0 ) - buf += " rweekdays=\"" + recMap[ORecur::RWeekdays] + "\""; + buf += " rweekdays=\"" + recMap[OPimRecurrence::RWeekdays] + "\""; if ( data->pos != 0 ) - buf += " rposition=\"" + recMap[ORecur::RPosition] + "\""; + buf += " rposition=\"" + recMap[OPimRecurrence::RPosition] + "\""; - buf += " rfreq=\"" + recMap[ORecur::RFreq] + "\""; - buf += " rhasenddate=\"" + recMap[ORecur::RHasEndDate]+ "\""; + buf += " rfreq=\"" + recMap[OPimRecurrence::RFreq] + "\""; + buf += " rhasenddate=\"" + recMap[OPimRecurrence::RHasEndDate]+ "\""; if ( data->hasEnd ) buf += " enddt=\"" - + recMap[ORecur::EndDate] + + recMap[OPimRecurrence::EndDate] + "\""; - buf += " created=\"" + recMap[ORecur::Created] + "\""; + buf += " created=\"" + recMap[OPimRecurrence::Created] + "\""; if ( data->list.isEmpty() ) return buf; buf += " exceptions=\""; - buf += recMap[ORecur::Exceptions]; + buf += recMap[OPimRecurrence::Exceptions]; buf += "\" "; return buf; } -QString ORecur::rTypeString() const +QString OPimRecurrence::rTypeString() const { QString retString; switch ( data->type ) { - case ORecur::Daily: + case OPimRecurrence::Daily: retString = "Daily"; break; - case ORecur::Weekly: + case OPimRecurrence::Weekly: retString = "Weekly"; break; - case ORecur::MonthlyDay: + case OPimRecurrence::MonthlyDay: retString = "MonthlyDay"; break; - case ORecur::MonthlyDate: + case OPimRecurrence::MonthlyDate: retString = "MonthlyDate"; break; - case ORecur::Yearly: + case OPimRecurrence::Yearly: retString = "Yearly"; break; default: @@ -614,33 +614,33 @@ QString ORecur::rTypeString() const return retString; } -QMap ORecur::rTypeValueConvertMap() const +QMap OPimRecurrence::rTypeValueConvertMap() const { QMap convertMap; - convertMap.insert( QString( "Daily" ), ORecur::Daily ); - convertMap.insert( QString( "Weekly" ), ORecur::Weekly ); - convertMap.insert( QString( "MonthlyDay" ), ORecur::MonthlyDay ); - convertMap.insert( QString( "MonthlyDate" ), ORecur::MonthlyDate ); - convertMap.insert( QString( "Yearly" ), ORecur::Yearly ); - convertMap.insert( QString( "NoRepeat" ), ORecur::NoRepeat ); + convertMap.insert( QString( "Daily" ), OPimRecurrence::Daily ); + convertMap.insert( QString( "Weekly" ), OPimRecurrence::Weekly ); + convertMap.insert( QString( "MonthlyDay" ), OPimRecurrence::MonthlyDay ); + convertMap.insert( QString( "MonthlyDate" ), OPimRecurrence::MonthlyDate ); + convertMap.insert( QString( "Yearly" ), OPimRecurrence::Yearly ); + convertMap.insert( QString( "NoRepeat" ), OPimRecurrence::NoRepeat ); return convertMap; } -QMap ORecur::toMap() const +QMap OPimRecurrence::toMap() const { QMap retMap; - retMap.insert( ORecur::RType, rTypeString() ); - retMap.insert( ORecur::RWeekdays, QString::number( static_cast( data->days ) ) ); - retMap.insert( ORecur::RPosition, QString::number(data->pos ) ); - retMap.insert( ORecur::RFreq, QString::number( data->freq ) ); - retMap.insert( ORecur::RHasEndDate, QString::number( static_cast( data->hasEnd ) ) ); + retMap.insert( OPimRecurrence::RType, rTypeString() ); + retMap.insert( OPimRecurrence::RWeekdays, QString::number( static_cast( data->days ) ) ); + retMap.insert( OPimRecurrence::RPosition, QString::number(data->pos ) ); + retMap.insert( OPimRecurrence::RFreq, QString::number( data->freq ) ); + retMap.insert( OPimRecurrence::RHasEndDate, QString::number( static_cast( data->hasEnd ) ) ); if( data -> hasEnd ) - retMap.insert( ORecur::EndDate, QString::number( OTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) ); - retMap.insert( ORecur::Created, QString::number( OTimeZone::utc().fromUTCDateTime( data->create ) ) ); + retMap.insert( OPimRecurrence::EndDate, QString::number( OPimTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) ); + retMap.insert( OPimRecurrence::Created, QString::number( OPimTimeZone::utc().fromUTCDateTime( data->create ) ) ); if ( data->list.isEmpty() ) return retMap; @@ -656,31 +656,31 @@ QMap ORecur::toMap() const exceptBuf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); } - retMap.insert( ORecur::Exceptions, exceptBuf ); + retMap.insert( OPimRecurrence::Exceptions, exceptBuf ); return retMap; } -void ORecur::fromMap( const QMap& map ) +void OPimRecurrence::fromMap( const QMap& map ) { QMap repTypeMap = rTypeValueConvertMap(); - data -> type = repTypeMap[ map [ORecur::RType] ]; - data -> days = (char) map[ ORecur::RWeekdays ].toInt(); - data -> pos = map[ ORecur::RPosition ].toInt(); - data -> freq = map[ ORecur::RFreq ].toInt(); - data -> hasEnd= map[ ORecur::RHasEndDate ].toInt() ? true : false; - OTimeZone utc = OTimeZone::utc(); + data -> type = repTypeMap[ map [OPimRecurrence::RType] ]; + data -> days = (char) map[ OPimRecurrence::RWeekdays ].toInt(); + data -> pos = map[ OPimRecurrence::RPosition ].toInt(); + data -> freq = map[ OPimRecurrence::RFreq ].toInt(); + data -> hasEnd= map[ OPimRecurrence::RHasEndDate ].toInt() ? true : false; + OPimTimeZone utc = OPimTimeZone::utc(); if ( data -> hasEnd ){ - data -> end = utc.fromUTCDateTime( (time_t) map[ ORecur::EndDate ].toLong() ).date(); + data -> end = utc.fromUTCDateTime( (time_t) map[ OPimRecurrence::EndDate ].toLong() ).date(); } - data -> create = utc.fromUTCDateTime( (time_t) map[ ORecur::Created ].toLong() ).date(); + data -> create = utc.fromUTCDateTime( (time_t) map[ OPimRecurrence::Created ].toLong() ).date(); #if 0 // FIXME: Exceptions currently not supported... // Convert the list of exceptions from QString into ExceptionList data -> list.clear(); - QString exceptStr = map[ ORecur::Exceptions ]; + QString exceptStr = map[ OPimRecurrence::Exceptions ]; QStringList exceptList = QStringList::split( " ", exceptStr ); ... #endif diff --git a/libopie2/opiepim/core/orecur.h b/libopie2/opiepim/core/opimrecurrence.h index 7808897..f186cfe 100644 --- a/libopie2/opiepim/core/orecur.h +++ b/libopie2/opiepim/core/opimrecurrence.h @@ -43,7 +43,7 @@ namespace Opie { * Class to handle Recurrencies.. */ -class ORecur { +class OPimRecurrence { public: typedef QValueList ExceptionList; @@ -54,13 +54,13 @@ class ORecur { enum Fields{ RType = 0, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions }; - ORecur(); - ORecur( const QMap& map ); - ORecur( const ORecur& ); - ~ORecur(); + OPimRecurrence(); + OPimRecurrence( const QMap& map ); + OPimRecurrence( const OPimRecurrence& ); + ~OPimRecurrence(); - ORecur &operator=( const ORecur& ); - bool operator==(const ORecur& )const; + OPimRecurrence &operator=( const OPimRecurrence& ); + bool operator==(const OPimRecurrence& )const; bool doesRecur()const; /* if it recurrs on that day */ @@ -85,7 +85,7 @@ class ORecur { bool nextOcurrence( const QDate& FromWhereToStart, QDate &recurDate ); /** - * The module this ORecur belongs to + * The module this OPimRecurrence belongs to */ QString service()const; @@ -129,8 +129,8 @@ class ORecur { class Data; Data* data; - class ORecurPrivate; - ORecurPrivate *d; + class OPimRecurrencePrivate; + OPimRecurrencePrivate *d; }; } diff --git a/libopie2/opiepim/core/opimresolver.cpp b/libopie2/opiepim/core/opimresolver.cpp index 73d7de1..eb6661a 100644 --- a/libopie2/opiepim/core/opimresolver.cpp +++ b/libopie2/opiepim/core/opimresolver.cpp @@ -72,9 +72,9 @@ OPimRecord* OPimResolver::record( int rtti ) { OPimRecord* rec = 0l; switch( rtti ) { case 1: /* todolist */ - rec = new OTodo(); + rec = new OPimTodo(); case 2: /* contact */ - rec = new OContact(); + rec = new OPimContact(); default: break; } @@ -211,12 +211,12 @@ OPimBase* OPimResolver::backend( int rtti ) { OPimBase* base = 0l; switch( rtti ) { case TodoList: - base = new OTodoAccess(); + base = new OPimTodoAccess(); break; case DateBook: break; case AddressBook: - base = new OContactAccess("Resolver"); + base = new OPimContactAccess("Resolver"); break; default: break; diff --git a/libopie2/opiepim/core/opimresolver.h b/libopie2/opiepim/core/opimresolver.h index dd6f07f..0a6dddf 100644 --- a/libopie2/opiepim/core/opimresolver.h +++ b/libopie2/opiepim/core/opimresolver.h @@ -30,7 +30,7 @@ #define OPIMRESOLVER_H /* OPIE */ -#include +#include /* QT */ #include diff --git a/libopie2/opiepim/core/otemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h index 58cbfeb..58cbfeb 100644 --- a/libopie2/opiepim/core/otemplatebase.h +++ b/libopie2/opiepim/core/opimtemplatebase.h diff --git a/libopie2/opiepim/core/otimezone.cpp b/libopie2/opiepim/core/opimtimezone.cpp index e67715f..be21b1b 100644 --- a/libopie2/opiepim/core/otimezone.cpp +++ b/libopie2/opiepim/core/opimtimezone.cpp @@ -27,7 +27,7 @@ Boston, MA 02111-1307, USA. */ -#include "otimezone.h" +#include "opimtimezone.h" /* STD */ #include @@ -100,16 +100,16 @@ time_t to_Time_t( const QDateTime& utc, const QString& str ) namespace Opie { -OTimeZone::OTimeZone( const ZoneName& zone ) +OPimTimeZone::OPimTimeZone( const ZoneName& zone ) : m_name( zone ) {} -OTimeZone::~OTimeZone() +OPimTimeZone::~OPimTimeZone() {} -bool OTimeZone::isValid() const +bool OPimTimeZone::isValid() const { return !m_name.isEmpty(); } @@ -118,25 +118,25 @@ bool OTimeZone::isValid() const * we will get the current timezone * and ask it to convert to the timezone date */ -QDateTime OTimeZone::toLocalDateTime( const QDateTime& dt ) +QDateTime OPimTimeZone::toLocalDateTime( const QDateTime& dt ) { - return OTimeZone::current().toDateTime( dt, *this ); + return OPimTimeZone::current().toDateTime( dt, *this ); } -QDateTime OTimeZone::toUTCDateTime( const QDateTime& dt ) +QDateTime OPimTimeZone::toUTCDateTime( const QDateTime& dt ) { - return OTimeZone::utc().toDateTime( dt, *this ); + return OPimTimeZone::utc().toDateTime( dt, *this ); } -QDateTime OTimeZone::fromUTCDateTime( time_t t ) +QDateTime OPimTimeZone::fromUTCDateTime( time_t t ) { return utcTime( t ); } -QDateTime OTimeZone::toDateTime( time_t t ) +QDateTime OPimTimeZone::toDateTime( time_t t ) { return utcTime( t, m_name ); } @@ -146,7 +146,7 @@ QDateTime OTimeZone::toDateTime( time_t t ) * convert dt to utc using zone.m_name * convert utc -> timeZoneDT using this->m_name */ -QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone ) +QDateTime OPimTimeZone::toDateTime( const QDateTime& dt, const OPimTimeZone& zone ) { time_t utc = to_Time_t( dt, zone.m_name ); qWarning( "%d %s", utc, zone.m_name.latin1() ); @@ -154,33 +154,33 @@ QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone ) } -time_t OTimeZone::fromDateTime( const QDateTime& time ) +time_t OPimTimeZone::fromDateTime( const QDateTime& time ) { return to_Time_t( time, m_name ); } -time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) +time_t OPimTimeZone::fromUTCDateTime( const QDateTime& time ) { return to_Time_t( time, "UTC" ); } -OTimeZone OTimeZone::current() +OPimTimeZone OPimTimeZone::current() { QCString str = ::getenv( "TZ" ); - OTimeZone zone( str ); + OPimTimeZone zone( str ); return zone; } -OTimeZone OTimeZone::utc() +OPimTimeZone OPimTimeZone::utc() { - return OTimeZone( "UTC" ); + return OPimTimeZone( "UTC" ); } -QString OTimeZone::timeZone() const +QString OPimTimeZone::timeZone() const { return m_name; } diff --git a/libopie2/opiepim/core/otimezone.h b/libopie2/opiepim/core/opimtimezone.h index f0b4022..284e80f 100644 --- a/libopie2/opiepim/core/otimezone.h +++ b/libopie2/opiepim/core/opimtimezone.h @@ -44,12 +44,12 @@ namespace Opie * and to localtime * and time_t */ -class OTimeZone { +class OPimTimeZone { public: typedef QString ZoneName; - OTimeZone( const ZoneName& = ZoneName::null ); - virtual ~OTimeZone(); // just in case. + OPimTimeZone( const ZoneName& = ZoneName::null ); + virtual ~OPimTimeZone(); // just in case. bool isValid()const; @@ -80,7 +80,7 @@ class OTimeZone { /** * converts the QDateTime from one timezone to this timeZone */ - QDateTime toDateTime( const QDateTime&, const OTimeZone& timeZone ); + QDateTime toDateTime( const QDateTime&, const OPimTimeZone& timeZone ); /** * converts the date time into a time_t. It takes the timezone into account @@ -92,8 +92,8 @@ class OTimeZone { */ time_t fromUTCDateTime( const QDateTime& ); - static OTimeZone current(); - static OTimeZone utc(); + static OPimTimeZone current(); + static OPimTimeZone utc(); QString timeZone() const; diff --git a/libopie2/opiepim/core/opimtodo.cpp b/libopie2/opiepim/core/opimtodo.cpp new file mode 100644 index 0000000..34df807 --- a/dev/null +++ b/libopie2/opiepim/core/opimtodo.cpp @@ -0,0 +1,712 @@ +/* + This file is part of the Opie Project + Copyright (C) The Main Author + =. Copyright (C) The Opie Team + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include "opimtodo.h" + +/* OPIE */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* QT */ +#include +#include + +namespace Opie +{ + +struct OPimTodo::OPimTodoData : public QShared +{ + OPimTodoData() : QShared() + { + recur = 0; + state = 0; + maintainer = 0; + notifiers = 0; + }; + ~OPimTodoData() + { + delete recur; + delete maintainer; + delete notifiers; + } + + QDate date; + bool isCompleted: 1; + bool hasDate: 1; + int priority; + QString desc; + QString sum; + QMap extra; + ushort prog; + OPimState *state; + OPimRecurrence *recur; + OPimMaintainer *maintainer; + QDate start; + QDate completed; + OPimNotifyManager *notifiers; +}; + + +OPimTodo::OPimTodo( const OPimTodo &event ) + : OPimRecord( event ), data( event.data ) +{ + data->ref(); + // qWarning("ref up"); +} + + +OPimTodo::~OPimTodo() +{ + + // qWarning("~OPimTodo " ); + if ( data->deref() ) + { + // qWarning("OPimTodo::dereffing"); + delete data; + data = 0l; + } +} + + +OPimTodo::OPimTodo( bool completed, int priority, + const QArray &category, + const QString& summary, + const QString &description, + ushort progress, + bool hasDate, QDate date, int uid ) + : OPimRecord( uid ) +{ + // qWarning("OPimTodoData " + summary); + setCategories( category ); + + data = new OPimTodoData; + + data->date = date; + data->isCompleted = completed; + data->hasDate = hasDate; + data->priority = priority; + data->sum = summary; + data->prog = progress; + data->desc = Qtopia::simplifyMultiLineSpace( description ); +} + + +OPimTodo::OPimTodo( bool completed, int priority, + const QStringList &category, + const QString& summary, + const QString &description, + ushort progress, + bool hasDate, QDate date, int uid ) + : OPimRecord( uid ) +{ + // qWarning("OPimTodoData" + summary); + setCategories( idsFromString( category.join( ";" ) ) ); + + data = new OPimTodoData; + + data->date = date; + data->isCompleted = completed; + data->hasDate = hasDate; + data->priority = priority; + data->sum = summary; + data->prog = progress; + data->desc = Qtopia::simplifyMultiLineSpace( description ); +} + + +bool OPimTodo::match( const QRegExp ®Exp ) const +{ + if ( QString::number( data->priority ).find( regExp ) != -1 ) + { + setLastHitField( Priority ); + return true; + } + else if ( data->hasDate && data->date.toString().find( regExp ) != -1 ) + { + setLastHitField( HasDate ); + return true; + } + else if ( data->desc.find( regExp ) != -1 ) + { + setLastHitField( Description ); + return true; + } + else if ( data->sum.find( regExp ) != -1 ) + { + setLastHitField( Summary ); + return true; + } + return false; +} + + +bool OPimTodo::isCompleted() const +{ + return data->isCompleted; +} + + +bool OPimTodo::hasDueDate() const +{ + return data->hasDate; +} + + +bool OPimTodo::hasStartDate() const +{ + return data->start.isValid(); +} + + +bool OPimTodo::hasCompletedDate() const +{ + return data->completed.isValid(); +} + + +int OPimTodo::priority() const +{ + return data->priority; +} + + +QString OPimTodo::summary() const +{ + return data->sum; +} + + +ushort OPimTodo::progress() const +{ + return data->prog; +} + + +QDate OPimTodo::dueDate() const +{ + return data->date; +} + + +QDate OPimTodo::startDate() const +{ + return data->start; +} + + +QDate OPimTodo::completedDate() const +{ + return data->completed; +} + + +QString OPimTodo::description() const +{ + return data->desc; +} + + +bool OPimTodo::hasState() const +{ + if ( !data->state ) return false; + return ( data->state->state() != OPimState::Undefined ); +} + + +OPimState OPimTodo::state() const +{ + if ( !data->state ) + { + OPimState state; + return state; + } + + return ( *data->state ); +} + + +bool OPimTodo::hasRecurrence() const +{ + if ( !data->recur ) return false; + return data->recur->doesRecur(); +} + + +OPimRecurrence OPimTodo::recurrence() const +{ + if ( !data->recur ) return OPimRecurrence(); + + return ( *data->recur ); +} + + +bool OPimTodo::hasMaintainer() const +{ + if ( !data->maintainer ) return false; + + return ( data->maintainer->mode() != OPimMaintainer::Undefined ); +} + + +OPimMaintainer OPimTodo::maintainer() const +{ + if ( !data->maintainer ) return OPimMaintainer(); + + return ( *data->maintainer ); +} + + +void OPimTodo::setCompleted( bool completed ) +{ + changeOrModify(); + data->isCompleted = completed; +} + + +void OPimTodo::setHasDueDate( bool hasDate ) +{ + changeOrModify(); + data->hasDate = hasDate; +} + + +void OPimTodo::setDescription( const QString &desc ) +{ + // qWarning( "desc " + desc ); + changeOrModify(); + data->desc = Qtopia::simplifyMultiLineSpace( desc ); +} + + +void OPimTodo::setSummary( const QString& sum ) +{ + changeOrModify(); + data->sum = sum; +} + + +void OPimTodo::setPriority( int prio ) +{ + changeOrModify(); + data->priority = prio; +} + + +void OPimTodo::setDueDate( const QDate& date ) +{ + changeOrModify(); + data->date = date; +} + + +void OPimTodo::setStartDate( const QDate& date ) +{ + changeOrModify(); + data->start = date; +} + + +void OPimTodo::setCompletedDate( const QDate& date ) +{ + changeOrModify(); + data->completed = date; +} + + +void OPimTodo::setState( const OPimState& state ) +{ + changeOrModify(); + if ( data->state ) + ( *data->state ) = state; + else + data->state = new OPimState( state ); +} + + +void OPimTodo::setRecurrence( const OPimRecurrence& rec ) +{ + changeOrModify(); + if ( data->recur ) + ( *data->recur ) = rec; + else + data->recur = new OPimRecurrence( rec ); +} + + +void OPimTodo::setMaintainer( const OPimMaintainer& pim ) +{ + changeOrModify(); + + if ( data->maintainer ) + ( *data->maintainer ) = pim; + else + data->maintainer = new OPimMaintainer( pim ); +} + + +bool OPimTodo::isOverdue( ) +{ + if ( data->hasDate && !data->isCompleted ) + return QDate::currentDate() > data->date; + return false; +} + + +void OPimTodo::setProgress( ushort progress ) +{ + changeOrModify(); + data->prog = progress; +} + + +QString OPimTodo::toShortText() const +{ + return summary(); +} + + +/*! + Returns a richt text string +*/ +QString OPimTodo::toRichText() const +{ + QString text; + QStringList catlist; + + // summary + text += "

"; + if ( !summary().isEmpty() ) + { + text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" ); + } + text += "




"; + + // description + if ( !description().isEmpty() ) + { + text += "" + QObject::tr( "Description:" ) + "
"; + text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "
" ) + "
"; + } + + // priority + int priorityval = priority(); + text += "" + QObject::tr( "Priority:" ) + " "; + + switch ( priorityval ) + { + case 1 : text += QObject::tr( "Very high" ); + break; + case 2 : text += QObject::tr( "High" ); + break; + case 3 : text += QObject::tr( "Normal" ); + break; + case 4 : text += QObject::tr( "Low" ); + break; + case 5 : text += QObject::tr( "Very low" ); + break; + }; + text += "
"; + + // progress + text += "" + QObject::tr( "Progress:" ) + " " + + QString::number( progress() ) + " %
"; + + // due date + if ( hasDueDate() ) + { + QDate dd = dueDate(); + int off = QDate::currentDate().daysTo( dd ); + + text += "" + QObject::tr( "Deadline:" ) + " 0 ) + text += "#00FF00"; + + text += "\">" + dd.toString() + "
"; + } + + // categories + text += "" + QObject::tr( "Category:" ) + " "; + text += categoryNames( "Todo List" ).join( ", " ); + text += "
"; + + return text; +} + + +bool OPimTodo::hasNotifiers() const +{ + if ( !data->notifiers ) return false; + return !data->notifiers->isEmpty(); +} + + +OPimNotifyManager& OPimTodo::notifiers() +{ + if ( !data->notifiers ) + data->notifiers = new OPimNotifyManager; + return ( *data->notifiers ); +} + + +const OPimNotifyManager& OPimTodo::notifiers() const +{ + if ( !data->notifiers ) + data->notifiers = new OPimNotifyManager; + + return ( *data->notifiers ); +} + + +bool OPimTodo::operator<( const OPimTodo &toDoEvent ) const +{ + if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; + if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; + if ( hasDueDate() && toDoEvent.hasDueDate() ) + { + if ( dueDate() == toDoEvent.dueDate() ) + { // let's the priority decide + return priority() < toDoEvent.priority(); + } + else + { + return dueDate() < toDoEvent.dueDate(); + } + } + return false; +} + + +bool OPimTodo::operator<=( const OPimTodo &toDoEvent ) const +{ + if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; + if ( !hasDueDate() && toDoEvent.hasDueDate() ) return true; + if ( hasDueDate() && toDoEvent.hasDueDate() ) + { + if ( dueDate() == toDoEvent.dueDate() ) + { // let's the priority decide + return priority() <= toDoEvent.priority(); + } + else + { + return dueDate() <= toDoEvent.dueDate(); + } + } + return true; +} + + +bool OPimTodo::operator>( const OPimTodo &toDoEvent ) const +{ + if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; + if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; + if ( hasDueDate() && toDoEvent.hasDueDate() ) + { + if ( dueDate() == toDoEvent.dueDate() ) + { // let's the priority decide + return priority() > toDoEvent.priority(); + } + else + { + return dueDate() > toDoEvent.dueDate(); + } + } + return false; +} + + +bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const +{ + if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; + if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; + if ( hasDueDate() && toDoEvent.hasDueDate() ) + { + if ( dueDate() == toDoEvent.dueDate() ) + { // let's the priority decide + return priority() > toDoEvent.priority(); + } + else + { + return dueDate() > toDoEvent.dueDate(); + } + } + return true; +} + + +bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const +{ + if ( data->priority != toDoEvent.data->priority ) return false; + if ( data->priority != toDoEvent.data->prog ) return false; + if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; + if ( data->hasDate != toDoEvent.data->hasDate ) return false; + if ( data->date != toDoEvent.data->date ) return false; + if ( data->sum != toDoEvent.data->sum ) return false; + if ( data->desc != toDoEvent.data->desc ) return false; + if ( data->maintainer != toDoEvent.data->maintainer ) + return false; + + return OPimRecord::operator==( toDoEvent ); +} + + +void OPimTodo::deref() +{ + + // qWarning("deref in ToDoEvent"); + if ( data->deref() ) + { + // qWarning("deleting"); + delete data; + data = 0; + } +} + + +OPimTodo &OPimTodo::operator=( const OPimTodo &item ) +{ + if ( this == &item ) return * this; + + OPimRecord::operator=( item ); + //qWarning("operator= ref "); + item.data->ref(); + deref(); + data = item.data; + + return *this; +} + + +QMap OPimTodo::toMap() const +{ + QMap map; + + map.insert( Uid, QString::number( uid() ) ); + map.insert( Category, idsToString( categories() ) ); + map.insert( HasDate, QString::number( data->hasDate ) ); + map.insert( Completed, QString::number( data->isCompleted ) ); + map.insert( Description, data->desc ); + map.insert( Summary, data->sum ); + map.insert( Priority, QString::number( data->priority ) ); + map.insert( DateDay, QString::number( data->date.day() ) ); + map.insert( DateMonth, QString::number( data->date.month() ) ); + map.insert( DateYear, QString::number( data->date.year() ) ); + map.insert( Progress, QString::number( data->prog ) ); + // map.insert( CrossReference, crossToString() ); + /* FIXME!!! map.insert( State, ); + map.insert( Recurrence, ); + map.insert( Reminders, ); + map. + */ + return map; +} + + +/** + * change or modify looks at the ref count and either + * creates a new QShared Object or it can modify it + * right in place + */ +void OPimTodo::changeOrModify() +{ + if ( data->count != 1 ) + { + qWarning( "changeOrModify" ); + data->deref(); + OPimTodoData* d2 = new OPimTodoData(); + copy( data, d2 ); + data = d2; + } +} + + +// WATCHOUT +/* + * if you add something to the Data struct + * be sure to copy it here + */ +void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest ) +{ + dest->date = src->date; + dest->isCompleted = src->isCompleted; + dest->hasDate = src->hasDate; + dest->priority = src->priority; + dest->desc = src->desc; + dest->sum = src->sum; + dest->extra = src->extra; + dest->prog = src->prog; + + if ( src->state ) + dest->state = new OPimState( *src->state ); + + if ( src->recur ) + dest->recur = new OPimRecurrence( *src->recur ); + + if ( src->maintainer ) + dest->maintainer = new OPimMaintainer( *src->maintainer ) + ; + dest->start = src->start; + dest->completed = src->completed; + + if ( src->notifiers ) + dest->notifiers = new OPimNotifyManager( *src->notifiers ); +} + + +QString OPimTodo::type() const +{ + return QString::fromLatin1( "OPimTodo" ); +} + + +QString OPimTodo::recordField( int /*id*/ ) const +{ + return QString::null; +} + + +int OPimTodo::rtti() +{ + return OPimResolver::TodoList; +} + +} diff --git a/libopie2/opiepim/core/opimtodo.h b/libopie2/opiepim/core/opimtodo.h new file mode 100644 index 0000000..5304180 --- a/dev/null +++ b/libopie2/opiepim/core/opimtodo.h @@ -0,0 +1,320 @@ +/* + This file is part of the Opie Project + Copyright (C) The Main Author + =. Copyright (C) The Opie Team + .=l. + .>+-= +_;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. +: = ...= . :.=- +-. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef OTODOEVENT_H +#define OTODOEVENT_H + +/* OPIE */ +#include +#include +#include + +/* QT */ +#include +#include +#include +#include +#include +#include + +namespace Opie +{ + +class OPimState; +class OPimRecurrence; +class OPimMaintainer; +class OPimNotifyManager; +class OPimTodo : public OPimRecord +{ + public: + typedef QValueList ValueList; + enum RecordFields { + Uid = Qtopia::UID_ID, + Category = Qtopia::CATEGORY_ID, + HasDate, + Completed, + Description, + Summary, + Priority, + DateDay, + DateMonth, + DateYear, + Progress, + CrossReference, + State, + Recurrence, + Alarms, + Reminders, + Notifiers, + Maintainer, + StartDate, + CompletedDate + }; + public: + // priorities from Very low to very high + enum TaskPriority { VeryHigh = 1, High, Normal, Low, VeryLow }; + + /* Constructs a new ToDoEvent + @param completed Is the TodoEvent completed + @param priority What is the priority of this ToDoEvent + @param category Which category does it belong( uid ) + @param summary A small summary of the todo + @param description What is this ToDoEvent about + @param hasDate Does this Event got a deadline + @param date what is the deadline? + @param uid what is the UUID of this Event + **/ + OPimTodo( bool completed = false, int priority = Normal, + const QStringList &category = QStringList(), + const QString &summary = QString::null , + const QString &description = QString::null, + ushort progress = 0, + bool hasDate = false, QDate date = QDate::currentDate(), + int uid = 0 /*empty*/ ); + + OPimTodo( bool completed, int priority, + const QArray& category, + const QString& summary = QString::null, + const QString& description = QString::null, + ushort progress = 0, + bool hasDate = false, QDate date = QDate::currentDate(), + int uid = 0 /* empty */ ); + + /** Copy c'tor + * + */ + OPimTodo( const OPimTodo & ); + + /** + *destructor + */ + ~OPimTodo(); + + /** + * Is this event completed? + */ + bool isCompleted() const; + + /** + * Does this Event have a deadline + */ + bool hasDueDate() const; + bool hasStartDate() const; + bool hasCompletedDate() const; + + /** + * What is the priority? + */ + int priority() const ; + + /** + * progress as ushort 0, 20, 40, 60, 80 or 100% + */ + ushort progress() const; + + /** + * The due Date + */ + QDate dueDate() const; + + /** + * When did it start? + */ + QDate startDate() const; + + /** + * When was it completed? + */ + QDate completedDate() const; + + /** + * does it have a state? + */ + bool hasState() const; + + /** + * What is the state of this OPimTodo? + */ + OPimState state() const; + + /** + * has recurrence? + */ + bool hasRecurrence() const; + + /** + * the recurrance of this + */ + OPimRecurrence recurrence() const; + + /** + * does this OPimTodo have a maintainer? + */ + bool hasMaintainer() const; + + /** + * the Maintainer of this OPimTodo + */ + OPimMaintainer maintainer() const; + + /** + * The description of the todo + */ + QString description() const; + + /** + * A small summary of the todo + */ + QString summary() const; + + /** + * @reimplemented + * Return this todoevent in a RichText formatted QString + */ + QString toRichText() const; + + bool hasNotifiers() const; + /* + * FIXME check if the sharing is still fine!! -zecke + * ### CHECK If API is fine + */ + /** + * return a reference to our notifiers... + */ + OPimNotifyManager ¬ifiers(); + + /** + * + */ + const OPimNotifyManager ¬ifiers() const; + + /** + * reimplementations + */ + QString type() const; + QString toShortText() const; + QString recordField( int id ) const; + + /** + * toMap puts all data into the map. int relates + * to ToDoEvent RecordFields enum + */ + QMap toMap() const; + + /** + * Set if this Todo is completed + */ + void setCompleted( bool completed ); + + /** + * set if this todo got an end data + */ + void setHasDueDate( bool hasDate ); + // FIXME we do not have these for start, completed + // cause we'll use the isNull() of QDate for figuring + // out if it's has a date... + // decide what to do here? -zecke + + /** + * Set the priority of the Todo + */ + void setPriority( int priority ); + + /** + * Set the progress. + */ + void setProgress( ushort progress ); + + /** + * set the end date + */ + void setDueDate( const QDate& date ); + + /** + * set the start date + */ + void setStartDate( const QDate& date ); + + /** + * set the completed date + */ + void setCompletedDate( const QDate& date ); + + void setRecurrence( const OPimRecurrence& ); + + void setDescription( const QString& ); + void setSummary( const QString& ); + + /** + * set the state of a Todo + * @param state State what the todo should take + */ + void setState( const OPimState& state ); + + /** + * set the Maintainer Mode + */ + void setMaintainer( const OPimMaintainer& ); + + bool isOverdue(); + + + virtual bool match( const QRegExp &r ) const; + + bool operator<( const OPimTodo &toDoEvent ) const; + bool operator<=( const OPimTodo &toDoEvent ) const; + bool operator!=( const OPimTodo &toDoEvent ) const; + bool operator>( const OPimTodo &toDoEvent ) const; + bool operator>=( const OPimTodo &toDoEvent ) const; + bool operator==( const OPimTodo &toDoEvent ) const; + OPimTodo &operator=( const OPimTodo &toDoEvent ); + + static int rtti(); + + private: + class OPimTodoPrivate; + struct OPimTodoData; + + void deref(); + inline void changeOrModify(); + void copy( OPimTodoData* src, OPimTodoData* dest ); + OPimTodoPrivate *d; + OPimTodoData *data; + +}; + + +inline bool OPimTodo::operator!=( const OPimTodo &toDoEvent ) const +{ + return !( *this == toDoEvent ); +} + +} + +#endif diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp index 2a3695d..83750d5 100644 --- a/libopie2/opiepim/core/otodoaccess.cpp +++ b/libopie2/opiepim/core/otodoaccess.cpp @@ -35,28 +35,28 @@ #include namespace Opie { -OTodoAccess::OTodoAccess( OTodoAccessBackend* end, enum Access ) - : QObject(), OPimAccessTemplate( end ), m_todoBackEnd( end ) +OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) + : QObject(), OPimAccessTemplate( end ), m_todoBackEnd( end ) { // if (end == 0l ) -// m_todoBackEnd = new OTodoAccessBackendSQL( QString::null); +// m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null); // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben ! if (end == 0l ) - m_todoBackEnd = OBackendFactory::Default ("todo", QString::null); + m_todoBackEnd = OBackendFactory::Default ("todo", QString::null); setBackEnd( m_todoBackEnd ); } -OTodoAccess::~OTodoAccess() { -// qWarning("~OTodoAccess"); +OPimTodoAccess::~OPimTodoAccess() { +// qWarning("~OPimTodoAccess"); } -void OTodoAccess::mergeWith( const QValueList& list ) { - QValueList::ConstIterator it; +void OPimTodoAccess::mergeWith( const QValueList& list ) { + QValueList::ConstIterator it; for ( it = list.begin(); it != list.end(); ++it ) { replace( (*it) ); } } -OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, +OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, const QDate& end, bool includeNoDates ) { QArray ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); @@ -64,29 +64,29 @@ OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, List lis( ints, this ); return lis; } -OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, +OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, bool includeNoDates ) { return effectiveToDos( start, QDate::currentDate(), includeNoDates ); } -OTodoAccess::List OTodoAccess::overDue() { +OPimTodoAccess::List OPimTodoAccess::overDue() { List lis( m_todoBackEnd->overDue(), this ); return lis; } /* sort order */ -OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { +OPimTodoAccess::List OPimTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { QArray ints = m_todoBackEnd->sorted( ascending, sort, filter, cat ); - OTodoAccess::List list( ints, this ); + OPimTodoAccess::List list( ints, this ); return list; } -void OTodoAccess::removeAllCompleted() { +void OPimTodoAccess::removeAllCompleted() { m_todoBackEnd->removeAllCompleted(); } -QBitArray OTodoAccess::backendSupport( const QString& ) const{ +QBitArray OPimTodoAccess::backendSupport( const QString& ) const{ return m_todoBackEnd->supports(); } -bool OTodoAccess::backendSupports( int attr, const QString& ar) const{ +bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{ return backendSupport(ar).testBit( attr ); } diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h index e13d277..51f3793 100644 --- a/libopie2/opiepim/core/otodoaccess.h +++ b/libopie2/opiepim/core/otodoaccess.h @@ -32,18 +32,18 @@ #include #include -#include +#include #include #include namespace Opie { /** - * OTodoAccess + * OPimTodoAccess * the class to get access to * the todolist */ -class OTodoAccess : public QObject, public OPimAccessTemplate { +class OPimTodoAccess : public QObject, public OPimAccessTemplate { Q_OBJECT public: enum SortOrder { Completed = 0, @@ -58,8 +58,8 @@ public: * the default resource will be * picked up */ - OTodoAccess( OTodoAccessBackend* = 0l, enum Access acc = Random ); - ~OTodoAccess(); + OPimTodoAccess( OPimTodoAccessBackend* = 0l, enum Access acc = Random ); + ~OPimTodoAccess(); /* our functions here */ @@ -81,7 +81,7 @@ public: /** - * return overdue OTodos + * return overdue OPimTodos */ List overDue(); @@ -91,10 +91,10 @@ public: List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); /** - * merge a list of OTodos into + * merge a list of OPimTodos into * the resource */ - void mergeWith( const QValueList& ); + void mergeWith( const QValueList& ); /** * delete all already completed items @@ -104,7 +104,7 @@ public: /** * request information about what a backend supports. * Supports in the sense of beeing able to store. - * This is related to the enum in OTodo + * This is related to the enum in OPimTodo * * @param backend Will be used in the future when we support multiple backend */ @@ -118,17 +118,17 @@ public: bool backendSupports( int attr, const QString& backend = QString::null )const; signals: /** - * if the OTodoAccess was changed + * if the OPimTodoAccess was changed */ - void changed( const OTodoAccess* ); - void changed( const OTodoAccess*, int uid ); - void added( const OTodoAccess*, int uid ); - void removed( const OTodoAccess*, int uid ); + void changed( const OPimTodoAccess* ); + void changed( const OPimTodoAccess*, int uid ); + void added( const OPimTodoAccess*, int uid ); + void removed( const OPimTodoAccess*, int uid ); private: int m_cat; - OTodoAccessBackend* m_todoBackEnd; - class OTodoAccessPrivate; - OTodoAccessPrivate* d; + OPimTodoAccessBackend* m_todoBackEnd; + class OPimTodoAccessPrivate; + OPimTodoAccessPrivate* d; }; } -- cgit v0.9.0.2