Replace Command class to ClickableItem 32/281532/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 7 Sep 2022 06:21:19 +0000 (15:21 +0900)
committerTizen AI <ai.tzn.sec@samsung.com>
Tue, 20 Sep 2022 02:54:14 +0000 (11:54 +0900)
Change-Id: Ib6a18a5a3460a381bf899bbeda05f3501a4e7e83
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
src/mmimgr/iu/ClickableItem.h
src/mmimgr/iu/Command.cpp [deleted file]
src/mmimgr/iu/Command.h [deleted file]
src/mmimgr/iu/CommandFinder.cpp
src/mmimgr/iu/CommandFinder.h
src/mmimgr/iu/CommandManager.cpp
src/mmimgr/iu/CommandManager.h
src/mmimgr/meson.build

index e1e1b2e..b9bdcc4 100644 (file)
@@ -34,7 +34,7 @@ struct ClickableItem {
        int width;
        int height;
 
-       int objectId;
+       std::string objectId;
        std::string label;
        int index;
 };
diff --git a/src/mmimgr/iu/Command.cpp b/src/mmimgr/iu/Command.cpp
deleted file mode 100644 (file)
index a82867d..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-* Copyright © 2022 Samsung Electronics co., Ltd. All Rights Reserved.
-*
-* Permission is hereby granted, free of charge, to any person obtaining a
-* copy of this software and associated documentation files (the "Software"),
-* to deal in the Software without restriction, including without limitation
-* the rights to use, copy, modify, merge, publish, distribute, sublicense,
-* and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice (including the next
-* paragraph) shall be included in all copies or substantial portions of the
-* Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-* DEALINGS IN THE SOFTWARE.
-*/
-
-
-#include "Command.h"
-
-Command::Command(ClickableItem item)
-{
-       __item = item;
-}
-
-ClickableItem Command::getItem()
-{
-       return __item;
-}
-
-std::string Command::getLabel()
-{
-       return __item.label;
-}
-
-int Command::getIndex()
-{
-       return __item.index;
-}
diff --git a/src/mmimgr/iu/Command.h b/src/mmimgr/iu/Command.h
deleted file mode 100644 (file)
index 9761665..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
-* Copyright © 2022 Samsung Electronics co., Ltd. All Rights Reserved.
-*
-* Permission is hereby granted, free of charge, to any person obtaining a
-* copy of this software and associated documentation files (the "Software"),
-* to deal in the Software without restriction, including without limitation
-* the rights to use, copy, modify, merge, publish, distribute, sublicense,
-* and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice (including the next
-* paragraph) shall be included in all copies or substantial portions of the
-* Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-* DEALINGS IN THE SOFTWARE.
-*/
-
-
-#ifndef __TIZEN_UIX_MMI_IU_COMMAND_H__
-#define __TIZEN_UIX_MMI_IU_COMMAND_H__
-
-#include <string>
-#include "ClickableItem.h"
-
-class Command {
-       public:
-               Command(ClickableItem item);
-
-               ClickableItem getItem();
-               std::string getLabel();
-               int getIndex();
-
-       private:
-               ClickableItem __item;
-};
-
-#endif /* __TIZEN_UIX_MMI_IU_COMMAND_H__ */
\ No newline at end of file
index a733cd8..4dd2b19 100644 (file)
 
 using namespace std;
 
-CommandFinder::CommandFinder(std::string text, std::list<std::shared_ptr<Command>>& commands) :
-               __WORD_MATCHING_RATE(0.3), __CHAR_MATCHING_RATE(0.25), __commands(commands)
+CommandFinder::CommandFinder(std::string text, std::list<std::shared_ptr<ClickableItem>>& commands) :
+               __WORD_MATCHING_RATE(0.3), __CHAR_MATCHING_RATE(0.25), __MIN_WORD_SIZE(3), __commands(commands)
 {
        _I("[CommandFinder] Initiate command searcher. text(%s)", text.c_str());
 
        __loweredText = StringUtil::makeLowerCase(text);
        __splitText = StringUtil::splitText(__loweredText, ' ');
 
+       __index = -1;
        __isLabel = true;
 }
 
-CommandFinder::CommandFinder(int index, std::list<std::shared_ptr<Command>>& commands) :
-               __WORD_MATCHING_RATE(0.3), __CHAR_MATCHING_RATE(0.25), __commands(commands)
+CommandFinder::CommandFinder(int index, std::list<std::shared_ptr<ClickableItem>>& commands) :
+               __WORD_MATCHING_RATE(0.3), __CHAR_MATCHING_RATE(0.25), __MIN_WORD_SIZE(3), __commands(commands)
 {
        _I("[CommandFinder] Initiate command searcher. index(%d)", index);
 
        __index = index;
-
        __isLabel = false;
 }
 
-Command* CommandFinder::findCommand()
+ClickableItem* CommandFinder::findCommand()
 {
-       Command* result = nullptr;
+       ClickableItem* result = nullptr;
        if (__isLabel) {
                _I("[CommandFinder] Finde command by label text. text(%s)", __loweredText.c_str());
                result = findCommandByText();
@@ -82,7 +82,7 @@ Command* CommandFinder::findCommand()
 }
 
 
-Command* CommandFinder::findCommandByIndex()
+ClickableItem* CommandFinder::findCommandByIndex()
 {
        _I("[CommandFinder] Find command by index (%d)", __index);
 
@@ -91,7 +91,7 @@ Command* CommandFinder::findCommandByIndex()
        }
 
        for (auto command : __commands) {
-               if (command->getIndex() == __index) {
+               if (command->index == __index) {
                        return command.get();
                }
        }
@@ -99,12 +99,12 @@ Command* CommandFinder::findCommandByIndex()
        return nullptr;
 }
 
-Command* CommandFinder::findCommandByText()
+ClickableItem* CommandFinder::findCommandByText()
 {
        _I("[CommandFinder] Find command by text");
 
        for (auto command : __commands) {
-               string label = StringUtil::makeLowerCase(command->getLabel());
+               string label = StringUtil::makeLowerCase(command->label);
 
                bool isValid = true;
                for (auto& word : __splitText) {
@@ -122,15 +122,15 @@ Command* CommandFinder::findCommandByText()
        return nullptr;
 }
 
-Command* CommandFinder::findCommandByWord()
+ClickableItem* CommandFinder::findCommandByWord()
 {
        _I("[CommandFinder] Find command by word");
 
        int maxNumber = __splitText.size() * __WORD_MATCHING_RATE;
-       Command* result = nullptr;
+       ClickableItem* result = nullptr;
 
        for (auto command : __commands) {
-               string label = StringUtil::makeLowerCase(command->getLabel());
+               string label = StringUtil::makeLowerCase(command->label);
 
                int numOfWord = 0;
                for (auto& word : __splitText) {
@@ -148,20 +148,20 @@ Command* CommandFinder::findCommandByWord()
        return result;
 }
 
-Command* CommandFinder::findCommandByChar()
+ClickableItem* CommandFinder::findCommandByChar()
 {
        _I("[CommandFinder] Find command by word");
 
-       Command* result = nullptr;
+       ClickableItem* result = nullptr;
        int resultScore = numeric_limits<int>::max();
 
        for (auto command : __commands) {
-               string label = StringUtil::makeLowerCase(command->getLabel());
+               string label = StringUtil::makeLowerCase(command->label);
                vector<string> splitLabel = StringUtil::splitText(label, ' ');
 
                int score = 0;
                for (auto& word : __splitText) {
-                       if (word.size() < 3) {
+                       if (word.size() < __MIN_WORD_SIZE) {
                                continue;
                        }
 
@@ -169,7 +169,7 @@ Command* CommandFinder::findCommandByChar()
                        const int __MIN_THRESHOLD = word.size() * __CHAR_MATCHING_RATE;
                        int minScore = __MIN_THRESHOLD;
                        for (auto& labelWord : splitLabel) {
-                               if (labelWord.size() < 3) {
+                               if (labelWord.size() < __MIN_WORD_SIZE) {
                                        continue;
                                }
 
@@ -231,7 +231,7 @@ Command* CommandFinder::findCommandByChar()
 
        int threshold = 0;
        for (auto& word : __splitText) {
-               if (3 <= word.size()) {
+               if (word.size() >= __MIN_WORD_SIZE) {
                        threshold += word.size();
                }
        }
@@ -243,7 +243,7 @@ Command* CommandFinder::findCommandByChar()
        return nullptr;
 }
 
-Command* CommandFinder::findCommandByPron()
+ClickableItem* CommandFinder::findCommandByPron()
 {
        _I("[CommandFinder] Find command by word");
        _E("[CommandFinder] Not implemented");
index f2a2c02..31f43b9 100644 (file)
 #include <string>
 #include <memory>
 
-#include "Command.h"
+#include "ClickableItem.h"
 
 class CommandFinder {
        public:
-               CommandFinder(std::string text, std::list<std::shared_ptr<Command>>& __commands);
-               CommandFinder(int index, std::list<std::shared_ptr<Command>>& __commands);
+               CommandFinder(std::string text, std::list<std::shared_ptr<ClickableItem>> &__commands);
+               CommandFinder(int index, std::list<std::shared_ptr<ClickableItem>> &__commands);
 
-               Command* findCommand();
+               ClickableItem* findCommand();
 
        private:
-               Command* findCommandByIndex();
-               Command* findCommandByText();
-               Command* findCommandByWord();
-               Command* findCommandByChar();
-               Command* findCommandByPron();
+               ClickableItem* findCommandByIndex();
+               ClickableItem* findCommandByText();
+               ClickableItem* findCommandByWord();
+               ClickableItem* findCommandByChar();
+               ClickableItem* findCommandByPron();
 
        private:
                const double __WORD_MATCHING_RATE;
                const double __CHAR_MATCHING_RATE;
+               const std::size_t __MIN_WORD_SIZE;
 
-               std::list<std::shared_ptr<Command>>& __commands;
+               std::list<std::shared_ptr<ClickableItem>> &__commands;
                std::vector<std::string> __splitText;
                std::string __loweredText;
                int __index;
index 3389de9..e9f1856 100644 (file)
 
 using namespace std;
 
-
 void CommandManager::addCommand(ClickableItem item)
 {
        try {
-               shared_ptr<Command> command = make_shared<Command>(item);
+               shared_ptr<ClickableItem> command = make_shared<ClickableItem>(item);
                __commands.push_back(command);
-       } catch (exception e) {
+       } catch (exception &e) {
                _E("[CommandManager] Fail to make command. exception(%s)", e.what());
                return;
        }
@@ -50,13 +49,12 @@ void CommandManager::cleanCommands()
        __commands.clear();
 }
 
-Command* CommandManager::findCommand(std::string text, bool isIndex)
+ClickableItem* CommandManager::findCommand(std::string text, bool isIndex)
 {
        int index = -1;
-
        try {
                index = stoi(text);
-       } catch (exception e) {
+       } catch (exception &e) {
                _E("[CommandManager] Fail to convert. exception(%s)", e.what());
        }
 
@@ -72,7 +70,7 @@ Command* CommandManager::findCommand(std::string text, bool isIndex)
        }
 
        auto command = finder->findCommand();
-       _I("[CommandManager] Find command. text(%s). command(%s)", text.c_str(), command->getLabel().c_str());
+       _I("[CommandManager] Find command. text(%s). command(%s)", text.c_str(), command->label.c_str());
 
        return command;
 }
index b652b83..c467080 100644 (file)
 #define __TIZEN_UIX_MMI_IU_COMMAND_MANAGER_H__
 
 #include <list>
-#include <vector>
 #include <string>
 #include <memory>
 
-#include "Command.h"
+#include "ClickableItem.h"
 
 class CommandManager {
        public:
                void addCommand(ClickableItem item);
                void cleanCommands();
-               Command* findCommand(std::string text, bool isIndex);
-       private:
-
+               ClickableItem* findCommand(std::string text, bool isIndex);
 
        private:
-               std::list<std::shared_ptr<Command>> __commands;
+               std::list<std::shared_ptr<ClickableItem>> __commands;
 };
 
 #endif /* __TIZEN_UIX_MMI_IU_COMMAND_MANAGER_H__ */
\ No newline at end of file
index 63f43aa..9011afb 100644 (file)
@@ -29,13 +29,13 @@ mmimgr_srcs = [
        'iu/mmi_iu.cpp',
        'iu/output_intent.cpp',
        'iu/output_intent.h',
-       'iu/Command.h',
-       'iu/Command.cpp',
        'iu/CommandFinder.cpp',
        'iu/CommandFinder.h',
        'iu/ClickableItem.h',
        'iu/StringUtil.cpp',
-       'iu/StringUtil.h'
+       'iu/StringUtil.h',
+       'iu/CommandManager.cpp',
+       'iu/CommandManager.h',
        ]
 
 install_headers(