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

KParts

  • sources
  • kde-4.14
  • kdelibs
  • 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 
28 using namespace KParts;
29 
30 KParts::HtmlExtension::HtmlExtension(KParts::ReadOnlyPart* parent)
31  : QObject(parent), d(0)
32 {
33 }
34 
35 KParts::HtmlExtension::~HtmlExtension()
36 {
37 }
38 
39 bool HtmlExtension::hasSelection() const
40 {
41  return false;
42 }
43 
44 HtmlExtension * KParts::HtmlExtension::childObject( QObject *obj )
45 {
46  return KGlobal::findDirectChild<KParts::HtmlExtension *>(obj);
47 }
48 
49 SelectorInterface::QueryMethods SelectorInterface::supportedQueryMethods() const
50 {
51  return KParts::SelectorInterface::None;
52 }
53 
54 class SelectorInterface::ElementPrivate : public QSharedData
55 {
56 public:
57  QString tag;
58  QHash<QString, QString> attributes;
59 };
60 
61 SelectorInterface::Element::Element()
62  : d(new ElementPrivate)
63 {
64 }
65 
66 SelectorInterface::Element::Element(const SelectorInterface::Element& other)
67  : d(other.d)
68 {
69 }
70 
71 SelectorInterface::Element::~Element()
72 {
73 }
74 
75 bool SelectorInterface::Element::isNull() const
76 {
77  return d->tag.isNull();
78 }
79 
80 void SelectorInterface::Element::setTagName(const QString& tag)
81 {
82  d->tag = tag;
83 }
84 
85 QString SelectorInterface::Element::tagName() const
86 {
87  return d->tag;
88 }
89 
90 void SelectorInterface::Element::setAttribute(const QString& name, const QString& value)
91 {
92  d->attributes[name] = value; // insert or replace
93 }
94 
95 QStringList SelectorInterface::Element::attributeNames() const
96 {
97  return d->attributes.keys();
98 }
99 
100 QString SelectorInterface::Element::attribute(const QString& name, const QString& defaultValue) const
101 {
102  return d->attributes.value(name, defaultValue);
103 }
104 
105 bool SelectorInterface::Element::hasAttribute(const QString& name) const
106 {
107  return d->attributes.contains(name);
108 }
109 
110 const 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 
127 HtmlSettingsInterface::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 
142 void 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::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
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
KParts::SelectorInterface::Element::attributeNames
QStringList attributeNames() const
Returns the list of attributes in this element.
Definition: htmlextension.cpp:95
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
I18N_NOOP
#define I18N_NOOP(x)
KParts::SelectorInterface::Element::tagName
QString tagName() const
Returns the tag name of this element.
Definition: htmlextension.cpp:85
KParts::SelectorInterface::Element
Definition: htmlextension.h:149
kglobal.h
QSharedData
KParts::SelectorInterface::Element::~Element
~Element()
Destructor.
Definition: htmlextension.cpp:71
QHash< QString, QString >
htmlextension.h
KParts::HtmlSettingsInterface::JavaScriptAdvice
JavaScriptAdvice
This enum specifies whether Java/JavaScript execution is allowed.
Definition: htmlextension.h:270
QObject
QString::isEmpty
bool isEmpty() const
KParts::SelectorInterface::Element::setTagName
void setTagName(const QString &tag)
Sets the tag name of this element.
Definition: htmlextension.cpp:80
KParts::SelectorInterface::Element::hasAttribute
bool hasAttribute(const QString &name) const
Returns true if the attribute with the given name exists.
Definition: htmlextension.cpp:105
QString
KParts::HtmlExtension::HtmlExtension
HtmlExtension(KParts::ReadOnlyPart *parent)
Definition: htmlextension.cpp:30
QStringList
KParts::SelectorInterface::Element::isNull
bool isNull() const
Returns true if the element is null ; otherwise returns false.
Definition: htmlextension.cpp:75
QString::toLower
QString toLower() const
QLatin1Char
KParts::HtmlSettingsInterface::textToJavascriptAdvice
static JavaScriptAdvice textToJavascriptAdvice(const QString &text)
A convenience function that returns the javascript advice for text.
Definition: htmlextension.cpp:127
KParts::HtmlExtension
an extension for KParts to provide HTML-related features
Definition: htmlextension.h:45
QString::mid
QString mid(int position, int n) const
QLatin1String
klocalizedstring.h
QString::length
int length() const
KParts::SelectorInterface::Element::Element
Element()
Constructor.
Definition: htmlextension.cpp:61
QString::left
QString left(int n) const
KParts::SelectorInterface::supportedQueryMethods
virtual QueryMethods supportedQueryMethods() const
Returns the supported query methods.
Definition: htmlextension.cpp:49
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::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::HtmlExtension::childObject
static HtmlExtension * childObject(QObject *obj)
Queries obj for a child object which inherits from this HtmlExtension class.
Definition: htmlextension.cpp:44
QString::compare
int compare(const QString &other) const
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
part.h
KParts::HtmlExtension::~HtmlExtension
~HtmlExtension()
Definition: htmlextension.cpp:35
KParts::SelectorInterface::None
Definition: htmlextension.h:99
KParts::ReadOnlyPart
Base class for any "viewer" part.
Definition: part.h:488
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:25:36 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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