[kmobiletools] KDE/kdepim/kmobiletools/kmobiletools

Matthias Lechner matthias at lmme.de
Sat Jun 9 20:03:42 CEST 2007


SVN commit 673279 by lechner:

moving more engine data specific signals to EngineData and adding appropriate setters and getters


 M  +6 -4      engines/at_engine/at_engine.cpp  
 M  +5 -5      engines/at_engine/at_jobs.cpp  
 M  +6 -2      engines/at_engine/at_jobs.h  
 M  +3 -30     libkmobiletools/engine.h  
 M  +59 -11    libkmobiletools/enginedata.cpp  
 M  +86 -0     libkmobiletools/enginedata.h  
 M  +1 -1      mainpart/devicehome.cpp  


--- trunk/KDE/kdepim/kmobiletools/kmobiletools/engines/at_engine/at_engine.cpp #673278:673279
@@ -139,9 +139,9 @@
             break;
         case KMobileTools::Job::pollStatus:
             engineData()->setSignalStrength( ((PollStatus*) job)->phoneSignal() );
-            emit chargeChanged( ((PollStatus*) job)->phoneCharge() );
-            emit chargeTypeChanged( ((PollStatus*) job)->phoneChargeType() );
-            emit ringing( ((PollStatus*) job)->ringing() );
+            engineData()->setCharge( ((PollStatus*) job)->phoneCharge() );
+            engineData()->setChargeType( ((PollStatus*) job)->phoneChargeType() );
+            engineData()->setPhoneRinging( ((PollStatus*) job)->ringing() );
             break;
         case KMobileTools::Job::fetchPhoneInfos:
             engineData()->setManufacturer( ( (FetchPhoneInfos*) job )->rawManufacturer() );
@@ -149,7 +149,9 @@
             engineData()->setRevision (( (FetchPhoneInfos*) job )->revision() );
             engineData()->setIMEI( ( (FetchPhoneInfos*) job )->imei() );
             engineData()->setSMSCenter(( (FetchPhoneInfos*) job )->smsCenter() );
-            if(! engineData()->smsCenter().isNull() ) emit networkNameChanged( i18n("Network: %1",PickSMSCenter::smsCenterName (engineData()->smsCenter() ) ) );
+            if(! engineData()->smsCenter().isNull() )
+                engineData()->setNetworkName( i18n("Network: %1",
+                PickSMSCenter::smsCenterName (engineData()->smsCenter() ) ) );
             if ( engineData()->manufacturer().contains( "Siemens", Qt::CaseInsensitive ) ) engineData()->setManufacturerID( Siemens);
             if ( engineData()->manufacturer().contains( "Motorola", Qt::CaseInsensitive ) ) engineData()->setManufacturerID ( Motorola);
             if ( engineData()->manufacturer().contains( "Ericsson", Qt::CaseInsensitive ) ) engineData()->setManufacturerID ( SonyEricsson);
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/engines/at_engine/at_jobs.cpp #673278:673279
@@ -192,7 +192,7 @@
 
 
 PollStatus::PollStatus(KMobileTools::Job *pjob, KMobileTools::SerialManager *device, AT_Engine* parent) : kmobiletoolsATJob(pjob, device, parent)
-        , i_charge(0), i_signal(0), i_chargeType(0), b_calling(false)
+        , i_charge(0), i_signal(0), m_chargeType(KMobileTools::EngineData::Battery), b_calling(false)
 {}
 void PollStatus::run ()
 {
@@ -210,9 +210,9 @@
         s_charge=s_charge.trimmed();
 
         i_charge=s_charge.section(",",1,1).toInt();
-        i_chargeType=s_charge.section(",",0,0).toInt();
+        m_chargeType=(KMobileTools::EngineData::ChargeType) s_charge.section(",",0,0).toInt();
     }
-    else { i_charge=-1; i_chargeType=-1; }
+    else { i_charge=-1; m_chargeType=KMobileTools::EngineData::Unknown; }
 
     if( str_status.contains("+CSQ",Qt::CaseSensitive) )
     {
@@ -229,12 +229,12 @@
 //     sleep(10);
     if ( true /* ! Config->getMotoBattery() */ ) return;
 
-    if(i_chargeType==0)
+    if(m_chargeType==KMobileTools::EngineData::Battery)
     {
         if( log(i_charge/1.4)/log(1.038) > 30 )
             i_charge=(int) (log((double) i_charge/1.4)/log(1.038));
     }
-    if(i_chargeType==1)
+    if(m_chargeType==KMobileTools::EngineData::ACAdaptor)
     {
         i_charge= (int) ((int) pow( (double) (i_charge-6), (4.0/6.0) ) * 5.2) +2;
     }
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/engines/at_engine/at_jobs.h #673278:673279
@@ -22,6 +22,7 @@
 #ifndef ATJOBSS_H
 #define ATJOBSS_H
 
+#include <libkmobiletools/enginedata.h>
 #include <libkmobiletools/engine.h>
 #include <libkmobiletools/sms.h>
 
@@ -93,14 +94,17 @@
     public:
       PollStatus (KMobileTools::Job *pjob, KMobileTools::SerialManager *device, AT_Engine* parent = 0 );
         int phoneCharge()     { return i_charge; }
-        int phoneChargeType() { return i_chargeType; }
+        KMobileTools::EngineData::ChargeType phoneChargeType() {
+            return m_chargeType;
+        }
         int phoneSignal()     { return i_signal; }
         bool ringing()        { return b_calling; }
         JobType type()            { return KMobileTools::Job::pollStatus; }
     protected:
         void run ();
     private:
-        int i_charge, i_signal, i_chargeType;
+        int i_charge, i_signal;
+        KMobileTools::EngineData::ChargeType m_chargeType;
         bool b_calling;
 };
 
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/libkmobiletools/engine.h #673278:673279
@@ -308,33 +308,13 @@
 
         /**
          * This signal is emitted when a SMS folder is added
+         * 
+         * @TODO move this signal to engineData (and add a method to explicitly
+         * add and remove sms folders so the signal gets emitted automatically)
          */
         void smsFoldersAdded();
 
         /**
-         * This signal is emitted every phone poll.
-         *
-         * @param charge the charge level in percentual.
-         */
-        void chargeChanged( int charge );
-
-        /**
-         * This signal is emitted every phone poll.
-         * Charge type is 1 when phone is connected to the adapter.
-         *
-         * @param chargeType the type of charge
-         */
-        void chargeTypeChanged( int chargeType );
-
-        /**
-         * This signal is emitted every phone poll.
-         *
-         * @param ringing true if phone is ringing
-         * @todo emit only if phone is ringing
-         */
-        void ringing( bool ringing );
-
-        /**
          * This signal is emitted when the mobile's phone book has been changed.
          *
          * @todo to be deleted
@@ -347,13 +327,6 @@
         void phoneBookChanged();
 
         /**
-         * This signal is emitted every phone infos fetch.
-         *
-         * @param name the name of the network.
-         */
-        void networkNameChanged( const QString& name );
-
-        /**
          * This signal is emitted when the engine is suspended.
          */
         void suspended();
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/libkmobiletools/enginedata.cpp #673278:673279
@@ -33,17 +33,21 @@
     public:
         EngineDataPrivate() : engine(NULL), i_manufacturer(KMobileTools::Engine::Unknown) {}
         KMobileTools::Engine *engine;
-        bool b_connected;               // phone connected?
-        int i_signalStrength;           // signal strength in percent
-        QString s_manufacturer;         // manufacturer raw string
-        int i_manufacturer;             // enum value?
-        QString s_model;                // phone model
-        QString s_imei;                 // phone imei code
-        QString s_smscenter;            // SMS Center number
-        QString s_revision;             // Firmware revision
-        KCal::Event::List *p_calendar;  // Internal Calendar Events List
-        ContactsList* p_addresseeList;  // Phonebook Contacts List
-        SMSList *p_smsList;             // List of SMS fetched from the phone
+        bool b_connected;                           // phone connected?
+        int i_signalStrength;                       // signal strength in percent
+        int i_charge;                               // charge in percent
+        EngineData::ChargeType m_chargeType;        // charge type
+        bool b_ringing;                             // phone is ringing?
+        QString s_networkName;                      // network name
+        QString s_manufacturer;                     // manufacturer raw string
+        int i_manufacturer;                         // enum value?
+        QString s_model;                            // phone model
+        QString s_imei;                             // phone imei code
+        QString s_smscenter;                        // SMS Center number
+        QString s_revision;                         // Firmware revision
+        KCal::Event::List *p_calendar;              // Internal Calendar Events List
+        ContactsList* p_addresseeList;              // Phonebook Contacts List
+        SMSList *p_smsList;                         // List of SMS fetched from the phone
 };
 
 EngineData::EngineData(KMobileTools::Engine *parentEngine)
@@ -118,3 +122,47 @@
 
     d->i_signalStrength = signalStrength;
 }
+
+int EngineData::charge() const {
+    return d->i_charge;
+}
+
+void EngineData::setCharge( int charge ) {
+    if( charge != d->i_charge )
+        emit chargeChanged( charge );
+
+    d->i_charge = charge;
+}
+
+int EngineData::chargeType() const {
+    return d->m_chargeType;
+}
+
+void EngineData::setChargeType( ChargeType chargeType ) {
+    if( chargeType != d->m_chargeType )
+        emit chargeTypeChanged( chargeType );
+
+    d->m_chargeType = chargeType;
+}
+
+bool EngineData::phoneRinging() const {
+    return d->b_ringing;
+}
+
+void EngineData::setPhoneRinging( bool ringing ) {
+    if( ringing != d->b_ringing )
+        emit EngineData::ringing( ringing );
+
+    d->b_ringing = ringing;
+}
+
+QString EngineData::networkName() const {
+    return d->s_networkName;
+}
+
+void EngineData::setNetworkName( const QString& networkName ) {
+    if( networkName != d->s_networkName )
+        emit networkNameChanged( networkName );
+
+    d->s_networkName = networkName;
+}
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/libkmobiletools/enginedata.h #673278:673279
@@ -37,6 +37,8 @@
     {
         Q_OBJECT
         public:
+            enum ChargeType { Unknown = -1, Battery = 0, ACAdaptor = 1 };
+
             /**
              * Creates a new EngineData object.
              * This class can store data from engines, emit signals when it changes,
@@ -76,6 +78,62 @@
             void setSignalStrength( int signalStrength );
 
             /**
+             * Returns the phone's charge in percent
+             * 
+             * @return the phone's charge in percent
+             */
+            int charge() const;
+
+            /**
+             * Sets the phone's charge in percent
+             * 
+             * @p charge the phone's charge in percent
+             */
+            void setCharge( int charge );
+
+            /**
+             * Returns the phone's charge type
+             * 
+             * @return the phone's charge type
+             */
+            int chargeType() const;
+
+            /**
+             * Sets the phone's charge type
+             * 
+             * @p chargeType the phone's charge type
+             */
+            void setChargeType( ChargeType chargeType );
+
+            /**
+             * Returns whether the phone is ringing
+             * 
+             * @return true if the phone is ringing
+             */
+            bool phoneRinging() const;
+
+            /**
+             * Sets whether the phone is ringing
+             * 
+             * @p chargeType true if the phone is ringing
+             */
+            void setPhoneRinging( bool ringing );
+
+            /**
+             * Returns the network the phone is currently logged in
+             * 
+             * @return the network name
+             */
+            QString networkName() const;
+
+            /**
+             * Sets the network name the phone is currently logged in
+             * 
+             * @param networkName the network name
+             */
+            void setNetworkName( const QString& networkName );
+
+            /**
              * Sets phone manufacturer as returned by the mobile phone.
              *
              * @param manufacturer the manufacturer string.
@@ -213,6 +271,34 @@
             */
             void signalStrengthChanged( int signalStrength );
 
+            /**
+            * This signal is whenever the phone charge changes
+            *
+            * @param charge the charge level in percent
+            */
+            void chargeChanged( int charge );
+
+            /**
+            * This signal is emitted whenever the phone's charge type changed
+            *
+            * @param chargeType the charge type
+            */
+            void chargeTypeChanged( ChargeType chargeType );
+
+            /**
+            * This signal whenever the phone is ringing
+            *
+            * @param ringing true if phone is ringing
+            */
+            void ringing( bool ringing );
+
+            /**
+            * This signal is emitted whenever the current network changes
+            *
+            * @param name the name of the network.
+            */
+            void networkNameChanged( const QString& name );
+
         private:
             EngineDataPrivate *const d;
     };
--- trunk/KDE/kdepim/kmobiletools/kmobiletools/mainpart/devicehome.cpp #673278:673279
@@ -326,7 +326,7 @@
     connect(engine, SIGNAL(smsAdded( const QByteArray& )), SLOT(smsAdded( const QByteArray&) ) );
     connect(engine, SIGNAL(smsDeleted( const QByteArray& )), SLOT(smsRemoved(const QByteArray&) ) );
     connect(engine, SIGNAL(smsModified( const QByteArray& )), SLOT(smsModified( const QByteArray& )) );
-    connect(engine, SIGNAL(ringing( bool )), this, SLOT(slotRing( bool ) ) );
+    connect(engine->constEngineData(), SIGNAL(ringing( bool )), this, SLOT(slotRing( bool ) ) );
     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* ) ) );


More information about the kmobiletools mailing list