diff --git a/containments/taskpanel/taskpanel.cpp b/containments/taskpanel/taskpanel.cpp index dbf7cc3..818a931 100644 --- a/containments/taskpanel/taskpanel.cpp +++ b/containments/taskpanel/taskpanel.cpp @@ -1,201 +1,201 @@ /*************************************************************************** * Copyright (C) 2015 Marco Martin * * * * 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 of the License, 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 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 "taskpanel.h" #include #include #include #include #include #include #include #include #include #include #include static const QString s_kwinService = QStringLiteral("org.kde.KWin"); TaskPanel::TaskPanel(QObject *parent, const QVariantList &args) : Plasma::Containment(parent, args) , m_showingDesktop(false) , m_windowManagement(nullptr) { setHasConfigurationInterface(true); m_activeTimer = new QTimer(this); m_activeTimer->setSingleShot(true); m_activeTimer->setInterval(250); connect(m_activeTimer, &QTimer::timeout, this, &TaskPanel::updateActiveWindow); initWayland(); } TaskPanel::~TaskPanel() { } void TaskPanel::requestShowingDesktop(bool showingDesktop) { if (!m_windowManagement) { return; } m_windowManagement->setShowingDesktop(showingDesktop); } void TaskPanel::initWayland() { if (!QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) { return; } using namespace KWayland::Client; ConnectionThread *connection = ConnectionThread::fromApplication(this); if (!connection) { return; } - Registry *registry = new Registry(this); + auto *registry = new Registry(this); registry->create(connection); connect(registry, &Registry::plasmaWindowManagementAnnounced, this, [this, registry] (quint32 name, quint32 version) { m_windowManagement = registry->createPlasmaWindowManagement(name, version, this); qRegisterMetaType >("QVector"); connect(m_windowManagement, &PlasmaWindowManagement::showingDesktopChanged, this, [this] (bool showing) { if (showing == m_showingDesktop) { return; } m_showingDesktop = showing; emit showingDesktopChanged(m_showingDesktop); } ); //FIXME //connect(m_windowManagement, &PlasmaWindowManagement::activeWindowChanged, this, &TaskPanel::updateActiveWindow, Qt::QueuedConnection); connect(m_windowManagement, SIGNAL(activeWindowChanged()), m_activeTimer, SLOT(start())); updateActiveWindow(); } ); connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry] (quint32 name, quint32 version) { m_shellInterface = registry->createPlasmaShell(name, version, this); if (!m_panel) { return; } Surface *s = Surface::fromWindow(m_panel); if (!s) { return; } m_shellSurface = m_shellInterface->createSurface(s, this); m_shellSurface->setSkipTaskbar(true); } ); registry->setup(); connection->roundtrip(); } QWindow *TaskPanel::panel() { return m_panel; } void TaskPanel::setPanel(QWindow *panel) { if (panel == m_panel) { return; } if (m_panel) { disconnect(m_panel, &QWindow::visibilityChanged, this, &TaskPanel::updatePanelVisibility); } m_panel = panel; connect(m_panel, &QWindow::visibilityChanged, this, &TaskPanel::updatePanelVisibility, Qt::QueuedConnection); emit panelChanged(); updatePanelVisibility(); } void TaskPanel::updatePanelVisibility() { using namespace KWayland::Client; if (!m_panel->isVisible()) { return; } Surface *s = Surface::fromWindow(m_panel); if (!s) { return; } m_shellSurface = m_shellInterface->createSurface(s, this); if (m_shellSurface) { m_shellSurface->setSkipTaskbar(true); } } void TaskPanel::updateActiveWindow() { if (!m_windowManagement || m_activeWindow == m_windowManagement->activeWindow()) { return; } if (m_activeWindow) { disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged); disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, this, &TaskPanel::forgetActiveWindow); } m_activeWindow = m_windowManagement->activeWindow(); if (m_activeWindow) { connect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged); connect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, this, &TaskPanel::forgetActiveWindow); } // TODO: connect to closeableChanged, not needed right now as KWin doesn't provide this changeable emit hasCloseableActiveWindowChanged(); } bool TaskPanel::hasCloseableActiveWindow() const { return m_activeWindow && m_activeWindow->isCloseable() /*&& !m_activeWindow->isMinimized()*/; } void TaskPanel::forgetActiveWindow() { if (m_activeWindow) { disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged); disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, this, &TaskPanel::forgetActiveWindow); } m_activeWindow.clear(); emit hasCloseableActiveWindowChanged(); } void TaskPanel::closeActiveWindow() { if (m_activeWindow) { m_activeWindow->requestClose(); } } K_EXPORT_PLASMA_APPLET_WITH_JSON(taskpanel, TaskPanel, "metadata.json") #include "taskpanel.moc" diff --git a/dialer/src/main.cpp b/dialer/src/main.cpp index 5db51c0..742f06a 100644 --- a/dialer/src/main.cpp +++ b/dialer/src/main.cpp @@ -1,216 +1,214 @@ /* * 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 #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"), 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->loadPackage(packagePath); obj->engine()->rootContext()->setContextProperty("commandlineArguments", parser.positionalArguments()); auto *dialerUtils = new DialerUtils(simAccount); obj->engine()->rootContext()->setContextProperty("dialerUtils", QVariant::fromValue(dialerUtils)); obj->completeInitialization(); if (!obj->package().metadata().isValid()) { return -1; } Tp::SharedPtr callHandler(new CallHandler(dialerUtils)); registrar->registerClient(Tp::AbstractClientPtr::dynamicCast(callHandler), "Plasma.Dialer"); KPluginMetaData data = obj->package().metadata(); // About data KAboutData aboutData(data.pluginId(), data.name(), data.version(), data.description(), KAboutLicense::byKeyword(data.license()).key()); for (auto author : data.authors()) { aboutData.addAuthor(author.name(), author.task(), author.emailAddress(), author.webAddress(), author.ocsUsername()); } //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(); }