[Gallery] Implemented content DB update event listening 09/128609/4
authorIgor Nazarov <i.nazarov@samsung.com>
Wed, 10 May 2017 12:43:24 +0000 (15:43 +0300)
committerIgor Nazarov <i.nazarov@samsung.com>
Mon, 15 May 2017 14:06:51 +0000 (17:06 +0300)
- Implemented content DB update listening logic in GalleryAlbum class;
- Fixed ImageGrid linear EDC layout.

Change-Id: I71f5f8c258ebb251d2a3d7e1cb94f23b99820237

edc/image-grid.edc
inc/model/Gallery.h
src/model/Gallery.cpp
src/model/GalleryAlbum.cpp
src/model/GalleryAlbum.h
src/presenters/Instance.cpp

index ad03e260604c5e0841d689b12979e16f04e87e5e..7ca4b37f1bec2f8784ee0a6603464914d0210b2a 100644 (file)
@@ -164,6 +164,7 @@ group { "elm/layout/gallery_image_grid/linear";
          }
       }
       image { "image_mask_0";
+         scale;
          precise;
          desc { "default";
             image.normal: "gallery_circle_basic.png";
@@ -186,6 +187,7 @@ group { "elm/layout/gallery_image_grid/linear";
          }
       }
       image { "select_ring_0";
+         scale;
          repeat;
          desc { "default";
             hid;
index 3026a7b10f94b915be8fbd24f7237446130af9f6..e3f994d2a7247b9bc864bf108bf720bcfce988c9 100644 (file)
@@ -26,9 +26,6 @@ namespace gallery {
                static GallerySRef newInstance();
                ~Gallery();
 
-               // TODO Temporary feature while support only offline mode
-               void updateAlbum();
-
                IMediaAlbumSRef getAlbum();
 
        private:
index c8e511a6ba2db078cba97cec1fd9026b6eedfe6a..73c804d9b1a829852ffe00136a73d8e37218c34e 100644 (file)
@@ -55,28 +55,14 @@ namespace gallery {
 
                m_isMediaDbConnected = true;
 
-               auto album = GalleryAlbum::newInstance();
-               if (!album) {
+               m_album = GalleryAlbum::newInstance();
+               if (!m_album) {
                        LOG_RETURN(RES_FAIL, "GalleryAlbum::newInstance() failed!");
                }
 
-               FAIL_RETURN(album->update(), "album->update() failed!");
-
-               m_album = std::move(album);
-
                return RES_OK;
        }
 
-       void Gallery::updateAlbum()
-       {
-               const auto album = dynamic_cast<GalleryAlbum *>(m_album.get());
-               if (album) {
-                       album->update();
-               } else {
-                       ELOG("m_album is not a GalleryAlbum!");
-               }
-       }
-
        IMediaAlbumSRef Gallery::getAlbum()
        {
                return m_album;
index 5cdab127bea30954649518366f638b6b9a184467..b0eb5f06b61704afccf9a011179b700cd44bd648 100644 (file)
@@ -16,6 +16,9 @@
 
 #include "GalleryAlbum.h"
 
+// Including next header in order to use: getpid().
+#include <unistd.h>
+
 #include "ucl/misc/TString.h"
 
 #include "model/MediaItem.h"
@@ -28,6 +31,8 @@ namespace gallery { namespace { namespace impl {
 
        const auto CONDITION = TString("%s=%d").format(
                        MEDIA_TYPE, MEDIA_CONTENT_TYPE_IMAGE);
+
+       constexpr auto UPDATE_IDLE_TIMEOUT_SEC = 0.1;
 }}}
 
 namespace gallery {
@@ -35,13 +40,20 @@ namespace gallery {
        using namespace ucl;
 
        GalleryAlbum::GalleryAlbum() :
+               m_pid(getpid()),
                m_filter(nullptr),
+               m_noti(),
+               m_updateTimer(nullptr),
                m_isValid(false)
        {
        }
 
        GalleryAlbum::~GalleryAlbum()
        {
+               stopUpdateTimer();
+               if (m_noti) {
+                       media_content_remove_db_updated_cb(m_noti);
+               }
                if (m_filter) {
                        const int ret = media_filter_destroy(m_filter);
                        if (ret != 0) {
@@ -61,6 +73,14 @@ namespace gallery {
        {
                int ret = 0;
 
+               ret = media_content_add_db_updated_cb(
+                               CALLBACK_B(GalleryAlbum::onContentDbUpdate), this, &m_noti);
+               if (ret != 0) {
+                       m_noti = {};
+                       LOG_RETURN(RES_FAIL,
+                                       "media_content_add_db_updated_cb() failed: %d", ret);
+               }
+
                ret = media_filter_create(&m_filter);
                if (ret != 0) {
                        ELOG("media_filter_create() failed: %d", ret);
@@ -82,11 +102,61 @@ namespace gallery {
                        return RES_FAIL;
                }
 
+               FAIL_RETURN(update(), "update() failed!");
+
                return RES_OK;
        }
 
+       void GalleryAlbum::onContentDbUpdate(
+                       media_content_error_e error, int pid,
+                       media_content_db_update_item_type_e update_item,
+                       media_content_db_update_type_e update_type,
+                       media_content_type_e media_type,
+                       char *uuid, char *path, char *mime_type)
+       {
+               if ((update_item == MEDIA_ITEM_FILE) &&
+                               (media_type == MEDIA_CONTENT_TYPE_IMAGE) &&
+                               ((pid != m_pid) || (update_type != MEDIA_CONTENT_DELETE))) {
+                       if (!resetUpdateTimer()) {
+                               update();
+                       }
+               }
+       }
+
+       bool GalleryAlbum::resetUpdateTimer()
+       {
+               stopUpdateTimer();
+
+               m_updateTimer = ecore_timer_add(impl::UPDATE_IDLE_TIMEOUT_SEC,
+                               CALLBACK_A(GalleryAlbum::onUpdateTimer), this);
+               if (!m_updateTimer) {
+                       LOG_RETURN_VALUE(RES_FAIL, false, "ecore_timer_add() failed!");
+               }
+
+               return true;
+       }
+
+       void GalleryAlbum::stopUpdateTimer()
+       {
+               if (m_updateTimer) {
+                       ecore_timer_del(m_updateTimer);
+                       m_updateTimer = nullptr;
+               }
+       }
+
+       Eina_Bool GalleryAlbum::onUpdateTimer()
+       {
+               m_updateTimer = nullptr;
+
+               update();
+
+               return ECORE_CALLBACK_CANCEL;
+       }
+
        Result GalleryAlbum::update()
        {
+               stopUpdateTimer();
+
                MediaItems newItems;
 
                {
index de5bab2c730bb477c249cb85727b385542dd42f4..9a030439667467222d02368bdddbd7cd5b719f78 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <vector>
 
+#include <Ecore.h>
+
 #include "ucl/misc/Event.h"
 
 #include "model/IMediaAlbum.h"
@@ -32,8 +34,6 @@ namespace gallery {
                static GalleryAlbumSRef newInstance();
                virtual ~GalleryAlbum();
 
-               ucl::Result update();
-
                // IMediaAlbum //
 
                virtual void addChangeHandler(
@@ -52,8 +52,25 @@ namespace gallery {
 
                ucl::Result prepare();
 
+               ucl::Result update();
+
+               bool resetUpdateTimer();
+               void stopUpdateTimer();
+
+               void onContentDbUpdate(
+                               media_content_error_e error, int pid,
+                               media_content_db_update_item_type_e update_item,
+                               media_content_db_update_type_e update_type,
+                               media_content_type_e media_type,
+                               char *uuid, char *path, char *mime_type);
+
+               Eina_Bool onUpdateTimer();
+
        private:
+               const int m_pid;
                filter_h m_filter;
+               media_content_noti_h m_noti;
+               Ecore_Timer *m_updateTimer;
                ucl::Event<NotiHandler> m_onChange;
                MediaItems m_items;
                bool m_isValid;
index ede037c8f73c5ba302179a2d4922089513009b91..fef4dce8c96d8e44e62bceebd8cf6f81dd7f18e0 100644 (file)
@@ -160,8 +160,6 @@ namespace gallery {
                DLOG("Media scan complete. error: %d", error);
 
                m_isScanInProgress = false;
-
-               m_gallery->updateAlbum();
        }
 
        void Instance::onAppControl(app_control_h appControl)