diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-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 | ||||
-rw-r--r-- | src/application.cpp | 32 | ||||
-rw-r--r-- | src/application.h | 2 | ||||
-rw-r--r-- | src/iconmanager.cpp | 13 | ||||
-rw-r--r-- | src/iconmanager.h | 2 | ||||
-rw-r--r-- | src/mainwindow.cpp | 5 | ||||
-rw-r--r-- | src/rekonqui.rc | 3 |
14 files changed, 430 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index fe562612..1d898884 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,6 +113,8 @@ IF(REKONQ_CAN_BE_COMPILED) ADD_SUBDIRECTORY( docs ) # ADD_SUBDIRECTORY( i18n ) + ADD_SUBDIRECTORY( kwebapp ) + ENDIF(REKONQ_CAN_BE_COMPILED) # ================================================================================ 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 diff --git a/src/application.cpp b/src/application.cpp index df99b785..ea0a65e6 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -764,3 +764,35 @@ void Application::queryQuit() // in case of just one window... quit(); } + + +void Application::createWebAppShortcut() +{ + KUrl u = mainWindow()->currentTab()->url(); + QString h = u.host(); + + QString desktop = KGlobalSettings::desktopPath(); + QFile wAppFile(desktop + QL1C('/') + h + QL1S(".desktop")); + + if (!wAppFile.open(QIODevice::WriteOnly | QIODevice::Text)) + { + kDebug() << "oops! " << wAppFile.errorString(); + return; + } + + iconManager()->saveDesktopIconForUrl(u); + + QString iconPath = KStandardDirs::locateLocal("cache" , "favicons/" , true) + h + QL1S("_WEBAPPICON.png"); + + QTextStream out(&wAppFile); + out.setCodec("UTF-8"); + + out << QL1S("[Desktop Entry]\n"); + out << QL1S("name=kwebapp\n"); + out << QL1S("Icon=") << iconPath << QL1S("\n"); + out << QL1S("Exec=kwebapp ") << u.url() << QL1S("\n"); + out << QL1S("Type=Application\n"); + out << QL1S("Categories=Application;\n"); + + wAppFile.close(); +} diff --git a/src/application.h b/src/application.h index 0c4d3101..30d2b55d 100644 --- a/src/application.h +++ b/src/application.h @@ -134,6 +134,8 @@ private slots: void queryQuit(); + void createWebAppShortcut(); + private: QWeakPointer<HistoryManager> m_historyManager; QWeakPointer<BookmarkProvider> m_bookmarkProvider; diff --git a/src/iconmanager.cpp b/src/iconmanager.cpp index 9ee024e2..ac53fdac 100644 --- a/src/iconmanager.cpp +++ b/src/iconmanager.cpp @@ -225,3 +225,16 @@ void IconManager::notifyLastStuffs(KJob *j) doLastStuffs(j); emit iconChanged(); } + + +void IconManager::saveDesktopIconForUrl(const KUrl &u) +{ + KIcon icon = iconForUrl(u); + QString destPath = _faviconsDir + u.host() + QL1S("_WEBAPPICON.png"); + + QPixmap pix = icon.pixmap(16, 16); + int s = KIconLoader::global()->currentSize(KIconLoader::Desktop); + pix = pix.scaled(s, s); + + pix.save(destPath); +} diff --git a/src/iconmanager.h b/src/iconmanager.h index 8f55b7df..85db5ddd 100644 --- a/src/iconmanager.h +++ b/src/iconmanager.h @@ -54,6 +54,8 @@ public: void clearIconCache(); + void saveDesktopIconForUrl(const KUrl &u); + private Q_SLOTS: void doLastStuffs(KJob *); void notifyLastStuffs(KJob *); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index beab3afc..880e4d47 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -531,6 +531,11 @@ void MainWindow::setupActions() a = new KAction(KIcon("preferences-web-browser-adblock"), i18n("Ad Block"), this); actionCollection()->addAction(QL1S("adblock"), a); connect(a, SIGNAL(triggered(bool)), rApp->adblockManager(), SLOT(showSettings())); + + // Web Applications + a = new KAction(KIcon("applications-internet"), i18n("Create application shortcut"), this); + actionCollection()->addAction(QL1S("webapp_shortcut"), a); + connect(a, SIGNAL(triggered(bool)), rApp, SLOT(createWebAppShortcut())); } diff --git a/src/rekonqui.rc b/src/rekonqui.rc index 66d34980..bad56615 100644 --- a/src/rekonqui.rc +++ b/src/rekonqui.rc @@ -1,6 +1,6 @@ <?xml version="1.0"?> <!DOCTYPE gui SYSTEM "kpartgui.dtd"> -<gui name="rekonq" version="56"> +<gui name="rekonq" version="58"> <!--- =========== Rekonq Menu ============= --> <Menu name="rekonqMenu" noMerge="1"> @@ -16,6 +16,7 @@ <Menu name="toolsMenu" icon="preferences-other" noMerge="1"> <text>&Tools</text> + <Action name="webapp_shortcut" /> <Action name="web_inspector" /> <Action name="page_source" /> <Action name="net_analyzer" /> |