[kmobiletools] KDE/kdepim/kmobiletools

Marco Gulino marco at kmobiletools.org
Tue Jun 26 23:20:56 CEST 2007


SVN commit 680672 by gulino:

More kmime stuff.


 M  +28 -13    kmobiletools/libkmobiletools/sms.cpp  
 M  +4 -4      kmobiletools/libkmobiletools/sms.h  
 M  +3 -0      tests/testlibkmobiletools/testlibkmobiletools.cpp  


--- trunk/KDE/kdepim/kmobiletools/kmobiletools/libkmobiletools/sms.cpp #680671:680672
@@ -36,13 +36,12 @@
 class SMSPrivate {
     public:
         SMSPrivate(SMS* p_parent) :
-        i_folder(0), i_slot(0), i_type(SMS::All)
+        i_folder(0), i_slot(0)
         { parent=p_parent; }
     QStringList sl_numbers;
 //     QString s_text;
     int i_folder;
     int i_slot;
-    SMS::SMSType i_type;
     QList<int> v_id;
     QString s_rawSlot;
     SMS *parent;
@@ -203,7 +202,7 @@
 
 QStringList SMS::getTo() const
 {
-    if (d->i_type==Unsent || d->i_type==Sent)
+    if (type()==Unsent || type()==Sent)
     {
         return d->sl_numbers;
     } else {
@@ -299,7 +298,7 @@
 {
     QString filename=dir+QDir::separator();
     QString text;
-    if((d->i_type & Unsent) || (d->i_type & Sent) )
+    if((type() & Unsent) || (type() & Sent) )
     {
         filename+=i18nc("Outgoing MailDir", "Outgoing");
         text="To: \"";
@@ -360,7 +359,7 @@
     kDebug() << k_funcinfo << endl;
     QString text;
 
-    if((d->i_type & Unsent) || (d->i_type & Sent) )
+    if((type() & Unsent) || (type() & Sent) )
     {
         text="\"OUTGOING\",";
         for(QStringList::Iterator it=d->sl_numbers.begin(); it!=d->sl_numbers.end(); ++it)
@@ -409,15 +408,15 @@
 }
 
 bool SMS::unread() const {
-    return const_cast<SMS*>(this)->hasHeader("Read");
+    return const_cast<SMS*>(this)->hasHeader("X-KMobileTools-Read");
 }
 
 void SMS::setUnread(bool unread) {
     if(unread && ! this->unread() ) {
-        removeHeader("Read");
+        removeHeader("X-KMobileTools-Read");
         return;
     }
-    setHeader( new KMime::Headers::Generic("Read", 0, QString("read").toUtf8() ) );
+    setHeader( new KMime::Headers::Generic("X-KMobileTools-Read", 0, QString("read").toUtf8() ) );
 }
 
 QString SMS::SMSTypeString(SMSType smstype) {
@@ -436,13 +435,13 @@
     return QString();
 }
 
-int SMS::SMSIntType(const QString& type) {
+SMS::SMSType SMS::SMSIntType(const QString& type) {
     if (type==QLatin1String("REC UNREAD")) return SMS::Unread;
     if (type==QLatin1String("REC READ")) return SMS::Read;
     if (type==QLatin1String("STO UNSENT")) return SMS::Unsent;
     if (type==QLatin1String("STO SENT")) return SMS::Sent;
     if (type==QLatin1String("ALL")) return SMS::Sent;
-    return -1;
+    return SMS::All; // Good enough or switch back to -1?
 }
 
 QByteArray SMS::assembleHeaders()
@@ -455,6 +454,10 @@
     if(h) ret+= h->as7BitString()+'\n';
     h=destination();
     if(h) ret+= h->as7BitString()+'\n';
+    h=getHeaderByType("X-KMobileTools-Type");
+    if(h) ret+= h->as7BitString()+'\n';
+    h=getHeaderByType("X-KMobileTools-Read");
+    if(h) ret+= h->as7BitString()+'\n';
     return ret + Content::assembleHeaders();
 }
 
@@ -492,7 +495,7 @@
 
 QString SMS::getFrom() const
 {
-    if (d->i_type==Unsent || d->i_type==Sent)
+    if (type()==Unsent || type()==Sent)
     {
         return QString();
     } else {
@@ -500,7 +503,20 @@
     }
 }
 
+SMS::SMSType SMS::type() const {
+    KMime::Headers::Generic* htype=dynamic_cast<KMime::Headers::Generic*>(const_cast<SMS*>(this)->getHeaderByType("X-KMobileTools-Type") );
+    if(!htype) return All; /// @TODO error handling here
+    kDebug() << htype->as7BitString (false);
+    return SMSIntType( QString ( htype->as7BitString() ) );
+}
+void SMS::setType( SMSType newType ) {
+    KMime::Headers::Generic *htype=dynamic_cast<KMime::Headers::Generic*>(getHeaderByType("X-KMobileTools-Type") );
+    if(!htype) htype=new KMime::Headers::Generic("X-KMobileTools-Type");
+    htype->from7BitString( SMS::SMSTypeString(newType).toUtf8() );
+    setHeader( htype );
+}
 
+
 /// @TODO port-or-delete the following ones
 void SMS::setRawSlot(const QString &rawSlot){ d->s_rawSlot=rawSlot;}
 QString SMS::rawSlot() const { return d->s_rawSlot;}
@@ -509,8 +525,7 @@
 int SMS::folder() const { return d->i_folder; }
 QList<int> *SMS::idList() { return &(d->v_id); }
 void SMS::setSlot( int newSlot ) { d->i_slot=newSlot; /*emit updated();*/ }
-SMS::SMSType SMS::type() const { return d->i_type; }
-void SMS::setType( SMSType newType ) { d->i_type = newType;/* emit updated();*/ }
+
 int SMS::slot() const { return d->i_slot; }
 
 
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/libkmobiletools/sms.h #680671:680672
@@ -76,7 +76,7 @@
     { Unread=0x1, Read=0x2, Unsent=0x4, Sent=0x8, All=0xA };
     static QString SMSTypeString(SMSType smstype);
 
-    static int SMSIntType (const QString& type);
+    static SMSType SMSIntType (const QString& type);
 
     bool isIncoming() const;
     void setText(const QString & text);
@@ -95,12 +95,12 @@
     virtual QString rawSlot() const;
     void setDateTime(const KDateTime & datetime);
 
-    void setFolder( int newFolder );
-    int folder() const;
+    void KDE_DEPRECATED setFolder( int newFolder );
+    int KDE_DEPRECATED  folder() const;
     QList<int> *idList();
 //     void setId( int newId ) { i_id = newId; }; // krazy:exclude=inline
 
-    void setSlot( int newSlot );
+    void KDE_DEPRECATED setSlot( int newSlot );
     SMSType type() const;
     void setType( SMSType newType );
     int slot() const;
--- trunk/KDE/kdepim/kmobiletools/tests/testlibkmobiletools/testlibkmobiletools.cpp #680671:680672
@@ -70,12 +70,15 @@
     out << "setting test to sms: " << sms->getText() << endl;
     out << "Raw content: " << sms->body() << endl;
     sms->setDateTime( KDateTime(QDate(2002,7,2), QTime(21,12,13) ) );
+    sms->setUnread(false);
     out << "Set date time to " << sms->getDateTime().toString() << endl;
     sms->setSender( "+39123456789", "Sender Name");
     out << "Added numbers: Sender=" << sms->sender()->as7BitString() << endl;
     sms->addDestination("+22123456789", "Destination Name #1");
     sms->addDestination("+33345678923", "Destination Name #2 testing some special chars.. #@1\"<>, ");
     sms->sender()->from7BitString("Sender: Sender Name #1 <+33345678923>, \"Sender 2\" <1234543>, \"Sender 3 with ,commas,\" <224123>, \"Sender 4 with \\\"quotes\\\"\" <1234567>");
+    sms->setType( KMobileTools::SMS::Unread );
+
     out << endl;
     sms->assemble();
     out << "****************** SMS Serialization ******************\n"


More information about the kmobiletools mailing list