summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-gutenbrowser
Unidiff
Diffstat (limited to 'noncore/apps/opie-gutenbrowser') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-gutenbrowser/gutenbrowser.cpp26
-rw-r--r--noncore/apps/opie-gutenbrowser/helpwindow.cpp64
2 files changed, 41 insertions, 49 deletions
diff --git a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
index 733db17..8b02f9f 100644
--- a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
+++ b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
@@ -800,112 +800,106 @@ bool Gutenbrowser::load( const char *fileName) {
800 pageStopArray.resize(3); 800 pageStopArray.resize(3);
801 pageStopArray[0] = currentFilePos; 801 pageStopArray[0] = currentFilePos;
802 802
803 fileHandle = f.handle(); 803 fileHandle = f.handle();
804 QString insertString; 804 QString insertString;
805 QTextStream t(&f); 805 QTextStream t(&f);
806 QString s; 806 QString s;
807 for(int fd=0; fd < Lview->PageSize() ;fd++) { 807 for(int fd=0; fd < Lview->PageSize() ;fd++) {
808 s=t.readLine(); 808 s=t.readLine();
809 // insertString+=s; 809 // insertString+=s;
810 if(useWrap) 810 if(useWrap)
811 s.replace(QRegExp("\n"),""); 811 s.replace(QRegExp("\n"),"");
812 // s.replace(QRegExp("\r"),""); 812 // s.replace(QRegExp("\r"),"");
813 Lview->insertLine( s,-1); 813 Lview->insertLine( s,-1);
814 currentLine++; 814 currentLine++;
815 } 815 }
816 816
817 // int length = Lview->length(); 817 // int length = Lview->length();
818 currentFilePos = f.at(); 818 currentFilePos = f.at();
819 819
820 pageStopArray[1] = currentFilePos; 820 pageStopArray[1] = currentFilePos;
821 821
822 odebug << "<<<<<<<<<<<" << currentFilePos << " current page is number " << i_pageNum 822 odebug << "<<<<<<<<<<<" << currentFilePos << " current page is number " << i_pageNum
823 << ", length " << Lview->length() << ", current " << pageStopArray[i_pageNum] 823 << ", length " << Lview->length() << ", current " << pageStopArray[i_pageNum]
824 << ", pageSize " << Lview->PageSize() << oendl; 824 << ", pageSize " << Lview->PageSize() << oendl;
825 825
826 Lview->setMaxLines(Lview->PageSize()*2); 826 Lview->setMaxLines(Lview->PageSize()*2);
827// odebug << "Gulped " << currentLine << "" << oendl; 827// odebug << "Gulped " << currentLine << "" << oendl;
828 setCaption(title); 828 setCaption(title);
829 Lview->setAutoUpdate( TRUE); 829 Lview->setAutoUpdate( TRUE);
830 830
831// Lview->setCursorPosition(0,0,FALSE); 831// Lview->setCursorPosition(0,0,FALSE);
832 832
833 // pages = (int)(( Lview->numLines() / Lview->editSize() ) / 2 ) +1; 833 // pages = (int)(( Lview->numLines() / Lview->editSize() ) / 2 ) +1;
834 //odebug << "number of pages " << pages << "" << oendl; 834 //odebug << "number of pages " << pages << "" << oendl;
835 835
836 loadCheck = true; 836 loadCheck = true;
837 enableButtons(true); 837 enableButtons(true);
838 if( donateMenu->count() == 3) { 838 if( donateMenu->count() == 3) {
839 donateMenu->insertItem("Current Title", this, SLOT( InfoBarClick() )); 839 donateMenu->insertItem("Current Title", this, SLOT( InfoBarClick() ));
840 } 840 }
841 Lview->setFocus(); 841 Lview->setFocus();
842 842
843 // QCopEnvelope("QPE/System", "notBusy()" ); 843 // QCopEnvelope("QPE/System", "notBusy()" );
844 return true; 844 return true;
845} // end load 845} // end load
846 846
847void Gutenbrowser::Search() { 847void Gutenbrowser::Search() {
848 848 odebug << "Starting search dialog" << oendl;
849 // if( searchDlg->isHidden()) 849 searchDlg = new SearchDialog( this, "Etext Search", true);
850 { 850 searchDlg->setCaption( tr( "Etext Search" ));
851 odebug << "Starting search dialog" << oendl; 851 connect( searchDlg,SIGNAL( search_signal()),this,SLOT( search_slot()));
852 searchDlg = new SearchDialog( this, "Etext Search", true); 852 connect( searchDlg,SIGNAL( search_done_signal()),this,SLOT( searchdone_slot()));
853 searchDlg->setCaption( tr( "Etext Search" )); 853
854 // searchDlg->setLabel( "- searches etext"); 854 QString resultString;
855 connect( searchDlg,SIGNAL( search_signal()),this,SLOT( search_slot())); 855 QString string = searchDlg->searchString;
856 connect( searchDlg,SIGNAL( search_done_signal()),this,SLOT( searchdone_slot())); 856 Lview->deselect();
857 857 searchDlg->show();
858 QString resultString;
859 QString string = searchDlg->searchString;
860 Lview->deselect();
861 searchDlg->show();
862 searchDlg->result();
863 }
864} 858}
865 859
866void Gutenbrowser::search_slot( ) { 860void Gutenbrowser::search_slot( ) {
867 int line, col; 861 int line, col;
868 if (!searchDlg /*&& !loadCheck */) 862 if (!searchDlg /*&& !loadCheck */)
869 return; 863 return;
870 864
871 Lview->getCursorPosition(&line,&col); 865 Lview->getCursorPosition(&line,&col);
872 QString to_find_string=searchDlg->get_text(); 866 QString to_find_string=searchDlg->get_text();
873 867
874 // searchDlg->get_direction();// is true if searching backward 868 // searchDlg->get_direction();// is true if searching backward
875 if ( last_search != 0 && searchDlg->get_direction() ){ 869 if ( last_search != 0 && searchDlg->get_direction() ){
876 col = col - pattern.length() - 1 ; 870 col = col - pattern.length() - 1 ;
877 } 871 }
878 again: 872 again:
879 int result = doSearch( to_find_string , /* searchDlg->case_sensitive()*/ TRUE, searchDlg->forward_search(), line, col); 873 int result = doSearch( to_find_string , /* searchDlg->case_sensitive()*/ TRUE, searchDlg->forward_search(), line, col);
880 if(result == 0){ 874 if(result == 0){
881 if(!searchDlg->get_direction()){ // forward search 875 if(!searchDlg->get_direction()){ // forward search
882 int query = QMessageBox::information( searchDlg, "Find", 876 int query = QMessageBox::information( searchDlg, "Find",
883 "End of document reached.\nContinue from the beginning?", 877 "End of document reached.\nContinue from the beginning?",
884 "Yes", "No", "", 0,1); 878 "Yes", "No", "", 0,1);
885 if (query == 0){ 879 if (query == 0){
886 line = 0; 880 line = 0;
887 col = 0; 881 col = 0;
888 goto again; 882 goto again;
889 } 883 }
890 } else { //backward search 884 } else { //backward search
891 int query = QMessageBox::information( searchDlg, "Find", 885 int query = QMessageBox::information( searchDlg, "Find",
892 "End of document reached.\nContinue from the beginning?", 886 "End of document reached.\nContinue from the beginning?",
893 "Yes", "No", "", 0,1); 887 "Yes", "No", "", 0,1);
894 if (query == 0){ 888 if (query == 0){
895 QString string = Lview->textLine( Lview->numLines() - 1 ); 889 QString string = Lview->textLine( Lview->numLines() - 1 );
896 line = Lview->numLines() - 1; 890 line = Lview->numLines() - 1;
897 lineCheck = line; 891 lineCheck = line;
898 col = string.length(); 892 col = string.length();
899 last_search = -1; //BACKWARD; 893 last_search = -1; //BACKWARD;
900 goto again; 894 goto again;
901 } 895 }
902 } 896 }
903 } else { 897 } else {
904 898
905 //// emit CursorPositionChanged(); textLine 899 //// emit CursorPositionChanged(); textLine
906 } 900 }
907} 901}
908 902
909int Gutenbrowser::doSearch( const QString &s_pattern , bool case_sensitive, bool forward, int line, int col ) { 903int Gutenbrowser::doSearch( const QString &s_pattern , bool case_sensitive, bool forward, int line, int col ) {
910 int i, length; 904 int i, length;
911 int pos = -1; 905 int pos = -1;
diff --git a/noncore/apps/opie-gutenbrowser/helpwindow.cpp b/noncore/apps/opie-gutenbrowser/helpwindow.cpp
index 4bdac02..f444a2e 100644
--- a/noncore/apps/opie-gutenbrowser/helpwindow.cpp
+++ b/noncore/apps/opie-gutenbrowser/helpwindow.cpp
@@ -148,186 +148,184 @@ HelpWindow::HelpWindow( const QString& home_, const QString&, QWidget* parent, c
148 148
149 149
150void HelpWindow::setBackwardAvailable( bool b) 150void HelpWindow::setBackwardAvailable( bool b)
151{ 151{
152 menuBar()->setItemEnabled( backwardId, b); 152 menuBar()->setItemEnabled( backwardId, b);
153} 153}
154 154
155void HelpWindow::setForwardAvailable( bool b) 155void HelpWindow::setForwardAvailable( bool b)
156{ 156{
157 menuBar()->setItemEnabled( forwardId, b); 157 menuBar()->setItemEnabled( forwardId, b);
158} 158}
159 159
160 160
161void HelpWindow::textChanged() 161void HelpWindow::textChanged()
162{ 162{
163 if ( browser->documentTitle().isNull() ) { 163 if ( browser->documentTitle().isNull() ) {
164 setCaption( "Gutenbrowser - Helpviewer - " + browser->context() ); 164 setCaption( "Gutenbrowser - Helpviewer - " + browser->context() );
165 selectedURL = browser->context(); 165 selectedURL = browser->context();
166 } 166 }
167 else { 167 else {
168 setCaption( "Gutenbrowser - Helpviewer - " + browser->documentTitle() ) ; 168 setCaption( "Gutenbrowser - Helpviewer - " + browser->documentTitle() ) ;
169 selectedURL = browser->documentTitle(); 169 selectedURL = browser->documentTitle();
170 } 170 }
171 171
172 if ( !selectedURL.isEmpty() && pathCombo ) { 172 if ( !selectedURL.isEmpty() && pathCombo ) {
173 bool exists = FALSE; 173 bool exists = FALSE;
174 int i; 174 int i;
175 for ( i = 0; i < pathCombo->count(); ++i ) { 175 for ( i = 0; i < pathCombo->count(); ++i ) {
176 if ( pathCombo->text( i ) == selectedURL ) { 176 if ( pathCombo->text( i ) == selectedURL ) {
177 exists = TRUE; 177 exists = TRUE;
178 break; 178 break;
179 } 179 }
180 } 180 }
181 if ( !exists ) { 181 if ( !exists ) {
182 pathCombo->insertItem( selectedURL, 0 ); 182 pathCombo->insertItem( selectedURL, 0 );
183 pathCombo->setCurrentItem( 0 ); 183 pathCombo->setCurrentItem( 0 );
184 mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; 184 mHistory[ hist->insertItem( selectedURL ) ] = selectedURL;
185 } else 185 } else
186 pathCombo->setCurrentItem( i ); 186 pathCombo->setCurrentItem( i );
187 selectedURL = QString::null; 187 selectedURL = QString::null;
188 } 188 }
189} 189}
190 190
191HelpWindow::~HelpWindow() 191HelpWindow::~HelpWindow()
192{ 192{
193 history.clear(); 193 history.clear();
194 QMap<int, QString>::Iterator it = mHistory.begin(); 194 QMap<int, QString>::Iterator it = mHistory.begin();
195 for ( ; it != mHistory.end(); ++it ) 195 for ( ; it != mHistory.end(); ++it )
196 history.append( *it ); 196 history.append( *it );
197 197
198 QFile f( QDir::currentDirPath() + "/.history" ); 198 QFile f( QDir::currentDirPath() + "/.history" );
199 f.open( IO_WriteOnly ); 199 if ( f.open( IO_WriteOnly ) ) {
200 QDataStream s( &f ); 200 QDataStream s( &f );
201 s << history; 201 s << history;
202 f.close(); 202 f.close();
203 }
203 204
204 bookmarks.clear(); 205 bookmarks.clear();
205 QMap<int, QString>::Iterator it2 = mBookmarks.begin(); 206 QMap<int, QString>::Iterator it2 = mBookmarks.begin();
206 for ( ; it2 != mBookmarks.end(); ++it2 ) 207 for ( ; it2 != mBookmarks.end(); ++it2 )
207 bookmarks.append( *it2 ); 208 bookmarks.append( *it2 );
208 209
209 QFile f2( QDir::currentDirPath() + "/.bookmarks" ); 210 QFile f2( QDir::currentDirPath() + "/.bookmarks" );
210 f2.open( IO_WriteOnly ); 211 if ( !f2.open( IO_WriteOnly ) )
212 return;
213
211 QDataStream s2( &f2 ); 214 QDataStream s2( &f2 );
212 s2 << bookmarks; 215 s2 << bookmarks;
213 f2.close(); 216 f2.close();
214} 217}
215 218
216// void HelpWindow::about()
217// {
218// QMessageBox::about( this, "Gutenbrowser", "<p>Thanks to Trolltech for this</p>" );
219// }
220
221// void HelpWindow::aboutQt()
222// {
223// QMessageBox::aboutQt( this, "QBrowser" );
224// }
225
226void HelpWindow::openFile() 219void HelpWindow::openFile()
227{ 220{
228#ifndef QT_NO_FILEDIALOG 221#ifndef QT_NO_FILEDIALOG
229 QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this ); 222 QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this );
230 if ( !fn.isEmpty() ) 223 if ( !fn.isEmpty() )
231 browser->setSource( fn ); 224 browser->setSource( fn );
232#endif 225#endif
233} 226}
234 227
235void HelpWindow::newWindow() 228void HelpWindow::newWindow()
236{ 229{
237 ( new HelpWindow(browser->source(), "qbrowser") )->show(); 230 ( new HelpWindow(browser->source(), "qbrowser") )->show();
238} 231}
239 232
240void HelpWindow::print() 233void HelpWindow::print()
241{ 234{
242#ifndef QT_NO_PRINTER 235#ifndef QT_NO_PRINTER
243 QPrinter printer; 236 QPrinter printer;
244 printer.setFullPage(TRUE); 237 printer.setFullPage(TRUE);
245 if ( printer.setup() ) { 238 if ( printer.setup() ) {
246 QPainter p( &printer ); 239 QPainter p( &printer );
247 QPaintDeviceMetrics metrics(p.device()); 240 QPaintDeviceMetrics metrics(p.device());
248 int dpix = metrics.logicalDpiX(); 241 int dpix = metrics.logicalDpiX();
249 int dpiy = metrics.logicalDpiY(); 242 int dpiy = metrics.logicalDpiY();
250 const int margin = 72; // pt 243 const int margin = 72; // pt
251 QRect body(margin*dpix/72, margin*dpiy/72, 244 QRect body(margin*dpix/72, margin*dpiy/72,
252 metrics.width()-margin*dpix/72*2, 245 metrics.width()-margin*dpix/72*2,
253 metrics.height()-margin*dpiy/72*2 ); 246 metrics.height()-margin*dpiy/72*2 );
254 QFont font("times", 10); 247 QFont font("times", 10);
255 QSimpleRichText richText( browser->text(), font, browser->context(), browser->styleSheet(), 248 QSimpleRichText richText( browser->text(), font, browser->context(), browser->styleSheet(),
256 browser->mimeSourceFactory(), body.height() ); 249 browser->mimeSourceFactory(), body.height() );
257 richText.setWidth( &p, body.width() ); 250 richText.setWidth( &p, body.width() );
258 QRect view( body ); 251 QRect view( body );
259 int page = 1; 252 int page = 1;
260 do { 253 do {
261 p.setClipRect( body ); 254 p.setClipRect( body );
262 richText.draw( &p, body.left(), body.top(), view, colorGroup() ); 255 richText.draw( &p, body.left(), body.top(), view, colorGroup() );
263 p.setClipping( FALSE ); 256 p.setClipping( FALSE );
264 view.moveBy( 0, body.height() ); 257 view.moveBy( 0, body.height() );
265 p.translate( 0 , -body.height() ); 258 p.translate( 0 , -body.height() );
266 p.setFont( font ); 259 p.setFont( font );
267 p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ), 260 p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ),
268 view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) ); 261 view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) );
269 if ( view.top() >= richText.height() ) 262 if ( view.top() >= richText.height() )
270 break; 263 break;
271 printer.newPage(); 264 printer.newPage();
272 page++; 265 page++;
273 } while (TRUE); 266 } while (TRUE);
274 } 267 }
275#endif 268#endif
276} 269}
277 270
278void HelpWindow::pathSelected( const QString &_path ) 271void HelpWindow::pathSelected( const QString &_path )
279{ 272{
280 browser->setSource( _path ); 273 browser->setSource( _path );
281 QMap<int, QString>::Iterator it = mHistory.begin(); 274 QMap<int, QString>::Iterator it = mHistory.begin();
282 bool exists = FALSE; 275 bool exists = FALSE;
283 for ( ; it != mHistory.end(); ++it ) { 276 for ( ; it != mHistory.end(); ++it ) {
284 if ( *it == _path ) { 277 if ( *it == _path ) {
285 exists = TRUE; 278 exists = TRUE;
286 break; 279 break;
287 } 280 }
288 } 281 }
289 if ( !exists ) 282 if ( !exists )
290 mHistory[ hist->insertItem( _path ) ] = _path; 283 mHistory[ hist->insertItem( _path ) ] = _path;
291} 284}
292 285
293void HelpWindow::readHistory() 286void HelpWindow::readHistory()
294{ 287{
295 if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) { 288 if ( !QFile::exists( QDir::currentDirPath() + "/.history" ) )
296 QFile f( QDir::currentDirPath() + "/.history" ); 289 return;
297 f.open( IO_ReadOnly ); 290
298 QDataStream s( &f ); 291 QFile f( QDir::currentDirPath() + "/.history" );
299 s >> history; 292 if ( !f.open( IO_ReadOnly ) )
300 f.close(); 293 return;
301 while ( history.count() > 20 ) 294
302 history.remove( history.begin() ); 295 QDataStream s( &f );
303 } 296 s >> history;
297 f.close();
298 while ( history.count() > 20 )
299 history.remove( history.begin() );
304} 300}
305 301
306void HelpWindow::readBookmarks() 302void HelpWindow::readBookmarks()
307{ 303{
308 if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) { 304 if ( !QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) )
309 QFile f( QDir::currentDirPath() + "/.bookmarks" ); 305 return;
310 f.open( IO_ReadOnly ); 306
311 QDataStream s( &f ); 307 QFile f( QDir::currentDirPath() + "/.bookmarks" );
312 s >> bookmarks; 308 if ( !f.open( IO_ReadOnly ) )
313 f.close(); 309 return;
314 } 310 QDataStream s( &f );
311 s >> bookmarks;
312 f.close();
315} 313}
316 314
317void HelpWindow::histChosen( int i ) 315void HelpWindow::histChosen( int i )
318{ 316{
319 if ( mHistory.contains( i ) ) 317 if ( mHistory.contains( i ) )
320 browser->setSource( mHistory[ i ] ); 318 browser->setSource( mHistory[ i ] );
321} 319}
322 320
323void HelpWindow::bookmChosen( int i ) 321void HelpWindow::bookmChosen( int i )
324{ 322{
325 if ( mBookmarks.contains( i ) ) 323 if ( mBookmarks.contains( i ) )
326 browser->setSource( mBookmarks[ i ] ); 324 browser->setSource( mBookmarks[ i ] );
327} 325}
328 326
329void HelpWindow::addBookmark() 327void HelpWindow::addBookmark()
330{ 328{
331 mBookmarks[ bookm->insertItem( caption() ) ] = caption(); 329 mBookmarks[ bookm->insertItem( caption() ) ] = caption();
332} 330}
333 331