diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -9,7 +9,6 @@ # TODO add_subdirectory( uachanger ) add_subdirectory( babelfish ) add_subdirectory( validators ) -add_subdirectory( domtreeviewer ) add_subdirectory( webarchiver ) if (Qt5TextToSpeech_FOUND) diff --git a/plugins/README b/plugins/README --- a/plugins/README +++ b/plugins/README @@ -13,10 +13,6 @@ This works on dolphin part. This allows you to filter the current directory in a variety of ways. -domtreeviewer -------------------- -Displays the document object model (DOM) in a dialog box. - validators ------------------- This works on KHTMLPart/KWebKitPart. It uses the w3c HTML validator to validate diff --git a/plugins/domtreeviewer/CMakeLists.txt b/plugins/domtreeviewer/CMakeLists.txt deleted file mode 100644 --- a/plugins/domtreeviewer/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -find_package(KF5 REQUIRED KHtml) -add_definitions(-DTRANSLATION_DOMAIN=\"domtreeviewer\") -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}") -########### next target ############### - -set(domtreeviewerplugin_PART_SRCS - plugin_domtreeviewer.cpp - domtreeview.cpp - domlistviewitem.cpp - domtreewindow.cpp - domtreecommands.cpp - signalreceiver.cpp ) - -ki18n_wrap_ui(domtreeviewerplugin_PART_SRCS domtreeviewbase.ui texteditwidget.ui elementeditwidget.ui attributeeditwidget.ui messagedialog.ui) - -add_library(domtreeviewerplugin MODULE ${domtreeviewerplugin_PART_SRCS}) - - - -target_link_libraries(domtreeviewerplugin KF5::KHtml KF5::KDELibs4Support) - -install(TARGETS domtreeviewerplugin DESTINATION ${KDE_INSTALL_PLUGINDIR} ) - - -########### install files ############### - -install( FILES plugin_domtreeviewer.rc plugin_domtreeviewer.desktop DESTINATION ${KDE_INSTALL_DATADIR}/khtml/kpartplugins ) -install( FILES domtreeviewerui.rc DESTINATION ${KDE_INSTALL_DATADIR}/domtreeviewer ) - - - - - diff --git a/plugins/domtreeviewer/Messages.sh b/plugins/domtreeviewer/Messages.sh deleted file mode 100644 --- a/plugins/domtreeviewer/Messages.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/sh -$EXTRACTRC *.rc *.ui >> rc.cpp -$XGETTEXT *.cpp -o $podir/domtreeviewer.pot diff --git a/plugins/domtreeviewer/attributeeditwidget.ui b/plugins/domtreeviewer/attributeeditwidget.ui deleted file mode 100644 --- a/plugins/domtreeviewer/attributeeditwidget.ui +++ /dev/null @@ -1,86 +0,0 @@ - - AttributeEditWidget - - - - 0 - 0 - 412 - 254 - - - - - 0 - - - - - 0 - - - - - Attribute &name: - - - false - - - attrName - - - - - - - - - - - - Attribute &value: - - - false - - - attrValue - - - - - - - true - - - true - - - false - - - - - - - - - KLineEdit - QLineEdit -
klineedit.h
-
- - KTextEdit - QTextEdit -
ktextedit.h
-
-
- - klineedit.h - ktextedit.h - - - -
diff --git a/plugins/domtreeviewer/domlistviewitem.h b/plugins/domtreeviewer/domlistviewitem.h deleted file mode 100644 --- a/plugins/domtreeviewer/domlistviewitem.h +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - domlistviewitem.h - ------------------- - - author : Andreas Schlapbach - email : schlpbch@iam.unibe.ch - author : Harri Porten - email : porten@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. * - * * - ***************************************************************************/ - -#ifndef DOMLISTVIEWITEMS_H -#define DOMLISTVIEWITEMS_H - -#include - -#include -#include -#include - -class DOMListViewItem : public QTreeWidgetItem -{ - -public: - DOMListViewItem(const DOM::Node &, QTreeWidget *parent); - DOMListViewItem(const DOM::Node &, QTreeWidget *parent, - QTreeWidgetItem *preceding); - DOMListViewItem(const DOM::Node &, QTreeWidgetItem *parent); - DOMListViewItem(const DOM::Node &, QTreeWidgetItem *parent, - QTreeWidgetItem *preceding); - ~DOMListViewItem() override; - - void setColor(const QColor &color) - { - setForeground(0, color); - } - - void setFont(const QFont &font) - { - m_font = font; - QTreeWidgetItem::setFont(0, font); - } - void setItalic(bool b) - { - m_font.setItalic(b); - setFont(m_font); - } - void setBold(bool b) - { - m_font.setBold(b); - setFont(m_font); - } - void setUnderline(bool b) - { - m_font.setUnderline(b); - setFont(m_font); - } - - bool isClosing() const - { - return clos; - } - void setClosing(bool s) - { - clos = s; - } - - DOM::Node node() const - { - return m_node; - } - -private: - void init(); - QFont m_font; - DOM::Node m_node; - bool clos; -}; -#endif diff --git a/plugins/domtreeviewer/domlistviewitem.cpp b/plugins/domtreeviewer/domlistviewitem.cpp deleted file mode 100644 --- a/plugins/domtreeviewer/domlistviewitem.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - domlistviewitem.cpp - ------------------- - - author : Andreas Schlapbach - email : schlpbch@iam.unibe.ch - author : Harri Porten - email : porten@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. * - * * - ***************************************************************************/ - -#include "domlistviewitem.h" - -#include -#include - -#include - -DOMListViewItem::DOMListViewItem(const DOM::Node &node, QTreeWidget *parent) - : QTreeWidgetItem(parent), m_node(node) -{ - init(); -} - -DOMListViewItem::DOMListViewItem(const DOM::Node &node, QTreeWidget *parent, QTreeWidgetItem *preceding) - : QTreeWidgetItem(parent, preceding), m_node(node) -{ - init(); -} - -DOMListViewItem::DOMListViewItem(const DOM::Node &node, QTreeWidgetItem *parent) - : QTreeWidgetItem(parent), m_node(node) -{ - init(); -} - -DOMListViewItem::DOMListViewItem(const DOM::Node &node, QTreeWidgetItem *parent, QTreeWidgetItem *preceding) - : QTreeWidgetItem(parent, preceding), m_node(node) -{ - init(); -} - -DOMListViewItem::~DOMListViewItem() -{ - //NOP -} - -void DOMListViewItem::init() -{ - setColor(QApplication::palette().color(QPalette::Active, QPalette::Text)); - m_font = QFontDatabase::systemFont(QFontDatabase::GeneralFont); - QTreeWidgetItem::setFont(0, m_font); - clos = false; -} diff --git a/plugins/domtreeviewer/domtreecommands.h b/plugins/domtreeviewer/domtreecommands.h deleted file mode 100644 --- a/plugins/domtreeviewer/domtreecommands.h +++ /dev/null @@ -1,377 +0,0 @@ -/* This file is part of the KDE project - * - * Copyright (C) 2005 Leo Savernik - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef domtreecommands_H -#define domtreecommands_H - -#include -#include -#include -#include - -#include - -#include -#include - -namespace domtreeviewer -{ - -class ManipulationCommandSignalEmitter; -class ChangedNodeSet; - -/** returns a localized string for the given dom exception code */ -QString domErrorMessage(int exception_code); - -/** - * Internal class for emitting signals. - * @internal - */ -class ManipulationCommandSignalEmitter : public QObject -{ - Q_OBJECT -public: - ManipulationCommandSignalEmitter(); - ~ManipulationCommandSignalEmitter() override; - -// public signals: -signals: -#if !defined(Q_MOC_RUN) && !defined(DOXYGEN_SHOULD_SKIP_THIS) && !defined(IN_IDE_PARSER) -public: -#endif - /** emitted if the DOM structure has been changed */ - void structureChanged(); - /** emitted if a DOM node has been changed */ - void nodeChanged(const DOM::Node &changedNode); - /** emitted if an error occurred - * @param err_id DOM error id - * @param msg error message - */ - void error(int err_id, const QString &msg); -}; - -/** - * Base class of all dom tree manipulation commands. - * @author Leo Savernik - */ -class ManipulationCommand : public QUndoCommand -{ -public: - ManipulationCommand(); - ~ManipulationCommand() override; - - /** returns whether this command is still valid and can be executed */ - bool isValid() const - { - return !_exception.code; - } - /** returns the last occurred DOM exception */ - DOM::DOMException exception() const - { - return _exception; - } - /** returns true when the next issue of execute will reapply the command */ - bool shouldReapply() const - { - return _reapplied; - } - /** returns true if the command may emit signals */ - bool allowSignals() const - { - return allow_signals; - } - - /** connects the given signal to a slot */ - static void connect(const char *signal, QObject *recv, const char *slot); - - /** does grunt work and calls apply()/reapply() */ - void redo() override; - /** does grunt work and calls unapply() */ - void undo() override; - -protected: - virtual void apply() = 0; - virtual void reapply(); - virtual void unapply() = 0; - - void handleException(DOM::DOMException &); - void checkAndEmitSignals(); - void addChangedNode(const DOM::Node &); - - static ManipulationCommandSignalEmitter *mcse(); - -protected: - DOM::DOMException _exception; - ChangedNodeSet *changedNodes; - bool _reapplied: 1; - bool struc_changed: 1; - -private: - bool allow_signals: 1; - - friend class MultiCommand; -}; - -/** - * Combines multiple commands into a single command. - * - * Does basically the same as KMacroCommand, but inherits from - * ManipulationCommand, and supports rollback. - */ -class MultiCommand : public ManipulationCommand -{ -public: - MultiCommand(const QString &name); - ~MultiCommand() override; - - /** Adds a new command. Will take ownership of \c cmd */ - void addCommand(ManipulationCommand *cmd); - - virtual QString name() const; - -protected: - void apply() override; - void unapply() override; - - void mergeChangedNodesFrom(ManipulationCommand *cmd); - -protected: - QList cmds; - QString _name; -}; - -/** - * Adds an attribute to a node. - * @author Leo Savernik - */ -class AddAttributeCommand : public ManipulationCommand -{ -public: - AddAttributeCommand(const DOM::Element &element, const QString &attrName, const QString &attrValue); - ~AddAttributeCommand() override; - - virtual QString name() const; - -protected: - void apply() override; - void unapply() override; - -protected: - DOM::Element _element; - DOM::DOMString attrName; - DOM::DOMString attrValue; -}; - -/** - * Manipulates an attribute's value. - * @author Leo Savernik - */ -class ChangeAttributeValueCommand : public ManipulationCommand -{ -public: - ChangeAttributeValueCommand(const DOM::Element &element, const QString &attr, const QString &value); - ~ChangeAttributeValueCommand() override; - - virtual QString name() const; - -protected: - void apply() override; - void unapply() override; - -protected: - DOM::Element _element; - DOM::DOMString _attr; - DOM::DOMString old_value; - DOM::DOMString new_value; -}; - -/** - * Removes an attribute from a node. - * @author Leo Savernik - */ -class RemoveAttributeCommand : public ManipulationCommand -{ -public: - RemoveAttributeCommand(const DOM::Element &element, const QString &attrName); - ~RemoveAttributeCommand() override; - - virtual QString name() const; - -protected: - void apply() override; - void unapply() override; - -protected: - DOM::Element _element; - DOM::DOMString attrName; - DOM::DOMString oldAttrValue; -}; - -/** - * Renames an attribute. - * @author Leo Savernik - */ -class RenameAttributeCommand : public ManipulationCommand -{ -public: - RenameAttributeCommand(const DOM::Element &element, const QString &attrOldName, const QString &attrNewName); - ~RenameAttributeCommand() override; - - virtual QString name() const; - -protected: - void apply() override; - void unapply() override; - -protected: - DOM::Element _element; - DOM::DOMString attrOldName; - DOM::DOMString attrNewName; - DOM::DOMString attrValue; -}; - -/** - * Changes the value of a CData-node. - * @author Leo Savernik - */ -class ChangeCDataCommand : public ManipulationCommand -{ -public: - ChangeCDataCommand(const DOM::CharacterData &, const QString &value); - ~ChangeCDataCommand() override; - - virtual QString name() const; - -protected: - void apply() override; - void unapply() override; - -protected: - DOM::CharacterData cdata; - DOM::DOMString value; - DOM::DOMString oldValue; - bool has_newlines; -}; - -/** - * Handles insertion and deletion primitives of nodes. - * @author Leo Savernik - */ -class ManipulateNodeCommand : public ManipulationCommand -{ -public: - /** - * Prepare command, where \c node is to be contained in \c parent, just - * before \c after. If \c after is 0, it is appended at the end. - */ - ManipulateNodeCommand(const DOM::Node &node, const DOM::Node &parent, const DOM::Node &after); - ~ManipulateNodeCommand() override; - -protected: - void insert(); - void remove(); - -protected: - DOM::Node _node; - DOM::Node _parent; - DOM::Node _after; -}; - -/** - * Inserts a node into the tree. - * - * The handed in node may be a full tree, even a document fragment. - * - * @author Leo Savernik - */ -class InsertNodeCommand : public ManipulateNodeCommand -{ -public: - /** - * Prepare insertion command, inserting \c node into \c parent, just - * before \c after. If \c after is 0, append it to the list of children. - */ - InsertNodeCommand(const DOM::Node &node, const DOM::Node &parent, const DOM::Node &after); - ~InsertNodeCommand() override; - - virtual QString name() const; - -protected: - void apply() override; - void unapply() override; - -protected: -}; - -/** - * Removes a node from the tree. - * - * The handed in node may be a full tree, even a document fragment. - * - * @author Leo Savernik - */ -class RemoveNodeCommand : public ManipulateNodeCommand -{ -public: - /** - * Prepare insertion command, inserting \c node into \c parent, just - * before \c after. If \c after is 0, append it to the list of children. - */ - RemoveNodeCommand(const DOM::Node &node, const DOM::Node &parent, const DOM::Node &after); - ~RemoveNodeCommand() override; - - virtual QString name() const; - -protected: - void apply() override; - void unapply() override; - -protected: -}; - -/** - * Moves a node. - * @author Leo Savernik - */ -class MoveNodeCommand : public ManipulationCommand -{ -public: - /** - * Move \c node from current position into \c parent, just before \c after. - * Appends if \c after is 0. - */ - MoveNodeCommand(const DOM::Node &node, const DOM::Node &parent, const DOM::Node &after); - ~MoveNodeCommand() override; - - virtual QString name() const; - -protected: - void apply() override; - void unapply() override; - -protected: - DOM::Node _node; - DOM::Node old_parent, old_after; - DOM::Node new_parent, new_after; -}; - -} // namespace domtreeviewer - -#endif // domtreewindow_H diff --git a/plugins/domtreeviewer/domtreecommands.cpp b/plugins/domtreeviewer/domtreecommands.cpp deleted file mode 100644 --- a/plugins/domtreeviewer/domtreecommands.cpp +++ /dev/null @@ -1,596 +0,0 @@ -/* This file is part of the KDE project - * - * Copyright (C) 2005 Leo Savernik - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "domtreecommands.h" - -#include -#include - -#include - -#include - -using namespace domtreeviewer; - -static const char *const dom_error_msgs[] = { - I18N_NOOP("No error"), - I18N_NOOP("Index size exceeded"), - I18N_NOOP("DOMString size exceeded"), - I18N_NOOP("Hierarchy request error"), - I18N_NOOP("Wrong document"), - I18N_NOOP("Invalid character"), - I18N_NOOP("No data allowed"), - I18N_NOOP("No modification allowed"), - I18N_NOOP("Not found"), - I18N_NOOP("Not supported"), - I18N_NOOP("Attribute in use"), - I18N_NOOP("Invalid state"), - I18N_NOOP("Syntax error"), - I18N_NOOP("Invalid modification"), - I18N_NOOP("Namespace error"), - I18N_NOOP("Invalid access") -}; - -// == global functions ============================================== - -QString domtreeviewer::domErrorMessage(int dom_err) -{ - if ((unsigned)dom_err >= sizeof dom_error_msgs / sizeof dom_error_msgs[0]) { - return i18n("Unknown Exception %1", dom_err); - } else { - return i18n(dom_error_msgs[dom_err]); - } -} - -// == ManipulationCommandSignalEmitter ============================== - -static ManipulationCommandSignalEmitter *_mcse; - -ManipulationCommandSignalEmitter::ManipulationCommandSignalEmitter() -{} -ManipulationCommandSignalEmitter::~ManipulationCommandSignalEmitter() -{} - -namespace domtreeviewer -{ - -ManipulationCommandSignalEmitter *ManipulationCommand::mcse() -{ - if (!_mcse) { - _mcse = new ManipulationCommandSignalEmitter; - } - return _mcse; -} - -} - -// == ChangedNodeSet ================================================ - -namespace DOM -{ - -inline static bool operator <(const DOM::Node &n1, const DOM::Node &n2) -{ - return (qptrdiff)n1.handle() - (qptrdiff)n2.handle() < 0; -} - -} - -namespace domtreeviewer -{ - -// collection of nodes for which to emit the nodeChanged signal -class ChangedNodeSet : public QMap -{ -}; - -} - -// == ManipulationCommand =========================================== - -ManipulationCommand::ManipulationCommand() : _exception(0), changedNodes(nullptr) - , _reapplied(false), allow_signals(true) -{ -} - -ManipulationCommand::~ManipulationCommand() -{ -} - -void ManipulationCommand::connect(const char *signal, QObject *recv, const char *slot) -{ - QObject::connect(mcse(), signal, recv, slot); -} - -void ManipulationCommand::handleException(DOM::DOMException &ex) -{ - _exception = ex; - QString msg = text() + ": " + domErrorMessage(ex.code); - emit mcse()->error(ex.code, msg); -} - -void ManipulationCommand::checkAndEmitSignals() -{ - if (allow_signals) { - if (changedNodes) { - ChangedNodeSet::Iterator end = changedNodes->end(); - for (ChangedNodeSet::Iterator it = changedNodes->begin(); it != end; ++it) { - emit mcse()->nodeChanged(it.key()); - } - } - - if (struc_changed) { - emit mcse()->structureChanged(); - } - } - if (changedNodes) { - changedNodes->clear(); - } -} - -void ManipulationCommand::addChangedNode(const DOM::Node &node) -{ - if (!changedNodes) { - changedNodes = new ChangedNodeSet; - } - changedNodes->insert(node, true); -} - -void ManipulationCommand::redo() -{ - if (!isValid()) { - return; - } - - struc_changed = false; - - try { - if (shouldReapply()) { - reapply(); - } else { - apply(); - } - - checkAndEmitSignals(); - - } catch (DOM::DOMException &ex) { - handleException(ex); - } - _reapplied = true; -} - -void ManipulationCommand::undo() -{ - if (!isValid()) { - return; - } - - struc_changed = false; - - try { - unapply(); - checkAndEmitSignals(); - } catch (DOM::DOMException &ex) { - handleException(ex); - } -} - -void ManipulationCommand::reapply() -{ - apply(); -} - -// == MultiCommand =========================================== - -MultiCommand::MultiCommand(const QString &desc) - : _name(desc) -{ -} - -MultiCommand::~MultiCommand() -{ - qDeleteAll(cmds); -} - -void MultiCommand::addCommand(ManipulationCommand *cmd) -{ - cmd->allow_signals = false; - cmds.append(cmd); -} - -void MultiCommand::apply() -{ - // apply in forward order - QList::ConstIterator it = cmds.constBegin(), itEnd = cmds.constEnd(); - for (; it != itEnd; ++it) { - try { - if (shouldReapply()) { - (*it)->reapply(); - } else { - (*it)->apply(); - } - - struc_changed |= (*it)->struc_changed; - mergeChangedNodesFrom(*it); - - } catch (DOM::DOMException &) { - // rollback - for (--it; *it; --it) { - try { - (*it)->unapply(); - } catch (DOM::DOMException &) { - // ignore - } - } - throw; - } - - } -} - -void MultiCommand::unapply() -{ - // unapply in reverse order - QListIterator it(cmds); - it.toBack(); - while (it.hasPrevious()) { - ManipulationCommand *current = it.previous(); - try { - current->unapply(); - - struc_changed |= current->struc_changed; - mergeChangedNodesFrom(current); - - } catch (DOM::DOMException &) { - // rollback - while (it.hasNext()) { - ManipulationCommand *newcurrent = it.next(); - try { - newcurrent->reapply(); - } catch (DOM::DOMException &) { - // ignore - } - } - throw; - } - - } -} - -void MultiCommand::mergeChangedNodesFrom(ManipulationCommand *cmd) -{ - if (!cmd->changedNodes) { - return; - } - - ChangedNodeSet::ConstIterator end = cmd->changedNodes->constEnd(); - for (ChangedNodeSet::ConstIterator it = cmd->changedNodes->constBegin(); it != end; ++it) { - addChangedNode(it.key()); - } - - cmd->changedNodes->clear(); -} - -QString MultiCommand::name() const -{ - return _name; -} - -// == AddAttributeCommand =========================================== - -AddAttributeCommand::AddAttributeCommand(const DOM::Element &element, const QString &attrName, const QString &attrValue) - : _element(element), attrName(attrName), attrValue(attrValue) -{ - if (attrValue.isEmpty()) { - this->attrValue = ""; - } -} - -AddAttributeCommand::~AddAttributeCommand() -{ -} - -void AddAttributeCommand::apply() -{ - _element.setAttribute(attrName, attrValue); - addChangedNode(_element); -} - -void AddAttributeCommand::unapply() -{ - _element.removeAttribute(attrName); - addChangedNode(_element); -} - -QString AddAttributeCommand::name() const -{ - return i18n("Add attribute"); -} - -// == ChangeAttributeValueCommand ==================================== - -ChangeAttributeValueCommand::ChangeAttributeValueCommand( - const DOM::Element &element, const QString &attr, const QString &value) - : _element(element), _attr(attr), new_value(value) -{ -} - -ChangeAttributeValueCommand::~ChangeAttributeValueCommand() -{ -} - -void ChangeAttributeValueCommand::apply() -{ - if (!shouldReapply()) { - old_value = _element.getAttribute(_attr); - } - _element.setAttribute(_attr, new_value); - addChangedNode(_element); -} - -void ChangeAttributeValueCommand::unapply() -{ - _element.setAttribute(_attr, old_value); - addChangedNode(_element); -} - -QString ChangeAttributeValueCommand::name() const -{ - return i18n("Change attribute value"); -} - -// == RemoveAttributeCommand ======================================== - -RemoveAttributeCommand::RemoveAttributeCommand(const DOM::Element &element, const QString &attrName) - : _element(element), attrName(attrName) -{ -} - -RemoveAttributeCommand::~RemoveAttributeCommand() -{ -} - -void RemoveAttributeCommand::apply() -{ -// kDebug(90180) << _element.nodeName().string() << ": " << attrName.string(); - if (!shouldReapply()) { - oldAttrValue = _element.getAttribute(attrName); - } - _element.removeAttribute(attrName); - addChangedNode(_element); -} - -void RemoveAttributeCommand::unapply() -{ - _element.setAttribute(attrName, oldAttrValue); - addChangedNode(_element); -} - -QString RemoveAttributeCommand::name() const -{ - return i18n("Remove attribute"); -} - -// == RenameAttributeCommand ======================================== - -RenameAttributeCommand::RenameAttributeCommand(const DOM::Element &element, const QString &attrOldName, const QString &attrNewName) - : _element(element), attrOldName(attrOldName), attrNewName(attrNewName) -{ -} - -RenameAttributeCommand::~RenameAttributeCommand() -{ -} - -void RenameAttributeCommand::apply() -{ - if (!shouldReapply()) { - attrValue = _element.getAttribute(attrOldName); - } - _element.removeAttribute(attrOldName); - _element.setAttribute(attrNewName, attrValue); - addChangedNode(_element); -} - -void RenameAttributeCommand::unapply() -{ - _element.removeAttribute(attrNewName); - _element.setAttribute(attrOldName, attrValue); - addChangedNode(_element); -} - -QString RenameAttributeCommand::name() const -{ - return i18n("Rename attribute"); -} - -// == ChangeCDataCommand ======================================== - -ChangeCDataCommand::ChangeCDataCommand(const DOM::CharacterData &cdata, const QString &value) - : cdata(cdata), value(value), has_newlines(false) -{ -} - -ChangeCDataCommand::~ChangeCDataCommand() -{ -} - -void ChangeCDataCommand::apply() -{ - if (!shouldReapply()) { - oldValue = cdata.data(); - has_newlines = - QString::fromRawData(value.unicode(), value.length()).contains('\n') - || QString::fromRawData(oldValue.unicode(), oldValue.length()).contains('\n'); - } - cdata.setData(value); - addChangedNode(cdata); - struc_changed = has_newlines; -} - -void ChangeCDataCommand::unapply() -{ - cdata.setData(oldValue); - addChangedNode(cdata); - struc_changed = has_newlines; -} - -QString ChangeCDataCommand::name() const -{ - return i18n("Change textual content"); -} - -// == ManipulateNodeCommand =========================================== - -ManipulateNodeCommand::ManipulateNodeCommand(const DOM::Node &node, const DOM::Node &parent, const DOM::Node &after) - : _node(node), _parent(parent), _after(after) -{ -} - -ManipulateNodeCommand::~ManipulateNodeCommand() -{ -} - -void ManipulateNodeCommand::insert() -{ - _parent.insertBefore(_node, _after); -} - -void ManipulateNodeCommand::remove() -{ - DOM::DocumentFragment frag = _node; - - if (frag.isNull()) { // do a normal remove - _node = _parent.removeChild(_node); - - } else { // remove fragment nodes and recreate fragment - DOM::DocumentFragment newfrag = _parent.ownerDocument().createDocumentFragment(); - - for (DOM::Node i = frag.firstChild(); !i.isNull(); i = i.nextSibling()) { - newfrag.appendChild(_parent.removeChild(i)); - } - - _node = newfrag; - } -} - -// == InsertNodeCommand =========================================== - -InsertNodeCommand::InsertNodeCommand(const DOM::Node &node, const DOM::Node &parent, const DOM::Node &after) - : ManipulateNodeCommand(node, parent, after) -{ -} - -InsertNodeCommand::~InsertNodeCommand() -{ -} - -void InsertNodeCommand::apply() -{ - insert(); - struc_changed = true; -} - -void InsertNodeCommand::unapply() -{ - remove(); - struc_changed = true; -} - -QString InsertNodeCommand::name() const -{ - return i18n("Insert node"); -} - -// == RemoveNodeCommand =========================================== - -RemoveNodeCommand::RemoveNodeCommand(const DOM::Node &node, const DOM::Node &parent, const DOM::Node &after) - : ManipulateNodeCommand(node, parent, after) -{ -} - -RemoveNodeCommand::~RemoveNodeCommand() -{ -} - -void RemoveNodeCommand::apply() -{ - remove(); - struc_changed = true; -} - -void RemoveNodeCommand::unapply() -{ - insert(); - struc_changed = true; -} - -QString RemoveNodeCommand::name() const -{ - return i18n("Remove node"); -} - -// == MoveNodeCommand =========================================== - -MoveNodeCommand::MoveNodeCommand(const DOM::Node &node, const DOM::Node &parent, const DOM::Node &after) - : _node(node), new_parent(parent), new_after(after) -{ - old_parent = node.parentNode(); - old_after = node.nextSibling(); -} - -MoveNodeCommand::~MoveNodeCommand() -{ -} - -void MoveNodeCommand::apply() -{ - old_parent.removeChild(_node); - try { - new_parent.insertBefore(_node, new_after); - } catch (DOM::DOMException &) { - try { // rollback - old_parent.insertBefore(_node, old_after); - } catch (DOM::DOMException &) {} - throw; - } - struc_changed = true; -} - -void MoveNodeCommand::unapply() -{ - new_parent.removeChild(_node); - try { - old_parent.insertBefore(_node, old_after); - } catch (DOM::DOMException &) { - try { // rollback - new_parent.insertBefore(_node, new_after); - } catch (DOM::DOMException &) {} - throw; - } - struc_changed = true; -} - -QString MoveNodeCommand::name() const -{ - return i18n("Move node"); -} - -#undef MCSE diff --git a/plugins/domtreeviewer/domtreeview.h b/plugins/domtreeviewer/domtreeview.h deleted file mode 100644 --- a/plugins/domtreeviewer/domtreeview.h +++ /dev/null @@ -1,207 +0,0 @@ -/*************************************************************************** - copyright : (C) 2001 - The Kafka Team/Andreas Schlapbach - (C) 2005 - Leo Savernik - (C) 2008 - Harri Porten - email : kde-kafka@master.kde.org - schlpbch@iam.unibe.ch - porten@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. * - * * - ***************************************************************************/ - -#ifndef DOMTREEVIEW_H -#define DOMTREEVIEW_H - -#include -#include -#include -#include - -#include "ui_domtreeviewbase.h" - -namespace DOM -{ -class Element; -class CharacterData; -} - -class DOMListViewItem; -class DOMTreeWindow; - -class KFindDialog; -class KHTMLPart; - -class DOMTreeView : public QWidget, public Ui::DOMTreeViewBase -{ - Q_OBJECT - -public: - explicit DOMTreeView(QWidget *parent, bool allowSaving = true); - ~DOMTreeView() override; - - KHTMLPart *htmlPart() const - { - return part; - } - void setHtmlPart(KHTMLPart *); - - /** returns the main window */ - DOMTreeWindow *mainWindow() const; - -protected: - /* - void saveTreeAsHTML(const DOM::Node &pNode); - */ - bool eventFilter(QObject *o, QEvent *e) override; - -signals: - /** emitted when the part has been changed. */ - void htmlPartChanged(KHTMLPart *part); - -public slots: - void refresh(); - void increaseExpansionDepth(); - void decreaseExpansionDepth(); - void setMessage(const QString &msg); - void hideMessageLine(); - - void moveToParent(); - - void activateNode(const DOM::Node &node); - void deleteNodes(); - - /** - * Takes measures to disconnect this instance from the current html - * part as long as it is active. - */ - void disconnectFromActivePart(); - - /** - * Takes measures to disconnect this instance from the current html - * part when it is being torn down. - */ - void disconnectFromTornDownPart(); - - /** - * Connects to the current html part. - */ - void connectToPart(); - - void slotFindClicked(); - void slotAddElementDlg(); - void slotAddTextDlg(); - -protected slots: - void slotShowNode(const DOM::Node &pNode); - void slotShowTree(const DOM::Node &pNode); - void slotItemClicked(QTreeWidgetItem *); - void slotRefreshNode(const DOM::Node &pNode); -#if 0 // ### port to Qt 4 - void slotMovedItems(Q3PtrList &items, Q3PtrList &afterFirst, Q3PtrList &afterNow); -#endif - void slotPrepareMove(); - void slotSearch(); - - // void slotSaveClicked(); - - void slotPureToggled(bool); - void slotShowAttributesToggled(bool); - void slotHighlightHTMLToggled(bool); - - void showDOMTreeContextMenu(const QPoint &); - - void slotSetHtmlPartDelayed(); - void slotRestoreScrollOffset(); - -private: - QHash m_itemdict; - DOM::Node m_document; - - uint m_expansionDepth, m_maxDepth; - bool m_bPure, m_bShowAttributes, m_bHighlightHTML; - -private: - void connectToDocument(); - void showRecursive(const DOM::Node &pNode, const DOM::Node &node, - uint depth); - - // void saveRecursive(const DOM::Node &node, int ident); - - void searchRecursive(DOMListViewItem *cur_item, - const QString &searchText, - Qt::CaseSensitivity caseSensitivity); - - void adjustDepth(); - void adjustDepthRecursively(QTreeWidgetItem *cur_item, uint currDepth); - void highlightHTML(DOMListViewItem *cur_item, - const QString &nodeName); - - DOMListViewItem *addElement(const DOM::Node &node, DOMListViewItem *cur_item, - bool isLast); - void updateIncrDecreaseButton(); - -private: - KFindDialog *m_findDialog; - - KHTMLPart *part; - QTextStream *m_textStream; - - QObject *focused_child; - DOM::Node current_node; - DOM::CSSStyleSheet stylesheet; - DOM::CSSRule active_node_rule; - - bool _refreshed; - int scroll_ofs_x, scroll_ofs_y; - - // == DOM Node Info panel ====================================== - -public: - // Keep in sync with the widget stack children - enum InfoPanel { ElementPanel, CDataPanel, EmptyPanel }; - -public slots: - void initializeOptionsFromNode(const DOM::Node &); - void initializeOptionsFromListItem(QTreeWidgetItem *); - - void copyAttributes(); - void cutAttributes(); - void pasteAttributes(); - void deleteAttributes(); - -private: - void initDOMNodeInfo(); - - void initializeStyleSheetsFromDocument(const DOM::Document &); - - void initializeOptionsFromElement(const DOM::Element &); - void initializeDOMInfoFromElement(const DOM::Element &); - void initializeCSSInfoFromElement(const DOM::Element &); - - void initializeOptionsFromCData(const DOM::CharacterData &); - void initializeDOMInfoFromCData(const DOM::CharacterData &); - void initializeCSSInfoFromCData(const DOM::CharacterData &); - -private slots: - void slotItemRenamed(QTreeWidgetItem *, const QString &str, int col); - void slotEditAttribute(QTreeWidgetItem *, int col); - void slotApplyContent(); - - void showInfoPanelContextMenu(const QPoint &); - -private: - DOM::Node infoNode; // node these infos apply to - - // == End DOM Node Info panel ================================== - -}; - -#endif - diff --git a/plugins/domtreeviewer/domtreeview.cpp b/plugins/domtreeviewer/domtreeview.cpp deleted file mode 100644 --- a/plugins/domtreeviewer/domtreeview.cpp +++ /dev/null @@ -1,1442 +0,0 @@ -/*************************************************************************** - copyright : (C) 2001 - The Kafka Team/Andreas Schlapbach - (C) 2005 - Leo Savernik - (C) 2008 - Harri Porten - email : kde-kafka@master.kde.org - schlpbch@iam.unibe.ch - porten@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. * - * * - ***************************************************************************/ - -#include "domtreeview.h" -#include "domlistviewitem.h" -#include "domtreewindow.h" -#include "domtreecommands.h" - -#include "signalreceiver.h" -#include "ui_attributeeditwidget.h" -#include "ui_elementeditwidget.h" -#include "ui_texteditwidget.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace domtreeviewer; - -class ElementEditDialog : public KDialog, public Ui::ElementEditWidget -{ -public: - ElementEditDialog(QWidget *parent) - : KDialog(parent) - { - setupUi(mainWidget()); - - setWindowTitle(i18nc("@title:window", "Edit Element")); - setButtons(User1 | User2 | Cancel); - setButtonText(User1, i18n("&Append as Child")); - setButtonText(User2, i18n("Insert &Before Current")); - - connect(this, &KDialog::cancelClicked, this, &QDialog::reject); - connect(this, &KDialog::user1Clicked, this, &QDialog::accept); - connect(this, &KDialog::user2Clicked, this, &QDialog::accept); - } -}; - -class TextEditDialog : public KDialog, public Ui::TextEditWidget -{ -public: - TextEditDialog(QWidget *parent) - : KDialog(parent) - { - setupUi(mainWidget()); - - setWindowTitle(i18nc("@title:window", "Edit Text")); - setButtons(User1 | User2 | Cancel); - setButtonText(User1, i18n("&Append as Child")); - setButtonText(User2, i18n("Insert &Before Current")); - - connect(this, &KDialog::cancelClicked, this, &QDialog::reject); - connect(this, &KDialog::user1Clicked, this, &QDialog::accept); - connect(this, &KDialog::user2Clicked, this, &QDialog::accept); - } -}; - -class AttributeEditDialog : public KDialog, public Ui::AttributeEditWidget -{ -public: - AttributeEditDialog(QWidget *parent) - : KDialog(parent) - { - setupUi(mainWidget()); - - setWindowTitle(i18nc("@title:window", "Edit Attribute")); - setButtons(Ok | Cancel); - - connect(this, &KDialog::okClicked, this, &QDialog::accept); - connect(this, &KDialog::cancelClicked, this, &QDialog::reject); - connect(attrName, SIGNAL(returnPressed()), this, SLOT(accept())); - } -}; - -DOMTreeView::DOMTreeView(QWidget *parent, bool /*allowSaving*/) - : QWidget(parent), m_expansionDepth(5), m_maxDepth(0), - m_bPure(true), m_bShowAttributes(true), m_bHighlightHTML(true), - m_findDialog(nullptr), focused_child(nullptr) -{ - setupUi(this); - - part = nullptr; - - const QFont font(QFontDatabase::systemFont(QFontDatabase::GeneralFont)); - m_listView->setFont(font); - - connect(m_listView, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, - SLOT(slotItemClicked(QTreeWidgetItem*))); - m_listView->setContextMenuPolicy(Qt::CustomContextMenu); - connect(m_listView, SIGNAL(customContextMenuRequested(QPoint)), - SLOT(showDOMTreeContextMenu(QPoint))); -#if 0 // ### port to Qt 4 - connect(m_listView, SIGNAL(moved(Q3PtrList&,Q3PtrList&,Q3PtrList&)), - SLOT(slotMovedItems(Q3PtrList&,Q3PtrList&,Q3PtrList&))); -#endif - - // set up message line - messageLinePane->hide(); - connect(messageHideBtn, SIGNAL(clicked()), SLOT(hideMessageLine())); - connect(messageListBtn, SIGNAL(clicked()), mainWindow(), SLOT(showMessageLog())); - - installEventFilter(m_listView); - - ManipulationCommand::connect(SIGNAL(nodeChanged(DOM::Node)), this, SLOT(slotRefreshNode(DOM::Node))); - ManipulationCommand::connect(SIGNAL(structureChanged()), this, SLOT(refresh())); - - initDOMNodeInfo(); - - installEventFilter(this); -} - -DOMTreeView::~DOMTreeView() -{ - delete m_findDialog; - disconnectFromActivePart(); -} - -void DOMTreeView::setHtmlPart(KHTMLPart *_part) -{ - KHTMLPart *oldPart = part; - part = _part; - - if (oldPart) { - // nothing here yet - } - - parentWidget()->setWindowTitle(part ? i18nc("@title:window", "DOM Tree for %1", part->url().toDisplayString()) : i18nc("@title:window", "DOM Tree")); - - QTimer::singleShot(0, this, SLOT(slotSetHtmlPartDelayed())); -} - -DOMTreeWindow *DOMTreeView::mainWindow() const -{ - return static_cast(parentWidget()); -} - -bool DOMTreeView::eventFilter(QObject *o, QEvent *e) -{ - if (e->type() == QEvent::FocusIn) { - - kDebug(90180) << " focusin o " << o->objectName(); - if (o != this) { - focused_child = o; - } - - } else if (e->type() == QEvent::FocusOut) { - - kDebug(90180) << " focusout o " << o->objectName(); - if (o != this) { - focused_child = nullptr; - } - - } - - return false; -} - -void DOMTreeView::activateNode(const DOM::Node &node) -{ - slotShowNode(node); - initializeOptionsFromNode(node); -} - -void DOMTreeView::slotShowNode(const DOM::Node &pNode) -{ - - if (QTreeWidgetItem *item = m_itemdict.value(pNode.handle(), nullptr)) { - m_listView->setCurrentItem(item); - m_listView->scrollToItem(item); - } -} - -void DOMTreeView::slotShowTree(const DOM::Node &pNode) -{ - DOM::Node child; - - m_listView->clear(); - m_itemdict.clear(); - - try { - child = pNode.firstChild(); - } catch (DOM::DOMException &) { - return; - } - - while (!child.isNull()) { - showRecursive(nullptr, child, 0); - child = child.nextSibling(); - } - - m_maxDepth--; - //kDebug(90180) << " Max Depth: " << m_maxDepth; -} - -void DOMTreeView::showRecursive(const DOM::Node &pNode, const DOM::Node &node, uint depth) -{ - DOMListViewItem *cur_item; - DOMListViewItem *parent_item = m_itemdict.value(pNode.handle(), nullptr); - - if (depth > m_maxDepth) { - m_maxDepth = depth; - } - - if (depth == 0) { - cur_item = new DOMListViewItem(node, m_listView); - m_document = pNode.ownerDocument(); - } else { - cur_item = new DOMListViewItem(node, parent_item); - } - - //kDebug(90180) << node.nodeName().string() << " [" << depth << "]"; - cur_item = addElement(node, cur_item, false); - m_listView->setItemExpanded(cur_item, depth < m_expansionDepth); - - if (node.handle()) { - m_itemdict.insert(node.handle(), cur_item); - } - - DOM::Node child = node.firstChild(); - if (child.isNull()) { - DOM::HTMLFrameElement frame = node; - if (!frame.isNull()) { - child = frame.contentDocument().documentElement(); - } else { - DOM::HTMLIFrameElement iframe = node; - if (!iframe.isNull()) { - child = iframe.contentDocument().documentElement(); - } - } - } - while (!child.isNull()) { - showRecursive(node, child, depth + 1); - child = child.nextSibling(); - } - - const DOM::Element element = node; - if (!m_bPure) { - if (!element.isNull() && !element.firstChild().isNull()) { - if (depth == 0) { - cur_item = new DOMListViewItem(node, m_listView, cur_item); - m_document = pNode.ownerDocument(); - } else { - cur_item = new DOMListViewItem(node, parent_item, cur_item); - } - //kDebug(90180) << ""; - cur_item = addElement(element, cur_item, true); -// m_listView->setItemExpanded(cur_item, depth < m_expansionDepth); - } - } -} - -DOMListViewItem *DOMTreeView::addElement(const DOM::Node &node, DOMListViewItem *cur_item, bool isLast) -{ - assert(cur_item); - cur_item->setClosing(isLast); - - const QString nodeName(node.nodeName().string()); - QString text; - const DOM::Element element = node; - if (!element.isNull()) { - if (!m_bPure) { - if (isLast) { - text = QStringLiteral("(attrs.item(j)); - attributes += " " + attr.name().string() + "=\"" + attr.value().string() + "\""; - } - if (!(attributes.isEmpty())) { - text += ' '; - } - text += attributes.simplified(); - } - - if (!m_bPure) { - if (element.firstChild().isNull()) { - text += QLatin1String("/>"); - } else { - text += '>'; - } - } - cur_item->setText(0, text); - } else { - text = node.nodeValue().string(); - - // Hacks to deal with PRE - QTextStream ts(&text, QIODevice::ReadOnly); - while (!ts.atEnd()) { - const QString txt(ts.readLine()); - const QFont font(QFontDatabase::systemFont(QFontDatabase::FixedFont)); - cur_item->setFont(font); - cur_item->setText(0, '`' + txt + '\''); - - if (node.handle()) { - m_itemdict.insert(node.handle(), cur_item); - } - - DOMListViewItem *parent; - if (cur_item->parent()) { - parent = static_cast(cur_item->parent()); - } else { - parent = cur_item; - } - cur_item = new DOMListViewItem(node, parent, cur_item); - } - // This is one is too much - DOMListViewItem *notLastItem = static_cast(m_listView->itemAbove(cur_item)); - delete cur_item; - cur_item = notLastItem; - } - - if (cur_item && m_bHighlightHTML && node.ownerDocument().isHTMLDocument()) { - highlightHTML(cur_item, nodeName); - } - return cur_item; -} - -void DOMTreeView::highlightHTML(DOMListViewItem *cur_item, const QString &nodeName) -{ - assert(cur_item); - /* This is slow. I could make it O(1) be using the tokenizer of khtml but I don't - * think it's worth it. - */ - - QColor namedColor(palette().color(QPalette::Active, QPalette::Text)); - QString tagName = nodeName.toUpper(); - if (tagName == QLatin1String("HTML")) { - namedColor = "#0000ff"; - cur_item->setBold(true); - } else if (tagName == QLatin1String("HEAD")) { - namedColor = "#0022ff"; - cur_item->setBold(true); - - } else if (tagName == QLatin1String("TITLE")) { - namedColor = "#2200ff"; - } else if (tagName == QLatin1String("SCRIPT")) { - namedColor = "#4400ff"; - } else if (tagName == QLatin1String("NOSCRIPT")) { - namedColor = "#0044ff"; - } else if (tagName == QLatin1String("STYLE")) { - namedColor = "#0066ff"; - } else if (tagName == QLatin1String("LINK")) { - namedColor = "#6600ff"; - } else if (tagName == QLatin1String("META")) { - namedColor = "#0088ff"; - - } else if (tagName == QLatin1String("BODY")) { - namedColor = "#ff0000"; - cur_item->setBold(true); - } else if (tagName == QLatin1String("A")) { - namedColor = "blue"; - cur_item->setUnderline(true); - } else if (tagName == QLatin1String("IMG")) { - namedColor = "magenta"; - cur_item->setUnderline(true); - - } else if (tagName == QLatin1String("DIV")) { - namedColor = "#ff0044"; - } else if (tagName == QLatin1String("SPAN")) { - namedColor = "#ff4400"; - } else if (tagName == QLatin1String("P")) { - namedColor = "#ff0066"; - - } else if (tagName == QLatin1String("DL") || tagName == QLatin1String("OL") || tagName == QLatin1String("UL") || tagName == QLatin1String("TABLE")) { - namedColor = "#880088"; - } else if (tagName == QLatin1String("LI")) { - namedColor = "#884488"; - } else if (tagName == QLatin1String("TBODY")) { - namedColor = "#888888"; - } else if (tagName == QLatin1String("TR")) { - namedColor = "#882288"; - } else if (tagName == QLatin1String("TD")) { - namedColor = "#886688"; - - } else if ((tagName == QLatin1String("H1")) || (tagName == QLatin1String("H2")) || (tagName == QLatin1String("H3")) || - (tagName == QLatin1String("H4")) || (tagName == QLatin1String("H5")) || (tagName == QLatin1String("H6"))) { - namedColor = "#008800"; - } else if (tagName == QLatin1String("HR")) { - namedColor = "#228822"; - - } else if (tagName == QLatin1String("FRAME") || tagName == QLatin1String("IFRAME")) { - namedColor = "#ff22ff"; - } else if (tagName == QLatin1String("FRAMESET")) { - namedColor = "#dd22dd"; - - } else if (tagName == QLatin1String("APPLET") || tagName == QLatin1String("OBJECT")) { - namedColor = "#bb22bb"; - - } else if (tagName == QLatin1String("BASEFONT") || tagName == QLatin1String("FONT")) { - namedColor = "#097200"; - - } else if (tagName == QLatin1String("B") || tagName == QLatin1String("STRONG")) { - cur_item->setBold(true); - } else if (tagName == QLatin1String("I") || tagName == QLatin1String("EM")) { - cur_item->setItalic(true); - } else if (tagName == QLatin1String("U")) { - cur_item->setUnderline(true); - } - - cur_item->setColor(namedColor); -} - -void DOMTreeView::slotItemClicked(QTreeWidgetItem *cur_item) -{ - DOMListViewItem *cur = static_cast(cur_item); - if (!cur) { - return; - } - - DOM::Node handle = cur->node(); - kDebug() << " handle :"; - if (!handle.isNull()) { - part->setActiveNode(handle); - } -} - -void DOMTreeView::slotFindClicked() -{ - if (m_findDialog == nullptr) { - m_findDialog = new KFindDialog(this); - m_findDialog->setSupportsWholeWordsFind(false); - m_findDialog->setHasCursor(false); - m_findDialog->setHasSelection(false); - m_findDialog->setSupportsRegularExpressionFind(false); - - connect(m_findDialog, SIGNAL(okClicked()), this, SLOT(slotSearch())); - } - m_findDialog->show(); -} - -void DOMTreeView::slotRefreshNode(const DOM::Node &pNode) -{ - DOMListViewItem *cur = static_cast(m_itemdict.value(pNode.handle(), nullptr)); - if (!cur) { - return; - } - - addElement(pNode, cur, false); -} - -// ### unused -void DOMTreeView::slotPrepareMove() -{ - DOMListViewItem *item = static_cast(m_listView->currentItem()); - - if (!item) { - current_node = DOM::Node(); - } else { - current_node = item->node(); - } -} - -#if 0 // ### port to Qt 4 -void DOMTreeView::slotMovedItems(Q3PtrList &items, Q3PtrList &/*afterFirst*/, Q3PtrList &afterNow) -{ - MultiCommand *cmd = new MultiCommand(i18n("Move Nodes")); - _refreshed = false; - - Q3PtrList::Iterator it = items.begin(); - Q3PtrList::Iterator anit = afterNow.begin(); - for (; it != items.end(); ++it, ++anit) { - DOMListViewItem *item = static_cast(*it); - DOMListViewItem *anitem = static_cast(*anit); - DOM::Node parent = static_cast(item->parent())->node(); - Q_ASSERT(!parent.isNull()); - -// kDebug(90180) << " afternow " << anitem << " node " << (anitem ? anitem->node().nodeName().string() : QString()) << "=" << (anitem ? anitem->node().nodeValue().string() : QString()); - - cmd->addCommand(new MoveNodeCommand(item->node(), parent, - anitem ? anitem->node().nextSibling() : parent.firstChild()) - ); - } - - mainWindow()->executeAndAddCommand(cmd); - - // refresh *anyways*, otherwise consistency is disturbed - if (!_refreshed) { - refresh(); - } - - slotShowNode(current_node); -} -#endif - -void DOMTreeView::slotSearch() -{ - assert(m_findDialog); - const QString searchText = m_findDialog->pattern(); - Qt::CaseSensitivity caseSensitivity = (m_findDialog->options() & KFind::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive; - - for (int i = 0; i < m_listView->topLevelItemCount(); ++i) { - QTreeWidgetItem *topLevelItem = m_listView->topLevelItem(i); - searchRecursive(static_cast(topLevelItem), - searchText, caseSensitivity); - } - - m_findDialog->hide(); -} - -void DOMTreeView::searchRecursive(DOMListViewItem *cur_item, const QString &searchText, - Qt::CaseSensitivity caseSensitivity) -{ - assert(cur_item); - const QString text(cur_item->text(0)); - if (text.contains(searchText, caseSensitivity)) { - cur_item->setUnderline(true); - cur_item->setItalic(true); - m_listView->setCurrentItem(cur_item); - m_listView->scrollToItem(cur_item); - QTreeWidgetItem *parent = cur_item->parent(); - while (parent && !parent->isExpanded()) { - m_listView->setItemExpanded(parent, true); - parent = parent->parent(); - } - } else { - m_listView->setItemExpanded(cur_item, false); - } - for (int cp = 0; cp < cur_item->childCount(); ++cp) { - searchRecursive(static_cast(cur_item->child(cp)), searchText, caseSensitivity); - } -} - -#if 0 -void DOMTreeView::slotSaveClicked() -{ - //kDebug(90180) << "void KfingerCSSWidget::slotSaveAs()"; - KUrl url = KFileDialog::getSaveFileName(part->url().url(), "*.html", - this, i18n("Save DOM Tree as HTML")); - if (!(url.isEmpty()) && url.isValid()) { - QFile file(url.path()); - - if (file.exists()) { - const QString title = i18nc("@title:window", "File Exists"); - const QString text = i18n("Do you really want to overwrite: \n%1?", url.url()); - if (KMessageBox::Continue != KMessageBox::warningContinueCancel(this, text, title, KStandardGuiItem::overwrite())) { - return; - } - } - - if (file.open(QIODevice::WriteOnly)) { - kDebug(90180) << "Opened File: " << url.url(); - m_textStream = new QTextStream(&file); //(stdOut) - saveTreeAsHTML(part->document()); - file.close(); - kDebug(90180) << "File closed "; - delete m_textStream; - } else { - const QString title = i18nc("@title:window", "Unable to Open File"); - const QString text = i18n("Unable to open \n %1 \n for writing", url.path()); - KMessageBox::sorry(this, text, title); - } - } else { - const QString title = i18nc("@title:window", "Invalid URL"); - const QString text = i18n("This URL \n %1 \n is not valid.", url.url()); - KMessageBox::sorry(this, text, title); - } -} - -void DOMTreeView::saveTreeAsHTML(const DOM::Node &pNode) -{ - assert(m_textStream); - - // Add a doctype - - (*m_textStream) << "" << endl; - if (pNode.ownerDocument().isNull()) { - saveRecursive(pNode, 0); - } else { - saveRecursive(pNode.ownerDocument(), 0); - } -} - -void DOMTreeView::saveRecursive(const DOM::Node &pNode, int indent) -{ - const QString nodeName(pNode.nodeName().string()); - QString text; - QString strIndent; - strIndent.fill(' ', indent); - const DOM::Element element = static_cast(pNode); - - text = strIndent; - - if (!element.isNull()) { - if (nodeName.at(0) == '-') { - /* Don't save khtml internal tags '-konq..' - * Approximating it with
- */ - text += "
"; - } else { - text += '<' + nodeName; - - QString attributes; - DOM::Attr attr; - const DOM::NamedNodeMap attrs = element.attributes(); - unsigned long lmap = attrs.length(); - for (uint j = 0; j < lmap; j++) { - attr = static_cast(attrs.item(j)); - attributes += " " + attr.name().string() + "=\"" + attr.value().string() + "\""; - } - if (!(attributes.isEmpty())) { - text += ' '; - } - - text += attributes.simplified(); - - if (element.firstChild().isNull()) { - text += "/>"; - } else { - text += '>'; - } - } - } else { - text = strIndent + pNode.nodeValue().string(); - } - - kDebug(90180) << text; - if (!(text.isEmpty())) { - (*m_textStream) << text << endl; - } - - DOM::Node child = pNode.firstChild(); - while (!child.isNull()) { - saveRecursive(child, indent + 2); - child = child.nextSibling(); - } - - if (!(element.isNull()) && (!(element.firstChild().isNull()))) { - if (nodeName.at(0) == '-') { - text = strIndent + "
"; - } else { - text = strIndent + "'; - } - kDebug(90180) << text; - (*m_textStream) << text << endl; - } -} -#endif - -void DOMTreeView::updateIncrDecreaseButton() -{ -#if 0 - m_decreaseButton->setEnabled((m_expansionDepth > 0)); - m_increaseButton->setEnabled((m_expansionDepth < m_maxDepth)); -#endif -} - -void DOMTreeView::refresh() -{ - if (!part) { - return; - } - scroll_ofs_x = m_listView->horizontalScrollBar()->value(); - scroll_ofs_y = m_listView->verticalScrollBar()->value(); - - m_listView->setUpdatesEnabled(false); - slotShowTree(part->document()); - - QTimer::singleShot(0, this, SLOT(slotRestoreScrollOffset())); - _refreshed = true; -} - -void DOMTreeView::increaseExpansionDepth() -{ - if (!part) { - return; - } - if (m_expansionDepth < m_maxDepth) { - ++m_expansionDepth; - adjustDepth(); - updateIncrDecreaseButton(); - } else { - QApplication::beep(); - } -} - -void DOMTreeView::decreaseExpansionDepth() -{ - if (!part) { - return; - } - if (m_expansionDepth > 0) { - --m_expansionDepth; - adjustDepth(); - updateIncrDecreaseButton(); - } else { - QApplication::beep(); - } -} - -void DOMTreeView::adjustDepth() -{ - // get current item in a hypersmart way - DOMListViewItem *cur_node_item = m_itemdict.value(infoNode.handle(), nullptr); - if (!cur_node_item) { - cur_node_item = static_cast(m_listView->currentItem()); - } - - for (int i = 0; i < m_listView->topLevelItemCount(); ++i) { - QTreeWidgetItem *topLevelItem = m_listView->topLevelItem(i); - adjustDepthRecursively(topLevelItem, 0); - } - - // make current item visible again if possible - if (cur_node_item) { - m_listView->scrollToItem(cur_node_item); - } - -} - -void DOMTreeView::adjustDepthRecursively(QTreeWidgetItem *curItem, uint currDepth) -{ - if (!curItem) { - return; - } - - m_listView->setItemExpanded(curItem, m_expansionDepth > currDepth); - - for (int cp = 0; cp < curItem->childCount(); ++cp) { - adjustDepthRecursively(curItem->child(cp), currDepth + 1); - } -} - -void DOMTreeView::setMessage(const QString &msg) -{ - messageLine->setText(msg); - messageLinePane->show(); -} - -void DOMTreeView::hideMessageLine() -{ - messageLinePane->hide(); -} - -void DOMTreeView::moveToParent() -{ - // This is a hypersmart algorithm. - // If infoNode is defined, go to the parent of infoNode, otherwise, go - // to the parent of the tree view's current item. - // Hope this isn't too smart. - - DOM::Node cur = infoNode; - if (cur.isNull() && m_listView->currentItem()) { - cur = static_cast(m_listView->currentItem())->node(); - } - - if (cur.isNull()) { - return; - } - - cur = cur.parentNode(); - activateNode(cur); -} - -void DOMTreeView::showDOMTreeContextMenu(const QPoint &pos) -{ - QMenu *ctx = mainWindow()->domTreeViewContextMenu(); - Q_ASSERT(ctx); - ctx->popup(m_listView->mapToGlobal(pos)); -} - -void DOMTreeView::slotPureToggled(bool b) -{ - m_bPure = b; - refresh(); -} - -void DOMTreeView::slotShowAttributesToggled(bool b) -{ - m_bShowAttributes = b; - refresh(); -} - -void DOMTreeView::slotHighlightHTMLToggled(bool b) -{ - m_bHighlightHTML = b; - refresh(); -} - -void DOMTreeView::deleteNodes() -{ -// kDebug(90180) ; - - DOM::Node last; - MultiCommand *cmd = new MultiCommand(i18n("Delete Nodes")); - QTreeWidgetItemIterator it(m_listView, QTreeWidgetItemIterator::Selected); - for (; *it; ++it) { - DOMListViewItem *item = static_cast(*it); -// kDebug(90180) << " item->node " << item->node().nodeName().string() << " clos " << item->isClosing(); - if (item->isClosing()) { - continue; - } - - // don't regard node more than once - if (item->node() == last) { - continue; - } - - // check for selected parent - bool has_selected_parent = false; - for (QTreeWidgetItem *p = item->parent(); p; p = p->parent()) { - if (p->isSelected()) { - has_selected_parent = true; - break; - } - } - if (has_selected_parent) { - continue; - } - -// kDebug(90180) << " item->node " << item->node().nodeName().string() << ": schedule for removal"; - // remove this node if it isn't already recursively removed by its parent - cmd->addCommand(new RemoveNodeCommand(item->node(), item->node().parentNode(), item->node().nextSibling())); - last = item->node(); - } - mainWindow()->executeAndAddCommand(cmd); -} - -void DOMTreeView::disconnectFromTornDownPart() -{ - if (!part) { - return; - } - - m_listView->clear(); - initializeOptionsFromNode(DOM::Node()); - - // remove all references to nodes - infoNode = DOM::Node(); // ### have this handled by dedicated info node panel method - current_node = DOM::Node(); - active_node_rule = DOM::CSSRule(); - stylesheet = DOM::CSSStyleSheet(); -} - -void DOMTreeView::connectToPart() -{ - if (part) { - connect(part, SIGNAL(nodeActivated(DOM::Node)), this, - SLOT(activateNode(DOM::Node))); - connect(part, SIGNAL(completed()), this, SLOT(refresh())); - - if (!part->document().isNull()) { - connectToDocument(); - } else { - // TODO: regularly poll for a document? wait for a signal? - } - } else { - slotShowTree(DOM::Node()); - } - - updateIncrDecreaseButton(); -} - -void DOMTreeView::connectToDocument() -{ - assert(part); - assert(!part->document().isNull()); - - { - // insert a style rule to indicate activated nodes - try { - kDebug(90180) << "(1) part.document: " << part->document().handle(); - stylesheet = part->document().implementation().createCSSStyleSheet("-domtreeviewer-style", "screen"); - kDebug(90180) << "(2)"; - stylesheet.insertRule(":focus { outline: medium #f00 solid }", 0); - // ### for testing only -// stylesheet.insertRule("body { background: #f0f !important }", 1); - kDebug(90180) << "(3)"; - active_node_rule = stylesheet.cssRules().item(0); - kDebug(90180) << "(4)"; - part->document().addStyleSheet(stylesheet); - kDebug(90180) << "(5)"; - } catch (DOM::CSSException &ex) { - kDebug(90180) << "CSS Exception " << ex.code; - } catch (DOM::DOMException &ex) { - kDebug(90180) << "DOM Exception " << ex.code; - } - } - - slotShowTree(part->document()); - updateIncrDecreaseButton(); -} - -void DOMTreeView::disconnectFromActivePart() -{ - if (!part) { - return; - } - - // remove style sheet - try { - part->document().removeStyleSheet(stylesheet); - } catch (DOM::CSSException &ex) { - kDebug(90180) << "CSS Exception " << ex.code; - } catch (DOM::DOMException &ex) { - kDebug(90180) << "DOM Exception " << ex.code; - } - -} - -void DOMTreeView::slotSetHtmlPartDelayed() -{ - connectToPart(); - emit htmlPartChanged(part); -} - -void DOMTreeView::slotRestoreScrollOffset() -{ - m_listView->setUpdatesEnabled(true); - m_listView->horizontalScrollBar()->setValue(scroll_ofs_x); - m_listView->verticalScrollBar()->setValue(scroll_ofs_y); -} - -void DOMTreeView::slotAddElementDlg() -{ - DOMListViewItem *item = static_cast(m_listView->currentItem()); - if (!item) { - return; - } - - QString qname; - QString namespc; - SignalReceiver addBefore; - - { - ElementEditDialog dlg(this); - dlg.setModal(true); - connect(dlg.button(KDialog::User2), SIGNAL(clicked()), &addBefore, SLOT(slot())); - - // ### activate when namespaces are supported - dlg.elemNamespace->setEnabled(false); - - if (dlg.exec() != QDialog::Accepted) { - return; - } - - qname = dlg.elemName->text(); - namespc = dlg.elemNamespace->currentText(); - } - - DOM::Node curNode = item->node(); - - try { - DOM::Node parent = addBefore() ? curNode.parentNode() : curNode; - DOM::Node after = addBefore() ? curNode : nullptr; - - // ### take namespace into account - DOM::Node newNode = curNode.ownerDocument().createElement(qname); - - ManipulationCommand *cmd = new InsertNodeCommand(newNode, parent, after); - mainWindow()->executeAndAddCommand(cmd); - - if (cmd->isValid()) { - activateNode(newNode); - } - - } catch (DOM::DOMException &ex) { - mainWindow()->addMessage(ex.code, domErrorMessage(ex.code)); - } -} - -void DOMTreeView::slotAddTextDlg() -{ - DOMListViewItem *item = static_cast(m_listView->currentItem()); - if (!item) { - return; - } - - QString text; - SignalReceiver addBefore; - - { - TextEditDialog dlg(this); - dlg.setModal(true); - connect(dlg.button(KDialog::User2), SIGNAL(clicked()), &addBefore, SLOT(slot())); - - if (dlg.exec() != QDialog::Accepted) { - return; - } - - text = dlg.textPane->toPlainText(); - } - - DOM::Node curNode = item->node(); - - try { - DOM::Node parent = addBefore() ? curNode.parentNode() : curNode; - DOM::Node after = addBefore() ? curNode : nullptr; - - DOM::Node newNode = curNode.ownerDocument().createTextNode(text); - - ManipulationCommand *cmd = new InsertNodeCommand(newNode, parent, after); - mainWindow()->executeAndAddCommand(cmd); - - if (cmd->isValid()) { - activateNode(newNode); - } - - } catch (DOM::DOMException &ex) { - mainWindow()->addMessage(ex.code, domErrorMessage(ex.code)); - } -} - -// == DOM Node info panel ============================================= - -static QString *clickToAdd; - -/** - * List view item for attribute list. - */ -class AttributeListItem : public QTreeWidgetItem -{ - typedef QTreeWidgetItem super; - - bool _new; - -public: - AttributeListItem(QTreeWidget *parent, QTreeWidgetItem *prev) - : super(parent, prev), _new(true) - { - if (!clickToAdd) { - clickToAdd = new QString(i18n("")); - } - setText(0, *clickToAdd); - QColor c = QApplication::palette().color(QPalette::Disabled, - QPalette::Text); - setForeground(0, c); - setFirstColumnSpanned(true); - } - - AttributeListItem(const QString &attrName, const QString &attrValue, - QTreeWidget *parent, QTreeWidgetItem *prev) - : super(parent, prev), _new(false) - { - setText(0, attrName); - setText(1, attrValue); - } - - bool isNew() const - { - return _new; - } - void setNew(bool s) - { - _new = s; - } - - bool operator<(const QTreeWidgetItem &other) const override - { - // Keep the "Add" item at the end - if (_new) { - return false; - } - if (static_cast(other).isNew()) { - return true; - } - return QTreeWidgetItem::operator<(other); - } -}; - -void DOMTreeView::initDOMNodeInfo() -{ - connect(m_listView, SIGNAL(itemClicked(QTreeWidgetItem*,int)), - SLOT(initializeOptionsFromListItem(QTreeWidgetItem*))); - - connect(nodeAttributes, SIGNAL(itemRenamed(QTreeWidgetItem*,QString,int)), - SLOT(slotItemRenamed(QTreeWidgetItem*,QString,int))); - connect(nodeAttributes, SIGNAL(itemClicked(QTreeWidgetItem*,int)), - SLOT(slotEditAttribute(QTreeWidgetItem*,int))); - nodeAttributes->setContextMenuPolicy(Qt::CustomContextMenu); - connect(nodeAttributes, SIGNAL(customContextMenuRequested(QPoint)), - SLOT(showInfoPanelContextMenu(QPoint))); - - connect(applyContent, SIGNAL(clicked()), SLOT(slotApplyContent())); - - ManipulationCommand::connect(SIGNAL(nodeChanged(DOM::Node)), this, SLOT(initializeOptionsFromNode(DOM::Node))); - - // ### nodeAttributes->setRenameable(0, true); - // ### nodeAttributes->setRenameable(1, true); - - nodeInfoStack->setCurrentIndex(EmptyPanel); - - installEventFilter(nodeAttributes); -} - -void DOMTreeView::initializeOptionsFromNode(const DOM::Node &node) -{ - infoNode = node; - - nodeName->clear(); - nodeType->clear(); - nodeNamespace->clear(); - nodeValue->clear(); - - if (node.isNull()) { - nodeInfoStack->setCurrentIndex(EmptyPanel); - return; - } - - nodeName->setText(node.nodeName().string()); - nodeType->setText(QString::number(node.nodeType())); - nodeNamespace->setText(node.namespaceURI().string()); -// nodeValue->setText(node.value().string()); - - initializeStyleSheetsFromDocument(node.ownerDocument()); - - DOM::Element element = node; - if (!element.isNull()) { - initializeOptionsFromElement(element); - return; - } - - DOM::CharacterData cdata = node; - if (!cdata.isNull()) { - initializeOptionsFromCData(cdata); - return; - } - - // Fallback - nodeInfoStack->setCurrentIndex(EmptyPanel); -} - -void DOMTreeView::initializeOptionsFromListItem(QTreeWidgetItem *item) -{ - const DOMListViewItem *cur_item = static_cast(item); - -// kDebug(90180) << "cur_item: " << cur_item; - initializeOptionsFromNode(cur_item ? cur_item->node() : DOM::Node()); -} - -void DOMTreeView::initializeOptionsFromElement(const DOM::Element &element) -{ - initializeDOMInfoFromElement(element); - initializeCSSInfoFromElement(element); -} - -void DOMTreeView::initializeDOMInfoFromElement(const DOM::Element &element) -{ - QTreeWidgetItem *last = nullptr; - nodeAttributes->clear(); - - DOM::NamedNodeMap attrs = element.attributes(); - unsigned long lmap = attrs.length(); - for (unsigned int j = 0; j < lmap; j++) { - DOM::Attr attr = attrs.item(j); -// kDebug(90180) << attr.name().string() << "=" << attr.value().string(); - QTreeWidgetItem *item = new AttributeListItem(attr.name().string(), - attr.value().string(), - nodeAttributes, last); - last = item; - } - - // append new item - last = new AttributeListItem(nodeAttributes, last); - - nodeAttributes->sortByColumn(0, Qt::AscendingOrder); - - nodeInfoStack->setCurrentIndex(ElementPanel); -} - -void DOMTreeView::initializeCSSInfoFromElement(const DOM::Element &element) -{ - DOM::Document doc = element.ownerDocument(); - DOM::AbstractView view = doc.defaultView(); - DOM::CSSStyleDeclaration styleDecl = view.getComputedStyle(element, - DOM::DOMString()); - - unsigned long l = styleDecl.length(); - cssProperties->clear(); - cssProperties->setEnabled(true); - QList items; - for (unsigned long i = 0; i < l; ++i) { - DOM::DOMString name = styleDecl.item(i); - DOM::DOMString value = styleDecl.getPropertyValue(name); - - QStringList values; - values.append(name.string()); - values.append(value.string()); - items.append(new QTreeWidgetItem(static_cast(nullptr), values)); - } - - cssProperties->insertTopLevelItems(0, items); - cssProperties->resizeColumnToContents(0); -} - -void DOMTreeView::initializeStyleSheetsFromDocument(const DOM::Document &doc) -{ - styleSheetsTree->clear(); - styleSheetsTree->setEnabled(true); - - DOM::StyleSheetList sheets = doc.styleSheets(); - unsigned long l = sheets.length(); - for (unsigned long i = 0; i < l; ++i) { - DOM::StyleSheet sheet = sheets.item(i); - // some info about the sheet itself - QString str = "type=\"" + sheet.type().string() + "\""; - if (!sheet.href().isEmpty()) { - str += " href=\"" + sheet.href().string() + "\""; - } - if (!sheet.title().isEmpty()) { - str += " title=\"" + sheet.title().string() + "\""; - } - if (sheet.disabled()) { - str += QLatin1String(" disabled"); - } - QStringList strList = QStringList(str); - QTreeWidgetItem *topLevel = new QTreeWidgetItem(strList); - styleSheetsTree->addTopLevelItem(topLevel); - - // list the content - DOM::CSSStyleSheet cssSheet(sheet); - if (!cssSheet.isNull()) { - DOM::CSSRuleList cssRules = cssSheet.cssRules(); - unsigned long numRules = cssRules.length(); - for (unsigned long r = 0; r < numRules; ++r) { - DOM::CSSRule rule = cssRules.item(r); - QString cssText = rule.cssText().string(); - (void)new QTreeWidgetItem(topLevel, QStringList(cssText)); - } - } - } -} - -void DOMTreeView::initializeOptionsFromCData(const DOM::CharacterData &cdata) -{ - initializeDOMInfoFromCData(cdata); - initializeCSSInfoFromCData(cdata); -} - -void DOMTreeView::initializeDOMInfoFromCData(const DOM::CharacterData &cdata) -{ - contentEditor->setText(cdata.data().string()); - - DOM::Text text = cdata; - contentEditor->setEnabled(!text.isNull()); - - nodeInfoStack->setCurrentIndex(CDataPanel); -} - -void DOMTreeView::initializeCSSInfoFromCData(const DOM::CharacterData &) -{ - cssProperties->clear(); - cssProperties->setEnabled(false); -} - -void DOMTreeView::slotItemRenamed(QTreeWidgetItem *lvi, const QString &str, int col) -{ - AttributeListItem *item = static_cast(lvi); - - DOM::Element element = infoNode; - if (element.isNull()) { - return; // Should never happen - } - - switch (col) { - case 0: { - ManipulationCommand *cmd; -// kDebug(90180) << "col 0: " << element.nodeName() << " isNew: " << item->isNew(); - if (item->isNew()) { - cmd = new AddAttributeCommand(element, str, item->text(1)); - item->setNew(false); - } else { - cmd = new RenameAttributeCommand(element, item->text(0), str); - } - - mainWindow()->executeAndAddCommand(cmd); - break; - } - case 1: { - if (item->isNew()) { - lvi->setText(1, QString()); - break; - } - - ChangeAttributeValueCommand *cmd = new ChangeAttributeValueCommand( - element, item->text(0), str); - mainWindow()->executeAndAddCommand(cmd); - break; - } - } -} - -void DOMTreeView::slotEditAttribute(QTreeWidgetItem *lvi, int col) -{ - if (!lvi) { - return; - } - - QString attrName; - QString attrValue; - bool newItem = static_cast(lvi)->isNew(); - int res = 0; - - { - AttributeEditDialog dlg(this); - dlg.setModal(true); - if (!newItem) { - dlg.attrName->setText(lvi->text(0)); - dlg.attrValue->setText(lvi->text(1)); - } - if (col == 0) { - dlg.attrName->setFocus(); - dlg.attrName->selectAll(); - } else { - dlg.attrValue->setFocus(); - dlg.attrValue->selectAll(); - } - - res = dlg.exec(); - - attrName = dlg.attrName->text(); - attrValue = dlg.attrValue->toPlainText(); - } - -// kDebug(90180) << "name=" << attrName << " value=" << attrValue; - - if (res == QDialog::Accepted) do { - if (attrName.isEmpty()) { - break; - } - - if (lvi->text(0) != attrName) { - // hack: set value to assign attribute/value pair in one go - lvi->setText(1, attrValue); - - slotItemRenamed(lvi, attrName, 0); - // Reget, item may have been changed - QList il = nodeAttributes->findItems(attrName, - Qt::MatchExactly, - 0); - assert(il.count() == 1); - lvi = il.at(0); - } - - if (lvi && lvi->text(1) != attrValue) { - slotItemRenamed(lvi, attrValue, 1); - } - - } while (false) /*end if*/; -} - -void DOMTreeView::slotApplyContent() -{ - DOM::CharacterData cdata = infoNode; - - if (cdata.isNull()) { - return; - } - - ManipulationCommand *cmd = new ChangeCDataCommand(cdata, contentEditor->toPlainText()); - mainWindow()->executeAndAddCommand(cmd); -} - -void DOMTreeView::showInfoPanelContextMenu(const QPoint &pos) -{ - QMenu *ctx = mainWindow()->infoPanelAttrContextMenu(); - Q_ASSERT(ctx); - ctx->popup(nodeAttributes->mapToGlobal(pos)); -} - -void DOMTreeView::copyAttributes() -{ - // TODO implement me -} - -void DOMTreeView::cutAttributes() -{ - // TODO implement me -} - -void DOMTreeView::pasteAttributes() -{ - // TODO implement me -} - -void DOMTreeView::deleteAttributes() -{ - MultiCommand *cmd = new MultiCommand(i18n("Delete Attributes")); - QTreeWidgetItemIterator it(nodeAttributes, QTreeWidgetItemIterator::Selected); - for (; *it; ++it) { - AttributeListItem *item = static_cast(*it); - if (item->isNew()) { - continue; - } - - cmd->addCommand(new RemoveAttributeCommand(infoNode, item->text(0))); - } - mainWindow()->executeAndAddCommand(cmd); -} - diff --git a/plugins/domtreeviewer/domtreeviewbase.ui b/plugins/domtreeviewer/domtreeviewbase.ui deleted file mode 100644 --- a/plugins/domtreeviewer/domtreeviewbase.ui +++ /dev/null @@ -1,406 +0,0 @@ - - DOMTreeViewBase - - - - 0 - 0 - 663 - 583 - - - - - 600 - 380 - - - - DOM Tree Viewer - - - - - - QFrame::Panel - - - QFrame::Plain - - - - 0 - - - 1 - - - - - - 75 - true - - - - false - - - true - - - - - - - - 10 - - - - &List - - - true - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 20 - - - - - - - - - 10 - - - - H&ide - - - true - - - - - - - - - - true - - - true - - - true - - - - DOM Tree - - - - - - - - 0 - - - - DOM Node - - - - - - 0 - - - - - Node &value: - - - false - - - nodeValue - - - - - - - Node &type: - - - false - - - nodeType - - - - - - - Namespace &URI: - - - false - - - nodeNamespace - - - - - - - Node &name: - - - false - - - nodeName - - - - - - - true - - - true - - - - - - - true - - - true - - - - - - - true - - - true - - - - - - - true - - - true - - - - - - - - - - - 0 - - - - - Qt::StrongFocus - - - false - - - true - - - - Name - - - - - Value - - - - - - - - - - 0 - - - 0 - - - - - false - - - true - - - - - - - 0 - - - - - Appl&y - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 81 - 20 - - - - - - - - - - - - - - nodeInfoStack - - - - Computed Style - - - - - - false - - - false - - - true - - - 2 - - - - Property - - - - - Value - - - - - - - - - Stylesheets - - - - - - false - - - true - - - - 1 - - - - - - - - - - - - - - KLineEdit - QLineEdit -
klineedit.h
-
- - KTextEdit - QTextEdit -
ktextedit.h
-
-
- - m_listView - nodeName - nodeNamespace - nodeType - nodeValue - contentEditor - applyContent - nodeAttributes - - - klineedit.h - ktextedit.h - - - -
diff --git a/plugins/domtreeviewer/domtreeviewerui.rc b/plugins/domtreeviewer/domtreeviewerui.rc deleted file mode 100644 --- a/plugins/domtreeviewer/domtreeviewerui.rc +++ /dev/null @@ -1,49 +0,0 @@ - - - - &File - - &Edit - - &View - - - - - - - - - - - &Go - - - -Main Toolbar - -Tree Toolbar - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/domtreeviewer/domtreewindow.h b/plugins/domtreeviewer/domtreewindow.h deleted file mode 100644 --- a/plugins/domtreeviewer/domtreewindow.h +++ /dev/null @@ -1,210 +0,0 @@ -/* This file is part of the KDE project - * - * Copyright (C) 2005 Leo Savernik - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef domtreewindow_H -#define domtreewindow_H - -#include - -#include - -namespace domtreeviewer -{ -class ManipulationCommand; -} - -namespace KParts -{ -class Part; -class PartManager; -} - -class DOMTreeView; -class PluginDomtreeviewer; - -class QAction; -class KConfig; -class KUndoStack; -class KHTMLPart; -class MessageDialog; - -class QMenu; - -/** - * This class serves as the main window for DOM Tree Viewer. It handles the - * menus, toolbars, and status bars. - * - * @short Main window class - * @author Leo Savernik - */ -class DOMTreeWindow : public KXmlGuiWindow -{ - Q_OBJECT -public: - /** - * Default Constructor - */ - DOMTreeWindow(PluginDomtreeviewer *plugin); - - /** - * Default Destructor - */ - ~DOMTreeWindow() override; - - /** - * returns the dom tree view - */ - DOMTreeView *view() const - { - return m_view; - } - - /** - * returns the command history - */ - KUndoStack *commandHistory() const - { - return m_commandHistory; - } - - /** - * creates and returns the context menu for the list info panel - */ - QMenu *createInfoPanelAttrContextMenu(); - - /** - * returns the context menu for the list info panel - */ - QMenu *infoPanelAttrContextMenu() - { - return infopanel_ctx; - } - - /** - * creates and returns the context menu for the DOM tree view - */ - QMenu *createDOMTreeViewContextMenu(); - - /** - * returns the context menu for the DOM tree view - */ - QMenu *domTreeViewContextMenu() - { - return domtree_ctx; - } - - /** - * Executes the given command and adds it to the history. - * - * If the command could not be executed, it will not be added. - */ - void executeAndAddCommand(domtreeviewer::ManipulationCommand *); - - /** - * Returns the config object for this plugin. - */ - KConfig *config() const - { - return _config; - } - - /** returns the attribute delete action */ - QAction *deleteAttributeAction() const - { - return del_attr; - } - /** returns the node delete action */ - QAction *deleteNodeAction() const - { - return del_tree; - } - -public slots: - /** - * Adds a log message - * @param id message id - * @param msg message text - */ - void addMessage(int id, const QString &msg); - - /** - * Displays the message log window. - */ - void showMessageLog(); - -protected: - /** - * Overridden virtuals for Qt drag 'n drop (XDND) - */ - void dragEnterEvent(QDragEnterEvent *event) override; - void dropEvent(QDropEvent *event) override; -protected: - /** - * This function is called when it is time for the app to save its - * properties for session management purposes. - */ - void saveProperties(KConfigGroup &) override; - - /** - * This function is called when this app is restored. The KConfig - * object points to the session management config file that was saved - * with @ref saveProperties - */ - void readProperties(const KConfigGroup &) override; - -private slots: - void slotCut(); - void slotCopy(); - void slotPaste(); - //void slotUndo(); - //void slotRedo(); - void slotFind(); - void optionsConfigureToolbars(); - void optionsPreferences(); - void newToolbarConfig(); - - void changeStatusbar(const QString &text); - void changeCaption(const QString &text); - - void slotHtmlPartChanged(KHTMLPart *); - void slotActivePartChanged(KParts::Part *); - void slotPartRemoved(KParts::Part *); - void slotClosePart(); - -private: - void setupAccel(); - void setupActions(); - -private: - PluginDomtreeviewer *m_plugin; - DOMTreeView *m_view; - MessageDialog *msgdlg; - - KUndoStack *m_commandHistory; - QMenu *infopanel_ctx; - QMenu *domtree_ctx; - KConfig *_config; - - QAction *del_tree, *del_attr; - - QPointer part_manager; -}; - -#endif // domtreewindow_H diff --git a/plugins/domtreeviewer/domtreewindow.cpp b/plugins/domtreeviewer/domtreewindow.cpp deleted file mode 100644 --- a/plugins/domtreeviewer/domtreewindow.cpp +++ /dev/null @@ -1,430 +0,0 @@ -/* This file is part of the KDE project - * - * Copyright (C) 2005 Leo Savernik - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "domtreewindow.h" -#include "domtreeview.h" -#include "domtreecommands.h" -#include "plugin_domtreeviewer.h" -#include "ui_messagedialog.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -//KDELibs4Support -#include -#include - - -class MessageDialog : public KDialog, public Ui::MessageDialog -{ -public: - MessageDialog(QWidget *parent) - : KDialog(parent) - { - setupUi(mainWidget()); - - setWindowTitle(i18nc("@title:window", "Message Log")); - setButtons(Close | User1); - setButtonGuiItem(User1, KStandardGuiItem::clear()); - - QPalette pal = messagePane->palette(); - pal.setColor(messagePane->backgroundRole(), palette().color(QPalette::Active, QPalette::Base)); - messagePane->setPalette(pal); - - connect(this, &KDialog::closeClicked, this, &QWidget::close); - connect(this, SIGNAL(user1Clicked()), messagePane, SLOT(clear())); - } - - void addMessage(const QString &msg) - { - messagePane->append(msg); - } -}; - -using domtreeviewer::ManipulationCommand; - -DOMTreeWindow::DOMTreeWindow(PluginDomtreeviewer *plugin) - : KXmlGuiWindow(nullptr), - m_plugin(plugin), m_view(new DOMTreeView(this)) -{ - setObjectName(QStringLiteral("DOMTreeWindow")); - part_manager = nullptr; - - // set configuration object - _config = new KConfig(QStringLiteral("domtreeviewerrc")); - - // accept dnd - setAcceptDrops(true); - - // tell the KXmlGuiWindow that this is indeed the main widget - setCentralWidget(m_view); - - // message window dialog - msgdlg = new MessageDialog(nullptr); -// msgdlg->show(); - - // then, setup our actions - setupActions(); - - // Add typical actions and save size/toolbars/statusbar - setupGUI(ToolBar | Keys | StatusBar | Save | Create, KStandardDirs::locate("data", QStringLiteral("domtreeviewer/domtreeviewerui.rc"))); - - // allow the view to change the statusbar and caption -#if 0 - connect(m_view, SIGNAL(signalChangeStatusbar(QString)), - this, SLOT(changeStatusbar(QString))); - connect(m_view, SIGNAL(signalChangeCaption(QString)), - this, SLOT(changeCaption(QString))); -#endif - connect(view(), SIGNAL(htmlPartChanged(KHTMLPart*)), - SLOT(slotHtmlPartChanged(KHTMLPart*))); - - ManipulationCommand::connect(SIGNAL(error(int,QString)), - this, SLOT(addMessage(int,QString))); - - infopanel_ctx = createInfoPanelAttrContextMenu(); - domtree_ctx = createDOMTreeViewContextMenu(); - -} - -DOMTreeWindow::~DOMTreeWindow() -{ - kDebug(90180) << this; - delete m_commandHistory; - delete msgdlg; - delete _config; -} - -void DOMTreeWindow::executeAndAddCommand(ManipulationCommand *cmd) -{ - m_commandHistory->push(cmd); // calls cmd->redo() - if (!cmd->isValid()) { - cmd->undo(); - // TODO: ideally, remove the command from m_commandHistory, but I don't see how to do that. - } else { - view()->hideMessageLine(); - } -} - -void DOMTreeWindow::setupActions() -{ - KStandardAction::close(this, SLOT(close()), actionCollection()); - - KStandardAction::cut(this, &DOMTreeWindow::slotCut, actionCollection())->setEnabled(false); - KStandardAction::copy(this, &DOMTreeWindow::slotCopy, actionCollection())->setEnabled(false); - KStandardAction::paste(this, &DOMTreeWindow::slotPaste, actionCollection())->setEnabled(false); - - m_commandHistory = new KUndoStack; - - QAction *undoAction = m_commandHistory->createUndoAction(actionCollection()); - connect(undoAction, SIGNAL(triggered()), m_commandHistory, SLOT(undo())); - QAction *redoAction = m_commandHistory->createRedoAction(actionCollection()); - connect(redoAction, SIGNAL(triggered()), m_commandHistory, SLOT(redo())); - - KStandardAction::find(this, SLOT(slotFind()), actionCollection()); - - KStandardAction::redisplay(m_view, SLOT(refresh()), actionCollection()); - - // Show/hide options - QAction *pure = actionCollection()->addAction(QStringLiteral("show_dom_pure")); - pure->setText(i18n("Pure DOM Tree")); - pure->setCheckable(true); - pure->setChecked(true); - connect(pure, SIGNAL(toggled(bool)), m_view, SLOT(slotPureToggled(bool))); - - QAction *attr = actionCollection()->addAction(QStringLiteral("show_dom_attributes")); - attr->setText(i18n("Show DOM Attributes")); - attr->setCheckable(true); - attr->setChecked(true); - connect(attr, SIGNAL(toggled(bool)), - m_view, SLOT(slotShowAttributesToggled(bool))); - - QAction *highlight = actionCollection()->addAction(QStringLiteral("show_highlight_html")); - highlight->setText(i18n("Highlight HTML")); - highlight->setCheckable(true); - highlight->setChecked(true); - connect(highlight, SIGNAL(toggled(bool)), - m_view, SLOT(slotHighlightHTMLToggled(bool))); - - // toggle manipulation dialog - QAction *a = actionCollection()->addAction(QStringLiteral("show_msg_dlg")); - a->setText(i18n("Show Message Log")); - actionCollection()->setDefaultShortcut(a, Qt::CTRL + Qt::Key_E); - connect(a, SIGNAL(triggered()), this, SLOT(showMessageLog())); - -// KAction *custom = new KAction(i18n("Cus&tom Menuitem"), 0, -// this, SLOT(optionsPreferences()), -// actionCollection(), "custom_action"); - - // actions for the dom tree list view toolbar - QAction *tree = KStandardAction::up(view(), SLOT(moveToParent()), actionCollection()); - actionCollection()->addAction(QStringLiteral("tree_up"), tree); - QAction *tree_inc_level = actionCollection()->addAction(QStringLiteral("tree_inc_level")); - tree_inc_level->setText(i18n("Expand")); - tree_inc_level->setIcon(QIcon::fromTheme(QStringLiteral("arrow-right"))); - actionCollection()->setDefaultShortcut(tree_inc_level, QKeySequence(Qt::CTRL + Qt::Key_Greater)); - tree_inc_level->setToolTip(i18n("Increase expansion level")); - connect(tree_inc_level, SIGNAL(triggered()), view(), SLOT(increaseExpansionDepth())); - QAction *tree_dec_level = actionCollection()->addAction(QStringLiteral("tree_dec_level")); - tree_dec_level->setText(i18n("Collapse")); - tree_dec_level->setIcon(QIcon::fromTheme(QStringLiteral("arrow-left"))); - actionCollection()->setDefaultShortcut(tree_dec_level, QKeySequence(Qt::CTRL + Qt::Key_Less)); - tree_dec_level->setToolTip(i18n("Decrease expansion level")); - connect(tree_dec_level, SIGNAL(triggered()), view(), SLOT(decreaseExpansionDepth())); - - // actions for the dom tree list view context menu - - del_tree = actionCollection()->addAction(QStringLiteral("tree_delete")); - del_tree->setText(i18n("&Delete")); - del_tree->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete"))); - actionCollection()->setDefaultShortcut(del_tree, QKeySequence(Qt::Key_Delete)); - del_tree->setToolTip(i18n("Delete nodes")); - del_tree->setShortcutContext(Qt::WidgetShortcut); - view()->m_listView->addAction(del_tree); - connect(del_tree, SIGNAL(triggered()), view(), SLOT(deleteNodes())); - QAction *new_elem = actionCollection()->addAction(QStringLiteral("tree_add_element")); - new_elem->setText(i18n("New &Element...")); - new_elem->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); - connect(new_elem, SIGNAL(triggered()), view(), SLOT(slotAddElementDlg())); - QAction *new_text = actionCollection()->addAction(QStringLiteral("tree_add_text")); - new_text->setText(i18n("New &Text Node...")); - new_text->setIcon(QIcon::fromTheme(QStringLiteral("draw-text"))); - connect(new_text, SIGNAL(triggered()), view(), SLOT(slotAddTextDlg())); - - // actions for the info panel attribute list context menu - del_attr = actionCollection()->addAction(QStringLiteral("attr_delete")); - del_attr->setText(i18n("&Delete")); - del_attr->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete"))); - actionCollection()->setDefaultShortcut(del_attr, QKeySequence(Qt::Key_Delete)); - del_attr->setToolTip(i18n("Delete attributes")); - del_attr->setShortcutContext(Qt::WidgetShortcut); - view()->nodeAttributes->addAction(del_attr); - connect(del_attr, SIGNAL(triggered()), view(), SLOT(deleteAttributes())); - -} - -QMenu *DOMTreeWindow::createInfoPanelAttrContextMenu() -{ - QWidget *w = factory()->container(QStringLiteral("infopanelattr_context"), this); - Q_ASSERT(w); - return static_cast(w); -} - -QMenu *DOMTreeWindow::createDOMTreeViewContextMenu() -{ - QWidget *w = factory()->container(QStringLiteral("domtree_context"), this); - Q_ASSERT(w); - return static_cast(w); -} - -void DOMTreeWindow::saveProperties(KConfigGroup &config) -{ - // the 'config' object points to the session managed - // config file. anything you write here will be available - // later when this app is restored - -#if 0 - if (!m_view->currentURL().isNull()) { - config.writePathEntry("lastURL", m_view->currentURL()); -#endif - } - - void DOMTreeWindow::readProperties(const KConfigGroup & config) { - // the 'config' object points to the session managed - // config file. this function is automatically called whenever - // the app is being restored. read in here whatever you wrote - // in 'saveProperties' - -#if 0 - QString url = config.readPathEntry("lastURL", QString()); - - if (!url.isEmpty()) { - m_view->openUrl(KUrl::fromPathOrUrl(url)); - } -#endif - } - - void DOMTreeWindow::dragEnterEvent(QDragEnterEvent * event) { - // accept uri drops only - event->setAccepted(event->mimeData()->hasUrls()); - } - - void DOMTreeWindow::dropEvent(QDropEvent * event) { - // this is a very simplistic implementation of a drop event. we - // will only accept a dropped URL. the Qt dnd code can do *much* - // much more, so please read the docs there - - // see if we can decode a URI.. if not, just ignore it - QList urls = event->mimeData()->urls(); - if (!urls.isEmpty()) { - // okay, we have a URI.. process it - const QUrl &url = urls.first(); -#if 0 - // load in the file - load(url); -#endif - } - } - - void DOMTreeWindow::addMessage(int msg_id, const QString & msg) { - QDateTime t(QDateTime::currentDateTime()); - QString fullmsg = t.toString(); - fullmsg += ':'; - - if (msg_id != 0) { - fullmsg += " (" + QString::number(msg_id) + ") "; - } - fullmsg += msg; - - if (msgdlg) { - msgdlg->addMessage(fullmsg); - } - view()->setMessage(msg); - kWarning() << fullmsg; - } - void DOMTreeWindow::slotCut() { - // TODO implement - } - - void DOMTreeWindow::slotCopy() { - // TODO implement - } - - void DOMTreeWindow::slotPaste() { - // TODO implement - } - - void DOMTreeWindow::slotFind() { - view()->slotFindClicked(); - } - - void DOMTreeWindow::showMessageLog() { - msgdlg->show(); - msgdlg->raise(); - msgdlg->activateWindow(); - } - - void DOMTreeWindow::optionsConfigureToolbars() { - // use the standard toolbar editor - KConfigGroup autoSaveGrp = config()->group(autoSaveGroup()); - saveMainWindowSettings(autoSaveGrp); - KEditToolBar dlg(actionCollection()); - connect(&dlg, SIGNAL(newToolbarConfig()), this, SLOT(newToolbarConfig())); - dlg.exec(); - } - - void DOMTreeWindow::newToolbarConfig() { - // this slot is called when user clicks "Ok" or "Apply" in the toolbar editor. - // recreate our GUI, and re-apply the settings (e.g. "text under icons", etc.) - createGUI(KStandardDirs::locate("data", QStringLiteral("domtreeviewer/domtreeviewerui.rc"))); - applyMainWindowSettings(config()->group(autoSaveGroup())); - } - - void DOMTreeWindow::optionsPreferences() { -#if 0 - // popup some sort of preference dialog, here - DOMTreeWindowPreferences dlg; - if (dlg.exec()) { - // redo your settings - } -#endif - } - - void DOMTreeWindow::changeStatusbar(const QString & text) { - // display the text on the statusbar - statusBar()->showMessage(text); - } - - void DOMTreeWindow::changeCaption(const QString & text) { - // display the text on the caption - setCaption(text); - } - - void DOMTreeWindow::slotHtmlPartChanged(KHTMLPart * p) { - kDebug(90180) << p; - - if (p) { - // set up manager connections - if (part_manager) { - disconnect(part_manager); - } - - part_manager = p->manager(); - - connect(part_manager, SIGNAL(activePartChanged(KParts::Part*)), - SLOT(slotActivePartChanged(KParts::Part*))); - connect(part_manager, SIGNAL(partRemoved(KParts::Part*)), - SLOT(slotPartRemoved(KParts::Part*))); - - // set up browser extension connections - connect(p, SIGNAL(docCreated()), SLOT(slotClosePart())); - } - } - - void DOMTreeWindow::slotActivePartChanged(KParts::Part * p) { - kDebug(90180) << p; - if (p == view()->htmlPart()) { - return; - } - - m_commandHistory->clear(); - view()->disconnectFromTornDownPart(); - view()->setHtmlPart(qobject_cast(p)); - } - - void DOMTreeWindow::slotPartRemoved(KParts::Part * p) { - kDebug(90180) << p; - if (p != view()->htmlPart()) { - return; - } - - m_commandHistory->clear(); - view()->disconnectFromTornDownPart(); - view()->setHtmlPart(nullptr); - } - - void DOMTreeWindow::slotClosePart() { - kDebug(90180); - view()->disconnectFromTornDownPart(); - view()->connectToPart(); - } - diff --git a/plugins/domtreeviewer/elementeditwidget.ui b/plugins/domtreeviewer/elementeditwidget.ui deleted file mode 100644 --- a/plugins/domtreeviewer/elementeditwidget.ui +++ /dev/null @@ -1,100 +0,0 @@ - - ElementEditWidget - - - - 0 - 0 - 469 - 58 - - - - - 0 - - - - - 0 - - - - - Element &name: - - - false - - - elemName - - - - - - - - - - - - 0 - - - - - Element &namespace: - - - false - - - elemNamespace - - - - - - - - 0 - 0 - - - - true - - - false - - - false - - - - - - - - - - - KComboBox - QComboBox -
kcombobox.h
-
- - KLineEdit - QLineEdit -
klineedit.h
-
-
- - klineedit.h - kcombobox.h - klineedit.h - - - -
diff --git a/plugins/domtreeviewer/messagedialog.ui b/plugins/domtreeviewer/messagedialog.ui deleted file mode 100644 --- a/plugins/domtreeviewer/messagedialog.ui +++ /dev/null @@ -1,44 +0,0 @@ - - MessageDialog - - - - 0 - 0 - 511 - 282 - - - - - 0 - - - - - false - - - true - - - false - - - - - - - - - KTextEdit - QTextEdit -
ktextedit.h
-
-
- - ktextedit.h - - - -
diff --git a/plugins/domtreeviewer/plugin_domtreeviewer.h b/plugins/domtreeviewer/plugin_domtreeviewer.h deleted file mode 100644 --- a/plugins/domtreeviewer/plugin_domtreeviewer.h +++ /dev/null @@ -1,24 +0,0 @@ - -#ifndef __plugin_domtreeviewer_h -#define __plugin_domtreeviewer_h - -#include - -class DOMTreeWindow; - -class PluginDomtreeviewer : public KParts::Plugin -{ - Q_OBJECT -public: - PluginDomtreeviewer(QObject *parent, - const QVariantList &); - ~PluginDomtreeviewer() override; - -public slots: - void slotShowDOMTree(); - void slotDestroyed(); -private: - DOMTreeWindow *m_dialog; -}; - -#endif diff --git a/plugins/domtreeviewer/plugin_domtreeviewer.cpp b/plugins/domtreeviewer/plugin_domtreeviewer.cpp deleted file mode 100644 --- a/plugins/domtreeviewer/plugin_domtreeviewer.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "plugin_domtreeviewer.h" -#include "domtreewindow.h" -#include "domtreeview.h" - - -#include - -#include -#include -#include -#include -#include - -//KDELibs4Support - - -K_PLUGIN_FACTORY(DomtreeviewerFactory, registerPlugin();) - -PluginDomtreeviewer::PluginDomtreeviewer(QObject *parent, - const QVariantList &) - : Plugin(parent), m_dialog(nullptr) -{ - QAction *a = actionCollection()->addAction(QStringLiteral("viewdomtree")); - - a->setText(i18n("Show &DOM Tree")); - a->setIcon(QIcon::fromTheme(QStringLiteral("view-web-browser-dom-tree"))); - connect(a, SIGNAL(triggered()), this, SLOT(slotShowDOMTree())); -} - -PluginDomtreeviewer::~PluginDomtreeviewer() -{ - kDebug(90180); - delete m_dialog; -} - -void PluginDomtreeviewer::slotShowDOMTree() -{ - if (m_dialog) { - delete m_dialog; - Q_ASSERT((DOMTreeWindow *)m_dialog == (DOMTreeWindow *)nullptr); - } - if (KHTMLPart *part = qobject_cast(parent())) { - m_dialog = new DOMTreeWindow(this); - connect(m_dialog, SIGNAL(destroyed()), this, SLOT(slotDestroyed())); - m_dialog->view()->setHtmlPart(part); - m_dialog->show(); - } -} - -void PluginDomtreeviewer::slotDestroyed() -{ - kDebug(90180); - m_dialog = nullptr; -} - -#include diff --git a/plugins/domtreeviewer/plugin_domtreeviewer.desktop b/plugins/domtreeviewer/plugin_domtreeviewer.desktop deleted file mode 100644 --- a/plugins/domtreeviewer/plugin_domtreeviewer.desktop +++ /dev/null @@ -1,137 +0,0 @@ -[Desktop Entry] -X-KDE-Library=domtreeviewer -X-KDE-PluginInfo-Author=The Kafka Team, Andreas Schlapbach -X-KDE-PluginInfo-Email=kde-kafka@master.kde.org, schlpbch@iam.unibe.ch -X-KDE-PluginInfo-Name=domtreeviewer -X-KDE-PluginInfo-Version=3.3 -X-KDE-PluginInfo-Website= -X-KDE-PluginInfo-Category=Tools -X-KDE-PluginInfo-Depends= -X-KDE-PluginInfo-License=GPL -X-KDE-PluginInfo-EnabledByDefault=false -Name=DOM Tree Viewer -Name[ar]=عارض شجرة DOM -Name[ast]=Visor d'árboles DOM -Name[bg]=Преглед на дървото на DOM -Name[bs]=Prikazivač DOM stabla -Name[ca]=Visor d'arbres DOM -Name[ca@valencia]=Visor d'arbres DOM -Name[cs]=Prohlížeč DOM stromu -Name[da]=DOM-træviser -Name[de]=Ansicht für DOM-Baum -Name[el]=Προβολέας δέντρου DOM -Name[en_GB]=DOM Tree Viewer -Name[es]=Visor del árbol DOM -Name[et]=DOM-puu näitaja -Name[eu]=DOM zuhaitz-ikustailea -Name[fi]=DOM-puunäkymä -Name[fr]=Afficheur d'arborescence « DOM » -Name[ga]=Amharcán Crainn DOM -Name[gl]=Visor da árbore DOM -Name[he]=מציג עץ DOM -Name[hne]=डाम ट्री प्रदर्सक -Name[hr]=Preglednik DOM stabla -Name[hu]=DOM-fa-megjelenítő -Name[ia]=Visor de arbore DOM -Name[id]=Penampil Hierarki DOM -Name[is]=DOM greinaskoðari -Name[it]=Visore albero DOM -Name[ja]=DOM ツリービューア -Name[kk]=DOM бұтағының көрнісі -Name[km]=កម្មវិធី​មើល​មែកធាង​ DOM -Name[ko]=DOM 트리 뷰어 -Name[ku]=DOM Nîşanderê Wekî Dar -Name[lt]=DOM medžio žiūryklė -Name[lv]=DOM koka rādītājs -Name[mr]=DOM ट्री प्रदर्शक -Name[ms]=Pemapar Pepohon DOM -Name[nb]=DOM trevisning -Name[nds]=DOM-Boom-Kieker -Name[nl]=DOM-boomstructuurweergave -Name[nn]=DOM-trevising -Name[pa]=DOM ਲੜੀ ਦਰਸ਼ਕ -Name[pl]=Przeglądarka drzewa DOM -Name[pt]=Visualizador da Árvore DOM -Name[pt_BR]=Visualizador de árvore DOM -Name[ro]=Vizualizor arbore DOM -Name[ru]=Просмотр дерева DOM -Name[sk]=Prehliadač DOM stromu -Name[sl]=Pregledovalnik dreves DOM -Name[sr]=Приказивач ДОМ стабла -Name[sr@ijekavian]=Приказивач ДОМ стабла -Name[sr@ijekavianlatin]=Prikazivač DOM stabla -Name[sr@latin]=Prikazivač DOM stabla -Name[sv]=DOM-trädvisning -Name[tg]=Нишонгари дарахти DOM -Name[th]=เครื่องมือดูโมเดล DOM ในแบบผังต้นไม้ -Name[tr]=DOM Ağacı Görüntüleyicisi -Name[ug]=DOM شاخسىمان كۆرگۈچ -Name[uk]=Перегляд дерева DOM -Name[wa]=Håyneu d' coxhlaedje DOM -Name[x-test]=xxDOM Tree Viewerxx -Name[zh_CN]=DOM 树查看器 -Name[zh_TW]=DOM 樹狀檢視器 -Comment=View the DOM tree of the current page -Comment[ar]=يعرض شجرة DOM للصفحة الحالية -Comment[ast]=Visualiza l'árbole DOM de la páxina actual -Comment[bg]=Преглед на дървото на DOM за текущата страница -Comment[bs]=Prikazuje DOM stablo trenutne stranice -Comment[ca]=Visualitza l'arbre DOM de la pàgina actual -Comment[ca@valencia]=Visualitza l'arbre DOM de la pàgina actual -Comment[cs]=Prohlédne DOM strom současné stránky -Comment[da]=Vis DOM-træ af den aktuelle side -Comment[de]=DOM-Baum der aktuellen Webseite anzeigen -Comment[el]=Εμφάνιση του δέντρου DOM της τρέχουσας σελίδας -Comment[en_GB]=View the DOM tree of the current page -Comment[es]=Ver el árbol DOM de la página actual -Comment[et]=Näitab aktiivse lehekülje DOM-puud -Comment[eu]=Ikusi uneko orriaren DOM zuhaitza -Comment[fi]=Katso sivun DOM-puuta -Comment[fr]=Affiche l'arborescence « DOM » de la page actuelle -Comment[ga]=Féach ar chrann DOM an leathanaigh reatha -Comment[gl]=Mostra a árbore DOM da páxina actual -Comment[he]=הצג את עץ ה־DOM של הדף הנוכחי -Comment[hne]=अभी हाल के पेज के डाम ट्री देखव -Comment[hr]=Pogledaj DOM stablo trenutne stranice -Comment[hu]=Az aktuális oldal DOM–fájának megjelenítése -Comment[ia]=Vide le arbore DOM del pagina currente -Comment[id]=Tampilan hierarki DOM halaman saat ini -Comment[is]=Skoða DOM uppbyggingu síðunnar -Comment[it]=Visualizza l'albero DOM della pagina corrente -Comment[ja]=現在のページの DOM ツリーを表示します -Comment[kk]=Назардағы беттегі DOM бұтағының көрінісі -Comment[km]=មើល​មែកធាង DOM នៃ​ទំព័រ​បច្ចុប្បន្ន -Comment[ko]=현재 페이지의 DOM 트리 보기 -Comment[ku]=Rûpela heyî bi DOM dîtina wekî dar bibîne -Comment[lt]=Parodyti dabartinio puslapio DOM medį -Comment[lv]=Parāda aktīvās lapas DOM koku -Comment[mr]=वर्तमान पानाचे DOM ट्री बघा -Comment[nb]=Vis DOM-treet til gjeldende side -Comment[nds]=Den DOM-Boom vun de aktuelle Siet ankieken -Comment[nl]=Bekijk de DOM-structuur van de huidige pagina -Comment[nn]=Vis DOM-treet til den gjeldande sida -Comment[pa]=ਮੌਜੂਦਾ ਪੇਜ਼ ਦੀ DOM ਲੜੀ ਵੇਖੋ -Comment[pl]=Zobacz drzewo DOM dla bieżącej strony -Comment[pt]=Vê a árvore DOM da página actual -Comment[pt_BR]=Visualizar a árvore DOM da página atual -Comment[ro]=Vizualizează arborele DOM al paginii curente -Comment[ru]=Смотреть дерево DOM текущей страницы -Comment[sk]=Prezrie DOM strom súčasnej stránky -Comment[sl]=Oglejte si drevo DOM trenutne spletne strani -Comment[sr]=Приказује ДОМ стабло тренутне странице -Comment[sr@ijekavian]=Приказује ДОМ стабло тренутне странице -Comment[sr@ijekavianlatin]=Prikazuje DOM stablo trenutne stranice -Comment[sr@latin]=Prikazuje DOM stablo trenutne stranice -Comment[sv]=Visar DOM-trädet för den aktuella sidan -Comment[tg]=Намоиши дарахти DOM дар саҳифаи ҷорӣ -Comment[th]=ดูผังต้นไม้โมเดล DOM ของหน้าเว็บปัจจุบัน -Comment[tr]=Yürürlükteki sayfanın DOM ağacını göster -Comment[ug]=نۆۋەتتىكى بەتنىڭ DOM ساخسىمان كۆرۈنۈشى -Comment[uk]=Переглянути дерево DOM поточної сторінки -Comment[wa]=Vey li coxhlaedje DOM del pådje do moumint -Comment[x-test]=xxView the DOM tree of the current pagexx -Comment[zh_CN]=查看当前页面的 DOM 树 -Comment[zh_TW]=檢視目前頁面的 DOM 樹狀圖 -Icon=view-web-browser-dom-tree -X-KDE-ParentApp=konqueror -DocPath=konq-plugins/domtreeviewer/index.html diff --git a/plugins/domtreeviewer/plugin_domtreeviewer.rc b/plugins/domtreeviewer/plugin_domtreeviewer.rc deleted file mode 100644 --- a/plugins/domtreeviewer/plugin_domtreeviewer.rc +++ /dev/null @@ -1,11 +0,0 @@ - - - - &Tools - - - -Extra Toolbar - - - diff --git a/plugins/domtreeviewer/signalreceiver.h b/plugins/domtreeviewer/signalreceiver.h deleted file mode 100644 --- a/plugins/domtreeviewer/signalreceiver.h +++ /dev/null @@ -1,73 +0,0 @@ -/* This file is part of the KDE project - * - * Copyright (C) 2005 Leo Savernik - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef KONQ_PLUGIN_SIGNALRECEIVER_H -#define KONQ_PLUGIN_SIGNALRECEIVER_H - -#include - -/** - * \brief Class for receiving signals. - * - * This is a convenience class for receiving signals when it is not worth - * the effort, or overly complicated to introduce a dedicated slot. - * - * Use as follows: - * \code - * SignalReceiver sr; - * sr.connect(some_obj, SIGNAL(someSignal()), SLOT(slot())); - * ... - * if (sr.receivedSignal()) { // yes, signal was received - * } - * \endcode - * - * It is not possible to discriminate between different signals. Hence, - * use different signal receiver instances for different signals. - * @author Leo Savernik - */ -class SignalReceiver : public QObject -{ - Q_OBJECT - -public: - explicit SignalReceiver(QObject *parent = nullptr); - ~SignalReceiver() override; - - /** returns true if any signal has been received */ - bool signalReceived() const - { - return rcvd; - } - - /** returns true if any signal has been received */ - bool operator()() const - { - return rcvd; - } - -public slots: - /** connect a signal to this slot to receive it */ - void slot(); - -private: - bool rcvd; -}; - -#endif // KONQ_PLUGIN_SIGNALRECEIVER_H diff --git a/plugins/domtreeviewer/signalreceiver.cpp b/plugins/domtreeviewer/signalreceiver.cpp deleted file mode 100644 --- a/plugins/domtreeviewer/signalreceiver.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* This file is part of the KDE project - * - * Copyright (C) 2005 Leo Savernik - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "signalreceiver.h" - -SignalReceiver::SignalReceiver(QObject *parent) - : QObject(parent), rcvd(false) -{ -} - -SignalReceiver::~SignalReceiver() -{ -} - -void SignalReceiver::slot() -{ - rcvd = true; -} - diff --git a/plugins/domtreeviewer/texteditwidget.ui b/plugins/domtreeviewer/texteditwidget.ui deleted file mode 100644 --- a/plugins/domtreeviewer/texteditwidget.ui +++ /dev/null @@ -1,57 +0,0 @@ - - TextEditWidget - - - - 0 - 0 - 469 - 117 - - - - - 0 - - - - - Edit &text for text node: - - - false - - - textPane - - - - - - - true - - - true - - - false - - - - - - - - - KTextEdit - QTextEdit -
ktextedit.h
-
-
- - ktextedit.h - - - -