Refact MsgThread controller, Fixed: TizenRefApp-5082 09/56609/3
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Mon, 11 Jan 2016 10:09:42 +0000 (12:09 +0200)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Mon, 11 Jan 2016 12:55:02 +0000 (14:55 +0200)
Show "no content layout" in case of no threads in thread-list view

Change-Id: I78818a5bdf867a35d2dd05f213ce81e964b78c02
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
21 files changed:
res/edje/macros.inl
res/edje/msg_thread.edc
src/Common/MsgEngine/inc/MsgList.h
src/Common/View/inc/ListItem.h
src/Common/View/inc/ListView.h
src/Common/View/inc/View.h
src/Common/View/src/ListView.cpp
src/MsgThread/Controller/inc/MsgThread.h
src/MsgThread/Controller/inc/ThreadList.h [new file with mode: 0644]
src/MsgThread/Controller/inc/ThreadSearchList.h [moved from src/MsgThread/View/inc/ThreadListView.h with 70% similarity]
src/MsgThread/Controller/src/MsgThread.cpp
src/MsgThread/Controller/src/MsgThreadSearch.cpp [deleted file]
src/MsgThread/Controller/src/ThreadList.cpp [new file with mode: 0644]
src/MsgThread/Controller/src/ThreadSearchList.cpp [moved from src/MsgThread/Controller/inc/ThreadListItemType.h with 73% similarity]
src/MsgThread/View/inc/MsgThreadLayout.h
src/MsgThread/View/inc/MsgThreadSearchPanel.h
src/MsgThread/View/src/MsgThreadLayout.cpp
src/MsgThread/View/src/MsgThreadSearchPanel.cpp
src/MsgThread/View/src/ThreadListView.cpp [deleted file]
src/MsgThread/View/src/ThreadListViewItem.cpp
src/Settings/Controller/src/SimListViewItem.cpp

index aa81d4e..37bd3fa 100644 (file)
@@ -1,3 +1,4 @@
+#define BASE_SCALE 1.8
 
 #define PADDING_LEFT(param_padding_name, param_padding_size) \
        part \
                        color: 255 255 255 64; \
                } \
        }
-
+#define SIG(name_, state_, target_)            \
+       program { name: name_;                          \
+               signal: name_;                                  \
+               source: "";                                             \
+               action: STATE_SET state_ 0.0;   \
+               target: target_;                                \
+       }
index 8aeb74d..608fe85 100755 (executable)
@@ -1,30 +1,33 @@
+#include "macros.inl"
+
 collections {
 
-    base_scale: 1.8;
+    base_scale: BASE_SCALE;
 
-    group { name: "msg_thread";
+    group { name: "msg_thread_layout";
       parts {
          part { name: "swl.bg";
             type: SWALLOW;
             scale: 1;
             description { state: "default" 0.0;
+                visible: 1;
+            }
+            description { state: "hide" 0.0;
+                inherit: "default" 0.0;
+                visible: 0;
             }
          }
-         part { name: "swl.searchbar";
+         part { name: "swl.search_list";
             type: SWALLOW;
             mouse_events: 1;
             scale: 1;
             description { state: "default" 0.0;
-               min: 0 0;
-               fixed: 0 1;
-               align: 0.5 1.0;
-               rel2 {
-                  relative: 1.0 0.0;
-               }
+               align: 0.0 0.0;
+               visible: 1;
             }
-            description { state: "visible" 0.0;
-               inherit: "default" 0.0;
-               align: 0.5 0.0;
+            description { state: "hide" 0.0;
+                inherit: "default" 0.0;
+                visible: 0;
             }
          }
          part { name: "swl.list";
@@ -33,26 +36,21 @@ collections {
             scale: 1;
             description { state: "default" 0.0;
                align: 0.0 0.0;
-               rel1 {
-                  relative: 0.0 1.0;
-                  to: "swl.searchbar";
-               }
+               visible: 1;
+            }
+            description { state: "hide" 0.0;
+                inherit: "default" 0.0;
+                visible: 0;
             }
          }
       }
       programs {
-         program { name: "show_searchbar";
-            signal: "show_searchbar";
-            source: "";
-            action: STATE_SET "visible" 0.0;
-            target: "swl.searchbar";
-         }
-         program { name: "hide_searchbar";
-            signal: "hide_searchbar";
-            source: "";
-            action: STATE_SET "default" 0.0;
-            target: "swl.searchbar";
-         }
+         SIG("hide_bg", "hide", "swl.bg");
+         SIG("show_bg", "default", "swl.bg");
+         SIG("hide_list", "hide", "swl.list");
+         SIG("show_list", "default", "swl.list");
+         SIG("hide_search_list", "hide", "swl.search_list");
+         SIG("show_search_list", "default", "swl.search_list");
       }
    }
 }
index 8a7160d..8a0aacb 100644 (file)
@@ -42,6 +42,11 @@ namespace Msg
             {
                 return at(i);
             }
+
+            inline bool isEmpty() const
+            {
+                return getLength() <= 0;
+            }
     };
 }
 
index 83c20dd..4cc9883 100644 (file)
@@ -63,7 +63,7 @@ namespace Msg
 
         public:
             ListItem(Elm_Genlist_Item_Type type = ELM_GENLIST_ITEM_NONE, int userType = 0);
-            ListItem(const ListItemStyleRef &itemStyle, Elm_Genlist_Item_Type type, int userType);
+            ListItem(const ListItemStyleRef &itemStyle, Elm_Genlist_Item_Type type, int userType = 0);
             virtual ~ListItem();
 
             // Base elm methods:
index 9befdbe..f874b46 100644 (file)
@@ -45,6 +45,7 @@ namespace Msg
             void setMultiSelection(bool value);
             bool getMultiSelection() const;
             void clear();
+            bool isEmpty() const;
             void setMode(Elm_List_Mode mode);
             void setHomogeneous(bool isHomogeneous);
             ListItem *getSelectedItem() const;
@@ -108,9 +109,7 @@ namespace Msg
             {
                 T *listItem = dynamic_cast<T*>(static_cast<ListItem*>(data));
                 if(listItem)
-                {
                     list.push_back(listItem);
-                }
             }
             elmItem = elm_genlist_item_next_get(elmItem);
         }
index b57b05f..da1c3f6 100644 (file)
@@ -38,6 +38,7 @@ namespace Msg
             inline bool isVisible() const;
             inline void show();
             inline void hide();
+            inline void setVisibility(bool show);
             inline void move(Evas_Coord x, Evas_Coord y);
             inline void setSizeHintWeight(double x = EVAS_HINT_EXPAND, double y = EVAS_HINT_EXPAND);
             inline void setSizeHintAlign(double x = EVAS_HINT_FILL, double y = EVAS_HINT_FILL);
@@ -128,6 +129,14 @@ namespace Msg
         evas_object_hide(m_pEo);
     }
 
+    inline void View::setVisibility(bool show)
+    {
+        if(show)
+            View::show();
+        else
+            hide();
+    }
+
     inline void View::setSizeHintWeight(double x, double y)
     {
         evas_object_size_hint_weight_set(m_pEo, x, y);
index 9a24b42..30e9899 100644 (file)
@@ -123,6 +123,11 @@ void ListView::clear()
     elm_genlist_clear(getEo());
 }
 
+bool ListView::isEmpty() const
+{
+    return elm_genlist_first_item_get(getEo()) == nullptr;
+}
+
 void ListView::setMode(Elm_List_Mode mode)
 {
     elm_genlist_mode_set(getEo(), mode);
index cce6b3f..9995126 100644 (file)
 
 #include "FrameController.h"
 #include "HwButtonListener.h"
-#include "MsgStorage.h"
-#include "ListView.h"
 #include "Popup.h"
 #include "ContextPopup.h"
 #include "MsgThreadLayout.h"
 #include "MsgThreadSearchPanel.h"
 #include "FloatingButton.h"
 #include "NoContentLayout.h"
+#include "MsgTypes.h"
+#include "ThreadList.h"
+#include "ThreadSearchList.h"
 
 #include <string>
 #include <memory>
@@ -37,16 +38,14 @@ namespace Msg
     class SelectAllListItem;
     class NaviFrameController;
     class ThreadListItem;
-    class ThreadListView;
     class App;
 
     class MsgThread
         : public FrameController
         , private IHwButtonListener
-        , private IListViewListener
-        , private IMsgStorageListener
         , private IMsgThreadSearchPanelListener
         , private IFloatingButtonListener
+        , private IThreadListListener
     {
         public:
             MsgThread(NaviFrameController &parent);
@@ -61,17 +60,7 @@ namespace Msg
             virtual void onHwBackButtonClicked();
             virtual void onHwMoreButtonClicked();
 
-            // IMsgStorageListener:
-            virtual void onMsgStorageChange(const MsgIdList &idList);
-
-            // IListViewListener:
-            virtual void onListItemSelected(ListItem &listItem, void *funcData);
-            virtual void onListItemChecked(ListItem &listItem, void *funcData);
-
-            // IPopupListener:
-            virtual void onPopupButtonClicked(Popup &popup, int buttonId);
-
-            // ContextPopup callbacks:
+            // Popup callbacks:
             void onSettingsItemPressed(ContextPopupItem &item);
             void onDeleteItemPressed(ContextPopupItem &item);
             void onSearchItemPressed(ContextPopupItem &item);
@@ -83,18 +72,21 @@ namespace Msg
             // IFloatingButtonListener
             virtual void onFloatingButtonPressed();
 
+            // IThreadListListener:
+            virtual void onListItemSelected(ThreadId id);
+            virtual void onThreadListChanged();
+
         private:
             enum Mode
             {
                 InitMode,
-                NormalMode,
                 DeleteMode,
+                NormalMode,
                 SearchMode
             };
 
         private:
             // MsgThread:
-            void updateThreadList();
             void composeNewMessage();
             void navigateToSettings();
             void navigateToConversation(ThreadId threadId);
@@ -102,11 +94,7 @@ namespace Msg
             void setMode(Mode mode);
             void setDeleteMode(bool value);
             void setNormalMode();
-            void deleteSelectedItems();
-
-            void checkHandler(SelectAllListItem &item);
-            void checkHandler(ThreadListItem &item);
-            void selectHandler(ThreadListItem &item);
+            void update();
 
             // Search:
             Evas_Object *createSearchPanel(Evas_Object *parent);
@@ -115,7 +103,8 @@ namespace Msg
         private:
             MsgThreadLayout *m_pLayout;
             NoContentLayout *m_pNoContent;
-            ThreadListView *m_pThreadListView;
+            ThreadList *m_pThreadList;
+            ThreadSearchList *m_pSearchList;
             MsgThreadSearchPanel *m_pSearchPanel;
             Mode m_Mode;
 
diff --git a/src/MsgThread/Controller/inc/ThreadList.h b/src/MsgThread/Controller/inc/ThreadList.h
new file mode 100644 (file)
index 0000000..6896aac
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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 ThreadList_h_
+#define ThreadList_h_
+
+#include "ListView.h"
+#include "MsgStorage.h"
+
+namespace Msg
+{
+    class IThreadListListener;
+    class SelectAllListItem;
+    class ThreadListItem;
+    class App;
+
+    class ThreadList
+        : public ListView
+        , private IMsgStorageListener
+        , private IListViewListener
+    {
+        public:
+            ThreadList(Evas_Object *parent, App &app);
+            virtual ~ThreadList();
+
+            void setListener(IThreadListListener *l);
+            void setDeleteMode(bool value);
+            bool isDeleteModeEnabled() const;
+            void deleteSelectedItems();
+
+        private:
+            // IMsgStorageListener:
+            virtual void onMsgStorageChange(const MsgIdList &idList);
+
+            // IListViewListener:
+            virtual void onListItemSelected(ListItem &listItem, void *funcData);
+            virtual void onListItemChecked(ListItem &listItem, void *funcData);
+
+        private:
+            void showSelectAllItem(bool show, bool resetCheck = true);
+            void checkAllItems(bool check);
+            void checkHandler(SelectAllListItem &item);
+            void checkHandler(ThreadListItem &item);
+            void updateList();
+
+        private:
+            IThreadListListener *m_pListener;
+            App &m_App;
+            bool m_DeleteMode;
+    };
+
+    class IThreadListListener
+    {
+        public:
+            virtual ~IThreadListListener() {}
+            virtual void onListItemSelected(ThreadId id) {};
+            virtual void onThreadListChanged() {}
+    };
+}
+
+#endif // ThreadList_h_
similarity index 70%
rename from src/MsgThread/View/inc/ThreadListView.h
rename to src/MsgThread/Controller/inc/ThreadSearchList.h
index 8681294..690c357 100644 (file)
  *
  */
 
-#ifndef ThreadListView_h_
-#define ThreadListView_h_
+#ifndef ThreadSearchList_h_
+#define ThreadSearchList_h_
 
 #include "ListView.h"
 
 namespace Msg
 {
-    class ThreadListView
+    class ThreadSearchList
         : public ListView
     {
         public:
-            ThreadListView(Evas_Object *parent);
-            virtual ~ThreadListView();
-
-            void showSelectAllItem(bool show, bool resetCheck = true);
-            void checkAllItems(bool check);
+            ThreadSearchList(Evas_Object *parent);
+            virtual ~ThreadSearchList();
     };
 }
 
-#endif // ThreadListView_h_
+#endif // ThreadSearchList_h_
index a15a1cd..b04efad 100644 (file)
 #include "Settings.h"
 #include "Conversation.h"
 #include "Logger.h"
-#include "ThreadListView.h"
-#include "ThreadListItem.h"
-#include "PathUtils.h"
-#include "MsgEngine.h"
 #include "App.h"
-#include "ThreadListItem.h"
-#include "ThreadListItemType.h"
-#include "SelectAllListItem.h"
 #include "Popup.h"
-#include "ContactManager.h"
-#include <Elementary.h>
-#include <sstream>
 
 using namespace Msg;
 
@@ -38,7 +28,8 @@ MsgThread::MsgThread(NaviFrameController &parent)
     : FrameController(parent)
     , m_pLayout(nullptr)
     , m_pNoContent(nullptr)
-    , m_pThreadListView(nullptr)
+    , m_pThreadList(nullptr)
+    , m_pSearchList(nullptr)
     , m_pSearchPanel(nullptr)
     , m_Mode(InitMode)
     , m_pFloatingBtn(nullptr)
@@ -52,24 +43,33 @@ MsgThread::MsgThread(NaviFrameController &parent)
     m_pLayout->setFloatingButton(*m_pFloatingBtn);
 
     m_pNoContent = new NoContentLayout(*m_pLayout);
-    m_pNoContent->setText(msgt("IDS_MSG_NPBODY_NO_MESSAGES"));
+    m_pNoContent->show();
+
+    m_pThreadList = new ThreadList(*m_pLayout, getApp());
+    m_pThreadList->setListener(this);
+    m_pThreadList->show();
 
-    m_pThreadListView = new ThreadListView(*m_pLayout);
-    m_pThreadListView->setListener(this);
-    m_pThreadListView->setMultiSelection(false);
-    m_pThreadListView->show();
+    m_pSearchList = new ThreadSearchList(*m_pLayout);
+    m_pSearchList->show();
 
-    m_pLayout->setBg(*m_pNoContent);
-    m_pLayout->setList(*m_pThreadListView);
-    updateThreadList();
-    getMsgEngine().getStorage().addListener(*this);
+    m_pLayout->setNoContent(*m_pNoContent);
+    m_pLayout->setList(*m_pThreadList);
+    m_pLayout->setSearchList(*m_pSearchList);
 
     setMode(NormalMode);
 }
 
 MsgThread::~MsgThread()
 {
-    getMsgEngine().getStorage().removeListener(*this);
+}
+
+Evas_Object *MsgThread::createSearchPanel(Evas_Object *parent)
+{
+    m_pSearchPanel = new MsgThreadSearchPanel(*m_pLayout);
+    m_pSearchPanel->setListener(this);
+    m_pSearchPanel->setGuideText("Search");
+    m_pSearchPanel->show();
+    return *m_pSearchPanel;
 }
 
 void MsgThread::onAttached(ViewItem &item)
@@ -93,34 +93,6 @@ void MsgThread::showMainCtxPopup()
     popupMngr.getCtxPopup().show();
 }
 
-void MsgThread::onFloatingButtonPressed()
-{
-    composeNewMessage();
-}
-
-void MsgThread::updateThreadList()
-{
-    MsgThreadListRef list = getMsgEngine().getStorage().getThreadList();
-
-    int length = list->getLength();
-    for(int i = 0; i < length; ++i)
-    {
-        ThreadListItem *item = new ThreadListItem(list->at(i), getApp());
-        m_pThreadListView->appendItem(*item);
-    }
-
-    if(length > 0)
-    {
-        m_pNoContent->hide();
-        m_pThreadListView->show();
-    }
-    else
-    {
-       m_pThreadListView->hide();
-       m_pNoContent->show();
-    }
-}
-
 void MsgThread::composeNewMessage()
 {
     Conversation *frame = new Conversation(getParent());
@@ -145,20 +117,19 @@ void MsgThread::setMode(Mode mode)
         return;
 
     setNormalMode();
-
     switch(mode)
     {
         case NormalMode:
             break;
 
-        case DeleteMode:
-            setDeleteMode(true);
-            break;
-
         case SearchMode:
             setSearchMode(true);
             break;
 
+        case DeleteMode:
+            setDeleteMode(true);
+            break;
+
         case InitMode:
         default:
             MSG_ASSERT(false, "Not supported mode");
@@ -168,6 +139,8 @@ void MsgThread::setMode(Mode mode)
 
 void MsgThread::setNormalMode()
 {
+    MSG_LOG("");
+
     // Reset previus mode:
     switch(m_Mode)
     {
@@ -183,39 +156,62 @@ void MsgThread::setNormalMode()
             break;
     }
 
+    m_pNoContent->setText(msgt("IDS_MSG_NPBODY_NO_MESSAGES"));
     m_Mode = NormalMode;
+    update();
 }
 
 void MsgThread::setDeleteMode(bool value)
 {
+    MSG_LOG("");
+
     if(value)
         m_Mode = DeleteMode;
 
     getNaviBar().showButton(NaviOkButtonId, value);
     getNaviBar().showButton(NaviCancelButtonId, value);
-
-    m_pThreadListView->setCheckMode(value);
-    m_pThreadListView->checkAllItems(false);
-    m_pThreadListView->showSelectAllItem(value);
+    m_pThreadList->setDeleteMode(value);
 }
 
-void MsgThread::checkHandler(SelectAllListItem &item)
+void MsgThread::setSearchMode(bool value)
 {
-    bool checked = item.getCheckedState();
-    m_pThreadListView->checkAllItems(checked);
-}
+    MSG_LOG("");
 
-void MsgThread::checkHandler(ThreadListItem &item)
-{
-    ThreadId threadId = item.getThreadId();
-    MSG_LOG("Checked (id : state) = ", threadId, ":", item.getCheckedState());
+    getNaviBar().showButton(NaviPrevButtonId, value);
+    if(value)
+    {
+        m_Mode = SearchMode;
+        m_pSearchPanel->clearEntry();
+        getNaviBar().showSearch();
+        m_pNoContent->setText(msgt("IDS_MSG_NPBODY_NO_RESULTS_FOUND_ABB"));
+    }
+    else
+    {
+        getNaviBar().hideSearch();
+    }
+
+    update();
+    m_pSearchPanel->setEntryFocus(value);
 }
 
-void MsgThread::selectHandler(ThreadListItem &item)
+void MsgThread::update()
 {
-    ThreadId threadId = item.getThreadId();
-    MSG_LOG("Selected MsgThreadItem id = ", threadId);
-    navigateToConversation(threadId);
+    if(m_Mode == SearchMode)
+    {
+        bool showSearch = !m_pSearchList->isEmpty();
+        bool showThread = !showSearch && !m_pThreadList->isEmpty();
+        bool showNoContent = !showThread;
+
+        m_pLayout->showSearchList(showSearch);
+        m_pLayout->showThreadList(showThread);
+        m_pLayout->showNoContent(showNoContent);
+    }
+    else
+    {
+        bool showThread = !m_pThreadList->isEmpty();
+        m_pLayout->showThreadList(showThread);
+        m_pLayout->showNoContent(!showThread);
+    }
 }
 
 void MsgThread::onHwBackButtonClicked()
@@ -234,65 +230,56 @@ void MsgThread::onHwMoreButtonClicked()
         showMainCtxPopup();
 }
 
-void MsgThread::onListItemSelected(ListItem &listItem, void *funcData)
+void MsgThread::onSettingsItemPressed(ContextPopupItem &item)
 {
-    listItem.setSelected(false);
-    if(ThreadListItem *it = dynamic_cast<ThreadListItem*>(&listItem))
-        selectHandler(*it);
+    MSG_LOG("");
+    item.getParent().destroy();
+    navigateToSettings();
 }
 
-void MsgThread::onListItemChecked(ListItem &listItem, void *funcData)
+void MsgThread::onDeleteItemPressed(ContextPopupItem &item)
 {
-    if(ThreadListItem *it = dynamic_cast<ThreadListItem*>(&listItem))
-        checkHandler(*it);
-    else if(SelectAllListItem *it = dynamic_cast<SelectAllListItem*>(&listItem))
-        checkHandler(*it);
+    MSG_LOG("");
+    item.getParent().destroy();
+    setMode(DeleteMode);
 }
 
-void MsgThread::onPopupButtonClicked(Popup &popup, int buttonId)
+void MsgThread::onSearchItemPressed(ContextPopupItem &item)
 {
-    MSG_LOG("Popup button id: ", buttonId);
-    popup.destroy();
+    MSG_LOG("");
+    item.getParent().destroy();
+    setMode(SearchMode);
 }
 
-void MsgThread::onMsgStorageChange(const MsgIdList &idList)
+void MsgThread::onButtonClicked(NaviFrameItem &item, NaviButtonId buttonId)
 {
-    m_pThreadListView->clear(); // FIXME: temporary solution for demo
-    updateThreadList();
+    MSG_LOG("NaviButton id:", buttonId);
+    if(buttonId == NaviOkButtonId)
+        m_pThreadList->deleteSelectedItems();
+    setMode(NormalMode);
 }
 
-void MsgThread::onSettingsItemPressed(ContextPopupItem &item)
+void MsgThread::onListItemSelected(ThreadId id)
 {
-    item.getParent().destroy();
-    navigateToSettings();
+    navigateToConversation(id);
 }
 
-void MsgThread::onDeleteItemPressed(ContextPopupItem &item)
+void MsgThread::onThreadListChanged()
 {
-    item.getParent().destroy();
-    setMode(DeleteMode);
+    update();
 }
 
-void MsgThread::onSearchItemPressed(ContextPopupItem &item)
+void MsgThread::onFloatingButtonPressed()
 {
-    item.getParent().destroy();
-    setMode(SearchMode);
+    composeNewMessage();
 }
 
-void MsgThread::deleteSelectedItems()
+void MsgThread::onSearchButtonClicked(MsgThreadSearchPanel &obj)
 {
-    auto collection = m_pThreadListView->getItems<ThreadListItem>();
-    for(ThreadListItem *it : collection)
-    {
-        if(it->getCheckedState())
-            getMsgEngine().getStorage().deleteThread(it->getThreadId());
-    }
+    MSG_LOG("");
 }
 
-void MsgThread::onButtonClicked(NaviFrameItem &item, NaviButtonId buttonId)
+void MsgThread::onEntryChanged(MsgThreadSearchPanel &obj)
 {
-    MSG_LOG("NaviButton id:", buttonId);
-    if(buttonId == NaviOkButtonId)
-        deleteSelectedItems();
-    setMode(NormalMode);
+    MSG_LOG("");
 }
diff --git a/src/MsgThread/Controller/src/MsgThreadSearch.cpp b/src/MsgThread/Controller/src/MsgThreadSearch.cpp
deleted file mode 100644 (file)
index 2cca558..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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 "MsgThread.h"
-#include "App.h"
-#include "Logger.h"
-
-using namespace Msg;
-
-Evas_Object *MsgThread::createSearchPanel(Evas_Object *parent)
-{
-    m_pSearchPanel = new MsgThreadSearchPanel(*m_pLayout);
-    m_pSearchPanel->setListener(this);
-    m_pSearchPanel->setGuideText("Search");
-    m_pSearchPanel->show();
-    return *m_pSearchPanel;
-}
-
-void MsgThread::setSearchMode(bool value)
-{
-    getNaviBar().showButton(NaviPrevButtonId, value);
-    if(value)
-    {
-        m_Mode = SearchMode;
-        m_pSearchPanel->clearEntry();
-        getNaviBar().showSearch();
-    }
-    else
-    {
-        getNaviBar().hideSearch();
-    }
-
-    m_pSearchPanel->setEntryFocus(value);
-}
-
-void MsgThread::onSearchButtonClicked(MsgThreadSearchPanel &obj)
-{
-    MSG_LOG("");
-}
-
-void MsgThread::onEntryChanged(MsgThreadSearchPanel &obj)
-{
-    MSG_LOG("");
-}
diff --git a/src/MsgThread/Controller/src/ThreadList.cpp b/src/MsgThread/Controller/src/ThreadList.cpp
new file mode 100644 (file)
index 0000000..f00bd62
--- /dev/null
@@ -0,0 +1,161 @@
+/*
+ * 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 "ThreadList.h"
+#include "ThreadListItem.h"
+#include "ListItem.h"
+#include "SelectAllListItem.h"
+#include "App.h"
+
+using namespace Msg;
+
+namespace
+{
+    inline bool isSelectAll(ListItem *it)
+    {
+        return dynamic_cast<SelectAllListItem*>(it) != nullptr;
+    }
+}
+
+ThreadList::ThreadList(Evas_Object *parent, App &app)
+    : ListView(parent)
+    , m_pListener(nullptr)
+    , m_App(app)
+    , m_DeleteMode(false)
+{
+    ListView::setListener(this);
+    ListView::setMultiSelection(false);
+    ListView::setMode(ELM_LIST_COMPRESS);
+    m_App.getMsgEngine().getStorage().addListener(*this);
+    updateList();
+}
+
+ThreadList::~ThreadList()
+{
+    m_App.getMsgEngine().getStorage().removeListener(*this);
+}
+
+void ThreadList::setListener(IThreadListListener *l)
+{
+    m_pListener = l;
+}
+
+void ThreadList::setDeleteMode(bool value)
+{
+    m_DeleteMode = value;
+    setCheckMode(value);
+    checkAllItems(false);
+    showSelectAllItem(value);
+}
+
+bool ThreadList::isDeleteModeEnabled() const
+{
+    return m_DeleteMode;
+}
+
+
+void ThreadList::deleteSelectedItems()
+{
+    auto collection = getItems<ThreadListItem>();
+    for(ThreadListItem *it : collection)
+    {
+        if(it->getCheckedState())
+            m_App.getMsgEngine().getStorage().deleteThread(it->getThreadId());
+    }
+}
+
+void ThreadList::showSelectAllItem(bool show, bool resetCheck)
+{
+    SelectAllListItem *item = dynamic_cast<SelectAllListItem*>(getFirstItem());
+
+    if(show)
+    {
+        if(!item)
+        {
+            item = new SelectAllListItem;
+            prependItem(*item);
+        }
+
+        if(item && resetCheck)
+            item->setCheckedState(false, true);
+    }
+    else
+    {
+        if(item)
+            item->destroy();
+    }
+}
+
+void ThreadList::checkAllItems(bool check)
+{
+    auto items = getItems();
+    for(ListItem *it : items)
+    {
+        if(it->isCheckable() && !isSelectAll(it))
+            it->setCheckedState(check, true);
+    }
+}
+
+void ThreadList::checkHandler(SelectAllListItem &item)
+{
+    bool checked = item.getCheckedState();
+    checkAllItems(checked);
+}
+
+void ThreadList::checkHandler(ThreadListItem &item)
+{
+    ThreadId threadId = item.getThreadId();
+    MSG_LOG("Checked (id : state) = ", threadId, ":", item.getCheckedState());
+}
+
+void ThreadList::updateList()
+{
+    MsgThreadListRef list = m_App.getMsgEngine().getStorage().getThreadList();
+    if(!list)
+        return;
+
+    int length = list->getLength();
+    for(int i = 0; i < length; ++i)
+    {
+        ThreadListItem *item = new ThreadListItem(list->at(i), m_App);
+        ListView::appendItem(*item);
+    }
+}
+
+void ThreadList::onMsgStorageChange(const MsgIdList &idList)
+{
+    ListView::clear(); // FIXME: temporary solution for demo
+    updateList();
+    if(m_pListener)
+        m_pListener->onThreadListChanged();
+}
+
+void ThreadList::onListItemSelected(ListItem &listItem, void *funcData)
+{
+    ThreadListItem *it = dynamic_cast<ThreadListItem*>(&listItem);
+    if(it && m_pListener)
+        m_pListener->onListItemSelected(it->getThreadId());
+}
+
+void ThreadList::onListItemChecked(ListItem &listItem, void *funcData)
+{
+    if(ThreadListItem *it = dynamic_cast<ThreadListItem*>(&listItem))
+        checkHandler(*it);
+    else if(SelectAllListItem *it = dynamic_cast<SelectAllListItem*>(&listItem))
+        checkHandler(*it);
+}
  * 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 __THREAD_LIST_ITEM_TYPE_H__
-#define __THREAD_LIST_ITEM_TYPE_H__
 
-namespace Msg
-{
-    enum ItemType
-    {
-        IT_TREAD = 0,
-        IT_SEPARATOR,
-        IT_MAX
-    };
-}
+#include "ThreadSearchList.h"
 
+using namespace Msg;
 
+ThreadSearchList::ThreadSearchList(Evas_Object *parent)
+    : ListView(parent)
+{
+    setMultiSelection(false);
+    setMode(ELM_LIST_COMPRESS);
+}
 
-#endif /* __THREAD_LIST_ITEM_TYPE_H__ */
+ThreadSearchList::~ThreadSearchList()
+{
+}
index 2cbb2a2..8ab36ce 100644 (file)
@@ -31,8 +31,11 @@ namespace Msg
             virtual ~MsgThreadLayout();
 
             void setList(Evas_Object *list);
-            void setBg(Evas_Object *bg);
-
+            void setSearchList(Evas_Object *searchList);
+            void setNoContent(Evas_Object *bg);
+            void showNoContent(bool show);
+            void showSearchList(bool show);
+            void showThreadList(bool show);
         private:
             void create(Evas_Object *parent);
             void setContent(Evas_Object *obj);
index cb59347..d0e1211 100644 (file)
@@ -38,6 +38,7 @@ namespace Msg
             void showClearButton(bool visible);
             void setGuideText(const std::string &text);
             void setEntryFocus(bool focus);
+            bool isEmpty() const;
 
         private:
             void create(Evas_Object *parent);
index 70dec0a..1437657 100644 (file)
@@ -37,7 +37,7 @@ void MsgThreadLayout::create(Evas_Object *parent)
     m_pLayout = elm_layout_add(parent);
     evas_object_show(m_pLayout);
     std::string path = PathUtils::getResourcePath(MSG_THREAD_EDJ_PATH);
-    elm_layout_file_set(m_pLayout, path.c_str(), "msg_thread");
+    elm_layout_file_set(m_pLayout, path.c_str(), "msg_thread_layout");
     DefaultLayout::setContent(m_pLayout);
 }
 
@@ -46,7 +46,30 @@ void MsgThreadLayout::setList(Evas_Object *list)
     elm_object_part_content_set(m_pLayout, "swl.list", list);
 }
 
-void MsgThreadLayout::setBg(Evas_Object *bg)
+void MsgThreadLayout::setSearchList(Evas_Object *searchList)
+{
+    elm_object_part_content_set(m_pLayout, "swl.search_list", searchList);
+}
+
+void MsgThreadLayout::setNoContent(Evas_Object *bg)
 {
     elm_object_part_content_set(m_pLayout, "swl.bg", bg);
 }
+
+void MsgThreadLayout::showNoContent(bool show)
+{
+    const char *sig = show ? "show_bg" : "hide_bg";
+    elm_layout_signal_emit(m_pLayout, sig, "");
+}
+
+void MsgThreadLayout::showSearchList(bool show)
+{
+    const char *sig = show ? "show_search_list" : "hide_search_list";
+    elm_layout_signal_emit(m_pLayout, sig, "");
+}
+
+void MsgThreadLayout::showThreadList(bool show)
+{
+    const char *sig = show ? "show_list" : "hide_list";
+    elm_layout_signal_emit(m_pLayout, sig, "");
+}
index 55a0d80..b9f08ec 100644 (file)
@@ -49,6 +49,12 @@ void MsgThreadSearchPanel::create(Evas_Object *parent)
     // setContent(backButton, "swl.back_button"); TODO:
 }
 
+bool MsgThreadSearchPanel::isEmpty() const
+{
+    const char *text = elm_entry_entry_get(m_pEntry);
+    return text ? *text == 0 : true;
+}
+
 void MsgThreadSearchPanel::setListener(IMsgThreadSearchPanelListener *listener)
 {
     m_pListener = listener;
diff --git a/src/MsgThread/View/src/ThreadListView.cpp b/src/MsgThread/View/src/ThreadListView.cpp
deleted file mode 100644 (file)
index b75108a..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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 "ThreadListView.h"
-#include "ThreadListViewItem.h"
-#include "ListItem.h"
-#include "SelectAllListItem.h"
-
-using namespace Msg;
-
-namespace
-{
-    inline bool isSelectAll(ListItem *it)
-    {
-        return dynamic_cast<SelectAllListItem*>(it) != nullptr;
-    }
-}
-
-ThreadListView::ThreadListView(Evas_Object *parent)
-    : ListView(parent)
-{
-
-}
-
-ThreadListView::~ThreadListView()
-{
-}
-
-void ThreadListView::showSelectAllItem(bool show, bool resetCheck)
-{
-    SelectAllListItem *item = dynamic_cast<SelectAllListItem*>(getFirstItem());
-
-    if(show)
-    {
-        if(!item)
-        {
-            item = new SelectAllListItem;
-            prependItem(*item);
-        }
-
-        if(item && resetCheck)
-        {
-            item->setCheckedState(false, true);
-        }
-    }
-    else
-    {
-        if(item)
-        {
-            item->destroy();
-        }
-    }
-}
-
-void ThreadListView::checkAllItems(bool check)
-{
-    auto items = getItems();
-    for(ListItem *it : items)
-    {
-        if(it->isCheckable() && !isSelectAll(it))
-        {
-            it->setCheckedState(check, true);
-        }
-    }
-}
index 608b114..50a10cc 100644 (file)
@@ -16,8 +16,6 @@
  */
 
 #include "ThreadListViewItem.h"
-#include "ThreadListView.h"
-#include "ThreadListItemType.h"
 #include "Logger.h"
 #include "PathUtils.h"
 #include "ThumbnailMaker.h"
@@ -48,7 +46,7 @@ namespace
 }
 
 ThreadListViewItem::ThreadListViewItem(Elm_Genlist_Item_Type type)
-    : ListItem(threadItemStyle, type, IT_TREAD)
+    : ListItem(threadItemStyle, type)
     , m_State(NormalState)
 {
 }
index 4c33826..485041c 100644 (file)
@@ -16,8 +16,6 @@
  */
 
 #include "SimListViewItem.h"
-#include "ThreadListView.h"
-#include "ThreadListItemType.h"
 #include "Logger.h"
 #include "PathUtils.h"
 #include "ThumbnailMaker.h"
@@ -40,7 +38,7 @@ namespace
 }
 
 SimListViewItem::SimListViewItem(Elm_Genlist_Item_Type type)
-    : ListItem(SimItemStyle, type, IT_TREAD)
+    : ListItem(SimItemStyle, type)
 {
 }