Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

helpbrowser.cpp

Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008 *   Copyright (C) 2004 by Craig Bradney                                   *
00009 *   cbradney@zip.com.au                                                   *
00010 *   Copyright (C) 2005 by Petr Vanek                                      *
00011 *   petr@yarpen.cz                                                        *
00012 *                                                                         *
00013 *   This program is free software; you can redistribute it and/or modify  *
00014 *   it under the terms of the GNU General Public License as published by  *
00015 *   the Free Software Foundation; either version 2 of the License, or     *
00016 *   (at your option) any later version.                                   *
00017 *                                                                         *
00018 *   This program is distributed in the hope that it will be useful,       *
00019 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00020 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00021 *   GNU General Public License for more details.                          *
00022 *                                                                         *
00023 *   You should have received a copy of the GNU General Public License     *
00024 *   along with this program; if not, write to the                         *
00025 *   Free Software Foundation, Inc.,                                       *
00026 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00027 ***************************************************************************/
00028 
00029 #include "helpbrowser.h"
00030 
00031 #include <QAction>
00032 #include <QDebug>
00033 #include <QDir>
00034 #include <QDomDocument>
00035 #include <QEvent>
00036 #include <QFileDialog>
00037 #include <QFileInfo>
00038 #include <QHeaderView>
00039 #include <QInputDialog>
00040 #include <QItemSelectionModel>
00041 #include <QList>
00042 #include <QMessageBox>
00043 #include <QModelIndex>
00044 #include <QModelIndexList>
00045 #include <QPainter>
00046 #include <QPrinter>
00047 #include <QPrintDialog>
00048 #include <QProcess>
00049 #include <QPushButton>
00050 #include <QString>
00051 #include <QStandardItem>
00052 #include <QTextEdit>
00053 #include <QTreeView>
00054 #include <QXmlDefaultHandler>
00055 
00056 #include "prefsmanager.h"
00057 #include "scribuscore.h"
00058 #include "util_icon.h"
00059 
00066 class HistoryParser2 : public QXmlDefaultHandler
00067 {
00068     public:
00069         HelpBrowser *helpBrowser;
00070 
00071         bool startDocument()
00072         {
00073             return true;
00074         }
00075 
00076         bool startElement(const QString&, const QString&, const QString& qName, const QXmlAttributes& attrs)
00077         {
00078             if (qName == "item")
00079             {
00080                 struct histd2 his;
00081                 his.title = attrs.value(0);
00082                 his.url = attrs.value(1);
00083                 helpBrowser->mHistory[helpBrowser->histMenu->addAction(his.title)] = his;
00084             }
00085             return true;
00086         }
00087 
00088         bool endElement(const QString&, const QString&, const QString&)
00089         {
00090             return true;
00091         }
00092 };
00093 
00100 class BookmarkParser2 : public QXmlDefaultHandler
00101 {
00102     public:
00103         QTreeWidget* view;
00104         QMap<QString, QString>* quickHelpIndex;
00105         QMap<QString, QPair<QString, QString> >* bookmarkIndex;
00106 
00107         bool startDocument()
00108         {
00109             return true;
00110         }
00111 
00112         bool startElement(const QString&, const QString&, const QString& qName, const QXmlAttributes& attrs)
00113         {
00114             if (qName == "item")
00115             {
00116                 //TODO : This will dump items if bookmarks get loaded into a different GUI language
00117                 if (quickHelpIndex->contains(attrs.value(1)))
00118                 {
00119                     bookmarkIndex->insert(attrs.value(0), qMakePair(attrs.value(1), attrs.value(2)));
00120                     view->addTopLevelItem(new QTreeWidgetItem(view, QStringList() << attrs.value(0)));
00121                 }
00122             }
00123             return true;
00124         }
00125 
00126         bool endElement(const QString&, const QString&, const QString&)
00127         {
00128             return true;
00129         }
00130 };
00131 
00132 bool HelpBrowser::firstRun=true;
00133 
00134 HelpBrowser::HelpBrowser(QWidget* parent)
00135     : QMainWindow( parent )
00136 {
00137     setupUi(this);
00138 }
00139 
00140 HelpBrowser::HelpBrowser( QWidget* parent, const QString& /*caption*/, const QString& guiLanguage, const QString& jumpToSection, const QString& jumpToFile)
00141     : QMainWindow( parent )
00142 {
00143     firstRun=true;
00144     setupUi(this);
00145     setupLocalUI();
00146     language = guiLanguage.isEmpty() ? QString("en") : guiLanguage.left(2);
00147     finalBaseDir = ScPaths::instance().docDir() + "en/"; //Sane default for help location
00148     menuModel=NULL;
00149     loadMenu();
00150     if (menuModel!=NULL)
00151     {
00152         readBookmarks();
00153         readHistory();
00154         jumpToHelpSection(jumpToSection, jumpToFile );
00155         languageChange();
00156     }
00157     else
00158     {
00159         displayNoHelp();
00160     }
00161 }
00162 
00163 HelpBrowser::~HelpBrowser()
00164 {
00165     firstRun=true;
00166 }
00167 
00168 void HelpBrowser::closeEvent(QCloseEvent * event)
00169 {
00170     delete menuModel;
00171 
00172     // no need to delete child widgets, Qt does it all for us
00173     // bookmarks
00174     QFile bookFile(bookmarkFile());
00175     if (bookFile.open(QIODevice::WriteOnly))
00176     {
00177         QTextStream stream(&bookFile);
00178         stream.setCodec("UTF-8");
00179         stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
00180         stream << "<bookmarks>\n";
00181         QTreeWidgetItemIterator it(bookmarksView);
00182         while (*it) 
00183         {
00184             if (bookmarkIndex.contains((*it)->text(0)))
00185             {
00186                 QString pagetitle(bookmarkIndex.value((*it)->text(0)).first);
00187                 QString filename(bookmarkIndex.value((*it)->text(0)).second);
00188                 stream << "\t<item title=\"" << (*it)->text(0) << "\" pagetitle=\"" << pagetitle << "\" url=\"" << filename << "\" />\n";
00189             }
00190             ++it;
00191         }
00192         stream << "</bookmarks>\n";
00193         bookFile.close();
00194     }
00195     // history
00196     QFile histFile(historyFile());
00197     if (histFile.open(QIODevice::WriteOnly))
00198     {
00199         QTextStream stream(&histFile);
00200         stream.setCodec("UTF-8");
00201         stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
00202         stream << "<history>\n";
00203         for (QMap<QAction*,histd2>::Iterator it = mHistory.begin() ; it != mHistory.end(); ++it)
00204             stream << "\t<item title=\"" << it.value().title << "\" url=\"" << it.value().url << "\" />\n";
00205         stream << "</history>\n";
00206         histFile.close();
00207     }
00208     // size
00209     prefs->set("xsize", width());
00210     prefs->set("ysize", height());
00211 
00212     emit closed();
00213 }
00214 
00215 void HelpBrowser::setupLocalUI()
00216 {
00217     setWindowIcon(loadIcon("AppIcon.png"));
00218     //Add Menus
00219     fileMenu=menuBar()->addMenu("");
00220     editMenu=menuBar()->addMenu("");
00221     bookMenu=menuBar()->addMenu("");
00222     histMenu=new QMenu(this);
00223 
00224     //Add Menu items
00225     filePrint=fileMenu->addAction(loadIcon("16/document-print.png"), "", this, SLOT(print()), Qt::CTRL+Qt::Key_P);
00226     fileMenu->addSeparator();
00227     fileExit=fileMenu->addAction(loadIcon("exit.png"), "", this, SLOT(close()));
00228     editFind=editMenu->addAction(loadIcon("find.png"), "", this, SLOT(find()), Qt::CTRL+Qt::Key_F);
00229     editFindNext=editMenu->addAction( "", this, SLOT(findNext()), Qt::Key_F3);
00230     editFindPrev=editMenu->addAction( "", this, SLOT(findPrevious()), Qt::SHIFT+Qt::Key_F3);
00231     bookAdd=bookMenu->addAction( "", this, SLOT(bookmarkButton_clicked()), Qt::CTRL+Qt::Key_D);
00232     bookDel=bookMenu->addAction( "", this, SLOT(deleteBookmarkButton_clicked()));
00233     bookDelAll=bookMenu->addAction( "", this, SLOT(deleteAllBookmarkButton_clicked()));
00234 
00235     //Add Toolbar items
00236     goHome=toolBar->addAction(loadIcon("16/go-home.png"), "", textBrowser, SLOT(home()));
00237     goBack=toolBar->addAction(loadIcon("16/go-previous.png"), "", textBrowser, SLOT(backward()));
00238     goFwd=toolBar->addAction(loadIcon("16/go-next.png"), "", textBrowser, SLOT(forward()));
00239     goBack->setMenu(histMenu);
00240     
00241     listView->header()->hide();
00242     searchingView->header()->hide();
00243     bookmarksView->header()->hide();
00244 
00245     splitter->setStretchFactor(splitter->indexOf(tabWidget), 0);
00246     splitter->setStretchFactor(splitter->indexOf(textBrowser), 1);
00247     // reset previous size
00248     prefs = PrefsManager::instance()->prefsFile->getPluginContext("helpbrowser");
00249     int xsize = prefs->getUInt("xsize", 640);
00250     int ysize = prefs->getUInt("ysize", 480);
00251     resize(QSize(xsize, ysize).expandedTo(minimumSizeHint()) );
00252 
00253     //basic ui
00254     connect(histMenu, SIGNAL(triggered(QAction*)), this, SLOT(histChosen(QAction*)));
00255     // searching
00256     connect(searchingEdit, SIGNAL(returnPressed()), this, SLOT(searchingButton_clicked()));
00257     connect(searchingButton, SIGNAL(clicked()), this, SLOT(searchingButton_clicked()));
00258     connect(searchingView, SIGNAL(itemClicked( QTreeWidgetItem *, int)), this, SLOT(itemSearchSelected(QTreeWidgetItem *, int)));
00259     // bookmarks
00260     connect(bookmarkButton, SIGNAL(clicked()), this, SLOT(bookmarkButton_clicked()));
00261     connect(deleteBookmarkButton, SIGNAL(clicked()), this, SLOT(deleteBookmarkButton_clicked()));
00262     connect(deleteAllBookmarkButton, SIGNAL(clicked()), this, SLOT(deleteAllBookmarkButton_clicked()));
00263     connect(bookmarksView, SIGNAL(itemClicked( QTreeWidgetItem *, int)), this, SLOT(itemBookmarkSelected(QTreeWidgetItem *, int)));
00264     // links hoover
00265     connect(textBrowser, SIGNAL(overLink(const QString &)), this, SLOT(showLinkContents(const QString &)));
00266     
00267     languageChange();
00268 }
00269 
00270 void HelpBrowser::showLinkContents(const QString &link)
00271 {
00272     statusBar()->showMessage(link);
00273 }
00274 
00275 void HelpBrowser::changeEvent(QEvent *e)
00276 {
00277     if (e->type() == QEvent::LanguageChange)
00278     {
00279         languageChange();
00280     }
00281     else
00282         QWidget::changeEvent(e);
00283 }
00284 
00285 void HelpBrowser::languageChange()
00286 {
00287     setWindowTitle( tr( "Scribus Online Help" ) );
00288     
00289     fileMenu->setTitle(tr("&File"));
00290     editMenu->setTitle(tr("&Edit"));
00291     bookMenu->setTitle(tr("&Bookmarks"));
00292     
00293     filePrint->setText(tr("&Print..."));
00294     fileExit->setText(tr("&Quit"));
00295     editFind->setText(tr("&Find..."));
00296     editFindNext->setText(tr("Find &Next"));
00297     editFindPrev->setText(tr("Find &Previous"));
00298     bookAdd->setText(tr("&Add Bookmark"));
00299     bookDel->setText(tr("&Delete"));
00300     bookDelAll->setText(tr("D&elete All"));
00301     Ui::HelpBrowser::retranslateUi(this);
00302     if (!firstRun)
00303     {
00304         QString fname(QDir::cleanPath(textBrowser->source().toString()));
00305         QFileInfo fi(fname);
00306         QString filename(fi.fileName());
00307         if (ScCore->getGuiLanguage().isEmpty())
00308             language="en";
00309         else
00310             language=ScCore->getGuiLanguage();
00311         loadMenu();
00312         if (menuModel!=NULL)
00313             loadHelp(finalBaseDir + "/" + filename);
00314     }
00315     else
00316         firstRun=false;
00317 }
00318 
00319 void HelpBrowser::print()
00320 {
00321     QPrinter printer;
00322     printer.setFullPage(true);
00323     QPrintDialog dialog(&printer, this);
00324     if (dialog.exec())
00325         textBrowser->print(&printer);
00326 }
00327 
00328 void HelpBrowser::searchingButton_clicked()
00329 {
00330     // root files
00331     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
00332     searchingInDirectory(finalBaseDir);
00333     QApplication::restoreOverrideCursor();
00334 }
00335 
00336 void HelpBrowser::searchingInDirectory(const QString& aDir)
00337 {
00338     QDir dir(QDir::convertSeparators(aDir + "/"));
00339     QStringList in;
00340     in.append("*.html");
00341     QStringList lst = dir.entryList(in);
00342     for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it)
00343     {
00344         QString fname(aDir + "/" + (*it));
00345         QFile f(fname);
00346         if (f.open(QIODevice::ReadOnly))
00347         {
00348             QTextStream stream(&f);
00349             QString str = stream.readAll();
00350             int cnt = str.count(searchingEdit->text(), Qt::CaseInsensitive);
00351             if (cnt > 0)
00352             {
00353                 QString fullname = fname;
00354                 QString toFind(fname.remove(finalBaseDir + "/"));
00355                 QMapIterator<QString, QString> i(quickHelpIndex);
00356                 while (i.hasNext())
00357                 {
00358                     i.next();
00359                     if (i.value()==toFind)
00360                         searchingView->addTopLevelItem(new QTreeWidgetItem(searchingView, QStringList() << i.key()));
00361                 }
00362             }
00363             f.close();
00364         }
00365     }
00366     // get dirs - ugly recursion
00367     in.clear();
00368     in.append("*");
00369     QStringList dst = dir.entryList(in, QDir::Dirs);
00370     for (QStringList::Iterator it = dst.begin(); it != dst.end(); ++it)
00371         if ((*it)!="." && (*it)!="..")
00372             searchingInDirectory(QDir::convertSeparators(aDir + QString((*it)) + "/"));
00373 }
00374 
00375 void HelpBrowser::find()
00376 {
00377     findText = QInputDialog::getText( this, tr("Find"), tr("Search Term:"), QLineEdit::Normal, findText, 0);
00378     if (findText.isNull())
00379         return;
00380     findNext();
00381 }
00382 
00383 void HelpBrowser::findNext()
00384 {
00385     if (findText.isNull())
00386     {
00387         find();
00388         return;
00389     }
00390     // find it. finally
00391     textBrowser->find(findText, 0);
00392 }
00393 
00394 void HelpBrowser::findPrevious()
00395 {
00396     if (findText.isNull())
00397     {
00398         find();
00399         return;
00400     }
00401     // find it. finally
00402     textBrowser->find(findText);
00403 }
00404 
00405 void HelpBrowser::bookmarkButton_clicked()
00406 {
00407     QString title = textBrowser->documentTitle();
00408     QString fname(QDir::cleanPath(textBrowser->source().toLocalFile()));
00409     title = QInputDialog::getText(this, tr("New Bookmark"), tr("New Bookmark's Title:"), QLineEdit::Normal, title, 0);
00410     // user cancel
00411     if (title.isNull())
00412         return;
00413     //TODO: start storing full paths
00414     QString toFind(fname.remove(QDir::convertSeparators(finalBaseDir)));
00415     toFind=toFind.mid(1, toFind.length()-1);
00416     QMapIterator<QString, QString> i(quickHelpIndex);
00417     while (i.hasNext())
00418     {
00419         i.next();
00420         if (i.value()==toFind)
00421         {
00422             bookmarkIndex.insert(title, qMakePair(i.key(), i.value()));
00423             bookmarksView->addTopLevelItem(new QTreeWidgetItem(bookmarksView, QStringList() << title));
00424         }
00425     }
00426 }
00427 
00428 void HelpBrowser::deleteBookmarkButton_clicked()
00429 {
00430     QTreeWidgetItem *twi=bookmarksView->currentItem();
00431     if (twi!=NULL)
00432     {
00433         if (bookmarkIndex.contains(twi->text(0)))
00434             bookmarkIndex.remove(twi->text(0));
00435         delete twi;
00436     }
00437 }
00438 
00439 void HelpBrowser::deleteAllBookmarkButton_clicked()
00440 {
00441     bookmarkIndex.clear();
00442     bookmarksView->clear();
00443 }
00444 
00445 void HelpBrowser::histChosen(QAction* i)
00446 {
00447     if (mHistory.contains(i))
00448         textBrowser->setSource( QUrl::fromLocalFile(mHistory[i].url) );
00449 }
00450 
00451 void HelpBrowser::jumpToHelpSection(const QString& jumpToSection, const QString& jumpToFile)
00452 {
00453     QString toLoad;
00454     bool noDocs=false;
00455 
00456     if (jumpToFile.isEmpty())
00457     {
00458         toLoad = finalBaseDir + "/"; //clean this later to handle 5 char locales
00459         if (jumpToSection.isEmpty())
00460         {
00461             QModelIndex index=menuModel->index(0,1);
00462             if (index.isValid())
00463             {
00464                 listView->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
00465                 toLoad += menuModel->data(index, Qt::DisplayRole).toString();
00466             }
00467             else
00468                 noDocs=true;
00469         }
00470         else if (jumpToSection=="scripter")
00471         {
00472             toLoad+="scripter1.html";
00473         }
00474     }
00475     else
00476         toLoad=jumpToFile;
00477 
00478     if (!noDocs)
00479         loadHelp(toLoad);
00480     else
00481         displayNoHelp();
00482 }
00483 
00484 void HelpBrowser::loadHelp(const QString& filename)
00485 {
00486     struct histd2 his;
00487     bool Avail = true;
00488     QString toLoad;
00489     QFileInfo fi;
00490     fi = QFileInfo(filename);
00491     if (fi.fileName().length()>0)
00492     {
00493         if (fi.exists())
00494             toLoad=filename;
00495         else
00496         {
00497             toLoad = QDir::convertSeparators(ScPaths::instance().docDir() + "en/index.html");
00498             language="en";
00499             fi = QFileInfo(toLoad);
00500             if (!fi.exists())
00501             {
00502                 displayNoHelp();
00503                 Avail = false;
00504             }
00505         }
00506     }
00507     else
00508         Avail=false;
00509     if (Avail)
00510     {
00511         textBrowser->setSource( QUrl::fromLocalFile(toLoad) );
00512         
00513         his.title = textBrowser->documentTitle();
00514         if (his.title.isEmpty())
00515             his.title = toLoad;
00516         his.url = toLoad;
00517         mHistory[histMenu->addAction(his.title)] = his;
00518     }
00519     if (mHistory.count() > 15)
00520     {
00521         QAction* first=histMenu->actions().first();
00522         mHistory.remove(first);
00523         histMenu->removeAction(first);
00524     }
00525 }
00526 
00527 void HelpBrowser::loadMenu()
00528 {
00529     QString baseHelpDir = ScPaths::instance().docDir();
00530     QString altHelpDir  = ScPaths::instance().getApplicationDataDir();
00531     QString baseHelpMenuFile = QDir::convertSeparators(baseHelpDir + language + "/menu.xml");
00532     QString altHelpMenuFile = QDir::convertSeparators(altHelpDir + "doc/" + language + "/menu.xml");
00533     QFileInfo baseFi = QFileInfo(baseHelpMenuFile);
00534     QFileInfo altFi = QFileInfo(altHelpMenuFile);
00535     QString toLoad = baseHelpMenuFile;
00536     if (!baseFi.exists())
00537     {
00538         if (altFi.exists())
00539         {
00540             toLoad=altHelpMenuFile;
00541             baseFi=altFi;
00542         }
00543         else        
00544         {
00545             if (!language.isEmpty())
00546             {
00547                 //Check if we can load, eg "de" when "de_CH" docs dont exist
00548                 QString baseHelpMenuFile3 = QDir::convertSeparators(baseHelpDir + language.left(2) + "/menu.xml");
00549                 QString altHelpMenuFile3 = QDir::convertSeparators(altHelpDir + "doc/" + language.left(2) + "/menu.xml");
00550                 QFileInfo fi3 = QFileInfo(baseHelpMenuFile3);
00551                 QFileInfo altfi3 = QFileInfo(altHelpMenuFile3);
00552                 if (fi3.exists())
00553                 {
00554                     language=language.left(2);
00555                     toLoad = QDir::convertSeparators(baseHelpMenuFile3);
00556                 }
00557                 else
00558                 if (altfi3.exists())
00559                 {
00560                     language=language.left(2);
00561                     toLoad = QDir::convertSeparators(altHelpMenuFile3);
00562                 }
00563                 else
00564                 {
00565                     //Fall back to English
00566                     sDebug("Scribus help in your selected language does not exist, trying English. Otherwise, please visit http://docs.scribus.net.");
00567                     language="en";
00568                     toLoad = QDir::convertSeparators(baseHelpDir + language + "/menu.xml");
00569                 }
00570             }
00571             else
00572             {
00573                 language="en";
00574                 toLoad = QDir::convertSeparators(baseHelpDir + language + "/menu.xml");
00575             }
00576             baseFi = QFileInfo(toLoad);
00577         }
00578     }
00579     //Set our final location for loading the help files
00580     finalBaseDir=baseFi.path();
00581     if (baseFi.exists())
00582     {
00583         if (menuModel!=NULL)
00584             delete menuModel;
00585         menuModel=new ScHelpTreeModel(toLoad, "Topic", "Location", &quickHelpIndex);
00586     
00587         listView->setModel(menuModel);
00588         listView->setSelectionMode(QAbstractItemView::SingleSelection);
00589         QItemSelectionModel *selectionModel = new QItemSelectionModel(menuModel);
00590         listView->setSelectionModel(selectionModel);
00591         connect(listView->selectionModel(), SIGNAL(selectionChanged( const QItemSelection &, const QItemSelection &)), this, SLOT(itemSelected( const QItemSelection &, const QItemSelection &)));
00592     
00593         listView->setColumnHidden(1,true);
00594     }
00595     else
00596         menuModel=NULL;
00597 }
00598 
00599 void HelpBrowser::readBookmarks()
00600 {
00601     BookmarkParser2 handler;
00602     handler.view = bookmarksView;
00603     handler.quickHelpIndex=&quickHelpIndex;
00604     handler.bookmarkIndex=&bookmarkIndex;
00605     QFile xmlFile(bookmarkFile());
00606     QXmlInputSource source(&xmlFile);
00607     QXmlSimpleReader reader;
00608     reader.setContentHandler(&handler);
00609     reader.parse(source);
00610 }
00611 
00612 void HelpBrowser::readHistory()
00613 {
00614     HistoryParser2 handler;
00615     handler.helpBrowser = this;
00616     QFile xmlFile(historyFile());
00617     QXmlInputSource source(&xmlFile);
00618     QXmlSimpleReader reader;
00619     reader.setContentHandler(&handler);
00620     reader.parse(source);
00621 }
00622 
00623 void HelpBrowser::setText(const QString& str)
00624 {
00625     textBrowser->setText(str);
00626 }
00627 
00628 void HelpBrowser::itemSelected(const QItemSelection & selected, const QItemSelection & deselected)
00629 {
00630     Q_UNUSED(deselected);
00631 
00632     QModelIndex index;
00633     QModelIndexList items = selected.indexes();
00634     int i=0;
00635     foreach (index, items)
00636     {
00637         if (i==1) // skip 0, as this is always the rootitem, even if we are selecting the rootitem. hmm
00638         {
00639             QString filename(menuModel->data(index, Qt::DisplayRole).toString());
00640             if (!filename.isEmpty())
00641             {
00642                 loadHelp(finalBaseDir + "/" + filename);
00643             }
00644         }
00645         ++i;
00646     }
00647 }
00648 
00649 void HelpBrowser::itemSearchSelected(QTreeWidgetItem *twi, int i)
00650 {
00651     Q_UNUSED(i);
00652     if (!twi)
00653         return;
00654     if (quickHelpIndex.contains(twi->text(0)))
00655     {
00656         QString filename(quickHelpIndex.value(twi->text(0)));
00657         if (!filename.isEmpty())
00658         {
00659             loadHelp(finalBaseDir + "/" + filename);
00660             findText = searchingEdit->text();
00661             findNext();
00662         }
00663     }
00664 }
00665 
00666 void HelpBrowser::itemBookmarkSelected(QTreeWidgetItem *twi, int i)
00667 {
00668     Q_UNUSED(i);
00669     if (!twi)
00670         return;
00671     if (bookmarkIndex.contains(twi->text(0)))
00672     {
00673         QString filename(bookmarkIndex.value(twi->text(0)).second);
00674         if (!filename.isEmpty())
00675             loadHelp(finalBaseDir + "/" + filename);
00676     }
00677 }
00678 
00683 QString HelpBrowser::bookmarkFile()
00684 {
00685     QString appDataDir(ScPaths::getApplicationDataDir());
00686     QString fname(appDataDir + "doc/bookmarks.xml");
00687     if (!QFile::exists(fname))
00688     {
00689         QDir d(QDir::convertSeparators(appDataDir));
00690         d.mkdir("doc");
00691     }
00692     return fname;
00693 }
00694 
00695 
00700 QString HelpBrowser::historyFile()
00701 {
00702     QString appDataDir(ScPaths::getApplicationDataDir());
00703     QString fname(appDataDir + "doc/history.xml");
00704     if (!QFile::exists(fname))
00705     {
00706         QDir d(QDir::convertSeparators(appDataDir));
00707         d.mkdir("doc");
00708     }
00709     return fname;
00710 }
00711 
00712 void HelpBrowser::displayNoHelp()
00713 {
00714     QString noHelpMsg=tr("<h2><p>Sorry, no manual is installed!</p><p>Please see:</p><ul><li>http://docs.scribus.net for updated documentation</li><li>http://www.scribus.net for downloads</li></ul></h2>",
00715                          "HTML message for no documentation available to show");
00716 
00717     textBrowser->setText(noHelpMsg);
00718     
00719     filePrint->setEnabled(false);
00720     editFind->setEnabled(false);
00721     editFindNext->setEnabled(false);
00722     editFindPrev->setEnabled(false);
00723     bookAdd->setEnabled(false);
00724     bookDel->setEnabled(false);
00725     bookDelAll->setEnabled(false);
00726     goHome->setEnabled(false);
00727     goBack->setEnabled(false);
00728     goFwd->setEnabled(false);
00729     
00730     histMenu->disconnect();
00731     searchingEdit->disconnect();
00732     searchingButton->disconnect();
00733     searchingView->disconnect();
00734     bookmarkButton->disconnect();
00735     deleteBookmarkButton->disconnect();
00736     deleteAllBookmarkButton->disconnect();
00737     bookmarksView->disconnect();
00738     textBrowser->disconnect();
00739 }
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.