summaryrefslogtreecommitdiffstats
path: root/parts/documentation/docutils.cpp
blob: cce369328beab8f4913c976f03a9cd4948860484 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/***************************************************************************
 *   Copyright (C) 2004 by Alexander Dymo                                  *
 *   cloudtemple@mksat.net                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "docutils.h"

#include <kurlrequester.h>
#include <kurlcompletion.h>
#include <klineedit.h>
#include <kcombobox.h>
#include <kpopupmenu.h>
#include <klocale.h>
#include <kstringhandler.h>

#include <kdevpartcontroller.h>

#include "kdevdocumentationplugin.h"
#include "documentation_part.h"

QString DocUtils::noEnvURL(const QString &url)
{
    return KURLCompletion::replacedPath(url, true, true);
}

KURL DocUtils::noEnvURL(const KURL &url)
{
    QString replaced = KURLCompletion::replacedPath(url.url(), true, true);
    KURL kurl(replaced);
    kurl.setQuery(url.query());
    kurl.setRef(url.ref());
    return kurl;
}

QString DocUtils::envURL(KURLRequester *req)
{
    if (req->lineEdit())
        return req->lineEdit()->text();
    else if (req->comboBox())
        return req->comboBox()->currentText();
    else
        return req->url();
}

void DocUtils::docItemPopup(DocumentationPart *part, DocumentationItem *docItem,
    const QPoint &pos, bool showBookmark, bool showSearch, int titleCol)
{
    docItemPopup(part, docItem->text(titleCol), docItem->url(), pos, showBookmark, showSearch);
}

void DocUtils::docItemPopup(DocumentationPart *part, IndexItem *docItem, const QPoint &pos,
    bool showBookmark, bool showSearch)
{
    //FIXME: index item can have more than one url, what to do?
    KURL url;
    if (docItem->urls().count() > 0)
        url = docItem->urls().first().second;
    docItemPopup(part, docItem->text(), url, pos, showBookmark, showSearch);
}

void DocUtils::docItemPopup(DocumentationPart *part, const QString &title, const KURL &url,
    const QPoint &pos, bool showBookmark, bool showSearch)
{
    KPopupMenu menu;
    menu.insertTitle(i18n("Documentation"));
    menu.insertItem(i18n("Open in Current Tab"), 1);
    menu.insertItem(i18n("Open in New Tab"), 2);
    if (showBookmark)
    {
        menu.insertSeparator();   
        menu.insertItem(i18n("Bookmark This Location"), 3);
    }
    if (showSearch)
    {
        menu.insertSeparator();
        menu.insertItem(QString("%1: %2").arg(i18n("Search")).arg(KStringHandler::csqueeze(title,20)), 4);
    }
    
    switch (menu.exec(pos))
    {
        case 1: part->partController()->showDocument(url); break;
        case 2: part->partController()->showDocument(url, true); break;
        case 3: part->emitBookmarkLocation(title, url); break;
        case 4: part->searchInDocumentation(title); break;
    }
}