Re: [PATCH] fix sorting of birthdays and anniversaries on today screen
Paul Eggleton <[email protected]> Fri, 5 Jan 2007 18:45:02 +1300
| Newsgroups | gmane.comp.handhelds.opie.devel |
|---|---|
| Message-ID | <[email protected]> |
On Sunday 31 December 2006 01:10, Paul Eggleton wrote: > The attached patch implements the missing sort types that enable correct > sorting of upcoming birthdays and anniversaries on the today screen. > > This fixes bug #1760 (http://opie-bugs.oszine.de/view.php?id=1760). Re-based patch with style changes removed is attached. Cheers, Paul _______________________________________________ http://opie.handhelds.org/cgi-bin/moin.cgi/DeveloperWikiIndex Opie-devel mailing list [email protected] https://handhelds.org/mailman/listinfo/opie-devel
today_contactdate_sort2.patch
(text/x-diff, 3.2 KB)
Index: libopie2/opiepim/private/opimcontactsortvector.cpp
===================================================================
RCS file: /cvs/opie/libopie2/opiepim/private/opimcontactsortvector.cpp,v
retrieving revision 1.2
diff -u -B -b -r1.2 opimcontactsortvector.cpp
--- libopie2/opiepim/private/opimcontactsortvector.cpp 15 Mar 2005 18:20:46 -0000 1.2
+++ libopie2/opiepim/private/opimcontactsortvector.cpp 5 Jan 2007 05:43:02 -0000
@@ -64,6 +64,9 @@
ret = testString( left.middleName(), right.middleName() );
soMiddleName = true;
break;
+ case OPimContactAccess::SortLastName:
+ ret = testString( left.lastName(), right.lastName() );
+ break;
case OPimContactAccess::SortSuffix:
ret = testString( left.suffix(), right.suffix() );
soSuffix = true;
@@ -93,6 +96,17 @@
ret = testString( left.gender(), right.gender() );
soGender = true;
break;
+ case OPimContactAccess::SortBirthdayWithoutYear:
+ // This doesn't actually just sort by the date without year,
+ // it actually works out the days until the next occurrence,
+ // which is more useful since it will work correctly when
+ // crossing year boundaries. - Paul Eggleton Dec 2006
+ ret = testDaysUntilNextDate( left.birthday(), right.birthday() );
+ break;
+ case OPimContactAccess::SortAnniversaryWithoutYear:
+ // (as above)
+ ret = testDaysUntilNextDate( left.anniversary(), right.anniversary() );
+ break;
}
/* twist to honor ascending/descending setting as QVector only sorts ascending*/
Index: libopie2/opiepim/private/opimsortvector.h
===================================================================
RCS file: /cvs/opie/libopie2/opiepim/private/opimsortvector.h,v
retrieving revision 1.2
diff -u -B -b -r1.2 opimsortvector.h
--- libopie2/opiepim/private/opimsortvector.h 16 Jan 2005 19:54:30 -0000 1.2
+++ libopie2/opiepim/private/opimsortvector.h 5 Jan 2007 05:43:02 -0000
@@ -56,6 +56,8 @@
int testTime( const QTime&, const QTime& )const;
int testDateTime( const QDateTime& left,
const QDateTime& right )const;
+ int testDaysUntilNextDate( const QDate& left,
+ const QDate& right )const;
protected:
bool sortAscending()const;
int sortOrder()const;
@@ -166,6 +168,28 @@
}
+template<class T>
+inline int OPimSortVector<T>::testDaysUntilNextDate( const QDate& left,
+ const QDate& right )const {
+ int ret = 0;
+ if ( !left .isValid() ) ret++;
+ if ( !right.isValid() ) ret--;
+
+ if ( left.isValid() && right.isValid() ){
+ int currentYear = QDate::currentDate().year();
+ QDate nextLeft( currentYear, left.month(), left.day() );
+ if ( QDate::currentDate().daysTo(nextLeft) < 0 )
+ nextLeft.setYMD( currentYear+1, left.month(), left.day() );
+ QDate nextRight( currentYear, right.month(), right.day() );
+ if ( QDate::currentDate().daysTo(nextRight) < 0 )
+ nextRight.setYMD( currentYear+1, right.month(), right.day() );
+
+ ret += QDate::currentDate().daysTo(nextLeft) < QDate::currentDate().daysTo(nextRight) ? -1 : 1;
+ }
+
+ return ret;
+}
+
}
}