• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KParts

  • kparts
htmlextension.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 Copyright (C) 2010 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18 */
19
20#include "htmlextension.h"
21
22#include "part.h"
23
24#include <kglobal.h>
25#include <klocalizedstring.h>
26
27
28using namespace KParts;
29
30KParts::HtmlExtension::HtmlExtension(KParts::ReadOnlyPart* parent)
31 : QObject(parent), d(0)
32{
33}
34
35KParts::HtmlExtension::~HtmlExtension()
36{
37}
38
39bool HtmlExtension::hasSelection() const
40{
41 return false;
42}
43
44HtmlExtension * KParts::HtmlExtension::childObject( QObject *obj )
45{
46 return KGlobal::findDirectChild<KParts::HtmlExtension *>(obj);
47}
48
49SelectorInterface::QueryMethods SelectorInterface::supportedQueryMethods() const
50{
51 return KParts::SelectorInterface::None;
52}
53
54class SelectorInterface::ElementPrivate : public QSharedData
55{
56public:
57 QString tag;
58 QHash<QString, QString> attributes;
59};
60
61SelectorInterface::Element::Element()
62 : d(new ElementPrivate)
63{
64}
65
66SelectorInterface::Element::Element(const SelectorInterface::Element& other)
67 : d(other.d)
68{
69}
70
71SelectorInterface::Element::~Element()
72{
73}
74
75bool SelectorInterface::Element::isNull() const
76{
77 return d->tag.isNull();
78}
79
80void SelectorInterface::Element::setTagName(const QString& tag)
81{
82 d->tag = tag;
83}
84
85QString SelectorInterface::Element::tagName() const
86{
87 return d->tag;
88}
89
90void SelectorInterface::Element::setAttribute(const QString& name, const QString& value)
91{
92 d->attributes[name] = value; // insert or replace
93}
94
95QStringList SelectorInterface::Element::attributeNames() const
96{
97 return d->attributes.keys();
98}
99
100QString SelectorInterface::Element::attribute(const QString& name, const QString& defaultValue) const
101{
102 return d->attributes.value(name, defaultValue);
103}
104
105bool SelectorInterface::Element::hasAttribute(const QString& name) const
106{
107 return d->attributes.contains(name);
108}
109
110const char* HtmlSettingsInterface::javascriptAdviceToText(HtmlSettingsInterface::JavaScriptAdvice advice)
111{
112 // NOTE: The use of I18N_NOOP below is intended to allow GUI code to call
113 // i18n on the returned text without affecting use of untranslated text in
114 // config files.
115 switch (advice) {
116 case JavaScriptAccept:
117 return I18N_NOOP("Accept");
118 case JavaScriptReject:
119 return I18N_NOOP("Reject");
120 default:
121 break;
122 }
123
124 return 0;
125}
126
127HtmlSettingsInterface::JavaScriptAdvice HtmlSettingsInterface::textToJavascriptAdvice(const QString& text)
128{
129 JavaScriptAdvice ret = JavaScriptDunno;
130
131 if (!text.isEmpty()) {
132 if (text.compare(QLatin1String("accept"), Qt::CaseInsensitive) == 0) {
133 ret = JavaScriptAccept;
134 } else if (text.compare(QLatin1String("reject"), Qt::CaseInsensitive) == 0) {
135 ret = JavaScriptReject;
136 }
137 }
138
139 return ret;
140}
141
142void HtmlSettingsInterface::splitDomainAdvice(const QString& adviceStr, QString& domain, HtmlSettingsInterface::JavaScriptAdvice& javaAdvice, HtmlSettingsInterface::JavaScriptAdvice& javaScriptAdvice)
143{
144 const QString tmp(adviceStr);
145 const int splitIndex = tmp.indexOf(':');
146
147 if (splitIndex == -1) {
148 domain = adviceStr.toLower();
149 javaAdvice = JavaScriptDunno;
150 javaScriptAdvice = JavaScriptDunno;
151 } else {
152 domain = tmp.left(splitIndex).toLower();
153 const QString adviceString = tmp.mid(splitIndex+1, tmp.length());
154 const int splitIndex2 = adviceString.indexOf(QLatin1Char(':'));
155 if (splitIndex2 == -1) {
156 // Java advice only
157 javaAdvice = textToJavascriptAdvice(adviceString);
158 javaScriptAdvice = JavaScriptDunno;
159 } else {
160 // Java and JavaScript advice
161 javaAdvice = textToJavascriptAdvice(adviceString.left(splitIndex2));
162 javaScriptAdvice = textToJavascriptAdvice(adviceString.mid(splitIndex2+1,
163 adviceString.length()));
164 }
165 }
166}
KParts::HtmlExtension
an extension for KParts to provide HTML-related features
Definition: htmlextension.h:46
KParts::HtmlExtension::~HtmlExtension
~HtmlExtension()
Definition: htmlextension.cpp:35
KParts::HtmlExtension::hasSelection
virtual bool hasSelection() const
Returns true if portions of the content in the part that implements this extension are selected.
Definition: htmlextension.cpp:39
KParts::HtmlExtension::HtmlExtension
HtmlExtension(KParts::ReadOnlyPart *parent)
Definition: htmlextension.cpp:30
KParts::HtmlExtension::childObject
static HtmlExtension * childObject(QObject *obj)
Queries obj for a child object which inherits from this HtmlExtension class.
Definition: htmlextension.cpp:44
KParts::HtmlSettingsInterface::splitDomainAdvice
static void splitDomainAdvice(const QString &text, QString &domain, JavaScriptAdvice &javaAdvice, JavaScriptAdvice &javaScriptAdvice)
A convenience function that splits text into domain, javaAdvice and jScriptAdvice.
Definition: htmlextension.cpp:142
KParts::HtmlSettingsInterface::javascriptAdviceToText
static const char * javascriptAdviceToText(JavaScriptAdvice advice)
A convenience function Returns the text for the given JavascriptAdvice advice.
Definition: htmlextension.cpp:110
KParts::HtmlSettingsInterface::textToJavascriptAdvice
static JavaScriptAdvice textToJavascriptAdvice(const QString &text)
A convenience function that returns the javascript advice for text.
Definition: htmlextension.cpp:127
KParts::HtmlSettingsInterface::JavaScriptAdvice
JavaScriptAdvice
This enum specifies whether Java/JavaScript execution is allowed.
Definition: htmlextension.h:270
KParts::ReadOnlyPart
Base class for any "viewer" part.
Definition: part.h:489
KParts::SelectorInterface::Element
Definition: htmlextension.h:149
KParts::SelectorInterface::Element::attribute
QString attribute(const QString &name, const QString &defaultValue=QString()) const
Returns the attribute with the given name.
Definition: htmlextension.cpp:100
KParts::SelectorInterface::Element::isNull
bool isNull() const
Returns true if the element is null ; otherwise returns false.
Definition: htmlextension.cpp:75
KParts::SelectorInterface::Element::~Element
~Element()
Destructor.
Definition: htmlextension.cpp:71
KParts::SelectorInterface::Element::Element
Element()
Constructor.
Definition: htmlextension.cpp:61
KParts::SelectorInterface::Element::tagName
QString tagName() const
Returns the tag name of this element.
Definition: htmlextension.cpp:85
KParts::SelectorInterface::Element::setTagName
void setTagName(const QString &tag)
Sets the tag name of this element.
Definition: htmlextension.cpp:80
KParts::SelectorInterface::Element::setAttribute
void setAttribute(const QString &name, const QString &value)
Adds an attribute with the given name and value.
Definition: htmlextension.cpp:90
KParts::SelectorInterface::Element::hasAttribute
bool hasAttribute(const QString &name) const
Returns true if the attribute with the given name exists.
Definition: htmlextension.cpp:105
KParts::SelectorInterface::Element::attributeNames
QStringList attributeNames() const
Returns the list of attributes in this element.
Definition: htmlextension.cpp:95
KParts::SelectorInterface::None
@ None
Definition: htmlextension.h:99
KParts::SelectorInterface::supportedQueryMethods
virtual QueryMethods supportedQueryMethods() const
Returns the supported query methods.
Definition: htmlextension.cpp:49
QHash
QObject
htmlextension.h
defaultValue
QString defaultValue(const QString &t)
kglobal.h
klocalizedstring.h
I18N_NOOP
#define I18N_NOOP(x)
KParts
name
const char * name(StandardAction id)
part.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KParts

Skip menu "KParts"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal