Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get general settings from Control Center #162

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions calendar-client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ 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: 7 additions & 0 deletions calendar-client/src/dbus/org.deepin.dde.ControlCenter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<node>
<interface name="org.deepin.dde.ControlCenter1">
<method name="ShowPage">
<arg name="url" type="s" direction="in"/>
</method>
</interface>
</node>
104 changes: 58 additions & 46 deletions calendar-client/src/dialog/settingdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

#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 @@ -142,26 +146,19 @@ static CalendarSettingSetting setting_general = {
"general",
QObject::tr("General"),
{
{
"firstday", //key
QObject::tr("First day of week"), //name
"FirstDayofWeek", //type
"", //default
"Sunday" //text
},

{
"time", //key
QObject::tr("Time"), //name
"Time", //type
"" //default
}
}
}
{ "firstday", QObject::tr("First day of week"), "FirstDayofWeek", "", "Sunday" },
{ "time", QObject::tr("Time"), "Time", "" },
{ "control-center-button", "", "ControlCenterLink", "" },
},
},
}
};
CSettingDialog::CSettingDialog(QWidget *parent) : DSettingsDialog(parent)
{
m_controlCenterProxy = new ControlCenterProxy(ControlCenterDBusName,
ControlCenterDBusPath,
QDBusConnection::sessionBus(),
this);
initWidget();
initConnect();
initData();
Expand All @@ -176,6 +173,7 @@ 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 @@ -285,8 +283,6 @@ 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 @@ -337,36 +333,29 @@ void CSettingDialog::initWidgetDisplayStatus()

void CSettingDialog::initFirstDayofWeekWidget()
{
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_firstDayofWeekWidget = new QWidget(this);

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_firstDayofWeekCombobox, 1);
layout->addWidget(m_firstDayofWeekLabel, 1);

m_firstDayofWeekWidget->setLayout(layout);
}

void CSettingDialog::initTimeTypeWidget()
{
m_timeTypeWidget = new QWidget();
m_timeTypeWidget = new QWidget(this);

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"));
m_timeTypeLabel = new QLabel(m_timeTypeWidget);

QHBoxLayout *layout = new QHBoxLayout(m_timeTypeWidget);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addStretch(10);
layout->addWidget(m_timeTypeCombobox, 1);
layout->addWidget(m_timeTypeLabel, 1);

m_timeTypeWidget->setLayout(layout);
}
Expand Down Expand Up @@ -593,31 +582,34 @@ void CSettingDialog::slotAccountStateChange()

void CSettingDialog::setFirstDayofWeek(int value)
{
if (!m_firstDayofWeekCombobox) {
if (!m_firstDayofWeekLabel) {
return;
}
//设置一周首日并刷新界面
if (value == 1) {
m_firstDayofWeekCombobox->setCurrentIndex(1);
gCalendarManager->setFirstDayOfWeek(1, true);
} else {
m_firstDayofWeekCombobox->setCurrentIndex(0);
gCalendarManager->setFirstDayOfWeek(7, true);
if (value < 1 || value > 7) {
value = 1;
}
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_timeTypeCombobox) {
if (!m_timeTypeLabel) {
return;
}
if (value > 1 || value < 0) {
value = 0;
if (value == DCalendarGeneralSettings::Twelve) {
m_timeTypeLabel->setText(tr("12-hour clock"));
} else {
m_timeTypeLabel->setText(tr("24-hour clock"));
}
//设置时间显示格式并刷新界面
m_timeTypeCombobox->setCurrentIndex(value);
gCalendarManager->setTimeShowType(value, true);
}

void CSettingDialog::accountUpdate()
Expand Down Expand Up @@ -742,3 +734,23 @@ 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: 6 additions & 2 deletions calendar-client/src/dialog/settingdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

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

DWIDGET_USE_NAMESPACE

Expand All @@ -27,6 +29,7 @@ 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 @@ -74,11 +77,11 @@ public slots:
private:
//一周首日
QWidget *m_firstDayofWeekWidget = nullptr;
QComboBox *m_firstDayofWeekCombobox = nullptr;
QLabel *m_firstDayofWeekLabel= nullptr;

//时间格式
QWidget *m_timeTypeWidget = nullptr;
QComboBox *m_timeTypeCombobox = nullptr;
QLabel *m_timeTypeLabel = nullptr;

//帐户选择
QComboBox *m_accountComboBox = nullptr;
Expand All @@ -97,6 +100,7 @@ public slots:
DOANetWorkDBus *m_ptrNetworkState;
SettingWidget::SyncTagRadioButton *m_radiobuttonAccountCalendar = nullptr;
SettingWidget::SyncTagRadioButton *m_radiobuttonAccountSetting = nullptr;
ControlCenterProxy *m_controlCenterProxy;
};

#endif // SETTINGDIALOG_H
53 changes: 47 additions & 6 deletions calendar-service/src/calendarDataManager/daccountmanagemodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@
#include "units.h"
#include "calendarprogramexitcontrol.h"

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();
//新文件路径
QString newDbPath = getDBPath();
Expand Down Expand Up @@ -45,7 +55,7 @@
}
}
}
m_generalSetting = m_accountManagerDB->getCalendarGeneralSettings();
m_generalSetting = getGeneralSettings();

connect(&m_timer, &QTimer::timeout, this, &DAccountManageModule::slotClientIsOpen);
m_timer.start(2000);
Expand All @@ -69,7 +79,7 @@
QString DAccountManageModule::getCalendarGeneralSettings()
{
QString cgSetStr;
m_generalSetting = m_accountManagerDB->getCalendarGeneralSettings();
m_generalSetting = getGeneralSettings();
DCalendarGeneralSettings::toJsonString(m_generalSetting, cgSetStr);
return cgSetStr;
}
Expand All @@ -79,7 +89,7 @@
DCalendarGeneralSettings::Ptr cgSetPtr = DCalendarGeneralSettings::Ptr(new DCalendarGeneralSettings);
DCalendarGeneralSettings::fromJsonString(cgSetPtr, cgSet);
if (m_generalSetting != cgSetPtr) {
m_accountManagerDB->setCalendarGeneralSettings(cgSetPtr);
setGeneralSettings(cgSetPtr);
DCalendarGeneralSettings::Ptr tmpSetting = DCalendarGeneralSettings::Ptr(m_generalSetting->clone());
m_generalSetting = cgSetPtr;
if (tmpSetting->firstDayOfWeek() != m_generalSetting->firstDayOfWeek()) {
Expand All @@ -100,7 +110,7 @@
{
if (m_generalSetting->firstDayOfWeek() != firstday) {
m_generalSetting->setFirstDayOfWeek(static_cast<Qt::DayOfWeek>(firstday));
m_accountManagerDB->setCalendarGeneralSettings(m_generalSetting);
setGeneralSettings(m_generalSetting);
foreach (auto account, m_accountList) {
if (account->accountType() == DAccount::Account_UnionID) {
m_accountModuleMap[account->accountID()]->accountDownload();
Expand All @@ -118,7 +128,7 @@
{
if (m_generalSetting->timeShowType() != timeType) {
m_generalSetting->setTimeShowType(static_cast<DCalendarGeneralSettings::TimeShowType>(timeType));
m_accountManagerDB->setCalendarGeneralSettings(m_generalSetting);
setGeneralSettings(m_generalSetting);
foreach (auto account, m_accountList) {
if (account->accountType() == DAccount::Account_UnionID) {
m_accountModuleMap[account->accountID()]->accountDownload();
Expand Down Expand Up @@ -312,7 +322,38 @@
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)

Check warning on line 356 in calendar-service/src/calendarDataManager/daccountmanagemodule.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'slotFirstDayOfWeek' is never used.
{
if (getfirstDayOfWeek() != firstDay) {
setFirstDayOfWeek(firstDay);
Expand Down Expand Up @@ -423,7 +464,7 @@

void DAccountManageModule::slotSettingChange()
{
DCalendarGeneralSettings::Ptr newSetting = m_accountManagerDB->getCalendarGeneralSettings();
DCalendarGeneralSettings::Ptr newSetting = getGeneralSettings();
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,6 +14,7 @@
#include <QObject>
#include <QSharedPointer>
#include <QTimer>
#include <DConfig>

//帐户类型总数,若支持的类型增加则需要修改
const int accountTypeCount = 3;
Expand Down Expand Up @@ -80,6 +81,10 @@ 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 @@ -105,6 +110,7 @@ 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("_", QString::SkipEmptyParts);
QStringList parseLocalNameList = locale.name().split("_", Qt::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
Loading