diff options
Diffstat (limited to 'kwebapp')
-rw-r--r-- | kwebapp/CMakeLists.txt | 24 | ||||
-rw-r--r-- | kwebapp/Messages.sh | 3 | ||||
-rw-r--r-- | kwebapp/kwebmain.cpp | 65 | ||||
-rw-r--r-- | kwebapp/webpage.cpp | 63 | ||||
-rw-r--r-- | kwebapp/webpage.h | 51 | ||||
-rw-r--r-- | kwebapp/webview.cpp | 121 | ||||
-rw-r--r-- | kwebapp/webview.h | 45 |
7 files changed, 372 insertions, 0 deletions
diff --git a/kwebapp/CMakeLists.txt b/kwebapp/CMakeLists.txt new file mode 100644 index 00000000..dda4616d --- /dev/null +++ b/kwebapp/CMakeLists.txt @@ -0,0 +1,24 @@ +set( kwebapp_SRCS + webview.cpp + webpage.cpp + kwebmain.cpp + ) + +include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${QT4_INCLUDES} + ${KDE4_INCLUDES} + +) + + +kde4_add_executable(kwebapp ${kwebapp_SRCS}) + +target_link_libraries(kwebapp + ${KDE4_KDEUI_LIBS} + ${KDE4_KDEWEBKIT_LIBS} +) + + +install(TARGETS kwebapp ${INSTALL_TARGETS_DEFAULT_ARGS} ) + diff --git a/kwebapp/Messages.sh b/kwebapp/Messages.sh new file mode 100644 index 00000000..37199e06 --- /dev/null +++ b/kwebapp/Messages.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash +$EXTRACTRC `find . -name \*.rc` >> rc.cpp +$XGETTEXT *.cpp -o $podir/kwebapp.pot diff --git a/kwebapp/kwebmain.cpp b/kwebapp/kwebmain.cpp new file mode 100644 index 00000000..3de5b182 --- /dev/null +++ b/kwebapp/kwebmain.cpp @@ -0,0 +1,65 @@ +/* + * This file is part of the KDE project. + * Copyright (C) 2011 by Andrea Diamantini <adjam7@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "webview.h" + +#include <KDE/KApplication> + +#include <KDE/KAboutData> +#include <KDE/KCmdLineArgs> + +#include <QDebug> +#include <QUrl> + +static const char description[] = + I18N_NOOP("Web Application Viewer"); + +static const char version[] = "0.1"; + +int main(int argc, char **argv) +{ + KAboutData about("kwebapp", 0, ki18n("kwebapp"), version, ki18n(description), + KAboutData::License_GPL, ki18n("(C) 2011 Andrea Diamantini"), KLocalizedString(), 0, "adjam7@gmail.com"); + about.addAuthor(ki18n("Andrea Diamantini"), KLocalizedString(), "adjam7@gmail.com"); + KCmdLineArgs::init(argc, argv, &about); + + KCmdLineOptions options; + options.add("+[URL]", ki18n("Document to open")); + KCmdLineArgs::addCmdLineOptions(options); + + KApplication app; + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + if (args->count() != 1) + { + qDebug() << "ERROR: Impossible to launch kwebapp WITHOUT just ONE url to load!!!"; + return 0; + } + + WebView *widg = new WebView; + widg->show(); + widg->load(QUrl::fromUserInput(args->arg(0))); + args->clear(); + + return app.exec(); +} + diff --git a/kwebapp/webpage.cpp b/kwebapp/webpage.cpp new file mode 100644 index 00000000..f1f3c38d --- /dev/null +++ b/kwebapp/webpage.cpp @@ -0,0 +1,63 @@ +/* + * This file is part of the KDE project. + * Copyright (C) 2011 by Andrea Diamantini <adjam7@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + */ + + +// Self Includes +#include "webpage.h" +#include "webpage.moc" + +// KDE Includes +#include <KRun> + +// Qt Includes +#include <QNetworkRequest> + + +WebPage::WebPage(QObject *parent) + : KWebPage(parent) + , _selfLoading(false) +{ + connect(this, SIGNAL(loadFinished(bool)), this, SLOT(disableSelfLoading())); +} + + +bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type) +{ + if (_selfLoading) + { + return KWebPage::acceptNavigationRequest(frame, request, type); + } + + (void)new KRun(request.url(), view(), 0); + return false; +} + + +void WebPage::setSelfLoadingEnabled(bool b) +{ + _selfLoading = b; +} + + +void WebPage::disableSelfLoading() +{ + _selfLoading = false; +} diff --git a/kwebapp/webpage.h b/kwebapp/webpage.h new file mode 100644 index 00000000..fd8c88f1 --- /dev/null +++ b/kwebapp/webpage.h @@ -0,0 +1,51 @@ +/* + * This file is part of the KDE project. + * Copyright (C) 2011 by Andrea Diamantini <adjam7@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _WEB_PAGE_H +#define _WEB_PAGE_H + + +// KDE Includes +#include <KWebPage> + + +class WebPage : public KWebPage +{ + Q_OBJECT + +public: + WebPage(QObject *parent = 0); + + void setSelfLoadingEnabled(bool); + +private Q_SLOTS: + void disableSelfLoading(); + +protected: + virtual bool acceptNavigationRequest(QWebFrame *, const QNetworkRequest &, NavigationType); + +private: + bool _selfLoading; + +}; + +#endif // _WEB_PAGE_H diff --git a/kwebapp/webview.cpp b/kwebapp/webview.cpp new file mode 100644 index 00000000..7a5ba4c1 --- /dev/null +++ b/kwebapp/webview.cpp @@ -0,0 +1,121 @@ +/*************************************************************************** + * Copyright (C) 2011 by Andrea Diamantini <adjam7@gmail.com> * + * * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + + +// Self Includes +#include "webview.h" +#include "webview.moc" + +// KDE Includes +#include <KIO/Job> +#include <KIO/RenameDialog> +#include <KIO/JobUiDelegate> + +#include <KGlobalSettings> +#include <KStandardDirs> +#include <KFileDialog> +#include <KJobUiDelegate> +#include <KLocalizedString> +#include <KMenu> +#include <KAction> +#include <KUrl> +#include <KRun> + +// Qt Includes +#include <QUrl> +#include <QDebug> +#include <QWebHitTestResult> +#include <QWebHistory> +#include <QNetworkRequest> +#include <QPointer> + + +WebView::WebView(QWidget *parent) + : KWebView(parent) +{ + page()->setForwardUnsupportedContent(true); + connect(page(), SIGNAL(unsupportedContent(QNetworkReply *)), page(), SLOT(downloadResponse(QNetworkReply *))); + connect(page(), SIGNAL(downloadRequested(const QNetworkRequest &)), page(), SLOT(downloadRequest(const QNetworkRequest &))); + connect(this, SIGNAL(linkShiftClicked(const KUrl &)), page(), SLOT(downloadUrl(const KUrl &))); + + QWebSettings::setIconDatabasePath( KStandardDirs::locateLocal("cache","kwebapp.favicons") ); + + setContextMenuPolicy(Qt::CustomContextMenu); + + connect(this, SIGNAL(titleChanged(const QString &)), this, SLOT(setTitle(const QString &))); + connect(this, SIGNAL(iconChanged()), this, SLOT(setIcon())); + connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(menuRequested(const QPoint &))); +} + + +void WebView::setTitle(const QString &t) +{ + setWindowTitle(t); +} + + +void WebView::setIcon() +{ + setWindowIcon(icon()); +} + + +void WebView::menuRequested(const QPoint &pos) +{ + QWebHitTestResult result = page()->mainFrame()->hitTestContent(pos); + + KMenu menu(this); + QAction *a; + + // is a link? + if (!result.linkUrl().isEmpty()) + { + a = new KAction(KIcon("window-new"), i18n("Open in default browser"), this); + a->setData(result.linkUrl()); + connect(a, SIGNAL(triggered(bool)), this, SLOT(openLinkInDefaultBrowser())); + menu.addAction(a); + + menu.addAction(pageAction(KWebPage::DownloadLinkToDisk)); + menu.addAction(pageAction(KWebPage::CopyLinkToClipboard)); + menu.addSeparator(); + } + + if(history()->canGoBack()) + { + menu.addAction(pageAction(KWebPage::Back)); + } + + if(history()->canGoBack()) + { + menu.addAction(pageAction(KWebPage::Forward)); + } + + menu.addAction(pageAction(KWebPage::Reload)); + + menu.exec(mapToGlobal(pos)); +} + + +void WebView::openLinkInDefaultBrowser() +{ + KAction *a = qobject_cast<KAction*>(sender()); + KUrl u(a->data().toUrl()); + + (void)new KRun(u, this, 0); +} diff --git a/kwebapp/webview.h b/kwebapp/webview.h new file mode 100644 index 00000000..536dba8c --- /dev/null +++ b/kwebapp/webview.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2011 by Andrea Diamantini <adjam7@gmail.com> * + * * + * 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. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef WEB_VIEW_H +#define WEB_VIEW_H + + +// Local Includes +#include "webpage.h" + +// KDE Includes +#include <KWebView> + + +class WebView : public KWebView +{ + Q_OBJECT + +public: + WebView(QWidget *parent = 0); + +private Q_SLOTS: + void setTitle(const QString &); + void setIcon(); + void menuRequested(const QPoint &); + void openLinkInDefaultBrowser(); +}; + +#endif // WEB_VIEW_H |