summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2005-08-24 20:22:10 (UTC)
committer llornkcor <llornkcor>2005-08-24 20:22:10 (UTC)
commit65edeafe2dc8689dce7c2ce94e954933b393dcf0 (patch) (unidiff)
tree17d0986ef0bce73f44a4b9900466fcc533954814
parentf0bb6c410f19d502cf563254d95158617a32b94e (diff)
downloadopie-65edeafe2dc8689dce7c2ce94e954933b393dcf0.zip
opie-65edeafe2dc8689dce7c2ce94e954933b393dcf0.tar.gz
opie-65edeafe2dc8689dce7c2ce94e954933b393dcf0.tar.bz2
optimize search. fix other things
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-gutenbrowser/LibraryDialog.cpp265
-rw-r--r--noncore/apps/opie-gutenbrowser/LibraryDialog.h15
-rw-r--r--noncore/apps/opie-gutenbrowser/LibraryDialogData.cpp90
3 files changed, 170 insertions, 200 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
@@ -138,3 +138,5 @@ void LibraryDialog::Library() {
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 );
@@ -142,46 +144,62 @@ void LibraryDialog::Library() {
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 }
@@ -194,2 +212,5 @@ void LibraryDialog::Library() {
194 } 212 }
213 system("date");
214 sortLists(0);
215
195} //end Library() 216} //end Library()
@@ -305,7 +326,11 @@ bool LibraryDialog::getAuthor()
305 326
306void LibraryDialog::addItems() { 327void 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)
@@ -314,20 +339,23 @@ void LibraryDialog::addItems() {
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 }
@@ -677,82 +705,23 @@ void LibraryDialog::onButtonSearch()
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
@@ -775,4 +744,2 @@ void LibraryDialog::onButtonSearch()
775 744
776 // if(SearchResultsDialog)
777 // delete SearchResultsDialog;
778 QString tester; 745 QString tester;
@@ -822,3 +789,3 @@ void LibraryDialog::parseSearchResults( QString resultStr)
822 789
823 if(DlglistItemFile.toInt() > 10000 ) { 790 if(DlglistItemFile.toInt() > 10000 || yearInt == 1980 ) {
824 // new directory sturcture 791 // new directory sturcture
@@ -831,5 +798,15 @@ void LibraryDialog::parseSearchResults( QString resultStr)
831 798
832void LibraryDialog::sort() 799void 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}
@@ -1052,3 +1029,3 @@ void LibraryDialog::FindLibrary()
1052 } 1029 }
1053 indexLoaded=true; 1030 indexLoaded =true;
1054 buttonSearch->setEnabled(true); 1031 buttonSearch->setEnabled(true);
@@ -1069 +1046,7 @@ void LibraryDialog::cleanStrings() {
1069} 1046}
1047
1048void LibraryDialog::authBoxClicked()
1049{
1050 qApp->processEvents();
1051 FindLibrary();
1052}
diff --git a/noncore/apps/opie-gutenbrowser/LibraryDialog.h b/noncore/apps/opie-gutenbrowser/LibraryDialog.h
index 8d6352f..95226b2 100644
--- a/noncore/apps/opie-gutenbrowser/LibraryDialog.h
+++ b/noncore/apps/opie-gutenbrowser/LibraryDialog.h
@@ -32,2 +32,3 @@
32#include <qtabwidget.h> 32#include <qtabwidget.h>
33#include <qvaluelist.h>
33 34
@@ -43,2 +44,10 @@ class QWidget;
43 44
45typedef struct {
46 QString title;
47 QString author;
48 QString year;
49 QString file;
50} etext;
51
52
44class LibraryDialog : public QDialog { 53class LibraryDialog : public QDialog {
@@ -101,3 +110,3 @@ public slots:
101 void cancelIt(); 110 void cancelIt();
102 void sort(); 111 void sortLists(int);
103 bool moreInfo(); 112 bool moreInfo();
@@ -120,2 +129,4 @@ protected:
120 129
130 QValueList<etext> etextLibrary;
131
121 void initDialog(); 132 void initDialog();
@@ -129,2 +140,4 @@ private:
129 bool getEtext(const QStringList &); 140 bool getEtext(const QStringList &);
141private slots:
142 void authBoxClicked();
130 143
diff --git a/noncore/apps/opie-gutenbrowser/LibraryDialogData.cpp b/noncore/apps/opie-gutenbrowser/LibraryDialogData.cpp
index 60c1c75..bfbf84d 100644
--- a/noncore/apps/opie-gutenbrowser/LibraryDialogData.cpp
+++ b/noncore/apps/opie-gutenbrowser/LibraryDialogData.cpp
@@ -74,11 +74,8 @@ void LibraryDialog::initDialog(){
74 74
75 ListView1->addColumn( tr( "Title" ) ); 75 ListView1->addColumn( tr( "Author" ), -1 );
76 ListView1->setColumnWidthMode( 0, QListView::Manual ); 76 ListView1->setColumnAlignment( 1, 1 );
77 ListView1->setColumnWidth(0, 330); 77
78 ListView1->addColumn( tr( "Title" ), -1 );
78 ListView1->setColumnAlignment( 0, 1 ); 79 ListView1->setColumnAlignment( 0, 1 );
79 80
80 ListView1->addColumn( tr( "Author" ) );
81 ListView1->setColumnWidthMode( 1, QListView::Manual );
82 ListView1->setColumnWidth(1, 170);
83 ListView1->setColumnAlignment( 1, 1 );
84 81
@@ -86,48 +83,36 @@ void LibraryDialog::initDialog(){
86 ListView1->setColumnWidthMode( 2, QListView::Manual ); 83 ListView1->setColumnWidthMode( 2, QListView::Manual );
87 ListView1->setColumnWidth(2, 50);
88 ListView1->setColumnAlignment( 2, 1 ); 84 ListView1->setColumnAlignment( 2, 1 );
89 85
90 ListView1->addColumn( tr( "File" ) ); 86 ListView1->addColumn( tr( "File" ), -1 );
91 ListView1->setColumnWidthMode( 2, QListView::Manual ); 87 ListView1->setColumnWidthMode( 2, QListView::Manual );
92 ListView1->setColumnWidth(2, 100);
93 ListView1->setColumnAlignment( 2, 1 );
94 88
95 ListView2->addColumn( tr( "Title" ) ); 89 ListView1->setColumnAlignment( 2, 1 );
96 ListView2->setColumnWidthMode( 0, QListView::Manual );
97 ListView2->setColumnWidth(0, 330);
98 ListView2->setColumnAlignment( 0, 1 );
99 90
100 ListView2->addColumn( tr( "Author" ) ); 91 ListView2->addColumn( tr( "Author" ), -1 );
101 ListView2->setColumnWidthMode( 1, QListView::Manual );
102 ListView2->setColumnWidth(1, 170);
103 ListView2->setColumnAlignment( 1, 1 ); 92 ListView2->setColumnAlignment( 1, 1 );
104 93
105 ListView2->addColumn( tr( "Year" ) ); 94 ListView2->addColumn( tr( "Title" ), -1);
95 ListView2->setColumnAlignment( 0, 1 );
96
97 ListView2->addColumn( tr( "Year" ), -1 );
106 ListView2->setColumnWidthMode( 2, QListView::Manual ); 98 ListView2->setColumnWidthMode( 2, QListView::Manual );
107 ListView2->setColumnWidth(2, 50);
108 ListView2->setColumnAlignment( 2, 1 ); 99 ListView2->setColumnAlignment( 2, 1 );
109 100
110 ListView2->addColumn( tr( "File" ) ); 101 ListView2->addColumn( tr( "File" ), -1 );
111 ListView2->setColumnWidthMode( 3, QListView::Manual ); 102 ListView2->setColumnWidthMode( 3, QListView::Manual );
112 ListView2->setColumnWidth(3, 100);
113 ListView2->setColumnAlignment( 3, 1 ); 103 ListView2->setColumnAlignment( 3, 1 );
114 104
115 ListView3->addColumn( tr( "Title" ) ); 105 ListView3->addColumn( tr( "Author" ), -1 );
116 ListView3->setColumnWidthMode( 0, QListView::Manual ); 106 ListView3->setColumnAlignment( 1, 1 );
117 ListView3->setColumnWidth(0, 330); 107
108 ListView3->addColumn( tr( "Title" ), -1 );
118 ListView3->setColumnAlignment( 0, 1 ); 109 ListView3->setColumnAlignment( 0, 1 );
119 110
120 ListView3->addColumn( tr( "Author" ) );
121 ListView3->setColumnWidthMode( 1, QListView::Manual );
122 ListView3->setColumnWidth(1, 170);
123 ListView3->setColumnAlignment( 1, 1 );
124 111
125 ListView3->addColumn( tr( "Year" ) ); 112 ListView3->addColumn( tr( "Year" ), -1 );
126 ListView3->setColumnWidthMode( 2, QListView::Manual ); 113 ListView3->setColumnWidthMode( 2, QListView::Manual );
127 ListView3->setColumnWidth(2, 50);
128 ListView3->setColumnAlignment( 2, 1 ); 114 ListView3->setColumnAlignment( 2, 1 );
129 115
130 ListView3->addColumn( tr( "File" ) ); 116 ListView3->addColumn( tr( "File" ), -1 );
131 ListView3->setColumnWidthMode( 3, QListView::Manual ); 117 ListView3->setColumnWidthMode( 3, QListView::Manual );
132 ListView3->setColumnWidth(3, 100);
133 ListView3->setColumnAlignment( 3, 1 ); 118 ListView3->setColumnAlignment( 3, 1 );
@@ -135,40 +120,28 @@ void LibraryDialog::initDialog(){
135 120
136 ListView4->addColumn( tr( "Title" ) ); 121 ListView4->addColumn( tr( "Author" ), -1 );
137 ListView4->setColumnWidthMode( 0, QListView::Manual );
138 ListView4->setColumnWidth(0, 330);
139 ListView4->setColumnAlignment( 0, 1 );
140
141 ListView4->addColumn( tr( "Author" ) );
142 ListView4->setColumnWidthMode( 1, QListView::Manual );
143 ListView4->setColumnWidth(1, 170);
144 ListView4->setColumnAlignment( 1, 1 ); 122 ListView4->setColumnAlignment( 1, 1 );
123 ListView4->addColumn( tr( "Title" ), -1 );
124 ListView4->setColumnAlignment( 0, 1 );
145 125
146 ListView4->addColumn( tr( "Year" ) ); 126 ListView4->addColumn( tr( "Year" ), -1 );
147 ListView4->setColumnWidthMode( 2, QListView::Manual ); 127 ListView4->setColumnWidthMode( 2, QListView::Manual );
148 ListView4->setColumnWidth(2, 50);
149 ListView4->setColumnAlignment( 2, 1 ); 128 ListView4->setColumnAlignment( 2, 1 );
150 129
151 ListView4->addColumn( tr( "File" ) ); 130 ListView4->addColumn( tr( "File" ), -1 );
152 ListView4->setColumnWidthMode( 3, QListView::Manual ); 131 ListView4->setColumnWidthMode( 3, QListView::Manual );
153 ListView4->setColumnWidth(3, 100);
154 ListView4->setColumnAlignment( 3, 1 ); 132 ListView4->setColumnAlignment( 3, 1 );
155 133
156 ListView5->addColumn( tr( "Title" ) ); 134 ListView5->addColumn( tr( "Author" ), -1 );
157 ListView5->setColumnWidthMode( 0, QListView::Manual ); 135 ListView5->setColumnAlignment( 1, 1 );
158 ListView5->setColumnWidth(0, 330); 136
137 ListView5->addColumn( tr( "Title" ), -1 );
159 ListView5->setColumnAlignment( 0, 1 ); 138 ListView5->setColumnAlignment( 0, 1 );
160 139
161 ListView5->addColumn( tr( "Author" ) );
162 ListView5->setColumnWidthMode( 1, QListView::Manual );
163 ListView5->setColumnWidth(1, 170);
164 ListView5->setColumnAlignment( 1, 1 );
165 140
166 ListView5->addColumn( tr( "Year" ) ); 141 ListView5->addColumn( tr( "Year" ), -1 );
167 ListView5->setColumnWidthMode( 2, QListView::Manual ); 142 ListView5->setColumnWidthMode( 2, QListView::Manual );
168 ListView5->setColumnWidth(2, 50);
169 ListView5->setColumnAlignment( 2, 1 ); 143 ListView5->setColumnAlignment( 2, 1 );
170 144
171 ListView5->addColumn( tr( "File" ) ); 145 ListView5->addColumn( tr( "File" ), -1 );
172 ListView5->setColumnWidthMode( 3, QListView::Manual ); 146 ListView5->setColumnWidthMode( 3, QListView::Manual );
173 ListView5->setColumnWidth(3, 100);
174 ListView5->setColumnAlignment( 3, 1 ); 147 ListView5->setColumnAlignment( 3, 1 );
@@ -209,4 +182,4 @@ void LibraryDialog::initDialog(){
209// QToolTip::add( httpBox, ( tr("Use http to download \nproxy users should probably use this.")) ); 182// QToolTip::add( httpBox, ( tr("Use http to download \nproxy users should probably use this.")) );
210 authBox= new QCheckBox( ( tr("Last name first \n(requires library restart)")),widget_6); 183 authBox= new QCheckBox( ( tr("Last name first.")),widget_6);
211 authBox->setChecked( FALSE); 184 authBox->setChecked( true);
212 185
@@ -274,2 +247,3 @@ void LibraryDialog::initDialog(){
274 connect(ListView5,SIGNAL(returnPressed(QListViewItem*)),SLOT(select_title(QListViewItem*))); 247 connect(ListView5,SIGNAL(returnPressed(QListViewItem*)),SLOT(select_title(QListViewItem*)));
248 connect(authBox,SIGNAL(clicked()),this,SLOT(authBoxClicked()));
275 249