From 1358a6e3166298a095ae8c7552ae55d8e67ac77f Mon Sep 17 00:00:00 2001 From: myml Date: Tue, 12 Dec 2023 13:25:30 +0800 Subject: [PATCH] Revert "feat: get general settings from Control Center" This reverts commit c536ec2b6735be7fb79252ba3c05c14d9bc722c1. --- calendar-client/CMakeLists.txt | 3 - .../src/dbus/org.deepin.dde.ControlCenter.xml | 7 -- calendar-client/src/dialog/settingdialog.cpp | 104 ++++++++---------- calendar-client/src/dialog/settingdialog.h | 8 +- .../daccountmanagemodule.cpp | 53 +-------- .../daccountmanagemodule.h | 6 - calendar-service/src/main.cpp | 2 +- 7 files changed, 55 insertions(+), 128 deletions(-) delete mode 100644 calendar-client/src/dbus/org.deepin.dde.ControlCenter.xml diff --git a/calendar-client/CMakeLists.txt b/calendar-client/CMakeLists.txt index 34c154230..7cfc613b8 100644 --- a/calendar-client/CMakeLists.txt +++ b/calendar-client/CMakeLists.txt @@ -70,9 +70,6 @@ find_package(DtkWidget REQUIRED) find_package(DtkGui REQUIRED) find_package(Qt5Network REQUIRED) -set_source_files_properties(src/dbus/org.deepin.dde.ControlCenter.xml PROPERTIES CLASSNAME ControlCenterProxy) -qt5_add_dbus_interface(Calendar_SRC src/dbus/org.deepin.dde.ControlCenter.xml controlCenterProxy) - include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) # Tell CMake to create the executable add_executable(${PROJECT_NAME} ${Calendar_SRC} ${APP_QRC}) diff --git a/calendar-client/src/dbus/org.deepin.dde.ControlCenter.xml b/calendar-client/src/dbus/org.deepin.dde.ControlCenter.xml deleted file mode 100644 index 100b26104..000000000 --- a/calendar-client/src/dbus/org.deepin.dde.ControlCenter.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/calendar-client/src/dialog/settingdialog.cpp b/calendar-client/src/dialog/settingdialog.cpp index 92baa8dc3..fef20b39a 100644 --- a/calendar-client/src/dialog/settingdialog.cpp +++ b/calendar-client/src/dialog/settingdialog.cpp @@ -22,10 +22,6 @@ #include -const QString ControlCenterDBusName = "org.deepin.dde.ControlCenter1"; -const QString ControlCenterDBusPath = "/org/deepin/dde/ControlCenter1"; -const QString ControlCenterPage = "datetime/region"; - using namespace SettingWidget; //静态的翻译不会真的翻译,但是会更新ts文件 //像static QString a = QObject::tr("hello"), a实际等于hello,但是ts会有hello这个词条 @@ -146,19 +142,26 @@ static CalendarSettingSetting setting_general = { "general", QObject::tr("General"), { - { "firstday", QObject::tr("First day of week"), "FirstDayofWeek", "", "Sunday" }, - { "time", QObject::tr("Time"), "Time", "" }, - { "control-center-button", "", "ControlCenterLink", "" }, - }, - }, + { + "firstday", //key + QObject::tr("First day of week"), //name + "FirstDayofWeek", //type + "", //default + "Sunday" //text + }, + + { + "time", //key + QObject::tr("Time"), //name + "Time", //type + "" //default + } + } + } } }; CSettingDialog::CSettingDialog(QWidget *parent) : DSettingsDialog(parent) { - m_controlCenterProxy = new ControlCenterProxy(ControlCenterDBusName, - ControlCenterDBusPath, - QDBusConnection::sessionBus(), - this); initWidget(); initConnect(); initData(); @@ -173,7 +176,6 @@ void CSettingDialog::initView() widgetFactory()->registerWidget("login", UserloginWidget::createloginButton); widgetFactory()->registerWidget("FirstDayofWeek", std::bind(&CSettingDialog::createFirstDayofWeekWidget, this, std::placeholders::_1)); widgetFactory()->registerWidget("Time", std::bind(&CSettingDialog::createTimeTypeWidget, this, std::placeholders::_1)); - widgetFactory()->registerWidget("ControlCenterLink", std::bind(&CSettingDialog::createControlCenterLink, this, std::placeholders::_1)); widgetFactory()->registerWidget("AccountCombobox", std::bind(&CSettingDialog::createAccountCombobox, this, std::placeholders::_1)); widgetFactory()->registerWidget("JobTypeListView", std::bind(&CSettingDialog::createJobTypeListView, this, std::placeholders::_1)); widgetFactory()->registerWidget("SyncTagRadioButton", std::bind(&CSettingDialog::createSyncTagRadioButton, this, std::placeholders::_1)); @@ -283,6 +285,8 @@ void CSettingDialog::initConnect() connect(gAccountManager, &AccountManager::signalAccountUpdate, this, &CSettingDialog::slotAccountUpdate); connect(gAccountManager, &AccountManager::signalLogout, this, &CSettingDialog::slotLogout); connect(gAccountManager, &AccountManager::signalAccountStateChange, this, &CSettingDialog::slotAccountStateChange); + connect(m_firstDayofWeekCombobox, QOverload::of(&QComboBox::currentIndexChanged), this, &CSettingDialog::slotFirstDayofWeekCurrentChanged); + connect(m_timeTypeCombobox, QOverload::of(&QComboBox::currentIndexChanged), this, &CSettingDialog::slotTimeTypeCurrentChanged); connect(m_accountComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &CSettingDialog::slotAccountCurrentChanged); connect(m_typeAddBtn, &DIconButton::clicked, this, &CSettingDialog::slotTypeAddBtnClickded); connect(m_typeImportBtn, &DIconButton::clicked, this, &CSettingDialog::slotTypeImportBtnClickded); @@ -333,29 +337,36 @@ void CSettingDialog::initWidgetDisplayStatus() void CSettingDialog::initFirstDayofWeekWidget() { - m_firstDayofWeekWidget = new QWidget(this); + m_firstDayofWeekWidget = new QWidget(); + + m_firstDayofWeekCombobox = new QComboBox(m_firstDayofWeekWidget); + m_firstDayofWeekCombobox->setFixedSize(150, 36); + m_firstDayofWeekCombobox->addItem(tr("Sunday")); + m_firstDayofWeekCombobox->addItem(tr("Monday")); - m_firstDayofWeekLabel = new QLabel(m_firstDayofWeekWidget); QHBoxLayout *layout = new QHBoxLayout(m_firstDayofWeekWidget); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); layout->addStretch(10); - layout->addWidget(m_firstDayofWeekLabel, 1); + layout->addWidget(m_firstDayofWeekCombobox, 1); m_firstDayofWeekWidget->setLayout(layout); } void CSettingDialog::initTimeTypeWidget() { - m_timeTypeWidget = new QWidget(this); + m_timeTypeWidget = new QWidget(); - m_timeTypeLabel = new QLabel(m_timeTypeWidget); + m_timeTypeCombobox = new QComboBox(m_timeTypeWidget); + m_timeTypeCombobox->setFixedSize(150, 36); + m_timeTypeCombobox->addItem(tr("24-hour clock")); + m_timeTypeCombobox->addItem(tr("12-hour clock")); QHBoxLayout *layout = new QHBoxLayout(m_timeTypeWidget); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); layout->addStretch(10); - layout->addWidget(m_timeTypeLabel, 1); + layout->addWidget(m_timeTypeCombobox, 1); m_timeTypeWidget->setLayout(layout); } @@ -582,34 +593,31 @@ void CSettingDialog::slotAccountStateChange() void CSettingDialog::setFirstDayofWeek(int value) { - if (!m_firstDayofWeekLabel) { + if (!m_firstDayofWeekCombobox) { return; } - if (value < 1 || value > 7) { - value = 1; + //设置一周首日并刷新界面 + if (value == 1) { + m_firstDayofWeekCombobox->setCurrentIndex(1); + gCalendarManager->setFirstDayOfWeek(1, true); + } else { + m_firstDayofWeekCombobox->setCurrentIndex(0); + gCalendarManager->setFirstDayOfWeek(7, true); } - QHash m = { - { Qt::DayOfWeek::Monday, tr("Monday") }, - { Qt::DayOfWeek::Tuesday, tr("Tuesday") }, - { Qt::DayOfWeek::Wednesday, tr("Wednesday") }, - { Qt::DayOfWeek::Thursday, tr("Thursday") }, - { Qt::DayOfWeek::Friday, tr("Friday") }, - { Qt::DayOfWeek::Saturday, tr("Saturday") }, - { Qt::DayOfWeek::Sunday, tr("Sunday") }, - }; - m_firstDayofWeekLabel->setText(m.value(Qt::DayOfWeek(value))); } + void CSettingDialog::setTimeType(int value) { - if (!m_timeTypeLabel) { + if (!m_timeTypeCombobox) { return; } - if (value == DCalendarGeneralSettings::Twelve) { - m_timeTypeLabel->setText(tr("12-hour clock")); - } else { - m_timeTypeLabel->setText(tr("24-hour clock")); + if (value > 1 || value < 0) { + value = 0; } + //设置时间显示格式并刷新界面 + m_timeTypeCombobox->setCurrentIndex(value); + gCalendarManager->setTimeShowType(value, true); } void CSettingDialog::accountUpdate() @@ -734,23 +742,3 @@ DIconButton *CSettingDialog::createTypeAddButton() { return m_typeAddBtn; } - -QWidget *CSettingDialog::createControlCenterLink(QObject *obj) -{ - DLabel *myLabel = new DLabel(tr("Please go to the Control Center to change settings"), this); - myLabel->setTextFormat(Qt::RichText); - myLabel->setFixedHeight(36); - connect(myLabel, &DLabel::linkActivated, this, [this]{ - qDebug() << "open control center"; - this->m_controlCenterProxy->ShowPage(ControlCenterPage); - }); - auto w = new QWidget(this); - QHBoxLayout *layout = new QHBoxLayout(w); - layout->setContentsMargins(0, 0, 10, 0); - layout->setSpacing(0); - layout->addStretch(10); - layout->addWidget(myLabel, 1); - - w->setLayout(layout); - return w; -} \ No newline at end of file diff --git a/calendar-client/src/dialog/settingdialog.h b/calendar-client/src/dialog/settingdialog.h index c65caafae..1c55b9017 100644 --- a/calendar-client/src/dialog/settingdialog.h +++ b/calendar-client/src/dialog/settingdialog.h @@ -7,10 +7,8 @@ #include "settingWidget/settingwidgets.h" #include "doanetworkdbus.h" -#include "controlCenterProxy.h" #include #include -#include DWIDGET_USE_NAMESPACE @@ -29,7 +27,6 @@ class CSettingDialog : public DSettingsDialog QWidget *createManualSyncButton(QObject *obj); QWidget *createJobTypeListView(QObject *obj); DIconButton *createTypeAddButton(); - QWidget *createControlCenterLink(QObject *obj); public slots: void slotGeneralSettingsUpdate(); @@ -77,11 +74,11 @@ public slots: private: //一周首日 QWidget *m_firstDayofWeekWidget = nullptr; - QLabel *m_firstDayofWeekLabel= nullptr; + QComboBox *m_firstDayofWeekCombobox = nullptr; //时间格式 QWidget *m_timeTypeWidget = nullptr; - QLabel *m_timeTypeLabel = nullptr; + QComboBox *m_timeTypeCombobox = nullptr; //帐户选择 QComboBox *m_accountComboBox = nullptr; @@ -100,7 +97,6 @@ public slots: DOANetWorkDBus *m_ptrNetworkState; SettingWidget::SyncTagRadioButton *m_radiobuttonAccountCalendar = nullptr; SettingWidget::SyncTagRadioButton *m_radiobuttonAccountSetting = nullptr; - ControlCenterProxy *m_controlCenterProxy; }; #endif // SETTINGDIALOG_H diff --git a/calendar-service/src/calendarDataManager/daccountmanagemodule.cpp b/calendar-service/src/calendarDataManager/daccountmanagemodule.cpp index 85386f2b2..20d3ae4e8 100644 --- a/calendar-service/src/calendarDataManager/daccountmanagemodule.cpp +++ b/calendar-service/src/calendarDataManager/daccountmanagemodule.cpp @@ -8,21 +8,11 @@ #include "calendarprogramexitcontrol.h" #include -const QString firstDayOfWeek_key = "firstDayOfWeek"; -const QString shortTimeFormat_key = "shortTimeFormat"; - DAccountManageModule::DAccountManageModule(QObject *parent) : QObject(parent) , m_syncFileManage(new SyncFileManage()) , m_accountManagerDB(new DAccountManagerDataBase) - , m_reginFormatConfig(DTK_CORE_NAMESPACE::DConfig::createGeneric("org.deepin.region-format", QString(), this)) { - if (m_reginFormatConfig->isValid()) { - connect(m_reginFormatConfig, - &DTK_CORE_NAMESPACE::DConfig::valueChanged, - this, - &DAccountManageModule::slotSettingChange); - } m_isSupportUid = m_syncFileManage->getSyncoperation()->hasAvailable(); if(Dtk::Core::DSysInfo::isCommunityEdition()){ m_isSupportUid = false; @@ -59,7 +49,7 @@ DAccountManageModule::DAccountManageModule(QObject *parent) } } } - m_generalSetting = getGeneralSettings(); + m_generalSetting = m_accountManagerDB->getCalendarGeneralSettings(); connect(&m_timer, &QTimer::timeout, this, &DAccountManageModule::slotClientIsOpen); m_timer.start(2000); @@ -83,7 +73,7 @@ QString DAccountManageModule::getAccountList() QString DAccountManageModule::getCalendarGeneralSettings() { QString cgSetStr; - m_generalSetting = getGeneralSettings(); + m_generalSetting = m_accountManagerDB->getCalendarGeneralSettings(); DCalendarGeneralSettings::toJsonString(m_generalSetting, cgSetStr); return cgSetStr; } @@ -93,7 +83,7 @@ void DAccountManageModule::setCalendarGeneralSettings(const QString &cgSet) DCalendarGeneralSettings::Ptr cgSetPtr = DCalendarGeneralSettings::Ptr(new DCalendarGeneralSettings); DCalendarGeneralSettings::fromJsonString(cgSetPtr, cgSet); if (m_generalSetting != cgSetPtr) { - setGeneralSettings(cgSetPtr); + m_accountManagerDB->setCalendarGeneralSettings(cgSetPtr); DCalendarGeneralSettings::Ptr tmpSetting = DCalendarGeneralSettings::Ptr(m_generalSetting->clone()); m_generalSetting = cgSetPtr; if (tmpSetting->firstDayOfWeek() != m_generalSetting->firstDayOfWeek()) { @@ -114,7 +104,7 @@ void DAccountManageModule::setFirstDayOfWeek(const int firstday) { if (m_generalSetting->firstDayOfWeek() != firstday) { m_generalSetting->setFirstDayOfWeek(static_cast(firstday)); - setGeneralSettings(m_generalSetting); + m_accountManagerDB->setCalendarGeneralSettings(m_generalSetting); foreach (auto account, m_accountList) { if (account->accountType() == DAccount::Account_UnionID) { m_accountModuleMap[account->accountID()]->accountDownload(); @@ -132,7 +122,7 @@ void DAccountManageModule::setTimeFormatType(const int timeType) { if (m_generalSetting->timeShowType() != timeType) { m_generalSetting->setTimeShowType(static_cast(timeType)); - setGeneralSettings(m_generalSetting); + m_accountManagerDB->setCalendarGeneralSettings(m_generalSetting); foreach (auto account, m_accountList) { if (account->accountType() == DAccount::Account_UnionID) { m_accountModuleMap[account->accountID()]->accountDownload(); @@ -326,37 +316,6 @@ void DAccountManageModule::setUidSwitchStatus(const DAccount::Ptr &account) account->setAccountState(accountState); } -// 获取通用配置 -DCalendarGeneralSettings::Ptr DAccountManageModule::getGeneralSettings() -{ - auto cg = m_accountManagerDB->getCalendarGeneralSettings(); - // 如果读取控制中心的配置失败,则使用数据库的配置 - if (!m_reginFormatConfig->isValid()) { - qWarning() << "regin format config invalid"; - return cg; - } - bool ok; - auto dayofWeek = Qt::DayOfWeek(m_reginFormatConfig->value(firstDayOfWeek_key).toInt(&ok)); - if (ok) { - cg->setFirstDayOfWeek(dayofWeek); - } else { - qWarning() << "Unable to get first day of week from control center"; - } - auto shortTimeFormat = m_reginFormatConfig->value(shortTimeFormat_key).toString(); - if (shortTimeFormat.contains("ap")) { - cg->setTimeShowType(DCalendarGeneralSettings::Twelve); - } else { - cg->setTimeShowType(DCalendarGeneralSettings::TwentyFour); - } - return cg; -} - -// 更改通用配置 -void DAccountManageModule::setGeneralSettings(const DCalendarGeneralSettings::Ptr &cgSet) -{ - m_accountManagerDB->setCalendarGeneralSettings(cgSet); -}; - void DAccountManageModule::slotFirstDayOfWeek(const int firstDay) { if (getfirstDayOfWeek() != firstDay) { @@ -468,7 +427,7 @@ void DAccountManageModule::slotSwitcherChange(const bool state) void DAccountManageModule::slotSettingChange() { - DCalendarGeneralSettings::Ptr newSetting = getGeneralSettings(); + DCalendarGeneralSettings::Ptr newSetting = m_accountManagerDB->getCalendarGeneralSettings(); if (newSetting->firstDayOfWeek() != m_generalSetting->firstDayOfWeek()) { m_generalSetting->setFirstDayOfWeek(newSetting->firstDayOfWeek()); emit firstDayOfWeekChange(); diff --git a/calendar-service/src/calendarDataManager/daccountmanagemodule.h b/calendar-service/src/calendarDataManager/daccountmanagemodule.h index 86f03f0cd..d0ef3da16 100644 --- a/calendar-service/src/calendarDataManager/daccountmanagemodule.h +++ b/calendar-service/src/calendarDataManager/daccountmanagemodule.h @@ -14,7 +14,6 @@ #include #include #include -#include //帐户类型总数,若支持的类型增加则需要修改 const int accountTypeCount = 3; @@ -81,10 +80,6 @@ class DAccountManageModule : public QObject //获取设置开关状态 void setUidSwitchStatus(const DAccount::Ptr &account); - DCalendarGeneralSettings::Ptr getGeneralSettings(); - - void setGeneralSettings(const DCalendarGeneralSettings::Ptr &cgSet); - signals: void firstDayOfWeekChange(); void timeFormatTypeChange(); @@ -110,7 +105,6 @@ public slots: QMap m_accountModuleMap; QMap m_AccountServiceMap[accountTypeCount]; DCalendarGeneralSettings::Ptr m_generalSetting; - DTK_CORE_NAMESPACE::DConfig *m_reginFormatConfig; QTimer m_timer; bool m_isSupportUid = false; }; diff --git a/calendar-service/src/main.cpp b/calendar-service/src/main.cpp index cf6922467..d40e91fbb 100644 --- a/calendar-service/src/main.cpp +++ b/calendar-service/src/main.cpp @@ -28,7 +28,7 @@ bool loadTranslator(QCoreApplication *app, QList localeFallback = QList app->installTranslator(translator); bsuccess = true; } - QStringList parseLocalNameList = locale.name().split("_", Qt::SkipEmptyParts); + QStringList parseLocalNameList = locale.name().split("_", QString::SkipEmptyParts); if (parseLocalNameList.length() > 0 && !bsuccess) { translateFilename = QString("%1_%2").arg(app->applicationName()).arg(parseLocalNameList.at(0)); QString parseTranslatePath = QString("%1/%2.qm").arg(CalendarServiceTranslationsDir).arg(translateFilename);