File indexing completed on 2024-04-28 05:11:36

0001 /*
0002   SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org>
0003   SPDX-FileCopyrightText: 2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0004 
0005   SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "incidencesecrecy.h"
0009 #include "ui_dialogdesktop.h"
0010 
0011 #include <KCalUtils/Stringify>
0012 
0013 using namespace IncidenceEditorNG;
0014 
0015 IncidenceSecrecy::IncidenceSecrecy(Ui::EventOrTodoDesktop *ui)
0016     : mUi(ui)
0017 {
0018     setObjectName(QLatin1StringView("IncidenceSecrecy"));
0019     mUi->mSecrecyCombo->addItems(KCalUtils::Stringify::incidenceSecrecyList());
0020     connect(mUi->mSecrecyCombo, &QComboBox::currentIndexChanged, this, &IncidenceSecrecy::checkDirtyStatus);
0021 }
0022 
0023 void IncidenceSecrecy::load(const KCalendarCore::Incidence::Ptr &incidence)
0024 {
0025     mLoadedIncidence = incidence;
0026     if (mLoadedIncidence) {
0027         Q_ASSERT(mUi->mSecrecyCombo->count() == KCalUtils::Stringify::incidenceSecrecyList().count());
0028         mUi->mSecrecyCombo->setCurrentIndex(mLoadedIncidence->secrecy());
0029     } else {
0030         mUi->mSecrecyCombo->setCurrentIndex(0);
0031     }
0032 
0033     mWasDirty = false;
0034 }
0035 
0036 void IncidenceSecrecy::save(const KCalendarCore::Incidence::Ptr &incidence)
0037 {
0038     Q_ASSERT(incidence);
0039     switch (mUi->mSecrecyCombo->currentIndex()) {
0040     case 1:
0041         incidence->setSecrecy(KCalendarCore::Incidence::SecrecyPrivate);
0042         break;
0043     case 2:
0044         incidence->setSecrecy(KCalendarCore::Incidence::SecrecyConfidential);
0045         break;
0046     default:
0047         incidence->setSecrecy(KCalendarCore::Incidence::SecrecyPublic);
0048     }
0049 }
0050 
0051 bool IncidenceSecrecy::isDirty() const
0052 {
0053     if (mLoadedIncidence) {
0054         if (mLoadedIncidence->secrecy() != mUi->mSecrecyCombo->currentIndex()) {
0055             return true;
0056         }
0057     } else {
0058         if (mUi->mSecrecyCombo->currentIndex() != 0) {
0059             return true;
0060         }
0061     }
0062 
0063     return false;
0064 }
0065 
0066 #include "moc_incidencesecrecy.cpp"