telepathy-ofono-0.2+14.04.20140407/0000755000015301777760000000000012320627204017065 5ustar pbusernogroup00000000000000telepathy-ofono-0.2+14.04.20140407/voicemailiface.cpp0000644000015301777760000001570612320626651022547 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include #include #include "voicemailiface.h" // Conn.I.Voicemail BaseConnectionVoicemailInterface::Adaptee::Adaptee(BaseConnectionVoicemailInterface *interface) : QObject(interface), mInterface(interface) { } struct TP_QT_NO_EXPORT BaseConnectionVoicemailInterface::Private { Private(BaseConnectionVoicemailInterface *parent) : adaptee(new BaseConnectionVoicemailInterface::Adaptee(parent)) { } VoicemailCountCallback voicemailCountCB; VoicemailNumberCallback voicemailNumberCB; VoicemailIndicatorCallback voicemailIndicatorCB; BaseConnectionVoicemailInterface::Adaptee *adaptee; }; BaseConnectionVoicemailInterface::Adaptee::~Adaptee() { } void BaseConnectionVoicemailInterface::Adaptee::voicemailIndicator(const ConnectionInterfaceVoicemailAdaptor::VoicemailIndicatorContextPtr &context) { if (!mInterface->mPriv->voicemailIndicatorCB.isValid()) { context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); return; } Tp::DBusError error; bool active = mInterface->mPriv->voicemailIndicatorCB(&error); if (error.isValid()) { context->setFinishedWithError(error.name(), error.message()); return; } context->setFinished(active); } void BaseConnectionVoicemailInterface::Adaptee::voicemailNumber(const ConnectionInterfaceVoicemailAdaptor::VoicemailNumberContextPtr &context) { if (!mInterface->mPriv->voicemailNumberCB.isValid()) { context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); return; } Tp::DBusError error; QString number = mInterface->mPriv->voicemailNumberCB(&error); if (error.isValid()) { context->setFinishedWithError(error.name(), error.message()); return; } context->setFinished(number); } void BaseConnectionVoicemailInterface::Adaptee::voicemailCount(const ConnectionInterfaceVoicemailAdaptor::VoicemailCountContextPtr &context) { if (!mInterface->mPriv->voicemailCountCB.isValid()) { context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); return; } Tp::DBusError error; uint count = mInterface->mPriv->voicemailCountCB(&error); if (error.isValid()) { context->setFinishedWithError(error.name(), error.message()); return; } context->setFinished(count); } BaseConnectionVoicemailInterface::BaseConnectionVoicemailInterface() : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_VOICEMAIL), mPriv(new Private(this)) { } BaseConnectionVoicemailInterface::~BaseConnectionVoicemailInterface() { delete mPriv; } void BaseConnectionVoicemailInterface::setVoicemailIndicatorCallback(const VoicemailIndicatorCallback &cb) { mPriv->voicemailIndicatorCB = cb; } void BaseConnectionVoicemailInterface::setVoicemailNumberCallback(const VoicemailNumberCallback &cb) { mPriv->voicemailNumberCB = cb; } void BaseConnectionVoicemailInterface::setVoicemailCountCallback(const VoicemailCountCallback &cb) { mPriv->voicemailCountCB = cb; } void BaseConnectionVoicemailInterface::setVoicemailCount(int count) { Q_EMIT mPriv->adaptee->voicemailCountChanged(uint(count)); } void BaseConnectionVoicemailInterface::setVoicemailIndicator(bool active) { Q_EMIT mPriv->adaptee->voicemailIndicatorChanged(active); } QVariantMap BaseConnectionVoicemailInterface::immutableProperties() const { QVariantMap map; return map; } void BaseConnectionVoicemailInterface::createAdaptor() { (void) new ConnectionInterfaceVoicemailAdaptor(dbusObject()->dbusConnection(), mPriv->adaptee, dbusObject()); } ConnectionInterfaceVoicemailAdaptor::ConnectionInterfaceVoicemailAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent) : Tp::AbstractAdaptor(bus, adaptee, parent) { connect(adaptee, SIGNAL(voicemailCountChanged(uint)), SIGNAL(VoicemailCountChanged(uint))); connect(adaptee, SIGNAL(voicemailIndicatorChanged(bool)), SIGNAL(VoicemailIndicatorChanged(bool))); } ConnectionInterfaceVoicemailAdaptor::~ConnectionInterfaceVoicemailAdaptor() { } bool ConnectionInterfaceVoicemailAdaptor::VoicemailIndicator(const QDBusMessage& dbusMessage) { if (!adaptee()->metaObject()->indexOfMethod("voicemailIndicator(ConnectionInterfaceVoicemailAdaptor::VoicemailIndicatorContextPtr)") == -1) { dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); return bool(); } VoicemailIndicatorContextPtr ctx = VoicemailIndicatorContextPtr( new Tp::MethodInvocationContext< bool >(dbusConnection(), dbusMessage)); QMetaObject::invokeMethod(adaptee(), "voicemailIndicator", Q_ARG(ConnectionInterfaceVoicemailAdaptor::VoicemailIndicatorContextPtr, ctx)); return bool(); } QString ConnectionInterfaceVoicemailAdaptor::VoicemailNumber(const QDBusMessage& dbusMessage) { if (!adaptee()->metaObject()->indexOfMethod("voicemailNumber(ConnectionInterfaceVoicemailAdaptor::VoicemailNumberContextPtr)") == -1) { dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); return QString(); } VoicemailNumberContextPtr ctx = VoicemailNumberContextPtr( new Tp::MethodInvocationContext< QString >(dbusConnection(), dbusMessage)); QMetaObject::invokeMethod(adaptee(), "voicemailNumber", Q_ARG(ConnectionInterfaceVoicemailAdaptor::VoicemailNumberContextPtr, ctx)); return QString(); } uint ConnectionInterfaceVoicemailAdaptor::VoicemailCount(const QDBusMessage& dbusMessage) { if (!adaptee()->metaObject()->indexOfMethod("voicemailCount(ConnectionInterfaceVoicemailAdaptor::VoicemailCountContextPtr)") == -1) { dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); return uint(); } VoicemailCountContextPtr ctx = VoicemailCountContextPtr( new Tp::MethodInvocationContext< uint >(dbusConnection(), dbusMessage)); QMetaObject::invokeMethod(adaptee(), "voicemailCount", Q_ARG(ConnectionInterfaceVoicemailAdaptor::VoicemailCountContextPtr, ctx)); return uint(); } telepathy-ofono-0.2+14.04.20140407/mmsdservice.cpp0000644000015301777760000000770512320626651022130 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include #include "dbustypes.h" #include "mmsdservice.h" QDBusArgument &operator<<(QDBusArgument &argument, const MessageStruct &message) { argument.beginStructure(); argument << message.path << message.properties; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, MessageStruct &message) { argument.beginStructure(); argument >> message.path >> message.properties; argument.endStructure(); return argument; } MMSDService::MMSDService(QString objectPath, oFonoConnection* connection, QObject *parent) : QObject(parent), m_servicePath(objectPath) { QDBusReply replyMessages; QDBusReply replyProperties; QDBusMessage request; qDBusRegisterMetaType(); qDBusRegisterMetaType(); request = QDBusMessage::createMethodCall("org.ofono.mms", m_servicePath, "org.ofono.mms.Service", "GetProperties"); replyProperties = QDBusConnection::sessionBus().call(request); m_properties = replyProperties; request = QDBusMessage::createMethodCall("org.ofono.mms", m_servicePath, "org.ofono.mms.Service", "GetMessages"); replyMessages = QDBusConnection::sessionBus().call(request); m_messages = replyMessages; QDBusConnection::sessionBus().connect("org.ofono.mms", m_servicePath, "org.ofono.mms.Service", "MessageAdded", this, SLOT(onMessageAdded(const QDBusObjectPath&, const QVariantMap&))); QDBusConnection::sessionBus().connect("org.ofono.mms", m_servicePath, "org.ofono.mms.Service", "MessageRemoved", this, SLOT(onMessageRemoved(const QDBusObjectPath&))); } MMSDService::~MMSDService() { } QString MMSDService::path() const { return m_servicePath; } QVariantMap MMSDService::properties() const { return m_properties; } MessageList MMSDService::messages() const { return m_messages; } void MMSDService::onMessageAdded(const QDBusObjectPath &path, const QVariantMap &properties) { qDebug() << "message added" << path.path() << properties; Q_EMIT messageAdded(path.path(), properties); } void MMSDService::onMessageRemoved(const QDBusObjectPath& path) { qDebug() << "message removed" << path.path(); Q_EMIT messageRemoved(path.path()); } QDBusObjectPath MMSDService::sendMessage(QStringList recipients, QString smil, AttachmentList attachments) { QDBusMessage request; QList arguments; QDBusReply reply; arguments.append(recipients); arguments.append(smil); arguments.append(QVariant::fromValue(attachments)); request = QDBusMessage::createMethodCall("org.ofono.mms", m_servicePath, "org.ofono.mms.Service", "SendMessage"); request.setArguments(arguments); reply = QDBusConnection::sessionBus().call(request); return reply; } telepathy-ofono-0.2+14.04.20140407/dbustypes.h0000644000015301777760000000232212320626651021264 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef DBUSTYPES #define DBUSTYPES struct MessageStruct { QDBusObjectPath path; QVariantMap properties; }; struct AttachmentStruct { QString id; QString contentType; QString filePath; quint64 offset; quint64 length; }; typedef QList AttachmentList; Q_DECLARE_METATYPE(AttachmentStruct) Q_DECLARE_METATYPE(AttachmentList) typedef QList MessageList; Q_DECLARE_METATYPE(MessageStruct) Q_DECLARE_METATYPE(MessageList) #endif telepathy-ofono-0.2+14.04.20140407/cmake/0000755000015301777760000000000012320627204020145 5ustar pbusernogroup00000000000000telepathy-ofono-0.2+14.04.20140407/cmake/modules/0000755000015301777760000000000012320627204021615 5ustar pbusernogroup00000000000000telepathy-ofono-0.2+14.04.20140407/cmake/modules/FindLcov.cmake0000644000015301777760000000172012320626651024330 0ustar pbusernogroup00000000000000# - Find lcov # Will define: # # LCOV_EXECUTABLE - the lcov binary # GENHTML_EXECUTABLE - the genhtml executable # # Copyright (C) 2010 by Johannes Wienke # # This program is free software; you can redistribute it # and/or modify it under the terms of the GNU General # Public License as published by the Free Software Foundation; # either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # INCLUDE(FindPackageHandleStandardArgs) FIND_PROGRAM(LCOV_EXECUTABLE lcov) FIND_PROGRAM(GENHTML_EXECUTABLE genhtml) FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lcov DEFAULT_MSG LCOV_EXECUTABLE GENHTML_EXECUTABLE) # only visible in advanced view MARK_AS_ADVANCED(LCOV_EXECUTABLE GENHTML_EXECUTABLE) telepathy-ofono-0.2+14.04.20140407/cmake/modules/EnableCoverageReport.cmake0000644000015301777760000001531112320626651026663 0ustar pbusernogroup00000000000000# - Creates a special coverage build type and target on GCC. # # Defines a function ENABLE_COVERAGE_REPORT which generates the coverage target # for selected targets. Optional arguments to this function are used to filter # unwanted results using globbing expressions. Moreover targets with tests for # the source code can be specified to trigger regenerating the report if the # test has changed # # ENABLE_COVERAGE_REPORT(TARGETS target... [FILTER filter...] [TESTS test targets...]) # # To generate a coverage report first build the project with # CMAKE_BUILD_TYPE=coverage, then call make test and afterwards make coverage. # # The coverage report is based on gcov. Depending on the availability of lcov # a HTML report will be generated and/or an XML report of gcovr is found. # The generated coverage target executes all found solutions. Special targets # exist to create e.g. only the xml report: coverage-xml. # # Copyright (C) 2010 by Johannes Wienke # # This program is free software; you can redistribute it # and/or modify it under the terms of the GNU General # Public License as published by the Free Software Foundation; # either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # INCLUDE(ParseArguments) FIND_PACKAGE(Lcov) FIND_PACKAGE(gcovr) FUNCTION(ENABLE_COVERAGE_REPORT) # argument parsing PARSE_ARGUMENTS(ARG "FILTER;TARGETS;TESTS" "" ${ARGN}) SET(COVERAGE_RAW_FILE "${CMAKE_BINARY_DIR}/coverage.raw.info") SET(COVERAGE_FILTERED_FILE "${CMAKE_BINARY_DIR}/coverage.info") SET(COVERAGE_REPORT_DIR "${CMAKE_BINARY_DIR}/coveragereport") SET(COVERAGE_XML_FILE "${CMAKE_BINARY_DIR}/coverage.xml") SET(COVERAGE_XML_COMMAND_FILE "${CMAKE_BINARY_DIR}/coverage-xml.cmake") # decide if there is any tool to create coverage data SET(TOOL_FOUND FALSE) IF(LCOV_FOUND OR GCOVR_FOUND) SET(TOOL_FOUND TRUE) ENDIF() IF(NOT TOOL_FOUND) MESSAGE(STATUS "Cannot enable coverage targets because neither lcov nor gcovr are found.") ENDIF() STRING(TOLOWER "${CMAKE_BUILD_TYPE}" COVERAGE_BUILD_TYPE) IF(CMAKE_COMPILER_IS_GNUCXX AND TOOL_FOUND AND "${COVERAGE_BUILD_TYPE}" MATCHES "coverage") MESSAGE(STATUS "Coverage support enabled for targets: ${ARG_TARGETS}") # create coverage build type SET(CMAKE_CXX_FLAGS_COVERAGE ${CMAKE_CXX_FLAGS_DEBUG} PARENT_SCOPE) SET(CMAKE_C_FLAGS_COVERAGE ${CMAKE_C_FLAGS_DEBUG} PARENT_SCOPE) SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES} coverage PARENT_SCOPE) # instrument targets SET_TARGET_PROPERTIES(${ARG_TARGETS} PROPERTIES COMPILE_FLAGS --coverage LINK_FLAGS --coverage) # html report IF (LCOV_FOUND) MESSAGE(STATUS "Enabling HTML coverage report") # set up coverage target ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_RAW_FILE} COMMAND ${LCOV_EXECUTABLE} -c -d ${CMAKE_BINARY_DIR} -o ${COVERAGE_RAW_FILE} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMENT "Collecting coverage data" DEPENDS ${ARG_TARGETS} ${ARG_TESTS} VERBATIM) # filter unwanted stuff LIST(LENGTH ARG_FILTER FILTER_LENGTH) IF(${FILTER_LENGTH} GREATER 0) SET(FILTER COMMAND ${LCOV_EXECUTABLE}) FOREACH(F ${ARG_FILTER}) SET(FILTER ${FILTER} -r ${COVERAGE_FILTERED_FILE} ${F}) ENDFOREACH() SET(FILTER ${FILTER} -o ${COVERAGE_FILTERED_FILE}) ELSE() SET(FILTER "") ENDIF() ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_FILTERED_FILE} COMMAND ${LCOV_EXECUTABLE} -e ${COVERAGE_RAW_FILE} "${CMAKE_SOURCE_DIR}*" -o ${COVERAGE_FILTERED_FILE} ${FILTER} DEPENDS ${COVERAGE_RAW_FILE} COMMENT "Filtering recorded coverage data for project-relevant entries" VERBATIM) ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_REPORT_DIR} COMMAND ${CMAKE_COMMAND} -E make_directory ${COVERAGE_REPORT_DIR} COMMAND ${GENHTML_EXECUTABLE} --legend --show-details -t "${PROJECT_NAME} test coverage" -o ${COVERAGE_REPORT_DIR} ${COVERAGE_FILTERED_FILE} DEPENDS ${COVERAGE_FILTERED_FILE} COMMENT "Generating HTML coverage report in ${COVERAGE_REPORT_DIR}" VERBATIM) ADD_CUSTOM_TARGET(coverage-html DEPENDS ${COVERAGE_REPORT_DIR}) ENDIF() # xml coverage report IF(GCOVR_FOUND) MESSAGE(STATUS "Enabling XML coverage report") # gcovr cannot write directly to a file so the execution needs to # be wrapped in a cmake file that generates the file output FILE(WRITE ${COVERAGE_XML_COMMAND_FILE} "SET(ENV{LANG} en)\n") FILE(APPEND ${COVERAGE_XML_COMMAND_FILE} "EXECUTE_PROCESS(COMMAND \"${GCOVR_EXECUTABLE}\" -x -r \"${CMAKE_SOURCE_DIR}\" OUTPUT_FILE \"${COVERAGE_XML_FILE}\" WORKING_DIRECTORY \"${CMAKE_BINARY_DIR}\")\n") ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_XML_FILE} COMMAND ${CMAKE_COMMAND} ARGS -P ${COVERAGE_XML_COMMAND_FILE} COMMENT "Generating coverage XML report" VERBATIM) ADD_CUSTOM_TARGET(coverage-xml DEPENDS ${COVERAGE_XML_FILE}) ENDIF() # provide a global coverage target executing both steps if available SET(GLOBAL_DEPENDS "") IF(LCOV_FOUND) LIST(APPEND GLOBAL_DEPENDS ${COVERAGE_REPORT_DIR}) ENDIF() IF(GCOVR_FOUND) LIST(APPEND GLOBAL_DEPENDS ${COVERAGE_XML_FILE}) ENDIF() IF(LCOV_FOUND OR GCOVR_FOUND) ADD_CUSTOM_TARGET(coverage DEPENDS ${GLOBAL_DEPENDS}) ENDIF() ENDIF() ENDFUNCTION() telepathy-ofono-0.2+14.04.20140407/cmake/modules/Findgcovr.cmake0000644000015301777760000000170212320626651024545 0ustar pbusernogroup00000000000000# - Find gcovr scrip # Will define: # # GCOVR_EXECUTABLE - the gcovr script # # Uses: # # GCOVR_ROOT - root to search for the script # # Copyright (C) 2011 by Johannes Wienke # # This program is free software; you can redistribute it # and/or modify it under the terms of the GNU General # Public License as published by the Free Software Foundation; # either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # INCLUDE(FindPackageHandleStandardArgs) FIND_PROGRAM(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin") FIND_PACKAGE_HANDLE_STANDARD_ARGS(gcovr DEFAULT_MSG GCOVR_EXECUTABLE) # only visible in advanced view MARK_AS_ADVANCED(GCOVR_EXECUTABLE) telepathy-ofono-0.2+14.04.20140407/cmake/modules/ParseArguments.cmake0000644000015301777760000000340612320626651025567 0ustar pbusernogroup00000000000000# Parse arguments passed to a function into several lists separated by # upper-case identifiers and options that do not have an associated list e.g.: # # SET(arguments # hello OPTION3 world # LIST3 foo bar # OPTION2 # LIST1 fuz baz # ) # PARSE_ARGUMENTS(ARG "LIST1;LIST2;LIST3" "OPTION1;OPTION2;OPTION3" ${arguments}) # # results in 7 distinct variables: # * ARG_DEFAULT_ARGS: hello;world # * ARG_LIST1: fuz;baz # * ARG_LIST2: # * ARG_LIST3: foo;bar # * ARG_OPTION1: FALSE # * ARG_OPTION2: TRUE # * ARG_OPTION3: TRUE # # taken from http://www.cmake.org/Wiki/CMakeMacroParseArguments MACRO(PARSE_ARGUMENTS prefix arg_names option_names) SET(DEFAULT_ARGS) FOREACH(arg_name ${arg_names}) SET(${prefix}_${arg_name}) ENDFOREACH(arg_name) FOREACH(option ${option_names}) SET(${prefix}_${option} FALSE) ENDFOREACH(option) SET(current_arg_name DEFAULT_ARGS) SET(current_arg_list) FOREACH(arg ${ARGN}) SET(larg_names ${arg_names}) LIST(FIND larg_names "${arg}" is_arg_name) IF (is_arg_name GREATER -1) SET(${prefix}_${current_arg_name} ${current_arg_list}) SET(current_arg_name ${arg}) SET(current_arg_list) ELSE (is_arg_name GREATER -1) SET(loption_names ${option_names}) LIST(FIND loption_names "${arg}" is_option) IF (is_option GREATER -1) SET(${prefix}_${arg} TRUE) ELSE (is_option GREATER -1) SET(current_arg_list ${current_arg_list} ${arg}) ENDIF (is_option GREATER -1) ENDIF (is_arg_name GREATER -1) ENDFOREACH(arg) SET(${prefix}_${current_arg_name} ${current_arg_list}) ENDMACRO(PARSE_ARGUMENTS) telepathy-ofono-0.2+14.04.20140407/pendingmessagesmanager.h0000644000015301777760000000240012320626651023746 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include struct PendingMessage { QString recipientId; QDateTime timestamp; }; class PendingMessagesManager : public QObject { Q_OBJECT public: static PendingMessagesManager *instance(); void addPendingMessage(const QString &objectPath, const QString &id); void removePendingMessage(const QString &objectPath); QString recipientIdForMessageId(const QString &messageId); private: explicit PendingMessagesManager(QObject *parent = 0); QSqlDatabase mDatabase; }; telepathy-ofono-0.2+14.04.20140407/ofonotextchannel.cpp0000644000015301777760000003520512320626661023162 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ // ofono-qt #include // telepathy-ofono #include "ofonotextchannel.h" #include "pendingmessagesmanager.h" QDBusArgument &operator<<(QDBusArgument &argument, const AttachmentStruct &attachment) { argument.beginStructure(); argument << attachment.id << attachment.contentType << attachment.filePath << attachment.offset << attachment.length; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, AttachmentStruct &attachment) { argument.beginStructure(); argument >> attachment.id >> attachment.contentType >> attachment.filePath >> attachment.offset >> attachment.length; argument.endStructure(); return argument; } oFonoTextChannel::oFonoTextChannel(oFonoConnection *conn, QStringList phoneNumbers, bool flash, QObject *parent): QObject(parent), mConnection(conn), mPhoneNumbers(phoneNumbers), mFlash(flash), mMessageCounter(1) { qDBusRegisterMetaType(); qDBusRegisterMetaType(); Tp::BaseChannelPtr baseChannel; if (phoneNumbers.size() == 1) { baseChannel = Tp::BaseChannel::create(mConnection, TP_QT_IFACE_CHANNEL_TYPE_TEXT, mConnection->ensureHandle(mPhoneNumbers[0]), Tp::HandleTypeContact); } else { baseChannel = Tp::BaseChannel::create(mConnection, TP_QT_IFACE_CHANNEL_TYPE_TEXT, 0, Tp::HandleTypeNone); } Tp::BaseChannelTextTypePtr textType = Tp::BaseChannelTextType::create(baseChannel.data()); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(textType)); QStringList supportedContentTypes = QStringList() << "text/plain"; Tp::UIntList messageTypes = Tp::UIntList() << Tp::ChannelTextMessageTypeNormal << Tp::ChannelTextMessageTypeDeliveryReport; uint messagePartSupportFlags = 0; uint deliveryReportingSupport = Tp::DeliveryReportingSupportFlagReceiveSuccesses; mMessagesIface = Tp::BaseChannelMessagesInterface::create(textType.data(), supportedContentTypes, messageTypes, messagePartSupportFlags, deliveryReportingSupport); mMessagesIface->setSendMessageCallback(Tp::memFun(this,&oFonoTextChannel::sendMessage)); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mMessagesIface)); mGroupIface = Tp::BaseChannelGroupInterface::create(Tp::ChannelGroupFlagCanAdd, conn->selfHandle()); mGroupIface->setAddMembersCallback(Tp::memFun(this,&oFonoTextChannel::onAddMembers)); mGroupIface->setRemoveMembersCallback(Tp::memFun(this,&oFonoTextChannel::onRemoveMembers)); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mGroupIface)); addMembers(phoneNumbers); mSMSIface = Tp::BaseChannelSMSInterface::create(flash, true); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mSMSIface)); mBaseChannel = baseChannel; mTextChannel = Tp::BaseChannelTextTypePtr::dynamicCast(mBaseChannel->interface(TP_QT_IFACE_CHANNEL_TYPE_TEXT)); mTextChannel->setMessageAcknowledgedCallback(Tp::memFun(this,&oFonoTextChannel::messageAcknowledged)); QObject::connect(mBaseChannel.data(), SIGNAL(closed()), this, SLOT(deleteLater())); } void oFonoTextChannel::onAddMembers(const Tp::UIntList& handles, const QString& message, Tp::DBusError* error) { addMembers(mConnection->inspectHandles(Tp::HandleTypeContact, handles, error)); } void oFonoTextChannel::onRemoveMembers(const Tp::UIntList& handles, const QString& message, Tp::DBusError* error) { Q_FOREACH(uint handle, handles) { Q_FOREACH(const QString &phoneNumber, mConnection->inspectHandles(Tp::HandleTypeContact, Tp::UIntList() << handle, error)) { mPhoneNumbers.removeAll(phoneNumber); } mMembers.removeAll(handle); } mGroupIface->removeMembers(handles); } void oFonoTextChannel::addMembers(QStringList phoneNumbers) { Tp::UIntList handles; Q_FOREACH(const QString &phoneNumber, phoneNumbers) { uint handle = mConnection->ensureHandle(phoneNumber); handles << handle; if (!mPhoneNumbers.contains(phoneNumber)) { mPhoneNumbers << phoneNumber; } if (!mMembers.contains(handle)) { mMembers << handle; } } mGroupIface->addMembers(handles, phoneNumbers); } Tp::UIntList oFonoTextChannel::members() { return mMembers; } oFonoTextChannel::~oFonoTextChannel() { } Tp::BaseChannelPtr oFonoTextChannel::baseChannel() { return mBaseChannel; } void oFonoTextChannel::sendDeliveryReport(const QString &messageId, uint handle, Tp::DeliveryStatus status) { Tp::MessagePartList partList; Tp::MessagePart header; header["message-sender"] = QDBusVariant(handle); header["message-sender-id"] = QDBusVariant(mPhoneNumbers[0]); header["message-type"] = QDBusVariant(Tp::ChannelTextMessageTypeDeliveryReport); header["delivery-status"] = QDBusVariant(status); header["delivery-token"] = QDBusVariant(messageId); partList << header; mTextChannel->addReceivedMessage(partList); } void oFonoTextChannel::deliveryReportReceived(const QString &messageId, uint handle, bool success) { sendDeliveryReport(messageId, handle, success ? Tp::DeliveryStatusDelivered : Tp::DeliveryStatusPermanentlyFailed); } void oFonoTextChannel::messageAcknowledged(const QString &id) { Q_EMIT messageRead(id); } QString oFonoTextChannel::sendMessage(const Tp::MessagePartList& message, uint flags, Tp::DBusError* error) { bool success = true; Tp::MessagePart header = message.at(0); Tp::MessagePart body = message.at(1); QString objpath; if (mPhoneNumbers.size() == 1) { QString phoneNumber = mPhoneNumbers[0]; uint handle = mConnection->ensureHandle(phoneNumber); objpath = mConnection->messageManager()->sendMessage(phoneNumber, body["content"].variant().toString(), success).path(); if (objpath.isEmpty() || !success) { if (!success) { qWarning() << mConnection->messageManager()->errorName() << mConnection->messageManager()->errorMessage(); } else { error->set(TP_QT_ERROR_INVALID_ARGUMENT, mConnection->messageManager()->errorMessage()); } // create an unique id for this message that ofono failed to send objpath = QDateTime::currentDateTimeUtc().toString(Qt::ISODate) + "-" + QString::number(mMessageCounter++); mPendingDeliveryReportFailed[objpath] = handle; QTimer::singleShot(0, this, SLOT(onProcessPendingDeliveryReport())); return objpath; } OfonoMessage *msg = new OfonoMessage(objpath); if (msg->state() == "") { // message was already sent or failed too fast (this case is only reproducible with the emulator) msg->deleteLater(); mPendingDeliveryReportDelivered[objpath] = handle; QTimer::singleShot(0, this, SLOT(onProcessPendingDeliveryReport())); return objpath; } // FIXME: track pending messages only if delivery reports are enabled. We need a system config option for it. PendingMessagesManager::instance()->addPendingMessage(objpath, mPhoneNumbers[0]); QObject::connect(msg, SIGNAL(stateChanged(QString)), SLOT(onOfonoMessageStateChanged(QString))); return objpath; } else { bool someMessageSent = false; QString lastPhoneNumber; Q_FOREACH(const QString &phoneNumber, mPhoneNumbers) { uint handle = mConnection->ensureHandle(mPhoneNumbers[0]); objpath = mConnection->messageManager()->sendMessage(phoneNumber, body["content"].variant().toString(), success).path(); lastPhoneNumber = phoneNumber; // dont fail if this is a group chat as we cannot track individual messages if (objpath.isEmpty() || !success) { if (!success) { qWarning() << mConnection->messageManager()->errorName() << mConnection->messageManager()->errorMessage(); } else { error->set(TP_QT_ERROR_INVALID_ARGUMENT, mConnection->messageManager()->errorMessage()); } continue; } someMessageSent = true; } if (!someMessageSent) { // for group chat we only fail if all the messages failed to send objpath = QDateTime::currentDateTimeUtc().toString(Qt::ISODate) + "-" + QString::number(mMessageCounter++); uint handle = mConnection->ensureHandle(lastPhoneNumber); mPendingDeliveryReportFailed[objpath] = handle; QTimer::singleShot(0, this, SLOT(onProcessPendingDeliveryReport())); return objpath; } OfonoMessage *msg = new OfonoMessage(objpath); if (msg->state() == "") { // message was already sent or failed too fast (this case is only reproducible with the emulator) msg->deleteLater(); uint handle = mConnection->ensureHandle(lastPhoneNumber); mPendingDeliveryReportDelivered[objpath] = handle; QTimer::singleShot(0, this, SLOT(onProcessPendingDeliveryReport())); // return only the last one in case of group chat for history purposes return objpath; } QObject::connect(msg, SIGNAL(stateChanged(QString)), SLOT(onOfonoMessageStateChanged(QString))); return objpath; } } void oFonoTextChannel::onProcessPendingDeliveryReport() { QMapIterator iterator(mPendingDeliveryReportFailed); while(iterator.hasNext()) { iterator.next(); sendDeliveryReport(iterator.key(), iterator.value(), Tp::DeliveryStatusPermanentlyFailed); } iterator = mPendingDeliveryReportDelivered; while(iterator.hasNext()) { iterator.next(); sendDeliveryReport(iterator.key(), iterator.value(), Tp::DeliveryStatusPermanentlyFailed); } mPendingDeliveryReportFailed.clear(); mPendingDeliveryReportDelivered.clear(); } void oFonoTextChannel::onOfonoMessageStateChanged(QString status) { OfonoMessage *msg = static_cast(sender()); if(msg) { Tp::DeliveryStatus delivery_status; if (status == "sent") { delivery_status = Tp::DeliveryStatusAccepted; msg->deleteLater(); } else if(status == "failed") { delivery_status = Tp::DeliveryStatusPermanentlyFailed; PendingMessagesManager::instance()->removePendingMessage(msg->path()); msg->deleteLater(); } else if(status == "pending") { delivery_status = Tp::DeliveryStatusTemporarilyFailed; } else { delivery_status = Tp::DeliveryStatusUnknown; } sendDeliveryReport(msg->path(), mConnection->ensureHandle(mPhoneNumbers[0]), delivery_status); } } void oFonoTextChannel::messageReceived(const QString &message, uint handle, const QVariantMap &info) { Tp::MessagePartList partList; Tp::MessagePart body; body["content-type"] = QDBusVariant("text/plain"); body["content"] = QDBusVariant(message); Tp::MessagePart header; header["message-token"] = QDBusVariant(info["SentTime"].toString() +"-" + QString::number(mMessageCounter++)); header["message-received"] = QDBusVariant(QDateTime::fromString(info["SentTime"].toString(), Qt::ISODate).toTime_t()); header["message-sender"] = QDBusVariant(handle); header["message-sender-id"] = QDBusVariant(mPhoneNumbers[0]); header["message-type"] = QDBusVariant(Tp::ChannelTextMessageTypeNormal); partList << header << body; mTextChannel->addReceivedMessage(partList); } void oFonoTextChannel::mmsReceived(const QString &id, uint handle, const QVariantMap &properties) { Tp::MessagePartList message; QString subject = properties["Subject"].toString(); QString smil = properties["Smil"].toString(); Tp::MessagePart header; header["message-token"] = QDBusVariant(id); header["message-sender"] = QDBusVariant(handle); header["message-received"] = QDBusVariant(QDateTime::fromString(properties["Date"].toString(), Qt::ISODate).toTime_t()); header["message-type"] = QDBusVariant(Tp::DeliveryStatusDelivered); if (!subject.isEmpty()) { header["subject"] = QDBusVariant(subject); } message << header; AttachmentList mmsdAttachments = qdbus_cast(properties["Attachments"]); Q_FOREACH(const AttachmentStruct &attachment, mmsdAttachments) { QFile attachmentFile(attachment.filePath); if (!attachmentFile.open(QIODevice::ReadOnly)) { qWarning() << "fail to load attachment" << attachmentFile.errorString() << attachment.filePath; continue; } // FIXME check if we managed to read the total attachment file attachmentFile.seek(attachment.offset); QByteArray fileData = attachmentFile.read(attachment.length); Tp::MessagePart part; part["content-type"] = QDBusVariant(attachment.contentType); part["identifier"] = QDBusVariant(attachment.id); part["content"] = QDBusVariant(fileData); part["size"] = QDBusVariant(attachment.length); message << part; } if (!smil.isEmpty()) { Tp::MessagePart part; part["content-type"] = QDBusVariant(QString("application/smil")); part["identifier"] = QDBusVariant(QString("smil")); part["content"] = QDBusVariant(smil); part["size"] = QDBusVariant(smil.size()); message << part; } mTextChannel->addReceivedMessage(message); } telepathy-ofono-0.2+14.04.20140407/qpulseaudioengine.cpp0000644000015301777760000002764412320626651023334 0ustar pbusernogroup00000000000000/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file was taken from qt5 and modified by ** David Henningsson for usage in ** telepathy-ofono. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ****************************************************************************/ #include #include "qpulseaudioengine.h" #include #include QT_BEGIN_NAMESPACE static void contextStateCallbackInit(pa_context *context, void *userdata) { Q_UNUSED(context); #ifdef DEBUG_PULSE qDebug() << QPulseAudioInternal::stateToQString(pa_context_get_state(context)); #endif QPulseAudioEngine *pulseEngine = reinterpret_cast(userdata); pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); } static void contextStateCallback(pa_context *context, void *userdata) { Q_UNUSED(userdata); Q_UNUSED(context); #ifdef DEBUG_PULSE pa_context_state_t state = pa_context_get_state(context); qDebug() << QPulseAudioInternal::stateToQString(state); #endif } static void success_cb(pa_context *context, int success, void *userdata) { QPulseAudioEngine *pulseEngine = reinterpret_cast(userdata); pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); } static void subscribeCallback(pa_context *context, pa_subscription_event_type_t t, uint32_t idx, void *userdata) { /* We're interested in plug/unplug stuff only, i e, card changes */ if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) != PA_SUBSCRIPTION_EVENT_CARD) return; if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) != PA_SUBSCRIPTION_EVENT_CHANGE) return; /* Handle it later, and in the right thread */ QMetaObject::invokeMethod((QPulseAudioEngine *) userdata, "plugUnplugSlot", Qt::QueuedConnection); } Q_GLOBAL_STATIC(QPulseAudioEngine, pulseEngine); QPulseAudioEngine::QPulseAudioEngine(QObject *parent) : QObject(parent) , m_mainLoopApi(0) , m_context(0) , m_incall(false) , m_speakermode(false) , m_micmute(false) { bool keepGoing = true; bool ok = true; m_mainLoop = pa_threaded_mainloop_new(); if (m_mainLoop == 0) { qWarning("Unable to create pulseaudio mainloop"); return; } if (pa_threaded_mainloop_start(m_mainLoop) != 0) { qWarning("Unable to start pulseaudio mainloop"); pa_threaded_mainloop_free(m_mainLoop); return; } m_mainLoopApi = pa_threaded_mainloop_get_api(m_mainLoop); pa_threaded_mainloop_lock(m_mainLoop); m_context = pa_context_new(m_mainLoopApi, QString(QLatin1String("QtmPulseContext:%1")).arg(::getpid()).toLatin1().constData()); pa_context_set_state_callback(m_context, contextStateCallbackInit, this); if (!m_context) { qWarning("Unable to create new pulseaudio context"); pa_threaded_mainloop_free(m_mainLoop); return; } if (pa_context_connect(m_context, NULL, (pa_context_flags_t)0, NULL) < 0) { qWarning("Unable to create a connection to the pulseaudio context"); pa_context_unref(m_context); pa_threaded_mainloop_free(m_mainLoop); return; } pa_threaded_mainloop_wait(m_mainLoop); while (keepGoing) { switch (pa_context_get_state(m_context)) { case PA_CONTEXT_CONNECTING: case PA_CONTEXT_AUTHORIZING: case PA_CONTEXT_SETTING_NAME: break; case PA_CONTEXT_READY: #ifdef DEBUG_PULSE qDebug("Connection established."); #endif keepGoing = false; break; case PA_CONTEXT_TERMINATED: qCritical("Context terminated."); keepGoing = false; ok = false; break; case PA_CONTEXT_FAILED: default: qCritical() << QString("Connection failure: %1").arg(pa_strerror(pa_context_errno(m_context))); keepGoing = false; ok = false; } if (keepGoing) { pa_threaded_mainloop_wait(m_mainLoop); } } if (ok) { pa_context_set_state_callback(m_context, contextStateCallback, this); pa_context_set_subscribe_callback(m_context, subscribeCallback, this); pa_context_subscribe(m_context, PA_SUBSCRIPTION_MASK_CARD, NULL, this); } else { if (m_context) { pa_context_unref(m_context); m_context = 0; } } pa_threaded_mainloop_unlock(m_mainLoop); } QPulseAudioEngine::~QPulseAudioEngine() { if (m_context) { pa_threaded_mainloop_lock(m_mainLoop); pa_context_disconnect(m_context); pa_threaded_mainloop_unlock(m_mainLoop); m_context = 0; } if (m_mainLoop) { pa_threaded_mainloop_stop(m_mainLoop); pa_threaded_mainloop_free(m_mainLoop); m_mainLoop = 0; } } QPulseAudioEngine *QPulseAudioEngine::instance() { return pulseEngine(); } void QPulseAudioEngine::sinkInfoCallback(const pa_sink_info *info) { pa_sink_port_info *earpiece = NULL, *speaker = NULL, *headphones = NULL; pa_sink_port_info *highest = NULL, *preferred = NULL; for (int i = 0; i < info->n_ports; i++) { if (!highest || info->ports[i]->priority > highest->priority) { if (info->ports[i]->available != PA_PORT_AVAILABLE_NO) highest = info->ports[i]; } if (!strcmp(info->ports[i]->name, "[Out] Earpiece")) earpiece = info->ports[i]; if (!strcmp(info->ports[i]->name, "[Out] Speaker")) speaker = info->ports[i]; if (!strcmp(info->ports[i]->name, "[Out] Headphones") && info->ports[i]->available != PA_PORT_AVAILABLE_NO) headphones = info->ports[i]; } if (!earpiece) return; /* Not the right sink */ /* TODO: When on ringtone and headphones are plugged in, people want output through *both* headphones and speaker, but when on call with speaker mode, people want *just* speaker, not including headphones. */ if (m_speakermode) preferred = speaker; else if (m_incall) preferred = headphones ? headphones : earpiece; if (!preferred) preferred = highest; if (preferred && preferred != info->active_port) { m_nametoset = info->name; m_valuetoset = preferred->name; } } void QPulseAudioEngine::cardInfoCallback(const pa_card_info *info) { pa_card_profile_info *voice_call = NULL, *highest = NULL; for (int i = 0; i < info->n_profiles; i++) { if (!highest || info->profiles[i].priority > highest->priority) highest = &info->profiles[i]; if (!strcmp(info->profiles[i].name, "Voice Call")) voice_call = &info->profiles[i]; } if (!voice_call) return; /* Not the right card */ if (m_incall && (voice_call != info->active_profile)) { m_nametoset = info->name; m_valuetoset = voice_call->name; } else if (!m_incall && (voice_call == info->active_profile)) { m_nametoset = info->name; m_valuetoset = highest->name; } } void QPulseAudioEngine::sourceInfoCallback(const pa_source_info *info) { pa_source_port_info *handset = NULL; if (info->monitor_of_sink != PA_INVALID_INDEX) return; /* Not the right source */ for (int i = 0; i < info->n_ports; i++) { if (!strcmp(info->ports[i]->name, "[In] Handset")) handset = info->ports[i]; } if (!handset) return; /* Not the right source */ if (!!info->mute != !!m_micmute) { m_nametoset = info->name; } } static void cardinfo_cb(pa_context *context, const pa_card_info *info, int isLast, void *userdata) { QPulseAudioEngine *pulseEngine = static_cast(userdata); /* qDebug("cardinfo_cb: pulseengine = %p, info = %p, isLast = %d", pulseEngine, info, isLast); */ if (isLast != 0 || !pulseEngine || !info) { pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); return; } pulseEngine->cardInfoCallback(info); } static void sinkinfo_cb(pa_context *context, const pa_sink_info *info, int isLast, void *userdata) { QPulseAudioEngine *pulseEngine = static_cast(userdata); if (isLast != 0 || !pulseEngine || !info) { pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); return; } pulseEngine->sinkInfoCallback(info); } static void sourceinfo_cb(pa_context *context, const pa_source_info *info, int isLast, void *userdata) { QPulseAudioEngine *pulseEngine = static_cast(userdata); if (isLast != 0 || !pulseEngine || !info) { pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); return; } pulseEngine->sourceInfoCallback(info); } bool QPulseAudioEngine::handleOperation(pa_operation *operation, const char *func_name) { if (!operation) { qDebug("'%s' failed (lost PulseAudio connection?)", func_name); pa_threaded_mainloop_unlock(m_mainLoop); return false; } while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) pa_threaded_mainloop_wait(m_mainLoop); pa_operation_unref(operation); return true; } void QPulseAudioEngine::setCallMode(bool inCall, bool speakerMode) { pa_operation *operation; m_incall = inCall; m_speakermode = speakerMode; pa_threaded_mainloop_lock(m_mainLoop); m_nametoset = ""; pa_operation *o = pa_context_get_card_info_list(m_context, cardinfo_cb, this); if (!handleOperation(o, "pa_context_get_card_info_list")) return; if (m_nametoset != "") { qDebug("Setting PulseAudio card '%s' profile '%s'", m_nametoset.c_str(), m_valuetoset.c_str()); o = pa_context_set_card_profile_by_name(m_context, m_nametoset.c_str(), m_valuetoset.c_str(), success_cb, this); if (!handleOperation(o, "pa_context_set_card_profile_by_name")) return; } m_nametoset = ""; o = pa_context_get_sink_info_list(m_context, sinkinfo_cb, this); if (!handleOperation(o, "pa_context_get_sink_info_list")) return; if (m_nametoset != "") { qDebug("Setting PulseAudio sink '%s' port '%s'", m_nametoset.c_str(), m_valuetoset.c_str()); o = pa_context_set_sink_port_by_name(m_context, m_nametoset.c_str(), m_valuetoset.c_str(), success_cb, this); if (!handleOperation(o, "pa_context_set_sink_port_by_name")) return; } pa_threaded_mainloop_unlock(m_mainLoop); if (inCall) setMicMute(m_micmute); } void QPulseAudioEngine::setMicMute(bool muted) { m_nametoset = ""; m_micmute = muted; if (!m_incall) return; pa_threaded_mainloop_lock(m_mainLoop); pa_operation *o = pa_context_get_source_info_list(m_context, sourceinfo_cb, this); if (!handleOperation(o, "pa_context_get_source_info_list")) return; if (m_nametoset != "") { int m = m_micmute ? 1 : 0; qDebug("Setting PulseAudio source '%s' muted '%d'", m_nametoset.c_str(), m); o = pa_context_set_source_mute_by_name(m_context, m_nametoset.c_str(), m, success_cb, this); if (!handleOperation(o, "pa_context_set_source_mute_by_name")) return; } pa_threaded_mainloop_unlock(m_mainLoop); } void QPulseAudioEngine::plugUnplugSlot() { qDebug("Notified about card event from PulseAudio"); if (m_incall) setCallMode(m_incall, m_speakermode); } QT_END_NAMESPACE telepathy-ofono-0.2+14.04.20140407/speakeriface.h0000644000015301777760000000746612320626651021702 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef OFONOSPEAKERIFACE_H #define OFONOSPEAKERIFACE_H // telepathy-qt #include #include #include #include #include #define TP_QT_IFACE_CHANNEL_SPEAKER "com.canonical.Telephony.Speaker" class BaseChannelSpeakerInterface; typedef Tp::SharedPtr BaseChannelSpeakerInterfacePtr; class TP_QT_EXPORT BaseChannelSpeakerInterface : public Tp::AbstractChannelInterface { Q_OBJECT Q_DISABLE_COPY(BaseChannelSpeakerInterface) public: static BaseChannelSpeakerInterfacePtr create() { return BaseChannelSpeakerInterfacePtr(new BaseChannelSpeakerInterface()); } template static Tp::SharedPtr create() { return Tp::SharedPtr( new BaseChannelSpeakerInterfaceSubclass()); } QVariantMap immutableProperties() const; virtual ~BaseChannelSpeakerInterface(); bool speakerMode() const; typedef Tp::Callback2 turnOnSpeakerCallback; void setTurnOnSpeakerCallback(const turnOnSpeakerCallback &cb); public Q_SLOTS: void setSpeakerMode(bool active); protected: BaseChannelSpeakerInterface(); private: void createAdaptor(); class Adaptee; friend class Adaptee; struct Private; friend struct Private; Private *mPriv; }; class TP_QT_EXPORT ChannelInterfaceSpeakerAdaptor : public Tp::AbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", TP_QT_IFACE_CHANNEL_SPEAKER) Q_CLASSINFO("D-Bus Introspection", "" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "") Q_PROPERTY(bool SpeakerMode READ SpeakerMode) public: ChannelInterfaceSpeakerAdaptor(const QDBusConnection& dbusConnection, QObject* adaptee, QObject* parent); virtual ~ChannelInterfaceSpeakerAdaptor(); typedef Tp::MethodInvocationContextPtr< bool > turnOnSpeakerContextPtr; public: // PROPERTIES bool SpeakerMode() const; public Q_SLOTS: // METHODS void turnOnSpeaker(bool active, const QDBusMessage& dbusMessage); Q_SIGNALS: // SIGNALS void SpeakerChanged(bool active); }; class TP_QT_NO_EXPORT BaseChannelSpeakerInterface::Adaptee : public QObject { Q_OBJECT Q_PROPERTY(bool speakerMode READ speakerMode) public: Adaptee(BaseChannelSpeakerInterface *interface); ~Adaptee(); bool speakerMode() const { return mInterface->speakerMode(); } private Q_SLOTS: void turnOnSpeaker(bool active, const ChannelInterfaceSpeakerAdaptor::turnOnSpeakerContextPtr &context); Q_SIGNALS: void speakerChanged(bool active); public: BaseChannelSpeakerInterface *mInterface; }; #endif telepathy-ofono-0.2+14.04.20140407/voicemailiface.h0000644000015301777760000001164212320626651022207 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef OFONOVOICEMAILIFACE_H #define OFONOVOICEMAILIFACE_H // telepathy-qt #include #include #include #include #include class BaseConnectionVoicemailInterface; typedef Tp::SharedPtr BaseConnectionVoicemailInterfacePtr; #define TP_QT_IFACE_CONNECTION_VOICEMAIL "com.canonical.Telephony.Voicemail" class TP_QT_EXPORT BaseConnectionVoicemailInterface : public Tp::AbstractConnectionInterface { Q_OBJECT Q_DISABLE_COPY(BaseConnectionVoicemailInterface) public: static BaseConnectionVoicemailInterfacePtr create() { return BaseConnectionVoicemailInterfacePtr(new BaseConnectionVoicemailInterface()); } template static Tp::SharedPtr create() { return Tp::SharedPtr( new BaseConnectionVoicemailInterfaceSubclass()); } QVariantMap immutableProperties() const; virtual ~BaseConnectionVoicemailInterface(); typedef Tp::Callback1 VoicemailCountCallback; void setVoicemailCountCallback(const VoicemailCountCallback &cb); typedef Tp::Callback1 VoicemailIndicatorCallback; void setVoicemailIndicatorCallback(const VoicemailIndicatorCallback &cb); typedef Tp::Callback1 VoicemailNumberCallback; void setVoicemailNumberCallback(const VoicemailNumberCallback &cb); public Q_SLOTS: void setVoicemailCount(int count); void setVoicemailIndicator(bool active); protected: BaseConnectionVoicemailInterface(); private: void createAdaptor(); class Adaptee; friend class Adaptee; struct Private; friend struct Private; Private *mPriv; }; class TP_QT_EXPORT ConnectionInterfaceVoicemailAdaptor : public Tp::AbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", TP_QT_IFACE_CONNECTION_VOICEMAIL) Q_CLASSINFO("D-Bus Introspection", "" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "") public: ConnectionInterfaceVoicemailAdaptor(const QDBusConnection& dbusConnection, QObject* adaptee, QObject* parent); virtual ~ConnectionInterfaceVoicemailAdaptor(); typedef Tp::MethodInvocationContextPtr< bool > VoicemailIndicatorContextPtr; typedef Tp::MethodInvocationContextPtr< QString > VoicemailNumberContextPtr; typedef Tp::MethodInvocationContextPtr< uint > VoicemailCountContextPtr; public Q_SLOTS: // METHODS bool VoicemailIndicator(const QDBusMessage& dbusMessage); QString VoicemailNumber(const QDBusMessage& dbusMessage); uint VoicemailCount(const QDBusMessage& dbusMessage); Q_SIGNALS: // SIGNALS void VoicemailCountChanged(uint count); void VoicemailIndicatorChanged(bool active); }; class TP_QT_NO_EXPORT BaseConnectionVoicemailInterface::Adaptee : public QObject { Q_OBJECT public: Adaptee(BaseConnectionVoicemailInterface *interface); ~Adaptee(); private Q_SLOTS: void voicemailIndicator(const ConnectionInterfaceVoicemailAdaptor::VoicemailIndicatorContextPtr &context); void voicemailNumber(const ConnectionInterfaceVoicemailAdaptor::VoicemailNumberContextPtr &context); void voicemailCount(const ConnectionInterfaceVoicemailAdaptor::VoicemailCountContextPtr &context); Q_SIGNALS: void voicemailCountChanged(uint count); void voicemailIndicatorChanged(bool active); public: BaseConnectionVoicemailInterface *mInterface; }; #endif telepathy-ofono-0.2+14.04.20140407/tests/0000755000015301777760000000000012320627204020227 5ustar pbusernogroup00000000000000telepathy-ofono-0.2+14.04.20140407/tests/MessagesTest.cpp0000644000015301777760000001552212320626651023354 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include #include #include #include #include #include #include #include #include "telepathyhelper.h" #include "ofonomockcontroller.h" #include "handler.h" #include "approvertext.h" Q_DECLARE_METATYPE(Tp::TextChannelPtr); Q_DECLARE_METATYPE(QList); class MessagesTest : public QObject { Q_OBJECT Q_SIGNALS: void contactsReceived(QList contacts); private Q_SLOTS: void initTestCase(); void testMessageReceived(); void testMessageSend(); void testMessageSendGroupChat(); // helper slots void onPendingContactsFinished(Tp::PendingOperation*); private: Approver *mApprover; Handler *mHandler; }; void MessagesTest::initTestCase() { qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType >(); TelepathyHelper::instance(); QSignalSpy spy(TelepathyHelper::instance(), SIGNAL(accountReady())); QTRY_COMPARE(spy.count(), 1); OfonoMockController::instance()->NetworkRegistrationSetStatus("registered"); // the account should be connected QTRY_VERIFY(TelepathyHelper::instance()->connected()); mHandler = new Handler(this); TelepathyHelper::instance()->registerClient(mHandler, "TpOfonoTestHandler"); QTRY_VERIFY(mHandler->isRegistered()); // register the approver mApprover = new Approver(this); TelepathyHelper::instance()->registerClient(mApprover, "TpOfonoTestApprover"); // Tp-qt does not set registered status to approvers QTRY_VERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(TELEPHONY_SERVICE_APPROVER)); // we need to wait in order to give telepathy time to notify about the approver and handler QTest::qWait(10000); } void MessagesTest::testMessageReceived() { QSignalSpy spy(mHandler, SIGNAL(textChannelAvailable(Tp::TextChannelPtr))); OfonoMockController::instance()->MessageManagerSendMessage("123", "text"); QTRY_COMPARE(spy.count(), 1); Tp::TextChannelPtr channel = spy.first().first().value(); QVERIFY(channel); QCOMPARE(channel->messageQueue().count(), 1); Tp::ReceivedMessage message = channel->messageQueue().first(); QCOMPARE(message.sender()->id(), QString("123")); QCOMPARE(message.text(), QString("text")); } void MessagesTest::testMessageSend() { // Request the contact to start chatting to Tp::AccountPtr account = TelepathyHelper::instance()->account(); QSignalSpy spy(this, SIGNAL(contactsReceived(QList))); connect(account->connection()->contactManager()->contactsForIdentifiers(QStringList() << "321"), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onPendingContactsFinished(Tp::PendingOperation*))); QTRY_COMPARE(spy.count(), 1); QList contacts = spy.first().first().value >(); QCOMPARE(contacts.count(), 1); QCOMPARE(contacts.first()->id(), QString("321")); QSignalSpy spyTextChannel(mHandler, SIGNAL(textChannelAvailable(Tp::TextChannelPtr))); Q_FOREACH(Tp::ContactPtr contact, contacts) { account->ensureTextChat(contact, QDateTime::currentDateTime(), TP_QT_IFACE_CLIENT + ".TpOfonoTestHandler"); } QTRY_COMPARE(spyTextChannel.count(), 1); Tp::TextChannelPtr channel = spyTextChannel.first().first().value(); QVERIFY(channel); QSignalSpy spyOfonoMessageAdded(OfonoMockController::instance(), SIGNAL(MessageAdded(QDBusObjectPath, QVariantMap))); Tp::PendingSendMessage *message = channel->send("text"); QTRY_COMPARE(spyOfonoMessageAdded.count(), 1); QDBusObjectPath path = spyOfonoMessageAdded.first().first().value(); OfonoMockController::instance()->MessageMarkSent(path.path()); QTRY_COMPARE(channel->messageQueue().count(), 1); QVERIFY(channel->messageQueue()[0].isDeliveryReport()); QCOMPARE(channel->messageQueue()[0].deliveryDetails().status(), Tp::DeliveryStatusAccepted); OfonoMockController::instance()->MessageManagerStatusReport(path.path(), true); QTRY_COMPARE(channel->messageQueue().count(), 2); QVERIFY(channel->messageQueue()[1].isDeliveryReport()); QCOMPARE(channel->messageQueue()[1].deliveryDetails().status(), Tp::DeliveryStatusDelivered); } void MessagesTest::testMessageSendGroupChat() { // Request the contact to start chatting to Tp::AccountPtr account = TelepathyHelper::instance()->account(); QSignalSpy spy(this, SIGNAL(contactsReceived(QList))); connect(account->connection()->contactManager()->contactsForIdentifiers(QStringList() << "321" << "123"), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onPendingContactsFinished(Tp::PendingOperation*))); QTRY_COMPARE(spy.count(), 1); QList contacts = spy.first().first().value >(); QCOMPARE(contacts.count(), 2); QCOMPARE(contacts[0]->id(), QString("321")); QCOMPARE(contacts[1]->id(), QString("123")); QSignalSpy spyTextChannel(mHandler, SIGNAL(textChannelAvailable(Tp::TextChannelPtr))); account->createConferenceTextChat(QList(), contacts, QDateTime::currentDateTime(), TP_QT_IFACE_CLIENT + ".TpOfonoTestHandler"); QTRY_COMPARE(spyTextChannel.count(), 1); Tp::TextChannelPtr channel = spyTextChannel.first().first().value(); QVERIFY(channel); QSignalSpy spyOfonoMessageAdded(OfonoMockController::instance(), SIGNAL(MessageAdded(QDBusObjectPath, QVariantMap))); Tp::PendingSendMessage *message = channel->send("text"); QTRY_COMPARE(spyOfonoMessageAdded.count(), 2); } void MessagesTest::onPendingContactsFinished(Tp::PendingOperation *op) { Tp::PendingContacts *pc = qobject_cast(op); if (!pc) { return; } Q_EMIT contactsReceived(pc->contacts()); } QTEST_MAIN(MessagesTest) #include "MessagesTest.moc" telepathy-ofono-0.2+14.04.20140407/tests/approvertext.h0000644000015301777760000000307012320626651023150 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef APPROVER_H #define APPROVER_H #include #include #include #include #define TELEPHONY_SERVICE_HANDLER TP_QT_IFACE_CLIENT + ".TpOfonoTestHandler" #define TELEPHONY_SERVICE_APPROVER TP_QT_IFACE_CLIENT + ".TpOfonoTestApprover" class Approver : public QObject, public Tp::AbstractClientApprover { Q_OBJECT public: Approver(QObject *parent = 0); ~Approver(); Tp::ChannelClassSpecList channelFilters() const; void addDispatchOperation(const Tp::MethodInvocationContextPtr<> &context, const Tp::ChannelDispatchOperationPtr &dispatchOperation); private Q_SLOTS: void processChannels(); private: QList mDispatchOps; }; #endif // APPROVER_H telepathy-ofono-0.2+14.04.20140407/tests/ConnectionTest.cpp0000644000015301777760000001013612320626651023700 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include #include #include #include "telepathyhelper.h" #include "ofonomockcontroller.h" class ConnectionTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void testConnected(); void testModemStatus(); }; void ConnectionTest::initTestCase() { TelepathyHelper::instance(); QSignalSpy spy(TelepathyHelper::instance(), SIGNAL(accountReady())); QTRY_COMPARE(spy.count(), 1); OfonoMockController::instance()->NetworkRegistrationSetStatus("registered"); qRegisterMetaType(); QTest::qWait(3000); } void ConnectionTest::testConnected() { // the account should be connected automatically QTRY_VERIFY(TelepathyHelper::instance()->connected()); } void ConnectionTest::testModemStatus() { Tp::ContactPtr selfContact = TelepathyHelper::instance()->account()->connection()->selfContact(); QSignalSpy signalSpy(selfContact.data(), SIGNAL(presenceChanged(Tp::Presence))); // set the status as unregistered OfonoMockController::instance()->NetworkRegistrationSetStatus("unregistered"); QTRY_COMPARE(signalSpy.count(), 1); Tp::Presence presence = signalSpy.first().first().value(); QCOMPARE(presence.type(), Tp::ConnectionPresenceTypeOffline); signalSpy.clear(); // now set the modem as registered to the network again to see if it works OfonoMockController::instance()->NetworkRegistrationSetStatus("registered"); QTRY_COMPARE(signalSpy.count(), 1); presence = signalSpy.first().first().value(); QCOMPARE(presence.type(), Tp::ConnectionPresenceTypeAvailable); signalSpy.clear(); // searching should be reported as offline OfonoMockController::instance()->NetworkRegistrationSetStatus("searching"); QTRY_COMPARE(signalSpy.count(), 1); presence = signalSpy.first().first().value(); QCOMPARE(presence.type(), Tp::ConnectionPresenceTypeOffline); signalSpy.clear(); // denied should be reported as offline (set registered first to force the signal to be emitted) OfonoMockController::instance()->NetworkRegistrationSetStatus("registered"); QTRY_COMPARE(signalSpy.count(), 1); signalSpy.clear(); OfonoMockController::instance()->NetworkRegistrationSetStatus("denied"); QTRY_COMPARE(signalSpy.count(), 1); presence = signalSpy.first().first().value(); QCOMPARE(presence.type(), Tp::ConnectionPresenceTypeOffline); signalSpy.clear(); // unknown should be reported as offline (set registered first to force the signal to be emitted) OfonoMockController::instance()->NetworkRegistrationSetStatus("registered"); QTRY_COMPARE(signalSpy.count(), 1); signalSpy.clear(); OfonoMockController::instance()->NetworkRegistrationSetStatus("unknown"); QTRY_COMPARE(signalSpy.count(), 1); presence = signalSpy.first().first().value(); QCOMPARE(presence.type(), Tp::ConnectionPresenceTypeOffline); signalSpy.clear(); // roaming should be reported as available OfonoMockController::instance()->NetworkRegistrationSetStatus("roaming"); QTRY_COMPARE(signalSpy.count(), 1); presence = signalSpy.first().first().value(); QCOMPARE(presence.type(), Tp::ConnectionPresenceTypeAvailable); } QTEST_MAIN(ConnectionTest) #include "ConnectionTest.moc" telepathy-ofono-0.2+14.04.20140407/tests/mock/0000755000015301777760000000000012320627204021160 5ustar pbusernogroup00000000000000telepathy-ofono-0.2+14.04.20140407/tests/mock/callvolumeprivate.cpp0000644000015301777760000000302312320626651025425 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include "callvolumeprivateadaptor.h" QMap callVolumeData; CallVolumePrivate::CallVolumePrivate(QObject *parent) : QObject(parent) { QDBusConnection::sessionBus().registerObject(OFONO_MOCK_CALL_VOLUME_OBJECT, this); QDBusConnection::sessionBus().registerService("org.ofono"); SetProperty("Muted", QDBusVariant(QVariant(false))); new CallVolumeAdaptor(this); } CallVolumePrivate::~CallVolumePrivate() { } QVariantMap CallVolumePrivate::GetProperties() { return mProperties; } void CallVolumePrivate::SetProperty(const QString &name, const QDBusVariant& value) { qDebug() << "CallVolumePrivate::SetProperty" << name << value.variant(); mProperties[name] = value.variant(); Q_EMIT PropertyChanged(name, value); } telepathy-ofono-0.2+14.04.20140407/tests/mock/CallVolumePrivate.xml0000644000015301777760000000125512320626651025310 0ustar pbusernogroup00000000000000 telepathy-ofono-0.2+14.04.20140407/tests/mock/MessagePrivate.xml0000644000015301777760000000146312320626651024632 0ustar pbusernogroup00000000000000 telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonovoicecall.cpp0000644000015301777760000001651712320626651024705 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include #include #include "ofonointerface.h" #include "ofonovoicecall.h" #include "voicecallprivate.h" #define VOICECALL_TIMEOUT 30000 OfonoVoiceCall::OfonoVoiceCall(const QString& callId, QObject *parent) : QObject(parent) { m_if = new OfonoInterface(callId, "org.ofono.VoiceCall", OfonoGetAllOnStartup, this); if (!voiceCallData.keys().contains(callId)) { m_if->setPath(callId); voiceCallData[callId] = new VoiceCallPrivate(callId); } connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), this, SLOT(propertyChanged(const QString&, const QVariant&))); QDBusConnection::sessionBus().connect("org.ofono",path(),m_if->ifname(), "DisconnectReason", this, SIGNAL(disconnectReason(const QString&))); } OfonoVoiceCall::OfonoVoiceCall(const OfonoVoiceCall& call) : QObject(call.parent()) { m_if = new OfonoInterface(call.path(), "org.ofono.VoiceCall", OfonoGetAllOnStartup, this); if (!voiceCallData.keys().contains(call.path())) { m_if->setPath(call.path()); voiceCallData[call.path()] = new VoiceCallPrivate(call.path()); } connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), this, SLOT(propertyChanged(const QString&, const QVariant&))); QDBusConnection::sessionBus().connect("org.ofono",path(),m_if->ifname(), "DisconnectReason", this, SIGNAL(disconnectReason(const QString&))); } bool OfonoVoiceCall::operator==(const OfonoVoiceCall &call) { return path() == call.path(); } OfonoVoiceCall::~OfonoVoiceCall() { } void OfonoVoiceCall::answer() { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "Answer"); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(answerResp()), SLOT(answerErr(const QDBusError&)), VOICECALL_TIMEOUT); } void OfonoVoiceCall::hangup() { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "Hangup"); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(hangupResp()), SLOT(hangupErr(const QDBusError&)), VOICECALL_TIMEOUT); } void OfonoVoiceCall::deflect(const QString &number) { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "Deflect"); QListarg; arg.append(QVariant(number)); request.setArguments(arg); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(deflectResp()), SLOT(deflectErr(const QDBusError&)), VOICECALL_TIMEOUT); } void OfonoVoiceCall::answerResp() { Q_EMIT answerComplete(true); } void OfonoVoiceCall::answerErr(const QDBusError &error) { m_if->setError(error.name(), error.message()); Q_EMIT answerComplete(false); } void OfonoVoiceCall::hangupResp() { Q_EMIT hangupComplete(true); } void OfonoVoiceCall::hangupErr(const QDBusError &error) { m_if->setError(error.name(), error.message()); Q_EMIT hangupComplete(false); } void OfonoVoiceCall::deflectResp() { Q_EMIT deflectComplete(true); } void OfonoVoiceCall::deflectErr(const QDBusError &error) { m_if->setError(error.name(), error.message()); Q_EMIT deflectComplete(false); } QString OfonoVoiceCall::incomingLine() const { return m_if->properties()["IncomingLine"].value(); } QString OfonoVoiceCall::lineIdentification() const { return m_if->properties()["LineIdentification"].value(); } QString OfonoVoiceCall::name() const { return m_if->properties()["Name"].value(); } QString OfonoVoiceCall::state() const { return m_if->properties()["State"].value(); } QString OfonoVoiceCall::startTime() const { return m_if->properties()["StartTime"].value(); } QString OfonoVoiceCall::information() const { return m_if->properties()["Information"].value(); } bool OfonoVoiceCall::multiparty() const { return m_if->properties()["Multiparty"].value(); } bool OfonoVoiceCall::emergency() const { return m_if->properties()["Emergency"].value(); } quint8 OfonoVoiceCall::icon() const { return m_if->properties()["Icon"].value(); } bool OfonoVoiceCall::remoteHeld() const { return m_if->properties()["RemoteHeld"].value(); } bool OfonoVoiceCall::remoteMultiparty() const { return m_if->properties()["RemoteMultiparty"].value(); } void OfonoVoiceCall::propertyChanged(const QString &property, const QVariant &value) { if (property == "LineIdentification") { Q_EMIT lineIdentificationChanged(value.value()); } else if (property == "Name") { Q_EMIT nameChanged(value.value()); } else if (property == "State") { Q_EMIT stateChanged(value.value()); } else if (property == "Information") { Q_EMIT informationChanged(value.value()); } else if (property == "IncomingLine") { Q_EMIT incomingLineChanged(value.value()); } else if (property == "Multiparty") { Q_EMIT multipartyChanged(value.value()); } else if (property == "Emergency") { Q_EMIT emergencyChanged(value.value()); } else if (property == "StartTime") { Q_EMIT startTimeChanged(value.value()); } else if (property == "Icon") { Q_EMIT iconChanged(value.value()); } else if (property == "RemoteHeld") { Q_EMIT remoteHeldChanged(value.value()); } else if (property == "RemoteMultiparty") { Q_EMIT remoteMultipartyChanged(value.value()); } } QString OfonoVoiceCall::path() const { return m_if->path(); } QString OfonoVoiceCall::errorName() const { return m_if->errorName(); } QString OfonoVoiceCall::errorMessage() const { return m_if->errorMessage(); } telepathy-ofono-0.2+14.04.20140407/tests/mock/messagemanagerprivate.h0000644000015301777760000000400612320626651025710 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef MESSAGEMANAGERPRIVATE_H #define MESSAGEMANAGERPRIVATE_H #include #include #include "mock_common.h" class OfonoMessage; class MessageManagerPrivate : public QObject, protected QDBusContext { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.ofono.MessageManager") public: MessageManagerPrivate(QObject *parent = 0); ~MessageManagerPrivate(); Q_SIGNALS: void MessageRemoved(const QDBusObjectPath &obj); void PropertyChanged(const QString &name, const QDBusVariant &value); void MessageAdded(const QDBusObjectPath &obj, const QVariantMap &value); void IncomingMessage(const QString &text, const QVariantMap &info); void StatusReport(const QString &message, const QVariantMap &info); private Q_SLOTS: void onMessageDestroyed(); public Q_SLOTS: QVariantMap GetProperties(); void SetProperty(const QString &name, const QDBusVariant &value); void MockSendMessage(const QString &from, const QString &text); QDBusObjectPath SendMessage(const QString &to, const QString &text); void MockStatusReport(const QString &message, bool success); private: QVariantMap mProperties; QMap mMessages; int messageCount; }; extern QMap messageManagerData; #endif telepathy-ofono-0.2+14.04.20140407/tests/mock/voicecallmanagerprivate.cpp0000644000015301777760000001535212320626651026566 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include "voicecallmanagerprivateadaptor.h" #include "ofonovoicecall.h" #include "voicecallprivate.h" QMap voiceCallManagerData; VoiceCallManagerPrivate::VoiceCallManagerPrivate(QObject *parent) : voiceCallCount(0), failNextDtmf(false), QObject(parent) { qDBusRegisterMetaType >(); QDBusConnection::sessionBus().registerObject(OFONO_MOCK_VOICECALL_MANAGER_OBJECT, this); QDBusConnection::sessionBus().registerService("org.ofono"); SetProperty("EmergencyNumbers", QDBusVariant(QVariant(QStringList()))); new VoiceCallManagerAdaptor(this); } VoiceCallManagerPrivate::~VoiceCallManagerPrivate() { } QMap VoiceCallManagerPrivate::GetCalls() { QMap props; Q_FOREACH(const QString &key, mVoiceCalls.keys()) { VoiceCallPrivate *callPrivate = voiceCallData[key]; if (callPrivate) { props[QDBusObjectPath(key)] = callPrivate->GetProperties(); } } return props; } QVariantMap VoiceCallManagerPrivate::GetProperties() { return mProperties; } void VoiceCallManagerPrivate::SetProperty(const QString &name, const QDBusVariant& value) { qDebug() << "VoiceCallManagerPrivate::SetProperty" << name << value.variant(); if (mProperties[name] != value.variant()) { mProperties[name] = value.variant(); Q_EMIT PropertyChanged(name, value); } } void VoiceCallManagerPrivate::MockFailNextDtmf() { failNextDtmf = true; } QDBusObjectPath VoiceCallManagerPrivate::MockIncomingCall(const QString &from) { qDebug() << "VoiceCallManagerPrivate::MockIncomingCall" << from; QString newPath("/OfonoVoiceCall/OfonoVoiceCall"+QString::number(++voiceCallCount)); QDBusObjectPath newPathObj(newPath); QVariantMap callProperties; callProperties["State"] = "incoming"; callProperties["LineIdentification"] = from; callProperties["Name"] = ""; callProperties["Multiparty"] = false; callProperties["RemoteHeld"] = false; callProperties["RemoteMultiparty"] = false; callProperties["Emergency"] = false; initialCallProperties[newPath] = callProperties; mVoiceCalls[newPath] = new OfonoVoiceCall(newPath); connect(voiceCallData[newPath], SIGNAL(destroyed()), this, SLOT(onVoiceCallDestroyed())); Q_EMIT CallAdded(newPathObj, callProperties); return newPathObj; } void VoiceCallManagerPrivate::SwapCalls() { Q_FOREACH(const QString &objPath, mVoiceCalls.keys()) { QDBusInterface iface("org.ofono", objPath, "org.ofono.VoiceCall"); if (mVoiceCalls[objPath]->state() == "active") { iface.call("SetProperty", "State", QVariant::fromValue(QDBusVariant("held")));; } else if (mVoiceCalls[objPath]->state() == "held") { iface.call("SetProperty", "State", QVariant::fromValue(QDBusVariant("active")));; } } } QList VoiceCallManagerPrivate::CreateMultiparty() { QList calls; if (mVoiceCalls.size() < 2) { return QList(); } // set everything as active Q_FOREACH(const QString &objPath, mVoiceCalls.keys()) { QDBusInterface iface("org.ofono", objPath, "org.ofono.VoiceCall"); iface.call("SetProperty", "State", QVariant::fromValue(QDBusVariant("active")));; iface.call("SetProperty", "Multiparty", QVariant::fromValue(QDBusVariant(true)));; calls << QDBusObjectPath(objPath); } return calls; } QList VoiceCallManagerPrivate::PrivateChat(const QDBusObjectPath &objPath) { QList remainingCalls; Q_FOREACH(const QString &path, mVoiceCalls.keys()) { QDBusInterface iface("org.ofono", objPath.path(), "org.ofono.VoiceCall"); if (objPath.path() == path) { iface.call("SetProperty", "State", QVariant::fromValue(QDBusVariant("active"))); } else { iface.call("SetProperty", "State", QVariant::fromValue(QDBusVariant("held"))); remainingCalls << objPath; } } // remove the multiparty call if there are only 2 calls if (mVoiceCalls.size() == 2) { Q_FOREACH(const QString &objPath, mVoiceCalls.keys()) { QDBusInterface iface("org.ofono", objPath, "org.ofono.VoiceCall"); iface.call("SetProperty", "Multiparty", QVariant::fromValue(QDBusVariant(false)));; } } if (remainingCalls.size() < 2) { return QList(); } return remainingCalls; } void VoiceCallManagerPrivate::SendTones(const QString &tones) { if (failNextDtmf) { failNextDtmf = false; sendErrorReply("org.ofono.Error.InProgress", "Operation already in progress"); return; } Q_EMIT TonesReceived(tones); } QDBusObjectPath VoiceCallManagerPrivate::Dial(const QString &to, const QString &hideCallerId) { qDebug() << "DIAL" << to; QString newPath("/OfonoVoiceCall/OfonoVoiceCall"+QString::number(++voiceCallCount)); QDBusObjectPath newPathObj(newPath); QVariantMap callProperties; callProperties["State"] = "dialing"; callProperties["LineIdentification"] = to; callProperties["Name"] = ""; callProperties["Multiparty"] = false; callProperties["RemoteHeld"] = false; callProperties["RemoteMultiparty"] = false; callProperties["Emergency"] = false; initialCallProperties[newPath] = callProperties; mVoiceCalls[newPath] = new OfonoVoiceCall(newPath); connect(voiceCallData[newPath], SIGNAL(destroyed()), this, SLOT(onVoiceCallDestroyed())); Q_EMIT CallAdded(newPathObj, callProperties); return newPathObj; } void VoiceCallManagerPrivate::onVoiceCallDestroyed() { VoiceCallPrivate *voiceCall = static_cast(sender()); if (voiceCall) { voiceCallData.remove(voiceCall->objectPath()); mVoiceCalls[voiceCall->objectPath()]->deleteLater(); mVoiceCalls.remove(voiceCall->objectPath()); Q_EMIT CallRemoved(QDBusObjectPath(voiceCall->objectPath())); } } telepathy-ofono-0.2+14.04.20140407/tests/mock/networkregistrationprivate.h0000644000015301777760000000264312320626651027062 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef NETWORKREGISTRATIONPRIVATE_H #define NETWORKREGISTRATIONPRIVATE_H #include #include "mock_common.h" class NetworkRegistrationPrivate : public QObject, protected QDBusContext { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.ofono.NetworkRegistration") public: NetworkRegistrationPrivate(QObject *parent = 0); ~NetworkRegistrationPrivate(); Q_SIGNALS: void PropertyChanged(const QString &, const QDBusVariant &); public Q_SLOTS: QVariantMap GetProperties(); void SetProperty(const QString &name, const QDBusVariant &value); private: QVariantMap mProperties; }; extern QMap networkRegistrationData; #endif telepathy-ofono-0.2+14.04.20140407/tests/mock/ofononetworkregistration.cpp0000644000015301777760000001513712320626651027065 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include #include #include "ofononetworkregistration.h" #include "ofonointerface.h" #include "modemprivate.h" #include "networkregistrationprivate.h" #define REGISTER_TIMEOUT 300000 #define SCAN_TIMEOUT 300000 QDBusArgument &operator<<(QDBusArgument &argument, const OfonoOperatorStruct &op) { argument.beginStructure(); argument << op.path << op.properties; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, OfonoOperatorStruct &op) { argument.beginStructure(); argument >> op.path >> op.properties; argument.endStructure(); return argument; } OfonoNetworkRegistration::OfonoNetworkRegistration(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent) : OfonoModemInterface(modemSetting, modemPath, "org.ofono.NetworkRegistration", OfonoGetAllOnStartup, parent) { qDBusRegisterMetaType(); qDBusRegisterMetaType(); m_if->setPath(OFONO_MOCK_NETWORK_REGISTRATION_OBJECT); if (!networkRegistrationData.keys().contains(modem()->path())) { networkRegistrationData[modem()->path()] = new NetworkRegistrationPrivate(); } connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), this, SLOT(propertyChanged(const QString&, const QVariant&))); } OfonoNetworkRegistration::~OfonoNetworkRegistration() { } void OfonoNetworkRegistration::registerOp() { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", OFONO_MOCK_NETWORK_REGISTRATION_OBJECT, m_if->ifname(), "Register"); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(registerResp()), SLOT(registerErr(const QDBusError&)), REGISTER_TIMEOUT); } void OfonoNetworkRegistration::scan() { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", OFONO_MOCK_NETWORK_REGISTRATION_OBJECT, m_if->ifname(), "Scan"); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(scanResp(OfonoOperatorList)), SLOT(scanErr(const QDBusError&)), REGISTER_TIMEOUT); } void OfonoNetworkRegistration::getOperators() { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", OFONO_MOCK_NETWORK_REGISTRATION_OBJECT, m_if->ifname(), "GetOperators"); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(getOperatorsResp(OfonoOperatorList)), SLOT(getOperatorsErr(const QDBusError&)), SCAN_TIMEOUT); } QString OfonoNetworkRegistration::mode() const { return m_if->properties()["Mode"].value(); } QString OfonoNetworkRegistration::status() const { return m_if->properties()["Status"].value(); } uint OfonoNetworkRegistration::locationAreaCode() const { return m_if->properties()["LocationAreaCode"].value(); } uint OfonoNetworkRegistration::cellId() const { return m_if->properties()["CellId"].value(); } QString OfonoNetworkRegistration::mcc() const { return m_if->properties()["MobileCountryCode"].value(); } QString OfonoNetworkRegistration::mnc() const { return m_if->properties()["MobileNetworkCode"].value(); } QString OfonoNetworkRegistration::technology() const { return m_if->properties()["Technology"].value(); } QString OfonoNetworkRegistration::name() const { return m_if->properties()["Name"].value(); } uint OfonoNetworkRegistration::strength() const { return m_if->properties()["Strength"].value(); } QString OfonoNetworkRegistration::baseStation() const { return m_if->properties()["BaseStation"].value(); } void OfonoNetworkRegistration::propertyChanged(const QString& property, const QVariant& value) { if (property == "Mode") { Q_EMIT modeChanged(value.value()); } else if (property == "Status") { Q_EMIT statusChanged(value.value()); } else if (property == "LocationAreaCode") { Q_EMIT locationAreaCodeChanged(value.value()); } else if (property == "CellId") { Q_EMIT cellIdChanged(value.value()); } else if (property == "MobileCountryCode") { Q_EMIT mccChanged(value.value()); } else if (property == "MobileNetworkCode") { Q_EMIT mncChanged(value.value()); } else if (property == "Technology") { Q_EMIT technologyChanged(value.value()); } else if (property == "Name") { Q_EMIT nameChanged(value.value()); } else if (property == "Strength") { Q_EMIT strengthChanged(value.value()); } else if (property == "BaseStation") { Q_EMIT baseStationChanged(value.value()); } } void OfonoNetworkRegistration::registerResp() { Q_EMIT registerComplete(true); } void OfonoNetworkRegistration::registerErr(QDBusError error) { m_if->setError(error.name(), error.message()); Q_EMIT registerComplete(false); } void OfonoNetworkRegistration::getOperatorsResp(OfonoOperatorList list) { QStringList oplist; Q_FOREACH(OfonoOperatorStruct op, list) { oplist << op.path.path(); } Q_EMIT getOperatorsComplete(true, oplist); } void OfonoNetworkRegistration::getOperatorsErr(QDBusError error) { m_if->setError(error.name(), error.message()); Q_EMIT getOperatorsComplete(false, QStringList()); } void OfonoNetworkRegistration::scanResp(OfonoOperatorList list) { QStringList oplist; Q_FOREACH(OfonoOperatorStruct op, list) { oplist << op.path.path(); } Q_EMIT scanComplete(true, oplist); } void OfonoNetworkRegistration::scanErr(QDBusError error) { m_if->setError(error.name(), error.message()); Q_EMIT scanComplete(false, QStringList()); } telepathy-ofono-0.2+14.04.20140407/tests/mock/VoiceCallPrivate.xml0000644000015301777760000000153512320626651025107 0ustar pbusernogroup00000000000000 telepathy-ofono-0.2+14.04.20140407/tests/mock/ofononetworkregistration.h0000644000015301777760000000742712320626651026535 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef OFONONETWORKREGISTRATION_H #define OFONONETWORKREGISTRATION_H #include #include #include #include #include "ofonomodeminterface.h" #include "libofono-qt_global.h" struct OfonoOperatorStruct { QDBusObjectPath path; QVariantMap properties; }; typedef QList OfonoOperatorList; Q_DECLARE_METATYPE(OfonoOperatorStruct) Q_DECLARE_METATYPE(OfonoOperatorList) //! This class is used to access oFono network registration API /*! * The API is documented in * http://git.kernel.org/?p=network/ofono/ofono.git;a=blob_plain;f=doc/network-api.txt */ class OFONO_QT_EXPORT OfonoNetworkRegistration : public OfonoModemInterface { Q_OBJECT Q_PROPERTY(QString mode READ mode NOTIFY modeChanged) Q_PROPERTY(QString status READ status NOTIFY statusChanged) Q_PROPERTY(uint locationAreaCode READ locationAreaCode NOTIFY locationAreaCodeChanged) Q_PROPERTY(uint cellId READ cellId NOTIFY cellIdChanged) Q_PROPERTY(QString mcc READ mcc NOTIFY mccChanged) Q_PROPERTY(QString mnc READ mnc NOTIFY mncChanged) Q_PROPERTY(QString technology READ technology NOTIFY technologyChanged) Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(uint strength READ strength NOTIFY strengthChanged) Q_PROPERTY(QString baseStation READ baseStation NOTIFY baseStationChanged) public: OfonoNetworkRegistration(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent=0); ~OfonoNetworkRegistration(); /* Properties */ QString mode() const; QString status() const; uint locationAreaCode() const; uint cellId() const; QString mcc() const; QString mnc() const; QString technology() const; QString name() const; uint strength() const; QString baseStation() const; public Q_SLOTS: void registerOp(); void getOperators(); void scan(); Q_SIGNALS: void modeChanged(const QString &mode); void statusChanged(const QString &status); void locationAreaCodeChanged(uint locationAreaCode); void cellIdChanged(uint cellId); void mccChanged(const QString &mcc); void mncChanged(const QString &mnc); void technologyChanged(const QString &technology); void nameChanged(const QString &name); void strengthChanged(uint strength); void baseStationChanged(const QString &baseStation); void registerComplete(bool success); void getOperatorsComplete(bool success, const QStringList &operatorIds); void scanComplete(bool success, const QStringList &operatorIds); private Q_SLOTS: void propertyChanged(const QString& property, const QVariant& value); void registerResp(); void registerErr(QDBusError error); void getOperatorsResp(OfonoOperatorList list); void getOperatorsErr(QDBusError error); void scanResp(OfonoOperatorList list); void scanErr(QDBusError error); private: }; #endif /* !OFONONETWORKREGISTRATION_H */ telepathy-ofono-0.2+14.04.20140407/tests/mock/voicecallprivate.h0000644000015301777760000000304312320626651024672 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef VOICECALLPRIVATE_H #define VOICECALLPRIVATE_H #include class VoiceCallPrivate : public QObject, protected QDBusContext { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.ofono.VoiceCall") public: VoiceCallPrivate(const QString &path, QObject *parent = 0); ~VoiceCallPrivate(); QString objectPath() const; Q_SIGNALS: void PropertyChanged(const QString &name, const QDBusVariant &value); public Q_SLOTS: QVariantMap GetProperties(); void SetProperty(const QString &name, const QDBusVariant &value); void Hangup(); void Answer(); void MockSetAlerting(); void MockAnswer(); private: QVariantMap mProperties; QString mObjectPath; }; extern QMap voiceCallData; extern QMap initialCallProperties; #endif telepathy-ofono-0.2+14.04.20140407/tests/mock/ModemPrivate.xml0000644000015301777760000000141312320626651024302 0ustar pbusernogroup00000000000000 telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonomodem.h0000644000015301777760000001273612320626651023511 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef OFONOMODEM_H #define OFONOMODEM_H #include #include #include #include "libofono-qt_global.h" class OfonoModemManager; class OfonoInterface; //! This class is used to access an oFono modem object and its properties /*! * oFono modem properties are documented in * http://git.kernel.org/?p=network/ofono/ofono.git;a=blob_plain;f=doc/modem-api.txt */ class OFONO_QT_EXPORT OfonoModem : public QObject { Q_OBJECT Q_PROPERTY(bool isValid READ isValid NOTIFY validityChanged) Q_PROPERTY(QString path READ path NOTIFY pathChanged) Q_PROPERTY(QString errorName READ errorName) Q_PROPERTY(QString errorMessage READ errorMessage) Q_PROPERTY(bool powered READ powered WRITE setPowered NOTIFY poweredChanged) Q_PROPERTY(bool online READ online WRITE setOnline NOTIFY onlineChanged) Q_PROPERTY(bool lockdown READ lockdown WRITE setLockdown NOTIFY lockdownChanged) Q_PROPERTY(bool emergency READ emergency NOTIFY emergencyChanged) Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString manufacturer READ manufacturer NOTIFY manufacturerChanged) Q_PROPERTY(QString model READ model NOTIFY modelChanged) Q_PROPERTY(QString revision READ revision NOTIFY revisionChanged) Q_PROPERTY(QString serial READ serial NOTIFY serialChanged) Q_PROPERTY(QString type READ type NOTIFY typeChanged) Q_PROPERTY(QStringList features READ features NOTIFY featuresChanged) Q_PROPERTY(QStringList interfaces READ interfaces NOTIFY interfacesChanged) public: //! How the modem object should select a modem enum SelectionSetting { AutomaticSelect, /*!< Select the first available modem automatically; * if that modem becomes unavailable, select the first available * modem again. */ ManualSelect /*!< Do not select a modem automatically, * use the modem path provided in the constructor, and do not * attempt to select another modem if the first one becomes * unavailable. */ }; /*! * \param setting sets the modem selection policy for the object * \param modemPath if modem selection policy is ManualSelect, then this contains * the D-Bus path to the modem object. Otherwise, it is ignored. */ OfonoModem(SelectionSetting setting, const QString& modemPath, QObject *parent=0); ~OfonoModem(); //! Returns true if D-Bus modem object exists. bool isValid() const; //! Returns the D-Bus object path of the modem QString path() const; //! Get the D-Bus error name of the last operation. /*! * Returns the D-Bus error name of the last operation (setting a property * or calling a method) if it has failed */ QString errorName() const; //! Get the D-Bus error message of the last operation. /*! * Returns the D-Bus error message of the last operation (setting a property * or calling a method) if it has failed */ QString errorMessage() const; bool powered() const; bool online() const; bool lockdown() const; bool emergency() const; QString name() const; QString manufacturer() const; QString model() const; QString revision() const; QString serial() const; QString type() const; QStringList features() const; QStringList interfaces() const; public Q_SLOTS: void setPowered(bool powered); void setOnline(bool online); void setLockdown(bool lockdown); Q_SIGNALS: //! Issued when a modem becomes unavailable or available again void validityChanged(bool validity); //! Issued when the object has switched to another modem void pathChanged(QString modemPath); void poweredChanged(bool powered); void setPoweredFailed(); void onlineChanged(bool online); void setOnlineFailed(); void lockdownChanged(bool lockdown); void setLockdownFailed(); void emergencyChanged(bool emergency); void nameChanged(const QString &name); void manufacturerChanged(const QString &manufacturer); void modelChanged(const QString &model); void revisionChanged(const QString &revision); void serialChanged(const QString &serial); void typeChanged(const QString &type); void featuresChanged(const QStringList &features); void interfacesChanged(const QStringList &interfaces); private Q_SLOTS: void propertyChanged(const QString &property, const QVariant &value); void setPropertyFailed(const QString& property); void modemAdded(const QString &modem); void modemRemoved(const QString &modem); private: void modemsChanged(); private: OfonoModemManager *m_mm; OfonoInterface *m_if; SelectionSetting m_selectionSetting; bool m_isValid; }; #endif telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonointerface.h0000644000015301777760000001152712320626651024345 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef OFONOINTERFACE_H #define OFONOINTERFACE_H #include #include #include #include #include "ofonopropertysetting.h" #include "libofono-qt_global.h" //! Basic oFono interface class /*! * This class implements basic access to properties of oFono interfaces. * It should not be instantiated directly; instead you should instantiate * interface-specific classes. */ class OFONO_QT_EXPORT OfonoInterface : public QObject { Q_OBJECT public: /*! * \param path D-Bus path to the interface * \param ifname D-Bus name of the interface * \param setting specifies how the object should handle oFono properties of the interface */ OfonoInterface(const QString &path, const QString &ifname, OfonoGetPropertySetting setting, QObject *parent=0); ~OfonoInterface(); //! Get all properties /*! * Returns the full set of current properties. If the object was constructed with * OfonoInterface::GetAllOnFirstRequest, and no properties have been explicitly queried yet * via requestProperty(), then returns nothing. */ QVariantMap properties() const; //! Request a property asynchronously. /*! * Result is returned via requestPropertyComplete() signal. */ void requestProperty(const QString &name); //! Set a property asynchronously. /*! * Result is returned via propertyChanged() signal * if setting is successful or via setPropertyFailed() signal if setting has failed. */ void setProperty(const QString &name, const QVariant &property, const QString& password=0); //! Resets the property cache. void resetProperties(); //! Get the interface D-Bus path QString path() const {return m_path;} //! Get the interface D-Bus name QString ifname() const {return m_ifname;} //! Get the D-Bus error name of the last operation. /*! * Returns the D-Bus error name of the last operation (setting a property * or calling a method) if it has failed */ QString errorName() const {return m_errorName;} //! Get the D-Bus error message of the last operation. /*! * Returns the D-Bus error message of the last operation (setting a property * or calling a method) if it has failed */ QString errorMessage() const {return m_errorMessage;} public Q_SLOTS: //! Changes the interface path /*! * This method changes the D-Bus path to the interface. * Properties are updated immediately if property setting is set to * GetAllOnStartup or reset otherwise. */ void setPath(const QString &path); //! Sets the last error explicitly void setError(const QString &errorName, const QString &errorMessage); Q_SIGNALS: //! Issued when a property has changed /*! * \param name name of the property * \param property value of the property */ void propertyChanged(const QString &name, const QVariant &property); //! Issued when requesting a property has completed /*! * \param success true if requesting a property was successful, false if there was an error * \param name name of the property * \param property value of the property */ void requestPropertyComplete(bool success, const QString &name, const QVariant &property); //! Issued when setting a property has failed /*! * \param name name of the property */ void setPropertyFailed(const QString &name); private Q_SLOTS: void onPropertyChanged(QString property, QDBusVariant value); void getPropertiesAsyncResp(QVariantMap properties); void getPropertiesAsyncErr(const QDBusError&); void setPropertyResp(); void setPropertyErr(const QDBusError& error); protected Q_SLOTS: private: QVariantMap getAllPropertiesSync(); protected: QString m_errorName; QString m_errorMessage; private: QString m_path; QString m_ifname; QVariantMap m_properties; QString m_pendingProperty; OfonoGetPropertySetting m_getpropsetting; }; #endif telepathy-ofono-0.2+14.04.20140407/tests/mock/callvolumeprivate.h0000644000015301777760000000257412320626651025104 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef CALLVOLUMEPRIVATE_H #define CALLVOLUMEPRIVATE_H #include #include #include "mock_common.h" class CallVolumePrivate : public QObject, protected QDBusContext { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.ofono.CallVolume") public: CallVolumePrivate(QObject *parent = 0); ~CallVolumePrivate(); Q_SIGNALS: void PropertyChanged(const QString &name, const QDBusVariant &value); public Q_SLOTS: QVariantMap GetProperties(); void SetProperty(const QString &name, const QDBusVariant &value); private: QVariantMap mProperties; }; extern QMap callVolumeData; #endif telepathy-ofono-0.2+14.04.20140407/tests/mock/modemprivate.h0000644000015301777760000000263112320626651024034 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef MODEMPRIVATE_H #define MODEMPRIVATE_H #include #include #include #include "mock_common.h" class ModemPrivate : public QObject, protected QDBusContext { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.ofono.Modem") public: ModemPrivate(QObject *parent = 0); ~ModemPrivate(); Q_SIGNALS: void PropertyChanged(const QString &name, const QDBusVariant& value); public Q_SLOTS: void MockSetOnline(bool online); QVariantMap GetProperties(); void SetProperty(const QString &name, const QDBusVariant& value); private: QVariantMap mProperties; }; extern QMap modemData; #endif telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonomessagemanager.cpp0000644000015301777760000002333112320626651025713 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include #include #include "ofonomessagemanager.h" #include "ofonointerface.h" #include "messagemanagerprivate.h" QDBusArgument &operator<<(QDBusArgument &argument, const OfonoMessageManagerStruct &message) { argument.beginStructure(); argument << message.path << message.properties; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, OfonoMessageManagerStruct &message) { argument.beginStructure(); argument >> message.path >> message.properties; argument.endStructure(); return argument; } OfonoMessageManager::OfonoMessageManager(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent) : OfonoModemInterface(modemSetting, modemPath, "org.ofono.MessageManager", OfonoGetAllOnFirstRequest, parent) { qDBusRegisterMetaType(); qDBusRegisterMetaType(); if (!messageManagerData.keys().contains(modem()->path())) { m_if->setPath(OFONO_MOCK_MESSAGE_MANAGER_OBJECT); messageManagerData[modem()->path()] = new MessageManagerPrivate(); } m_messagelist = getMessageList(); connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), this, SLOT(propertyChanged(const QString&, const QVariant&))); connect(m_if, SIGNAL(setPropertyFailed(const QString&)), this, SLOT(setPropertyFailed(const QString&))); connect(m_if, SIGNAL(requestPropertyComplete(bool, const QString&, const QVariant&)), this, SLOT(requestPropertyComplete(bool, const QString&, const QVariant&))); connect(this, SIGNAL(validityChanged(bool)), this, SLOT(validityChanged(bool))); connect(modem(), SIGNAL(pathChanged(QString)), this, SLOT(pathChanged(const QString&))); connectDbusSignals(path()); } OfonoMessageManager::~OfonoMessageManager() { } void OfonoMessageManager::validityChanged(bool /*validity*/) { m_messagelist = getMessageList(); } void OfonoMessageManager::pathChanged(const QString& path) { connectDbusSignals(path); } QStringList OfonoMessageManager::getMessageList() { QDBusReply reply; OfonoMessageManagerList messages; QDBusMessage request; QStringList messageList; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "GetMessages"); reply = QDBusConnection::sessionBus().call(request); messages = reply; Q_FOREACH(OfonoMessageManagerStruct message, messages) { messageList << message.path.path(); } return messageList; } void OfonoMessageManager::connectDbusSignals(const QString& path) { QDBusConnection::sessionBus().disconnect("org.ofono", QString(), m_if->ifname(), "MessageAdded", this, SLOT(onMessageAdded(const QDBusObjectPath&, const QVariantMap&))); QDBusConnection::sessionBus().disconnect("org.ofono", QString(), m_if->ifname(), "MessageRemoved", this, SLOT(onMessageRemoved(const QDBusObjectPath&))); QDBusConnection::sessionBus().disconnect("org.ofono", QString(), m_if->ifname(), "IncomingMessage", this, SIGNAL(incomingMessage(QString, QVariantMap))); QDBusConnection::sessionBus().disconnect("org.ofono", QString(), m_if->ifname(), "ImmediateMessage", this, SIGNAL(immediateMessage(QString, QVariantMap))); QDBusConnection::sessionBus().disconnect("org.ofono", QString(), m_if->ifname(), "StatusReport", this, SIGNAL(statusReport(QString, QVariantMap))); QDBusConnection::sessionBus().connect("org.ofono", path, m_if->ifname(), "MessageAdded", this, SLOT(onMessageAdded(const QDBusObjectPath&, const QVariantMap&))); QDBusConnection::sessionBus().connect("org.ofono", path, m_if->ifname(), "MessageRemoved", this, SLOT(onMessageRemoved(const QDBusObjectPath&))); QDBusConnection::sessionBus().connect("org.ofono", path, m_if->ifname(), "IncomingMessage", this, SIGNAL(incomingMessage(QString, QVariantMap))); QDBusConnection::sessionBus().connect("org.ofono", path, m_if->ifname(), "ImmediateMessage", this, SIGNAL(immediateMessage(QString, QVariantMap))); QDBusConnection::sessionBus().connect("org.ofono", path, m_if->ifname(), "StatusReport", this, SIGNAL(statusReport(QString, QVariantMap))); } void OfonoMessageManager::requestServiceCenterAddress() { m_if->requestProperty("ServiceCenterAddress"); } void OfonoMessageManager::setServiceCenterAddress(QString address) { m_if->setProperty("ServiceCenterAddress", qVariantFromValue(address)); } void OfonoMessageManager::requestUseDeliveryReports() { m_if->requestProperty("UseDeliveryReports"); } void OfonoMessageManager::setUseDeliveryReports(bool useDeliveryReports) { m_if->setProperty("UseDeliveryReports", qVariantFromValue(useDeliveryReports)); } void OfonoMessageManager::requestBearer() { m_if->requestProperty("Bearer"); } void OfonoMessageManager::setBearer(QString bearer) { m_if->setProperty("Bearer", qVariantFromValue(bearer)); } void OfonoMessageManager::requestAlphabet() { m_if->requestProperty("Alphabet"); } void OfonoMessageManager::setAlphabet(QString alphabet) { m_if->setProperty("Alphabet", qVariantFromValue(alphabet)); } QDBusObjectPath OfonoMessageManager::sendMessage(const QString &to, const QString &message, bool &success) { QDBusMessage request; QDBusReply reply; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "SendMessage"); request << to << message; reply = QDBusConnection::sessionBus().call(request); success = reply.isValid(); if (!success) { m_if->setError(reply.error().name(), reply.error().message()); } return reply; } void OfonoMessageManager::requestPropertyComplete(bool success, const QString& property, const QVariant& value) { if (property == "ServiceCenterAddress") { Q_EMIT serviceCenterAddressComplete(success, value.value()); } else if (property == "UseDeliveryReports") { Q_EMIT useDeliveryReportsComplete(success, value.value()); } else if (property == "Bearer") { Q_EMIT bearerComplete(success, value.value()); } else if (property == "Alphabet") { Q_EMIT alphabetComplete(success, value.value()); } } void OfonoMessageManager::propertyChanged(const QString& property, const QVariant& value) { if (property == "ServiceCenterAddress") { Q_EMIT serviceCenterAddressChanged(value.value()); } else if (property == "UseDeliveryReports") { Q_EMIT useDeliveryReportsChanged(value.value()); } else if (property == "Bearer") { Q_EMIT bearerChanged(value.value()); } else if (property == "Alphabet") { Q_EMIT alphabetChanged(value.value()); } } void OfonoMessageManager::setPropertyFailed(const QString& property) { if (property == "ServiceCenterAddress") { Q_EMIT setServiceCenterAddressFailed(); } else if (property == "UseDeliveryReports") { Q_EMIT setUseDeliveryReportsFailed(); } else if (property == "Bearer") { Q_EMIT setBearerFailed(); } else if (property == "Alphabet") { Q_EMIT setAlphabetFailed(); } } QStringList OfonoMessageManager::getMessages() const { return m_messagelist; } void OfonoMessageManager::onMessageAdded(const QDBusObjectPath &path, const QVariantMap& /*properties*/) { m_messagelist << path.path(); Q_EMIT messageAdded(path.path()); } void OfonoMessageManager::onMessageRemoved(const QDBusObjectPath &path) { m_messagelist.removeAll(path.path()); Q_EMIT messageRemoved(path.path()); } telepathy-ofono-0.2+14.04.20140407/tests/mock/voicecallprivate.cpp0000644000015301777760000000607012320626651025230 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include "voicecallprivateadaptor.h" QMap voiceCallData; QMap initialCallProperties; VoiceCallPrivate::VoiceCallPrivate(const QString &path, QObject *parent) : QObject(parent), mObjectPath(path) { QDBusConnection::sessionBus().registerObject(path, this); QDBusConnection::sessionBus().registerService("org.ofono"); SetProperty("LineIdentification", QDBusVariant(QVariant(""))); SetProperty("IncomingLine", QDBusVariant(QVariant(""))); SetProperty("Name", QDBusVariant(QVariant(""))); SetProperty("Multiparty", QDBusVariant(QVariant(false))); SetProperty("State", QDBusVariant(QVariant(""))); SetProperty("StartTime", QDBusVariant(QVariant(""))); SetProperty("Information", QDBusVariant(QVariant(""))); SetProperty("Icon", QDBusVariant(QVariant(""))); SetProperty("Emergency", QDBusVariant(QVariant(false))); SetProperty("RemoteHeld", QDBusVariant(QVariant(false))); SetProperty("RemoteMultiparty", QDBusVariant(QVariant(false))); QMapIterator i(initialCallProperties[path]); while (i.hasNext()) { i.next(); SetProperty(i.key(), QDBusVariant(i.value())); } new VoiceCallAdaptor(this); } VoiceCallPrivate::~VoiceCallPrivate() { } QString VoiceCallPrivate::objectPath() const { return mObjectPath; } QVariantMap VoiceCallPrivate::GetProperties() { return mProperties; } void VoiceCallPrivate::SetProperty(const QString &name, const QDBusVariant& value) { qDebug() << "VoiceCallPrivate::SetProperty" << name << value.variant(); mProperties[name] = value.variant(); Q_EMIT PropertyChanged(name, value); } void VoiceCallPrivate::Hangup() { SetProperty("State", QDBusVariant(QVariant("disconnected"))); deleteLater(); } void VoiceCallPrivate::Answer() { if (mProperties["State"] == QString("incoming")) { SetProperty("State", QDBusVariant(QVariant("active"))); } } void VoiceCallPrivate::MockSetAlerting() { if (mProperties["State"] == QString("dialing")) { SetProperty("State", QDBusVariant(QVariant("alerting"))); } } void VoiceCallPrivate::MockAnswer() { if (mProperties["State"] == QString("dialing") || mProperties["State"] == QString("alerting")) { SetProperty("State", QDBusVariant(QVariant("active"))); } } telepathy-ofono-0.2+14.04.20140407/tests/mock/messagemanagerprivate.cpp0000644000015301777760000000600012320626651026237 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include "messagemanagerprivateadaptor.h" #include "ofonomessage.h" QMap messageManagerData; MessageManagerPrivate::MessageManagerPrivate(QObject *parent) : messageCount(0), QObject(parent) { QDBusConnection::sessionBus().registerObject(OFONO_MOCK_MESSAGE_MANAGER_OBJECT, this); QDBusConnection::sessionBus().registerService("org.ofono"); SetProperty("ServiceCenterAddress", QDBusVariant(QVariant(""))); SetProperty("UseDeliveryReports", QDBusVariant(QVariant(false))); SetProperty("Bearer", QDBusVariant(QVariant(""))); SetProperty("Alphabet", QDBusVariant(QVariant(""))); new MessageManagerAdaptor(this); } MessageManagerPrivate::~MessageManagerPrivate() { } QVariantMap MessageManagerPrivate::GetProperties() { return mProperties; } void MessageManagerPrivate::SetProperty(const QString &name, const QDBusVariant& value) { qDebug() << "MessageManagerPrivate::SetProperty" << name << value.variant(); mProperties[name] = value.variant(); Q_EMIT PropertyChanged(name, value); } void MessageManagerPrivate::MockSendMessage(const QString &from, const QString &text) { QVariantMap properties; properties["Sender"] = from; properties["SentTime"] = QDateTime::currentDateTime().toString(Qt::ISODate); properties["LocalSentTime"] = QDateTime::currentDateTime().toString(Qt::ISODate); Q_EMIT IncomingMessage(text, properties); } QDBusObjectPath MessageManagerPrivate::SendMessage(const QString &to, const QString &text) { QString newPath("/OfonoMessage"+QString::number(++messageCount)); QDBusObjectPath newPathObj(newPath); mMessages[newPath] = new OfonoMessage(newPath); connect(mMessages[newPath], SIGNAL(destroyed()), this, SLOT(onMessageDestroyed())); Q_EMIT MessageAdded(newPathObj, QVariantMap()); return newPathObj; } void MessageManagerPrivate::MockStatusReport(const QString &message, bool success) { QVariantMap info; info["Delivered"] = success; Q_EMIT StatusReport(message, info); } void MessageManagerPrivate::onMessageDestroyed() { OfonoMessage *message = static_cast(sender()); if (message) { mMessages.remove(message->path()); Q_EMIT MessageRemoved(QDBusObjectPath(message->path())); } } telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonopropertysetting.h0000644000015301777760000000243212320626651025662 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef OFONOPROPERTYSETTING_H #define OFONOPROPERTYSETTING_H //! How to handle getting the properties enum OfonoGetPropertySetting { OfonoGetAllOnStartup, /*!< Get all properties synchronously on startup; * they would be immediately available. */ OfonoGetAllOnFirstRequest /*!< Do not get properties on startup; * get them in an asynhronous way when the first * property is requested. */ }; #endif telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonovoicecall.h0000644000015301777760000001050212320626651024336 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef OFONOVOICECALL_H #define OFONOVOICECALL_H #include #include #include #include #include "libofono-qt_global.h" class OfonoInterface; //! This class is used to access oFono voice call API /*! * The API is documented in * http://git.kernel.org/?p=network/ofono/ofono.git;a=blob;f=doc/voicecall-api.txt */ class OFONO_QT_EXPORT OfonoVoiceCall : public QObject { Q_OBJECT Q_PROPERTY(QString path READ path) Q_PROPERTY(QString errorName READ errorName) Q_PROPERTY(QString errorMessage READ errorMessage) Q_PROPERTY(QString lineIdentification READ lineIdentification NOTIFY lineIdentificationChanged) Q_PROPERTY(QString incomingLine READ incomingLine NOTIFY incomingLineChanged) Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString state READ state NOTIFY stateChanged) Q_PROPERTY(QString startTime READ startTime NOTIFY startTimeChanged) Q_PROPERTY(QString information READ information NOTIFY informationChanged) Q_PROPERTY(bool multiparty READ multiparty NOTIFY multipartyChanged) Q_PROPERTY(bool emergency READ emergency NOTIFY emergencyChanged) Q_PROPERTY(quint8 icon READ icon NOTIFY iconChanged) public: OfonoVoiceCall(const QString &callId, QObject *parent=0); OfonoVoiceCall(const OfonoVoiceCall &op); ~OfonoVoiceCall(); OfonoVoiceCall operator=(const OfonoVoiceCall &op); bool operator==(const OfonoVoiceCall &op); //! Returns the D-Bus object path of the voice call object QString path() const; //! Get the D-Bus error name of the last operation. /*! * Returns the D-Bus error name of the last operation (setting a property * or calling a method) if it has failed */ QString errorName() const; //! Get the D-Bus error message of the last operation. /*! * Returns the D-Bus error message of the last operation (setting a property * or calling a method) if it has failed */ QString errorMessage() const; QString lineIdentification() const; QString incomingLine() const; QString name() const; QString state() const; QString startTime() const; QString information() const; bool multiparty() const; bool emergency() const; quint8 icon() const; bool remoteHeld() const; bool remoteMultiparty() const; public Q_SLOTS: void answer(); void hangup(); void deflect(const QString &number); Q_SIGNALS: void answerComplete(bool status); void hangupComplete(bool status); void deflectComplete(bool status); void lineIdentificationChanged(const QString &name); void nameChanged(const QString &name); void stateChanged(const QString &state); void startTimeChanged(const QString &time); void informationChanged(const QString &mcc); void incomingLineChanged(const QString &line); void disconnectReason(const QString &reason); void multipartyChanged(const bool multiparty); void iconChanged(const quint8 &icon); void emergencyChanged(const bool emergency); void remoteHeldChanged(const bool remoteHeld); void remoteMultipartyChanged(const bool remoteMultiparty); private Q_SLOTS: void propertyChanged(const QString &property, const QVariant &value); void answerResp(); void answerErr(const QDBusError &error); void hangupResp(); void hangupErr(const QDBusError &error); void deflectResp(); void deflectErr(const QDBusError &error); private: OfonoInterface *m_if; }; #endif // OFONOVOICECALL_H telepathy-ofono-0.2+14.04.20140407/tests/mock/messageprivate.h0000644000015301777760000000261712320626651024363 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef MESSAGEPRIVATE_H #define MESSAGEPRIVATE_H #include class MessagePrivate : public QObject, protected QDBusContext { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.ofono.Message") public: MessagePrivate(const QString &path, QObject *parent = 0); ~MessagePrivate(); Q_SIGNALS: void PropertyChanged(const QString &name, const QDBusVariant &value); public Q_SLOTS: QVariantMap GetProperties(); void SetProperty(const QString &name, const QDBusVariant &value); void Cancel(); void MockMarkFailed(); void MockMarkSent(); private: QVariantMap mProperties; }; extern QMap messageData; #endif telepathy-ofono-0.2+14.04.20140407/tests/mock/MessageManagerPrivate.xml0000644000015301777760000000426612320626651026131 0ustar pbusernogroup00000000000000 telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonovoicecallmanager.cpp0000644000015301777760000003500612320626651026232 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * Portions of this file are Copyright (C) 2011 Intel Corporation * Contact: Shane Bryan * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include #include #include "ofonovoicecallmanager.h" #include "ofonointerface.h" #include "voicecallmanagerprivate.h" #define DIAL_TIMEOUT 30000 #define TONE_TIMEOUT 10000 #define TRANSFER_TIMEOUT 20000 #define SWAP_TIMEOUT 20000 #define HANGUP_TIMEOUT 30000 #define HOLD_TIMEOUT 30000 #define PRIVATE_CHAT_TIMEOUT 30000 #define CREATE_MULTIPARTY_TIMEOUT 30000 QDBusArgument &operator<<(QDBusArgument &argument, const OfonoVoiceCallManagerStruct &call) { argument.beginStructure(); argument << call.path << call.properties; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, OfonoVoiceCallManagerStruct &call) { argument.beginStructure(); argument >> call.path >> call.properties; argument.endStructure(); return argument; } OfonoVoiceCallManager::OfonoVoiceCallManager(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent) : OfonoModemInterface(modemSetting, modemPath, "org.ofono.VoiceCallManager", OfonoGetAllOnStartup, parent) { qDBusRegisterMetaType(); qDBusRegisterMetaType(); if (!voiceCallManagerData.keys().contains(modem()->path())) { m_if->setPath(OFONO_MOCK_VOICECALL_MANAGER_OBJECT); voiceCallManagerData[modem()->path()] = new VoiceCallManagerPrivate(); } m_calllist = getCallList(); connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), this, SLOT(propertyChanged(const QString&, const QVariant&))); connect(this, SIGNAL(validityChanged(bool)), this, SLOT(validityChanged(bool))); connect(modem(), SIGNAL(pathChanged(QString)), this, SLOT(pathChanged(const QString&))); connectDbusSignals(path()); } OfonoVoiceCallManager::~OfonoVoiceCallManager() { } void OfonoVoiceCallManager::validityChanged(bool /*validity*/) { m_calllist = getCallList(); } void OfonoVoiceCallManager::pathChanged(const QString& path) { connectDbusSignals(path); } QStringList OfonoVoiceCallManager::getCallList() { QDBusReply reply; OfonoVoiceCallManagerList calls; QDBusMessage request; QStringList messageList; qDBusRegisterMetaType(); qDBusRegisterMetaType(); request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "GetCalls"); reply = QDBusConnection::sessionBus().call(request); calls = reply; Q_FOREACH(OfonoVoiceCallManagerStruct call, calls) { messageList<< call.path.path(); } return messageList; } void OfonoVoiceCallManager::connectDbusSignals(const QString& path) { QDBusConnection::sessionBus().disconnect("org.ofono", QString(), m_if->ifname(), "CallAdded", this, SLOT(callAddedChanged(const QDBusObjectPath&, const QVariantMap&))); QDBusConnection::sessionBus().disconnect("org.ofono", QString(), m_if->ifname(), "CallRemoved", this, SLOT(callRemovedChanged(const QDBusObjectPath&))); QDBusConnection::sessionBus().disconnect("org.ofono", QString(), m_if->ifname(), "BarringActive", this, SIGNAL(barringActive(const QString&))); QDBusConnection::sessionBus().disconnect("org.ofono", QString(), m_if->ifname(), "Forwarded", this, SIGNAL(forwarded(const QString&))); QDBusConnection::sessionBus().connect("org.ofono", path, m_if->ifname(), "CallAdded", this, SLOT(callAddedChanged(const QDBusObjectPath&, const QVariantMap&))); QDBusConnection::sessionBus().connect("org.ofono", path, m_if->ifname(), "CallRemoved", this, SLOT(callRemovedChanged(const QDBusObjectPath&))); QDBusConnection::sessionBus().connect("org.ofono", path, m_if->ifname(), "BarringActive", this, SIGNAL(barringActive(const QString&))); QDBusConnection::sessionBus().connect("org.ofono", path, m_if->ifname(), "Forwarded", this, SIGNAL(forwarded(const QString&))); } QDBusObjectPath OfonoVoiceCallManager::dial(const QString &number, const QString &callerid_hide, bool &success) { QDBusMessage request; QDBusReply reply; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "Dial"); QListarg; arg.append(QVariant(number)); arg.append(QVariant(callerid_hide)); request.setArguments(arg); reply = QDBusConnection::sessionBus().call(request); success = reply.isValid(); if (!success) { m_if->setError(reply.error().name(), reply.error().message()); } return reply; } void OfonoVoiceCallManager::hangupAll() { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "HangupAll"); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(hangupAllResp()), SLOT(hangupAllErr(const QDBusError&)), HANGUP_TIMEOUT); } void OfonoVoiceCallManager::sendTones(const QString &tonestring) { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "SendTones"); QListarg; arg.append(QVariant(tonestring)); request.setArguments(arg); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(sendTonesResp()), SLOT(sendTonesErr(const QDBusError&)), (TONE_TIMEOUT*tonestring.length())); } void OfonoVoiceCallManager::transfer() { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "Transfer"); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(transferResp()), SLOT(transferErr(const QDBusError&)), TRANSFER_TIMEOUT); } void OfonoVoiceCallManager::swapCalls() { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "SwapCalls"); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(swapCallsResp()), SLOT(swapCallsErr(const QDBusError&)), SWAP_TIMEOUT); } void OfonoVoiceCallManager::releaseAndAnswer() { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "ReleaseAndAnswer"); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(releaseAndAnswerResp()), SLOT(releaseAndAnswerErr(const QDBusError&)), HANGUP_TIMEOUT); } void OfonoVoiceCallManager::holdAndAnswer() { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "HoldAndAnswer"); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(holdAndAnswerResp()), SLOT(holdAndAnswerErr(const QDBusError&)), HOLD_TIMEOUT); } void OfonoVoiceCallManager::privateChat(const QString &call) { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "PrivateChat"); QListarg; arg.append(qVariantFromValue(QDBusObjectPath(call))); request.setArguments(arg); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(privateChatResp(const QList&)), SLOT(privateChatErr(const QDBusError&)), PRIVATE_CHAT_TIMEOUT); } QList OfonoVoiceCallManager::createMultiparty() { QDBusMessage request; QDBusReply > reply; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "CreateMultiparty"); reply = QDBusConnection::sessionBus().call(request); bool success = reply.isValid(); if (!success) { m_if->setError(reply.error().name(), reply.error().message()); } return reply; } void OfonoVoiceCallManager::hangupMultiparty() { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", path(), m_if->ifname(), "HangupMultiparty"); QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(hangupMultipartyResp()), SLOT(hangupMultipartyErr(const QDBusError&)), HANGUP_TIMEOUT); } void OfonoVoiceCallManager::hangupMultipartyResp() { Q_EMIT hangupMultipartyComplete(true); } void OfonoVoiceCallManager::hangupMultipartyErr(const QDBusError &error) { m_if->setError(error.name(), error.message()); Q_EMIT hangupMultipartyComplete(false); } void OfonoVoiceCallManager::createMultipartyResp(const QList &paths) { QStringList calls; Q_FOREACH(QDBusObjectPath path, paths) calls << path.path(); Q_EMIT createMultipartyComplete(true, calls); } void OfonoVoiceCallManager::createMultipartyErr(const QDBusError &error) { m_if->setError(error.name(), error.message()); Q_EMIT createMultipartyComplete(false, QStringList()); } void OfonoVoiceCallManager::privateChatResp(const QList &paths) { QStringList calls; Q_FOREACH(QDBusObjectPath path, paths) calls << path.path(); Q_EMIT privateChatComplete(true, calls); } void OfonoVoiceCallManager::privateChatErr(const QDBusError &error) { m_if->setError(error.name(), error.message()); Q_EMIT privateChatComplete(false, QStringList()); } void OfonoVoiceCallManager::holdAndAnswerResp() { Q_EMIT holdAndAnswerComplete(true); } void OfonoVoiceCallManager::holdAndAnswerErr(const QDBusError &error) { m_if->setError(error.name(), error.message()); Q_EMIT holdAndAnswerComplete(false); } void OfonoVoiceCallManager::releaseAndAnswerResp() { Q_EMIT releaseAndAnswerComplete(true); } void OfonoVoiceCallManager::releaseAndAnswerErr(const QDBusError &error) { m_if->setError(error.name(), error.message()); Q_EMIT releaseAndAnswerComplete(false); } void OfonoVoiceCallManager::swapCallsResp() { Q_EMIT swapCallsComplete(true); } void OfonoVoiceCallManager::swapCallsErr(const QDBusError &error) { m_if->setError(error.name(), error.message()); Q_EMIT swapCallsComplete(false); } void OfonoVoiceCallManager::hangupAllResp() { Q_EMIT hangupAllComplete(true); } void OfonoVoiceCallManager::hangupAllErr(const QDBusError &error) { m_if->setError(error.name(), error.message()); Q_EMIT hangupAllComplete(false); } void OfonoVoiceCallManager::sendTonesResp() { Q_EMIT sendTonesComplete(true); } void OfonoVoiceCallManager::sendTonesErr(const QDBusError &error) { m_if->setError(error.name(), error.message()); Q_EMIT sendTonesComplete(false); } void OfonoVoiceCallManager::transferResp() { Q_EMIT transferComplete(true); } void OfonoVoiceCallManager::transferErr(const QDBusError &error) { m_if->setError(error.name(), error.message()); Q_EMIT transferComplete(false); } QStringList OfonoVoiceCallManager::emergencyNumbers() const { return m_if->properties()["EmergencyNumbers"].value(); } void OfonoVoiceCallManager::propertyChanged(const QString &property, const QVariant &value) { if (property == "EmergencyNumbers") { Q_EMIT emergencyNumbersChanged(value.value()); } } QStringList OfonoVoiceCallManager::getCalls() const { return m_calllist; } void OfonoVoiceCallManager::callAddedChanged(const QDBusObjectPath &path, const QVariantMap& values) { m_calllist << path.path(); Q_EMIT callAdded(path.path(), values); } void OfonoVoiceCallManager::callRemovedChanged(const QDBusObjectPath &path) { m_calllist.removeAll(path.path()); Q_EMIT callRemoved(path.path()); } telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonointerface.cpp0000644000015301777760000001502712320626651024677 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include #include #include "ofonointerface.h" #define GET_PROPERTIES_TIMEOUT 300000 #define SET_PROPERTY_TIMEOUT 300000 OfonoInterface::OfonoInterface(const QString& path, const QString& ifname, OfonoGetPropertySetting setting, QObject *parent) : QObject(parent) , m_path(path), m_ifname(ifname), m_getpropsetting(setting) { QDBusConnection::sessionBus().connect("org.ofono", path, ifname, "PropertyChanged", this, SLOT(onPropertyChanged(QString, QDBusVariant))); if (setting == OfonoGetAllOnStartup && path != "/") m_properties = getAllPropertiesSync(); } OfonoInterface::~OfonoInterface() { } void OfonoInterface::setPath(const QString& path) { QDBusConnection::sessionBus().disconnect("org.ofono", m_path, m_ifname, "PropertyChanged", this, SLOT(onPropertyChanged(QString, QDBusVariant))); m_path = path; QDBusConnection::sessionBus().connect("org.ofono", m_path, m_ifname, "PropertyChanged", this, SLOT(onPropertyChanged(QString, QDBusVariant))); if (m_getpropsetting == OfonoGetAllOnStartup) m_properties = getAllPropertiesSync(); else resetProperties(); } QVariantMap OfonoInterface::properties() const { return m_properties; } void OfonoInterface::resetProperties() { m_properties = QVariantMap(); } QVariantMap OfonoInterface::getAllPropertiesSync() { QDBusReply reply; QVariantMap map; QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", m_path, m_ifname, "GetProperties"); reply = QDBusConnection::sessionBus().call(request); map = reply; Q_FOREACH (QString property, map.keys()) { Q_EMIT propertyChanged(property, map[property]); } return map; } void OfonoInterface::requestProperty(const QString& name) { if (m_pendingProperty.length() > 0) { // FIXME: should indicate that a get/setProperty is already in progress setError(QString(), QString("Already in progress")); Q_EMIT requestPropertyComplete(false, name, QVariant()); return; } if (m_properties.keys().contains(name)) { Q_EMIT requestPropertyComplete(true, name, m_properties[name]); return; } QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", m_path, m_ifname, "GetProperties"); bool result = QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(getPropertiesAsyncResp(QVariantMap)), SLOT(getPropertiesAsyncErr(const QDBusError&)), GET_PROPERTIES_TIMEOUT); if (!result) { // FIXME: should indicate that sending a message failed setError(QString(), QString("Sending a message failed")); Q_EMIT requestPropertyComplete(false, name, QVariant()); return; } m_pendingProperty = name; } void OfonoInterface::getPropertiesAsyncResp(QVariantMap properties) { QString prop = m_pendingProperty; m_properties = properties; m_pendingProperty = QString(); if (m_properties.keys().contains(prop)) { Q_EMIT requestPropertyComplete(true, prop, m_properties[prop]); } else { // FIXME: should indicate that property is not available setError(QString(), QString("Property not available")); Q_EMIT requestPropertyComplete(false, prop, QVariant()); } Q_FOREACH (QString property, properties.keys()) { Q_EMIT propertyChanged(property, properties[property]); } } void OfonoInterface::getPropertiesAsyncErr(const QDBusError& error) { QString prop = m_pendingProperty; setError(error.name(), error.message()); m_pendingProperty = QString(); Q_EMIT requestPropertyComplete(false, prop, QVariant()); } void OfonoInterface::onPropertyChanged(QString property, QDBusVariant value) { qDebug() << "OfonoInterface::onPropertyChanged" << property << value.variant(); m_properties[property] = value.variant(); Q_EMIT propertyChanged(property, value.variant()); } void OfonoInterface::setProperty(const QString& name, const QVariant& property, const QString& password) { if (m_pendingProperty.length() > 0) { // FIXME: should indicate that a get/setProperty is already in progress setError(QString(), QString("Already in progress")); Q_EMIT setPropertyFailed(name); return; } QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono", m_path, m_ifname, "SetProperty"); QVariantList arguments; arguments << QVariant(name) << QVariant::fromValue(QDBusVariant(property)); if (!password.isNull()) arguments << QVariant(password); request.setArguments(arguments); bool result = QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(setPropertyResp()), SLOT(setPropertyErr(const QDBusError&)), SET_PROPERTY_TIMEOUT); if (!result) { // FIXME: should indicate that sending a message failed setError(QString(), QString("Sending a message failed")); Q_EMIT setPropertyFailed(name); return; } m_pendingProperty = name; } void OfonoInterface::setPropertyResp() { m_pendingProperty = QString(); // Q_EMIT nothing; we will get a PropertyChanged signal } void OfonoInterface::setPropertyErr(const QDBusError& error) { QString prop = m_pendingProperty; setError(error.name(), error.message()); m_pendingProperty = QString(); Q_EMIT setPropertyFailed(prop); } void OfonoInterface::setError(const QString& errorName, const QString& errorMessage) { m_errorName = errorName; m_errorMessage = errorMessage; } telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonomodemmanager.h0000644000015301777760000000336412320626651025041 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef OFONOMODEMMANAGER_H #define OFONOMODEMMANAGER_H #include #include #include #include #include "libofono-qt_global.h" //! Provides access to the list of available modems and changes in that list. class OFONO_QT_EXPORT OfonoModemManager : public QObject { Q_OBJECT public: OfonoModemManager(QObject *parent=0); ~OfonoModemManager(); //! Returns a list of d-bus object paths that represent available modems Q_INVOKABLE QStringList modems() const; Q_SIGNALS: //! Issued when a modem has been added void modemAdded(const QString &modemPath); //! Issued when a modem has been removed void modemRemoved(const QString &modemPath); private Q_SLOTS: void onModemAdded(const QDBusObjectPath &path, const QVariantMap &map); void onModemRemoved(const QDBusObjectPath &path); private: QStringList m_modems; }; #endif telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonovoicecallmanager.h0000644000015301777760000001070612320626651025677 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * Portions of this file are Copyright (C) 2011 Intel Corporation * Contact: Shane Bryan * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef OFONOVOICECALLMANAGER_H #define OFONOVOICECALLMANAGER_H #include #include #include #include #include "ofonomodeminterface.h" #include "libofono-qt_global.h" struct OfonoVoiceCallManagerStruct { QDBusObjectPath path; QVariantMap properties; }; typedef QList OfonoVoiceCallManagerList; Q_DECLARE_METATYPE(OfonoVoiceCallManagerStruct) Q_DECLARE_METATYPE(OfonoVoiceCallManagerList) //! This class is used to access oFono voice call manager API /*! * The API is documented in * http://git.kernel.org/?p=network/ofono/ofono.git;a=blob_plain;f=doc/voicecallmanager-api.txt */ class OFONO_QT_EXPORT OfonoVoiceCallManager : public OfonoModemInterface { Q_OBJECT Q_PROPERTY(QStringList emergencyNumbers READ emergencyNumbers NOTIFY emergencyNumbersChanged) public: OfonoVoiceCallManager(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent=0); ~OfonoVoiceCallManager(); /* Properties */ QStringList emergencyNumbers() const; Q_INVOKABLE QStringList getCalls() const; public Q_SLOTS: QDBusObjectPath dial(const QString &number, const QString &callerid_hide, bool &success); void hangupAll(); void sendTones(const QString &tonestring); void transfer(); void swapCalls(); void releaseAndAnswer(); void holdAndAnswer(); void privateChat(const QString &path); QList createMultiparty(); void hangupMultiparty(); Q_SIGNALS: void emergencyNumbersChanged(const QStringList &numbers); void callAdded(const QString &call, const QVariantMap &values); void callRemoved(const QString &call); void hangupAllComplete(const bool status); void sendTonesComplete(const bool status); void transferComplete(const bool status); void swapCallsComplete(const bool status); void releaseAndAnswerComplete(const bool status); void holdAndAnswerComplete(const bool status); void privateChatComplete(const bool status, const QStringList& calls); void createMultipartyComplete(const bool status, const QStringList& calls); void hangupMultipartyComplete(const bool status); void barringActive(const QString &type); void forwarded(const QString &type); private Q_SLOTS: void validityChanged(bool); void pathChanged(const QString& path); void propertyChanged(const QString &property, const QVariant &value); void callAddedChanged(const QDBusObjectPath &call, const QVariantMap &values); void callRemovedChanged(const QDBusObjectPath &call); void hangupAllResp(); void hangupAllErr(const QDBusError &error); void sendTonesResp(); void sendTonesErr(const QDBusError &error); void transferResp(); void transferErr(const QDBusError &error); void swapCallsResp(); void swapCallsErr(const QDBusError &error); void releaseAndAnswerResp(); void releaseAndAnswerErr(const QDBusError &error); void holdAndAnswerResp(); void holdAndAnswerErr(const QDBusError &error); void privateChatResp(const QList &paths); void privateChatErr(const QDBusError &error); void createMultipartyResp(const QList &paths); void createMultipartyErr(const QDBusError &error); void hangupMultipartyResp(); void hangupMultipartyErr(const QDBusError &error); private: QStringList getCallList(); void connectDbusSignals(const QString& path); private: QStringList m_calllist; }; #endif /* !OFONOVOICECALLMANAGER_H */ telepathy-ofono-0.2+14.04.20140407/tests/mock/voicecallmanagerprivate.h0000644000015301777760000000421212320626651026224 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef VOICECALLMANAGERPRIVATE_H #define VOICECALLMANAGERPRIVATE_H #include #include #include "mock_common.h" class OfonoVoiceCall; class VoiceCallManagerPrivate : public QObject, protected QDBusContext { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.ofono.VoiceCallManager") public: VoiceCallManagerPrivate(QObject *parent = 0); ~VoiceCallManagerPrivate(); Q_SIGNALS: void CallRemoved(const QDBusObjectPath &obj); void CallAdded(const QDBusObjectPath &obj, const QVariantMap &value); void PropertyChanged(const QString &name, const QDBusVariant &value); void TonesReceived(const QString &tones); private Q_SLOTS: void onVoiceCallDestroyed(); public Q_SLOTS: QVariantMap GetProperties(); void SetProperty(const QString &name, const QDBusVariant &value); QDBusObjectPath MockIncomingCall(const QString &from); void MockFailNextDtmf(); QDBusObjectPath Dial(const QString &to, const QString &hideCallerId); QMap GetCalls(); void SwapCalls(); void SendTones(const QString &tones); QList CreateMultiparty(); QList PrivateChat(const QDBusObjectPath &path); private: QVariantMap mProperties; QMap mVoiceCalls; int voiceCallCount; bool failNextDtmf; }; extern QMap voiceCallManagerData; #endif telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonomessagewaiting.h0000644000015301777760000000454512320626651025416 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef OFONOMESSAGEWAITING_H #define OFONOMESSAGEWAITING_H #include #include "ofonomodeminterface.h" #include "libofono-qt_global.h" //! This class is used to access oFono message waiting API /*! * oFono message manager API is documented in * http://git.kernel.org/?p=network/ofono/ofono.git;a=blob_plain;f=doc/message-waiting-api.txt */ class OFONO_QT_EXPORT OfonoMessageWaiting : public OfonoModemInterface { Q_OBJECT Q_PROPERTY(bool voicemailWaiting READ voicemailWaiting NOTIFY voicemailWaitingChanged) Q_PROPERTY(int voicemailMessageCount READ voicemailMessageCount NOTIFY voicemailMessageCountChanged) Q_PROPERTY(QString voicemailMailboxNumber READ voicemailMailboxNumber WRITE setVoicemailMailboxNumber NOTIFY voicemailMailboxNumberChanged) public: OfonoMessageWaiting(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent=0); ~OfonoMessageWaiting(); bool voicemailWaiting() const; int voicemailMessageCount() const; QString voicemailMailboxNumber() const; public Q_SLOTS: void setVoicemailMailboxNumber(QString mailboxnumber); Q_SIGNALS: void voicemailWaitingChanged(bool waiting); void voicemailMessageCountChanged(int count); void voicemailMailboxNumberChanged(const QString &mailboxnumber); void setVoicemailMailboxNumberFailed(); private Q_SLOTS: void propertyChanged(const QString& property, const QVariant& value); void setPropertyFailed(const QString& property); }; #endif /* !OFONOMESSAGEWAITING_H */ telepathy-ofono-0.2+14.04.20140407/tests/mock/mock_common.h0000644000015301777760000000047012320626651023640 0ustar pbusernogroup00000000000000#define OFONO_MOCK_MESSAGE_MANAGER_OBJECT "/OfonoMessageManager" #define OFONO_MOCK_MODEM_OBJECT "/OfonoModem" #define OFONO_MOCK_NETWORK_REGISTRATION_OBJECT "/OfonoNetworkRegistration" #define OFONO_MOCK_VOICECALL_MANAGER_OBJECT "/OfonoVoiceCallManager" #define OFONO_MOCK_CALL_VOLUME_OBJECT "/OfonoCallVolume" telepathy-ofono-0.2+14.04.20140407/tests/mock/VoiceCallManagerPrivate.xml0000644000015301777760000000412612320626651026401 0ustar pbusernogroup00000000000000 telepathy-ofono-0.2+14.04.20140407/tests/mock/NetworkRegistrationPrivate.xml0000644000015301777760000000123512320626651027267 0ustar pbusernogroup00000000000000 telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonomessagewaiting.cpp0000644000015301777760000000517412320626651025750 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include #include #include "ofonomessagewaiting.h" #include "ofonointerface.h" OfonoMessageWaiting::OfonoMessageWaiting(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent) : OfonoModemInterface(modemSetting, modemPath, "org.ofono.MessageWaiting", OfonoGetAllOnStartup, parent) { connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), this, SLOT(propertyChanged(const QString&, const QVariant&))); connect(m_if, SIGNAL(setPropertyFailed(const QString&)), this, SLOT(setPropertyFailed(const QString&))); } OfonoMessageWaiting::~OfonoMessageWaiting() { } bool OfonoMessageWaiting::voicemailWaiting() const { return m_if->properties()["VoicemailWaiting"].value(); } int OfonoMessageWaiting::voicemailMessageCount() const { return m_if->properties()["VoicemailMessageCount"].value(); } QString OfonoMessageWaiting::voicemailMailboxNumber() const { return m_if->properties()["VoicemailMailboxNumber"].value(); } void OfonoMessageWaiting::setVoicemailMailboxNumber(QString mailboxnumber) { m_if->setProperty("VoicemailMailboxNumber", qVariantFromValue(mailboxnumber)); } void OfonoMessageWaiting::setPropertyFailed(const QString& property) { if (property == "VoicemailMailboxNumber") Q_EMIT setVoicemailMailboxNumberFailed(); } void OfonoMessageWaiting::propertyChanged(const QString& property, const QVariant& value) { if (property == "VoicemailWaiting") Q_EMIT voicemailWaitingChanged(value.value()); else if (property == "VoicemailMessageCount") Q_EMIT voicemailMessageCountChanged(value.value()); else if (property == "VoicemailMailboxNumber") Q_EMIT voicemailMailboxNumberChanged(value.value()); } telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonocallvolume.cpp0000644000015301777760000000611412320626651025077 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include #include #include "ofonocallvolume.h" #include "ofonointerface.h" #include "callvolumeprivate.h" OfonoCallVolume::OfonoCallVolume(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent) : OfonoModemInterface(modemSetting, modemPath, "org.ofono.CallVolume", OfonoGetAllOnStartup, parent) { if (!callVolumeData.keys().contains(modem()->path())) { m_if->setPath(OFONO_MOCK_CALL_VOLUME_OBJECT); callVolumeData[modem()->path()] = new CallVolumePrivate(); } connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), this, SLOT(propertyChanged(const QString&, const QVariant&))); connect(m_if, SIGNAL(setPropertyFailed(const QString&)), this, SLOT(setPropertyFailed(const QString&))); } OfonoCallVolume::~OfonoCallVolume() { } void OfonoCallVolume::propertyChanged(const QString &property, const QVariant &value) { if (property == "SpeakerVolume") { Q_EMIT speakerVolumeChanged(value.value()); } else if (property == "MicrophoneVolume") { Q_EMIT microphoneVolumeChanged(value.value()); } else if (property == "Muted") { Q_EMIT mutedChanged(value.value()); } } quint8 OfonoCallVolume::speakerVolume() const { return m_if->properties()["SpeakerVolume"].value(); } quint8 OfonoCallVolume::microphoneVolume() const { return m_if->properties()["MicrophoneVolume"].value(); } bool OfonoCallVolume::muted() const { return m_if->properties()["Muted"].value(); } void OfonoCallVolume::setMuted(const bool value) { m_if->setProperty("Muted",QVariant(value)); } void OfonoCallVolume::setPropertyFailed(const QString &property) { if (property == "SpeakerVolume") { Q_EMIT setSpeakerVolumeFailed(); } else if (property == "MicrophoneVolume") { Q_EMIT setMicrophoneVolumeFailed(); } else if (property == "Muted") { Q_EMIT setMutedFailed(); } } void OfonoCallVolume::setSpeakerVolume(const quint8 &spvolume) { m_if->setProperty("SpeakerVolume",qVariantFromValue(spvolume)); } void OfonoCallVolume::setMicrophoneVolume(const quint8 &mpvolume) { m_if->setProperty("MicrophoneVolume",qVariantFromValue(mpvolume)); } telepathy-ofono-0.2+14.04.20140407/tests/mock/messageprivate.cpp0000644000015301777760000000352312320626651024713 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include "messageprivateadaptor.h" QMap messageData; MessagePrivate::MessagePrivate(const QString &path, QObject *parent) : QObject(parent) { QDBusConnection::sessionBus().registerObject(path, this); QDBusConnection::sessionBus().registerService("org.ofono"); SetProperty("State", QDBusVariant(QVariant("pending"))); new MessageAdaptor(this); } MessagePrivate::~MessagePrivate() { } QVariantMap MessagePrivate::GetProperties() { return mProperties; } void MessagePrivate::SetProperty(const QString &name, const QDBusVariant& value) { qDebug() << "MessagePrivate::SetProperty" << name << value.variant(); mProperties[name] = value.variant(); Q_EMIT PropertyChanged(name, value); } void MessagePrivate::Cancel() { SetProperty("State", QDBusVariant(QVariant("failed"))); deleteLater(); } void MessagePrivate::MockMarkFailed() { SetProperty("State", QDBusVariant(QVariant("failed"))); deleteLater(); } void MessagePrivate::MockMarkSent() { SetProperty("State", QDBusVariant(QVariant("sent"))); deleteLater(); } telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonomodeminterface.cpp0000644000015301777760000000502012320626651025711 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include #include #include "ofonomodeminterface.h" #include "ofonomodem.h" #include "ofonointerface.h" OfonoModemInterface::OfonoModemInterface(OfonoModem::SelectionSetting modemSetting, const QString& modemPath, const QString& ifname, OfonoGetPropertySetting propertySetting, QObject *parent) : QObject(parent) { m_m = new OfonoModem(modemSetting, modemPath, this); connect(m_m, SIGNAL(validityChanged(bool)), this, SLOT(modemValidityChanged(bool))); connect(m_m, SIGNAL(interfacesChanged(QStringList)), this, SLOT(interfacesChanged(QStringList))); m_if = new OfonoInterface(m_m->path(), ifname, propertySetting, this); connect(m_m, SIGNAL(pathChanged(QString)), m_if, SLOT(setPath(const QString&))); m_isValid = checkValidity(); } OfonoModemInterface::~OfonoModemInterface() { } bool OfonoModemInterface::isValid() const { return m_isValid; } OfonoModem* OfonoModemInterface::modem() const { return m_m; } bool OfonoModemInterface::checkValidity() { return (m_m->isValid() && m_m->interfaces().contains(m_if->ifname())); } void OfonoModemInterface::updateValidity() { if (isValid() != checkValidity()) { m_isValid = checkValidity(); Q_EMIT validityChanged(isValid()); } } void OfonoModemInterface::modemValidityChanged(bool /*validity*/) { updateValidity(); } void OfonoModemInterface::interfacesChanged(const QStringList& /*interfaces*/) { updateValidity(); } QString OfonoModemInterface::path() const { return m_if->path(); } QString OfonoModemInterface::errorName() const { return m_if->errorName(); } QString OfonoModemInterface::errorMessage() const { return m_if->errorMessage(); } telepathy-ofono-0.2+14.04.20140407/tests/mock/CMakeLists.txt0000644000015301777760000000306012320626651023724 0ustar pbusernogroup00000000000000set(library_SRCS callvolumeprivate.cpp messagemanagerprivate.cpp messageprivate.cpp modemprivate.cpp voicecallmanagerprivate.cpp voicecallprivate.cpp networkregistrationprivate.cpp ofonocallvolume.cpp ofonointerface.cpp ofonomessage.cpp ofonomessagemanager.cpp ofonomessagewaiting.cpp ofonomodem.cpp ofonomodeminterface.cpp ofonomodemmanager.cpp ofononetworkregistration.cpp ofonovoicecall.cpp ofonovoicecallmanager.cpp ) include_directories( ${CMAKE_BINARY_DIR} ) qt5_add_dbus_adaptor(library_SRCS CallVolumePrivate.xml callvolumeprivate.h CallVolumePrivate) qt5_add_dbus_adaptor(library_SRCS ModemPrivate.xml modemprivate.h ModemPrivate) qt5_add_dbus_adaptor(library_SRCS NetworkRegistrationPrivate.xml networkregistrationprivate.h NetworkRegistrationPrivate) qt5_add_dbus_adaptor(library_SRCS MessageManagerPrivate.xml messagemanagerprivate.h MessageManagerPrivate) qt5_add_dbus_adaptor(library_SRCS MessagePrivate.xml messageprivate.h MessagePrivate) qt5_add_dbus_adaptor(library_SRCS VoiceCallManagerPrivate.xml voicecallmanagerprivate.h VoiceCallManagerPrivate) qt5_add_dbus_adaptor(library_SRCS VoiceCallPrivate.xml voicecallprivate.h VoiceCallPrivate) add_library(ofono-qt SHARED ${library_SRCS}) # Set the library version and the SOVERSION #set_target_properties(historyservice PROPERTIES # SOVERSION ${HISTORY_VERSION_MAJOR} # VERSION ${HISTORY_VERSION_MAJOR}.${HISTORY_VERSION_MINOR}.${HISTORY_VERSION_PATCH}) qt5_use_modules(ofono-qt Core DBus) telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonomessage.h0000644000015301777760000000476512320626651024037 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef OFONOMESSAGE_H #define OFONOMESSAGE_H #include #include #include #include #include "libofono-qt_global.h" class OfonoInterface; //! This class is used to access oFono message API /*! * oFono message API is documented in * http://git.kernel.org/?p=network/ofono/ofono.git;a=blob_plain;f=doc/message-api.txt */ class OFONO_QT_EXPORT OfonoMessage : public QObject { Q_OBJECT Q_PROPERTY(QString path READ path) Q_PROPERTY(QString errorName READ errorName) Q_PROPERTY(QString errorMessage READ errorMessage) Q_PROPERTY(QString state READ state NOTIFY stateChanged) public: OfonoMessage(const QString &messageId, QObject *parent=0); OfonoMessage(const OfonoMessage &message); ~OfonoMessage(); OfonoMessage operator=(const OfonoMessage &message); bool operator==(const OfonoMessage &message); //! Returns the D-Bus object path of the message object QString path() const; //! Get the D-Bus error name of the last operation. /*! * Returns the D-Bus error name of the last operation (setting a property * or calling a method) if it has failed */ QString errorName() const; //! Get the D-Bus error message of the last operation. /*! * Returns the D-Bus error message of the last operation (setting a property * or calling a method) if it has failed */ QString errorMessage() const; QString state() const; Q_SIGNALS: void stateChanged(const QString &state); private Q_SLOTS: void propertyChanged(const QString &property, const QVariant &value); private: OfonoInterface *m_if; }; #endif // OFONOMESSAGE_H telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonomodem.cpp0000644000015301777760000001464712320626651024047 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include #include #include "ofonomodem.h" #include "ofonointerface.h" #include "ofonomodemmanager.h" #include "ofonomessage.h" #include "ofonovoicecall.h" #include "modemprivate.h" OfonoModem::OfonoModem(SelectionSetting setting, const QString &modemPath, QObject *parent) : QObject(parent), m_selectionSetting(setting) { m_mm = new OfonoModemManager(this); connect(m_mm, SIGNAL(modemAdded(QString)), this, SLOT(modemAdded(QString))); connect(m_mm, SIGNAL(modemRemoved(QString)), this, SLOT(modemRemoved(QString))); QString finalModemPath; if (setting == AutomaticSelect) finalModemPath = m_mm->modems().value(0); else if (setting == ManualSelect) if (m_mm->modems().contains(modemPath)) finalModemPath = modemPath; if (finalModemPath.isEmpty()) { finalModemPath = "/"; } if (!modemData.keys().contains(finalModemPath)) { modemData[finalModemPath] = new ModemPrivate(); } m_if = new OfonoInterface(finalModemPath, "org.ofono.Modem", OfonoGetAllOnStartup, this); connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), this, SLOT(propertyChanged(const QString&, const QVariant&))); connect(m_if, SIGNAL(setPropertyFailed(const QString&)), this, SLOT(setPropertyFailed(const QString&))); m_isValid = m_mm->modems().contains(finalModemPath); } OfonoModem::~OfonoModem() { } void OfonoModem::propertyChanged(const QString& property, const QVariant& value) { if (property == "Online") Q_EMIT onlineChanged(value.value()); else if (property == "Powered") Q_EMIT poweredChanged(value.value()); else if (property == "Lockdown") Q_EMIT lockdownChanged(value.value()); else if (property == "Emergency") Q_EMIT emergencyChanged(value.value()); else if (property == "Name") Q_EMIT nameChanged(value.value()); else if (property == "Manufacturer") Q_EMIT manufacturerChanged(value.value()); else if (property == "Model") Q_EMIT modelChanged(value.value()); else if (property == "Revision") Q_EMIT revisionChanged(value.value()); else if (property == "Serial") Q_EMIT serialChanged(value.value()); else if (property == "Type") Q_EMIT typeChanged(value.value()); else if (property == "Features") Q_EMIT featuresChanged(value.value()); else if (property == "Interfaces") Q_EMIT interfacesChanged(value.value()); } void OfonoModem::setPropertyFailed(const QString& property) { if (property == "Online") Q_EMIT setOnlineFailed(); else if (property == "Powered") Q_EMIT setPoweredFailed(); else if (property == "Lockdown") Q_EMIT setLockdownFailed(); } void OfonoModem::modemAdded(const QString& /*modem*/) { modemsChanged(); } void OfonoModem::modemRemoved(const QString& /*modem*/) { modemsChanged(); } void OfonoModem::modemsChanged() { // validity has changed if (isValid() != m_mm->modems().contains(path())) { m_isValid = m_mm->modems().contains(path()); Q_EMIT validityChanged(isValid()); } if (!m_mm->modems().contains(path())) { if (m_selectionSetting == AutomaticSelect) { QString modemPath = m_mm->modems().value(0); if (modemPath.isEmpty()) { modemPath = "/"; } m_if->setPath(modemPath); Q_EMIT pathChanged(modemPath); } else if (m_selectionSetting == ManualSelect) { m_if->setPath("/"); } } // validity has changed if (isValid() != m_mm->modems().contains(path())) { m_isValid = m_mm->modems().contains(path()); Q_EMIT validityChanged(isValid()); } } bool OfonoModem::isValid() const { return m_isValid; } QString OfonoModem::path() const { return m_if->path(); } QString OfonoModem::errorName() const { return m_if->errorMessage(); } QString OfonoModem::errorMessage() const { return m_if->errorMessage(); } bool OfonoModem::powered() const { return m_if->properties()["Powered"].value(); } void OfonoModem::setPowered(bool powered) { m_if->setProperty("Powered", qVariantFromValue(powered)); } bool OfonoModem::online() const { return m_if->properties()["Online"].value(); } void OfonoModem::setOnline(bool online) { m_if->setProperty("Online", qVariantFromValue(online)); } bool OfonoModem::lockdown() const { return m_if->properties()["Lockdown"].value(); } void OfonoModem::setLockdown(bool lockdown) { m_if->setProperty("Lockdown", qVariantFromValue(lockdown)); } bool OfonoModem::emergency() const { return m_if->properties()["Emergency"].value(); } QString OfonoModem::name() const { return m_if->properties()["Name"].value(); } QString OfonoModem::manufacturer() const { return m_if->properties()["Manufacturer"].value(); } QString OfonoModem::model() const { return m_if->properties()["Model"].value(); } QString OfonoModem::revision() const { return m_if->properties()["Revision"].value(); } QString OfonoModem::serial() const { return m_if->properties()["Serial"].value(); } QString OfonoModem::type() const { return m_if->properties()["Type"].value(); } QStringList OfonoModem::features() const { return m_if->properties()["Features"].value(); } QStringList OfonoModem::interfaces() const { return m_if->properties()["Interfaces"].value(); } telepathy-ofono-0.2+14.04.20140407/tests/mock/networkregistrationprivate.cpp0000644000015301777760000000275612320626651027422 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include "networkregistrationprivateadaptor.h" QMap networkRegistrationData; NetworkRegistrationPrivate::NetworkRegistrationPrivate(QObject *parent) : QObject(parent) { QDBusConnection::sessionBus().registerObject(OFONO_MOCK_NETWORK_REGISTRATION_OBJECT, this); QDBusConnection::sessionBus().registerService("org.ofono"); new NetworkRegistrationAdaptor(this); } NetworkRegistrationPrivate::~NetworkRegistrationPrivate() { } QVariantMap NetworkRegistrationPrivate::GetProperties() { return mProperties; } void NetworkRegistrationPrivate::SetProperty(const QString &name, const QDBusVariant& value) { mProperties[name] = value.variant(); Q_EMIT PropertyChanged(name, value); } telepathy-ofono-0.2+14.04.20140407/tests/mock/libofono-qt_global.h0000644000015301777760000000207212320626651025110 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef OFONO_QT_GLOBAL_H #define OFONO_QT_GLOBAL_H #include #ifdef BUILD_OFONO_QT_LIBRARY # define OFONO_QT_EXPORT Q_DECL_EXPORT #else # define OFONO_QT_EXPORT Q_DECL_IMPORT #endif #endif // OFONO_QT_GLOBAL_H telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonomodeminterface.h0000644000015301777760000000706112320626651025365 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef OFONOMODEMINTERFACE_H #define OFONOMODEMINTERFACE_H #include #include #include "ofonomodem.h" #include "ofonopropertysetting.h" #include "libofono-qt_global.h" class OfonoInterface; //! This class implements a generic modem interface object /*! * It provides validity checking and modem binding. * It should not be instantiated directly; instead you should instantiate * interface-specific subclasses. */ class OFONO_QT_EXPORT OfonoModemInterface : public QObject { Q_OBJECT Q_PROPERTY(bool isValid READ isValid NOTIFY validityChanged) Q_PROPERTY(QString path READ path) Q_PROPERTY(QString errorName READ errorName) Q_PROPERTY(QString errorMessage READ errorMessage) public: //! Construct a modem interface object /*! * \param modemSetting modem selection setting * \param modemPath path to the modem (may not be significant, depending on modemSetting) * \param ifname d-bus interface name * \param propertySetting oFono d-bus properties setting */ OfonoModemInterface(OfonoModem::SelectionSetting modemSetting, const QString& modemPath, const QString& ifname, OfonoGetPropertySetting propertySetting, QObject *parent=0); ~OfonoModemInterface(); //! Check that the modem interface object is valid /*! * This means that a modem d-bus object * exists and has the d-bus interface specified in the contstructor. */ bool isValid() const; //! Get the modem object that this interface belongs to. /*! * The ownership of the modem object stays with the OfonoModemInterface object. */ OfonoModem *modem() const; //! Returns the D-Bus object path of the interface QString path() const; //! Get the D-Bus error name of the last operation. /*! * Returns the D-Bus error name of the last operation (setting a property * or calling a method) if it has failed */ QString errorName() const; //! Get the D-Bus error message of the last operation. /*! * Returns the D-Bus error message of the last operation (setting a property * or calling a method) if it has failed */ QString errorMessage() const; Q_SIGNALS: //! Interface validity has changed /*! * This may mean that modem has become unavailable * (or available again) or that the modem interface has become unavailable * (or available again) */ void validityChanged(bool validity); private: bool checkValidity(); void updateValidity(); private Q_SLOTS: void modemValidityChanged(bool validity); void interfacesChanged(const QStringList &interfaces); protected: OfonoInterface *m_if; private: OfonoModem *m_m; bool m_isValid; }; #endif telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonomessage.cpp0000644000015301777760000000510412320626651024356 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include #include #include "ofonointerface.h" #include "ofonomessage.h" #include "messageprivate.h" OfonoMessage::OfonoMessage(const QString& messageId, QObject *parent) : QObject(parent) { m_if = new OfonoInterface(messageId, "org.ofono.Message", OfonoGetAllOnStartup, this); if (!messageData.keys().contains(messageId)) { m_if->setPath(messageId); messageData[messageId] = new MessagePrivate(messageId); } connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), this, SLOT(propertyChanged(const QString&, const QVariant&))); } OfonoMessage::OfonoMessage(const OfonoMessage& message) : QObject(message.parent()) { m_if = new OfonoInterface(message.path(), "org.ofono.Message", OfonoGetAllOnStartup, this); if (!messageData.keys().contains(message.path())) { m_if->setPath(message.path()); messageData[message.path()] = new MessagePrivate(message.path()); } connect(m_if, SIGNAL(propertyChanged(const QString&, const QVariant&)), this, SLOT(propertyChanged(const QString&, const QVariant&))); } bool OfonoMessage::operator==(const OfonoMessage &message) { return path() == message.path(); } OfonoMessage::~OfonoMessage() { } QString OfonoMessage::state() const { return m_if->properties()["State"].value(); } void OfonoMessage::propertyChanged(const QString &property, const QVariant &value) { if (property == "State") { Q_EMIT stateChanged(value.value()); } } QString OfonoMessage::path() const { return m_if->path(); } QString OfonoMessage::errorName() const { return m_if->errorName(); } QString OfonoMessage::errorMessage() const { return m_if->errorMessage(); } telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonomessagemanager.h0000644000015301777760000000744212320626651025365 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef OFONOMESSAGEMANAGER_H #define OFONOMESSAGEMANAGER_H #include #include #include #include "ofonomodeminterface.h" #include "libofono-qt_global.h" struct OfonoMessageManagerStruct { QDBusObjectPath path; QVariantMap properties; }; typedef QList OfonoMessageManagerList; Q_DECLARE_METATYPE(OfonoMessageManagerStruct) Q_DECLARE_METATYPE(OfonoMessageManagerList) //! This class is used to access oFono message manager API /*! * oFono message manager API is documented in * http://git.kernel.org/?p=network/ofono/ofono.git;a=blob_plain;f=doc/messagemanager-api.txt */ class OFONO_QT_EXPORT OfonoMessageManager : public OfonoModemInterface { Q_OBJECT public: OfonoMessageManager(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent=0); ~OfonoMessageManager(); Q_INVOKABLE QStringList getMessages() const; public Q_SLOTS: /* Properties */ void requestServiceCenterAddress(); void setServiceCenterAddress(QString address); void requestUseDeliveryReports(); void setUseDeliveryReports(bool useDeliveryReports); void requestBearer(); void setBearer(QString bearer); void requestAlphabet(); void setAlphabet(QString alphabet); QDBusObjectPath sendMessage(const QString &to, const QString &message, bool &success); Q_SIGNALS: void serviceCenterAddressChanged(const QString &address); void useDeliveryReportsChanged(const bool &useDeliveryReports); void bearerChanged(const QString &bearer); void alphabetChanged(const QString &alphabet); void serviceCenterAddressComplete(bool success, const QString &address); void useDeliveryReportsComplete(bool success, const bool &useDeliveryReports); void bearerComplete(bool success, const QString &bearer); void alphabetComplete(bool success, const QString &alphabet); void setServiceCenterAddressFailed(); void setUseDeliveryReportsFailed(); void setBearerFailed(); void setAlphabetFailed(); void messageAdded(const QString &message); void messageRemoved(const QString &message); void immediateMessage(const QString &message, const QVariantMap &info); void incomingMessage(const QString &message, const QVariantMap &info); void statusReport(const QString &message, const QVariantMap &info); private Q_SLOTS: void validityChanged(bool); void pathChanged(const QString& path); void propertyChanged(const QString &property, const QVariant &value); void setPropertyFailed(const QString &property); void requestPropertyComplete(bool success, const QString &property, const QVariant &value); void onMessageAdded(const QDBusObjectPath &message, const QVariantMap &properties); void onMessageRemoved(const QDBusObjectPath &message); private: QStringList getMessageList(); void connectDbusSignals(const QString& path); private: QStringList m_messagelist; }; #endif /* !OFONOMESSAGEMANAGER_H */ telepathy-ofono-0.2+14.04.20140407/tests/mock/modemprivate.cpp0000644000015301777760000000562212320626651024372 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include "modemprivate.h" #include "modemprivateadaptor.h" QMap modemData; ModemPrivate::ModemPrivate(QObject *parent) : QObject(parent) { QDBusConnection::sessionBus().registerObject(OFONO_MOCK_MODEM_OBJECT, this); QDBusConnection::sessionBus().registerService("org.ofono"); SetProperty("Powered", QDBusVariant(QVariant(false))); SetProperty("Online", QDBusVariant(QVariant(false))); SetProperty("Lockdown", QDBusVariant(QVariant(false))); SetProperty("Emergency", QDBusVariant(QVariant(false))); SetProperty("Name", QDBusVariant(QVariant("Mock Modem"))); SetProperty("Manufacturer", QDBusVariant(QVariant("Canonical"))); SetProperty("Model", QDBusVariant(QVariant("Mock Modem"))); SetProperty("Revision", QDBusVariant(QVariant("1.0"))); SetProperty("Serial", QDBusVariant(QVariant("ABC123"))); SetProperty("Type", QDBusVariant(QVariant("Software"))); SetProperty("Features", QDBusVariant(QVariant(QStringList() << "gprs" << "cbs" << "net" << "sms" << "sim"))); SetProperty("Interfaces", QDBusVariant(QVariant(QStringList() << "org.ofono.ConnectionManager" << "org.ofono.AssistedSatelliteNavigation" << "org.ofono.CellBroadcast" << "org.ofono.NetworkRegistration" << "org.ofono.CallVolume" << "org.ofono.CallMeter" << "org.ofono.SupplementaryServices" << "org.ofono.CallBarring" << "org.ofono.CallSettings" << "org.ofono.MessageWaiting" << "org.ofono.SmartMessaging" << "org.ofono.PushNotification" << "org.ofono.MessageManager" << "org.ofono.Phonebook" << "org.ofono.TextTelephony" << "org.ofono.CallForwarding" << "org.ofono.SimToolkit" << "org.ofono.NetworkTime" << "org.ofono.VoiceCallManager" << "org.ofono.SimManager"))); new ModemAdaptor(this); } ModemPrivate::~ModemPrivate() { } void ModemPrivate::MockSetOnline(bool online) { SetProperty("Powered", QDBusVariant(QVariant(online))); SetProperty("Online", QDBusVariant(QVariant(online))); } QVariantMap ModemPrivate::GetProperties() { return mProperties; } void ModemPrivate::SetProperty(const QString &name, const QDBusVariant& value) { mProperties[name] = value.variant(); Q_EMIT PropertyChanged(name, value); } telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonocallvolume.h0000644000015301777760000000456512320626651024554 0ustar pbusernogroup00000000000000/* * This file is part of ofono-qt * * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). * * Contact: Alexander Kanavin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef OFONOCALLVOLUME_H #define OFONOCALLVOLUME_H #include #include "ofonomodeminterface.h" #include "libofono-qt_global.h" //! This class is used to access oFono call volume API /*! * The API is documented in * http://git.kernel.org/?p=network/ofono/ofono.git;a=blob_plain;f=doc/call-volume-api.txt */ class OFONO_QT_EXPORT OfonoCallVolume : public OfonoModemInterface { Q_OBJECT Q_PROPERTY(bool muted READ muted WRITE setMuted NOTIFY mutedChanged) Q_PROPERTY(quint8 speakerVolume READ speakerVolume WRITE setSpeakerVolume NOTIFY speakerVolumeChanged) Q_PROPERTY(quint8 microphoneVolume READ microphoneVolume WRITE setMicrophoneVolume NOTIFY microphoneVolumeChanged) public: OfonoCallVolume(OfonoModem::SelectionSetting modemSetting, const QString &modemPath, QObject *parent=0); ~OfonoCallVolume(); /* Properties */ bool muted() const; quint8 speakerVolume() const; quint8 microphoneVolume()const ; public Q_SLOTS: void setMuted(const bool mute); void setSpeakerVolume(const quint8 &spvolume); void setMicrophoneVolume(const quint8 &mpvolume); Q_SIGNALS: void mutedChanged(const bool &muted); void speakerVolumeChanged(const quint8 &volume); void microphoneVolumeChanged(const quint8 &mvolume); void setMutedFailed(); void setSpeakerVolumeFailed(); void setMicrophoneVolumeFailed(); private Q_SLOTS: void propertyChanged(const QString& property, const QVariant& value); void setPropertyFailed(const QString& property); }; #endif // OFONOCALLVOLUME_H telepathy-ofono-0.2+14.04.20140407/tests/mock/ofonomodemmanager.cpp0000644000015301777760000000074612320626651025375 0ustar pbusernogroup00000000000000#include "ofonomodemmanager.h" #include "modemprivate.h" // mock implementation of ofono-qt OfonoModemManager::OfonoModemManager(QObject *parent) : QObject(parent) { } OfonoModemManager::~OfonoModemManager() { } QStringList OfonoModemManager::modems() const { return QStringList() << OFONO_MOCK_MODEM_OBJECT; } void OfonoModemManager::onModemAdded(const QDBusObjectPath &path, const QVariantMap &map) { } void OfonoModemManager::onModemRemoved(const QDBusObjectPath &path) { } telepathy-ofono-0.2+14.04.20140407/tests/telepathyhelper.cpp0000644000015301777760000002103412320626651024137 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: * Tiago Salem Herrmann * Gustavo Pichorim Boiko */ #include "telepathyhelper.h" #include #include #include #include #include #include #include TelepathyHelper::TelepathyHelper(QObject *parent) : QObject(parent), //mChannelObserver(0), mFirstTime(true), mConnected(false), mHandlerInterface(0) { Tp::registerTypes(); mAccountFeatures << Tp::Account::FeatureCore; mContactFeatures << Tp::Contact::FeatureAlias << Tp::Contact::FeatureAvatarData << Tp::Contact::FeatureAvatarToken << Tp::Contact::FeatureCapabilities << Tp::Contact::FeatureSimplePresence; mConnectionFeatures << Tp::Connection::FeatureCore << Tp::Connection::FeatureSelfContact << Tp::Connection::FeatureSimplePresence; Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus()); channelFactory->addCommonFeatures(Tp::Channel::FeatureCore); Tp::ChannelClassSpec audioConferenceSpec(TP_QT_IFACE_CHANNEL_TYPE_CALL, Tp::HandleTypeNone); audioConferenceSpec.setCallInitialAudioFlag(); channelFactory->setSubclassFor(audioConferenceSpec); mAccountManager = Tp::AccountManager::create( Tp::AccountFactory::create(QDBusConnection::sessionBus(), mAccountFeatures), Tp::ConnectionFactory::create(QDBusConnection::sessionBus(), mConnectionFeatures), channelFactory, Tp::ContactFactory::create(mContactFeatures)); connect(mAccountManager->becomeReady(Tp::AccountManager::FeatureCore), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onAccountManagerReady(Tp::PendingOperation*))); mClientRegistrar = Tp::ClientRegistrar::create(mAccountManager); } TelepathyHelper::~TelepathyHelper() { } TelepathyHelper *TelepathyHelper::instance() { static TelepathyHelper* helper = new TelepathyHelper(); return helper; } QString TelepathyHelper::accountId() const { if (mAccount) { return mAccount->uniqueIdentifier(); } return QString(); } Tp::AccountPtr TelepathyHelper::account() const { return mAccount; } /* ChannelObserver *TelepathyHelper::channelObserver() const { return mChannelObserver; } */ bool TelepathyHelper::connected() const { return mConnected; } /* void TelepathyHelper::registerChannelObserver(const QString &observerName) { QString name = observerName; if (name.isEmpty()) { name = "TelephonyPluginObserver"; } if (mChannelObserver) { mChannelObserver->deleteLater(); } mChannelObserver = new ChannelObserver(this); registerClient(mChannelObserver, name); // messages connect(mChannelObserver, SIGNAL(textChannelAvailable(Tp::TextChannelPtr)), ChatManager::instance(), SLOT(onTextChannelAvailable(Tp::TextChannelPtr))); // calls connect(mChannelObserver, SIGNAL(callChannelAvailable(Tp::CallChannelPtr)), CallManager::instance(), SLOT(onCallChannelAvailable(Tp::CallChannelPtr))); Q_EMIT channelObserverCreated(mChannelObserver); } void TelepathyHelper::unregisterChannelObserver() { Tp::AbstractClientPtr clientPtr(mChannelObserver); if (clientPtr) { mClientRegistrar->unregisterClient(clientPtr); } mChannelObserver->deleteLater(); mChannelObserver = NULL; Q_EMIT channelObserverUnregistered(); } */ QStringList TelepathyHelper::supportedProtocols() const { QStringList protocols; protocols << "ufa" << "tel" << "ofono"; return protocols; } void TelepathyHelper::initializeAccount() { // watch for account state and connection changes connect(mAccount.data(), SIGNAL(stateChanged(bool)), SLOT(onAccountStateChanged(bool))); connect(mAccount.data(), SIGNAL(connectionChanged(const Tp::ConnectionPtr&)), SLOT(onAccountConnectionChanged(const Tp::ConnectionPtr&))); // and make sure it is enabled and connected if (!mAccount->isEnabled()) { ensureAccountEnabled(); } else { ensureAccountConnected(); } } void TelepathyHelper::ensureAccountEnabled() { mAccount->setConnectsAutomatically(true); connect(mAccount->setEnabled(true), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onAccountEnabled(Tp::PendingOperation*))); } void TelepathyHelper::ensureAccountConnected() { // if the account is not connected, request it to connect if (!mAccount->connection() || mAccount->connectionStatus() != Tp::ConnectionStatusConnected) { Tp::Presence presence(Tp::ConnectionPresenceTypeAvailable, "available", "online"); mAccount->setRequestedPresence(presence); } else { watchSelfContactPresence(); } if (mFirstTime) { Q_EMIT accountReady(); mFirstTime = false; } } void TelepathyHelper::watchSelfContactPresence() { if (mAccount.isNull() || mAccount->connection().isNull()) { return; } connect(mAccount->connection()->selfContact().data(), SIGNAL(presenceChanged(Tp::Presence)), SLOT(onPresenceChanged(Tp::Presence))); onPresenceChanged(mAccount->connection()->selfContact()->presence()); } void TelepathyHelper::registerClient(Tp::AbstractClient *client, QString name) { Tp::AbstractClientPtr clientPtr(client); bool succeeded = mClientRegistrar->registerClient(clientPtr, name); if (!succeeded) { name.append("%1"); int count = 0; // limit the number of registered clients to 20, that should be a safe margin while (!succeeded && count < 20) { succeeded = mClientRegistrar->registerClient(clientPtr, name.arg(++count)); if (succeeded) { name = name.arg(count); } } } if (succeeded) { QObject *object = dynamic_cast(client); if (object) { object->setProperty("clientName", TP_QT_IFACE_CLIENT + "." + name ); } } } void TelepathyHelper::onAccountManagerReady(Tp::PendingOperation *op) { Q_UNUSED(op) Tp::AccountSetPtr accountSet; // try to find an account of the one of supported protocols Q_FOREACH(const QString &protocol, supportedProtocols()) { accountSet = mAccountManager->accountsByProtocol(protocol); if (accountSet->accounts().count() > 0) { break; } } if (accountSet->accounts().count() == 0) { qCritical() << "No compatible telepathy account found!"; return; } mAccount = accountSet->accounts()[0]; // in case we have more than one account, the first one to show on the list is going to be used if (accountSet->accounts().count() > 1) { qWarning() << "There are more than just one account of type" << mAccount->protocolName(); } Q_EMIT accountIdChanged(); initializeAccount(); } void TelepathyHelper::onAccountEnabled(Tp::PendingOperation *op) { // we might need to do more stuff once the account is enabled, but making sure it is connected is a good start ensureAccountConnected(); } void TelepathyHelper::onAccountStateChanged(bool enabled) { if (!enabled) { ensureAccountEnabled(); } } void TelepathyHelper::onAccountConnectionChanged(const Tp::ConnectionPtr &connection) { if (connection.isNull()) { ensureAccountConnected(); } else { watchSelfContactPresence(); } Q_EMIT connectionChanged(); } void TelepathyHelper::onPresenceChanged(const Tp::Presence &presence) { mConnected = (presence.type() == Tp::ConnectionPresenceTypeAvailable); Q_EMIT connectedChanged(); } telepathy-ofono-0.2+14.04.20140407/tests/ofonomockcontroller.h0000644000015301777760000000423112320626651024503 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: * Tiago Salem Herrmann * Gustavo Pichorim Boiko */ #ifndef OFONOMOCKCONTROLLER_H #define OFONOMOCKCONTROLLER_H #include #include class OfonoMockController : public QObject { Q_OBJECT public: static OfonoMockController *instance(); Q_SIGNALS: void MessageAdded(QDBusObjectPath, QVariantMap); void CallAdded(QDBusObjectPath, QVariantMap); void TonesReceived(QString); void CallVolumeMuteChanged(bool muted); public Q_SLOTS: void NetworkRegistrationSetStatus(const QString &status); void MessageManagerSendMessage(const QString &from, const QString &text); void MessageManagerStatusReport(const QString &message, bool success); void MessageMarkFailed(const QString &objPath); void MessageMarkSent(const QString &objPath); void MessageCancel(const QString &objPath); void VoiceCallManagerIncomingCall(const QString &from); void VoiceCallManagerFailNextDtmf(); void VoiceCallHangup(const QString &objPath); void VoiceCallAnswer(const QString &objPath); void VoiceCallSetAlerting(const QString &objPath); private Q_SLOTS: void onCallVolumePropertyChanged(const QString &name, const QDBusVariant &value); private: explicit OfonoMockController(QObject *parent = 0); QDBusInterface mNetworkRegistrationInterface; QDBusInterface mMessageManagerInterface; QDBusInterface mVoiceCallManagerInterface; }; #endif // OFONOMOCKCONTROLLER_H telepathy-ofono-0.2+14.04.20140407/tests/PhoneUtilsTest.cpp0000644000015301777760000000720112320626651023672 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: * Gustavo Pichorim Boiko */ #include #include #include "phoneutils_p.h" class PhoneUtilsTest : public QObject { Q_OBJECT private Q_SLOTS: void testIsPhoneNumber_data(); void testIsPhoneNumber(); void testComparePhoneNumbers_data(); void testComparePhoneNumbers(); }; void PhoneUtilsTest::testIsPhoneNumber_data() { QTest::addColumn("number"); QTest::addColumn("expectedResult"); QTest::newRow("simple number") << "12345678" << true; QTest::newRow("number with dash") << "1234-5678" << true; QTest::newRow("number with area code") << "(123)12345678" << true; QTest::newRow("number with extension") << "12345678#123" << true; QTest::newRow("number with comma") << "33333333,1,1" << true; QTest::newRow("number with semicolon") << "33333333;1" << true; QTest::newRow("short/emergency number") << "190" << true; QTest::newRow("non phone numbers") << "abcdefg" << false; } void PhoneUtilsTest::testIsPhoneNumber() { QFETCH(QString, number); QFETCH(bool, expectedResult); bool result = PhoneUtils::isPhoneNumber(number); QCOMPARE(result, expectedResult); } void PhoneUtilsTest::testComparePhoneNumbers_data() { QTest::addColumn("number1"); QTest::addColumn("number2"); QTest::addColumn("expectedResult"); QTest::newRow("string equal") << "12345678" << "12345678" << true; QTest::newRow("number with dash") << "1234-5678" << "12345678" << true; QTest::newRow("number with area code") << "12312345678" << "12345678" << true; QTest::newRow("number with extension") << "12345678#123" << "12345678" << false; QTest::newRow("both numbers with extension") << "(123)12345678#1" << "12345678#1" << true; QTest::newRow("numbers with different extension") << "1234567#1" << "1234567#2" << false; QTest::newRow("number with comma") << "33333333,1,1" << "33333333" << true; QTest::newRow("both numbers with comma") << "22222222,1" << "22222222,2,1" << true; QTest::newRow("number with semicolon") << "33333333;1" << "33333333" << true; QTest::newRow("both numbers with semicolon") << "22222222;1" << "22222222;2" << true; QTest::newRow("short/emergency numbers") << "190" << "190" << true; QTest::newRow("different numbers") << "12345678" << "1234567" << false; QTest::newRow("both non phone numbers") << "abcdefg" << "abcdefg" << true; QTest::newRow("different non phone numbers") << "abcdefg" << "bcdefg" << false; QTest::newRow("phone number and custom string") << "abc12345678" << "12345678" << false; // FIXME: check what other cases we need to test here" } void PhoneUtilsTest::testComparePhoneNumbers() { QFETCH(QString, number1); QFETCH(QString, number2); QFETCH(bool, expectedResult); bool result = PhoneUtils::comparePhoneNumbers(number1, number2); QCOMPARE(result, expectedResult); } QTEST_MAIN(PhoneUtilsTest) #include "PhoneUtilsTest.moc" telepathy-ofono-0.2+14.04.20140407/tests/approvertext.cpp0000644000015301777760000000565412320626651023515 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include "approvertext.h" #include #include #include #include #include Approver::Approver(QObject* parent) : QObject(parent), Tp::AbstractClientApprover(channelFilters()) { } Approver::~Approver() { } Tp::ChannelClassSpecList Approver::channelFilters() const { Tp::ChannelClassSpecList specList; specList << Tp::ChannelClassSpec::textChat(); return specList; } void Approver::addDispatchOperation(const Tp::MethodInvocationContextPtr<> &context, const Tp::ChannelDispatchOperationPtr &dispatchOperation) { bool willHandle = false; QList channels = dispatchOperation->channels(); Q_FOREACH (Tp::ChannelPtr channel, channels) { // Text Channel Tp::TextChannelPtr textChannel = Tp::TextChannelPtr::dynamicCast(channel); if (!textChannel.isNull()) { // right now we are not using any of the text channel's features in the approver // so no need to call becomeReady() on it. willHandle = true; } } if (willHandle) { mDispatchOps.append(dispatchOperation); } context->setFinished(); // check if we need to approve channels already or if we should wait. processChannels(); } void Approver::processChannels() { Q_FOREACH (Tp::ChannelDispatchOperationPtr dispatchOperation, mDispatchOps) { QList channels = dispatchOperation->channels(); Q_FOREACH (Tp::ChannelPtr channel, channels) { // approve only text channels Tp::TextChannelPtr textChannel = Tp::TextChannelPtr::dynamicCast(channel); if (textChannel.isNull()) { continue; } if (dispatchOperation->possibleHandlers().contains(TELEPHONY_SERVICE_HANDLER)) { dispatchOperation->handleWith(TELEPHONY_SERVICE_HANDLER); mDispatchOps.removeAll(dispatchOperation); } // FIXME: this shouldn't happen, but in any case, we need to check what to do when // the phone app client is not available } } } telepathy-ofono-0.2+14.04.20140407/tests/approvercall.h0000644000015301777760000000362112320626651023101 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef APPROVER_H #define APPROVER_H #include #include #include #include #define TELEPHONY_SERVICE_HANDLER TP_QT_IFACE_CLIENT + ".TpOfonoTestHandler" #define TELEPHONY_SERVICE_APPROVER TP_QT_IFACE_CLIENT + ".TpOfonoTestApprover" class Approver : public QObject, public Tp::AbstractClientApprover { Q_OBJECT public: Approver(QObject *parent = 0); ~Approver(); Tp::ChannelClassSpecList channelFilters() const; void addDispatchOperation(const Tp::MethodInvocationContextPtr<> &context, const Tp::ChannelDispatchOperationPtr &dispatchOperation); Tp::ChannelDispatchOperationPtr dispatchOperation(Tp::PendingOperation *op); void acceptCall(); void rejectCall(); private Q_SLOTS: void onClaimFinished(Tp::PendingOperation* op); void onHangupFinished(Tp::PendingOperation* op); void onChannelReady(Tp::PendingOperation *op); Q_SIGNALS: void newCall(); private: QList mDispatchOps; QMap mChannels; }; #endif // APPROVER_H telepathy-ofono-0.2+14.04.20140407/tests/approvercall.cpp0000644000015301777760000001144212320626651023434 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include "approvercall.h" #include #include #include #include #include Approver::Approver(QObject* parent) : QObject(parent), Tp::AbstractClientApprover(channelFilters()) { } Approver::~Approver() { } Tp::ChannelClassSpecList Approver::channelFilters() const { Tp::ChannelClassSpecList specList; specList << Tp::ChannelClassSpec::audioCall(); return specList; } void Approver::addDispatchOperation(const Tp::MethodInvocationContextPtr<> &context, const Tp::ChannelDispatchOperationPtr &dispatchOperation) { bool willHandle = false; QList channels = dispatchOperation->channels(); Q_FOREACH (Tp::ChannelPtr channel, channels) { Tp::CallChannelPtr callChannel = Tp::CallChannelPtr::dynamicCast(channel); if (!callChannel.isNull()) { Tp::PendingReady *pr = callChannel->becomeReady(Tp::Features() << Tp::CallChannel::FeatureCore << Tp::CallChannel::FeatureCallState << Tp::CallChannel::FeatureLocalHoldState); mChannels[pr] = callChannel; connect(pr, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onChannelReady(Tp::PendingOperation*))); callChannel->setProperty("accountId", QVariant(dispatchOperation->account()->uniqueIdentifier())); willHandle = true; continue; } } if (willHandle) { mDispatchOps.append(dispatchOperation); } context->setFinished(); } void Approver::acceptCall() { Q_FOREACH (Tp::ChannelDispatchOperationPtr dispatchOperation, mDispatchOps) { QList channels = dispatchOperation->channels(); Q_FOREACH (Tp::ChannelPtr channel, channels) { if (dispatchOperation->possibleHandlers().contains(TELEPHONY_SERVICE_HANDLER)) { dispatchOperation->handleWith(TELEPHONY_SERVICE_HANDLER); mDispatchOps.removeAll(dispatchOperation); } } } } void Approver::rejectCall() { Q_FOREACH (Tp::ChannelDispatchOperationPtr dispatchOperation, mDispatchOps) { QList channels = dispatchOperation->channels(); Q_FOREACH (Tp::ChannelPtr channel, channels) { if (dispatchOperation->possibleHandlers().contains(TELEPHONY_SERVICE_HANDLER)) { Tp::PendingOperation *claimop = dispatchOperation->claim(); mChannels[claimop] = dispatchOperation->channels().first(); connect(claimop, SIGNAL(finished(Tp::PendingOperation*)), this, SLOT(onClaimFinished(Tp::PendingOperation*))); } } } } void Approver::onClaimFinished(Tp::PendingOperation* op) { if(!op || op->isError()) { return; } Tp::CallChannelPtr callChannel = Tp::CallChannelPtr::dynamicCast(mChannels[op]); if (callChannel) { Tp::PendingOperation *hangupop = callChannel->hangup(Tp::CallStateChangeReasonUserRequested, TP_QT_ERROR_REJECTED, QString()); mChannels[hangupop] = callChannel; connect(hangupop, SIGNAL(finished(Tp::PendingOperation*)), this, SLOT(onHangupFinished(Tp::PendingOperation*))); } } void Approver::onHangupFinished(Tp::PendingOperation* op) { if(!op || op->isError()) { return; } mDispatchOps.removeAll(dispatchOperation(op)); mChannels.remove(op); } Tp::ChannelDispatchOperationPtr Approver::dispatchOperation(Tp::PendingOperation *op) { Tp::ChannelPtr channel = mChannels[op]; QString accountId = channel->property("accountId").toString(); Q_FOREACH (Tp::ChannelDispatchOperationPtr dispatchOperation, mDispatchOps) { if (dispatchOperation->account()->uniqueIdentifier() == accountId) { return dispatchOperation; } } return Tp::ChannelDispatchOperationPtr(); } void Approver::onChannelReady(Tp::PendingOperation *op) { Q_EMIT newCall(); } telepathy-ofono-0.2+14.04.20140407/tests/telepathyhelper.h0000644000015301777760000000602712320626651023611 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: * Tiago Salem Herrmann * Gustavo Pichorim Boiko */ #ifndef TELEPATHYHELPER_H #define TELEPATHYHELPER_H #include #include #include #include #include #include //#include "channelobserver.h" #define CANONICAL_TELEPHONY_VOICEMAIL_IFACE "com.canonical.Telephony.Voicemail" #define CANONICAL_TELEPHONY_SPEAKER_IFACE "com.canonical.Telephony.Speaker" class TelepathyHelper : public QObject { Q_OBJECT Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged) Q_PROPERTY(QString accountId READ accountId NOTIFY accountIdChanged) public: ~TelepathyHelper(); static TelepathyHelper *instance(); Tp::AccountPtr account() const; //ChannelObserver *channelObserver() const; bool connected() const; QString accountId() const; void registerClient(Tp::AbstractClient *client, QString name); Q_SIGNALS: //void channelObserverCreated(ChannelObserver *observer); //void channelObserverUnregistered(); void accountReady(); void connectionChanged(); void connectedChanged(); void accountIdChanged(); public Q_SLOTS: //Q_INVOKABLE void registerChannelObserver(const QString &observerName = QString::null); //Q_INVOKABLE void unregisterChannelObserver(); protected: QStringList supportedProtocols() const; void initializeAccount(); void ensureAccountEnabled(); void ensureAccountConnected(); void watchSelfContactPresence(); private Q_SLOTS: void onAccountManagerReady(Tp::PendingOperation *op); void onAccountEnabled(Tp::PendingOperation *op); void onAccountStateChanged(bool enabled); void onAccountConnectionChanged(const Tp::ConnectionPtr &connection); void onPresenceChanged(const Tp::Presence &presence); private: explicit TelepathyHelper(QObject *parent = 0); Tp::AccountManagerPtr mAccountManager; Tp::Features mAccountManagerFeatures; Tp::Features mAccountFeatures; Tp::Features mContactFeatures; Tp::Features mConnectionFeatures; Tp::ClientRegistrarPtr mClientRegistrar; Tp::AccountPtr mAccount; //ChannelObserver *mChannelObserver; bool mFirstTime; bool mConnected; QDBusInterface *mHandlerInterface; }; #endif // TELEPATHYHELPER_H telepathy-ofono-0.2+14.04.20140407/tests/CallTest.cpp0000644000015301777760000005077512320626651022471 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include #include #include #include #include #include #include #include "telepathyhelper.h" #include "ofonomockcontroller.h" #include "handler.h" #include "approvercall.h" Q_DECLARE_METATYPE(Tp::CallChannelPtr); Q_DECLARE_METATYPE(Tp::ChannelPtr); Q_DECLARE_METATYPE(Tp::CallState); Q_DECLARE_METATYPE(QList); #define TELEPATHY_MUTE_IFACE "org.freedesktop.Telepathy.Call1.Interface.Mute" class CallTest : public QObject { Q_OBJECT Q_SIGNALS: void contactsReceived(QList contacts); private Q_SLOTS: void initTestCase(); void testCallIncoming(); void testCallIncomingPrivateNumber(); void testCallIncomingUnknownNumber(); void testCallOutgoing(); void testCallHold(); void testCallDTMF(); void testCallMute(); void testCallConference(); // helper slots void onPendingContactsFinished(Tp::PendingOperation*); private: Approver *mApprover; Handler *mHandler; }; void CallTest::initTestCase() { qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType >(); TelepathyHelper::instance(); QSignalSpy spy(TelepathyHelper::instance(), SIGNAL(accountReady())); QTRY_COMPARE(spy.count(), 1); OfonoMockController::instance()->NetworkRegistrationSetStatus("registered"); // the account should be connected QTRY_VERIFY(TelepathyHelper::instance()->connected()); mHandler = new Handler(this); TelepathyHelper::instance()->registerClient(mHandler, "TpOfonoTestHandler"); QTRY_VERIFY(mHandler->isRegistered()); mApprover = new Approver(this); TelepathyHelper::instance()->registerClient(mApprover, "TpOfonoTestApprover"); QTRY_VERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(TELEPHONY_SERVICE_APPROVER)); // we need to wait in order to give telepathy time to notify about the approver and handler QTest::qWait(10000); } void CallTest::testCallIncoming() { QSignalSpy spyNewCallChannel(mHandler, SIGNAL(callChannelAvailable(Tp::CallChannelPtr))); QSignalSpy spyNewCallApprover(mApprover, SIGNAL(newCall())); QSignalSpy spyOfonoCallAdded(OfonoMockController::instance(), SIGNAL(CallAdded(QDBusObjectPath, QVariantMap))); OfonoMockController::instance()->VoiceCallManagerIncomingCall("123"); QTRY_COMPARE(spyOfonoCallAdded.count(), 1); QTRY_COMPARE(spyNewCallApprover.count(), 1); mApprover->acceptCall(); QTRY_COMPARE(spyNewCallChannel.count(), 1); Tp::CallChannelPtr channel = spyNewCallChannel.first().first().value(); QVERIFY(channel); QDBusObjectPath path = spyOfonoCallAdded.first().first().value(); OfonoMockController::instance()->VoiceCallHangup(path.path()); QTRY_COMPARE(channel->callState(), Tp::CallStateEnded); } void CallTest::testCallIncomingPrivateNumber() { QSignalSpy spyNewCallChannel(mHandler, SIGNAL(callChannelAvailable(Tp::CallChannelPtr))); QSignalSpy spyNewCallApprover(mApprover, SIGNAL(newCall())); QSignalSpy spyOfonoCallAdded(OfonoMockController::instance(), SIGNAL(CallAdded(QDBusObjectPath, QVariantMap))); OfonoMockController::instance()->VoiceCallManagerIncomingCall("withheld"); QTRY_COMPARE(spyOfonoCallAdded.count(), 1); QTRY_COMPARE(spyNewCallApprover.count(), 1); mApprover->acceptCall(); QTRY_COMPARE(spyNewCallChannel.count(), 1); Tp::CallChannelPtr channel = spyNewCallChannel.first().first().value(); QVERIFY(channel); QCOMPARE(channel->initiatorContact()->id(), QString("x-ofono-private")); QDBusObjectPath path = spyOfonoCallAdded.first().first().value(); OfonoMockController::instance()->VoiceCallHangup(path.path()); QTRY_COMPARE(channel->callState(), Tp::CallStateEnded); } void CallTest::testCallIncomingUnknownNumber() { QSignalSpy spyNewCallChannel(mHandler, SIGNAL(callChannelAvailable(Tp::CallChannelPtr))); QSignalSpy spyNewCallApprover(mApprover, SIGNAL(newCall())); QSignalSpy spyOfonoCallAdded(OfonoMockController::instance(), SIGNAL(CallAdded(QDBusObjectPath, QVariantMap))); OfonoMockController::instance()->VoiceCallManagerIncomingCall(""); QTRY_COMPARE(spyOfonoCallAdded.count(), 1); QTRY_COMPARE(spyNewCallApprover.count(), 1); mApprover->acceptCall(); QTRY_COMPARE(spyNewCallChannel.count(), 1); Tp::CallChannelPtr channel = spyNewCallChannel.first().first().value(); QVERIFY(channel); QCOMPARE(channel->initiatorContact()->id(), QString("x-ofono-unknown")); QDBusObjectPath path = spyOfonoCallAdded.first().first().value(); OfonoMockController::instance()->VoiceCallHangup(path.path()); QTRY_COMPARE(channel->callState(), Tp::CallStateEnded); } void CallTest::testCallOutgoing() { // Request the contact to start chatting to Tp::AccountPtr account = TelepathyHelper::instance()->account(); QSignalSpy spy(this, SIGNAL(contactsReceived(QList))); connect(account->connection()->contactManager()->contactsForIdentifiers(QStringList() << "321"), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onPendingContactsFinished(Tp::PendingOperation*))); QTRY_COMPARE(spy.count(), 1); QList contacts = spy.first().first().value >(); QCOMPARE(contacts.count(), 1); QCOMPARE(contacts.first()->id(), QString("321")); QSignalSpy spyOfonoCallAdded(OfonoMockController::instance(), SIGNAL(CallAdded(QDBusObjectPath, QVariantMap))); QSignalSpy spyCallChannel(mHandler, SIGNAL(callChannelAvailable(Tp::CallChannelPtr))); Q_FOREACH(Tp::ContactPtr contact, contacts) { account->ensureAudioCall(contact, "audio", QDateTime::currentDateTime(), TP_QT_IFACE_CLIENT + ".TpOfonoTestHandler"); } QTRY_COMPARE(spyOfonoCallAdded.count(), 1); QTRY_COMPARE(spyCallChannel.count(), 1); QDBusObjectPath path = spyOfonoCallAdded.first().first().value(); Tp::CallChannelPtr channel = spyCallChannel.first().first().value(); QVERIFY(channel); OfonoMockController::instance()->VoiceCallSetAlerting(path.path()); QTRY_COMPARE(channel->callState(), Tp::CallStateInitialised); OfonoMockController::instance()->VoiceCallAnswer(path.path()); QTRY_COMPARE(channel->callState(), Tp::CallStateActive); OfonoMockController::instance()->VoiceCallHangup(path.path()); QTRY_COMPARE(channel->callState(), Tp::CallStateEnded); } void CallTest::testCallHold() { QSignalSpy spyNewCallChannel(mHandler, SIGNAL(callChannelAvailable(Tp::CallChannelPtr))); QSignalSpy spyNewCallApprover(mApprover, SIGNAL(newCall())); OfonoMockController::instance()->VoiceCallManagerIncomingCall("123"); QTRY_COMPARE(spyNewCallApprover.count(), 1); mApprover->acceptCall(); QTRY_COMPARE(spyNewCallChannel.count(), 1); Tp::CallChannelPtr channel = spyNewCallChannel.first().first().value(); QVERIFY(channel); channel->accept(); QTRY_COMPARE(channel->callState(), Tp::CallStateActive); channel->requestHold(true); QTRY_COMPARE(channel->localHoldState(), Tp::LocalHoldStateHeld); channel->requestHold(false); QTRY_COMPARE(channel->localHoldState(), Tp::LocalHoldStateUnheld); channel->hangup(); } void CallTest::testCallDTMF() { // Request the contact to start chatting to Tp::AccountPtr account = TelepathyHelper::instance()->account(); QSignalSpy spy(this, SIGNAL(contactsReceived(QList))); connect(account->connection()->contactManager()->contactsForIdentifiers(QStringList() << "321"), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onPendingContactsFinished(Tp::PendingOperation*))); QTRY_COMPARE(spy.count(), 1); QList contacts = spy.first().first().value >(); QCOMPARE(contacts.count(), 1); QCOMPARE(contacts.first()->id(), QString("321")); QSignalSpy spyOfonoCallAdded(OfonoMockController::instance(), SIGNAL(CallAdded(QDBusObjectPath, QVariantMap))); QSignalSpy spyCallChannel(mHandler, SIGNAL(callChannelAvailable(Tp::CallChannelPtr))); Q_FOREACH(Tp::ContactPtr contact, contacts) { account->ensureAudioCall(contact, "audio", QDateTime::currentDateTime(), TP_QT_IFACE_CLIENT + ".TpOfonoTestHandler"); } QTRY_COMPARE(spyOfonoCallAdded.count(), 1); QTRY_COMPARE(spyCallChannel.count(), 1); QDBusObjectPath path = spyOfonoCallAdded.first().first().value(); Tp::CallChannelPtr channel = spyCallChannel.first().first().value(); QVERIFY(channel); OfonoMockController::instance()->VoiceCallSetAlerting(path.path()); QTRY_COMPARE(channel->callState(), Tp::CallStateInitialised); OfonoMockController::instance()->VoiceCallAnswer(path.path()); QTRY_COMPARE(channel->callState(), Tp::CallStateActive); Q_FOREACH(const Tp::CallContentPtr &content, channel->contents()) { if (content->supportsDTMF()) { bool ok; QStringList keys; keys << "0" << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8" << "9" << "*" << "#"; QStringListIterator keysIterator(keys); while (keysIterator.hasNext()) { QString key = keysIterator.next(); Tp::DTMFEvent event = (Tp::DTMFEvent)key.toInt(&ok); if (!ok) { if (!key.compare("*")) { event = Tp::DTMFEventAsterisk; } else if (!key.compare("#")) { event = Tp::DTMFEventHash; } else { qWarning() << "Tone not recognized. DTMF failed"; return; } } QSignalSpy spyOfonoTonesReceived(OfonoMockController::instance(), SIGNAL(TonesReceived(const QString&))); content->startDTMFTone(event); QTRY_COMPARE(spyOfonoTonesReceived.count(), 1); QCOMPARE(spyOfonoTonesReceived.first().first().value(), key); } // test failed tones QSignalSpy spyOfonoTonesReceived(OfonoMockController::instance(), SIGNAL(TonesReceived(const QString&))); OfonoMockController::instance()->VoiceCallManagerFailNextDtmf(); content->startDTMFTone((Tp::DTMFEvent)QString("1").toInt(&ok)); OfonoMockController::instance()->VoiceCallManagerFailNextDtmf(); content->startDTMFTone((Tp::DTMFEvent)QString("2").toInt(&ok)); content->startDTMFTone((Tp::DTMFEvent)QString("3").toInt(&ok)); QTRY_COMPARE(spyOfonoTonesReceived.count(), 2); QCOMPARE(spyOfonoTonesReceived.first().first().value(), QString("1")); spyOfonoTonesReceived.removeFirst(); QCOMPARE(spyOfonoTonesReceived.first().first().value(), QString("23")); } } OfonoMockController::instance()->VoiceCallHangup(path.path()); QTRY_COMPARE(channel->callState(), Tp::CallStateEnded); } void CallTest::testCallMute() { // Request the contact to start chatting to Tp::AccountPtr account = TelepathyHelper::instance()->account(); QSignalSpy spy(this, SIGNAL(contactsReceived(QList))); connect(account->connection()->contactManager()->contactsForIdentifiers(QStringList() << "321"), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onPendingContactsFinished(Tp::PendingOperation*))); QTRY_COMPARE(spy.count(), 1); QList contacts = spy.first().first().value >(); QCOMPARE(contacts.count(), 1); QCOMPARE(contacts.first()->id(), QString("321")); QSignalSpy spyOfonoCallAdded(OfonoMockController::instance(), SIGNAL(CallAdded(QDBusObjectPath, QVariantMap))); QSignalSpy spyCallChannel(mHandler, SIGNAL(callChannelAvailable(Tp::CallChannelPtr))); Q_FOREACH(Tp::ContactPtr contact, contacts) { account->ensureAudioCall(contact, "audio", QDateTime::currentDateTime(), TP_QT_IFACE_CLIENT + ".TpOfonoTestHandler"); } QTRY_COMPARE(spyOfonoCallAdded.count(), 1); QTRY_COMPARE(spyCallChannel.count(), 1); QDBusObjectPath path = spyOfonoCallAdded.first().first().value(); Tp::CallChannelPtr channel = spyCallChannel.first().first().value(); QVERIFY(channel); OfonoMockController::instance()->VoiceCallSetAlerting(path.path()); QTRY_COMPARE(channel->callState(), Tp::CallStateInitialised); OfonoMockController::instance()->VoiceCallAnswer(path.path()); QTRY_COMPARE(channel->callState(), Tp::CallStateActive); QDBusInterface muteInterface(channel->busName(), channel->objectPath(), TELEPATHY_MUTE_IFACE); QSignalSpy spyMuteChanged(OfonoMockController::instance(), SIGNAL(CallVolumeMuteChanged(bool))); muteInterface.call("RequestMuted", true); QTRY_COMPARE(spyMuteChanged.count(), 1); QTRY_COMPARE(spyMuteChanged.first().first().value(), true); spyMuteChanged.clear(); muteInterface.call("RequestMuted", false); QTRY_COMPARE(spyMuteChanged.count(), 1); QTRY_COMPARE(spyMuteChanged.first().first().value(), false); OfonoMockController::instance()->VoiceCallHangup(path.path()); QTRY_COMPARE(channel->callState(), Tp::CallStateEnded); } void CallTest::testCallConference() { // Request the contact to start chatting to Tp::AccountPtr account = TelepathyHelper::instance()->account(); QSignalSpy spy(this, SIGNAL(contactsReceived(QList))); QSignalSpy spyOfonoCallAdded(OfonoMockController::instance(), SIGNAL(CallAdded(QDBusObjectPath, QVariantMap))); QSignalSpy spyCallChannel(mHandler, SIGNAL(callChannelAvailable(Tp::CallChannelPtr))); // Call #1 connect(account->connection()->contactManager()->contactsForIdentifiers(QStringList() << "333"), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onPendingContactsFinished(Tp::PendingOperation*))); QTRY_COMPARE(spy.count(), 1); QList contacts = spy.first().first().value >(); QCOMPARE(contacts.count(), 1); QCOMPARE(contacts.first()->id(), QString("333")); Q_FOREACH(Tp::ContactPtr contact, contacts) { account->ensureAudioCall(contact, "audio", QDateTime::currentDateTime(), TP_QT_IFACE_CLIENT + ".TpOfonoTestHandler"); } QTRY_COMPARE(spyOfonoCallAdded.count(), 1); QTRY_COMPARE(spyCallChannel.count(), 1); QDBusObjectPath path1 = spyOfonoCallAdded.first().first().value(); Tp::CallChannelPtr channel1 = spyCallChannel.first().first().value(); QVERIFY(channel1); OfonoMockController::instance()->VoiceCallSetAlerting(path1.path()); QTRY_COMPARE(channel1->callState(), Tp::CallStateInitialised); OfonoMockController::instance()->VoiceCallAnswer(path1.path()); QTRY_COMPARE(channel1->callState(), Tp::CallStateActive); spy.clear(); spyOfonoCallAdded.clear(); spyCallChannel.clear(); // Call #2 connect(account->connection()->contactManager()->contactsForIdentifiers(QStringList() << "444"), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onPendingContactsFinished(Tp::PendingOperation*))); QTRY_COMPARE(spy.count(), 1); contacts = spy.first().first().value >(); QCOMPARE(contacts.count(), 1); QCOMPARE(contacts.first()->id(), QString("444")); Q_FOREACH(Tp::ContactPtr contact, contacts) { account->ensureAudioCall(contact, "audio", QDateTime::currentDateTime(), TP_QT_IFACE_CLIENT + ".TpOfonoTestHandler"); } QTRY_COMPARE(spyOfonoCallAdded.count(), 1); QTRY_COMPARE(spyCallChannel.count(), 1); QDBusObjectPath path2 = spyOfonoCallAdded.first().first().value(); Tp::CallChannelPtr channel2 = spyCallChannel.first().first().value(); QVERIFY(channel2); OfonoMockController::instance()->VoiceCallSetAlerting(path2.path()); QTRY_COMPARE(channel2->callState(), Tp::CallStateInitialised); OfonoMockController::instance()->VoiceCallAnswer(path2.path()); QTRY_COMPARE(channel2->callState(), Tp::CallStateActive); spy.clear(); spyOfonoCallAdded.clear(); spyCallChannel.clear(); // create conference QList calls; calls << channel1 << channel2; TelepathyHelper::instance()->account()->createConferenceCall(calls, QStringList(), QDateTime::currentDateTime(), TP_QT_IFACE_CLIENT + ".TpOfonoTestHandler"); QTRY_COMPARE(spyCallChannel.count(), 1); Tp::CallChannelPtr conferenceChannel = spyCallChannel.first().first().value(); QVERIFY(conferenceChannel); QSignalSpy spyConferenceChannelMerged(conferenceChannel.data(), SIGNAL(conferenceChannelMerged(const Tp::ChannelPtr &))); QSignalSpy spyConferenceChannelRemoved(conferenceChannel.data(), SIGNAL(conferenceChannelRemoved(const Tp::ChannelPtr &, const Tp::Channel::GroupMemberChangeDetails &))); spy.clear(); spyOfonoCallAdded.clear(); spyCallChannel.clear(); // Call #3 connect(account->connection()->contactManager()->contactsForIdentifiers(QStringList() << "555"), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onPendingContactsFinished(Tp::PendingOperation*))); QTRY_COMPARE(spy.count(), 1); contacts = spy.first().first().value >(); QCOMPARE(contacts.count(), 1); QCOMPARE(contacts.first()->id(), QString("555")); Q_FOREACH(Tp::ContactPtr contact, contacts) { account->ensureAudioCall(contact, "audio", QDateTime::currentDateTime(), TP_QT_IFACE_CLIENT + ".TpOfonoTestHandler"); } QTRY_COMPARE(spyOfonoCallAdded.count(), 1); QTRY_COMPARE(spyCallChannel.count(), 1); QDBusObjectPath path3 = spyOfonoCallAdded.first().first().value(); Tp::CallChannelPtr channel3 = spyCallChannel.first().first().value(); QVERIFY(channel3); OfonoMockController::instance()->VoiceCallSetAlerting(path3.path()); QTRY_COMPARE(channel3->callState(), Tp::CallStateInitialised); OfonoMockController::instance()->VoiceCallAnswer(path3.path()); QTRY_COMPARE(channel3->callState(), Tp::CallStateActive); spy.clear(); spyOfonoCallAdded.clear(); spyCallChannel.clear(); // merge channel 3 into the conference conferenceChannel->conferenceMergeChannel(channel3); QTRY_COMPARE(spyConferenceChannelMerged.count(), 1); // hangup first call so we end up with 2 calls in a conference OfonoMockController::instance()->VoiceCallHangup(path1.path()); QTRY_COMPARE(channel1->callState(), Tp::CallStateEnded); QTRY_COMPARE(spyConferenceChannelRemoved.count(), 1); // split conference so we end up with 2 individual calls channel2->conferenceSplitChannel(); QTRY_COMPARE(channel2->callState(), Tp::CallStateActive); // check if the conference was finished QTRY_COMPARE(conferenceChannel->callState(), Tp::CallStateEnded); OfonoMockController::instance()->VoiceCallHangup(path2.path()); QTRY_COMPARE(channel2->callState(), Tp::CallStateEnded); OfonoMockController::instance()->VoiceCallHangup(path3.path()); QTRY_COMPARE(channel3->callState(), Tp::CallStateEnded); } void CallTest::onPendingContactsFinished(Tp::PendingOperation *op) { Tp::PendingContacts *pc = qobject_cast(op); if (!pc) { return; } Q_EMIT contactsReceived(pc->contacts()); } QTEST_MAIN(CallTest) #include "CallTest.moc" telepathy-ofono-0.2+14.04.20140407/tests/handler.cpp0000644000015301777760000001205112320626651022354 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: * Tiago Salem Herrmann * Gustavo Pichorim Boiko */ #include "handler.h" #include "telepathyhelper.h" #include #include #include #include #include Handler::Handler(QObject *parent) : QObject(parent), Tp::AbstractClientHandler(channelFilters()), mBypassApproval(false) { } void Handler::setBypassApproval(bool bypass) { mBypassApproval = bypass; } bool Handler::bypassApproval() const { return mBypassApproval; } void Handler::handleChannels(const Tp::MethodInvocationContextPtr<> &context, const Tp::AccountPtr &account, const Tp::ConnectionPtr &connection, const QList &channels, const QList &requestsSatisfied, const QDateTime &userActionTime, const Tp::AbstractClientHandler::HandlerInfo &handlerInfo) { Q_UNUSED(account) Q_UNUSED(connection) Q_UNUSED(requestsSatisfied) Q_UNUSED(userActionTime) Q_UNUSED(handlerInfo) Q_FOREACH(const Tp::ChannelPtr channel, channels) { Tp::TextChannelPtr textChannel = Tp::TextChannelPtr::dynamicCast(channel); if (textChannel) { Tp::PendingReady *pr = textChannel->becomeReady(Tp::Features() << Tp::TextChannel::FeatureCore << Tp::TextChannel::FeatureChatState << Tp::TextChannel::FeatureMessageCapabilities << Tp::TextChannel::FeatureMessageQueue << Tp::TextChannel::FeatureMessageSentSignal); connect(pr, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onTextChannelReady(Tp::PendingOperation*))); mReadyRequests[pr] = textChannel; continue; } Tp::CallChannelPtr callChannel = Tp::CallChannelPtr::dynamicCast(channel); if (callChannel) { Tp::PendingReady *pr = callChannel->becomeReady(Tp::Features() << Tp::CallChannel::FeatureCore << Tp::CallChannel::FeatureCallState << Tp::CallChannel::FeatureContents << Tp::CallChannel::FeatureLocalHoldState); connect(pr, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onCallChannelReady(Tp::PendingOperation*))); mReadyRequests[pr] = callChannel; continue; } } context->setFinished(); } Tp::ChannelClassSpecList Handler::channelFilters() { Tp::ChannelClassSpecList specList; Tp::ChannelClassSpec spec(TP_QT_IFACE_CHANNEL_TYPE_CALL, Tp::HandleTypeNone); spec.setCallInitialAudioFlag(); specList << spec; specList << Tp::ChannelClassSpec::audioCall(); specList << Tp::ChannelClassSpec::textChat(); return specList; } void Handler::onTextChannelReady(Tp::PendingOperation *op) { Tp::PendingReady *pr = qobject_cast(op); if (!pr) { qCritical() << "The pending object is not a Tp::PendingReady"; return; } Tp::ChannelPtr channel = mReadyRequests[pr]; Tp::TextChannelPtr textChannel = Tp::TextChannelPtr::dynamicCast(channel); if(!textChannel) { qCritical() << "The saved channel is not a Tp::TextChannel"; return; } mReadyRequests.remove(pr); Q_EMIT textChannelAvailable(textChannel); } void Handler::onCallChannelReady(Tp::PendingOperation *op) { Tp::PendingReady *pr = qobject_cast(op); if (!pr) { qCritical() << "The pending object is not a Tp::PendingReady"; return; } Tp::ChannelPtr channel = mReadyRequests[pr]; Tp::CallChannelPtr callChannel = Tp::CallChannelPtr::dynamicCast(channel); if(!callChannel) { qCritical() << "The saved channel is not a Tp::CallChannel"; return; } mReadyRequests.remove(pr); Q_EMIT callChannelAvailable(callChannel); } telepathy-ofono-0.2+14.04.20140407/tests/CMakeLists.txt0000644000015301777760000000427212320626651023001 0ustar pbusernogroup00000000000000include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR} ) macro(generate_test TESTNAME USE_DBUS) add_executable(${TESTNAME} ${ARGN} ${TESTNAME}.cpp) qt5_use_modules(${TESTNAME} Core DBus Test) set(TEST_COMMAND ) if (${USE_DBUS}) set(TEST_COMMAND -p ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME} -p -xunitxml -p -o -p ${CMAKE_BINARY_DIR}/test_${TESTNAME}.xml) add_test(${TESTNAME} ${DBUS_RUNNER} --keep-env --task ${CMAKE_CURRENT_BINARY_DIR}/dbus-test-wrapper.sh ${TEST_COMMAND}) else (${USE_DBUS}) add_test(${TESTNAME} ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME} -xunitxml -o ${CMAKE_BINARY_DIR}/test_${TESTNAME}.xml) endif(${USE_DBUS}) # force telepathy not to use system approvers when available, # also force usage of memory backend in history-service set(TMPDIR "/tmp/tpofono_test_home") set(TEST_ENVIRONMENT "HOME=${TMPDIR}; HISTORY_SQLITE_DBPATH=:memory:; TP_OFONO_SQLITE_DBPATH=:memory:; XDG_CONFIG_HOME=${TMPDIR}; XDG_DATA_HOME=${TMPDIR}; XDG_CACHE_DIR=${TMPDIR}; XDG_CACHE_HOME=${TMPDIR}; XDG_DATA_DIRS=${TMPDIR}; MC_ACCOUNT_DIR=${TMPDIR}; MC_MANAGER_DIR=${TMPDIR}; PA_DISABLED=1") set_tests_properties(${TESTNAME} PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}" TIMEOUT 30) target_link_libraries(${TESTNAME} ${TP_QT5_LIBRARIES} ) endmacro(generate_test) configure_file(dbus-test-wrapper.sh.in ${CMAKE_CURRENT_BINARY_DIR}/dbus-test-wrapper.sh) generate_test(PhoneUtilsTest False ${CMAKE_SOURCE_DIR}/phoneutils.cpp) if (DBUS_RUNNER) generate_test(ConnectionTest True telepathyhelper.cpp ofonomockcontroller.cpp) generate_test(MessagesTest True telepathyhelper.cpp ofonomockcontroller.cpp handler.cpp approvertext.cpp) generate_test(CallTest True telepathyhelper.cpp ofonomockcontroller.cpp handler.cpp approvercall.cpp) endif(DBUS_RUNNER) add_subdirectory(mock) telepathy-ofono-0.2+14.04.20140407/tests/handler.h0000644000015301777760000000415312320626651022025 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: * Tiago Salem Herrmann * Gustavo Pichorim Boiko */ #ifndef HANDLER_H #define HANDLER_H #include #include #include #include #include class Handler : public QObject, public Tp::AbstractClientHandler { Q_OBJECT public: Handler(QObject *parent = 0); ~Handler() { } bool bypassApproval() const; void handleChannels(const Tp::MethodInvocationContextPtr<> &context, const Tp::AccountPtr &account, const Tp::ConnectionPtr &connection, const QList &channels, const QList &requestsSatisfied, const QDateTime &userActionTime, const Tp::AbstractClientHandler::HandlerInfo &handlerInfo); Tp::ChannelClassSpecList channelFilters(); void setBypassApproval(bool bypass); Q_SIGNALS: void textChannelAvailable(Tp::TextChannelPtr textChannel); void callChannelAvailable(Tp::CallChannelPtr callChannel); private Q_SLOTS: void onTextChannelReady(Tp::PendingOperation *op); void onCallChannelReady(Tp::PendingOperation *op); private: QMap mReadyRequests; bool mBypassApproval; }; #endif // HANDLER_H telepathy-ofono-0.2+14.04.20140407/tests/dbus-test-wrapper.sh.in0000755000015301777760000000131312320626661024567 0ustar pbusernogroup00000000000000#!/bin/sh # export the home folder to somewhere in /tmp TMPDIR=/tmp/tpofono_test_home rm -rf $TMPDIR export HOME=$TMPDIR # now run gnome-keyring gnome-keyring-daemon -r -d # we need to set this otherwise mission-control doesn't work properly dconf write /org/gnome/empathy/use-conn false export PA_DISABLED=1 # start telepathy-ofono with the ofono-qt mock library LD_PRELOAD=@CMAKE_CURRENT_BINARY_DIR@/mock/libofono-qt.so ${CMAKE_BINARY_DIR}/telepathy-ofono & TP_OFONO_PID=$! mc-tool add ofono/ofono account0 mc-tool enable ofono/ofono/account0 $@ RESULT=$? kill -9 $TP_OFONO_PID #FIXME for some reason history-daemon is not being finished, so we have to kill it here killall history-daemon return $RESULT telepathy-ofono-0.2+14.04.20140407/tests/ofonomockcontroller.cpp0000644000015301777760000001045112320626651025037 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: * Tiago Salem Herrmann * Gustavo Pichorim Boiko */ #include "ofonomockcontroller.h" #include "mock/mock_common.h" OfonoMockController::OfonoMockController(QObject *parent) : QObject(parent), mNetworkRegistrationInterface("org.ofono", OFONO_MOCK_NETWORK_REGISTRATION_OBJECT, "org.ofono.NetworkRegistration"), mMessageManagerInterface("org.ofono", OFONO_MOCK_MESSAGE_MANAGER_OBJECT, "org.ofono.MessageManager"), mVoiceCallManagerInterface("org.ofono", OFONO_MOCK_VOICECALL_MANAGER_OBJECT, "org.ofono.VoiceCallManager") { QDBusConnection::sessionBus().connect("org.ofono", OFONO_MOCK_MESSAGE_MANAGER_OBJECT, "org.ofono.MessageManager", "MessageAdded", this, SIGNAL(MessageAdded(QDBusObjectPath, QVariantMap))); QDBusConnection::sessionBus().connect("org.ofono", OFONO_MOCK_VOICECALL_MANAGER_OBJECT, "org.ofono.VoiceCallManager", "CallAdded", this, SIGNAL(CallAdded(QDBusObjectPath, QVariantMap))); QDBusConnection::sessionBus().connect("org.ofono", OFONO_MOCK_VOICECALL_MANAGER_OBJECT, "org.ofono.VoiceCallManager", "TonesReceived", this, SIGNAL(TonesReceived(QString))); QDBusConnection::sessionBus().connect("org.ofono", OFONO_MOCK_CALL_VOLUME_OBJECT, "org.ofono.CallVolume", "PropertyChanged", this, SLOT(onCallVolumePropertyChanged(QString, QDBusVariant))); } OfonoMockController *OfonoMockController::instance() { static OfonoMockController *self = new OfonoMockController(); return self; } void OfonoMockController::onCallVolumePropertyChanged(const QString& name, const QDBusVariant& value) { if (name == "Muted") { Q_EMIT CallVolumeMuteChanged(value.variant().value()); } } void OfonoMockController::NetworkRegistrationSetStatus(const QString &status) { mNetworkRegistrationInterface.call("SetProperty", "Status", QVariant::fromValue(QDBusVariant(status))); } void OfonoMockController::MessageManagerSendMessage(const QString &from, const QString &text) { mMessageManagerInterface.call("MockSendMessage", from, text); } void OfonoMockController::MessageManagerStatusReport(const QString &message, bool success) { mMessageManagerInterface.call("MockStatusReport", message, success); } void OfonoMockController::MessageMarkSent(const QString &objPath) { QDBusInterface iface("org.ofono", objPath, "org.ofono.Message"); iface.call("MockMarkSent"); } void OfonoMockController::MessageMarkFailed(const QString &objPath) { QDBusInterface iface("org.ofono", objPath, "org.ofono.Message"); iface.call("MockMarkFailed"); } void OfonoMockController::MessageCancel(const QString &objPath) { QDBusInterface iface("org.ofono", objPath, "org.ofono.Message"); iface.call("Cancel"); } void OfonoMockController::VoiceCallManagerIncomingCall(const QString &from) { QDBusInterface iface("org.ofono", OFONO_MOCK_VOICECALL_MANAGER_OBJECT, "org.ofono.VoiceCallManager"); iface.call("MockIncomingCall", from); } void OfonoMockController::VoiceCallManagerFailNextDtmf() { QDBusInterface iface("org.ofono", OFONO_MOCK_VOICECALL_MANAGER_OBJECT, "org.ofono.VoiceCallManager"); iface.call("MockFailNextDtmf"); } void OfonoMockController::VoiceCallSetAlerting(const QString &objPath) { QDBusInterface iface("org.ofono", objPath, "org.ofono.VoiceCall"); iface.call("MockSetAlerting"); } void OfonoMockController::VoiceCallAnswer(const QString &objPath) { QDBusInterface iface("org.ofono", objPath, "org.ofono.VoiceCall"); iface.call("MockAnswer"); } void OfonoMockController::VoiceCallHangup(const QString &objPath) { QDBusInterface iface("org.ofono", objPath, "org.ofono.VoiceCall"); iface.call("Hangup"); } telepathy-ofono-0.2+14.04.20140407/schema/0000755000015301777760000000000012320627204020325 5ustar pbusernogroup00000000000000telepathy-ofono-0.2+14.04.20140407/schema/v1.sql0000644000015301777760000000024612320626651021403 0ustar pbusernogroup00000000000000CREATE TABLE schema_version ( version int ); CREATE TABLE pending_messages ( messageId varchar(255), recipientId varchar(255), timestamp datetime ); telepathy-ofono-0.2+14.04.20140407/schema/CMakeLists.txt0000644000015301777760000000077712320626651023105 0ustar pbusernogroup00000000000000file(GLOB SCHEMA_FILES ${CMAKE_CURRENT_SOURCE_DIR}/v*.sql) set(SCHEMA_FILE ${CMAKE_CURRENT_SOURCE_DIR}/schema.sql) set(VERSION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/version.info) add_custom_command( OUTPUT ${SCHEMA_FILE} ${VERSION_FILE} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/update_schema.sh ${CMAKE_CURRENT_SOURCE_DIR} ${SCHEMA_FILE} ${VERSION_FILE} WORKING DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${SCHEMA_FILES} ) add_custom_target(schema_update DEPENDS ${SCHEMA_FILE} ${VERSION_FILE}) telepathy-ofono-0.2+14.04.20140407/schema/update_schema.sh0000755000015301777760000000100212320626651023464 0ustar pbusernogroup00000000000000#!/bin/sh if [ $# -lt 3 ]; then echo "Usage: $0 " fi SOURCE_DIR=$1 TARGET_FILE=$2 VERSION_FILE=$3 VERSION="1" LATEST_VERSION="1" TMPFILE=`tempfile` SCHEMA_FILE="$SOURCE_DIR/v${VERSION}.sql" while [ -e $SCHEMA_FILE ]; do cat $SCHEMA_FILE >> $TMPFILE LATEST_VERSION=$VERSION VERSION=$(($VERSION+1)) SCHEMA_FILE="$SOURCE_DIR/v${VERSION}.sql" done sqlite3 -init $TMPFILE :memory: .schema > $TARGET_FILE echo $LATEST_VERSION > $VERSION_FILE telepathy-ofono-0.2+14.04.20140407/ofonoconferencecallchannel.cpp0000644000015301777760000002361412320626651025141 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include "ofonoconferencecallchannel.h" #ifdef USE_PULSEAUDIO #include "qpulseaudioengine.h" #endif #include "ofonocallchannel.h" oFonoConferenceCallChannel::oFonoConferenceCallChannel(oFonoConnection *conn, QObject *parent): mRequestedHangup(false), mConnection(conn), mDtmfLock(false) { Q_FOREACH(oFonoCallChannel *channel, mConnection->callChannels().values()) { if (channel->callState() == Tp::CallStateActive) { QDBusObjectPath path(channel->baseChannel()->objectPath()); mCallChannels << path; } } Tp::BaseChannelPtr baseChannel = Tp::BaseChannel::create(mConnection, TP_QT_IFACE_CHANNEL_TYPE_CALL, 0, Tp::HandleTypeNone); Tp::BaseChannelCallTypePtr callType = Tp::BaseChannelCallType::create(baseChannel.data(), true, Tp::StreamTransportTypeUnknown, true, false, "",""); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(callType)); mHoldIface = Tp::BaseChannelHoldInterface::create(); mHoldIface->setSetHoldStateCallback(Tp::memFun(this,&oFonoConferenceCallChannel::onHoldStateChanged)); mMuteIface = Tp::BaseCallMuteInterface::create(); mMuteIface->setSetMuteStateCallback(Tp::memFun(this,&oFonoConferenceCallChannel::onMuteStateChanged)); mSpeakerIface = BaseChannelSpeakerInterface::create(); mSpeakerIface->setTurnOnSpeakerCallback(Tp::memFun(this,&oFonoConferenceCallChannel::onTurnOnSpeaker)); mConferenceIface = Tp::BaseChannelConferenceInterface::create(mCallChannels); mMergeableIface = Tp::BaseChannelMergeableConferenceInterface::create(); mMergeableIface->setMergeCallback(Tp::memFun(this,&oFonoConferenceCallChannel::onMerge)); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mHoldIface)); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mMuteIface)); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mSpeakerIface)); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mConferenceIface)); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mMergeableIface)); mBaseChannel = baseChannel; mCallChannel = Tp::BaseChannelCallTypePtr::dynamicCast(mBaseChannel->interface(TP_QT_IFACE_CHANNEL_TYPE_CALL)); mCallChannel->setHangupCallback(Tp::memFun(this,&oFonoConferenceCallChannel::onHangup)); Tp::CallStateReason reason; QVariantMap stateDetails; reason.actor = 0; reason.reason = Tp::CallStateChangeReasonUserRequested; reason.message = ""; reason.DBusReason = ""; mCallChannel->setCallState(Tp::CallStateActive, 0, reason, stateDetails); // init must be called after initialization, otherwise we will have no object path registered. QTimer::singleShot(0, this, SLOT(init())); } Tp::BaseChannelPtr oFonoConferenceCallChannel::baseChannel() { return mBaseChannel; } void oFonoConferenceCallChannel::onMerge(const QDBusObjectPath &channel, Tp::DBusError *error) { // on gsm we always merge all the existing calls mConnection->voiceCallManager()->createMultiparty(); } void oFonoConferenceCallChannel::onChannelMerged(const QDBusObjectPath &path) { if (!mCallChannels.contains(path)) { mCallChannels << path; mConferenceIface->mergeChannel(path, 0, QVariantMap()); } } void oFonoConferenceCallChannel::onChannelSplitted(const QDBusObjectPath &path) { if (mCallChannels.contains(path)) { mCallChannels.removeAll(path); mConferenceIface->removeChannel(path, QVariantMap()); } if (mCallChannels.size() == 1) { // remove the call channel from the conference before closing it. mConferenceIface->removeChannel(mCallChannels.takeFirst(), QVariantMap()); Tp::CallStateReason reason; QVariantMap stateDetails; reason.actor = 0; reason.reason = Tp::CallStateChangeReasonUserRequested; reason.message = ""; reason.DBusReason = ""; mCallChannel->setCallState(Tp::CallStateEnded, 0, reason, stateDetails); mBaseChannel->close(); } } void oFonoConferenceCallChannel::onTurnOnSpeaker(bool active, Tp::DBusError *error) { mConnection->setSpeakerMode(active); } void oFonoConferenceCallChannel::onHangup(uint reason, const QString &detailedReason, const QString &message, Tp::DBusError *error) { // TODO: use the parameters sent by telepathy //mRequestedHangup = true; mConnection->voiceCallManager()->hangupMultiparty(); //hangup(); } void oFonoConferenceCallChannel::init() { QVariantMap stateDetails; Tp::CallStateReason reason; mObjPath = mBaseChannel->objectPath(); reason.actor = 0; reason.reason = Tp::CallStateChangeReasonProgressMade; reason.message = ""; reason.DBusReason = ""; mCallChannel->setCallState(Tp::CallStateActive, 0, reason, stateDetails); mDTMFIface = Tp::BaseCallContentDTMFInterface::create(); mDTMFIface->setStartToneCallback(Tp::memFun(this,&oFonoConferenceCallChannel::onDTMFStartTone)); mDTMFIface->setStopToneCallback(Tp::memFun(this,&oFonoConferenceCallChannel::onDTMFStopTone)); QObject::connect(mBaseChannel.data(), SIGNAL(closed()), this, SLOT(deleteLater())); QObject::connect(mConnection->callVolume(), SIGNAL(mutedChanged(bool)), SLOT(onOfonoMuteChanged(bool))); QObject::connect(mConnection, SIGNAL(speakerModeChanged(bool)), mSpeakerIface.data(), SLOT(setSpeakerMode(bool))); QObject::connect(mConnection->voiceCallManager(), SIGNAL(sendTonesComplete(bool)), SLOT(onDtmfComplete(bool))); mSpeakerIface->setSpeakerMode(mConnection->speakerMode()); QObject::connect(mConnection, SIGNAL(channelMerged(const QDBusObjectPath&)), this, SLOT(onChannelMerged(const QDBusObjectPath&))); QObject::connect(mConnection, SIGNAL(channelSplitted(const QDBusObjectPath&)), this, SLOT(onChannelSplitted(const QDBusObjectPath&))); QObject::connect(mConnection, SIGNAL(channelHangup(const QDBusObjectPath&)), this, SLOT(onChannelSplitted(const QDBusObjectPath&))); } void oFonoConferenceCallChannel::onOfonoMuteChanged(bool mute) { Tp::LocalMuteState state = mute ? Tp::LocalMuteStateMuted : Tp::LocalMuteStateUnmuted; mMuteIface->setMuteState(state); } void oFonoConferenceCallChannel::setConferenceActive(bool active) { if (active) { mHoldIface->setHoldState(Tp::LocalHoldStateUnheld, Tp::LocalHoldStateReasonNone); } else { mHoldIface->setHoldState(Tp::LocalHoldStateHeld, Tp::LocalHoldStateReasonNone); } } void oFonoConferenceCallChannel::onHoldStateChanged(const Tp::LocalHoldState &state, const Tp::LocalHoldStateReason &reason, Tp::DBusError *error) { if (state == Tp::LocalHoldStateHeld && mHoldIface->getHoldState() == Tp::LocalHoldStateUnheld) { mConnection->voiceCallManager()->swapCalls(); } else if (state == Tp::LocalHoldStateUnheld && mHoldIface->getHoldState() == Tp::LocalHoldStateHeld) { mConnection->voiceCallManager()->swapCalls(); } } void oFonoConferenceCallChannel::onMuteStateChanged(const Tp::LocalMuteState &state, Tp::DBusError *error) { if (state == Tp::LocalMuteStateMuted) { mConnection->callVolume()->setMuted(true); #ifdef USE_PULSEAUDIO QPulseAudioEngine::instance()->setMicMute(true); #endif } else if (state == Tp::LocalMuteStateUnmuted) { mConnection->callVolume()->setMuted(false); #ifdef USE_PULSEAUDIO QPulseAudioEngine::instance()->setMicMute(false); #endif } } void oFonoConferenceCallChannel::sendNextDtmf() { if (mDtmfLock) { return; } if (!mDtmfPendingStrings.isEmpty()) { mDtmfLock = true; mConnection->voiceCallManager()->sendTones(mDtmfPendingStrings.front()); } } void oFonoConferenceCallChannel::onDtmfComplete(bool success) { mDtmfLock = false; if (success) { mDtmfPendingStrings.removeFirst(); if (mDtmfPendingStrings.isEmpty()) { return; } sendNextDtmf(); } else { QTimer::singleShot(1000, this, SLOT(sendNextDtmf())); } } void oFonoConferenceCallChannel::onDTMFStartTone(uchar event, Tp::DBusError *error) { QString finalString; if (event == 10) { finalString = "*"; } else if (event == 11) { finalString = "#"; } else { finalString = QString::number(event); } qDebug() << "start tone" << finalString; // we can't append to the first item in the queue as it is being sent and // we dont know yet if it will succeed or not. if (mDtmfPendingStrings.count() > 1) { mDtmfPendingStrings[1] += finalString; } else { mDtmfPendingStrings << finalString; } sendNextDtmf(); } void oFonoConferenceCallChannel::onDTMFStopTone(Tp::DBusError *error) { } oFonoConferenceCallChannel::~oFonoConferenceCallChannel() { qDebug() << "conference call channel closed"; // TODO - for some reason the object is not being removed mConnection->dbusConnection().unregisterObject(mObjPath, QDBusConnection::UnregisterTree); } telepathy-ofono-0.2+14.04.20140407/qpulseaudioengine.h0000644000015301777760000000374412320626651022774 0ustar pbusernogroup00000000000000/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file was taken from qt5 and modified by ** David Henningsson for usage in ** telepathy-ofono. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ****************************************************************************/ #ifndef QPULSEAUDIOENGINE_H #define QPULSEAUDIOENGINE_H #include #include #include QT_BEGIN_NAMESPACE class QPulseAudioEngine : public QObject { Q_OBJECT public: QPulseAudioEngine(QObject *parent = 0); ~QPulseAudioEngine(); static QPulseAudioEngine *instance(); pa_threaded_mainloop *mainloop() { return m_mainLoop; } pa_context *context() { return m_context; } void setCallMode(bool inCall, bool speakerMode); void setMicMute(bool muted); /* True if muted, false if unmuted */ /* These four are only used internally */ void cardInfoCallback(const pa_card_info *card); void sinkInfoCallback(const pa_sink_info *sink); void sourceInfoCallback(const pa_source_info *source); public Q_SLOTS: void plugUnplugSlot(); private: pa_mainloop_api *m_mainLoopApi; pa_threaded_mainloop *m_mainLoop; pa_context *m_context; bool m_incall, m_speakermode, m_micmute; std::string m_nametoset, m_valuetoset; bool handleOperation(pa_operation *operation, const char *func_name); }; QT_END_NAMESPACE #endif telepathy-ofono-0.2+14.04.20140407/ofonocallchannel.cpp0000644000015301777760000002624212320626651023111 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include "ofonocallchannel.h" #ifdef USE_PULSEAUDIO #include "qpulseaudioengine.h" #endif oFonoCallChannel::oFonoCallChannel(oFonoConnection *conn, QString phoneNumber, uint targetHandle, QString voiceObj, QObject *parent): OfonoVoiceCall(voiceObj), mIncoming(false), mRequestedHangup(false), mConnection(conn), mPhoneNumber(phoneNumber), mTargetHandle(targetHandle), mDtmfLock(false), mMultiparty(false) { Tp::BaseChannelPtr baseChannel = Tp::BaseChannel::create(mConnection, TP_QT_IFACE_CHANNEL_TYPE_CALL, targetHandle, Tp::HandleTypeContact); Tp::BaseChannelCallTypePtr callType = Tp::BaseChannelCallType::create(baseChannel.data(), true, Tp::StreamTransportTypeUnknown, true, false, "",""); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(callType)); mHoldIface = Tp::BaseChannelHoldInterface::create(); mHoldIface->setSetHoldStateCallback(Tp::memFun(this,&oFonoCallChannel::onHoldStateChanged)); mMuteIface = Tp::BaseCallMuteInterface::create(); mMuteIface->setSetMuteStateCallback(Tp::memFun(this,&oFonoCallChannel::onMuteStateChanged)); mSpeakerIface = BaseChannelSpeakerInterface::create(); mSpeakerIface->setTurnOnSpeakerCallback(Tp::memFun(this,&oFonoCallChannel::onTurnOnSpeaker)); mSplittableIface = Tp::BaseChannelSplittableInterface::create(); mSplittableIface->setSplitCallback(Tp::memFun(this,&oFonoCallChannel::onSplit)); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mHoldIface)); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mMuteIface)); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mSpeakerIface)); baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mSplittableIface)); mBaseChannel = baseChannel; mCallChannel = Tp::BaseChannelCallTypePtr::dynamicCast(mBaseChannel->interface(TP_QT_IFACE_CHANNEL_TYPE_CALL)); mCallChannel->setHangupCallback(Tp::memFun(this,&oFonoCallChannel::onHangup)); mCallChannel->setAcceptCallback(Tp::memFun(this,&oFonoCallChannel::onAccept)); // init must be called after initialization, otherwise we will have no object path registered. QTimer::singleShot(0, this, SLOT(init())); } Tp::CallState oFonoCallChannel::callState() { return (Tp::CallState)mCallChannel->callState(); } void oFonoCallChannel::onSplit(Tp::DBusError *error) { mConnection->voiceCallManager()->privateChat(path()); } void oFonoCallChannel::onTurnOnSpeaker(bool active, Tp::DBusError *error) { mConnection->setSpeakerMode(active); } void oFonoCallChannel::onHangup(uint reason, const QString &detailedReason, const QString &message, Tp::DBusError *error) { // TODO: use the parameters sent by telepathy mRequestedHangup = true; hangup(); } void oFonoCallChannel::onAccept(Tp::DBusError*) { if (this->state() == "waiting") { mConnection->voiceCallManager()->holdAndAnswer(); } else { answer(); } } void oFonoCallChannel::init() { mIncoming = this->state() == "incoming" || this->state() == "waiting"; mMultiparty = this->multiparty(); mPreviousState = this->state(); mObjPath = mBaseChannel->objectPath(); Tp::CallMemberMap memberFlags; Tp::HandleIdentifierMap identifiers; QVariantMap stateDetails; Tp::CallStateReason reason; identifiers[mTargetHandle] = mPhoneNumber; reason.actor = 0; reason.reason = Tp::CallStateChangeReasonProgressMade; reason.message = ""; reason.DBusReason = ""; if (mIncoming) { memberFlags[mTargetHandle] = 0; } else { memberFlags[mTargetHandle] = Tp::CallMemberFlagRinging; } mCallChannel->setCallState(Tp::CallStateInitialising, 0, reason, stateDetails); mCallContent = Tp::BaseCallContent::create(baseChannel()->dbusConnection(), baseChannel().data(), "audio", Tp::MediaStreamTypeAudio, Tp::MediaStreamDirectionNone); mDTMFIface = Tp::BaseCallContentDTMFInterface::create(); mCallContent->plugInterface(Tp::AbstractCallContentInterfacePtr::dynamicCast(mDTMFIface)); mCallChannel->addContent(mCallContent); mDTMFIface->setStartToneCallback(Tp::memFun(this,&oFonoCallChannel::onDTMFStartTone)); mDTMFIface->setStopToneCallback(Tp::memFun(this,&oFonoCallChannel::onDTMFStopTone)); mCallChannel->setMembersFlags(memberFlags, identifiers, Tp::UIntList(), reason); mCallChannel->setCallState(Tp::CallStateInitialised, 0, reason, stateDetails); QObject::connect(mBaseChannel.data(), SIGNAL(closed()), this, SLOT(deleteLater())); QObject::connect(mConnection->callVolume(), SIGNAL(mutedChanged(bool)), SLOT(onOfonoMuteChanged(bool))); QObject::connect(this, SIGNAL(stateChanged(QString)), SLOT(onOfonoCallStateChanged(QString))); QObject::connect(mConnection, SIGNAL(speakerModeChanged(bool)), mSpeakerIface.data(), SLOT(setSpeakerMode(bool))); QObject::connect(mConnection->voiceCallManager(), SIGNAL(sendTonesComplete(bool)), SLOT(onDtmfComplete(bool))); QObject::connect(this, SIGNAL(multipartyChanged(bool)), this, SLOT(onMultipartyChanged(bool))); mSpeakerIface->setSpeakerMode(mConnection->speakerMode()); } void oFonoCallChannel::onMultipartyChanged(bool multiparty) { // if previous state was multparty then split if (multiparty) { Q_EMIT merged(); } else { Q_EMIT splitted(); } mMultiparty = multiparty; } void oFonoCallChannel::onOfonoMuteChanged(bool mute) { Tp::LocalMuteState state = mute ? Tp::LocalMuteStateMuted : Tp::LocalMuteStateUnmuted; mMuteIface->setMuteState(state); } void oFonoCallChannel::onHoldStateChanged(const Tp::LocalHoldState &state, const Tp::LocalHoldStateReason &reason, Tp::DBusError *error) { if (state == Tp::LocalHoldStateHeld && this->state() == "active") { mConnection->voiceCallManager()->swapCalls(); } else if (state == Tp::LocalHoldStateUnheld && this->state() == "held") { mConnection->voiceCallManager()->swapCalls(); } } void oFonoCallChannel::onMuteStateChanged(const Tp::LocalMuteState &state, Tp::DBusError *error) { bool hasPulseAudio = true; QByteArray pulseAudioDisabled = qgetenv("PA_DISABLED"); if (!pulseAudioDisabled.isEmpty()) { hasPulseAudio = false; } if (state == Tp::LocalMuteStateMuted) { mConnection->callVolume()->setMuted(true); #ifdef USE_PULSEAUDIO if(hasPulseAudio) { QPulseAudioEngine::instance()->setMicMute(true); } #endif } else if (state == Tp::LocalMuteStateUnmuted) { mConnection->callVolume()->setMuted(false); #ifdef USE_PULSEAUDIO if(hasPulseAudio) { QPulseAudioEngine::instance()->setMicMute(false); } #endif } } void oFonoCallChannel::sendNextDtmf() { if (mDtmfLock) { return; } if (!mDtmfPendingStrings.isEmpty()) { mDtmfLock = true; mConnection->voiceCallManager()->sendTones(mDtmfPendingStrings.front()); } } void oFonoCallChannel::onDtmfComplete(bool success) { mDtmfLock = false; if (success) { mDtmfPendingStrings.removeFirst(); if (mDtmfPendingStrings.isEmpty()) { return; } sendNextDtmf(); } else { QTimer::singleShot(1000, this, SLOT(sendNextDtmf())); } } void oFonoCallChannel::onDTMFStartTone(uchar event, Tp::DBusError *error) { QString finalString; if (event == 10) { finalString = "*"; } else if (event == 11) { finalString = "#"; } else { finalString = QString::number(event); } qDebug() << "start tone" << finalString; // we can't append to the first item in the queue as it is being sent and // we dont know yet if it will succeed or not. if (mDtmfPendingStrings.count() > 1) { mDtmfPendingStrings[1] += finalString; } else { mDtmfPendingStrings << finalString; } sendNextDtmf(); } void oFonoCallChannel::onDTMFStopTone(Tp::DBusError *error) { } oFonoCallChannel::~oFonoCallChannel() { qDebug() << "call channel closed"; // TODO - for some reason the object is not being removed mConnection->dbusConnection().unregisterObject(mObjPath, QDBusConnection::UnregisterTree); } Tp::BaseChannelPtr oFonoCallChannel::baseChannel() { return mBaseChannel; } void oFonoCallChannel::onOfonoCallStateChanged(const QString &state) { Tp::CallStateReason reason; QVariantMap stateDetails; reason.actor = 0; reason.reason = Tp::CallStateChangeReasonUserRequested; reason.message = ""; reason.DBusReason = ""; // we invalidate the pending dtmf strings if the call status is changed mDtmfPendingStrings.clear(); mDtmfLock = false; if (state == "disconnected") { qDebug() << "disconnected"; if (mIncoming && (mPreviousState == "incoming" || mPreviousState == "waiting") && !mRequestedHangup) { reason.reason = Tp::CallStateChangeReasonNoAnswer; } mCallChannel->setCallState(Tp::CallStateEnded, 0, reason, stateDetails); Q_EMIT closed(); mBaseChannel->close(); } else if (state == "active") { qDebug() << "active"; mHoldIface->setHoldState(Tp::LocalHoldStateUnheld, Tp::LocalHoldStateReasonNone); if (mMultiparty) { Q_EMIT multipartyCallActive(); } if (mPreviousState == "dialing" || mPreviousState == "alerting" || mPreviousState == "incoming") { mConnection->callVolume()->setMuted(false); mCallChannel->setCallState(Tp::CallStateAccepted, 0, reason, stateDetails); } mCallChannel->setCallState(Tp::CallStateActive, 0, reason, stateDetails); } else if (state == "held") { mHoldIface->setHoldState(Tp::LocalHoldStateHeld, Tp::LocalHoldStateReasonNone); if (mMultiparty) { Q_EMIT multipartyCallHeld(); } qDebug() << "held"; } else if (state == "dialing") { qDebug() << "dialing"; } else if (state == "alerting") { qDebug() << "alerting"; } else if (state == "incoming") { qDebug() << "incoming"; } else if (state == "waiting") { qDebug() << "waiting"; } // always update the audio route when call state changes mConnection->updateAudioRoute(); mPreviousState = state; } telepathy-ofono-0.2+14.04.20140407/speakeriface.cpp0000644000015301777760000000770512320626651022231 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include #include #include "speakeriface.h" // Chan.I.Speaker BaseChannelSpeakerInterface::Adaptee::Adaptee(BaseChannelSpeakerInterface *interface) : QObject(interface), mInterface(interface) { } struct TP_QT_NO_EXPORT BaseChannelSpeakerInterface::Private { Private(BaseChannelSpeakerInterface *parent) : speakerMode(false), adaptee(new BaseChannelSpeakerInterface::Adaptee(parent)) { } bool speakerMode; turnOnSpeakerCallback turnOnSpeakerCB; BaseChannelSpeakerInterface::Adaptee *adaptee; }; BaseChannelSpeakerInterface::Adaptee::~Adaptee() { } void BaseChannelSpeakerInterface::Adaptee::turnOnSpeaker(bool active, const ChannelInterfaceSpeakerAdaptor::turnOnSpeakerContextPtr &context) { if (!mInterface->mPriv->turnOnSpeakerCB.isValid()) { context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); return; } Tp::DBusError error; mInterface->mPriv->turnOnSpeakerCB(active, &error); if (error.isValid()) { context->setFinishedWithError(error.name(), error.message()); return; } context->setFinished(); } BaseChannelSpeakerInterface::BaseChannelSpeakerInterface() : AbstractChannelInterface(TP_QT_IFACE_CHANNEL_SPEAKER), mPriv(new Private(this)) { } BaseChannelSpeakerInterface::~BaseChannelSpeakerInterface() { delete mPriv; } bool BaseChannelSpeakerInterface::speakerMode() const { return mPriv->speakerMode; } void BaseChannelSpeakerInterface::setTurnOnSpeakerCallback(const turnOnSpeakerCallback &cb) { mPriv->turnOnSpeakerCB = cb; } void BaseChannelSpeakerInterface::setSpeakerMode(bool active) { mPriv->speakerMode = active; Q_EMIT mPriv->adaptee->speakerChanged(active); } QVariantMap BaseChannelSpeakerInterface::immutableProperties() const { QVariantMap map; return map; } void BaseChannelSpeakerInterface::createAdaptor() { (void) new ChannelInterfaceSpeakerAdaptor(dbusObject()->dbusConnection(), mPriv->adaptee, dbusObject()); } ChannelInterfaceSpeakerAdaptor::ChannelInterfaceSpeakerAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent) : Tp::AbstractAdaptor(bus, adaptee, parent) { connect(adaptee, SIGNAL(speakerChanged(bool)), SIGNAL(SpeakerChanged(bool))); } ChannelInterfaceSpeakerAdaptor::~ChannelInterfaceSpeakerAdaptor() { } void ChannelInterfaceSpeakerAdaptor::turnOnSpeaker(bool active, const QDBusMessage& dbusMessage) { if (!adaptee()->metaObject()->indexOfMethod("turnOnSpeaker(bool,ChannelInterfaceSpeakerAdaptor::turnOnSpeakerContextPtr)") == -1) { dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); return; } turnOnSpeakerContextPtr ctx = turnOnSpeakerContextPtr( new Tp::MethodInvocationContext< bool >(dbusConnection(), dbusMessage)); QMetaObject::invokeMethod(adaptee(), "turnOnSpeaker", Q_ARG(bool, active), Q_ARG(ChannelInterfaceSpeakerAdaptor::turnOnSpeakerContextPtr, ctx)); return; } bool ChannelInterfaceSpeakerAdaptor::SpeakerMode() const { return qvariant_cast< bool >(adaptee()->property("speakerMode")); } telepathy-ofono-0.2+14.04.20140407/ofonotextchannel.h0000644000015301777760000000521512320626661022625 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef OFONOTEXTCHANNEL_H #define OFONOTEXTCHANNEL_H #include #include #include #include #include #include "connection.h" class oFonoConnection; class oFonoTextChannel : public QObject { Q_OBJECT public: oFonoTextChannel(oFonoConnection *conn, QStringList phoneNumbers, bool flash = false, QObject *parent = 0); QString sendMessage(const Tp::MessagePartList& message, uint flags, Tp::DBusError* error); void messageReceived(const QString & message, uint handle, const QVariantMap &info); Tp::BaseChannelPtr baseChannel(); void messageAcknowledged(const QString &id); void mmsReceived(const QString &id, uint handle, const QVariantMap &properties); void deliveryReportReceived(const QString& messageId, uint handle, bool success); void addMembers(QStringList phoneNumbers); Tp::UIntList members(); void onAddMembers(const Tp::UIntList& handles, const QString& message, Tp::DBusError* error); void onRemoveMembers(const Tp::UIntList& handles, const QString& message, Tp::DBusError* error); private Q_SLOTS: void onOfonoMessageStateChanged(QString status); void onProcessPendingDeliveryReport(); Q_SIGNALS: void messageRead(const QString &id); private: void sendDeliveryReport(const QString &messageId, uint handle, Tp::DeliveryStatus status); ~oFonoTextChannel(); Tp::BaseChannelPtr mBaseChannel; QStringList mPhoneNumbers; oFonoConnection *mConnection; Tp::BaseChannelMessagesInterfacePtr mMessagesIface; Tp::BaseChannelGroupInterfacePtr mGroupIface; Tp::BaseChannelSMSInterfacePtr mSMSIface; Tp::BaseChannelTextTypePtr mTextChannel; uint mMessageCounter; QMap mPendingDeliveryReportFailed; QMap mPendingDeliveryReportDelivered; Tp::UIntList mMembers; bool mFlash; }; #endif // OFONOTEXTCHANNEL_H telepathy-ofono-0.2+14.04.20140407/ofonocallchannel.h0000644000015301777760000000563412320626651022560 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef OFONOCALLCHANNEL_H #define OFONOCALLCHANNEL_H #include #include #include #include #include #include #include "connection.h" #include "speakeriface.h" class oFonoConnection; class oFonoCallChannel : public OfonoVoiceCall { Q_OBJECT public: oFonoCallChannel(oFonoConnection *conn, QString phoneNumber, uint targetHandle, QString voiceObj, QObject *parent = 0); ~oFonoCallChannel(); Tp::BaseChannelPtr baseChannel(); void onHangup(uint reason, const QString &detailedReason, const QString &message, Tp::DBusError* error); void onAccept(Tp::DBusError*); void onMuteStateChanged(const Tp::LocalMuteState &state, Tp::DBusError *error); void onHoldStateChanged(const Tp::LocalHoldState &state, const Tp::LocalHoldStateReason &reason, Tp::DBusError *error); void onDTMFStartTone(uchar event, Tp::DBusError *error); void onDTMFStopTone(Tp::DBusError *error); void onTurnOnSpeaker(bool active, Tp::DBusError *error); void onSplit(Tp::DBusError *error); Tp::CallState callState(); Q_SIGNALS: void splitted(); void merged(); void closed(); void multipartyCallHeld(); void multipartyCallActive(); private Q_SLOTS: void onOfonoCallStateChanged(const QString &state); void onDtmfComplete(bool success); void sendNextDtmf(); void init(); void onOfonoMuteChanged(bool mute); void onMultipartyChanged(bool multiparty); private: QString mObjPath; QString mPreviousState; bool mIncoming; bool mRequestedHangup; Tp::BaseChannelPtr mBaseChannel; QString mPhoneNumber; oFonoConnection *mConnection; uint mTargetHandle; Tp::BaseChannelHoldInterfacePtr mHoldIface; Tp::BaseChannelSplittableInterfacePtr mSplittableIface; Tp::BaseCallMuteInterfacePtr mMuteIface; BaseChannelSpeakerInterfacePtr mSpeakerIface; Tp::BaseChannelCallTypePtr mCallChannel; Tp::BaseCallContentDTMFInterfacePtr mDTMFIface; Tp::BaseCallContentPtr mCallContent; bool mDtmfLock; QStringList mDtmfPendingStrings; bool mMultiparty; }; #endif // OFONOCALLCHANNEL_H telepathy-ofono-0.2+14.04.20140407/ussdiface.h0000644000015301777760000002220612320626661021214 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef OFONOUSSDIFACE_H #define OFONOUSSDIFACE_H // telepathy-qt #include #include #include #include #include class BaseConnectionUSSDInterface; typedef Tp::SharedPtr BaseConnectionUSSDInterfacePtr; #define TP_QT_IFACE_CONNECTION_USSD "com.canonical.Telephony.USSD" class TP_QT_EXPORT BaseConnectionUSSDInterface : public Tp::AbstractConnectionInterface { Q_OBJECT Q_DISABLE_COPY(BaseConnectionUSSDInterface) public: static BaseConnectionUSSDInterfacePtr create() { return BaseConnectionUSSDInterfacePtr(new BaseConnectionUSSDInterface()); } template static Tp::SharedPtr create() { return Tp::SharedPtr( new BaseConnectionUSSDInterfaceSubclass()); } QVariantMap immutableProperties() const; virtual ~BaseConnectionUSSDInterface(); typedef Tp::Callback2 InitiateCallback; void setInitiateCallback(const InitiateCallback &cb); typedef Tp::Callback2 RespondCallback; void setRespondCallback(const RespondCallback &cb); typedef Tp::Callback1 CancelCallback; void setCancelCallback(const CancelCallback &cb); QString state() const; QString serial() const; void setSerial(const QString& serial) const; public Q_SLOTS: void NotificationReceived(const QString &message); void RequestReceived(const QString &message); void InitiateUSSDComplete(const QString &ussdResp); void RespondComplete(bool success, const QString &ussdResp); void BarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap); void ForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap); void WaitingComplete(const QString &ssOp, const QVariantMap &cwMap); void CallingLinePresentationComplete(const QString &ssOp, const QString &status); void ConnectedLinePresentationComplete(const QString &ssOp, const QString &status); void CallingLineRestrictionComplete(const QString &ssOp, const QString &status); void ConnectedLineRestrictionComplete(const QString &ssOp, const QString &status); void InitiateFailed(); void StateChanged(const QString &state); protected: BaseConnectionUSSDInterface(); private: void createAdaptor(); class Adaptee; friend class Adaptee; struct Private; friend struct Private; Private *mPriv; }; class TP_QT_EXPORT ConnectionInterfaceUSSDAdaptor : public Tp::AbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", TP_QT_IFACE_CONNECTION_USSD) Q_CLASSINFO("D-Bus Introspection", "" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "") Q_PROPERTY(QString State READ State) Q_PROPERTY(QString Serial READ Serial) public: ConnectionInterfaceUSSDAdaptor(const QDBusConnection& dbusConnection, QObject* adaptee, QObject* parent); virtual ~ConnectionInterfaceUSSDAdaptor(); typedef Tp::MethodInvocationContextPtr< > InitiateContextPtr; typedef Tp::MethodInvocationContextPtr< > RespondContextPtr; typedef Tp::MethodInvocationContextPtr< > CancelContextPtr; public Q_SLOTS: // METHODS void Initiate(const QString &command, const QDBusMessage& dbusMessage); void Respond(const QString &reply, const QDBusMessage& dbusMessage); void Cancel(const QDBusMessage& dbusMessage); QString State() const; QString Serial() const; Q_SIGNALS: // SIGNALS void NotificationReceived(const QString &message); void RequestReceived(const QString &message); void InitiateUSSDComplete(const QString &ussdResp); void RespondComplete(bool success, const QString &ussdResp); void BarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap); void ForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap); void WaitingComplete(const QString &ssOp, const QVariantMap &cwMap); void CallingLinePresentationComplete(const QString &ssOp, const QString &status); void ConnectedLinePresentationComplete(const QString &ssOp, const QString &status); void CallingLineRestrictionComplete(const QString &ssOp, const QString &status); void ConnectedLineRestrictionComplete(const QString &ssOp, const QString &status); void InitiateFailed(); void StateChanged(const QString &state); }; class TP_QT_NO_EXPORT BaseConnectionUSSDInterface::Adaptee : public QObject { Q_OBJECT Q_PROPERTY(QString state READ state) Q_PROPERTY(QString serial READ serial) public: Adaptee(BaseConnectionUSSDInterface *interface); ~Adaptee(); QString state() const { return mInterface->state(); } QString serial() const { return mInterface->serial(); } private Q_SLOTS: void initiate(const QString &command, const ConnectionInterfaceUSSDAdaptor::InitiateContextPtr &context); void respond(const QString &reply, const ConnectionInterfaceUSSDAdaptor::RespondContextPtr &context); void cancel(const ConnectionInterfaceUSSDAdaptor::CancelContextPtr &context); Q_SIGNALS: void notificationReceived(const QString &message); void requestReceived(const QString &message); void initiateUSSDComplete(const QString &ussdResp); void barringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap); void forwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap); void waitingComplete(const QString &ssOp, const QVariantMap &cwMap); void callingLinePresentationComplete(const QString &ssOp, const QString &status); void connectedLinePresentationComplete(const QString &ssOp, const QString &status); void callingLineRestrictionComplete(const QString &ssOp, const QString &status); void connectedLineRestrictionComplete(const QString &ssOp, const QString &status); void initiateFailed(); void respondComplete(bool success, const QString &response); void stateChanged(const QString &state); public: BaseConnectionUSSDInterface *mInterface; }; #endif telepathy-ofono-0.2+14.04.20140407/phonenumberutils_p.h0000644000015301777760000001723012320626651023170 0ustar pbusernogroup00000000000000/* * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Original source code available at: http://androidxref.com/4.0.4/xref/frameworks/base/telephony/java/android/telephony/PhoneNumberUtils.java */ #ifndef PHONENUMBERUTILS_H #define PHONENUMBERUTILS_H namespace PhoneNumberUtils { /** True if c is ISO-LATIN characters 0-9, *, # , +, WILD, WAIT, PAUSE */ bool isNonSeparator(char c) { return (c >= '0' && c <= '9') || c == '*' || c == '#' || c == '+' || c == 'N' || c == ';' || c == ','; } /** True if c is ISO-LATIN characters 0-9, *, # , +, WILD */ bool isDialable(char c) { return (c >= '0' && c <= '9') || c == '*' || c == '#' || c == '+' || c == 'N'; } /** True if c is ISO-LATIN characters 0-9 */ bool isISODigit (char c) { return c >= '0' && c <= '9'; } /** or -1 if both are negative */ int minPositive (int a, int b) { if (a >= 0 && b >= 0) { return (a < b) ? a : b; } else if (a >= 0) { /* && b < 0 */ return a; } else if (b >= 0) { /* && a < 0 */ return b; } else { /* a < 0 && b < 0 */ return -1; } } /** index of the last character of the network portion * (eg anything after is a post-dial string) */ int indexOfLastNetworkChar(const QString &a) { int pIndex, wIndex; int origLength; int trimIndex; origLength = a.length(); pIndex = a.indexOf(','); wIndex = a.indexOf(';'); trimIndex = minPositive(pIndex, wIndex); if (trimIndex < 0) { return origLength - 1; } else { return trimIndex - 1; } } /** all of a up to len must be an international prefix or * separators/non-dialing digits */ bool matchIntlPrefix(const QString &a, int len) { /* '([^0-9*#+pwn]\+[^0-9*#+pwn] | [^0-9*#+pwn]0(0|11)[^0-9*#+pwn] )$' */ /* 0 1 2 3 45 */ int state = 0; for (int i = 0 ; i < len ; i++) { char c = a.at(i).toLatin1(); switch (state) { case 0: if (c == '+') state = 1; else if (c == '0') state = 2; else if (isNonSeparator(c)) return false; break; case 2: if (c == '0') state = 3; else if (c == '1') state = 4; else if (isNonSeparator(c)) return false; break; case 4: if (c == '1') state = 5; else if (isNonSeparator(c)) return false; break; default: if (isNonSeparator(c)) return false; break; } } return state == 1 || state == 3 || state == 5; } /** all of 'a' up to len must match non-US trunk prefix ('0') */ bool matchTrunkPrefix(const QString &a, int len) { bool found; found = false; for (int i = 0 ; i < len ; i++) { char c = a.at(i).toLatin1(); if (c == '0' && !found) { found = true; } else if (isNonSeparator(c)) { return false; } } return found; } /** all of 'a' up to len must be a (+|00|011)country code) * We're fast and loose with the country code. Any \d{1,3} matches */ bool matchIntlPrefixAndCC(const QString &a, int len) { /* [^0-9*#+pwn]*(\+|0(0|11)\d\d?\d? [^0-9*#+pwn] $ */ /* 0 1 2 3 45 6 7 8 */ int state = 0; for (int i = 0 ; i < len ; i++ ) { char c = a.at(i).toLatin1(); switch (state) { case 0: if (c == '+') state = 1; else if (c == '0') state = 2; else if (isNonSeparator(c)) return false; break; case 2: if (c == '0') state = 3; else if (c == '1') state = 4; else if (isNonSeparator(c)) return false; break; case 4: if (c == '1') state = 5; else if (isNonSeparator(c)) return false; break; case 1: case 3: case 5: if (isISODigit(c)) state = 6; else if (isNonSeparator(c)) return false; break; case 6: case 7: if (isISODigit(c)) state++; else if (isNonSeparator(c)) return false; break; default: if (isNonSeparator(c)) return false; } } return state == 6 || state == 7 || state == 8; } /** * Compare phone numbers a and b, return true if they're identical * enough for caller ID purposes. * * - Compares from right to left * - requires MIN_MATCH (7) characters to match * - handles common trunk prefixes and international prefixes * (basically, everything except the Russian trunk prefix) * * Note that this method does not return false even when the two phone numbers * are not exactly same; rather; we can call this method "similar()", not "equals()". * * @hide */ bool compareLoosely(const QString &a, const QString &b) { int ia, ib; int matched; int numNonDialableCharsInA = 0; int numNonDialableCharsInB = 0; if (a.length() == 0 || b.length() == 0) { return false; } if (a == b) { return true; } ia = indexOfLastNetworkChar (a); ib = indexOfLastNetworkChar (b); matched = 0; while (ia >= 0 && ib >=0) { char ca, cb; bool skipCmp = false; ca = a.at(ia).toLatin1(); if (!isDialable(ca)) { ia--; skipCmp = true; numNonDialableCharsInA++; } cb = b.at(ib).toLatin1(); if (!isDialable(cb)) { ib--; skipCmp = true; numNonDialableCharsInB++; } if (!skipCmp) { if (cb != ca && ca != 'N' && cb != 'N') { break; } ia--; ib--; matched++; } } if (matched < 7) { int effectiveALen = a.length() - numNonDialableCharsInA; int effectiveBLen = b.length() - numNonDialableCharsInB; // if the number of dialable chars in a and b match, but the matched chars < MIN_MATCH, // treat them as equal (i.e. 404-04 and 40404) if (effectiveALen == effectiveBLen && effectiveALen == matched) { return true; } return false; } // At least one string has matched completely; if (matched >= 7 && (ia < 0 || ib < 0)) { return true; } /* * Now, what remains must be one of the following for a * match: * * - a '+' on one and a '00' or a '011' on the other * - a '0' on one and a (+,00) on the other * (for this, a '0' and a '00' prefix would have succeeded above) */ if (matchIntlPrefix(a, ia + 1) && matchIntlPrefix (b, ib +1) ) { return true; } if (matchTrunkPrefix(a, ia + 1) && matchIntlPrefixAndCC(b, ib +1) ) { return true; } if (matchTrunkPrefix(b, ib + 1) && matchIntlPrefixAndCC(a, ia +1) ) { return true; } return false; } } #endif telepathy-ofono-0.2+14.04.20140407/ofono.manager0000644000015301777760000000030612320626651021545 0ustar pbusernogroup00000000000000[ConnectionManager] Name = ofono BusName = org.freedesktop.Telepathy.ConnectionManager.ofono ObjectPath = /org/freedesktop/Telepathy/ConnectionManager/ofono [Protocol ofono] param-modem-objpath=s telepathy-ofono-0.2+14.04.20140407/protocol.h0000644000015301777760000000216312320626651021106 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * Authors: * Tiago Salem Herrmann * * This file is part of telepathy-ofono. * * telepathy-ofono is free software; you can redistribute it and/or modify * it under the terms of the GNU LESSER General Public License as published by * the Free Software Foundation; version 3. * * telepathy-ofono is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU LESSER General Public License * along with this program. If not, see . */ #ifndef OFONOPROTOCOL_H #define OFONOPROTOCOL_H #include class Protocol : public Tp::BaseProtocol { Q_OBJECT Q_DISABLE_COPY(Protocol) public: Protocol(const QDBusConnection &dbusConnection, const QString &name); private: Tp::BaseConnectionPtr createConnection(const QVariantMap ¶meters, Tp::DBusError *error); }; #endif telepathy-ofono-0.2+14.04.20140407/connection.cpp0000644000015301777760000012112312320626661021736 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include #include #include // ofono-qt #include // telepathy-ofono #include "connection.h" #include "phoneutils_p.h" #include "protocol.h" #include "ofonoconferencecallchannel.h" #include "mmsdmessage.h" #include "mmsdservice.h" // audioflinger #ifdef USE_AUDIOFLINGER #include #endif #ifdef USE_PULSEAUDIO #include "qpulseaudioengine.h" #endif #include "sqlitedatabase.h" #include "pendingmessagesmanager.h" static void enable_earpiece() { #ifdef USE_AUDIOFLINGER char parameter[20]; int i; /* Set the call mode in AudioFlinger */ AudioSystem_setMode(AUDIO_MODE_IN_CALL); sprintf(parameter, "routing=%d", AUDIO_DEVICE_OUT_EARPIECE); /* Try the first 3 threads, as this is not fixed and there's no easy * way to retrieve the default thread/output from Android */ for (i = 1; i <= 3; i++) { if (AudioSystem_setParameters(i, parameter) >= 0) break; } #endif #ifdef USE_PULSEAUDIO QPulseAudioEngine::instance()->setCallMode(true, false); #endif } static void enable_normal() { #ifdef USE_AUDIOFLINGER char parameter[20]; int i; /* Set normal mode in AudioFlinger */ AudioSystem_setMode(AUDIO_MODE_NORMAL); /* Get device back to speaker mode, as by default in_call * mode sets up device out to earpiece */ sprintf(parameter, "routing=%d", AUDIO_DEVICE_OUT_SPEAKER); /* Try the first 3 threads, as this is not fixed and there's no easy * way to retrieve the default thread/output from Android */ for (i = 1; i <= 3; i++) { if (AudioSystem_setParameters(i, parameter) >= 0) break; } #endif #ifdef USE_PULSEAUDIO QPulseAudioEngine::instance()->setCallMode(false, false); QPulseAudioEngine::instance()->setMicMute(false); #endif } static void enable_speaker() { #ifdef USE_AUDIOFLINGER char parameter[20]; int i; /* Set the call mode in AudioFlinger */ AudioSystem_setMode(AUDIO_MODE_IN_CALL); sprintf(parameter, "routing=%d", AUDIO_DEVICE_OUT_SPEAKER); /* Try the first 3 threads, as this is not fixed and there's no easy * way to retrieve the default thread/output from Android */ for (i = 1; i <= 3; i++) { if (AudioSystem_setParameters(i, parameter) >= 0) break; } #endif #ifdef USE_PULSEAUDIO QPulseAudioEngine::instance()->setCallMode(true, true); #endif } static void enable_ringtone() { #ifdef USE_AUDIOFLINGER char parameter[20]; int i; /* Set the call mode in AudioFlinger */ AudioSystem_setMode(AUDIO_MODE_IN_CALL); sprintf(parameter, "routing=%d", AUDIO_DEVICE_OUT_SPEAKER); /* Try the first 3 threads, as this is not fixed and there's no easy * way to retrieve the default thread/output from Android */ for (i = 1; i <= 3; i++) { if (AudioSystem_setParameters(i, parameter) >= 0) break; } #endif #ifdef USE_PULSEAUDIO QPulseAudioEngine::instance()->setCallMode(false, true); #endif } // miliseconds #define OFONO_REGISTER_RETRY_TIME 5000 oFonoConnection::oFonoConnection(const QDBusConnection &dbusConnection, const QString &cmName, const QString &protocolName, const QVariantMap ¶meters) : Tp::BaseConnection(dbusConnection, cmName, protocolName, parameters), mOfonoModemManager(new OfonoModemManager(this)), mHandleCount(0), mRegisterTimer(new QTimer(this)), mMmsdManager(new MMSDManager(this)), mSpeakerMode(false), mConferenceCall(NULL) { OfonoModem::SelectionSetting setting = OfonoModem::AutomaticSelect; QString modemPath = parameters["modem-objpath"].toString(); if (!modemPath.isEmpty()) { setting = OfonoModem::ManualSelect; } mOfonoMessageManager = new OfonoMessageManager(setting, modemPath); mOfonoVoiceCallManager = new OfonoVoiceCallManager(setting, modemPath); mOfonoCallVolume = new OfonoCallVolume(setting, modemPath); mOfonoNetworkRegistration = new OfonoNetworkRegistration(setting, modemPath); mOfonoMessageWaiting = new OfonoMessageWaiting(setting, modemPath); mOfonoSupplementaryServices = new OfonoSupplementaryServices(setting, modemPath); setSelfHandle(newHandle("")); setConnectCallback(Tp::memFun(this,&oFonoConnection::connect)); setInspectHandlesCallback(Tp::memFun(this,&oFonoConnection::inspectHandles)); setRequestHandlesCallback(Tp::memFun(this,&oFonoConnection::requestHandles)); setCreateChannelCallback(Tp::memFun(this,&oFonoConnection::createChannel)); // initialise requests interface (Connection.Interface.Requests) requestsIface = Tp::BaseConnectionRequestsInterface::create(this); // set requestable text channel properties Tp::RequestableChannelClass text; text.fixedProperties[TP_QT_IFACE_CHANNEL+".ChannelType"] = TP_QT_IFACE_CHANNEL_TYPE_TEXT; text.fixedProperties[TP_QT_IFACE_CHANNEL+".TargetHandleType"] = Tp::HandleTypeContact; text.allowedProperties.append(TP_QT_IFACE_CHANNEL+".TargetHandle"); text.allowedProperties.append(TP_QT_IFACE_CHANNEL+".TargetID"); text.allowedProperties.append(TP_QT_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialInviteeHandles")); // set requestable call channel properties Tp::RequestableChannelClass call; call.fixedProperties[TP_QT_IFACE_CHANNEL+".ChannelType"] = TP_QT_IFACE_CHANNEL_TYPE_CALL; call.fixedProperties[TP_QT_IFACE_CHANNEL+".TargetHandleType"] = Tp::HandleTypeContact; call.fixedProperties[TP_QT_IFACE_CHANNEL_TYPE_CALL+".InitialAudio"] = true; call.allowedProperties.append(TP_QT_IFACE_CHANNEL+".TargetHandle"); call.allowedProperties.append(TP_QT_IFACE_CHANNEL+".TargetID"); call.allowedProperties.append(TP_QT_IFACE_CHANNEL_TYPE_CALL+".InitialAudio"); call.allowedProperties.append(TP_QT_IFACE_CHANNEL_TYPE_CALL+".InitialVideo"); call.allowedProperties.append(TP_QT_IFACE_CHANNEL_TYPE_CALL+".InitialAudioName"); call.allowedProperties.append(TP_QT_IFACE_CHANNEL_TYPE_CALL+".InitialVideoName"); call.allowedProperties.append(TP_QT_IFACE_CHANNEL_TYPE_CALL+".InitialTransport"); call.allowedProperties.append(TP_QT_IFACE_CHANNEL_TYPE_CALL+".HardwareStreaming"); call.allowedProperties.append(TP_QT_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialChannels")); requestsIface->requestableChannelClasses << text << call; plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(requestsIface)); // init presence interface simplePresenceIface = Tp::BaseConnectionSimplePresenceInterface::create(); simplePresenceIface->setSetPresenceCallback(Tp::memFun(this,&oFonoConnection::setPresence)); plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(simplePresenceIface)); // init custom voicemail interface (not provided by telepathy) voicemailIface = BaseConnectionVoicemailInterface::create(); voicemailIface->setVoicemailCountCallback(Tp::memFun(this,&oFonoConnection::voicemailCount)); voicemailIface->setVoicemailIndicatorCallback(Tp::memFun(this,&oFonoConnection::voicemailIndicator)); voicemailIface->setVoicemailNumberCallback(Tp::memFun(this,&oFonoConnection::voicemailNumber)); plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(voicemailIface)); supplementaryServicesIface = BaseConnectionUSSDInterface::create(); supplementaryServicesIface->setInitiateCallback(Tp::memFun(this,&oFonoConnection::USSDInitiate)); supplementaryServicesIface->setRespondCallback(Tp::memFun(this,&oFonoConnection::USSDRespond)); supplementaryServicesIface->setCancelCallback(Tp::memFun(this,&oFonoConnection::USSDCancel)); supplementaryServicesIface->StateChanged(mOfonoSupplementaryServices->state()); supplementaryServicesIface->setSerial(mOfonoSupplementaryServices->modem()->serial()); plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(supplementaryServicesIface)); // Set Presence Tp::SimpleStatusSpec presenceOnline; presenceOnline.type = Tp::ConnectionPresenceTypeAvailable; presenceOnline.maySetOnSelf = true; presenceOnline.canHaveMessage = false; Tp::SimpleStatusSpec presenceOffline; presenceOffline.type = Tp::ConnectionPresenceTypeOffline; presenceOffline.maySetOnSelf = false; presenceOffline.canHaveMessage = false; Tp::SimpleStatusSpecMap statuses; statuses.insert(QLatin1String("available"), presenceOnline); statuses.insert(QLatin1String("offline"), presenceOffline); simplePresenceIface->setStatuses(statuses); mSelfPresence.type = Tp::ConnectionPresenceTypeOffline; mRequestedSelfPresence.type = Tp::ConnectionPresenceTypeOffline; bool validModem = false; if (mOfonoVoiceCallManager->modem()) { validModem = mOfonoVoiceCallManager->modem()->isValid(); if (validModem) { supplementaryServicesIface->setSerial(mOfonoSupplementaryServices->modem()->serial()); QObject::connect(mOfonoVoiceCallManager->modem(), SIGNAL(onlineChanged(bool)), SLOT(onValidityChanged(bool))); } } // force update current presence onOfonoNetworkRegistrationChanged(mOfonoNetworkRegistration->status()); contactsIface = Tp::BaseConnectionContactsInterface::create(); contactsIface->setGetContactAttributesCallback(Tp::memFun(this,&oFonoConnection::getContactAttributes)); contactsIface->setContactAttributeInterfaces(QStringList() << TP_QT_IFACE_CONNECTION << TP_QT_IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE); plugInterface(Tp::AbstractConnectionInterfacePtr::dynamicCast(contactsIface)); QObject::connect(mOfonoMessageManager, SIGNAL(incomingMessage(QString,QVariantMap)), this, SLOT(onOfonoIncomingMessage(QString,QVariantMap))); QObject::connect(mOfonoMessageManager, SIGNAL(immediateMessage(QString,QVariantMap)), this, SLOT(onOfonoImmediateMessage(QString,QVariantMap))); QObject::connect(mOfonoMessageManager, SIGNAL(statusReport(QString,QVariantMap)), this, SLOT(onDeliveryReportReceived(QString,QVariantMap))); QObject::connect(mOfonoVoiceCallManager, SIGNAL(callAdded(QString,QVariantMap)), SLOT(onOfonoCallAdded(QString, QVariantMap))); QObject::connect(mOfonoVoiceCallManager, SIGNAL(validityChanged(bool)), SLOT(onValidityChanged(bool))); QObject::connect(mOfonoNetworkRegistration, SIGNAL(statusChanged(QString)), SLOT(onOfonoNetworkRegistrationChanged(QString))); QObject::connect(mOfonoMessageWaiting, SIGNAL(voicemailMessageCountChanged(int)), voicemailIface.data(), SLOT(setVoicemailCount(int))); QObject::connect(mOfonoMessageWaiting, SIGNAL(voicemailWaitingChanged(bool)), voicemailIface.data(), SLOT(setVoicemailIndicator(bool))); QObject::connect(mRegisterTimer, SIGNAL(timeout()), SLOT(onTryRegister())); QObject::connect(mMmsdManager, SIGNAL(serviceAdded(const QString&)), SLOT(onMMSDServiceAdded(const QString&))); QObject::connect(mMmsdManager, SIGNAL(serviceRemoved(const QString&)), SLOT(onMMSDServiceRemoved(const QString&))); // update audio route QObject::connect(mOfonoVoiceCallManager, SIGNAL(callAdded(QString,QVariantMap)), SLOT(updateAudioRoute())); QObject::connect(mOfonoVoiceCallManager, SIGNAL(callRemoved(QString)), SLOT(updateAudioRoute())); QObject::connect(mOfonoSupplementaryServices, SIGNAL(notificationReceived(const QString &)), supplementaryServicesIface.data(), SLOT(NotificationReceived(const QString &))); QObject::connect(mOfonoSupplementaryServices, SIGNAL(requestReceived(const QString &)), supplementaryServicesIface.data(), SLOT(RequestReceived(const QString &))); QObject::connect(mOfonoSupplementaryServices, SIGNAL(initiateUSSDComplete(const QString &)), supplementaryServicesIface.data(), SLOT(InitiateUSSDComplete(const QString &))); QObject::connect(mOfonoSupplementaryServices, SIGNAL(barringComplete(const QString &, const QString &, const QVariantMap &)), supplementaryServicesIface.data(), SLOT(BarringComplete(const QString &, const QString &, const QVariantMap &))); QObject::connect(mOfonoSupplementaryServices, SIGNAL(forwardingComplete(const QString &, const QString &, const QVariantMap &)), supplementaryServicesIface.data(), SLOT(ForwardingComplete(const QString &, const QString &, const QVariantMap &))); QObject::connect(mOfonoSupplementaryServices, SIGNAL(waitingComplete(const QString &, const QVariantMap &)), supplementaryServicesIface.data(), SLOT(WaitingComplete(const QString &, const QVariantMap &))); QObject::connect(mOfonoSupplementaryServices, SIGNAL(callingLinePresentationComplete(const QString &, const QString &)), supplementaryServicesIface.data(), SLOT(CallingLinePresentationComplete(const QString &, const QString &))); QObject::connect(mOfonoSupplementaryServices, SIGNAL(connectedLinePresentationComplete(const QString &, const QString &)), supplementaryServicesIface.data(), SLOT(ConnectedLinePresentationComplete(const QString &, const QString &))); QObject::connect(mOfonoSupplementaryServices, SIGNAL(callingLineRestrictionComplete(const QString &, const QString &)), supplementaryServicesIface.data(), SLOT(CallingLineRestrictionComplete(const QString &, const QString &))); QObject::connect(mOfonoSupplementaryServices, SIGNAL(connectedLineRestrictionComplete(const QString &, const QString &)), supplementaryServicesIface.data(), SLOT(ConnectedLineRestrictionComplete(const QString &, const QString &))); QObject::connect(mOfonoSupplementaryServices, SIGNAL(initiateFailed()), supplementaryServicesIface.data(), SLOT(InitiateFailed())); QObject::connect(mOfonoSupplementaryServices, SIGNAL(stateChanged(const QString&)), supplementaryServicesIface.data(), SLOT(StateChanged(const QString&))); QObject::connect(mOfonoSupplementaryServices, SIGNAL(respondComplete(bool, const QString &)), supplementaryServicesIface.data(), SLOT(RespondComplete(bool, const QString &))); // workaround: we can't add services here as tp-ofono interfaces are not exposed on dbus // todo: use QDBusServiceWatcher QTimer::singleShot(1000, this, SLOT(onCheckMMSServices())); } QMap oFonoConnection::callChannels() { return mCallChannels; } void oFonoConnection::onCheckMMSServices() { Q_FOREACH(QString servicePath, mMmsdManager->services()) { onMMSDServiceAdded(servicePath); } } void oFonoConnection::onMMSDServiceAdded(const QString &path) { qDebug() << "oFonoConnection::onMMSServiceAdded" << path; MMSDService *service = new MMSDService(path, this); mMmsdServices[path] = service; QObject::connect(service, SIGNAL(messageAdded(const QString&, const QVariantMap&)), SLOT(onMMSAdded(const QString&, const QVariantMap&))); QObject::connect(service, SIGNAL(messageRemoved(const QString&)), SLOT(onMMSRemoved(const QString&))); Q_FOREACH(MessageStruct message, service->messages()) { addMMSToService(message.path.path(), message.properties, service->path()); } } void oFonoConnection::onMMSPropertyChanged(QString property, QVariant value) { qDebug() << "oFonoConnection::onMMSPropertyChanged" << property << value; if (property == "Status") { if (value == "sent") { // FIXME send delivery report } } } void oFonoConnection::onMMSDServiceRemoved(const QString &path) { MMSDService *service = mMmsdServices.take(path); if (!service) { qWarning() << "oFonoConnection::onMMSServiceRemoved failed" << path; return; } // remove all messages from this service Q_FOREACH(MMSDMessage *message, mServiceMMSList[service->path()]) { qDebug() << "removing message " << message->path() << " from service " << service->path(); message->deleteLater(); mServiceMMSList[service->path()].removeAll(message); } mServiceMMSList.remove(service->path()); service->deleteLater(); qDebug() << "oFonoConnection::onMMSServiceRemoved" << path; } oFonoTextChannel* oFonoConnection::textChannelForMembers(const QStringList &members) { Q_FOREACH(oFonoTextChannel* channel, mTextChannels) { int count = 0; Tp::DBusError error; if (members.size() != channel->members().size()) { continue; } QStringList phoneNumbersOld = inspectHandles(Tp::HandleTypeContact, channel->members(), &error); if (error.isValid()) { continue; } Q_FOREACH(const QString &phoneNumberNew, members) { Q_FOREACH(const QString &phoneNumberOld, phoneNumbersOld) { if (PhoneUtils::comparePhoneNumbers(PhoneUtils::normalizePhoneNumber(phoneNumberOld), PhoneUtils::normalizePhoneNumber(phoneNumberNew))) { count++; } } } if (count == members.size()) { return channel; } } return NULL; } void oFonoConnection::addMMSToService(const QString &path, const QVariantMap &properties, const QString &servicePath) { qDebug() << "addMMSToService " << path << properties << servicePath; MMSDMessage *msg = new MMSDMessage(path, properties); QObject::connect(msg, SIGNAL(propertyChanged(QString,QVariant)), SLOT(onMMSPropertyChanged(QString,QVariant))); mServiceMMSList[servicePath].append(msg); if (properties["Status"] == "received") { const QString normalizedNumber = PhoneUtils::normalizePhoneNumber(properties["Sender"].toString()); // check if there is an open channel for this number and use it oFonoTextChannel *channel = textChannelForMembers(QStringList() << normalizedNumber); if (channel) { channel->mmsReceived(path, ensureHandle(normalizedNumber), properties); return; } Tp::DBusError error; bool yours; qDebug() << "new handle" << normalizedNumber; uint handle = newHandle(normalizedNumber); ensureChannel(TP_QT_IFACE_CHANNEL_TYPE_TEXT,Tp::HandleTypeContact, handle, yours, handle, false, QVariantMap(), &error); if(error.isValid()) { qCritical() << "Error creating channel for incoming message " << error.name() << error.message(); return; } channel = textChannelForMembers(QStringList() << normalizedNumber); if (channel) { channel->mmsReceived(path, ensureHandle(normalizedNumber), properties); } } } void oFonoConnection::onMMSAdded(const QString &path, const QVariantMap &properties) { qDebug() << "oFonoConnection::onMMSAdded" << path << properties; MMSDService *service = qobject_cast(sender()); if (!service) { qWarning() << "oFonoConnection::onMMSAdded failed"; return; } addMMSToService(path, properties, service->path()); } void oFonoConnection::onMMSRemoved(const QString &path) { qDebug() << "oFonoConnection::onMMSRemoved" << path; MMSDService *service = qobject_cast(sender()); if (!service) { qWarning() << "oFonoConnection::onMMSRemoved failed"; return; } // remove this message from the service Q_FOREACH(MMSDMessage *message, mServiceMMSList[service->path()]) { if (message->path() == path) { message->deleteLater(); mServiceMMSList[service->path()].removeAll(message); break; } } } oFonoConnection::~oFonoConnection() { mOfonoModemManager->deleteLater(); mOfonoMessageManager->deleteLater(); mOfonoVoiceCallManager->deleteLater(); mOfonoCallVolume->deleteLater(); mOfonoNetworkRegistration->deleteLater(); mRegisterTimer->deleteLater(); Q_FOREACH(MMSDService *service, mMmsdServices) { onMMSDServiceRemoved(service->path()); } } void oFonoConnection::onTryRegister() { bool networkRegistered = isNetworkRegistered(); if (networkRegistered) { setOnline(networkRegistered); mRegisterTimer->stop(); return; } // if we have modem, check if it is online OfonoModem *modem = mOfonoNetworkRegistration->modem(); if (modem) { if (!modem->online()) { modem->setOnline(true); } } } bool oFonoConnection::isNetworkRegistered() { QString status = mOfonoNetworkRegistration->status(); return !(!mOfonoNetworkRegistration->modem() || !mOfonoNetworkRegistration->modem()->online() || status == "unregistered" || status == "denied" || status == "unknown" || status == "searching" || status.isEmpty()); } void oFonoConnection::onOfonoNetworkRegistrationChanged(const QString &status) { qDebug() << "onOfonoNetworkRegistrationChanged" << status << "is network registered: " << isNetworkRegistered(); if (!isNetworkRegistered() && mRequestedSelfPresence.type == Tp::ConnectionPresenceTypeAvailable) { setOnline(false); onTryRegister(); mRegisterTimer->setInterval(OFONO_REGISTER_RETRY_TIME); mRegisterTimer->start(); return; } setOnline(isNetworkRegistered()); } uint oFonoConnection::setPresence(const QString& status, const QString& statusMessage, Tp::DBusError *error) { qDebug() << "setPresence" << status; if (status == "available") { mRequestedSelfPresence.type = Tp::ConnectionPresenceTypeAvailable; if (!isNetworkRegistered()) { onTryRegister(); mRegisterTimer->setInterval(OFONO_REGISTER_RETRY_TIME); mRegisterTimer->start(); } } return selfHandle(); } Tp::ContactAttributesMap oFonoConnection::getContactAttributes(const Tp::UIntList &handles, const QStringList &ifaces, Tp::DBusError *error) { qDebug() << "getContactAttributes" << handles << ifaces; Tp::ContactAttributesMap attributesMap; QVariantMap attributes; Q_FOREACH(uint handle, handles) { attributes[TP_QT_IFACE_CONNECTION+"/contact-id"] = inspectHandles(Tp::HandleTypeContact, Tp::UIntList() << handle, error).at(0); if (ifaces.contains(TP_QT_IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE)) { attributes[TP_QT_IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE+"/presence"] = QVariant::fromValue(mSelfPresence); } attributesMap[handle] = attributes; } return attributesMap; } void oFonoConnection::onValidityChanged(bool valid) { qDebug() << "validityChanged" << valid << "is network registered: " << isNetworkRegistered() << mRequestedSelfPresence.type; QObject::disconnect(mOfonoVoiceCallManager->modem(), 0,0,0); QObject::connect(mOfonoVoiceCallManager->modem(), SIGNAL(onlineChanged(bool)), SLOT(onValidityChanged(bool))); supplementaryServicesIface->setSerial(mOfonoSupplementaryServices->modem()->serial()); if (!isNetworkRegistered() && mRequestedSelfPresence.type == Tp::ConnectionPresenceTypeAvailable) { setOnline(false); onTryRegister(); mRegisterTimer->setInterval(OFONO_REGISTER_RETRY_TIME); mRegisterTimer->start(); } } void oFonoConnection::setOnline(bool online) { qDebug() << "setOnline" << online; Tp::SimpleContactPresences presences; if (online) { mSelfPresence.status = "available"; mSelfPresence.statusMessage = ""; mSelfPresence.type = Tp::ConnectionPresenceTypeAvailable; } else { mSelfPresence.status = "offline"; mSelfPresence.statusMessage = ""; mSelfPresence.type = Tp::ConnectionPresenceTypeOffline; } presences[selfHandle()] = mSelfPresence; simplePresenceIface->setPresences(presences); } uint oFonoConnection::newHandle(const QString &identifier) { mHandles[++mHandleCount] = identifier; return mHandleCount; } QStringList oFonoConnection::inspectHandles(uint handleType, const Tp::UIntList& handles, Tp::DBusError *error) { QStringList identifiers; if( handleType != Tp::HandleTypeContact ) { error->set(TP_QT_ERROR_INVALID_ARGUMENT,"Not supported"); return QStringList(); } qDebug() << "oFonoConnection::inspectHandles " << handles; Q_FOREACH( uint handle, handles) { if (mHandles.keys().contains(handle)) { identifiers.append(mHandles.value(handle)); } else { error->set(TP_QT_ERROR_INVALID_HANDLE, "Handle not found"); return QStringList(); } } qDebug() << "oFonoConnection::inspectHandles " << identifiers; return identifiers; } void oFonoConnection::connect(Tp::DBusError *error) { qDebug() << "oFonoConnection::connect"; setStatus(Tp::ConnectionStatusConnected, Tp::ConnectionStatusReasonRequested); } Tp::UIntList oFonoConnection::requestHandles(uint handleType, const QStringList& identifiers, Tp::DBusError* error) { qDebug() << "requestHandles"; Tp::UIntList handles; if( handleType != Tp::HandleTypeContact ) { error->set(TP_QT_ERROR_INVALID_ARGUMENT, "Not supported"); return Tp::UIntList(); } Q_FOREACH( const QString& identifier, identifiers) { const QString normalizedNumber = PhoneUtils::normalizePhoneNumber(identifier); if (mHandles.values().contains(normalizedNumber)) { handles.append(mHandles.key(normalizedNumber)); } else if (PhoneUtils::isPhoneNumber(normalizedNumber)) { handles.append(newHandle(normalizedNumber)); } else { handles.append(newHandle(identifier)); } } qDebug() << "requestHandles" << handles; return handles; } Tp::BaseChannelPtr oFonoConnection::createTextChannel(uint targetHandleType, uint targetHandle, const QVariantMap &hints, Tp::DBusError *error) { Q_UNUSED(targetHandleType); QStringList phoneNumbers; bool flash = false; if (hints.contains(TP_QT_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialInviteeHandles"))) { phoneNumbers << inspectHandles(Tp::HandleTypeContact, qdbus_cast(hints[TP_QT_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialInviteeHandles")]), error); } else { phoneNumbers << mHandles.value(targetHandle); } if (hints.contains(TP_QT_IFACE_CHANNEL_INTERFACE_SMS + QLatin1String(".Flash"))) { flash = hints[TP_QT_IFACE_CHANNEL_INTERFACE_SMS + QLatin1String(".Flash")].toBool(); } oFonoTextChannel *channel = new oFonoTextChannel(this, phoneNumbers, flash); mTextChannels << channel; QObject::connect(channel, SIGNAL(messageRead(QString)), SLOT(onMessageRead(QString))); QObject::connect(channel, SIGNAL(destroyed()), SLOT(onTextChannelClosed())); return channel->baseChannel(); } void oFonoConnection::onMessageRead(const QString &id) { Q_FOREACH(QList messages, mServiceMMSList.values()) { Q_FOREACH(MMSDMessage* message, messages) { if (message->path() == id) { message->markRead(); message->remove(); return; } } } } void oFonoConnection::onConferenceCallChannelClosed() { if (mConferenceCall) { mConferenceCall = NULL; } } Tp::BaseChannelPtr oFonoConnection::createCallChannel(uint targetHandleType, uint targetHandle, const QVariantMap &hints, Tp::DBusError *error) { Q_UNUSED(targetHandleType); bool success = true; QString newPhoneNumber = mHandles.value(targetHandle); if (hints.contains(TP_QT_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialChannels")) && targetHandleType == Tp::HandleTypeNone && targetHandle == 0) { // conference call request if (mConferenceCall) { error->set(TP_QT_ERROR_NOT_AVAILABLE, "Conference call already exists"); return Tp::BaseChannelPtr(); } QList channels = mOfonoVoiceCallManager->createMultiparty(); if (!channels.isEmpty()) { mConferenceCall = new oFonoConferenceCallChannel(this); QObject::connect(mConferenceCall, SIGNAL(destroyed()), SLOT(onConferenceCallChannelClosed())); return mConferenceCall->baseChannel(); } error->set(TP_QT_ERROR_NOT_AVAILABLE, "Impossible to merge calls"); return Tp::BaseChannelPtr(); } QDBusObjectPath objpath(hints["ofonoObjPath"].toString()); if (objpath.path().isEmpty()) { objpath = mOfonoVoiceCallManager->dial(newPhoneNumber, "", success); } qDebug() << "success " << success; if (objpath.path().isEmpty() || !success) { if (!success) { error->set(TP_QT_ERROR_NOT_AVAILABLE, mOfonoVoiceCallManager->errorMessage()); } else { error->set(TP_QT_ERROR_NOT_AVAILABLE, "Channel could not be created"); } return Tp::BaseChannelPtr(); } oFonoCallChannel *channel = new oFonoCallChannel(this, newPhoneNumber, targetHandle, objpath.path()); mCallChannels[objpath.path()] = channel; QObject::connect(channel, SIGNAL(destroyed()), SLOT(onCallChannelDestroyed())); QObject::connect(channel, SIGNAL(closed()), SLOT(onCallChannelClosed())); QObject::connect(channel, SIGNAL(merged()), SLOT(onCallChannelMerged())); QObject::connect(channel, SIGNAL(splitted()), SLOT(onCallChannelSplitted())); QObject::connect(channel, SIGNAL(multipartyCallHeld()), SLOT(onMultipartyCallHeld())); QObject::connect(channel, SIGNAL(multipartyCallActive()), SLOT(onMultipartyCallActive())); qDebug() << channel; return channel->baseChannel(); } void oFonoConnection::onMultipartyCallHeld() { if (!mConferenceCall) { return; } mConferenceCall->setConferenceActive(false); } void oFonoConnection::onMultipartyCallActive() { if (!mConferenceCall) { return; } mConferenceCall->setConferenceActive(true); } void oFonoConnection::onCallChannelMerged() { if (!mConferenceCall) { return; } oFonoCallChannel *channel = static_cast(sender()); Q_EMIT channelMerged(QDBusObjectPath(channel->baseChannel()->objectPath())); } void oFonoConnection::onCallChannelSplitted() { if (!mConferenceCall) { return; } oFonoCallChannel *channel = static_cast(sender()); Q_EMIT channelSplitted(QDBusObjectPath(channel->baseChannel()->objectPath())); } Tp::BaseChannelPtr oFonoConnection::createChannel(const QString& channelType, uint targetHandleType, uint targetHandle, const QVariantMap &hints, Tp::DBusError *error) { if (mSelfPresence.type != Tp::ConnectionPresenceTypeAvailable) { error->set(TP_QT_ERROR_NETWORK_ERROR, "No network available"); return Tp::BaseChannelPtr(); } if (channelType == TP_QT_IFACE_CHANNEL_TYPE_TEXT) { return createTextChannel(targetHandleType, targetHandle, hints, error); } else if (channelType == TP_QT_IFACE_CHANNEL_TYPE_CALL) { return createCallChannel(targetHandleType, targetHandle, hints, error); } else { error->set(TP_QT_ERROR_NOT_IMPLEMENTED, "Channel type not available"); } return Tp::BaseChannelPtr(); } OfonoMessageManager *oFonoConnection::messageManager() { return mOfonoMessageManager; } OfonoVoiceCallManager *oFonoConnection::voiceCallManager() { return mOfonoVoiceCallManager; } OfonoCallVolume *oFonoConnection::callVolume() { return mOfonoCallVolume; } void oFonoConnection::onDeliveryReportReceived(const QString &messageId, const QVariantMap& info) { const QString pendingMessageNumber = PendingMessagesManager::instance()->recipientIdForMessageId(messageId); if (pendingMessageNumber.isEmpty()) { return; } const QString normalizedNumber = PhoneUtils::normalizePhoneNumber(pendingMessageNumber); PendingMessagesManager::instance()->removePendingMessage(messageId); // check if there is an open channel for this sender and use it oFonoTextChannel *channel = textChannelForMembers(QStringList() << normalizedNumber); if(channel) { channel->deliveryReportReceived(messageId, ensureHandle(normalizedNumber), info["Delivered"].toBool()); return; } Tp::DBusError error; bool yours; uint handle = newHandle(normalizedNumber); ensureChannel(TP_QT_IFACE_CHANNEL_TYPE_TEXT,Tp::HandleTypeContact, handle, yours, handle, false, QVariantMap(), &error); if(error.isValid()) { qWarning() << "Error creating channel for incoming message" << error.name() << error.message(); return; } channel = textChannelForMembers(QStringList() << normalizedNumber); if(channel) { channel->deliveryReportReceived(messageId, ensureHandle(normalizedNumber), info["Delivered"].toBool()); return; } } void oFonoConnection::onOfonoIncomingMessage(const QString &message, const QVariantMap &info) { ensureTextChannel(message, info, false); } void oFonoConnection::onOfonoImmediateMessage(const QString &message, const QVariantMap &info) { ensureTextChannel(message, info, true); } void oFonoConnection::ensureTextChannel(const QString &message, const QVariantMap &info, bool flash) { const QString normalizedNumber = PhoneUtils::normalizePhoneNumber(info["Sender"].toString()); // check if there is an open channel for this sender and use it oFonoTextChannel *channel = textChannelForMembers(QStringList() << normalizedNumber); if(channel) { channel->messageReceived(message, ensureHandle(normalizedNumber), info); return; } Tp::DBusError error; bool yours; QVariantMap hints; hints[TP_QT_IFACE_CHANNEL_INTERFACE_SMS + QLatin1String(".Flash")] = flash; uint handle = newHandle(normalizedNumber); ensureChannel(TP_QT_IFACE_CHANNEL_TYPE_TEXT,Tp::HandleTypeContact, handle, yours, handle, false, hints, &error); if(error.isValid()) { qWarning() << "Error creating channel for incoming message" << error.name() << error.message(); return; } channel = textChannelForMembers(QStringList() << normalizedNumber); if (channel) { channel->messageReceived(message, ensureHandle(normalizedNumber), info); } } void oFonoConnection::onTextChannelClosed() { oFonoTextChannel *channel = static_cast(sender()); if (channel) { qDebug() << "text channel closed"; mTextChannels.removeAll(channel); } } void oFonoConnection::onCallChannelClosed() { qDebug() << "onCallChannelClosed()"; oFonoCallChannel *channel = static_cast(sender()); if (channel) { Q_EMIT channelHangup(QDBusObjectPath(channel->baseChannel()->objectPath())); } } void oFonoConnection::onCallChannelDestroyed() { qDebug() << "onCallChannelDestroyed()"; oFonoCallChannel *channel = static_cast(sender()); if (channel) { QString key = mCallChannels.key(channel); qDebug() << "call channel closed for number " << key; mCallChannels.remove(key); } } uint oFonoConnection::ensureHandle(const QString &phoneNumber) { const QString normalizedNumber = PhoneUtils::normalizePhoneNumber(phoneNumber); Q_FOREACH(const QString &phone, mHandles.values()) { if (PhoneUtils::comparePhoneNumbers(normalizedNumber, phone)) { // this user already exists return mHandles.key(phone); } } return newHandle(normalizedNumber); } Tp::BaseChannelPtr oFonoConnection::ensureChannel(const QString &channelType, uint targetHandleType, uint targetHandle, bool &yours, uint initiatorHandle, bool suppressHandler, const QVariantMap &hints, Tp::DBusError* error) { // we only reuse old text channels if (channelType == TP_QT_IFACE_CHANNEL_TYPE_TEXT) { Q_FOREACH(oFonoTextChannel *channel, mTextChannels) { if (channel->baseChannel()->targetHandleType() == targetHandleType && channel->baseChannel()->targetHandle() == targetHandle) { yours = false; return channel->baseChannel(); } } } yours = true; return Tp::BaseConnection::createChannel(channelType, targetHandleType, targetHandle, initiatorHandle, suppressHandler, hints, error); } void oFonoConnection::onOfonoCallAdded(const QString &call, const QVariantMap &properties) { qDebug() << "new call" << call << properties; bool yours; Tp::DBusError error; QString lineIdentification = properties["LineIdentification"].toString(); // check if there is an open channel for this call, if so, ignore it if (mCallChannels.keys().contains(call)) { qWarning() << "call channel for this object path already exists: " << call; return; } QString normalizedNumber; // TODO check if more than one private/unknown calls are supported at the same time if (lineIdentification.isEmpty()) { // unknown caller Id lineIdentification = QString("x-ofono-unknown"); normalizedNumber = lineIdentification; } else if (lineIdentification == "withheld") { // private caller lineIdentification = QString("x-ofono-private"); normalizedNumber = lineIdentification; } else { normalizedNumber = PhoneUtils::normalizePhoneNumber(lineIdentification); } uint handle = ensureHandle(normalizedNumber); uint initiatorHandle = 0; if (properties["State"] == "incoming" || properties["State"] == "waiting") { initiatorHandle = handle; } else { initiatorHandle = selfHandle(); } qDebug() << "initiatorHandle " <voicemailMessageCount(); } QString oFonoConnection::voicemailNumber(Tp::DBusError *error) { return mOfonoMessageWaiting->voicemailMailboxNumber(); } bool oFonoConnection::voicemailIndicator(Tp::DBusError *error) { return mOfonoMessageWaiting->voicemailWaiting(); } bool oFonoConnection::speakerMode() { return mSpeakerMode; } void oFonoConnection::setSpeakerMode(bool active) { if (mSpeakerMode != active) { mSpeakerMode = active; QMetaObject::invokeMethod(this, "updateAudioRoute", Qt::QueuedConnection); Q_EMIT speakerModeChanged(active); } } void oFonoConnection::USSDInitiate(const QString &command, Tp::DBusError *error) { mOfonoSupplementaryServices->initiate(command); } void oFonoConnection::USSDRespond(const QString &reply, Tp::DBusError *error) { mOfonoSupplementaryServices->respond(reply); } void oFonoConnection::USSDCancel(Tp::DBusError *error) { mOfonoSupplementaryServices->cancel(); } void oFonoConnection::updateAudioRoute() { QByteArray pulseAudioDisabled = qgetenv("PA_DISABLED"); if (!pulseAudioDisabled.isEmpty()) { return; } int currentCalls = mOfonoVoiceCallManager->getCalls().size(); if (currentCalls != 0) { if (currentCalls == 1) { // if we have only one call, check if it's incoming and // enable speaker mode so the ringtone is audible OfonoVoiceCall *call = new OfonoVoiceCall(mOfonoVoiceCallManager->getCalls().first()); if (call) { if (call->state() == "incoming") { enable_ringtone(); call->deleteLater(); return; } if (call->state() == "disconnected") { enable_normal(); call->deleteLater(); return; } if (call->state().isEmpty()) { call->deleteLater(); return; } call->deleteLater(); } } if(mSpeakerMode) { enable_speaker(); } else { enable_earpiece(); } } else { enable_normal(); setSpeakerMode(false); } } telepathy-ofono-0.2+14.04.20140407/mmsdmanager.h0000644000015301777760000000251412320626651021540 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef MMSDMANAGER_H #define MMSDMANAGER_H #include #include #include #include class MMSDManager : public QObject { Q_OBJECT public: MMSDManager(QObject *parent=0); ~MMSDManager(); QStringList services() const; Q_SIGNALS: void serviceAdded(const QString &servicePath); void serviceRemoved(const QString &servicePath); private Q_SLOTS: void onServiceAdded(const QDBusObjectPath &path, const QVariantMap &properties); void onServiceRemoved(const QDBusObjectPath &path); private: QStringList m_services; }; #endif telepathy-ofono-0.2+14.04.20140407/ofono.service.in0000644000015301777760000000020112320626651022172 0ustar pbusernogroup00000000000000[D-BUS Service] Name=org.freedesktop.Telepathy.ConnectionManager.ofono Exec=@CMAKE_INSTALL_PREFIX@/@LIBEXEC_DIR@/telepathy-ofono telepathy-ofono-0.2+14.04.20140407/update_qrc.sh0000755000015301777760000000057312320626651021565 0ustar pbusernogroup00000000000000#!/bin/sh QRC_FILE=$1 FILES=`ls schema/*.sql schema/*.info` # clear the file if [ -e $QRC_FILE ]; then rm -f $QRC_FILE fi # and print the contents echo '' >> $QRC_FILE echo ' ' >> $QRC_FILE for file in $FILES; do echo " $file" >> $QRC_FILE done echo ' ' >> $QRC_FILE echo '' >> $QRC_FILE telepathy-ofono-0.2+14.04.20140407/mmsdmessage.h0000644000015301777760000000265712320626651021562 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef MMSDMESSAGE_H #define MMSDMESSAGE_H #include #include #include #include class MMSDMessage : public QObject { Q_OBJECT public: MMSDMessage(QString objectPath, QVariantMap properties, QObject *parent=0); ~MMSDMessage(); QVariantMap properties() const; QString path() const; void markRead() const; // it should be called delete, but it is a reserved keyword in c++ void remove() const; Q_SIGNALS: void propertyChanged(const QString&, const QVariant&); private Q_SLOTS: void onPropertyChanged(const QString&, const QVariant&); private: QVariantMap m_properties; QString m_messagePath; }; #endif telepathy-ofono-0.2+14.04.20140407/main.cpp0000644000015301777760000000255212320626651020526 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include #include #include "protocol.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Tp::registerTypes(); Tp::enableDebug(true); Tp::enableWarnings(true); Tp::BaseProtocolPtr proto = Tp::BaseProtocol::create( QDBusConnection::sessionBus(), QLatin1String("ofono")); Tp::BaseConnectionManagerPtr cm = Tp::BaseConnectionManager::create( QDBusConnection::sessionBus(), QLatin1String("ofono")); cm->addProtocol(proto); cm->registerObject(); return a.exec(); } telepathy-ofono-0.2+14.04.20140407/mmsdservice.h0000644000015301777760000000330012320626651021560 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef MMSDSERVICE_H #define MMSDSERVICE_H #include #include #include #include #include "dbustypes.h" #include "connection.h" #include "mmsdmessage.h" class MMSDService : public QObject { Q_OBJECT public: MMSDService(QString objectPath, oFonoConnection *connection, QObject *parent=0); ~MMSDService(); QVariantMap properties() const; MessageList messages() const; QString path() const; QDBusObjectPath sendMessage(QStringList recipients, QString smil, AttachmentList attachments); Q_SIGNALS: void messageAdded(const QString &messagePath, const QVariantMap &properties); void messageRemoved(const QString &messagePath); private Q_SLOTS: void onMessageAdded(const QDBusObjectPath &path, const QVariantMap &properties); void onMessageRemoved(const QDBusObjectPath &path); private: QVariantMap m_properties; QString m_servicePath; MessageList m_messages; }; #endif telepathy-ofono-0.2+14.04.20140407/CMakeLists.txt0000644000015301777760000001037512320626661021641 0ustar pbusernogroup00000000000000project(telepathy-ofono) cmake_minimum_required(VERSION 2.8) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) set(TELEPATHY_OFONO telepathy-ofono) # Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) # Standard install paths include(GNUInstallDirs) # Check for include files include(CheckIncludeFileCXX) include(EnableCoverageReport) ##################################################################### # Enable code coverage calculation with gcov/gcovr/lcov # Usage: # * Switch build type to coverage (use ccmake or cmake-gui) # * Invoke make, make test, make coverage # * Find html report in subdir coveragereport # * Find xml report feasible for jenkins in coverage.xml ##################################################################### IF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE]) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs" ) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs" ) SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -coverage" ) SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -coverage" ) ENABLE_COVERAGE_REPORT(TARGETS ${TELEPATHY_OFONO}) ENDIF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE]) find_package(Qt5Core) find_package(Qt5DBus) add_definitions(-DQT_NO_KEYWORDS) check_include_file_cxx("waudio.h" USE_AUDIOFLINGER) if (USE_AUDIOFLINGER) add_definitions(-DUSE_AUDIOFLINGER) set(WAUDIO_LIBRARIES -lwaudio) endif (USE_AUDIOFLINGER) find_package(PkgConfig REQUIRED) pkg_check_modules(TP_QT5 REQUIRED TelepathyQt5) pkg_check_modules(SQLITE3 REQUIRED sqlite3) pkg_check_modules(PULSEAUDIO libpulse) if (PULSEAUDIO_FOUND) add_definitions(-DUSE_PULSEAUDIO) set(USE_PULSEAUDIO ON) include_directories(${PULSEAUDIO_INCLUDE_DIRS}) endif (PULSEAUDIO_FOUND) find_program(DBUS_RUNNER dbus-test-runner) if(NOT DAEMON_DIR) set(DAEMON_DIR lib/telepathy) endif(NOT DAEMON_DIR) set(CMAKE_AUTOMOC ON) include_directories(${TP_QT5_INCLUDE_DIRS}) include_directories(${Qt5Core_INCLUDE_DIRS}) include_directories(${Qt5DBus_INCLUDE_DIRS}) include_directories(${SQLITE3_INCLUDE_DIRS}) include_directories(/usr/include/telepathy-qt5/) include_directories(/usr/include/ofono-qt/) find_library(TELEPATHY_QT5_LIBRARIES telepathy-qt5) find_library(TELEPATHY_QT5_SERVICE_LIBRARIES telepathy-qt5-service) find_library(OFONO_QT_LIBRARIES ofono-qt) qt5_add_resources(telepathyfono_RES sqlitetelepathyofono.qrc) # update the .qrc file automatically when there are new schema files file(GLOB QRC_RESOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/*.sql ${CMAKE_CURRENT_SOURCE_DIR}/schema/*.info) set(QRC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/sqlitetelepathyofono.qrc) add_custom_command( OUTPUT ${QRC_FILE} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/update_qrc.sh ${QRC_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${QRC_RESOURCE_FILES} ) add_custom_target(qrc_update DEPENDS ${QRC_FILE} schema_update) set(TELEPATHY_OFONO_SRC main.cpp protocol.cpp connection.cpp ofonotextchannel.cpp ofonocallchannel.cpp ofonoconferencecallchannel.cpp voicemailiface.cpp speakeriface.cpp mmsdmanager.cpp mmsdservice.cpp mmsdmessage.cpp pendingmessagesmanager.cpp phoneutils.cpp sqlitedatabase.cpp ussdiface.cpp ${telepathyfono_RES}) if(USE_PULSEAUDIO) add_executable(${TELEPATHY_OFONO} qpulseaudioengine.cpp ${TELEPATHY_OFONO_SRC}) else(USE_PULSEAUDIO) add_executable(${TELEPATHY_OFONO} ${TELEPATHY_OFONO_SRC}) endif(USE_PULSEAUDIO) qt5_use_modules(${TELEPATHY_OFONO} Core DBus Sql) add_dependencies(${TELEPATHY_OFONO} schema_update qrc_update) enable_testing() target_link_libraries(${TELEPATHY_OFONO} ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${WAUDIO_LIBRARIES} -ltelepathy-qt5 ${TELEPATHY_QT5_SERVICE_LIBRARIES} ${OFONO_QT_LIBRARIES} ${PULSEAUDIO_LIBRARIES} ${SQLITE3_LIBRARIES}) install(TARGETS ${TELEPATHY_OFONO} DESTINATION ${DAEMON_DIR}) configure_file(ofono.service.in org.freedesktop.Telepathy.ConnectionManager.ofono.service) install (FILES ofono.manager DESTINATION share/telepathy/managers) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.ConnectionManager.ofono.service DESTINATION share/dbus-1/services) add_subdirectory(schema) add_subdirectory(tests) telepathy-ofono-0.2+14.04.20140407/sqlitedatabase.h0000644000015301777760000000262412320626651022235 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Gustavo Pichorim Boiko */ #ifndef SQLITEDATABASE_H #define SQLITEDATABASE_H #include #include class SQLiteDatabase : public QObject { Q_OBJECT public: static SQLiteDatabase *instance(); bool initializeDatabase(); QSqlDatabase database() const; bool beginTransation(); bool finishTransaction(); bool rollbackTransaction(); bool reopen(); protected: bool createOrUpdateDatabase(); QStringList parseSchemaFile(const QString &fileName); void parseVersionInfo(); private: explicit SQLiteDatabase(QObject *parent = 0); QString mDatabasePath; QSqlDatabase mDatabase; int mSchemaVersion; }; #endif // SQLITEDATABASE_H telepathy-ofono-0.2+14.04.20140407/protocol.cpp0000644000015301777760000000307112320626651021440 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include "protocol.h" #include "connection.h" #include #include Protocol::Protocol(const QDBusConnection &dbusConnection, const QString &name) : Tp::BaseProtocol(dbusConnection, name) { setRequestableChannelClasses(Tp::RequestableChannelClassSpecList() << Tp::RequestableChannelClassSpec::textChat() << Tp::RequestableChannelClassSpec::audioCall()); setCreateConnectionCallback(memFun(this, &Protocol::createConnection)); } Tp::BaseConnectionPtr Protocol::createConnection(const QVariantMap ¶meters, Tp::DBusError *error) { Q_UNUSED(error); return Tp::BaseConnection::create(QDBusConnection::sessionBus(), "ofono", name().toLatin1(), parameters); } telepathy-ofono-0.2+14.04.20140407/sqlitedatabase.cpp0000644000015301777760000001551312320626651022571 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Gustavo Pichorim Boiko */ #include "phoneutils_p.h" #include "sqlite3.h" #include "sqlitedatabase.h" #include #include #include #include #include #include #include Q_DECLARE_OPAQUE_POINTER(sqlite3*) Q_DECLARE_METATYPE(sqlite3*) // custom sqlite function "comparePhoneNumbers" used to compare IDs if necessary void comparePhoneNumbers(sqlite3_context *context, int argc, sqlite3_value **argv) { QString arg1((const char*)sqlite3_value_text(argv[0])); QString arg2((const char*)sqlite3_value_text(argv[1])); sqlite3_result_int(context, (int)PhoneUtils::comparePhoneNumbers(arg1, arg2)); } SQLiteDatabase::SQLiteDatabase(QObject *parent) : QObject(parent), mSchemaVersion(0) { initializeDatabase(); } SQLiteDatabase *SQLiteDatabase::instance() { static SQLiteDatabase *self = new SQLiteDatabase(); return self; } bool SQLiteDatabase::initializeDatabase() { mDatabasePath = qgetenv("TP_OFONO_SQLITE_DBPATH"); if (mDatabasePath.isEmpty()) { mDatabasePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); QDir dir(mDatabasePath); if (!dir.exists("telepathy-ofono") && !dir.mkpath("telepathy-ofono")) { qCritical() << "Failed to create dir"; return false; } dir.cd("telepathy-ofono"); mDatabasePath = dir.absoluteFilePath("telepathy-ofono.sqlite"); } mDatabase = QSqlDatabase::addDatabase("QSQLITE"); mDatabase.setDatabaseName(mDatabasePath); // always run the createDatabase function at least during the development if (!createOrUpdateDatabase()) { qCritical() << "Failed to create or update the database"; return false; } return true; } QSqlDatabase SQLiteDatabase::database() const { return mDatabase; } bool SQLiteDatabase::beginTransation() { return mDatabase.transaction(); } bool SQLiteDatabase::finishTransaction() { return mDatabase.commit(); } bool SQLiteDatabase::rollbackTransaction() { return mDatabase.rollback(); } /// this method is to be used mainly by unit tests in order to clean up the database between /// tests. bool SQLiteDatabase::reopen() { mDatabase.close(); mDatabase.open(); // make sure the database is up-to-date after reopening. // this is mainly required for the memory backend used for testing createOrUpdateDatabase(); } bool SQLiteDatabase::createOrUpdateDatabase() { bool create = !QFile(mDatabasePath).exists(); if (!mDatabase.open()) { return false; } // create the comparePhoneNumbers custom sqlite function sqlite3 *handle = database().driver()->handle().value(); sqlite3_create_function(handle, "comparePhoneNumbers", 2, SQLITE_ANY, NULL, &comparePhoneNumbers, NULL, NULL); parseVersionInfo(); QSqlQuery query(mDatabase); QStringList statements; if (create) { statements = parseSchemaFile(":/database/schema/schema.sql"); } else { // if the database already exists, we donĀ“t need to create the tables // only check if an update is needed query.exec("SELECT * FROM schema_version"); if (!query.exec() || !query.next()) { return false; } int upgradeToVersion = query.value(0).toInt() + 1; while (upgradeToVersion <= mSchemaVersion) { statements += parseSchemaFile(QString(":/database/schema/v%1.sql").arg(QString::number(upgradeToVersion))); ++upgradeToVersion; } } // if at this point needsUpdate is still false, it means the database is up-to-date if (statements.isEmpty()) { return true; } beginTransation(); Q_FOREACH(const QString &statement, statements) { if (!query.exec(statement)) { qCritical() << "Failed to create or update database. SQL Statements:" << query.lastQuery() << "Error:" << query.lastError(); rollbackTransaction(); return false; } } // now set the new database schema version if (!query.exec("DELETE FROM schema_version")) { qCritical() << "Failed to remove previous schema versions. SQL Statement:" << query.lastQuery() << "Error:" << query.lastError(); rollbackTransaction(); return false; } if (!query.exec(QString("INSERT INTO schema_version VALUES (%1)").arg(mSchemaVersion))) { qCritical() << "Failed to insert new schema version. SQL Statement:" << query.lastQuery() << "Error:" << query.lastError(); rollbackTransaction(); return false; } finishTransaction(); return true; } QStringList SQLiteDatabase::parseSchemaFile(const QString &fileName) { QFile schema(fileName); if (!schema.open(QFile::ReadOnly)) { qCritical() << "Failed to open " << fileName; return QStringList(); } bool parsingBlock = false; QString statement; QStringList statements; // FIXME: this parser is very basic, it needs to be improved in the future // it does a lot of assumptions based on the structure of the schema.sql file QTextStream stream(&schema); while (!stream.atEnd()) { QString line = stream.readLine(); bool statementEnded = false; statement += line; // check if we are parsing a trigger command if (line.trimmed().startsWith("CREATE TRIGGER", Qt::CaseInsensitive)) { parsingBlock = true; } else if (parsingBlock) { if (line.contains("END;")) { parsingBlock = false; statementEnded = true; } } else if (statement.contains(";")) { statementEnded = true; } statement += "\n"; if (statementEnded) { statements.append(statement); statement.clear(); } } return statements; } void SQLiteDatabase::parseVersionInfo() { QFile schema(":/database/schema/version.info"); if (!schema.open(QFile::ReadOnly)) { qDebug() << schema.error(); qCritical() << "Failed to get database version"; } QString version = schema.readAll(); mSchemaVersion = version.toInt(); } telepathy-ofono-0.2+14.04.20140407/ussdiface.cpp0000644000015301777760000002471312320626661021554 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include #include #include "ussdiface.h" // Conn.I.USSD BaseConnectionUSSDInterface::Adaptee::Adaptee(BaseConnectionUSSDInterface *interface) : QObject(interface), mInterface(interface) { } struct TP_QT_NO_EXPORT BaseConnectionUSSDInterface::Private { Private(BaseConnectionUSSDInterface *parent) : adaptee(new BaseConnectionUSSDInterface::Adaptee(parent)) { } QString state; QString serial; InitiateCallback initiateCB; RespondCallback respondCB; CancelCallback cancelCB; BaseConnectionUSSDInterface::Adaptee *adaptee; }; BaseConnectionUSSDInterface::Adaptee::~Adaptee() { } void BaseConnectionUSSDInterface::Adaptee::initiate(const QString &command, const ConnectionInterfaceUSSDAdaptor::InitiateContextPtr &context) { if (!mInterface->mPriv->initiateCB.isValid()) { context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); return; } Tp::DBusError error; mInterface->mPriv->initiateCB(command, &error); if (error.isValid()) { context->setFinishedWithError(error.name(), error.message()); return; } context->setFinished(); } void BaseConnectionUSSDInterface::Adaptee::respond(const QString &reply, const ConnectionInterfaceUSSDAdaptor::RespondContextPtr &context) { if (!mInterface->mPriv->respondCB.isValid()) { context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); return; } Tp::DBusError error; mInterface->mPriv->respondCB(reply, &error); if (error.isValid()) { context->setFinishedWithError(error.name(), error.message()); return; } context->setFinished(); } void BaseConnectionUSSDInterface::Adaptee::cancel(const ConnectionInterfaceUSSDAdaptor::CancelContextPtr &context) { if (!mInterface->mPriv->cancelCB.isValid()) { context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")); return; } Tp::DBusError error; mInterface->mPriv->cancelCB(&error); if (error.isValid()) { context->setFinishedWithError(error.name(), error.message()); return; } context->setFinished(); } BaseConnectionUSSDInterface::BaseConnectionUSSDInterface() : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_USSD), mPriv(new Private(this)) { } BaseConnectionUSSDInterface::~BaseConnectionUSSDInterface() { delete mPriv; } void BaseConnectionUSSDInterface::setInitiateCallback(const InitiateCallback &cb) { mPriv->initiateCB = cb; } void BaseConnectionUSSDInterface::setRespondCallback(const RespondCallback &cb) { mPriv->respondCB = cb; } void BaseConnectionUSSDInterface::setCancelCallback(const CancelCallback &cb) { mPriv->cancelCB = cb; } QString BaseConnectionUSSDInterface::state() const { return mPriv->state; } void BaseConnectionUSSDInterface::setSerial(const QString &serial) const { mPriv->serial = serial; } QString BaseConnectionUSSDInterface::serial() const { return mPriv->serial; } void BaseConnectionUSSDInterface::StateChanged(const QString &state) { mPriv->state = state; Q_EMIT mPriv->adaptee->stateChanged(state); } void BaseConnectionUSSDInterface::InitiateUSSDComplete(const QString &ussdResp) { Q_EMIT mPriv->adaptee->initiateUSSDComplete(ussdResp); } void BaseConnectionUSSDInterface::RespondComplete(bool success, const QString &ussdResp) { Q_EMIT mPriv->adaptee->respondComplete(success, ussdResp); } void BaseConnectionUSSDInterface::BarringComplete(const QString &ssOp, const QString &cbService, const QVariantMap &cbMap) { Q_EMIT mPriv->adaptee->barringComplete(ssOp, cbService, cbMap); } void BaseConnectionUSSDInterface::ForwardingComplete(const QString &ssOp, const QString &cfService, const QVariantMap &cfMap) { Q_EMIT mPriv->adaptee->forwardingComplete(ssOp, cfService, cfMap); } void BaseConnectionUSSDInterface::WaitingComplete(const QString &ssOp, const QVariantMap &cwMap) { Q_EMIT mPriv->adaptee->waitingComplete(ssOp, cwMap); } void BaseConnectionUSSDInterface::CallingLinePresentationComplete(const QString &ssOp, const QString &status) { Q_EMIT mPriv->adaptee->callingLinePresentationComplete(ssOp, status); } void BaseConnectionUSSDInterface::ConnectedLinePresentationComplete(const QString &ssOp, const QString &status) { Q_EMIT mPriv->adaptee->connectedLinePresentationComplete(ssOp, status); } void BaseConnectionUSSDInterface::CallingLineRestrictionComplete(const QString &ssOp, const QString &status) { Q_EMIT mPriv->adaptee->callingLineRestrictionComplete(ssOp, status); } void BaseConnectionUSSDInterface::ConnectedLineRestrictionComplete(const QString &ssOp, const QString &status) { Q_EMIT mPriv->adaptee->connectedLineRestrictionComplete(ssOp, status); } void BaseConnectionUSSDInterface::InitiateFailed() { Q_EMIT mPriv->adaptee->initiateFailed(); } void BaseConnectionUSSDInterface::NotificationReceived(const QString &message) { Q_EMIT mPriv->adaptee->notificationReceived(message); } void BaseConnectionUSSDInterface::RequestReceived(const QString &message) { Q_EMIT mPriv->adaptee->requestReceived(message); } QVariantMap BaseConnectionUSSDInterface::immutableProperties() const { QVariantMap map; return map; } void BaseConnectionUSSDInterface::createAdaptor() { (void) new ConnectionInterfaceUSSDAdaptor(dbusObject()->dbusConnection(), mPriv->adaptee, dbusObject()); } ConnectionInterfaceUSSDAdaptor::ConnectionInterfaceUSSDAdaptor(const QDBusConnection& bus, QObject* adaptee, QObject* parent) : Tp::AbstractAdaptor(bus, adaptee, parent) { connect(adaptee, SIGNAL(notificationReceived(const QString &)), SIGNAL(NotificationReceived(const QString &))); connect(adaptee, SIGNAL(requestReceived(const QString &)), SIGNAL(RequestReceived(const QString &))); connect(adaptee, SIGNAL(initiateUSSDComplete(const QString &)), SIGNAL(InitiateUSSDComplete(const QString &))); connect(adaptee, SIGNAL(barringComplete(const QString &, const QString &, const QVariantMap &)), SIGNAL(BarringComplete(const QString &, const QString &, const QVariantMap &))); connect(adaptee, SIGNAL(forwardingComplete(const QString &, const QString &, const QVariantMap &)), SIGNAL(ForwardingComplete(const QString &, const QString &, const QVariantMap &))); connect(adaptee, SIGNAL(waitingComplete(const QString &, const QVariantMap &)), SIGNAL(WaitingComplete(const QString &, const QVariantMap &))); connect(adaptee, SIGNAL(callingLinePresentationComplete(const QString &, const QString &)), SIGNAL(CallingLinePresentationComplete(const QString &, const QString &))); connect(adaptee, SIGNAL(connectedLinePresentationComplete(const QString &, const QString &)), SIGNAL(ConnectedLinePresentationComplete(const QString &, const QString &))); connect(adaptee, SIGNAL(callingLineRestrictionComplete(const QString &, const QString &)), SIGNAL(CallingLineRestrictionComplete(const QString &, const QString &))); connect(adaptee, SIGNAL(connectedLineRestrictionComplete(const QString &, const QString &)), SIGNAL(ConnectedLineRestrictionComplete(const QString &, const QString &))); connect(adaptee, SIGNAL(initiateFailed()), SIGNAL(InitiateFailed())); connect(adaptee, SIGNAL(stateChanged(const QString&)), SIGNAL(StateChanged(const QString&))); connect(adaptee, SIGNAL(respondComplete(bool, const QString &)), SIGNAL(RespondComplete(bool, const QString &))); } ConnectionInterfaceUSSDAdaptor::~ConnectionInterfaceUSSDAdaptor() { } void ConnectionInterfaceUSSDAdaptor::Initiate(const QString &command, const QDBusMessage& dbusMessage) { if (!adaptee()->metaObject()->indexOfMethod("initiate(const QString &,ConnectionInterfaceUSSDAdaptor::InitiateContextPtr)") == -1) { dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); return; } InitiateContextPtr ctx = InitiateContextPtr( new Tp::MethodInvocationContext< >(dbusConnection(), dbusMessage)); QMetaObject::invokeMethod(adaptee(), "initiate", Q_ARG(QString, command), Q_ARG(ConnectionInterfaceUSSDAdaptor::InitiateContextPtr, ctx)); return; } void ConnectionInterfaceUSSDAdaptor::Respond(const QString &reply, const QDBusMessage& dbusMessage) { if (!adaptee()->metaObject()->indexOfMethod("respond(QConnectionInterfaceUSSDAdaptor::RespondContextPtr)") == -1) { dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); return; } RespondContextPtr ctx = RespondContextPtr( new Tp::MethodInvocationContext< >(dbusConnection(), dbusMessage)); QMetaObject::invokeMethod(adaptee(), "respond", Q_ARG(QString, reply), Q_ARG(ConnectionInterfaceUSSDAdaptor::RespondContextPtr, ctx)); return; } void ConnectionInterfaceUSSDAdaptor::Cancel(const QDBusMessage& dbusMessage) { if (!adaptee()->metaObject()->indexOfMethod("cancel(ConnectionInterfaceUSSDAdaptor::CancelContextPtr)") == -1) { dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"))); return; } CancelContextPtr ctx = CancelContextPtr( new Tp::MethodInvocationContext< >(dbusConnection(), dbusMessage)); QMetaObject::invokeMethod(adaptee(), "cancel", Q_ARG(ConnectionInterfaceUSSDAdaptor::CancelContextPtr, ctx)); return; } QString ConnectionInterfaceUSSDAdaptor::Serial() const { return qvariant_cast< QString >(adaptee()->property("serial")); } QString ConnectionInterfaceUSSDAdaptor::State() const { return qvariant_cast< QString >(adaptee()->property("state")); } telepathy-ofono-0.2+14.04.20140407/mmsdmessage.cpp0000644000015301777760000000431112320626651022102 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include #include "mmsdmessage.h" MMSDMessage::MMSDMessage(QString objectPath, QVariantMap properties, QObject *parent) : QObject(parent), m_messagePath(objectPath), m_properties(properties) { QDBusConnection::sessionBus().connect("org.ofono.mms", m_messagePath, "org.ofono.mms.Message", "PropertyChanged", this, SLOT(onPropertyChanged(const QString&, const QVariant&))); } MMSDMessage::~MMSDMessage() { } QString MMSDMessage::path() const { return m_messagePath; } QVariantMap MMSDMessage::properties() const { return m_properties; } void MMSDMessage::onPropertyChanged(const QString &property, const QVariant &value) { qDebug() << "property changed" << property << value; m_properties[property] = value; Q_EMIT propertyChanged(property, value); } void MMSDMessage::markRead() const { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono.mms", m_messagePath, "org.ofono.mms.Message", "MarkRead"); QDBusConnection::sessionBus().call(request); } void MMSDMessage::remove() const { QDBusMessage request; request = QDBusMessage::createMethodCall("org.ofono.mms", m_messagePath, "org.ofono.mms.Message", "Delete"); QDBusConnection::sessionBus().call(request); } telepathy-ofono-0.2+14.04.20140407/phoneutils.cpp0000644000015301777760000000417212320626651021774 0ustar pbusernogroup00000000000000/* * Copyright (C) 2012-2013 Canonical, Ltd. * * Authors: * Gustavo Pichorim Boiko * Tiago Salem Herrmann * * This file is part of telepathy-ofono. * * telepathy-ofono is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * telepathy-ofono is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include "phoneutils_p.h" #include "phonenumberutils_p.h" PhoneUtils::PhoneUtils(QObject *parent) : QObject(parent) { } bool PhoneUtils::comparePhoneNumbers(const QString &number1, const QString &number2) { if (isPhoneNumber(number1) && isPhoneNumber(number2)) { return PhoneNumberUtils::compareLoosely(number1, number2); } return number1 == number2; } bool PhoneUtils::isPhoneNumber(const QString &identifier) { // remove all non diable digits QString finalNumber = QString(identifier).replace(QRegExp("[p+*#(),;-]"),""); finalNumber = finalNumber.replace(QRegExp("(\\s+)"), ""); // if empty, the number is invalid if (finalNumber.isEmpty()) return false; finalNumber = finalNumber.replace(QRegExp("(\\d+)"), ""); return finalNumber.isEmpty(); } // TODO improve this normalization algorithm. More complex numbers // like "+1 234 234-1234 w 12345678#" should be normalizd to "+12342341234" QString PhoneUtils::normalizePhoneNumber(const QString &identifier) { if (!isPhoneNumber(identifier)) { // do not normalize non phone numbers return identifier; } QRegExp regexp = QRegExp("(\\s+)"); QString finalNumber = QString(identifier).replace(regexp,""); finalNumber = finalNumber.replace(QRegExp("[()-]"),""); return finalNumber; } telepathy-ofono-0.2+14.04.20140407/phoneutils_p.h0000644000015301777760000000234112320626651021754 0ustar pbusernogroup00000000000000/* * Copyright (C) 2012 Canonical, Ltd. * * Authors: * Gustavo Pichorim Boiko * Tiago Salem Herrmann * * This file is part of telepathy-ofono. * * telepathy-ofono is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * telepathy-ofono is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef PHONEUTILS_H #define PHONEUTILS_H #include class PhoneUtils : public QObject { Q_OBJECT public: explicit PhoneUtils(QObject *parent = 0); Q_INVOKABLE static bool comparePhoneNumbers(const QString &number1, const QString &number2); Q_INVOKABLE static bool isPhoneNumber(const QString &identifier); Q_INVOKABLE static QString normalizePhoneNumber(const QString &identifier); }; #endif // PHONEUTILS_H telepathy-ofono-0.2+14.04.20140407/pendingmessagesmanager.cpp0000644000015301777760000000554412320626651024315 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include #include #include "pendingmessagesmanager.h" #include "sqlitedatabase.h" PendingMessagesManager::PendingMessagesManager(QObject *parent) : QObject(parent), mDatabase(SQLiteDatabase::instance()->database()) { } PendingMessagesManager *PendingMessagesManager::instance() { static PendingMessagesManager *self = new PendingMessagesManager(); return self; } QString PendingMessagesManager::recipientIdForMessageId(const QString &messageId) { QSqlQuery query(SQLiteDatabase::instance()->database()); QString queryString("SELECT recipientId FROM pending_messages WHERE messageId=:messageId"); query.prepare(queryString); query.bindValue(":messageId", messageId); if (!query.exec()) { qCritical() << "Error:" << query.lastError() << query.lastQuery(); return QString(); } if(!query.next()) { return QString(); } return query.value(0).toString(); } void PendingMessagesManager::addPendingMessage(const QString &messageId, const QString &recipientId) { QSqlQuery query(SQLiteDatabase::instance()->database()); PendingMessage message; message.recipientId = recipientId; message.timestamp = QDateTime::currentDateTimeUtc(); QString queryString("INSERT into pending_messages (messageId, recipientId, timestamp) VALUES (:messageId, :recipientId, :timestamp)"); query.prepare(queryString); query.bindValue(":messageId", messageId); query.bindValue(":recipientId", message.recipientId); query.bindValue(":timestamp", message.timestamp.toString(Qt::ISODate)); if (!query.exec()) { qCritical() << "Error:" << query.lastError() << query.lastQuery(); return; } } void PendingMessagesManager::removePendingMessage(const QString &messageId) { QSqlQuery query(SQLiteDatabase::instance()->database()); QString queryString("DELETE FROM pending_messages WHERE messageId=:messageId"); query.prepare(queryString); query.bindValue(":messageId", messageId); if (!query.exec()) { qCritical() << "Error:" << query.lastError() << query.lastQuery(); return; } } telepathy-ofono-0.2+14.04.20140407/mmsdmanager.cpp0000644000015301777760000000606512320626651022100 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #include #include #include "mmsdmanager.h" struct ServiceStruct { QDBusObjectPath path; QVariantMap properties; }; typedef QList ServiceList; Q_DECLARE_METATYPE(ServiceStruct) Q_DECLARE_METATYPE(ServiceList) QDBusArgument &operator<<(QDBusArgument &argument, const ServiceStruct &service) { argument.beginStructure(); argument << service.path << service.properties; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, ServiceStruct &service) { argument.beginStructure(); argument >> service.path >> service.properties; argument.endStructure(); return argument; } MMSDManager::MMSDManager(QObject *parent) : QObject(parent) { QDBusReply reply; ServiceList services; QDBusMessage request; qDBusRegisterMetaType(); qDBusRegisterMetaType(); request = QDBusMessage::createMethodCall("org.ofono.mms", "/org/ofono/mms", "org.ofono.mms.Manager", "GetServices"); reply = QDBusConnection::sessionBus().call(request); services = reply; Q_FOREACH(ServiceStruct service, services) { m_services << service.path.path(); } QDBusConnection::sessionBus().connect("org.ofono.mms","/org/ofono/mms","org.ofono.mms.Manager", "ServiceAdded", this, SLOT(onServiceAdded(const QDBusObjectPath&, const QVariantMap&))); QDBusConnection::sessionBus().connect("org.ofono.mms","/org/ofono/mms","org.ofono.mms.Manager", "ServiceRemoved", this, SLOT(onServiceRemoved(const QDBusObjectPath&))); } MMSDManager::~MMSDManager() { } QStringList MMSDManager::services() const { return m_services; } void MMSDManager::onServiceAdded(const QDBusObjectPath& path, const QVariantMap& map) { qDebug() << "service added" << path.path() << map; m_services << path.path(); Q_EMIT serviceAdded(path.path()); } void MMSDManager::onServiceRemoved(const QDBusObjectPath& path) { qDebug() << "service removed" << path.path(); m_services.removeAll(path.path()); Q_EMIT serviceRemoved(path.path()); } telepathy-ofono-0.2+14.04.20140407/COPYING.LGPL0000644000015301777760000001674312320626651020675 0ustar pbusernogroup00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. telepathy-ofono-0.2+14.04.20140407/ofonoconferencecallchannel.h0000644000015301777760000000543712320626651024611 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef OFONOCONFERENCECALLCHANNEL_H #define OFONOCONFERENCECALLCHANNEL_H #include #include #include #include #include #include #include "connection.h" #include "speakeriface.h" class oFonoConnection; class oFonoConferenceCallChannel : public QObject { Q_OBJECT public: oFonoConferenceCallChannel(oFonoConnection *conn, QObject *parent = 0); ~oFonoConferenceCallChannel(); void onHangup(uint reason, const QString &detailedReason, const QString &message, Tp::DBusError* error); void onMuteStateChanged(const Tp::LocalMuteState &state, Tp::DBusError *error); void onHoldStateChanged(const Tp::LocalHoldState &state, const Tp::LocalHoldStateReason &reason, Tp::DBusError *error); void onDTMFStartTone(uchar event, Tp::DBusError *error); void onDTMFStopTone(Tp::DBusError *error); void onTurnOnSpeaker(bool active, Tp::DBusError *error); void onMerge(const QDBusObjectPath &channel, Tp::DBusError *error); Tp::BaseChannelPtr baseChannel(); void setConferenceActive(bool active); private Q_SLOTS: void onDtmfComplete(bool success); void sendNextDtmf(); void init(); void onOfonoMuteChanged(bool mute); void onChannelMerged(const QDBusObjectPath &path); void onChannelSplitted(const QDBusObjectPath &path); private: QString mObjPath; QString mPreviousState; bool mIncoming; bool mRequestedHangup; oFonoConnection *mConnection; QList mCallChannels; Tp::BaseChannelPtr mBaseChannel; Tp::BaseChannelHoldInterfacePtr mHoldIface; Tp::BaseChannelConferenceInterfacePtr mConferenceIface; Tp::BaseChannelMergeableConferenceInterfacePtr mMergeableIface; Tp::BaseCallMuteInterfacePtr mMuteIface; BaseChannelSpeakerInterfacePtr mSpeakerIface; Tp::BaseChannelCallTypePtr mCallChannel; Tp::BaseCallContentDTMFInterfacePtr mDTMFIface; bool mDtmfLock; QStringList mDtmfPendingStrings; }; #endif // OFONOCONFERENCECALLCHANNEL_H telepathy-ofono-0.2+14.04.20140407/connection.h0000644000015301777760000001520212320626661021403 0ustar pbusernogroup00000000000000/** * Copyright (C) 2013 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: Tiago Salem Herrmann */ #ifndef OFONOCONNECTION_H #define OFONOCONNECTION_H // qt #include // telepathy-qt #include #include #include #include #include // ofono-qt #include #include #include #include #include #include #include #include // telepathy-ofono #include "ofonotextchannel.h" #include "ofonocallchannel.h" #include "voicemailiface.h" #include "mmsdmanager.h" #include "mmsdmessage.h" #include "dbustypes.h" #include "speakeriface.h" #include "ussdiface.h" class oFonoConnection; class oFonoTextChannel; class oFonoCallChannel; class oFonoConferenceCallChannel; class MMSDService; class oFonoConnection : public Tp::BaseConnection { Q_OBJECT Q_DISABLE_COPY(oFonoConnection) public: oFonoConnection(const QDBusConnection &dbusConnection, const QString &cmName, const QString &protocolName, const QVariantMap ¶meters); QStringList inspectHandles(uint handleType, const Tp::UIntList& handles, Tp::DBusError *error); Tp::UIntList requestHandles(uint handleType, const QStringList& identifiers, Tp::DBusError* error); Tp::BaseChannelPtr createChannel(const QString& channelType, uint targetHandleType, uint targetHandle, const QVariantMap &hints, Tp::DBusError *error); Tp::ContactAttributesMap getContactAttributes(const Tp::UIntList &handles, const QStringList &ifaces, Tp::DBusError *error); uint setPresence(const QString& status, const QString& statusMessage, Tp::DBusError *error); void connect(Tp::DBusError *error); void setOnline(bool online); void setSpeakerMode(bool active); bool speakerMode(); bool voicemailIndicator(Tp::DBusError *error); QString voicemailNumber(Tp::DBusError *error); uint voicemailCount(Tp::DBusError *error); void USSDInitiate(const QString &command, Tp::DBusError *error); void USSDRespond(const QString &reply, Tp::DBusError *error); void USSDCancel(Tp::DBusError *error); Tp::BaseConnectionRequestsInterfacePtr requestsIface; Tp::BaseConnectionSimplePresenceInterfacePtr simplePresenceIface; Tp::BaseConnectionContactsInterfacePtr contactsIface; BaseConnectionVoicemailInterfacePtr voicemailIface; BaseConnectionUSSDInterfacePtr supplementaryServicesIface; uint newHandle(const QString &identifier); OfonoMessageManager *messageManager(); OfonoVoiceCallManager *voiceCallManager(); OfonoCallVolume *callVolume(); QMap callChannels(); uint ensureHandle(const QString &phoneNumber); oFonoTextChannel* textChannelForMembers(const QStringList &members); Tp::BaseChannelPtr createTextChannel(uint targetHandleType, uint targetHandle, const QVariantMap &hints, Tp::DBusError *error); Tp::BaseChannelPtr createCallChannel(uint targetHandleType, uint targetHandle, const QVariantMap &hints, Tp::DBusError *error); Tp::BaseChannelPtr ensureChannel(const QString &channelType, uint targetHandleType, uint targetHandle, bool &yours, uint initiatorHandle, bool suppressHandler, const QVariantMap &hints, Tp::DBusError* error); ~oFonoConnection(); Q_SIGNALS: void speakerModeChanged(bool active); void channelMerged(const QDBusObjectPath &objPath); void channelSplitted(const QDBusObjectPath &objPath); void channelHangup(const QDBusObjectPath &objPath); public Q_SLOTS: void Q_DBUS_EXPORT onTryRegister(); void updateAudioRoute(); private Q_SLOTS: void onOfonoIncomingMessage(const QString &message, const QVariantMap &info); void onOfonoImmediateMessage(const QString &message, const QVariantMap &info); void onOfonoCallAdded(const QString &call, const QVariantMap &properties); void onOfonoNetworkRegistrationChanged(const QString &status); void onTextChannelClosed(); void onCallChannelClosed(); void onCallChannelDestroyed(); void onValidityChanged(bool valid); void onMMSDServiceAdded(const QString&); void onMMSDServiceRemoved(const QString&); void onMMSAdded(const QString &, const QVariantMap&); void onMMSRemoved(const QString &); void onMMSPropertyChanged(QString property, QVariant value); void onCheckMMSServices(); void onMessageRead(const QString &id); void onDeliveryReportReceived(const QString &messageId, const QVariantMap &info); void onConferenceCallChannelClosed(); void onCallChannelMerged(); void onCallChannelSplitted(); void onMultipartyCallHeld(); void onMultipartyCallActive(); private: bool isNetworkRegistered(); void addMMSToService(const QString &path, const QVariantMap &properties, const QString &servicePath); void ensureTextChannel(const QString &message, const QVariantMap &info, bool flash); QMap mHandles; QList mTextChannels; QMap mCallChannels; QStringList mModems; OfonoModemManager *mOfonoModemManager; OfonoMessageManager *mOfonoMessageManager; OfonoVoiceCallManager *mOfonoVoiceCallManager; OfonoCallVolume *mOfonoCallVolume; OfonoNetworkRegistration *mOfonoNetworkRegistration; OfonoMessageWaiting *mOfonoMessageWaiting; OfonoSupplementaryServices *mOfonoSupplementaryServices; uint mHandleCount; Tp::SimplePresence mSelfPresence; Tp::SimplePresence mRequestedSelfPresence; QTimer *mRegisterTimer; MMSDManager *mMmsdManager; QMap mMmsdServices; QMap > mServiceMMSList; oFonoConferenceCallChannel *mConferenceCall; bool mSpeakerMode; }; #endif