author | llornkcor <llornkcor> | 2005-08-24 20:22:10 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-08-24 20:22:10 (UTC) |
commit | 65edeafe2dc8689dce7c2ce94e954933b393dcf0 (patch) (unidiff) | |
tree | 17d0986ef0bce73f44a4b9900466fcc533954814 /noncore/apps/opie-gutenbrowser/LibraryDialog.cpp | |
parent | f0bb6c410f19d502cf563254d95158617a32b94e (diff) | |
download | opie-65edeafe2dc8689dce7c2ce94e954933b393dcf0.zip opie-65edeafe2dc8689dce7c2ce94e954933b393dcf0.tar.gz opie-65edeafe2dc8689dce7c2ce94e954933b393dcf0.tar.bz2 |
optimize search. fix other things
Diffstat (limited to 'noncore/apps/opie-gutenbrowser/LibraryDialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-gutenbrowser/LibraryDialog.cpp | 265 |
1 files changed, 124 insertions, 141 deletions
diff --git a/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp b/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp index 58babe9..9858188 100644 --- a/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp +++ b/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp | |||
@@ -135,64 +135,85 @@ void LibraryDialog::Library() { | |||
135 | clearItems(); | 135 | clearItems(); |
136 | 136 | ||
137 | // qDebug( "opening GUTINDEX.ALL file"); | 137 | // qDebug( "opening GUTINDEX.ALL file"); |
138 | IDontKnowWhy = ""; | 138 | IDontKnowWhy = ""; |
139 | if ( indexLib.open( IO_ReadOnly) ) { // file opened successfully | 139 | system("date"); |
140 | if ( indexLib.open( IO_ReadOnly) ) { | ||
141 | // file opened successfully | ||
140 | QTextStream indexStream( &indexLib ); | 142 | QTextStream indexStream( &indexLib ); |
141 | QString indexLine; | 143 | QString indexLine; |
142 | qApp->processEvents(); | 144 | qApp->processEvents(); |
143 | 145 | ||
146 | bool okToRead = false; | ||
144 | while ( !indexStream.eof() ) { | 147 | while ( !indexStream.eof() ) { |
145 | |||
146 | indexLine = indexStream.readLine(); | 148 | indexLine = indexStream.readLine(); |
147 | if ( indexLine != "") { | 149 | if(indexLine == "<==Start GUTINDEX.ALL listings==>") |
148 | 150 | okToRead = true; | |
149 | if( (indexLine.mid(4,4)).toInt() ) { | 151 | if(indexLine == "<==End of GUTINDEX.ALL==>") { |
150 | 152 | okToRead = false; | |
151 | year = indexLine.mid(4,4); | 153 | indexLib.at(indexLib.size()); |
152 | file = indexLine.mid(60,12); | ||
153 | if(file.left(1).find("[",0,TRUE) != -1) | ||
154 | file.remove(1,1); | ||
155 | if( file.find("]",0,TRUE) != -1) | ||
156 | file = file.left( file.find("]",0,TRUE)); | ||
157 | |||
158 | if(file.find("?", 0, false) != -1 ) { | ||
159 | QString tmpfile = file.replace(QRegExp("[?]"), "8"); | ||
160 | file = tmpfile; | ||
161 | } | ||
162 | |||
163 | number = indexLine.mid(55,5); | ||
164 | title = indexLine.mid( 9, 50 ); | ||
165 | |||
166 | addItems(); | ||
167 | |||
168 | } | ||
169 | else if ( indexLine.mid(73,5).toInt() && indexLine.mid(73,5).toInt() > 10000 ) { | ||
170 | // newer files with numbers > 100000 have new dir structure and need to be parsed differently.. | ||
171 | number = indexLine.mid(73,5); | ||
172 | int num = number.toInt(); | ||
173 | if(num < 10626) | ||
174 | year = "2003"; | ||
175 | else if(num >= 10626 && num < 14600) | ||
176 | year = "2004"; | ||
177 | else if(num >= 14600) | ||
178 | year = "2005"; | ||
179 | |||
180 | file = number;// + ".txt"; | ||
181 | title = indexLine.mid(0,72); | ||
182 | |||
183 | addItems(); | ||
184 | //qDebug("file number is " + number + " title is " + title ); | ||
185 | } | ||
186 | } | 154 | } |
155 | |||
156 | if(okToRead) { | ||
157 | QStringList token = QStringList::split(' ', indexLine); | ||
158 | int textNumber; | ||
159 | if(( textNumber = token.last().toInt() )) | ||
160 | if(textNumber > 10001) { | ||
161 | // qWarning("Last "+token.last()); | ||
162 | // newer files with numbers > 100000 have new dir structure and need to be parsed differently.. | ||
163 | if(textNumber < 10626) | ||
164 | year = "2003"; | ||
165 | else if(textNumber >= 10626 && textNumber < 14600) | ||
166 | year = "2004"; | ||
167 | else if(textNumber >= 14600) | ||
168 | year = "2005"; | ||
169 | |||
170 | file = token.last(); | ||
171 | title = indexLine.mid(0,72); | ||
172 | |||
173 | addItems(); //author and qlistview | ||
174 | //qDebug("file number is " + number + " title is " + title ); | ||
175 | |||
176 | } else { //end new etexts | ||
177 | |||
178 | if(token[1].toInt() && token[1].toInt() > 1969) { | ||
179 | year = token[1]; | ||
180 | file = indexLine.mid(60,12); | ||
181 | |||
182 | if(file.left(1).find("[",0,TRUE) != -1) { | ||
183 | file.remove(1,1); | ||
184 | if( file.find("]",0,TRUE) != -1) | ||
185 | file = file.left( file.find("]",0,TRUE)); | ||
186 | |||
187 | if(file.find("?", 0, false) != -1 ) { | ||
188 | QString tmpfile = file.replace(QRegExp("[?]"), "8"); | ||
189 | file = tmpfile; | ||
190 | } | ||
191 | title = indexLine.mid( 9, 50); | ||
192 | |||
193 | addItems(); | ||
194 | } | ||
195 | } else { // then try new format texts | ||
196 | file = token.last(); | ||
197 | title = indexLine.mid(0,72); | ||
198 | year = "1980"; | ||
199 | |||
200 | addItems(); //author and qlistview | ||
201 | } | ||
202 | } //end old etexts | ||
203 | |||
204 | } //end okToTRead | ||
187 | } | 205 | } |
188 | indexLib.close(); | 206 | indexLib.close(); |
189 | } else { | 207 | } else { |
190 | QString sMsg; | 208 | QString sMsg; |
191 | 209 | ||
192 | sMsg = ( tr("<p>Error opening library index file. Please download a new one.</P> ")); | 210 | sMsg = ( tr("<p>Error opening library index file. Please download a new one.</P> ")); |
193 | QMessageBox::message( "Error",sMsg); | 211 | QMessageBox::message( "Error",sMsg); |
194 | } | 212 | } |
213 | system("date"); | ||
214 | sortLists(0); | ||
215 | |||
195 | } //end Library() | 216 | } //end Library() |
196 | 217 | ||
197 | 218 | ||
198 | /* | 219 | /* |
@@ -302,35 +323,42 @@ bool LibraryDialog::getAuthor() | |||
302 | } | 323 | } |
303 | return true; | 324 | return true; |
304 | }////// end getAuthor() | 325 | }////// end getAuthor() |
305 | 326 | ||
306 | void LibraryDialog::addItems() { | 327 | void LibraryDialog::addItems() |
328 | { | ||
307 | cleanStrings(); | 329 | cleanStrings(); |
308 | getAuthor(); // grok author | 330 | getAuthor(); // grok author |
309 | if( !number.isEmpty() | 331 | |
310 | && (title.find( "reserved",0, FALSE) == -1) | 332 | etext etextStruct; |
333 | if( /*!number.isEmpty() | ||
334 | && */ | ||
335 | (title.find( "reserved",0, FALSE) == -1) | ||
311 | && (file.find( "]",0, true) == -1) | 336 | && (file.find( "]",0, true) == -1) |
312 | &&(title.find( "Audio",0, FALSE) == -1)) { | 337 | &&(title.find( "Audio",0, FALSE) == -1)) { |
313 | // qDebug("new item "+title); | 338 | // qDebug("new item "+title); |
314 | // fill string list or something to be able to sort by Author | 339 | // fill string list or something to be able to sort by Author |
340 | etextStruct.title = title; | ||
341 | etextStruct.author = author; | ||
342 | etextStruct.year = year; | ||
343 | etextStruct.file = file; | ||
344 | |||
345 | etextLibrary.append( etextStruct); | ||
346 | |||
315 | if( author.isEmpty() ) | 347 | if( author.isEmpty() ) |
316 | QList_Item5 = new QListViewItem( ListView5, /*number, */title, author, year, file ); | 348 | QList_Item5 = new QListViewItem( ListView5, /*number, */author, title, year, file ); |
317 | else { | 349 | else { |
318 | if( (author.left(1) >= QString("A") && author.left(1) <= QString("F")) || | 350 | if( author.find(QRegExp("[^a-fA-F]")) ) |
319 | (author.left(1) >= QString("a") && author.left(1) <= QString("f")) ) | 351 | QList_Item1 = new QListViewItem( ListView1, /* number,*/author, title, year, file ); |
320 | QList_Item1 = new QListViewItem( ListView1, /* number,*/ title, author, year, file ); | ||
321 | 352 | ||
322 | else if( (author.left(1) >= QString("G") && author.left(1) <= QString("M")) || | 353 | else if(author.find(QRegExp("[^g-mG-M]")) ) |
323 | (author.left(1) >= QString("g") && author.left(1) <= QString("m")) ) | 354 | QList_Item2 = new QListViewItem( ListView2, /* number,*/ author, title,year, file ); |
324 | QList_Item2 = new QListViewItem( ListView2, /* number,*/ title, author, year, file ); | ||
325 | 355 | ||
326 | else if( (author.left(1) >= QString("N") && author.left(1) <= QString("R")) || | 356 | else if(author.find(QRegExp("[^n-rN-R]")) ) |
327 | (author.left(1) >= QString("n") && author.left(1) <= QString("r")) ) | 357 | QList_Item3 = new QListViewItem( ListView3, /* number,*/ author, title, year, file ); |
328 | QList_Item3 = new QListViewItem( ListView3, /* number,*/ title, author, year, file ); | ||
329 | 358 | ||
330 | else if( (author.left(1) >= QString("S") && author.left(1) <= QString("Z")) || | 359 | else if(author.find(QRegExp("[^s-zS-Z]")) ) |
331 | (author.left(1) >= QString("s") && author.left(1) <= QString("z")) ) | 360 | QList_Item4 = new QListViewItem( ListView4, /* number,*/ author, title, year, file ); |
332 | QList_Item4 = new QListViewItem( ListView4, /* number,*/ title, author, year, file ); | ||
333 | } | 361 | } |
334 | } | 362 | } |
335 | } | 363 | } |
336 | 364 | ||
@@ -674,88 +702,29 @@ void LibraryDialog::onButtonSearch() | |||
674 | if( searchDlg->exec() != 0 ) { | 702 | if( searchDlg->exec() != 0 ) { |
675 | QString searcherStr = searchDlg->get_text(); | 703 | QString searcherStr = searchDlg->get_text(); |
676 | int fluff = 0; | 704 | int fluff = 0; |
677 | 705 | ||
678 | // int tabPage = tabWidget->currentPageIndex(); | ||
679 | // TODO ititerate here... struct<listViews>?? | ||
680 | |||
681 | QListViewItemIterator it1( ListView1 ); | ||
682 | QListViewItemIterator it2( ListView2 ); | ||
683 | QListViewItemIterator it3( ListView3 ); | ||
684 | QListViewItemIterator it4( ListView4 ); | ||
685 | QListViewItemIterator it5( ListView5 ); | ||
686 | |||
687 | //// this is really pitiful work, | ||
688 | /////// | ||
689 | bool cS; | 706 | bool cS; |
690 | if( searchDlg->caseSensitiveCheckBox->isChecked()) | 707 | if( searchDlg->caseSensitiveCheckBox->isChecked()) |
691 | cS=true; //case sensitive | 708 | cS = true; //case sensitive |
692 | else | 709 | else |
693 | cS=false; | 710 | cS = false; |
694 | 711 | ||
695 | if(fluff==0) { | 712 | etext etextStruct; |
696 | for ( ; it1.current(); ++it1 ) { | 713 | QValueList<etext>::Iterator it; |
697 | resultString = ( it1.current() )->text(0); | 714 | |
698 | resultString += (" : "); | 715 | for( it = etextLibrary.begin(); it != etextLibrary.end(); ++it ) { |
699 | resultString += ( it1.current() )->text(2); | 716 | QString tempTitle = (*it).title; |
700 | resultString += (" : "); | 717 | QString tempAuthor = (*it).author; |
701 | resultString += ( it1.current() )->text(3); | 718 | QString tempFile = (*it).file; |
702 | if( resultString.find( searcherStr, 0, cS) != -1) | 719 | QString tempYear = (*it).year; |
703 | { | 720 | if(tempTitle.find( searcherStr, 0, cS) != -1 |
704 | Searchlist.append( resultString); | 721 | || tempAuthor.find( searcherStr, 0, cS) != -1) { |
705 | } | 722 | qWarning(tempTitle); |
706 | } | 723 | Searchlist.append( tempTitle + " : " + tempYear + " : " + tempFile); |
707 | } | 724 | } |
708 | if(fluff==0) {// search routine here | 725 | } |
709 | for ( ; it2.current(); ++it2 ) { | 726 | |
710 | resultString = ( it2.current() )->text(0); | ||
711 | resultString += (" : "); | ||
712 | resultString += ( it2.current() )->text(2); | ||
713 | resultString += (" : "); | ||
714 | resultString += ( it2.current() )->text(3); | ||
715 | if( resultString.find( searcherStr, 0, cS) != -1) { | ||
716 | Searchlist.append( resultString); | ||
717 | } | ||
718 | } | ||
719 | } | ||
720 | if(fluff==0) {// search routine here | ||
721 | for ( ; it3.current(); ++it3 ) { | ||
722 | resultString = ( it3.current() )->text(0); | ||
723 | resultString += (" : "); | ||
724 | resultString += ( it3.current() )->text(2); | ||
725 | resultString += (" : "); | ||
726 | resultString += ( it3.current() )->text(3); | ||
727 | |||
728 | if( resultString.find( searcherStr, 0, cS) != -1) { | ||
729 | Searchlist.append( resultString); | ||
730 | } | ||
731 | } | ||
732 | } | ||
733 | if(fluff==0) { | ||
734 | // search routine here | ||
735 | for ( ; it4.current(); ++it4 ) { | ||
736 | resultString = ( it4.current() )->text(0); | ||
737 | resultString += (" : "); | ||
738 | resultString += ( it4.current() )->text(2); | ||
739 | resultString += (" : "); | ||
740 | resultString += ( it4.current() )->text(3); | ||
741 | if( resultString.find( searcherStr, 0, cS) != -1) { | ||
742 | Searchlist.append( resultString); | ||
743 | } | ||
744 | } | ||
745 | } | ||
746 | if(fluff==0) { // search routine here | ||
747 | for ( ; it5.current(); ++it5 ) { | ||
748 | resultString = ( it5.current() )->text(0); | ||
749 | resultString += (" : "); | ||
750 | resultString += ( it5.current() )->text(2); | ||
751 | resultString += (" : "); | ||
752 | resultString += ( it5.current() )->text(3); | ||
753 | if( resultString.find( searcherStr, 0, cS) != -1) { | ||
754 | Searchlist.append( resultString); | ||
755 | } | ||
756 | } | ||
757 | } | ||
758 | 727 | ||
759 | tabWidget->setCurrentPage( curTab); | 728 | tabWidget->setCurrentPage( curTab); |
760 | 729 | ||
761 | Searchlist.sort(); | 730 | Searchlist.sort(); |
@@ -772,10 +741,8 @@ void LibraryDialog::onButtonSearch() | |||
772 | resultLs.clear(); | 741 | resultLs.clear(); |
773 | } | 742 | } |
774 | Searchlist.clear(); | 743 | Searchlist.clear(); |
775 | 744 | ||
776 | // if(SearchResultsDialog) | ||
777 | // delete SearchResultsDialog; | ||
778 | QString tester; | 745 | QString tester; |
779 | for ( QStringList::Iterator it = resultLs.begin(); it != resultLs.end(); ++it ) { | 746 | for ( QStringList::Iterator it = resultLs.begin(); it != resultLs.end(); ++it ) { |
780 | texter.sprintf("%s \n",(*it).latin1()); | 747 | texter.sprintf("%s \n",(*it).latin1()); |
781 | // //odebug << texter << oendl; | 748 | // //odebug << texter << oendl; |
@@ -819,20 +786,30 @@ void LibraryDialog::parseSearchResults( QString resultStr) | |||
819 | if(DlglistItemFile.left(1) == "/") | 786 | if(DlglistItemFile.left(1) == "/") |
820 | DlglistItemFile = DlglistItemFile.right( DlglistItemFile.length() - 1); | 787 | DlglistItemFile = DlglistItemFile.right( DlglistItemFile.length() - 1); |
821 | 788 | ||
822 | 789 | ||
823 | if(DlglistItemFile.toInt() > 10000 ) { | 790 | if(DlglistItemFile.toInt() > 10000 || yearInt == 1980 ) { |
824 | // new directory sturcture | 791 | // new directory sturcture |
825 | download_newEtext(); //) | 792 | download_newEtext(); //) |
826 | } else { | 793 | } else { |
827 | download_Etext(); //) | 794 | download_Etext(); //) |
828 | } | 795 | } |
829 | } | 796 | } |
830 | } | 797 | } |
831 | 798 | ||
832 | void LibraryDialog::sort() | 799 | void LibraryDialog::sortLists(int index) |
833 | { | 800 | { |
834 | 801 | ||
802 | ListView1->setSorting(index); | ||
803 | ListView2->setSorting(index); | ||
804 | ListView3->setSorting(index); | ||
805 | ListView4->setSorting(index); | ||
806 | ListView5->setSorting(index); | ||
807 | ListView1->sort(); | ||
808 | ListView2->sort(); | ||
809 | ListView3->sort(); | ||
810 | ListView4->sort(); | ||
811 | ListView5->sort(); | ||
835 | } | 812 | } |
836 | 813 | ||
837 | /* | 814 | /* |
838 | Downloads the current selected listitem*/ | 815 | Downloads the current selected listitem*/ |
@@ -1049,9 +1026,9 @@ void LibraryDialog::FindLibrary() | |||
1049 | indexLib.setName( old_index); | 1026 | indexLib.setName( old_index); |
1050 | //odebug << "new index nameis "+ old_index << oendl; | 1027 | //odebug << "new index nameis "+ old_index << oendl; |
1051 | Library(); | 1028 | Library(); |
1052 | } | 1029 | } |
1053 | indexLoaded=true; | 1030 | indexLoaded =true; |
1054 | buttonSearch->setEnabled(true); | 1031 | buttonSearch->setEnabled(true); |
1055 | moreInfoButton->setEnabled(true); | 1032 | moreInfoButton->setEnabled(true); |
1056 | 1033 | ||
1057 | buttonLibrary->setDown(false); | 1034 | buttonLibrary->setDown(false); |
@@ -1066,4 +1043,10 @@ void LibraryDialog::cleanStrings() { | |||
1066 | title = title.stripWhiteSpace(); | 1043 | title = title.stripWhiteSpace(); |
1067 | number = number.stripWhiteSpace(); | 1044 | number = number.stripWhiteSpace(); |
1068 | 1045 | ||
1069 | } | 1046 | } |
1047 | |||
1048 | void LibraryDialog::authBoxClicked() | ||
1049 | { | ||
1050 | qApp->processEvents(); | ||
1051 | FindLibrary(); | ||
1052 | } | ||