Rev 2006 | Rev 2023 | 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"); |
||
2008 | cbradney | 129 | searchingButton = new QPushButton(tr("&Search"), tabSearching, "searchingButton"); |
2006 | subik | 130 | searchingButtonLayout->addWidget(searchingEdit); |
131 | searchingButtonLayout->addWidget(searchingButton); |
||
132 | searchingMainLayout->addLayout(searchingButtonLayout); |
||
133 | searchingView = new QListView(tabSearching, "searchingView"); |
||
134 | searchingView->addColumn( tr( "Contents" ) ); |
||
135 | searchingView->addColumn( tr( "Link" ) , 0 ); |
||
136 | searchingView->setColumnWidthMode( 0, QListView::Maximum ); |
||
137 | searchingView->setColumnWidthMode( 1, QListView::Manual ); |
||
138 | searchingView->setSorting(-1,-1); |
||
139 | searchingView->setRootIsDecorated( true ); |
||
140 | searchingView->setSelectionMode(QListView::Single); |
||
141 | searchingView->setDefaultRenameAction(QListView::Reject); |
||
142 | searchingView->clear(); |
||
143 | searchingMainLayout->addWidget(searchingView); |
||
144 | tabWidget->insertTab(tabSearching, tr("S&earch")); |
||
145 | |||
786 | cbradney | 146 | textBrowser = new QTextBrowser( splitter, "textBrowser" ); |
147 | splitter->setResizeMode(textBrowser, QSplitter::Stretch); |
||
148 | //textBrowser = new QTextBrowser( this, "textBrowser" ); |
||
149 | textBrowser->setSizePolicy( QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Expanding, false ) ); |
||
564 | cbradney | 150 | textBrowser->setFrameShape( QTextBrowser::StyledPanel ); |
1144 | cbradney | 151 | QMimeSourceFactory *textBrowserMSF=textBrowser->mimeSourceFactory(); |
152 | textBrowserMSF->setExtensionType("html", "text/html;charset=UTF-8"); |
||
786 | cbradney | 153 | //helpBrowserLayout->addWidget( textBrowser ); |
564 | cbradney | 154 | helpBrowsermainLayout->addLayout( helpBrowserLayout ); |
560 | cbradney | 155 | |
564 | cbradney | 156 | languageChange(); |
157 | resize( QSize(602, 491).expandedTo(minimumSizeHint()) ); |
||
158 | clearWState( WState_Polished ); |
||
1092 | cbradney | 159 | loadMenu(); |
560 | cbradney | 160 | listView->header()->hide(); |
2006 | subik | 161 | searchingView->header()->hide(); |
1092 | cbradney | 162 | jumpToHelpSection(jumpToSection, jumpToFile ); |
560 | cbradney | 163 | |
2006 | subik | 164 | QAccel *a = new QAccel( this, "a"); |
165 | a->connectItem(a->insertItem(QAccel::stringToKey(tr("Ctrl+F"))), this, SLOT(find())); |
||
166 | a->connectItem(a->insertItem(QAccel::stringToKey(tr("F3"))), this, SLOT(findNext())); |
||
167 | |||
560 | cbradney | 168 | connect( homeButton, SIGNAL( clicked() ), textBrowser, SLOT( home() ) ); |
169 | connect( forwButton, SIGNAL( clicked() ), textBrowser, SLOT( forward() ) ); |
||
170 | connect( backButton, SIGNAL( clicked() ), textBrowser, SLOT( backward() ) ); |
||
564 | cbradney | 171 | connect( histMenu, SIGNAL(activated(int)), this, SLOT(histChosen(int))); |
172 | connect( listView, SIGNAL(clicked( QListViewItem *)), this, SLOT(itemSelected( QListViewItem *))); |
||
2006 | subik | 173 | // searching |
2008 | cbradney | 174 | connect( searchingEdit, SIGNAL(returnPressed()), this, SLOT(searchingButton_clicked())); |
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 | { |
2008 | cbradney | 234 | toLoad = ScPaths::instance().docDir() + language + "/"; //clean this later to handle 5 char locales |
2006 | subik | 235 | if (jumpToSection=="") |
564 | cbradney | 236 | { |
1141 | cbradney | 237 | if (listView->firstChild()) |
238 | { |
||
239 | toLoad+=listView->firstChild()->text(1); |
||
240 | listView->setSelected( listView->firstChild(), true ); |
||
241 | } |
||
242 | else |
||
243 | noDocs=true; |
||
205 | Franz | 244 | } |
2006 | subik | 245 | else if (jumpToSection=="scripter") |
564 | cbradney | 246 | { |
560 | cbradney | 247 | toLoad+="scripter1.html"; |
248 | QListViewItemIterator it(listView); |
||
2006 | subik | 249 | while (it.current()) |
564 | cbradney | 250 | { |
560 | cbradney | 251 | if (it.current()->text(1)=="scripter1.html") |
252 | listView->setSelected( it.current(), true ); |
||
253 | if (it.current()->text(1)=="developers.html") |
||
254 | it.current()->setOpen( true ); |
||
255 | ++it; |
||
256 | } |
||
257 | } |
||
205 | Franz | 258 | } |
560 | cbradney | 259 | else |
564 | cbradney | 260 | toLoad=jumpToFile; |
3 | paul | 261 | |
1141 | cbradney | 262 | if (!noDocs) |
263 | loadHelp(toLoad); |
||
264 | else |
||
265 | 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 | 266 | } |
267 | |||
560 | cbradney | 268 | void HelpBrowser::loadHelp(QString filename) |
68 | Franz | 269 | { |
75 | Franz | 270 | struct histd his; |
564 | cbradney | 271 | bool Avail = true; |
560 | cbradney | 272 | QString toLoad; |
564 | cbradney | 273 | QFileInfo fi; |
274 | fi = QFileInfo(filename); |
||
1100 | cbradney | 275 | if (fi.fileName().length()>0) |
564 | cbradney | 276 | { |
1100 | cbradney | 277 | if (fi.exists()) |
278 | toLoad=filename; |
||
2006 | subik | 279 | else |
564 | cbradney | 280 | { |
2008 | cbradney | 281 | toLoad = QDir::convertSeparators(ScPaths::instance().docDir() + "en/index.html"); |
1100 | cbradney | 282 | language="en"; |
283 | fi = QFileInfo(toLoad); |
||
284 | if (!fi.exists()) |
||
285 | { |
||
286 | textBrowser->setText("<h2>"+ tr("Sorry, no manual available! Please see: http://docs.scribus.net for updated docs\nand www.scribus.net for downloads.")+"</h2>"); |
||
287 | Avail = false; |
||
288 | } |
||
564 | cbradney | 289 | } |
290 | } |
||
2006 | subik | 291 | else |
1100 | cbradney | 292 | Avail=false; |
2006 | subik | 293 | if (Avail) |
564 | cbradney | 294 | { |
295 | textBrowser->setSource(toLoad); |
||
296 | his.Title = textBrowser->documentTitle(); |
||
297 | if (his.Title == "") |
||
298 | his.Title = toLoad; |
||
299 | his.Url = toLoad; |
||
300 | mHistory[histMenu->insertItem(his.Title)] = his; |
||
301 | } |
||
560 | cbradney | 302 | } |
303 | |||
1092 | cbradney | 304 | void HelpBrowser::loadMenu() |
560 | cbradney | 305 | { |
1693 | craig | 306 | QString pfad = ScPaths::instance().docDir(); |
786 | cbradney | 307 | QString toLoad; |
2008 | cbradney | 308 | QString pfad2 = QDir::convertSeparators(pfad + language + "/menu.xml"); |
564 | cbradney | 309 | QFileInfo fi = QFileInfo(pfad2); |
786 | cbradney | 310 | |
793 | cbradney | 311 | if (fi.exists()) |
312 | toLoad=pfad2; |
||
313 | else |
||
314 | { |
||
2008 | cbradney | 315 | toLoad = QDir::convertSeparators(pfad + "en/menu.xml"); |
1092 | cbradney | 316 | language="en"; |
786 | cbradney | 317 | fi = QFileInfo(toLoad); |
318 | qDebug("Scribus help in your selected language does not exist, trying English. Otherwise, please visit http://docs.scribus.net."); |
||
319 | } |
||
320 | |||
560 | cbradney | 321 | if (fi.exists()) |
564 | cbradney | 322 | { |
560 | cbradney | 323 | QDomDocument doc( "menuentries" ); |
786 | cbradney | 324 | QFile file( toLoad ); |
560 | cbradney | 325 | if ( !file.open( IO_ReadOnly ) ) |
326 | return; |
||
2006 | subik | 327 | if ( !doc.setContent( &file ) ) |
564 | cbradney | 328 | { |
560 | cbradney | 329 | file.close(); |
330 | return; |
||
331 | } |
||
332 | file.close(); |
||
333 | |||
334 | QDomElement docElem = doc.documentElement(); |
||
335 | QDomNode n = docElem.firstChild(); |
||
336 | QListViewItem *qlvi=NULL, *qlvi2=NULL, *qlvi3=NULL, *qlvi4=NULL, *qlvi5=NULL, *qlvi6=NULL; |
||
1033 | cbradney | 337 | QListViewItem *tutorialsMenuItem; |
338 | bool haveTutorials=false; |
||
560 | cbradney | 339 | |
2006 | subik | 340 | while( !n.isNull() ) |
564 | cbradney | 341 | { |
560 | cbradney | 342 | QDomElement e = n.toElement(); // try to convert the node to an element. |
2006 | subik | 343 | if( !e.isNull() ) |
564 | cbradney | 344 | { |
2006 | subik | 345 | if (e.hasAttribute( "text" ) && e.hasAttribute( "file" )) |
564 | cbradney | 346 | { |
560 | cbradney | 347 | QDomAttr textAttr = e.attributeNode( "text" ); |
348 | QDomAttr fileAttr = e.attributeNode( "file" ); |
||
349 | if (qlvi2==NULL) |
||
350 | qlvi=new QListViewItem(listView, textAttr.value(), fileAttr.value()); |
||
2006 | subik | 351 | else |
1033 | cbradney | 352 | qlvi=new QListViewItem(listView, qlvi2, textAttr.value(), fileAttr.value()); |
1103 | cbradney | 353 | if (qlvi!=NULL && e.hasAttribute( "section" )) |
564 | cbradney | 354 | { |
1103 | cbradney | 355 | QDomAttr sectionAttr = e.attributeNode( "section" ); |
2006 | subik | 356 | if (sectionAttr.value()=="tutorials" && !haveTutorials) |
1103 | cbradney | 357 | { |
358 | haveTutorials=true; |
||
359 | tutorialsMenuItem=qlvi; |
||
360 | } |
||
560 | cbradney | 361 | } |
1033 | cbradney | 362 | |
560 | cbradney | 363 | if (qlvi!=NULL) |
364 | qlvi2=qlvi; |
||
365 | } |
||
366 | |||
367 | QDomNodeList nl=n.childNodes(); |
||
2006 | subik | 368 | for(uint i=0 ; i<= nl.count() ; i++) |
564 | cbradney | 369 | { |
560 | cbradney | 370 | QDomNode child=nl.item(i); |
2006 | subik | 371 | if (child.isElement()) |
564 | cbradney | 372 | { |
2006 | subik | 373 | QDomElement ec = child.toElement(); |
374 | if (!ec.isNull()) |
||
564 | cbradney | 375 | { |
2006 | subik | 376 | if (ec.hasAttribute( "text" ) && ec.hasAttribute( "file" )) |
564 | cbradney | 377 | { |
560 | cbradney | 378 | QDomAttr textAttr = ec.attributeNode( "text" ); |
379 | QDomAttr fileAttr = ec.attributeNode( "file" ); |
||
380 | if (qlvi4==NULL) |
||
381 | qlvi3=new QListViewItem(qlvi, textAttr.value(), fileAttr.value()); |
||
2006 | subik | 382 | else |
1033 | cbradney | 383 | qlvi3=new QListViewItem(qlvi, qlvi4, textAttr.value(), fileAttr.value()); |
1103 | cbradney | 384 | if (qlvi3!=NULL && ec.hasAttribute( "section" )) |
564 | cbradney | 385 | { |
1103 | cbradney | 386 | QDomAttr sectionAttr = e.attributeNode( "section" ); |
1105 | cbradney | 387 | if (sectionAttr.value()=="tutorials" && !haveTutorials) |
1103 | cbradney | 388 | { |
389 | haveTutorials=true; |
||
390 | tutorialsMenuItem=qlvi3; |
||
391 | } |
||
560 | cbradney | 392 | } |
393 | if (qlvi3!=NULL) |
||
394 | qlvi4=qlvi3; |
||
395 | } |
||
396 | //3rd level |
||
397 | QDomNodeList nl2=child.childNodes(); |
||
2006 | subik | 398 | for(uint i=0 ; i<= nl2.count() ; i++) |
564 | cbradney | 399 | { |
560 | cbradney | 400 | QDomNode childchild=nl2.item(i); |
2006 | subik | 401 | if (childchild.isElement()) |
564 | cbradney | 402 | { |
2006 | subik | 403 | QDomElement ecc = childchild.toElement(); |
404 | if (!ecc.isNull()) |
||
564 | cbradney | 405 | { |
2006 | subik | 406 | if (ecc.hasAttribute( "text" ) && ecc.hasAttribute( "file" )) |
564 | cbradney | 407 | { |
560 | cbradney | 408 | QDomAttr textAttr = ecc.attributeNode( "text" ); |
409 | QDomAttr fileAttr = ecc.attributeNode( "file" ); |
||
410 | if (qlvi6==NULL) |
||
411 | qlvi5=new QListViewItem(qlvi3, textAttr.value(), fileAttr.value()); |
||
2006 | subik | 412 | else |
1033 | cbradney | 413 | qlvi5=new QListViewItem(qlvi3, qlvi6, textAttr.value(), fileAttr.value()); |
1103 | cbradney | 414 | if (qlvi5!=NULL && ecc.hasAttribute( "section" )) |
564 | cbradney | 415 | { |
1103 | cbradney | 416 | QDomAttr sectionAttr = e.attributeNode( "section" ); |
1105 | cbradney | 417 | if (sectionAttr.value()=="tutorials" && !haveTutorials) |
1103 | cbradney | 418 | { |
419 | haveTutorials=true; |
||
420 | tutorialsMenuItem=qlvi5; |
||
421 | } |
||
560 | cbradney | 422 | } |
423 | } |
||
424 | if (qlvi5!=NULL) |
||
425 | qlvi6=qlvi5; |
||
426 | } |
||
427 | } |
||
428 | } |
||
429 | } |
||
430 | } |
||
431 | } |
||
432 | } |
||
433 | n = n.nextSibling(); |
||
434 | } |
||
1033 | cbradney | 435 | //scan for installed tutorials |
2006 | subik | 436 | if (haveTutorials) |
1033 | cbradney | 437 | { |
1693 | craig | 438 | QString path = ScPaths::instance().docDir(); |
1092 | cbradney | 439 | path += language + "/tutorials/"; |
1033 | cbradney | 440 | QDir dir(path, "*", QDir::Name, QDir::Dirs | QDir::NoSymLinks); |
441 | |||
2006 | subik | 442 | if (dir.exists() && (dir.count() != 0)) |
1033 | cbradney | 443 | { |
2006 | subik | 444 | for (uint i = 0; i < dir.count(); ++i) |
1033 | cbradney | 445 | { |
446 | if (dir[i]!="." && dir[i]!="..") |
||
447 | { |
||
2008 | cbradney | 448 | QString tutorialdir = QDir::convertSeparators("tutorials/" + dir[i] + "/"); |
449 | QFileInfo file(QDir::convertSeparators(path + dir[i] + "/menu.xml")); |
||
1033 | cbradney | 450 | if (file.exists()) // menu.xml exists for tutorial |
451 | { |
||
452 | QDomDocument docTutorial( "tutorialmenuentries" ); |
||
453 | QFile fileTutorialMenu( file.filePath() ); |
||
454 | if ( !fileTutorialMenu.open( IO_ReadOnly ) ) |
||
455 | break; |
||
2006 | subik | 456 | if ( !docTutorial.setContent( &fileTutorialMenu ) ) |
1033 | cbradney | 457 | { |
458 | fileTutorialMenu.close(); |
||
459 | break; |
||
460 | } |
||
461 | fileTutorialMenu.close(); |
||
462 | |||
463 | QDomElement docElemTutorial = docTutorial.documentElement(); |
||
464 | QDomNode nTutorial = docElemTutorial.firstChild(); |
||
465 | QListViewItem *tutorialQLVI=NULL; |
||
466 | |||
2006 | subik | 467 | while( !nTutorial.isNull() ) |
1033 | cbradney | 468 | { |
469 | QDomElement eTutorial = nTutorial.toElement(); // try to convert the node to an element. |
||
2006 | subik | 470 | if( !eTutorial.isNull() ) |
1033 | cbradney | 471 | { |
2006 | subik | 472 | if (tutorialsMenuItem!=NULL && eTutorial.hasAttribute( "text" ) && eTutorial.hasAttribute( "file" )) |
1033 | cbradney | 473 | { |
474 | QDomAttr textAttr = eTutorial.attributeNode( "text" ); |
||
475 | QDomAttr fileAttr = eTutorial.attributeNode( "file" ); |
||
1092 | cbradney | 476 | tutorialQLVI=new QListViewItem(tutorialsMenuItem, textAttr.value(), tutorialdir + fileAttr.value()); |
1033 | cbradney | 477 | } |
478 | QDomNodeList nl=nTutorial.childNodes(); |
||
479 | QListViewItem *tutorialSubMenuItem, *tutorialSubMenuItemLast=NULL; |
||
1092 | cbradney | 480 | for(uint j=0 ; j<= nl.count() ; j++) |
1033 | cbradney | 481 | { |
1092 | cbradney | 482 | QDomNode child=nl.item(j); |
1033 | cbradney | 483 | if (child.isElement()) |
484 | { |
||
485 | QDomElement ec = child.toElement(); |
||
486 | if (!ec.isNull()) |
||
487 | { |
||
488 | if (ec.hasAttribute( "text" ) && ec.hasAttribute( "file" )) |
||
489 | { |
||
490 | QDomAttr textAttr = ec.attributeNode( "text" ); |
||
491 | QDomAttr fileAttr = ec.attributeNode( "file" ); |
||
492 | if (tutorialSubMenuItemLast==NULL) |
||
1092 | cbradney | 493 | tutorialSubMenuItem=new QListViewItem(tutorialQLVI, textAttr.value(), tutorialdir + fileAttr.value()); |
2006 | subik | 494 | else |
1092 | cbradney | 495 | tutorialSubMenuItem=new QListViewItem(tutorialQLVI, tutorialSubMenuItemLast, textAttr.value(), tutorialdir + fileAttr.value()); |
1033 | cbradney | 496 | if (tutorialSubMenuItem!=NULL) |
497 | tutorialSubMenuItemLast=tutorialSubMenuItem; |
||
498 | } |
||
499 | } |
||
500 | } |
||
501 | } |
||
502 | } |
||
503 | nTutorial = nTutorial.nextSibling(); |
||
504 | } |
||
505 | } |
||
506 | } |
||
507 | } |
||
508 | } |
||
509 | |||
510 | } |
||
205 | Franz | 511 | } |
68 | Franz | 512 | } |
513 | |||
560 | cbradney | 514 | void HelpBrowser::itemSelected(QListViewItem *item) |
68 | Franz | 515 | { |
560 | cbradney | 516 | if ( !item ) |
517 | return; |
||
1033 | cbradney | 518 | if (item->text(1)!=QString::null) |
519 | { |
||
1693 | craig | 520 | QString pfad = ScPaths::instance().docDir(); |
2008 | cbradney | 521 | loadHelp(QDir::convertSeparators(pfad + language + "/" + item->text(1))); |
1033 | cbradney | 522 | } |
68 | Franz | 523 | } |
2006 | subik | 524 | |
525 | void HelpBrowser::itemSearchSelected(QListViewItem *item) |
||
526 | { |
||
527 | if (item && item->text(1) != QString::null) |
||
528 | { |
||
529 | loadHelp(item->text(1)); |
||
530 | findText = searchingEdit->text(); |
||
531 | findNext(); |
||
532 | } |
||
533 | } |
||
534 | |||
535 | void HelpBrowser::searchingInDirectory(QString aDir) |
||
536 | { |
||
537 | QDir dir(aDir + "/"); |
||
538 | QStringList lst = dir.entryList("*.html"); |
||
539 | for (QStringList::Iterator it = lst.begin(); it != lst.end(); ++it) |
||
540 | { |
||
541 | QString fname(aDir + (*it)); |
||
542 | QFile f(fname); |
||
543 | if (f.open(IO_ReadOnly)) |
||
544 | { |
||
545 | QTextStream stream(&f); |
||
546 | QString str = stream.read().lower(); |
||
547 | int cnt = str.contains(searchingEdit->text().lower()); |
||
548 | if (cnt > 0) |
||
549 | { |
||
550 | // the remove() hack is here for itemSelected() handling |
||
551 | QString fullname = fname; |
||
552 | QString title; |
||
2008 | cbradney | 553 | QListViewItem *refItem = listView->findItem(fname.remove(QDir::convertSeparators(ScPaths::instance().docDir()+language + "/")), 1); |
2006 | subik | 554 | refItem ? title = refItem->text(0) : title = tr("unknown"); |
555 | QListViewItem *item = new QListViewItem(searchingView, QString("%1x %2").arg(cnt).arg(title), fullname); |
||
556 | searchingView->insertItem(item); |
||
557 | } |
||
558 | f.close(); |
||
559 | } |
||
560 | } |
||
561 | // get dirs - ugly recursion |
||
562 | QStringList dst = dir.entryList("*", QDir::Dirs); |
||
563 | for (QStringList::Iterator it = dst.begin(); it != dst.end(); ++it) |
||
564 | if ((*it)!="." && (*it)!="..") |
||
2008 | cbradney | 565 | searchingInDirectory(QDir::convertSeparators(aDir + QString((*it)) + "/")); |
2006 | subik | 566 | } |
567 | |||
568 | void HelpBrowser::searchingButton_clicked() |
||
569 | { |
||
570 | searchingView->clear(); |
||
571 | // root files |
||
572 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
||
2008 | cbradney | 573 | searchingInDirectory(ScPaths::instance().docDir() + language + "/"); |
2006 | subik | 574 | QApplication::restoreOverrideCursor(); |
575 | } |
||
576 | |||
577 | void HelpBrowser::find() |
||
578 | { |
||
579 | findText = QInputDialog::getText(tr("Find"), tr("Search Term:"), QLineEdit::Normal, findText, 0, this); |
||
580 | if (findText == QString::null) |
||
581 | return; |
||
582 | findNext(); |
||
583 | } |
||
584 | |||
585 | void HelpBrowser::findNext() |
||
586 | { |
||
587 | if (findText == QString::null) |
||
588 | { |
||
589 | find(); |
||
590 | return; |
||
591 | } |
||
592 | // find it. finally |
||
593 | textBrowser->find(findText, false, false, true, 0, 0); |
||
594 | } |