diff --git a/calendar-client/src/customWidget/colorseletorwidget.cpp b/calendar-client/src/customWidget/colorseletorwidget.cpp index efb3eba5..7bce3ff6 100644 --- a/calendar-client/src/customWidget/colorseletorwidget.cpp +++ b/calendar-client/src/customWidget/colorseletorwidget.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2024 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -122,7 +122,7 @@ void ColorSeletorWidget::setSelectedColorById(int colorId) } else { ++colorId; } - if (m_colorGroup->buttons().size() > 0) { + if (m_colorGroup->buttons().size() > colorId) { m_colorGroup->buttons().at(colorId)->click(); } } diff --git a/calendar-client/src/dataManage/accountitem.cpp b/calendar-client/src/dataManage/accountitem.cpp index 60bb0634..b1847912 100644 --- a/calendar-client/src/dataManage/accountitem.cpp +++ b/calendar-client/src/dataManage/accountitem.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2024 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -315,8 +315,8 @@ void AccountItem::deleteSchedulesByTypeID(const QString &typeID, CallbackFunc ca void AccountItem::querySchedulesWithParameter(const int year, CallbackFunc callback) { - QDateTime start = QDate(year - 1, 12, 1).startOfDay(); - QDateTime end = QDate(year + 1, 1, 31).startOfDay(); + QDateTime start = QDateTime(QDate(year, 1, 1)); + QDateTime end = QDateTime(QDate(year, 12, 31)); querySchedulesWithParameter(start, end, callback); } diff --git a/calendar-client/src/dbus/dbusaccountrequest.cpp b/calendar-client/src/dbus/dbusaccountrequest.cpp index 3c1a0c63..90af6a7e 100644 --- a/calendar-client/src/dbus/dbusaccountrequest.cpp +++ b/calendar-client/src/dbus/dbusaccountrequest.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2024 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -282,12 +282,12 @@ void DbusAccountRequest::slotCallFinished(CDBusPendingCallWatcher *call) } else if (call->getmember() == "querySchedulesWithParameter") { QDBusPendingReply reply = *call; QString str = reply.argumentAt<0>(); - QMap map = DSchedule::fromMapString(str); + QMap map = DSchedule::fromQueryResult(str); emit signalGetScheduleListFinish(map); } else if (call->getmember() == "searchSchedulesWithParameter") { QDBusPendingReply reply = *call; QString str = reply.argumentAt<0>(); - QMap map = DSchedule::fromMapString(str); + QMap map = DSchedule::fromQueryResult(str); emit signalSearchScheduleListFinish(map); } else if (call->getmember() == "getSysColors") { QDBusPendingReply reply = *call; diff --git a/calendar-common/CMakeLists.txt b/calendar-common/CMakeLists.txt index a2eee76a..0079c06c 100644 --- a/calendar-common/CMakeLists.txt +++ b/calendar-common/CMakeLists.txt @@ -19,9 +19,15 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong -z noexecstack include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) aux_source_directory(src BASESTRUCT_SRCS) aux_source_directory(src/huangliData BASESTRUCT_SRCS_HUANGLI) +aux_source_directory(src/lunarandfestival BASESTRUCT_SRCS_NONGLI) +aux_source_directory(src/pinyin BASESTRUCT_SRCS_PINYIN) link_libraries(${Qt5CORE_LIBRARIES} ${Qt5DBus_LIBRARIES}) -add_library(${PROJECT_NAME} STATIC ${BASESTRUCT_SRCS} ${BASESTRUCT_SRCS_HUANGLI}) +add_library(${PROJECT_NAME} STATIC ${BASESTRUCT_SRCS} + ${BASESTRUCT_SRCS_HUANGLI} + ${BASESTRUCT_SRCS_NONGLI} + ${BASESTRUCT_SRCS_PINYIN} +) target_include_directories(${PROJECT_NAME} PUBLIC ../3rdparty/kcalendarcore/src) target_link_libraries(${PROJECT_NAME} diff --git a/calendar-common/src/dschedule.cpp b/calendar-common/src/dschedule.cpp index f9f1b287..e7a11d59 100644 --- a/calendar-common/src/dschedule.cpp +++ b/calendar-common/src/dschedule.cpp @@ -1,9 +1,10 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2024 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later #include "dschedule.h" #include "commondef.h" +#include "lunarandfestival/lunardateinfo.h" #include "icalformat.h" #include "memorycalendar.h" @@ -343,6 +344,191 @@ QString DSchedule::toMapString(const QMap &scheduleMap) return QString::fromUtf8(jsonDoc.toJson(QJsonDocument::Compact)); } +QPair DSchedule::fromListString(const QString &json) +{ + QPair schedulePair; + QJsonParseError jsonError; + QJsonDocument jsonDoc(QJsonDocument::fromJson(json.toLocal8Bit(), &jsonError)); + if (jsonError.error != QJsonParseError::NoError) { + qCWarning(CommonLogger) << "error:" << jsonError.errorString(); + return schedulePair; + } + + QJsonObject jsonObj = jsonDoc.object(); + DSchedule::List scheduleList; + if (jsonObj.contains("query")) { + schedulePair.first = jsonObj.value("query").toString(); + } + if (jsonObj.contains("schedules")) { + QJsonArray jsonArray = jsonObj.value("schedules").toArray(); + foreach (auto scheduleValue, jsonArray) { + QString scheduleStr = scheduleValue.toString(); + DSchedule::Ptr schedule = DSchedule::Ptr(new DSchedule); + DSchedule::fromJsonString(schedule, scheduleStr); + scheduleList.append(schedule); + } + } + schedulePair.second = scheduleList; + + return schedulePair; +} + +QString DSchedule::toListString(const QString &query, const DSchedule::List &scheduleList) +{ + QJsonObject jsonObj; + jsonObj.insert("query", query); + QJsonArray jsonArray; + foreach (auto &schedule, scheduleList) { + QString scheduleStr; + DSchedule::toJsonString(schedule, scheduleStr); + jsonArray.append(scheduleStr); + } + jsonObj.insert("schedules", jsonArray); + + + QJsonDocument jsonDoc; + jsonDoc.setObject(jsonObj); + return QString::fromUtf8(jsonDoc.toJson(QJsonDocument::Compact)); +} + +void DSchedule::expendRecurrence(DSchedule::Map &scheduleMap, const DSchedule::Ptr &schedule, const QDateTime &dtStart, const QDateTime &dtEnd) +{ + QDateTime queryDtStart = dtStart; + //如果日程为全天日程,则查询的开始时间设置为0点,因为全天日程的开始和结束时间都是0点 + if(schedule->allDay()){ + queryDtStart.setTime(QTime(0,0,0)); + } + if (schedule->recurs()) { + //获取日程的开始结束时间差 + qint64 interval = schedule->dtStart().secsTo(schedule->dtEnd()); + QList dtList = schedule->recurrence()->timesInInterval(queryDtStart, dtEnd); + foreach (auto &dt, dtList) { + QDateTime scheduleDtEnd = dt.addSecs(interval); + DSchedule::Ptr newSchedule = DSchedule::Ptr(schedule->clone()); + newSchedule->setDtStart(dt); + newSchedule->setDtEnd(scheduleDtEnd); + + //只有重复日程设置RecurrenceId + if (schedule->dtStart() != dt) { + newSchedule->setRecurrenceId(dt); + } + scheduleMap[dt.date()].append(newSchedule); + } + } else { + if (!(schedule->dtStart() > dtEnd || schedule->dtEnd() < queryDtStart)) { + scheduleMap[schedule->dtStart().date()].append(schedule); + } + } +} + +QMap DSchedule::convertSchedules(const DScheduleQueryPar::Ptr &queryPar, const DSchedule::List &scheduleList) +{ + QDateTime dtStart = queryPar->dtStart(); + QDateTime dtEnd = queryPar->dtEnd(); + bool extend = queryPar->queryType() == DScheduleQueryPar::Query_None; + + QMap scheduleMap; + foreach (auto &schedule, scheduleList) { + //获取日程的开始结束时间差 + qint64 interval = schedule->dtStart().secsTo(schedule->dtEnd()); + //如果存在重复日程 + if (schedule->recurs()) { + //如果为农历日程 + if (schedule->lunnar()) { + //农历重复日程计算 + LunarDateInfo lunardate(schedule->recurrence()->defaultRRuleConst(), interval); + + QMap ruleStartDate = lunardate.getRRuleStartDate(dtStart.date(), dtEnd.date(), schedule->dtStart().date()); + + QDateTime recurDateTime; + recurDateTime.setTime(schedule->dtStart().time()); + QDateTime copyEnd; + QMap::ConstIterator iter = ruleStartDate.constBegin(); + for (; iter != ruleStartDate.constEnd(); iter++) { + recurDateTime.setDate(iter.value()); + //如果在忽略时间列表中,则忽略 + if (schedule->recurrence()->exDateTimes().contains(recurDateTime)) + continue; + copyEnd = recurDateTime.addSecs(interval); + DSchedule::Ptr newSchedule = DSchedule::Ptr(new DSchedule(*schedule.data())); + newSchedule->setDtStart(recurDateTime); + newSchedule->setDtEnd(copyEnd); + //只有重复日程设置RecurrenceId + if (schedule->dtStart() != recurDateTime) { + newSchedule->setRecurrenceId(recurDateTime); + } + scheduleMap[recurDateTime.date()].append(newSchedule); + } + } else { + //非农历日程 + expendRecurrence(scheduleMap, schedule, dtStart, dtEnd); + } + } else { + //普通日程 + //如果在查询时间范围内 + QDateTime queryDtStart = dtStart; + //如果日程为全天日程,则查询的开始时间设置为0点,因为全天日程的开始和结束时间都是0点 + if(schedule->allDay()){ + queryDtStart.setTime(QTime(0,0,0)); + } + if (!(schedule->dtEnd() < queryDtStart || schedule->dtStart() > dtEnd)) { + if (extend && schedule->isMultiDay()) { + //需要扩展的天数 + int extenddays = static_cast(schedule->dtStart().daysTo(schedule->dtEnd())); + for (int i = 0; i <= extenddays; ++i) { + //如果扩展的日期在查询范围内则添加,否则退出 + if(scheduleMap.contains(schedule->dtStart().date().addDays(i))){ + scheduleMap[schedule->dtStart().date().addDays(i)].append(schedule); + } else { + break; + } + } + } else { + scheduleMap[schedule->dtStart().date()].append(schedule); + } + } + } + } + + //如果为查询前N个日程,则取前N个日程 + if (queryPar->queryType() == DScheduleQueryPar::Query_Top) { + int scheduleNum = 0; + DSchedule::Map filterSchedule; + DSchedule::Map::const_iterator iter = scheduleMap.constBegin(); + for (; iter != scheduleMap.constEnd(); ++iter) { + if (iter.value().size() == 0) { + continue; + } + if (scheduleNum + iter.value().size() > queryPar->queryTop()) { + DSchedule::List scheduleList; + int residuesNum = queryPar->queryTop() - scheduleNum; + for (int i = 0; i < residuesNum; ++i) { + scheduleList.append(iter.value().at(i)); + } + filterSchedule[iter.key()] = scheduleList; + } else { + filterSchedule[iter.key()] = iter.value(); + } + } + scheduleMap = filterSchedule; + } + + return scheduleMap; +} + +QMap DSchedule::fromQueryResult(const QString &query) +{ + QMap scheduleMap; + QPair pair = fromListString(query); + DScheduleQueryPar::Ptr queryPar = DScheduleQueryPar::fromJsonString(pair.first); + if (queryPar.isNull()) { + return scheduleMap; + } + + scheduleMap = DSchedule::convertSchedules(queryPar, pair.second); + return scheduleMap; +} + bool operator==(const DSchedule::Ptr &s1, const DSchedule::Ptr &s2) { return s1.isNull() || s2.isNull() ? s1.isNull() && s2.isNull() : s1->instanceIdentifier() == s2->instanceIdentifier(); diff --git a/calendar-common/src/dschedule.h b/calendar-common/src/dschedule.h index fbc8c4d6..d47c5f9b 100644 --- a/calendar-common/src/dschedule.h +++ b/calendar-common/src/dschedule.h @@ -6,6 +6,7 @@ #define DSCHEDULE_H #include "event.h" +#include "dschedulequerypar.h" #include #include @@ -92,6 +93,13 @@ class DSchedule : public KCalendarCore::Event static QMap fromMapString(const QString &json); static QString toMapString(const QMap &scheduleMap); + static QPair fromListString(const QString &json); + static QString toListString(const QString &query, const DSchedule::List &scheduleList); + + static void expendRecurrence(DSchedule::Map &scheduleMap, const DSchedule::Ptr &schedule, const QDateTime &dtStart, const QDateTime &dtEnd); + static QMap convertSchedules(const DScheduleQueryPar::Ptr &queryPar, const DSchedule::List &scheduleList); + static QMap fromQueryResult(const QString &query); + private: QMap getAlarmMap(); diff --git a/calendar-service/src/lunarandfestival/celestialbodies.cpp b/calendar-common/src/lunarandfestival/celestialbodies.cpp similarity index 100% rename from calendar-service/src/lunarandfestival/celestialbodies.cpp rename to calendar-common/src/lunarandfestival/celestialbodies.cpp diff --git a/calendar-service/src/lunarandfestival/celestialbodies.h b/calendar-common/src/lunarandfestival/celestialbodies.h similarity index 100% rename from calendar-service/src/lunarandfestival/celestialbodies.h rename to calendar-common/src/lunarandfestival/celestialbodies.h diff --git a/calendar-service/src/lunarandfestival/lunarandfestival.h b/calendar-common/src/lunarandfestival/lunarandfestival.h similarity index 100% rename from calendar-service/src/lunarandfestival/lunarandfestival.h rename to calendar-common/src/lunarandfestival/lunarandfestival.h diff --git a/calendar-service/src/lunarandfestival/lunarcalendar.cpp b/calendar-common/src/lunarandfestival/lunarcalendar.cpp similarity index 100% rename from calendar-service/src/lunarandfestival/lunarcalendar.cpp rename to calendar-common/src/lunarandfestival/lunarcalendar.cpp diff --git a/calendar-service/src/lunarandfestival/lunarcalendar.h b/calendar-common/src/lunarandfestival/lunarcalendar.h similarity index 100% rename from calendar-service/src/lunarandfestival/lunarcalendar.h rename to calendar-common/src/lunarandfestival/lunarcalendar.h diff --git a/calendar-service/src/lunarandfestival/lunardateinfo.cpp b/calendar-common/src/lunarandfestival/lunardateinfo.cpp similarity index 100% rename from calendar-service/src/lunarandfestival/lunardateinfo.cpp rename to calendar-common/src/lunarandfestival/lunardateinfo.cpp diff --git a/calendar-service/src/lunarandfestival/lunardateinfo.h b/calendar-common/src/lunarandfestival/lunardateinfo.h similarity index 100% rename from calendar-service/src/lunarandfestival/lunardateinfo.h rename to calendar-common/src/lunarandfestival/lunardateinfo.h diff --git a/calendar-service/src/lunarandfestival/lunarmanager.cpp b/calendar-common/src/lunarandfestival/lunarmanager.cpp similarity index 100% rename from calendar-service/src/lunarandfestival/lunarmanager.cpp rename to calendar-common/src/lunarandfestival/lunarmanager.cpp diff --git a/calendar-service/src/lunarandfestival/lunarmanager.h b/calendar-common/src/lunarandfestival/lunarmanager.h similarity index 100% rename from calendar-service/src/lunarandfestival/lunarmanager.h rename to calendar-common/src/lunarandfestival/lunarmanager.h diff --git a/calendar-service/src/lunarandfestival/method_interface.cpp b/calendar-common/src/lunarandfestival/method_interface.cpp similarity index 100% rename from calendar-service/src/lunarandfestival/method_interface.cpp rename to calendar-common/src/lunarandfestival/method_interface.cpp diff --git a/calendar-service/src/lunarandfestival/method_interface.h b/calendar-common/src/lunarandfestival/method_interface.h similarity index 100% rename from calendar-service/src/lunarandfestival/method_interface.h rename to calendar-common/src/lunarandfestival/method_interface.h diff --git a/calendar-service/src/pinyin/pinyindict.cpp b/calendar-common/src/pinyin/pinyindict.cpp similarity index 100% rename from calendar-service/src/pinyin/pinyindict.cpp rename to calendar-common/src/pinyin/pinyindict.cpp diff --git a/calendar-service/src/pinyin/pinyindict.h b/calendar-common/src/pinyin/pinyindict.h similarity index 100% rename from calendar-service/src/pinyin/pinyindict.h rename to calendar-common/src/pinyin/pinyindict.h diff --git a/calendar-service/src/pinyin/pinyinsearch.cpp b/calendar-common/src/pinyin/pinyinsearch.cpp similarity index 100% rename from calendar-service/src/pinyin/pinyinsearch.cpp rename to calendar-common/src/pinyin/pinyinsearch.cpp diff --git a/calendar-service/src/pinyin/pinyinsearch.h b/calendar-common/src/pinyin/pinyinsearch.h similarity index 100% rename from calendar-service/src/pinyin/pinyinsearch.h rename to calendar-common/src/pinyin/pinyinsearch.h diff --git a/calendar-service/src/calendarDataManager/daccountmodule.cpp b/calendar-service/src/calendarDataManager/daccountmodule.cpp index a9103c87..e3cfce36 100644 --- a/calendar-service/src/calendarDataManager/daccountmodule.cpp +++ b/calendar-service/src/calendarDataManager/daccountmodule.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2024 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -7,8 +7,8 @@ #include "dscheduletype.h" #include "dschedulequerypar.h" #include "memorycalendar.h" -#include "lunardateinfo.h" -#include "lunarmanager.h" +#include "lunarandfestival/lunardateinfo.h" +#include "lunarandfestival/lunarmanager.h" #include "dbus/dbusuiopenschedule.h" #include "dalarmmanager.h" #include "syncfilemanage.h" @@ -442,16 +442,7 @@ QString DAccountModule::querySchedulesWithParameter(const QString ¶ms) if (schedule.isNull()) { return QString(); } - QMap m_scheduleMap; - //相差多少天 - int days = static_cast(queryPar->dtStart().daysTo(queryPar->dtEnd())); - for (int i = 0; i <= days; ++i) { - DSchedule::List scheduleList; - m_scheduleMap[queryPar->dtStart().addDays(i).date()] = scheduleList; - } - extendRecurrence(m_scheduleMap, schedule, queryPar->dtStart(), queryPar->dtEnd(), false); - return DSchedule::toMapString(m_scheduleMap); - + scheduleList.append(schedule); } else { scheduleList = m_accountDB->querySchedulesByKey(queryPar->key()); } @@ -462,32 +453,7 @@ QString DAccountModule::querySchedulesWithParameter(const QString ¶ms) scheduleList.append(getFestivalSchedule(queryPar->dtStart(), queryPar->dtEnd(), queryPar->key())); } - //获取一定范围内的日程 - QMap scheduleMap = getScheduleTimesOn(queryPar->dtStart(), queryPar->dtEnd(), scheduleList, extend); - - //如果为查询前N个日程,则取前N个日程 - if (queryPar->queryType() == DScheduleQueryPar::Query_Top) { - int scheduleNum = 0; - DSchedule::Map filterSchedule; - DSchedule::Map::const_iterator iter = scheduleMap.constBegin(); - for (; iter != scheduleMap.constEnd(); ++iter) { - if (iter.value().size() == 0) { - continue; - } - if (scheduleNum + iter.value().size() > queryPar->queryTop()) { - DSchedule::List scheduleList; - int residuesNum = queryPar->queryTop() - scheduleNum; - for (int i = 0; i < residuesNum; ++i) { - scheduleList.append(iter.value().at(i)); - } - filterSchedule[iter.key()] = scheduleList; - } else { - filterSchedule[iter.key()] = iter.value(); - } - } - scheduleMap = filterSchedule; - } - return DSchedule::toMapString(scheduleMap); + return DSchedule::toListString(params, scheduleList); } DSchedule::List DAccountModule::getRemindScheduleList(const QDateTime &dtStart, const QDateTime &dtEnd) diff --git a/calendar-service/src/dbmanager/dhuanglidatabase.h b/calendar-service/src/dbmanager/dhuanglidatabase.h index 6ff466da..a74b2845 100644 --- a/calendar-service/src/dbmanager/dhuanglidatabase.h +++ b/calendar-service/src/dbmanager/dhuanglidatabase.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2019 - 2024 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -7,7 +7,7 @@ #include "ddatabase.h" #include "huangliData/lunardatastruct.h" -#include "lunarandfestival.h" +#include "lunarandfestival/lunarandfestival.h" #include #include #include