Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KAlarm
Commits
f5c25088
Commit
f5c25088
authored
Oct 05, 2014
by
David Jarvie
Browse files
Replace magic numbers with symbols
parent
87d2707c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/alarmtext.cpp
View file @
f5c25088
...
...
@@ -31,6 +31,14 @@
#include
<QDateTime>
#include
<KLocale>
namespace
{
const
int
MAIL_FROM_LINE
=
0
;
// line number containing From in email text
const
int
MAIL_TO_LINE
=
1
;
// line number containing To in email text
const
int
MAIL_CC_LINE
=
2
;
// line number containing CC in email text
const
int
MAIL_MIN_LINES
=
4
;
// allow for From, To, no CC, Date, Subject
}
namespace
KAlarmCal
{
...
...
@@ -419,11 +427,11 @@ QString AlarmText::fromCalendarText(const QString &text, bool &email)
Private
::
initialise
();
const
QStringList
lines
=
text
.
split
(
QLatin1Char
(
'\n'
),
QString
::
SkipEmptyParts
);
const
int
maxn
=
lines
.
count
();
if
(
maxn
>=
4
&&
lines
[
0
].
startsWith
(
Private
::
mFromPrefixEn
)
&&
lines
[
1
].
startsWith
(
Private
::
mToPrefixEn
))
{
int
n
=
2
;
if
(
lines
[
2
].
startsWith
(
Private
::
mCcPrefixEn
))
{
if
(
maxn
>=
MAIL_MIN_LINES
&&
lines
[
MAIL_FROM_LINE
].
startsWith
(
Private
::
mFromPrefixEn
)
&&
lines
[
MAIL_TO_LINE
].
startsWith
(
Private
::
mToPrefixEn
))
{
int
n
=
MAIL_CC_LINE
;
if
(
lines
[
MAIL_CC_LINE
].
startsWith
(
Private
::
mCcPrefixEn
))
{
++
n
;
}
if
(
maxn
>
n
+
1
...
...
@@ -431,10 +439,10 @@ QString AlarmText::fromCalendarText(const QString &text, bool &email)
&&
lines
[
n
+
1
].
startsWith
(
Private
::
mSubjectPrefixEn
))
{
Private
::
setUpTranslations
();
QString
dispText
;
dispText
=
Private
::
mFromPrefix
+
lines
[
0
].
mid
(
Private
::
mFromPrefixEn
.
length
())
+
QLatin1Char
(
'\n'
);
dispText
+=
Private
::
mToPrefix
+
lines
[
1
].
mid
(
Private
::
mToPrefixEn
.
length
())
+
QLatin1Char
(
'\n'
);
if
(
n
==
3
)
{
dispText
+=
Private
::
mCcPrefix
+
lines
[
2
].
mid
(
Private
::
mCcPrefixEn
.
length
())
+
QLatin1Char
(
'\n'
);
dispText
=
Private
::
mFromPrefix
+
lines
[
MAIL_FROM_LINE
].
mid
(
Private
::
mFromPrefixEn
.
length
())
+
QLatin1Char
(
'\n'
);
dispText
+=
Private
::
mToPrefix
+
lines
[
MAIL_TO_LINE
].
mid
(
Private
::
mToPrefixEn
.
length
())
+
QLatin1Char
(
'\n'
);
if
(
n
>
MAIL_CC_LINE
)
{
dispText
+=
Private
::
mCcPrefix
+
lines
[
MAIL_CC_LINE
].
mid
(
Private
::
mCcPrefixEn
.
length
())
+
QLatin1Char
(
'\n'
);
}
dispText
+=
Private
::
mDatePrefix
+
lines
[
n
].
mid
(
Private
::
mDatePrefixEn
.
length
())
+
QLatin1Char
(
'\n'
);
dispText
+=
Private
::
mSubjectPrefix
+
lines
[
n
+
1
].
mid
(
Private
::
mSubjectPrefixEn
.
length
());
...
...
@@ -460,11 +468,11 @@ QString AlarmText::toCalendarText(const QString &text)
Private
::
setUpTranslations
();
const
QStringList
lines
=
text
.
split
(
QLatin1Char
(
'\n'
),
QString
::
SkipEmptyParts
);
const
int
maxn
=
lines
.
count
();
if
(
maxn
>=
4
&&
lines
[
0
].
startsWith
(
Private
::
mFromPrefix
)
&&
lines
[
1
].
startsWith
(
Private
::
mToPrefix
))
{
int
n
=
2
;
if
(
lines
[
2
].
startsWith
(
Private
::
mCcPrefix
))
{
if
(
maxn
>=
MAIL_MIN_LINES
&&
lines
[
MAIL_FROM_LINE
].
startsWith
(
Private
::
mFromPrefix
)
&&
lines
[
MAIL_TO_LINE
].
startsWith
(
Private
::
mToPrefix
))
{
int
n
=
MAIL_CC_LINE
;
if
(
lines
[
MAIL_CC_LINE
].
startsWith
(
Private
::
mCcPrefix
))
{
++
n
;
}
if
(
maxn
>
n
+
1
...
...
@@ -472,10 +480,10 @@ QString AlarmText::toCalendarText(const QString &text)
&&
lines
[
n
+
1
].
startsWith
(
Private
::
mSubjectPrefix
))
{
// Format the email into a text alarm
QString
calText
;
calText
=
Private
::
mFromPrefixEn
+
lines
[
0
].
mid
(
Private
::
mFromPrefix
.
length
())
+
QLatin1Char
(
'\n'
);
calText
+=
Private
::
mToPrefixEn
+
lines
[
1
].
mid
(
Private
::
mToPrefix
.
length
())
+
QLatin1Char
(
'\n'
);
if
(
n
==
3
)
{
calText
+=
Private
::
mCcPrefixEn
+
lines
[
2
].
mid
(
Private
::
mCcPrefix
.
length
())
+
QLatin1Char
(
'\n'
);
calText
=
Private
::
mFromPrefixEn
+
lines
[
MAIL_FROM_LINE
].
mid
(
Private
::
mFromPrefix
.
length
())
+
QLatin1Char
(
'\n'
);
calText
+=
Private
::
mToPrefixEn
+
lines
[
MAIL_TO_LINE
].
mid
(
Private
::
mToPrefix
.
length
())
+
QLatin1Char
(
'\n'
);
if
(
n
>
MAIL_CC_LINE
)
{
calText
+=
Private
::
mCcPrefixEn
+
lines
[
MAIL_CC_LINE
].
mid
(
Private
::
mCcPrefix
.
length
())
+
QLatin1Char
(
'\n'
);
}
calText
+=
Private
::
mDatePrefixEn
+
lines
[
n
].
mid
(
Private
::
mDatePrefix
.
length
())
+
QLatin1Char
(
'\n'
);
calText
+=
Private
::
mSubjectPrefixEn
+
lines
[
n
+
1
].
mid
(
Private
::
mSubjectPrefix
.
length
());
...
...
@@ -529,11 +537,11 @@ int AlarmText::Private::emailHeaderCount(const QStringList &lines)
{
setUpTranslations
();
const
int
maxn
=
lines
.
count
();
if
(
maxn
>=
4
&&
lines
[
0
].
startsWith
(
mFromPrefix
)
&&
lines
[
1
].
startsWith
(
mToPrefix
))
{
int
n
=
2
;
if
(
lines
[
2
].
startsWith
(
mCcPrefix
))
{
if
(
maxn
>=
MAIL_MIN_LINES
&&
lines
[
MAIL_FROM_LINE
].
startsWith
(
mFromPrefix
)
&&
lines
[
MAIL_TO_LINE
].
startsWith
(
mToPrefix
))
{
int
n
=
MAIL_CC_LINE
;
if
(
lines
[
MAIL_CC_LINE
].
startsWith
(
mCcPrefix
))
{
++
n
;
}
if
(
maxn
>
n
+
1
...
...
src/kaevent.cpp
View file @
f5c25088
...
...
@@ -3832,15 +3832,28 @@ DateTime KAEventPrivate::readDateTime(const Event::Ptr &event, bool dateOnly, Da
start
.
setDateOnly
(
true
);
}
DateTime
next
=
start
;
const
int
SZ_YEAR
=
4
;
// number of digits in year value
const
int
SZ_MONTH
=
2
;
// number of digits in month value
const
int
SZ_DAY
=
2
;
// number of digits in day value
const
int
SZ_DATE
=
SZ_YEAR
+
SZ_MONTH
+
SZ_DAY
;
// total size of date value
const
int
IX_TIME
=
SZ_DATE
+
1
;
// offset to time value
const
int
SZ_HOUR
=
2
;
// number of digits in hour value
const
int
SZ_MIN
=
2
;
// number of digits in minute value
const
int
SZ_SEC
=
2
;
// number of digits in second value
const
int
SZ_TIME
=
SZ_HOUR
+
SZ_MIN
+
SZ_SEC
;
// total size of time value
const
QString
prop
=
event
->
customProperty
(
KACalendar
::
APPNAME
,
KAEventPrivate
::
NEXT_RECUR_PROPERTY
);
if
(
prop
.
length
()
>=
8
)
{
if
(
prop
.
length
()
>=
SZ_DATE
)
{
// The next due recurrence time is specified
const
QDate
d
(
prop
.
left
(
4
).
toInt
(),
prop
.
mid
(
4
,
2
).
toInt
(),
prop
.
mid
(
6
,
2
).
toInt
());
const
QDate
d
(
prop
.
left
(
SZ_YEAR
).
toInt
(),
prop
.
mid
(
SZ_YEAR
,
SZ_MONTH
).
toInt
(),
prop
.
mid
(
SZ_YEAR
+
SZ_MONTH
,
SZ_DAY
).
toInt
());
if
(
d
.
isValid
())
{
if
(
dateOnly
&&
prop
.
length
()
==
8
)
{
if
(
dateOnly
&&
prop
.
length
()
==
SZ_DATE
)
{
next
.
setDate
(
d
);
}
else
if
(
!
dateOnly
&&
prop
.
length
()
==
15
&&
prop
[
8
]
==
QLatin1Char
(
'T'
))
{
const
QTime
t
(
prop
.
mid
(
9
,
2
).
toInt
(),
prop
.
mid
(
11
,
2
).
toInt
(),
prop
.
mid
(
13
,
2
).
toInt
());
}
else
if
(
!
dateOnly
&&
prop
.
length
()
==
IX_TIME
+
SZ_TIME
&&
prop
[
SZ_DATE
]
==
QLatin1Char
(
'T'
))
{
const
QTime
t
(
prop
.
mid
(
IX_TIME
,
SZ_HOUR
).
toInt
(),
prop
.
mid
(
IX_TIME
+
SZ_HOUR
,
SZ_MIN
).
toInt
(),
prop
.
mid
(
IX_TIME
+
SZ_HOUR
+
SZ_MIN
,
SZ_SEC
).
toInt
());
if
(
t
.
isValid
())
{
next
.
setDate
(
d
);
next
.
setTime
(
t
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment