summaryrefslogtreecommitdiffstats
path: root/konq-plugins/rellinks/plugin_rellinks.h
blob: 3b58cdcfcacc7698a28c7340df039eaaa3448d7a (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/***************************************************************************
 *   Copyright (C) 2002, Anders Lund <anders@alweb.dk>                     *
 *   Copyright (C) 2003, 2004, Franck Quélain <shift@free.fr>              *
 *   Copyright (C) 2004, Kevin Krammer <kevin.krammer@gmx.at>              *
 *   Copyright (C) 2004, 2005, Oliviet Goffart <ogoffart @ kde.org>        *
 *                                                                         *
 *   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  02110-1301, USA.             *
 ***************************************************************************/


#ifndef _PLUGIN_RELLINKS_H_
#define _PLUGIN_RELLINKS_H_

/*
   This plugin queries the current HTML document for LINK elements.

   This plugin create a toolbar similar to the Site Navigation Bar of Mozilla
*/

// TQt includes
#include <tqmap.h>

// KDE includes
#include <tdeparts/plugin.h>
#include <dom/dom_string.h>

// type definitions
typedef TQMap<int,DOM::Element> DOMElementMap;
typedef TQMap<TQString, TDEAction*> TDEActionMap;
typedef TQMap<TQString, TDEActionMenu*> TDEActionMenuMap;

// forward declarations
class TDEActionMenu;
class TDEHTMLPart;
class TDEHTMLView;
class TDEToolBar;
class KURL;
class TQTimer;

/**
 * KPart plugin adding document relations toolbar to Konqueror
 * @author Franck Quélain
 * @author Anders Lund
 */
class RelLinksPlugin : public KParts::Plugin {
    TQ_OBJECT
  
public:
    /** Constructor */
    RelLinksPlugin( TQObject *parent, const char *name, const TQStringList & );
    /** Destructor */
    virtual ~RelLinksPlugin();

    bool eventFilter(TQObject *watched, TQEvent* event);

private slots:
    void delayedSetup();

    /**
     * TDEHTMLPart has created a new document, disable actions and
     * start polling for links
     */
    void newDocument();

    /**
     * TDEHTMLPart has finished loading, stop the poller and
     * parse the document a last time.
     */
    void loadingFinished();

    /**
     * Update the toolbar (Parse the document again)
     */
    void updateToolbar();


    void goHome();
    void goUp();
    void goFirst();
    void goPrevious();
    void goNext();
    void goLast();
    void goContents();
    void goIndex();
    void goGlossary();
    void goHelp();
    void goSearch();
    void goCopyright();
    void goAuthor();

    void goBookmark(int id);
    void goChapter(int id);
    void goSection(int id);
    void goSubsection(int id);
    void goAppendix(int id);
    void goAlternate(int id);
    void goAllElements(int id);

private:

    /**
     * Try to guess some relations from the url, if the document doesn't contains relations
	 * example:   http://example.com/page4.html
	 * the "next" relation will be set to page5.html
	 */
	void guessRelations();
	
    /**
     * Function used to get link type of a relation.
     * For example "prev" is of type "previous" and "toc" is of type "contents"
     * If the relation must be ignored return NULL.
     * If the relation is unknow return the input relation type.
     * @param lrel Previous relation name
     * @return New relation name
     */
    TQString getLinkType(const TQString &lrel);

    /**
     * Function used to return the "rel" equivalent of "rev" link type
     * If the equivalent is not found return NULL
     * @param rev Inverse relation name
     * @return Equivalent relation name
     */
    TQString transformRevToRel(const TQString &rev) ;

    /**
     * Function used to disable all the item of the toolbar
     */
    void disableAll();

    /**
     * Go to the link
     * @param rel Relation name
     * @param id Identifier of the menu item
     */
    void goToLink(const TQString & rel, int id=0);

private:
    TDEHTMLPart* m_part;
    TDEHTMLView* m_view;
	bool m_viewVisible;

    TDEActionMenu *m_document;
    TDEActionMenu *m_more;
    TDEActionMenu *m_links;

    /** Map of TDEAction */
    TDEActionMap tdeaction_map;
    /** Map of TDEActionMenu */
    TDEActionMenuMap tdeactionmenu_map;

    /** Map of all the link element which can be managed by rellinks */
    TQMap<TQString,DOMElementMap> element_map;

    TQTimer* m_pollTimer;
};

#endif // _PLUGIN_RELLINKS_H_