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

0001 /*
0002   SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com>
0003   SPDX-FileCopyrightText: 2009-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 "attendeeeditor.h"
0009 
0010 using namespace IncidenceEditorNG;
0011 
0012 AttendeeEditor::AttendeeEditor(QWidget *parent)
0013     : MultiplyingLineEditor(new AttendeeLineFactory(parent), parent)
0014 {
0015     connect(this, &AttendeeEditor::lineAdded, this, &AttendeeEditor::slotLineAdded);
0016 
0017     addData();
0018 }
0019 
0020 void AttendeeEditor::slotLineAdded(KPIM::MultiplyingLine *line)
0021 {
0022     auto att = qobject_cast<AttendeeLine *>(line);
0023     if (!att) {
0024         return;
0025     }
0026 
0027     connect(att, qOverload<>(&AttendeeLine::changed), this, &AttendeeEditor::slotCalculateTotal);
0028     connect(att, qOverload<const KCalendarCore::Attendee &, const KCalendarCore::Attendee &>(&AttendeeLine::changed), this, &AttendeeEditor::changed);
0029     connect(att, &AttendeeLine::editingFinished, this, &AttendeeEditor::editingFinished);
0030 }
0031 
0032 void AttendeeEditor::slotCalculateTotal()
0033 {
0034     int empty = 0;
0035     int count = 0;
0036 
0037     const QList<KPIM::MultiplyingLine *> listLines = lines();
0038     for (KPIM::MultiplyingLine *line : listLines) {
0039         auto att = qobject_cast<AttendeeLine *>(line);
0040         if (att) {
0041             if (att->isEmpty()) {
0042                 ++empty;
0043             } else {
0044                 ++count;
0045             }
0046         }
0047     }
0048     Q_EMIT countChanged(count);
0049     // We always want at least one empty line
0050     if (empty == 0) {
0051         addData();
0052     }
0053 }
0054 
0055 AttendeeData::List AttendeeEditor::attendees() const
0056 {
0057     const QList<KPIM::MultiplyingLineData::Ptr> dataList = allData();
0058     AttendeeData::List attList; // clazy:exclude=inefficient-qlist
0059     // qCDebug(INCIDENCEEDITOR_LOG) << "num attendees:" << dataList.size();
0060     for (const KPIM::MultiplyingLineData::Ptr &datum : dataList) {
0061         AttendeeData::Ptr att = qSharedPointerDynamicCast<AttendeeData>(datum);
0062         if (!att) {
0063             continue;
0064         }
0065         attList << att;
0066     }
0067     return attList;
0068 }
0069 
0070 void AttendeeEditor::addAttendee(const KCalendarCore::Attendee &attendee)
0071 {
0072     addData(AttendeeData::Ptr(new AttendeeData(attendee)));
0073 }
0074 
0075 void AttendeeEditor::removeAttendee(const AttendeeData::Ptr &attendee)
0076 {
0077     removeData(attendee);
0078 }
0079 
0080 void AttendeeEditor::setActions(AttendeeLine::AttendeeActions actions)
0081 {
0082     const QList<KPIM::MultiplyingLine *> listLines = lines();
0083     for (KPIM::MultiplyingLine *line : listLines) {
0084         auto att = qobject_cast<AttendeeLine *>(line);
0085         att->setActions(actions);
0086     }
0087 }
0088 
0089 #include "moc_attendeeeditor.cpp"