summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-07-16 23:46:36 (UTC)
committer llornkcor <llornkcor>2002-07-16 23:46:36 (UTC)
commit238f77dac6c82b420e2e6334fabf9b7744abd844 (patch) (unidiff)
tree23771c76cb5ffa8da248ae4977ec13e36c5cb62f
parent6d5261a534612f0f993caca801e7c7e1a5c74f32 (diff)
downloadopie-238f77dac6c82b420e2e6334fabf9b7744abd844.zip
opie-238f77dac6c82b420e2e6334fabf9b7744abd844.tar.gz
opie-238f77dac6c82b420e2e6334fabf9b7744abd844.tar.bz2
fix for initial start crash when there's no config file
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/QTReader.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index fc9cffb..6335ea2 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -548,256 +548,257 @@ void QTReader::ChangeFont(int tgt)
548 m_textsize = best; 548 m_textsize = best;
549 fontsizes[i] = 0; 549 fontsizes[i] = 0;
550 setfont(NULL); 550 setfont(NULL);
551 QFont font(m_fontname, fontsizes[m_textsize], (m_bBold) ? QFont::Bold : QFont::Normal ); 551 QFont font(m_fontname, fontsizes[m_textsize], (m_bBold) ? QFont::Bold : QFont::Normal );
552 if (m_fm == NULL) 552 if (m_fm == NULL)
553 { 553 {
554 m_fm = new QFontMetrics(font); 554 m_fm = new QFontMetrics(font);
555 buffdoc.setfm(m_fm); 555 buffdoc.setfm(m_fm);
556 } 556 }
557} 557}
558 558
559void QTReader::init() 559void QTReader::init()
560{ 560{
561 // setCaption( "Qt Draw Demo Application" ); 561 // setCaption( "Qt Draw Demo Application" );
562 562
563 setBackgroundColor( white ); 563 setBackgroundColor( white );
564// QPainter p(this); 564// QPainter p(this);
565// p.setBackgroundMode( Qt::OpaqueMode ); 565// p.setBackgroundMode( Qt::OpaqueMode );
566 buffdoc.setfilter(getfilter()); 566 buffdoc.setfilter(getfilter());
567 ChangeFont(m_textsize); 567 ChangeFont(m_textsize);
568 // setFocusPolicy(QWidget::StrongFocus); 568 // setFocusPolicy(QWidget::StrongFocus);
569 // resize( 240, 320 ); 569 // resize( 240, 320 );
570 //setFocus(); 570 //setFocus();
571 timer = new QTimer(this); 571 timer = new QTimer(this);
572 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll())); 572 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll()));
573// QMessageBox::information(this, "init", m_lastfile, 1); 573// QMessageBox::information(this, "init", m_lastfile, 1);
574 m_lastwidth = width(); 574 m_lastwidth = width();
575 if (!m_lastfile.isEmpty()) 575 if (!m_lastfile.isEmpty())
576 { 576 {
577 m_string = DocLnk(m_lastfile).name(); 577 m_string = DocLnk(m_lastfile).name();
578 load_file(m_lastfile); 578 load_file(m_lastfile);
579 } 579 }
580} 580}
581 581
582// 582//
583// Clean up 583// Clean up
584// 584//
585QTReader::~QTReader() 585QTReader::~QTReader()
586{ 586{
587 if (fontsizes != NULL) delete [] fontsizes; 587 if (fontsizes != NULL) delete [] fontsizes;
588#ifndef QT_NO_PRINTER 588#ifndef QT_NO_PRINTER
589 // delete printer; 589 // delete printer;
590#endif 590#endif
591} 591}
592 592
593// 593//
594// Calls the drawing function as specified by the radio buttons. 594// Calls the drawing function as specified by the radio buttons.
595// 595//
596 596
597void QTReader::drawIt( QPainter *p ) 597void QTReader::drawIt( QPainter *p )
598{ 598{
599 drawFonts(p); 599 drawFonts(p);
600} 600}
601 601
602// 602//
603// Called when the print button is clicked. 603// Called when the print button is clicked.
604// 604//
605/* 605/*
606void QTReader::printIt() 606void QTReader::printIt()
607{ 607{
608#ifndef QT_NO_PRINTER 608#ifndef QT_NO_PRINTER
609 if ( printer->setup( this ) ) { 609 if ( printer->setup( this ) ) {
610 QPainter paint; 610 QPainter paint;
611 if ( !paint.begin( printer ) ) 611 if ( !paint.begin( printer ) )
612 return; 612 return;
613 drawIt( &paint ); 613 drawIt( &paint );
614 } 614 }
615#endif 615#endif
616} 616}
617*/ 617*/
618// 618//
619// Called when the widget needs to be updated. 619// Called when the widget needs to be updated.
620// 620//
621 621
622void QTReader::paintEvent( QPaintEvent * ) 622void QTReader::paintEvent( QPaintEvent * )
623{ 623{
624 QPainter paint( this ); 624 QPainter paint( this );
625 drawIt( &paint ); 625 drawIt( &paint );
626} 626}
627 627
628// 628//
629// Called when the widget has been resized. 629// Called when the widget has been resized.
630// Moves the button group to the upper right corner 630// Moves the button group to the upper right corner
631// of the widget. 631// of the widget.
632 632
633/* 633/*
634void QTReader::resizeEvent( QResizeEvent * ) 634void QTReader::resizeEvent( QResizeEvent * )
635{ 635{
636 // qDebug("resize:(%u,%u)", width(), height()); 636 // qDebug("resize:(%u,%u)", width(), height());
637 // bgroup->move( width()-bgroup->width(), 0 ); 637 // bgroup->move( width()-bgroup->width(), 0 );
638} 638}
639*/ 639*/
640 640
641// 641//
642// Create and display our widget. 642// Create and display our widget.
643// 643//
644/* 644/*
645int main( int argc, tchar **argv ) 645int main( int argc, tchar **argv )
646{ 646{
647 QApplication app( argc, argv ); 647 QApplication app( argc, argv );
648 QTReader draw; 648 QTReader draw;
649 app.setMainWidget( &draw ); 649 app.setMainWidget( &draw );
650 draw.setCaption("Qt Example - Drawdemo"); 650 draw.setCaption("Qt Example - Drawdemo");
651 draw.show(); 651 draw.show();
652 return app.exec(); 652 return app.exec();
653} 653}
654*/ 654*/
655 655
656 656
657bool QTReader::locate(unsigned long n) { 657bool QTReader::locate(unsigned long n) {
658 //printf("Locate\n"); 658 //printf("Locate\n");
659 buffdoc.locate(n); 659 buffdoc.locate(n);
660 // qDebug("&buffdoc.located"); 660 // qDebug("&buffdoc.located");
661 fillbuffer(); 661 fillbuffer();
662 // qDebug("&Buffer filled"); 662 // qDebug("&Buffer filled");
663 update(); 663 update();
664 // qDebug("&Located"); 664 // qDebug("&Located");
665 return true; 665 return true;
666} 666}
667 667
668unsigned int QTReader::screenlines() 668unsigned int QTReader::screenlines()
669{ 669{
670 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent; 670 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent;
671 // return (height()-m_descent)/(m_linespacing); 671 // return (height()-m_descent)/(m_linespacing);
672 return (height()-2)/(m_linespacing); 672 return (height()-2)/(m_linespacing);
673}; 673};
674 674
675bool QTReader::fillbuffer() { 675bool QTReader::fillbuffer() {
676 if (buffdoc.empty()) return false;
676 //printf("Fillbuffer\n"); 677 //printf("Fillbuffer\n");
677 m_scrolldy = 0; 678 m_scrolldy = 0;
678 int ch; 679 int ch;
679 bool ret = false; 680 bool ret = false;
680 int delta = screenlines(); 681 int delta = screenlines();
681 // qDebug("fillbuffer:%u-%u",delta,numlines); 682 // qDebug("fillbuffer:%u-%u",delta,numlines);
682 if (delta != numlines) 683 if (delta != numlines)
683 { 684 {
684 if (textarray != NULL) 685 if (textarray != NULL)
685 { 686 {
686 for (int i = 0; i < numlines; i++) delete textarray[i]; 687 for (int i = 0; i < numlines; i++) delete textarray[i];
687 delete [] textarray; 688 delete [] textarray;
688 delete [] locnarray; 689 delete [] locnarray;
689 } 690 }
690 numlines = delta; 691 numlines = delta;
691 textarray = new CBuffer*[numlines]; 692 textarray = new CBuffer*[numlines];
692 locnarray = new size_t[numlines]; 693 locnarray = new size_t[numlines];
693 for (int i = 0; i < numlines; i++) textarray[i] = new CBuffer; 694 for (int i = 0; i < numlines; i++) textarray[i] = new CBuffer;
694 } 695 }
695 // qDebug("fillbuffer:pagepos:%u",pagepos); 696 // qDebug("fillbuffer:pagepos:%u",pagepos);
696 unsigned int oldpagepos = pagepos; 697 unsigned int oldpagepos = pagepos;
697// if (textarray != NULL) 698// if (textarray != NULL)
698// pagepos = locnarray[0]; 699// pagepos = locnarray[0];
699// else 700// else
700 pagepos = locate(); 701 pagepos = locate();
701 for (int i = 0; i < delta; i++) 702 for (int i = 0; i < delta; i++)
702 { 703 {
703 locnarray[i] = locate(); 704 locnarray[i] = locate();
704 ch = getline(textarray[i]); 705 ch = getline(textarray[i]);
705 // if (ch == EOF) { 706 // if (ch == EOF) {
706 if (!ch) 707 if (!ch)
707 { 708 {
708 if (i == 0) 709 if (i == 0)
709 { 710 {
710 locate(oldpagepos); 711 locate(oldpagepos);
711 return false; 712 return false;
712 } 713 }
713 else 714 else
714 { 715 {
715 ret = true; 716 ret = true;
716 for (int j = i+1; j < delta; j++) 717 for (int j = i+1; j < delta; j++)
717 { 718 {
718 locnarray[j] = locnarray[j-1]; 719 locnarray[j] = locnarray[j-1];
719 (*(textarray[j]))[0] = '\0'; 720 (*(textarray[j]))[0] = '\0';
720 } 721 }
721 break; 722 break;
722 } 723 }
723 } 724 }
724 if (ch == '\012') ret = true; 725 if (ch == '\012') ret = true;
725 } 726 }
726 mylastpos = locate(); 727 mylastpos = locate();
727 // qDebug("fillbuffer:lastpos:%u",mylastpos); 728 // qDebug("fillbuffer:lastpos:%u",mylastpos);
728 return true; 729 return true;
729} 730}
730 731
731 732
732void QTReader::dopagedn() 733void QTReader::dopagedn()
733{ 734{
734 if (m_overlap == 0) 735 if (m_overlap == 0)
735 { 736 {
736 if (locate() != mylastpos) jumpto(mylastpos); 737 if (locate() != mylastpos) jumpto(mylastpos);
737 } 738 }
738 else 739 else
739 { 740 {
740 if (m_overlap >= screenlines()) m_overlap = screenlines()/2; 741 if (m_overlap >= screenlines()) m_overlap = screenlines()/2;
741 jumpto(locnarray[screenlines()-m_overlap]); 742 jumpto(locnarray[screenlines()-m_overlap]);
742 } 743 }
743 if (fillbuffer()) 744 if (fillbuffer())
744 { 745 {
745 update(); 746 update();
746 } 747 }
747} 748}
748 749
749void QTReader::dopageup() 750void QTReader::dopageup()
750{ 751{
751 CBuffer** buff = textarray; 752 CBuffer** buff = textarray;
752 unsigned int *loc = new unsigned int[numlines]; 753 unsigned int *loc = new unsigned int[numlines];
753 int cbptr = 0; 754 int cbptr = 0;
754 if (locate() != mylastpos) jumpto(mylastpos); 755 if (locate() != mylastpos) jumpto(mylastpos);
755 if (m_overlap >= screenlines()) m_overlap = screenlines()/2; 756 if (m_overlap >= screenlines()) m_overlap = screenlines()/2;
756 unsigned int target = locnarray[m_overlap]; 757 unsigned int target = locnarray[m_overlap];
757 if (buffdoc.hasrandomaccess()) 758 if (buffdoc.hasrandomaccess())
758 { 759 {
759 unsigned int delta = locate()-pagelocate(); 760 unsigned int delta = locate()-pagelocate();
760 if (delta < 64) delta = 64; 761 if (delta < 64) delta = 64;
761 if (delta % 2 != 0) delta++; 762 if (delta % 2 != 0) delta++;
762 if (target % 2 != 0) target++; 763 if (target % 2 != 0) target++;
763 do 764 do
764 { 765 {
765 delta <<= 1; 766 delta <<= 1;
766 if (delta >= target) 767 if (delta >= target)
767 { 768 {
768 delta = target; 769 delta = target;
769 jumpto(0); 770 jumpto(0);
770 for (int i = 0; i < numlines; i++) 771 for (int i = 0; i < numlines; i++)
771 { 772 {
772 loc[i] = locate(); 773 loc[i] = locate();
773 getline(buff[i]); 774 getline(buff[i]);
774 } 775 }
775 break; 776 break;
776 } 777 }
777 jumpto(target-delta); 778 jumpto(target-delta);
778 do 779 do
779 { 780 {
780 getline(buff[0]); 781 getline(buff[0]);
781#ifdef WS 782#ifdef WS
782 //printf("Trying:%s\n",buff[0]); 783 //printf("Trying:%s\n",buff[0]);
783#endif 784#endif
784 if (locate() > target) continue; 785 if (locate() > target) continue;
785 } 786 }
786 while (!buffdoc.iseol()); 787 while (!buffdoc.iseol());
787 for (int i = 0; i < numlines; i++) 788 for (int i = 0; i < numlines; i++)
788 { 789 {
789 loc[i] = locate(); 790 loc[i] = locate();
790 getline(buff[i]); 791 getline(buff[i]);
791#ifdef WS 792#ifdef WS
792 //printf("Filling:%s\n",buff[i]); 793 //printf("Filling:%s\n",buff[i]);
793#endif 794#endif
794 } 795 }
795 } 796 }
796 while (locate() >= target && delta < 4096); 797 while (locate() >= target && delta < 4096);
797#ifdef WS 798#ifdef WS
798 //printf("Delta:%u\n",delta); 799 //printf("Delta:%u\n",delta);
799#endif 800#endif
800 } 801 }
801 else 802 else
802 { 803 {
803 jumpto(0); 804 jumpto(0);