diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2011-11-08 10:39:53 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2011-11-08 10:40:39 +0100 |
commit | eea1e2f00325f4048fc42cf945e9a98369e6f8ea (patch) | |
tree | fe6683814c84b3ddf9725a0db27e82754b4c1f09 /src/application.cpp | |
parent | Application Shortcut (diff) | |
download | rekonq-eea1e2f00325f4048fc42cf945e9a98369e6f8ea.tar.xz |
Application Shortcut, last commit
Config dialog, settings
REVIEW:103010
Diffstat (limited to 'src/application.cpp')
-rw-r--r-- | src/application.cpp | 87 |
1 files changed, 70 insertions, 17 deletions
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 <KWindowInfo> #include <KGlobal> #include <KCharsets> +#include <KPushButton> // Qt Includes #include <QVBoxLayout> @@ -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<KDialog> 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(); } |