From 7187da9812bbe6ffb5bf272f18f8e74c8d23d3c7 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 8 Nov 2011 10:17:36 +0100 Subject: Application Shortcut Added an action to manage it in the tools menu, added initial code to manage icons, added kwebapp application --- src/application.cpp | 32 ++++++++++++++++++++++++++++++++ src/application.h | 2 ++ src/iconmanager.cpp | 13 +++++++++++++ src/iconmanager.h | 2 ++ src/mainwindow.cpp | 5 +++++ src/rekonqui.rc | 3 ++- 6 files changed, 56 insertions(+), 1 deletion(-) (limited to 'src') 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 m_historyManager; QWeakPointer 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 @@ - + @@ -16,6 +16,7 @@ &Tools + -- cgit v1.2.1