22 #include <tqstringlist.h>
23 #include <tdelocale.h>
27 #include "alarmtext.h"
30 TQString AlarmText::mFromPrefix;
31 TQString AlarmText::mToPrefix;
32 TQString AlarmText::mCcPrefix;
33 TQString AlarmText::mDatePrefix;
34 TQString AlarmText::mSubjectPrefix;
35 TQString AlarmText::mFromPrefixEn = TQString::fromLatin1(
"From:");
36 TQString AlarmText::mToPrefixEn = TQString::fromLatin1(
"To:");
37 TQString AlarmText::mCcPrefixEn = TQString::fromLatin1(
"Cc:");
38 TQString AlarmText::mDatePrefixEn = TQString::fromLatin1(
"Date:");
39 TQString AlarmText::mSubjectPrefixEn = TQString::fromLatin1(
"Subject:");
42 void AlarmText::setText(
const TQString& text)
45 mIsScript = text.startsWith(TQString::fromLatin1(
"#!"));
47 mTo = mFrom = mCc = mTime = mSubject = TQString();
51 void AlarmText::setEmail(
const TQString& to,
const TQString& from,
const TQString& cc,
const TQString& time,
52 const TQString& subject,
const TQString& body,
unsigned long kmailSerialNumber)
62 mKMailSerialNum = kmailSerialNumber;
68 TQString AlarmText::displayText()
const
75 text = mFromPrefix +
'\t' + mFrom +
'\n';
76 text += mToPrefix +
'\t' + mTo +
'\n';
78 text += mCcPrefix +
'\t' + mCc +
'\n';
80 text += mDatePrefix +
'\t' + mTime +
'\n';
81 text += mSubjectPrefix +
'\t' + mSubject;
95 bool AlarmText::isEmpty()
const
101 return mFrom.isEmpty() && mTo.isEmpty() && mCc.isEmpty() && mTime.isEmpty() && mSubject.isEmpty();
107 bool AlarmText::checkIfEmail(
const TQString& text)
109 TQStringList lines = TQStringList::split(
'\n', text);
110 return emailHeaderCount(lines);
117 int AlarmText::emailHeaderCount(
const TQStringList& lines)
120 int maxn = lines.count();
122 && lines[0].startsWith(mFromPrefix)
123 && lines[1].startsWith(mToPrefix))
126 if (lines[2].startsWith(mCcPrefix))
129 && lines[n].startsWith(mDatePrefix)
130 && lines[n+1].startsWith(mSubjectPrefix))
141 TQString AlarmText::emailHeaders(
const TQString& text,
bool subjectOnly)
143 TQStringList lines = TQStringList::split(
'\n', text);
144 int n = emailHeaderCount(lines);
148 return lines[n-1].mid(mSubjectPrefix.length()).stripWhiteSpace();
149 TQString h = lines[0];
150 for (
int i = 1; i < n; ++i)
164 TQString AlarmText::fromCalendarText(
const TQString& text,
bool& email)
166 TQStringList lines = TQStringList::split(
'\n', text);
167 int maxn = lines.count();
169 && lines[0].startsWith(mFromPrefixEn)
170 && lines[1].startsWith(mToPrefixEn))
173 if (lines[2].startsWith(mCcPrefixEn))
176 && lines[n].startsWith(mDatePrefixEn)
177 && lines[n+1].startsWith(mSubjectPrefixEn))
181 dispText = mFromPrefix + lines[0].mid(mFromPrefixEn.length()) +
'\n';
182 dispText += mToPrefix + lines[1].mid(mToPrefixEn.length()) +
'\n';
184 dispText += mCcPrefix + lines[2].mid(mCcPrefixEn.length()) +
'\n';
185 dispText += mDatePrefix + lines[n].mid(mDatePrefixEn.length()) +
'\n';
186 dispText += mSubjectPrefix + lines[n+1].mid(mSubjectPrefixEn.length());
187 int i = text.find(mSubjectPrefixEn);
188 i = text.find(
'\n', i);
190 dispText += text.mid(i);
203 TQString AlarmText::toCalendarText(
const TQString& text)
206 TQStringList lines = TQStringList::split(
'\n', text);
207 int maxn = lines.count();
209 && lines[0].startsWith(mFromPrefix)
210 && lines[1].startsWith(mToPrefix))
213 if (lines[2].startsWith(mCcPrefix))
216 && lines[n].startsWith(mDatePrefix)
217 && lines[n+1].startsWith(mSubjectPrefix))
221 calText = mFromPrefixEn + lines[0].mid(mFromPrefix.length()) +
'\n';
222 calText += mToPrefixEn + lines[1].mid(mToPrefix.length()) +
'\n';
224 calText += mCcPrefixEn + lines[2].mid(mCcPrefix.length()) +
'\n';
225 calText += mDatePrefixEn + lines[n].mid(mDatePrefix.length()) +
'\n';
226 calText += mSubjectPrefixEn + lines[n+1].mid(mSubjectPrefix.length());
227 int i = text.find(mSubjectPrefix);
228 i = text.find(
'\n', i);
230 calText += text.mid(i);
240 void AlarmText::setUpTranslations()
242 if (mFromPrefix.isNull())
244 mFromPrefix = EditAlarmDlg::i18n_EmailFrom();
245 mToPrefix = EditAlarmDlg::i18n_EmailTo();
246 mCcPrefix = i18n(
"Copy-to in email headers",
"Cc:");
247 mDatePrefix = i18n(
"Date:");
248 mSubjectPrefix = EditAlarmDlg::i18n_EmailSubject();
258 TQString AlarmText::summary(
const KAEvent& event,
int maxLines,
bool* truncated)
260 TQString text = (
event.action() == KAEvent::EMAIL) ? event.emailSubject() :
event.cleanText();
261 if (event.action() == KAEvent::MESSAGE)
264 TQString subject = emailHeaders(text, (maxLines <= 1));
265 if (!subject.isNull())
274 if (text.contains(
'\n') < maxLines)
277 for (
int i = 0; i < maxLines; ++i)
279 newline = text.find(
'\n', newline + 1);
283 if (newline ==
static_cast<int>(text.length()) - 1)
284 return text.left(newline);
287 return text.left(newline + (maxLines <= 1 ? 0 : 1)) + TQString::fromLatin1(
"...");
represents calendar alarms and events
KAEvent corresponds to a KCal::Event instance.