Commit 2bdfa2a7 authored by David Jarvie's avatar David Jarvie
Browse files

Code quality fixes

parent 15a20c25
Pipeline #145235 passed with stage
in 3 minutes and 16 seconds
KAlarm Change Log
=== Version 3.4.0 (KDE Applications 22.04) --- 9 February 2022 ===
=== Version 3.4.0 (KDE Applications 22.04) --- 4 March 2022 ===
* Allow calendars and date picker to be shown together in side panel [KDE Bug 440250]
* Shrink calendar list to remove empty space when too large.
* Cancel sound file playback if audio alarm edit dialogue is closed after clicking Try.
* Use threading correctly for playing sound files.
* Incorporate kalarmcal library into KAlarm as a private library.
=== Version 3.3.6 (KDE Applications 21.12.3) --- 9 February 2022 ===
* Fix failure to create a missing calendar file after enabling a resource.
......
......@@ -1482,7 +1482,7 @@ bool editAlarmById(const EventId& id, QWidget* parent)
* Open the Edit Alarm dialog to edit the specified template.
* If the template is read-only, the dialog is opened read-only.
*/
void editTemplate(KAEvent& event, QWidget* parent)
void editTemplate(const KAEvent& event, QWidget* parent)
{
if (eventReadOnly(event.id()))
{
......
......@@ -84,7 +84,7 @@ void updateEditedAlarm(EditAlarmDlg*, KAEvent&, Resource&);
void viewAlarm(const KAEvent&, QWidget* parent = nullptr);
void editNewTemplate(EditAlarmDlg::Type, QWidget* parent = nullptr);
void editNewTemplate(const KAEvent& preset, QWidget* parent = nullptr);
void editTemplate(KAEvent&, QWidget* parent = nullptr);
void editTemplate(const KAEvent&, QWidget* parent = nullptr);
void execNewAlarmDlg(EditAlarmDlg*, const QDate& startDate = QDate());
/** Create a "New From Template" QAction */
KToggleAction* createAlarmEnableAction(QObject* parent);
......
......@@ -1257,8 +1257,8 @@ void KAEventTest::toKCalEvent()
}
{
// Start time using LocalZone
const KADateTime dt(QDate(2010,5,13), QTime(3, 45, 0), KADateTime::LocalZone);
KAEvent event(dt, name, text, bgColour, fgColour, font, KAEvent::MESSAGE, 3, KAEvent::CONFIRM_ACK);
const KADateTime dtl(QDate(2010,5,13), QTime(3, 45, 0), KADateTime::LocalZone);
KAEvent event(dtl, name, text, bgColour, fgColour, font, KAEvent::MESSAGE, 3, KAEvent::CONFIRM_ACK);
event.setEventId(uid);
event.incrementRevision();
event.setCategory(CalEvent::ACTIVE);
......@@ -1271,7 +1271,7 @@ void KAEventTest::toKCalEvent()
QStringList flags = kcalevent->customProperty("KALARM", "FLAGS").split(SC);
QCOMPARE(flags.size(), 4); // must contain LOCAL, LATECANCEL;3 and ACKCONF
QVERIFY(flags.contains(QLatin1String("LOCAL")));
const QDateTime dtCurrentTz(dt.date(), dt.time(), QTimeZone::systemTimeZone());
const QDateTime dtCurrentTz(dtl.date(), dtl.time(), QTimeZone::systemTimeZone());
QCOMPARE(kcalevent->dtStart(), dtCurrentTz);
QCOMPARE(kcalevent->created(), createdDt.qDateTime());
}
......
......@@ -294,10 +294,10 @@ Type status(const Event::Ptr& event, QString* param)
// The event either wasn't written by KAlarm, or was written by a pre-2.0 version.
// Check first for an old KAlarm format, which indicated the event type in the
// middle of its UID.
const QString uid = event->uid();
if (uid.indexOf(staticStrings->OLD_ARCHIVED_UID) > 0)
const QString euid = event->uid();
if (euid.indexOf(staticStrings->OLD_ARCHIVED_UID) > 0)
return ARCHIVED;
if (uid.indexOf(staticStrings->OLD_TEMPLATE_UID) > 0)
if (euid.indexOf(staticStrings->OLD_TEMPLATE_UID) > 0)
return TEMPLATE;
// Otherwise, assume it's an active alarm
......@@ -343,21 +343,21 @@ Type type(const QString& mimeType)
Types types(const QStringList& mimeTypes)
{
Types types = {};
for (const QString& type : mimeTypes)
for (const QString& mtype : mimeTypes)
{
if (type == MIME_ACTIVE)
if (mtype == MIME_ACTIVE)
types |= ACTIVE;
else if (type == MIME_ARCHIVED)
else if (mtype == MIME_ARCHIVED)
types |= ARCHIVED;
else if (type == MIME_TEMPLATE)
else if (mtype == MIME_TEMPLATE)
types |= TEMPLATE;
}
return types;
}
QString mimeType(Type type)
QString mimeType(Type mtype)
{
switch (type)
switch (mtype)
{
case ACTIVE: return MIME_ACTIVE;
case ARCHIVED: return MIME_ARCHIVED;
......
......@@ -1558,16 +1558,13 @@ QString KADateTime::toString(const QString& format) const
enum { TZNone, UTCOffsetShort, UTCOffset, UTCOffsetColon, TZAbbrev, TZName };
const QLocale locale;
QString result;
int num;
int numLength;
int zone;
bool escape = false;
ushort flag = 0;
for (int i = 0, end = format.length(); i < end; ++i)
{
zone = TZNone;
num = NO_NUMBER;
numLength = 0; // no leading zeroes
int zone = TZNone;
int num = NO_NUMBER;
int numLength = 0; // no leading zeroes
ushort ch = format[i].unicode();
if (!escape)
{
......@@ -1748,7 +1745,6 @@ QString KADateTime::toString(const QString& format) const
else if (zone != TZNone)
{
QTimeZone tz;
int offset;
switch (d->specType)
{
case UTC:
......@@ -1772,8 +1768,8 @@ QString KADateTime::toString(const QString& format) const
case OffsetFromUTC:
{
QTimeZone local;
offset = (d->specType == TimeZone || d->specType == LocalZone) ? d->timeZoneOffset(local)
: (d->specType == OffsetFromUTC) ? d->spec().utcOffset() : 0;
int offset = (d->specType == TimeZone || d->specType == LocalZone) ? d->timeZoneOffset(local)
: (d->specType == OffsetFromUTC) ? d->spec().utcOffset() : 0;
if (offset == InvalidOffset)
return result + QLatin1String("+ERROR");
offset /= 60;
......@@ -2078,8 +2074,8 @@ KADateTime KADateTime::fromString(const QString& string, TimeFormat format, bool
{
// Check for any other alphabetic time zone
bool nonalpha = false;
for (int i = 0, end = zone.size(); i < end && !nonalpha; ++i)
nonalpha = !isalpha(zone[i]);
for (int j = 0, end = zone.size(); j < end && !nonalpha; ++j)
nonalpha = !isalpha(zone[j]);
if (nonalpha)
break;
// TODO: Attempt to recognize the time zone abbreviation?
......@@ -2268,12 +2264,10 @@ KADateTime KADateTime::fromString(const QString& string, TimeFormat format, bool
break;
}
}
int month;
int day;
if (parts[3].length() == 3)
{
// A day of the year is specified
day = parts[3].toInt(&ok);
int day = parts[3].toInt(&ok);
if (!ok || day < 1 || day > 366)
break;
d = QDate(year, 1, 1).addDays(day - 1);
......@@ -2285,8 +2279,8 @@ KADateTime KADateTime::fromString(const QString& string, TimeFormat format, bool
else
{
// A month and day are specified
month = QStringView(parts[3]).left(2).toInt(&ok);
day = QStringView(parts[3]).right(2).toInt(&ok1);
int month = QStringView(parts[3]).left(2).toInt(&ok);
int day = QStringView(parts[3]).right(2).toInt(&ok1);
if (!ok || !ok1)
break;
d = QDate(year, month, day);
......@@ -2701,14 +2695,13 @@ QDateTime fromStr(const QString& string, const QString& format, int& utcOffset,
zoneAbbrev.clear();
enum { TZNone, UTCOffset, UTCOffsetColon, TZAbbrev, TZName };
int zone;
int s = 0;
int send = str.length();
bool escape = false;
ushort flag = 0;
for (int f = 0, fend = format.length(); f < fend && s < send; ++f)
{
zone = TZNone;
int zone = TZNone;
ushort ch = format[f].unicode();
if (!escape)
{
......
......@@ -34,7 +34,7 @@ class EmailAddressList : public KCalendarCore::Person::List
{
public:
EmailAddressList() : KCalendarCore::Person::List() {}
EmailAddressList(const KCalendarCore::Person::List& list)
explicit EmailAddressList(const KCalendarCore::Person::List& list)
{
operator=(list);
}
......@@ -502,6 +502,7 @@ KAEventPrivate::KAEventPrivate(const KADateTime& dateTime, const QString& name,
KAEvent::SubAction action, int lateCancel, KAEvent::Flags flags,
bool changesPending)
: mName(name)
, mStartDateTime(dateTime)
, mAlarmCount(1)
, mBgColour(bg)
, mFgColour(fg)
......@@ -509,7 +510,6 @@ KAEventPrivate::KAEventPrivate(const KADateTime& dateTime, const QString& name,
, mLateCancel(lateCancel) // do this before setting flags
, mCategory(CalEvent::ACTIVE)
{
mStartDateTime = dateTime;
if (flags & KAEvent::ANY_TIME)
mStartDateTime.setDateOnly(true);
mNextMainDateTime = mStartDateTime;
......@@ -831,10 +831,10 @@ KAEventPrivate::KAEventPrivate(const KCalendarCore::Event::Ptr& event)
{
mDisplaying = true;
mDisplayingFlags = data.displayingFlags;
const bool dateOnly = (mDisplayingFlags & DEFERRAL) ? !(mDisplayingFlags & TIMED_FLAG)
const bool dateonly = (mDisplayingFlags & DEFERRAL) ? !(mDisplayingFlags & TIMED_FLAG)
: mStartDateTime.isDateOnly();
mDisplayingTime = dateTime;
mDisplayingTime.setDateOnly(dateOnly);
mDisplayingTime.setDateOnly(dateonly);
alTime = mDisplayingTime;
break;
}
......@@ -1169,10 +1169,10 @@ bool KAEventPrivate::updateKCalEvent(const Event::Ptr& ev, KAEvent::UidAction ui
}
if (mDeferDefaultMinutes)
{
QString param = QString::number(mDeferDefaultMinutes);
QString ddparam = QString::number(mDeferDefaultMinutes);
if (mDeferDefaultDateOnly)
param += QLatin1Char('D');
(flags += DEFER_FLAG) += param;
ddparam += QLatin1Char('D');
(flags += DEFER_FLAG) += ddparam;
}
if (mCategory == CalEvent::TEMPLATE && mTemplateAfterTime >= 0)
(flags += TEMPL_AFTER_TIME_FLAG) += QString::number(mTemplateAfterTime);
......@@ -1240,8 +1240,8 @@ bool KAEventPrivate::updateKCalEvent(const Event::Ptr& ev, KAEvent::UidAction ui
{
// Alarm repetition is normally held in the main alarm, but since
// the main alarm has expired, store in a custom property.
const QString param = QStringLiteral("%1:%2").arg(mRepetition.intervalMinutes()).arg(mRepetition.count());
ev->setCustomProperty(KACalendar::APPNAME, REPEAT_PROPERTY, param);
const QString repparam = QStringLiteral("%1:%2").arg(mRepetition.intervalMinutes()).arg(mRepetition.count());
ev->setCustomProperty(KACalendar::APPNAME, REPEAT_PROPERTY, repparam);
}
// Add subsidiary alarms
......@@ -2203,7 +2203,7 @@ void KAEventPrivate::defer(const DateTime& dateTime, bool reminder, bool adjustR
mTriggerChanged = true;
}
}
else if (mReminderMinutes < 0 && reminder)
else if (reminder)
deferReminder = true; // deferring a reminder AFTER the main alarm
if (deferReminder)
{
......@@ -4123,8 +4123,8 @@ void KAEventPrivate::readAlarm(const Alarm::Ptr& alarm, AlarmData& data, bool au
data.action = KAAlarm::MESSAGE;
data.cleanText = AlarmText::fromCalendarText(alarm->text(), data.isEmailText);
}
const QString property = alarm->customProperty(KACalendar::APPNAME, KAEventPrivate::FONT_COLOUR_PROPERTY);
const QStringList list = property.split(QLatin1Char(';'), Qt::KeepEmptyParts);
const QString prop = alarm->customProperty(KACalendar::APPNAME, KAEventPrivate::FONT_COLOUR_PROPERTY);
const QStringList list = prop.split(QLatin1Char(';'), Qt::KeepEmptyParts);
data.bgColour = QColor(255, 255, 255); // white
data.fgColour = QColor(0, 0, 0); // black
const int n = list.count();
......@@ -4165,19 +4165,18 @@ void KAEventPrivate::readAlarm(const Alarm::Ptr& alarm, AlarmData& data, bool au
data.soundVolume = -1;
data.fadeVolume = -1;
data.fadeSeconds = 0;
QString property = alarm->customProperty(KACalendar::APPNAME, KAEventPrivate::VOLUME_PROPERTY);
if (!property.isEmpty())
QString prop = alarm->customProperty(KACalendar::APPNAME, KAEventPrivate::VOLUME_PROPERTY);
if (!prop.isEmpty())
{
bool ok;
float fadeVolume;
int fadeSecs = 0;
const QStringList list = property.split(QLatin1Char(';'), Qt::KeepEmptyParts);
const QStringList list = prop.split(QLatin1Char(';'), Qt::KeepEmptyParts);
data.soundVolume = list[0].toFloat(&ok);
if (!ok || data.soundVolume > 1.0f)
data.soundVolume = -1;
if (data.soundVolume >= 0 && list.count() >= 3)
{
fadeVolume = list[1].toFloat(&ok);
float fadeVolume = list[1].toFloat(&ok);
int fadeSecs = 0;
if (ok)
fadeSecs = static_cast<int>(list[2].toUInt(&ok));
if (ok && fadeVolume >= 0 && fadeVolume <= 1.0f && fadeSecs > 0)
......@@ -4449,12 +4448,11 @@ void KAEventPrivate::calcNextWorkingTime(const DateTime& nextTrigger) const
if (!rrule)
return; // no recurrence rule!
unsigned allDaysMask = 0x7F; // mask bits for all days of week
bool noWorkPos = false; // true if no recurrence day position is working day
const QList<RecurrenceRule::WDayPos> pos = rrule->byDays();
const int nDayPos = pos.count(); // number of day positions
if (nDayPos)
{
noWorkPos = true;
bool noWorkPos = true; // true if no recurrence day position is working day
allDaysMask = 0;
for (const RecurrenceRule::WDayPos& p : pos)
{
......@@ -5450,8 +5448,8 @@ bool KAEvent::convertKCalEvents(const Calendar::Ptr& calendar, int calendarVersi
* offsets to zero, and convert deferral alarm offsets to be relative to
* the next recurrence.
*/
const QStringList flags = event->customProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY).split(KAEventPrivate::SC, Qt::SkipEmptyParts);
const bool dateOnly = flags.contains(KAEventPrivate::DATE_ONLY_FLAG);
const QStringList flagsProp = event->customProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY).split(KAEventPrivate::SC, Qt::SkipEmptyParts);
const bool dateOnly = flagsProp.contains(KAEventPrivate::DATE_ONLY_FLAG);
KADateTime startDateTime(event->dtStart());
if (dateOnly)
startDateTime.setDateOnly(true);
......@@ -5590,15 +5588,15 @@ bool KAEvent::convertKCalEvents(const Calendar::Ptr& calendar, int calendarVersi
* Move EMAILID, SPEAK, ERRCANCEL and ERRNOSHOW alarm properties into new FLAGS property.
*/
bool flagsValid = false;
QStringList flags;
QStringList preFlags;
QString reminder;
bool reminderOnce = false;
const QString prop = event->customProperty(KACalendar::APPNAME, ARCHIVE_PROPERTY);
if (!prop.isEmpty())
{
// Convert the event's ARCHIVE property to parameters in the FLAGS property
flags = event->customProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY).split(KAEventPrivate::SC, Qt::SkipEmptyParts);
flags << KAEventPrivate::ARCHIVE_FLAG;
preFlags = event->customProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY).split(KAEventPrivate::SC, Qt::SkipEmptyParts);
preFlags << KAEventPrivate::ARCHIVE_FLAG;
flagsValid = true;
if (prop != QLatin1String("0"))
{ // "0" was a dummy parameter if no others were present
......@@ -5608,44 +5606,44 @@ bool KAEvent::convertKCalEvents(const Calendar::Ptr& calendar, int calendarVersi
for (const QString& pr : list)
{
if (pr == KAEventPrivate::AT_LOGIN_TYPE)
flags << KAEventPrivate::AT_LOGIN_TYPE;
preFlags << KAEventPrivate::AT_LOGIN_TYPE;
else if (pr == ARCHIVE_REMINDER_ONCE_TYPE)
reminderOnce = true;
else if (!pr.isEmpty() && !pr.startsWith(QChar::fromLatin1('-')))
reminder = pr;
}
}
event->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY, flags.join(KAEventPrivate::SC));
event->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY, preFlags.join(KAEventPrivate::SC));
event->removeCustomProperty(KACalendar::APPNAME, ARCHIVE_PROPERTY);
}
for (Alarm::Ptr alarm : alarms)
{
// Convert EMAILID, SPEAK, ERRCANCEL, ERRNOSHOW properties
QStringList flags;
QStringList alflags;
QString property = alarm->customProperty(KACalendar::APPNAME, EMAIL_ID_PROPERTY);
if (!property.isEmpty())
{
flags << KAEventPrivate::EMAIL_ID_FLAG << property;
alflags << KAEventPrivate::EMAIL_ID_FLAG << property;
alarm->removeCustomProperty(KACalendar::APPNAME, EMAIL_ID_PROPERTY);
}
if (!alarm->customProperty(KACalendar::APPNAME, SPEAK_PROPERTY).isEmpty())
{
flags << KAEventPrivate::SPEAK_FLAG;
alflags << KAEventPrivate::SPEAK_FLAG;
alarm->removeCustomProperty(KACalendar::APPNAME, SPEAK_PROPERTY);
}
if (!alarm->customProperty(KACalendar::APPNAME, CANCEL_ON_ERROR_PROPERTY).isEmpty())
{
flags << KAEventPrivate::CANCEL_ON_ERROR_FLAG;
alflags << KAEventPrivate::CANCEL_ON_ERROR_FLAG;
alarm->removeCustomProperty(KACalendar::APPNAME, CANCEL_ON_ERROR_PROPERTY);
}
if (!alarm->customProperty(KACalendar::APPNAME, DONT_SHOW_ERROR_PROPERTY).isEmpty())
{
flags << KAEventPrivate::DONT_SHOW_ERROR_FLAG;
alflags << KAEventPrivate::DONT_SHOW_ERROR_FLAG;
alarm->removeCustomProperty(KACalendar::APPNAME, DONT_SHOW_ERROR_PROPERTY);
}
if (!flags.isEmpty())
alarm->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY, flags.join(KAEventPrivate::SC));
if (!alflags.isEmpty())
alarm->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY, alflags.join(KAEventPrivate::SC));
// Invalidate negative reminder periods in alarms
if (!alarm->hasStartOffset())
......@@ -5677,13 +5675,13 @@ bool KAEvent::convertKCalEvents(const Calendar::Ptr& calendar, int calendarVersi
{
// Write reminder parameters into the event's FLAGS property
if (!flagsValid)
flags = event->customProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY).split(KAEventPrivate::SC, Qt::SkipEmptyParts);
if (!flags.contains(KAEventPrivate::REMINDER_TYPE))
preFlags = event->customProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY).split(KAEventPrivate::SC, Qt::SkipEmptyParts);
if (!preFlags.contains(KAEventPrivate::REMINDER_TYPE))
{
flags += KAEventPrivate::REMINDER_TYPE;
preFlags += KAEventPrivate::REMINDER_TYPE;
if (reminderOnce)
flags += KAEventPrivate::REMINDER_ONCE_FLAG;
flags += reminder;
preFlags += KAEventPrivate::REMINDER_ONCE_FLAG;
preFlags += reminder;
}
}
}
......
......@@ -27,7 +27,7 @@ class Recurrence_p : public Recurrence
public:
using Recurrence::setNewRecurrenceType;
Recurrence_p() : Recurrence() {}
Recurrence_p(const Recurrence& r) : Recurrence(r) {}
explicit Recurrence_p(const Recurrence& r) : Recurrence(r) {}
Recurrence_p(const Recurrence_p& r) = default;
Recurrence_p& operator=(const Recurrence_p& r) = delete;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment