Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 144 |
1 files changed, 120 insertions, 24 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index 3d284f7..9375f43 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp @@ -129,3 +129,3 @@ namespace { FindQuery(int uid); - FindQuery(const QArray<int>& ); + FindQuery(const UIDArray& ); ~FindQuery(); @@ -135,3 +135,3 @@ namespace { QString multi()const; - QArray<int> m_uids; + UIDArray m_uids; int m_uid; @@ -145,3 +145,3 @@ namespace { FindCustomQuery(int uid); - FindCustomQuery(const QArray<int>& ); + FindCustomQuery(const UIDArray& ); ~FindCustomQuery(); @@ -151,3 +151,3 @@ namespace { QString multi()const; - QArray<int> m_uids; + UIDArray m_uids; int m_uid; @@ -296,3 +296,3 @@ namespace { } - FindQuery::FindQuery(const QArray<int>& ints) + FindQuery::FindQuery(const UIDArray& ints) : OSQLQuery(), m_uids( ints ){ @@ -331,3 +331,3 @@ namespace { } - FindCustomQuery::FindCustomQuery(const QArray<int>& ints) + FindCustomQuery::FindCustomQuery(const UIDArray& ints) : OSQLQuery(), m_uids( ints ){ @@ -424,3 +424,3 @@ bool OPimContactAccessBackend_SQL::wasChangedExternally() -QArray<int> OPimContactAccessBackend_SQL::allRecords() const +UIDArray OPimContactAccessBackend_SQL::allRecords() const { @@ -487,3 +487,3 @@ OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const -OPimContact OPimContactAccessBackend_SQL::find( int uid, const QArray<int>& queryUids, uint current, Frontend::CacheDirection direction ) const +OPimContact OPimContactAccessBackend_SQL::find( int uid, const UIDArray& queryUids, uint current, Frontend::CacheDirection direction ) const { @@ -530,3 +530,4 @@ OPimContact OPimContactAccessBackend_SQL::find( int uid, const QArray<int>& quer -QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd ) +UIDArray OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, + const QDateTime& qd ) const { @@ -641,3 +642,3 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu if ( res.state() != OSQLResult::Success ){ - QArray<int> empty; + UIDArray empty; return empty; @@ -645,3 +646,3 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu - QArray<int> list = extractUids( res ); + UIDArray list = extractUids( res ); @@ -650,3 +651,3 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu -QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const +UIDArray OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const { @@ -681,3 +682,3 @@ QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const -const uint OPimContactAccessBackend_SQL::querySettings() +const uint OPimContactAccessBackend_SQL::querySettings() const { @@ -740,3 +741,4 @@ bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const -QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) +UIDArray OPimContactAccessBackend_SQL::sorted( const UIDArray& ar, bool asc, int sortOrder, + int filter, const QArray<int>& categories )const { @@ -745,9 +747,103 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) - QString query = "SELECT uid FROM addressbook "; - query += "ORDER BY \"Last Name\" "; + QString query = "SELECT uid FROM addressbook"; + + query += " WHERE ("; + for ( uint i = 0; i < ar.count(); i++ ) { + query += " uid = " + QString::number( ar[i] ) + " OR"; + } + query.remove( query.length()-2, 2 ); // Hmmmm.. + query += ")"; + + + if ( filter != OPimBase::FilterOff ){ + if ( filter & OPimContactAccess::DoNotShowWithCategory ){ + query += " AND ( \"Categories\" == '' )"; + } else if ( filter & OPimBase::FilterCategory ){ + query += " AND ("; + for ( uint i = 0; i < categories.count(); i++ ){ + query += "\"Categories\" LIKE"; + query += QString( " '%" ) + QString::number( categories[i] ) + "%' OR"; + } + query.remove( query.length()-2, 2 ); // Hmmmm.. + query += ")"; + } + + if ( filter & OPimContactAccess::DoNotShowWithoutChildren ){ + query += " AND ( \"Children\" != '' )"; + } + + if ( filter & OPimContactAccess::DoNotShowWithoutAnniversary ){ + query += " AND ( \"Anniversary\" != '' )"; + } + + if ( filter & OPimContactAccess::DoNotShowWithoutBirthday ){ + query += " AND ( \"Birthday\" != '' )"; + } + + if ( filter & OPimContactAccess::DoNotShowWithoutHomeAddress ){ + // Expect that no Street means no Address, too! (eilers) + query += " AND ( \"Home Street\" != '' )"; + } + + if ( filter & OPimContactAccess::DoNotShowWithoutBusinessAddress ){ + // Expect that no Street means no Address, too! (eilers) + query += " AND ( \"Business Street\" != '' )"; + } + + } + + query += " ORDER BY"; + + switch ( sortOrder ) { + case OPimContactAccess::SortSummary: + query += " \"Notes\""; + break; + case OPimContactAccess::SortByCategory: + query += " \"Categories\""; + break; + case OPimContactAccess::SortByDate: + query += " \"\""; + break; + case OPimContactAccess::SortTitle: + query += " \"Name Title\""; + break; + case OPimContactAccess::SortFirstName: + query += " \"First Name\""; + break; + case OPimContactAccess::SortMiddleName: + query += " \"Middle Name\""; + break; + case OPimContactAccess::SortLastName: + query += " \"Last Name\""; + break; + case OPimContactAccess::SortFileAsName: + query += " \"File As\""; + break; + case OPimContactAccess::SortSuffix: + query += " \"Suffix\""; + break; + case OPimContactAccess::SortEmail: + query += " \"Default Email\""; + break; + case OPimContactAccess::SortNickname: + query += " \"Nickname\""; + break; + case OPimContactAccess::SortAnniversary: + query += " \"Anniversary\""; + break; + case OPimContactAccess::SortBirthday: + query += " \"Birthday\""; + break; + case OPimContactAccess::SortGender: + query += " \"Gender\""; + break; + default: + query += " \"Last Name\""; + } if ( !asc ) - query += "DESC"; + query += " DESC"; + - // odebug << "sorted query is: " << query << "" << oendl; + odebug << "sorted query is: " << query << "" << oendl; @@ -756,3 +852,3 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) if ( res.state() != OSQLResult::Success ){ - QArray<int> empty; + UIDArray empty; return empty; @@ -760,3 +856,3 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) - QArray<int> list = extractUids( res ); + UIDArray list = extractUids( res ); @@ -788,3 +884,3 @@ void OPimContactAccessBackend_SQL::update() -QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const +UIDArray OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const { @@ -795,3 +891,3 @@ QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const OSQLResultItem::ValueList::Iterator it; - QArray<int> ints(list.count() ); + UIDArray ints(list.count() ); odebug << " count = " << list.count() << "" << oendl; @@ -839,3 +935,3 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co /* Returns contact requested by uid and fills cache with contacts requested by uids in the cachelist */ -OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, const QArray<int>& uidlist )const +OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, const UIDArray& uidlist )const { @@ -845,3 +941,3 @@ OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, cons // by using the cache.. - QArray<int> cachelist = uidlist; + UIDArray cachelist = uidlist; OPimContact retContact; |