[pim/kcalutils] /: Remove DndFactory::pasteIncidences

Volker Krause <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit d120a07c435997e699275f234f596a1badfb29b6 by Volker Krause.
Committed on 01/08/2026 at 09:56.
Pushed by winterz into branch 'master'.

Remove DndFactory::pasteIncidences

Moved to its single user, korganizer.

M  +0    -5    autotests/CMakeLists.txt
D  +0    -154  autotests/testdndfactory.cpp
D  +0    -37   autotests/testdndfactory.h
M  +1    -124  src/dndfactory.cpp
M  +4    -28   src/dndfactory.h

https://invent.kde.org/pim/kcalutils/-/commit/d120a07c435997e699275f234f596a1badfb29b6

diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index 2d836e56d..8e5f63381 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -9,11 +9,6 @@ set(TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/data")
 set(TEST_PLUGIN_PATH "${CMAKE_BINARY_DIR}/grantlee")
 configure_file(test_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/test_config.h @ONLY)
 
-ecm_add_tests(testdndfactory.cpp teststringify.cpp testtodotooltip.cpp
-    NAME_PREFIX "kcalutils-"
-    LINK_LIBRARIES KPim6CalendarUtils KF6::I18n Qt::Test
-)
-
 ecm_add_test(testincidenceformatter.cpp testincidenceformatter.h
     TEST_NAME "testincidenceformatter"
     NAME_PREFIX "kcalutils-"
diff --git a/autotests/testdndfactory.cpp b/autotests/testdndfactory.cpp
deleted file mode 100644
index b9bf24f10..000000000
--- a/autotests/testdndfactory.cpp
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
-  This file is part of the kcalcore library.
-
-  SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
-  SPDX-FileContributor: Sérgio Martins <[email protected]>
-
-  SPDX-License-Identifier: LGPL-2.0-or-later
-*/
-
-#include "testdndfactory.h"
-
-#include "dndfactory.h"
-
-#include <KCalendarCore/MemoryCalendar>
-#if KCALENDARCORE_VERSION >= QT_VERSION_CHECK(6, 29, 0)
-#include <KCalendarCore/MimeData>
-#endif
-
-#include <QClipboard>
-#include <QGuiApplication>
-#include <QMimeData>
-#include <QTest>
-#include <QTimeZone>
-
-QTEST_MAIN(DndFactoryTest) // clipboard() needs GUI
-
-using namespace KCalendarCore;
-using namespace KCalUtils;
-
-void DndFactoryTest::testPasteAllDayEvent()
-{
-#if KCALENDARCORE_VERSION >= QT_VERSION_CHECK(6, 29, 0)
-    const Event::Ptr allDayEvent(new Event());
-    allDayEvent->setSummary(QStringLiteral("Summary 1"));
-    allDayEvent->setDtStart(QDateTime(QDate(2010, 8, 8), {}));
-    allDayEvent->setDtEnd(QDateTime(QDate(2010, 8, 9), {}));
-    allDayEvent->setAllDay(true);
-    const QString originalUid = allDayEvent->uid();
-    const bool originalIsAllDay = allDayEvent->allDay();
-
-    Incidence::List incidencesToPaste;
-    incidencesToPaste.append(allDayEvent);
-
-    auto mimeData = new QMimeData;
-    KCalendarCore::MimeData::populate(mimeData, incidencesToPaste);
-    qGuiApp->clipboard()->setMimeData(mimeData);
-
-    Incidence::List pastedIncidences = DndFactory::pasteIncidences();
-    QVERIFY(pastedIncidences.size() == 1);
-
-    const Incidence::Ptr &incidence = pastedIncidences.first();
-
-    QVERIFY(incidence->type() == Incidence::TypeEvent);
-
-    // check if a new uid was generated.
-    QVERIFY(incidence->uid() != originalUid);
-
-    // we passed an invalid KDateTime to pasteIncidences() so dates don't change.
-    QVERIFY(incidence->allDay() == originalIsAllDay);
-
-    const Event::Ptr pastedEvent = incidence.staticCast<Event>();
-
-    QCOMPARE(pastedEvent->dtStart(), allDayEvent->dtStart());
-    QCOMPARE(pastedEvent->dtEnd(), allDayEvent->dtEnd());
-    QCOMPARE(pastedEvent->summary(), allDayEvent->summary());
-#endif
-}
-
-void DndFactoryTest::testPasteAllDayEvent2()
-{
-#if KCALENDARCORE_VERSION >= QT_VERSION_CHECK(6, 29, 0)
-
-    const Event::Ptr allDayEvent(new Event());
-    allDayEvent->setSummary(QStringLiteral("Summary 2"));
-    allDayEvent->setDtStart(QDateTime(QDate(2010, 8, 8), {}));
-    allDayEvent->setDtEnd(QDateTime(QDate(2010, 8, 9), {}));
-    allDayEvent->setAllDay(true);
-    const QString originalUid = allDayEvent->uid();
-
-    Incidence::List incidencesToPaste;
-    incidencesToPaste.append(allDayEvent);
-
-    auto mimeData = new QMimeData;
-    KCalendarCore::MimeData::populate(mimeData, incidencesToPaste);
-    qGuiApp->clipboard()->setMimeData(mimeData);
-
-    const QDateTime newDateTime(QDate(2011, 1, 1).startOfDay());
-    const uint originalLength = allDayEvent->dtStart().secsTo(allDayEvent->dtEnd());
-
-    // paste at the new time
-    Incidence::List pastedIncidences = DndFactory::pasteIncidences(newDateTime);
-
-    // we only copied one incidence
-    QVERIFY(pastedIncidences.size() == 1);
-
-    const Incidence::Ptr &incidence = pastedIncidences.first();
-
-    QVERIFY(incidence->type() == Incidence::TypeEvent);
-
-    // check if a new uid was generated.
-    QVERIFY(incidence->uid() != originalUid);
-
-    // the new dateTime didn't have time component
-    QVERIFY(incidence->allDay());
-
-    const Event::Ptr pastedEvent = incidence.staticCast<Event>();
-    const uint newLength = pastedEvent->dtStart().secsTo(pastedEvent->dtEnd());
-    /*
-        qDebug() << "originalLength was " << originalLength << "; and newLength is "
-                 << newLength << "; old dtStart was " << allDayEvent->dtStart()
-                 << " and old dtEnd was " << allDayEvent->dtEnd() << endl
-                 << "; new dtStart is " << pastedEvent->dtStart()
-                 << " and new dtEnd is " << pastedEvent->dtEnd();
-    */
-    QCOMPARE(newLength, originalLength);
-    QCOMPARE(newDateTime, pastedEvent->dtStart());
-    QCOMPARE(allDayEvent->summary(), pastedEvent->summary());
-#endif
-}
-
-void DndFactoryTest::testPasteTodo()
-{
-#if KCALENDARCORE_VERSION >= QT_VERSION_CHECK(6, 29, 0)
-    const Todo::Ptr todo(new Todo());
-    todo->setSummary(QStringLiteral("Summary 1"));
-    todo->setDtDue(QDateTime(QDate(2010, 8, 9), {}));
-
-    Incidence::List incidencesToPaste;
-    incidencesToPaste.append(todo);
-
-    auto mimeData = new QMimeData;
-    KCalendarCore::MimeData::populate(mimeData, incidencesToPaste);
-    qGuiApp->clipboard()->setMimeData(mimeData);
-
-    const QDateTime newDateTime(QDate(2011, 1, 1), QTime(10, 10));
-
-    Incidence::List pastedIncidences = DndFactory::pasteIncidences(newDateTime);
-    QVERIFY(pastedIncidences.size() == 1);
-
-    const Incidence::Ptr &incidence = pastedIncidences.first();
-
-    QVERIFY(incidence->type() == Incidence::TypeTodo);
-
-    // check if a new uid was generated.
-    QVERIFY(incidence->uid() != todo->uid());
-
-    const Todo::Ptr pastedTodo = incidence.staticCast<Todo>();
-
-    QCOMPARE(newDateTime, pastedTodo->dtDue());
-    QCOMPARE(todo->summary(), pastedTodo->summary());
-#endif
-}
-
-#include "moc_testdndfactory.cpp"
diff --git a/autotests/testdndfactory.h b/autotests/testdndfactory.h
deleted file mode 100644
index 74101cfe1..000000000
--- a/autotests/testdndfactory.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
-  This file is part of the kcalutils library.
-
-  SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
-  SPDX-FileContributor: Sérgio Martins <[email protected]>
-
-  SPDX-License-Identifier: LGPL-2.0-or-later
-*/
-
-#pragma once
-
-#include <QObject>
-
-class DndFactoryTest : public QObject
-{
-    Q_OBJECT
-private Q_SLOTS:
-
-    /** Pastes an event without time component (all day). We don't specify a new date/time to
-        DndFactory::pasteIncidences(), so dates of the pasted incidence should be the same as
-        the copied incidence */
-    void testPasteAllDayEvent();
-
-    /** Pastes an event without time component (all day). We specify a new date/time to
-        DndFactory::pasteIncidences(), so dates of the pasted incidence should be different than
-        the copied incidence */
-    void testPasteAllDayEvent2();
-
-    /** Pastes to-do at a given date/time, should change due-date.
-     */
-    void testPasteTodo();
-
-    /** Things that need testing:
-        - Paste to-do, changing dtStart instead of dtDue.
-        - ...
-     */
-};
diff --git a/src/dndfactory.cpp b/src/dndfactory.cpp
index 8cad65046..e48b7af5f 100644
--- a/src/dndfactory.cpp
+++ b/src/dndfactory.cpp
@@ -22,6 +22,7 @@
   @author Reinhold Kainhofer \<[email protected]\>
 */
 #include "dndfactory.h"
+#if KCALENDARCORE_VERSION < QT_VERSION_CHECK(6, 29, 0)
 #include "icaldrag.h"
 #include "vcaldrag.h"
 
@@ -41,83 +42,6 @@
 using namespace KCalendarCore;
 using namespace KCalUtils;
 
-static QDateTime copyTimeSpec(const QDateTime &dt, const QDateTime &source)
-{
-    switch (source.timeSpec()) {
-    case Qt::TimeZone:
-    case Qt::LocalTime:
-    case Qt::UTC:
-        return dt.toTimeZone(source.timeZone());
-    case Qt::OffsetFromUTC:
-        return dt.toOffsetFromUtc(source.offsetFromUtc());
-    }
-
-    Q_UNREACHABLE();
-}
-
-//@cond PRIVATE
-static Incidence::Ptr pasteIncidence(const Incidence::Ptr &incidence, QDateTime newDateTime, DndFactory::PasteFlags pasteOptions)
-{
-    Incidence::Ptr inc(incidence);
-
-    if (inc) {
-        inc = Incidence::Ptr(inc->clone());
-        inc->recreate();
-    }
-
-    if (inc && newDateTime.isValid()) {
-        if (inc->type() == Incidence::TypeEvent) {
-            Event::Ptr const event = inc.staticCast<Event>();
-            if (pasteOptions & DndFactory::FlagPasteAtOriginalTime) {
-                // Set date and preserve time and timezone stuff
-                const QDate date = newDateTime.date();
-                newDateTime = event->dtStart();
-                newDateTime.setDate(date);
-            }
-
-            // in seconds
-            const qint64 durationInSeconds = event->dtStart().secsTo(event->dtEnd());
-            const qint64 durationInDays = event->dtStart().daysTo(event->dtEnd());
-
-            if (incidence->allDay()) {
-                event->setDtStart(QDateTime(newDateTime.date(), {}));
-                event->setDtEnd(newDateTime.addDays(durationInDays));
-            } else {
-                event->setDtStart(copyTimeSpec(newDateTime, event->dtStart()));
-                event->setDtEnd(copyTimeSpec(newDateTime.addSecs(durationInSeconds), event->dtEnd()));
-            }
-        } else if (inc->type() == Incidence::TypeTodo) {
-            Todo::Ptr const aTodo = inc.staticCast<Todo>();
-            const bool pasteAtDtStart = (pasteOptions & DndFactory::FlagTodosPasteAtDtStart);
-            if (pasteOptions & DndFactory::FlagPasteAtOriginalTime) {
-                // Set date and preserve time and timezone stuff
-                const QDate date = newDateTime.date();
-                newDateTime = pasteAtDtStart ? aTodo->dtStart() : aTodo->dtDue();
-                newDateTime.setDate(date);
-            }
-            if (pasteAtDtStart) {
-                aTodo->setDtStart(copyTimeSpec(newDateTime, aTodo->dtStart()));
-            } else {
-                aTodo->setDtDue(copyTimeSpec(newDateTime, aTodo->dtDue()));
-            }
-        } else if (inc->type() == Incidence::TypeJournal) {
-            if (pasteOptions & DndFactory::FlagPasteAtOriginalTime) {
-                // Set date and preserve time and timezone stuff
-                const QDate date = newDateTime.date();
-                newDateTime = inc->dtStart();
-                newDateTime.setDate(date);
-            }
-            inc->setDtStart(copyTimeSpec(newDateTime, inc->dtStart()));
-        } else {
-            qCDebug(KCALUTILS_LOG) << "Trying to paste unknown incidence of type" << int(inc->type());
-        }
-    }
-
-    return inc;
-}
-//@endcond
-
-#if KCALENDARCORE_VERSION < QT_VERSION_CHECK(6, 29, 0)
 Calendar::Ptr DndFactory::createDropCalendar(const QMimeData *mimeData)
 {
     if (mimeData) {
@@ -162,50 +86,3 @@ Todo::Ptr DndFactory::createDropTodo(const QMimeData *mimeData)
     return todo;
 }
 #endif
-
-Incidence::List DndFactory::pasteIncidences(const QDateTime &newDateTime, PasteFlags pasteOptions)
-{
-    QClipboard const *clipboard = QGuiApplication::clipboard();
-    Q_ASSERT(clipboard);
-#if KCALENDARCORE_VERSION < QT_VERSION_CHECK(6, 29, 0)
-    Calendar::Ptr const calendar(createDropCalendar(clipboard->mimeData()));
-#else
-    Calendar::Ptr const calendar(KCalendarCore::MimeData::decodeCalendar(clipboard->mimeData()));
-#endif
-    Incidence::List list;
-
-    if (!calendar) {
-        qCDebug(KCALUTILS_LOG) << "Can't parse clipboard";
-        return list;
-    }
-
-    // All pasted incidences get new uids, must keep track of old uids,
-    // so we can update child's parents
-    QHash<QString, Incidence::Ptr> oldUidToNewInc;
-
-    Incidence::List::ConstIterator it;
-    const Incidence::List incidences = calendar->incidences();
-    Incidence::List::ConstIterator end(incidences.constEnd());
-    for (it = incidences.constBegin(); it != end; ++it) {
-        Incidence::Ptr const incidence = pasteIncidence(*it, newDateTime, pasteOptions);
-        if (incidence) {
-            list.append(incidence);
-            oldUidToNewInc[(*it)->uid()] = *it;
-        }
-    }
-
-    // update relations
-    end = list.constEnd();
-    for (it = list.constBegin(); it != end; ++it) {
-        const Incidence::Ptr &incidence = *it;
-        if (oldUidToNewInc.contains(incidence->relatedTo())) {
-            Incidence::Ptr const parentInc = oldUidToNewInc[incidence->relatedTo()];
-            incidence->setRelatedTo(parentInc->uid());
-        } else {
-            // not related to anything in the clipboard
-            incidence->setRelatedTo(QString());
-        }
-    }
-
-    return list;
-}
diff --git a/src/dndfactory.h b/src/dndfactory.h
index 0ba44d5a5..13289b99a 100644
--- a/src/dndfactory.h
+++ b/src/dndfactory.h
@@ -21,6 +21,9 @@
 
 #include "kcalutils_export.h"
 
+#include <kcalendarcore_version.h>
+#include <qglobal.h>
+#if KCALENDARCORE_VERSION < QT_VERSION_CHECK(6, 29, 0)
 #include <KCalendarCore/Calendar>
 #include <KCalendarCore/Event>
 #include <KCalendarCore/Todo>
@@ -45,17 +48,6 @@ namespace KCalUtils
 class KCALUTILS_EXPORT DndFactory
 {
 public:
-    enum PasteFlag {
-        FlagTodosPasteAtDtStart = 1, /*!< If the cloned incidence is a to-do, the date/time passed
-                                        to DndFactory::pasteIncidence() will change dtStart if this
-                                        flag is on, changes dtDue otherwise. */
-        FlagPasteAtOriginalTime = 2 /*!< If set, incidences will be pasted at the specified date
-                                       but will preserve their original time */
-    };
-
-    Q_DECLARE_FLAGS(PasteFlags, PasteFlag)
-
-#if KCALENDARCORE_VERSION < QT_VERSION_CHECK(6, 29, 0)
     /*!
      Create the calendar that is contained in the mime data.
     */
@@ -70,22 +62,6 @@ public:
       Create Event object from mime data.
     */
     static KCalendarCore::Event::Ptr createDropEvent(const QMimeData *mimeData);
-#endif
-
-    /*!
-      This function clones the incidences that are in the clipboard and sets the clone's
-      date/time to the specified \a newDateTime.
-
-      \a newDateTime The new date/time that the incidence will have. If it's an event
-      or journal, DTSTART will be set. If it's a to-do, DTDUE is set.
-      If you wish another behaviour, like changing DTSTART on to-dos, specify
-      \a pasteOptions. If newDateTime is invalid the original incidence's dateTime
-      will be used, regardless of \a pasteOptions.
-
-      \a pasteOptions Control how \a newDateTime changes the incidence's dates. \sa PasteFlag.
-
-      Returns the cloned incidence.
-    */
-    static KCalendarCore::Incidence::List pasteIncidences(const QDateTime &newDateTime = QDateTime(), PasteFlags pasteOptions = PasteFlags());
 };
 }
+#endif
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.