10#include "prefs_base.h"
12#include "calendarview_debug.h"
14#include <Akonadi/AttributeFactory>
15#include <Akonadi/CollectionColorAttribute>
17#include <QFontDatabase>
18#include <QRandomGenerator>
24 for (
int i = 0; i < array.
size(); ++i) {
25 if (i >= EventViews::EventView::IconCount) {
26 qCWarning(CALENDARVIEW_LOG) <<
"Icon array is too big: " << array.
size();
30 set.
insert(
static_cast<EventViews::EventView::ItemIcon
>(i));
39 for (
int i = 0; i < EventViews::EventView::IconCount; ++i) {
40 const bool contains = set.
contains(
static_cast<EventViews::EventView::ItemIcon
>(i));
41 array.
append(contains ? 1 : 0);
52 iconDefaults[EventViews::EventView::CalendarCustomIcon] = 1;
53 iconDefaults[EventViews::EventView::TaskIcon] = 1;
54 iconDefaults[EventViews::EventView::JournalIcon] = 1;
55 iconDefaults[EventViews::EventView::RecurringIcon] = 1;
56 iconDefaults[EventViews::EventView::ReminderIcon] = 1;
57 iconDefaults[EventViews::EventView::ReadOnlyIcon] = 1;
58 iconDefaults[EventViews::EventView::ReplyIcon] = 0;
68 iconDefaults[EventViews::EventView::CalendarCustomIcon] = 1;
69 iconDefaults[EventViews::EventView::TaskIcon] = 1;
70 iconDefaults[EventViews::EventView::JournalIcon] = 1;
71 iconDefaults[EventViews::EventView::RecurringIcon] = 0;
72 iconDefaults[EventViews::EventView::ReminderIcon] = 0;
73 iconDefaults[EventViews::EventView::ReadOnlyIcon] = 1;
74 iconDefaults[EventViews::EventView::ReplyIcon] = 0;
79class BaseConfig :
public PrefsBase
84 void setResourceColor(
const QString &resource,
const QColor &color);
86 void setTimeScaleTimezones(
const QStringList &timeZones);
91 QColor mDefaultResourceColor;
93 QFont mDefaultMonthViewFont;
94 QFont mDefaultAgendaTimeLabelsFont;
102 void usrSetDefaults()
override;
103 void usrRead()
override;
104 bool usrSave()
override;
107BaseConfig::BaseConfig()
110 mDefaultResourceColor =
QColor();
114 mDefaultAgendaTimeLabelsFont.setPointSize(qMax(mDefaultAgendaTimeLabelsFont.pointSize() + 4, 16));
118 mDefaultMonthViewFont.setPointSize(qMax(mDefaultMonthViewFont.pointSize() - 2, 6));
120 agendaTimeLabelsFontItem()->setDefaultValue(mDefaultAgendaTimeLabelsFont);
121 agendaTimeLabelsFontItem()->setDefault();
122 monthViewFontItem()->setDefaultValue(mDefaultMonthViewFont);
123 monthViewFontItem()->setDefault();
126void BaseConfig::setResourceColor(
const QString &resource,
const QColor &color)
128 mResourceColors.
insert(resource, color);
131void BaseConfig::setTimeScaleTimezones(
const QStringList &list)
133 mTimeScaleTimeZones =
list;
138 return mTimeScaleTimeZones;
141void BaseConfig::usrSetDefaults()
143 setAgendaTimeLabelsFont(mDefaultAgendaTimeLabelsFont);
144 setMonthViewFont(mDefaultMonthViewFont);
146 PrefsBase::usrSetDefaults();
149void BaseConfig::usrRead()
151 KConfigGroup rColorsConfig(config(), QStringLiteral(
"Resources Colors"));
152 const QStringList colorKeyList = rColorsConfig.keyList();
154 for (
const QString &key : colorKeyList) {
155 QColor color = rColorsConfig.readEntry(key, mDefaultResourceColor);
157 setResourceColor(key, color);
161 config()->setGroup(
"FreeBusy");
162 if (mRememberRetrievePw) {
168 KConfigGroup timeScaleConfig(config(), QStringLiteral(
"Timescale"));
169 setTimeScaleTimezones(timeScaleConfig.readEntry(
"Timescale Timezones",
QStringList()));
171 KConfigGroup monthViewConfig(config(), QStringLiteral(
"Month View"));
172 KConfigGroup agendaViewConfig(config(), QStringLiteral(
"Agenda View"));
173 const auto agendaIconArray = agendaViewConfig.readEntry<
QByteArray>(
"agendaViewItemIcons", agendaViewIconDefaults());
174 const auto monthIconArray = monthViewConfig.readEntry<
QByteArray>(
"monthViewItemIcons", monthViewIconDefaults());
176 mAgendaViewIcons = iconArrayToSet(agendaIconArray);
177 mMonthViewIcons = iconArrayToSet(monthIconArray);
182bool BaseConfig::usrSave()
184 KConfigGroup rColorsConfig(config(), QStringLiteral(
"Resources Colors"));
185 for (
auto it = mResourceColors.
constBegin(); it != mResourceColors.
constEnd(); ++it) {
186 rColorsConfig.writeEntry(it.key(), it.value());
190 if (mRememberRetrievePw) {
191 config()->writeEntry(
"Retrieve Server Password",
194 config()->deleteEntry(
"Retrieve Server Password");
198 KConfigGroup timeScaleConfig(config(), QStringLiteral(
"Timescale"));
199 timeScaleConfig.writeEntry(
"Timescale Timezones", timeScaleTimezones());
201 KConfigGroup monthViewConfig(config(), QStringLiteral(
"Month View"));
202 KConfigGroup agendaViewConfig(config(), QStringLiteral(
"Agenda View"));
204 const QByteArray agendaIconArray = iconSetToArray(mAgendaViewIcons);
205 const QByteArray monthIconArray = iconSetToArray(mMonthViewIcons);
207 agendaViewConfig.writeEntry<
QByteArray>(
"agendaViewItemIcons", agendaIconArray);
208 monthViewConfig.writeEntry<
QByteArray>(
"monthViewItemIcons", monthIconArray);
213class EventViews::PrefsPrivate
216 explicit PrefsPrivate(Prefs *parent)
217 : mAppConfig(nullptr)
223 : mAppConfig(appConfig)
252 BaseConfig mBaseConfig;
261 Q_ASSERT(baseConfigItem);
276 item->setValue(value);
278 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type Bool";
291 return item->value();
293 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type Bool";
295 return baseConfigItem->
value();
304 item->setValue(value);
306 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type Int";
319 return item->value();
321 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type Int";
323 return baseConfigItem->
value();
333 item->setValue(value);
335 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type String";
349 return item->value();
351 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type String";
353 return baseConfigItem->
value();
363 item->setValue(value);
365 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type DateTime";
379 return item->value();
381 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type DateTime";
383 return baseConfigItem->
value();
393 item->setValue(value);
395 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type StringList";
409 return item->value();
411 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type StringList";
413 return baseConfigItem->
value();
422 item->setValue(value);
424 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type Color";
437 return item->value();
439 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type Color";
441 return baseConfigItem->
value();
450 item->setValue(value);
452 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type Font";
465 return item->value();
467 qCCritical(CALENDARVIEW_LOG) <<
"Application config item" << appItem->
name() <<
"is not of type Font";
469 return baseConfigItem->
value();
473 : d(new PrefsPrivate(this))
480 : d(new PrefsPrivate(this, appConfig))
486Prefs::~Prefs() =
default;
488void Prefs::readConfig()
490 d->mBaseConfig.load();
492 d->mAppConfig->load();
496void Prefs::writeConfig()
498 d->mBaseConfig.save();
500 d->mAppConfig->save();
504void Prefs::setUseSystemColor(
bool useSystemColor)
506 d->setBool(d->mBaseConfig.useSystemColorItem(), useSystemColor);
509bool Prefs::useSystemColor()
const
511 return d->getBool(d->mBaseConfig.useSystemColorItem());
514void Prefs::setMarcusBainsShowSeconds(
bool showSeconds)
516 d->setBool(d->mBaseConfig.marcusBainsShowSecondsItem(), showSeconds);
519bool Prefs::marcusBainsShowSeconds()
const
521 return d->getBool(d->mBaseConfig.marcusBainsShowSecondsItem());
524void Prefs::setAgendaMarcusBainsLineLineColor(
const QColor &color)
526 d->setColor(d->mBaseConfig.agendaMarcusBainsLineLineColorItem(), color);
529QColor Prefs::agendaMarcusBainsLineLineColor()
const
531 return d->getColor(d->mBaseConfig.agendaMarcusBainsLineLineColorItem());
534void Prefs::setMarcusBainsEnabled(
bool enabled)
536 d->setBool(d->mBaseConfig.marcusBainsEnabledItem(), enabled);
539bool Prefs::marcusBainsEnabled()
const
541 return d->getBool(d->mBaseConfig.marcusBainsEnabledItem());
544void Prefs::setAgendaMarcusBainsLineFont(
const QFont &font)
546 d->setFont(d->mBaseConfig.agendaMarcusBainsLineFontItem(), font);
549QFont Prefs::agendaMarcusBainsLineFont()
const
551 return d->getFont(d->mBaseConfig.agendaMarcusBainsLineFontItem());
554void Prefs::setHourSize(
int size)
556 d->setInt(d->mBaseConfig.hourSizeItem(), size);
559int Prefs::hourSize()
const
561 return d->getInt(d->mBaseConfig.hourSizeItem());
564void Prefs::setDayBegins(
const QDateTime &dateTime)
566 d->setDateTime(d->mBaseConfig.dayBeginsItem(), dateTime);
571 return d->getDateTime(d->mBaseConfig.dayBeginsItem());
574void Prefs::setFirstDayOfWeek(
const int day)
576 d->setInt(d->mBaseConfig.weekStartDayItem(), day - 1);
579int Prefs::firstDayOfWeek()
const
581 return d->getInt(d->mBaseConfig.weekStartDayItem()) + 1;
584void Prefs::setWorkingHoursStart(
const QDateTime &dateTime)
586 d->setDateTime(d->mBaseConfig.workingHoursStartItem(), dateTime);
589QDateTime Prefs::workingHoursStart()
const
591 return d->getDateTime(d->mBaseConfig.workingHoursStartItem());
594void Prefs::setWorkingHoursEnd(
const QDateTime &dateTime)
596 d->setDateTime(d->mBaseConfig.workingHoursEndItem(), dateTime);
601 return d->getDateTime(d->mBaseConfig.workingHoursEndItem());
604void Prefs::setSelectionStartsEditor(
bool startEditor)
606 d->setBool(d->mBaseConfig.selectionStartsEditorItem(), startEditor);
609bool Prefs::selectionStartsEditor()
const
611 return d->getBool(d->mBaseConfig.selectionStartsEditorItem());
614void Prefs::setAgendaGridWorkHoursBackgroundColor(
const QColor &color)
616 d->setColor(d->mBaseConfig.agendaGridWorkHoursBackgroundColorItem(), color);
619QColor Prefs::agendaGridWorkHoursBackgroundColor()
const
621 return d->getColor(d->mBaseConfig.agendaGridWorkHoursBackgroundColorItem());
624void Prefs::setAgendaGridHighlightColor(
const QColor &color)
626 d->setColor(d->mBaseConfig.agendaGridHighlightColorItem(), color);
629QColor Prefs::agendaGridHighlightColor()
const
631 return d->getColor(d->mBaseConfig.agendaGridHighlightColorItem());
634void Prefs::setAgendaGridBackgroundColor(
const QColor &color)
636 d->setColor(d->mBaseConfig.agendaGridBackgroundColorItem(), color);
639QColor Prefs::agendaGridBackgroundColor()
const
641 return d->getColor(d->mBaseConfig.agendaGridBackgroundColorItem());
644void Prefs::setEnableAgendaItemIcons(
bool enable)
646 d->setBool(d->mBaseConfig.enableAgendaItemIconsItem(), enable);
649bool Prefs::enableAgendaItemIcons()
const
651 return d->getBool(d->mBaseConfig.enableAgendaItemIconsItem());
654void Prefs::setTodosUseCategoryColors(
bool useColors)
656 d->setBool(d->mBaseConfig.todosUseCategoryColorsItem(), useColors);
659bool Prefs::todosUseCategoryColors()
const
661 return d->getBool(d->mBaseConfig.todosUseCategoryColorsItem());
664void Prefs::setAgendaHolidaysBackgroundColor(
const QColor &color)
const
666 d->setColor(d->mBaseConfig.agendaHolidaysBackgroundColorItem(), color);
669QColor Prefs::agendaHolidaysBackgroundColor()
const
671 return d->getColor(d->mBaseConfig.agendaHolidaysBackgroundColorItem());
674void Prefs::setAgendaViewColors(
int colors)
676 d->setInt(d->mBaseConfig.agendaViewColorsItem(), colors);
679int Prefs::agendaViewColors()
const
681 return d->getInt(d->mBaseConfig.agendaViewColorsItem());
684void Prefs::setAgendaViewFont(
const QFont &font)
686 d->setFont(d->mBaseConfig.agendaViewFontItem(), font);
689QFont Prefs::agendaViewFont()
const
691 return d->getFont(d->mBaseConfig.agendaViewFontItem());
694void Prefs::setMonthViewFont(
const QFont &font)
696 d->setFont(d->mBaseConfig.monthViewFontItem(), font);
699QFont Prefs::monthViewFont()
const
701 return d->getFont(d->mBaseConfig.monthViewFontItem());
704QColor Prefs::monthGridBackgroundColor()
const
706 return d->getColor(d->mBaseConfig.monthGridBackgroundColorItem());
709void Prefs::setMonthGridBackgroundColor(
const QColor &color)
711 d->setColor(d->mBaseConfig.monthGridBackgroundColorItem(), color);
714QColor Prefs::monthGridWorkHoursBackgroundColor()
const
716 return d->getColor(d->mBaseConfig.monthGridWorkHoursBackgroundColorItem());
719void Prefs::monthGridWorkHoursBackgroundColor(
const QColor &color)
721 d->setColor(d->mBaseConfig.monthGridWorkHoursBackgroundColorItem(), color);
724int Prefs::monthViewColors()
const
726 return d->getInt(d->mBaseConfig.monthViewColorsItem());
729void Prefs::setMonthViewColors(
int colors)
const
731 d->setInt(d->mBaseConfig.monthViewColorsItem(), colors);
734void Prefs::setEnableMonthItemIcons(
bool enable)
736 d->setBool(d->mBaseConfig.enableMonthItemIconsItem(), enable);
739bool Prefs::enableMonthItemIcons()
const
741 return d->getBool(d->mBaseConfig.enableMonthItemIconsItem());
744bool Prefs::showTimeInMonthView()
const
746 return d->getBool(d->mBaseConfig.showTimeInMonthViewItem());
749void Prefs::setShowTimeInMonthView(
bool show)
751 d->setBool(d->mBaseConfig.showTimeInMonthViewItem(), show);
754bool Prefs::showTodosMonthView()
const
756 return d->getBool(d->mBaseConfig.showTodosMonthViewItem());
759void Prefs::setShowTodosMonthView(
bool enable)
761 d->setBool(d->mBaseConfig.showTodosMonthViewItem(), enable);
764bool Prefs::showJournalsMonthView()
const
766 return d->getBool(d->mBaseConfig.showJournalsMonthViewItem());
769void Prefs::setShowJournalsMonthView(
bool enable)
771 d->setBool(d->mBaseConfig.showJournalsMonthViewItem(), enable);
774bool Prefs::fullViewMonth()
const
776 return d->getBool(d->mBaseConfig.fullViewMonthItem());
779void Prefs::setFullViewMonth(
bool fullView)
781 d->setBool(d->mBaseConfig.fullViewMonthItem(), fullView);
784bool Prefs::sortCompletedTodosSeparately()
const
786 return d->getBool(d->mBaseConfig.sortCompletedTodosSeparatelyItem());
789void Prefs::setSortCompletedTodosSeparately(
bool enable)
791 d->setBool(d->mBaseConfig.sortCompletedTodosSeparatelyItem(), enable);
794void Prefs::setEnableToolTips(
bool enable)
796 d->setBool(d->mBaseConfig.enableToolTipsItem(), enable);
799bool Prefs::enableToolTips()
const
801 return d->getBool(d->mBaseConfig.enableToolTipsItem());
804void Prefs::setShowTodosAgendaView(
bool show)
806 d->setBool(d->mBaseConfig.showTodosAgendaViewItem(), show);
809bool Prefs::showTodosAgendaView()
const
811 return d->getBool(d->mBaseConfig.showTodosAgendaViewItem());
814void Prefs::setAgendaTimeLabelsFont(
const QFont &font)
816 d->setFont(d->mBaseConfig.agendaTimeLabelsFontItem(), font);
819QFont Prefs::agendaTimeLabelsFont()
const
821 return d->getFont(d->mBaseConfig.agendaTimeLabelsFontItem());
829bool Prefs::colorAgendaBusyDays()
const
831 return d->getBool(d->mBaseConfig.colorBusyDaysEnabledItem());
834bool Prefs::colorMonthBusyDays()
const
836 return d->getBool(d->mBaseConfig.colorMonthBusyDaysEnabledItem());
839QColor Prefs::viewBgBusyColor()
const
841 return d->getColor(d->mBaseConfig.viewBgBusyColorItem());
844void Prefs::setViewBgBusyColor(
const QColor &color)
846 d->mBaseConfig.mViewBgBusyColor = color;
849QColor Prefs::holidayColor()
const
851 return d->getColor(d->mBaseConfig.holidayColorItem());
854void Prefs::setHolidayColor(
const QColor &color)
856 d->mBaseConfig.mHolidayColor = color;
859QColor Prefs::agendaViewBackgroundColor()
const
861 return d->getColor(d->mBaseConfig.agendaBgColorItem());
864void Prefs::setAgendaViewBackgroundColor(
const QColor &color)
866 d->mBaseConfig.mAgendaBgColor = color;
869QColor Prefs::workingHoursColor()
const
871 return d->getColor(d->mBaseConfig.workingHoursColorItem());
874void Prefs::setWorkingHoursColor(
const QColor &color)
876 d->mBaseConfig.mWorkingHoursColor = color;
879QColor Prefs::todoDueTodayColor()
const
881 return d->getColor(d->mBaseConfig.todoDueTodayColorItem());
884void Prefs::setTodoDueTodayColor(
const QColor &color)
886 d->mBaseConfig.mTodoDueTodayColor = color;
889QColor Prefs::todoOverdueColor()
const
891 return d->getColor(d->mBaseConfig.todoOverdueColorItem());
894void Prefs::setTodoOverdueColor(
const QColor &color)
896 d->mBaseConfig.mTodoOverdueColor = color;
899void Prefs::setColorAgendaBusyDays(
bool enable)
901 d->mBaseConfig.mColorBusyDaysEnabled = enable;
904void Prefs::setColorMonthBusyDays(
bool enable)
906 d->mBaseConfig.mColorMonthBusyDaysEnabled = enable;
909void Prefs::setResourceColor(
const QString &cal,
const QColor &color)
911 d->mBaseConfig.setResourceColor(cal, color);
918 color = d->mBaseConfig.mResourceColors.value(cal);
926 return d->mBaseConfig.mDefaultResourceColor;
929 QColor color = resourceColorKnown(cal);
932 if (!color.
isValid() && d->getBool(d->mBaseConfig.assignDefaultResourceColorsItem())) {
933 color.
setRgb(0x37, 0x7A, 0xBC);
934 const int seed = d->getInt(d->mBaseConfig.defaultResourceColorSeedItem());
935 const QStringList colors = d->getStringList(d->mBaseConfig.defaultResourceColorsItem());
936 if (seed > 0 && seed - 1 < colors.
size()) {
941 d->setInt(d->mBaseConfig.defaultResourceColorSeedItem(), (seed + 1));
942 d->mBaseConfig.setResourceColor(cal, color);
947 return d->mBaseConfig.mDefaultResourceColor;
953 return d->mBaseConfig.timeScaleTimezones();
956void Prefs::setTimeScaleTimezones(
const QStringList &list)
958 d->mBaseConfig.setTimeScaleTimezones(list);
966 item = d->mBaseConfig.findItem(name);
974 return d->mBaseConfig.mSelectedPlugins;
977QStringList Prefs::decorationsAtAgendaViewTop()
const
979 return d->mBaseConfig.decorationsAtAgendaViewTop();
982QStringList Prefs::decorationsAtAgendaViewBottom()
const
984 return d->mBaseConfig.decorationsAtAgendaViewBottom();
987void Prefs::setSelectedPlugins(
const QStringList &plugins)
989 d->mBaseConfig.setSelectedPlugins(plugins);
992void Prefs::setDecorationsAtAgendaViewTop(
const QStringList &decorations)
994 d->mBaseConfig.setDecorationsAtAgendaViewTop(decorations);
997void Prefs::setDecorationsAtAgendaViewBottom(
const QStringList &decorations)
999 d->mBaseConfig.setDecorationsAtAgendaViewBottom(decorations);
1004 return d->mBaseConfig.mAgendaViewIcons;
1009 d->mBaseConfig.mAgendaViewIcons = icons;
1014 return d->mBaseConfig.mMonthViewIcons;
1019 d->mBaseConfig.mMonthViewIcons = icons;
1022void Prefs::setFlatListTodo(
bool enable)
1024 d->mBaseConfig.mFlatListTodo = enable;
1027bool Prefs::flatListTodo()
const
1029 return d->mBaseConfig.mFlatListTodo;
1032void Prefs::setFullViewTodo(
bool enable)
1034 d->mBaseConfig.mFullViewTodo = enable;
1037bool Prefs::fullViewTodo()
const
1039 return d->mBaseConfig.mFullViewTodo;
1042bool Prefs::enableTodoQuickSearch()
const
1044 return d->mBaseConfig.mEnableTodoQuickSearch;
1047void Prefs::setEnableTodoQuickSearch(
bool enable)
1049 d->mBaseConfig.mEnableTodoQuickSearch = enable;
1052bool Prefs::enableQuickTodo()
const
1054 return d->mBaseConfig.mEnableQuickTodo;
1057void Prefs::setEnableQuickTodo(
bool enable)
1059 d->mBaseConfig.mEnableQuickTodo = enable;
1062bool Prefs::highlightTodos()
const
1064 return d->mBaseConfig.mHighlightTodos;
1067void Prefs::setHighlightTodos(
bool highlight)
1069 d->mBaseConfig.mHighlightTodos = highlight;
1074 return d->mAppConfig ? d->mAppConfig->config() : d->mBaseConfig.config();
static void registerAttribute()
void setValue(const T &v)
KConfigSkeletonItem * findItem(const QString &name) const
Namespace EventViews provides facilities for displaying incidences, including events,...
KIOCORE_EXPORT QStringList list(const QString &fileClass)
KCOREADDONS_EXPORT QString obscure(const QString &str)
QByteArray & append(QByteArrayView data)
void resize(qsizetype newSize, char c)
qsizetype size() const const
QColor fromString(QAnyStringView name)
bool isValid() const const
QFont systemFont(SystemFont type)
const_iterator constBegin() const const
const_iterator constEnd() const const
iterator insert(const Key &key, const T &value)
qsizetype size() const const
QRandomGenerator * global()
bool contains(const QSet< T > &other) const const
iterator insert(const T &value)
bool isEmpty() const const
QTimeZone systemTimeZone()