File indexing completed on 2024-06-09 05:15:51
0001 /* 0002 This file is part of KOrganizer. 0003 0004 SPDX-FileCopyrightText: 2000, 2001 Cornelius Schumacher <schumacher@kde.org> 0005 SPDX-FileCopyrightText: 2005 Rafal Rzepecki <divide@users.sourceforge.net> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0008 */ 0009 0010 #include "koeventviewerdialog.h" 0011 #include "korganizer_debug.h" 0012 #include "korganizerinterface.h" 0013 0014 #include <Akonadi/ETMCalendar> 0015 #include <CalendarSupport/IncidenceViewer> 0016 #include <CalendarSupport/Utils> 0017 0018 #include <Akonadi/Item> 0019 0020 #include <KGuiItem> 0021 #include <KLocalizedString> 0022 #include <QDialogButtonBox> 0023 #include <QIcon> 0024 #include <QPushButton> 0025 #include <QStandardPaths> 0026 #include <QVBoxLayout> 0027 0028 KOEventViewerDialog::KOEventViewerDialog(Akonadi::ETMCalendar *calendar, QWidget *parent) 0029 : QDialog(parent) 0030 , mUser1Button(new QPushButton(this)) 0031 { 0032 setWindowTitle(i18nc("@title:window", "Event Viewer")); 0033 auto mainLayout = new QVBoxLayout(this); 0034 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this); 0035 buttonBox->addButton(mUser1Button, QDialogButtonBox::ActionRole); 0036 auto user2Button = new QPushButton(this); 0037 buttonBox->addButton(user2Button, QDialogButtonBox::ActionRole); 0038 connect(buttonBox, &QDialogButtonBox::rejected, this, &KOEventViewerDialog::reject); 0039 setModal(false); 0040 KGuiItem::assign(mUser1Button, KGuiItem(i18n("Edit..."), QIcon::fromTheme(QStringLiteral("document-edit")))); 0041 KGuiItem::assign(user2Button, KGuiItem(i18n("Show in Context"))); 0042 mEventViewer = new CalendarSupport::IncidenceViewer(calendar, this); 0043 mainLayout->addWidget(mEventViewer); 0044 mainLayout->addWidget(buttonBox); 0045 0046 resize(QSize(500, 520).expandedTo(minimumSizeHint())); 0047 0048 connect(this, &KOEventViewerDialog::finished, this, &KOEventViewerDialog::delayedDestruct); 0049 connect(mUser1Button, &QPushButton::clicked, this, &KOEventViewerDialog::editIncidence); 0050 connect(user2Button, &QPushButton::clicked, this, &KOEventViewerDialog::showIncidenceContext); 0051 } 0052 0053 KOEventViewerDialog::~KOEventViewerDialog() = default; 0054 0055 void KOEventViewerDialog::delayedDestruct() 0056 { 0057 if (isVisible()) { 0058 hide(); 0059 } 0060 0061 deleteLater(); 0062 } 0063 0064 QPushButton *KOEventViewerDialog::editButton() const 0065 { 0066 return mUser1Button; 0067 } 0068 0069 void KOEventViewerDialog::setIncidence(const Akonadi::Item &incidence, const QDate &date) 0070 { 0071 mEventViewer->setIncidence(incidence, date); 0072 } 0073 0074 void KOEventViewerDialog::addText(const QString &text) 0075 { 0076 mEventViewer->setHeaderText(text); 0077 } 0078 0079 void KOEventViewerDialog::editIncidence() 0080 { 0081 const Akonadi::Item item = mEventViewer->item(); 0082 0083 if (CalendarSupport::hasIncidence(item)) { 0084 // make sure korganizer is running or the part is shown 0085 const QString desktopFile = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, QStringLiteral("org.kde.korganizer.desktop")); 0086 QString error; 0087 if (!QDBusConnection::sessionBus().interface()->startService(desktopFile).isValid()) { 0088 OrgKdeKorganizerKorganizerInterface korganizerIface(QStringLiteral("org.kde.korganizer"), 0089 QStringLiteral("/Korganizer"), 0090 QDBusConnection::sessionBus()); 0091 korganizerIface.editIncidence(QString::number(item.id())); 0092 } else { 0093 qCWarning(KORGANIZER_LOG) << "Failure starting korganizer:" << error; 0094 } 0095 } 0096 } 0097 0098 void KOEventViewerDialog::showIncidenceContext() 0099 { 0100 const Akonadi::Item item = mEventViewer->item(); 0101 0102 if (CalendarSupport::hasIncidence(item)) { 0103 // make sure korganizer is running or the part is shown 0104 const QString desktopFile = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, QStringLiteral("org.kde.korganizer.desktop")); 0105 QString error; 0106 if (!QDBusConnection::sessionBus().interface()->startService(desktopFile).isValid()) { 0107 OrgKdeKorganizerKorganizerInterface korganizerIface(QStringLiteral("org.kde.korganizer"), 0108 QStringLiteral("/Korganizer"), 0109 QDBusConnection::sessionBus()); 0110 korganizerIface.showIncidenceContext(QString::number(item.id())); 0111 } else { 0112 qCWarning(KORGANIZER_LOG) << "Failure starting korganizer:" << error; 0113 } 0114 } 0115 } 0116 0117 #include "moc_koeventviewerdialog.cpp"