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;
#include "GalleryAlbum.h"
+// Including next header in order to use: getpid().
+#include <unistd.h>
+
#include "ucl/misc/TString.h"
#include "model/MediaItem.h"
const auto CONDITION = TString("%s=%d").format(
MEDIA_TYPE, MEDIA_CONTENT_TYPE_IMAGE);
+
+ constexpr auto UPDATE_IDLE_TIMEOUT_SEC = 0.1;
}}}
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) {
{
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);
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;
{
#include <vector>
+#include <Ecore.h>
+
#include "ucl/misc/Event.h"
#include "model/IMediaAlbum.h"
static GalleryAlbumSRef newInstance();
virtual ~GalleryAlbum();
- ucl::Result update();
-
// IMediaAlbum //
virtual void addChangeHandler(
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;