[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    [Kde-pim] libkcal amendments for email alarms
From:       David Jarvie <lists () astrojar ! org ! uk>
Date:       2002-11-28 2:55:28
[Download RAW message or body]

Email addresses need to be handled differently in alarms in libkcal. 
Currently, an email address is simply held as a string. But in iCalendar, it 
is best stored as a name plus an email address (assuming that a name is 
available). So, I propose to store email recipients in the Alarm class as 
Person instances instead of QStrings.

Additionally, KAlarm needs to be able to store some stuff specific to it in 
alarms, so I propose to add an X-KDE-KALARM-TYPE property to the VALARM 
component in iCalendar.

The attached patch is to implement these things. I will go ahead if nobody has 
any objections.

-- 
David Jarvie
["df" (text/x-diff)]

--- kdepim/libkcal/alarm.h	Wed Aug 21 21:55:09 2002
+++ new/alarm.h	Wed Nov 13 23:13:28 2002
@@ -22,8 +22,10 @@
 #define KCAL_ALARM_H
 
 #include <qstring.h>
+#include <qvaluelist.h>
 
 #include "duration.h"
+#include "person.h"
 
 namespace KCal {
 
@@ -34,6 +36,7 @@
 */
 class Alarm {
   public:
+    enum Type { Display, Procedure, Email, Audio };
     typedef QValueList<Alarm *> List;
 
     /** Constructs a new alarm with variables initialized to "sane" values. */
@@ -41,6 +44,9 @@
     /** Destruct Alarm object. */
     ~Alarm();
 
+    /** return the type of the alarm */
+    Type type() const;
+
     /** set the event to have this file as the noise for the alarm. */
     void setAudioFile(const QString &audioAlarmFile);
     /** return the name of the audio file for the alarm */
@@ -52,13 +58,13 @@
     QString programFile() const;
 
     /** send mail to this address when an alarm goes off */
-    void setMailAddress(const QString &mailAlarmAddress);
+    void setMailAddress(const Person &mailAlarmAddress);
     /** send mail to these addresses when an alarm goes off */
-    void setMailAddresses(const QStringList &mailAlarmAddresses);
+    void setMailAddresses(const QValueList<Person> &mailAlarmAddresses);
     /** add this address to the list of addresses to send mail to when an alarm goes off */
-    void addMailAddress(const QString &mailAlarmAddress);
+    void addMailAddress(const Person &mailAlarmAddress);
     /** return the addresses to send mail to when an alarm goes off */
-    QStringList mailAddresses() const;
+    QValueList<Person> mailAddresses() const;
 
     /** set the subject line of the mail */
     void setMailSubject(const QString &mailAlarmSubject);
@@ -115,11 +121,16 @@
     /** get the alarm's parent incidence */
     Incidence *parent() const  { return mParent; }
 
+    /** Set KAlarm's alarm type */
+    void setKAlarmType(const QString &);
+    /** Get KAlarm's alarm type */
+    QString kAlarmType() const;
+
   private:
     QString mAudioAlarmFile;     // url/filename of sound to play
     QString mProgramAlarmFile;   // filename of program to run
-    QStringList mMailAttachFiles;      // filenames to attach to email
-    QStringList mMailAlarmAddresses;   // who to mail for reminder
+    QStringList mMailAttachFiles;           // filenames to attach to email
+    QValueList<Person> mMailAlarmAddresses; // who to mail for reminder
     QString mMailAlarmSubject;   // subject of email
     QString mAlarmText;          // text to display/mail for alarm
 
@@ -134,6 +145,8 @@
     Duration mOffset;
 
     Incidence *mParent;
+
+    QString mKAlarmType;         // KAlarm's alarm type, or null if not KAlarm
 };
 
 }
--- kdepim/libkcal/alarm.cpp	Wed Aug 21 21:58:24 2002
+++ new/alarm.cpp	Wed Nov 13 23:14:15 2002
@@ -43,6 +43,17 @@
 {
 }
 
+Alarm::Type Alarm::type() const
+{
+  if (!mProgramAlarmFile.isEmpty())
+    return Procedure;
+  if (!mAudioAlarmFile.isEmpty())
+    return Audio;
+  if (mMailAlarmAddresses.count() > 0)
+    return Email;
+  return Display;
+}
+
 void Alarm::setAudioFile(const QString &audioAlarmFile)
 {
   mAudioAlarmFile = audioAlarmFile;
@@ -65,26 +76,26 @@
   return mProgramAlarmFile;
 }
 
-void Alarm::setMailAddress(const QString &mailAlarmAddress)
+void Alarm::setMailAddress(const Person &mailAlarmAddress)
 {
   mMailAlarmAddresses.clear();
   mMailAlarmAddresses += mailAlarmAddress;
   mParent->updated();
 }
 
-void Alarm::setMailAddresses(const QStringList &mailAlarmAddresses)
+void Alarm::setMailAddresses(const QValueList<Person> &mailAlarmAddresses)
 {
   mMailAlarmAddresses = mailAlarmAddresses;
   mParent->updated();
 }
 
-void Alarm::addMailAddress(const QString &mailAlarmAddress)
+void Alarm::addMailAddress(const Person &mailAlarmAddress)
 {
   mMailAlarmAddresses += mailAlarmAddress;
   mParent->updated();
 }
 
-QStringList Alarm::mailAddresses() const
+QValueList<Person> Alarm::mailAddresses() const
 {
   return mMailAlarmAddresses;
 }
@@ -225,4 +236,14 @@
 void Alarm::setParent( Incidence *parent )
 {
   mParent = parent;
+}
+
+void Alarm::setKAlarmType(const QString &type)
+{
+  mKAlarmType = type;
+}
+
+QString Alarm::kAlarmType() const
+{
+  return mKAlarmType;
 }
--- kdepim/libkcal/icalformatimpl.cpp	Mon Oct 21 17:55:53 2002
+++ new/icalformatimpl.cpp	Thu Nov 28 02:48:06 2002
@@ -653,9 +653,13 @@
     icalattachtype_free(attach);
   } else if (alarm->mailAddresses().count() > 0) {
     action = ICAL_ACTION_EMAIL;
-    QStringList addresses = alarm->mailAddresses();
-    for (QStringList::Iterator ad = addresses.begin();  ad != addresses.end();  ++ad) {
-      icalcomponent_add_property(a,icalproperty_new_attendee((*ad).utf8()));
+    QValueList<Person> addresses = alarm->mailAddresses();
+    for (QValueList<Person>::Iterator ad = addresses.begin();  ad != addresses.
+      icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf
+      if (!(*ad).name().isEmpty()) {
+        icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8()))
+      }
+      icalcomponent_add_property(a,p);
     }
     icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8()));
     icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8()));
@@ -690,6 +694,13 @@
                              icaldurationtype_from_int(alarm->snoozeTime()*60)));
   }
 
+  // KAlarm-specific stuff
+  if (!alarm->kAlarmType().isEmpty()) {
+    icalproperty *p = icalproperty_new_x(alarm->kAlarmType().utf8());
+    icalproperty_set_x_name(p,"X-KDE-KALARM-TYPE");
+    icalcomponent_add_property(a,p);
+  }
+
   return a;
 }
 
@@ -1434,10 +1445,24 @@
         break;
 
       // Only in EMAIL alarm
-      case ICAL_ATTENDEE_PROPERTY:
-        ialarm->addMailAddress(QString::fromUtf8(icalproperty_get_attendee(p)));
+      case ICAL_ATTENDEE_PROPERTY: {
+        QString email = QString::fromUtf8(icalproperty_get_attendee(p));
+        QString name;
+        icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAM
+        if (param) {
+          name = QString::fromUtf8(icalparameter_get_cn(param));
+        }
+        ialarm->addMailAddress(Person(name, email));
         break;
-
+      }
+      case ICAL_X_PROPERTY: {
+        const char *text;
+        if (strcmp(icalproperty_get_name(p),"X-KDE-KALARM-TYPE") == 0) {
+          text = icalproperty_get_value_as_string(p);
+          ialarm->setKAlarmType(QString::fromUtf8(text));
+        }
+        break;
+      }
       default:
         break;
     }

_______________________________________________
kde-pim mailing list
kde-pim@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic