Re: [PATCH] fix sorting of birthdays and anniversaries on today screen
Dmitriy Korovkin <[email protected]> Sat, 30 Dec 2006 20:49:59 +0300
| Newsgroups | gmane.comp.handhelds.opie.devel |
|---|---|
| Message-ID | <[email protected]> |
Paul,
Great work! Please, take a little break. We all are preparing to the New
Year celebration. We can't review ant test your patches so fast :-).
Happy New Year!
Dmitriy
Paul Eggleton wrote:
> Hi there,
>
> 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).
>
> Cheers,
> Paul
>
> ------------------------------------------------------------------------
>
> Index: opimcontactsortvector.cpp
> ===================================================================
> RCS file: /cvs/opie/libopie2/opiepim/private/opimcontactsortvector.cpp,v
> retrieving revision 1.2
> diff -d -u -r1.2 opimcontactsortvector.cpp
> --- opimcontactsortvector.cpp 15 Mar 2005 18:20:46 -0000 1.2
> +++ opimcontactsortvector.cpp 30 Dec 2006 12:02:16 -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: opimsortvector.h
> ===================================================================
> RCS file: /cvs/opie/libopie2/opiepim/private/opimsortvector.h,v
> retrieving revision 1.2
> diff -d -u -r1.2 opimsortvector.h
> --- opimsortvector.h 16 Jan 2005 19:54:30 -0000 1.2
> +++ opimsortvector.h 30 Dec 2006 12:02:17 -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;
> +}
> +
> }
> }
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
>
> http://opie.handhelds.org/cgi-bin/moin.cgi/DeveloperWikiIndex
>
> Opie-devel mailing list
> [email protected]
> https://handhelds.org/mailman/listinfo/opie-devel
>
_______________________________________________
http://opie.handhelds.org/cgi-bin/moin.cgi/DeveloperWikiIndex
Opie-devel mailing list
[email protected]
https://handhelds.org/mailman/listinfo/opie-devel