00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qregexp.h>
00022 #include <qclipboard.h>
00023 #include <qwidgetstack.h>
00024 #ifdef USEQPE
00025 #include <qpe/qpemenubar.h>
00026 #include <qpe/qpetoolbar.h>
00027 #endif
00028 #include <qmenubar.h>
00029 #include <qtoolbar.h>
00030 #ifdef USEQPE
00031 #include <qpe/menubutton.h>
00032 #endif
00033 #include <qcombobox.h>
00034 #include <qpopupmenu.h>
00035 #include <qaction.h>
00036 #include <qapplication.h>
00037 #include <qlineedit.h>
00038 #include <qtoolbutton.h>
00039 #include <qspinbox.h>
00040 #include <qobjectlist.h>
00041 #include <qstatusbar.h>
00042 #ifdef USEQPE
00043 #include <qpe/global.h>
00044 #include <qpe/applnk.h>
00045 #endif
00046 #include <qfileinfo.h>
00047 #include <stdlib.h>
00048 #include <qprogressbar.h>
00049 #ifdef USEQPE
00050 #include <qpe/config.h>
00051 #endif
00052 #include <qbuttongroup.h>
00053 #include <qradiobutton.h>
00054 #ifdef USEQPE
00055 #include <qpe/qcopenvelope_qws.h>
00056 #endif
00057 #include "QTReader.h"
00058 #include "GraphicWin.h"
00059 #include "Bkmks.h"
00060 #include "cbkmkselector.h"
00061 #include "infowin.h"
00062 #include "ToolbarPrefs.h"
00063 #include "Prefs.h"
00064 #include "CAnnoEdit.h"
00065 #include "QFloatBar.h"
00066 #include "FixedFont.h"
00067 #include "URLDialog.h"
00068 #include "util.h"
00069 #include <qfontdatabase.h>
00070
00071 #ifdef USEQPE
00072 #include <opie2/oresource.h>
00073 #ifdef OPIE
00074 #if defined(OPIEFILEDIALOG)
00075 #include <qpe/applnk.h>
00076 #include <opie2/ofiledialog.h>
00077 using namespace Opie::Ui;
00078 #else
00079 #include "fileBrowser.h"
00080 #endif
00081 #else
00082 #include "fileBrowser.h"
00083 #endif
00084 #else
00085 #include "qfiledialog.h"
00086 #endif
00087
00088 #include "QTReaderApp.h"
00089 #include "CDrawBuffer.h"
00090 #include "Filedata.h"
00091 #include "names.h"
00092 #include "CEncoding_tables.h"
00093 #include "CloseDialog.h"
00094
00095 #include "ButtonPrefs.h"
00096
00097 bool CheckVersion(int&, int&, char&, QWidget*);
00098
00099 #ifdef _WINDOWS
00100 #define PICDIR "c:\\uqtreader\\pics\\"
00101 #else
00102 #ifdef USEQPE
00103 #define USEMSGS
00104 #define PICDIR "opie-reader/"
00105 #else
00106
00107 QString picdir()
00108 {
00109 QString hd(getenv("READERDIR"));
00110 return hd + "/pics";
00111 }
00112 #define PICDIR picdir()
00113 #endif
00114 #endif
00115
00116 unsigned long QTReaderApp::m_uid = 0;
00117
00118 void QTReaderApp::setScrollState(bool _b) { m_scrollButton->setOn(_b); }
00119
00120 #ifdef USEQPE
00121 #define geticon(iconname) Opie::Core::OResource::loadPixmap( iconname, Opie::Core::OResource::SmallIcon )
00122 #define getmyicon(iconname) Opie::Core::OResource::loadPixmap( PICDIR iconname, Opie::Core::OResource::SmallIcon )
00123 #else
00124
00125 #define geticon(iconname) QPixmap(PICDIR +"/"+iconname+".png")
00126 #define getmyicon(iconname) geticon(iconname)
00127
00128 #endif
00129
00130 #ifndef _WINDOWS
00131 #include <unistd.h>
00132 #endif
00133 #include <stddef.h>
00134 #ifndef _WINDOWS
00135 #include <dirent.h>
00136 #endif
00137
00138 void QTReaderApp::listBkmkFiles()
00139 {
00140 bkmkselector->clear();
00141 bkmkselector->setText("Cancel");
00142 #ifndef USEQPE
00143 int cnt = 0;
00144
00145 QDir d = QDir::home();
00146 if ( !d.cd(APPDIR) ) {
00147 qWarning( "Cannot find the \"~/" APPDIR "\" directory" );
00148 d = QDir::home();
00149 d.mkdir(APPDIR);
00150 d.cd(APPDIR);
00151 }
00152
00153
00154
00155
00156 d.setFilter( QDir::Files | QDir::NoSymLinks );
00157
00158
00159 const QFileInfoList *list = d.entryInfoList();
00160 QFileInfoListIterator it( *list );
00161 QFileInfo *fi;
00162 while ( (fi=it.current()) ) {
00163
00164 bkmkselector->insertItem(fi->fileName(), cnt++);
00165
00166
00167 ++it;
00168 }
00169
00170 #else
00171 int cnt = 0;
00172 DIR *d;
00173 d = opendir((const char *)Global::applicationFileName(APPDIR,""));
00174
00175 while(1)
00176 {
00177 struct dirent* de;
00178 struct stat buf;
00179 de = readdir(d);
00180 if (de == NULL) break;
00181
00182 if (lstat((const char *)Global::applicationFileName(APPDIR,de->d_name),&buf) == 0 && S_ISREG(buf.st_mode))
00183 {
00184 bkmkselector->insertItem(de->d_name, cnt++);
00185 }
00186 }
00187
00188 closedir(d);
00189 #endif
00190 if (cnt > 0)
00191 {
00192
00193
00194
00195 editorStack->raiseWidget( bkmkselector );
00196 hidetoolbars();
00197 m_nBkmkAction = cRmBkmkFile;
00198 }
00199 else
00200 QMessageBox::information(this, PROGNAME, "No bookmark files");
00201 }
00202
00203 void QTReaderApp::hidetoolbars()
00204 {
00205 if (m_scrollbar != NULL) m_scrollbar->hide();
00206 if (m_prog != NULL) m_prog->hide();
00207
00208 #if defined(USEQPE)
00209 menubar->hide();
00210 #endif
00211
00212 if (m_scrollbar != NULL) m_scrollbar->hide();
00213
00214 if (fileBar != NULL) fileBar->hide();
00215 if (viewBar != NULL) viewBar->hide();
00216 if (navBar != NULL) navBar->hide();
00217 if (markBar != NULL) markBar->hide();
00218 if (m_fontVisible) m_fontBar->hide();
00219 if (regVisible)
00220 {
00221 #ifdef USEQPE
00222 Global::hideInputMethod();
00223 #endif
00224 regBar->hide();
00225 }
00226 if (searchVisible)
00227 {
00228 #ifdef USEQPE
00229 Global::hideInputMethod();
00230 #endif
00231 searchBar->hide();
00232 }
00233 }
00234
00235 QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
00236 : QMainWindow( parent, name, f ), m_dontSave(false),
00237 fileBar(NULL), navBar(NULL), viewBar(NULL), markBar(NULL), m_scrollbar(NULL), m_localscroll(2), m_hidebars(false), m_kmapchanged(false)
00238 {
00239 {
00240 setKeyCompression ( true );
00241 #ifndef USEQPE
00242 QDir d = QDir::home();
00243 d.cd(APPDIR);
00244 QFileInfo fi(d, ".keymap");
00245 FILE* f = fopen((const char *)fi.absFilePath(), "r");
00246 #else
00247 FILE* f = fopen((const char *)Global::applicationFileName(APPDIR,".keymap"), "r");
00248 #endif
00249 if (f != NULL)
00250 {
00251 uint cnt;
00252 if ((fread(&cnt, sizeof(cnt), 1, f) != 0) && (cnt == KEYMAPVERSION))
00253 {
00254 if (fread(&cnt, sizeof(cnt), 1, f) == 0) cnt = 0;
00255 for (uint i = 0; i != cnt; i++)
00256 {
00257 orKey key;
00258 int data;
00259 fread(&key, sizeof(key), 1, f);
00260 fread(&data, sizeof(data), 1, f);
00261 kmap[key] = data;
00262 }
00263 }
00264 fclose(f);
00265 }
00266 }
00267
00268 m_url_clipboard = false;
00269 m_url_localfile = false;
00270 m_url_globalfile = false;
00271 ftime(&m_lastkeytime);
00274
00275 m_bcloseDisabled = true;
00276 m_disableesckey = false;
00277 pBkmklist = NULL;
00278 pOpenlist = NULL;
00279
00280
00281 m_fBkmksChanged = false;
00282
00283 QString lang = getenv( "LANG" );
00284 QString rot = getenv( "QWS_DISPLAY" );
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 m_autogenstr = "^ *[A-Z].*[a-z] *$";
00304
00305 #ifdef USEQPE
00306 setIcon( Opie::Core::OResource::loadPixmap( PICDIR "uqtreader", Opie::Core::OResource::SmallIcon ) );
00307 #else
00308 setIcon( QPixmap (PICDIR + "/uqtreader.png") );
00309 #endif
00310
00311
00312
00313 #ifdef USEQPE
00314 Config config( APPDIR );
00315 #else
00316 QDir d = QDir::home();
00317 if ( !d.cd(APPDIR) ) {
00318 qWarning( "Cannot find the \"~/" APPDIR "\" directory" );
00319 d = QDir::home();
00320 d.mkdir(APPDIR);
00321 d.cd(APPDIR);
00322 }
00323 QFileInfo fi(d, INIFILE);
00324
00325 Config config(fi.absFilePath());
00326 #endif
00327 config.setGroup("Toolbar");
00328 m_tbmovesave = m_tbmove = config.readBoolEntry("Movable", false);
00329 m_tbpolsave = m_tbpol = (ToolbarPolicy)config.readNumEntry("Policy", 1);
00330 m_tbposition = (ToolBarDock)config.readNumEntry("Position", 2);
00331 m_qtscroll = config.readNumEntry("QTScrollBar", false);
00332 m_localscroll = config.readNumEntry("LocalScrollBar", false);
00333
00334
00335
00336
00337
00338
00339 #if defined(USEQPE)
00340 menubar = new QToolBar("Menus", this, m_tbposition);
00341 mb = new QPEMenuBar( menubar );
00342 #else
00343 mb = new QMenuBar( this );
00344 #endif
00345
00346 #if defined(USEQPE)
00347 QPopupMenu* tmp = new QPopupMenu(mb);
00348 mb->insertItem( geticon( "AppsIcon" ), tmp );
00349 #else
00350 QMenuBar* tmp = mb;
00351 #endif
00352
00353 QPopupMenu *file = new QPopupMenu( mb );
00354 tmp->insertItem( tr( "File" ), file );
00355
00356 QPopupMenu *navigation = new QPopupMenu(mb);
00357 tmp->insertItem( tr( "Navigation" ), navigation );
00358
00359 QPopupMenu *view = new QPopupMenu( mb );
00360 tmp->insertItem( tr( "View" ), view );
00361
00362 QPopupMenu *marks = new QPopupMenu( this );
00363 tmp->insertItem( tr( "Marks" ), marks );
00364
00365 QPopupMenu *settings = new QPopupMenu( this );
00366 tmp->insertItem( tr( "Settings" ), settings );
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379 QWidget* widge = new QWidget(this);
00380 setCentralWidget( widge );
00381 QVBoxLayout* vlayout = new QVBoxLayout(widge);
00382 m_layout = new QBoxLayout(QBoxLayout::LeftToRight);
00383 m_prog = new QLabel(widge);
00384 vlayout->addLayout(m_layout, 1);
00385 vlayout->addWidget(m_prog);
00386
00387 editorStack = new QWidgetStack( widge );
00388
00389
00390 searchVisible = FALSE;
00391 regVisible = FALSE;
00392 m_fontVisible = false;
00393
00394 m_buttonprefs = new CButtonPrefs(&kmap, this);
00395 editorStack->addWidget(m_buttonprefs, get_unique_id());
00396 connect( m_buttonprefs, SIGNAL( Closed() ), this, SLOT( infoClose() ) );
00397
00398
00399 m_annoWin = new CAnnoEdit(editorStack);
00400 editorStack->addWidget(m_annoWin, get_unique_id());
00401 connect( m_annoWin, SIGNAL( finished(const QString&, const QString&) ), this, SLOT( addAnno(const QString&, const QString&) ) );
00402 connect( m_annoWin, SIGNAL( cancelled() ), this, SLOT( infoClose() ) );
00403
00404 m_infoWin = new infowin(editorStack);
00405 editorStack->addWidget(m_infoWin, get_unique_id());
00406 connect( m_infoWin, SIGNAL( Close() ), this, SLOT( infoClose() ) );
00407
00408 m_graphicwin = new GraphicWin(editorStack);
00409 editorStack->addWidget(m_graphicwin, get_unique_id());
00410 connect( m_graphicwin, SIGNAL( Closed() ), this, SLOT( infoClose() ) );
00411
00412
00413 bkmkselector = new CBkmkSelector(editorStack, "Bookmarks");
00414
00415 connect(bkmkselector, SIGNAL( selected(int) ), this, SLOT( gotobkmk(int) ) );
00416 connect(bkmkselector, SIGNAL( cancelled() ), this, SLOT( cancelbkmk() ) );
00417 editorStack->addWidget( bkmkselector, get_unique_id() );
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429 readfilelist();
00430
00431 reader = new QTReader( editorStack );
00432
00433 reader->setDoUpdates(false);
00434
00435 #ifdef USEQPE
00436 ((QPEApplication*)qApp)->setStylusOperation(reader, QPEApplication::RightOnHold);
00437 #endif
00438
00439
00440
00441 config.setGroup( "View" );
00442 #if defined(USEQPE) && defined(USENEWFULLSCREEN)
00443 m_usenewfullscreen = config.readBoolEntry("NewFullScreen", false);
00444 #endif
00445 m_debounce = config.readNumEntry("Debounce", 0);
00446 m_buttonprefs->Debounce(m_debounce);
00447 #ifdef USEQPE
00448 m_bFloatingDialog = config.readBoolEntry("FloatDialogs", false);
00449 #else
00450 m_bFloatingDialog = config.readBoolEntry("FloatDialogs", true);
00451 #endif
00452 reader->setStripCR(config.readBoolEntry( "StripCr", true ));
00453 reader->bfulljust = config.readBoolEntry( "FullJust", false );
00454
00455
00456
00457
00458 reader->bInverse = config.readBoolEntry("Inverse", false);
00459 reader->m_fontControl.FixGraphics(config.readBoolEntry( "FixGraphics", false ));
00460 reader->setextraspace(config.readNumEntry( "ExtraSpace", 0 ));
00461 reader->setlead(config.readNumEntry( "ExtraLead", 0 ));
00462 reader->btextfmt = config.readBoolEntry( "TextFmt", false );
00463 reader->bautofmt = config.readBoolEntry( "AutoFmt", true );
00464 reader->bstriphtml = config.readBoolEntry( "StripHtml", false );
00465 reader->bNoInlineTables = config.readBoolEntry( "NoInlineTables", false );
00466 reader->bpeanut = config.readBoolEntry( "Peanut", false );
00467 reader->bdehyphen = config.readBoolEntry( "Dehyphen", false );
00468 reader->bdepluck = config.readBoolEntry( "Depluck", false );
00469 reader->bdejpluck = config.readBoolEntry( "Dejpluck", false );
00470 reader->bonespace = config.readBoolEntry( "OneSpace", false );
00471 reader->bunindent = config.readBoolEntry( "Unindent", false );
00472 reader->brepara = config.readBoolEntry( "Repara", false );
00473 reader->m_reparastring = config.readEntry( "ReparaString", "\\n{[\\n \\t]}");
00474 m_bgtype = (bground)config.readNumEntry( "BackgroundType" , 0 );
00475 m_themename = config.readEntry("Theme", QString::null );
00476 reader->bdblspce = config.readBoolEntry( "DoubleSpace", false );
00477 reader->bindenter = config.readNumEntry( "Indent", 0 );
00478 reader->m_textsize = config.readNumEntry( "FontSize", 12 );
00479 reader->m_delay = config.readNumEntry( "ScrollDelay", 5184);
00480 reader->m_scrollstep = config.readNumEntry( "ScrollStep", 1);
00481 reader->m_outputName = config.readEntry( "OutputCodec", "");
00482
00483
00484 reader->m_lastfile = config.readEntry( "LastFile", QString::null );
00485 reader->m_lastposn = config.readNumEntry( "LastPosn", 0 );
00486 reader->m_bpagemode = config.readBoolEntry( "PageMode", true );
00487 reader->m_bMonoSpaced = config.readBoolEntry( "MonoSpaced", false);
00488 reader->m_rotated = config.readBoolEntry( "IsRotated", false );
00489 reader->m_scrolltype = config.readNumEntry( "ScrollType", 0 );
00490 m_statusstring = config.readEntry("StatusContent", "%P%% Doc:%d/%D %p%% %z%%");
00491 m_statusishidden = config.readBoolEntry("StatusHidden", false);
00492 m_background = config.readNumEntry( "Background", 0 );
00493 reader->setBackground(getcolour(m_background));
00494 m_foreground = config.readNumEntry( "Foreground", 1 );
00495 reader->setForeground(getcolour(m_foreground));
00496 m_scrollcolor = config.readNumEntry( "ScrollColour", 5 );
00497 setscrollcolour();
00498 m_scrollbarcolor = config.readNumEntry( "ScrollBarColour", 5 );
00499 setscrollbarcolour();
00500 reader->hyphenate = config.readBoolEntry( "Hyphenate", false );
00501 reader->m_swapmouse = config.readBoolEntry( "SwapMouse", false);
00502 reader->m_fontname = config.readEntry( "Fontname", "helvetica" );
00503 reader->m_encd = config.readNumEntry( "Encoding", 0 );
00504 reader->m_charpc = config.readNumEntry( "CharSpacing", 100 );
00505 reader->m_overlap = config.readNumEntry( "Overlap", 0 );
00506 reader->m_abstopmargin = config.readNumEntry( "Top Margin", 100 );
00507 reader->m_absbottommargin = config.readNumEntry( "Bottom Margin", 100 );
00508 reader->m_absleft_border = config.readNumEntry( "Left Margin", 100 );
00509 reader->m_absright_border = config.readNumEntry( "Right Margin", 100 );
00510
00511 m_scrollishidden = config.readBoolEntry( "HideScrollBar", false );
00512 m_hidebars = config.readBoolEntry( "HideToolBar", false );
00513
00514 reader->brepalm = config.readBoolEntry( "Repalm", false );
00515 reader->bunderlineLink = config.readBoolEntry( "UnderlineLink", true );
00516 reader->bkern = config.readBoolEntry( "Kern", false );
00517 reader->bremap = config.readBoolEntry( "Remap", true );
00518 reader->bmakebold = config.readBoolEntry( "MakeBold", false );
00519 reader->setContinuous(config.readBoolEntry( "Continuous", true ));
00520 reader->setDoubleBuffer(config.readBoolEntry("DoubleBuffer", true));
00521 m_targetapp = config.readEntry( "TargetApp", QString::null );
00522 m_targetmsg = config.readEntry( "TargetMsg", QString::null );
00523 #ifdef _SCROLLPIPE
00524 reader->m_pipetarget = config.readEntry( "PipeTarget", QString::null );
00525 reader->m_pauseAfterEachPara = config.readBoolEntry( "PauseAfterPara", true );
00526 #endif
00527 m_twoTouch = config.readBoolEntry( "TwoTouch", false);
00528 m_doAnnotation = config.readBoolEntry( "Annotation", false);
00529 m_doDictionary = config.readBoolEntry( "Dictionary", false);
00530 m_doClipboard = config.readBoolEntry( "Clipboard", false);
00531 m_doOutput = config.readBoolEntry( "OutputTgt", false);
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546 m_propogatefontchange = config.readBoolEntry( "RequestorFontChange", false);
00547 reader->setBaseSize(config.readNumEntry( "Basesize", 10 ));
00548 reader->setHyphenThreshold(config.readNumEntry( "HyphenThreshold", 50 ));
00549
00550 #ifndef USEQPE
00551 config.setGroup( "Geometry" );
00552 setGeometry(0,0,
00553 config.readNumEntry( "width", QApplication::desktop()->width()/2 ),
00554 config.readNumEntry( "height", QApplication::desktop()->height()/2 ));
00555 move(
00556 config.readNumEntry( "x", 20 ),
00557 config.readNumEntry( "y", 20 ));
00558 #else
00559 m_grabkeyboard = config.readBoolEntry( "GrabKeyboard", false);
00560 #endif
00561
00562
00563
00564 setTwoTouch(m_twoTouch);
00565
00566 connect( reader, SIGNAL( OnShowPicture(QImage&) ), this, SLOT( showgraphic(QImage&) ) );
00567
00568 connect( reader, SIGNAL( OnRedraw() ), this, SLOT( OnRedraw() ) );
00569 connect( reader, SIGNAL( OnWordSelected(const QString&, size_t, size_t, const QString&) ), this, SLOT( OnWordSelected(const QString&, size_t, size_t, const QString&) ) );
00570 connect( reader, SIGNAL( OnURLSelected(const QString&, const size_t) ), this, SLOT( OnURLSelected(const QString&, const size_t) ) );
00571 connect( reader, SIGNAL( NewFileRequest(const QString&) ), this, SLOT( forceopen(const QString&) ) );
00572 connect( reader, SIGNAL( HandleKeyRequest(QKeyEvent*) ), this, SLOT( handlekey(QKeyEvent*) ) );
00573 connect( reader, SIGNAL( SetScrollState(bool) ), this, SLOT( setScrollState(bool) ) );
00574 connect( reader, SIGNAL(RefreshBitmap()), this, SLOT(setBackgroundBitmap()));
00575 editorStack->addWidget( reader, get_unique_id() );
00576
00577 m_preferences_action = new QAction( tr( "Configuration" ), geticon( "SettingsIcon" ), QString::null, 0, this, NULL);
00578 connect( m_preferences_action, SIGNAL( activated() ), this, SLOT( showprefs() ) );
00579 m_preferences_action->addTo( settings );
00580
00581 m_saveconfig_action = new QAction( tr( "Save Config" ), QString::null, 0, this, NULL);
00582 connect( m_saveconfig_action, SIGNAL( activated() ), this, SLOT( SaveConfig() ) );
00583 m_saveconfig_action->addTo( settings );
00584
00585 m_loadconfig_action = new QAction( tr( "Load Config" ), QString::null, 0, this, NULL);
00586 connect( m_loadconfig_action, SIGNAL( activated() ), this, SLOT( LoadConfig() ) );
00587 m_loadconfig_action->addTo( settings );
00588
00589 m_tidyconfig_action = new QAction( tr( "Delete Config" ), QString::null, 0, this, NULL);
00590 connect( m_tidyconfig_action, SIGNAL( activated() ), this, SLOT( TidyConfig() ) );
00591 m_tidyconfig_action->addTo( settings );
00592
00593 settings->insertSeparator();
00594 m_toolbarprefs_action = new QAction( tr( "Toolbars" ), QString::null, 0, this, NULL);
00595 connect( m_toolbarprefs_action, SIGNAL( activated() ), this, SLOT( showtoolbarprefs() ) );
00596 m_toolbarprefs_action->addTo( settings );
00597
00598 m_buttonprefs_action = new QAction( tr( "Buttons" ), QString::null, 0, this, NULL);
00599 connect( m_buttonprefs_action, SIGNAL( activated() ), this, SLOT( showbuttonprefs() ) );
00600 m_buttonprefs_action->addTo( settings );
00601
00602 m_loadtheme_action = new QAction( tr( "Load Theme" ), QString::null, 0, this, NULL);
00603 connect( m_loadtheme_action, SIGNAL( activated() ), this, SLOT( LoadTheme() ) );
00604 m_loadtheme_action->addTo( settings );
00605
00606 m_repara_action = new QAction( tr( "EOP Marker" ), QString::null, 0, this, NULL);
00607 connect( m_repara_action, SIGNAL( activated() ), this, SLOT( reparastring() ) );
00608 m_repara_action->addTo(settings);
00609
00610 #ifdef USEQPE
00611 m_grab_action = new QAction( tr( "Grab Buttons" ), QString::null, 0, this, NULL, true );
00612 connect( m_grab_action, SIGNAL( toggled(bool) ), this, SLOT( setgrab(bool) ) );
00613 m_grab_action->setOn(m_grabkeyboard);
00614 m_grab_action->addTo( settings );
00615 #endif
00616
00617 m_open_action = new QAction( tr( "Open" ), geticon( "fileopen" ), QString::null, 0, this, 0 );
00618 connect( m_open_action, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
00619 m_open_action->addTo( file );
00620
00621 m_close_action = new QAction( tr( "Close" ), geticon( "close" ), QString::null, 0, this, 0 );
00622 connect( m_close_action, SIGNAL( activated() ), this, SLOT( fileClose() ) );
00623 m_close_action->addTo( file );
00624
00625 #ifdef _SCRIPT
00626 a = new QAction( tr( "Run Script" ), QString::null, 0, this, NULL);
00627 connect( a, SIGNAL( activated() ), this, SLOT( RunScript() ) );
00628 a->addTo( file );
00629 #endif
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641 m_info_action = new QAction( tr( "Info" ), geticon( "UtilsIcon" ), QString::null, 0, this, NULL);
00642 connect( m_info_action, SIGNAL( activated() ), this, SLOT( showinfo() ) );
00643 m_info_action->addTo( file );
00644
00645 m_touch_action = new QAction( tr( "Two/One Touch" ), geticon( "1to1" ), QString::null, 0, this, NULL, true );
00646 connect( m_touch_action, SIGNAL( toggled(bool) ), this, SLOT( setTwoTouch(bool) ) );
00647 m_touch_action->setOn(m_twoTouch);
00648 m_touch_action->addTo( file );
00649
00650 m_find_action = new QAction( tr( "Find..." ), geticon( "find" ), QString::null, 0, this, NULL);
00651 connect( m_find_action, SIGNAL( activated() ), this, SLOT( editFind() ) );
00652 file->insertSeparator();
00653
00654 m_find_action->addTo( file );
00655
00656 m_exportlinks_action = new QAction( tr( "Export Links" ), QString::null, 0, this, NULL);
00657 connect( m_exportlinks_action, SIGNAL( activated() ), this, SLOT( ExportLinks() ) );
00658 m_exportlinks_action->addTo( file );
00659
00660 m_scrollButton = new QAction( tr( "Scroll" ), getmyicon( "panel-arrow-down" ), QString::null, 0, this, 0, true );
00661 connect( m_scrollButton, SIGNAL( toggled(bool) ), this, SLOT( autoScroll(bool) ) );
00662 m_scrollButton->addTo(navigation);
00663 m_scrollButton->setOn(false);
00664
00665 m_start_action = new QAction( tr( "Goto Start" ), geticon( "start" ), QString::null, 0, this, NULL);
00666 connect( m_start_action, SIGNAL( activated() ), this, SLOT( gotoStart() ) );
00667 m_start_action->addTo(navigation);
00668
00669 m_end_action = new QAction( tr( "Goto End" ), geticon( "finish" ), QString::null, 0, this, NULL);
00670 connect( m_end_action, SIGNAL( activated() ), this, SLOT( gotoEnd() ) );
00671 m_end_action->addTo(navigation);
00672
00673 m_jump_action = new QAction( tr( "Jump" ), geticon( "rotate" ), QString::null, 0, this, NULL);
00674 connect( m_jump_action, SIGNAL( activated() ), this, SLOT( jump() ) );
00675 m_jump_action->addTo(navigation);
00676
00677 m_pageline_action = new QAction( tr( "Page/Line Scroll" ), geticon( "pass" ), QString::null, 0, this, NULL, true );
00678 connect( m_pageline_action, SIGNAL( toggled(bool) ), this, SLOT( pagemode(bool) ) );
00679 m_pageline_action->addTo(navigation);
00680 m_pageline_action->setOn(reader->m_bpagemode);
00681
00682 m_pageup_action = new QAction( tr( "Up" ), geticon( "up" ), QString::null, 0, this, 0 );
00683 connect( m_pageup_action, SIGNAL( activated() ), this, SLOT( pageup() ) );
00684 m_pageup_action->addTo( navigation );
00685
00686 m_pagedn_action = new QAction( tr( "Down" ), geticon( "down" ), QString::null, 0, this, 0 );
00687 connect( m_pagedn_action, SIGNAL( activated() ), this, SLOT( pagedn() ) );
00688 m_pagedn_action->addTo( navigation );
00689
00690 m_back_action = new QAction( tr( "Back" ), geticon( "back" ), QString::null, 0, this, 0 );
00691 connect( m_back_action, SIGNAL( activated() ), reader, SLOT( goBack() ) );
00692 m_back_action->addTo( navigation );
00693
00694 m_home_action = new QAction( tr( "Home" ), geticon( "home" ), QString::null, 0, this, 0 );
00695 connect( m_home_action, SIGNAL( activated() ), reader, SLOT( goHome() ) );
00696 m_home_action->addTo( navigation );
00697
00698 m_forward_action = new QAction( tr( "Forward" ), geticon( "forward" ), QString::null, 0, this, 0 );
00699 connect( m_forward_action, SIGNAL( activated() ), reader, SLOT( goForward() ) );
00700 m_forward_action->addTo( navigation );
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714 #ifdef _SCROLLPIPE
00715
00716 QActionGroup* ag = new QActionGroup(this);
00717 ag->setExclusive(false);
00718 spacemenu = new QPopupMenu(this);
00719 file->insertItem( tr( "Scrolling" ), spacemenu );
00720
00721 a = new QAction( tr( "Set Target" ), QString::null, 0, ag, NULL);
00722 connect( a, SIGNAL( activated() ), this, SLOT( setpipetarget() ) );
00723
00724 a = new QAction( tr( "Pause Paras" ), QString::null, 0, ag, NULL, true );
00725 connect( a, SIGNAL( toggled(bool) ), this, SLOT( setpause(bool) ) );
00726 a->setOn(reader->m_pauseAfterEachPara);
00727
00728 ag->addTo(spacemenu);
00729
00730
00731 #endif
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748 m_fullscreen = false;
00749 m_actFullscreen = new QAction( tr( "Fullscreen" ), geticon( "fullscreen" ), QString::null, 0, this, NULL, true );
00750 connect( m_actFullscreen, SIGNAL( toggled(bool) ), this, SLOT( setfullscreen(bool) ) );
00751 m_actFullscreen->setOn(m_fullscreen);
00752 m_actFullscreen->addTo( view );
00753
00754 m_rotate_action = new QAction( tr( "Rotate" ), geticon( "repeat" ), QString::null, 0, this, NULL, true );
00755 connect( m_rotate_action, SIGNAL( toggled(bool) ), this, SLOT( setrotated(bool) ) );
00756 m_rotate_action->setOn(reader->m_rotated);
00757 m_rotate_action->addTo( view );
00758
00759 m_inverse_action = new QAction( tr( "Invert" ), getmyicon( "invert" ), QString::null, 0, this, NULL, true );
00760 connect( m_inverse_action, SIGNAL( toggled(bool) ), this, SLOT( setinverted(bool) ) );
00761 m_inverse_action->setOn(reader->bInverse);
00762 m_inverse_action->addTo( view );
00763
00764 view->insertSeparator();
00765
00766 m_zoomin_action = new QAction( tr( "Zoom In" ), geticon( "zoom" ), QString::null, 0, this);
00767 connect( m_zoomin_action, SIGNAL( activated() ), this, SLOT( zoomin() ) );
00768 m_zoomin_action->addTo( view );
00769
00770 m_zoomout_action = new QAction( tr( "Zoom Out" ), geticon( "mag" ), QString::null, 0, this);
00771 connect( m_zoomout_action, SIGNAL( activated() ), this, SLOT( zoomout() ) );
00772 m_zoomout_action->addTo( view );
00773
00774 view->insertSeparator();
00775 m_setfont_action = new QAction( tr( "Set Font" ), getmyicon( "font" ), QString::null, 0, this);
00776 connect( m_setfont_action, SIGNAL( activated() ), this, SLOT( setfont() ) );
00777 m_setfont_action->addTo( view );
00778
00779 view->insertSeparator();
00780 m_setenc_action = new QAction( tr( "Set Encoding" ), getmyicon( "charset" ), QString::null, 0, this);
00781 connect( m_setenc_action, SIGNAL( activated() ), this, SLOT( chooseencoding() ) );
00782 m_setenc_action->addTo( view );
00783
00784 m_setmono_action = new QAction( tr( "Ideogram" ), getmyicon( "ideogram" ), QString::null, 0, this, NULL, true);
00785 connect( m_setmono_action, SIGNAL( toggled(bool) ), this, SLOT( monospace(bool) ) );
00786 m_setmono_action->addTo( view );
00787 m_setmono_action->setOn(reader->m_bMonoSpaced);
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810 m_mark_action = new QAction( tr( "Bookmark" ), getmyicon( "bookmark" ), QString::null, 0, this, NULL);
00811 connect( m_mark_action, SIGNAL( activated() ), this, SLOT( addbkmk() ) );
00812 m_mark_action->addTo( marks );
00813
00814 m_annotate_action = new QAction( tr( "Annotate" ), getmyicon( "annotate" ), QString::null, 0, this, NULL);
00815 connect( m_annotate_action, SIGNAL( activated() ), this, SLOT( addanno() ) );
00816 m_annotate_action->addTo( marks );
00817
00818 m_goto_action = new QAction( tr( "Goto" ), getmyicon( "bookmark_goto" ), QString::null, 0, this, NULL, false );
00819 connect( m_goto_action, SIGNAL( activated() ), this, SLOT( do_gotomark() ) );
00820 m_goto_action->addTo( marks );
00821
00822 m_delete_action = new QAction( tr( "Delete" ), getmyicon( "bookmark_delete" ), QString::null, 0, this, NULL);
00823 connect( m_delete_action, SIGNAL( activated() ), this, SLOT( do_delmark() ) );
00824 m_delete_action->addTo( marks );
00825
00826 m_autogen_action = new QAction( tr( "Autogen" ), geticon( "exec" ), QString::null, 0, this, NULL, false );
00827 connect( m_autogen_action, SIGNAL( activated() ), this, SLOT( do_autogen() ) );
00828 marks->insertSeparator();
00829 m_autogen_action->addTo( marks );
00830
00831 m_clear_action = new QAction( tr( "Clear" ), getmyicon( "bookmark_clear" ), QString::null, 0, this, NULL);
00832 connect( m_clear_action, SIGNAL( activated() ), this, SLOT( clearBkmkList() ) );
00833 m_clear_action->addTo( marks );
00834
00835 m_save_action = new QAction( tr( "Save" ), getmyicon( "bookmark_save" ), QString::null, 0, this, NULL );
00836 connect( m_save_action, SIGNAL( activated() ), this, SLOT( savebkmks() ) );
00837 m_save_action->addTo( marks );
00838
00839 m_tidy_action = new QAction( tr( "Tidy" ), getmyicon( "bookmark_tidy" ), QString::null, 0, this, NULL);
00840 connect( m_tidy_action, SIGNAL( activated() ), this, SLOT( listBkmkFiles() ) );
00841 marks->insertSeparator();
00842 m_tidy_action->addTo( marks );
00843
00844 m_startBlock_action = new QAction( tr( "Start Block" ), geticon( "new" ), QString::null, 0, this, NULL);
00845 connect( m_startBlock_action, SIGNAL( activated() ), this, SLOT( editMark() ) );
00846 marks->insertSeparator();
00847 m_startBlock_action->addTo( marks );
00848
00849 m_endBlock_action = new QAction( tr( "Copy Block" ), geticon( "copy" ), QString::null, 0, this, NULL);
00850 connect( m_endBlock_action, SIGNAL( activated() ), this, SLOT( editCopy() ) );
00851 m_endBlock_action->addTo( marks );
00852
00853 m_bkmkAvail = NULL;
00854
00855
00856 setToolBarsMovable(m_tbmove);
00857 addtoolbars(&config);
00858 if (m_hidebars)
00859 {
00860 #if defined(USEQPE)
00861 menubar->hide();
00862 #endif
00863 if (fileBar != NULL) fileBar->hide();
00864 if (viewBar != NULL) viewBar->hide();
00865 if (navBar != NULL) navBar->hide();
00866 if (markBar != NULL) markBar->hide();
00867 mb->hide();
00868 }
00869
00870
00871 pbar = new QProgressBar(this);
00872 pbar->hide();
00873
00874 searchBar = new QFloatBar( "Search", this, QMainWindow::Top, TRUE );
00875
00876 searchBar->setHorizontalStretchable( TRUE );
00877
00878 connect(searchBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() ));
00879
00880 searchEdit = new QLineEdit( searchBar, "searchEdit" );
00881
00882
00883 searchBar->setStretchableWidget( searchEdit );
00884
00885
00886 #ifdef __ISEARCH
00887 connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
00888 this, SLOT( search( const QString& ) ) );
00889 #else
00890 connect( searchEdit, SIGNAL( returnPressed( ) ),
00891 this, SLOT( search( ) ) );
00892 #endif
00893 QAction*a = new QAction( tr( "Find Next" ), geticon( "next" ), QString::null, 0, this, 0 );
00894 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
00895 a->addTo( searchBar );
00896
00897 a = new QAction( tr( "Close Find" ), geticon( "close" ), QString::null, 0, this, 0 );
00898 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
00899 a->addTo( searchBar );
00900
00901 searchBar->hide();
00902
00903 regBar = new QFloatBar( "Autogen", this, QMainWindow::Top, TRUE );
00904 connect(regBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() ));
00905
00906 regBar->setHorizontalStretchable( TRUE );
00907
00908 regEdit = new QLineEdit( regBar, "regEdit" );
00909
00910
00911 regBar->setStretchableWidget( regEdit );
00912
00913 connect( regEdit, SIGNAL( returnPressed( ) ),
00914 this, SLOT( do_regaction() ) );
00915
00916 a = new QAction( tr( "Do Reg" ), geticon( "enter" ), QString::null, 0, this, 0 );
00917 connect( a, SIGNAL( activated() ), this, SLOT( do_regaction() ) );
00918 a->addTo( regBar );
00919
00920 a = new QAction( tr( "Close Edit" ), geticon( "close" ), QString::null, 0, this, 0 );
00921 connect( a, SIGNAL( activated() ), this, SLOT( regClose() ) );
00922 a->addTo( regBar );
00923
00924 regBar->hide();
00925
00926 m_fontBar = new QToolBar( "Autogen", this, QMainWindow::Top, TRUE );
00927
00928 m_fontBar->setHorizontalStretchable( TRUE );
00929
00930
00931 m_fontSelector = new QComboBox(false, m_fontBar);
00932 m_fontBar->setStretchableWidget( m_fontSelector );
00933 {
00934 QFontDatabase f;
00935 QStringList flist = f.families();
00936 bool realfont = false;
00937 for (QStringList::Iterator nm = flist.begin(); nm != flist.end(); nm++)
00938 {
00939 if (reader->m_fontname == *nm)
00940 {
00941 realfont = true;
00942 }
00943 if ((*nm).contains(FIXEDFONT,false)) reader->m_fontControl.hasCourier(true, *nm);
00944 }
00945 if (!realfont) reader->m_fontname = flist[0];
00946 }
00947 connect( m_fontSelector, SIGNAL( activated(const QString& ) ),
00948 this, SLOT( do_setfont(const QString&) ) );
00949 connect( m_fontSelector, SIGNAL( activated(int ) ),
00950 this, SLOT( do_setencoding(int) ) );
00951
00952 m_fontBar->hide();
00953 m_fontVisible = false;
00954 #ifdef USEMSGS
00955 connect(qApp, SIGNAL( appMessage(const QCString&, const QByteArray& ) ),
00956 this, SLOT( msgHandler(const QCString&, const QByteArray&) ) );
00957 #endif
00958
00959
00960 m_layout->addWidget(editorStack);
00961 if (m_qtscroll != 0)
00962 {
00963
00964
00965
00966
00967
00968 scrollbar = m_scrollbar = new QScrollBar(QScrollBar::Vertical, widge);
00969 m_layout->addWidget(scrollbar);
00970 scrollbar->setTracking(false);
00971
00972
00973 if (m_scrollishidden)
00974 {
00975 m_scrollbar->hide();
00976 }
00977 else
00978 {
00979 m_scrollbar->show();
00980 }
00981
00982 setrotated(reader->m_rotated);
00983 }
00984 else
00985 {
00986 m_scrollbar = NULL;
00987 }
00988 setBackgroundBitmap();
00989 m_inverse_action->setOn(reader->bInverse);
00990 reader->init();
00991
00992
00993
00994
00995 do_setfont(reader->m_fontname);
00996
00997 QFont progfont(reader->m_fontname, reader->m_fontControl.getsize(0));
00998 m_prog->setFont( progfont );
00999 if (m_statusishidden) m_prog->hide();
01000 showEditTools();
01001 if (!reader->m_lastfile.isEmpty())
01002 {
01003
01004
01005
01006 if (pOpenlist != NULL)
01007 {
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017 Bkmk* p = NULL;
01018 for (CList<Bkmk>::iterator iter = pOpenlist->begin(); iter != pOpenlist->end(); iter++)
01019 {
01020 p = iter.pContent();
01021 if (toQString(CFiledata(p->anno()).name()) == reader->m_lastfile)
01022 {
01023 break;
01024 }
01025
01026 p = NULL;
01027 }
01028 if (p != NULL)
01029 {
01030 if (!openfrombkmk(p))
01031 {
01032 showEditTools();
01033 }
01034 }
01035 else
01036 {
01037 openFile( reader->m_lastfile );
01038 }
01039 }
01040 else
01041 {
01042 if (!reader->m_lastfile.isEmpty())
01043 {
01044 openFile( reader->m_lastfile );
01045 }
01046 }
01047 }
01048 else
01049 {
01050 showEditTools();
01051 }
01052
01053 if (m_scrollbar == NULL || m_scrollbar->isHidden())
01054 {
01055 reader->m_scrollpos = m_localscroll;
01056 }
01057 else
01058 {
01059 reader->m_scrollpos = (m_qtscroll == 0) ? m_localscroll : 0;
01060 }
01061
01062
01063 config.setGroup("Version");
01064 int major = config.readNumEntry("Major", 0);
01065 int bkmktype = config.readNumEntry("BkmkType", 0);
01066 char minor = config.readNumEntry("Minor", 0);
01067 if (CheckVersion(major, bkmktype, minor, this))
01068 {
01069 config.writeEntry("Major", major);
01070 config.writeEntry("BkmkType", bkmktype);
01071 config.writeEntry("Minor", (int)minor);
01072 }
01073
01074 if (kmap.isEmpty())
01075 {
01076 QMessageBox::warning(this, PROGNAME, "You haven't mapped any keys yet!\n\nYou will be taken to the key\nmapping dialog.\nA few defaults are provided\nbut you can change then to\nsuit yourself.\n\nYou can change the key\nmapping at any time by\nselecting the Settings/Button\noption on the menu.");
01077
01078 m_buttonprefs->mapkey(Qt::NoButton, Key_Up, cesPageUp);
01079 m_buttonprefs->mapkey(Qt::NoButton, Key_Down, cesPageDown);
01080
01081 m_buttonprefs->mapkey(Qt::NoButton, Key_Right, cesZoomIn);
01082 m_buttonprefs->mapkey(Qt::NoButton, Key_Left, cesZoomOut);
01083
01084 showbuttonprefs();
01085 }
01086 }
01087
01088 void QTReaderApp::addtoolbars(Config* config)
01089 {
01090 config->setGroup("Toolbar");
01091
01092 if (fileBar != NULL)
01093 {
01094 #if defined(USEQPE)
01095 if (fileBar != menubar)
01096 {
01097 fileBar->clear();
01098 }
01099 else
01100 {
01101 m_preferences_action->removeFrom( filebar() );
01102 m_open_action->removeFrom( filebar() );
01103 m_close_action->removeFrom( filebar() );
01104 m_info_action->removeFrom( filebar() );
01105 m_touch_action->removeFrom( filebar() );
01106 m_find_action->removeFrom( filebar() );
01107 }
01108 #else
01109 fileBar->clear();
01110 #endif
01111 }
01112
01113 m_preferences_action->addTo( filebar() );
01114 addfilebar(config, "Open", m_open_action);
01115 addfilebar(config, "Close", m_close_action);
01116 addfilebar(config, "Info", m_info_action);
01117 addfilebar(config, "Two/One Touch", m_touch_action);
01118 addfilebar(config, "Find", m_find_action);
01119
01120 if (navBar != NULL)
01121 {
01122 #if defined(USEQPE)
01123 if ((navBar == fileBar) && (fileBar == menubar))
01124 #else
01125 if (navBar == fileBar)
01126 #endif
01127 {
01128 m_scrollButton->removeFrom( navbar() );
01129 m_start_action->removeFrom( navbar() );
01130 m_end_action->removeFrom( navbar() );
01131 m_jump_action->removeFrom( navbar() );
01132 m_pageline_action->removeFrom( navbar() );
01133 m_pageup_action->removeFrom( navbar() );
01134 m_pagedn_action->removeFrom( navbar() );
01135 m_back_action->removeFrom( navbar() );
01136 m_home_action->removeFrom( navbar() );
01137 m_forward_action->removeFrom( navbar() );
01138 }
01139 else if (navBar != fileBar)
01140 {
01141 navBar->clear();
01142 }
01143 }
01144
01145 addnavbar(config, "Scroll", m_scrollButton);
01146 addnavbar(config, "Goto Start", m_start_action);
01147 addnavbar(config, "Goto End", m_end_action);
01148
01149 addnavbar(config, "Jump", m_jump_action);
01150 addnavbar(config, "Page/Line Scroll", m_pageline_action);
01151
01152 addnavbar(config, "Page Up", m_pageup_action);
01153 addnavbar(config, "Page Down", m_pagedn_action);
01154
01155 addnavbar(config, "Back", m_back_action);
01156 addnavbar(config, "Home", m_home_action);
01157 addnavbar(config, "Forward", m_forward_action);
01158
01159 if (viewBar != NULL)
01160 {
01161 #if defined(USEQPE)
01162 if ((viewBar == fileBar) && (fileBar == menubar))
01163 #else
01164 if (viewBar == fileBar)
01165 #endif
01166 {
01167 m_actFullscreen->removeFrom( filebar() );
01168 m_rotate_action->removeFrom( viewbar() );
01169 m_inverse_action->removeFrom( viewbar() );
01170 m_zoomin_action->removeFrom( viewbar() );
01171 m_zoomout_action->removeFrom( viewbar() );
01172 m_setfont_action->removeFrom( viewbar() );
01173 m_setenc_action->removeFrom( viewbar() );
01174 m_setmono_action->removeFrom( viewbar() );
01175 }
01176 else if (viewBar != fileBar)
01177 {
01178 viewBar->clear();
01179 }
01180 }
01181
01182 addviewbar(config, "Fullscreen", m_actFullscreen);
01183 addviewbar(config, "Rotate", m_rotate_action);
01184 addviewbar(config, "Invert Action", m_inverse_action);
01185 addviewbar(config, "Zoom In", m_zoomin_action);
01186 addviewbar(config, "Zoom Out", m_zoomout_action);
01187 addviewbar(config, "Set Font", m_setfont_action);
01188 addviewbar(config, "Encoding Select", m_setenc_action);
01189 addviewbar(config, "Ideogram Mode", m_setmono_action);
01190
01191 if (markBar != NULL)
01192 {
01193 #if defined(USEQPE)
01194 if ((markBar == fileBar) && (fileBar == menubar))
01195 #else
01196 if (markBar == fileBar)
01197 #endif
01198 {
01199 m_mark_action->removeFrom( markbar() );
01200 m_annotate_action->removeFrom( markbar());
01201 m_goto_action->removeFrom( markbar() );
01202 m_delete_action->removeFrom( markbar() );
01203 m_autogen_action->removeFrom( markbar() );
01204 m_clear_action->removeFrom( markbar() );
01205 m_save_action->removeFrom( markbar() );
01206 m_tidy_action->removeFrom( markbar() );
01207 m_startBlock_action->removeFrom( markbar() );
01208 m_endBlock_action->removeFrom( markbar() );
01209 }
01210 else if (markBar != fileBar)
01211 {
01212 markBar->clear();
01213 }
01214 }
01215 addmarkbar(config, "Mark", m_mark_action);
01216 addmarkbar(config, "Annotate", m_annotate_action);
01217 addmarkbar(config, "Goto", m_goto_action);
01218 addmarkbar(config, "Delete", m_delete_action);
01219 addmarkbar(config, "Autogen", m_autogen_action);
01220 addmarkbar(config, "Clear", m_clear_action);
01221 addmarkbar(config, "Save", m_save_action);
01222 addmarkbar(config, "Tidy", m_tidy_action);
01223 addmarkbar(config, "Start Block", m_startBlock_action);
01224 addmarkbar(config, "Copy Block", m_endBlock_action);
01225 if (checkbar(config, "Annotation indicator"))
01226 {
01227 if (m_bkmkAvail == NULL)
01228 {
01229 m_bkmkAvail = new QAction( tr( "Annotation" ), geticon( "find" ), QString::null, 0, this, 0 );
01230 connect( m_bkmkAvail, SIGNAL( activated() ), this, SLOT( showAnnotation() ) );
01231
01232 m_bkmkAvail->setEnabled(false);
01233 }
01234 QLabel *spacer = new QLabel(markBar, "");
01235 markbar()->setStretchableWidget(spacer);
01236 m_bkmkAvail->removeFrom( markbar() );
01237 m_bkmkAvail->addTo( markbar() );
01238 }
01239 else
01240 {
01241 if (m_bkmkAvail != NULL)
01242 {
01243 m_bkmkAvail->removeFrom( markbar() );
01244 delete m_bkmkAvail;
01245 m_bkmkAvail = NULL;
01246 }
01247 }
01248 }
01249
01250 bool QTReaderApp::checkbar(Config* _config, const QString& key)
01251 {
01252 return _config->readBoolEntry(key, false);
01253 }
01254
01255
01256 QToolBar* QTReaderApp::filebar()
01257 {
01258 if (fileBar == NULL)
01259 {
01260 switch (m_tbpol)
01261 {
01262 #if defined(USEQPE)
01263 case cesSingle:
01264
01265 fileBar = menubar;
01266 break;
01267 #endif
01268 default:
01269 qDebug("Incorrect toolbar policy set");
01270 case cesMenuTool:
01271 case cesMultiple:
01272
01273 fileBar = new QToolBar("File", this, m_tbposition);
01274 break;
01275 }
01276
01277 }
01278 return fileBar;
01279 }
01280 QToolBar* QTReaderApp::viewbar()
01281 {
01282 if (viewBar == NULL)
01283 {
01284 switch (m_tbpol)
01285 {
01286 case cesMultiple:
01287 viewBar = new QToolBar("View", this, m_tbposition);
01288 break;
01289 default:
01290 qDebug("Incorrect toolbar policy set");
01291 #ifdef USEQPE
01292 case cesSingle:
01293 #endif
01294 case cesMenuTool:
01295 viewBar = fileBar;
01296 break;
01297 }
01298 }
01299 return viewBar;
01300 }
01301 QToolBar* QTReaderApp::navbar()
01302 {
01303 if (navBar == NULL)
01304 {
01305 switch (m_tbpol)
01306 {
01307 case cesMultiple:
01308
01309 navBar = new QToolBar("Navigation", this, m_tbposition);
01310 break;
01311 default:
01312 qDebug("Incorrect toolbar policy set");
01313 #ifdef USEQPE
01314 case cesSingle:
01315 #endif
01316 case cesMenuTool:
01317 navBar = fileBar;
01318
01319 break;
01320 }
01321 }
01322 return navBar;
01323 }
01324 QToolBar* QTReaderApp::markbar()
01325 {
01326 if (markBar == NULL)
01327 {
01328 switch (m_tbpol)
01329 {
01330 case cesMultiple:
01331 markBar = new QToolBar("Marks", this, m_tbposition);
01332 break;
01333 default:
01334 qDebug("Incorrect toolbar policy set");
01335 #ifdef USEQPE
01336 case cesSingle:
01337 #endif
01338 case cesMenuTool:
01339 markBar = fileBar;
01340 break;
01341 }
01342 }
01343 return markBar;
01344 }
01345
01346 void QTReaderApp::addfilebar(Config* _config, const QString& key, QAction* a)
01347 {
01348 if (_config->readBoolEntry(key, false)) a->addTo( filebar() );
01349 }
01350 void QTReaderApp::addnavbar(Config* _config, const QString& key, QAction* a)
01351 {
01352 if (_config->readBoolEntry(key, false)) a->addTo( navbar() );
01353 }
01354 void QTReaderApp::addmarkbar(Config* _config, const QString& key, QAction* a)
01355 {
01356 if (_config->readBoolEntry(key, false)) a->addTo( markbar() );
01357 }
01358 void QTReaderApp::addviewbar(Config* _config, const QString& key, QAction* a)
01359 {
01360 if (_config->readBoolEntry(key, false)) a->addTo( viewbar() );
01361 }
01362
01363 void QTReaderApp::suspend() { reader->suspend(); }
01364
01365 void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data)
01366 {
01367 #ifndef USEMSGS
01368 return;
01369 #else
01370 QString msg = QString::fromUtf8(_msg);
01371
01372 qDebug("Received:%s", (const char*)msg);
01373 QDataStream stream( _data, IO_ReadOnly );
01374 if ( msg == "suspend()" )
01375 {
01376 qDebug("Suspending");
01377 suspend();
01378 qDebug("Suspendedb");
01379 }
01380 return;
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710 #endif
01711 }
01712
01713 ActionTypes QTReaderApp::ActNameToInt(const QString& _enc)
01714 {
01715 for (int i = 0; i < MAX_ACTIONS; i++)
01716 {
01717 if (m_buttonAction[i]->text() == _enc) return (ActionTypes)i;
01718 }
01719 return cesAutoScroll;
01720 }
01721
01722 void QTReaderApp::setinverted(bool sfs)
01723 {
01724 reader->setInverse(sfs);
01725 reader->setfilter(reader->getfilter());
01726 reader->refresh();
01727 }
01728
01729 void QTReaderApp::setrotated(bool sfs)
01730 {
01731 reader->setrotated(sfs);
01732 if (sfs)
01733 {
01734 m_layout->setDirection( (m_qtscroll == 2) ? QBoxLayout::BottomToTop : QBoxLayout::TopToBottom );
01735 if (m_scrollbar != NULL)
01736 {
01737 scrollbar->disconnect();
01738 m_scrollbar->setOrientation(Qt::Horizontal);
01739 connect(scrollbar, SIGNAL(nextLine()), reader, SLOT(lineUp()) );
01740 connect(scrollbar, SIGNAL(prevLine()), reader, SLOT(lineDown()) );
01741 connect(scrollbar, SIGNAL(nextPage()), reader, SLOT(dopageup()) );
01742 connect(scrollbar, SIGNAL(prevPage()), reader, SLOT(dopagedn()) );
01743 connect(scrollbar, SIGNAL(sliderMoved(int)), this, SLOT(actionscroll(int)) );
01744 }
01745
01746 }
01747 else
01748 {
01749 m_layout->setDirection( (m_qtscroll == 2) ? QBoxLayout::RightToLeft : QBoxLayout::LeftToRight );
01750 if (m_scrollbar != NULL)
01751 {
01752 scrollbar->disconnect();
01753 m_scrollbar->setOrientation(Qt::Vertical);
01754 connect(scrollbar, SIGNAL(nextLine()), reader, SLOT(lineDown()) );
01755 connect(scrollbar, SIGNAL(prevLine()), reader, SLOT(lineUp()) );
01756 connect(scrollbar, SIGNAL(nextPage()), reader, SLOT(dopagedn()) );
01757 connect(scrollbar, SIGNAL(prevPage()), reader, SLOT(dopageup()) );
01758 connect(scrollbar, SIGNAL(sliderMoved(int)), this, SLOT(actionscroll(int)) );
01759 }
01760
01761 }
01762 reader->refresh();
01763 }
01764
01765 void QTReaderApp::setgrab(bool sfs)
01766 {
01767 #ifdef USEQPE
01768 m_grabkeyboard = sfs;
01769 if (m_grabkeyboard)
01770 {
01771 ((QPEApplication*)qApp)->grabKeyboard();
01772 }
01773 else
01774 {
01775 ((QPEApplication*)qApp)->ungrabKeyboard();
01776 }
01777 #endif
01778 }
01779
01780 void QTReaderApp::setfullscreen(bool sfs)
01781 {
01782 reader->bDoUpdates = false;
01783 m_fullscreen = sfs;
01784 showEditTools();
01785
01786 reader->bDoUpdates = true;
01787 reader->update();
01788 }
01789
01790
01791
01793
01794
01795
01796 QTReaderApp::~QTReaderApp()
01797 {
01798 }
01799
01800 void QTReaderApp::autoScroll(bool _b)
01801 {
01802 reader->setautoscroll(_b);
01803 setScrollState(reader->m_autoScroll);
01804 }
01805
01806 void QTReaderApp::zoomin()
01807 {
01808 reader->zoomin();
01809 QFont f(reader->m_fontname, reader->m_fontControl.getsize(0));
01810 m_prog->setFont( f );
01811 }
01812
01813 void QTReaderApp::zoomout()
01814 {
01815 reader->zoomout();
01816 QFont f(reader->m_fontname, reader->m_fontControl.getsize(0));
01817 m_prog->setFont( f );
01818 }
01819
01820 void QTReaderApp::clearBkmkList()
01821 {
01822 delete pBkmklist;
01823 reader->pBkmklist = pBkmklist = NULL;
01824 m_fBkmksChanged = false;
01825 reader->refresh(true);
01826 }
01827
01828 void QTReaderApp::fileClose()
01829 {
01830 CCloseDialog* cd = new CCloseDialog(reader->m_string, false, this);
01831 if (cd->exec())
01832 {
01833 if (pOpenlist != NULL)
01834 {
01835 int ind = 0;
01836 Bkmk* p = (*pOpenlist)[ind];
01837 while (p != NULL && toQString(CFiledata(p->anno()).name()) != reader->m_lastfile)
01838 {
01839 p = (*pOpenlist)[++ind];
01840 }
01841 if (p != NULL) pOpenlist->erase(ind);
01842 if (cd->delFile())
01843 {
01844 unlink((const char*)reader->m_lastfile);
01845 }
01846 if (cd->delMarks())
01847 {
01848 #ifndef USEQPE
01849 QDir d = QDir::home();
01850 d.cd(APPDIR);
01851 d.remove(reader->m_string);
01852 #else
01853 unlink((const char *)Global::applicationFileName(APPDIR,reader->m_string));
01854 #endif
01855 }
01856 if (cd->delConfig())
01857 {
01858 #ifndef USEQPE
01859 QDir d = QDir::home();
01860 d.cd(APPDIR "/configs");
01861 d.remove(reader->m_string);
01862 #else
01863 unlink((const char *)Global::applicationFileName(APPDIR "/configs",reader->m_string));
01864 #endif
01865 }
01866 }
01867
01868 fileOpen2();
01869 }
01870 delete cd;
01871 }
01872
01873 void QTReaderApp::updatefileinfo()
01874 {
01875 if (reader->m_string.isEmpty()) return;
01876 if (reader->m_lastfile.isEmpty()) return;
01877 tchar* nm = fromQString(reader->m_string);
01878 tchar* fl = fromQString(reader->m_lastfile);
01879
01880 bool notadded = true;
01881 if (pOpenlist == NULL) pOpenlist = new CList<Bkmk>;
01882 else
01883 {
01884 for (CList<Bkmk>::iterator iter = pOpenlist->begin(); iter != pOpenlist->end(); iter++)
01885 {
01886 if (ustrcmp(CFiledata(iter->anno()).name(), fl) == 0)
01887 {
01888 iter->value(reader->pagelocate());
01889 unsigned short dlen;
01890 unsigned char* data;
01891 CFiledata fd(iter->anno());
01892 reader->setSaveData(data, dlen, fd.content(), fd.length());
01893
01894
01895 iter->setAnno(data, dlen);
01896 notadded = false;
01897 delete [] data;
01898 break;
01899 }
01900 }
01901 }
01902
01903 if (notadded)
01904 {
01905 struct stat fnstat;
01906 stat((const char *)reader->m_lastfile, &fnstat);
01907 CFiledata fd(fnstat.st_mtime, fl);
01908 unsigned short dlen;
01909 unsigned char* data;
01910 reader->setSaveData(data, dlen, fd.content(), fd.length());
01911 pOpenlist->push_front(Bkmk(nm, data, dlen, reader->pagelocate()));
01912
01913 delete [] data;
01914 }
01915 delete [] nm;
01916 delete [] fl;
01917 }
01918
01919 void QTReaderApp::fileOpen()
01920 {
01921
01922
01923
01924
01925
01926
01927
01928
01929 updatefileinfo();
01930 fileOpen2();
01931 }
01932
01933 void QTReaderApp::fileOpen2()
01934 {
01935 if (pBkmklist != NULL)
01936 {
01937 if (m_fBkmksChanged)
01938 {
01939 if (QMessageBox::warning(this, PROGNAME, "Save bookmarks?", "Save", "Don't bother") == 0)
01940 savebkmks();
01941 }
01942 delete pBkmklist;
01943 reader->pBkmklist = pBkmklist = NULL;
01944 m_fBkmksChanged = false;
01945 }
01946 reader->disableAutoscroll();
01947
01948
01949
01950
01951 bool usebrowser = true;
01952 if (pOpenlist != NULL)
01953 {
01954 m_nBkmkAction = cOpenFile;
01955 if (listbkmk(pOpenlist, "Browse", true)) usebrowser = false;
01956 }
01957 if (usebrowser)
01958 {
01959 QString fn = usefilebrowser();
01960
01961 if (!fn.isEmpty() && QFileInfo(fn).isFile())
01962 {
01963 openFile(fn);
01964 }
01965 reader->setFocus();
01966 }
01967
01968
01969 }
01970
01971 QString QTReaderApp::usefilebrowser()
01972 {
01973 #ifndef USEQPE
01974 QString s( QFileDialog::getOpenFileName( reader->m_lastfile, QString::null, this ) );
01975 return s;
01976 #else
01977 QString fn;
01978 #if defined(OPIE) && defined(OPIEFILEDIALOG)
01979 QMap<QString, QStringList> mimeTypes;
01980 QStringList etypes;
01981 etypes << "etext/*";
01982 mimeTypes.insert( tr("eText"), etypes );
01983 QStringList types;
01984 types << "text/*";
01985 mimeTypes.insert( tr("Text"), types );
01986 mimeTypes.insert( tr("All"), "*/*" );
01987 fn = OFileDialog::getOpenFileName(OFileSelector::EXTENDED_ALL, QFileInfo(reader->m_lastfile).dirPath(true), QString::null, mimeTypes, 0, "OpieReader");
01988 #else
01989 fileBrowser* fb = new fileBrowser(false, this,"OpieReader",!m_bFloatingDialog,
01990 0,
01991
01992 "*", QFileInfo(reader->m_lastfile).dirPath(true));
01993
01994
01995 if (fb->exec())
01996 {
01997 fn = fb->getCurrentFile();
01998 }
01999
02000 delete fb;
02001 #endif
02002 showEditTools();
02003 return fn;
02004 #endif
02005 }
02006
02007 void QTReaderApp::showgraphic(QImage& pm)
02008 {
02009 m_graphicwin->setImage(pm);
02010 editorStack->raiseWidget( m_graphicwin );
02011 hidetoolbars();
02012 m_graphicwin->setFocus();
02013 }
02014
02015 void QTReaderApp::showbuttonprefs()
02016 {
02017 editorStack->raiseWidget( m_buttonprefs );
02018 hidetoolbars();
02019 m_buttonprefs->setFocus();
02020 m_kmapchanged = true;
02021 }
02022
02023 void QTReaderApp::showprefs()
02024 {
02025 CPrefs* prefwin = new CPrefs(reader->width(), !m_bFloatingDialog, this);
02026
02027
02028 prefwin->bgtype(m_bgtype);
02029 prefwin->repalm(reader->brepalm);
02030 prefwin->UnderlineLink(reader->bunderlineLink);
02031 prefwin->kern(reader->bkern);
02032 prefwin->hyphenate(reader->hyphenate);
02033
02034 prefwin->scrolltype(reader->m_scrolltype);
02035 prefwin->scrollstep(reader->m_scrollstep);
02036 prefwin->scrollcolor(m_scrollcolor);
02037 prefwin->minibarcol(m_scrollbarcolor);
02038 prefwin->foreground(m_foreground);
02039 prefwin->background(m_background);
02040 prefwin->twotouch(m_twoTouch);
02041 prefwin->propfontchange(m_propogatefontchange);
02042 prefwin->StripCR(reader->bstripcr);
02043 prefwin->InlineTables(!reader->bNoInlineTables);
02044 prefwin->Dehyphen(reader->bdehyphen);
02045 prefwin->SingleSpace(reader->bonespace);
02046 prefwin->Unindent(reader->bunindent);
02047 prefwin->Reparagraph(reader->brepara);
02048 prefwin->DoubleSpace(reader->bdblspce);
02049 prefwin->Remap(reader->bremap);
02050 prefwin->Embolden(reader->bmakebold);
02051 prefwin->FullJustify(reader->bfulljust);
02052
02053
02054 prefwin->FixGraphics(reader->m_fontControl.FixGraphics());
02055 prefwin->ParaLead(reader->getextraspace());
02056 prefwin->LineLead(reader->getlead());
02057 prefwin->TopMargin(reader->m_abstopmargin);
02058 prefwin->BottomMargin(reader->m_absbottommargin);
02059 prefwin->LeftMargin(reader->m_absleft_border);
02060 prefwin->RightMargin(reader->m_absright_border);
02061 prefwin->Indent(reader->bindenter);
02062 if (reader->bautofmt)
02063 {
02064 prefwin->Markup(0);
02065 }
02066 else if (reader->btextfmt)
02067 {
02068 prefwin->Markup(2);
02069 }
02070 else if (reader->bstriphtml)
02071 {
02072 prefwin->Markup(3);
02073 }
02074 else if (reader->bpeanut)
02075 {
02076 prefwin->Markup(4);
02077 }
02078 else
02079 {
02080 prefwin->Markup(1);
02081 }
02082 prefwin->Depluck(reader->bdepluck);
02083 prefwin->Dejpluck(reader->bdejpluck);
02084 prefwin->Continuous(reader->m_continuousDocument);
02085 prefwin->DoubleBuffer(reader->m_doubleBuffered);
02086
02087 prefwin->dictApplication(m_targetapp);
02088 prefwin->dictMessage(m_targetmsg);
02089
02090
02091
02092
02093
02094
02095
02096
02097 prefwin->miscannotation(m_doAnnotation);
02098 prefwin->miscdictionary(m_doDictionary);
02099 prefwin->miscclipboard(m_doClipboard);
02100 prefwin->miscoutput(m_doOutput);
02101
02102 prefwin->SwapMouse(reader->m_swapmouse);
02103
02104 prefwin->Font(reader->m_fontname);
02105
02106 prefwin->gfxsize(reader->getBaseSize());
02107
02108 prefwin->pageoverlap(reader->m_overlap);
02109
02110 prefwin->ideogram(reader->m_bMonoSpaced);
02111
02112 prefwin->encoding(reader->m_encd);
02113
02114 prefwin->ideogramwidth(reader->m_charpc);
02115
02116 prefwin->outcodec(reader->m_outputName);
02117
02118 if (prefwin->exec())
02119 {
02120
02121 reader->brepalm = prefwin->repalm();
02122 reader->bunderlineLink = prefwin->UnderlineLink();
02123
02124 reader->bkern = prefwin->kern();
02125 reader->hyphenate = prefwin->hyphenate();
02126
02127 reader->m_scrolltype = prefwin->scrolltype();
02128 reader->m_scrollstep = prefwin->scrollstep();
02129 m_scrollcolor = prefwin->scrollcolor();
02130 setscrollcolour();
02131 m_scrollbarcolor = prefwin->minibarcol();
02132 setscrollbarcolour();
02133 m_foreground = prefwin->foreground();
02134 reader->setForeground(getcolour(m_foreground));
02135 m_background = prefwin->background();
02136 reader->setBackground(getcolour(m_background));
02137 m_twoTouch = prefwin->twotouch();
02138 reader->setTwoTouch(m_twoTouch);
02139 m_touch_action->setOn(m_twoTouch);
02140
02141 reader->bstripcr = prefwin->StripCR();
02142 reader->bNoInlineTables = !prefwin->InlineTables();
02143 reader->bdehyphen = prefwin->Dehyphen();
02144 reader->bonespace = prefwin->SingleSpace();
02145 reader->bunindent = prefwin->Unindent();
02146 reader->brepara = prefwin->Reparagraph();
02147 reader->bdblspce = prefwin->DoubleSpace();
02148 reader->bremap = prefwin->Remap();
02149 reader->bmakebold = prefwin->Embolden();
02150 reader->bfulljust = prefwin->FullJustify();
02151
02152
02153 reader->m_fontControl.FixGraphics(prefwin->FixGraphics());
02154
02155 reader->setextraspace(prefwin->ParaLead());
02156 reader->setlead(prefwin->LineLead());
02157 reader->m_abstopmargin = prefwin->TopMargin();
02158 reader->m_absbottommargin = prefwin->BottomMargin();
02159 reader->m_absleft_border = prefwin->LeftMargin();
02160 reader->m_absright_border = prefwin->RightMargin();
02161 reader->bindenter = prefwin->Indent();
02162 reader->bautofmt = reader->btextfmt = reader->bstriphtml = reader->bpeanut = false;
02163 switch (prefwin->Markup())
02164 {
02165 case 0:
02166 reader->bautofmt = true;
02167 break;
02168 case 1:
02169 break;
02170 case 2:
02171 reader->btextfmt = true;
02172 break;
02173 case 3:
02174 reader->bstriphtml = true;
02175 break;
02176 case 4:
02177 reader->bpeanut = true;
02178 break;
02179 default:
02180 qDebug("Format out of range");
02181 }
02182 reader->bdepluck = prefwin->Depluck();
02183 reader->bdejpluck = prefwin->Dejpluck();
02184 reader->setContinuous(prefwin->Continuous());
02185 reader->setDoubleBuffer(prefwin->DoubleBuffer());
02186
02187
02188
02189
02190
02191
02192
02193 m_targetapp = prefwin->dictApplication();
02194 m_targetmsg = prefwin->dictMessage();
02195
02196 m_doAnnotation = prefwin->miscannotation();
02197 m_doDictionary = prefwin->miscdictionary();
02198 m_doClipboard = prefwin->miscclipboard();
02199 m_doOutput = prefwin->miscoutput();
02200 reader->m_swapmouse = prefwin->SwapMouse();
02201 reader->setBaseSize(prefwin->gfxsize());
02202 reader->m_overlap = prefwin->pageoverlap();
02203 reader->m_bMonoSpaced = prefwin->ideogram();
02204 m_setmono_action->setOn(reader->m_bMonoSpaced);
02205 reader->m_encd = prefwin->encoding();
02206 reader->m_charpc = prefwin->ideogramwidth();
02207
02208 if (
02209 reader->m_fontname != prefwin->Font()
02210 ||
02211 m_propogatefontchange != prefwin->propfontchange())
02212 {
02213 m_propogatefontchange = prefwin->propfontchange();
02214 setfontHelper(prefwin->Font());
02215 }
02216 if (m_bgtype != (bground)prefwin->bgtype())
02217 {
02218 m_bgtype = (bground)prefwin->bgtype();
02219 setBackgroundBitmap();
02220 }
02221 qDebug("OutCodec:%s", (const char*)prefwin->outcodec());
02222 if (reader->m_outputName != prefwin->outcodec())
02223 {
02224 if (reader->m_output != NULL)
02225 {
02226 QMessageBox::warning(this, PROGNAME, "Change of output codec\nrequires a restart");
02227 }
02228 reader->m_outputName = prefwin->outcodec();
02229 }
02230 delete prefwin;
02231 reader->setfilter(reader->getfilter());
02232 reader->refresh();
02233 }
02234 else
02235 {
02236 delete prefwin;
02237 }
02238 }
02239
02240 void QTReaderApp::showtoolbarprefs()
02241 {
02242 #ifdef USEQPE
02243 CBarPrefs* prefwin = new CBarPrefs(APPDIR, !m_bFloatingDialog, this);
02244 #else
02245 QFileInfo fi;
02246 QDir d = QDir::home();
02247 if ( !d.cd(APPDIR) )
02248 {
02249 qWarning( "Cannot find the \"~/%s\" directory", APPDIR );
02250 d = QDir::home();
02251 d.mkdir(APPDIR);
02252 d.cd(APPDIR);
02253 }
02254 fi.setFile(d, INIFILE);
02255 CBarPrefs* prefwin = new CBarPrefs(fi.absFilePath(), !m_bFloatingDialog, this);
02256 #endif
02257 prefwin->tbpolicy(m_tbpolsave);
02258 prefwin->tbposition(m_tbposition-2);
02259 prefwin->tbmovable(m_tbmovesave);
02260 prefwin->floating(m_bFloatingDialog);
02261 prefwin->qtscroll(m_qtscroll);
02262 prefwin->localscroll(m_localscroll);
02263 if (prefwin->exec())
02264 {
02265 m_bFloatingDialog = prefwin->floating();
02266 if (
02267 m_tbpolsave != (ToolbarPolicy)prefwin->tbpolicy()
02268 ||
02269 m_tbposition != (ToolBarDock)(prefwin->tbposition()+2)
02270 ||
02271 m_tbmovesave != prefwin->tbmovable()
02272 ||
02273 m_qtscroll != prefwin->qtscroll()
02274
02275
02276 )
02277 {
02278 QMessageBox::warning(this, PROGNAME, "Some changes won't take effect\nuntil the next time the\napplication is started");
02279 }
02280 m_tbpolsave = (ToolbarPolicy)prefwin->tbpolicy();
02281 m_tbposition = (ToolBarDock)(prefwin->tbposition()+2);
02282 m_tbmovesave = prefwin->tbmovable();
02283 reader->m_scrollpos = m_localscroll = prefwin->localscroll();
02284 if (m_qtscroll != prefwin->qtscroll())
02285 {
02286 m_qtscroll = prefwin->qtscroll();
02287 setrotated(reader->m_rotated);
02288 }
02289 if (m_scrollbar == NULL || m_scrollbar->isHidden())
02290 {
02291 reader->m_scrollpos = m_localscroll;
02292 }
02293 else
02294 {
02295 reader->m_scrollpos = (m_qtscroll == 0) ? m_localscroll : 0;
02296 }
02297 bool isChanged = prefwin->isChanged();
02298 delete prefwin;
02299 #ifdef USEQPE
02300 Config config( APPDIR );
02301 #else
02302 QFileInfo fi;
02303 QDir d = QDir::home();
02304 if ( !d.cd(APPDIR) )
02305 {
02306 qWarning( "Cannot find the \"~/%s\" directory", APPDIR );
02307 d = QDir::home();
02308 d.mkdir(APPDIR);
02309 d.cd(APPDIR);
02310 }
02311 fi.setFile(d, INIFILE);
02312 Config config( fi.absFilePath() );
02313 #endif
02314 if (isChanged) addtoolbars(&config);
02315 }
02316 else
02317 {
02318 delete prefwin;
02319 }
02320 }
02321
02322 void QTReaderApp::showinfo()
02323 {
02324 unsigned long ds, fs, ts, pl, dl;
02325 if (reader->empty())
02326 {
02327 QMessageBox::information(this, PROGNAME, "No file loaded", 1);
02328 }
02329 else
02330 {
02331 reader->sizes(fs,ts);
02332 ds = reader->buffdoc.endSection() - reader->buffdoc.startSection();
02333 pl = reader->pagelocate();
02334 dl = pl - reader->buffdoc.startSection();
02335 m_infoWin->setFileSize(fs);
02336 m_infoWin->setTextSize(ts);
02337 if (fs > UINT_MAX/100)
02338 {
02339 unsigned long t1 = (ts+50)/100;
02340 m_infoWin->setRatio(100-(fs + (t1 >> 1))/t1);
02341 }
02342 else
02343 {
02344 m_infoWin->setRatio(100-(100*fs + (ts >> 1))/ts);
02345 }
02346 m_infoWin->setLocation(pl);
02347 if (pl > UINT_MAX/100)
02348 {
02349 unsigned long t1 = (ts+50)/100;
02350 m_infoWin->setRead((pl + (t1 >> 1))/t1);
02351 }
02352 else
02353 {
02354 m_infoWin->setRead((100*pl + (ts >> 1))/ts);
02355 }
02356 m_infoWin->setDocSize(ds);
02357 m_infoWin->setDocLocation(dl);
02358 if (dl > UINT_MAX/100)
02359 {
02360 unsigned long d1 = (ds+50)/100;
02361 m_infoWin->setDocRead((dl + (d1 >> 1))/d1);
02362 }
02363 else
02364 {
02365 m_infoWin->setDocRead((100*dl + (ds >> 1))/ds);
02366 }
02367 m_infoWin->setZoom(reader->m_fontControl.currentsize()*10);
02368 m_infoWin->setAbout(QString("\nApplication (c) Tim Wentford\n")+reader->about());
02369 editorStack->raiseWidget( m_infoWin );
02370 hidetoolbars();
02371 m_infoWin->setFocus();
02372 }
02373 }
02374
02375 void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn, size_t posn2)
02376 {
02377 if (pBkmklist == NULL) reader->pBkmklist = pBkmklist = new CList<Bkmk>;
02378 #ifdef _UNICODE
02379 CBuffer buff(name.length()+1);
02380 int i;
02381 for (i = 0; i < name.length(); i++)
02382 {
02383 buff[i] = name[i].unicode();
02384 }
02385 buff[i] = 0;
02386 CBuffer buff2(text.length()+1);
02387 for (i = 0; i < text.length(); i++)
02388 {
02389 buff2[i] = text[i].unicode();
02390 }
02391 buff2[i] = 0;
02392 Bkmk b(buff.data(), buff2.data(), posn, posn2);
02393 QColor c = m_annoWin->getColor();
02394 int red,green,blue;
02395 c.rgb(&red, &green, &blue);
02396 b.red(red);
02397 b.green(green);
02398 b.blue(blue);
02399 pBkmklist->push_front(b);
02400 #else
02401 pBkmklist->push_front(Bkmk((const tchar*)text,posn));
02402 #endif
02403 m_fBkmksChanged = true;
02404 pBkmklist->sort();
02405 }
02406
02407 void QTReaderApp::addAnno(const QString& name, const QString& text)
02408 {
02409 if (m_annoIsEditing)
02410 {
02411 if (name.isEmpty())
02412 {
02413 QMessageBox::information(this, PROGNAME, "Need a name for the bookmark\nPlease try again", 1);
02414 }
02415 else
02416 {
02417 addAnno(name, text, m_annoWin->getPosn(), m_annoWin->getPosn2());
02418 }
02419 showEditTools();
02420 }
02421 else
02422 {
02423 if (m_annoWin->edited())
02424 {
02425 CBuffer buff(text.length()+1);
02426 int i;
02427 for (i = 0; i < text.length(); i++)
02428 {
02429 buff[i] = text[i].unicode();
02430 }
02431 buff[i] = 0;
02432 m_fBkmksChanged = true;
02433 m_anno->setAnno(buff.data());
02434 }
02435 QColor c = m_annoWin->getColor();
02436 int red,green,blue;
02437 c.rgb(&red, &green, &blue);
02438 m_anno->red(red);
02439 m_anno->green(green);
02440 m_anno->blue(blue);
02441 bool found = findNextBookmark(m_anno->value()+1);
02442 if (found)
02443 {
02444 m_annoWin->setName(toQString(m_anno->name()));
02445 m_annoWin->setAnno(toQString(m_anno->anno()));
02446 m_annoWin->setColor(QColor(m_anno->red(), m_anno->green(), m_anno->blue()));
02447 }
02448 else
02449 {
02450 showEditTools();
02451 }
02452 }
02453 }
02454
02455 bool QTReaderApp::findNextBookmark(size_t start)
02456 {
02457 bool found = false;
02458 for (CList<Bkmk>::iterator iter = pBkmklist->begin(); iter != pBkmklist->end(); iter++)
02459 {
02460 if (iter->value() >= start)
02461 {
02462 if (iter->value() < reader->locate())
02463 {
02464 found = true;
02465 m_anno = iter.pContent();
02466 }
02467 break;
02468 }
02469 }
02470 return found;
02471 }
02472
02473 void QTReaderApp::addanno()
02474 {
02475 if (reader->empty())
02476 {
02477 QMessageBox::information(this, PROGNAME, "No file loaded", 1);
02478 }
02479 else
02480 {
02481 m_annoWin->setName("");
02482 m_annoWin->setAnno("");
02483 m_annoWin->setPosn(reader->pagelocate());
02484 m_annoIsEditing = true;
02485 editorStack->raiseWidget( m_annoWin );
02486 hidetoolbars();
02487 #ifdef USEQPE
02488 Global::showInputMethod();
02489 #endif
02490 m_annoWin->setFocus();
02491 }
02492 }
02493
02494 void QTReaderApp::infoClose()
02495 {
02496 m_debounce = m_buttonprefs->Debounce();
02497 if (m_kmapchanged)
02498 {
02499 m_kmapchanged = false;
02500 #ifndef USEQPE
02501 QDir d = QDir::home();
02502 d.cd(APPDIR);
02503 QFileInfo fi(d, ".keymap");
02504 FILE* f = fopen((const char *)fi.absFilePath(), "w");
02505 #else
02506 FILE* f = fopen((const char *)Global::applicationFileName(APPDIR,".keymap"), "w");
02507 #endif
02508 if (f != NULL)
02509 {
02510 uint cnt = KEYMAPVERSION;
02511 fwrite(&cnt, sizeof(cnt), 1, f);
02512 cnt = kmap.count();
02513 fwrite(&cnt, sizeof(cnt), 1, f);
02514 for (QMap<orKey,int>::Iterator i = kmap.begin(); i != kmap.end(); i++)
02515 {
02516 orKey key = i.key();
02517 int data = i.data();
02518 fwrite(&key, sizeof(key), 1, f);
02519 fwrite(&data, sizeof(data), 1, f);
02520 qDebug("Saved %s as %u", (const char*)key.text(), data);
02521 }
02522 fclose(f);
02523 }
02524 }
02525 showEditTools();
02526 }
02527
02528
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539
02540
02541
02542 void QTReaderApp::editMark()
02543 {
02544 m_savedpos = reader->pagelocate();
02545 }
02546
02547 void QTReaderApp::editCopy()
02548 {
02549 QClipboard* cb = QApplication::clipboard();
02550 QString text;
02551 int ch;
02552 unsigned long currentpos = reader->pagelocate();
02553 unsigned long endpos = reader->locate();
02554 if (m_savedpos == 0xffffffff)
02555 {
02556 m_savedpos = currentpos;
02557 }
02558 reader->jumpto(m_savedpos);
02559 while (reader->explocate() < endpos && (ch = reader->getch()) != UEOF)
02560 {
02561 text += ch;
02562 }
02563 cb->setText(text);
02564 reader->locate(currentpos);
02565 m_savedpos = 0xffffffff;
02566 }
02567
02568 void QTReaderApp::gotoStart()
02569 {
02570 reader->locate(reader->buffdoc.startSection());
02571 }
02572
02573 void QTReaderApp::gotoEnd()
02574 {
02575 reader->dopageup(reader->buffdoc.endSection());
02576 }
02577
02578 void QTReaderApp::pageup()
02579 {
02580 reader->NavUp();
02581 }
02582
02583 void QTReaderApp::pagedn()
02584 {
02585 reader->NavDown();
02586 }
02587
02588 void QTReaderApp::pagemode(bool _b)
02589 {
02590 reader->setpagemode(_b);
02591 }
02592
02593
02594
02595
02596
02597
02598
02599
02600
02601
02602
02603 void QTReaderApp::settarget()
02604 {
02605 m_nRegAction = cSetTarget;
02606 QString text = ((m_targetapp.isEmpty()) ? QString("") : m_targetapp)
02607 + "/"
02608 + ((m_targetmsg.isEmpty()) ? QString("") : m_targetmsg);
02609 regEdit->setText(text);
02610 do_regedit();
02611 }
02612
02613
02614
02615
02616
02617
02618
02619
02620
02621
02622
02623
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638 void QTReaderApp::editFind()
02639 {
02640 searchStart = reader->pagelocate();
02641 #ifdef __ISEARCH
02642 searchStack = new QStack<searchrecord>;
02643 #endif
02644 #ifdef USEQPE
02645 Global::showInputMethod();
02646 #endif
02647 searchBar->show();
02648 searchVisible = TRUE;
02649 searchEdit->setFocus();
02650 #ifdef __ISEARCH
02651 searchStack->push(new searchrecord("",reader->pagelocate()));
02652 #endif
02653 }
02654
02655 void QTReaderApp::findNext()
02656 {
02657
02658 #ifdef __ISEARCH
02659 QString arg = searchEdit->text();
02660 #else
02661 QRegExp arg = searchEdit->text();
02662 #endif
02663 CDrawBuffer test(&(reader->m_fontControl));
02664 size_t start = reader->pagelocate();
02665 reader->jumpto(start);
02666 reader->getline(&test);
02667 dosearch(start, test, arg);
02668 }
02669
02670 void QTReaderApp::findClose()
02671 {
02672 searchVisible = FALSE;
02673 searchEdit->setText("");
02674 #ifdef USEQPE
02675 Global::hideInputMethod();
02676 #endif
02677 searchBar->hide();
02678 #ifdef __ISEARCH
02679
02680 while (!searchStack->isEmpty())
02681 {
02682 delete searchStack->pop();
02683 }
02684 delete searchStack;
02685 #endif
02686 reader->setFocus();
02687 }
02688
02689 void QTReaderApp::regClose()
02690 {
02691 regVisible = FALSE;
02692 regEdit->setText("");
02693 regBar->hide();
02694 #ifdef USEQPE
02695 Global::hideInputMethod();
02696 #endif
02697 reader->setFocus();
02698 }
02699
02700 #ifdef __ISEARCH
02701 bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QString& arg)
02702 #else
02703 bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg)
02704 #endif
02705 {
02706 bool ret = true;
02707 unsigned long fs, ts;
02708 reader->sizes(fs,ts);
02709 size_t pos = reader->locate();
02710 pbar->setGeometry(searchBar->x(),searchBar->y(),searchBar->width(), searchBar->height());
02711 pbar->show();
02712 pbar->raise();
02713 pbar->reset();
02714 int offset;
02715 int lastpc = (100*pos)/ts;
02716 pbar->setProgress(lastpc);
02717
02718 if (reader->buffdoc.getpara(test) >= 0)
02719 {
02720 reader->setFocus();
02721 #ifdef __ISEARCH
02722 while (strstr(test.data(),(const tchar*)arg) == NULL)
02723 #else
02724 #ifdef _UNICODE
02725 while ((offset = arg.match(toQString(test.data()))) == -1)
02726 #else
02727 while (arg.match(test.data()) == -1)
02728 #endif
02729 #endif
02730 {
02731 pos = reader->locate();
02732 int pc = (100*pos)/ts;
02733 if (pc != lastpc)
02734 {
02735 pbar->setProgress(pc);
02736 qApp->processEvents();
02737 reader->setFocus();
02738 lastpc = pc;
02739 }
02740
02741 if (reader->buffdoc.getpara(test) < 0)
02742 {
02743 if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2)
02744 pos = searchStart;
02745 else
02746 pos = start;
02747 findClose();
02748 pbar->hide();
02749 reader->locate(pos);
02750 return false;
02751 }
02752 }
02753
02754 pbar->hide();
02755
02756 reader->locate(pos+offset);
02757
02758
02759 ret = true;
02760 }
02761 else
02762 {
02763 if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2)
02764 pos = searchStart;
02765 else
02766 pos = start;
02767 ret = false;
02768 findClose();
02769 }
02770 return ret;
02771 }
02772
02773 #ifdef __ISEARCH
02774 void QTReaderApp::search(const QString & arg)
02775 {
02776 searchrecord* ss = searchStack->top();
02777 CBuffer test;
02778 size_t start = reader->pagelocate();
02779 bool haspopped = false;
02780 while (arg.left(ss->s.length()) != ss->s)
02781 {
02782 haspopped = true;
02783 start = ss->pos;
02784
02785 searchStack->pop();
02786 delete ss;
02787 }
02788 if (haspopped) reader->locate(start);
02789
02790
02791
02792
02793
02794
02795
02796
02797
02798 else
02799 {
02800 start = reader->pagelocate();
02801 reader->jumpto(start);
02802 searchStack->push(new searchrecord(arg,start));
02803 }
02804 dosearch(start, test, arg);
02805 }
02806 #else
02807 void QTReaderApp::search()
02808 {
02809 findNext();
02810 }
02811 #endif
02812
02813 void QTReaderApp::openFile( const QString &f, unsigned int loc )
02814 {
02815
02816
02817
02818
02819
02820
02821 clear();
02822 QFileInfo fm(f);
02823 if ( fm.exists() )
02824 {
02825
02826 #ifdef USEQPE
02827 if (fm.extension( FALSE ) == "desktop")
02828 {
02829 DocLnk d(f);
02830 QFileInfo fnew(d.file());
02831 fm = fnew;
02832 if (!fm.exists()) return;
02833 }
02834 #endif
02835 clear();
02836 reader->setText(fm.baseName(), fm.absFilePath(), loc);
02837 m_loadedconfig = readconfig(APPDIR "/configs", reader->m_string, false);
02838 qDebug("Showing tools");
02839 showEditTools();
02840 qDebug("Shown tools");
02841 readbkmks();
02842 qDebug("read markss");
02843 m_savedpos = 0xffffffff;
02844 }
02845 else
02846 {
02847 QString msg = f;
02848 msg += "\nFile does not exist";
02849 QMessageBox::information(this, PROGNAME, msg);
02850 reader->m_lastfile = QString::null;
02851 }
02852
02853 }
02854
02855
02856
02857
02858
02859
02860
02861
02862
02863
02864 void QTReaderApp::handlekey(QKeyEvent* e)
02865 {
02866
02867 timeb now;
02868 ftime(&now);
02869 unsigned long etime = (1000*(now.time - m_lastkeytime.time) + now.millitm)-m_lastkeytime.millitm;
02870 if (etime < m_debounce)
02871 {
02872 return;
02873 }
02874 switch(e->key())
02875 {
02876 case Key_Escape:
02877 qDebug("escape event");
02878 if (m_disableesckey)
02879 {
02880 m_disableesckey = false;
02881 }
02882 else
02883 {
02884 m_bcloseDisabled = true;
02885 if (m_fullscreen)
02886 {
02887 m_actFullscreen->setOn(false);
02888 e->accept();
02889 }
02890 else
02891 {
02892
02893 doAction(e);
02894 }
02895 }
02896 break;
02897
02898
02899
02900
02901
02902
02903
02904
02905
02906
02907
02908
02909
02910
02911
02912
02913
02914
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924
02925
02926
02927
02928
02929
02930
02931
02932
02933
02934
02935
02936
02937
02938
02939
02940
02941
02942
02943
02944
02945
02946
02947 default:
02948 {
02949 doAction(e);
02950 }
02951
02952
02953
02954
02955
02956
02957
02958 }
02959 ftime(&m_lastkeytime);
02960 }
02961
02962 #if defined(USEQPE) && defined(USENEWFULLSCREEN)
02963 void QTReaderApp::focusInEvent(QFocusEvent *)
02964 {
02965 if (m_usenewfullscreen && m_fullscreen && (editorStack->visibleWidget() == reader))
02966 {
02967 m_usenewfullscreen = false;
02968 reader->bDoUpdates = false;
02969 showEditTools();
02970 reader->bDoUpdates = true;
02971 reader->update();
02972 m_usenewfullscreen = true;
02973 }
02974 }
02975
02976 void QTReaderApp::resizeEvent(QResizeEvent *)
02977 {
02978 if (m_usenewfullscreen && m_fullscreen && (editorStack->visibleWidget() == reader))
02979 {
02980 m_usenewfullscreen = false;
02981 reader->bDoUpdates = false;
02982 showEditTools();
02983 reader->bDoUpdates = true;
02984 reader->update();
02985 m_usenewfullscreen = true;
02986 }
02987 }
02988 #endif
02989
02990 void QTReaderApp::showEditTools()
02991 {
02992
02993
02994 if (m_fullscreen)
02995 {
02996 #if defined(USEQPE)
02997 if (menubar != NULL) menubar->hide();
02998 #endif
02999 if (fileBar != NULL) fileBar->hide();
03000 if (viewBar != NULL) viewBar->hide();
03001 if (navBar != NULL) navBar->hide();
03002 if (markBar != NULL) markBar->hide();
03003 if (m_prog != NULL)
03004 {
03005
03006 m_prog->hide();
03007 }
03008 searchBar->hide();
03009 regBar->hide();
03010 #ifdef USEQPE
03011 Global::hideInputMethod();
03012 #endif
03013 if (m_scrollbar != NULL) m_scrollbar->hide();
03014 m_fontBar->hide();
03015
03016 showFullScreen();
03017 }
03018 else
03019 {
03020
03021 #ifdef USEQPE
03022 Global::hideInputMethod();
03023 #endif
03024
03025 if (m_scrollbar != NULL)
03026 {
03027 if (m_scrollishidden)
03028 {
03029 m_scrollbar->hide();
03030 }
03031 else
03032 {
03033 m_scrollbar->show();
03034 }
03035 }
03036 if (!m_hidebars)
03037 {
03038 #if defined(USEQPE)
03039 menubar->show();
03040 #endif
03041 if (fileBar != NULL) fileBar->show();
03042 if (viewBar != NULL) viewBar->show();
03043 if (navBar != NULL) navBar->show();
03044 if (markBar != NULL) markBar->show();
03045 if (m_prog != NULL && !m_statusishidden)
03046 {
03047
03048 m_prog->show();
03049
03050 }
03051
03052 mb->show();
03053 }
03054 if ( searchVisible )
03055 {
03056 #ifdef USEQPE
03057 Global::showInputMethod();
03058 #endif
03059 searchBar->show();
03060 }
03061 if ( regVisible )
03062 {
03063 #ifdef USEQPE
03064 Global::showInputMethod();
03065 #endif
03066 regBar->show();
03067 }
03068 if (m_fontVisible) m_fontBar->show();
03069
03070 showNormal();
03071
03072 #if defined(USEQPE) && !defined(SIMPAD)
03073 showMaximized();
03074 #endif
03075
03076 }
03077
03078
03079 updateCaption();
03080
03081 editorStack->raiseWidget( reader );
03082
03083 reader->setFocus();
03084
03085
03086
03087 }
03088
03089
03090
03091
03092
03093
03094
03095
03096
03097
03098
03099
03100
03101
03102
03103
03104
03105
03106
03107
03108
03109
03110
03111
03112
03113
03114
03115
03116
03117
03118
03119 void QTReaderApp::clear()
03120 {
03121
03122
03123
03124
03125
03126
03127
03128 reader->clear();
03129 }
03130
03131 void QTReaderApp::updateCaption()
03132 {
03133
03134
03135
03136
03137
03138
03139 setCaption( reader->m_string + " - " + tr(SHORTPROGNAME) );
03140
03141 }
03142
03143 void QTReaderApp::setDocument(const QString& fileref)
03144 {
03145
03146 openFile(fileref);
03147
03148 }
03149
03150 void QTReaderApp::closeEvent( QCloseEvent *e )
03151 {
03152
03153 if (m_fullscreen)
03154 {
03155 m_fullscreen = false;
03156 showEditTools();
03157 e->ignore();
03158 }
03159 else if (editorStack->visibleWidget() == m_buttonprefs)
03160 {
03161 int ret = QMessageBox::warning(this, PROGNAME,
03162 tr("Do you wish to map this key?\n\nIf you proceed you will map\nthe escape key and you will\nneed to press the close box\ntwice to exit this program\n\nContinue?"), tr("Yes"), tr("No"), QString::null, 0, 1);
03163 if (ret == 0)
03164 {
03165 m_buttonprefs->mapkey(Qt::NoButton, Key_Escape);
03166 }
03167 e->ignore();
03168 }
03169 else if (m_dontSave)
03170 {
03171 e->accept();
03172 }
03173 else
03174 {
03175 if (editorStack->visibleWidget() == reader)
03176 {
03177 if ((kmap.find(orKey(Qt::NoButton,Key_Escape,false)) != kmap.end()) && m_bcloseDisabled)
03178 {
03179
03180 m_bcloseDisabled = false;
03181 e->ignore();
03182 }
03183 else
03184 {
03185 if (m_fontVisible)
03186 {
03187 m_fontBar->hide();
03188 m_fontVisible = false;
03189 e->ignore();
03190 return;
03191 }
03192 if (regVisible)
03193 {
03194 regBar->hide();
03195 #ifdef USEQPE
03196 Global::hideInputMethod();
03197 #endif
03198 regVisible = false;
03199 e->ignore();
03200 return;
03201 }
03202 if (searchVisible)
03203 {
03204 searchBar->hide();
03205 #ifdef USEQPE
03206 Global::hideInputMethod();
03207 #endif
03208 searchVisible = false;
03209 e->ignore();
03210 return;
03211 }
03212 if (m_fBkmksChanged && pBkmklist != NULL)
03213 {
03214 if (QMessageBox::warning(this, PROGNAME, "Save bookmarks?", "Save", "Don't bother") == 0)
03215 savebkmks();
03216 delete pBkmklist;
03217 reader->pBkmklist = pBkmklist = NULL;
03218 m_fBkmksChanged = false;
03219 }
03220 updatefileinfo();
03221 saveprefs();
03222 e->accept();
03223 }
03224 }
03225 else
03226 {
03227 showEditTools();
03228 m_disableesckey = true;
03229 }
03230 }
03231 }
03232
03233 void QTReaderApp::do_gotomark()
03234 {
03235 m_nBkmkAction = cGotoBkmk;
03236 if (!listbkmk(pBkmklist))
03237 QMessageBox::information(this, PROGNAME, "No bookmarks in memory");
03238 }
03239
03240 void QTReaderApp::do_delmark()
03241 {
03242 m_nBkmkAction = cDelBkmk;
03243 if (!listbkmk(pBkmklist))
03244 QMessageBox::information(this, PROGNAME, "No bookmarks in memory");
03245 }
03246
03247 bool QTReaderApp::listbkmk(CList<Bkmk>* plist, const QString& _lab, bool presel)
03248 {
03249 bkmkselector->clear();
03250 if (_lab.isEmpty())
03251 bkmkselector->setText("Cancel");
03252 else
03253 bkmkselector->setText(_lab);
03254 int cnt = 0;
03255 int slt = -1;
03256 if (plist != NULL)
03257 {
03258 for (CList<Bkmk>::iterator i = plist->begin(); i != plist->end(); i++)
03259 {
03260 if (presel)
03261 {
03262 Bkmk* p = i.pContent();
03263 if (toQString(CFiledata(p->anno()).name()) == reader->m_lastfile)
03264 {
03265 slt = cnt;
03266 }
03267 }
03268 #ifdef _UNICODE
03269
03270 bkmkselector->insertItem(toQString(i->name()), cnt++);
03271 #else
03272 bkmkselector->insertItem(i->name(), cnt++);
03273 #endif
03274
03275 }
03276 }
03277 if (cnt > 0)
03278 {
03279 hidetoolbars();
03280 editorStack->raiseWidget( bkmkselector );
03281 if (slt != -1) bkmkselector->setCurrentItem(slt);
03282 return true;
03283 }
03284 else
03285 return false;
03286 }
03287
03288 void QTReaderApp::do_autogen()
03289 {
03290 m_nRegAction = cAutoGen;
03291 regEdit->setText(m_autogenstr);
03292 do_regedit();
03293 }
03294
03295 void QTReaderApp::do_regedit()
03296 {
03297
03298 reader->bDoUpdates = false;
03299
03300 regBar->show();
03301
03302 #ifdef USEQPE
03303 Global::showInputMethod();
03304 #endif
03305 regVisible = true;
03306 regEdit->setFocus();
03307
03308 reader->bDoUpdates = true;
03309 reader->update();
03310 }
03311
03312 bool QTReaderApp::openfrombkmk(Bkmk* bk)
03313 {
03314 QString fn = toQString(
03315 CFiledata(bk->anno()).name()
03316 );
03317
03318 if (!fn.isEmpty() && QFileInfo(fn).isFile())
03319 {
03320
03321 struct stat fnstat;
03322 stat((const char *)fn, &fnstat);
03323
03324 if (CFiledata(bk->anno()).date()
03325 != fnstat.st_mtime)
03326 {
03327 CFiledata fd(bk->anno());
03328 fd.setdate(fnstat.st_mtime);
03329 bk->value(0);
03330 reader->m_lastposn = 0;
03331 openFile(fn);
03332 }
03333 else
03334 {
03335 unsigned short svlen = bk->filedatalen();
03336 unsigned char* svdata = bk->filedata();
03337 openFile(fn, bk->value());
03338 reader->putSaveData(svdata, svlen);
03339
03340 if (svlen != 0)
03341 {
03342 QMessageBox::warning(this, PROGNAME, "Not all file data used\nNew version?");
03343 }
03344
03345
03346 }
03347 return true;
03348 }
03349 else
03350 {
03351 return false;
03352 }
03353 }
03354
03355 void QTReaderApp::gotobkmk(int ind)
03356 {
03357 qDebug("gbkmk");
03358 showEditTools();
03359 switch (m_nBkmkAction)
03360 {
03361 case cOpenFile:
03362 {
03363
03364 if (!openfrombkmk((*pOpenlist)[ind]))
03365 {
03366 pOpenlist->erase(ind);
03367 QMessageBox::information(this, PROGNAME, "Can't find file");
03368 }
03369 }
03370 break;
03371 case cGotoBkmk:
03372 reader->buffdoc.saveposn(reader->m_lastfile, reader->pagelocate());
03373 reader->locate((*pBkmklist)[ind]->value());
03374 break;
03375 case cDelBkmk:
03377 pBkmklist->erase(ind);
03378 m_fBkmksChanged = true;
03379 reader->refresh(true);
03380
03381 break;
03382 case cRmBkmkFile:
03383 {
03384 #ifndef USEQPE
03385 QDir d = QDir::home();
03386 d.cd(APPDIR);
03387 d.remove(bkmkselector->text(ind));
03388 #else
03389 unlink((const char *)Global::applicationFileName(APPDIR,bkmkselector->text(ind)));
03390 #endif
03391 }
03392 break;
03393 case cLdConfig:
03394 readconfig(APPDIR "/configs", bkmkselector->text(ind), false);
03395 break;
03396 case cLdTheme:
03397 m_themename = bkmkselector->text(ind);
03398 readconfig(QString(APPDIR "/Themes/")+m_themename , "config", false);
03399 setBackgroundBitmap();
03400 break;
03401 case cRmConfig:
03402 {
03403 #ifndef USEQPE
03404 QDir d = QDir::home();
03405 d.cd(APPDIR "/configs");
03406 d.remove(bkmkselector->text(ind));
03407 #else
03408 unlink((const char *)Global::applicationFileName(APPDIR "/configs",bkmkselector->text(ind)));
03409 #endif
03410 }
03411 break;
03412 case cExportLinks:
03413 {
03414 #ifndef USEQPE
03415 QDir d = QDir::home();
03416 d.cd(APPDIR "/urls");
03417 QFileInfo fi(d, bkmkselector->text(ind));
03418 if (fi.exists())
03419 {
03420 QString outfile( QFileDialog::getSaveFileName( QString::null, QString::null, this ) );
03421 if (!outfile.isEmpty())
03422 {
03423 FILE* fout = fopen((const char *)outfile, "w");
03424 if (fout != NULL)
03425 {
03426 FILE* fin = fopen((const char *)fi.absFilePath(), "r");
03427 if (fin != NULL)
03428 {
03429 fprintf(fout, "<html><body>\n");
03430 int ch = 0;
03431 while ((ch = fgetc(fin)) != EOF)
03432 {
03433 fputc(ch, fout);
03434 }
03435 fclose(fin);
03436 fprintf(fout, "</html></body>\n");
03437 d.remove(bkmkselector->text(ind));
03438 }
03439 fclose(fout);
03440 }
03441 else
03442 QMessageBox::information(this, PROGNAME, "Couldn't open output");
03443 }
03444 }
03445 #else
03446 FILE* fin = fopen((const char *)Global::applicationFileName(APPDIR "/urls",bkmkselector->text(ind)), "r");
03447 if (fin != NULL)
03448 {
03449 bool allok = false;
03450 #if defined(OPIE) && defined(OPIEFILEDIALOG)
03451 QString outfile = OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, QString::null, QString::null, MimeTypes(), 0, "OpieReader");
03452 if (!outfile.isEmpty())
03453 {
03454 FILE* fout = fopen((const char *)outfile, "w");
03455 if (fout != NULL)
03456 {
03457 fprintf(fout, "<html><body>\n");
03458 int ch = 0;
03459 while ((ch = fgetc(fin)) != EOF)
03460 {
03461 fputc(ch, fout);
03462 }
03463 fprintf(fout, "</html></body>\n");
03464 fclose(fout);
03465 allok = true;
03466 }
03467 else
03468 QMessageBox::information(this, PROGNAME, "Couldn't open output");
03469 }
03470 fclose(fin);
03471 if (allok) unlink((const char *)Global::applicationFileName(APPDIR "/urls",bkmkselector->text(ind)));
03472 #else
03473 fileBrowser* fb = new fileBrowser(true, this,"OpieReader",!m_bFloatingDialog, 0, "*", QString::null);
03474 if (fb->exec())
03475 {
03476 QString outfile = fb->getCurrentFile();
03477 FILE* fout = fopen((const char *)outfile, "w");
03478 if (fout != NULL)
03479 {
03480 fprintf(fout, "<html><body>\n");
03481 int ch = 0;
03482 while ((ch = fgetc(fin)) != EOF)
03483 {
03484 fputc(ch, fout);
03485 }
03486 fprintf(fout, "</html></body>\n");
03487 fclose(fout);
03488 allok = true;
03489 }
03490 else
03491 QMessageBox::information(this, PROGNAME, "Couldn't open output");
03492 }
03493 delete fb;
03494 fclose(fin);
03495 if (allok) unlink((const char *)Global::applicationFileName(APPDIR "/urls",bkmkselector->text(ind)));
03496 #endif
03497 }
03498 else
03499 {
03500 QMessageBox::information(this, PROGNAME, "Couldn't open input");
03501 }
03502
03503
03504
03505
03506
03507
03508
03509
03510
03511
03512
03513
03514
03515
03516
03517
03518
03519
03520
03521
03522
03523
03524
03525
03526
03527
03528
03529
03530
03531
03532
03533
03534
03535 #endif
03536 }
03537 break;
03538 }
03539 }
03540
03541 void QTReaderApp::cancelbkmk()
03542 {
03543 if (m_nBkmkAction == cOpenFile)
03544 {
03545 QString fn = usefilebrowser();
03546 if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn);
03547 }
03548 showEditTools();
03549 }
03550
03551 void QTReaderApp::reparastring()
03552 {
03553 m_nRegAction = cRepara;
03554 regEdit->setText(reader->m_reparastring);
03555 do_regedit();
03556 }
03557
03558 void QTReaderApp::do_reparastring(const QString& _lcn)
03559 {
03560 reader->m_reparastring = _lcn;
03561 if (reader->brepara)
03562 {
03563 reader->bDoUpdates = true;
03564 reader->setfilter(reader->getfilter());
03565 }
03566 }
03567
03568 void QTReaderApp::jump()
03569 {
03570 m_nRegAction = cJump;
03571 char lcn[20];
03572 sprintf(lcn, "%lu", reader->pagelocate());
03573 regEdit->setText(lcn);
03574 do_regedit();
03575 }
03576
03577 void QTReaderApp::do_jump(const QString& _lcn)
03578 {
03579 bool ok;
03580 QString lcn = _lcn.stripWhiteSpace();
03581 unsigned long ulcn = lcn.toULong(&ok);
03582 if (!ok)
03583 {
03584 double pc = 0.0;
03585 #ifdef _WINDOWS
03586 if (lcn.at(lcn.length()-1) == '%')
03587 #else
03588 if (lcn[lcn.length()-1] == '%')
03589 #endif
03590 {
03591 lcn = lcn.left(lcn.length()-1);
03592 pc = lcn.toDouble(&ok);
03593 }
03594 else
03595 {
03596 pc = lcn.toDouble(&ok);
03597 }
03598 if (ok && 0 <= pc && pc <= 100)
03599 {
03600 ulcn = (pc*(reader->buffdoc.endSection()-reader->buffdoc.startSection()))/100 + reader->buffdoc.startSection();
03601 }
03602 else
03603 {
03604 ok = false;
03605 }
03606 }
03607 if (ok)
03608 reader->locate(ulcn);
03609 else
03610 QMessageBox::information(this, PROGNAME, "Must be a number\nor a percentage");
03611 }
03612
03613 void QTReaderApp::do_regaction()
03614 {
03615 reader->bDoUpdates = false;
03616 regBar->hide();
03617 #ifdef USEQPE
03618 Global::hideInputMethod();
03619 #endif
03620 regVisible = false;
03621 switch(m_nRegAction)
03622 {
03623 case cAutoGen:
03624 do_autogen(regEdit->text());
03625 break;
03626 case cAddBkmk:
03627 do_addbkmk(regEdit->text());
03628 break;
03629 case cRepara:
03630 do_reparastring(regEdit->text());
03631 break;
03632 case cJump:
03633 do_jump(regEdit->text());
03634 break;
03635
03636
03637
03638
03639
03640 case cSetTarget:
03641 do_settarget(regEdit->text());
03642 break;
03643 #ifdef _SCROLLPIPE
03644 case cSetPipeTarget:
03645 do_setpipetarget(regEdit->text());
03646 break;
03647 #endif
03648 case cSetConfigName:
03649
03650 do_saveconfig(regEdit->text(), false);
03651 break;
03652 }
03653
03654
03655 reader->setFocus();
03656
03657 reader->bDoUpdates = true;
03658 reader->update();
03659 }
03660
03661 void QTReaderApp::do_settarget(const QString& _txt)
03662 {
03663 int ind = _txt.find('/');
03664 if (ind == -1)
03665 {
03666 m_targetapp = "";
03667 m_targetmsg = "";
03668 QMessageBox::information(this, PROGNAME, "Format is\nappname/messagename");
03669 }
03670 else
03671 {
03672 m_targetapp = _txt.left(ind);
03673 m_targetmsg = _txt.right(_txt.length()-ind-1);
03674 }
03675 }
03676
03677 void QTReaderApp::chooseencoding()
03678 {
03679 m_fontSelector->clear();
03680 m_fontSelector->insertItem("Ascii");
03681 m_fontSelector->insertItem("UTF-8");
03682 m_fontSelector->insertItem("UCS-2(BE)");
03683 m_fontSelector->insertItem("USC-2(LE)");
03684 m_fontSelector->insertItem("Palm");
03685 for (unicodetable::iterator iter = unicodetable::begin(); iter != unicodetable::end(); iter++)
03686 {
03687 m_fontSelector->insertItem(iter->mime);
03688 }
03689 m_fontSelector->setCurrentItem (reader->m_encd);
03690 m_fontAction = cChooseEncoding;
03691 m_fontBar->show();
03692 m_fontVisible = true;
03693 }
03694
03695 void QTReaderApp::setfont()
03696 {
03697 m_fontSelector->clear();
03698 {
03699 QFontDatabase f;
03700 QStringList flist = f.families();
03701 m_fontSelector->insertStringList(flist);
03702 }
03703
03704 for (int i = 1; i <= m_fontSelector->count(); i++)
03705 {
03706 if (m_fontSelector->text(i) == reader->m_fontname)
03707 {
03708 m_fontSelector->setCurrentItem(i);
03709 break;
03710 }
03711 }
03712 m_fontAction = cChooseFont;
03713 m_fontBar->show();
03714 m_fontVisible = true;
03715 }
03716
03717 void QTReaderApp::setfontHelper(const QString& lcn, int size)
03718 {
03719 if (size == 0) size = reader->m_fontControl.currentsize();
03720 if (m_propogatefontchange)
03721 {
03722 QFont f(lcn, 10);
03723 bkmkselector->setFont( f );
03724 regEdit->setFont( f );
03725 searchEdit->setFont( f );
03726 m_annoWin->setFont( f );
03727 }
03728 reader->m_fontname = lcn;
03729 if (!reader->ChangeFont(size))
03730 {
03731 reader->ChangeFont(size);
03732 }
03733 }
03734
03735 void QTReaderApp::do_setencoding(int i)
03736 {
03737 qDebug("setencoding:%d", i);
03738 if (m_fontAction == cChooseEncoding)
03739 {
03740 reader->setencoding(i);
03741 }
03742 reader->refresh();
03743 m_fontBar->hide();
03744 m_fontVisible = false;
03745
03746 if (reader->isVisible()) showEditTools();
03747
03748 }
03749
03750 void QTReaderApp::do_setfont(const QString& lcn)
03751 {
03752 if (m_fontAction == cChooseFont)
03753 {
03754 setfontHelper(lcn);
03755 }
03756 reader->refresh();
03757 m_fontBar->hide();
03758 m_fontVisible = false;
03759
03760
03761 showEditTools();
03762
03763 }
03764
03765 void QTReaderApp::do_autogen(const QString& regText)
03766 {
03767 unsigned long fs, ts;
03768 reader->sizes(fs,ts);
03769
03770 m_autogenstr = regText;
03771 QRegExp re(regText);
03772 CBuffer buff;
03773 if (pBkmklist != NULL) delete pBkmklist;
03774 reader->pBkmklist = pBkmklist = new CList<Bkmk>;
03775 m_fBkmksChanged = true;
03776
03777 pbar->setGeometry(regBar->x(),regBar->y(),regBar->width(), regBar->height());
03778 pbar->show();
03779 pbar->raise();
03780 pbar->reset();
03781 reader->update();
03782 qApp->processEvents();
03783 reader->setFocus();
03784 reader->jumpto(0);
03785 int lastpc = 0;
03786 int i = 0;
03787 unsigned int llcn = reader->locate();
03788 while (i >= 0)
03789 {
03790 unsigned int lcn = llcn;
03791 int pc = (100*lcn)/ts;
03792 if (pc != lastpc)
03793 {
03794 pbar->setProgress(pc);
03795 qApp->processEvents();
03796 if (reader->locate() != lcn) reader->jumpto(lcn);
03797 reader->setFocus();
03798 lastpc = pc;
03799 }
03800 i = reader->buffdoc.getpara(buff);
03801 #ifdef _UNICODE
03802 if (re.match(toQString(buff.data())) != -1)
03803 #else
03804 if (re.match(buff.data()) != -1)
03805 #endif
03806 pBkmklist->push_back(Bkmk(buff.data(), NULL, lcn));
03807
03808
03809
03810
03811
03812
03813
03814
03815 }
03816 pBkmklist->sort();
03817 pbar->setProgress(100);
03818 qApp->processEvents();
03819 pbar->hide();
03820 reader->refresh();
03821 }
03822
03823 void QTReaderApp::saveprefs()
03824 {
03825 do_saveconfig( APPDIR, true );
03826 savefilelist();
03827 }
03828
03829
03830
03831
03832
03833
03834
03835
03836
03837
03838
03839
03840
03841
03842
03843
03844
03845
03846
03847
03848
03849
03850
03851
03852
03853
03854
03855
03856
03857
03858
03859
03860
03861
03862
03863
03864
03865
03866
03867
03868
03869
03870
03871
03872
03873
03874
03875
03876
03877
03878
03879
03880
03881
03882
03883
03884
03885 void QTReaderApp::savebkmks()
03886 {
03887 if (pBkmklist != NULL)
03888 {
03889 #ifndef USEQPE
03890 QDir d = QDir::home();
03891 d.cd(APPDIR);
03892 QFileInfo fi(d, reader->m_string);
03893 BkmkFile bf((const char *)fi.absFilePath(), true, true);
03894 #else
03895 BkmkFile bf((const char *)Global::applicationFileName(APPDIR,reader->m_string), true, true);
03896 #endif
03897 bf.write(*pBkmklist);
03898 }
03899 m_fBkmksChanged = false;
03900 }
03901
03902 void QTReaderApp::readfilelist()
03903 {
03904 #ifndef USEQPE
03905 QDir d = QDir::home();
03906 d.cd(APPDIR);
03907 QFileInfo fi(d, ".openfiles");
03908 BkmkFile bf((const char *)fi.absFilePath(), false, false);
03909 #else
03910 BkmkFile bf((const char *)Global::applicationFileName(APPDIR,".openfiles"), false, false);
03911 #endif
03912
03913 pOpenlist = bf.readall();
03914
03915
03916 }
03917
03918 void QTReaderApp::savefilelist()
03919 {
03920 if (pOpenlist != NULL)
03921 {
03922 #ifndef USEQPE
03923 QDir d = QDir::home();
03924 d.cd(APPDIR);
03925 QFileInfo fi(d, ".openfiles");
03926 BkmkFile bf((const char *)fi.absFilePath(), true, false);
03927 #else
03928 BkmkFile bf((const char *)Global::applicationFileName(APPDIR,".openfiles"), true, false);
03929 #endif
03930
03931 bf.write(*pOpenlist);
03932 }
03933 }
03934
03935 void QTReaderApp::readbkmks()
03936 {
03937 if (pBkmklist != NULL)
03938 {
03939 delete pBkmklist;
03940 }
03941 struct stat fnstat;
03942 struct stat bkstat;
03943 #ifndef USEQPE
03944 QDir d = QDir::home();
03945 d.cd(APPDIR);
03946 QFileInfo fi(d, reader->m_string);
03947 #endif
03948 if (
03949 stat((const char *)reader->m_lastfile, &fnstat) == 0
03950 &&
03951 #ifndef USEQPE
03952 stat((const char *)fi.absFilePath(), &bkstat) == 0
03953 #else
03954 stat((const char *)Global::applicationFileName(APPDIR,reader->m_string), &bkstat) == 0
03955 #endif
03956 )
03957 {
03958 if (bkstat.st_mtime < fnstat.st_mtime)
03959 {
03960 #ifndef USEQPE
03961 unlink((const char *)fi.absFilePath());
03962 #else
03963 unlink((const char *)Global::applicationFileName(APPDIR,reader->m_string));
03964 #endif
03965 }
03966 }
03967
03968 #ifndef USEQPE
03969 BkmkFile bf((const char *)fi.absFilePath(), false, true);
03970 #else
03971 BkmkFile bf((const char *)Global::applicationFileName(APPDIR,reader->m_string), false, true);
03972 #endif
03973
03974 reader->pBkmklist = pBkmklist = bf.readall();
03975 m_fBkmksChanged = bf.upgraded();
03976 if (pBkmklist == NULL)
03977 {
03978 reader->pBkmklist = pBkmklist = reader->getbkmklist();
03979 }
03980 if (pBkmklist != NULL)
03981 pBkmklist->sort();
03982 }
03983
03984 void QTReaderApp::addbkmk()
03985 {
03986 m_nRegAction = cAddBkmk;
03987 regEdit->setText(reader->firstword());
03988 do_regedit();
03989 }
03990
03991 void QTReaderApp::do_addbkmk(const QString& text)
03992 {
03993 if (text.isEmpty())
03994 {
03995 QMessageBox::information(this, PROGNAME, "Need a name for the bookmark\nSelect add again", 1);
03996 }
03997 else
03998 {
03999 if (pBkmklist == NULL) reader->pBkmklist = pBkmklist = new CList<Bkmk>;
04000 #ifdef _UNICODE
04001 CBuffer buff;
04002 int i = 0;
04003 for (i = 0; i < text.length(); i++)
04004 {
04005 buff[i] = text[i].unicode();
04006 }
04007 buff[i] = 0;
04008 pBkmklist->push_front(Bkmk(buff.data(), NULL, reader->pagelocate()));
04009 #else
04010 pBkmklist->push_front(Bkmk((const tchar*)text, reader->pagelocate()));
04011 #endif
04012 m_fBkmksChanged = true;
04013 pBkmklist->sort();
04014 reader->refresh(true);
04015 }
04016 }
04017
04018 void QTReaderApp::UpdateStatus()
04019 {
04020 QString status;
04021 for (int i = 0; i < m_statusstring.length(); i++)
04022 {
04023 if (m_statusstring[i].unicode() == '%')
04024 {
04025 i++;
04026 if (i < m_statusstring.length())
04027 {
04028 switch (m_statusstring[i].unicode())
04029 {
04030 case 'F':
04031 {
04032 unsigned long fs,ts;
04033 reader->sizes(fs,ts);
04034 status += filesize(ts);
04035 }
04036 break;
04037 case 'f':
04038 {
04039 status += filesize(reader->pagelocate());
04040 }
04041 break;
04042 case 'D':
04043 {
04044 status += filesize(reader->buffdoc.endSection()-reader->buffdoc.startSection());
04045 }
04046 break;
04047 case 'd':
04048 {
04049 status += filesize(reader->pagelocate()-reader->buffdoc.startSection());
04050 }
04051 break;
04052 case 'P':
04053 {
04054 unsigned long fs,ts;
04055 reader->sizes(fs,ts);
04056 status += percent(reader->pagelocate(),ts);
04057 }
04058 break;
04059 case 'p':
04060 {
04061 status += percent(reader->pagelocate()-reader->buffdoc.startSection(),reader->buffdoc.endSection()-reader->buffdoc.startSection());
04062 }
04063 break;
04064 case 'z':
04065 {
04066
04067 status += QString().setNum(reader->m_fontControl.currentsize()*10);
04068 }
04069 break;
04070 default:
04071 status += m_statusstring[i];
04072 }
04073 }
04074 }
04075 else
04076 {
04077 status += m_statusstring[i];
04078 }
04079 }
04080 m_prog->setText(status);
04081 }
04082
04083 void QTReaderApp::OnRedraw()
04084 {
04085 if ((pBkmklist != NULL) && (m_bkmkAvail != NULL))
04086 {
04087 bool found = findNextBookmark(reader->pagelocate());
04088 m_bkmkAvail->setEnabled(found);
04089 }
04090 if (m_scrollbar != NULL)
04091 {
04092
04093 scrollbar->setRange(reader->buffdoc.startSection(), reader->buffdoc.endSection()-1);
04094 scrollbar->setPageStep(reader->locate()-reader->pagelocate());
04095 scrollbar->setValue((reader->m_rotated) ?
04096 (reader->buffdoc.endSection() - reader->locate()+reader->buffdoc.startSection()) :
04097 reader->pagelocate());
04098 }
04099 if (m_prog->isVisible())
04100 {
04101
04102 UpdateStatus();
04103
04104 }
04105 }
04106
04107 void QTReaderApp::showAnnotation()
04108 {
04109 m_annoWin->setName(toQString(m_anno->name()));
04110 m_annoWin->setAnno(toQString(m_anno->anno()));
04111 m_annoWin->setColor(QColor(m_anno->red(), m_anno->green(), m_anno->blue()));
04112 m_annoIsEditing = false;
04113 #ifdef USEQPE
04114 Global::showInputMethod();
04115 #endif
04116 editorStack->raiseWidget( m_annoWin );
04117 hidetoolbars();
04118 m_annoWin->setFocus();
04119 }
04120
04121 void QTReaderApp::OnWordSelected(const QString& wrd, size_t posn, size_t posn2, const QString& line)
04122 {
04124
04125 if (m_doOutput && reader->checkoutput())
04126 {
04127 reader->doOutput(wrd);
04128 }
04129 if (m_doClipboard)
04130 {
04131 QClipboard* cb = QApplication::clipboard();
04132 cb->setText(wrd);
04133 #ifdef USEQPE
04134 if (wrd.length() > 10)
04135 {
04136 Global::statusMessage(wrd.left(8) + "..");
04137 }
04138 else
04139 {
04140 Global::statusMessage(wrd);
04141 }
04142 #endif
04143 }
04144 if (m_doAnnotation)
04145 {
04146
04147 m_annoWin->setName(line);
04148 m_annoWin->setAnno("");
04149 m_annoWin->setPosn(posn);
04150 m_annoWin->setPosn2(posn2);
04151 m_annoIsEditing = true;
04152 #ifdef USEQPE
04153 Global::showInputMethod();
04154 #endif
04155 editorStack->raiseWidget( m_annoWin );
04156 hidetoolbars();
04157 }
04158 #ifdef USEQPE
04159 if (m_doDictionary)
04160 {
04161 if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty())
04162 {
04163 QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8());
04164 e << wrd;
04165 }
04166 }
04167 #endif
04168 }
04169
04170 void QTReaderApp::doAction(QKeyEvent* e)
04171 {
04172 QMap<orKey,int>::Iterator f = kmap.end();
04173
04174 if (reader->m_autoScroll)
04175 {
04176 f = kmap.find(orKey(e->state(), e->key(), true));
04177 }
04178 if (f == kmap.end())
04179 {
04180 f = kmap.find(orKey(e->state(), e->key(), false));
04181 }
04182
04183 if (f == kmap.end())
04184 {
04185 qDebug("doaction (no action) : %d %d %d", e->key(), e->state(), f.data());
04186 e->ignore();
04187 }
04188 else
04189 {
04190 qDebug("doaction (some action) : %d %d %d", e->key(), e->state(), f.data());
04191 ActionTypes a = (ActionTypes)f.data();
04192 e->accept();
04193
04194 switch (a)
04195 {
04196 case cesGotoLink:
04197 {
04198 reader->gotoLink();
04199 }
04200 break;
04201 case cesNextLink:
04202 {
04203 reader->getNextLink();
04204 }
04205 break;
04206 case cesInvertColours:
04207 m_inverse_action->setOn(!reader->bInverse);
04208 break;
04209 case cesToggleBars:
04210 m_hidebars = !m_hidebars;
04211 if (m_hidebars)
04212 {
04213 #if defined(USEQPE)
04214 menubar->hide();
04215 #endif
04216 if (fileBar != NULL) fileBar->hide();
04217 if (viewBar != NULL) viewBar->hide();
04218 if (navBar != NULL) navBar->hide();
04219 if (markBar != NULL) markBar->hide();
04220 mb->hide();
04221 }
04222 else
04223 {
04224 #if defined(USEQPE)
04225 menubar->show();
04226 #endif
04227 if (fileBar != NULL) fileBar->show();
04228 if (viewBar != NULL) viewBar->show();
04229 if (navBar != NULL) navBar->show();
04230 if (markBar != NULL) markBar->show();
04231 mb->show();
04232 }
04233 break;
04234 case cesToggleScrollBar:
04235 if (m_scrollbar != NULL)
04236 {
04237 if (m_scrollbar->isHidden())
04238 {
04239 m_scrollishidden = false;
04240 m_scrollbar->show();
04241 reader->m_scrollpos = (m_qtscroll == 0) ? m_localscroll : 0;
04242 }
04243 else
04244 {
04245 m_scrollishidden = true;
04246 m_scrollbar->hide();
04247 reader->m_scrollpos = m_localscroll;
04248 }
04249 }
04250 break;
04251 case cesToggleStatusBar:
04252 if (m_prog != NULL)
04253 {
04254 if (m_prog->isHidden())
04255 {
04256 m_statusishidden = false;
04257 m_prog->show();
04258 }
04259 else
04260 {
04261 m_statusishidden = true;
04262 m_prog->hide();
04263 }
04264 }
04265 break;
04266 case cesOpenFile:
04267 {
04268 qDebug("Open file");
04269 fileOpen();
04270 }
04271 break;
04272 case cesAutoScroll:
04273 {
04274 reader->setautoscroll(!reader->m_autoScroll);
04275 setScrollState(reader->m_autoScroll);
04276 }
04277 break;
04278 case cesActionMark:
04279 {
04280 addbkmk();
04281 }
04282 break;
04283 case cesFullScreen:
04284 {
04285 m_actFullscreen->setOn(!m_fullscreen);
04286 }
04287 break;
04288 case cesRotate:
04289 {
04290 m_rotate_action->setOn(!reader->m_rotated);
04291 }
04292 break;
04293 case cesActionAnno:
04294 {
04295 addanno();
04296 }
04297 break;
04298 case cesZoomIn:
04299 zoomin();
04300 break;
04301 case cesZoomOut:
04302 zoomout();
04303 break;
04304 case cesBack:
04305 reader->goBack();
04306 break;
04307 case cesForward:
04308 reader->goForward();
04309 break;
04310 case cesHome:
04311 reader->goHome();
04312 break;
04313 case cesPageUp:
04314 reader->dopageup();
04315
04316
04317
04318
04319
04320
04321
04322
04323
04324
04325 break;
04326 case cesPageDown:
04327 reader->dopagedn();
04328
04329
04330
04331
04332
04333
04334
04335
04336
04337
04338
04339 break;
04340 case cesLineUp:
04341 reader->lineUp();
04342 break;
04343 case cesLineDown:
04344 reader->lineDown();
04345 break;
04346 case cesStartDoc:
04347 gotoStart();
04348 break;
04349 case cesEndDoc:
04350 gotoEnd();
04351 break;
04352 case cesScrollMore:
04353 reader->increaseScroll();
04354 break;
04355 case cesScrollLess:
04356 reader->reduceScroll();
04357 break;
04358 default:
04359 qDebug("Unknown ActionType:%u", a);
04360 break;
04361 }
04362 }
04363 }
04364
04365 void QTReaderApp::setTwoTouch(bool _b) { reader->setTwoTouch(_b); }
04366 void QTReaderApp::restoreFocus() { reader->setFocus(); }
04367
04368 void QTReaderApp::SaveConfig()
04369 {
04370 m_nRegAction = cSetConfigName;
04371 regEdit->setText(reader->m_string);
04372 do_regedit();
04373 }
04374
04375 void QTReaderApp::do_saveconfig(const QString& _txt, bool full)
04376 {
04377
04378 #ifdef USEQPE
04379 QString configname;
04380 Config::Domain dom;
04381
04382 if (full)
04383 {
04384 configname = _txt;
04385 dom = Config::User;
04386 }
04387 else
04388 {
04389 configname = Global::applicationFileName(APPDIR "/configs", _txt);
04390 dom = Config::File;
04391 }
04392
04393 Config config(configname, dom);
04394 config.setGroup( "View" );
04395
04396 #else
04397 QFileInfo fi;
04398 if (full)
04399 {
04400
04401 QDir d = QDir::home();
04402 if ( !d.cd(_txt) )
04403 {
04404 qWarning( "Cannot find the \"~/%s\" directory", (const char*)_txt );
04405 d = QDir::home();
04406 d.mkdir(_txt);
04407 d.cd(_txt);
04408 }
04409 fi.setFile(d, INIFILE);
04410 }
04411 else
04412 {
04413 QDir d = QDir::home();
04414 if ( !d.cd(APPDIR) )
04415 {
04416 qWarning( "Cannot find the \"~/" APPDIR "\" directory" );
04417 d = QDir::home();
04418 d.mkdir(APPDIR);
04419 d.cd(APPDIR);
04420 }
04421 if ( !d.cd("configs") )
04422 {
04423 qWarning( "Cannot find the \"~/" APPDIR "/configs\" directory" );
04424 d = QDir::home();
04425 d.cd(APPDIR);
04426 d.mkdir("configs");
04427 d.cd("configs");
04428 }
04429 fi.setFile(d, _txt);
04430 }
04431
04432 Config config(fi.absFilePath());
04433 #endif
04434
04435
04436 config.writeEntry( "StripCr", reader->bstripcr );
04437 config.writeEntry( "NoInlineTables", reader->bNoInlineTables );
04438 config.writeEntry( "AutoFmt", reader->bautofmt );
04439 config.writeEntry( "TextFmt", reader->btextfmt );
04440 config.writeEntry( "StripHtml", reader->bstriphtml );
04441 config.writeEntry( "Dehyphen", reader->bdehyphen );
04442 config.writeEntry( "Depluck", reader->bdepluck );
04443 config.writeEntry( "Dejpluck", reader->bdejpluck );
04444 config.writeEntry( "OneSpace", reader->bonespace );
04445 config.writeEntry( "Unindent", reader->bunindent );
04446 config.writeEntry( "Repara", reader->brepara );
04447 config.writeEntry( "ReparaString", reader->m_reparastring);
04448 config.writeEntry( "BackgroundType" , (int)m_bgtype );
04449 config.writeEntry( "Theme", m_themename );
04450 config.writeEntry( "DoubleSpace", reader->bdblspce );
04451 config.writeEntry( "Indent", reader->bindenter );
04452 config.writeEntry( "FontSize", (int)(reader->m_fontControl.currentsize()) );
04453 config.writeEntry( "ScrollDelay", reader->m_delay);
04454 config.writeEntry( "ScrollStep", reader->m_scrollstep);
04455 config.writeEntry( "ScrollType", reader->m_scrolltype );
04456 if (full)
04457 {
04458 config.writeEntry("Debounce", m_debounce);
04459 config.writeEntry("FloatDialogs", m_bFloatingDialog);
04460 reader->m_lastposn = reader->pagelocate();
04461 config.writeEntry( "LastFile", reader->m_lastfile );
04462 config.writeEntry( "LastPosn", (int)(reader->pagelocate()) );
04463 config.writeEntry( "OutputCodec", reader->m_outputName);
04464 }
04465 config.writeEntry( "PageMode", reader->m_bpagemode );
04466 config.writeEntry( "MonoSpaced", reader->m_bMonoSpaced );
04467 config.writeEntry( "SwapMouse", reader->m_swapmouse);
04468 config.writeEntry( "IsRotated", reader->m_rotated );
04469 config.writeEntry("StatusContent", m_statusstring);
04470 config.writeEntry("StatusHidden", m_statusishidden);
04471 config.writeEntry( "Background", m_background );
04472 config.writeEntry( "Foreground", m_foreground );
04473 config.writeEntry( "ScrollColour", m_scrollcolor );
04474 config.writeEntry( "ScrollBarColour", m_scrollbarcolor );
04475 config.writeEntry( "Hyphenate", reader->hyphenate );
04476
04477 config.writeEntry( "Fontname", reader->m_fontname );
04478 config.writeEntry( "Encoding", reader->m_encd );
04479 config.writeEntry( "CharSpacing", reader->m_charpc );
04480 config.writeEntry( "Overlap", (int)(reader->m_overlap) );
04481 config.writeEntry( "Top Margin", (int)reader->m_abstopmargin );
04482 config.writeEntry( "Bottom Margin", (int)reader->m_absbottommargin );
04483 config.writeEntry( "Left Margin", (int)reader->m_absleft_border );
04484 config.writeEntry( "Right Margin", (int)reader->m_absright_border );
04485 config.writeEntry( "TargetApp", m_targetapp );
04486 config.writeEntry( "TargetMsg", m_targetmsg );
04487 #ifdef _SCROLLPIPE
04488 config.writeEntry( "PipeTarget", reader->m_pipetarget );
04489 config.writeEntry( "PauseAfterPara", reader->m_pauseAfterEachPara );
04490 #endif
04491 config.writeEntry( "TwoTouch", m_twoTouch );
04492 config.writeEntry( "Annotation", m_doAnnotation);
04493 config.writeEntry( "Dictionary", m_doDictionary);
04494 config.writeEntry( "Clipboard", m_doClipboard);
04495 config.writeEntry( "OutputTgt", m_doOutput);
04496
04497
04498
04499
04500
04501
04502
04503
04504
04505
04506
04507
04508
04509 config.writeEntry( "Repalm", reader->brepalm );
04510 config.writeEntry( "UnderlineLink", reader->bunderlineLink );
04511 config.writeEntry( "HideScrollBar", m_scrollishidden );
04512 config.writeEntry( "HideToolBar", m_hidebars );
04513 config.writeEntry( "Kern", reader->bkern );
04514 config.writeEntry( "Remap", reader->bremap );
04515 config.writeEntry( "Peanut", reader->bpeanut );
04516 config.writeEntry( "MakeBold", reader->bmakebold );
04517 config.writeEntry( "Continuous", reader->m_continuousDocument );
04518 config.writeEntry( "DoubleBuffer", reader->m_doubleBuffered);
04519 config.writeEntry( "FullJust", reader->bfulljust );
04520
04521 config.writeEntry( "Inverse", reader->bInverse );
04522 config.writeEntry( "FixGraphics", reader->m_fontControl.FixGraphics());
04523 config.writeEntry( "ExtraSpace", reader->getextraspace() );
04524 config.writeEntry( "ExtraLead", reader->getlead() );
04525 config.writeEntry( "Basesize", (int)reader->getBaseSize());
04526 config.writeEntry( "RequestorFontChange", m_propogatefontchange);
04527 #ifdef USEQPE
04528 config.writeEntry( "GrabKeyboard", m_grabkeyboard );
04529 #endif
04530 if (full)
04531 {
04532 config.setGroup( "Toolbar" );
04533 config.writeEntry("QTScrollBar", m_qtscroll);
04534 config.writeEntry("LocalScrollBar", m_localscroll);
04535 config.writeEntry("Movable", m_tbmovesave);
04536 config.writeEntry("Policy", m_tbpolsave);
04537 config.writeEntry("Position", m_tbposition);
04538 #ifndef USEQPE
04539 if (!isMaximized() && !isMinimized())
04540 {
04541 config.setGroup( "Geometry" );
04542 config.writeEntry( "x", x() );
04543 config.writeEntry( "y", y() );
04544 config.writeEntry( "width", width() );
04545 config.writeEntry( "height", height() );
04546 }
04547 #endif
04548 }
04549 }
04550
04551 #ifdef _SCROLLPIPE
04552 void QTReaderApp::setpipetarget()
04553 {
04554 m_nRegAction = cSetPipeTarget;
04555 QString text = (reader->m_pipetarget.isEmpty()) ? QString("") : reader->m_pipetarget;
04556 regEdit->setText(text);
04557 do_regedit();
04558 }
04559
04560 void QTReaderApp::do_setpipetarget(const QString& _txt)
04561 {
04562 reader->m_pipetarget = _txt;
04563 }
04564
04565 void QTReaderApp::setpause(bool sfs)
04566 {
04567 reader->m_pauseAfterEachPara = sfs;
04568 }
04569 #endif
04570
04571 void QTReaderApp::monospace(bool _b)
04572 {
04573 reader->setmono(_b);
04574 }
04575
04576 bool QTReaderApp::readconfig(const QString& dirname, const QString& _txt, bool full=false)
04577 {
04578 #ifdef USEQPE
04579 QString configname;
04580 Config::Domain dom;
04581
04582 if (full)
04583 {
04584 configname = _txt;
04585 dom = Config::User;
04586 }
04587 else
04588 {
04589 configname = Global::applicationFileName(dirname, _txt);
04590 QFileInfo fm(configname);
04591 if ( !fm.exists() ) return false;
04592 dom = Config::File;
04593 }
04594
04595 Config config(configname, dom);
04596 config.setGroup( "View" );
04597
04598 #else
04599 QString fullname;
04600 if (full)
04601 {
04602 fullname = QDir::homeDirPath() + "/" + _txt + "/" + INIFILE;
04603 }
04604 else
04605 {
04606 fullname = QDir::homeDirPath() + "/" + dirname + "/" + _txt;
04607 }
04608 if (!QFile::exists(fullname)) return false;
04609
04610 Config config(fullname);
04611 #endif
04612 if (full)
04613 {
04614 config.setGroup("Toolbar");
04615 m_tbmovesave = m_tbmove = config.readBoolEntry("Movable", m_tbmovesave);
04616 m_tbpolsave = m_tbpol = (ToolbarPolicy)config.readNumEntry("Policy", m_tbpolsave);
04617 m_tbposition = (ToolBarDock)config.readNumEntry("Position", m_tbposition);
04618 }
04619 config.setGroup( "View" );
04620 m_bFloatingDialog = config.readBoolEntry("FloatDialogs", m_bFloatingDialog);
04621 reader->bstripcr = config.readBoolEntry( "StripCr", reader->bstripcr );
04622 reader->bNoInlineTables = config.readBoolEntry( "NoInlineTables", reader->bNoInlineTables );
04623 reader->bfulljust = config.readBoolEntry( "FullJust", reader->bfulljust );
04624 reader->bInverse = config.readBoolEntry( "Inverse", reader->bInverse );
04625
04626 reader->m_fontControl.FixGraphics(config.readBoolEntry( "FixGraphics", reader->m_fontControl.FixGraphics() ));
04627 reader->setextraspace(config.readNumEntry( "ExtraSpace", reader->getextraspace() ));
04628 reader->setlead(config.readNumEntry( "ExtraLead", reader->getlead() ));
04629 reader->btextfmt = config.readBoolEntry( "TextFmt", reader->btextfmt );
04630 reader->bautofmt = config.readBoolEntry( "AutoFmt", reader->bautofmt );
04631 reader->bstriphtml = config.readBoolEntry( "StripHtml", reader->bstriphtml );
04632 reader->bpeanut = config.readBoolEntry( "Peanut", reader->bpeanut );
04633 reader->bdehyphen = config.readBoolEntry( "Dehyphen", reader->bdehyphen );
04634 reader->bdepluck = config.readBoolEntry( "Depluck", reader->bdepluck );
04635 reader->bdejpluck = config.readBoolEntry( "Dejpluck", reader->bdejpluck );
04636 reader->bonespace = config.readBoolEntry( "OneSpace", reader->bonespace );
04637 reader->bunindent = config.readBoolEntry( "Unindent", reader->bunindent );
04638 reader->brepara = config.readBoolEntry( "Repara", reader->brepara );
04639 reader->m_reparastring = config.readEntry( "ReparaString", reader->m_reparastring);
04640 m_bgtype = (bground)config.readNumEntry( "BackgroundType" , m_bgtype );
04641 m_themename = config.readEntry("Theme", m_themename );
04642 reader->bdblspce = config.readBoolEntry( "DoubleSpace", reader->bdblspce );
04643 reader->bindenter = config.readNumEntry( "Indent", reader->bindenter );
04644 reader->m_textsize = config.readNumEntry( "FontSize", reader->m_textsize );
04645 reader->m_delay = config.readNumEntry( "ScrollDelay", reader->m_delay);
04646 reader->m_scrollstep = config.readNumEntry( "ScrollStep", reader->m_scrollstep);
04647 reader->m_scrolltype = config.readNumEntry( "ScrollType", reader->m_scrolltype);
04648 if (full)
04649 {
04650 reader->m_lastfile = config.readEntry( "LastFile", reader->m_lastfile );
04651 reader->m_lastposn = config.readNumEntry( "LastPosn", reader->m_lastposn );
04652 }
04653 reader->m_bpagemode = config.readBoolEntry( "PageMode", reader->m_bpagemode );
04654 reader->m_bMonoSpaced = config.readBoolEntry( "MonoSpaced", reader->m_bMonoSpaced);
04655 reader->m_rotated = config.readBoolEntry( "IsRotated", reader->m_rotated );
04656 m_statusstring = config.readEntry("StatusContent", m_statusstring);
04657 m_statusishidden = config.readBoolEntry("StatusHidden", m_statusishidden);
04658 m_background = config.readNumEntry( "Background", m_background );
04659 reader->setBackground(getcolour(m_background));
04660 m_foreground = config.readNumEntry( "Foreground", m_foreground );
04661 reader->setForeground(getcolour(m_foreground));
04662 m_scrollcolor = config.readNumEntry( "ScrollColour", m_scrollcolor);
04663 setscrollcolour();
04664 m_scrollbarcolor = config.readNumEntry( "ScrollBarColour", m_scrollbarcolor);
04665 setscrollbarcolour();
04666 reader->hyphenate = config.readBoolEntry( "Hyphenate", reader->hyphenate );
04667
04668 reader->m_swapmouse = config.readBoolEntry( "SwapMouse", reader->m_swapmouse);
04669 reader->m_fontname = config.readEntry( "Fontname", reader->m_fontname );
04670 reader->m_encd = config.readNumEntry( "Encoding", reader->m_encd );
04671 reader->m_charpc = config.readNumEntry( "CharSpacing", reader->m_charpc );
04672 reader->m_overlap = config.readNumEntry( "Overlap", reader->m_overlap );
04673 reader->m_abstopmargin = config.readNumEntry( "Top Margin", reader->m_abstopmargin );
04674 reader->m_absbottommargin = config.readNumEntry( "Bottom Margin", reader->m_absbottommargin );
04675 reader->m_absleft_border = config.readNumEntry( "Left Margin", reader->m_absleft_border );
04676 reader->m_absright_border = config.readNumEntry( "Right Margin", reader->m_absright_border );
04677 m_scrollishidden = config.readBoolEntry( "HideScrollBar", m_scrollishidden );
04678 m_hidebars = config.readBoolEntry( "HideToolBar", m_hidebars );
04679 reader->brepalm = config.readBoolEntry( "Repalm", reader->brepalm );
04680 reader->bunderlineLink = config.readBoolEntry( "UnderlineLink", reader->bunderlineLink );
04681 reader->bkern = config.readBoolEntry( "Kern", reader->bkern );
04682 reader->bremap = config.readBoolEntry( "Remap", reader->bremap );
04683 reader->bmakebold = config.readBoolEntry( "MakeBold", reader->bmakebold );
04684 reader->setContinuous(config.readBoolEntry( "Continuous", reader->m_continuousDocument ));
04685 reader->setDoubleBuffer(config.readBoolEntry("DoubleBuffer", reader->m_doubleBuffered));
04686 m_targetapp = config.readEntry( "TargetApp", m_targetapp );
04687 m_targetmsg = config.readEntry( "TargetMsg", m_targetmsg );
04688 #ifdef _SCROLLPIPE
04689 reader->m_pipetarget = config.readEntry( "PipeTarget", reader->m_pipetarget );
04690 reader->m_pauseAfterEachPara = config.readBoolEntry( "PauseAfterPara", reader->m_pauseAfterEachPara );
04691 #endif
04692 m_twoTouch = config.readBoolEntry( "TwoTouch", m_twoTouch);
04693 m_doAnnotation = config.readBoolEntry( "Annotation", m_doAnnotation);
04694 m_doDictionary = config.readBoolEntry( "Dictionary", m_doDictionary);
04695 m_doClipboard = config.readBoolEntry( "Clipboard", m_doClipboard);
04696 m_doOutput = config.readBoolEntry( "OutputTgt", m_doOutput);
04697 #ifdef USEQPE
04698 m_grabkeyboard = config.readBoolEntry( "GrabKeyboard", m_grabkeyboard);
04699 #endif
04700 m_propogatefontchange = config.readBoolEntry( "RequestorFontChange", m_propogatefontchange);
04701 reader->setBaseSize(config.readNumEntry( "Basesize", reader->getBaseSize() ));
04702 reader->setTwoTouch(m_twoTouch);
04703
04704 reader->m_outputName = config.readEntry( "OutputCodec", reader->m_outputName);
04705
04706 m_touch_action->setOn(m_twoTouch);
04707 m_setmono_action->setOn(reader->m_bMonoSpaced);
04708 setfontHelper(reader->m_fontname);
04709 if (full)
04710 {
04711 addtoolbars(&config);
04712 }
04713 reader->setfilter(reader->getfilter());
04714 reader->refresh();
04715 return true;
04716 }
04717
04718 bool QTReaderApp::PopulateConfig(const char* tgtdir, bool usedirs)
04719 {
04720 bkmkselector->clear();
04721 bkmkselector->setText("Cancel");
04722 #ifndef USEQPE
04723 int cnt = 0;
04724
04725 QDir d = QDir::home();
04726 if ( !d.cd(APPDIR) ) {
04727 qWarning( "Cannot find the \"~/" APPDIR "\" directory" );
04728 d = QDir::home();
04729 d.mkdir(APPDIR);
04730 d.cd(APPDIR);
04731 }
04732 if ( !d.cd(tgtdir) ) {
04733 qWarning( "Cannot find the \"~/" APPDIR "/%s\" directory", tgtdir );
04734 d = QDir::home();
04735 d.mkdir(tgtdir);
04736 d.cd(tgtdir);
04737 }
04738 d.setFilter( ((usedirs) ? QDir::Dirs : QDir::Files) | QDir::NoSymLinks );
04739
04740
04741 const QFileInfoList *list = d.entryInfoList();
04742 QFileInfoListIterator it( *list );
04743 QFileInfo *fi;
04744
04745 while ( (fi=it.current()) ) {
04746
04747 bkmkselector->insertItem(fi->fileName(), cnt++);
04748
04749
04750 ++it;
04751 }
04752
04753 #else
04754 int cnt = 0;
04755 DIR *d;
04756 char* finaldir;
04757 finaldir = new char[strlen(APPDIR)+1+strlen(tgtdir)+1];
04758 strcpy(finaldir, APPDIR);
04759 strcat(finaldir, "/");
04760 strcat(finaldir, tgtdir);
04761 d = opendir((const char *)Global::applicationFileName(finaldir,""));
04762
04763 while(1)
04764 {
04765 struct dirent* de;
04766 struct stat buf;
04767 de = readdir(d);
04768 if (de == NULL) break;
04769
04770 if (lstat((const char *)Global::applicationFileName(finaldir,de->d_name),&buf) == 0 && ((usedirs && S_ISDIR(buf.st_mode)) || (!usedirs && S_ISREG(buf.st_mode))))
04771 {
04772 bkmkselector->insertItem(de->d_name, cnt++);
04773 }
04774 }
04775 delete [] finaldir;
04776 closedir(d);
04777 #endif
04778 return (cnt > 0);
04779 }
04780
04781 void QTReaderApp::LoadTheme()
04782 {
04783 if (PopulateConfig("Themes", true))
04784 {
04785 editorStack->raiseWidget( bkmkselector );
04786 hidetoolbars();
04787 m_nBkmkAction = cLdTheme;
04788 }
04789 else
04790 QMessageBox::information(this, PROGNAME, "No config files");
04791 }
04792
04793 void QTReaderApp::LoadConfig()
04794 {
04795 if (PopulateConfig("configs"))
04796 {
04797 editorStack->raiseWidget( bkmkselector );
04798 hidetoolbars();
04799 m_nBkmkAction = cLdConfig;
04800 }
04801 else
04802 QMessageBox::information(this, PROGNAME, "No config files");
04803 }
04804
04805 void QTReaderApp::TidyConfig()
04806 {
04807 if (PopulateConfig("configs"))
04808 {
04809 editorStack->raiseWidget( bkmkselector );
04810 hidetoolbars();
04811 m_nBkmkAction = cRmConfig;
04812 }
04813 else
04814 QMessageBox::information(this, PROGNAME, "No config files");
04815 }
04816
04817 void QTReaderApp::ExportLinks()
04818 {
04819 if (PopulateConfig("urls"))
04820 {
04821 editorStack->raiseWidget( bkmkselector );
04822 hidetoolbars();
04823 m_nBkmkAction = cExportLinks;
04824 }
04825 else
04826 QMessageBox::information(this, PROGNAME, "No url files");
04827 }
04828
04829 void QTReaderApp::OnURLSelected(const QString& href, const size_t tgt)
04830 {
04831 #ifndef USEQPE
04832 qDebug("URL:%s", (const char*)href);
04833 int col = href.find(':');
04834 if (col > 0)
04835 {
04836 QString type = href.left(col);
04837 qDebug("Type:%s", (const char*)type);
04838 }
04839 else
04840 {
04841 qDebug("No type");
04842 }
04843 QString msg = "External URL\n" + href;
04844 QMessageBox::information(this, PROGNAME, msg);
04845 #else
04846 if (href.isEmpty())
04847 {
04848 QMessageBox::information(this, PROGNAME, "No URL information supplied");
04849 }
04850 else
04851 {
04852 CURLDialog* urld = new CURLDialog(href, false, this);
04853 urld->clipboard(m_url_clipboard);
04854 urld->localfile(m_url_localfile);
04855 urld->globalfile(m_url_globalfile);
04856 if (urld->exec())
04857 {
04858 m_url_clipboard = urld->clipboard();
04859 m_url_localfile = urld->localfile();
04860 m_url_globalfile = urld->globalfile();
04861 if (m_url_clipboard)
04862 {
04863 QClipboard* cb = QApplication::clipboard();
04864 cb->setText(href);
04865 qDebug("<a href=\"%s\">%s</a>", (const char*)href, (const char*)href);
04866 }
04867 if (m_url_localfile)
04868 {
04869 writeUrl(reader->m_string, href);
04870 }
04871 if (m_url_globalfile)
04872 {
04873 writeUrl("GlobalURLFile", href);
04874 }
04875 }
04876 delete urld;
04877 }
04878 #endif
04879 }
04880
04881 void QTReaderApp::writeUrl(const QString& file, const QString& href)
04882 {
04883 QString filename;
04884 #ifdef USEQPE
04885 filename = Global::applicationFileName(APPDIR "/urls", file);
04886 #else
04887 QFileInfo fi;
04888 QDir d = QDir::home();
04889 if ( !d.cd(APPDIR) )
04890 {
04891 qWarning( "Cannot find the \"~/" APPDIR "\" directory" );
04892 d = QDir::home();
04893 d.mkdir(APPDIR);
04894 d.cd(APPDIR);
04895 }
04896 if ( !d.cd("urls") )
04897 {
04898 qWarning( "Cannot find the \"~/" APPDIR "/urls\" directory" );
04899 d = QDir::home();
04900 d.cd(APPDIR);
04901 d.mkdir("urls");
04902 d.cd("urls");
04903 }
04904 fi.setFile(d, file);
04905 filename = fi.absFilePath();
04906 #endif
04907 FILE* fout = fopen(filename, "a");
04908 if (fout != NULL)
04909 {
04910 fprintf(fout, "<p><a href=\"%s\">%s</a>\n", (const char*)href, (const char*)href);
04911 fclose(fout);
04912 }
04913 else
04914 {
04915 QMessageBox::warning(this, PROGNAME, "Problem with writing URL");
04916 }
04917 }
04918
04919 QColor QTReaderApp::getcolour(int _c)
04920 {
04921 QColor c = white;
04922 switch (_c)
04923 {
04924 case 0:
04925 c = white;
04926 break;
04927 case 1:
04928 c = black;
04929 break;
04930 case 2:
04931 c = darkGray;
04932 break;
04933 case 3:
04934 c = gray;
04935 break;
04936 case 4:
04937 c = lightGray;
04938 break;
04939 case 5:
04940 c = red;
04941 break;
04942 case 6:
04943 c = green;
04944 break;
04945 case 7:
04946 c = blue;
04947 break;
04948 case 8:
04949 c = cyan;
04950 break;
04951 case 9:
04952 c = magenta;
04953 break;
04954 case 10:
04955 c = yellow;
04956 break;
04957 case 11:
04958 c = darkRed;
04959 break;
04960 case 12:
04961 c = darkGreen;
04962 break;
04963 case 13:
04964 c = darkBlue;
04965 break;
04966 case 14:
04967 c = darkCyan;
04968 break;
04969 case 15:
04970 c = darkMagenta;
04971 break;
04972 case 16:
04973 c = darkYellow;
04974 break;
04975 default:
04976 c = lightGray;
04977 break;
04978 }
04979 return c;
04980 }
04981
04982 void QTReaderApp::setscrollcolour()
04983 {
04984
04985
04986
04987
04988
04989
04990 reader->m_scrollcolor = getcolour(m_scrollcolor);
04991 }
04992
04993 void QTReaderApp::setscrollbarcolour()
04994 {
04995
04996
04997
04998
04999
05000
05001 reader->m_scrollbarcolor = getcolour(m_scrollbarcolor);
05002 }
05003
05004 void QTReaderApp::forceopen(const QString& filename)
05005 {
05006
05007
05008
05009
05010
05011 if (!filename.isEmpty() && QFileInfo(filename).exists())
05012 {
05013 updatefileinfo();
05014 if (pBkmklist != NULL)
05015 {
05016 if (m_fBkmksChanged)
05017 {
05018 savebkmks();
05019 }
05020 delete pBkmklist;
05021 pBkmklist = NULL;
05022 m_fBkmksChanged = false;
05023 }
05024 reader->disableAutoscroll();
05025 openFile(filename);
05026 reader->setFocus();
05027 }
05028 else
05029 {
05030 OnURLSelected(filename, 0);
05031 }
05032 }
05033
05034 void QTReaderApp::actionscroll(int v)
05035 {
05036 if (reader->m_rotated)
05037 {
05038 reader->dopageup(reader->buffdoc.startSection()+reader->buffdoc.endSection()-v);
05039 }
05040 else
05041 {
05042
05043
05044
05045
05046
05047
05048
05049 reader->locate(v);
05050 }
05051 }
05052
05053 void QTReaderApp::setBackgroundBitmap()
05054 {
05055 #ifdef USEQPE
05056 QString file = APPDIR "/Themes/";
05057 file += m_themename;
05058 QString tgt = Global::applicationFileName(file,"background");
05059 #else
05060 QString tgt(QDir::homeDirPath());
05061 tgt += QString("/" APPDIR "/Themes/") + m_themename + "/background";
05062 #endif
05063 qDebug("Trying to load %s", (const char *)tgt);
05064 QPixmap pm(tgt);
05065 reader->setBackgroundBitmap(pm, m_bgtype);
05066 }
05067
05068
05069
05070
05071
05072
05073
05074