TizenRefApp-5800 Implement Listener to track time format settings change 54/64354/4
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Thu, 31 Mar 2016 14:48:53 +0000 (17:48 +0300)
committerAndrey Klimenko <and.klimenko@samsung.com>
Tue, 5 Apr 2016 08:34:28 +0000 (01:34 -0700)
Change-Id: I6fc4b63fab379fe11cadd76eea905851f5c7d89b
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
17 files changed:
.cproject
CMakeLists.txt
src/Common/Controller/inc/App.h
src/Common/Controller/src/App.cpp
src/Common/SystemSettingsManager/inc/SystemSettingsManager.h [new file with mode: 0644]
src/Common/SystemSettingsManager/src/SystemSettingsManager.cpp [new file with mode: 0644]
src/Common/Utils/inc/CallbackAssist.h
src/Conversation/ConvList/Controller/inc/ConvList.h
src/Conversation/ConvList/Controller/inc/ConvListItem.h
src/Conversation/ConvList/Controller/src/ConvList.cpp
src/Conversation/ConvList/Controller/src/ConvListItem.cpp
src/MsgThread/Controller/inc/BaseThreadListItem.h
src/MsgThread/Controller/inc/ThreadList.h
src/MsgThread/Controller/inc/ThreadSearchList.h
src/MsgThread/Controller/src/BaseThreadListItem.cpp
src/MsgThread/Controller/src/ThreadList.cpp
src/MsgThread/Controller/src/ThreadSearchList.cpp

index 454c5a2..d62079f 100644 (file)
--- a/.cproject
+++ b/.cproject
                                                                </option>
                                                                <option id="gnu.cpp.compiler.option.include.paths.1578788940" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Conversation/Utils/inc}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/SystemSettingsManager/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Conversation/AppControl/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Conversation/ConvList/Controller/inc}&quot;"/>
                                                                </option>
                                                                <option id="gnu.cpp.compiler.option.include.paths.2132319922" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Conversation/Utils/inc}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/SystemSettingsManager/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Conversation/AppControl/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Conversation/ConvList/Controller/inc}&quot;"/>
index efe2abe..d7c5fa0 100644 (file)
@@ -8,6 +8,7 @@ FILE(GLOB_RECURSE SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
 #include file
 INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES}
                     ${CMAKE_CURRENT_SOURCE_DIR}/inc/
+                    ${CMAKE_CURRENT_SOURCE_DIR}/src/Common/SystemSettingsManager/inc/
                     ${CMAKE_CURRENT_SOURCE_DIR}/src/Common/AppControl/inc/
                     ${CMAKE_CURRENT_SOURCE_DIR}/src/Common/ContactManager/inc/
                     ${CMAKE_CURRENT_SOURCE_DIR}/src/Common/Controller/inc/
index ad8b670..83d606e 100644 (file)
@@ -23,6 +23,7 @@
 #include "PopupManager.h"
 #include "ContactManager.h"
 #include "ThumbnailMaker.h"
+#include "SystemSettingsManager.h"
 #include <memory>
 
 namespace Msg
@@ -51,6 +52,9 @@ namespace Msg
             ThumbnailMaker &getThumbnailMaker();
             const ThumbnailMaker &getThumbnailMaker() const;
 
+            SystemSettingsManager &getSysSettingsManager();
+            const SystemSettingsManager &getSysSettingsManager() const;
+
             void exit();
 
         protected:
@@ -64,6 +68,7 @@ namespace Msg
             ContactManager *m_pContactManager;
             PopupManager *m_pPopupManager;
             ThumbnailMaker *m_pThumbnailMaker;
+            SystemSettingsManager *m_pSysSettingsManager;
     };
 }
 
index 6bbd6a6..00a0d7a 100644 (file)
@@ -27,6 +27,7 @@ App::App()
     : m_pContactManager(nullptr)
     , m_pPopupManager(nullptr)
     , m_pThumbnailMaker(nullptr)
+    , m_pSysSettingsManager(nullptr)
 {
     int serviceResult = m_Engine.openService();
     if(serviceResult != MESSAGES_ERROR_NONE)
@@ -41,10 +42,12 @@ App::~App()
     delete m_pThumbnailMaker;
     delete m_pContactManager;
     delete m_pPopupManager;
+    delete m_pSysSettingsManager;
 }
 
 bool App::init()
 {
+    getSysSettingsManager();
     getContactManager();
     getMsgEngine();
     getThumbnailMaker();
@@ -107,6 +110,18 @@ const ThumbnailMaker &App::getThumbnailMaker() const
     return const_cast<App*>(this)->getThumbnailMaker();
 }
 
+SystemSettingsManager &App::getSysSettingsManager()
+{
+    if(!m_pSysSettingsManager)
+        m_pSysSettingsManager = new SystemSettingsManager;
+    return *m_pSysSettingsManager;
+}
+
+const SystemSettingsManager &App::getSysSettingsManager() const
+{
+    return const_cast<App*>(this)->getSysSettingsManager();
+}
+
 void App::exit()
 {
     terminate();
diff --git a/src/Common/SystemSettingsManager/inc/SystemSettingsManager.h b/src/Common/SystemSettingsManager/inc/SystemSettingsManager.h
new file mode 100644 (file)
index 0000000..6321d4a
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __SystemSettingsManager_h__
+#define __SystemSettingsManager_h__
+
+#include <vector>
+
+namespace Msg
+{
+    class ISystemSettingsManager;
+
+    class SystemSettingsManager
+    {
+        public:
+            SystemSettingsManager();
+
+            void addListener(ISystemSettingsManager &l);
+            void removeListener(ISystemSettingsManager&l);
+
+        private:
+            SystemSettingsManager(SystemSettingsManager&) = delete;
+            SystemSettingsManager &operator =(const SystemSettingsManager&) = delete;
+
+            void onTimeFormatChanged();
+
+        private:
+            std::vector<ISystemSettingsManager*> m_Listeners;
+    };
+
+    class ISystemSettingsManager
+    {
+        public:
+            virtual ~ISystemSettingsManager() {}
+
+            virtual void onTimeFormatChanged() {};
+    };
+}
+
+#endif /* __SystemSettingsManager_h__ */
diff --git a/src/Common/SystemSettingsManager/src/SystemSettingsManager.cpp b/src/Common/SystemSettingsManager/src/SystemSettingsManager.cpp
new file mode 100644 (file)
index 0000000..4dcc5a9
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SystemSettingsManager.h"
+
+#include <algorithm>
+#include <system_settings.h>
+
+using namespace Msg;
+
+
+#define CALLBACK(method) [](system_settings_key_e key, void *user_data) \
+{                                                                       \
+    static_cast<SystemSettingsManager*>(user_data)->method();           \
+}
+
+SystemSettingsManager::SystemSettingsManager()
+{
+    system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, CALLBACK(onTimeFormatChanged), this);
+}
+
+void SystemSettingsManager::addListener(ISystemSettingsManager &l)
+{
+    auto it = std::find(m_Listeners.begin(), m_Listeners.end(), &l);
+    if(it == m_Listeners.end())
+        m_Listeners.push_back(&l);
+}
+
+void SystemSettingsManager::removeListener(ISystemSettingsManager&l)
+{
+    auto it = std::find(m_Listeners.begin(), m_Listeners.end(), &l);
+    if(it != m_Listeners.end())
+        m_Listeners.erase(it);
+}
+
+void SystemSettingsManager::onTimeFormatChanged()
+{
+    for(ISystemSettingsManager *it : m_Listeners)
+    {
+        it->onTimeFormatChanged();
+    }
+}
index 97b0d68..eb7270d 100644 (file)
@@ -50,4 +50,5 @@
 {                                                                                                                          \
     static_cast<ClassName*>(data)->method(obj, emission, source);                                                          \
 }
+
 #endif /* CallBackAssist_h_ */
index 5129ea5..f849111 100644 (file)
@@ -27,7 +27,9 @@
 #include "ContactManager.h"
 #include "DateLineViewItem.h"
 #include "WorkingDir.h"
+
 #include <unordered_map>
+#include <unordered_set>
 
 namespace Msg
 {
@@ -39,6 +41,7 @@ namespace Msg
         , private IListViewListener
         , private IConvListItemListener
         , private IContactManagerListener
+        , private ISystemSettingsManager
     {
         public:
             enum Mode
@@ -112,7 +115,7 @@ namespace Msg
 
         private:
             typedef std::unordered_map<MsgId::Type, ConvListItem*> ConvListItemMap;
-            typedef std::unordered_map<std::string, DateLineViewItem*> DateLineItemMap;
+            typedef std::unordered_set<std::string> DateLineItemSet;
 
         private:
             void create(Evas_Object *parent);
@@ -153,6 +156,9 @@ namespace Msg
             // SelectAll callback:
             void onSelectAllChanged(Evas_Object *obj, void *eventInfo);
 
+            // ISystemSettingsManager:
+            virtual void onTimeFormatChanged();
+
         private:
             Mode m_Mode;
             MsgEngine &m_MsgEngine;
@@ -160,7 +166,7 @@ namespace Msg
             ConvSelectAll *m_pSelectAll;
             ListView *m_pList;
             ConvListItemMap m_ConvListItemMap;
-            DateLineItemMap m_DateLineItemMap;
+            DateLineItemSet m_DateLineItemSet;
             IConvListListener *m_pListner;
             App &m_App;
             WorkingDirRef m_WorkingDir;
index 3973455..a70213b 100644 (file)
@@ -67,6 +67,7 @@ namespace Msg
             void setListener(IConvListItemListener *l);
 
             void updateStatus();
+            void updateTime();
 
         protected:
             // ConvListViewItem:
@@ -113,6 +114,7 @@ namespace Msg
             Message::NetworkStatus m_NetworkStatus;
             Message::Type m_Type;
             time_t m_Time;
+            std::string m_TimeStr;
             BubbleEntity m_BubbleEntity;
             const ThumbnailMaker::ThumbId &m_ThumbId;
     };
index be313d6..d069aa0 100644 (file)
@@ -35,7 +35,7 @@ ConvList::ConvList(Evas_Object *parent, App &app, WorkingDirRef workingDir)
     , m_pSelectAll(nullptr)
     , m_pList(nullptr)
     , m_ConvListItemMap()
-    , m_DateLineItemMap()
+    , m_DateLineItemSet()
     , m_pListner(nullptr)
     , m_App(app)
     , m_WorkingDir(workingDir)
@@ -50,6 +50,7 @@ ConvList::~ConvList()
 {
     m_MsgEngine.getStorage().removeListener(*this);
     m_App.getContactManager().removeListener(*this);
+    m_App.getSysSettingsManager().removeListener(*this);
 }
 
 void ConvList::setListener(IConvListListener *l)
@@ -89,6 +90,7 @@ void ConvList::create(Evas_Object *parent)
     showSelectAllMode(m_Mode == SelectMode);
 
     m_App.getContactManager().addListener(*this);
+    m_App.getSysSettingsManager().addListener(*this);
 }
 
 Evas_Object *ConvList::createSelectAll(Evas_Object *parent)
@@ -120,7 +122,7 @@ void ConvList::fill()
     int convListLen = convList->getLength();
     int reserveSize = convListLen <= minMessagesBulk/2 ? minMessagesBulk : convListLen + additionalMessagesBulk;
     m_ConvListItemMap.reserve(reserveSize);
-    m_DateLineItemMap.reserve(reserveSize);
+    m_DateLineItemSet.reserve(reserveSize);
 
     for(int i = 0; i < convListLen; ++i)
     {
@@ -221,7 +223,7 @@ void ConvList::dateLineDelIfNec(ConvListItem *item)
 
     if(needDelDateLine)
     {
-        m_DateLineItemMap.erase(prev->getDateLine());
+        m_DateLineItemSet.erase(prev->getDateLine());
         m_pList->deleteItem(*prev);
     }
 }
@@ -229,11 +231,11 @@ void ConvList::dateLineDelIfNec(ConvListItem *item)
 void ConvList::dateLineAddIfNec(ConvListItem *item)
 {
     std::string dateStr = TimeUtils::makeBubbleDateLineString(item->getRawTime());
-    auto it = m_DateLineItemMap.find(dateStr);
-    if (it == m_DateLineItemMap.end())
+    auto it = m_DateLineItemSet.find(dateStr);
+    if (it == m_DateLineItemSet.end())
     {
         DateLineViewItem *dateLine = new DateLineViewItem(dateStr);
-        m_DateLineItemMap[dateStr] = dateLine;
+        m_DateLineItemSet.insert(dateStr);
         m_pList->appendItem(*dateLine);
     }
 }
@@ -242,7 +244,7 @@ void ConvList::clear()
 {
     m_pList->clear();
     m_ConvListItemMap.clear();
-    m_DateLineItemMap.clear();
+    m_DateLineItemSet.clear();
 }
 
 void ConvList::deleteSelectedItems()
@@ -389,3 +391,14 @@ void ConvList::onContactChanged()
     updateOwnerThumbId();
     m_pList->updateRealizedItems();
 }
+
+void ConvList::onTimeFormatChanged()
+{
+    MSG_LOG("");
+    auto items = m_pList->getItems<ConvListItem>();
+    for(ConvListItem *item : items)
+    {
+        item->updateTime();
+    }
+    m_pList->updateRealizedItems();
+}
index 8784dc6..beb0c01 100644 (file)
@@ -28,6 +28,7 @@
 #include "MediaType.h"
 #include "MediaUtils.h"
 #include <notification_status.h>
+#include "TimeUtils.h"
 
 using namespace Msg;
 
@@ -75,6 +76,11 @@ void ConvListItem::updateStatus()
     update();
 }
 
+void ConvListItem::updateTime()
+{
+    m_TimeStr.clear();
+}
+
 ConvListViewItem::ConvItemType ConvListItem::getConvItemType(const MsgConversationItem &item)
 {
     ConvItemType type = ConvItemType::Sent;
@@ -176,7 +182,9 @@ Evas_Object *ConvListItem::getProgress()
 
 std::string ConvListItem::getTime()
 {
-    return TimeUtils::makeBubbleTimeString(m_Time);
+    if(m_TimeStr.empty())
+        m_TimeStr = TimeUtils::makeBubbleTimeString(m_Time);
+    return m_TimeStr;
 }
 
 MsgId ConvListItem::getMsgId() const
index d1bb3e8..f7d23b0 100644 (file)
@@ -36,16 +36,17 @@ namespace Msg
             BaseThreadListItem(App &app);
             virtual ~BaseThreadListItem();
 
-        protected:
             void updateThumbnailAndName(const MsgAddressList &addressList, bool decorateName);
             void updateThumbnailAndName(const MsgThreadItem &threadItem, bool decorateName);
             void updateName(const MsgAddress &address, int addressesCount, bool decorateName);
             void updateName(const ContactPersonAddress &address, int addressesCount, bool decorateName);
             void updateName(const std::string &address, int addressesCount, bool decorateName);
             void updateTime(time_t time);
+            void updateTime();
             void updateMessage(const MsgThreadItem &threadItem);
             void updateMessage(const std::string &msg);
 
+        protected:
             // ThreadListViewItem:
             virtual std::string getName();
             virtual std::string getMessage();
@@ -57,6 +58,7 @@ namespace Msg
             std::string m_Name;
             std::string m_Message;
             std::string m_Time;
+            time_t m_RawTime;
     };
 }
 
index bda252b..4f3ca1f 100644 (file)
@@ -21,6 +21,7 @@
 #include "ListView.h"
 #include "MsgStorage.h"
 #include "ContactManager.h"
+#include "SystemSettingsManager.h"
 
 namespace Msg
 {
@@ -34,6 +35,7 @@ namespace Msg
         , private IMsgStorageListener
         , private IListViewListener
         , private IContactManagerListener
+        , private ISystemSettingsManager
     {
         public:
             ThreadList(Evas_Object *parent, App &app);
@@ -56,6 +58,9 @@ namespace Msg
             virtual void onListItemSelected(ListItem &listItem);
             virtual void onListItemChecked(ListItem &listItem);
 
+            // ISystemSettingsManager:
+            virtual void onTimeFormatChanged();
+
         private:
             void showSelectAllItem(bool show, bool resetCheck = true);
             void checkAllItems(bool check);
index c4e7608..fdb82c8 100644 (file)
@@ -32,6 +32,7 @@ namespace Msg
         : public ListView
         , private IListViewListener
         , private IContactManagerListener
+        , private ISystemSettingsManager
     {
         public:
             ThreadSearchList(Evas_Object *parent, App &app);
@@ -49,6 +50,9 @@ namespace Msg
             // IContactManagerListener:
             virtual void onContactChanged();
 
+            // ISystemSettingsManager:
+            virtual void onTimeFormatChanged();
+
             void search();
 
         private:
index 9c1e85f..8e433ad 100644 (file)
@@ -26,6 +26,7 @@ using namespace Msg;
 BaseThreadListItem::BaseThreadListItem(App &app)
     : m_App(app)
     , m_ThumbId(m_App.getThumbnailMaker().getThumbId(ThumbnailMaker::SingleThumb))
+    , m_RawTime()
 {
 
 }
@@ -102,9 +103,15 @@ void BaseThreadListItem::updateName(const std::string &address, int addressesCou
 
 void BaseThreadListItem::updateTime(time_t time)
 {
+    m_RawTime = time;
     m_Time = TimeUtils::makeThreadTimeString(time);
 }
 
+void BaseThreadListItem::updateTime()
+{
+    m_Time = TimeUtils::makeThreadTimeString(m_RawTime);
+}
+
 std::string BaseThreadListItem::getName()
 {
     return m_Name;
index f45ad7d..ced0557 100644 (file)
@@ -43,6 +43,7 @@ ThreadList::ThreadList(Evas_Object *parent, App &app)
     ListView::setMode(ELM_LIST_COMPRESS);
     m_App.getMsgEngine().getStorage().addListener(*this);
     m_App.getContactManager().addListener(*this);
+    m_App.getSysSettingsManager().addListener(*this);
     updateList();
 }
 
@@ -50,6 +51,7 @@ ThreadList::~ThreadList()
 {
     m_App.getMsgEngine().getStorage().removeListener(*this);
     m_App.getContactManager().removeListener(*this);
+    m_App.getSysSettingsManager().removeListener(*this);
 }
 
 void ThreadList::setListener(IThreadListListener *l)
@@ -209,3 +211,15 @@ void ThreadList::onListItemChecked(ListItem &listItem)
     else if(SelectAllListItem *it = dynamic_cast<SelectAllListItem*>(&listItem))
         checkHandler(*it);
 }
+
+void ThreadList::onTimeFormatChanged()
+{
+    MSG_LOG("");
+    auto items = ListView::getItems<BaseThreadListItem>();
+    for(BaseThreadListItem *item : items)
+    {
+        item->updateTime();
+    }
+
+    ListView::updateRealizedItems();
+}
index 161b164..53091a0 100644 (file)
@@ -21,6 +21,7 @@
 #include "MsgEngine.h"
 #include "Logger.h"
 
+
 using namespace Msg;
 
 ThreadSearchList::ThreadSearchList(Evas_Object *parent, App &app)
@@ -33,12 +34,14 @@ ThreadSearchList::ThreadSearchList(Evas_Object *parent, App &app)
     setMode(ELM_LIST_COMPRESS);
     ListView::setListener(this);
     m_App.getContactManager().addListener(*this);
+    m_App.getSysSettingsManager().addListener(*this);
 }
 
 ThreadSearchList::~ThreadSearchList()
 {
     cancelSearch();
     m_App.getContactManager().removeListener(*this);
+    m_App.getSysSettingsManager().removeListener(*this);
 }
 
 void ThreadSearchList::setListener(IThreadSearchListListener *l)
@@ -132,3 +135,15 @@ void ThreadSearchList::onContactChanged()
 {
     search();
 }
+
+void ThreadSearchList::onTimeFormatChanged()
+{
+    MSG_LOG("");
+    auto items = ListView::getItems<BaseThreadListItem>();
+    for(BaseThreadListItem *item : items)
+    {
+        item->updateTime();
+    }
+
+    ListView::updateRealizedItems();
+}