Commit f2c2fbc7 authored by David Jarvie's avatar David Jarvie

Move KAAlarm private members, and EmailAddressList, into kaevent.cpp

parent ee7c89d1
This diff is collapsed.
......@@ -60,125 +60,122 @@ class AlarmResource;
class AlarmData;
#ifdef USE_AKONADI
typedef KCalCore::Person EmailAddress;
class KALARM_CAL_EXPORT EmailAddressList : public KCalCore::Person::List
#else
typedef KCal::Person EmailAddress;
class KALARM_CAL_EXPORT EmailAddressList : public QList<KCal::Person>
#endif
{
public:
#ifdef USE_AKONADI
EmailAddressList() : KCalCore::Person::List() { }
EmailAddressList(const KCalCore::Person::List& list) { operator=(list); }
EmailAddressList& operator=(const KCalCore::Person::List&);
#else
EmailAddressList() : QList<KCal::Person>() { }
EmailAddressList(const QList<KCal::Person>& list) { operator=(list); }
EmailAddressList& operator=(const QList<KCal::Person>&);
#endif
operator QStringList() const;
QString join(const QString& separator) const;
QStringList pureAddresses() const;
QString pureAddresses(const QString& separator) const;
private:
QString address(int index) const;
};
// KAAlarm corresponds to a single KCal::Alarm instance.
// A KAEvent may contain multiple KAAlarm's.
/**
* The KAAlarm class represents one of the main or subsidiary alarms in
* a KAEvent instance. It contains the alarm's type and trigger time.
*
* Note that valid KAAlarm instances can only be created by the KAEvent
* class.
*
* @see KAEvent::alarm(), KAEvent::firstAlarm(), KAEvent::nextAlarm().
*/
class KALARM_CAL_EXPORT KAAlarm
{
public:
/** The basic KAAlarm action types. */
enum Action
{
MESSAGE, // KCal::Alarm::Display type: display a text message
FILE, // KCal::Alarm::Display type: display a file (URL given by the alarm text)
COMMAND, // KCal::Alarm::Procedure type: execute a shell command
EMAIL, // KCal::Alarm::Email type: send an email
AUDIO // KCal::Alarm::Audio type: play a sound file
MESSAGE, //!< KCal::Alarm::Display type: display a text message
FILE, //!< KCal::Alarm::Display type: display a file (URL given by the alarm text)
COMMAND, //!< KCal::Alarm::Procedure type: execute a shell command
EMAIL, //!< KCal::Alarm::Email type: send an email
AUDIO //!< KCal::Alarm::Audio type: play a sound file
};
/** The alarm types.
/** Alarm types.
* KAAlarm's of different types may be contained in a KAEvent,
* each defining a different component of the overall alarm.
* each KAAlarm defining a different component of the overall alarm.
*/
enum Type
{
INVALID_ALARM = 0, // not an alarm
MAIN_ALARM = 1, // THE real alarm. Must be the first in the enumeration.
// The following values may be used in combination as a bitmask 0x0E
REMINDER_ALARM = 0x02, // reminder in advance of main alarm
DEFERRED_ALARM = 0x04, // deferred alarm
DEFERRED_REMINDER_ALARM = REMINDER_ALARM | DEFERRED_ALARM, // deferred early warning
INVALID_ALARM = 0, //!< Not an alarm
MAIN_ALARM = 1, //!< THE real alarm. Must be the first in the enumeration.
REMINDER_ALARM = 0x02, //!< Reminder in advance of/after the main alarm
DEFERRED_ALARM = 0x04, //!< Deferred alarm
DEFERRED_REMINDER_ALARM = REMINDER_ALARM | DEFERRED_ALARM, //!< Deferred reminder alarm
// The following values must be greater than the preceding ones, to
// ensure that in ordered processing they are processed afterwards.
AT_LOGIN_ALARM = 0x10, // additional repeat-at-login trigger
DISPLAYING_ALARM = 0x20, // copy of the alarm currently being displayed
AT_LOGIN_ALARM = 0x10, //!< Additional repeat-at-login trigger
DISPLAYING_ALARM = 0x20, //!< Copy of the alarm currently being displayed
// The following values are for internal KAEvent use only
AUDIO_ALARM = 0x30, // sound to play when displaying the alarm
PRE_ACTION_ALARM = 0x40, // command to execute before displaying the alarm
POST_ACTION_ALARM = 0x50 // command to execute after the alarm window is closed
};
enum SubType
{
INVALID__ALARM = INVALID_ALARM,
MAIN__ALARM = MAIN_ALARM,
AT_LOGIN__ALARM = AT_LOGIN_ALARM,
// The following values may be used in combination as a bitmask 0x0E
REMINDER__ALARM = REMINDER_ALARM,
TIMED_DEFERRAL_FLAG = 0x08, // deferral has a time; if clear, it is date-only
DEFERRED_DATE__ALARM = DEFERRED_ALARM, // deferred alarm - date-only
DEFERRED_TIME__ALARM = DEFERRED_ALARM | TIMED_DEFERRAL_FLAG,
DEFERRED_REMINDER_DATE__ALARM = REMINDER_ALARM | DEFERRED_ALARM, // deferred early warning (date-only)
DEFERRED_REMINDER_TIME__ALARM = REMINDER_ALARM | DEFERRED_ALARM | TIMED_DEFERRAL_FLAG, // deferred early warning (date/time)
// The following values must be greater than the preceding ones, to
// ensure that in ordered processing they are processed afterwards.
DISPLAYING__ALARM = DISPLAYING_ALARM,
// The following values are for internal KAEvent use only
AUDIO__ALARM = AUDIO_ALARM, // audio alarm for main display alarm
PRE_ACTION__ALARM = PRE_ACTION_ALARM,
POST_ACTION__ALARM = POST_ACTION_ALARM
};
/** Default constructor, which creates an invalid instance. */
KAAlarm();
KAAlarm() : mType(INVALID__ALARM), mNextRepeat(0), mRepeatAtLogin(false), mDeferred(false) { }
KAAlarm(const KAAlarm&);
~KAAlarm() { }
Action action() const { return mActionType; }
bool isValid() const { return mType != INVALID__ALARM; }
Type type() const { return static_cast<Type>(mType & ~TIMED_DEFERRAL_FLAG); }
SubType subType() const { return mType; }
DateTime dateTime(bool withRepeats = false) const
{ return (withRepeats && mNextRepeat && mRepetition)
? mRepetition.duration(mNextRepeat).end(mNextMainDateTime.kDateTime()) : mNextMainDateTime; }
QDate date() const { return mNextMainDateTime.date(); }
QTime time() const { return mNextMainDateTime.effectiveTime(); }
bool repeatAtLogin() const { return mRepeatAtLogin; }
bool isReminder() const { return mType == REMINDER__ALARM; }
bool deferred() const { return mDeferred; }
void setTime(const DateTime& dt) { mNextMainDateTime = dt; }
void setTime(const KDateTime& dt) { mNextMainDateTime = dt; }
#ifdef KDE_NO_DEBUG_OUTPUT
void dumpDebug() const { }
static const char* debugType(Type) { return ""; }
#else
void dumpDebug() const;
/** Copy constructor. */
KAAlarm(const KAAlarm& other);
/** Destructor. */
~KAAlarm();
/** Assignment operator. */
KAAlarm& operator=(const KAAlarm& other);
/** Return the action type for the alarm. */
Action action() const;
/** Return whether the alarm is valid. */
bool isValid() const;
/** Return the alarm's type (main, reminder, etc.). */
Type type() const;
/** Return the trigger time for the alarm.
* Sub-repetitions can optionally be ignored; in this case, if a sub-repetition
* is due next, the last main recurrence will be returned instead.
* @param withRepeats if true, returns the next sub-repetition time where appropriate;
* if false, ignores sub-repetitions.
*/
DateTime dateTime(bool withRepeats = false) const;
/** Return the trigger date for the alarm.
* Sub-repetitions are ignored: if a sub-repetition is due next, the
* last main recurrence will be returned instead.
*/
QDate date() const;
/** Return the trigger time-of-day for the alarm.
* Sub-repetitions are ignored: if a sub-repetition is due next, the
* last main recurrence will be returned instead.
* @return trigger time-of-day. If the alarm is date-only, this will be
* the user-defined start-of-day time.
*/
QTime time() const;
/** Set the alarm's trigger time. */
void setTime(const DateTime& dt);
/** Set the alarm's trigger time. */
void setTime(const KDateTime& dt);
/** Return whether this is a repeat-at-login alarm. */
bool repeatAtLogin() const;
/** Return whether this is a reminder alarm. */
bool isReminder() const;
/** Return whether this is a deferred alarm. */
bool deferred() const;
/** Return whether in the case of a deferred alarm, it is timed (as
* opposed to date-only).
* @return true if a timed deferral alarm, false if date-only or not a deferred alarm.
*/
bool timedDeferral() const;
/** Return an alarm type as a string.
* @return alarm type string, or the empty string if debug output is disabled.
*/
static const char* debugType(Type);
#endif
private:
Action mActionType; // alarm action type
SubType mType; // alarm type
DateTime mNextMainDateTime; // next time to display the alarm, excluding repetitions
Repetition mRepetition; // sub-repetition count and interval
int mNextRepeat; // repetition count of next due sub-repetition
bool mRepeatAtLogin; // whether to repeat the alarm at every login
bool mRecurs; // there is a recurrence rule for the alarm
bool mDeferred; // whether the alarm is an extra deferred/deferred-reminder alarm
//@cond PRIVATE
class Private;
Private* const d;
//@endcond
friend class KAEvent;
};
......@@ -577,8 +574,13 @@ class KALARM_CAL_EXPORT KAEvent
bool copyToKOrganizer() const;
/** Set the email related data for the event. */
void setEmail(uint from, const EmailAddressList&, const QString& subject,
#ifdef USE_AKONADI
void setEmail(uint from, const KCalCore::Person::List&, const QString& subject,
const QStringList& attachments);
#else
void setEmail(uint from, const QList<KCal::Person>&, const QString& subject,
const QStringList& attachments);
#endif
/** Return the email message body, for an email alarm.
* @return email body, or empty if not an email alarm
......@@ -591,13 +593,27 @@ class KALARM_CAL_EXPORT KAEvent
uint emailFromId() const;
/** Return the list of email addressees, including names, for an email alarm. */
EmailAddressList emailAddresses() const;
#ifdef USE_AKONADI
KCalCore::Person::List emailAddressees() const;
#else
QList<KCal::Person> emailAddressees() const;
#endif
/** Return a list of the email addresses, including names, for an email alarm. */
QStringList emailAddresses() const;
/** Return a string containing the email addressees, including names, for an email alarm.
* @param sep separator string to insert between addresses.
*/
QString emailAddresses(const QString& sep) const;
/** Concatenate a list of email addresses into a string. */
#ifdef USE_AKONADI
static QString joinEmailAddresses(const KCalCore::Person::List& addresses, const QString& separator);
#else
static QString joinEmailAddresses(const QList<KCal::Person>& addresses, const QString& separator);
#endif
/** Return the list of email addressees, excluding names, for an email alarm. */
QStringList emailPureAddresses() const;
......
......@@ -63,7 +63,11 @@ class CommandOptions
int reminderMinutes() const { return mReminderMinutes; }
QString audioFile() const { return mAudioFile; }
float audioVolume() const { return mAudioVolume; }
EmailAddressList addressees() const { return mAddressees; }
#ifdef USE_AKONADI
KCalCore::Person::List addressees() const { return mAddressees; }
#else
QList<KCal::Person> addressees() const { return mAddressees; }
#endif
QStringList attachments() const { return mAttachments; }
QString subject() const { return mSubject; }
uint fromID() const { return mFromID; }
......@@ -104,7 +108,11 @@ class CommandOptions
int mReminderMinutes;// NEW: reminder period
QString mAudioFile; // NEW: audio file path
float mAudioVolume; // NEW: audio file volume
EmailAddressList mAddressees; // NEW: email addressees
#ifdef USE_AKONADI
KCalCore::Person::List mAddressees; // NEW: email addressees
#else
QList<KCal::Person> mAddressees; // NEW: email addressees
#endif
QStringList mAttachments; // NEW: email attachment file names
QString mSubject; // NEW: email subject
uint mFromID; // NEW: email sender ID
......
......@@ -354,7 +354,11 @@ bool DBusHandler::scheduleEmail(const QString& fromID, const QString& addresses,
return false;
}
}
EmailAddressList addrs;
#ifdef USE_AKONADI
KCalCore::Person::List addrs;
#else
QList<KCal::Person> addrs;
#endif
QString bad = KAMail::convertAddresses(addresses, addrs);
if (!bad.isEmpty())
{
......
......@@ -1202,13 +1202,18 @@ void EditEmailAlarmDlg::setAction(KAEvent::SubAction action, const AlarmText& al
/******************************************************************************
* Initialise various values in the New Alarm dialogue.
*/
void EditEmailAlarmDlg::setEmailFields(uint fromID, const EmailAddressList& addresses,
#ifdef USE_AKONADI
void EditEmailAlarmDlg::setEmailFields(uint fromID, const KCalCore::Person::List& addresses,
const QString& subject, const QStringList& attachments)
#else
void EditEmailAlarmDlg::setEmailFields(uint fromID, const QList<KCal::Person>& addresses,
const QString& subject, const QStringList& attachments)
#endif
{
if (fromID)
mEmailFromList->setCurrentIdentity(fromID);
if (!addresses.isEmpty())
mEmailToEdit->setText(addresses.join(", "));
mEmailToEdit->setText(KAEvent::joinEmailAddresses(addresses, ", "));
if (!subject.isEmpty())
mEmailSubjectEdit->setText(subject);
if (!attachments.isEmpty())
......@@ -1360,7 +1365,7 @@ bool EditEmailAlarmDlg::type_validate(bool trial)
void EditEmailAlarmDlg::type_trySuccessMessage(ShellProcess*, const QString&)
{
QString msg;
QString to = mEmailAddresses.join("<nl/>");
QString to = KAEvent::joinEmailAddresses(mEmailAddresses, "<nl/>");
to.replace('<', "&lt;");
to.replace('>', "&gt;");
if (mEmailBcc->isChecked())
......
......@@ -203,8 +203,13 @@ class EditEmailAlarmDlg : public EditAlarmDlg
// N.B. setTime() must be called first to set the date-only characteristic,
// followed by setRecurrence().
virtual void setAction(KAEvent::SubAction, const AlarmText& = AlarmText());
void setEmailFields(uint fromID, const EmailAddressList&, const QString& subject,
#ifdef USE_AKONADI
void setEmailFields(uint fromID, const KCalCore::Person::List&, const QString& subject,
const QStringList& attachments);
#else
void setEmailFields(uint fromID, const QList<KCal::Person>&, const QString& subject,
const QStringList& attachments);
#endif
void setBcc(bool);
static QString i18n_chk_CopyEmailToSelf(); // text of 'Copy email to self' checkbox
......@@ -243,7 +248,12 @@ class EditEmailAlarmDlg : public EditAlarmDlg
CheckBox* mEmailBcc;
QString mAttachDefaultDir;
EmailAddressList mEmailAddresses; // list of addresses to send email to
#ifdef USE_AKONADI
KCalCore::Person::List mEmailAddresses; // list of addresses to send email to
#else
QList<KCal::Person> mEmailAddresses; // list of addresses to send email to
#endif
QStringList mEmailAttachments; // list of email attachment file names
// Initial state of all controls
......
......@@ -1114,7 +1114,11 @@ bool KAlarmApp::scheduleEvent(KAEvent::SubAction action, const QString& text, co
int lateCancel, int flags, const QColor& bg, const QColor& fg, const QFont& font,
const QString& audioFile, float audioVolume, int reminderMinutes,
const KARecurrence& recurrence, int repeatInterval, int repeatCount,
uint mailFromID, const EmailAddressList& mailAddresses,
#ifdef USE_AKONADI
uint mailFromID, const KCalCore::Person::List& mailAddresses,
#else
uint mailFromID, const QList<KCal::Person>& mailAddresses,
#endif
const QString& mailSubject, const QStringList& mailAttachments)
{
kDebug() << text;
......
......@@ -84,8 +84,12 @@ class KAlarmApp : public KUniqueApplication
int lateCancel, int flags, const QColor& bg, const QColor& fg,
const QFont&, const QString& audioFile, float audioVolume,
int reminderMinutes, const KARecurrence& recurrence,
int repeatInterval, int repeatCount,
uint mailFromID = 0, const EmailAddressList& mailAddresses = EmailAddressList(),
int repeatInterval, int repeatCount,
#ifdef USE_AKONADI
uint mailFromID = 0, const KCalCore::Person::List& mailAddresses = KCalCore::Person::List(),
#else
uint mailFromID = 0, const QList<KCal::Person>& mailAddresses = QList<KCal::Person>(),
#endif
const QString& mailSubject = QString(),
const QStringList& mailAttachments = QStringList());
bool dbusTriggerEvent(const QString& eventID) { return dbusHandleEvent(eventID, EVENT_TRIGGER); }
......
......@@ -213,7 +213,7 @@ int KAMail::send(JobData& jobdata, QStringList& errmsgs)
mailjob->setMessage(message);
mailjob->transportAttribute().setTransportId(transport->id());
mailjob->addressAttribute().setFrom(jobdata.from);
mailjob->addressAttribute().setTo(static_cast<QStringList>(jobdata.event.emailAddresses()));
mailjob->addressAttribute().setTo(jobdata.event.emailAddresses());
if (!jobdata.bcc.isEmpty())
mailjob->addressAttribute().setBcc(QStringList(KPIMUtils::extractEmailAddress(jobdata.bcc)));
MailTransport::SentBehaviourAttribute::SentBehaviour sentAction =
......@@ -287,7 +287,11 @@ void initHeaders(KMime::Message& message, KAMail::JobData& data)
message.setHeader(from);
KMime::Headers::To* to = new KMime::Headers::To;
EmailAddressList toList = data.event.emailAddresses();
#ifdef USE_AKONADI
KCalCore::Person::List toList = data.event.emailAddressees();
#else
QList<KCal::Person> toList = data.event.emailAddressees();
#endif
for (int i = 0, count = toList.count(); i < count; ++i)
#ifdef USE_AKONADI
to->addAddress(toList[i]->email().toLatin1(), toList[i]->name());
......@@ -430,7 +434,11 @@ void KAMail::notifyQueued(const KAEvent& event)
KMime::Types::Address addr;
QString localhost = QLatin1String("localhost");
QString hostname = QHostInfo::localHostName();
const EmailAddressList& addresses = event.emailAddresses();
#ifdef USE_AKONADI
KCalCore::Person::List addresses = event.emailAddressees();
#else
QList<KCal::Person> addresses = event.emailAddressees();
#endif
for (int i = 0, end = addresses.count(); i < end; ++i)
{
#ifdef USE_AKONADI
......@@ -466,7 +474,11 @@ QString KAMail::controlCentreAddress()
* entered by the user.
* Reply = the invalid item if error, else empty string.
*/
QString KAMail::convertAddresses(const QString& items, EmailAddressList& list)
#ifdef USE_AKONADI
QString KAMail::convertAddresses(const QString& items, KCalCore::Person::List& list)
#else
QString KAMail::convertAddresses(const QString& items, QList<KCal::Person>& list)
#endif
{
list.clear();
QString invalidItem;
......
/*
* kamail.h - email functions
* Program: kalarm
* Copyright © 2002-2010 by David Jarvie <djarvie@kde.org>
* Copyright © 2002-2011 by David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -23,19 +23,28 @@
#include "kaevent.h"
#ifdef USE_AKONADI
#include <kcalcore/person.h>
#endif
#include <QObject>
#include <QString>
#include <QStringList>
#include <QQueue>
#ifdef USE_AKONADI
#include <QList>
#endif
class KUrl;
class KJob;
class EmailAddressList;
namespace MailTransport { class MessageQueueJob; }
namespace KMime {
namespace Types { struct Address; }
class Message;
}
#ifndef USE_AKONADI
namespace KCal { class Person; }
#endif
class KAMail : public QObject
......@@ -61,7 +70,11 @@ class KAMail : public QObject
static int checkAddress(QString& address);
static int checkAttachment(QString& attachment, KUrl* = 0);
static bool checkAttachment(const KUrl&);
static QString convertAddresses(const QString& addresses, EmailAddressList&);
#ifdef USE_AKONADI
static QString convertAddresses(const QString& addresses, KCalCore::Person::List&);
#else
static QString convertAddresses(const QString& addresses, QList<KCal::Person>&);
#endif
static QString convertAttachments(const QString& attachments, QStringList& list);
static QString controlCentreAddress();
#ifdef KMAIL_SUPPORTED
......
Markdown is supported
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