[kmobiletools] KDE/kdepim/kmobiletools/kmobiletools

Matthias Lechner matthias at lmme.de
Sat Jun 9 21:52:17 CEST 2007


SVN commit 673297 by lechner:

More constness in API


 M  +7 -1      libkmobiletools/enginedata.cpp  
 M  +10 -3     libkmobiletools/enginedata.h  
 M  +1 -1      libkmobiletools/homepage.cpp  
 M  +14 -14    libkmobiletools/smslist.cpp  
 M  +7 -7      libkmobiletools/smslist.h  
 M  +15 -17    mainpart/devicehome.cpp  
 M  +1 -1      mainpart/devicehome.h  


--- trunk/KDE/kdepim/kmobiletools/kmobiletools/libkmobiletools/enginedata.cpp #673296:673297
@@ -97,8 +97,14 @@
 
 KCal::Event::List *EngineData::calendar() { return d->p_calendar; }
 
-SMSList *EngineData::smsList() const { return d->p_smsList; }
+const SMSList* EngineData::constSMSList() const {
+    return d->p_smsList;
+}
 
+SMSList* EngineData::smsList() const {
+    return d->p_smsList;
+}
+
 ContactsList *EngineData::contactsList() const { return d->p_addresseeList; }
 void EngineData::setContactsList(ContactsList* cl) { d->p_addresseeList=cl; }
 
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/libkmobiletools/enginedata.h #673296:673297
@@ -236,15 +236,22 @@
             void setContactsList( ContactsList* contactsList );
 
             /**
-             * The engine internal list of retrieved SMS
+             * Returns the fetched sms list for reading and writing
              *
              * @return a SMSList object containing all fetched SMS.
              *
-             * @TODO make this method return a const reference
              */
             SMSList* smsList() const;
 
             /**
+             * Returns the fetched sms list for reading
+             *
+             * @return a SMSList object containing all fetched SMS.
+             *
+             */
+            const SMSList* constSMSList() const;
+
+            /**
              * Retrieves the phone calendar.
              *
              * @return the phone calendar
@@ -258,7 +265,7 @@
             * This signal is emitted when the phone is disconnected.
             */
             void disconnected();
-    
+
             /**
             * This signal is emitted when the phone is connected.
             */
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/libkmobiletools/homepage.cpp #673296:673297
@@ -233,7 +233,7 @@
     default:
         if( engine->constEngineData()->phoneConnected() )
         {
-            SMSList *l=engine->constEngineData()->smsList();
+            const SMSList *l=engine->constEngineData()->constSMSList();
             htmlData+="<ul><li><b>%8</b></li></ul><p>%1 %2</p><p>%3 %4</p><div align='right'><a href=\"infopage:1\">%7</a></div>";
             htmlData=htmlData
                     .arg( QString("<a href=\"%1:sms\">").arg( devname ) +
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/libkmobiletools/smslist.cpp #673296:673297
@@ -27,6 +27,7 @@
 #include "kmobiletools_cfg.h"
 #include "devicesconfig.h"
 
+#include <QListIterator>
 
 class SMSListPrivate {
 public:
@@ -67,18 +68,17 @@
 /*!
     \fn SMSList::find(int uid)
  */
-int SMSList::find(const QByteArray &uid)
+int SMSList::find(const QByteArray &uid) const
 {
-    int found=0;
-    SMS *tempSMS=0;
-    QList<SMS*>::iterator it;
-    for(it=begin(); it!=end(); ++it)
-    {
-        tempSMS=*it;
-        if(tempSMS->uid() == uid)
+    int found = 0;
+
+    QListIterator<SMS*> it( *this );
+    while( it.hasNext() ) {
+        if( it.next()->uid() == uid )
             return found;
         found++;
     }
+
     return -1;
 }
 
@@ -120,7 +120,7 @@
 //     return ( ((SMS*) item1)->uid()== ((SMS*) item2)->uid() );
 // }
 
-void SMSList::dump()
+void SMSList::dump() const
 {
     SMS *tempSMS;
     int i=0;
@@ -135,7 +135,7 @@
 //     kDebug() << "SMSList::dump(): Unread=" << i_unread << "; Read=" << i_read << "; Sent=" << i_sent << "; Unsent=" << i_unsent << endl;
 }
 
-void SMSList::calcSMSNumber()
+void SMSList::calcSMSNumber() const
 {
     resetCount();
     SMS *tempSMS;
@@ -169,7 +169,7 @@
     }
 }
 
-int SMSList::count(int smsType, int memSlot)
+int SMSList::count(int smsType, int memSlot) const
 {
     int result=0;
     if( (smsType & SMS::Unread) )
@@ -210,7 +210,7 @@
 /*!
     \fn SMSList::saveToMailBox()
  */
-void SMSList::saveToMailBox()
+void SMSList::saveToMailBox() const
 {
     QDir savedir=(KMobileTools::DevicesConfig::prefs(engineName() ))->maildir_path();
     QString dir=savedir.dirName();
@@ -243,7 +243,7 @@
  */
 
 /// @TODO Check if we can remove dialog windows out of this class, emitting insteada signal.
-int SMSList::saveToCSV()
+int SMSList::saveToCSV() const
 {
     QString dir=QDir::homePath();
     QListIterator<SMS*> it(*this);
@@ -297,7 +297,7 @@
     connect(item, SIGNAL(updated()), this, SIGNAL(updated()) );
 }
 
-void SMSList::resetCount() {
+void SMSList::resetCount() const {
     d->i_unread_phone=d->i_unread_sim=d->i_read_phone=d->i_read_sim=d->i_unsent_phone=d->i_unsent_sim=d->i_sent_phone=d->i_sent_sim=0;
 }
 
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/libkmobiletools/smslist.h #673296:673297
@@ -41,12 +41,12 @@
     ~SMSList();
     void append(SMSList *sublist, bool sync=false);
     void append(SMS *sms);
-    int find(const QByteArray &uid);
+    int find(const QByteArray &uid) const;
     void sync (SMSList *compList);
-    void dump();
-    void calcSMSNumber();
-    int count(int smsType, int memSlot);
-    void resetCount();
+    void dump() const;
+    void calcSMSNumber() const;
+    int count(int smsType, int memSlot) const;
+    void resetCount() const;
     void setEngineName(const QString &enginename);
     QString engineName() const ;
 protected:
@@ -62,9 +62,9 @@
 
 public Q_SLOTS:
     void saveToMailBox(const QString &engineName);
-    void saveToMailBox();
+    void saveToMailBox() const;
     int saveToCSV(const QString &engineName);
-    int saveToCSV();
+    int saveToCSV() const;
 };
 
 #endif
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/mainpart/devicehome.cpp #673296:673297
@@ -330,7 +330,7 @@
     connect(engine, SIGNAL(fullPhonebook()), this, SLOT(fullPhonebook()) );
     connect(p_smsPart, SIGNAL(getSMSList() ), engine, SLOT( slotFetchSMS() ) );
     connect(p_smsPart, SIGNAL(remove( SMS* ) ), engine, SLOT(slotDelSMS( SMS* ) ) );
-    connect(engine->constEngineData()->smsList(), SIGNAL(updated()), this, SLOT(updateSMSList() ) );
+    connect(engine->constEngineData()->constSMSList(), SIGNAL(updated()), this, SLOT(updateSMSList() ) );
     connect(engine, SIGNAL(jobFinished(KMobileTools::Job::JobType)), this, SLOT(jobDone(KMobileTools::Job::JobType)));
 #ifdef HAVE_KCAL
     connect(engine, SIGNAL(calendarParsed() ), this, SLOT(slotCalendarFetched() ) );
@@ -475,7 +475,7 @@
 void DeviceHome::jobDone(KMobileTools::Job::JobType jobtype)
 {
     if(jobtype==KMobileTools::Job::fetchAddressBook) emit phonebookUpdated();
-    int newsmscnt=engine->constEngineData()->smsList()->count(SMS::Unread, SMS::SIM | SMS::Phone );
+    int newsmscnt=engine->constEngineData()->constSMSList()->count(SMS::Unread, SMS::SIM | SMS::Phone );
 
     if(newsmscnt && engine->ThreadWeaver()->isEmpty() && engine->ThreadWeaver()->isIdle() && newsmscnt!=smsnotifynum) {
         smsnotifynum=newsmscnt;
@@ -782,7 +782,7 @@
     updateSMSCount();
     home->printInfoPage( home->currentInfoPage(), engine );
     kDebug( ) << "DeviceHome::smsAdded(" << smsUID << ")\n";
-    SMSList *smsList = engine->constEngineData()->smsList();
+    const SMSList *smsList = engine->constEngineData()->constSMSList();
     int newSMSIndex=smsList->find( smsUID );
     if(newSMSIndex<0) return;
     SMS *newSMS=smsList->at(newSMSIndex);
@@ -811,7 +811,7 @@
 //     return;
     updateSMSCount();
     home->printInfoPage( home->currentInfoPage(), engine );
-    SMSList *smsList = engine->constEngineData()->smsList();
+    const SMSList *smsList = engine->constEngineData()->constSMSList();
     int oldSMSIndex=smsList->find( smsUID );
     if(oldSMSIndex<0) return;
     SMS *oldSMS=smsList->at(oldSMSIndex);
@@ -845,16 +845,14 @@
 
 void DeviceHome::updateSMSList()
 {
-    SMSList *smsList = engine->constEngineData()->smsList();
     ui.SMSListView->clear();
-    SMS *newSMS;
-//     K3ListViewItem *newSMSItem;
-//     smsList->dump();
-    for ( QList<SMS*>::Iterator it=smsList->begin(); it!=smsList->end(); ++it )
+
+    QListIterator<SMS*> it( *(engine->constEngineData()->constSMSList()) );
+
+    while( it.hasNext() )
     {
-        newSMS=(*it);
-        if( !(newSMS->slot() & memslotSelected) || ! (newSMS->type() & smsTypeSelected)  ) continue;
-        new SMSListViewItem( ui.SMSListView, newSMS, engine->constEngineData()->contactsList() );
+        if( !(it.next()->slot() & memslotSelected) || ! (it.next()->type() & smsTypeSelected)  ) continue;
+        new SMSListViewItem( ui.SMSListView, it.next(), engine->constEngineData()->contactsList() );
     }
     updateSMSCount();
 
@@ -919,13 +917,13 @@
 void DeviceHome::updateSMSCount()
 {
     if(!engine) return;
-    engine->constEngineData()->smsList()->calcSMSNumber();
+    engine->constEngineData()->constSMSList()->calcSMSNumber();
     Q3ListViewItemIterator it( ui.SMSFolderView );
     SMSFolderListViewItem *tempItem;
     while ( it.current() ) {
         tempItem=(SMSFolderListViewItem*) it.current();
-        tempItem->setText(1, QString::number(engine->constEngineData()->smsList()->count( ( tempItem->smsType() & (SMS::Unread | SMS::Unsent) ), tempItem->memSlot() ) ) );
-        tempItem->setText(2,QString::number(engine->constEngineData()->smsList()->count( tempItem->smsType(), tempItem->memSlot() ) ) );
+        tempItem->setText(1, QString::number(engine->constEngineData()->constSMSList()->count( ( tempItem->smsType() & (SMS::Unread | SMS::Unsent) ), tempItem->memSlot() ) ) );
+        tempItem->setText(2,QString::number(engine->constEngineData()->constSMSList()->count( tempItem->smsType(), tempItem->memSlot() ) ) );
         ++it;
     }
 }
@@ -1024,7 +1022,7 @@
 {
 //     if ( KMobileTools::MainConfig::self()->maildir() )
     KMobileTools::KMobiletoolsHelper::createMailDir( objectName() );
-    engine->constEngineData()->smsList()->saveToMailBox();
+    engine->constEngineData()->constSMSList()->saveToMailBox();
     kDebug() << "STARTING SMS EXPORT\n";
     KMessageBox::information( m_widget, i18n("<qt>SMS List for the mobile phone <b>%1</b> was exported to KMail default directory (%2).<br>To view exported messages, close and reopen KMail.</qt>", DEVCFG(objectName() )->devicename(), DEVCFG(objectName() )->maildir_path() ), i18n("SMS List Exported."), "smslistexported_infobox" );
 }
@@ -1037,7 +1035,7 @@
     int result;
     
     kDebug() << "STARTING SMS EXPORT TO CSV\n";
-    result = engine->constEngineData()->smsList()->saveToCSV();
+    result = engine->constEngineData()->constSMSList()->saveToCSV();
     if (result >= 1) {
         KMessageBox::information( m_widget, i18n("<qt>SMS List for the mobile phone <b>%1</b> was exported to the selected Directory.</qt>", DEVCFG(objectName() )->devicename() ), i18n("SMS List Exported."), "smslistexportedtocsv_infobox" );
     }
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/mainpart/devicehome.h #673296:673297
@@ -131,7 +131,7 @@
     bool openFile() { return false; }
     QWidget *widget() { return m_widget;}
     QList<QAction*> actionList() { return l_actionList;}
-    SMSList *smsList() { return engine->constEngineData()->smsList(); }
+    const SMSList *smsList() { return engine->constEngineData()->constSMSList(); }
     void setupWidgets();
     kmobiletoolsMainPart *parent() { return (kmobiletoolsMainPart *) QObject::parent(); }
     KCal::CalendarLocal * calendar() { return p_calendar; }


More information about the kmobiletools mailing list