00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "HelpWindow.h"
00023 #include "RcFile.h"
00024 #include "../pics/next.xpm"
00025 #include "../pics/home.xpm"
00026 #include "../pics/previous.xpm"
00027 #include "../pics/disable.xpm"
00028 #include <qlayout.h>
00029 #include <qdir.h>
00030 #include <qfile.h>
00031
00032 HelpWindow::HelpWindow (QWidget *w, QString &fn) : QDialog (w, "HelpWindow", FALSE, WDestructiveClose)
00033 {
00034 RcFile rcfile;
00035 rcfile.loadData(RcFile::HelpFilePath, homePath);
00036 homePath.append("/");
00037 tocPath = homePath + "toc.html";
00038
00039 QVBoxLayout *vbox = new QVBoxLayout (this);
00040 vbox->setSpacing(5);
00041 vbox->setMargin(5);
00042
00043 toolbar = new Toolbar(this, Toolbar::Horizontal);
00044 vbox->addWidget(toolbar);
00045
00046 QString s("home");
00047 QString s2(tr("Home"));
00048 toolbar->addButton(s, home, s2);
00049 QObject::connect(toolbar->getButton(s), SIGNAL(clicked()), this, SLOT(goHome()));
00050
00051 s = "previous";
00052 s2 = tr("Previous");
00053 toolbar->addButton(s, previous, s2);
00054 QObject::connect(toolbar->getButton(s), SIGNAL(clicked()), this, SLOT(goPrevious()));
00055
00056 s = "next";
00057 s2 = tr("Next");
00058 toolbar->addButton(s, next, s2);
00059 QObject::connect(toolbar->getButton(s), SIGNAL(clicked()), this, SLOT(goNext()));
00060
00061 s = "exit";
00062 s2 = tr("Close");
00063 toolbar->addButton(s, disable, s2);
00064 QObject::connect(toolbar->getButton(s), SIGNAL(clicked()), this, SLOT(exit()));
00065
00066 text = new QTextBrowser(this);
00067
00068 QObject::connect(text, SIGNAL(backwardAvailable(bool)), this, SLOT(previousStatus(bool)));
00069 QObject::connect(text, SIGNAL(forwardAvailable(bool)), this, SLOT(nextStatus(bool)));
00070 QObject::connect(text, SIGNAL(linkClicked(const QString &)), this, SLOT(slotLoadFile(const QString &)));
00071
00072 vbox->addWidget (text);
00073
00074 s = homePath + fn;
00075 QDir dir;
00076
00077
00078 if (dir.exists(fn) && s.contains(".html"))
00079 text->setSource(fn);
00080 else if (dir.exists(s) && s.contains(".html"))
00081 text->setSource(s);
00082 else
00083 {
00084 qDebug("Document not found: " + fn);
00085 text->setSource(tocPath);
00086 }
00087
00088 setCaption(text->documentTitle());
00089
00090 QSize sz;
00091 rcfile.loadSize(RcFile::HelpWindowSize, sz);
00092 resize(sz);
00093 }
00094
00095 HelpWindow::~HelpWindow ()
00096 {
00097 }
00098
00099 void HelpWindow::goHome ()
00100 {
00101 text->setSource(tocPath);
00102 }
00103
00104 void HelpWindow::goPrevious ()
00105 {
00106 text->backward();
00107 }
00108
00109 void HelpWindow::goNext ()
00110 {
00111 text->forward();
00112 }
00113
00114 void HelpWindow::previousStatus (bool d)
00115 {
00116 QString s("previous");
00117 toolbar->setButtonStatus(s, d);
00118 }
00119
00120 void HelpWindow::nextStatus (bool d)
00121 {
00122 QString s("next");
00123 toolbar->setButtonStatus(s, d);
00124 }
00125
00126 void HelpWindow::exit ()
00127 {
00128 RcFile rcfile;
00129 rcfile.saveSize(RcFile::HelpWindowSize, size());
00130 done(0);
00131 }
00132
00133 void HelpWindow::slotLoadFile(const QString &fileName)
00134 {
00135 if (fileName.contains(".html"))
00136 {
00137 text->setSource(fileName);
00138
00139 }
00140 else
00141 {
00142
00143 QFile file(QFile::encodeName(fileName));
00144 QString s(file.name());
00145
00146 if ( file.open( IO_ReadOnly ) )
00147 {
00148 s = (QString)file.readAll();
00149 file.close();
00150 s.replace( QChar('<'), "<" );
00151 s.replace( QChar('>'), ">" );
00152 s.prepend("<html><title>CHANGELOG</title<body><pre>");
00153
00154
00155
00156 s.append("</pre></body></html>");
00157 }
00158 else
00159 {
00160 s = file.errorString ();
00161 }
00162 text->setText(s);
00163
00164 }
00165 setCaption(text->documentTitle());
00166 }