[kmobiletools] KDE/kdepim/kmobiletools

Marco Gulino marco at kmobiletools.org
Thu Jun 21 00:01:49 CEST 2007


SVN commit 678214 by gulino:

Setting date/time as a header in SMS.
Adding a test application to check libkmobiletools.


 M  +1 -0      CMakeLists.txt  
 M  +21 -15    kmobiletools/libkmobiletools/sms.cpp  
 M  +2 -1      tests/CMakeLists.txt  
 A             tests/testlibkmobiletools (directory)  
 A             tests/testlibkmobiletools/CMakeLists.txt  
 A             tests/testlibkmobiletools/testlibkmobiletools.cpp   [License: GPL (v2+)]
 A             tests/testlibkmobiletools/testlibkmobiletools.h   [License: GPL (v2+)]


--- trunk/KDE/kdepim/kmobiletools/CMakeLists.txt #678213:678214
@@ -17,5 +17,6 @@
 configure_file( config-kmobiletools.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kmobiletools.h )
 
 add_subdirectory( kmobiletools )
+add_subdirectory ( tests )
 #add_subdirectory( kbluetoothpairingwizard )
 #add_subdirectory( kmtsetup )
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/libkmobiletools/sms.cpp #678213:678214
@@ -39,7 +39,6 @@
         { parent=p_parent; }
     QStringList sl_numbers;
 //     QString s_text;
-    KDateTime dt_datetime;
     int i_folder;
     int i_slot;
     SMS::SMSType i_type;
@@ -84,11 +83,6 @@
     setText(text);
 }
 
-void SMS::setDateTime(const KDateTime & datetime)
-{
-    d->dt_datetime=datetime;
-}
-
 SMS::~SMS()
 {
 }
@@ -221,9 +215,9 @@
     subject+="...";
     subject=subject.replace( QRegExp("([^\\s]*=[\\dA-F]{2,2}[^\\s]*)"), "=?utf-8?q?\\1?=");
     text+=QString("Subject: %1\n").arg(subject);
-    text+="Date: " + d->dt_datetime.toString( "%1, d %2 yyyy hh:mm:ss" )
-            .arg( KMobileTools::KMobiletoolsHelper::shortWeekDayNameEng( d->dt_datetime.date().dayOfWeek() ) )
-            .arg( KMobileTools::KMobiletoolsHelper::shortMonthNameEng( d->dt_datetime.date().month() ) )
+    text+="Date: " + getDateTime().toString( "%1, d %2 yyyy hh:mm:ss" )
+            .arg( KMobileTools::KMobiletoolsHelper::shortWeekDayNameEng( getDateTime().date().dayOfWeek() ) )
+            .arg( KMobileTools::KMobiletoolsHelper::shortMonthNameEng( getDateTime().date().month() ) )
             + '\n';
     text+="X-KMobileTools-IntType: " + QString::number(type() ) + '\n';
     text+="X-KMobileTools-TextType: " + SMSTypeString(type() ) + '\n';
@@ -235,7 +229,7 @@
 //     text+="Content-Type: text/plain; charset=utf-8\n";
     text+="\n\n" + KCodecs::quotedPrintableEncode( getText().toUtf8() )+ '\n';
     filename=filename + QDir::separator() + "cur" + QDir::separator() +
-            QString::number(d->dt_datetime.toTime_t()) + '.' + QString(uid()) + '.' + "kmobiletools";
+            QString::number(getDateTime().toTime_t()) + '.' + QString(uid()) + '.' + "kmobiletools";
     kDebug() << "Writing sms to " << filename << endl;
     QFile file(filename);
     if(! file.open( QIODevice::WriteOnly | QIODevice::Truncate ) ) return false;
@@ -278,9 +272,9 @@
         text="\"INCOMING\",\"" + transNumber  + "\",\"" + getFrom() + "\",";
     }
 
-    text+="\"" + d->dt_datetime.toString( "%1, d %2 yyyy hh:mm:ss" )
-            .arg( KMobileTools::KMobiletoolsHelper::shortWeekDayNameEng( d->dt_datetime.date().dayOfWeek() ) )
-            .arg( KMobileTools::KMobiletoolsHelper::shortMonthNameEng( d->dt_datetime.date().month() ) )
+    text+="\"" + getDateTime().toString( "%1, d %2 yyyy hh:mm:ss" )
+            .arg( KMobileTools::KMobiletoolsHelper::shortWeekDayNameEng( getDateTime().date().dayOfWeek() ) )
+            .arg( KMobileTools::KMobiletoolsHelper::shortMonthNameEng( getDateTime().date().month() ) )
             + "\",";
     //text+="\"" + KCodecs::quotedPrintableEncode( getText().utf8() ) + "\"";
     //text+="\"" + getText().utf8() + "\"";
@@ -298,8 +292,20 @@
 
 void SMS::setText(const QString & text) { setBody(text.toUtf8()); }
 QString SMS::getText() const { return QString(body() ); }
-QString SMS::getDate() const { return d->dt_datetime.toString(); }
-KDateTime SMS::getDateTime() const { return d->dt_datetime; }
+QString SMS::getDate() const { return getDateTime().toString(); }
+
+KDateTime SMS::getDateTime() const {
+    if(! const_cast<SMS*>(this)->hasHeader("Date") ) return KDateTime();
+    return (dynamic_cast<KMime::Headers::Date*>(
+        const_cast<SMS*>(this)->getHeaderByType("Date"))
+            )->dateTime();
+}
+void SMS::setDateTime(const KDateTime & datetime) {
+    KMime::Headers::Date *h=new KMime::Headers::Date();
+    h->setDateTime(datetime);
+    setHeader(h);
+}
+
 void SMS::setRawSlot(const QString &rawSlot){ d->s_rawSlot=rawSlot;}
 QString SMS::rawSlot() const { return d->s_rawSlot;}
 void SMS::setNumbers(const QStringList & numbers) { d->sl_numbers=numbers; }
--- trunk/KDE/kdepim/kmobiletools/tests/CMakeLists.txt #678213:678214
@@ -1,5 +1,6 @@
 
-add_subdirectory( kserialdeviceemulator )
+# add_subdirectory( kserialdeviceemulator )
+add_subdirectory ( testlibkmobiletools )
 
 include_directories( ${KDE4_INCLUDE_DIR} ${QT_INCLUDES}  )
 


More information about the kmobiletools mailing list