summaryrefslogtreecommitdiff
authoreilers <eilers>2004-09-05 15:46:47 (UTC)
committer eilers <eilers>2004-09-05 15:46:47 (UTC)
commit97a40bb7f35a8323dd99712bf014387add283177 (patch) (unidiff)
treeec50fbb430f00c86af6ca5bd7c6b94fa29cfe3b1
parentf8b02e2ae752ce98b8840735260c4e9b0ff25cb8 (diff)
downloadopie-97a40bb7f35a8323dd99712bf014387add283177.zip
opie-97a40bb7f35a8323dd99712bf014387add283177.tar.gz
opie-97a40bb7f35a8323dd99712bf014387add283177.tar.bz2
Fixing really stupid caching bug.. Thanks to zecke who found it..
Removed cachefind in backend which isn't needed anymore and not a goot idea...
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp5
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.h4
-rw-r--r--libopie2/opiepim/backend/opimaccessbackend.h22
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp20
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.h2
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h4
6 files changed, 25 insertions, 32 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index abfd944..221e977 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -589,362 +589,365 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu
589 .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ); 589 .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) );
590 } 590 }
591 591
592 if ( settings & OPimContactAccess::DateMonth ){ 592 if ( settings & OPimContactAccess::DateMonth ){
593 if ( ( settings & OPimContactAccess::DateDiff ) 593 if ( ( settings & OPimContactAccess::DateDiff )
594 || ( settings & OPimContactAccess::DateYear ) ) 594 || ( settings & OPimContactAccess::DateYear ) )
595 searchQuery += " AND"; 595 searchQuery += " AND";
596 596
597 searchQuery += QString( " (\"%1\" LIKE '%-%2-%')" ) 597 searchQuery += QString( " (\"%1\" LIKE '%-%2-%')" )
598 .arg( *it ) 598 .arg( *it )
599 .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ); 599 .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) );
600 } 600 }
601 601
602 if ( settings & OPimContactAccess::DateDay ){ 602 if ( settings & OPimContactAccess::DateDay ){
603 if ( ( settings & OPimContactAccess::DateDiff ) 603 if ( ( settings & OPimContactAccess::DateDiff )
604 || ( settings & OPimContactAccess::DateYear ) 604 || ( settings & OPimContactAccess::DateYear )
605 || ( settings & OPimContactAccess::DateMonth ) ) 605 || ( settings & OPimContactAccess::DateMonth ) )
606 searchQuery += " AND"; 606 searchQuery += " AND";
607 607
608 searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" ) 608 searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" )
609 .arg( *it ) 609 .arg( *it )
610 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ); 610 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) );
611 } 611 }
612 612
613 break; 613 break;
614 default: 614 default:
615 // Switching between case sensitive and insensitive... 615 // Switching between case sensitive and insensitive...
616 // LIKE is not case sensitive, GLOB is case sensitive 616 // LIKE is not case sensitive, GLOB is case sensitive
617 // Do exist a better solution to switch this ? 617 // Do exist a better solution to switch this ?
618 if ( settings & OPimContactAccess::IgnoreCase ) 618 if ( settings & OPimContactAccess::IgnoreCase )
619 searchQuery += "(\"" + *it + "\"" + " LIKE " + "'" 619 searchQuery += "(\"" + *it + "\"" + " LIKE " + "'"
620 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")"; 620 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")";
621 else 621 else
622 searchQuery += "(\"" + *it + "\"" + " GLOB " + "'" 622 searchQuery += "(\"" + *it + "\"" + " GLOB " + "'"
623 + queryStr + "'" + ")"; 623 + queryStr + "'" + ")";
624 624
625 } 625 }
626 } 626 }
627 } 627 }
628 // Skip trailing "AND" 628 // Skip trailing "AND"
629// if ( isAnyFieldSelected ) 629// if ( isAnyFieldSelected )
630// qu = qu.left( qu.length() - 4 ); 630// qu = qu.left( qu.length() - 4 );
631 631
632 qu += searchQuery; 632 qu += searchQuery;
633 633
634 odebug << "queryByExample query: " << qu << "" << oendl; 634 odebug << "queryByExample query: " << qu << "" << oendl;
635 635
636 // Execute query and return the received uid's 636 // Execute query and return the received uid's
637 OSQLRawQuery raw( qu ); 637 OSQLRawQuery raw( qu );
638 OSQLResult res = m_driver->query( &raw ); 638 OSQLResult res = m_driver->query( &raw );
639 if ( res.state() != OSQLResult::Success ){ 639 if ( res.state() != OSQLResult::Success ){
640 QArray<int> empty; 640 QArray<int> empty;
641 return empty; 641 return empty;
642 } 642 }
643 643
644 QArray<int> list = extractUids( res ); 644 QArray<int> list = extractUids( res );
645 645
646 return list; 646 return list;
647} 647}
648 648
649QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 649QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
650{ 650{
651#if 0 651#if 0
652 QArray<int> nix(0); 652 QArray<int> nix(0);
653 return nix; 653 return nix;
654 654
655#else 655#else
656 QString qu = "SELECT uid FROM addressbook WHERE ("; 656 QString qu = "SELECT uid FROM addressbook WHERE (";
657 QString searchlist; 657 QString searchlist;
658 658
659 QStringList fieldList = OPimContactFields::untrfields( false ); 659 QStringList fieldList = OPimContactFields::untrfields( false );
660 // QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 660 // QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
661 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 661 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
662 if ( !searchlist.isEmpty() ) 662 if ( !searchlist.isEmpty() )
663 searchlist += " OR "; 663 searchlist += " OR ";
664 searchlist += " rlike(\""+ r.pattern() + "\",\"" + *it + "\") "; 664 searchlist += " rlike(\""+ r.pattern() + "\",\"" + *it + "\") ";
665 } 665 }
666 666
667 qu = qu + searchlist + ")"; 667 qu = qu + searchlist + ")";
668 668
669 odebug << "query: " << qu << "" << oendl; 669 odebug << "query: " << qu << "" << oendl;
670 670
671 OSQLRawQuery raw( qu ); 671 OSQLRawQuery raw( qu );
672 OSQLResult res = m_driver->query( &raw ); 672 OSQLResult res = m_driver->query( &raw );
673 673
674 return extractUids( res ); 674 return extractUids( res );
675 675
676 676
677#endif 677#endif
678} 678}
679 679
680const uint OPimContactAccessBackend_SQL::querySettings() 680const uint OPimContactAccessBackend_SQL::querySettings()
681{ 681{
682 return OPimContactAccess::IgnoreCase 682 return OPimContactAccess::IgnoreCase
683 | OPimContactAccess::WildCards 683 | OPimContactAccess::WildCards
684 | OPimContactAccess::DateDiff 684 | OPimContactAccess::DateDiff
685 | OPimContactAccess::DateYear 685 | OPimContactAccess::DateYear
686 | OPimContactAccess::DateMonth 686 | OPimContactAccess::DateMonth
687 | OPimContactAccess::DateDay 687 | OPimContactAccess::DateDay
688 ; 688 ;
689} 689}
690 690
691bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const 691bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const
692{ 692{
693 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay 693 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
694 * may be added with any of the other settings. IgnoreCase should never used alone. 694 * may be added with any of the other settings. IgnoreCase should never used alone.
695 * Wildcards, RegExp, ExactMatch should never used at the same time... 695 * Wildcards, RegExp, ExactMatch should never used at the same time...
696 */ 696 */
697 697
698 // Step 1: Check whether the given settings are supported by this backend 698 // Step 1: Check whether the given settings are supported by this backend
699 if ( ( querySettings & ( 699 if ( ( querySettings & (
700 OPimContactAccess::IgnoreCase 700 OPimContactAccess::IgnoreCase
701 | OPimContactAccess::WildCards 701 | OPimContactAccess::WildCards
702 | OPimContactAccess::DateDiff 702 | OPimContactAccess::DateDiff
703 | OPimContactAccess::DateYear 703 | OPimContactAccess::DateYear
704 | OPimContactAccess::DateMonth 704 | OPimContactAccess::DateMonth
705 | OPimContactAccess::DateDay 705 | OPimContactAccess::DateDay
706// | OPimContactAccess::RegExp 706// | OPimContactAccess::RegExp
707// | OPimContactAccess::ExactMatch 707// | OPimContactAccess::ExactMatch
708 ) ) != querySettings ) 708 ) ) != querySettings )
709 return false; 709 return false;
710 710
711 // Step 2: Check whether the given combinations are ok.. 711 // Step 2: Check whether the given combinations are ok..
712 712
713 // IngoreCase alone is invalid 713 // IngoreCase alone is invalid
714 if ( querySettings == OPimContactAccess::IgnoreCase ) 714 if ( querySettings == OPimContactAccess::IgnoreCase )
715 return false; 715 return false;
716 716
717 // WildCards, RegExp and ExactMatch should never used at the same time 717 // WildCards, RegExp and ExactMatch should never used at the same time
718 switch ( querySettings & ~( OPimContactAccess::IgnoreCase 718 switch ( querySettings & ~( OPimContactAccess::IgnoreCase
719 | OPimContactAccess::DateDiff 719 | OPimContactAccess::DateDiff
720 | OPimContactAccess::DateYear 720 | OPimContactAccess::DateYear
721 | OPimContactAccess::DateMonth 721 | OPimContactAccess::DateMonth
722 | OPimContactAccess::DateDay 722 | OPimContactAccess::DateDay
723 ) 723 )
724 ){ 724 ){
725 case OPimContactAccess::RegExp: 725 case OPimContactAccess::RegExp:
726 return ( true ); 726 return ( true );
727 case OPimContactAccess::WildCards: 727 case OPimContactAccess::WildCards:
728 return ( true ); 728 return ( true );
729 case OPimContactAccess::ExactMatch: 729 case OPimContactAccess::ExactMatch:
730 return ( true ); 730 return ( true );
731 case 0: // one of the upper removed bits were set.. 731 case 0: // one of the upper removed bits were set..
732 return ( true ); 732 return ( true );
733 default: 733 default:
734 return ( false ); 734 return ( false );
735 } 735 }
736 736
737} 737}
738 738
739QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) 739QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int )
740{ 740{
741 QTime t; 741 QTime t;
742 t.start(); 742 t.start();
743 743
744 QString query = "SELECT uid FROM addressbook "; 744 QString query = "SELECT uid FROM addressbook ";
745 query += "ORDER BY \"Last Name\" "; 745 query += "ORDER BY \"Last Name\" ";
746 746
747 if ( !asc ) 747 if ( !asc )
748 query += "DESC"; 748 query += "DESC";
749 749
750 // odebug << "sorted query is: " << query << "" << oendl; 750 // odebug << "sorted query is: " << query << "" << oendl;
751 751
752 OSQLRawQuery raw( query ); 752 OSQLRawQuery raw( query );
753 OSQLResult res = m_driver->query( &raw ); 753 OSQLResult res = m_driver->query( &raw );
754 if ( res.state() != OSQLResult::Success ){ 754 if ( res.state() != OSQLResult::Success ){
755 QArray<int> empty; 755 QArray<int> empty;
756 return empty; 756 return empty;
757 } 757 }
758 758
759 QArray<int> list = extractUids( res ); 759 QArray<int> list = extractUids( res );
760 760
761 odebug << "sorted needed " << t.elapsed() << " ms!" << oendl; 761 odebug << "sorted needed " << t.elapsed() << " ms!" << oendl;
762 return list; 762 return list;
763} 763}
764 764
765 765
766void OPimContactAccessBackend_SQL::update() 766void OPimContactAccessBackend_SQL::update()
767{ 767{
768 odebug << "Update starts" << oendl; 768 odebug << "Update starts" << oendl;
769 QTime t; 769 QTime t;
770 t.start(); 770 t.start();
771 771
772 // Now load the database set and extract the uid's 772 // Now load the database set and extract the uid's
773 // which will be held locally 773 // which will be held locally
774 774
775 LoadQuery lo; 775 LoadQuery lo;
776 OSQLResult res = m_driver->query(&lo); 776 OSQLResult res = m_driver->query(&lo);
777 if ( res.state() != OSQLResult::Success ) 777 if ( res.state() != OSQLResult::Success )
778 return; 778 return;
779 779
780 m_uids = extractUids( res ); 780 m_uids = extractUids( res );
781 781
782 m_changed = false; 782 m_changed = false;
783 783
784 odebug << "Update ends " << t.elapsed() << " ms" << oendl; 784 odebug << "Update ends " << t.elapsed() << " ms" << oendl;
785} 785}
786 786
787QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const 787QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
788{ 788{
789 odebug << "extractUids" << oendl; 789 odebug << "extractUids" << oendl;
790 QTime t; 790 QTime t;
791 t.start(); 791 t.start();
792 OSQLResultItem::ValueList list = res.results(); 792 OSQLResultItem::ValueList list = res.results();
793 OSQLResultItem::ValueList::Iterator it; 793 OSQLResultItem::ValueList::Iterator it;
794 QArray<int> ints(list.count() ); 794 QArray<int> ints(list.count() );
795 odebug << " count = " << list.count() << "" << oendl; 795 odebug << " count = " << list.count() << "" << oendl;
796 796
797 int i = 0; 797 int i = 0;
798 for (it = list.begin(); it != list.end(); ++it ) { 798 for (it = list.begin(); it != list.end(); ++it ) {
799 ints[i] = (*it).data("uid").toInt(); 799 ints[i] = (*it).data("uid").toInt();
800 i++; 800 i++;
801 } 801 }
802 odebug << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl; 802 odebug << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl;
803 803
804 return ints; 804 return ints;
805 805
806} 806}
807 807
808QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const 808QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const
809{ 809{
810 QTime t; 810 QTime t;
811 t.start(); 811 t.start();
812 812
813 int t2needed = 0; 813 int t2needed = 0;
814 int t3needed = 0; 814 int t3needed = 0;
815 QTime t2; 815 QTime t2;
816 t2.start(); 816 t2.start();
817 FindQuery query( uid ); 817 FindQuery query( uid );
818 OSQLResult res_noncustom = m_driver->query( &query ); 818 OSQLResult res_noncustom = m_driver->query( &query );
819 t2needed = t2.elapsed(); 819 t2needed = t2.elapsed();
820 820
821 OSQLResultItem resItem = res_noncustom.first(); 821 OSQLResultItem resItem = res_noncustom.first();
822 822
823 QMap<int, QString> nonCustomMap; 823 QMap<int, QString> nonCustomMap;
824 QTime t3; 824 QTime t3;
825 t3.start(); 825 t3.start();
826 nonCustomMap = fillNonCustomMap( resItem ); 826 nonCustomMap = fillNonCustomMap( resItem );
827 t3needed = t3.elapsed(); 827 t3needed = t3.elapsed();
828 828
829 829
830 // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; 830 // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl;
831 odebug << "RequestNonCustom needed: insg.:" << t.elapsed() << " ms, query: " << t2needed 831 odebug << "RequestNonCustom needed: insg.:" << t.elapsed() << " ms, query: " << t2needed
832 << " ms, mapping: " << t3needed << " ms" << oendl; 832 << " ms, mapping: " << t3needed << " ms" << oendl;
833 833
834 return nonCustomMap; 834 return nonCustomMap;
835} 835}
836 836
837/* Returns contact requested by uid and fills cache with contacts requested by uids in the cachelist */ 837/* Returns contact requested by uid and fills cache with contacts requested by uids in the cachelist */
838OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, const QArray<int>& uidlist )const 838OPimContact OPimContactAccessBackend_SQL::requestContactsAndCache( int uid, const QArray<int>& uidlist )const
839{ 839{
840 // We want to get all contacts with one query. 840 // We want to get all contacts with one query.
841 // We don't have to add the given uid to the uidlist, it is expected to be there already (see opimrecordlist.h). 841 // We don't have to add the given uid to the uidlist, it is expected to be there already (see opimrecordlist.h).
842 // All contacts will be stored in the cache, afterwards the contact with the user id "uid" will be returned 842 // All contacts will be stored in the cache, afterwards the contact with the user id "uid" will be returned
843 // by using the cache.. 843 // by using the cache..
844 QArray<int> cachelist = uidlist; 844 QArray<int> cachelist = uidlist;
845 OPimContact retContact;
845 846
846 odebug << "Reqest and cache" << cachelist.size() << "elements !" << oendl; 847 odebug << "Reqest and cache" << cachelist.size() << "elements !" << oendl;
847 848
848 QTime t; 849 QTime t;
849 t.start(); 850 t.start();
850 851
851 int t2needed = 0; 852 int t2needed = 0;
852 int t3needed = 0; 853 int t3needed = 0;
853 QTime t2; 854 QTime t2;
854 t2.start(); 855 t2.start();
855 FindQuery query( cachelist ); 856 FindQuery query( cachelist );
856 OSQLResult res_noncustom = m_driver->query( &query ); 857 OSQLResult res_noncustom = m_driver->query( &query );
857 t2needed = t2.elapsed(); 858 t2needed = t2.elapsed();
858 859
859 QMap<int, QString> nonCustomMap; 860 QMap<int, QString> nonCustomMap;
860 QTime t3; 861 QTime t3;
861 t3.start(); 862 t3.start();
862 OSQLResultItem resItem = res_noncustom.first(); 863 OSQLResultItem resItem = res_noncustom.first();
863 do { 864 do {
864 OPimContact contact( fillNonCustomMap( resItem ) ); 865 OPimContact contact( fillNonCustomMap( resItem ) );
865 contact.setExtraMap( requestCustom( contact.uid() ) ); 866 contact.setExtraMap( requestCustom( contact.uid() ) );
866 odebug << "Caching uid: " << contact.uid() << oendl; 867 odebug << "Caching uid: " << contact.uid() << oendl;
867 cache( contact ); 868 cache( contact );
869 if ( contact.uid() == uid )
870 retContact = contact;
868 resItem = res_noncustom.next(); 871 resItem = res_noncustom.next();
869 } while ( ! res_noncustom.atEnd() ); //atEnd() is true if we are past(!) the list !! 872 } while ( ! res_noncustom.atEnd() ); //atEnd() is true if we are past(!) the list !!
870 t3needed = t3.elapsed(); 873 t3needed = t3.elapsed();
871 874
872 875
873 // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; 876 // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl;
874 odebug << "RequestContactsAndCache needed: insg.:" << t.elapsed() << " ms, query: " << t2needed 877 odebug << "RequestContactsAndCache needed: insg.:" << t.elapsed() << " ms, query: " << t2needed
875 << " ms, mapping: " << t3needed << " ms" << oendl; 878 << " ms, mapping: " << t3needed << " ms" << oendl;
876 879
877 return cacheFind( uid ); 880 return retContact;
878} 881}
879 882
880QMap<int, QString> OPimContactAccessBackend_SQL::fillNonCustomMap( const OSQLResultItem& resultItem ) const 883QMap<int, QString> OPimContactAccessBackend_SQL::fillNonCustomMap( const OSQLResultItem& resultItem ) const
881{ 884{
882 QMap<int, QString> nonCustomMap; 885 QMap<int, QString> nonCustomMap;
883 886
884 // Now loop through all columns 887 // Now loop through all columns
885 QStringList fieldList = OPimContactFields::untrfields( false ); 888 QStringList fieldList = OPimContactFields::untrfields( false );
886 QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 889 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
887 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 890 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
888 // Get data for the selected column and store it with the 891 // Get data for the selected column and store it with the
889 // corresponding id into the map.. 892 // corresponding id into the map..
890 893
891 int id = translate[*it]; 894 int id = translate[*it];
892 QString value = resultItem.data( (*it) ); 895 QString value = resultItem.data( (*it) );
893 896
894 // odebug << "Reading " << (*it) << "... found: " << value << "" << oendl; 897 // odebug << "Reading " << (*it) << "... found: " << value << "" << oendl;
895 898
896 switch( id ){ 899 switch( id ){
897 case Qtopia::Birthday: 900 case Qtopia::Birthday:
898 case Qtopia::Anniversary:{ 901 case Qtopia::Anniversary:{
899 // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) 902 // Birthday and Anniversary are encoded special ( yyyy-mm-dd )
900 QStringList list = QStringList::split( '-', value ); 903 QStringList list = QStringList::split( '-', value );
901 QStringList::Iterator lit = list.begin(); 904 QStringList::Iterator lit = list.begin();
902 int year = (*lit).toInt(); 905 int year = (*lit).toInt();
903 int month = (*(++lit)).toInt(); 906 int month = (*(++lit)).toInt();
904 int day = (*(++lit)).toInt(); 907 int day = (*(++lit)).toInt();
905 if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ 908 if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){
906 QDate date( year, month, day ); 909 QDate date( year, month, day );
907 nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); 910 nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) );
908 } 911 }
909 } 912 }
910 break; 913 break;
911 case Qtopia::AddressCategory: 914 case Qtopia::AddressCategory:
912 odebug << "Category is: " << value << "" << oendl; 915 odebug << "Category is: " << value << "" << oendl;
913 default: 916 default:
914 nonCustomMap.insert( id, value ); 917 nonCustomMap.insert( id, value );
915 } 918 }
916 } 919 }
917 920
918 nonCustomMap.insert( Qtopia::AddressUid, resultItem.data( "uid" ) ); 921 nonCustomMap.insert( Qtopia::AddressUid, resultItem.data( "uid" ) );
919 922
920 return nonCustomMap; 923 return nonCustomMap;
921} 924}
922 925
923 926
924QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const 927QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const
925{ 928{
926 QTime t; 929 QTime t;
927 t.start(); 930 t.start();
928 931
929 QMap<QString, QString> customMap; 932 QMap<QString, QString> customMap;
930 933
931 FindCustomQuery query( uid ); 934 FindCustomQuery query( uid );
932 OSQLResult res_custom = m_driver->query( &query ); 935 OSQLResult res_custom = m_driver->query( &query );
933 936
934 if ( res_custom.state() == OSQLResult::Failure ) { 937 if ( res_custom.state() == OSQLResult::Failure ) {
935 owarn << "OSQLResult::Failure in find query !!" << oendl; 938 owarn << "OSQLResult::Failure in find query !!" << oendl;
936 QMap<QString, QString> empty; 939 QMap<QString, QString> empty;
937 return empty; 940 return empty;
938 } 941 }
939 942
940 OSQLResultItem::ValueList list = res_custom.results(); 943 OSQLResultItem::ValueList list = res_custom.results();
941 OSQLResultItem::ValueList::Iterator it = list.begin(); 944 OSQLResultItem::ValueList::Iterator it = list.begin();
942 for ( ; it != list.end(); ++it ) { 945 for ( ; it != list.end(); ++it ) {
943 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 946 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
944 } 947 }
945 948
946 odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl; 949 odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl;
947 return customMap; 950 return customMap;
948} 951}
949 952
950} 953}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
index 4f81735..28d9746 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h
@@ -1,114 +1,114 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) 3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29/* 29/*
30 * SQL Backend for the OPIE-Contact Database. 30 * SQL Backend for the OPIE-Contact Database.
31 */ 31 */
32 32
33#ifndef _OPimContactAccessBackend_SQL_ 33#ifndef _OPimContactAccessBackend_SQL_
34#define _OPimContactAccessBackend_SQL_ 34#define _OPimContactAccessBackend_SQL_
35 35
36#include <opie2/ocontactaccessbackend.h> 36#include <opie2/ocontactaccessbackend.h>
37#include <opie2/ocontactaccess.h> 37#include <opie2/ocontactaccess.h>
38 38
39#include <qlist.h> 39#include <qlist.h>
40#include <qdict.h> 40#include <qdict.h>
41 41
42/* aren't in namespace Opie yet - alwin */ 42/* aren't in namespace Opie yet - alwin */
43namespace Opie { 43namespace Opie {
44namespace DB { 44namespace DB {
45class OSQLDriver; 45class OSQLDriver;
46class OSQLResult; 46class OSQLResult;
47class OSQLResultItem; 47class OSQLResultItem;
48} 48}
49} 49}
50 50
51namespace Opie { 51namespace Opie {
52 52
53/* the default xml implementation */ 53/* the default xml implementation */
54/** 54/**
55 * This class is the SQL implementation of a Contact backend 55 * This class is the SQL implementation of a Contact backend
56 * it does implement everything available for OPimContact. 56 * it does implement everything available for OPimContact.
57 * @see OPimAccessBackend for more information of available methods 57 * @see OPimAccessBackend for more information of available methods
58 */ 58 */
59class OPimContactAccessBackend_SQL : public OPimContactAccessBackend { 59class OPimContactAccessBackend_SQL : public OPimContactAccessBackend {
60 public: 60 public:
61 OPimContactAccessBackend_SQL ( const QString& appname, const QString& filename = QString::null ); 61 OPimContactAccessBackend_SQL ( const QString& appname, const QString& filename = QString::null );
62 62
63 ~OPimContactAccessBackend_SQL (); 63 ~OPimContactAccessBackend_SQL ();
64 64
65 bool save(); 65 bool save();
66 66
67 bool load (); 67 bool load ();
68 68
69 void clear (); 69 void clear ();
70 70
71 bool wasChangedExternally(); 71 bool wasChangedExternally();
72 72
73 QArray<int> allRecords() const; 73 QArray<int> allRecords() const;
74 74
75 OPimContact find ( int uid ) const; 75 OPimContact find( int uid ) const;
76 OPimContact find( int uid, const QArray<int>&, uint cur, Frontend::CacheDirection ) const; 76 OPimContact find( int uid, const QArray<int>& items, uint cur, Frontend::CacheDirection ) const;
77 77
78 QArray<int> queryByExample ( const OPimContact &query, int settings, 78 QArray<int> queryByExample ( const OPimContact &query, int settings,
79 const QDateTime& d ); 79 const QDateTime& d );
80 80
81 QArray<int> matchRegexp( const QRegExp &r ) const; 81 QArray<int> matchRegexp( const QRegExp &r ) const;
82 82
83 const uint querySettings(); 83 const uint querySettings();
84 84
85 bool hasQuerySettings (uint querySettings) const; 85 bool hasQuerySettings (uint querySettings) const;
86 86
87 // Currently only asc implemented.. 87 // Currently only asc implemented..
88 QArray<int> sorted( bool asc, int , int , int ); 88 QArray<int> sorted( bool asc, int , int , int );
89 bool add ( const OPimContact &newcontact ); 89 bool add ( const OPimContact &newcontact );
90 90
91 bool replace ( const OPimContact &contact ); 91 bool replace ( const OPimContact &contact );
92 92
93 bool remove ( int uid ); 93 bool remove ( int uid );
94 bool reload(); 94 bool reload();
95 95
96 private: 96 private:
97 QArray<int> extractUids( Opie::DB::OSQLResult& res ) const; 97 QArray<int> extractUids( Opie::DB::OSQLResult& res ) const;
98 QMap<int, QString> requestNonCustom( int uid ) const; 98 QMap<int, QString> requestNonCustom( int uid ) const;
99 QMap<QString, QString> requestCustom( int uid ) const; 99 QMap<QString, QString> requestCustom( int uid ) const;
100 QMap<int, QString> fillNonCustomMap( const Opie::DB::OSQLResultItem& resultItem ) const; 100 QMap<int, QString> fillNonCustomMap( const Opie::DB::OSQLResultItem& resultItem ) const;
101 OPimContact requestContactsAndCache( int uid, const QArray<int>& cachelist ) const; 101 OPimContact requestContactsAndCache( int uid, const QArray<int>& cachelist ) const;
102 void update(); 102 void update();
103 103
104 protected: 104 protected:
105 bool m_changed; 105 bool m_changed;
106 QString m_fileName; 106 QString m_fileName;
107 QArray<int> m_uids; 107 QArray<int> m_uids;
108 108
109 Opie::DB::OSQLDriver* m_driver; 109 Opie::DB::OSQLDriver* m_driver;
110}; 110};
111 111
112} 112}
113 113
114#endif 114#endif
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h
index 15a7b7f..26af762 100644
--- a/libopie2/opiepim/backend/opimaccessbackend.h
+++ b/libopie2/opiepim/backend/opimaccessbackend.h
@@ -1,212 +1,196 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OPIE_PIM_ACCESS_BACKEND 29#ifndef OPIE_PIM_ACCESS_BACKEND
30#define OPIE_PIM_ACCESS_BACKEND 30#define OPIE_PIM_ACCESS_BACKEND
31 31
32#include <qarray.h> 32#include <qarray.h>
33#include <qdatetime.h> 33#include <qdatetime.h>
34 34
35#include <opie2/opimtemplatebase.h> 35#include <opie2/opimtemplatebase.h>
36#include <opie2/opimrecord.h> 36#include <opie2/opimrecord.h>
37 37
38 38
39namespace Opie { 39namespace Opie {
40class OPimAccessBackendPrivate; 40class OPimAccessBackendPrivate;
41/** 41/**
42 * OPimAccessBackend is the base class 42 * OPimAccessBackend is the base class
43 * for all private backends 43 * for all private backends
44 * it operates on OPimRecord as the base class 44 * it operates on OPimRecord as the base class
45 * and it's responsible for fast manipulating 45 * and it's responsible for fast manipulating
46 * the resource the implementation takes care 46 * the resource the implementation takes care
47 * of 47 * of
48 */ 48 */
49template <class T = OPimRecord> 49template <class T = OPimRecord>
50class OPimAccessBackend { 50class OPimAccessBackend {
51public: 51public:
52 typedef OTemplateBase<T> Frontend; 52 typedef OTemplateBase<T> Frontend;
53 53
54 /** The access hint from the frontend */ 54 /** The access hint from the frontend */
55 OPimAccessBackend(int access = 0); 55 OPimAccessBackend(int access = 0);
56 virtual ~OPimAccessBackend(); 56 virtual ~OPimAccessBackend();
57 57
58 /** 58 /**
59 * load the resource 59 * load the resource
60 */ 60 */
61 virtual bool load() = 0; 61 virtual bool load() = 0;
62 62
63 /** 63 /**
64 * reload the resource 64 * reload the resource
65 */ 65 */
66 virtual bool reload() = 0; 66 virtual bool reload() = 0;
67 67
68 /** 68 /**
69 * save the resource and 69 * save the resource and
70 * all it's changes 70 * all it's changes
71 */ 71 */
72 virtual bool save() = 0; 72 virtual bool save() = 0;
73 73
74 /** 74 /**
75 * return an array of 75 * return an array of
76 * all available uids 76 * all available uids
77 */ 77 */
78 virtual QArray<int> allRecords()const = 0; 78 virtual QArray<int> allRecords()const = 0;
79 79
80 /** 80 /**
81 * return a List of records 81 * return a List of records
82 * that match the regex 82 * that match the regex
83 */ 83 */
84 virtual QArray<int> matchRegexp(const QRegExp &r) const = 0; 84 virtual QArray<int> matchRegexp(const QRegExp &r) const = 0;
85 85
86 /** 86 /**
87 * queryByExample for T with the given Settings 87 * queryByExample for T with the given Settings
88 * 88 *
89 */ 89 */
90 virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0; 90 virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0;
91 91
92 /** 92 /**
93 * find the OPimRecord with uid @param uid 93 * find the OPimRecord with uid @param uid
94 * returns T and T.isEmpty() if nothing was found 94 * returns T and T.isEmpty() if nothing was found
95 */ 95 */
96 virtual T find(int uid )const = 0; 96 virtual T find( int uid )const = 0;
97 97
98 virtual T find(int uid, const QArray<int>& items, 98 virtual T find( int uid, const QArray<int>& items,
99 uint current, typename Frontend::CacheDirection ) const; 99 uint current, typename Frontend::CacheDirection ) const;
100 /** 100 /**
101 * clear the back end 101 * clear the back end
102 */ 102 */
103 virtual void clear() = 0; 103 virtual void clear() = 0;
104 104
105 /** 105 /**
106 * add T 106 * add T
107 */ 107 */
108 virtual bool add( const T& t ) = 0; 108 virtual bool add( const T& t ) = 0;
109 109
110 /** 110 /**
111 * remove 111 * remove
112 */ 112 */
113 virtual bool remove( int uid ) = 0; 113 virtual bool remove( int uid ) = 0;
114 114
115 /** 115 /**
116 * replace a record with T.uid() 116 * replace a record with T.uid()
117 */ 117 */
118 virtual bool replace( const T& t ) = 0; 118 virtual bool replace( const T& t ) = 0;
119 119
120 /* 120 /*
121 * setTheFrontEnd!!! 121 * setTheFrontEnd!!!
122 */ 122 */
123 void setFrontend( Frontend* front ); 123 void setFrontend( Frontend* front );
124 124
125 /** 125 /**
126 * set the read ahead count 126 * set the read ahead count
127 */ 127 */
128 void setReadAhead( uint count ); 128 void setReadAhead( uint count );
129protected: 129protected:
130 int access()const; 130 int access()const;
131 131
132 void cache( const T& t )const; 132 void cache( const T& t )const;
133 133
134 /**
135 * Returns the element with given uid out of the cache.
136 * Returns empty element if nothing was found.
137 * <b>Attention:</b> This just works if we have a frontend which contains the cache !
138 */
139 T cacheFind( int uid ) const;
140
141 /** 134 /**
142 * use a prime number here! 135 * use a prime number here!
143 */ 136 */
144 void setSaneCacheSize( int ); 137 void setSaneCacheSize( int );
145 138
146 uint readAhead()const; 139 uint readAhead()const;
147 140
148private: 141private:
149 OPimAccessBackendPrivate *d; 142 OPimAccessBackendPrivate *d;
150 Frontend* m_front; 143 Frontend* m_front;
151 uint m_read; 144 uint m_read;
152 int m_acc; 145 int m_acc;
153 146
154}; 147};
155 148
156template <class T> 149template <class T>
157OPimAccessBackend<T>::OPimAccessBackend(int acc) 150OPimAccessBackend<T>::OPimAccessBackend(int acc)
158 : m_acc( acc ) 151 : m_acc( acc )
159{ 152{
160 m_front = 0l; 153 m_front = 0l;
161} 154}
162template <class T> 155template <class T>
163OPimAccessBackend<T>::~OPimAccessBackend() { 156OPimAccessBackend<T>::~OPimAccessBackend() {
164 157
165} 158}
166template <class T> 159template <class T>
167void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { 160void OPimAccessBackend<T>::setFrontend( Frontend* fr ) {
168 m_front = fr; 161 m_front = fr;
169} 162}
170template <class T> 163template <class T>
171void OPimAccessBackend<T>::cache( const T& t )const { 164void OPimAccessBackend<T>::cache( const T& t )const {
172 if ( m_front ) 165 if ( m_front )
173 m_front->cache( t ); 166 m_front->cache( t );
174} 167}
175 168
176template <class T>
177T OPimAccessBackend<T>::cacheFind( int uid )const {
178 if ( ! m_front ){
179 qWarning ( "No frontend assigned ! Therefore we cannot access the cache to return the right element!" );
180 return T();
181 }
182
183 return m_front->cacheFind( uid );
184}
185 169
186template <class T> 170template <class T>
187void OPimAccessBackend<T>::setSaneCacheSize( int size) { 171void OPimAccessBackend<T>::setSaneCacheSize( int size) {
188 if ( m_front ) 172 if ( m_front )
189 m_front->setSaneCacheSize( size ); 173 m_front->setSaneCacheSize( size );
190} 174}
191template <class T> 175template <class T>
192T OPimAccessBackend<T>::find( int uid, const QArray<int>&, 176T OPimAccessBackend<T>::find( int uid, const QArray<int>&,
193 uint, typename Frontend::CacheDirection ) const{ 177 uint, typename Frontend::CacheDirection ) const{
194 qDebug( "*** Lookahead feature not supported. Fallback to default find!" ); 178 qDebug( "*** Lookahead feature not supported. Fallback to default find!!" );
195 return find( uid ); 179 return find( uid );
196} 180}
197template <class T> 181template <class T>
198void OPimAccessBackend<T>::setReadAhead( uint count ) { 182void OPimAccessBackend<T>::setReadAhead( uint count ) {
199 m_read = count; 183 m_read = count;
200} 184}
201template <class T> 185template <class T>
202uint OPimAccessBackend<T>::readAhead()const { 186uint OPimAccessBackend<T>::readAhead()const {
203 return m_read; 187 return m_read;
204} 188}
205template <class T> 189template <class T>
206int OPimAccessBackend<T>::access()const { 190int OPimAccessBackend<T>::access()const {
207 return m_acc; 191 return m_acc;
208} 192}
209 193
210} 194}
211 195
212#endif 196#endif
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index 12a8bea..4e3e47b 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -201,689 +201,695 @@ namespace {
201 : OSQLQuery(), m_todo( todo ) { 201 : OSQLQuery(), m_todo( todo ) {
202 } 202 }
203 InsertQuery::~InsertQuery() { 203 InsertQuery::~InsertQuery() {
204 } 204 }
205 /* 205 /*
206 * converts from a OPimTodo to a query 206 * converts from a OPimTodo to a query
207 * we leave out X-Ref + Maintainer 207 * we leave out X-Ref + Maintainer
208 * FIXME: Implement/Finish toMap()/fromMap() into OpimTodo to move the encoding 208 * FIXME: Implement/Finish toMap()/fromMap() into OpimTodo to move the encoding
209 * decoding stuff there.. (eilers) 209 * decoding stuff there.. (eilers)
210 */ 210 */
211 QString InsertQuery::query()const{ 211 QString InsertQuery::query()const{
212 212
213 int year, month, day; 213 int year, month, day;
214 year = month = day = 0; 214 year = month = day = 0;
215 if (m_todo.hasDueDate() ) { 215 if (m_todo.hasDueDate() ) {
216 QDate date = m_todo.dueDate(); 216 QDate date = m_todo.dueDate();
217 year = date.year(); 217 year = date.year();
218 month = date.month(); 218 month = date.month();
219 day = date.day(); 219 day = date.day();
220 } 220 }
221 int sYear = 0, sMonth = 0, sDay = 0; 221 int sYear = 0, sMonth = 0, sDay = 0;
222 if( m_todo.hasStartDate() ){ 222 if( m_todo.hasStartDate() ){
223 QDate sDate = m_todo.startDate(); 223 QDate sDate = m_todo.startDate();
224 sYear = sDate.year(); 224 sYear = sDate.year();
225 sMonth= sDate.month(); 225 sMonth= sDate.month();
226 sDay = sDate.day(); 226 sDay = sDate.day();
227 } 227 }
228 228
229 int eYear = 0, eMonth = 0, eDay = 0; 229 int eYear = 0, eMonth = 0, eDay = 0;
230 if( m_todo.hasCompletedDate() ){ 230 if( m_todo.hasCompletedDate() ){
231 QDate eDate = m_todo.completedDate(); 231 QDate eDate = m_todo.completedDate();
232 eYear = eDate.year(); 232 eYear = eDate.year();
233 eMonth= eDate.month(); 233 eMonth= eDate.month();
234 eDay = eDate.day(); 234 eDay = eDate.day();
235 } 235 }
236 QString qu; 236 QString qu;
237 QMap<int, QString> recMap = m_todo.recurrence().toMap(); 237 QMap<int, QString> recMap = m_todo.recurrence().toMap();
238 qu = "insert into todolist VALUES(" 238 qu = "insert into todolist VALUES("
239 + QString::number( m_todo.uid() ) + "," 239 + QString::number( m_todo.uid() ) + ","
240 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," 240 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + ","
241 + QString::number( m_todo.isCompleted() ) + "," 241 + QString::number( m_todo.isCompleted() ) + ","
242 + "'" + m_todo.description() + "'" + "," 242 + "'" + m_todo.description() + "'" + ","
243 + "'" + m_todo.summary() + "'" + "," 243 + "'" + m_todo.summary() + "'" + ","
244 + QString::number(m_todo.priority() ) + "," 244 + QString::number(m_todo.priority() ) + ","
245 + "'" + QString::number(year).rightJustify( 4, '0' ) + "-" 245 + "'" + QString::number(year).rightJustify( 4, '0' ) + "-"
246 + QString::number(month).rightJustify( 2, '0' ) 246 + QString::number(month).rightJustify( 2, '0' )
247 + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + "," 247 + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + ","
248 + QString::number( m_todo.progress() ) + "," 248 + QString::number( m_todo.progress() ) + ","
249 + QString::number( m_todo.state().state() ) + "," 249 + QString::number( m_todo.state().state() ) + ","
250 + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," 250 + "'" + recMap[ OPimRecurrence::RType ] + "'" + ","
251 + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," 251 + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + ","
252 + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," 252 + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + ","
253 + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," 253 + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + ","
254 + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," 254 + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + ","
255 + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," 255 + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + ","
256 + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," 256 + "'" + recMap[ OPimRecurrence::Created ] + "'" + ","
257 + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; 257 + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ",";
258 258
259 if ( m_todo.hasNotifiers() ) { 259 if ( m_todo.hasNotifiers() ) {
260 OPimNotifyManager manager = m_todo.notifiers(); 260 OPimNotifyManager manager = m_todo.notifiers();
261 qu += "'" + manager.remindersToString() + "'" + "," 261 qu += "'" + manager.remindersToString() + "'" + ","
262 + "'" + manager.alarmsToString() + "'" + ","; 262 + "'" + manager.alarmsToString() + "'" + ",";
263 } 263 }
264 else{ 264 else{
265 qu += QString( "''" ) + "," 265 qu += QString( "''" ) + ","
266 + "''" + ","; 266 + "''" + ",";
267 } 267 }
268 268
269 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) 269 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !)
270 + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" 270 + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-"
271 + QString::number(sMonth).rightJustify( 2, '0' ) 271 + QString::number(sMonth).rightJustify( 2, '0' )
272 + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," 272 + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + ","
273 + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" 273 + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-"
274 + QString::number(eMonth).rightJustify( 2, '0' ) 274 + QString::number(eMonth).rightJustify( 2, '0' )
275 + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" 275 + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'"
276 + "); "; 276 + "); ";
277 277
278 // Save custom Entries: 278 // Save custom Entries:
279 int id = 0; 279 int id = 0;
280 id = 0; 280 id = 0;
281 QMap<QString, QString> customMap = m_todo.toExtraMap(); 281 QMap<QString, QString> customMap = m_todo.toExtraMap();
282 for( QMap<QString, QString>::Iterator it = customMap.begin(); 282 for( QMap<QString, QString>::Iterator it = customMap.begin();
283 it != customMap.end(); ++it ){ 283 it != customMap.end(); ++it ){
284 qu += "insert into custom_data VALUES(" 284 qu += "insert into custom_data VALUES("
285 + QString::number( m_todo.uid() ) 285 + QString::number( m_todo.uid() )
286 + "," 286 + ","
287 + QString::number( id++ ) 287 + QString::number( id++ )
288 + ",'" 288 + ",'"
289 + it.key() 289 + it.key()
290 + "'," 290 + "',"
291 + "0" // Priority for future enhancements 291 + "0" // Priority for future enhancements
292 + ",'" 292 + ",'"
293 + it.data() 293 + it.data()
294 + "');"; 294 + "');";
295 } 295 }
296 296
297 297
298 odebug << "add " << qu << "" << oendl; 298 odebug << "add " << qu << "" << oendl;
299 return qu; 299 return qu;
300 } 300 }
301 301
302 RemoveQuery::RemoveQuery(int uid ) 302 RemoveQuery::RemoveQuery(int uid )
303 : OSQLQuery(), m_uid( uid ) {} 303 : OSQLQuery(), m_uid( uid ) {}
304 RemoveQuery::~RemoveQuery() {} 304 RemoveQuery::~RemoveQuery() {}
305 QString RemoveQuery::query()const { 305 QString RemoveQuery::query()const {
306 QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;"; 306 QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;";
307 qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid); 307 qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid);
308 return qu; 308 return qu;
309 } 309 }
310 310
311 311
312 ClearQuery::ClearQuery() 312 ClearQuery::ClearQuery()
313 : OSQLQuery() {} 313 : OSQLQuery() {}
314 ClearQuery::~ClearQuery() {} 314 ClearQuery::~ClearQuery() {}
315 QString ClearQuery::query()const { 315 QString ClearQuery::query()const {
316 QString qu = "drop table todolist"; 316 QString qu = "drop table todolist";
317 return qu; 317 return qu;
318 } 318 }
319 FindQuery::FindQuery(int uid) 319 FindQuery::FindQuery(int uid)
320 : OSQLQuery(), m_uid(uid ) { 320 : OSQLQuery(), m_uid(uid ) {
321 } 321 }
322 FindQuery::FindQuery(const QArray<int>& ints) 322 FindQuery::FindQuery(const QArray<int>& ints)
323 : OSQLQuery(), m_uids(ints){ 323 : OSQLQuery(), m_uids(ints){
324 } 324 }
325 FindQuery::~FindQuery() { 325 FindQuery::~FindQuery() {
326 } 326 }
327 QString FindQuery::query()const{ 327 QString FindQuery::query()const{
328 if (m_uids.count() == 0 ) 328 if (m_uids.count() == 0 )
329 return single(); 329 return single();
330 else 330 else
331 return multi(); 331 return multi();
332 } 332 }
333 QString FindQuery::single()const{ 333 QString FindQuery::single()const{
334 QString qu = "select * from todolist where uid = " + QString::number(m_uid); 334 QString qu = "select * from todolist where uid = " + QString::number(m_uid);
335 return qu; 335 return qu;
336 } 336 }
337 QString FindQuery::multi()const { 337 QString FindQuery::multi()const {
338 QString qu = "select * from todolist where "; 338 QString qu = "select * from todolist where ";
339 for (uint i = 0; i < m_uids.count(); i++ ) { 339 for (uint i = 0; i < m_uids.count(); i++ ) {
340 qu += " UID = " + QString::number( m_uids[i] ) + " OR"; 340 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
341 } 341 }
342 qu.remove( qu.length()-2, 2 ); 342 qu.remove( qu.length()-2, 2 );
343 return qu; 343 return qu;
344 } 344 }
345 345
346 OverDueQuery::OverDueQuery(): OSQLQuery() {} 346 OverDueQuery::OverDueQuery(): OSQLQuery() {}
347 OverDueQuery::~OverDueQuery() {} 347 OverDueQuery::~OverDueQuery() {}
348 QString OverDueQuery::query()const { 348 QString OverDueQuery::query()const {
349 QDate date = QDate::currentDate(); 349 QDate date = QDate::currentDate();
350 QString str; 350 QString str;
351 str = QString("select uid from todolist where DueDate ='%1-%2-%3'") 351 str = QString("select uid from todolist where DueDate ='%1-%2-%3'")
352 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) 352 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
353 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) 353 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
354 .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) ); 354 .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) );
355 355
356 return str; 356 return str;
357 } 357 }
358 358
359 359
360 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) 360 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc )
361 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} 361 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {}
362 EffQuery::~EffQuery() {} 362 EffQuery::~EffQuery() {}
363 QString EffQuery::query()const { 363 QString EffQuery::query()const {
364 return m_inc ? with() : out(); 364 return m_inc ? with() : out();
365 } 365 }
366 QString EffQuery::with()const { 366 QString EffQuery::with()const {
367 QString str; 367 QString str;
368 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") 368 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ")
369 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) 369 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) )
370 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) 370 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) )
371 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) 371 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) )
372 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) 372 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) )
373 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) 373 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) )
374 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); 374 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) );
375 return str; 375 return str;
376 } 376 }
377 QString EffQuery::out()const { 377 QString EffQuery::out()const {
378 QString str; 378 QString str;
379 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") 379 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'")
380 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) 380 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) )
381 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) 381 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) )
382 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) 382 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) )
383 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) 383 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) )
384 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) 384 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) )
385 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); 385 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) );
386 386
387 return str; 387 return str;
388 } 388 }
389 389
390 FindCustomQuery::FindCustomQuery(int uid) 390 FindCustomQuery::FindCustomQuery(int uid)
391 : OSQLQuery(), m_uid( uid ) { 391 : OSQLQuery(), m_uid( uid ) {
392 } 392 }
393 FindCustomQuery::FindCustomQuery(const QArray<int>& ints) 393 FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
394 : OSQLQuery(), m_uids( ints ){ 394 : OSQLQuery(), m_uids( ints ){
395 } 395 }
396 FindCustomQuery::~FindCustomQuery() { 396 FindCustomQuery::~FindCustomQuery() {
397 } 397 }
398 QString FindCustomQuery::query()const{ 398 QString FindCustomQuery::query()const{
399 return single(); // Multiple requests not supported ! 399 return single(); // Multiple requests not supported !
400 } 400 }
401 QString FindCustomQuery::single()const{ 401 QString FindCustomQuery::single()const{
402 QString qu = "select uid, type, value from custom_data where uid = "; 402 QString qu = "select uid, type, value from custom_data where uid = ";
403 qu += QString::number(m_uid); 403 qu += QString::number(m_uid);
404 return qu; 404 return qu;
405 } 405 }
406 406
407}; 407};
408 408
409 409
410namespace Opie { 410namespace Opie {
411OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) 411OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file )
412 : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true) 412 : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true)
413{ 413{
414 QString fi = file; 414 QString fi = file;
415 if ( fi.isEmpty() ) 415 if ( fi.isEmpty() )
416 fi = Global::applicationFileName( "todolist", "todolist.db" ); 416 fi = Global::applicationFileName( "todolist", "todolist.db" );
417 OSQLManager man; 417 OSQLManager man;
418 m_driver = man.standard(); 418 m_driver = man.standard();
419 m_driver->setUrl(fi); 419 m_driver->setUrl(fi);
420 // fillDict(); 420 // fillDict();
421} 421}
422 422
423OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){ 423OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){
424 if( m_driver ) 424 if( m_driver )
425 delete m_driver; 425 delete m_driver;
426} 426}
427 427
428bool OPimTodoAccessBackendSQL::load(){ 428bool OPimTodoAccessBackendSQL::load(){
429 if (!m_driver->open() ) 429 if (!m_driver->open() )
430 return false; 430 return false;
431 431
432 CreateQuery creat; 432 CreateQuery creat;
433 OSQLResult res = m_driver->query(&creat ); 433 OSQLResult res = m_driver->query(&creat );
434 434
435 m_dirty = true; 435 m_dirty = true;
436 return true; 436 return true;
437} 437}
438bool OPimTodoAccessBackendSQL::reload(){ 438bool OPimTodoAccessBackendSQL::reload(){
439 return load(); 439 return load();
440} 440}
441 441
442bool OPimTodoAccessBackendSQL::save(){ 442bool OPimTodoAccessBackendSQL::save(){
443 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) 443 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
444} 444}
445QArray<int> OPimTodoAccessBackendSQL::allRecords()const { 445QArray<int> OPimTodoAccessBackendSQL::allRecords()const {
446 if (m_dirty ) 446 if (m_dirty )
447 update(); 447 update();
448 448
449 return m_uids; 449 return m_uids;
450} 450}
451QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){ 451QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){
452 QArray<int> ints(0); 452 QArray<int> ints(0);
453 return ints; 453 return ints;
454} 454}
455OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ 455OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{
456 FindQuery query( uid ); 456 FindQuery query( uid );
457 return todo( m_driver->query(&query) ); 457 return parseResultAndCache( uid, m_driver->query(&query) );
458 458
459} 459}
460 460
461// Remember: uid is already in the list of uids, called ints ! 461// Remember: uid is already in the list of uids, called ints !
462OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, 462OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
463 uint cur, Frontend::CacheDirection dir ) const{ 463 uint cur, Frontend::CacheDirection dir ) const{
464 uint CACHE = readAhead(); 464 uint CACHE = readAhead();
465 odebug << "searching for " << uid << "" << oendl; 465 odebug << "searching for " << uid << "" << oendl;
466 QArray<int> search( CACHE ); 466 QArray<int> search( CACHE );
467 uint size =0; 467 uint size =0;
468 OPimTodo to; 468 OPimTodo to;
469 469
470 // we try to cache CACHE items 470 // we try to cache CACHE items
471 switch( dir ) { 471 switch( dir ) {
472 /* forward */ 472 /* forward */
473 case Frontend::Forward: 473 case Frontend::Forward:
474 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { 474 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
475 odebug << "size " << size << " " << ints[i] << "" << oendl; 475 odebug << "size " << size << " " << ints[i] << "" << oendl;
476 search[size] = ints[i]; 476 search[size] = ints[i];
477 size++; 477 size++;
478 } 478 }
479 break; 479 break;
480 /* reverse */ 480 /* reverse */
481 case Frontend::Reverse: 481 case Frontend::Reverse:
482 for (uint i = cur; i != 0 && size < CACHE; i-- ) { 482 for (uint i = cur; i != 0 && size < CACHE; i-- ) {
483 search[size] = ints[i]; 483 search[size] = ints[i];
484 size++; 484 size++;
485 } 485 }
486 break; 486 break;
487 } 487 }
488 488
489 search.resize( size ); 489 search.resize( size );
490 FindQuery query( search ); 490 FindQuery query( search );
491 OSQLResult res = m_driver->query( &query ); 491 OSQLResult res = m_driver->query( &query );
492 if ( res.state() != OSQLResult::Success ) 492 if ( res.state() != OSQLResult::Success )
493 return to; 493 return to;
494 494
495 todo( res ); //FIXME: Don't like polymorphism here. It makes the code hard to read here..(eilers) 495 return parseResultAndCache( uid, res );
496 return cacheFind( uid );
497} 496}
498 497
499void OPimTodoAccessBackendSQL::clear() { 498void OPimTodoAccessBackendSQL::clear() {
500 ClearQuery cle; 499 ClearQuery cle;
501 OSQLResult res = m_driver->query( &cle ); 500 OSQLResult res = m_driver->query( &cle );
502 CreateQuery qu; 501 CreateQuery qu;
503 res = m_driver->query(&qu); 502 res = m_driver->query(&qu);
504} 503}
505bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { 504bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) {
506 InsertQuery ins( t ); 505 InsertQuery ins( t );
507 OSQLResult res = m_driver->query( &ins ); 506 OSQLResult res = m_driver->query( &ins );
508 507
509 if ( res.state() == OSQLResult::Failure ) 508 if ( res.state() == OSQLResult::Failure )
510 return false; 509 return false;
511 int c = m_uids.count(); 510 int c = m_uids.count();
512 m_uids.resize( c+1 ); 511 m_uids.resize( c+1 );
513 m_uids[c] = t.uid(); 512 m_uids[c] = t.uid();
514 513
515 return true; 514 return true;
516} 515}
517bool OPimTodoAccessBackendSQL::remove( int uid ) { 516bool OPimTodoAccessBackendSQL::remove( int uid ) {
518 RemoveQuery rem( uid ); 517 RemoveQuery rem( uid );
519 OSQLResult res = m_driver->query(&rem ); 518 OSQLResult res = m_driver->query(&rem );
520 519
521 if ( res.state() == OSQLResult::Failure ) 520 if ( res.state() == OSQLResult::Failure )
522 return false; 521 return false;
523 522
524 m_dirty = true; 523 m_dirty = true;
525 return true; 524 return true;
526} 525}
527/* 526/*
528 * FIXME better set query 527 * FIXME better set query
529 * but we need the cache for that 528 * but we need the cache for that
530 * now we remove 529 * now we remove
531 */ 530 */
532bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) { 531bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) {
533 remove( t.uid() ); 532 remove( t.uid() );
534 bool b= add(t); 533 bool b= add(t);
535 m_dirty = false; // we changed some stuff but the UID stayed the same 534 m_dirty = false; // we changed some stuff but the UID stayed the same
536 return b; 535 return b;
537} 536}
538QArray<int> OPimTodoAccessBackendSQL::overDue() { 537QArray<int> OPimTodoAccessBackendSQL::overDue() {
539 OverDueQuery qu; 538 OverDueQuery qu;
540 return uids( m_driver->query(&qu ) ); 539 return uids( m_driver->query(&qu ) );
541} 540}
542QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, 541QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s,
543 const QDate& t, 542 const QDate& t,
544 bool u) { 543 bool u) {
545 EffQuery ef(s, t, u ); 544 EffQuery ef(s, t, u );
546 return uids (m_driver->query(&ef) ); 545 return uids (m_driver->query(&ef) );
547} 546}
548/* 547/*
549 * 548 *
550 */ 549 */
551QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, 550QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
552 int sortFilter, int cat ) { 551 int sortFilter, int cat ) {
553 odebug << "sorted " << asc << ", " << sortOrder << "" << oendl; 552 odebug << "sorted " << asc << ", " << sortOrder << "" << oendl;
554 QString query; 553 QString query;
555 query = "select uid from todolist WHERE "; 554 query = "select uid from todolist WHERE ";
556 555
557 /* 556 /*
558 * Sort Filter stuff 557 * Sort Filter stuff
559 * not that straight forward 558 * not that straight forward
560 * FIXME: Replace magic numbers 559 * FIXME: Replace magic numbers
561 * 560 *
562 */ 561 */
563 /* Category */ 562 /* Category */
564 if ( sortFilter & 1 ) { 563 if ( sortFilter & 1 ) {
565 QString str; 564 QString str;
566 if (cat != 0 ) str = QString::number( cat ); 565 if (cat != 0 ) str = QString::number( cat );
567 query += " categories like '%" +str+"%' AND"; 566 query += " categories like '%" +str+"%' AND";
568 } 567 }
569 /* Show only overdue */ 568 /* Show only overdue */
570 if ( sortFilter & 2 ) { 569 if ( sortFilter & 2 ) {
571 QDate date = QDate::currentDate(); 570 QDate date = QDate::currentDate();
572 QString due; 571 QString due;
573 QString base; 572 QString base;
574 base = QString("DueDate <= '%1-%2-%3' AND completed = 0") 573 base = QString("DueDate <= '%1-%2-%3' AND completed = 0")
575 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) 574 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
576 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) 575 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
577 .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); 576 .arg( QString::number( date.day() ).rightJustify( 2, '0' ) );
578 query += " " + base + " AND"; 577 query += " " + base + " AND";
579 } 578 }
580 /* not show completed */ 579 /* not show completed */
581 if ( sortFilter & 4 ) { 580 if ( sortFilter & 4 ) {
582 query += " completed = 0 AND"; 581 query += " completed = 0 AND";
583 }else{ 582 }else{
584 query += " ( completed = 1 OR completed = 0) AND"; 583 query += " ( completed = 1 OR completed = 0) AND";
585 } 584 }
586 /* strip the end */ 585 /* strip the end */
587 query = query.remove( query.length()-3, 3 ); 586 query = query.remove( query.length()-3, 3 );
588 587
589 588
590 /* 589 /*
591 * sort order stuff 590 * sort order stuff
592 * quite straight forward 591 * quite straight forward
593 */ 592 */
594 query += "ORDER BY "; 593 query += "ORDER BY ";
595 switch( sortOrder ) { 594 switch( sortOrder ) {
596 /* completed */ 595 /* completed */
597 case 0: 596 case 0:
598 query += "completed"; 597 query += "completed";
599 break; 598 break;
600 case 1: 599 case 1:
601 query += "priority"; 600 query += "priority";
602 break; 601 break;
603 case 2: 602 case 2:
604 query += "summary"; 603 query += "summary";
605 break; 604 break;
606 case 3: 605 case 3:
607 query += "DueDate"; 606 query += "DueDate";
608 break; 607 break;
609 } 608 }
610 609
611 if ( !asc ) { 610 if ( !asc ) {
612 odebug << "not ascending!" << oendl; 611 odebug << "not ascending!" << oendl;
613 query += " DESC"; 612 query += " DESC";
614 } 613 }
615 614
616 odebug << query << oendl; 615 odebug << query << oendl;
617 OSQLRawQuery raw(query ); 616 OSQLRawQuery raw(query );
618 return uids( m_driver->query(&raw) ); 617 return uids( m_driver->query(&raw) );
619} 618}
620bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ 619bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
621 if ( str == "0-0-0" ) 620 if ( str == "0-0-0" )
622 return false; 621 return false;
623 else{ 622 else{
624 int day, year, month; 623 int day, year, month;
625 QStringList list = QStringList::split("-", str ); 624 QStringList list = QStringList::split("-", str );
626 year = list[0].toInt(); 625 year = list[0].toInt();
627 month = list[1].toInt(); 626 month = list[1].toInt();
628 day = list[2].toInt(); 627 day = list[2].toInt();
629 da.setYMD( year, month, day ); 628 da.setYMD( year, month, day );
630 return true; 629 return true;
631 } 630 }
632} 631}
633OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ 632OPimTodo OPimTodoAccessBackendSQL::parseResultAndCache( int uid, const OSQLResult& res ) const{
634 if ( res.state() == OSQLResult::Failure ) { 633 if ( res.state() == OSQLResult::Failure ) {
635 OPimTodo to; 634 OPimTodo to;
636 return to; 635 return to;
637 } 636 }
638 637
638 OPimTodo retTodo;
639
639 OSQLResultItem::ValueList list = res.results(); 640 OSQLResultItem::ValueList list = res.results();
640 OSQLResultItem::ValueList::Iterator it = list.begin(); 641 OSQLResultItem::ValueList::Iterator it = list.begin();
641 odebug << "todo1" << oendl; 642 odebug << "todo1" << oendl;
642 OPimTodo to = todo( (*it) ); 643 OPimTodo to = todo( (*it) );
643 cache( to ); 644 cache( to );
644 ++it; 645 ++it;
645 646
646 for ( ; it != list.end(); ++it ) { 647 for ( ; it != list.end(); ++it ) {
647 odebug << "caching" << oendl; 648 odebug << "caching" << oendl;
648 cache( todo( (*it) ) ); 649 OPimTodo newTodo = todo( (*it) );
650 cache( newTodo );
651 if ( newTodo.uid() == uid )
652 retTodo = newTodo;
649 } 653 }
650 return to; 654 return retTodo;
651} 655}
652OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { 656OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
653 odebug << "todo(ResultItem)" << oendl; 657 odebug << "todo(ResultItem)" << oendl;
654 658
655 // Request information from addressbook table and create the OPimTodo-object. 659 // Request information from addressbook table and create the OPimTodo-object.
656 660
657 bool hasDueDate = false; QDate dueDate = QDate::currentDate(); 661 bool hasDueDate = false; QDate dueDate = QDate::currentDate();
658 hasDueDate = date( dueDate, item.data("DueDate") ); 662 hasDueDate = date( dueDate, item.data("DueDate") );
659 QStringList cats = QStringList::split(";", item.data("categories") ); 663 QStringList cats = QStringList::split(";", item.data("categories") );
660 664
661 odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl; 665 odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl;
662 666
663 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), 667 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
664 cats, item.data("summary"), item.data("description"), 668 cats, item.data("summary"), item.data("description"),
665 item.data("progress").toUShort(), hasDueDate, dueDate, 669 item.data("progress").toUShort(), hasDueDate, dueDate,
666 item.data("uid").toInt() ); 670 item.data("uid").toInt() );
667 671
668 bool isOk; 672 bool isOk;
669 int prioInt = QString( item.data("priority") ).toInt( &isOk ); 673 int prioInt = QString( item.data("priority") ).toInt( &isOk );
670 if ( isOk ) 674 if ( isOk )
671 to.setPriority( prioInt ); 675 to.setPriority( prioInt );
672 676
673 bool hasStartDate = false; QDate startDate = QDate::currentDate(); 677 bool hasStartDate = false; QDate startDate = QDate::currentDate();
674 hasStartDate = date( startDate, item.data("startdate") ); 678 hasStartDate = date( startDate, item.data("startdate") );
675 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); 679 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate();
676 hasCompletedDate = date( completedDate, item.data("completeddate") ); 680 hasCompletedDate = date( completedDate, item.data("completeddate") );
677 681
678 if ( hasStartDate ) 682 if ( hasStartDate )
679 to.setStartDate( startDate ); 683 to.setStartDate( startDate );
680 if ( hasCompletedDate ) 684 if ( hasCompletedDate )
681 to.setCompletedDate( completedDate ); 685 to.setCompletedDate( completedDate );
682 686
683 OPimNotifyManager& manager = to.notifiers(); 687 OPimNotifyManager& manager = to.notifiers();
684 manager.alarmsFromString( item.data("alarms") ); 688 manager.alarmsFromString( item.data("alarms") );
685 manager.remindersFromString( item.data("reminders") ); 689 manager.remindersFromString( item.data("reminders") );
686 690
687 OPimState pimState; 691 OPimState pimState;
688 pimState.setState( QString( item.data("state") ).toInt() ); 692 pimState.setState( QString( item.data("state") ).toInt() );
689 to.setState( pimState ); 693 to.setState( pimState );
690 694
691 QMap<int, QString> recMap; 695 QMap<int, QString> recMap;
692 recMap.insert( OPimRecurrence::RType , item.data("RType") ); 696 recMap.insert( OPimRecurrence::RType , item.data("RType") );
693 recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") ); 697 recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") );
694 recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") ); 698 recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") );
695 recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") ); 699 recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") );
696 recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") ); 700 recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") );
697 recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") ); 701 recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") );
698 recMap.insert( OPimRecurrence::Created , item.data("Created") ); 702 recMap.insert( OPimRecurrence::Created , item.data("Created") );
699 recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); 703 recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") );
700 704
701 OPimRecurrence recur; 705 OPimRecurrence recur;
702 recur.fromMap( recMap ); 706 recur.fromMap( recMap );
703 to.setRecurrence( recur ); 707 to.setRecurrence( recur );
704 708
705 // Finally load the custom-entries for this UID and put it into the created object 709 // Finally load the custom-entries for this UID and put it into the created object
706 to.setExtraMap( requestCustom( to.uid() ) ); 710 to.setExtraMap( requestCustom( to.uid() ) );
707 711
708 return to; 712 return to;
709} 713}
714
715// FIXME: Where is the difference to "find" ? (eilers)
710OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { 716OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
711 FindQuery find( uid ); 717 FindQuery find( uid );
712 return todo( m_driver->query(&find) ); 718 return parseResultAndCache( uid, m_driver->query(&find) );
713} 719}
714/* 720/*
715 * update the dict 721 * update the dict
716 */ 722 */
717void OPimTodoAccessBackendSQL::fillDict() { 723void OPimTodoAccessBackendSQL::fillDict() {
718 724
719#if 0 725#if 0
720 /* initialize dict */ 726 /* initialize dict */
721 /* 727 /*
722 * UPDATE dict if you change anything!!! 728 * UPDATE dict if you change anything!!!
723 * FIXME: Isn't this dict obsolete ? (eilers) 729 * FIXME: Isn't this dict obsolete ? (eilers)
724 */ 730 */
725 m_dict.setAutoDelete( TRUE ); 731 m_dict.setAutoDelete( TRUE );
726 m_dict.insert("Categories" , new int(OPimTodo::Category) ); 732 m_dict.insert("Categories" , new int(OPimTodo::Category) );
727 m_dict.insert("Uid" , new int(OPimTodo::Uid) ); 733 m_dict.insert("Uid" , new int(OPimTodo::Uid) );
728 m_dict.insert("HasDate" , new int(OPimTodo::HasDate) ); 734 m_dict.insert("HasDate" , new int(OPimTodo::HasDate) );
729 m_dict.insert("Completed" , new int(OPimTodo::Completed) ); 735 m_dict.insert("Completed" , new int(OPimTodo::Completed) );
730 m_dict.insert("Description" , new int(OPimTodo::Description) ); 736 m_dict.insert("Description" , new int(OPimTodo::Description) );
731 m_dict.insert("Summary" , new int(OPimTodo::Summary) ); 737 m_dict.insert("Summary" , new int(OPimTodo::Summary) );
732 m_dict.insert("Priority" , new int(OPimTodo::Priority) ); 738 m_dict.insert("Priority" , new int(OPimTodo::Priority) );
733 m_dict.insert("DateDay" , new int(OPimTodo::DateDay) ); 739 m_dict.insert("DateDay" , new int(OPimTodo::DateDay) );
734 m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) ); 740 m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) );
735 m_dict.insert("DateYear" , new int(OPimTodo::DateYear) ); 741 m_dict.insert("DateYear" , new int(OPimTodo::DateYear) );
736 m_dict.insert("Progress" , new int(OPimTodo::Progress) ); 742 m_dict.insert("Progress" , new int(OPimTodo::Progress) );
737 m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers) 743 m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers)
738 m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); 744 m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) );
739// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers) 745// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers)
740// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers) 746// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers)
741 747
742#endif 748#endif
743} 749}
744/* 750/*
745 * need to be const so let's fool the 751 * need to be const so let's fool the
746 * compiler :( 752 * compiler :(
747 */ 753 */
748void OPimTodoAccessBackendSQL::update()const { 754void OPimTodoAccessBackendSQL::update()const {
749 ((OPimTodoAccessBackendSQL*)this)->m_dirty = false; 755 ((OPimTodoAccessBackendSQL*)this)->m_dirty = false;
750 LoadQuery lo; 756 LoadQuery lo;
751 OSQLResult res = m_driver->query(&lo); 757 OSQLResult res = m_driver->query(&lo);
752 if ( res.state() != OSQLResult::Success ) 758 if ( res.state() != OSQLResult::Success )
753 return; 759 return;
754 760
755 ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res ); 761 ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res );
756} 762}
757QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ 763QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
758 764
759 OSQLResultItem::ValueList list = res.results(); 765 OSQLResultItem::ValueList list = res.results();
760 OSQLResultItem::ValueList::Iterator it; 766 OSQLResultItem::ValueList::Iterator it;
761 QArray<int> ints(list.count() ); 767 QArray<int> ints(list.count() );
762 odebug << " count = " << list.count() << "" << oendl; 768 odebug << " count = " << list.count() << "" << oendl;
763 769
764 int i = 0; 770 int i = 0;
765 for (it = list.begin(); it != list.end(); ++it ) { 771 for (it = list.begin(); it != list.end(); ++it ) {
766 ints[i] = (*it).data("uid").toInt(); 772 ints[i] = (*it).data("uid").toInt();
767 i++; 773 i++;
768 } 774 }
769 return ints; 775 return ints;
770} 776}
771 777
772QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const 778QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
773{ 779{
774 780
775#if 0 781#if 0
776 QArray<int> empty; 782 QArray<int> empty;
777 return empty; 783 return empty;
778 784
779#else 785#else
780 QString qu = "SELECT uid FROM todolist WHERE ("; 786 QString qu = "SELECT uid FROM todolist WHERE (";
781 787
782 // Do it make sense to search other fields, too ? 788 // Do it make sense to search other fields, too ?
783 qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; 789 qu += " rlike(\""+ r.pattern() + "\",\"description\") OR";
784 qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; 790 qu += " rlike(\""+ r.pattern() + "\",\"summary\")";
785 791
786 qu += ")"; 792 qu += ")";
787 793
788 odebug << "query: " << qu << "" << oendl; 794 odebug << "query: " << qu << "" << oendl;
789 795
790 OSQLRawQuery raw( qu ); 796 OSQLRawQuery raw( qu );
791 OSQLResult res = m_driver->query( &raw ); 797 OSQLResult res = m_driver->query( &raw );
792 798
793 return uids( res ); 799 return uids( res );
794 800
795 801
796#endif 802#endif
797 803
798} 804}
799QBitArray OPimTodoAccessBackendSQL::supports()const { 805QBitArray OPimTodoAccessBackendSQL::supports()const {
800 806
801 return sup(); 807 return sup();
802} 808}
803 809
804QBitArray OPimTodoAccessBackendSQL::sup() const{ 810QBitArray OPimTodoAccessBackendSQL::sup() const{
805 811
806 QBitArray ar( OPimTodo::CompletedDate + 1 ); 812 QBitArray ar( OPimTodo::CompletedDate + 1 );
807 ar.fill( true ); 813 ar.fill( true );
808 ar[OPimTodo::CrossReference] = false; 814 ar[OPimTodo::CrossReference] = false;
809 ar[OPimTodo::State ] = false; 815 ar[OPimTodo::State ] = false;
810 ar[OPimTodo::Reminders] = false; 816 ar[OPimTodo::Reminders] = false;
811 ar[OPimTodo::Notifiers] = false; 817 ar[OPimTodo::Notifiers] = false;
812 ar[OPimTodo::Maintainer] = false; 818 ar[OPimTodo::Maintainer] = false;
813 819
814 return ar; 820 return ar;
815} 821}
816 822
817void OPimTodoAccessBackendSQL::removeAllCompleted(){ 823void OPimTodoAccessBackendSQL::removeAllCompleted(){
818 // First we need the uids from all entries which are 824 // First we need the uids from all entries which are
819 // completed. Then, we just have to remove them... 825 // completed. Then, we just have to remove them...
820 826
821 QString qu = "SELECT uid FROM todolist WHERE completed = 1"; 827 QString qu = "SELECT uid FROM todolist WHERE completed = 1";
822 828
823 OSQLRawQuery raw( qu ); 829 OSQLRawQuery raw( qu );
824 OSQLResult res = m_driver->query( &raw ); 830 OSQLResult res = m_driver->query( &raw );
825 831
826 QArray<int> completed_uids = uids( res ); 832 QArray<int> completed_uids = uids( res );
827 833
828 odebug << "Number of completed: " << completed_uids.size() << "" << oendl; 834 odebug << "Number of completed: " << completed_uids.size() << "" << oendl;
829 835
830 if ( completed_uids.size() == 0 ) 836 if ( completed_uids.size() == 0 )
831 return; 837 return;
832 838
833 qu = "DELETE FROM todolist WHERE ("; 839 qu = "DELETE FROM todolist WHERE (";
834 QString query; 840 QString query;
835 841
836 for ( int i = 0; i < completed_uids.size(); i++ ){ 842 for ( int i = 0; i < completed_uids.size(); i++ ){
837 if ( !query.isEmpty() ) 843 if ( !query.isEmpty() )
838 query += " OR "; 844 query += " OR ";
839 query += QString( "uid = %1" ).arg( completed_uids[i] ); 845 query += QString( "uid = %1" ).arg( completed_uids[i] );
840 } 846 }
841 qu += query + " );"; 847 qu += query + " );";
842 848
843 // Put remove of custom entries in this query to speed up.. 849 // Put remove of custom entries in this query to speed up..
844 qu += "DELETE FORM custom_data WHERE ("; 850 qu += "DELETE FORM custom_data WHERE (";
845 query = ""; 851 query = "";
846 852
847 for ( int i = 0; i < completed_uids.size(); i++ ){ 853 for ( int i = 0; i < completed_uids.size(); i++ ){
848 if ( !query.isEmpty() ) 854 if ( !query.isEmpty() )
849 query += " OR "; 855 query += " OR ";
850 query += QString( "uid = %1" ).arg( completed_uids[i] ); 856 query += QString( "uid = %1" ).arg( completed_uids[i] );
851 } 857 }
852 qu += query + " );"; 858 qu += query + " );";
853 859
854 odebug << "query: " << qu << "" << oendl; 860 odebug << "query: " << qu << "" << oendl;
855 861
856 OSQLRawQuery raw2( qu ); 862 OSQLRawQuery raw2( qu );
857 res = m_driver->query( &raw2 ); 863 res = m_driver->query( &raw2 );
858 if ( res.state() == OSQLResult::Failure ) { 864 if ( res.state() == OSQLResult::Failure ) {
859 owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl; 865 owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl;
860 } 866 }
861} 867}
862 868
863 869
864QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const 870QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const
865{ 871{
866 QMap<QString, QString> customMap; 872 QMap<QString, QString> customMap;
867 873
868 FindCustomQuery query( uid ); 874 FindCustomQuery query( uid );
869 OSQLResult res_custom = m_driver->query( &query ); 875 OSQLResult res_custom = m_driver->query( &query );
870 876
871 if ( res_custom.state() == OSQLResult::Failure ) { 877 if ( res_custom.state() == OSQLResult::Failure ) {
872 owarn << "OSQLResult::Failure in find query !!" << oendl; 878 owarn << "OSQLResult::Failure in find query !!" << oendl;
873 QMap<QString, QString> empty; 879 QMap<QString, QString> empty;
874 return empty; 880 return empty;
875 } 881 }
876 882
877 OSQLResultItem::ValueList list = res_custom.results(); 883 OSQLResultItem::ValueList list = res_custom.results();
878 OSQLResultItem::ValueList::Iterator it = list.begin(); 884 OSQLResultItem::ValueList::Iterator it = list.begin();
879 for ( ; it != list.end(); ++it ) { 885 for ( ; it != list.end(); ++it ) {
880 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 886 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
881 } 887 }
882 888
883 return customMap; 889 return customMap;
884} 890}
885 891
886 892
887 893
888 894
889} 895}
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h
index 0cc7722..415f791 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.h
+++ b/libopie2/opiepim/backend/otodoaccesssql.h
@@ -1,93 +1,93 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) 3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OPIE_PIM_ACCESS_SQL_H 29#ifndef OPIE_PIM_ACCESS_SQL_H
30#define OPIE_PIM_ACCESS_SQL_H 30#define OPIE_PIM_ACCESS_SQL_H
31 31
32/* #include <qasciidict.h> */ 32/* #include <qasciidict.h> */
33 33
34#include <opie2/otodoaccessbackend.h> 34#include <opie2/otodoaccessbackend.h>
35 35
36namespace Opie { 36namespace Opie {
37namespace DB { 37namespace DB {
38class OSQLDriver; 38class OSQLDriver;
39class OSQLResult; 39class OSQLResult;
40class OSQLResultItem; 40class OSQLResultItem;
41} 41}
42} 42}
43 43
44namespace Opie { 44namespace Opie {
45 45
46class OPimTodoAccessBackendSQL : public OPimTodoAccessBackend { 46class OPimTodoAccessBackendSQL : public OPimTodoAccessBackend {
47public: 47public:
48 OPimTodoAccessBackendSQL( const QString& file ); 48 OPimTodoAccessBackendSQL( const QString& file );
49 ~OPimTodoAccessBackendSQL(); 49 ~OPimTodoAccessBackendSQL();
50 50
51 bool load(); 51 bool load();
52 bool reload(); 52 bool reload();
53 bool save(); 53 bool save();
54 QArray<int> allRecords()const; 54 QArray<int> allRecords()const;
55 55
56 QArray<int> queryByExample( const OPimTodo& t, int settings, const QDateTime& d = QDateTime() ); 56 QArray<int> queryByExample( const OPimTodo& t, int settings, const QDateTime& d = QDateTime() );
57 OPimTodo find(int uid)const; 57 OPimTodo find(int uid)const;
58 OPimTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; 58 OPimTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const;
59 void clear(); 59 void clear();
60 bool add( const OPimTodo& t ); 60 bool add( const OPimTodo& t );
61 bool remove( int uid ); 61 bool remove( int uid );
62 bool replace( const OPimTodo& t ); 62 bool replace( const OPimTodo& t );
63 63
64 QArray<int> overDue(); 64 QArray<int> overDue();
65 QArray<int> effectiveToDos( const QDate& start, 65 QArray<int> effectiveToDos( const QDate& start,
66 const QDate& end, bool includeNoDates ); 66 const QDate& end, bool includeNoDates );
67 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); 67 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat );
68 68
69 QBitArray supports()const; 69 QBitArray supports()const;
70 QArray<int> matchRegexp( const QRegExp &r ) const; 70 QArray<int> matchRegexp( const QRegExp &r ) const;
71 void removeAllCompleted(); 71 void removeAllCompleted();
72 72
73 73
74private: 74private:
75 void update()const; 75 void update()const;
76 void fillDict(); 76 void fillDict();
77 inline bool date( QDate& date, const QString& )const; 77 inline bool date( QDate& date, const QString& )const;
78 inline OPimTodo todo( const Opie::DB::OSQLResult& )const; 78 inline OPimTodo parseResultAndCache( int uid, const Opie::DB::OSQLResult& )const;
79 inline OPimTodo todo( Opie::DB::OSQLResultItem& )const; 79 inline OPimTodo todo( Opie::DB::OSQLResultItem& )const;
80 inline QArray<int> uids( const Opie::DB::OSQLResult& )const; 80 inline QArray<int> uids( const Opie::DB::OSQLResult& )const;
81 OPimTodo todo( int uid )const; 81 OPimTodo todo( int uid )const;
82 QBitArray sup() const; 82 QBitArray sup() const;
83 QMap<QString, QString> requestCustom( int uid ) const; 83 QMap<QString, QString> requestCustom( int uid ) const;
84 84
85 // QAsciiDict<int> m_dict; 85 // QAsciiDict<int> m_dict;
86 Opie::DB::OSQLDriver* m_driver; 86 Opie::DB::OSQLDriver* m_driver;
87 QArray<int> m_uids; 87 QArray<int> m_uids;
88 bool m_dirty : 1; 88 bool m_dirty : 1;
89}; 89};
90 90
91} 91}
92 92
93#endif 93#endif
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index 6f01b46..7ab1ea5 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -1,380 +1,380 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Holger Freyther <zecke@handhelds.org> 3 Copyright (C) Holger Freyther <zecke@handhelds.org>
4 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 4 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
6 .=l. 6 .=l.
7 .>+-= 7 .>+-=
8 _;:, .> :=|. This program is free software; you can 8 _;:, .> :=|. This program is free software; you can
9.> <`_, > . <= redistribute it and/or modify it under 9.> <`_, > . <= redistribute it and/or modify it under
10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
11.="- .-=="i, .._ License as published by the Free Software 11.="- .-=="i, .._ License as published by the Free Software
12 - . .-<_> .<> Foundation; either version 2 of the License, 12 - . .-<_> .<> Foundation; either version 2 of the License,
13 ._= =} : or (at your option) any later version. 13 ._= =} : or (at your option) any later version.
14 .%`+i> _;_. 14 .%`+i> _;_.
15 .i_,=:_. -<s. This program is distributed in the hope that 15 .i_,=:_. -<s. This program is distributed in the hope that
16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
17 : .. .:, . . . without even the implied warranty of 17 : .. .:, . . . without even the implied warranty of
18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.= = ; Library General Public License for more 20..}^=.= = ; Library General Public License for more
21++= -. .` .: details. 21++= -. .` .: details.
22 : = ...= . :.=- 22 : = ...= . :.=-
23 -. .:....=;==+<; You should have received a copy of the GNU 23 -. .:....=;==+<; You should have received a copy of the GNU
24 -_. . . )=. = Library General Public License along with 24 -_. . . )=. = Library General Public License along with
25 -- :-=` this library; see the file COPYING.LIB. 25 -- :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29*/ 29*/
30#ifndef OPIE_PIM_ACCESS_TEMPLATE_H 30#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
31#define OPIE_PIM_ACCESS_TEMPLATE_H 31#define OPIE_PIM_ACCESS_TEMPLATE_H
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/opimrecord.h> 34#include <opie2/opimrecord.h>
35#include <opie2/opimaccessbackend.h> 35#include <opie2/opimaccessbackend.h>
36#include <opie2/opimrecordlist.h> 36#include <opie2/opimrecordlist.h>
37 37
38#include <opie2/opimtemplatebase.h> 38#include <opie2/opimtemplatebase.h>
39#include <opie2/odebug.h> 39#include <opie2/odebug.h>
40 40
41/* QT */ 41/* QT */
42#include <qarray.h> 42#include <qarray.h>
43 43
44namespace Opie { 44namespace Opie {
45 45
46class OPimAccessTemplatePrivate; 46class OPimAccessTemplatePrivate;
47/** 47/**
48 * Thats the frontend to our OPIE PIM 48 * Thats the frontend to our OPIE PIM
49 * Library. Either you want to use it's 49 * Library. Either you want to use it's
50 * interface or you want to implement 50 * interface or you want to implement
51 * your own Access lib 51 * your own Access lib
52 * Just create a OPimRecord and inherit from 52 * Just create a OPimRecord and inherit from
53 * the templates 53 * the templates
54 */ 54 */
55 55
56template <class T = OPimRecord > 56template <class T = OPimRecord >
57class OPimAccessTemplate : public OTemplateBase<T> { 57class OPimAccessTemplate : public OTemplateBase<T> {
58public: 58public:
59 enum Access { 59 enum Access {
60 Random = 0, 60 Random = 0,
61 SortedAccess 61 SortedAccess
62 }; 62 };
63 typedef OPimRecordList<T> List; 63 typedef OPimRecordList<T> List;
64 typedef OPimAccessBackend<T> BackEnd; 64 typedef OPimAccessBackend<T> BackEnd;
65 typedef OPimCache<T> Cache; 65 typedef OPimCache<T> Cache;
66 66
67 /** 67 /**
68 * c'tor BackEnd 68 * c'tor BackEnd
69 * enum Access a small hint on how to handle the backend 69 * enum Access a small hint on how to handle the backend
70 */ 70 */
71 OPimAccessTemplate( BackEnd* end); 71 OPimAccessTemplate( BackEnd* end);
72 72
73 virtual ~OPimAccessTemplate(); 73 virtual ~OPimAccessTemplate();
74 74
75 /** 75 /**
76 * load from the backend 76 * load from the backend
77 */ 77 */
78 bool load(); 78 bool load();
79 79
80 /** Reload database. 80 /** Reload database.
81 * You should execute this function if the external database 81 * You should execute this function if the external database
82 * was changed. 82 * was changed.
83 * This function will load the external database and afterwards 83 * This function will load the external database and afterwards
84 * rejoin the local changes. Therefore the local database will be set consistent. 84 * rejoin the local changes. Therefore the local database will be set consistent.
85 */ 85 */
86 virtual bool reload(); 86 virtual bool reload();
87 87
88 /** Save contacts database. 88 /** Save contacts database.
89 * Save is more a "commit". After calling this function, all changes are public available. 89 * Save is more a "commit". After calling this function, all changes are public available.
90 * @return true if successful 90 * @return true if successful
91 */ 91 */
92 bool save(); 92 bool save();
93 93
94 /** 94 /**
95 * if the resource was changed externally 95 * if the resource was changed externally
96 * You should use the signal handling instead of polling possible changes ! 96 * You should use the signal handling instead of polling possible changes !
97 * zecke: Do you implement a signal for otodoaccess ? 97 * zecke: Do you implement a signal for otodoaccess ?
98 */ 98 */
99 bool wasChangedExternally()const; 99 bool wasChangedExternally()const;
100 100
101 /** 101 /**
102 * return a List of records 102 * return a List of records
103 * you can iterate over them 103 * you can iterate over them
104 */ 104 */
105 virtual List allRecords()const; 105 virtual List allRecords()const;
106 106
107 /** 107 /**
108 * return a List of records 108 * return a List of records
109 * that match the regex 109 * that match the regex
110 */ 110 */
111 virtual List matchRegexp( const QRegExp &r ) const; 111 virtual List matchRegexp( const QRegExp &r ) const;
112 112
113 /** 113 /**
114 * queryByExample. 114 * queryByExample.
115 * @see otodoaccess, ocontactaccess 115 * @see otodoaccess, ocontactaccess
116 */ 116 */
117 virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); 117 virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() );
118 118
119 /** 119 /**
120 * find the OPimRecord uid 120 * find the OPimRecord uid
121 */ 121 */
122 virtual T find( int uid )const; 122 T find( int uid )const;
123 123
124 /** 124 /**
125 * read ahead cache find method ;) 125 * read ahead cache find method ;)
126 */ 126 */
127 virtual T find( int uid, const QArray<int>&, 127 T find( int uid, const QArray<int>&,
128 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; 128 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
129 129
130 130
131 /* invalidate cache here */ 131 /* invalidate cache here */
132 /** 132 /**
133 * clears the backend and invalidates the backend 133 * clears the backend and invalidates the backend
134 */ 134 */
135 void clear() ; 135 void clear() ;
136 136
137 /** 137 /**
138 * add T to the backend 138 * add T to the backend
139 * @param t The item to add. 139 * @param t The item to add.
140 * @return <i>true</i> if added successfully. 140 * @return <i>true</i> if added successfully.
141 */ 141 */
142 virtual bool add( const T& t ) ; 142 virtual bool add( const T& t ) ;
143 143
144 bool add( const OPimRecord& ); 144 bool add( const OPimRecord& );
145 /** 145 /**
146 * Add an Opie PimRecord. 146 * Add an Opie PimRecord.
147 * Info: Take this if you are working with OPimRecords and you need to add it into any database. 147 * Info: Take this if you are working with OPimRecords and you need to add it into any database.
148 * But take care that the accessing database is compatible to the real type of OPimRecord !! 148 * But take care that the accessing database is compatible to the real type of OPimRecord !!
149 * Otherwise this access will be rejected ! 149 * Otherwise this access will be rejected !
150 */ 150 */
151 bool add( const OPimRecord* ); 151 bool add( const OPimRecord* );
152 152
153 153
154 /* only the uid matters */ 154 /* only the uid matters */
155 /** 155 /**
156 * remove T from the backend 156 * remove T from the backend
157 * @param t The item to remove 157 * @param t The item to remove
158 * @return <i>true</i> if successful. 158 * @return <i>true</i> if successful.
159 */ 159 */
160 virtual bool remove( const T& t ); 160 virtual bool remove( const T& t );
161 161
162 /** 162 /**
163 * remove the OPimRecord with uid 163 * remove the OPimRecord with uid
164 * @param uid The ID of the item to remove 164 * @param uid The ID of the item to remove
165 * @return <i>true</i> if successful. 165 * @return <i>true</i> if successful.
166 */ 166 */
167 bool remove( int uid ); 167 bool remove( int uid );
168 bool remove( const OPimRecord& ); 168 bool remove( const OPimRecord& );
169 169
170 /** 170 /**
171 * replace T from backend 171 * replace T from backend
172 * @param t The item to replace 172 * @param t The item to replace
173 * @return <i>true</i> if successful. 173 * @return <i>true</i> if successful.
174 */ 174 */
175 virtual bool replace( const T& t) ; 175 virtual bool replace( const T& t) ;
176 176
177 void setReadAhead( uint count ); 177 void setReadAhead( uint count );
178 /** 178 /**
179 * @internal 179 * @internal
180 */ 180 */
181 virtual T cacheFind( int uid )const; 181 virtual T cacheFind( int uid )const;
182 void cache( const T& )const; 182 void cache( const T& )const;
183 void setSaneCacheSize( int ); 183 void setSaneCacheSize( int );
184 184
185 QArray<int> records()const; 185 QArray<int> records()const;
186protected: 186protected:
187 /** 187 /**
188 * invalidate the cache 188 * invalidate the cache
189 */ 189 */
190 void invalidateCache(); 190 void invalidateCache();
191 191
192 void setBackEnd( BackEnd* end ); 192 void setBackEnd( BackEnd* end );
193 /** 193 /**
194 * returns the backend 194 * returns the backend
195 */ 195 */
196 BackEnd* backEnd(); 196 BackEnd* backEnd();
197 BackEnd* m_backEnd; 197 BackEnd* m_backEnd;
198 198
199 Cache m_cache; 199 Cache m_cache;
200 200
201private: 201private:
202 OPimAccessTemplatePrivate *d; 202 OPimAccessTemplatePrivate *d;
203 203
204}; 204};
205 205
206template <class T> 206template <class T>
207OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) 207OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
208 : OTemplateBase<T>(), m_backEnd( end ) 208 : OTemplateBase<T>(), m_backEnd( end )
209{ 209{
210 if (end ) 210 if (end )
211 end->setFrontend( this ); 211 end->setFrontend( this );
212} 212}
213template <class T> 213template <class T>
214OPimAccessTemplate<T>::~OPimAccessTemplate() { 214OPimAccessTemplate<T>::~OPimAccessTemplate() {
215 owarn << "~OPimAccessTemplate<T>" << oendl; 215 owarn << "~OPimAccessTemplate<T>" << oendl;
216 delete m_backEnd; 216 delete m_backEnd;
217} 217}
218template <class T> 218template <class T>
219bool OPimAccessTemplate<T>::load() { 219bool OPimAccessTemplate<T>::load() {
220 invalidateCache(); 220 invalidateCache();
221 return m_backEnd->load(); 221 return m_backEnd->load();
222} 222}
223template <class T> 223template <class T>
224bool OPimAccessTemplate<T>::reload() { 224bool OPimAccessTemplate<T>::reload() {
225 invalidateCache(); 225 invalidateCache();
226 return m_backEnd->reload(); 226 return m_backEnd->reload();
227} 227}
228template <class T> 228template <class T>
229bool OPimAccessTemplate<T>::save() { 229bool OPimAccessTemplate<T>::save() {
230 return m_backEnd->save(); 230 return m_backEnd->save();
231} 231}
232template <class T> 232template <class T>
233typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { 233typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
234 QArray<int> ints = m_backEnd->allRecords(); 234 QArray<int> ints = m_backEnd->allRecords();
235 List lis(ints, this ); 235 List lis(ints, this );
236 return lis; 236 return lis;
237} 237}
238template <class T> 238template <class T>
239typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { 239typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const {
240 QArray<int> ints = m_backEnd->matchRegexp( r ); 240 QArray<int> ints = m_backEnd->matchRegexp( r );
241 List lis(ints, this ); 241 List lis(ints, this );
242 return lis; 242 return lis;
243} 243}
244template <class T> 244template <class T>
245QArray<int> OPimAccessTemplate<T>::records()const { 245QArray<int> OPimAccessTemplate<T>::records()const {
246 return m_backEnd->allRecords(); 246 return m_backEnd->allRecords();
247} 247}
248template <class T> 248template <class T>
249typename OPimAccessTemplate<T>::List 249typename OPimAccessTemplate<T>::List
250OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { 250OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) {
251 QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); 251 QArray<int> ints = m_backEnd->queryByExample( t, settings, d );
252 252
253 List lis(ints, this ); 253 List lis(ints, this );
254 return lis; 254 return lis;
255} 255}
256template <class T> 256template <class T>
257T OPimAccessTemplate<T>::find( int uid ) const{ 257T OPimAccessTemplate<T>::find( int uid ) const{
258 // First search in cache.. 258 // First search in cache..
259 if ( m_cache.contains( uid ) ) 259 if ( m_cache.contains( uid ) )
260 return m_cache.find( uid ); 260 return m_cache.find( uid );
261 261
262 T t = m_backEnd->find( uid ); 262 T t = m_backEnd->find( uid );
263 cache( t ); 263 cache( t );
264 264
265 return t; 265 return t;
266} 266}
267 267
268template <class T> 268template <class T>
269T OPimAccessTemplate<T>::cacheFind( int uid ) const 269T OPimAccessTemplate<T>::cacheFind( int uid ) const
270{ 270{
271 return m_cache.find( uid ); 271 return m_cache.find( uid );
272} 272}
273 273
274template <class T> 274template <class T>
275T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, 275T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
276 uint current, typename OTemplateBase<T>::CacheDirection dir )const { 276 uint current, typename OTemplateBase<T>::CacheDirection dir )const {
277 /* 277 /*
278 * better do T.isEmpty() 278 * better do T.isEmpty()
279 * after a find this way we would 279 * after a find this way we would
280 * avoid two finds in QCache... 280 * avoid two finds in QCache...
281 */ 281 */
282 // owarn << "find it now " << uid << oendl; 282 // owarn << "find it now " << uid << oendl;
283 if ( m_cache.contains( uid ) ) { 283 if ( m_cache.contains( uid ) ) {
284 return m_cache.find( uid ); 284 return m_cache.find( uid );
285 } 285 }
286 286
287 T t = m_backEnd->find( uid, ar, current, dir ); 287 T t = m_backEnd->find( uid, ar, current, dir );
288 cache( t ); 288 cache( t );
289 return t; 289 return t;
290} 290}
291template <class T> 291template <class T>
292void OPimAccessTemplate<T>::clear() { 292void OPimAccessTemplate<T>::clear() {
293 invalidateCache(); 293 invalidateCache();
294 m_backEnd->clear(); 294 m_backEnd->clear();
295} 295}
296template <class T> 296template <class T>
297bool OPimAccessTemplate<T>::add( const T& t ) { 297bool OPimAccessTemplate<T>::add( const T& t ) {
298 cache( t ); 298 cache( t );
299 return m_backEnd->add( t ); 299 return m_backEnd->add( t );
300} 300}
301 301
302template <class T> 302template <class T>
303bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) { 303bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) {
304 /* same type */ 304 /* same type */
305 T tempInstance; 305 T tempInstance;
306 if ( rec.rtti() == tempInstance.rtti() ) { 306 if ( rec.rtti() == tempInstance.rtti() ) {
307 const T& t = static_cast<const T&>(rec); 307 const T& t = static_cast<const T&>(rec);
308 return add(t); 308 return add(t);
309 } else { 309 } else {
310 owarn << "Adding not possible: Objecttype mismatch" << oendl; 310 owarn << "Adding not possible: Objecttype mismatch" << oendl;
311 } 311 }
312 return false; 312 return false;
313} 313}
314 314
315template <class T> 315template <class T>
316bool OPimAccessTemplate<T>::add( const OPimRecord* rec) { 316bool OPimAccessTemplate<T>::add( const OPimRecord* rec) {
317 /* same type, but pointer */ 317 /* same type, but pointer */
318 T tempInstance; 318 T tempInstance;
319 if ( rec -> rtti() == tempInstance.rtti() ) { 319 if ( rec -> rtti() == tempInstance.rtti() ) {
320 const T* t = static_cast<const T*>(rec); 320 const T* t = static_cast<const T*>(rec);
321 return add( *t ); 321 return add( *t );
322 } else { 322 } else {
323 owarn << "Adding not possible: Objecttype mismatch" << oendl; 323 owarn << "Adding not possible: Objecttype mismatch" << oendl;
324 } 324 }
325 return false; 325 return false;
326} 326}
327 327
328template <class T> 328template <class T>
329bool OPimAccessTemplate<T>::remove( const T& t ) { 329bool OPimAccessTemplate<T>::remove( const T& t ) {
330 return remove( t.uid() ); 330 return remove( t.uid() );
331} 331}
332template <class T> 332template <class T>
333bool OPimAccessTemplate<T>::remove( int uid ) { 333bool OPimAccessTemplate<T>::remove( int uid ) {
334 m_cache.remove( uid ); 334 m_cache.remove( uid );
335 return m_backEnd->remove( uid ); 335 return m_backEnd->remove( uid );
336} 336}
337template <class T> 337template <class T>
338bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { 338bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
339 return remove( rec.uid() ); 339 return remove( rec.uid() );
340} 340}
341template <class T> 341template <class T>
342bool OPimAccessTemplate<T>::replace( const T& t ) { 342bool OPimAccessTemplate<T>::replace( const T& t ) {
343 m_cache.replace( t ); 343 m_cache.replace( t );
344 return m_backEnd->replace( t ); 344 return m_backEnd->replace( t );
345} 345}
346template <class T> 346template <class T>
347void OPimAccessTemplate<T>::invalidateCache() { 347void OPimAccessTemplate<T>::invalidateCache() {
348 m_cache.invalidate(); 348 m_cache.invalidate();
349} 349}
350template <class T> 350template <class T>
351typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { 351typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
352 return m_backEnd; 352 return m_backEnd;
353} 353}
354template <class T> 354template <class T>
355bool OPimAccessTemplate<T>::wasChangedExternally()const { 355bool OPimAccessTemplate<T>::wasChangedExternally()const {
356 return false; 356 return false;
357} 357}
358template <class T> 358template <class T>
359void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { 359void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) {
360 m_backEnd = end; 360 m_backEnd = end;
361 if (m_backEnd ) 361 if (m_backEnd )
362 m_backEnd->setFrontend( this ); 362 m_backEnd->setFrontend( this );
363} 363}
364template <class T> 364template <class T>
365void OPimAccessTemplate<T>::cache( const T& t ) const{ 365void OPimAccessTemplate<T>::cache( const T& t ) const{
366 /* hacky we need to work around the const*/ 366 /* hacky we need to work around the const*/
367 ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); 367 ((OPimAccessTemplate<T>*)this)->m_cache.add( t );
368} 368}
369template <class T> 369template <class T>
370void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { 370void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
371 m_cache.setSize( size ); 371 m_cache.setSize( size );
372} 372}
373template <class T> 373template <class T>
374void OPimAccessTemplate<T>::setReadAhead( uint count ) { 374void OPimAccessTemplate<T>::setReadAhead( uint count ) {
375 m_backEnd->setReadAhead( count ); 375 m_backEnd->setReadAhead( count );
376} 376}
377 377
378} 378}
379 379
380#endif 380#endif