ThemeExtension implementaion 92/94392/7
authorKamil Lipiszko <k.lipiszko@samsung.com>
Fri, 28 Oct 2016 13:27:48 +0000 (15:27 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Fri, 4 Nov 2016 11:27:08 +0000 (04:27 -0700)
Implements ThemeExtension static class to disable
adding themes to the search paths list that are
already added.

Change-Id: Ie92d0d52655e7c2455a0ef6d1834c4f1014ed76b

clock/inc/Utils/ThemeExtension.h [new file with mode: 0644]
clock/src/Utils/ThemeExtension.cpp [new file with mode: 0644]
clock/src/View/AlarmView.cpp
clock/src/View/EditAlarmView.cpp
clock/src/View/WorldClockDeleteItemsView.cpp
clock/src/View/WorldClockView.cpp

diff --git a/clock/inc/Utils/ThemeExtension.h b/clock/inc/Utils/ThemeExtension.h
new file mode 100644 (file)
index 0000000..ca42cd7
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2016 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 _CLOCK_UTILS_THEME_MANAGER_H_
+#define _CLOCK_UTILS_THEME_MANAGER_H_
+
+#include <set>
+#include <string>
+
+namespace utils {
+
+class ThemeExtension {
+public:
+
+       /**
+        * @brief Adds theme to the list of extensions.
+        *
+        * @param[in] path The path to the edje file
+        */
+       static void AddTheme(const std::string &path);
+
+       /**
+        * @brief Removes theme from the list of extensions.
+        *
+        * @param[in] path The path to the edje file
+        */
+       static void DelTheme(const std::string &path);
+
+private:
+       static std::set<std::string> themes_;
+       ThemeExtension() {};
+};
+}
+
+#endif //_CLOCK_UTILS_THEME_MANAGER_H_
diff --git a/clock/src/Utils/ThemeExtension.cpp b/clock/src/Utils/ThemeExtension.cpp
new file mode 100644 (file)
index 0000000..0a9ed89
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2016 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 <Elementary.h>
+
+#include "Utils/ThemeExtension.h"
+#include "Utils/Log.h"
+
+namespace utils {
+
+std::set<std::string> ThemeExtension::themes_;
+
+void ThemeExtension::AddTheme(const std::string &path)
+{
+       auto ret = themes_.insert(path);
+       if (!ret.second) {
+               INF("Theme with %s path already exists", path.c_str());
+               return;
+       }
+
+       elm_theme_extension_add(NULL, path.c_str());
+}
+
+void ThemeExtension::DelTheme(const std::string &path)
+{
+       auto it = themes_.find(path);
+       if (it == themes_.end())
+               return;
+       else
+               themes_.erase(it);
+
+       elm_theme_extension_del(NULL, path.c_str());
+}
+
+}
index 4416656..619668b 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "Utils/Log.h"
 #include "Utils/PopupManager.h"
+#include "Utils/ThemeExtension.h"
 
 using namespace view;
 using namespace model;
@@ -167,14 +168,15 @@ AlarmView::AlarmView(ui::IView &main)
        Evas_Object *btn = elm_button_add(fb);
        evas_object_smart_callback_add(btn, "clicked", AlarmView::ButtonClicked, this);
        Evas_Object *image = elm_image_add(fb);
-       elm_image_file_set(image, Utils::GetAppResourcePath(Utils::APP_DIR_RESOURCE, "images/core_floating_icon_01.png"), NULL);
+       elm_image_file_set(image, Utils::GetAppResourcePath(Utils::APP_DIR_RESOURCE,
+                               "images/core_floating_icon_01.png"), NULL);
        elm_object_part_content_set(btn, "icon", image);
 
        elm_object_part_content_set(fb, "button1", btn);
 
-       elm_theme_extension_add(NULL, Utils::GetAppResourcePath(Utils::APP_DIR_RESOURCE, "edje/alarm.edj"));
+       ThemeExtension::AddTheme(Utils::GetAppResourcePath(Utils::APP_DIR_RESOURCE, "edje/alarm.edj"));
 
-        eext_object_event_callback_add(content_, EEXT_CALLBACK_MORE,
+       eext_object_event_callback_add(content_, EEXT_CALLBACK_MORE,
                         AlarmView::MoreButtonClicked, this);
 }
 
index 30281f1..d856380 100644 (file)
@@ -17,6 +17,7 @@
 #include "Utils/Log.h"
 #include "View/EditAlarmView.h"
 #include "Utils/Utils.h"
+#include "Utils/ThemeExtension.h"
 
 #include <efl_extension.h>
 #include <Elementary.h>
@@ -183,8 +184,8 @@ void EditAlarmView::CreateContent(Evas_Object *parent)
        elm_object_item_content_set(navi_item_, content_);
 
        // load additional genlist item styles
-       elm_theme_extension_add(NULL,
-            Utils::GetAppResourcePath(Utils::APP_DIR_RESOURCE, "edje/edit_alarm.edj"));
+       ThemeExtension::AddTheme(Utils::GetAppResourcePath(Utils::APP_DIR_RESOURCE,
+                               "edje/edit_alarm.edj"));
 
        CreateGenlistItems();
 }
index 25f37fa..092d585 100644 (file)
@@ -14,7 +14,6 @@
 * limitations under the License.
 */
 
-#include <efl_extension.h>
 #include <vector>
 #include <sstream>
 #include <tuple>
@@ -26,6 +25,7 @@
 #include "Utils/Time.h"
 #include "Utils/Log.h"
 #include "Utils/WorldClock.h"
+#include "Utils/ThemeExtension.h"
 
 using namespace view;
 using namespace utils;
@@ -248,14 +248,9 @@ void WorldClockDeleteItemsView::CreateContent(Evas_Object *parent)
 
        elm_object_item_style_set(navi_item_, "basic");
 
-       static bool extension_init = false;
-
-       if (!extension_init) {
-               elm_theme_extension_add(NULL,
-                               Utils::GetAppResourcePath(Utils::APP_DIR_RESOURCE,
+       ThemeExtension::AddTheme(Utils::GetAppResourcePath(Utils::APP_DIR_RESOURCE,
                                "edje/WorldClockDeleteReorderList.edj"));
-               extension_init = true;
-       }
+
        left_button_ = elm_button_add(parent);
        elm_object_text_set(left_button_, "CANCEL");
        elm_object_style_set(left_button_, "naviframe/title_left");
index 8a058f7..59f5928 100644 (file)
@@ -30,6 +30,7 @@
 #include "Utils/Time.h"
 #include "Utils/WorldClock.h"
 #include "Utils/PopupManager.h"
+#include "Utils/ThemeExtension.h"
 
 using namespace view;
 using namespace utils;
@@ -253,8 +254,9 @@ WorldClockView::WorldClockView(ui::IView &main)
                "main")) {
                FAT("Failed to load layout file");
        }
-       elm_theme_extension_add(NULL,
-                       Utils::GetAppResourcePath(Utils::APP_DIR_RESOURCE, "edje/CitiesListItem.edj"));
+
+       ThemeExtension::AddTheme(Utils::GetAppResourcePath(Utils::APP_DIR_RESOURCE,
+                               "edje/CitiesListItem.edj"));
 
        evas_object_size_hint_align_set(world_clock_, EVAS_HINT_FILL, EVAS_HINT_FILL);
        evas_object_size_hint_weight_set(world_clock_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);