Rev 1693 | Rev 2008 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
564 | cbradney | 1 | /*************************************************************************** |
2 | * Copyright (C) 2004 by Craig Bradney * |
||
3 | * cbradney@zip.com.au * |
||
4 | * * |
||
5 | * This program is free software; you can redistribute it and/or modify * |
||
6 | * it under the terms of the GNU General Public License as published by * |
||
7 | * the Free Software Foundation; either version 2 of the License, or * |
||
8 | * (at your option) any later version. * |
||
9 | * * |
||
10 | * This program is distributed in the hope that it will be useful, * |
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
13 | * GNU General Public License for more details. * |
||
14 | * * |
||
15 | * You should have received a copy of the GNU General Public License * |
||
16 | * along with this program; if not, write to the * |
||
17 | * Free Software Foundation, Inc., * |
||
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
19 | ***************************************************************************/ |
||
560 | cbradney | 20 | |
3 | paul | 21 | #include "helpbrowser.h" |
22 | #include "helpbrowser.moc" |
||
560 | cbradney | 23 | |
3 | paul | 24 | #include <qvariant.h> |
560 | cbradney | 25 | #include <qpushbutton.h> |
26 | #include <qtabwidget.h> |
||
27 | #include <qwidget.h> |
||
28 | #include <qheader.h> |
||
29 | #include <qlistview.h> |
||
30 | #include <qtextbrowser.h> |
||
31 | #include <qlayout.h> |
||
3 | paul | 32 | #include <qtooltip.h> |
560 | cbradney | 33 | #include <qtoolbutton.h> |
34 | #include <qwhatsthis.h> |
||
3 | paul | 35 | #include <qimage.h> |
36 | #include <qpixmap.h> |
||
560 | cbradney | 37 | #include <qpopupmenu.h> |
38 | #include <qfileinfo.h> |
||
3 | paul | 39 | #include <qtextcodec.h> |
560 | cbradney | 40 | #include <qdom.h> |
1033 | cbradney | 41 | #include <qdir.h> |
786 | cbradney | 42 | #include <qsplitter.h> |
1144 | cbradney | 43 | #include <qmime.h> |
2006 | subik | 44 | #include <qlabel.h> |
45 | #include <qlineedit.h> |
||
46 | #include <qaccel.h> |
||
47 | #include <qinputdialog.h> |
||
128 | Franz | 48 | |
1693 | craig | 49 | #include "scpaths.h" |
50 | |||
617 | cbradney | 51 | #ifdef _MSC_VER |
1033 | cbradney | 52 | #if (_MSC_VER >= 1200) |
53 | #include "win-config.h" |
||
54 | #endif |
||
128 | Franz | 55 | #else |
1033 | cbradney | 56 | #include "config.h" |
128 | Franz | 57 | #endif |
58 | |||
3 | paul | 59 | extern QPixmap loadIcon(QString nam); |
60 | |||
560 | cbradney | 61 | |
2006 | subik | 62 | HelpBrowser::HelpBrowser( QWidget* parent, QString /*caption*/, QString guiLanguage, QString jumpToSection, QString jumpToFile) |
564 | cbradney | 63 | : QWidget( parent, "Help", WType_TopLevel | WDestructiveClose ) |
3 | paul | 64 | { |
560 | cbradney | 65 | QString fileName; |
564 | cbradney | 66 | mHistory.clear(); |
67 | struct histd his; |
||
1092 | cbradney | 68 | language = guiLanguage=="" ? "en" : guiLanguage.left(2); |
2006 | subik | 69 | helpBrowsermainLayout = new QVBoxLayout( this); |
564 | cbradney | 70 | buttonLayout = new QHBoxLayout; |
71 | buttonLayout->setSpacing( 6 ); |
||
72 | buttonLayout->setMargin( 2 ); |
||
3 | paul | 73 | |
564 | cbradney | 74 | homeButton = new QToolButton( this, "homeButton" ); |
75 | homeButton->setText( "" ); |
||
76 | homeButton->setPixmap(loadIcon("gohome.png")); |
||
786 | cbradney | 77 | homeButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed, homeButton->sizePolicy().hasHeightForWidth() ) ); |
564 | cbradney | 78 | buttonLayout->addWidget( homeButton ); |
3 | paul | 79 | |
564 | cbradney | 80 | histMenu = new QPopupMenu( this ); |
81 | backButton = new QToolButton( this, "backButton" ); |
||
82 | backButton->setPixmap(loadIcon("back.png")); |
||
786 | cbradney | 83 | backButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed, backButton->sizePolicy().hasHeightForWidth() ) ); |
564 | cbradney | 84 | backButton->setPopup(histMenu); |
85 | backButton->setPopupDelay(0); |
||
86 | buttonLayout->addWidget( backButton ); |
||
3 | paul | 87 | |
564 | cbradney | 88 | forwButton = new QToolButton( this, "forwButton" ); |
89 | forwButton->setPixmap(loadIcon("forward.png")); |
||
786 | cbradney | 90 | forwButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed, forwButton->sizePolicy().hasHeightForWidth() ) ); |
564 | cbradney | 91 | buttonLayout->addWidget( forwButton ); |
92 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
||
93 | buttonLayout->addItem( spacer ); |
||
560 | cbradney | 94 | helpBrowsermainLayout->addLayout( buttonLayout ); |
95 | |||
2006 | subik | 96 | helpBrowserLayout = new QHBoxLayout; |
786 | cbradney | 97 | splitter = new QSplitter(this, "splitter"); |
98 | splitter->setChildrenCollapsible( false ); |
||
99 | helpBrowserLayout->addWidget( splitter ); |
||
560 | cbradney | 100 | |
786 | cbradney | 101 | tabWidget = new QTabWidget( splitter, "tabWidget" ); |
102 | //tabWidget = new QTabWidget( this, "tabWidget" ); |
||
103 | splitter->setResizeMode(tabWidget, QSplitter::Stretch ); |
||
104 | tabWidget->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Expanding, false) ); |
||
564 | cbradney | 105 | tabContents = new QWidget( tabWidget, "tabContents" ); |
2006 | subik | 106 | tabLayout = new QHBoxLayout( tabContents, 11, 6, "tabLayout"); |
560 | cbradney | 107 | |
564 | cbradney | 108 | listView = new QListView( tabContents, "listView" ); |
109 | listView->addColumn( tr( "Contents" ) ); |
||
1097 | cbradney | 110 | listView->addColumn( tr( "Link" ) , 0 ); |
111 | // listView->addColumn( tr( "Link" ) ); |
||
112 | listView->setColumnWidthMode( 0, QListView::Maximum ); |
||
113 | listView->setColumnWidthMode( 1, QListView::Manual ); |
||
560 | cbradney | 114 | listView->setSorting(-1,-1); |
115 | listView->setRootIsDecorated( true ); |
||
116 | listView->setSelectionMode(QListView::Single); |
||
117 | listView->setDefaultRenameAction(QListView::Reject); |
||
118 | listView->clear(); |
||
564 | cbradney | 119 | tabLayout->addWidget( listView ); |
2006 | subik | 120 | |
121 | tabWidget->insertTab( tabContents, tr("&Contents") ); |
||
786 | cbradney | 122 | //helpBrowserLayout->addWidget( tabWidget ); |
560 | cbradney | 123 | |
2006 | subik | 124 | // searching |
125 | tabSearching = new QWidget(tabWidget, "tabSearching"); |
||
126 | searchingMainLayout = new QVBoxLayout(tabSearching, 11, 6, "searchingMainLayout"); |
||
127 | searchingButtonLayout = new QHBoxLayout; |
||
128 | searchingEdit = new QLineEdit(tabSearching, "searchingEdit"); |
||
129 | searchingButton = new QPushButton(tabSearching, "searchingButton"); |
||
130 | searchingButton->setText(tr("&Search")); |
||
131 | searchingButtonLayout->addWidget(searchingEdit); |
||
132 | searchingButtonLayout->addWidget(searchingButton); |
||
133 | searchingMainLayout->addLayout(searchingButtonLayout); |
||
134 | searchingView = new QListView(tabSearching, "searchingView"); |
||
135 | searchingView->addColumn( tr( "Contents" ) ); |
||
136 | searchingView->addColumn( tr( "Link" ) , 0 ); |
||
137 | searchingView->setColumnWidthMode( 0, QListView::Maximum ); |
||
138 | searchingView->setColumnWidthMode( 1, QListView::Manual ); |
||
139 | searchingView->setSorting(-1,-1); |
||
140 | searchingView->setRootIsDecorated( true ); |
||
141 | searchingView->setSelectionMode(QListView::Single); |
||
142 | searchingView->setDefaultRenameAction(QListView::Reject); |
||
143 | searchingView->clear(); |
||
144 | searchingMainLayout->addWidget(searchingView); |
||
145 | tabWidget->insertTab(tabSearching, tr("S&earch")); |
||
146 | |||
786 | cbradney | 147 | textBrowser = new QTextBrowser( splitter, "textBrowser" ); |
148 | splitter->setResizeMode(textBrowser, QSplitter::Stretch); |
||
149 | //textBrowser = new QTextBrowser( this, "textBrowser" ); |
||
150 | textBrowser->setSizePolicy( QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Expanding, false ) ); |
||
564 | cbradney | 151 | textBrowser->setFrameShape( QTextBrowser::StyledPanel ); |
1144 | cbradney | 152 | QMimeSourceFactory *textBrowserMSF=textBrowser->mimeSourceFactory(); |
153 | textBrowserMSF->setExtensionType("html", "text/html;charset=UTF-8"); |
||
786 | cbradney | 154 | //helpBrowserLayout->addWidget( textBrowser ); |
564 | cbradney | 155 | helpBrowsermainLayout->addLayout( helpBrowserLayout ); |
560 | cbradney | 156 | |
564 | cbradney | 157 | languageChange(); |
158 | resize( QSize(602, 491).expandedTo(minimumSizeHint()) ); |
||
159 | clearWState( WState_Polished ); |
||
1092 | cbradney | 160 | loadMenu(); |
560 | cbradney | 161 | listView->header()->hide(); |
2006 | subik | 162 | searchingView->header()->hide(); |
1092 | cbradney | 163 | jumpToHelpSection(jumpToSection, jumpToFile ); |
560 | cbradney | 164 | |
2006 | subik | 165 | QAccel *a = new QAccel( this, "a"); |
166 | a->connectItem(a->insertItem(QAccel::stringToKey(tr("Ctrl+F"))), this, SLOT(find())); |
||
167 | a->connectItem(a->insertItem(QAccel::stringToKey(tr("F3"))), this, SLOT(findNext())); |
||
168 | |||
560 | cbradney | 169 | connect( homeButton, SIGNAL( clicked() ), textBrowser, SLOT( home() ) ); |
170 | connect( forwButton, SIGNAL( clicked() ), textBrowser, SLOT( forward() ) ); |
||
171 | connect( backButton, SIGNAL( clicked() ), textBrowser, SLOT( backward() ) ); |
||
564 | cbradney | 172 | connect( histMenu, SIGNAL(activated(int)), this, SLOT(histChosen(int))); |
173 | connect( listView, SIGNAL(clicked( QListViewItem *)), this, SLOT(itemSelected( QListViewItem *))); |
||
2006 | subik | 174 | // searching |
175 | connect(searchingView, SIGNAL(clicked( QListViewItem *)), this, SLOT(itemSearchSelected(QListViewItem *))); |
||
176 | connect(searchingButton, SIGNAL(clicked()), this, SLOT(searchingButton_clicked())); |
||
560 | cbradney | 177 | } |
178 | |||
179 | HelpBrowser::~HelpBrowser() |
||
180 | { |
||
564 | cbradney | 181 | // no need to delete child widgets, Qt does it all for us |
560 | cbradney | 182 | } |
183 | |||
184 | void HelpBrowser::languageChange() |
||
185 | { |
||
564 | cbradney | 186 | setCaption( tr( "Scribus Online Help" ) ); |
187 | listView->header()->setLabel( 0, tr( "Contents" ) ); |
||
188 | listView->clear(); |
||
560 | cbradney | 189 | |
2006 | subik | 190 | tabWidget->changeTab( tabContents, tr( "&Contents" ) ); |
560 | cbradney | 191 | } |
192 | |||
193 | |||
194 | void HelpBrowser::sourceChanged(const QString& url) |
||
195 | { |
||
564 | cbradney | 196 | bool inList = false; |
197 | struct histd his; |
||
198 | QString title = ""; |
||
199 | title = textBrowser->documentTitle(); |
||
200 | if (title == "") |
||
201 | title = url; |
||
786 | cbradney | 202 | for (QMap<int, histd>::Iterator it = mHistory.begin(); it != mHistory.end(); ++it) |
564 | cbradney | 203 | { |
204 | if (it.data().Title == title) |
||
205 | inList = true; |
||
206 | } |
||
207 | if (!inList) |
||
208 | { |
||
209 | his.Title = title; |
||
210 | his.Url = url; |
||
211 | mHistory[histMenu->insertItem(title)] = his; |
||
212 | } |
||
213 | if (mHistory.count() > 15) |
||
214 | { |
||
215 | int itk = histMenu->idAt(0); |
||
216 | mHistory.remove(itk); |
||
217 | histMenu->removeItem(itk); |
||
218 | } |
||
560 | cbradney | 219 | } |
220 | |||
221 | void HelpBrowser::histChosen(int i) |
||
222 | { |
||
564 | cbradney | 223 | if (mHistory.contains(i)) |
224 | textBrowser->setSource(mHistory[i].Url); |
||
560 | cbradney | 225 | } |
226 | |||
1092 | cbradney | 227 | void HelpBrowser::jumpToHelpSection(QString jumpToSection, QString jumpToFile) |
560 | cbradney | 228 | { |
229 | QString toLoad; |
||
1141 | cbradney | 230 | bool noDocs=false; |
560 | cbradney | 231 | |
2006 | subik | 232 | if (jumpToFile=="") |
564 | cbradney | 233 | { |
1693 | craig | 234 | QString pfad = ScPaths::instance().docDir(); |
1092 | cbradney | 235 | toLoad = pfad + language + "/"; //clean this later to handle 5 char locales |
2006 | subik | 236 | if (jumpToSection=="") |
564 | cbradney | 237 | { |
1141 | cbradney | 238 | if (listView->firstChild()) |
239 | { |
||
240 | toLoad+=listView->firstChild()->text(1); |
||
241 | listView->setSelected( listView->firstChild(), true ); |
||
242 | } |
||
243 | else |
||
244 | noDocs=true; |
||
205 | Franz | 245 | } |
2006 | subik | 246 | else if (jumpToSection=="scripter") |
564 | cbradney | 247 | { |
560 | cbradney | 248 | toLoad+="scripter1.html"; |
249 | QListViewItemIterator it(listView); |
||
2006 | subik | 250 | while (it.current()) |
564 | cbradney | 251 | { |
560 | cbradney | 252 | if (it.current()->text(1)=="scripter1.html") |
253 | listView->setSelected( it.current(), true ); |
||
254 | if (it.current()->text(1)=="developers.html") |
||
255 | it.current()->setOpen( true ); |
||
256 | ++it; |
||
257 | } |
||
258 | } |
||
205 | Franz | 259 | } |
560 | cbradney | 260 | else |
564 | cbradney | 261 | toLoad=jumpToFile; |
3 | paul | 262 | |
1141 | cbradney | 263 | if (!noDocs) |
264 | loadHelp(toLoad); |
||
265 | else |
||
266 | textBrowser->setText("<h2>"+ tr("Sorry, no manual available! Please see: http://docs.scribus.net for updated docs\nand www.scribus.net for downloads.")+"</h2>"); |
||
3 | paul | 267 | } |
268 | |||
560 | cbradney | 269 | void HelpBrowser::loadHelp(QString filename) |
68 | Franz | 270 | { |
75 | Franz | 271 | struct histd his; |
564 | cbradney | 272 | bool Avail = true; |
560 | cbradney | 273 | QString toLoad; |
564 | cbradney | 274 | QFileInfo fi; |
275 | fi = QFileInfo(filename); |
||
1100 | cbradney | 276 | if (fi.fileName().length()>0) |
564 | cbradney | 277 | { |
1100 | cbradney | 278 | if (fi.exists()) |
279 | toLoad=filename; |
||
2006 | subik | 280 | else |
564 | cbradney | 281 | { |
1693 | craig | 282 | QString pfad = ScPaths::instance().docDir(); |
1100 | cbradney | 283 | toLoad = pfad + "en/index.html"; |
284 | language="en"; |
||
285 | fi = QFileInfo(toLoad); |
||
286 | if (!fi.exists()) |
||
287 | { |
||
288 | textBrowser->setText("<h2>"+ tr("Sorry, no manual available! Please see: http://docs.scribus.net for updated docs\nand www.scribus.net for downloads.")+"</h2>"); |
||
289 | Avail = false; |
||
290 | } |
||
564 | cbradney | 291 | } |
292 | } |
||
2006 | subik | 293 | else |
1100 | cbradney | 294 | Avail=false; |
2006 | subik | 295 | if (Avail) |
564 | cbradney | 296 | { |
297 | textBrowser->setSource(toLoad); |
||
298 | his.Title = textBrowser->documentTitle(); |
||
299 | if (his.Title == "") |
||
300 | his.Title = toLoad; |
||
301 | his.Url = toLoad; |
||
302 | mHistory[histMenu->insertItem(his.Title)] = his; |
||
303 | } |
||
560 | cbradney | 304 | } |
305 | |||
1092 | cbradney | 306 | void HelpBrowser::loadMenu() |
560 | cbradney | 307 | { |
1693 | craig | 308 | QString pfad = ScPaths::instance().docDir(); |
786 | cbradney | 309 | QString toLoad; |
1092 | cbradney | 310 | QString pfad2 = pfad + language + "/menu.xml"; |
564 | cbradney | 311 | QFileInfo fi = QFileInfo(pfad2); |
786 | cbradney | 312 | |
793 | cbradney | 313 | if (fi.exists()) |
314 | toLoad=pfad2; |
||
315 | else |
||
316 | { |
||
872 | cbradney | 317 | toLoad = pfad + "en/menu.xml"; |
1092 | cbradney | 318 | language="en"; |
786 | cbradney | 319 | fi = QFileInfo(toLoad); |
320 | qDebug("Scribus help in your selected language does not exist, trying English. Otherwise, please visit http://docs.scribus.net."); |
||
321 | } |
||
322 | |||
560 | cbradney | 323 | if (fi.exists()) |
564 | cbradney | 324 | { |
560 | cbradney | 325 | QDomDocument doc( "menuentries" ); |
786 | cbradney | 326 | QFile file( toLoad ); |
560 | cbradney | 327 | if ( !file.open( IO_ReadOnly ) ) |
328 | return; |
||
2006 | subik | 329 | if ( !doc.setContent( &file ) ) |
564 | cbradney | 330 | { |
560 | cbradney | 331 | file.close(); |
332 | return; |
||
333 | } |
||
334 | file.close(); |
||
335 | |||
336 | QDomElement docElem = doc.documentElement(); |
||
337 | QDomNode n = docElem.firstChild(); |
||
338 | QListViewItem *qlvi=NULL, *qlvi2=NULL, *qlvi3=NULL, *qlvi4=NULL, *qlvi5=NULL, *qlvi6=NULL; |
||
1033 | cbradney | 339 | QListViewItem *tutorialsMenuItem; |
340 | bool haveTutorials=false; |
||
560 | cbradney | 341 | |
2006 | subik | 342 | while( !n.isNull() ) |
564 | cbradney | 343 | { |
560 | cbradney | 344 | QDomElement e = n.toElement(); // try to convert the node to an element. |
2006 | subik | 345 | if( !e.isNull() ) |
564 | cbradney | 346 | { |
2006 | subik | 347 | if (e.hasAttribute( "text" ) && e.hasAttribute( "file" )) |
564 | cbradney | 348 | { |
560 | cbradney | 349 | QDomAttr textAttr = e.attributeNode( "text" ); |
350 | QDomAttr fileAttr = e.attributeNode( "file" ); |
||
351 | if (qlvi2==NULL) |
||
352 | qlvi=new QListViewItem(listView, textAttr.value(), fileAttr.value()); |
||
2006 | subik | 353 | else |
1033 | cbradney | 354 | qlvi=new QListViewItem(listView, qlvi2, textAttr.value(), fileAttr.value()); |
1103 | cbradney | 355 | if (qlvi!=NULL && e.hasAttribute( "section" )) |
564 | cbradney | 356 | { |
1103 | cbradney | 357 | QDomAttr sectionAttr = e.attributeNode( "section" ); |
2006 | subik | 358 | if (sectionAttr.value()=="tutorials" && !haveTutorials) |
1103 | cbradney | 359 | { |
360 | haveTutorials=true; |
||
361 | tutorialsMenuItem=qlvi; |
||
362 | } |
||
560 | cbradney | 363 | } |
1033 | cbradney | 364 | |
560 | cbradney | 365 | if (qlvi!=NULL) |
366 | qlvi2=qlvi; |
||
367 | } |
||
368 | |||
369 | QDomNodeList nl=n.childNodes(); |
||
2006 | subik | 370 | for(uint i=0 ; i<= nl.count() ; i++) |
564 | cbradney | 371 | { |
560 | cbradney | 372 | QDomNode child=nl.item(i); |
2006 | subik | 373 | if (child.isElement()) |
564 | cbradney | 374 | { |
2006 | subik | 375 | QDomElement ec = child.toElement(); |
376 | if (!ec.isNull()) |
||
564 | cbradney | 377 | { |
2006 | subik | 378 | if (ec.hasAttribute( "text" ) && ec.hasAttribute( "file" )) |
564 | cbradney | 379 | { |
560 | cbradney | 380 | QDomAttr textAttr = ec.attributeNode( "text" ); |
381 | QDomAttr fileAttr = ec.attributeNode( "file" ); |
||
382 | if (qlvi4==NULL) |
||
383 | qlvi3=new QListViewItem(qlvi, textAttr.value(), fileAttr.value()); |
||
2006 | subik | 384 | else |
1033 | cbradney | 385 | qlvi3=new QListViewItem(qlvi, qlvi4, textAttr.value(), fileAttr.value()); |
1103 | cbradney | 386 | if (qlvi3!=NULL && ec.hasAttribute( "section" )) |
564 | cbradney | 387 | { |
1103 | cbradney | 388 | QDomAttr sectionAttr = e.attributeNode( "section" ); |
1105 | cbradney | 389 | if (sectionAttr.value()=="tutorials" && !haveTutorials) |
1103 | cbradney | 390 | { |
391 | haveTutorials=true; |
||
392 | tutorialsMenuItem=qlvi3; |
||
393 | } |
||
560 | cbradney | 394 | } |
395 | if (qlvi3!=NULL) |
||
396 | qlvi4=qlvi3; |
||
397 | } |
||
398 | //3rd level |
||
399 | QDomNodeList nl2=child.childNodes(); |
||
2006 | subik | 400 | for(uint i=0 ; i<= nl2.count() ; i++) |
564 | cbradney | 401 | { |
560 | cbradney | 402 | QDomNode childchild=nl2.item(i); |
2006 | subik | 403 | if (childchild.isElement()) |
564 | cbradney | 404 | { |
2006 | subik | 405 | QDomElement ecc = childchild.toElement(); |
406 | if (!ecc.isNull()) |
||
564 | cbradney | 407 | { |
2006 | subik | 408 | if (ecc.hasAttribute( "text" ) && ecc.hasAttribute( "file" )) |
564 | cbradney | 409 | { |
560 | cbradney | 410 | QDomAttr textAttr = ecc.attributeNode( "text" ); |
411 | QDomAttr fileAttr = ecc.attributeNode( "file" ); |
||
412 | if (qlvi6==NULL) |
||
413 | qlvi5=new QListViewItem(qlvi3, textAttr.value(), fileAttr.value()); |
||
2006 | subik | 414 | else |
1033 | cbradney | 415 | qlvi5=new QListViewItem(qlvi3, qlvi6, textAttr.value(), fileAttr.value()); |
1103 | cbradney | 416 | if (qlvi5!=NULL && ecc.hasAttribute( "section" )) |
564 | cbradney | 417 | { |
1103 | cbradney | 418 | QDomAttr sectionAttr = e.attributeNode( "section" ); |
1105 | cbradney | 419 | if (sectionAttr.value()=="tutorials" && !haveTutorials) |
1103 | cbradney | 420 | { |
421 | haveTutorials=true; |
||
422 | tutorialsMenuItem=qlvi5; |
||
423 | } |
||
560 | cbradney | 424 | } |
425 | } |
||
426 | if (qlvi5!=NULL) |
||
427 | qlvi6=qlvi5; |
||
428 | } |
||
429 | } |
||
430 | } |
||
431 | } |
||
432 | } |
||
433 | } |
||
434 | } |
||
435 | n = n.nextSibling(); |
||
436 | } |
||
1033 | cbradney | 437 | //scan for installed tutorials |
2006 | subik | 438 | if (haveTutorials) |
1033 | cbradney | 439 | { |
1693 | craig | 440 | QString path = ScPaths::instance().docDir(); |
1092 | cbradney | 441 | path += language + "/tutorials/"; |
1033 | cbradney | 442 | QDir dir(path, "*", QDir::Name, QDir::Dirs | QDir::NoSymLinks); |
443 | |||
2006 | subik | 444 | if (dir.exists() && (dir.count() != 0)) |
1033 | cbradney | 445 | { |
2006 | subik | 446 | for (uint i = 0; i < dir.count(); ++i) |
1033 | cbradney | 447 | { |
448 | if (dir[i]!="." && dir[i]!="..") |
||
449 | { |
||
1092 | cbradney | 450 | QString tutorialdir = "tutorials/" + dir[i] + "/"; |
1033 | cbradney | 451 | QFileInfo file(path + dir[i] + "/menu.xml"); |
452 | if (file.exists()) // menu.xml exists for tutorial |
||
453 | { |
||
454 | QDomDocument docTutorial( "tutorialmenuentries" ); |
||
455 | QFile fileTutorialMenu( file.filePath() ); |
||
456 | if ( !fileTutorialMenu.open( IO_ReadOnly ) ) |
||
457 | break; |
||
2006 | subik | 458 | if ( !docTutorial.setContent( &fileTutorialMenu ) ) |
1033 | cbradney | 459 | { |
460 | fileTutorialMenu.close(); |
||
461 | break; |
||
462 | } |
||
463 | fileTutorialMenu.close(); |
||
464 | |||
465 | QDomElement docElemTutorial = docTutorial.documentElement(); |
||
466 | QDomNode nTutorial = docElemTutorial.firstChild(); |
||
467 | QListViewItem *tutorialQLVI=NULL; |
||
468 | |||
2006 | subik | 469 | while( !nTutorial.isNull() ) |
1033 | cbradney | 470 | { |
471 | QDomElement eTutorial = nTutorial.toElement(); // try to convert the node to an element. |
||
2006 | subik | 472 | if( !eTutorial.isNull() ) |
1033 | cbradney | 473 | { |
2006 | subik | 474 | if (tutorialsMenuItem!=NULL && eTutorial.hasAttribute( "text" ) && eTutorial.hasAttribute( "file" )) |
1033 | cbradney | 475 | { |
476 | QDomAttr textAttr = eTutorial.attributeNode( "text" ); |
||
477 | QDomAttr fileAttr = eTutorial.attributeNode( "file" ); |
||
1092 | cbradney | 478 | tutorialQLVI=new QListViewItem(tutorialsMenuItem, textAttr.value(), tutorialdir + fileAttr.value()); |
1033 | cbradney | 479 | } |
480 | QDomNodeList nl=nTutorial.childNodes(); |
||
481 | QListViewItem *tutorialSubMenuItem, *tutorialSubMenuItemLast=NULL; |
||
1092 | cbradney | 482 | for(uint j=0 ; j<= nl.count() ; j++) |
1033 | cbradney | 483 | { |
1092 | cbradney | 484 | QDomNode child=nl.item(j); |
1033 | cbradney | 485 | if (child.isElement()) |
486 | { |
||
487 | QDomElement ec = child.toElement(); |
||
488 | if (!ec.isNull()) |
||
489 | { |
||
490 | if (ec.hasAttribute( "text" ) && ec.hasAttribute( "file" )) |
||
491 | { |
||
492 | QDomAttr textAttr = ec.attributeNode( "text" ); |
||
493 | QDomAttr fileAttr = ec.attributeNode( "file" ); |
||
494 | if (tutorialSubMenuItemLast==NULL) |
||
1092 | cbradney | 495 | tutorialSubMenuItem=new QListViewItem(tutorialQLVI, textAttr.value(), tutorialdir + fileAttr.value()); |
2006 | subik | 496 | else |
1092 | cbradney | 497 | tutorialSubMenuItem=new QListViewItem(tutorialQLVI, tutorialSubMenuItemLast, textAttr.value(), tutorialdir + fileAttr.value()); |
1033 | cbradney | 498 | if (tutorialSubMenuItem!=NULL) |
499 | tutorialSubMenuItemLast=tutorialSubMenuItem; |
||
500 | } |
||
501 | } |
||
502 | } |
||
503 | } |
||
504 | } |
||
505 | nTutorial = nTutorial.nextSibling(); |
||
506 | } |
||
507 | } |
||
508 | } |
||
509 | } |
||
510 | } |
||
511 | |||
512 | } |
||
205 | Franz | 513 | } |
68 | Franz | 514 | } |
515 | |||
560 | cbradney | 516 | void HelpBrowser::itemSelected(QListViewItem *item) |
68 | Franz | 517 | { |
560 | cbradney | 518 | if ( !item ) |
519 | return; |
||
1033 | cbradney | 520 | if (item->text(1)!=QString::null) |
521 | { |
||
1693 | craig | 522 | QString pfad = ScPaths::instance().docDir(); |
1092 | cbradney | 523 | loadHelp(pfad + language + "/" + item->text(1)); |
1033 | cbradney | 524 | } |
68 | Franz | 525 | } |
2006 | subik | 526 | |
527 | void HelpBrowser::itemSearchSelected(QListViewItem *item) |
||
528 | { |
||
529 | if (item && item->text(1) != QString::null) |
||
530 | { |
||
531 | loadHelp(item->text(1)); |
||
532 | findText = searchingEdit->text(); |
||
533 | findNext(); |
||
534 | } |
||
535 | } |
||
536 | |||
537 | void HelpBrowser::searchingInDirectory(QString aDir) |
||
538 | { |
||
539 | QDir dir(aDir + "/"); |
||
540 | QStringList lst = dir.entryList("*.html"); |
||
541 | for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it) |
||
542 | { |
||
543 | QString fname(aDir + (*it)); |
||
544 | QFile f(fname); |
||
545 | if (f.open(IO_ReadOnly)) |
||
546 | { |
||
547 | QTextStream stream(&f); |
||
548 | QString str = stream.read().lower(); |
||
549 | int cnt = str.contains(searchingEdit->text().lower()); |
||
550 | if (cnt > 0) |
||
551 | { |
||
552 | // the remove() hack is here for itemSelected() handling |
||
553 | QString fullname = fname; |
||
554 | QString title; |
||
555 | QListViewItem *refItem = listView->findItem(fname.remove(ScPaths::instance().docDir()+"en/"), 1); |
||
556 | refItem ? title = refItem->text(0) : title = tr("unknown"); |
||
557 | QListViewItem *item = new QListViewItem(searchingView, QString("%1x %2").arg(cnt).arg(title), fullname); |
||
558 | searchingView->insertItem(item); |
||
559 | } |
||
560 | f.close(); |
||
561 | } |
||
562 | } |
||
563 | // get dirs - ugly recursion |
||
564 | QStringList dst = dir.entryList("*", QDir::Dirs); |
||
565 | for (QStringList::Iterator it = dst.begin(); it != dst.end(); ++it) |
||
566 | if ((*it)!="." && (*it)!="..") |
||
567 | searchingInDirectory(aDir + QString((*it)) + "/"); |
||
568 | } |
||
569 | |||
570 | void HelpBrowser::searchingButton_clicked() |
||
571 | { |
||
572 | searchingView->clear(); |
||
573 | // root files |
||
574 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
||
575 | searchingInDirectory(ScPaths::instance().docDir() + "en/"); |
||
576 | QApplication::restoreOverrideCursor(); |
||
577 | } |
||
578 | |||
579 | void HelpBrowser::find() |
||
580 | { |
||
581 | findText = QInputDialog::getText(tr("Find"), tr("Search Term:"), QLineEdit::Normal, findText, 0, this); |
||
582 | if (findText == QString::null) |
||
583 | return; |
||
584 | findNext(); |
||
585 | } |
||
586 | |||
587 | void HelpBrowser::findNext() |
||
588 | { |
||
589 | if (findText == QString::null) |
||
590 | { |
||
591 | find(); |
||
592 | return; |
||
593 | } |
||
594 | // find it. finally |
||
595 | textBrowser->find(findText, false, false, true, 0, 0); |
||
596 | } |