Skip to content

Commit

Permalink
Revert "feat: get general settings from Control Center"
Browse files Browse the repository at this point in the history
This reverts commit c536ec2.
  • Loading branch information
myml committed Dec 12, 2023
1 parent 569907a commit 1358a6e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 128 deletions.
3 changes: 0 additions & 3 deletions calendar-client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
7 changes: 0 additions & 7 deletions calendar-client/src/dbus/org.deepin.dde.ControlCenter.xml

This file was deleted.

104 changes: 46 additions & 58 deletions calendar-client/src/dialog/settingdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@

#include <qglobal.h>

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这个词条
Expand Down Expand Up @@ -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();
Expand All @@ -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));
Expand Down Expand Up @@ -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<int>::of(&QComboBox::currentIndexChanged), this, &CSettingDialog::slotFirstDayofWeekCurrentChanged);
connect(m_timeTypeCombobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &CSettingDialog::slotTimeTypeCurrentChanged);
connect(m_accountComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &CSettingDialog::slotAccountCurrentChanged);
connect(m_typeAddBtn, &DIconButton::clicked, this, &CSettingDialog::slotTypeAddBtnClickded);
connect(m_typeImportBtn, &DIconButton::clicked, this, &CSettingDialog::slotTypeImportBtnClickded);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<Qt::DayOfWeek, QString> 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()
Expand Down Expand Up @@ -734,23 +742,3 @@ DIconButton *CSettingDialog::createTypeAddButton()
{
return m_typeAddBtn;
}

QWidget *CSettingDialog::createControlCenterLink(QObject *obj)
{
DLabel *myLabel = new DLabel(tr("Please go to the <a href='/'>Control Center</a> 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;
}
8 changes: 2 additions & 6 deletions calendar-client/src/dialog/settingdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

#include "settingWidget/settingwidgets.h"
#include "doanetworkdbus.h"
#include "controlCenterProxy.h"
#include <DSettingsDialog>
#include <DIconButton>
#include <DCommandLinkButton>

DWIDGET_USE_NAMESPACE

Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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
53 changes: 6 additions & 47 deletions calendar-service/src/calendarDataManager/daccountmanagemodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,11 @@
#include "calendarprogramexitcontrol.h"
#include <DSysInfo>

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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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()) {
Expand All @@ -114,7 +104,7 @@ void DAccountManageModule::setFirstDayOfWeek(const int firstday)
{
if (m_generalSetting->firstDayOfWeek() != firstday) {
m_generalSetting->setFirstDayOfWeek(static_cast<Qt::DayOfWeek>(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();
Expand All @@ -132,7 +122,7 @@ void DAccountManageModule::setTimeFormatType(const int timeType)
{
if (m_generalSetting->timeShowType() != timeType) {
m_generalSetting->setTimeShowType(static_cast<DCalendarGeneralSettings::TimeShowType>(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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <QObject>
#include <QSharedPointer>
#include <QTimer>
#include <DConfig>

//帐户类型总数,若支持的类型增加则需要修改
const int accountTypeCount = 3;
Expand Down Expand Up @@ -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();
Expand All @@ -110,7 +105,6 @@ public slots:
QMap<QString, DAccountModule::Ptr> m_accountModuleMap;
QMap<QString, DAccountService::Ptr> m_AccountServiceMap[accountTypeCount];
DCalendarGeneralSettings::Ptr m_generalSetting;
DTK_CORE_NAMESPACE::DConfig *m_reginFormatConfig;
QTimer m_timer;
bool m_isSupportUid = false;
};
Expand Down
2 changes: 1 addition & 1 deletion calendar-service/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool loadTranslator(QCoreApplication *app, QList<QLocale> 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);
Expand Down

0 comments on commit 1358a6e

Please sign in to comment.