From a118af29f0d10e732baa7fe364be4091ada06765 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 8 Aug 2012 14:25:40 +0200 Subject: Tools actions restored --- src/CMakeLists.txt | 1 + src/application.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++++ src/application.h | 2 + src/webappcreation.ui | 96 +++++++++++++++++++++++++++++++++++++++++++++ src/webwindow/webwindow.cpp | 39 +++++++++++++++--- src/webwindow/webwindow.h | 2 + 6 files changed, 231 insertions(+), 5 deletions(-) create mode 100644 src/webappcreation.ui diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9cdccb5d..6c41fef6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -146,6 +146,7 @@ KDE4_ADD_UI_FILES( rekonq_KDEINIT_SRCS webtab/sslinfo.ui # ---------------------------------------- cleardata.ui + webappcreation.ui ) diff --git a/src/application.cpp b/src/application.cpp index 57aaa0f8..161ef5c6 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -31,6 +31,9 @@ // Auto Includes #include "rekonq.h" +// Ui Includes +#include "ui_webappcreation.h" + // Local Includes #include "searchengine.h" #include "tabwindow.h" @@ -620,3 +623,96 @@ void Application::clearPrivateData() dialog->deleteLater(); } + + +void Application::createWebAppShortcut() +{ + KUrl u = tabWindow()->currentWebWindow()->url(); + QString h = u.host(); + + QPointer dialog = new KDialog(tabWindow()); + dialog->setCaption(i18nc("@title:window", "Create Application Shortcut")); + dialog->setButtons(KDialog::Ok | KDialog::Cancel); + dialog->button(KDialog::Ok)->setText(i18n("Create")); + dialog->setMinimumSize(400, 50); + dialog->setWindowIcon( QIcon(IconManager::self()->iconForUrl(u).pixmap(16)) ); + + Ui::webAppCreation wAppWidget; + QWidget widget; + wAppWidget.setupUi(&widget); + + const QString title = tabWindow()->currentWebWindow()->title().remove('&'); + wAppWidget.nameLineEdit->setText(title); + wAppWidget.kcfg_createDesktopAppShortcut->setChecked(ReKonfig::createDesktopAppShortcut()); + wAppWidget.kcfg_createMenuAppShortcut->setChecked(ReKonfig::createMenuAppShortcut()); + + dialog->setMainWidget(&widget); + dialog->exec(); + + if (dialog->result() == QDialog::Accepted) + { + ReKonfig::setCreateDesktopAppShortcut(wAppWidget.kcfg_createDesktopAppShortcut->isChecked()); + ReKonfig::setCreateMenuAppShortcut(wAppWidget.kcfg_createMenuAppShortcut->isChecked()); + + IconManager::self()->saveDesktopIconForUrl(u); + QString iconPath = KStandardDirs::locateLocal("cache" , "favicons/" , true) + h + QL1S("_WEBAPPICON.png"); + + QString shortcutString = QL1S("#!/usr/bin/env xdg-open\n") + + QL1S("[Desktop Entry]\n") + + QL1S("Name=") + + (wAppWidget.nameLineEdit->text().isEmpty() + ? QL1S("kwebapp") + : wAppWidget.nameLineEdit->text()) + + QL1S("\n") + + QL1S("GenericName=") + + (wAppWidget.descriptionLineEdit->text().isEmpty() + ? QL1S("") + : wAppWidget.descriptionLineEdit->text()) + + QL1S("\n") + + QL1S("Icon=") + iconPath + QL1S("\n") + + QL1S("Exec=kwebapp ") + u.url() + QL1S("\n") + + QL1S("Type=Application\n") + + QL1S("Categories=Application;Network\n") + ; + + if (ReKonfig::createDesktopAppShortcut()) + { + QString desktop = KGlobalSettings::desktopPath(); + QFile wAppFile(desktop + QL1C('/') + title); + + if (!wAppFile.open(QIODevice::WriteOnly | QIODevice::Text)) + { + kDebug() << "Unable to open file: " << wAppFile.errorString(); + return; + } + + QTextStream out(&wAppFile); + out.setCodec("UTF-8"); + out << shortcutString; + + wAppFile.setPermissions(QFile::ReadUser | QFile::WriteUser | QFile::ExeUser | QFile::ReadGroup | QFile::ReadOther); + wAppFile.close(); + } + + if (ReKonfig::createMenuAppShortcut()) + { + QString appMenuDir = KStandardDirs::locateLocal("xdgdata-apps", QString()); + QFile wAppFile(appMenuDir + QL1C('/') + title + QL1S(".desktop")); + + if (!wAppFile.open(QIODevice::WriteOnly | QIODevice::Text)) + { + kDebug() << "Unable to open file: " << wAppFile.errorString(); + return; + } + + QTextStream out(&wAppFile); + out.setCodec("UTF-8"); + out << shortcutString; + + wAppFile.close(); + } + + } + + dialog->deleteLater(); +} diff --git a/src/application.h b/src/application.h index 760854b4..4934540e 100644 --- a/src/application.h +++ b/src/application.h @@ -102,6 +102,8 @@ private Q_SLOTS: void queryQuit(); + void createWebAppShortcut(); + private: TabWindowList m_tabWindows; }; diff --git a/src/webappcreation.ui b/src/webappcreation.ui new file mode 100644 index 00000000..1e688290 --- /dev/null +++ b/src/webappcreation.ui @@ -0,0 +1,96 @@ + + + webAppCreation + + + + 0 + 0 + 461 + 143 + + + + + + + + + Name: + + + + + + + + + + Description: + + + + + + + + + + (optional) + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Create Application shortcuts in: + + + + + + + Desktop + + + + + + + Application Menu + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/webwindow/webwindow.cpp b/src/webwindow/webwindow.cpp index 72bdc1e8..2dc476c1 100644 --- a/src/webwindow/webwindow.cpp +++ b/src/webwindow/webwindow.cpp @@ -29,8 +29,10 @@ #include "application.h" +#include "adblockmanager.h" #include "bookmarkmanager.h" #include "iconmanager.h" +#include "syncmanager.h" #include "useragentmanager.h" #include "webpage.h" @@ -179,6 +181,7 @@ void WebWindow::setupActions() KStandardAction::open(this, SLOT(fileOpen()), actionCollection()); KStandardAction::saveAs(this, SLOT(fileSaveAs()), actionCollection()); KStandardAction::print(_tab, SLOT(printFrame()), actionCollection()); + KStandardAction::preferences(this, SLOT(preferences()), actionCollection()); KStandardAction::quit(rApp, SLOT(queryQuit()), actionCollection()); a = KStandardAction::fullScreen(this, SLOT(viewFullScreen(bool)), this, actionCollection()); @@ -235,6 +238,26 @@ void WebWindow::setupActions() a->setMenu(uaMenu); connect(uaMenu, SIGNAL(aboutToShow()), this, SLOT(populateUserAgentMenu())); + // Editable Page + a = new KAction(KIcon("document-edit"), i18n("Set Editable"), this); + a->setCheckable(true); + actionCollection()->addAction(QL1S("set_editable"), a); + connect(a, SIGNAL(triggered(bool)), this, SLOT(setEditable(bool))); + + // Adblock + a = new KAction(KIcon("preferences-web-browser-adblock"), i18n("Ad Block"), this); + actionCollection()->addAction(QL1S("adblock"), a); + connect(a, SIGNAL(triggered(bool)), AdBlockManager::self(), 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())); + + // Sync action + a = new KAction(KIcon("tools-wizard"), i18n("Sync"), this); // FIXME sync icon!! + actionCollection()->addAction(QL1S("sync"), a); + connect(a, SIGNAL(triggered(bool)), SyncManager::self(), SLOT(showSettings())); // // --- @@ -252,15 +275,15 @@ void WebWindow::setupActions() // &Tools // + // -// ------- +// + // --------- // + // xxxxxxxxxxx -// ------- +// + // -// -// -// +// + +// + +// + // // // @@ -759,3 +782,9 @@ void WebWindow::populateUserAgentMenu() UserAgentManager::self()->populateUAMenuForTabUrl(uaMenu, this); } + + +void WebWindow::setEditable(bool on) +{ + page()->setContentEditable(on); +} diff --git a/src/webwindow/webwindow.h b/src/webwindow/webwindow.h index ed8a7f2b..ef8a502b 100644 --- a/src/webwindow/webwindow.h +++ b/src/webwindow/webwindow.h @@ -108,10 +108,12 @@ private Q_SLOTS: void fileOpen(); void fileSaveAs(); + // Tools Menu slots void viewPageSource(); void viewFullScreen(bool enable); void populateUserAgentMenu(); + void setEditable(bool); Q_SIGNALS: void titleChanged(QString); -- cgit v1.2.1