Verified Commit f1011445 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Add --view option to display incidence

Summary:
Similar to kmail --view, this opens only the incidence viewer with the specified
incidence. Also introduces korganizer-view service to allow opening the URL
through a desktop file.

Test Plan: korganizer --view "akonadi://?item=<some-incidence-item-akonadi-id>"

Reviewers: #kde_pim, winterz

Reviewed By: #kde_pim, winterz

Subscribers: winterz, kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D29530
parent fe786bee
......@@ -310,7 +310,7 @@ install(FILES
)
install(PROGRAMS
org.kde.korganizer.desktop korganizer-import.desktop
org.kde.korganizer.desktop korganizer-import.desktop korganizer-view.desktop
DESTINATION ${KDE_INSTALL_APPDIR}
)
......
......@@ -38,6 +38,11 @@
#include <QCommandLineParser>
#include <QDBusConnectionInterface>
#include <AkonadiCore/ItemFetchJob>
#include <AkonadiCore/ItemFetchScope>
#include <KMessageBox>
KOrganizerApp::KOrganizerApp(int &argc, char **argv[])
: KontactInterface::PimUniqueApplication(argc, argv)
{
......@@ -64,11 +69,34 @@ int KOrganizerApp::activate(const QStringList &args, const QString &workingDir)
}
first = false;
QDBusConnection::sessionBus().interface()->startService(QStringLiteral("org.kde.korgac"));
QCommandLineParser parser;
korganizer_options(&parser);
parser.process(args);
QDBusConnection::sessionBus().interface()->startService(QStringLiteral("org.kde.korgac"));
if (parser.isSet(QStringLiteral("view"))) {
processCalendar(QUrl(), false);
const auto url = QUrl{parser.value(QStringLiteral("view"))};
auto fetchJob = new Akonadi::ItemFetchJob(Akonadi::Item::fromUrl(url), this);
fetchJob->fetchScope().fetchFullPayload();
connect(fetchJob, &Akonadi::ItemFetchJob::result,
this, [](KJob *job) {
if (job->error()) {
KMessageBox::detailedSorry(nullptr, i18n("Failed to retrieve incidence from Akonadi"), job->errorText());
return;
}
auto fetchJob = static_cast<Akonadi::ItemFetchJob*>(job);
if (fetchJob->count() != 1) {
KMessageBox::sorry(nullptr, i18n("Failed to retrieve incidence from Akonadi: requested incidence doesn't exist."));
return;
}
KOrg::MainWindow *korg = ActionManager::findInstance(QUrl());
korg->actionManager()->view()->showIncidence(fetchJob->items().first());
});
return 0;
}
// No filenames given => all other args are meaningless, show main Window
if (parser.positionalArguments().isEmpty()) {
......@@ -105,14 +133,16 @@ int KOrganizerApp::activate(const QStringList &args, const QString &workingDir)
return 0;
}
void KOrganizerApp::processCalendar(const QUrl &url)
void KOrganizerApp::processCalendar(const QUrl &url, bool show)
{
KOrg::MainWindow *korg = ActionManager::findInstance(url);
if (!korg) {
bool hasDocument = !url.isEmpty();
korg = new KOrganizer();
korg->init(hasDocument);
korg->topLevelWidget()->show();
if (show) {
korg->topLevelWidget()->show();
}
qCDebug(KORGANIZER_LOG) << url.url();
......@@ -121,7 +151,7 @@ void KOrganizerApp::processCalendar(const QUrl &url)
} else {
// korg->view()->updateView();
}
} else {
} else if (show) {
korg->topLevelWidget()->show();
}
}
......@@ -48,7 +48,7 @@ private:
Process calendar from URL \arg url. If url is empty open the default
calendar based on the resource framework.
*/
void processCalendar(const QUrl &url);
void processCalendar(const QUrl &url, bool show = true);
};
#endif
[Desktop Entry]
Name=KOrganizer View
Comment=Display incidence specified by URL
Type=Application
Exec=korganizer --view %u
Icon=korganizer
Terminal=false
NoDisplay=true
MimeType=application/x-vnd.akonadi.calendar.event;application/x-vnd.akonadi.calendar.journal;application/x-vnd.akonadi.calendar.todo;text/calendar
X-KDE-StartupNotify=true
X-DBUS-StartupType=Unique
X-DBUS-ServiceName=org.kde.korganizer
......@@ -37,6 +37,9 @@ static void korganizer_options(QCommandLineParser *parser)
parser->addOption(QCommandLineOption(
QStringList() << QStringLiteral("m") << QStringLiteral("merge"),
i18n("Merge the specified files into an existing calendar")));
parser->addOption(QCommandLineOption(
{QStringLiteral("view")},
i18n("Display the specified incidence (by URL)"), QStringLiteral("url")));
parser->addPositionalArgument(
QStringLiteral("calendars"),
......
Markdown is supported
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