Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > by-pkgid > 9601c7beb4ff23e834bfa171795ed560 > files > 151

vidalia-0.2.9-1mdv2010.1.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Vidalia: HelpBrowser.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_b47abd1aad201a152869566145babb61.html">src</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_695ba8f8357372e02d38c40b3c6dbe81.html">vidalia</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_b6d10de2e9b292c6ec1000704888fbb8.html">help</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_29e5c2bf20d56a63773809b26e49a915.html">browser</a>
  </div>
</div>
<div class="contents">
<h1>HelpBrowser.cpp</h1><a href="_help_browser_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment">**  This file is part of Vidalia, and is subject to the license terms in the</span>
<a name="l00003"></a>00003 <span class="comment">**  LICENSE file, found in the top level directory of this distribution. If you</span>
<a name="l00004"></a>00004 <span class="comment">**  did not receive the LICENSE file with this file, you may obtain it from the</span>
<a name="l00005"></a>00005 <span class="comment">**  Vidalia source package distributed by the Vidalia Project at</span>
<a name="l00006"></a>00006 <span class="comment">**  http://www.vidalia-project.net/. No part of Vidalia, including this file,</span>
<a name="l00007"></a>00007 <span class="comment">**  may be copied, modified, propagated, or distributed except according to the</span>
<a name="l00008"></a>00008 <span class="comment">**  terms described in the LICENSE file.</span>
<a name="l00009"></a>00009 <span class="comment">*/</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="comment">/*</span>
<a name="l00012"></a>00012 <span class="comment">** \file HelpBrowser.cpp</span>
<a name="l00013"></a>00013 <span class="comment">** \version $Id: HelpBrowser.cpp 3735 2009-04-28 20:28:01Z edmanm $</span>
<a name="l00014"></a>00014 <span class="comment">** \brief Displays a list of help topics and content</span>
<a name="l00015"></a>00015 <span class="comment">*/</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="preprocessor">#include &quot;<a class="code" href="_help_browser_8h.html">HelpBrowser.h</a>&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="_vidalia_8h.html">Vidalia.h</a>&quot;</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;QDomDocument&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;QDir&gt;</span>
<a name="l00022"></a>00022 
<a name="l00023"></a><a class="code" href="_help_browser_8cpp.html#ad5f0fb0475cb984d6201e7d54dadea09">00023</a> <span class="preprocessor">#define LEFT_PANE_INDEX     0</span>
<a name="l00024"></a><a class="code" href="_help_browser_8cpp.html#a96259801b738aad01e59ff4aec722d77">00024</a> <span class="preprocessor"></span><span class="preprocessor">#define NO_STRETCH          0</span>
<a name="l00025"></a><a class="code" href="_help_browser_8cpp.html#a78adac6391b0448340c8934f613b9b80">00025</a> <span class="preprocessor"></span><span class="preprocessor">#define MINIMUM_PANE_SIZE   1</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span>
<a name="l00027"></a>00027 <span class="comment">/* Names of elements and attributes in the XML file */</span>
<a name="l00028"></a><a class="code" href="_help_browser_8cpp.html#a201dea4193475b97647d881a5821a9b1">00028</a> <span class="preprocessor">#define ELEMENT_CONTENTS        &quot;Contents&quot;</span>
<a name="l00029"></a><a class="code" href="_help_browser_8cpp.html#aca045e8afe68b3614f2f28ee9aae5951">00029</a> <span class="preprocessor"></span><span class="preprocessor">#define ELEMENT_TOPIC           &quot;Topic&quot;</span>
<a name="l00030"></a><a class="code" href="_help_browser_8cpp.html#a71904a978d540e4b8377e50c17b658f5">00030</a> <span class="preprocessor"></span><span class="preprocessor">#define ATTRIBUTE_TOPIC_ID      &quot;id&quot;</span>
<a name="l00031"></a><a class="code" href="_help_browser_8cpp.html#a13e6db2a236ab75af3856757cdaba077">00031</a> <span class="preprocessor"></span><span class="preprocessor">#define ATTRIBUTE_TOPIC_HTML    &quot;html&quot;</span>
<a name="l00032"></a><a class="code" href="_help_browser_8cpp.html#a2b3625df4ef764898523321ea749a431">00032</a> <span class="preprocessor"></span><span class="preprocessor">#define ATTRIBUTE_TOPIC_NAME    &quot;name&quot;</span>
<a name="l00033"></a><a class="code" href="_help_browser_8cpp.html#a43af0db43d757b6c3c33128174ce653c">00033</a> <span class="preprocessor"></span><span class="preprocessor">#define ATTRIBUTE_TOPIC_SECTION &quot;section&quot;</span>
<a name="l00034"></a>00034 <span class="preprocessor"></span>
<a name="l00035"></a>00035 <span class="comment">/* Define two roles used to store data associated with a topic item */</span>
<a name="l00036"></a><a class="code" href="_help_browser_8cpp.html#afd74dc6c7575602c8f7e70d1181e07bd">00036</a> <span class="preprocessor">#define ROLE_TOPIC_ID        Qt::UserRole</span>
<a name="l00037"></a><a class="code" href="_help_browser_8cpp.html#a5bdeb5f7020e06fc24a24a9aba2f8949">00037</a> <span class="preprocessor"></span><span class="preprocessor">#define ROLE_TOPIC_QRC_PATH (Qt::UserRole+1)</span>
<a name="l00038"></a>00038 <span class="preprocessor"></span>
<a name="l00039"></a>00039 <span class="comment"></span>
<a name="l00040"></a>00040 <span class="comment">/** Constuctor. This will probably do more later */</span>
<a name="l00041"></a><a class="code" href="class_help_browser.html#a7c96dde0b9aa69e2f995aed8d4ed306d">00041</a> <a class="code" href="class_help_browser.html#a7c96dde0b9aa69e2f995aed8d4ed306d">HelpBrowser::HelpBrowser</a>(QWidget *parent)
<a name="l00042"></a>00042  : <a class="code" href="class_vidalia_window.html">VidaliaWindow</a>(<span class="stringliteral">&quot;HelpBrowser&quot;</span>, parent)
<a name="l00043"></a>00043 {
<a name="l00044"></a>00044   <a class="code" href="class_vidalia_settings.html">VidaliaSettings</a> settings;
<a name="l00045"></a>00045 
<a name="l00046"></a>00046   <span class="comment">/* Invoke Qt Designer generated QObject setup routine */</span>
<a name="l00047"></a>00047   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.setupUi(<span class="keyword">this</span>);
<a name="l00048"></a>00048 <span class="preprocessor">#if defined(Q_WS_MAC)</span>
<a name="l00049"></a>00049 <span class="preprocessor"></span>  <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.actionHome-&gt;setShortcut(QString(<span class="stringliteral">&quot;Shift+Ctrl+H&quot;</span>));
<a name="l00050"></a>00050 <span class="preprocessor">#endif</span>
<a name="l00051"></a>00051 <span class="preprocessor"></span>
<a name="l00052"></a>00052   <span class="comment">/* Pressing &#39;Esc&#39; or &#39;Ctrl+W&#39; will close the window */</span>
<a name="l00053"></a>00053   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.actionClose-&gt;setShortcut(QString(<span class="stringliteral">&quot;Esc&quot;</span>));
<a name="l00054"></a>00054   <a class="code" href="class_vidalia.html#a4f28d73e2f92e6656f7c1c06d41b3569">Vidalia::createShortcut</a>(<span class="stringliteral">&quot;Ctrl+W&quot;</span>, <span class="keyword">this</span>, <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.actionClose, SLOT(trigger()));
<a name="l00055"></a>00055 
<a name="l00056"></a>00056   <span class="comment">/* Hide Search frame */</span>
<a name="l00057"></a>00057   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.frmFind-&gt;setHidden(<span class="keyword">true</span>);
<a name="l00058"></a>00058  
<a name="l00059"></a>00059   <span class="comment">/* Set the splitter pane sizes so that only the txtBrowser pane expands</span>
<a name="l00060"></a>00060 <span class="comment">   * and set to arbitrary sizes (the minimum sizes will take effect */</span>
<a name="l00061"></a>00061   QList&lt;int&gt; sizes;
<a name="l00062"></a>00062   sizes.append(<a class="code" href="_help_browser_8cpp.html#a78adac6391b0448340c8934f613b9b80">MINIMUM_PANE_SIZE</a>); 
<a name="l00063"></a>00063   sizes.append(<a class="code" href="_help_browser_8cpp.html#a78adac6391b0448340c8934f613b9b80">MINIMUM_PANE_SIZE</a>);
<a name="l00064"></a>00064   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.splitter-&gt;setSizes(sizes);
<a name="l00065"></a>00065   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.splitter-&gt;setStretchFactor(<a class="code" href="_help_browser_8cpp.html#ad5f0fb0475cb984d6201e7d54dadea09">LEFT_PANE_INDEX</a>, <a class="code" href="_help_browser_8cpp.html#a96259801b738aad01e59ff4aec722d77">NO_STRETCH</a>);
<a name="l00066"></a>00066 
<a name="l00067"></a>00067   connect(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents,
<a name="l00068"></a>00068           SIGNAL(<a class="code" href="class_help_browser.html#a8042e2a5c5264ede08b64a9098649861">currentItemChanged</a>(QTreeWidgetItem*,QTreeWidgetItem*)),
<a name="l00069"></a>00069           <span class="keyword">this</span>, SLOT(<a class="code" href="class_help_browser.html#a11c17a4292c52bcb770beebc473cff45">contentsItemChanged</a>(QTreeWidgetItem*,QTreeWidgetItem*)));
<a name="l00070"></a>00070 
<a name="l00071"></a>00071   connect(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeSearch,
<a name="l00072"></a>00072           SIGNAL(<a class="code" href="class_help_browser.html#a8042e2a5c5264ede08b64a9098649861">currentItemChanged</a>(QTreeWidgetItem*,QTreeWidgetItem*)),
<a name="l00073"></a>00073           <span class="keyword">this</span>, SLOT(<a class="code" href="class_help_browser.html#af7debfbeccfbcb956ff2f0681992acce">searchItemChanged</a>(QTreeWidgetItem*,QTreeWidgetItem*)));
<a name="l00074"></a>00074 
<a name="l00075"></a>00075   <span class="comment">/* Connect the navigation actions to their slots */</span>
<a name="l00076"></a>00076   connect(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.actionHome, SIGNAL(triggered()), <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser, SLOT(home()));
<a name="l00077"></a>00077   connect(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.actionBack, SIGNAL(triggered()), <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser, SLOT(backward()));
<a name="l00078"></a>00078   connect(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.actionForward, SIGNAL(triggered()), <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser, SLOT(forward()));
<a name="l00079"></a>00079   connect(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser, SIGNAL(backwardAvailable(<span class="keywordtype">bool</span>)), 
<a name="l00080"></a>00080           <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.actionBack, SLOT(setEnabled(<span class="keywordtype">bool</span>)));
<a name="l00081"></a>00081   connect(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser, SIGNAL(forwardAvailable(<span class="keywordtype">bool</span>)),
<a name="l00082"></a>00082           <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.actionForward, SLOT(setEnabled(<span class="keywordtype">bool</span>)));
<a name="l00083"></a>00083   connect(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.btnFindNext, SIGNAL(clicked()), <span class="keyword">this</span>, SLOT(<a class="code" href="class_help_browser.html#a23f1243d56aca0a036814e1e7c610fe9">findNext</a>()));
<a name="l00084"></a>00084   connect(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.btnFindPrev, SIGNAL(clicked()), <span class="keyword">this</span>, SLOT(<a class="code" href="class_help_browser.html#a79379cc2e363626933337e7f325e3a71">findPrev</a>()));
<a name="l00085"></a>00085   connect(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.btnSearch, SIGNAL(clicked()), <span class="keyword">this</span>, SLOT(<a class="code" href="class_help_browser.html#a9b8fb34d23d43045684e144633039d60">search</a>()));
<a name="l00086"></a>00086   
<a name="l00087"></a>00087   <span class="comment">/* Load the help topics from XML */</span>
<a name="l00088"></a>00088   <a class="code" href="class_help_browser.html#a6c778836327da46249d79d08de1f2bd0">loadContentsFromXml</a>(<span class="stringliteral">&quot;:/help/&quot;</span> + <a class="code" href="class_help_browser.html#ae95bb0c544007699aa90897216d9deda">language</a>() + <span class="stringliteral">&quot;/contents.xml&quot;</span>);
<a name="l00089"></a>00089 
<a name="l00090"></a>00090   <span class="comment">/* Show the first help topic in the tree */</span>
<a name="l00091"></a>00091   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;setCurrentItem(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;topLevelItem(0));
<a name="l00092"></a>00092   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;setItemExpanded(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;topLevelItem(0), <span class="keyword">true</span>);
<a name="l00093"></a>00093 }
<a name="l00094"></a>00094 <span class="comment"></span>
<a name="l00095"></a>00095 <span class="comment">/** Called when the user changes the UI translation. */</span>
<a name="l00096"></a>00096 <span class="keywordtype">void</span>
<a name="l00097"></a><a class="code" href="class_help_browser.html#a42f7ceb51f15ee807eabd01fcf4d1856">00097</a> <a class="code" href="class_help_browser.html#a42f7ceb51f15ee807eabd01fcf4d1856">HelpBrowser::retranslateUi</a>()
<a name="l00098"></a>00098 {
<a name="l00099"></a>00099   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.retranslateUi(<span class="keyword">this</span>);
<a name="l00100"></a>00100   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;clear();
<a name="l00101"></a>00101   <a class="code" href="class_help_browser.html#a6c778836327da46249d79d08de1f2bd0">loadContentsFromXml</a>(<span class="stringliteral">&quot;:/help/&quot;</span> + <a class="code" href="class_help_browser.html#ae95bb0c544007699aa90897216d9deda">language</a>() + <span class="stringliteral">&quot;/contents.xml&quot;</span>);
<a name="l00102"></a>00102   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;setItemExpanded(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;topLevelItem(0), <span class="keyword">true</span>);
<a name="l00103"></a>00103   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;setCurrentItem(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;topLevelItem(0));
<a name="l00104"></a>00104   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;setItemExpanded(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;topLevelItem(0), <span class="keyword">true</span>);
<a name="l00105"></a>00105 }
<a name="l00106"></a>00106 <span class="comment"></span>
<a name="l00107"></a>00107 <span class="comment">/** Returns the language in which help topics should appear, or English</span>
<a name="l00108"></a>00108 <span class="comment"> * (&quot;en&quot;) if no translated help files exist for the current GUI language. */</span>
<a name="l00109"></a>00109 QString
<a name="l00110"></a><a class="code" href="class_help_browser.html#ae95bb0c544007699aa90897216d9deda">00110</a> <a class="code" href="class_help_browser.html#ae95bb0c544007699aa90897216d9deda">HelpBrowser::language</a>()
<a name="l00111"></a>00111 {
<a name="l00112"></a>00112   QString lang = <a class="code" href="class_help_browser.html#ae95bb0c544007699aa90897216d9deda">Vidalia::language</a>();
<a name="l00113"></a>00113   <span class="keywordflow">if</span> (!QDir(<span class="stringliteral">&quot;:/help/&quot;</span> + lang).exists())
<a name="l00114"></a>00114     lang = <span class="stringliteral">&quot;en&quot;</span>;
<a name="l00115"></a>00115   <span class="keywordflow">return</span> lang;
<a name="l00116"></a>00116 }
<a name="l00117"></a>00117 <span class="comment"></span>
<a name="l00118"></a>00118 <span class="comment">/** Load the contents of the help topics tree from the specified XML file. */</span>
<a name="l00119"></a>00119 <span class="keywordtype">void</span>
<a name="l00120"></a><a class="code" href="class_help_browser.html#a6c778836327da46249d79d08de1f2bd0">00120</a> <a class="code" href="class_help_browser.html#a6c778836327da46249d79d08de1f2bd0">HelpBrowser::loadContentsFromXml</a>(QString xmlFile)
<a name="l00121"></a>00121 {
<a name="l00122"></a>00122   QString errorString;
<a name="l00123"></a>00123   QFile file(xmlFile);
<a name="l00124"></a>00124   QDomDocument document;
<a name="l00125"></a>00125   
<a name="l00126"></a>00126   <span class="comment">/* Load the XML contents into the DOM document */</span>
<a name="l00127"></a>00127   <span class="keywordflow">if</span> (!document.setContent(&amp;file, <span class="keyword">true</span>, &amp;errorString)) {
<a name="l00128"></a>00128     <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser-&gt;setPlainText(tr(<span class="stringliteral">&quot;Error Loading Help Contents: &quot;</span>)+errorString);
<a name="l00129"></a>00129     <span class="keywordflow">return</span>;
<a name="l00130"></a>00130   }
<a name="l00131"></a>00131   <span class="comment">/* Load the DOM document contents into the tree view */</span>
<a name="l00132"></a>00132   <span class="keywordflow">if</span> (!<a class="code" href="class_help_browser.html#ad43fd7148c403b9390c30269909f94ec">loadContents</a>(&amp;document, errorString)) {
<a name="l00133"></a>00133     <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser-&gt;setPlainText(tr(<span class="stringliteral">&quot;Error Loading Help Contents: &quot;</span>)+errorString);
<a name="l00134"></a>00134     <span class="keywordflow">return</span>;
<a name="l00135"></a>00135   }
<a name="l00136"></a>00136 }
<a name="l00137"></a>00137 <span class="comment"></span>
<a name="l00138"></a>00138 <span class="comment">/** Load the contents of the help topics tree from the given DOM document. */</span>
<a name="l00139"></a>00139 <span class="keywordtype">bool</span>
<a name="l00140"></a><a class="code" href="class_help_browser.html#ad43fd7148c403b9390c30269909f94ec">00140</a> <a class="code" href="class_help_browser.html#ad43fd7148c403b9390c30269909f94ec">HelpBrowser::loadContents</a>(<span class="keyword">const</span> QDomDocument *document, QString &amp;errorString)
<a name="l00141"></a>00141 {
<a name="l00142"></a>00142   <span class="comment">/* Grab the root document element and make sure it&#39;s the right one */</span>
<a name="l00143"></a>00143   QDomElement root = document-&gt;documentElement();
<a name="l00144"></a>00144   <span class="keywordflow">if</span> (root.tagName() != <a class="code" href="_help_browser_8cpp.html#a201dea4193475b97647d881a5821a9b1">ELEMENT_CONTENTS</a>) {
<a name="l00145"></a>00145     errorString = tr(<span class="stringliteral">&quot;Supplied XML file is not a valid Contents document.&quot;</span>);
<a name="l00146"></a>00146     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00147"></a>00147   }
<a name="l00148"></a>00148   <a class="code" href="class_help_browser.html#a018b0fc1d8783d4ba72725c66c4137d9">_elementList</a> &lt;&lt; root;
<a name="l00149"></a>00149 
<a name="l00150"></a>00150   <span class="comment">/* Create the home item */</span>
<a name="l00151"></a>00151   QTreeWidgetItem *home = <a class="code" href="class_help_browser.html#a6099416803afd9fc7b5ffb0b2ff9c081">createTopicTreeItem</a>(root, 0);
<a name="l00152"></a>00152   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;addTopLevelItem(home);
<a name="l00153"></a>00153   
<a name="l00154"></a>00154   <span class="comment">/* Process all top-level help topics */</span>
<a name="l00155"></a>00155   QDomElement child = root.firstChildElement(<a class="code" href="_help_browser_8cpp.html#aca045e8afe68b3614f2f28ee9aae5951">ELEMENT_TOPIC</a>);
<a name="l00156"></a>00156   <span class="keywordflow">while</span> (!child.isNull()) {
<a name="l00157"></a>00157     <a class="code" href="class_help_browser.html#ae7c004b8d205f92252188758b71d94cb">parseHelpTopic</a>(child, home);
<a name="l00158"></a>00158     child = child.nextSiblingElement(<a class="code" href="_help_browser_8cpp.html#aca045e8afe68b3614f2f28ee9aae5951">ELEMENT_TOPIC</a>);
<a name="l00159"></a>00159   }
<a name="l00160"></a>00160   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00161"></a>00161 }
<a name="l00162"></a>00162 <span class="comment"></span>
<a name="l00163"></a>00163 <span class="comment">/** Parse a Topic element and handle all its children recursively. */</span>
<a name="l00164"></a>00164 <span class="keywordtype">void</span>
<a name="l00165"></a><a class="code" href="class_help_browser.html#ae7c004b8d205f92252188758b71d94cb">00165</a> <a class="code" href="class_help_browser.html#ae7c004b8d205f92252188758b71d94cb">HelpBrowser::parseHelpTopic</a>(<span class="keyword">const</span> QDomElement &amp;topicElement, 
<a name="l00166"></a>00166                             QTreeWidgetItem *parent)
<a name="l00167"></a>00167 {
<a name="l00168"></a>00168   <span class="comment">/* Check that we have a valid help topic */</span>
<a name="l00169"></a>00169   <span class="keywordflow">if</span> (<a class="code" href="class_help_browser.html#af1b92353c4777d628ce882af91d53ccb">isValidTopicElement</a>(topicElement)) {
<a name="l00170"></a>00170     <span class="comment">/* Save this element for later (used for searching) */</span>
<a name="l00171"></a>00171     <a class="code" href="class_help_browser.html#a018b0fc1d8783d4ba72725c66c4137d9">_elementList</a> &lt;&lt; topicElement;
<a name="l00172"></a>00172 
<a name="l00173"></a>00173     <span class="comment">/* Create and populate the new topic item in the tree */</span>
<a name="l00174"></a>00174     QTreeWidgetItem *topic = <a class="code" href="class_help_browser.html#a6099416803afd9fc7b5ffb0b2ff9c081">createTopicTreeItem</a>(topicElement, parent);
<a name="l00175"></a>00175 
<a name="l00176"></a>00176     <span class="comment">/* Process all its child elements */</span>
<a name="l00177"></a>00177     QDomElement child = topicElement.firstChildElement(<a class="code" href="_help_browser_8cpp.html#aca045e8afe68b3614f2f28ee9aae5951">ELEMENT_TOPIC</a>);
<a name="l00178"></a>00178     <span class="keywordflow">while</span> (!child.isNull()) {
<a name="l00179"></a>00179       <a class="code" href="class_help_browser.html#ae7c004b8d205f92252188758b71d94cb">parseHelpTopic</a>(child, topic);
<a name="l00180"></a>00180       child = child.nextSiblingElement(<a class="code" href="_help_browser_8cpp.html#aca045e8afe68b3614f2f28ee9aae5951">ELEMENT_TOPIC</a>);
<a name="l00181"></a>00181     }
<a name="l00182"></a>00182   }
<a name="l00183"></a>00183 }
<a name="l00184"></a>00184 <span class="comment"></span>
<a name="l00185"></a>00185 <span class="comment">/** Returns true if the given Topic element has the necessary attributes. */</span>
<a name="l00186"></a>00186 <span class="keywordtype">bool</span>
<a name="l00187"></a><a class="code" href="class_help_browser.html#af1b92353c4777d628ce882af91d53ccb">00187</a> <a class="code" href="class_help_browser.html#af1b92353c4777d628ce882af91d53ccb">HelpBrowser::isValidTopicElement</a>(<span class="keyword">const</span> QDomElement &amp;topicElement)
<a name="l00188"></a>00188 {
<a name="l00189"></a>00189   <span class="keywordflow">return</span> (topicElement.hasAttribute(<a class="code" href="_help_browser_8cpp.html#a71904a978d540e4b8377e50c17b658f5">ATTRIBUTE_TOPIC_ID</a>) &amp;&amp;
<a name="l00190"></a>00190           topicElement.hasAttribute(<a class="code" href="_help_browser_8cpp.html#a2b3625df4ef764898523321ea749a431">ATTRIBUTE_TOPIC_NAME</a>) &amp;&amp;
<a name="l00191"></a>00191           topicElement.hasAttribute(<a class="code" href="_help_browser_8cpp.html#a13e6db2a236ab75af3856757cdaba077">ATTRIBUTE_TOPIC_HTML</a>));
<a name="l00192"></a>00192 }
<a name="l00193"></a>00193 <span class="comment"></span>
<a name="l00194"></a>00194 <span class="comment">/** Builds a resource path to an html file associated with the given help</span>
<a name="l00195"></a>00195 <span class="comment"> * topic. If the help topic needs an achor, the anchor will be formatted and</span>
<a name="l00196"></a>00196 <span class="comment"> * appended. */</span>
<a name="l00197"></a>00197 QString
<a name="l00198"></a><a class="code" href="class_help_browser.html#a59625e5b0e5adb8afe055a59b2c3e883">00198</a> <a class="code" href="class_help_browser.html#a59625e5b0e5adb8afe055a59b2c3e883">HelpBrowser::getResourcePath</a>(<span class="keyword">const</span> QDomElement &amp;topicElement)
<a name="l00199"></a>00199 {
<a name="l00200"></a>00200   QString link = <a class="code" href="class_help_browser.html#ae95bb0c544007699aa90897216d9deda">language</a>() + <span class="stringliteral">&quot;/&quot;</span> + topicElement.attribute(<a class="code" href="_help_browser_8cpp.html#a13e6db2a236ab75af3856757cdaba077">ATTRIBUTE_TOPIC_HTML</a>);
<a name="l00201"></a>00201   <span class="keywordflow">if</span> (topicElement.hasAttribute(<a class="code" href="_help_browser_8cpp.html#a43af0db43d757b6c3c33128174ce653c">ATTRIBUTE_TOPIC_SECTION</a>)) {
<a name="l00202"></a>00202     link += <span class="stringliteral">&quot;#&quot;</span> + topicElement.attribute(<a class="code" href="_help_browser_8cpp.html#a43af0db43d757b6c3c33128174ce653c">ATTRIBUTE_TOPIC_SECTION</a>);
<a name="l00203"></a>00203   }
<a name="l00204"></a>00204   <span class="keywordflow">return</span> link;
<a name="l00205"></a>00205 }
<a name="l00206"></a>00206 <span class="comment"></span>
<a name="l00207"></a>00207 <span class="comment">/** Creates a new element to be inserted into the topic tree. */</span>
<a name="l00208"></a>00208 QTreeWidgetItem*
<a name="l00209"></a><a class="code" href="class_help_browser.html#a6099416803afd9fc7b5ffb0b2ff9c081">00209</a> <a class="code" href="class_help_browser.html#a6099416803afd9fc7b5ffb0b2ff9c081">HelpBrowser::createTopicTreeItem</a>(<span class="keyword">const</span> QDomElement &amp;topicElement, 
<a name="l00210"></a>00210                                  QTreeWidgetItem *parent)
<a name="l00211"></a>00211 {
<a name="l00212"></a>00212   QTreeWidgetItem *topic = <span class="keyword">new</span> QTreeWidgetItem(parent);
<a name="l00213"></a>00213   QString label = topicElement.attribute(<a class="code" href="_help_browser_8cpp.html#a2b3625df4ef764898523321ea749a431">ATTRIBUTE_TOPIC_NAME</a>);
<a name="l00214"></a>00214 
<a name="l00215"></a>00215   topic-&gt;setText(0, label);
<a name="l00216"></a>00216   topic-&gt;setToolTip(0, label);
<a name="l00217"></a>00217   topic-&gt;setData(0, <a class="code" href="_help_browser_8cpp.html#afd74dc6c7575602c8f7e70d1181e07bd">ROLE_TOPIC_ID</a>, topicElement.attribute(<a class="code" href="_help_browser_8cpp.html#a71904a978d540e4b8377e50c17b658f5">ATTRIBUTE_TOPIC_ID</a>));
<a name="l00218"></a>00218   topic-&gt;setData(0, <a class="code" href="_help_browser_8cpp.html#a5bdeb5f7020e06fc24a24a9aba2f8949">ROLE_TOPIC_QRC_PATH</a>, <a class="code" href="class_help_browser.html#a59625e5b0e5adb8afe055a59b2c3e883">getResourcePath</a>(topicElement));
<a name="l00219"></a>00219 
<a name="l00220"></a>00220   <span class="keywordflow">return</span> topic;
<a name="l00221"></a>00221 }
<a name="l00222"></a>00222 <span class="comment"></span>
<a name="l00223"></a>00223 <span class="comment">/** Called when the user selects a different item in the content topic tree */</span>
<a name="l00224"></a>00224 <span class="keywordtype">void</span>
<a name="l00225"></a><a class="code" href="class_help_browser.html#a11c17a4292c52bcb770beebc473cff45">00225</a> <a class="code" href="class_help_browser.html#a11c17a4292c52bcb770beebc473cff45">HelpBrowser::contentsItemChanged</a>(QTreeWidgetItem *current, QTreeWidgetItem *prev)
<a name="l00226"></a>00226 {
<a name="l00227"></a>00227   QList&lt;QTreeWidgetItem *&gt; selected = <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeSearch-&gt;selectedItems();
<a name="l00228"></a>00228   <span class="comment">/* Deselect the selection in the search tree */</span>
<a name="l00229"></a>00229   <span class="keywordflow">if</span> (!selected.isEmpty()) {
<a name="l00230"></a>00230     <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeSearch-&gt;setItemSelected(selected[0], <span class="keyword">false</span>);
<a name="l00231"></a>00231   }
<a name="l00232"></a>00232   <a class="code" href="class_help_browser.html#a8042e2a5c5264ede08b64a9098649861">currentItemChanged</a>(current, prev);
<a name="l00233"></a>00233 }
<a name="l00234"></a>00234 <span class="comment"></span>
<a name="l00235"></a>00235 <span class="comment">/** Called when the user selects a different item in the content topic tree */</span>
<a name="l00236"></a>00236 <span class="keywordtype">void</span>
<a name="l00237"></a><a class="code" href="class_help_browser.html#af7debfbeccfbcb956ff2f0681992acce">00237</a> <a class="code" href="class_help_browser.html#af7debfbeccfbcb956ff2f0681992acce">HelpBrowser::searchItemChanged</a>(QTreeWidgetItem *current, QTreeWidgetItem *prev)
<a name="l00238"></a>00238 {
<a name="l00239"></a>00239   QList&lt;QTreeWidgetItem *&gt; selected = <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;selectedItems();
<a name="l00240"></a>00240   <span class="comment">/* Deselect the selection in the contents tree */</span>
<a name="l00241"></a>00241   <span class="keywordflow">if</span> (!selected.isEmpty()) {
<a name="l00242"></a>00242     <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;setItemSelected(selected[0], <span class="keyword">false</span>);
<a name="l00243"></a>00243   }
<a name="l00244"></a>00244 
<a name="l00245"></a>00245   <span class="comment">/* Change to selected page */</span>
<a name="l00246"></a>00246   <a class="code" href="class_help_browser.html#a8042e2a5c5264ede08b64a9098649861">currentItemChanged</a>(current, prev);
<a name="l00247"></a>00247 
<a name="l00248"></a>00248   <span class="comment">/* Highlight search phrase */</span>
<a name="l00249"></a>00249   QTextCursor found;
<a name="l00250"></a>00250   QTextDocument::FindFlags flags = QTextDocument::FindWholeWords;
<a name="l00251"></a>00251   found = <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser-&gt;document()-&gt;find(<a class="code" href="class_help_browser.html#a5fc1c44d6f56209cefa90158faf75717">_lastSearch</a>, 0, flags);
<a name="l00252"></a>00252   <span class="keywordflow">if</span> (!found.isNull()) {
<a name="l00253"></a>00253     <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser-&gt;setTextCursor(found);
<a name="l00254"></a>00254   }
<a name="l00255"></a>00255 }
<a name="l00256"></a>00256 <span class="comment"></span>
<a name="l00257"></a>00257 <span class="comment">/** Called when the user selects a different item in the tree. */</span>
<a name="l00258"></a>00258 <span class="keywordtype">void</span>
<a name="l00259"></a><a class="code" href="class_help_browser.html#a8042e2a5c5264ede08b64a9098649861">00259</a> <a class="code" href="class_help_browser.html#a8042e2a5c5264ede08b64a9098649861">HelpBrowser::currentItemChanged</a>(QTreeWidgetItem *current, QTreeWidgetItem *prev)
<a name="l00260"></a>00260 {
<a name="l00261"></a>00261   Q_UNUSED(prev);
<a name="l00262"></a>00262   <span class="keywordflow">if</span> (current) {
<a name="l00263"></a>00263     <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser-&gt;setSource(QUrl(current-&gt;data(0, 
<a name="l00264"></a>00264                                               <a class="code" href="_help_browser_8cpp.html#a5bdeb5f7020e06fc24a24a9aba2f8949">ROLE_TOPIC_QRC_PATH</a>).toString()));
<a name="l00265"></a>00265   }
<a name="l00266"></a>00266   <a class="code" href="class_help_browser.html#a0cc45464b816dcb82a575b64776067d6">_foundBefore</a> = <span class="keyword">false</span>;
<a name="l00267"></a>00267 }
<a name="l00268"></a>00268 <span class="comment"></span>
<a name="l00269"></a>00269 <span class="comment">/** Searches for a topic in the topic tree. Returns a pointer to that topics</span>
<a name="l00270"></a>00270 <span class="comment"> * item in the topic tree if it is found, 0 otherwise. */</span>
<a name="l00271"></a>00271 QTreeWidgetItem*
<a name="l00272"></a><a class="code" href="class_help_browser.html#a75fafd717174c766ff9c1a34bfcbe834">00272</a> <a class="code" href="class_help_browser.html#a75fafd717174c766ff9c1a34bfcbe834">HelpBrowser::findTopicItem</a>(QTreeWidgetItem *startItem, QString topic)
<a name="l00273"></a>00273 {
<a name="l00274"></a>00274   <span class="comment">/* If startItem is null, then we don&#39;t know where to start searching. */</span>
<a name="l00275"></a>00275   <span class="keywordflow">if</span> (!startItem)
<a name="l00276"></a>00276     <span class="keywordflow">return</span> 0;
<a name="l00277"></a>00277 
<a name="l00278"></a>00278   <span class="comment">/* Parse the first subtopic in the topic id. */</span>
<a name="l00279"></a>00279   QString subtopic = topic.mid(0, topic.indexOf(<span class="stringliteral">&quot;.&quot;</span>)).toLower();
<a name="l00280"></a>00280 
<a name="l00281"></a>00281   <span class="comment">/* Search through all children of startItem and look for a subtopic match */</span>
<a name="l00282"></a>00282   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a> = 0; <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a> &lt; startItem-&gt;childCount(); <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>++) {
<a name="l00283"></a>00283     QTreeWidgetItem *item = startItem-&gt;child(<a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>);
<a name="l00284"></a>00284     
<a name="l00285"></a>00285     <span class="keywordflow">if</span> (subtopic == item-&gt;data(0, <a class="code" href="_help_browser_8cpp.html#afd74dc6c7575602c8f7e70d1181e07bd">ROLE_TOPIC_ID</a>).toString().toLower()) {
<a name="l00286"></a>00286       <span class="comment">/* Found a subtopic match, so expand this item */</span>
<a name="l00287"></a>00287       <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;setItemExpanded(item, <span class="keyword">true</span>);
<a name="l00288"></a>00288       <span class="keywordflow">if</span> (!topic.contains(<span class="stringliteral">&quot;.&quot;</span>)) {
<a name="l00289"></a>00289         <span class="comment">/* Found the exact topic */</span>
<a name="l00290"></a>00290         <span class="keywordflow">return</span> item;
<a name="l00291"></a>00291       }
<a name="l00292"></a>00292       <span class="comment">/* Search recursively for the next subtopic */</span>
<a name="l00293"></a>00293       <span class="keywordflow">return</span> <a class="code" href="class_help_browser.html#a75fafd717174c766ff9c1a34bfcbe834">findTopicItem</a>(item, topic.mid(topic.indexOf(<span class="stringliteral">&quot;.&quot;</span>)+1));
<a name="l00294"></a>00294     }
<a name="l00295"></a>00295   }
<a name="l00296"></a>00296   <span class="keywordflow">return</span> 0;
<a name="l00297"></a>00297 }
<a name="l00298"></a>00298 <span class="comment"></span>
<a name="l00299"></a>00299 <span class="comment">/** Shows the help browser. If a sepcified topic was given, then search for</span>
<a name="l00300"></a>00300 <span class="comment"> * that topic&#39;s ID (e.g., &quot;log.basic&quot;) and display the appropriate page. */</span>
<a name="l00301"></a>00301 <span class="keywordtype">void</span>
<a name="l00302"></a><a class="code" href="class_help_browser.html#a36d2642ed0cfb1584ae903de2f4892ae">00302</a> <a class="code" href="class_help_browser.html#a36d2642ed0cfb1584ae903de2f4892ae">HelpBrowser::showTopic</a>(QString topic)
<a name="l00303"></a>00303 {
<a name="l00304"></a>00304   <span class="comment">/* Search for the topic in the contents tree */</span>
<a name="l00305"></a>00305   QTreeWidgetItem *item =
<a name="l00306"></a>00306     <a class="code" href="class_help_browser.html#a75fafd717174c766ff9c1a34bfcbe834">findTopicItem</a>(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;topLevelItem(0), topic);
<a name="l00307"></a>00307   QTreeWidgetItem *selected = 0;
<a name="l00308"></a>00308 
<a name="l00309"></a>00309   <span class="keywordflow">if</span> (item) {
<a name="l00310"></a>00310     <span class="comment">/* Item was found, so show its location in the hierarchy and select its</span>
<a name="l00311"></a>00311 <span class="comment">     * tree item. */</span>
<a name="l00312"></a>00312     <span class="keywordflow">if</span> (<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;selectedItems().size()) {
<a name="l00313"></a>00313       selected = <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;selectedItems()[0];
<a name="l00314"></a>00314       <span class="keywordflow">if</span> (selected)
<a name="l00315"></a>00315         <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;setItemSelected(selected, <span class="keyword">false</span>);
<a name="l00316"></a>00316     }
<a name="l00317"></a>00317     <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;setItemExpanded(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;topLevelItem(0), <span class="keyword">true</span>);
<a name="l00318"></a>00318     <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeContents-&gt;setItemSelected(item, <span class="keyword">true</span>);
<a name="l00319"></a>00319     <a class="code" href="class_help_browser.html#a8042e2a5c5264ede08b64a9098649861">currentItemChanged</a>(item, selected);
<a name="l00320"></a>00320   }
<a name="l00321"></a>00321 }
<a name="l00322"></a>00322 <span class="comment"></span>
<a name="l00323"></a>00323 <span class="comment">/** Called when the user clicks &quot;Find Next&quot;. */</span>
<a name="l00324"></a>00324 <span class="keywordtype">void</span>
<a name="l00325"></a><a class="code" href="class_help_browser.html#a23f1243d56aca0a036814e1e7c610fe9">00325</a> <a class="code" href="class_help_browser.html#a23f1243d56aca0a036814e1e7c610fe9">HelpBrowser::findNext</a>()
<a name="l00326"></a>00326 {
<a name="l00327"></a>00327   <a class="code" href="class_help_browser.html#ad57653be8683ad2b94f973d31ad2bf82">find</a>(<span class="keyword">true</span>);
<a name="l00328"></a>00328 }
<a name="l00329"></a>00329 <span class="comment"></span>
<a name="l00330"></a>00330 <span class="comment">/** Called when the user clicks &quot;Find Previous&quot;. */</span>
<a name="l00331"></a>00331 <span class="keywordtype">void</span>
<a name="l00332"></a><a class="code" href="class_help_browser.html#a79379cc2e363626933337e7f325e3a71">00332</a> <a class="code" href="class_help_browser.html#a79379cc2e363626933337e7f325e3a71">HelpBrowser::findPrev</a>()
<a name="l00333"></a>00333 {
<a name="l00334"></a>00334   <a class="code" href="class_help_browser.html#ad57653be8683ad2b94f973d31ad2bf82">find</a>(<span class="keyword">false</span>);
<a name="l00335"></a>00335 }
<a name="l00336"></a>00336 <span class="comment"></span>
<a name="l00337"></a>00337 <span class="comment">/** Searches the current page for the phrase in the Find box.</span>
<a name="l00338"></a>00338 <span class="comment"> *  Highlights the first instance found in the document</span>
<a name="l00339"></a>00339 <span class="comment"> *  \param forward true search forward if true, backward if false</span>
<a name="l00340"></a>00340 <span class="comment"> **/</span>
<a name="l00341"></a>00341 <span class="keywordtype">void</span>
<a name="l00342"></a><a class="code" href="class_help_browser.html#ad57653be8683ad2b94f973d31ad2bf82">00342</a> <a class="code" href="class_help_browser.html#ad57653be8683ad2b94f973d31ad2bf82">HelpBrowser::find</a>(<span class="keywordtype">bool</span> forward)
<a name="l00343"></a>00343 {
<a name="l00344"></a>00344   <span class="comment">/* Don&#39;t bother searching if there is no search phrase */</span>
<a name="l00345"></a>00345   <span class="keywordflow">if</span> (<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.lineFind-&gt;text().isEmpty()) {
<a name="l00346"></a>00346     <span class="keywordflow">return</span>;
<a name="l00347"></a>00347   }
<a name="l00348"></a>00348   
<a name="l00349"></a>00349   QTextDocument::FindFlags flags = 0;
<a name="l00350"></a>00350   QTextCursor cursor = <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser-&gt;textCursor();
<a name="l00351"></a>00351   QString searchPhrase = <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.lineFind-&gt;text();
<a name="l00352"></a>00352   
<a name="l00353"></a>00353   <span class="comment">/* Clear status bar */</span>
<a name="l00354"></a>00354   this-&gt;statusBar()-&gt;clearMessage();
<a name="l00355"></a>00355   
<a name="l00356"></a>00356   <span class="comment">/* Set search direction and other flags */</span>
<a name="l00357"></a>00357   <span class="keywordflow">if</span> (!forward) {
<a name="l00358"></a>00358     flags |= QTextDocument::FindBackward;
<a name="l00359"></a>00359   }
<a name="l00360"></a>00360   <span class="keywordflow">if</span> (<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.chkbxMatchCase-&gt;isChecked()) {
<a name="l00361"></a>00361     flags |= QTextDocument::FindCaseSensitively;
<a name="l00362"></a>00362   }
<a name="l00363"></a>00363   <span class="keywordflow">if</span> (<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.chkbxWholePhrase-&gt;isChecked()) {
<a name="l00364"></a>00364     flags |= QTextDocument::FindWholeWords;
<a name="l00365"></a>00365   }
<a name="l00366"></a>00366   
<a name="l00367"></a>00367   <span class="comment">/* Check if search phrase is the same as the previous */</span>
<a name="l00368"></a>00368   <span class="keywordflow">if</span> (searchPhrase != <a class="code" href="class_help_browser.html#a1e7afbaec5cf48534a92f1cdaec2f100">_lastFind</a>) {
<a name="l00369"></a>00369     <a class="code" href="class_help_browser.html#a0cc45464b816dcb82a575b64776067d6">_foundBefore</a> = <span class="keyword">false</span>;
<a name="l00370"></a>00370   }
<a name="l00371"></a>00371   <a class="code" href="class_help_browser.html#a1e7afbaec5cf48534a92f1cdaec2f100">_lastFind</a> = searchPhrase;
<a name="l00372"></a>00372   
<a name="l00373"></a>00373   <span class="comment">/* Set the cursor to the appropriate start location if necessary */</span>
<a name="l00374"></a>00374   <span class="keywordflow">if</span> (!cursor.hasSelection()) {
<a name="l00375"></a>00375     <span class="keywordflow">if</span> (forward) {
<a name="l00376"></a>00376       cursor.movePosition(QTextCursor::Start);
<a name="l00377"></a>00377     } <span class="keywordflow">else</span> {
<a name="l00378"></a>00378       cursor.movePosition(QTextCursor::End);
<a name="l00379"></a>00379     }
<a name="l00380"></a>00380     <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser-&gt;setTextCursor(cursor);
<a name="l00381"></a>00381   }
<a name="l00382"></a>00382 
<a name="l00383"></a>00383   <span class="comment">/* Search the page */</span>
<a name="l00384"></a>00384   QTextCursor found;
<a name="l00385"></a>00385   found = <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser-&gt;document()-&gt;find(searchPhrase, cursor, flags);
<a name="l00386"></a>00386   
<a name="l00387"></a>00387   <span class="comment">/* If found, move the cursor to the location */</span>
<a name="l00388"></a>00388   <span class="keywordflow">if</span> (!found.isNull()) {
<a name="l00389"></a>00389     <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.txtBrowser-&gt;setTextCursor(found);
<a name="l00390"></a>00390   <span class="comment">/* If not found, display appropriate error message */</span>
<a name="l00391"></a>00391   } <span class="keywordflow">else</span> {
<a name="l00392"></a>00392     <span class="keywordflow">if</span> (<a class="code" href="class_help_browser.html#a0cc45464b816dcb82a575b64776067d6">_foundBefore</a>) {
<a name="l00393"></a>00393       <span class="keywordflow">if</span> (forward) 
<a name="l00394"></a>00394         this-&gt;statusBar()-&gt;showMessage(tr(<span class="stringliteral">&quot;Search reached end of document&quot;</span>));
<a name="l00395"></a>00395       <span class="keywordflow">else</span> 
<a name="l00396"></a>00396         this-&gt;statusBar()-&gt;showMessage(tr(<span class="stringliteral">&quot;Search reached start of document&quot;</span>));
<a name="l00397"></a>00397     } <span class="keywordflow">else</span> {
<a name="l00398"></a>00398       this-&gt;statusBar()-&gt;showMessage(tr(<span class="stringliteral">&quot;Text not found in document&quot;</span>));
<a name="l00399"></a>00399     }
<a name="l00400"></a>00400   }
<a name="l00401"></a>00401   
<a name="l00402"></a>00402   <span class="comment">/* Even if not found this time, may have been found previously */</span>
<a name="l00403"></a>00403   <a class="code" href="class_help_browser.html#a0cc45464b816dcb82a575b64776067d6">_foundBefore</a> |= !found.isNull();
<a name="l00404"></a>00404 }
<a name="l00405"></a>00405  <span class="comment"></span>
<a name="l00406"></a>00406 <span class="comment">/** Searches all help pages for the phrase the Search box.</span>
<a name="l00407"></a>00407 <span class="comment"> *  Fills treeSearch with documents containing matches and sets the</span>
<a name="l00408"></a>00408 <span class="comment"> *  status bar text appropriately.</span>
<a name="l00409"></a>00409 <span class="comment"> */</span>
<a name="l00410"></a>00410 <span class="keywordtype">void</span>
<a name="l00411"></a><a class="code" href="class_help_browser.html#a9b8fb34d23d43045684e144633039d60">00411</a> <a class="code" href="class_help_browser.html#a9b8fb34d23d43045684e144633039d60">HelpBrowser::search</a>()
<a name="l00412"></a>00412 {
<a name="l00413"></a>00413   <span class="comment">/* Clear the list */</span>
<a name="l00414"></a>00414   <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeSearch-&gt;clear();
<a name="l00415"></a>00415   
<a name="l00416"></a>00416   <span class="comment">/* Don&#39;t search if invalid document or blank search phrase */</span>
<a name="l00417"></a>00417   <span class="keywordflow">if</span> (<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.lineSearch-&gt;text().isEmpty()) {
<a name="l00418"></a>00418     <span class="keywordflow">return</span>;
<a name="l00419"></a>00419   }
<a name="l00420"></a>00420     
<a name="l00421"></a>00421   <a class="code" href="class_help_text_browser.html">HelpTextBrowser</a> browser;
<a name="l00422"></a>00422   QTextCursor found;
<a name="l00423"></a>00423   QTextDocument::FindFlags flags = QTextDocument::FindWholeWords;
<a name="l00424"></a>00424 
<a name="l00425"></a>00425   <a class="code" href="class_help_browser.html#a5fc1c44d6f56209cefa90158faf75717">_lastSearch</a> = <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.lineSearch-&gt;text();
<a name="l00426"></a>00426 
<a name="l00427"></a>00427   <span class="comment">/* Search through all the pages looking for the phrase */</span>
<a name="l00428"></a>00428   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>=0; <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a> &lt; <a class="code" href="class_help_browser.html#a018b0fc1d8783d4ba72725c66c4137d9">_elementList</a>.size(); ++<a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>) {
<a name="l00429"></a>00429     <span class="comment">/* Load page data into browser */</span>
<a name="l00430"></a>00430     browser.<a class="code" href="class_help_text_browser.html#aefe360c4596be3dde4bbc66b82802551">setSource</a>(QUrl(<a class="code" href="class_help_browser.html#a59625e5b0e5adb8afe055a59b2c3e883">getResourcePath</a>(<a class="code" href="class_help_browser.html#a018b0fc1d8783d4ba72725c66c4137d9">_elementList</a>[<a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>])));
<a name="l00431"></a>00431       
<a name="l00432"></a>00432     <span class="comment">/* Search current document */</span>
<a name="l00433"></a>00433     found = browser.document()-&gt;find(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.lineSearch-&gt;text(), 0, flags);
<a name="l00434"></a>00434 
<a name="l00435"></a>00435     <span class="comment">/* If found, add page to tree */</span>
<a name="l00436"></a>00436     <span class="keywordflow">if</span> (!found.isNull()) {
<a name="l00437"></a>00437       <a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeSearch-&gt;addTopLevelItem(<a class="code" href="class_help_browser.html#a6099416803afd9fc7b5ffb0b2ff9c081">createTopicTreeItem</a>(<a class="code" href="class_help_browser.html#a018b0fc1d8783d4ba72725c66c4137d9">_elementList</a>[i], 0));
<a name="l00438"></a>00438     }
<a name="l00439"></a>00439   }
<a name="l00440"></a>00440 
<a name="l00441"></a>00441   <span class="comment">/* Set the status bar text */</span>
<a name="l00442"></a>00442   this-&gt;statusBar()-&gt;showMessage(tr(<span class="stringliteral">&quot;Found %1 results&quot;</span>)
<a name="l00443"></a>00443                                 .arg(<a class="code" href="class_help_browser.html#a3c0d594bacec354376ba1a3b1cbf6545">ui</a>.treeSearch-&gt;topLevelItemCount()));
<a name="l00444"></a>00444 }
<a name="l00445"></a>00445 <span class="comment"></span>
<a name="l00446"></a>00446 <span class="comment">/** Overrides the default show method */</span>
<a name="l00447"></a>00447 <span class="keywordtype">void</span>
<a name="l00448"></a><a class="code" href="class_help_browser.html#aec97ccd1c00a10949bb485ed312cbe81">00448</a> <a class="code" href="class_vidalia_window.html#a58aa3cff3f3cd54497431cef227df8b6">HelpBrowser::showWindow</a>(QString topic)
<a name="l00449"></a>00449 {
<a name="l00450"></a>00450   
<a name="l00451"></a>00451   <span class="comment">/* Bring the window to the top */</span>
<a name="l00452"></a>00452   <a class="code" href="class_vidalia_window.html#a58aa3cff3f3cd54497431cef227df8b6">VidaliaWindow::showWindow</a>();
<a name="l00453"></a>00453 
<a name="l00454"></a>00454   <span class="comment">/* If a topic was specified, then go ahead and display it. */</span>
<a name="l00455"></a>00455   <span class="keywordflow">if</span> (!topic.isEmpty()) {
<a name="l00456"></a>00456     <a class="code" href="class_help_browser.html#a36d2642ed0cfb1584ae903de2f4892ae">showTopic</a>(topic);
<a name="l00457"></a>00457   }
<a name="l00458"></a>00458 }
<a name="l00459"></a>00459 
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon Aug 30 22:58:54 2010 for Vidalia by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>