implemented ui_iface_viewmgr_get_view() and ui_viewmgr_get_view_by_name(). 95/75695/2
authorHermet Park <hermet@hermet.pe.kr>
Tue, 21 Jun 2016 05:02:32 +0000 (14:02 +0900)
committerHermet Park <chuneon.park@samsung.com>
Wed, 22 Jun 2016 06:11:54 +0000 (23:11 -0700)
also renamed an API from ui_viewmgr_get_view() to ui_viewmgr_get_view_by_idx().
and removed ui_iface_view::set_name().

Allow renaming of view is ridiculous because we expect view name is unique.
So users should decide its name when they create the view instance.

Change-Id: I769ded274f82cbce251fefe426555e890670095d

12 files changed:
src/include/efl/mobile/c/ui_standard_view.h
src/include/efl/mobile/c/ui_view.h
src/include/efl/mobile/c/ui_viewmgr.h
src/include/efl/mobile/ui_view.h
src/include/efl/ui_base_viewmgr.h
src/include/interface/ui_iface_view.h
src/include/interface/ui_iface_viewmgr.h
src/lib/efl/mobile/c/ui_view.cpp
src/lib/efl/mobile/c/ui_viewmgr.cpp
src/lib/efl/ui_base_viewmgr.cpp
src/lib/interface/ui_iface_view.cpp
src/lib/interface/ui_iface_viewmgr.cpp

index 0e0ae0a..b739280 100644 (file)
@@ -16,9 +16,10 @@ extern "C" {
  *  @brief A constructor for an ui_standard_view.
  *
  *  @param name view name
- *
  *  @param view An ui_standard_view instance.
  *
+ *  @warning if you don't set a view name, you could not look up the view with its name. @see ui_viewmgr_view_get_by_name().
+ *
  *  @see ui_view_destroy()
  */
 EAPI ui_standard_view *ui_standard_view_create(const char *name);
index 6854e79..69ce29b 100644 (file)
@@ -72,6 +72,8 @@ typedef struct
  *
  *  @return The ui_view instance.
  *
+ *  @warning if you don't set a view name, you could not look up the view with its name. @see ui_viewmgr_view_get_by_name().
+ *
  *  @see ui_view_destroy()
  */
 EAPI ui_view *ui_view_create(const char *name);
@@ -222,20 +224,6 @@ EAPI const char *ui_view_transition_style_get(ui_view *view);
 EAPI const ui_menu *ui_view_menu_get(ui_view *view);
 
 /**
- *  @brief Set name of ui_view.
- *
- *  @note A ui_view can have a unique name. Default value of the name is NULL.
- *
- *  @param view An ui_view instance.
- *  @param name A new name of given @p view.
- *
- *  @return @c true if the given @p name is available, otherwise @c false.
- *
- *  @see ui_view_name_get()
- */
-EAPI bool ui_view_name_set(ui_view *view, const char *name);
-
-/**
  *  @brief Return a name of this view.
  *
  *  @param view An ui_view instance.
index 6b38a05..5360f89 100644 (file)
@@ -136,7 +136,21 @@ EAPI ui_view *ui_viewmgr_last_view_get(ui_viewmgr *viewmgr);
  *  @see ui_viewmgr_view_index_get()
  *  @see ui_viewmgr_view_count_get()
  */
-EAPI ui_view *ui_viewmgr_view_get(ui_viewmgr *viewmgr, int idx);
+EAPI ui_view *ui_viewmgr_view_get_by_idx(ui_viewmgr *viewmgr, int idx);
+
+/**
+ *  @brief Return a view which is matched with the @p name.
+ *
+ *  @note Every view have their names as their own identifiers.
+ *
+ *  @param name The name of the view which you are looking for.
+ *
+ *  @return The view which name is matched with @p name.
+ *          If there were no views name matched, @c NULL will be returned.
+ *
+ *  @see ui_iface_view::set_name()
+ */
+EAPI ui_view *ui_viewmgr_view_get_by_name(ui_viewmgr *viewmgr, const char *name);
 
 /**
  *  @brief Get a base object of a ui_viewmgr.
@@ -162,9 +176,6 @@ EAPI Evas_Object *ui_viewmgr_base_get(ui_viewmgr *viewmgr);
  */
 EAPI int ui_viewmgr_view_index_get(ui_viewmgr *viewmgr, const ui_view *view);
 
-//FIXME:
-//ui_view *ui_viewmgr_view_get_by_id(ui_viewmgr *viewmgr, const char *id);
-
 /**
  *  @brief Return the number of views which this @p given viewmgr has.
  *
index c7b8bdf..5ae1d94 100644 (file)
@@ -40,6 +40,8 @@ public:
         *  @brief This is a constructor for initializing this view resources.
         *
         *  @param name view name.
+        *
+        *  @warning if you don't set a view name, you could not look up the view with its name. @see ui_viewmgr_view_get_by_name()
         */
        ui_view(const char *name = NULL);
 
index 398475d..7979bda 100644 (file)
@@ -154,6 +154,20 @@ public:
        ui_base_view *get_view(unsigned int idx);
 
        /**
+        *  @brief Return a view which is matched with the @p name.
+        *
+        *  @note Every view have their names as their own identifiers.
+        *
+        *  @param name The name of the view which you are looking for.
+        *
+        *  @return The view which name is matched with @p name.
+        *          If there were no views name matched, @c NULL will be returned.
+        *
+        *  @see ui_iface_view::set_name()
+        */
+       ui_base_view *get_view(const char *name);
+
+       /**
         *  @brief Get a base object of this viewmgr.
         *
         *  @note Normally, a base object can be used for adding additional objects.
index a4fbbd4..1324431 100644 (file)
@@ -44,6 +44,8 @@ public:
         *  @brief This is a constructor for initializing this view resources.
         *
         *  @param name view name.
+        *
+        *  @warning if you don't set a view name, you could not look up the view with its name. @see ui_viewmgr_view_get_by_name()
         */
        ui_iface_view(const char *name = NULL);
 
@@ -67,19 +69,6 @@ public:
        bool set_transition_style(const char *style);
 
        /**
-        *  @brief Set name of the view.
-        *
-        *  @note A view can have a unique name. Default value of the name is NULL.
-        *
-        *  @param name A new name of view.
-        *
-        *  @return true if the given @c name is available, otherwise false.
-        *
-        *  @warning When you override this member function, you should check the name duplicate with other view or not.
-        */
-       bool set_name(const char *name);
-
-       /**
         *  @brief Set content removable.
         *
         *  @param removable if @p removable is @c true, content of this view will be removed on unload state. @c false otherwise.
index a52faac..0efa710 100644 (file)
@@ -227,7 +227,7 @@ protected:
         *  @return The view which name is matched with @p name.
         *          If there were no views name matched, @c NULL will be returned.
         *
-        *  @see ui_iface_view::set_name()
+        *  @see ui_iface_view::get_name().
         */
        ui_iface_view *get_view(const char *name);
 
index eb777ab..365986f 100644 (file)
@@ -247,12 +247,6 @@ EAPI const ui_menu *ui_view_menu_get(ui_view *view)
        return view->get_menu();
 }
 
-EAPI bool ui_view_name_set(ui_view *view, const char *name)
-{
-       if (!validate_view(view)) return false;
-       return view->set_name(name);
-}
-
 EAPI const char *ui_view_name_get(ui_view *view)
 {
        if (!validate_view(view)) return NULL;
index 24e9e01..3a54ca1 100644 (file)
@@ -18,7 +18,6 @@ static bool validate_viewmgr(ui_viewmgr *viewmgr)
        return true;
 }
 
-
 EAPI ui_view *ui_viewmgr_view_push(ui_viewmgr *viewmgr, ui_view *view)
 {
        if (!viewmgr || !view)
@@ -82,12 +81,18 @@ EAPI ui_view *ui_viewmgr_last_view_get(ui_viewmgr *viewmgr)
        return dynamic_cast<ui_view *>(viewmgr->get_last_view());
 }
 
-EAPI ui_view *ui_viewmgr_view_get(ui_viewmgr *viewmgr, int idx)
+EAPI ui_view *ui_viewmgr_view_get_by_idx(ui_viewmgr *viewmgr, int idx)
 {
        if (!validate_viewmgr(viewmgr)) return NULL;
        return dynamic_cast<ui_view *>(viewmgr->get_view(idx));
 }
 
+EAPI ui_view *ui_viewmgr_view_get_by_name(ui_viewmgr *viewmgr, const char *name)
+{
+       if (!validate_viewmgr(viewmgr)) return NULL;
+       return dynamic_cast<ui_view *>(viewmgr->get_view(name));
+}
+
 EAPI Evas_Object *ui_viewmgr_base_get(ui_viewmgr *viewmgr)
 {
        if (!validate_viewmgr(viewmgr)) return NULL;
@@ -105,7 +110,6 @@ EAPI int ui_viewmgr_view_index_get(ui_viewmgr *viewmgr, const ui_view *view)
        return viewmgr->get_view_index(view);
 }
 
-
 EAPI int ui_viewmgr_view_count_get(ui_viewmgr *viewmgr)
 {
        if (!validate_viewmgr(viewmgr)) return -1;
index daddf2a..a5c3742 100644 (file)
@@ -521,6 +521,11 @@ ui_base_view *ui_base_viewmgr::get_view(unsigned int idx)
        return dynamic_cast<ui_base_view *>(ui_iface_viewmgr::get_view(idx));
 }
 
+ui_base_view *ui_base_viewmgr::get_view(const char *name)
+{
+       return dynamic_cast<ui_base_view *>(ui_iface_viewmgr::get_view(name));
+}
+
 ui_base_view *ui_base_viewmgr::get_last_view()
 {
        return dynamic_cast<ui_base_view *>(ui_iface_viewmgr::get_last_view());
index bdd0c48..2d6cfb9 100644 (file)
@@ -60,7 +60,6 @@ public:
        ~ui_iface_view_impl();
 
        bool set_transition_style(const char *style);
-       bool set_name(const char *name);
        void set_removable_content(bool removable);
        void set_indicator(ui_view_indicator indicator);
        const char *get_transition_style();
@@ -155,12 +154,6 @@ bool ui_iface_view_impl::set_transition_style(const char *style)
        return true;
 }
 
-bool ui_iface_view_impl::set_name(const char *name)
-{
-       this->name.assign(name);
-       return true;
-}
-
 void ui_iface_view_impl::set_removable_content(bool removable)
 {
        this->removable_content = removable;
@@ -288,11 +281,6 @@ bool ui_iface_view::set_transition_style(const char *style)
        return this->impl->set_transition_style(style);
 }
 
-bool ui_iface_view::set_name(const char *name)
-{
-       return this->impl->set_name(name);
-}
-
 void ui_iface_view::set_removable_content(bool removable)
 {
        this->impl->set_removable_content(removable);
index 7c14bf3..fb5cc86 100644 (file)
@@ -127,6 +127,26 @@ bool ui_iface_viewmgr_impl::need_soft_key()
 
 bool ui_iface_viewmgr_impl::connect_view(ui_iface_view *view)
 {
+       //TODO: Perform this only in debug mode?
+       //Check whether the same name of this view is already existed in this viewmgr?
+       int name_len = strlen(view->get_name());
+       const char *name = view->get_name();
+
+       for (VIEW_ITR it = this->view_list.begin(); it != this->view_list.end(); it++)
+       {
+               ui_iface_view *view = *it;
+               const char *view_name = view->get_name();
+               if (!view_name) continue;
+               int view_name_len = strlen(view_name);
+
+               //Got you!
+               if ((view_name_len == name_len) && !strcmp(name, view_name))
+               {
+                       LOGE("the same name of ui_iface_view(%p) is already in this ui_iface_viewmgr(%p)", view, this);
+                       return false;
+               }
+       }
+
        return view->set_viewmgr(this->get_instance());
 }
 
@@ -409,7 +429,23 @@ bool ui_iface_viewmgr_impl::deactivate()
 
 ui_iface_view *ui_iface_viewmgr_impl::get_view(const char *name)
 {
-       //FIXME: ...
+       if (!name) return NULL;
+       int name_len = strlen(name);
+
+       for (VIEW_ITR it = this->view_list.begin(); it != this->view_list.end(); it++)
+       {
+               ui_iface_view *view = *it;
+               const char *view_name = view->get_name();
+               if (!view_name) continue;
+               int view_name_len = strlen(view_name);
+
+               //Got you!
+               if ((view_name_len == name_len) && !strcmp(name, view_name))
+               {
+                       return view;
+               }
+       }
+
        return NULL;
 }