author | zecke <zecke> | 2002-10-20 12:15:51 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-20 12:15:51 (UTC) |
commit | 82689364fd558ccd28253961204e6b3eb9e32b03 (patch) (side-by-side diff) | |
tree | aec5a649346194aa76aaadd9c7418b700ac4d3d3 /libopie/pim | |
parent | 7948b5910a098d05f4cc7d0fb14b0f216bf41358 (diff) | |
download | opie-82689364fd558ccd28253961204e6b3eb9e32b03.zip opie-82689364fd558ccd28253961204e6b3eb9e32b03.tar.gz opie-82689364fd558ccd28253961204e6b3eb9e32b03.tar.bz2 |
Added ORecur which is a base class for Recurrance extracted from TT Event class
and a widget where you can set the Recurrance
This will be used at least in Todolist and Datebook and in the common
classes of OTodo and OEvent
Fixed the SQL in multiple ways it's summary not description for example
-rw-r--r-- | libopie/pim/libopie.pro | 6 | ||||
-rw-r--r-- | libopie/pim/orecordlist.h | 2 | ||||
-rw-r--r-- | libopie/pim/orecur.cpp | 127 | ||||
-rw-r--r-- | libopie/pim/orecur.h | 54 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 2 |
5 files changed, 188 insertions, 3 deletions
diff --git a/libopie/pim/libopie.pro b/libopie/pim/libopie.pro index 1dacbe7..b871374 100644 --- a/libopie/pim/libopie.pro +++ b/libopie/pim/libopie.pro @@ -1,75 +1,77 @@ TEMPLATE = lib CONFIG += qte warn_on release HEADERS = ofontmenu.h \ tododb.h \ todoevent.h todoresource.h \ todovcalresource.h xmltree.h \ colordialog.h colorpopupmenu.h \ oclickablelabel.h oprocctrl.h \ oprocess.h odevice.h \ otimepicker.h otabwidget.h \ otabbar.h otabinfo.h \ ofileselector/ofiledialog.h \ ofileselector/ofilelistview.h \ ofileselector/ofileselector.h \ ofileselector/ofileselectoritem.h \ ofileselector/ofileview.h \ ofileselector/olister.h \ ofileselector/olocallister.h \ ofileselector/ofileselectormain.h \ pim/opimrecord.h \ pim/otodo.h \ pim/orecordlist.h \ pim/opimaccesstemplate.h \ pim/opimaccessbackend.h \ pim/otodoaccess.h \ pim/otodacessbackend.h \ pim/ocontact.h \ pim/ocontactaccess.h \ pim/ocontactaccessbackend.h \ - pim/ocontactaccessbackend_xml.h + pim/ocontactaccessbackend_xml.h \ + pim/orecord.h SOURCES = ofontmenu.cc \ xmltree.cc \ tododb.cpp todoevent.cpp \ todovcalresource.cpp colordialog.cpp \ colorpopupmenu.cpp oclickablelabel.cpp \ oprocctrl.cpp oprocess.cpp \ odevice.cpp otimepicker.cpp \ otabwidget.cpp otabbar.cpp \ ofileselector/ofiledialog.cpp \ ofileselector/ofilelistview.cpp \ ofileselector/ofileselector.cpp \ ofileselector/ofileselectoritem.cpp \ ofileselector/ofileview.cpp \ ofileselector/olister.cpp \ ofileselector/olocallister.cpp \ ofileselector/ofileselectormain.cpp \ pim/otodo.cpp \ pim/opimrecord.cpp \ pim/otodoaccess.cpp \ pim/otodoaccessbackend.cpp \ pim/ocontact.cpp \ - pim/ocontactaccess.cpp + pim/ocontactaccess.cpp \ + pim/orecord.cpp TARGET = opie INCLUDEPATH += $(OPIEDIR)/include DESTDIR = $(QTDIR)/lib$(PROJMAK) #VERSION = 1.0.0 INTERFACES = otimepickerbase.ui TRANSLATIONS = ../i18n/de/libopie.ts \ ../i18n/en/libopie.ts \ ../i18n/es/libopie.ts \ ../i18n/fr/libopie.ts \ ../i18n/hu/libopie.ts \ ../i18n/ja/libopie.ts \ ../i18n/ko/libopie.ts \ ../i18n/no/libopie.ts \ ../i18n/pl/libopie.ts \ ../i18n/pt/libopie.ts \ ../i18n/pt_BR/libopie.ts \ ../i18n/sl/libopie.ts \ ../i18n/zh_CN/libopie.ts \ ../i18n/zh_TW/libopie.ts diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index 5404910..e377447 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h @@ -167,104 +167,106 @@ T ORecordListIterator<T>::operator*() { else m_record = T(); return m_record; } template <class T> ORecordListIterator<T> &ORecordListIterator<T>::operator++() { m_direction = true; if (m_current < m_uids.count() ) { m_end = false; ++m_current; }else m_end = true; return *this; } template <class T> ORecordListIterator<T> &ORecordListIterator<T>::operator--() { m_direction = false; if ( m_current > 0 ) { --m_current; m_end = false; } else m_end = true; return *this; } template <class T> bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& 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 <class T> bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { return !(*this == it ); } template <class T> ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, const Base* t ) : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), m_direction( false ) { } template <class T> uint ORecordListIterator<T>::current()const { return m_current; } template <class T> void ORecordListIterator<T>::setCurrent( uint cur ) { if( cur < m_uids.count() ) { m_end = false; m_current= cur; } } template <class T> uint ORecordListIterator<T>::count()const { return m_uids.count(); } template <class T> ORecordList<T>::ORecordList( const QArray<int>& ids, const Base* acc ) : m_ids( ids ), m_acc( acc ) { } template <class T> ORecordList<T>::~ORecordList() { /* nothing to do here */ } template <class T> ORecordList<T>::Iterator ORecordList<T>::begin() { Iterator it( m_ids, m_acc ); return it; } template <class T> ORecordList<T>::Iterator ORecordList<T>::end() { Iterator it( m_ids, m_acc ); it.m_end = true; it.m_current = m_ids.count(); return it; } template <class T> uint ORecordList<T>::count()const { return m_ids.count(); } template <class T> T ORecordList<T>::operator[]( uint i ) { + if ( i < 0 || (i+1) > m_ids.count() ) + return T(); /* forward */ return m_acc->find( m_ids[i], m_ids, i ); } template <class T> int ORecordList<T>::uidAt( uint i ) { return m_ids[i]; } #endif diff --git a/libopie/pim/orecur.cpp b/libopie/pim/orecur.cpp new file mode 100644 index 0000000..6c81f8f --- a/dev/null +++ b/libopie/pim/orecur.cpp @@ -0,0 +1,127 @@ +#include <qshared.h> + +#include <qtopia/timeconversion.h> + +#include "orecur.h" + +struct ORecur::Data : public QShared { + Data() : QShared() { + type = ORecur::NoRepeat; + freq = -1; + days = 0; + pos = 0; + create = -1; + hasEnd = FALSE; + end = 0; + } + char days; // Q_UINT8 for 8 seven days;) + ORecur::RepeatType type; + int freq; + int pos; + bool hasEnd : 1; + time_t end; + time_t create; +}; + + +ORecur::ORecur() { + data = new Data; +} +ORecur::ORecur( const ORecur& rec) + : data( rec.data ) +{ + data->ref(); +} +ORecur::~ORecur() { + if ( data->deref() ) { + delete data; + data = 0l; + } +} +void ORecur::deref() { + if ( data->deref() ) { + delete data; + data = 0l; + } +} +bool ORecur::operator==( const ORecur& )const { + return false; +} +ORecur &ORecur::operator=( const ORecur& re) { + re.data->ref(); + deref(); + data = re.data; + + return *this; +} +ORecur::RepeatType ORecur::type()const{ + return data->type; +} +int ORecur::frequency()const { + return data->freq; +} +int ORecur::position()const { + return data->pos; +} +char ORecur::days() const{ + return data->days; +} +bool ORecur::hasEndDate()const { + return data->hasEnd; +} +QDate ORecur::endDate()const { + return TimeConversion::fromUTC( data->end ).date(); +} +time_t ORecur::endDateUTC()const { + return data->end; +} +time_t ORecur::createTime()const { + return data->create; +} +void ORecur::setType( const RepeatType& z) { + checkOrModify(); + data->type = z; +} +void ORecur::setFrequency( int freq ) { + checkOrModify(); + data->freq = freq; +} +void ORecur::setPosition( int pos ) { + checkOrModify(); + data->pos = pos; +} +void ORecur::setDays( char c ) { + checkOrModify(); + data->days = c; +} +void ORecur::setEndDate( const QDate& dt) { + checkOrModify(); + data->end = TimeConversion::toUTC( dt ); +} +void ORecur::setEndDateUTC( time_t t) { + checkOrModify(); + data->end = t; +} +void ORecur::setCreateTime( time_t t) { + checkOrModify(); + data->create = t; +} +void ORecur::setHasEndDate( bool b) { + checkOrModify(); + data->hasEnd = b; +} +void ORecur::checkOrModify() { + if ( data->count != 1 ) { + data->deref(); + Data* d2 = new Data; + d2->days = data->days; + d2->type = data->type; + d2->freq = data->freq; + d2->pos = data->pos; + d2->hasEnd = data->hasEnd; + d2->end = data->end; + d2->create = data->create; + data = d2; + } +} + diff --git a/libopie/pim/orecur.h b/libopie/pim/orecur.h new file mode 100644 index 0000000..89258f8 --- a/dev/null +++ b/libopie/pim/orecur.h @@ -0,0 +1,54 @@ +/* + * GPL from TT + */ + +#ifndef OPIE_RECUR_H +#define OPIE_RECUR_H + +#include <sys/types.h> + +#include <qdatetime.h> + + + +class ORecur { +public: + enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay, + MonthlyDate, Yearly }; + enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, + FRI = 0x10, SAT = 0x20, SUN = 0x40 }; + ORecur(); + ORecur( const ORecur& ); + ~ORecur(); + + ORecur &operator=( const ORecur& ); + bool operator==(const ORecur& )const; + RepeatType type()const; + int frequency()const; + int position()const; + char days()const; + bool hasEndDate()const; + QDate endDate()const; + time_t endDateUTC()const; + time_t createTime()const; + + void setType( const RepeatType& ); + void setFrequency( int freq ); + void setPosition( int pos ); + void setDays( char c); + void setEndDate( const QDate& dt ); + void setEndDateUTC( time_t ); + void setCreateTime( time_t ); + void setHasEndDate( bool b ); +private: + void deref(); + inline void checkOrModify(); + + + class Data; + Data* data; + class ORecurPrivate; + ORecurPrivate *d; +}; + +#endif diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index 8c2ea3a..761d7d8 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp @@ -328,193 +328,193 @@ void OTodoAccessBackendSQL::clear() { } bool OTodoAccessBackendSQL::add( const OTodo& t) { InsertQuery ins( t ); OSQLResult res = m_driver->query( &ins ); if ( res.state() == OSQLResult::Failure ) return false; int c = m_uids.count(); m_uids.resize( c+1 ); m_uids[c] = t.uid(); return true; } bool OTodoAccessBackendSQL::remove( int uid ) { RemoveQuery rem( uid ); OSQLResult res = m_driver->query(&rem ); if ( res.state() == OSQLResult::Failure ) return false; m_dirty = true; return true; } /* * FIXME better set query * but we need the cache for that * now we remove */ bool OTodoAccessBackendSQL::replace( const OTodo& t) { remove( t.uid() ); bool b= add(t); m_dirty = false; // we changed some stuff but the UID stayed the same return b; } QArray<int> OTodoAccessBackendSQL::overDue() { OverDueQuery qu; return uids( m_driver->query(&qu ) ); } QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, const QDate& t, bool u) { EffQuery ef(s, t, u ); return uids (m_driver->query(&ef) ); } /* * */ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, int sortFilter, int cat ) { qWarning("sorted %d, %d", asc, sortOrder ); QString query; query = "select uid from todolist WHERE "; /* * Sort Filter stuff * not that straight forward * */ /* Category */ if ( sortFilter & 1 ) { QString str; if (cat != 0 ) str = QString::number( cat ); query += " categories like '%" +str+"%' AND"; } /* Show only overdue */ if ( sortFilter & 2 ) { QDate date = QDate::currentDate(); QString due; QString base; base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); query += " " + base + " AND"; } /* not show completed */ if ( sortFilter & 4 ) { query += " completed = 0 AND"; }else{ query += " ( completed = 1 OR completed = 0) AND"; } /* srtip the end */ query = query.remove( query.length()-3, 3 ); /* * sort order stuff * quite straight forward */ query += "ORDER BY "; switch( sortOrder ) { /* completed */ case 0: query += "completed"; break; case 1: query += "priority"; break; case 2: - query += "description"; + query += "summary"; break; case 3: query += "DueDate"; break; } if ( !asc ) { qWarning("not ascending!"); query += " DESC"; } qWarning( query ); OSQLRawQuery raw(query ); return uids( m_driver->query(&raw) ); } bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ if ( str == "0-0-0" ) return false; else{ int day, year, month; QStringList list = QStringList::split("-", str ); year = list[0].toInt(); month = list[1].toInt(); day = list[2].toInt(); da.setYMD( year, month, day ); return true; } } OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ if ( res.state() == OSQLResult::Failure ) { OTodo to; return to; } OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it = list.begin(); qWarning("todo1"); OTodo to = todo( (*it) ); cache( to ); ++it; for ( ; it != list.end(); ++it ) { qWarning("caching"); cache( todo( (*it) ) ); } return to; } OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { qWarning("todo"); bool has = false; QDate da = QDate::currentDate(); has = date( da, 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(), has, da, item.data("uid").toInt() ); 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!!! */ 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) ); m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); } /* * 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); |