diff --git a/CMakeLists.txt b/CMakeLists.txt index 475b24b..359889f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,66 +1,68 @@ project(plasma-phone-components) # minimal requirements cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR) set (QT_MIN_VERSION "5.2.0") set(KF5_MIN_VERSION "5.0.0") set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) find_package(ECM 5.41.0 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_SOURCE_DIR}/cmake) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings) include(ECMOptionalAddSubdirectory) include(ECMInstallIcons) include(ECMSetupVersion) include(ECMMarkNonGuiExecutable) include(ECMGenerateHeaders) include(GenerateExportHeader) include(FeatureSummary) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core Gui Widgets Qml Quick Test) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Plasma Service Declarative I18n KIO People) find_package(KF5 REQUIRED COMPONENTS PlasmaQuick DBusAddons Notifications) find_package(TelepathyQt5 REQUIRED) find_package(KF5Wayland CONFIG) set_package_properties(KF5Wayland PROPERTIES TYPE REQUIRED PURPOSE "Required for interacting with the compositor") # torch find_package(GStreamer 1.1.90 REQUIRED) find_package(GLIB2 REQUIRED) find_package(GObject REQUIRED) +find_package(Qofono REQUIRED) + include(CheckIncludeFiles) plasma_install_package(look-and-feel org.kde.plasma.phone look-and-feel) plasma_install_package(shell org.kde.plasma.phone shells) install(DIRECTORY wallpaper/ DESTINATION "${WALLPAPER_INSTALL_DIR}/org.kde.plasma.phone.lockers") install( DIRECTORY kwinmultitasking/ DESTINATION ${DATA_INSTALL_DIR}/kwin/scripts/org.kde.phone.multitasking ) install( FILES kwinmultitasking/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR} RENAME kwin-script-org.kde.phone.multitasking.desktop ) install( DIRECTORY qtvirtualkeyboardplugin/ DESTINATION ${KDE_INSTALL_QMLDIR}/QtQuick/VirtualKeyboard/Styles/Plasma ) configure_file(plasma-mobile.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/plasma-mobile.desktop) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/plasma-mobile.desktop DESTINATION ${KDE_INSTALL_DATADIR}/wayland-sessions ) add_subdirectory(bin) #add_subdirectory(services) add_subdirectory(applets) add_subdirectory(containments) add_subdirectory(dialer) add_subdirectory(sounds) #add_subdirectory(touchscreentest) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/cmake/FindQofono.cmake b/cmake/FindQofono.cmake new file mode 100644 index 0000000..5c9d520 --- /dev/null +++ b/cmake/FindQofono.cmake @@ -0,0 +1,62 @@ +#============================================================================= +# Copyright (c) 2019 Bhushan Shah +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#============================================================================= + +find_package(PkgConfig) +pkg_check_modules(PC_Qofono QUIET qofono-qt5) + +find_path(Qofono_INCLUDE_DIR + NAMES qofono.h + PATHS ${PC_Qofono_INCLUDE_DIRS} + PATH_SUFFIXES qofono-qt5 +) + +find_library(Qofono_LIBRARY + NAMES qofono-qt5 + PATHS ${PC_Qofono_LIBRARY_DIRS} +) + +set(Qofono_VERSION ${PC_Qofono_VERSION}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Qofono + FOUND_VAR Qofono_FOUND + REQUIRED_VARS + Qofono_LIBRARY + Qofono_INCLUDE_DIR + VERSION_VAR Qofono_VERSION +) + +if(Qofono_FOUND) + set(Qofono_LIBRARIES ${Qofono_LIBRARY}) + set(Qofono_INCLUDE_DIRS ${Qofono_INCLUDE_DIR}) + set(Qofono_DEFINITIONS ${PC_Qofono_CFLAGS_OTHER}) +endif() + +mark_as_advanced( + Qofono_INCLUDE_DIR + Qofono_LIBRARY +) diff --git a/dialer/CMakeLists.txt b/dialer/CMakeLists.txt index 06a952d..ce2944c 100644 --- a/dialer/CMakeLists.txt +++ b/dialer/CMakeLists.txt @@ -1,6 +1,6 @@ install(FILES metadata.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} RENAME org.kde.phone.dialer.desktop) include_directories(${TELEPATHY_QT5_INCLUDE_DIR}) -# +include_directories(${Qofono_INCLUDE_DIRS}) add_subdirectory(src) diff --git a/dialer/src/CMakeLists.txt b/dialer/src/CMakeLists.txt index 99a72bd..a985b50 100644 --- a/dialer/src/CMakeLists.txt +++ b/dialer/src/CMakeLists.txt @@ -1,34 +1,35 @@ set(plasmaphonedialer_SRCS main.cpp dialerutils.cpp call-handler.cpp call-manager.cpp ) qt5_add_resources(RESOURCES resources.qrc) add_executable(plasmaphonedialer ${plasmaphonedialer_SRCS} ${RESOURCES}) target_compile_definitions(plasmaphonedialer PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}") find_package(PhoneNumber COMPONENTS PhoneNumber REQUIRED) target_link_libraries(plasmaphonedialer PhoneNumber::PhoneNumber Qt5::Gui Qt5::Quick Qt5::Widgets KF5::Declarative KF5::I18n KF5::QuickAddons KF5::DBusAddons KF5::Notifications ${TELEPATHY_QT5_LIBRARIES} + ${Qofono_LIBRARIES} ) install(TARGETS plasmaphonedialer ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES plasma_dialer.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFY5RCDIR}) configure_file(org.freedesktop.Telepathy.Client.Plasma.Dialer.service.in org.freedesktop.Telepathy.Client.Plasma.Dialer.service) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.Plasma.Dialer.service DESTINATION ${DBUS_SERVICES_INSTALL_DIR}) install(FILES Plasma.Dialer.client DESTINATION ${SHARE_INSTALL_PREFIX}/telepathy/clients/) diff --git a/dialer/src/main.cpp b/dialer/src/main.cpp index 4448635..260e162 100644 --- a/dialer/src/main.cpp +++ b/dialer/src/main.cpp @@ -1,202 +1,212 @@ /* * Copyright 2015 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library 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 * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include "dialerutils.h" #include "call-handler.h" #include #include #include #include #include #include #include #include #include #include #include +#include #include #include #include #include #include #include +#include void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) { QFile file(QDir::homePath() + "/dialer.log"); bool opened = file.open(QIODevice::WriteOnly | QIODevice::Append); Q_ASSERT(opened); QString strout; QTextStream out(&strout); out << QTime::currentTime().toString("hh:mm:ss.zzz "); out << context.function << ":" << context.line << " "; switch (type) { case QtDebugMsg: out << "DBG"; break; case QtInfoMsg: out << "NFO"; break; case QtWarningMsg: out << "WRN"; break; case QtCriticalMsg: out << "CRT"; break; case QtFatalMsg: out << "FTL"; break; } out << " " << msg << '\n'; // Write to log file QTextStream fileout(&file); fileout << strout; out.flush(); // Write to stdout QTextStream console(stdout); console << strout; console.flush(); } int main(int argc, char **argv) { qInstallMessageHandler(myMessageOutput); QCommandLineParser parser; QApplication app(argc, argv); const QString description = i18n("Plasma Phone Dialer"); const char version[] = PROJECT_VERSION; // app.setQuitOnLastWindowClosed(false); app.setApplicationVersion(version); app.setOrganizationDomain("kde.org"); KDBusService service(KDBusService::Unique); parser.addVersionOption(); parser.addHelpOption(); parser.setApplicationDescription(description); QCommandLineOption daemonOption(QStringList() << QStringLiteral("d") << QStringLiteral("daemon"), i18n("Daemon mode. run without displaying anything.")); parser.addPositionalArgument("number", i18n("Call the given number")); parser.addOption(daemonOption); parser.process(app); Tp::registerTypes(); Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(QDBusConnection::sessionBus(), Tp::Features() << Tp::Account::FeatureCore ); Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(QDBusConnection::sessionBus(), Tp::Features() << Tp::Connection::FeatureCore << Tp::Connection::FeatureSelfContact << Tp::Connection::FeatureConnected ); Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus()); channelFactory->addCommonFeatures(Tp::Channel::FeatureCore); channelFactory->addFeaturesForCalls(Tp::Features() << Tp::CallChannel::FeatureContents << Tp::CallChannel::FeatureCallState << Tp::CallChannel::FeatureCallMembers << Tp::CallChannel::FeatureLocalHoldState ); // channelFactory->addFeaturesForTextChats(Tp::Features() << Tp::TextChannel::FeatureMessageQueue // << Tp::TextChannel::FeatureMessageSentSignal // << Tp::TextChannel::FeatureChatState // << Tp::TextChannel::FeatureMessageCapabilities); Tp::ContactFactoryPtr contactFactory = Tp::ContactFactory::create(Tp::Features() << Tp::Contact::FeatureAlias << Tp::Contact::FeatureAvatarData ); Tp::ClientRegistrarPtr registrar = Tp::ClientRegistrar::create(accountFactory, connectionFactory, channelFactory, contactFactory); - Tp::AccountPtr simAccount = Tp::Account::create(TP_QT_ACCOUNT_MANAGER_BUS_NAME, QStringLiteral("/org/freedesktop/Telepathy/Account/ofono/ofono/account0"), + // we ask the ofono for the default modem, which is generally first modem + QOfonoManager *ofonoManager = new QOfonoManager; + + QEventLoop loop; + QObject::connect(ofonoManager, &QOfonoManager::availableChanged, &loop, &QEventLoop::quit); + loop.exec(QEventLoop::ExcludeUserInputEvents); + + const QString accountName = ofonoManager->modems().isEmpty() ? "" : ofonoManager->modems().first(); + + Tp::AccountPtr simAccount = Tp::Account::create(TP_QT_ACCOUNT_MANAGER_BUS_NAME, QStringLiteral("/org/freedesktop/Telepathy/Account/ofono/ofono/") + accountName, connectionFactory, channelFactory); - const QString packagePath("org.kde.phone.dialer"); //usually we have an ApplicationWindow here, so we do not need to create a window by ourselves auto *obj = new KDeclarative::QmlObject(); obj->setTranslationDomain(packagePath); obj->setInitializationDelayed(true); obj->setSource(QUrl("qrc:///main.qml")); obj->engine()->rootContext()->setContextProperty("commandlineArguments", parser.positionalArguments()); auto *dialerUtils = new DialerUtils(simAccount); obj->engine()->rootContext()->setContextProperty("dialerUtils", QVariant::fromValue(dialerUtils)); obj->completeInitialization(); Tp::SharedPtr callHandler(new CallHandler(dialerUtils)); registrar->registerClient(Tp::AbstractClientPtr::dynamicCast(callHandler), "Plasma.Dialer"); KAboutData aboutData("dialer", i18n("Dialer"), "0.9", i18n("Plasma phone dialer"), KAboutLicense::GPL); aboutData.setDesktopFileName("org.kde.phone.dialer"); KAboutData::setApplicationData(aboutData); //The root is not a window? //have to use a normal QQuickWindow since the root item is already created QWindow *window = qobject_cast(obj->rootObject()); if (window) { QObject::connect(&service, &KDBusService::activateRequested, [=](const QStringList &arguments, const QString &workingDirectory) { Q_UNUSED(workingDirectory); window->show(); window->requestActivate(); if (arguments.length() > 0) { QString numberArg = arguments[1]; if (numberArg.startsWith("call://")) { numberArg = numberArg.mid(7); } obj->rootObject()->metaObject()->invokeMethod(obj->rootObject(), "call", Q_ARG(QVariant, numberArg)); } }); if (!parser.isSet(daemonOption)) { window->show(); window->requestActivate(); } window->setTitle(obj->package().metadata().name()); window->setIcon(QIcon::fromTheme(obj->package().metadata().iconName())); if (!parser.positionalArguments().isEmpty()) { QString numberArg = parser.positionalArguments().first(); if (numberArg.startsWith("call://")) { numberArg = numberArg.mid(7); } qWarning() << "Calling" << numberArg; obj->rootObject()->metaObject()->invokeMethod(obj->rootObject(), "call", Q_ARG(QVariant, numberArg)); } } else { qWarning() << "Error loading the ApplicationWindow"; } return app.exec(); }