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

KParts

htmlextension.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2010 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include "htmlextension.h"
00021 
00022 #include "part.h"
00023 
00024 #include <kglobal.h>
00025 #include <klocalizedstring.h>
00026 
00027 
00028 using namespace KParts;
00029 
00030 KParts::HtmlExtension::HtmlExtension(KParts::ReadOnlyPart* parent)
00031     : QObject(parent), d(0)
00032 {
00033 }
00034 
00035 KParts::HtmlExtension::~HtmlExtension()
00036 {
00037 }
00038 
00039 bool HtmlExtension::hasSelection() const
00040 {
00041     return false;
00042 }
00043 
00044 HtmlExtension * KParts::HtmlExtension::childObject( QObject *obj )
00045 {
00046     return KGlobal::findDirectChild<KParts::HtmlExtension *>(obj);
00047 }
00048 
00049 SelectorInterface::QueryMethods SelectorInterface::supportedQueryMethods() const
00050 {
00051     return KParts::SelectorInterface::None;
00052 }
00053 
00054 class SelectorInterface::ElementPrivate : public QSharedData
00055 {
00056 public:
00057     QString tag;
00058     QHash<QString, QString> attributes;
00059 };
00060 
00061 SelectorInterface::Element::Element()
00062     : d(new ElementPrivate)
00063 {
00064 }
00065 
00066 SelectorInterface::Element::Element(const SelectorInterface::Element& other)
00067     : d(other.d)
00068 {
00069 }
00070 
00071 SelectorInterface::Element::~Element()
00072 {
00073 }
00074 
00075 bool SelectorInterface::Element::isNull() const
00076 {
00077     return d->tag.isNull();
00078 }
00079 
00080 void SelectorInterface::Element::setTagName(const QString& tag)
00081 {
00082     d->tag = tag;
00083 }
00084 
00085 QString SelectorInterface::Element::tagName() const
00086 {
00087     return d->tag;
00088 }
00089 
00090 void SelectorInterface::Element::setAttribute(const QString& name, const QString& value)
00091 {
00092     d->attributes[name] = value; // insert or replace
00093 }
00094 
00095 QStringList SelectorInterface::Element::attributeNames() const
00096 {
00097     return d->attributes.keys();
00098 }
00099 
00100 QString SelectorInterface::Element::attribute(const QString& name, const QString& defaultValue) const
00101 {
00102     return d->attributes.value(name, defaultValue);
00103 }
00104 
00105 bool SelectorInterface::Element::hasAttribute(const QString& name) const
00106 {
00107     return d->attributes.contains(name);
00108 }
00109 
00110 const char* HtmlSettingsInterface::javascriptAdviceToText(HtmlSettingsInterface::JavaScriptAdvice advice)
00111 {
00112     // NOTE: The use of I18N_NOOP below is intended to allow GUI code to call
00113     // i18n on the returned text without affecting use of untranslated text in
00114     // config files.
00115     switch (advice) {
00116     case JavaScriptAccept:
00117         return I18N_NOOP("Accept");
00118     case JavaScriptReject:
00119         return I18N_NOOP("Reject");
00120     default:
00121         break;
00122     }
00123 
00124     return 0;
00125 }
00126 
00127 HtmlSettingsInterface::JavaScriptAdvice HtmlSettingsInterface::textToJavascriptAdvice(const QString& text)
00128 {
00129     JavaScriptAdvice ret = JavaScriptDunno;
00130 
00131     if (!text.isEmpty()) {
00132         if (text.compare(QLatin1String("accept"), Qt::CaseInsensitive) == 0) {
00133             ret = JavaScriptAccept;
00134         } else if (text.compare(QLatin1String("reject"), Qt::CaseInsensitive) == 0) {
00135             ret = JavaScriptReject;
00136         }
00137     }
00138 
00139     return ret;
00140 }
00141 
00142 void HtmlSettingsInterface::splitDomainAdvice(const QString& adviceStr, QString& domain, HtmlSettingsInterface::JavaScriptAdvice& javaAdvice, HtmlSettingsInterface::JavaScriptAdvice& javaScriptAdvice)
00143 {
00144     const QString tmp(adviceStr);
00145     const int splitIndex = tmp.indexOf(':');
00146 
00147     if (splitIndex == -1) {
00148         domain = adviceStr.toLower();
00149         javaAdvice = JavaScriptDunno;
00150         javaScriptAdvice = JavaScriptDunno;
00151     } else {
00152         domain = tmp.left(splitIndex).toLower();
00153         const QString adviceString = tmp.mid(splitIndex+1, tmp.length());
00154         const int splitIndex2 = adviceString.indexOf(QLatin1Char(':'));
00155         if (splitIndex2 == -1) {
00156             // Java advice only
00157             javaAdvice = textToJavascriptAdvice(adviceString);
00158             javaScriptAdvice = JavaScriptDunno;
00159         } else {
00160             // Java and JavaScript advice
00161             javaAdvice = textToJavascriptAdvice(adviceString.left(splitIndex2));
00162             javaScriptAdvice = textToJavascriptAdvice(adviceString.mid(splitIndex2+1,
00163                                                       adviceString.length()));
00164         }
00165     }
00166 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Wed May 2 2012 18:37:11 by doxygen 1.8.0 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.8.3 API Reference

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