3
* TOra - An Oracle Toolkit for DBA's and developers
4
* Copyright (C) 2003-2005 Quest Software, Inc
5
* Portions Copyright (C) 2005 Other Contributors
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; only version 2 of
10
* the License is valid for this program.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
* As a special exception, you have permission to link this program
22
* with the Oracle Client libraries and distribute executables, as long
23
* as you follow the requirements of the GNU GPL in regard to all of the
24
* software in the executable aside from Oracle client libraries.
26
* Specifically you are not permitted to link this program with the
27
* Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
28
* And you are not permitted to distribute binaries compiled against
29
* these libraries without written consent from Quest Software, Inc.
30
* Observe that this does not disallow linking to the Qt Free Edition.
32
* You may link this product with any GPL'd Qt library such as Qt/Free
34
* All trademarks belong to their respective owners.
44
#include "toresultview.h"
48
#include <kfiledialog.h>
49
#include <khtml_part.h>
53
#include <qcombobox.h>
55
#include <qfiledialog.h>
56
#include <qfileinfo.h>
59
#include <qlineedit.h>
60
#include <qmessagebox.h>
61
#include <qprogressbar.h>
62
#include <qpushbutton.h>
64
#include <qsplitter.h>
65
#include <qtabwidget.h>
66
#include <qtextbrowser.h>
67
#include <qtextview.h>
70
#include <qtoolbutton.h>
75
#include "tohelpaddfileui.moc"
76
#include "tohelpsetupui.moc"
79
#include "tohelpbrowser.h"
80
#include "tohelpbrowser.moc"
82
toHelpBrowser::toHelpBrowser(QWidget *parent, const char *name)
83
: KHTMLPart(parent, name)
85
connect(browserExtension(),
86
SIGNAL(openURLRequest(const KURL &, const KParts::URLArgs &)),
88
SLOT(openURLRequest(const KURL &, const KParts::URLArgs &)));
91
void toHelpBrowser::openURLRequest(const KURL &url, const KParts::URLArgs &)
97
bool toHelpBrowser::openURL(const KURL &url)
99
if (Forward.size() > 0)
101
emit forwardAvailable(false);
104
if (Backward.size() == 1)
105
emit backwardAvailable(true);
106
toPush(Backward, url.url());
107
bool ret = KHTMLPart::openURL(url);
112
void toHelpBrowser::backward(void)
114
toPush(Forward, toPop(Backward));
115
QString url = (*Backward.rbegin());
116
if (Forward.size() == 1)
117
emit forwardAvailable(true);
118
if (Backward.size() == 1)
119
emit backwardAvailable(false);
120
KHTMLPart::openURL(url);
124
void toHelpBrowser::forward(void)
126
QString url = toPop(Forward);
128
emit forwardAvailable(false);
129
if (Backward.size() == 1)
130
emit backwardAvailable(true);
131
toPush(Backward, url);
132
KHTMLPart::openURL(url);
136
QString toHelpBrowser::source(void)
138
if ( Backward.empty() )
139
return QString::null;
140
return (*Backward.rbegin());
145
toHelp *toHelp::Window;
147
class toHelpAddFile : public toHelpAddFileUI
150
toHelpAddFile(QWidget *parent, const char *name = 0)
151
: toHelpAddFileUI(parent, name, true)
153
OkButton->setEnabled(false);
154
toHelp::connectDialog(this);
156
virtual void browse(void)
158
QString filename = toOpenFilename(Filename->text(), QString::fromLatin1("toc.htm*"), this);
159
if (!filename.isEmpty())
160
Filename->setText(filename);
162
virtual void valid(void)
164
if (Filename->text().isEmpty() || Root->text().isEmpty())
165
OkButton->setEnabled(false);
167
OkButton->setEnabled(true);
171
class toHelpPrefs : public toHelpSetupUI, public toSettingTab
175
toHelpPrefs(toTool *tool, QWidget *parent, const char *name = 0)
176
: toHelpSetupUI(parent, name), toSettingTab("additionalhelp.html"), Tool(tool)
178
int tot = Tool->config("Number", "-1").toInt();
181
for (int i = 0;i < tot;i++)
183
QString num = QString::number(i);
184
QString root = Tool->config(num.latin1(), "");
185
num += QString::fromLatin1("file");
186
QString file = Tool->config(num.latin1(), "");
187
new QListViewItem(FileList, root, file);
191
virtual void saveSetting(void)
194
for (QListViewItem *item = FileList->firstChild();item;item = item->nextSibling())
196
QString nam = QString::number(i);
197
Tool->setConfig(nam.latin1(), item->text(0));
198
nam += QString::fromLatin1("file");
199
Tool->setConfig(nam.latin1(), item->text(1));
202
Tool->setConfig("Number", QString::number(i));
203
delete toHelp::Window;
205
virtual void addFile(void)
207
toHelpAddFile file(this);
209
new QListViewItem(FileList, file.Root->text(), file.Filename->text());
211
virtual void delFile(void)
213
delete FileList->selectedItem();
215
virtual void oracleManuals(void)
217
QString filename = toOpenFilename(QString::null, QString::fromLatin1("*index.htm*"), this);
220
toHtml file(toReadFile(filename));
223
QRegExp isToc(QString::fromLatin1("toc\\.html?$"));
229
if (file.open() && !strcmp(file.tag(), "a"))
231
QString href = toHelp::path(filename);
232
href += QString::fromLatin1(file.value("href"));
233
if (!href.isEmpty() &&
235
href.find(isToc) >= 0 &&
238
new QListViewItem(FileList, dsc.simplifyWhiteSpace(), href);
243
else if (file.open() && (!strcmp(file.tag(), "dd") || !strcmp(file.tag(), "book")))
250
dsc += QString::fromLatin1(file.text());
253
catch (const QString &str)
255
TOMessageBox::warning(toMainWidget(), qApp->translate("toHelpPrefs", "File error"), str);
260
QWidget *toHelpTool::configurationTab(QWidget *parent)
262
return new toHelpPrefs(this, parent);
265
void toHelpTool::displayHelp(void)
267
QWidget *cur = qApp->focusWidget();
270
QDialog *dlg = dynamic_cast<QDialog *>(cur);
273
toHelp::displayHelp(dlg);
276
cur = cur->parentWidget();
279
toHelp::displayHelp();
282
static toHelpTool HelpTool;
284
toHelp::toHelp(QWidget *parent, const char *name, bool modal)
285
: QDialog(parent, name, modal,
286
WStyle_Customize | WStyle_NormalBorder |
287
WStyle_Title | WStyle_SysMenu |
288
WStyle_Minimize | WStyle_Maximize)
292
QBoxLayout *l = new QVBoxLayout(this);
293
QToolBar *toolbar = toAllocBar(this, tr("Help Navigation"));
294
l->addWidget(toolbar);
296
QSplitter *splitter = new QSplitter(Horizontal, this);
297
l->addWidget(splitter);
299
QTabWidget *tabs = new QTabWidget(splitter);
300
Sections = new toListView(tabs);
301
Sections->addColumn(tr("Contents"));
302
Sections->setSorting( -1);
303
Sections->setRootIsDecorated(true);
305
tabs->addTab(Sections, tr("Contents"));
306
QVBox *box = new QVBox(tabs);
307
tabs->addTab(box, tr("Search"));
308
SearchLine = new QLineEdit(box);
309
connect(SearchLine, SIGNAL(returnPressed()), this, SLOT(search()));
310
Manuals = new QComboBox(box);
311
Manuals->insertItem(tr("All manuals"));
312
Result = new toListView(box);
313
Result->setSorting(0);
314
Result->addColumn(tr("Result"));
315
Result->addColumn(tr("Manual"));
316
Result->setSelectionMode(QListView::Single);
317
Sections->setSelectionMode(QListView::Single);
318
connect(Sections, SIGNAL(selectionChanged(QListViewItem *)),
319
this, SLOT(changeContent(QListViewItem *)));
320
connect(Result, SIGNAL(selectionChanged(QListViewItem *)),
321
this, SLOT(changeContent(QListViewItem *)));
325
Help = new toHelpBrowser(splitter);
328
Help = new QTextBrowser(splitter);
329
Help->mimeSourceFactory()->addFilePath(path());
331
// Help->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred));
332
setCaption(tr("Help Browser"));
334
connect(Help, SIGNAL(textChanged(void)),
335
this, SLOT(removeSelection(void)));
338
button = new QToolButton(LeftArrow, toolbar);
339
connect(Help, SIGNAL(backwardAvailable(bool)),
340
button, SLOT(setEnabled(bool)));
341
button->setEnabled(false);
342
connect(button, SIGNAL(clicked(void)),
343
Help, SLOT(backward(void)));
345
(button, tr("Backward one help page"));
347
button = new QToolButton(RightArrow, toolbar);
348
connect(Help, SIGNAL(forwardAvailable(bool)),
349
button, SLOT(setEnabled(bool)));
350
button->setEnabled(false);
351
connect(button, SIGNAL(clicked(void)),
352
Help, SLOT(forward(void)));
354
(button, tr("Forward one help page"));
356
toolbar->setStretchableWidget(new QLabel(toolbar, TO_KDE_TOOLBAR_WIDGET));
358
std::map<QString, QString> Dsc;
359
Dsc[tr(TOAPPNAME " manual")] = toHelpPath();
360
int tot = HelpTool.config("Number", "-1").toInt();
363
for (int i = 0;i < tot;i++)
365
QString num = QString::number(i);
366
QString dsc = HelpTool.config(num.latin1(), "");
367
num += QString::fromLatin1("file");
368
QString file = HelpTool.config(num.latin1(), "");
373
splitter->setResizeMode(tabs, QSplitter::KeepSize);
374
setGeometry(x(), y(), std::max(width(), 640), std::max(height(), 480));
376
QListViewItem *lastParent = NULL;
377
for (std::map<QString, QString>::iterator i = Dsc.begin();i != Dsc.end();i++)
381
QString path = toHelp::path((*i).second);
382
QString filename = (*i).second;
383
QListViewItem *parent;
384
if ((*i).first == tr("TOra manual"))
386
parent = new QListViewItem(Sections, NULL, (*i).first, QString::null, filename);
391
parent = lastParent = new QListViewItem(Sections, lastParent, (*i).first,
392
QString::null, filename);
393
toHtml file(toReadFile(filename));
397
QListViewItem *last = NULL;
406
dsc += QString::fromLatin1(file.text());
407
dsc = dsc.simplifyWhiteSpace();
412
const char *c = file.tag();
417
href = file.value("href");
427
if (href.find("//") < 0 &&
430
last = new QListViewItem(parent, last, dsc);
432
filename += QString::fromLatin1(href);
433
last->setText(2, filename);
440
else if (!strcmp(c, "dl"))
445
last = new QListViewItem(parent, NULL, QString::fromLatin1("--------"));
452
parent = parent->parent();
454
throw tr("Missing parent, unbalanced dl in help file content");
462
for (QListViewItem *item = Sections->firstChild();item;item = item->nextSibling())
463
Manuals->insertItem(item->text(0));
465
Progress = new QProgressBar(box);
466
Progress->setTotalSteps(Dsc.size());
478
QString toHelp::path(const QString &path)
485
cur.replace(QRegExp(QString::fromLatin1("[^/]+$")), QString::null);
489
void toHelp::displayHelp(const QString &context, QWidget *parent)
492
if (!Window || parent)
493
window = new toHelp(NULL, tr("Help window"), parent);
496
QString file = path();
501
window->Help->openURL(file);
504
if (context.find("htm") >= 0)
505
window->Help->setTextFormat(RichText);
507
window->Help->setTextFormat(AutoText);
508
window->Help->setSource(file);
511
window->removeSelection();
524
void toHelp::displayHelp(QWidget *parent)
526
QWidget *cur = qApp->focusWidget();
529
toHelpContext *ctx = dynamic_cast<toHelpContext *>(cur);
530
if (ctx && !ctx->context().isEmpty())
532
toHelp::displayHelp(ctx->context(), parent);
535
cur = cur->parentWidget();
537
toHelp::displayHelp(QString::fromLatin1("toc.htm"), parent);
540
void toHelp::connectDialog(QDialog *dialog)
542
QAccel *a = new QAccel(dialog);
543
a->connectItem(a->insertItem(toKeySequence(tr("F1", "Dialog|Help"))),
545
SLOT(displayHelp()));
548
void toHelp::changeContent(QListViewItem *item)
551
Help->openURL(item->text(2));
554
disconnect(Help, SIGNAL(textChanged(void)),
555
this, SLOT(removeSelection(void)));
557
if (item->text(2).find("htm") >= 0)
558
Help->setTextFormat(RichText);
560
Help->setTextFormat(AutoText);
561
if (!item->text(2).isEmpty())
562
Help->setSource(item->text(2));
564
connect(Help, SIGNAL(textChanged(void)),
565
this, SLOT(removeSelection(void)));
569
void toHelp::search(void)
574
QStringList words = QStringList::split(QRegExp(QString::fromLatin1("\\s+")), SearchLine->text().lower());
575
if (words.count() == 0)
577
QRegExp strip(QString::fromLatin1("\\d+-\\d+\\s*,\\s+"));
578
QRegExp stripend(QString::fromLatin1(",$"));
580
Progress->setProgress(0);
583
qApp->processEvents();
584
for (QListViewItem *parent = Sections->firstChild();parent;parent = parent->nextSibling())
586
if (Manuals->currentItem() == 0 || parent->text(0) == Manuals->currentText())
588
QString path = toHelp::path(parent->text(2));
589
QString filename = path;
590
filename += QString::fromLatin1("index.htm");
593
toHtml file(toReadFile(filename));
594
std::list<QString> Context;
596
bool aRestart = true;
606
if (!strcmp(file.tag(), "a"))
608
href = file.value("href");
611
else if (href.find("..") >= 0)
614
else if (!strcmp(file.tag(), "dd"))
620
else if (!strcmp(file.tag(), "dl"))
622
toPush(Context, QString::fromLatin1(dsc.simplifyWhiteSpace()));
627
else if (!strcmp(file.tag(), "a"))
629
if (!dsc.isEmpty() &&
633
for (std::list<QString>::iterator i = Context.begin();i != Context.end();i++)
634
if (i != Context.begin() && !(*i).isEmpty())
637
tmp += QString::fromLatin1(", ");
639
tmp += QString::fromLatin1(dsc.simplifyWhiteSpace());
641
url += QString::fromLatin1(href);
646
for (size_t i = 0;i < words.count();i++)
647
if (!tmp.contains(words[i], false))
656
tmp.replace(strip, QString::fromLatin1(" "));
657
tmp.replace(stripend, QString::fromLatin1(" "));
658
QListViewItem *item = new toResultViewItem(Result, NULL, tmp.simplifyWhiteSpace());
659
item->setText(1, parent->text(0));
660
item->setText(2, url);
665
else if (!strcmp(file.tag(), "dl"))
678
Progress->setProgress(steps);
680
qApp->processEvents();
686
void toHelp::setSelection(toListView *lst, const QString &source)
688
disconnect(lst, SIGNAL(selectionChanged(QListViewItem *)),
689
this, SLOT(changeContent(QListViewItem *)));
694
t.replace(QRegExp(QString::fromLatin1("^file:")), QString::fromLatin1(""));
696
QListViewItem *next = NULL;
697
for (QListViewItem *item = lst->firstChild();item;item = next)
700
if ((item->text(2) == t) != bool(item->isSelected()))
702
if (item->text(2) == t)
705
lst->setSelected(item, true);
706
lst->ensureItemVisible(item);
707
for (QListViewItem *parent = item->parent();parent;parent = parent->parent())
708
lst->setOpen(parent, true);
712
lst->setSelected(item, false);
715
if (item->firstChild())
716
next = item->firstChild();
717
else if (item->nextSibling())
719
next = item->nextSibling();
726
next = next->parent();
728
while (next && !next->nextSibling());
730
next = next->nextSibling();
734
connect(lst, SIGNAL(selectionChanged(QListViewItem *)),
735
this, SLOT(changeContent(QListViewItem *)));
740
t.replace(QRegExp(QString::fromLatin1("#[^#]*$")), QString::null);
742
setSelection(lst, t);
746
void toHelp::removeSelection(void)
748
setSelection(Sections, Help->source());
749
setSelection(Result, Help->source());