author | eilers <eilers> | 2003-10-20 15:58:00 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-10-20 15:58:00 (UTC) |
commit | fccc5d110dea3bc32176694c8e5fc7f014706be6 (patch) (side-by-side diff) | |
tree | 6dd44a78cadfd55fc8935dc661318e3ab12dd7b7 /libopie2 | |
parent | 758775c190470e569a0616bbd87d1a378c19b747 (diff) | |
download | opie-fccc5d110dea3bc32176694c8e5fc7f014706be6.zip opie-fccc5d110dea3bc32176694c8e5fc7f014706be6.tar.gz opie-fccc5d110dea3bc32176694c8e5fc7f014706be6.tar.bz2 |
Pushing todo closer to sql support. Recurrances and custom entries still missing.
But before I add this, I have to do some cleanup..
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 52 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessxml.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimnotifymanager.cpp | 72 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimnotifymanager.h | 24 | ||||
-rw-r--r-- | libopie2/opiepim/ocontactfields.cpp | 233 | ||||
-rw-r--r-- | libopie2/opiepim/ocontactfields.h | 7 |
7 files changed, 260 insertions, 132 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index d255c66..ebd03bb 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp @@ -1,59 +1,62 @@ #include <qdatetime.h> #include <qpe/global.h> #include <opie2/osqldriver.h> #include <opie2/osqlresult.h> #include <opie2/osqlmanager.h> #include <opie2/osqlquery.h> #include "otodoaccesssql.h" +#include "opimstate.h" +#include "opimnotifymanager.h" +#include "orecur.h" /* * first some query * CREATE query * LOAD query * INSERT * REMOVE * CLEAR */ namespace { /** * CreateQuery for the Todolist Table */ class CreateQuery : public OSQLQuery { public: CreateQuery(); ~CreateQuery(); QString query()const; }; /** * LoadQuery * this one queries for all uids */ class LoadQuery : public OSQLQuery { public: LoadQuery(); ~LoadQuery(); QString query()const; }; /** * inserts/adds a OTodo to the table */ class InsertQuery : public OSQLQuery { public: InsertQuery(const OTodo& ); ~InsertQuery(); QString query()const; private: OTodo m_todo; }; /** * removes one from the table */ class RemoveQuery : public OSQLQuery { public: @@ -75,165 +78,175 @@ namespace { }; /** * a find query */ class FindQuery : public OSQLQuery { public: FindQuery(int uid); FindQuery(const QArray<int>& ); ~FindQuery(); QString query()const; private: QString single()const; QString multi()const; QArray<int> m_uids; int m_uid; }; /** * overdue query */ class OverDueQuery : public OSQLQuery { public: OverDueQuery(); ~OverDueQuery(); QString query()const; }; class EffQuery : public OSQLQuery { public: EffQuery( const QDate&, const QDate&, bool inc ); ~EffQuery(); QString query()const; private: QString with()const; QString out()const; QDate m_start; QDate m_end; bool m_inc :1; }; CreateQuery::CreateQuery() : OSQLQuery() {} CreateQuery::~CreateQuery() {} QString CreateQuery::query()const { QString qu; qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; qu += "description, summary, priority, DueDate, progress , state, "; - qu += "Recurrence, notifiers, maintainer, startdate, completeddate)"; + qu += "Recurrence, reminders, alarms, maintainer, startdate, completeddate);"; + qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; return qu; } LoadQuery::LoadQuery() : OSQLQuery() {} LoadQuery::~LoadQuery() {} QString LoadQuery::query()const { QString qu; // We do not need "distinct" here. The primary key is always unique.. //qu += "select distinct uid from todolist"; qu += "select uid from todolist"; return qu; } InsertQuery::InsertQuery( const OTodo& todo ) : OSQLQuery(), m_todo( todo ) { } InsertQuery::~InsertQuery() { } /* * converts from a OTodo to a query * we leave out X-Ref + Alarms */ QString InsertQuery::query()const{ int year, month, day; year = month = day = 0; if (m_todo.hasDueDate() ) { QDate date = m_todo.dueDate(); year = date.year(); month = date.month(); day = date.day(); } int sYear = 0, sMonth = 0, sDay = 0; if( m_todo.hasStartDate() ){ QDate sDate = m_todo.startDate(); sYear = sDate.year(); sMonth= sDate.month(); sDay = sDate.day(); } int eYear = 0, eMonth = 0, eDay = 0; if( m_todo.hasCompletedDate() ){ QDate eDate = m_todo.completedDate(); eYear = eDate.year(); eMonth= eDate.month(); eDay = eDate.day(); } QString qu; qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + "," + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," + QString::number( m_todo.isCompleted() ) + "," + "'" + m_todo.description() + "'" + "," + "'" + m_todo.summary() + "'" + "," + QString::number(m_todo.priority() ) + "," + "'" + QString::number(year) + "-" + QString::number(month) + "-" + QString::number( day ) + "'" + "," + QString::number( m_todo.progress() ) + "," - + "''" + "," // state (conversion needed) -// + QString::number( m_todo.state() ) + "," - + "''" + "," // Recurrence (conversion needed) - + "''" + "," // Notifiers (conversion needed) - + "''" + "," // Maintainers (conversion needed) + + QString::number( m_todo.state().state() ) + "," + + "'" + m_todo.recurrence().toString() + "'"+ ","; + + if ( m_todo.hasNotifiers() ) { + OPimNotifyManager manager = m_todo.notifiers(); + qu += "'" + manager.remindersToString() + "'" + "," + + "'" + manager.alarmsToString() + "'" + ","; + } + else{ + qu += QString( "''" ) + "," + + "''" + ","; + } + + qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) + "'" + QString::number(sYear) + "-" - + QString::number(sMonth) - + "-" + QString::number(sDay) + "'" + "," + + QString::number(sMonth) + + "-" + QString::number(sDay) + "'" + "," + "'" + QString::number(eYear) + "-" + QString::number(eMonth) + "-"+QString::number(eDay) + "'" + ")"; qWarning("add %s", qu.latin1() ); return qu; } RemoveQuery::RemoveQuery(int uid ) : OSQLQuery(), m_uid( uid ) {} RemoveQuery::~RemoveQuery() {} QString RemoveQuery::query()const { QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); return qu; } ClearQuery::ClearQuery() : OSQLQuery() {} ClearQuery::~ClearQuery() {} QString ClearQuery::query()const { QString qu = "drop table todolist"; return qu; } FindQuery::FindQuery(int uid) : OSQLQuery(), m_uid(uid ) { } FindQuery::FindQuery(const QArray<int>& ints) : OSQLQuery(), m_uids(ints){ } FindQuery::~FindQuery() { } QString FindQuery::query()const{ if (m_uids.count() == 0 ) return single(); else return multi(); } QString FindQuery::single()const{ QString qu = "select * from todolist where uid = " + QString::number(m_uid); return qu; } QString FindQuery::multi()const { QString qu = "select * from todolist where "; for (uint i = 0; i < m_uids.count(); i++ ) { qu += " UID = " + QString::number( m_uids[i] ) + " OR"; } @@ -485,167 +498,170 @@ bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ da.setYMD( year, month, day ); return true; } } OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ if ( res.state() == OSQLResult::Failure ) { OTodo to; return to; } OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it = list.begin(); qWarning("todo1"); OTodo to = todo( (*it) ); cache( to ); ++it; for ( ; it != list.end(); ++it ) { qWarning("caching"); cache( todo( (*it) ) ); } return to; } OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { qWarning("todo"); bool hasDueDate = false; QDate dueDate = QDate::currentDate(); hasDueDate = date( dueDate, item.data("DueDate") ); QStringList cats = QStringList::split(";", item.data("categories") ); OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), cats, item.data("summary"), item.data("description"), item.data("progress").toUShort(), hasDueDate, dueDate, item.data("uid").toInt() ); bool isOk; int prioInt = QString( item.data("priority") ).toInt( &isOk ); if ( isOk ) to.setPriority( prioInt ); bool hasStartDate = false; QDate startDate = QDate::currentDate(); hasStartDate = date( startDate, item.data("startdate") ); bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); hasCompletedDate = date( completedDate, item.data("completeddate") ); if ( hasStartDate ) to.setStartDate( startDate ); if ( hasCompletedDate ) to.setCompletedDate( completedDate ); + + OPimNotifyManager& manager = to.notifiers(); + manager.alarmsFromString( item.data("alarms") ); + manager.remindersFromString( item.data("reminders") ); + + OPimState pimState; + pimState.setState( QString( item.data("state") ).toInt() ); + to.setState( pimState ); + + // Recurrence not supported yet + // to.setRecurrence( return to; } OTodo OTodoAccessBackendSQL::todo( int uid )const { FindQuery find( uid ); return todo( m_driver->query(&find) ); } /* * update the dict */ void OTodoAccessBackendSQL::fillDict() { /* initialize dict */ /* * UPDATE dict if you change anything!!! * FIXME: Isn't this dict obsolete ? (eilers) */ m_dict.setAutoDelete( TRUE ); m_dict.insert("Categories" , new int(OTodo::Category) ); m_dict.insert("Uid" , new int(OTodo::Uid) ); m_dict.insert("HasDate" , new int(OTodo::HasDate) ); m_dict.insert("Completed" , new int(OTodo::Completed) ); m_dict.insert("Description" , new int(OTodo::Description) ); m_dict.insert("Summary" , new int(OTodo::Summary) ); m_dict.insert("Priority" , new int(OTodo::Priority) ); m_dict.insert("DateDay" , new int(OTodo::DateDay) ); m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); m_dict.insert("DateYear" , new int(OTodo::DateYear) ); m_dict.insert("Progress" , new int(OTodo::Progress) ); m_dict.insert("Completed", new int(OTodo::Completed) ); // Why twice ? (eilers) m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); // m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); // old stuff (eilers) // m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); // old stuff (eilers) } /* * need to be const so let's fool the * compiler :( */ void OTodoAccessBackendSQL::update()const { ((OTodoAccessBackendSQL*)this)->m_dirty = false; LoadQuery lo; OSQLResult res = m_driver->query(&lo); if ( res.state() != OSQLResult::Success ) return; ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); } QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it; QArray<int> ints(list.count() ); qWarning(" count = %d", list.count() ); int i = 0; for (it = list.begin(); it != list.end(); ++it ) { ints[i] = (*it).data("uid").toInt(); i++; } return ints; } QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const { #warning OTodoAccessBackendSQL::matchRegexp() not implemented !! #if 0 Copied from xml-backend by not adapted to sql (eilers) QArray<int> m_currentQuery( m_events.count() ); uint arraycounter = 0; QMap<int, OTodo>::ConstIterator it; for (it = m_events.begin(); it != m_events.end(); ++it ) { if ( it.data().match( r ) ) m_currentQuery[arraycounter++] = it.data().uid(); } // Shrink to fit.. m_currentQuery.resize(arraycounter); return m_currentQuery; #endif QArray<int> empty; return empty; } QBitArray OTodoAccessBackendSQL::supports()const { - QBitArray ar( OTodo::CompletedDate + 1 ); - ar.fill( true ); - ar[OTodo::CrossReference] = false; - ar[OTodo::State ] = false; - ar[OTodo::Reminders] = false; - ar[OTodo::Notifiers] = false; - ar[OTodo::Maintainer] = false; - - return ar; + return sup(); } -QBitArray OTodoAccessBackendSQL::sup() { +QBitArray OTodoAccessBackendSQL::sup() const{ QBitArray ar( OTodo::CompletedDate + 1 ); ar.fill( true ); ar[OTodo::CrossReference] = false; ar[OTodo::State ] = false; ar[OTodo::Reminders] = false; ar[OTodo::Notifiers] = false; ar[OTodo::Maintainer] = false; return ar; } void OTodoAccessBackendSQL::removeAllCompleted(){ #warning OTodoAccessBackendSQL::removeAllCompleted() not implemented !! } diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h index 77d8b77..1c55567 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.h +++ b/libopie2/opiepim/backend/otodoaccesssql.h @@ -1,56 +1,56 @@ #ifndef OPIE_PIM_ACCESS_SQL_H #define OPIE_PIM_ACCESS_SQL_H #include <qasciidict.h> #include "otodoaccessbackend.h" class OSQLDriver; class OSQLResult; class OSQLResultItem; class OTodoAccessBackendSQL : public OTodoAccessBackend { public: OTodoAccessBackendSQL( const QString& file ); ~OTodoAccessBackendSQL(); bool load(); bool reload(); bool save(); QArray<int> allRecords()const; QArray<int> queryByExample( const OTodo& t, int settings, const QDateTime& d = QDateTime() ); OTodo find(int uid)const; OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; void clear(); bool add( const OTodo& t ); bool remove( int uid ); bool replace( const OTodo& t ); QArray<int> overDue(); QArray<int> effectiveToDos( const QDate& start, const QDate& end, bool includeNoDates ); QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); QBitArray supports()const; QArray<int> matchRegexp( const QRegExp &r ) const; void removeAllCompleted(); private: void update()const; void fillDict(); inline bool date( QDate& date, const QString& )const; inline OTodo todo( const OSQLResult& )const; inline OTodo todo( OSQLResultItem& )const; inline QArray<int> uids( const OSQLResult& )const; OTodo todo( int uid )const; - QBitArray sup(); + QBitArray sup() const; QAsciiDict<int> m_dict; OSQLDriver* m_driver; QArray<int> m_uids; bool m_dirty : 1; }; #endif diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp index f688735..4a5cb33 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.cpp +++ b/libopie2/opiepim/backend/otodoaccessxml.cpp @@ -523,97 +523,97 @@ QString customToXml(const QMap<QString, QString>& customMap ) } QString OTodoAccessXML::toString( const OTodo& ev )const { QString str; str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; str += "Categories=\"" + toString( ev.categories() ) + "\" "; str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; if ( ev.hasDueDate() ) { str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; } // qWarning( "Uid %d", ev.uid() ); str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; // append the extra options /* FIXME Qtopia::Record this is currently not * possible you can set custom fields * but don' iterate over the list * I may do #define private protected * for this case - cough --zecke */ /* QMap<QString, QString> extras = ev.extras(); QMap<QString, QString>::Iterator extIt; for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) str += extIt.key() + "=\"" + extIt.data() + "\" "; */ // cross refernce if ( ev.hasRecurrence() ) { str += ev.recurrence().toString(); } if ( ev.hasStartDate() ) str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" "; if ( ev.hasCompletedDate() ) str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" "; if ( ev.hasState() ) str += "State=\""+QString::number( ev.state().state() )+"\" "; /* * save reminders and notifiers! - * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER:DURATION:SOUND:.... + * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER_DURATION:SOUND:.... */ if ( ev.hasNotifiers() ) { OPimNotifyManager manager = ev.notifiers(); OPimNotifyManager::Alarms alarms = manager.alarms(); if (!alarms.isEmpty() ) { QStringList als; OPimNotifyManager::Alarms::Iterator it = alarms.begin(); for ( ; it != alarms.end(); ++it ) { /* only if time is valid */ if ( (*it).dateTime().isValid() ) { als << OConversion::dateTimeToString( (*it).dateTime() ) + ":" + QString::number( (*it).duration() ) + ":" + QString::number( (*it).sound() ) + ":"; } } // now write the list qWarning("als: %s", als.join("____________").latin1() ); str += "Alarms=\""+als.join(";") +"\" "; } /* * now the same for reminders but more easy. We just save the uid of the OEvent. */ OPimNotifyManager::Reminders reminders = manager.reminders(); if (!reminders.isEmpty() ) { OPimNotifyManager::Reminders::Iterator it = reminders.begin(); QStringList records; for ( ; it != reminders.end(); ++it ) { records << QString::number( (*it).recordUid() ); } str += "Reminders=\""+ records.join(";") +"\" "; } } str += customToXml( ev.toExtraMap() ); return str; } QString OTodoAccessXML::toString( const QArray<int>& ints ) const { return Qtopia::Record::idsToString( ints ); } /* internal class for sorting * * Inspired by todoxmlio.cpp from TT */ diff --git a/libopie2/opiepim/core/opimnotifymanager.cpp b/libopie2/opiepim/core/opimnotifymanager.cpp index 06b5987..53ad4c3 100644 --- a/libopie2/opiepim/core/opimnotifymanager.cpp +++ b/libopie2/opiepim/core/opimnotifymanager.cpp @@ -1,74 +1,146 @@ #include "opimnotifymanager.h" +#include "oconversion.h" + +#include <qstringlist.h> + OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al) : m_rem( rem ), m_al( al ) {} OPimNotifyManager::~OPimNotifyManager() { } /* use static_cast and type instead of dynamic... */ void OPimNotifyManager::add( const OPimNotify& noti) { if ( noti.type() == QString::fromLatin1("OPimReminder") ) { const OPimReminder& rem = static_cast<const OPimReminder&>(noti); m_rem.append( rem ); }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); m_al.append( al ); } } void OPimNotifyManager::remove( const OPimNotify& noti) { if ( noti.type() == QString::fromLatin1("OPimReminder") ) { const OPimReminder& rem = static_cast<const OPimReminder&>(noti); m_rem.remove( rem ); }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); m_al.remove( al ); } } void OPimNotifyManager::replace( const OPimNotify& noti) { if ( noti.type() == QString::fromLatin1("OPimReminder") ) { const OPimReminder& rem = static_cast<const OPimReminder&>(noti); m_rem.remove( rem ); m_rem.append( rem ); }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); m_al.remove( al ); m_al.append( al ); } } OPimNotifyManager::Reminders OPimNotifyManager::reminders()const { return m_rem; } OPimNotifyManager::Alarms OPimNotifyManager::alarms()const { return m_al; } void OPimNotifyManager::setAlarms( const Alarms& al) { m_al = al; } void OPimNotifyManager::setReminders( const Reminders& rem) { m_rem = rem; } /* FIXME!!! */ /** * The idea is to check if the provider for our service * is online * if it is we will use QCOP * if not the Factory to get the backend... * Qtopia1.6 services would be kewl to have here.... */ void OPimNotifyManager::registerNotify( const OPimNotify& ) { } /* FIXME!!! */ /** * same as above... * Also implement Url model * have a MainWindow.... */ void OPimNotifyManager::deregister( const OPimNotify& ) { } + bool OPimNotifyManager::isEmpty()const { qWarning("is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() ); if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; else return false; } + +// Taken from otodoaccessxml.. +QString OPimNotifyManager::alarmsToString() const +{ + QString str; + + OPimNotifyManager::Alarms alarms = m_al; + if ( !alarms.isEmpty() ) { + QStringList als; + OPimNotifyManager::Alarms::Iterator it = alarms.begin(); + for ( ; it != alarms.end(); ++it ) { + /* only if time is valid */ + if ( (*it).dateTime().isValid() ) { + als << OConversion::dateTimeToString( (*it).dateTime() ) + + ":" + QString::number( (*it).duration() ) + + ":" + QString::number( (*it).sound() ) + + ":"; + } + } + // now write the list + qWarning("als: %s", als.join("____________").latin1() ); + str = als.join(";"); + } + + return str; +} +QString OPimNotifyManager::remindersToString() const +{ + QString str; + + OPimNotifyManager::Reminders reminders = m_rem; + if (!reminders.isEmpty() ) { + OPimNotifyManager::Reminders::Iterator it = reminders.begin(); + QStringList records; + for ( ; it != reminders.end(); ++it ) { + records << QString::number( (*it).recordUid() ); + } + str = records.join(";"); + } + + return str; +} + +void OPimNotifyManager::alarmsFromString( const QString& str ) +{ + QStringList als = QStringList::split(";", str ); + for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { + QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty + qWarning("alarm: %s", alarm.join("___").latin1() ); + qWarning("alarm[0]: %s %s", alarm[0].latin1(), + OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); + OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), + alarm[1].toInt() ); + add( al ); + } +} + +void OPimNotifyManager::remindersFromString( const QString& str ) +{ + + QStringList rems = QStringList::split(";", str ); + for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { + OPimReminder rem( (*it).toInt() ); + add( rem ); + } + +} diff --git a/libopie2/opiepim/core/opimnotifymanager.h b/libopie2/opiepim/core/opimnotifymanager.h index 0ac30a1..48410e7 100644 --- a/libopie2/opiepim/core/opimnotifymanager.h +++ b/libopie2/opiepim/core/opimnotifymanager.h @@ -1,54 +1,76 @@ #ifndef OPIE_PIM_NOTIFY_MANAGER_H #define OPIE_PIM_NOTIFY_MANAGER_H #include <qvaluelist.h> #include <opie/opimnotify.h> /** * The notify manager keeps track of the Notifiers.... */ class OPimNotifyManager { public: typedef QValueList<OPimReminder> Reminders; typedef QValueList<OPimAlarm> Alarms; OPimNotifyManager( const Reminders& rems = Reminders(), const Alarms& alarms = Alarms() ); ~OPimNotifyManager(); /* we will cast it for you ;) */ void add( const OPimNotify& ); void remove( const OPimNotify& ); /* replaces all with this one! */ void replace( const OPimNotify& ); Reminders reminders()const; Alarms alarms()const; void setAlarms( const Alarms& ); void setReminders( const Reminders& ); /* register is a Ansi C keyword... */ /** * This function will register the Notify to the Alarm Server * or datebook depending on the type of the notify */ void registerNotify( const OPimNotify& ); /** * this will do the opposite.. */ void deregister( const OPimNotify& ); - bool isEmpty()const; + /** + * Return all alarms as string + */ + QString alarmsToString() const; + /** + * Return all notifiers as string + */ + QString remindersToString() const; + + /** + * Convert string to alarms + * @param str String created by alarmsToString() + */ + void alarmsFromString( const QString& str ); + + /** + * Convert string to reminders + * @param str String created by remindersToString() + */ + void remindersFromString( const QString& str ); + + + private: Reminders m_rem; Alarms m_al; class Private; Private *d; }; #endif diff --git a/libopie2/opiepim/ocontactfields.cpp b/libopie2/opiepim/ocontactfields.cpp index 7206f0d..0f08a5a 100644 --- a/libopie2/opiepim/ocontactfields.cpp +++ b/libopie2/opiepim/ocontactfields.cpp @@ -1,260 +1,269 @@ #include "ocontactfields.h" #include <qstringlist.h> #include <qobject.h> // We should use our own enum in the future .. #include <qpe/recordfields.h> #include <qpe/config.h> #include <opie/ocontact.h> /*! \internal - Returns a list of details field names for a contact. + Returns a list of personal field names for a contact. */ -QStringList OContactFields::untrdetailsfields( bool sorted ) +QStringList OContactFields::personalfields( bool sorted, bool translated ) { QStringList list; - QMap<int, QString> mapIdToStr = idToUntrFields(); + QMap<int, QString> mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); - list.append( mapIdToStr[ Qtopia::Office ] ); - list.append( mapIdToStr[ Qtopia::Profession ] ); - list.append( mapIdToStr[ Qtopia::Assistant ] ); - list.append( mapIdToStr[ Qtopia::Manager ] ); + list.append( mapIdToStr[ Qtopia::AddressUid ] ); + list.append( mapIdToStr[ Qtopia::AddressCategory ] ); - list.append( mapIdToStr[ Qtopia::Spouse ] ); - list.append( mapIdToStr[ Qtopia::Gender ] ); - list.append( mapIdToStr[ Qtopia::Birthday ] ); - list.append( mapIdToStr[ Qtopia::Anniversary ] ); - list.append( mapIdToStr[ Qtopia::Nickname ] ); - list.append( mapIdToStr[ Qtopia::Children ] ); + list.append( mapIdToStr[ Qtopia::Title ] ); + list.append( mapIdToStr[ Qtopia::FirstName ] ); + list.append( mapIdToStr[ Qtopia::MiddleName ] ); + list.append( mapIdToStr[ Qtopia::LastName ] ); + list.append( mapIdToStr[ Qtopia::Suffix ] ); + list.append( mapIdToStr[ Qtopia::FileAs ] ); + + list.append( mapIdToStr[ Qtopia::JobTitle ] ); + list.append( mapIdToStr[ Qtopia::Department ] ); + list.append( mapIdToStr[ Qtopia::Company ] ); + + list.append( mapIdToStr[ Qtopia::Notes ] ); + list.append( mapIdToStr[ Qtopia::Groups ] ); if (sorted) list.sort(); return list; } /*! \internal - Returns a translated list of details field names for a contact. + Returns a list of details field names for a contact. */ -QStringList OContactFields::trdetailsfields( bool sorted ) +QStringList OContactFields::detailsfields( bool sorted, bool translated ) { QStringList list; - QMap<int, QString> mapIdToStr = idToTrFields(); + QMap<int, QString> mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); - list.append( mapIdToStr[Qtopia::Office] ); - list.append( mapIdToStr[Qtopia::Profession] ); - list.append( mapIdToStr[Qtopia::Assistant] ); - list.append( mapIdToStr[Qtopia::Manager] ); + list.append( mapIdToStr[ Qtopia::Office ] ); + list.append( mapIdToStr[ Qtopia::Profession ] ); + list.append( mapIdToStr[ Qtopia::Assistant ] ); + list.append( mapIdToStr[ Qtopia::Manager ] ); - list.append( mapIdToStr[Qtopia::Spouse] ); - list.append( mapIdToStr[Qtopia::Gender] ); - list.append( mapIdToStr[Qtopia::Birthday] ); - list.append( mapIdToStr[Qtopia::Anniversary] ); - list.append( mapIdToStr[Qtopia::Nickname] ); - list.append( mapIdToStr[Qtopia::Children] ); + list.append( mapIdToStr[ Qtopia::Spouse ] ); + list.append( mapIdToStr[ Qtopia::Gender ] ); + list.append( mapIdToStr[ Qtopia::Birthday ] ); + list.append( mapIdToStr[ Qtopia::Anniversary ] ); + list.append( mapIdToStr[ Qtopia::Nickname ] ); + list.append( mapIdToStr[ Qtopia::Children ] ); if (sorted) list.sort(); return list; } - /*! \internal - Returns a translated list of phone field names for a contact. + Returns a list of phone field names for a contact. */ -QStringList OContactFields::trphonefields( bool sorted ) +QStringList OContactFields::phonefields( bool sorted, bool translated ) { QStringList list; - QMap<int, QString> mapIdToStr = idToTrFields(); + QMap<int, QString> mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); list.append( mapIdToStr[Qtopia::BusinessPhone] ); list.append( mapIdToStr[Qtopia::BusinessFax] ); list.append( mapIdToStr[Qtopia::BusinessMobile] ); list.append( mapIdToStr[Qtopia::BusinessPager] ); list.append( mapIdToStr[Qtopia::BusinessWebPage] ); list.append( mapIdToStr[Qtopia::DefaultEmail] ); list.append( mapIdToStr[Qtopia::Emails] ); list.append( mapIdToStr[Qtopia::HomePhone] ); list.append( mapIdToStr[Qtopia::HomeFax] ); list.append( mapIdToStr[Qtopia::HomeMobile] ); // list.append( mapIdToStr[Qtopia::HomePager] ); list.append( mapIdToStr[Qtopia::HomeWebPage] ); if (sorted) list.sort(); return list; } - /*! \internal - Returns a list of phone field names for a contact. + Returns a list of field names for a contact. */ -QStringList OContactFields::untrphonefields( bool sorted ) +QStringList OContactFields::fields( bool sorted, bool translated ) { QStringList list; - QMap<int, QString> mapIdToStr = idToUntrFields(); - - list.append( mapIdToStr[ Qtopia::BusinessPhone ] ); - list.append( mapIdToStr[ Qtopia::BusinessFax ] ); - list.append( mapIdToStr[ Qtopia::BusinessMobile ] ); - list.append( mapIdToStr[ Qtopia::BusinessPager ] ); - list.append( mapIdToStr[ Qtopia::BusinessWebPage ] ); - - list.append( mapIdToStr[ Qtopia::DefaultEmail ] ); - list.append( mapIdToStr[ Qtopia::Emails ] ); + QMap<int, QString> mapIdToStr; + if ( translated ) + mapIdToStr = idToTrFields(); + else + mapIdToStr = idToUntrFields(); - list.append( mapIdToStr[ Qtopia::HomePhone ] ); - list.append( mapIdToStr[ Qtopia::HomeFax ] ); - list.append( mapIdToStr[ Qtopia::HomeMobile ] ); - //list.append( mapIdToStr[Qtopia::HomePager] ); - list.append( mapIdToStr[Qtopia::HomeWebPage] ); + list += personalfields( sorted, translated ); - if (sorted) list.sort(); - - return list; -} - - -/*! - \internal - Returns a translated list of field names for a contact. -*/ -QStringList OContactFields::trfields( bool sorted ) -{ - QStringList list; - QMap<int, QString> mapIdToStr = idToTrFields(); - - list.append( mapIdToStr[Qtopia::Title]); - list.append( mapIdToStr[Qtopia::FirstName] ); - list.append( mapIdToStr[Qtopia::MiddleName] ); - list.append( mapIdToStr[Qtopia::LastName] ); - list.append( mapIdToStr[Qtopia::Suffix] ); - list.append( mapIdToStr[Qtopia::FileAs] ); - - list.append( mapIdToStr[Qtopia::JobTitle] ); - list.append( mapIdToStr[Qtopia::Department] ); - list.append( mapIdToStr[Qtopia::Company] ); - - list += trphonefields( sorted ); + list += phonefields( sorted, translated ); list.append( mapIdToStr[Qtopia::BusinessStreet] ); list.append( mapIdToStr[Qtopia::BusinessCity] ); list.append( mapIdToStr[Qtopia::BusinessState] ); list.append( mapIdToStr[Qtopia::BusinessZip] ); list.append( mapIdToStr[Qtopia::BusinessCountry] ); list.append( mapIdToStr[Qtopia::HomeStreet] ); list.append( mapIdToStr[Qtopia::HomeCity] ); list.append( mapIdToStr[Qtopia::HomeState] ); list.append( mapIdToStr[Qtopia::HomeZip] ); list.append( mapIdToStr[Qtopia::HomeCountry] ); - list += trdetailsfields( sorted ); - - list.append( mapIdToStr[Qtopia::Notes] ); - list.append( mapIdToStr[Qtopia::Groups] ); + list += detailsfields( sorted, translated ); if (sorted) list.sort(); return list; } + /*! \internal - Returns an untranslated list of field names for a contact. + Returns an untranslated list of personal field names for a contact. */ -QStringList OContactFields::untrfields( bool sorted ) +QStringList OContactFields::untrpersonalfields( bool sorted ) { - QStringList list; - QMap<int, QString> mapIdToStr = idToUntrFields(); + return personalfields( sorted, false ); +} - list.append( mapIdToStr[ Qtopia::AddressUid ] ); - list.append( mapIdToStr[ Qtopia::AddressCategory ] ); - list.append( mapIdToStr[ Qtopia::Title ] ); - list.append( mapIdToStr[ Qtopia::FirstName ] ); - list.append( mapIdToStr[ Qtopia::MiddleName ] ); - list.append( mapIdToStr[ Qtopia::LastName ] ); - list.append( mapIdToStr[ Qtopia::Suffix ] ); - list.append( mapIdToStr[ Qtopia::FileAs ] ); +/*! + \internal + Returns a translated list of personal field names for a contact. +*/ +QStringList OContactFields::trpersonalfields( bool sorted ) +{ + return personalfields( sorted, true ); +} - list.append( mapIdToStr[ Qtopia::JobTitle ] ); - list.append( mapIdToStr[ Qtopia::Department ] ); - list.append( mapIdToStr[ Qtopia::Company ] ); - list += untrphonefields( sorted ); +/*! + \internal + Returns an untranslated list of details field names for a contact. +*/ +QStringList OContactFields::untrdetailsfields( bool sorted ) +{ + return detailsfields( sorted, false ); +} - list.append( mapIdToStr[ Qtopia::BusinessStreet ] ); - list.append( mapIdToStr[ Qtopia::BusinessCity ] ); - list.append( mapIdToStr[ Qtopia::BusinessState ] ); - list.append( mapIdToStr[ Qtopia::BusinessZip ] ); - list.append( mapIdToStr[ Qtopia::BusinessCountry ] ); - list.append( mapIdToStr[ Qtopia::HomeStreet ] ); - list.append( mapIdToStr[ Qtopia::HomeCity ] ); - list.append( mapIdToStr[ Qtopia::HomeState ] ); - list.append( mapIdToStr[ Qtopia::HomeZip ] ); - list.append( mapIdToStr[ Qtopia::HomeCountry ] ); +/*! + \internal + Returns a translated list of details field names for a contact. +*/ +QStringList OContactFields::trdetailsfields( bool sorted ) +{ + return detailsfields( sorted, true ); +} - list += untrdetailsfields( sorted ); - list.append( mapIdToStr[ Qtopia::Notes ] ); - list.append( mapIdToStr[ Qtopia::Groups ] ); +/*! + \internal + Returns a translated list of phone field names for a contact. +*/ +QStringList OContactFields::trphonefields( bool sorted ) +{ + return phonefields( sorted, true ); +} - if (sorted) list.sort(); +/*! + \internal + Returns an untranslated list of phone field names for a contact. +*/ +QStringList OContactFields::untrphonefields( bool sorted ) +{ + return phonefields( sorted, false ); +} - return list; + +/*! + \internal + Returns a translated list of field names for a contact. +*/ +QStringList OContactFields::trfields( bool sorted ) +{ + return fields( sorted, true ); +} + +/*! + \internal + Returns an untranslated list of field names for a contact. +*/ +QStringList OContactFields::untrfields( bool sorted ) +{ + return fields( sorted, false ); } + QMap<int, QString> OContactFields::idToTrFields() { QMap<int, QString> ret_map; ret_map.insert( Qtopia::AddressUid, QObject::tr( "User Id" ) ); ret_map.insert( Qtopia::AddressCategory, QObject::tr( "Categories" ) ); ret_map.insert( Qtopia::Title, QObject::tr( "Name Title") ); ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) ); ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) ); ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) ); ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" )); ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) ); ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) ); ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) ); ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) ); ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) ); ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) ); ret_map.insert( Qtopia::BusinessMobile, QObject::tr( "Business Mobile" )); // email ret_map.insert( Qtopia::DefaultEmail, QObject::tr( "Default Email" ) ); ret_map.insert( Qtopia::Emails, QObject::tr( "Emails" ) ); ret_map.insert( Qtopia::HomePhone, QObject::tr( "Home Phone" ) ); ret_map.insert( Qtopia::HomeFax, QObject::tr( "Home Fax" ) ); ret_map.insert( Qtopia::HomeMobile, QObject::tr( "Home Mobile" ) ); // business ret_map.insert( Qtopia::BusinessStreet, QObject::tr( "Business Street" ) ); ret_map.insert( Qtopia::BusinessCity, QObject::tr( "Business City" ) ); ret_map.insert( Qtopia::BusinessState, QObject::tr( "Business State" ) ); ret_map.insert( Qtopia::BusinessZip, QObject::tr( "Business Zip" ) ); ret_map.insert( Qtopia::BusinessCountry, QObject::tr( "Business Country" ) ); ret_map.insert( Qtopia::BusinessPager, QObject::tr( "Business Pager" ) ); ret_map.insert( Qtopia::BusinessWebPage, QObject::tr( "Business WebPage" ) ); ret_map.insert( Qtopia::Office, QObject::tr( "Office" ) ); ret_map.insert( Qtopia::Profession, QObject::tr( "Profession" ) ); ret_map.insert( Qtopia::Assistant, QObject::tr( "Assistant" ) ); ret_map.insert( Qtopia::Manager, QObject::tr( "Manager" ) ); // home ret_map.insert( Qtopia::HomeStreet, QObject::tr( "Home Street" ) ); ret_map.insert( Qtopia::HomeCity, QObject::tr( "Home City" ) ); ret_map.insert( Qtopia::HomeState, QObject::tr( "Home State" ) ); ret_map.insert( Qtopia::HomeZip, QObject::tr( "Home Zip" ) ); @@ -284,124 +293,126 @@ QMap<int, QString> OContactFields::idToUntrFields() ret_map.insert( Qtopia::AddressCategory, "Categories" ); ret_map.insert( Qtopia::Title, "Name Title" ); ret_map.insert( Qtopia::FirstName, "First Name" ); ret_map.insert( Qtopia::MiddleName, "Middle Name" ); ret_map.insert( Qtopia::LastName, "Last Name" ); ret_map.insert( Qtopia::Suffix, "Suffix" ); ret_map.insert( Qtopia::FileAs, "File As" ); ret_map.insert( Qtopia::JobTitle, "Job Title" ); ret_map.insert( Qtopia::Department, "Department" ); ret_map.insert( Qtopia::Company, "Company" ); ret_map.insert( Qtopia::BusinessPhone, "Business Phone" ); ret_map.insert( Qtopia::BusinessFax, "Business Fax" ); ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" ); // email ret_map.insert( Qtopia::DefaultEmail, "Default Email" ); ret_map.insert( Qtopia::Emails, "Emails" ); ret_map.insert( Qtopia::HomePhone, "Home Phone" ); ret_map.insert( Qtopia::HomeFax, "Home Fax" ); ret_map.insert( Qtopia::HomeMobile, "Home Mobile" ); // business ret_map.insert( Qtopia::BusinessStreet, "Business Street" ); ret_map.insert( Qtopia::BusinessCity, "Business City" ); ret_map.insert( Qtopia::BusinessState, "Business State" ); ret_map.insert( Qtopia::BusinessZip, "Business Zip" ); ret_map.insert( Qtopia::BusinessCountry, "Business Country" ); ret_map.insert( Qtopia::BusinessPager, "Business Pager" ); ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" ); ret_map.insert( Qtopia::Office, "Office" ); ret_map.insert( Qtopia::Profession, "Profession" ); ret_map.insert( Qtopia::Assistant, "Assistant" ); ret_map.insert( Qtopia::Manager, "Manager" ); // home ret_map.insert( Qtopia::HomeStreet, "Home Street" ); ret_map.insert( Qtopia::HomeCity, "Home City" ); ret_map.insert( Qtopia::HomeState, "Home State" ); ret_map.insert( Qtopia::HomeZip, "Home Zip" ); ret_map.insert( Qtopia::HomeCountry, "Home Country" ); ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" ); //personal ret_map.insert( Qtopia::Spouse, "Spouse" ); - ret_map.insert( Qtopia::Gender, "Gender" ); + ret_map.insert( Qtopia::Gender, "Gender" ); ret_map.insert( Qtopia::Birthday, "Birthday" ); ret_map.insert( Qtopia::Anniversary, "Anniversary" ); ret_map.insert( Qtopia::Nickname, "Nickname" ); ret_map.insert( Qtopia::Children, "Children" ); // other ret_map.insert( Qtopia::Notes, "Notes" ); ret_map.insert( Qtopia::Groups, "Groups" ); return ret_map; } QMap<QString, int> OContactFields::trFieldsToId() { QMap<int, QString> idtostr = idToTrFields(); QMap<QString, int> ret_map; QMap<int, QString>::Iterator it; for( it = idtostr.begin(); it != idtostr.end(); ++it ) ret_map.insert( *it, it.key() ); return ret_map; } +/* ======================================================================= */ + QMap<QString, int> OContactFields::untrFieldsToId() { QMap<int, QString> idtostr = idToUntrFields(); QMap<QString, int> ret_map; QMap<int, QString>::Iterator it; for( it = idtostr.begin(); it != idtostr.end(); ++it ) ret_map.insert( *it, it.key() ); return ret_map; } OContactFields::OContactFields(): fieldOrder( DEFAULT_FIELD_ORDER ), changedFieldOrder( false ) { // Get the global field order from the config file and // use it as a start pattern Config cfg ( "AddressBook" ); cfg.setGroup( "ContactFieldOrder" ); globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER ); } OContactFields::~OContactFields(){ // We will store the fieldorder into the config file // to reuse it for the future.. if ( changedFieldOrder ){ Config cfg ( "AddressBook" ); cfg.setGroup( "ContactFieldOrder" ); cfg.writeEntry( "General", globalFieldOrder ); } } void OContactFields::saveToRecord( OContact &cnt ){ qDebug("ocontactfields saveToRecord: >%s<",fieldOrder.latin1()); // Store fieldorder into this contact. cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder ); globalFieldOrder = fieldOrder; changedFieldOrder = true; diff --git a/libopie2/opiepim/ocontactfields.h b/libopie2/opiepim/ocontactfields.h index 9f6171b..f105de7 100644 --- a/libopie2/opiepim/ocontactfields.h +++ b/libopie2/opiepim/ocontactfields.h @@ -1,60 +1,67 @@ #ifndef OPIE_CONTACTS_FIELDS #define OPIE_CONTACTS_FIELDS class QStringList; #include <qmap.h> #include <qstring.h> #include <opie/ocontact.h> #define CONTACT_FIELD_ORDER_NAME "opie-contactfield-order" #define DEFAULT_FIELD_ORDER "__________" class OContactFields{ public: OContactFields(); ~OContactFields(); /** Set the index for combo boxes. * Sets the <b>index</b> of combo <b>num</b>. * @param num selects the number of the combo * @param index sets the index in the combo */ void setFieldOrder( int num, int index ); /** Get the index for combo boxes. * Returns the index of combo <b>num</b> or defindex * if none was defined.. * @param num Selects the number of the combo * @param defIndex will be returned if none was defined (either * globally in the config file, nor by the contact which was used * by loadFromRecord() ) */ int getFieldOrder( int num, int defIndex); /** Store fieldorder to contact. */ void saveToRecord( OContact& ); /** Get Fieldorder from contact. */ void loadFromRecord( const OContact& ); private: QString fieldOrder; QString globalFieldOrder; bool changedFieldOrder; public: + static QStringList personalfields( bool sorted = true, bool translated = false ); + static QStringList phonefields( bool sorted = true, bool translated = false ); + static QStringList detailsfields( bool sorted = true, bool translated = false ); + static QStringList fields( bool sorted = true, bool translated = false ); + + static QStringList trpersonalfields( bool sorted = true ); + static QStringList untrpersonalfields( bool sorted = true ); static QStringList trphonefields( bool sorted = true ); static QStringList untrphonefields( bool sorted = true ); static QStringList trdetailsfields( bool sorted = true ); static QStringList untrdetailsfields( bool sorted = true ); static QStringList trfields( bool sorted = true ); static QStringList untrfields( bool sorted = true ); static QMap<int, QString> idToTrFields(); static QMap<QString, int> trFieldsToId(); static QMap<int, QString> idToUntrFields(); static QMap<QString, int> untrFieldsToId(); }; #endif |