Small fix to contact parsing.
[jenirok] / src / daemon / calllistener.cpp
index 0938fb8..bdc6529 100644 (file)
@@ -43,7 +43,7 @@ QDBusConnection CallListener::systemBus_ = QDBusConnection::systemBus();
 
 CallListener::CallListener(): source_(0),
 closeConnection_(false), initialized_(false), box_(0), label_(0),
-retries_(-1), timer_(0), currentCall_(0)
+retries_(-1), timer_(0), currentCall_(0), ignoreFirstZero_(false)
 {
 }
 
@@ -68,6 +68,8 @@ bool CallListener::begin()
     sourceConfig_ = tmpConfig;
     delete config;
 
+    ignoreFirstZero_ = (Settings::instance()->get("ignore_first_zero") == "1");
+
     systemBus_.connect(CALL_SERVICE_NAME,
                        CALL_SERVICE_PATH,
                        CALL_SERVICE_INTERFACE,
@@ -164,6 +166,8 @@ void CallListener::requestFinished(QVector <Source::Result> const& results,
         cm.disconnect(true);
     }*/
 
+    qDebug() << "Request finished";
+
     // If box is not visible, the call must have been terminated already
     if(!initialized_ || !box_->isVisible() || !currentCall_)
     {
@@ -269,6 +273,13 @@ void CallListener::incomingCall(QDBusObjectPath path, QString number)
         return;
     }
 
+    // If the call has come through some kind of switch board
+    // there might be a leading zero added
+    if(ignoreFirstZero_)
+    {
+        number = number.replace(QRegExp("^00"), "0");
+    }
+
     ContactManager cm;
 
     if(!cm.numberExists(number))
@@ -426,6 +437,7 @@ bool CallListener::handleConnection()
 
     if(cm.isConnected())
     {
+        cm.connect();
         closeConnection_ = false;
         return true;
     }
@@ -523,7 +535,6 @@ bool CallListener::handleConnection()
 
         if(cm.connect(best.id))
         {
-            sleep(500);
             break;
         }
         else if(cm.error() == ConnectionManager::INVALID_IAP)