Add new app event 98/297498/3
authorChanggyu Choi <changyu.choi@samsung.com>
Mon, 21 Aug 2023 04:29:25 +0000 (13:29 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Mon, 21 Aug 2023 08:21:31 +0000 (17:21 +0900)
tizen app can receive time zone changed event.

Adds:
 - TIME_ZONE_CHANGED

Change-Id: I1da9aeafd8e2afa1e878a1eaea5d8c68cfc1451d
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
tizen-cpp/app-core-cpp/app_core_base.cc
tizen-cpp/app-core-cpp/interface_app_core.hh
tizen-cpp/app-core-ui-cpp/app_core_task_base.cc
tizen-cpp/app-core-ui-cpp/app_core_task_base.hh

index 8a50042..38c02f0 100644 (file)
@@ -192,6 +192,7 @@ class AppCoreBase::Impl {
   static void ReceiveSuspendSignalCb(GDBusConnection*, const gchar*,
       const gchar*, const gchar*, const gchar*, GVariant*, gpointer);
   static void OnLowBatteryCb(keynode_t* key, void* data);
+  static void OnTimeZoneChangedCb(keynode_t* key, void* data);
   static void LockCb(keynode_t* node, void* user_data);
   static void AutoRotationChangedCb(sensor_t sensor, unsigned int event_type,
       sensor_data_t* data, void* user_data);
@@ -754,6 +755,21 @@ void AppCoreBase::Impl::OnLowBatteryCb(keynode_t* key, void* data) {
   }
 }
 
+void AppCoreBase::Impl::OnTimeZoneChangedCb(keynode_t* key, void* data) {
+  char* time_zone_id = vconf_keynode_get_str(key);
+  if (time_zone_id == nullptr) {
+    return;
+  }
+
+  char* time_zone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_INT);
+  if (time_zone != nullptr) {
+    AppCoreBase* base = reinterpret_cast<AppCoreBase*>(data);
+    base->impl_->InvokeCallback(std::string(time_zone) + "|" + time_zone_id,
+        IEvent::Type::TIME_ZONE_CHANGED);
+    free(time_zone);
+  }
+}
+
 void AppCoreBase::Impl::UnregisterRotationChangedEvent() {
   if (!__rotation.ref)
     return;
@@ -795,6 +811,10 @@ int AppCoreBase::OnSetEvent(IEvent::Type event) {
     break;
   case IEvent::Type::SUSPENDED_STATE_CHANGE:
     break;
+  case IEvent::Type::TIME_ZONE_CHANGED:
+    vconf_notify_key_changed(VCONFKEY_SETAPPL_TIMEZONE_ID,
+        impl_->OnTimeZoneChangedCb, this);
+    break;
   default:
     break;
   }
index 504abbe..ed9ce8b 100644 (file)
@@ -40,6 +40,7 @@ class EXPORT_API IAppCore {
       REGION_CHANGE,
       SUSPENDED_STATE_CHANGE,
       UPDATE_REQUESTED,
+      TIME_ZONE_CHANGED,
       END /* for iterate */
     };
 
index f6e1906..1425b68 100644 (file)
@@ -72,6 +72,7 @@ class AppCoreTaskBase::Impl : public SystemEvent::IEvent {
   std::shared_ptr<SystemEvent> lang_change_;
   std::shared_ptr<SystemEvent> device_orientation_changed_;
   std::shared_ptr<SystemEvent> region_change_;
+  std::shared_ptr<SystemEvent> time_zone_change_;
   GMainLoop* loop_ = nullptr;
   std::queue<UiState> queue_;
   mutable std::recursive_mutex mutex_;
@@ -100,6 +101,8 @@ AppCoreTaskBase::Impl::Impl(AppCoreTaskBase* parent) : parent_(parent) {
       IAppCore::IEvent::Type::DEVICE_ORIENTATION_CHANGED, this);
   region_change_ = std::make_shared<SystemEvent>(
       IAppCore::IEvent::Type::REGION_CHANGE, this);
+  time_zone_change_ = std::make_shared<SystemEvent>(
+      IAppCore::IEvent::Type::TIME_ZONE_CHANGED, this);
 }
 
 void AppCoreTaskBase::Impl::LoopInit(int argc, char** argv) {
@@ -127,6 +130,7 @@ void AppCoreTaskBase::Impl::SetSystemEvents() {
 }
 
 void AppCoreTaskBase::Impl::UnsetSystemEvents() {
+  parent_->RemoveEvent(time_zone_change_);
   parent_->RemoveEvent(region_change_);
   parent_->RemoveEvent(device_orientation_changed_);
   parent_->RemoveEvent(lang_change_);
@@ -146,6 +150,8 @@ void AppCoreTaskBase::Impl::OnSystemEvent(IAppCore::IEvent::Type type) {
         ConvertRotationState(device_orientation_changed_->GetVal(0)));
   } else if (type == IAppCore::IEvent::Type::REGION_CHANGE) {
     parent_->OnRegionChanged(region_change_->GetVal(""));
+  } else if (type == IAppCore::IEvent::Type::TIME_ZONE_CHANGED) {
+    parent_->OnTimeZoneChanged(time_zone_change_->GetVal(""));
   }
 }
 
@@ -286,6 +292,8 @@ void AppCoreTaskBase::OnDeviceOrientationChanged(DeviceOrientationState state) {
 
 void AppCoreTaskBase::OnRegionChanged(const std::string& region) {}
 
+void AppCoreTaskBase::OnTimeZoneChanged(const std::string& time_zone) {}
+
 void AppCoreTaskBase::Run(int argc, char** argv) {
   impl_->SetSystemEvents();
   AppCoreBase::Run(argc, argv);
index 182e64b..da4355c 100644 (file)
@@ -70,6 +70,7 @@ class EXPORT_API AppCoreTaskBase : public AppCoreBase,
   virtual void OnLangChanged(const std::string& lang);
   virtual void OnDeviceOrientationChanged(DeviceOrientationState state);
   virtual void OnRegionChanged(const std::string& region);
+  virtual void OnTimeZoneChanged(const std::string& time_zone);
 
   void Run(int argc, char** argv) override;