@@ -17,6 +17,12 @@ using namespace DDESESSIONCC;
17
17
const int TOP_TIP_MAX_LENGTH = 60 ;
18
18
const int TOP_TIP_SPACING = 10 ;
19
19
20
+ #ifdef ENABLE_DSS_SNIPE
21
+ static const QString localeNameKey = " localeName" ;
22
+ static const QString longDateFormatKey = " longDateFormat" ;
23
+ static const QString shortTimeFormatKey = " shortTimeFormat" ;
24
+ #endif // ENABLE_DSS_SNIPE
25
+
20
26
CenterTopWidget::CenterTopWidget (QWidget *parent)
21
27
: QWidget(parent)
22
28
, m_currentUser(nullptr )
@@ -64,6 +70,9 @@ void CenterTopWidget::setCurrentUser(User *user)
64
70
return ;
65
71
}
66
72
73
+ #ifdef ENABLE_DSS_SNIPE
74
+ updateRegionFormatConnection (user);
75
+ #endif // ENABLE_DSS_SNIPE
67
76
m_currentUser = QPointer<User>(user);
68
77
if (!m_currentUser.isNull ()) {
69
78
for (auto connect : m_currentUserConnects) {
@@ -86,6 +95,10 @@ void CenterTopWidget::setCurrentUser(User *user)
86
95
QTimer::singleShot (0 , this , [this , user] {
87
96
updateTimeFormat (user->isUse24HourFormat ());
88
97
});
98
+
99
+ #ifdef ENABLE_DSS_SNIPE
100
+ updateUserDateTimeFormat ();
101
+ #endif // ENABLE_DSS_SNIPE
89
102
}
90
103
91
104
@@ -157,3 +170,89 @@ void CenterTopWidget::onDConfigPropertyChanged(const QString &key, const QVarian
157
170
}
158
171
}
159
172
173
+ #ifdef ENABLE_DSS_SNIPE
174
+ void CenterTopWidget::onUserRegionFormatValueChanged (const QDBusMessage &dbusMessage)
175
+ {
176
+ QList<QVariant> arguments = dbusMessage.arguments ();
177
+ if (1 != arguments.count ())
178
+ return ;
179
+
180
+ QString key = dbusMessage.arguments ().at (0 ).toString ();
181
+ if (key == localeNameKey || key == shortTimeFormatKey || key == longDateFormatKey) {
182
+ updateUserDateTimeFormat ();
183
+ }
184
+ }
185
+
186
+ QString CenterTopWidget::getRegionFormatConfigPath (const User *user) const
187
+ {
188
+ if (!user)
189
+ return QString ();
190
+
191
+ QDBusInterface configInter (" org.desktopspec.ConfigManager" , " /" , " org.desktopspec.ConfigManager" , QDBusConnection::systemBus ());
192
+ if (!configInter.isValid ()) {
193
+ qWarning (" Can't acquire config manager. error:\" %s\" " ,
194
+ qPrintable (QDBusConnection::systemBus ().lastError ().message ()));
195
+ return QString ();
196
+ }
197
+ QDBusReply<QDBusObjectPath> dbusReply = configInter.call (" acquireManagerV2" ,
198
+ (uint )user->uid (),
199
+ QString (QCoreApplication::applicationName ()),
200
+ QString (" org.deepin.region-format" ),
201
+ QString (" " ));
202
+ if (configInter.lastError ().isValid () ) {
203
+ qWarning (" Call failed: %s" , qPrintable (configInter.lastError ().message ()));
204
+ return QString ();
205
+ }
206
+ return dbusReply.value ().path ();
207
+ }
208
+
209
+ QString CenterTopWidget::getRegionFormatValue (const QString &userConfigDbusPath, const QString &key) const
210
+ {
211
+ if (userConfigDbusPath.isEmpty ())
212
+ return QString ();
213
+ QDBusInterface managerInter (" org.desktopspec.ConfigManager" , userConfigDbusPath, " org.desktopspec.ConfigManager.Manager" , QDBusConnection::systemBus ());
214
+ QDBusReply<QVariant> reply = managerInter.call (" value" , key);
215
+ if (managerInter.lastError ().isValid () ) {
216
+ qWarning (" Call failed: %s" , qPrintable (managerInter.lastError ().message ()));
217
+ return QString ();
218
+ }
219
+ return reply.value ().toString ();
220
+ }
221
+
222
+ void CenterTopWidget::updateRegionFormatConnection (const User *user)
223
+ {
224
+ if (!user) {
225
+ return ;
226
+ }
227
+
228
+ // disconnect old user
229
+ if (m_currentUser) {
230
+ QString dbusPath = getRegionFormatConfigPath (m_currentUser);
231
+ if (dbusPath.isEmpty ())
232
+ return ;
233
+ QDBusConnection::systemBus ().disconnect (" org.desktopspec.ConfigManager" , dbusPath, " org.desktopspec.ConfigManager.Manager" ,
234
+ " valueChanged" , " s" , this ,
235
+ SLOT (onUserRegionFormatValueChanged (const QDBusMessage&)));
236
+ }
237
+
238
+ // connect new user
239
+ QString dbusPath = getRegionFormatConfigPath (user);
240
+ if (dbusPath.isEmpty ())
241
+ return ;
242
+
243
+ QDBusConnection::systemBus ().connect (" org.desktopspec.ConfigManager" , dbusPath, " org.desktopspec.ConfigManager.Manager" ,
244
+ " valueChanged" , " s" , this ,
245
+ SLOT (onUserRegionFormatValueChanged (const QDBusMessage&)));
246
+ }
247
+
248
+ void CenterTopWidget::updateUserDateTimeFormat ()
249
+ {
250
+ QString userConfigDbusPath = getRegionFormatConfigPath (m_currentUser);
251
+
252
+ QString localeName = qApp->applicationName () == " dde-lock" ? QLocale::system ().name () : getRegionFormatValue (userConfigDbusPath, localeNameKey);
253
+ QString shortTimeFormat = getRegionFormatValue (userConfigDbusPath, shortTimeFormatKey);
254
+ QString longDateFormat = getRegionFormatValue (userConfigDbusPath, longDateFormatKey);
255
+
256
+ m_timeWidget->updateLocale (localeName, shortTimeFormat, longDateFormat);
257
+ }
258
+ #endif // ENABLE_DSS_SNIPE
0 commit comments