From eea1e2f00325f4048fc42cf945e9a98369e6f8ea Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 8 Nov 2011 10:39:53 +0100 Subject: Application Shortcut, last commit Config dialog, settings REVIEW:103010 --- src/CMakeLists.txt | 1 + src/application.cpp | 87 +++++++++++++++++++++++++++++++++++++++++---------- src/rekonq.kcfg | 6 ++++ src/webappcreation.ui | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 162 insertions(+), 17 deletions(-) create mode 100644 src/webappcreation.ui diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d31b98f7..ced397c7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -102,6 +102,7 @@ KDE4_ADD_UI_FILES( rekonq_KDEINIT_SRCS adblock/settings_adblock.ui cleardata.ui sslinfo.ui + webappcreation.ui useragent/useragentsettings.ui ) diff --git a/src/application.cpp b/src/application.cpp index ea0a65e6..d29324c4 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -33,6 +33,9 @@ // Auto Includes #include "rekonq.h" +// Ui Includes +#include "ui_webappcreation.h" + // Local Includes #include "adblockmanager.h" #include "bookmarkprovider.h" @@ -61,6 +64,7 @@ #include #include #include +#include // Qt Includes #include @@ -771,28 +775,77 @@ void Application::createWebAppShortcut() KUrl u = mainWindow()->currentTab()->url(); QString h = u.host(); - QString desktop = KGlobalSettings::desktopPath(); - QFile wAppFile(desktop + QL1C('/') + h + QL1S(".desktop")); + QPointer dialog = new KDialog(mainWindow()); + dialog->setCaption(i18nc("@title:window", "Create Application Shortcut")); + dialog->setButtons(KDialog::Ok | KDialog::Cancel); + dialog->button(KDialog::Ok)->setText(i18n("Create")); + + Ui::webAppCreation wAppWidget; + QWidget widget; + wAppWidget.setupUi(&widget); + + wAppWidget.iconLabel->setPixmap(iconManager()->iconForUrl(u).pixmap(32)); + wAppWidget.titleLabel->setText(h); + wAppWidget.kcfg_createDesktopAppShortcut->setChecked(ReKonfig::createDesktopAppShortcut()); + wAppWidget.kcfg_createMenuAppShortcut->setChecked(ReKonfig::createMenuAppShortcut()); - if (!wAppFile.open(QIODevice::WriteOnly | QIODevice::Text)) + dialog->setMainWidget(&widget); + dialog->exec(); + + if (dialog->result() == QDialog::Accepted) { - kDebug() << "oops! " << wAppFile.errorString(); - return; - } + ReKonfig::setCreateDesktopAppShortcut(wAppWidget.kcfg_createDesktopAppShortcut->isChecked()); + ReKonfig::setCreateMenuAppShortcut(wAppWidget.kcfg_createMenuAppShortcut->isChecked()); + + iconManager()->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=kwebapp\n") + + QL1S("Icon=") + iconPath + QL1S("\n") + + QL1S("Exec=kwebapp ") + u.url() + QL1S("\n") + + QL1S("Type=Application\n") + + QL1S("Categories=Application;Network;WebBrowser\n") + ; + + if (ReKonfig::createDesktopAppShortcut()) + { + QString desktop = KGlobalSettings::desktopPath(); + QFile wAppFile(desktop + QL1C('/') + h + QL1S(".desktop")); + + if (!wAppFile.open(QIODevice::WriteOnly | QIODevice::Text)) + { + kDebug() << "Unable to open file: " << wAppFile.errorString(); + return; + } - iconManager()->saveDesktopIconForUrl(u); + QTextStream out(&wAppFile); + out.setCodec("UTF-8"); + out << shortcutString; - QString iconPath = KStandardDirs::locateLocal("cache" , "favicons/" , true) + h + QL1S("_WEBAPPICON.png"); + wAppFile.close(); + } - QTextStream out(&wAppFile); - out.setCodec("UTF-8"); + if (ReKonfig::createMenuAppShortcut()) + { + QString appMenuDir = KStandardDirs::locateLocal("xdgdata-apps", QString()); + QFile wAppFile(appMenuDir + QL1C('/') + h + QL1S(".desktop")); - 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"); + 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(); + } + + } - wAppFile.close(); + dialog->deleteLater(); } diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg index f0fc3766..96e71f00 100644 --- a/src/rekonq.kcfg +++ b/src/rekonq.kcfg @@ -30,6 +30,12 @@ 0 + + true + + + false + diff --git a/src/webappcreation.ui b/src/webappcreation.ui new file mode 100644 index 00000000..60fc841d --- /dev/null +++ b/src/webappcreation.ui @@ -0,0 +1,85 @@ + + + webAppCreation + + + + 0 + 0 + 445 + 151 + + + + Form + + + + + + + + + 0 + 0 + + + + ICON + + + + + + + + 0 + 0 + + + + TITLE + + + + + + + + + Create Application shortcuts in: + + + + + + + Desktop + + + + + + + Application MenĂ¹ + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + -- cgit v1.2.1