Commit ae94e32b authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Port from KNS3::QtQuickDialogWrapper to KNSWidgets::Action

parent e4f037de
Pipeline #169827 passed with stage
in 5 minutes and 33 seconds
......@@ -339,7 +339,7 @@ target_link_libraries(korganizerprivate
KF5::Mime
KF5::IdentityManagement
KF5::KCMUtils
KF5::NewStuff
KF5::NewStuffWidgets
KF5::Ldap
KF5::AkonadiWidgets
KF5::IconThemes
......
......@@ -63,7 +63,7 @@
#include "korganizer_debug.h"
#include "korganizer_options.h"
#include <KNewStuff3/KNS3/QtQuickDialogWrapper>
#include <KNSWidgets/Action>
#include <KToggleAction>
#include <KWindowSystem>
#include <QIcon>
......@@ -248,20 +248,57 @@ void ActionManager::initActions()
mACollection->addAction(QStringLiteral("import_icalendar"), mImportAction);
connect(mImportAction, &QAction::triggered, this, &ActionManager::file_import);
QAction *action = nullptr;
/** Get Hot New Stuff Action **/
// TODO: Icon
if (KAuthorized::authorize(QStringLiteral("ghns"))) {
action = new QAction(i18n("Get &Hot New Stuff..."), this);
action->setStatusTip(i18nc("@info:status", "Load a calendar from \"Get Hot New Stuff\""));
action->setToolTip(i18nc("@info:tooltip", "Search \"Get Hot New Stuff\" for calendars to import"));
action->setWhatsThis(i18nc("@info:whatsthis",
"This menu entry opens the \"Get Hot New Stuff\" dialog that allows you "
"to search and import fun and useful calendars donated to the community."));
mACollection->addAction(QStringLiteral("downloadnewstuff"), action);
connect(action, &QAction::triggered, this, &ActionManager::downloadNewStuff);
}
auto knsAction = new KNSWidgets::Action(i18n("Get New Calendars..."), QStringLiteral("korganizer.knsrc"), this);
knsAction->setStatusTip(i18nc("@info:status", "Load a calendar from \"Get Hot New Stuff\""));
knsAction->setToolTip(i18nc("@info:tooltip", "Search \"Get Hot New Stuff\" for calendars to import"));
knsAction->setWhatsThis(i18nc("@info:whatsthis",
"This menu entry opens the \"Get Hot New Stuff\" dialog that allows you "
"to search and import fun and useful calendars donated to the community."));
mACollection->addAction(QStringLiteral("downloadnewstuff"), knsAction);
connect(knsAction, &KNSWidgets::Action::dialogFinished, this, [this](auto changedEntries) {
for (const auto &e : changedEntries) {
qCDebug(KORGANIZER_LOG) << " downloadNewStuff :";
const QStringList lstFile = e.installedFiles();
if (lstFile.count() != 1) {
continue;
}
const QString file = lstFile.at(0);
const QUrl filename = QUrl::fromLocalFile(file);
qCDebug(KORGANIZER_LOG) << "filename :" << filename;
if (!filename.isValid()) {
continue;
}
KCalendarCore::FileStorage storage(calendar());
storage.setFileName(file);
storage.setSaveFormat(new KCalendarCore::ICalFormat);
if (!storage.load()) {
KMessageBox::error(mCalendarView, i18n("Could not load calendar %1.", file));
} else {
QStringList eventSummaries;
const KCalendarCore::Event::List events = calendar()->events();
eventSummaries.reserve(events.count());
for (const KCalendarCore::Event::Ptr &event : events) {
eventSummaries.append(event->summary());
}
const int result = KMessageBox::warningContinueCancelList(mCalendarView,
i18n("The downloaded events will be merged into your current calendar."),
eventSummaries);
if (result != KMessageBox::Continue) {
// FIXME (KNS2): hm, no way out here :-)
}
if (importURL(QUrl::fromLocalFile(file), true)) {
// FIXME (KNS2): here neither
}
}
}
});
QAction *action = nullptr;
/** Export Action **/
// TODO: Icon
action = new QAction(i18n("Export as &iCalendar..."), this);
......@@ -1195,49 +1232,6 @@ bool ActionManager::addIncidence(const QString &ical)
return mCalendarView->addIncidence(ical);
}
void ActionManager::downloadNewStuff()
{
const auto installedEntries = KNS3::QtQuickDialogWrapper(QStringLiteral("korganizer.knsrc")).exec();
for (const auto &e : installedEntries) {
qCDebug(KORGANIZER_LOG) << " downloadNewStuff :";
const QStringList lstFile = e.installedFiles();
if (lstFile.count() != 1) {
continue;
}
const QString file = lstFile.at(0);
const QUrl filename = QUrl::fromLocalFile(file);
qCDebug(KORGANIZER_LOG) << "filename :" << filename;
if (!filename.isValid()) {
continue;
}
KCalendarCore::FileStorage storage(calendar());
storage.setFileName(file);
storage.setSaveFormat(new KCalendarCore::ICalFormat);
if (!storage.load()) {
KMessageBox::error(mCalendarView, i18n("Could not load calendar %1.", file));
} else {
QStringList eventSummaries;
const KCalendarCore::Event::List events = calendar()->events();
eventSummaries.reserve(events.count());
for (const KCalendarCore::Event::Ptr &event : events) {
eventSummaries.append(event->summary());
}
const int result =
KMessageBox::warningContinueCancelList(mCalendarView, i18n("The downloaded events will be merged into your current calendar."), eventSummaries);
if (result != KMessageBox::Continue) {
// FIXME (KNS2): hm, no way out here :-)
}
if (importURL(QUrl::fromLocalFile(file), true)) {
// FIXME (KNS2): here neither
}
}
}
}
QString ActionManager::localFileName() const
{
return mFile;
......
......@@ -253,8 +253,6 @@ protected Q_SLOTS:
/** Open kcontrol module for configuring date and time formats */
void configureDateTime();
void downloadNewStuff();
void toggleDateNavigator();
void toggleTodoView();
void toggleEventViewer();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment