File indexing completed on 2024-04-14 14:23:10

0001 /* This file is part of the KDE project
0002  *
0003  * Copyright (C) 2002 Stephan Kulow <coolo@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #include "khtml_iface.h"
0022 #include "khtml_part.h"
0023 #include "khtmlview.h"
0024 #include "khtml_ext.h"
0025 #include <kio/global.h>
0026 #include <QApplication>
0027 #include <QVariant>
0028 #include <QKeyEvent>
0029 
0030 KHTMLPartIface::KHTMLPartIface(KHTMLPart *_part)
0031     : QDBusAbstractAdaptor(_part), part(_part)
0032 {
0033 }
0034 
0035 KHTMLPartIface::~KHTMLPartIface()
0036 {
0037 }
0038 
0039 QString KHTMLPartIface::url() const
0040 {
0041     return part->url().toString();
0042 }
0043 
0044 void KHTMLPartIface::setJScriptEnabled(bool enable)
0045 {
0046     part->setJScriptEnabled(enable);
0047 }
0048 
0049 bool KHTMLPartIface::jScriptEnabled() const
0050 {
0051     return part->jScriptEnabled();
0052 }
0053 
0054 bool KHTMLPartIface::closeUrl()
0055 {
0056     return part->closeUrl();
0057 }
0058 
0059 bool KHTMLPartIface::metaRefreshEnabled() const
0060 {
0061     return part->metaRefreshEnabled();
0062 }
0063 
0064 void KHTMLPartIface::setDndEnabled(bool b)
0065 {
0066     part->setDNDEnabled(b);
0067 }
0068 
0069 bool KHTMLPartIface::dndEnabled() const
0070 {
0071     return part->dndEnabled();
0072 }
0073 
0074 void KHTMLPartIface::setJavaEnabled(bool enable)
0075 {
0076     part->setJavaEnabled(enable);
0077 }
0078 
0079 bool KHTMLPartIface::javaEnabled() const
0080 {
0081     return part->javaEnabled();
0082 }
0083 
0084 void KHTMLPartIface::setPluginsEnabled(bool enable)
0085 {
0086     part->setPluginsEnabled(enable);
0087 }
0088 
0089 bool KHTMLPartIface::pluginsEnabled() const
0090 {
0091     return part->pluginsEnabled();
0092 }
0093 
0094 void KHTMLPartIface::setAutoloadImages(bool enable)
0095 {
0096     part->setAutoloadImages(enable);
0097 }
0098 
0099 bool KHTMLPartIface::autoloadImages() const
0100 {
0101     return part->autoloadImages();
0102 }
0103 
0104 void KHTMLPartIface::setOnlyLocalReferences(bool enable)
0105 {
0106     part->setOnlyLocalReferences(enable);
0107 }
0108 
0109 void KHTMLPartIface::setMetaRefreshEnabled(bool enable)
0110 {
0111     part->setMetaRefreshEnabled(enable);
0112 }
0113 
0114 bool KHTMLPartIface::onlyLocalReferences() const
0115 {
0116     return part->onlyLocalReferences();
0117 }
0118 
0119 bool KHTMLPartIface::setEncoding(const QString &name)
0120 {
0121     return part->setEncoding(name);
0122 }
0123 
0124 QString KHTMLPartIface::encoding() const
0125 {
0126     return part->encoding();
0127 }
0128 
0129 void KHTMLPartIface::setFixedFont(const QString &name)
0130 {
0131     part->setFixedFont(name);
0132 
0133 }
0134 
0135 bool KHTMLPartIface::gotoAnchor(const QString &name)
0136 {
0137     return part->gotoAnchor(name);
0138 }
0139 
0140 bool KHTMLPartIface::nextAnchor()
0141 {
0142     return part->nextAnchor();
0143 }
0144 
0145 bool KHTMLPartIface::prevAnchor()
0146 {
0147     return part->prevAnchor();
0148 }
0149 
0150 void KHTMLPartIface::activateNode()
0151 {
0152     KParts::ReadOnlyPart *p = part->currentFrame();
0153     if (p && p->widget()) {
0154         QKeyEvent ev(QKeyEvent::KeyPress, Qt::Key_Return, nullptr, "\n");
0155         QApplication::sendEvent(p->widget(), &ev);
0156     }
0157 }
0158 
0159 void KHTMLPartIface::selectAll()
0160 {
0161     part->selectAll();
0162 }
0163 
0164 QString KHTMLPartIface::lastModified() const
0165 {
0166     return part->lastModified();
0167 }
0168 
0169 void KHTMLPartIface::debugRenderTree()
0170 {
0171     part->slotDebugRenderTree();
0172 }
0173 
0174 void KHTMLPartIface::debugDOMTree()
0175 {
0176     part->slotDebugDOMTree();
0177 }
0178 
0179 void KHTMLPartIface::stopAnimations()
0180 {
0181     part->slotStopAnimations();
0182 }
0183 
0184 void KHTMLPartIface::viewDocumentSource()
0185 {
0186     part->slotViewDocumentSource();
0187 }
0188 
0189 void KHTMLPartIface::saveBackground(const QString &destination)
0190 {
0191     QUrl back = part->backgroundURL();
0192     if (back.isEmpty()) {
0193         return;
0194     }
0195 
0196     KIO::MetaData metaData;
0197     metaData["referrer"] = part->referrer();
0198     KHTMLPopupGUIClient::saveURL(part->widget(), back, QUrl(destination), metaData);
0199 }
0200 
0201 void KHTMLPartIface::saveDocument(const QString &destination)
0202 {
0203     QUrl srcURL(part->url());
0204 
0205     if (srcURL.fileName().isEmpty()) {
0206         srcURL.setPath(srcURL.path() + "index.html");
0207     }
0208 
0209     KIO::MetaData metaData;
0210     // Referrer unknown?
0211     KHTMLPopupGUIClient::saveURL(part->widget(), srcURL, QUrl(destination), metaData, part->cacheId());
0212 }
0213 
0214 void KHTMLPartIface::setUserStyleSheet(const QString &styleSheet)
0215 {
0216     part->setUserStyleSheet(styleSheet);
0217 }
0218 
0219 QString KHTMLPartIface::selectedText() const
0220 {
0221     return part->selectedText();
0222 }
0223 
0224 void KHTMLPartIface::viewFrameSource()
0225 {
0226     part->slotViewFrameSource();
0227 }
0228 
0229 QString KHTMLPartIface::evalJS(const QString &script)
0230 {
0231     return part->executeScript(DOM::Node(), script).toString();
0232 }
0233 
0234 void KHTMLPartIface::print(bool quick)
0235 {
0236     part->view()->print(quick);
0237 }
0238 
0239 #include "moc_khtml_iface.cpp"