~ubuntu-branches/ubuntu/wily/tora/wily-proposed

« back to all changes in this revision

Viewing changes to src/tohelp.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Albin Tonnerre
  • Date: 2007-05-29 13:13:36 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529131336-85ygaddivvmkd3xc
Tags: 1.3.21pre22-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules: call dh_iconcache
  - Remove g++ build dependency
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****
 
2
*
 
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
 
6
 
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.
 
11
 
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.
 
16
 
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.
 
20
*
 
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.
 
25
*
 
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.
 
31
*
 
32
*      You may link this product with any GPL'd Qt library such as Qt/Free
 
33
*
 
34
* All trademarks belong to their respective owners.
 
35
*
 
36
*****/
 
37
 
 
38
#include "utils.h"
 
39
 
 
40
#include "toconf.h"
 
41
#include "tohelp.h"
 
42
#include "tohtml.h"
 
43
#include "tomain.h"
 
44
#include "toresultview.h"
 
45
#include "totool.h"
 
46
 
 
47
#ifdef TO_KDE
 
48
#include <kfiledialog.h>
 
49
#include <khtml_part.h>
 
50
#endif
 
51
 
 
52
#include <qaccel.h>
 
53
#include <qcombobox.h>
 
54
#include <qdir.h>
 
55
#include <qfiledialog.h>
 
56
#include <qfileinfo.h>
 
57
#include <qlabel.h>
 
58
#include <qlayout.h>
 
59
#include <qlineedit.h>
 
60
#include <qmessagebox.h>
 
61
#include <qprogressbar.h>
 
62
#include <qpushbutton.h>
 
63
#include <qregexp.h>
 
64
#include <qsplitter.h>
 
65
#include <qtabwidget.h>
 
66
#include <qtextbrowser.h>
 
67
#include <qtextview.h>
 
68
#include <qtimer.h>
 
69
#include <qtoolbar.h>
 
70
#include <qtoolbutton.h>
 
71
#include <qtooltip.h>
 
72
#include <qvbox.h>
 
73
 
 
74
#include "tohelp.moc"
 
75
#include "tohelpaddfileui.moc"
 
76
#include "tohelpsetupui.moc"
 
77
 
 
78
#ifdef TO_KDE
 
79
#include "tohelpbrowser.h"
 
80
#include "tohelpbrowser.moc"
 
81
 
 
82
toHelpBrowser::toHelpBrowser(QWidget *parent, const char *name)
 
83
        : KHTMLPart(parent, name)
 
84
{
 
85
    connect(browserExtension(),
 
86
            SIGNAL(openURLRequest(const KURL &, const KParts::URLArgs &)),
 
87
            this,
 
88
            SLOT(openURLRequest(const KURL &, const KParts::URLArgs &)));
 
89
}
 
90
 
 
91
void toHelpBrowser::openURLRequest(const KURL &url, const KParts::URLArgs &)
 
92
{
 
93
    emit textChanged();
 
94
    openURL(url);
 
95
}
 
96
 
 
97
bool toHelpBrowser::openURL(const KURL &url)
 
98
{
 
99
    if (Forward.size() > 0)
 
100
    {
 
101
        emit forwardAvailable(false);
 
102
        Forward.clear();
 
103
    }
 
104
    if (Backward.size() == 1)
 
105
        emit backwardAvailable(true);
 
106
    toPush(Backward, url.url());
 
107
    bool ret = KHTMLPart::openURL(url);
 
108
    emit textChanged();
 
109
    return ret;
 
110
}
 
111
 
 
112
void toHelpBrowser::backward(void)
 
113
{
 
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);
 
121
    emit textChanged();
 
122
}
 
123
 
 
124
void toHelpBrowser::forward(void)
 
125
{
 
126
    QString url = toPop(Forward);
 
127
    if (Forward.empty())
 
128
        emit forwardAvailable(false);
 
129
    if (Backward.size() == 1)
 
130
        emit backwardAvailable(true);
 
131
    toPush(Backward, url);
 
132
    KHTMLPart::openURL(url);
 
133
    emit textChanged();
 
134
}
 
135
 
 
136
QString toHelpBrowser::source(void)
 
137
{
 
138
    if ( Backward.empty() )
 
139
        return QString::null;
 
140
    return (*Backward.rbegin());
 
141
}
 
142
 
 
143
#endif
 
144
 
 
145
toHelp *toHelp::Window;
 
146
 
 
147
class toHelpAddFile : public toHelpAddFileUI
 
148
{
 
149
public:
 
150
    toHelpAddFile(QWidget *parent, const char *name = 0)
 
151
            : toHelpAddFileUI(parent, name, true)
 
152
    {
 
153
        OkButton->setEnabled(false);
 
154
        toHelp::connectDialog(this);
 
155
    }
 
156
    virtual void browse(void)
 
157
    {
 
158
        QString filename = toOpenFilename(Filename->text(), QString::fromLatin1("toc.htm*"), this);
 
159
        if (!filename.isEmpty())
 
160
            Filename->setText(filename);
 
161
    }
 
162
    virtual void valid(void)
 
163
    {
 
164
        if (Filename->text().isEmpty() || Root->text().isEmpty())
 
165
            OkButton->setEnabled(false);
 
166
        else
 
167
            OkButton->setEnabled(true);
 
168
    }
 
169
};
 
170
 
 
171
class toHelpPrefs : public toHelpSetupUI, public toSettingTab
 
172
{
 
173
    toTool *Tool;
 
174
public:
 
175
    toHelpPrefs(toTool *tool, QWidget *parent, const char *name = 0)
 
176
            : toHelpSetupUI(parent, name), toSettingTab("additionalhelp.html"), Tool(tool)
 
177
    {
 
178
        int tot = Tool->config("Number", "-1").toInt();
 
179
        if (tot != -1)
 
180
        {
 
181
            for (int i = 0;i < tot;i++)
 
182
            {
 
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);
 
188
            }
 
189
        }
 
190
    }
 
191
    virtual void saveSetting(void)
 
192
    {
 
193
        int i = 0;
 
194
        for (QListViewItem *item = FileList->firstChild();item;item = item->nextSibling())
 
195
        {
 
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));
 
200
            i++;
 
201
        }
 
202
        Tool->setConfig("Number", QString::number(i));
 
203
        delete toHelp::Window;
 
204
    }
 
205
    virtual void addFile(void)
 
206
    {
 
207
        toHelpAddFile file(this);
 
208
        if (file.exec())
 
209
            new QListViewItem(FileList, file.Root->text(), file.Filename->text());
 
210
    }
 
211
    virtual void delFile(void)
 
212
    {
 
213
        delete FileList->selectedItem();
 
214
    }
 
215
    virtual void oracleManuals(void)
 
216
    {
 
217
        QString filename = toOpenFilename(QString::null, QString::fromLatin1("*index.htm*"), this);
 
218
        try
 
219
        {
 
220
            toHtml file(toReadFile(filename));
 
221
            QString dsc;
 
222
            bool inDsc = false;
 
223
            QRegExp isToc(QString::fromLatin1("toc\\.html?$"));
 
224
            while (!file.eof())
 
225
            {
 
226
                file.nextToken();
 
227
                if (file.isTag())
 
228
                {
 
229
                    if (file.open() && !strcmp(file.tag(), "a"))
 
230
                    {
 
231
                        QString href = toHelp::path(filename);
 
232
                        href += QString::fromLatin1(file.value("href"));
 
233
                        if (!href.isEmpty() &&
 
234
                                !dsc.isEmpty() &&
 
235
                                href.find(isToc) >= 0 &&
 
236
                                file.value("title"))
 
237
                        {
 
238
                            new QListViewItem(FileList, dsc.simplifyWhiteSpace(), href);
 
239
                            inDsc = false;
 
240
                            dsc = QString::null;
 
241
                        }
 
242
                    }
 
243
                    else if (file.open() && (!strcmp(file.tag(), "dd") || !strcmp(file.tag(), "book")))
 
244
                    {
 
245
                        dsc = QString::null;
 
246
                        inDsc = true;
 
247
                    }
 
248
                }
 
249
                else if (inDsc)
 
250
                    dsc += QString::fromLatin1(file.text());
 
251
            }
 
252
        }
 
253
        catch (const QString &str)
 
254
        {
 
255
            TOMessageBox::warning(toMainWidget(), qApp->translate("toHelpPrefs", "File error"), str);
 
256
        }
 
257
    }
 
258
};
 
259
 
 
260
QWidget *toHelpTool::configurationTab(QWidget *parent)
 
261
{
 
262
    return new toHelpPrefs(this, parent);
 
263
}
 
264
 
 
265
void toHelpTool::displayHelp(void)
 
266
{
 
267
    QWidget *cur = qApp->focusWidget();
 
268
    while (cur)
 
269
    {
 
270
        QDialog *dlg = dynamic_cast<QDialog *>(cur);
 
271
        if (dlg)
 
272
        {
 
273
            toHelp::displayHelp(dlg);
 
274
            return ;
 
275
        }
 
276
        cur = cur->parentWidget();
 
277
    }
 
278
    // No dialog found
 
279
    toHelp::displayHelp();
 
280
}
 
281
 
 
282
static toHelpTool HelpTool;
 
283
 
 
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)
 
289
{
 
290
    if (!modal)
 
291
        Window = this;
 
292
    QBoxLayout *l = new QVBoxLayout(this);
 
293
    QToolBar *toolbar = toAllocBar(this, tr("Help Navigation"));
 
294
    l->addWidget(toolbar);
 
295
 
 
296
    QSplitter *splitter = new QSplitter(Horizontal, this);
 
297
    l->addWidget(splitter);
 
298
 
 
299
    QTabWidget *tabs = new QTabWidget(splitter);
 
300
    Sections = new toListView(tabs);
 
301
    Sections->addColumn(tr("Contents"));
 
302
    Sections->setSorting( -1);
 
303
    Sections->setRootIsDecorated(true);
 
304
 
 
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 *)));
 
322
 
 
323
#ifdef TO_KDE
 
324
 
 
325
    Help = new toHelpBrowser(splitter);
 
326
#else
 
327
 
 
328
    Help = new QTextBrowser(splitter);
 
329
    Help->mimeSourceFactory()->addFilePath(path());
 
330
#endif
 
331
    // Help->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred));
 
332
    setCaption(tr("Help Browser"));
 
333
 
 
334
    connect(Help, SIGNAL(textChanged(void)),
 
335
            this, SLOT(removeSelection(void)));
 
336
 
 
337
    QToolButton *button;
 
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)));
 
344
    QToolTip::add
 
345
        (button, tr("Backward one help page"));
 
346
 
 
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)));
 
353
    QToolTip::add
 
354
        (button, tr("Forward one help page"));
 
355
 
 
356
    toolbar->setStretchableWidget(new QLabel(toolbar, TO_KDE_TOOLBAR_WIDGET));
 
357
 
 
358
    std::map<QString, QString> Dsc;
 
359
    Dsc[tr(TOAPPNAME " manual")] = toHelpPath();
 
360
    int tot = HelpTool.config("Number", "-1").toInt();
 
361
    if (tot != -1)
 
362
    {
 
363
        for (int i = 0;i < tot;i++)
 
364
        {
 
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(), "");
 
369
            Dsc[dsc] = file;
 
370
        }
 
371
    }
 
372
 
 
373
    splitter->setResizeMode(tabs, QSplitter::KeepSize);
 
374
    setGeometry(x(), y(), std::max(width(), 640), std::max(height(), 480));
 
375
 
 
376
    QListViewItem *lastParent = NULL;
 
377
    for (std::map<QString, QString>::iterator i = Dsc.begin();i != Dsc.end();i++)
 
378
    {
 
379
        try
 
380
        {
 
381
            QString path = toHelp::path((*i).second);
 
382
            QString filename = (*i).second;
 
383
            QListViewItem *parent;
 
384
            if ((*i).first == tr("TOra manual"))
 
385
            {
 
386
                parent = new QListViewItem(Sections, NULL, (*i).first, QString::null, filename);
 
387
                if (!lastParent)
 
388
                    lastParent = parent;
 
389
            }
 
390
            else
 
391
                parent = lastParent = new QListViewItem(Sections, lastParent, (*i).first,
 
392
                                                        QString::null, filename);
 
393
            toHtml file(toReadFile(filename));
 
394
            bool inA = false;
 
395
            QString dsc;
 
396
            QCString href;
 
397
            QListViewItem *last = NULL;
 
398
            while (!file.eof())
 
399
            {
 
400
                file.nextToken();
 
401
 
 
402
                if (!file.isTag())
 
403
                {
 
404
                    if (inA)
 
405
                    {
 
406
                        dsc += QString::fromLatin1(file.text());
 
407
                        dsc = dsc.simplifyWhiteSpace();
 
408
                    }
 
409
                }
 
410
                else
 
411
                {
 
412
                    const char *c = file.tag();
 
413
                    if (!strcmp(c, "a"))
 
414
                    {
 
415
                        if (file.open())
 
416
                        {
 
417
                            href = file.value("href");
 
418
                            if (!href.isEmpty())
 
419
                                inA = true;
 
420
                        }
 
421
                        else
 
422
                        {
 
423
                            if (inA &&
 
424
                                    !dsc.isEmpty() &&
 
425
                                    !href.isEmpty())
 
426
                            {
 
427
                                if (href.find("//") < 0 &&
 
428
                                        href.find("..") < 0)
 
429
                                {
 
430
                                    last = new QListViewItem(parent, last, dsc);
 
431
                                    filename = path;
 
432
                                    filename += QString::fromLatin1(href);
 
433
                                    last->setText(2, filename);
 
434
                                }
 
435
                                dsc = "";
 
436
                            }
 
437
                            inA = false;
 
438
                        }
 
439
                    }
 
440
                    else if (!strcmp(c, "dl"))
 
441
                    {
 
442
                        if (file.open())
 
443
                        {
 
444
                            if (!last)
 
445
                                last = new QListViewItem(parent, NULL, QString::fromLatin1("--------"));
 
446
                            parent = last;
 
447
                            last = NULL;
 
448
                        }
 
449
                        else
 
450
                        {
 
451
                            last = parent;
 
452
                            parent = parent->parent();
 
453
                            if (!parent)
 
454
                                throw tr("Missing parent, unbalanced dl in help file content");
 
455
                        }
 
456
                    }
 
457
                }
 
458
            }
 
459
        }
 
460
        TOCATCH
 
461
    }
 
462
    for (QListViewItem *item = Sections->firstChild();item;item = item->nextSibling())
 
463
        Manuals->insertItem(item->text(0));
 
464
 
 
465
    Progress = new QProgressBar(box);
 
466
    Progress->setTotalSteps(Dsc.size());
 
467
    Progress->hide();
 
468
 
 
469
    Searching = false;
 
470
}
 
471
 
 
472
toHelp::~toHelp()
 
473
{
 
474
    if (Window == this)
 
475
        Window = NULL;
 
476
}
 
477
 
 
478
QString toHelp::path(const QString &path)
 
479
{
 
480
    QString cur;
 
481
    if (path.isNull())
 
482
        cur = toHelpPath();
 
483
    else
 
484
        cur = path;
 
485
    cur.replace(QRegExp(QString::fromLatin1("[^/]+$")), QString::null);
 
486
    return cur;
 
487
}
 
488
 
 
489
void toHelp::displayHelp(const QString &context, QWidget *parent)
 
490
{
 
491
    toHelp *window;
 
492
    if (!Window || parent)
 
493
        window = new toHelp(NULL, tr("Help window"), parent);
 
494
    else
 
495
        window = Window;
 
496
    QString file = path();
 
497
 
 
498
    file += context;
 
499
#ifdef TO_KDE
 
500
 
 
501
    window->Help->openURL(file);
 
502
#else
 
503
 
 
504
    if (context.find("htm") >= 0)
 
505
        window->Help->setTextFormat(RichText);
 
506
    else
 
507
        window->Help->setTextFormat(AutoText);
 
508
    window->Help->setSource(file);
 
509
#  if 0 // Necessary?
 
510
 
 
511
    window->removeSelection();
 
512
#  endif
 
513
#endif
 
514
 
 
515
    if (parent)
 
516
    {
 
517
        window->exec();
 
518
        delete window;
 
519
    }
 
520
    else
 
521
        window->show();
 
522
}
 
523
 
 
524
void toHelp::displayHelp(QWidget *parent)
 
525
{
 
526
    QWidget *cur = qApp->focusWidget();
 
527
    while (cur)
 
528
    {
 
529
        toHelpContext *ctx = dynamic_cast<toHelpContext *>(cur);
 
530
        if (ctx && !ctx->context().isEmpty())
 
531
        {
 
532
            toHelp::displayHelp(ctx->context(), parent);
 
533
            return ;
 
534
        }
 
535
        cur = cur->parentWidget();
 
536
    }
 
537
    toHelp::displayHelp(QString::fromLatin1("toc.htm"), parent);
 
538
}
 
539
 
 
540
void toHelp::connectDialog(QDialog *dialog)
 
541
{
 
542
    QAccel *a = new QAccel(dialog);
 
543
    a->connectItem(a->insertItem(toKeySequence(tr("F1", "Dialog|Help"))),
 
544
                   &HelpTool,
 
545
                   SLOT(displayHelp()));
 
546
}
 
547
 
 
548
void toHelp::changeContent(QListViewItem *item)
 
549
{
 
550
#ifdef TO_KDE
 
551
    Help->openURL(item->text(2));
 
552
#else
 
553
 
 
554
    disconnect(Help, SIGNAL(textChanged(void)),
 
555
               this, SLOT(removeSelection(void)));
 
556
 
 
557
    if (item->text(2).find("htm") >= 0)
 
558
        Help->setTextFormat(RichText);
 
559
    else
 
560
        Help->setTextFormat(AutoText);
 
561
    if (!item->text(2).isEmpty())
 
562
        Help->setSource(item->text(2));
 
563
 
 
564
    connect(Help, SIGNAL(textChanged(void)),
 
565
            this, SLOT(removeSelection(void)));
 
566
#endif
 
567
}
 
568
 
 
569
void toHelp::search(void)
 
570
{
 
571
    if (Searching)
 
572
        return ;
 
573
    Result->clear();
 
574
    QStringList words = QStringList::split(QRegExp(QString::fromLatin1("\\s+")), SearchLine->text().lower());
 
575
    if (words.count() == 0)
 
576
        return ;
 
577
    QRegExp strip(QString::fromLatin1("\\d+-\\d+\\s*,\\s+"));
 
578
    QRegExp stripend(QString::fromLatin1(",$"));
 
579
    int steps = 1;
 
580
    Progress->setProgress(0);
 
581
    Progress->show();
 
582
    Searching = true;
 
583
    qApp->processEvents();
 
584
    for (QListViewItem *parent = Sections->firstChild();parent;parent = parent->nextSibling())
 
585
    {
 
586
        if (Manuals->currentItem() == 0 || parent->text(0) == Manuals->currentText())
 
587
        {
 
588
            QString path = toHelp::path(parent->text(2));
 
589
            QString filename = path;
 
590
            filename += QString::fromLatin1("index.htm");
 
591
            try
 
592
            {
 
593
                toHtml file(toReadFile(filename));
 
594
                std::list<QString> Context;
 
595
                bool inDsc = false;
 
596
                bool aRestart = true;
 
597
                QCString dsc;
 
598
                QCString href;
 
599
                while (!file.eof())
 
600
                {
 
601
                    file.nextToken();
 
602
                    if (file.isTag())
 
603
                    {
 
604
                        if (file.open())
 
605
                        {
 
606
                            if (!strcmp(file.tag(), "a"))
 
607
                            {
 
608
                                href = file.value("href");
 
609
                                if (href[0] == '#')
 
610
                                    href = "";
 
611
                                else if (href.find("..") >= 0)
 
612
                                    href = "";
 
613
                            }
 
614
                            else if (!strcmp(file.tag(), "dd"))
 
615
                            {
 
616
                                inDsc = true;
 
617
                                aRestart = false;
 
618
                                href = dsc = "";
 
619
                            }
 
620
                            else if (!strcmp(file.tag(), "dl"))
 
621
                            {
 
622
                                toPush(Context, QString::fromLatin1(dsc.simplifyWhiteSpace()));
 
623
                                href = dsc = "";
 
624
                                inDsc = true;
 
625
                            }
 
626
                        }
 
627
                        else if (!strcmp(file.tag(), "a"))
 
628
                        {
 
629
                            if (!dsc.isEmpty() &&
 
630
                                    !href.isEmpty())
 
631
                            {
 
632
                                QString tmp;
 
633
                                for (std::list<QString>::iterator i = Context.begin();i != Context.end();i++)
 
634
                                    if (i != Context.begin() && !(*i).isEmpty())
 
635
                                    {
 
636
                                        tmp += *i;
 
637
                                        tmp += QString::fromLatin1(", ");
 
638
                                    }
 
639
                                tmp += QString::fromLatin1(dsc.simplifyWhiteSpace());
 
640
                                QString url = path;
 
641
                                url += QString::fromLatin1(href);
 
642
                                aRestart = true;
 
643
 
 
644
                                bool incl = true;
 
645
                                {
 
646
                                    for (size_t i = 0;i < words.count();i++)
 
647
                                        if (!tmp.contains(words[i], false))
 
648
                                        {
 
649
                                            incl = false;
 
650
                                            break;
 
651
                                        }
 
652
                                }
 
653
 
 
654
                                if (incl)
 
655
                                {
 
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);
 
661
                                }
 
662
                                href = "";
 
663
                            }
 
664
                        }
 
665
                        else if (!strcmp(file.tag(), "dl"))
 
666
                        {
 
667
                            toPop(Context);
 
668
                        }
 
669
                    }
 
670
                    else if (inDsc)
 
671
                    {
 
672
                        dsc += file.text();
 
673
                    }
 
674
                }
 
675
            }
 
676
            TOCATCH
 
677
        }
 
678
        Progress->setProgress(steps);
 
679
        steps++;
 
680
        qApp->processEvents();
 
681
    }
 
682
    Progress->hide();
 
683
    Searching = false;
 
684
}
 
685
 
 
686
void toHelp::setSelection(toListView *lst, const QString &source)
 
687
{
 
688
    disconnect(lst, SIGNAL(selectionChanged(QListViewItem *)),
 
689
               this, SLOT(changeContent(QListViewItem *)));
 
690
 
 
691
    bool any = false;
 
692
 
 
693
    QString t = source;
 
694
    t.replace(QRegExp(QString::fromLatin1("^file:")), QString::fromLatin1(""));
 
695
 
 
696
    QListViewItem *next = NULL;
 
697
    for (QListViewItem *item = lst->firstChild();item;item = next)
 
698
    {
 
699
 
 
700
        if ((item->text(2) == t) != bool(item->isSelected()))
 
701
        {
 
702
            if (item->text(2) == t)
 
703
            {
 
704
                any = true;
 
705
                lst->setSelected(item, true);
 
706
                lst->ensureItemVisible(item);
 
707
                for (QListViewItem *parent = item->parent();parent;parent = parent->parent())
 
708
                    lst->setOpen(parent, true);
 
709
                break;
 
710
            }
 
711
            else
 
712
                lst->setSelected(item, false);
 
713
        }
 
714
 
 
715
        if (item->firstChild())
 
716
            next = item->firstChild();
 
717
        else if (item->nextSibling())
 
718
        {
 
719
            next = item->nextSibling();
 
720
        }
 
721
        else
 
722
        {
 
723
            next = item;
 
724
            do
 
725
            {
 
726
                next = next->parent();
 
727
            }
 
728
            while (next && !next->nextSibling());
 
729
            if (next)
 
730
                next = next->nextSibling();
 
731
        }
 
732
    }
 
733
 
 
734
    connect(lst, SIGNAL(selectionChanged(QListViewItem *)),
 
735
            this, SLOT(changeContent(QListViewItem *)));
 
736
 
 
737
    if (!any)
 
738
    {
 
739
        QString t = source;
 
740
        t.replace(QRegExp(QString::fromLatin1("#[^#]*$")), QString::null);
 
741
        if (t != source)
 
742
            setSelection(lst, t);
 
743
    }
 
744
}
 
745
 
 
746
void toHelp::removeSelection(void)
 
747
{
 
748
    setSelection(Sections, Help->source());
 
749
    setSelection(Result, Help->source());
 
750
}