3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
6 Based on Telepathy-SNOM with copyright notice below.
10 * Telepathy SNOM VoIP phone connection manager
11 * Copyright (C) 2006 by basyskom GmbH
12 * @author Tobias Hunger <info@basyskom.de>
14 * This library is free software; you can redisQObject::tribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License version 2.1 as published by the Free Software Foundation.
18 * This library is disQObject::tributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the
25 * Free Software Foundation, Inc.,
26 * 51 Franklin SQObject::treet, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "connectionmanager.h"
30 #include "connectionmanageradaptor.h"
31 #include "connection.h"
32 #include <logutility.h>
34 #include <QtCore/QDebug>
38 static const QString protocol_name("tel");
41 class ConnectionManagerPrivate
44 ConnectionManagerPrivate(ConnectionManager * parent) :
45 adaptor(new ConnectionManagerAdaptor(parent)),
46 logUtility(new LogUtility(parent))
48 Q_ASSERT(0 != adaptor);
52 ~ConnectionManagerPrivate() { delete(adaptor);}
53 ConnectionManagerAdaptor * const adaptor;
54 LogUtility * const logUtility;
55 Connection * activeConnection;
58 // ---------------------------------------------------------------------------
60 ConnectionManager::ConnectionManager(QObject * parent) :
62 d(new ConnectionManagerPrivate(this))
65 ConnectionManager::~ConnectionManager()
68 org::freedesktop::Telepathy::ParameterDefinitionList
69 ConnectionManager::GetParameters(const QString &proto)
73 Q_ASSERT(!proto.isEmpty());
75 strMessage = "VICAR: ConnectionManager::GetParameters(const QString &prot)";
76 d->logUtility->logMessage(strMessage);
77 org::freedesktop::Telepathy::ParameterDefinitionList result;
78 org::freedesktop::Telepathy::ParameterDefinition param;
80 //TODO - Match the parameters with telepathy-ring?
82 // Attention! Default constructed QDBusVariants cause havok on the D-Bus!
83 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.IMSI";
84 param.flags = Register;
85 param.signature = "s";
86 param.defaultValue = QDBusVariant(QString());
89 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.Privacy";
90 param.flags = Register|hasDefault;
91 param.signature = "s";
92 param.defaultValue = QDBusVariant(QString());
95 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.SMSServiceCentre";
96 param.flags = Register;
97 param.signature = "s";
98 param.defaultValue = QDBusVariant(QString());
101 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.SMSValidityPeriod";
102 param.flags = Register|hasDefault;
103 param.signature = "u";
104 param.defaultValue = QDBusVariant(0);
105 result.append(param);
107 param.name = "account";
109 param.signature = "s";
110 param.defaultValue = QDBusVariant(QString());
111 result.append(param);
113 param.name = "password";
115 param.signature = "s";
116 param.defaultValue = QDBusVariant(QString());
117 result.append(param);
122 QStringList ConnectionManager::ListProtocols()
124 QString strMessage = "VICaR ConnectionManager::ListProtocols()";
125 d->logUtility->logMessage(strMessage);
126 return QStringList(protocol_name);
129 QString ConnectionManager::RequestConnection(const QString & proto,
130 QVariantMap parameters,
131 QDBusObjectPath & object_path)
133 QString strMessage = "VICaR CM: Connection Requested for protocol "+proto;
134 d->logUtility->logMessage(strMessage);
135 QString connection_service;
136 //object_path = QDBusObjectPath();
138 if (proto != protocol_name)
141 sendErrorReply("org.freedesktop.Telepathy.Error.NotImplemented",
142 "VICaR - Unable to create Connection. Requested protocol is not implemented.");
144 strMessage = "VICaR CM::RequestConnection: proto mismatch.";
145 d->logUtility->logMessage(strMessage);
146 return connection_service;
148 if (d->activeConnection != 0){
149 strMessage = "VICaR CM::RequestConnection: An active connection already exists at "+d->activeConnection->serviceName();
150 d->logUtility->logMessage(strMessage);
152 object_path = d->activeConnection->objectPath();
153 connection_service = d->activeConnection->serviceName();
154 //emit NewConnection(connection_service, object_path, "tel"); //Just in case, emit the NewConnection again
155 return connection_service;
160 QString smsServiceCenter;
161 uint smsValidityPeriod(0);
167 foreach (param, parameters.keys())
169 if ("com.nokia.Telepathy.Connection.Interface.GSM.IMSI" == param)
170 { imsi = parameters[param].toString(); }
171 else if ("com.nokia.Telepathy.Connection.Interface.GSM.Privacy" == param)
172 { privacy = parameters[param].toString(); }
173 else if ("com.nokia.Telepathy.Connection.Interface.GSM.SMSServiceCentre" == param)
174 { smsServiceCenter = parameters[param].toString(); }
175 else if ("com.nokia.Telepathy.Connection.Interface.GSM.SMSValidityPeriod" == param)
176 { smsValidityPeriod = parameters[param].toInt(); }
177 else if ("account" == param)
178 { account = parameters[param].toString(); }
179 else if ("password" == param)
180 { password = parameters[param].toString(); }
184 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
185 "VICaR - Unable to create Connection. Invalid parameters specified.");
187 strMessage = "VICaR CM::RequestConnection: invalid parameter" + param + "found.";
188 d->logUtility->logMessage(strMessage);
189 return connection_service;
193 strMessage = "DEBUG CM: Trying to create new connection with account "+account;
194 d->logUtility->logMessage(strMessage);
196 Connection * new_connection = new Connection(account, this);
197 Q_ASSERT(0 != new_connection);
199 strMessage = "DEBUG CM: Trying to register new connection";
200 d->logUtility->logMessage(strMessage);
202 if (!new_connection->registerObject())
204 strMessage = "VICaR CM: Error while registering Connection object with DBus.";
205 d->logUtility->logMessage(strMessage);
206 new_connection->deleteLater();
210 strMessage = "VICaR CM: New Connection Created. Status is " + QString(new_connection->GetStatus());
211 d->logUtility->logMessage(strMessage);
214 object_path = new_connection->objectPath();
215 connection_service = new_connection->serviceName();
217 strMessage = "VICaR CM: Emitting New Connection Signal";
218 d->logUtility->logMessage(strMessage);
220 emit NewConnection(connection_service, object_path, "tel");
222 //Set ActiveConnection - We only need one active connection at a time
223 d->activeConnection = new_connection;
224 return new_connection->serviceName();