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"
33 #include <QtCore/QDebug>
37 static const QString protocol_name("tel");
40 class ConnectionManagerPrivate
43 ConnectionManagerPrivate(ConnectionManager * parent) :
44 adaptor(new ConnectionManagerAdaptor(parent))
45 { Q_ASSERT(0 != adaptor); }
47 ~ConnectionManagerPrivate() { delete(adaptor);}
49 ConnectionManagerAdaptor * const adaptor;
52 // ---------------------------------------------------------------------------
54 ConnectionManager::ConnectionManager(QObject * parent) :
56 d(new ConnectionManagerPrivate(this))
59 ConnectionManager::~ConnectionManager()
62 org::freedesktop::Telepathy::ParameterDefinitionList
63 ConnectionManager::GetParameters(const QString &proto)
65 Q_ASSERT(!proto.isEmpty());
66 qDebug() << "VICAR: ConnectionManager::GetParameters(const QString &prot)";
67 org::freedesktop::Telepathy::ParameterDefinitionList result;
68 org::freedesktop::Telepathy::ParameterDefinition param;
70 // Attention! Default constructed QDBusVariants cause havok on the D-Bus!
71 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.IMSI";
72 param.flags = Register;
73 param.signature = "s";
74 //param.defaultValue = QDBusVariant(QString());
77 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.Privacy";
78 param.flags = Register|hasDefault;
79 param.signature = "s";
80 param.defaultValue = QDBusVariant(QString());
83 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.SMSServiceCentre";
84 param.flags = Register;
85 param.signature = "s";
86 //param.defaultValue = QDBusVariant(QString());
89 param.name = "com.nokia.Telepathy.Connection.Interface.GSM.SMSValidityPeriod";
90 param.flags = Register|hasDefault;
91 param.signature = "u";
92 param.defaultValue = QDBusVariant(0);
95 param.name = "account";
97 param.signature = "s";
98 //param.defaultValue = QDBusVariant(QString());
101 param.name = "password";
103 param.signature = "s";
104 //param.defaultValue = QDBusVariant(QString());
105 result.append(param);
110 QStringList ConnectionManager::ListProtocols()
112 qDebug() << "VICaR ConnectionManager::ListProtocols()";
113 return QStringList(protocol_name);
116 QString ConnectionManager::RequestConnection(const QString & proto,
117 QVariantMap parameters,
118 QDBusObjectPath & object_path)
120 qDebug() << "VICaR CM: Connection Requested...";
121 QString connection_service;
122 object_path = QDBusObjectPath();
124 if (proto != protocol_name)
127 sendErrorReply("org.freedesktop.Telepathy.Error.NotImplemented",
128 "VICaR - Unable to create Connection. Requested protocol is not implemented.");
130 qDebug() << "VICaR CM::RequestConnection: proto mismatch.";
131 return connection_service;
137 QString smsServiceCenter;
138 uint smsValidityPeriod(0);
144 foreach (param, parameters.keys())
146 if ("com.nokia.Telepathy.Connection.Interface.GSM.IMSI" == param)
147 { imsi = parameters[param].toString(); }
148 else if ("com.nokia.Telepathy.Connection.Interface.GSM.Privacy" == param)
149 { privacy = parameters[param].toString(); }
150 else if ("com.nokia.Telepathy.Connection.Interface.GSM.SMSServiceCentre" == param)
151 { smsServiceCenter = parameters[param].toString(); }
152 else if ("com.nokia.Telepathy.Connection.Interface.GSM.SMSValidityPeriod" == param)
153 { smsValidityPeriod = parameters[param].toInt(); }
154 else if ("account" == param)
155 { account = parameters[param].toString(); }
156 else if ("password" == param)
157 { password = parameters[param].toString(); }
161 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
162 "VICaR - Unable to create Connection. Invalid parameters specified.");
164 qDebug() << "VICaR CM::RequestConnection: invalid parameter" << param << "found.";
165 return connection_service;
169 Connection * new_connection = new Connection(account, this);
170 Q_ASSERT(0 != new_connection);
172 if (!new_connection->registerObject())
174 qDebug() << "VICaR CM: Error while registering Connection object with DBus.";
175 delete new_connection;
179 qDebug() << "VICaR CM: New Connection Created. Status is "<< new_connection->GetStatus();
181 object_path = new_connection->objectPath();
182 connection_service = new_connection->serviceName();
184 emit NewConnection(connection_service, object_path, "tel");
186 return new_connection->serviceName();