9#include "navigationextension.h"
11#include "kparts_logging.h"
13#include <KLocalizedString>
17#include <QApplication>
20#include <QRegularExpression>
32 bool operator[](
int index)
34 return (val & (1 << index)) ? true :
false;
36 void setBit(
int index,
bool value)
39 val = val | (1 << index);
41 val = val & ~(1 << index);
46class NavigationExtensionPrivate
50 : m_urlDropHandlingEnabled(false)
55 struct DelayedRequest {
61 bool m_urlDropHandlingEnabled;
62 KBitArray m_actionStatus;
65 static void createActionSlotMap();
73void NavigationExtensionPrivate::createActionSlotMap()
75 s_actionSlotMap()->insert(
"cut", SLOT(
cut()));
76 s_actionSlotMap()->insert(
"copy", SLOT(
copy()));
77 s_actionSlotMap()->insert(
"paste", SLOT(
paste()));
78 s_actionSlotMap()->insert(
"print", SLOT(
print()));
87 for (
int i = 0; it != itEnd; ++it, ++i) {
89 s_actionNumberMap()->insert(it.key(), i);
97 , d(new NavigationExtensionPrivate(parent))
99 if (s_actionSlotMap()->isEmpty())
102 NavigationExtensionPrivate::createActionSlotMap();
110 for (
int i = 0; it != itEnd; ++it, ++i) {
121NavigationExtension::~NavigationExtension()
139 stream << d->m_part->url() <<
static_cast<qint32
>(
xOffset()) <<
static_cast<qint32
>(
yOffset());
147 stream >> u >> xOfs >> yOfs;
150 args.setXOffset(xOfs);
151 args.setYOffset(yOfs);
153 d->m_part->setArguments(args);
154 d->m_part->openUrl(u);
159 return d->m_urlDropHandlingEnabled;
164 d->m_urlDropHandlingEnabled = enable;
169 QString plain(QStringLiteral(
"plain"));
176 filters.
removeAll(QStringLiteral(
"kuriikwsfilter"));
177 filters.
removeAll(QStringLiteral(
"localdomainurifilter"));
182 switch (filterData.
uriType()) {
186 slotOpenUrlRequest(filterData.
uri());
196 i18n(
"<qt>Do you want to search the Internet for <b>%1</b>?</qt>", url.
toHtmlEscaped()),
197 i18n(
"Internet Search"),
200 QStringLiteral(
"MiddleClickSearch"))
202 slotOpenUrlRequest(filterData.
uri());
210 NavigationExtensionPrivate::DelayedRequest req;
211 req.m_delayedURL = url;
212 req.m_delayedArgs = args;
213 d->m_requests.append(req);
217void NavigationExtension::slotEmitOpenUrlRequestDelayed()
219 if (d->m_requests.isEmpty()) {
222 NavigationExtensionPrivate::DelayedRequest req = d->m_requests.front();
223 d->m_requests.pop_front();
228void NavigationExtension::slotEnableAction(
const char *name,
bool enabled)
232 if (it != s_actionNumberMap()->constEnd()) {
233 d->m_actionStatus.setBit(it.value(), enabled);
236 qCWarning(KPARTSLOG) <<
"BrowserExtension::slotEnableAction unknown action " <<
name;
242 int actionNumber = (*s_actionNumberMap())[name];
243 return d->m_actionStatus[actionNumber];
246void NavigationExtension::slotSetActionText(
const char *name,
const QString &text)
250 if (it != s_actionNumberMap()->constEnd()) {
251 d->m_actionText[it.value()] = text;
253 qCWarning(KPARTSLOG) <<
"BrowserExtension::slotSetActionText unknown action " << name;
259 int actionNumber = (*s_actionNumberMap())[name];
261 if (it != d->m_actionText.constEnd()) {
269 if (s_actionSlotMap()->isEmpty()) {
270 NavigationExtensionPrivate::createActionSlotMap();
272 return s_actionSlotMap();
280#include "moc_navigationextension.cpp"
An extension to KParts::ReadOnlyPart, which allows a better integration of parts with browsers (in pa...
NavigationExtension(KParts::ReadOnlyPart *parent)
Constructor.
void openUrlRequestDelayed(const QUrl &url, const KParts::OpenUrlArguments &arguments)
This signal is emitted when openUrlRequest() is called, after a 0-seconds timer.
static NavigationExtension * childObject(QObject *obj)
Queries obj for a child object which inherits from this BrowserExtension class.
void enableAction(const char *name, bool enabled)
Enables or disable a standard action held by the browser.
bool isURLDropHandlingEnabled() const
Returns whether url drop handling is enabled.
bool isActionEnabled(const char *name) const
virtual int yOffset()
Returns the current y offset.
virtual void restoreState(QDataStream &stream)
Used by the browser to restore the view in the state it was when we left it.
void pasteRequest()
Asks the hosting browser to perform a paste (using openUrlRequestDelayed())
virtual int xOffset()
Returns the current x offset.
void setURLDropHandlingEnabled(bool enable)
Enables or disables url drop handling.
QString actionText(const char *name) const
void openUrlRequest(const QUrl &url, const KParts::OpenUrlArguments &arguments=KParts::OpenUrlArguments())
Asks the host (browser) to open url.
static ActionSlotMap * actionSlotMap()
Returns a pointer to the static map containing the action names as keys and corresponding SLOT()'ifie...
virtual void saveState(QDataStream &stream)
Used by the browser to save the current state of the view (in order to restore it if going back in na...
void setActionText(const char *name, const QString &text)
Change the text of a standard action held by the browser.
OpenUrlArguments is the set of arguments that specify how a URL should be opened by KParts::ReadOnlyP...
Base class for any "viewer" part.
void setData(const QString &url)
void setCheckForExecutables(bool check)
QStringList pluginNames() const
static KUriFilter * self()
QString i18n(const char *text, const TYPE &arg...)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
ButtonCode questionTwoActions(QWidget *parent, const QString &text, const QString &title, const KGuiItem &primaryAction, const KGuiItem &secondaryAction, const QString &dontAskAgainName=QString(), Options options=Notify)
QAction * paste(const QObject *recvr, const char *slot, QObject *parent)
QAction * cut(const QObject *recvr, const char *slot, QObject *parent)
QString name(StandardAction id)
QAction * copy(const QObject *recvr, const char *slot, QObject *parent)
const char * constData() const const
QString text(Mode mode) const const
qsizetype removeAll(const AT &t)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T findChild(const QString &name, Qt::FindChildOptions options) const const
qsizetype length() const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QString toHtmlEscaped() const const
QString trimmed() const const