/* * Copyright (C) 2021 ~ 2022 Deepin Technology Co., Ltd. * * Author: weizhixiang * * Maintainer: weizhixiang * * 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 3 of the License, or * 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, see . */ #include "synconfig.h" #include #include #include #include #include const QString syncDBusService = "org.deepin.dde.Sync1.Config"; const QString syncDBusObject = "/org/deepin/dde/Sync1/Config"; const QString syncDBusDaemonService = "com.deepin.sync.Daemon"; const QString syncDBusDaemonObject = "/com/deepin/sync/Daemon"; const QString syncDBusDaemonInterface = syncDBusDaemonService; QMap SynConfig::synModulesMap; SynConfig *SynConfig::instance(QObject *parent) { static SynConfig synConfig(parent); return &synConfig; } bool SynConfig::registe(QString moduleName, SynModuleBase *module) { bool registed = false; if (moduleName.size() > 0 && module) { synModulesMap[moduleName] = module; registed = true; } return registed; } QByteArray SynConfig::GetSyncConfig(QString moduleName) { if (synModulesMap.find(moduleName) == synModulesMap.end()) return {}; SynModuleBase *module = synModulesMap[moduleName]; if (module) return module->getSyncConfig(); else return {}; } void SynConfig::SetSynConfig(QString moduleName, QByteArray ba) { if (synModulesMap.find(moduleName) == synModulesMap.end()) return; SynModuleBase *module = synModulesMap[moduleName]; if (module) { module->setSynConfig(ba); } } SynConfig::SynConfig(QObject *parent) : QObject(parent) { QDBusConnection con = QDBusConnection::sessionBus(); if (!con.registerService(syncDBusService)) { qCritical() << "register service org.deepin.dde.Sync1.Config error:" << con.lastError().message(); return; } if (!con.registerObject(syncDBusObject, this, QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals)) { qCritical() << "register object /org/deepin/dde/Sync1/Config error:" << con.lastError().message(); return; } // 只注册一次 registerOnSyncDaemon(); // 关联com.deepin.sync.Daemon所有者变化 QDBusConnectionInterface *ifc = QDBusConnection::sessionBus().interface(); connect(ifc, &QDBusConnectionInterface::serviceOwnerChanged, this, [ & ](const QString & name, const QString & oldOwner, const QString & newOwner) { Q_UNUSED(oldOwner) if (name == syncDBusDaemonService && !newOwner.isEmpty()) { this->registerOnSyncDaemon(); } }); } SynConfig::~SynConfig() { } void SynConfig::registerOnSyncDaemon() { QDBusInterface interface = QDBusInterface(syncDBusDaemonService, syncDBusDaemonObject, syncDBusDaemonInterface); // 修改V20注册方式,需同步到deepin-deepinid-daemon interface.call("Register", syncDBusService, syncDBusObject); }