Commit 70e3e9e1 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Plug the scan progress bar with media library

parent 5e8781db
...@@ -38,6 +38,9 @@ ...@@ -38,6 +38,9 @@
media_library::media_library() media_library::media_library()
: ml( NewMediaLibrary() ) : ml( NewMediaLibrary() )
, m_progressCb( nullptr )
, m_progressData( nullptr )
{ {
if ( ml == nullptr ) if ( ml == nullptr )
throw std::runtime_error( "Failed to initialize MediaLibrary" ); throw std::runtime_error( "Failed to initialize MediaLibrary" );
...@@ -110,7 +113,14 @@ media_library::onReloadCompleted( const std::string& entryPoint ) ...@@ -110,7 +113,14 @@ media_library::onReloadCompleted( const std::string& entryPoint )
void void
media_library::onParsingStatsUpdated( uint32_t percent ) media_library::onParsingStatsUpdated( uint32_t percent )
{ {
LOGI("Parser progress: %d%%", percent); auto ctx = new ProgressUpdateCallbackCtx{ this, (uint8_t)percent };
ecore_main_loop_thread_safe_call_async( [](void* p_data) {
std::unique_ptr<ProgressUpdateCallbackCtx> ctx( reinterpret_cast<ProgressUpdateCallbackCtx*>( p_data ) );
auto mlptr = ctx->wml.lock();
if ( mlptr == nullptr )
return;
ctx->ml->m_progressCb( ctx->ml->m_progressData, ctx->percent );
}, ctx);
} }
void void
...@@ -153,6 +163,12 @@ media_library::unregisterOnItemUpdated(media_library_item_updated_cb cb, void* u ...@@ -153,6 +163,12 @@ media_library::unregisterOnItemUpdated(media_library_item_updated_cb cb, void* u
} }
} }
void media_library::registerProgressCb( media_library_scan_progress_cb pf_progress, void* p_data )
{
m_progressCb = pf_progress;
m_progressData = p_data;
}
media_library * media_library *
media_library_create(application *p_app) media_library_create(application *p_app)
{ {
...@@ -351,6 +367,12 @@ media_library_unregister_item_updated(media_library* ml, media_library_item_upda ...@@ -351,6 +367,12 @@ media_library_unregister_item_updated(media_library* ml, media_library_item_upda
ml->unregisterOnItemUpdated(cb, p_data); ml->unregisterOnItemUpdated(cb, p_data);
} }
void
media_library_register_progress_cb( media_library* ml, media_library_scan_progress_cb pf_progress, void* p_data )
{
ml->registerProgressCb( pf_progress, p_data );
}
void void
media_library_reload(media_library* ml) media_library_reload(media_library* ml)
{ {
......
...@@ -47,6 +47,8 @@ typedef void (*media_library_list_cb)( Eina_List*, void *p_user_data ); ...@@ -47,6 +47,8 @@ typedef void (*media_library_list_cb)( Eina_List*, void *p_user_data );
*/ */
typedef bool (*media_library_item_updated_cb)( void *p_user_data, const library_item* p_item, bool b_new ); typedef bool (*media_library_item_updated_cb)( void *p_user_data, const library_item* p_item, bool b_new );
typedef void (*media_library_scan_progress_cb)( void*, uint8_t );
media_library* media_library*
media_library_create(application* p_app); media_library_create(application* p_app);
...@@ -92,6 +94,9 @@ media_library_register_item_updated(media_library* ml, media_library_item_update ...@@ -92,6 +94,9 @@ media_library_register_item_updated(media_library* ml, media_library_item_update
void void
media_library_unregister_item_updated(media_library* ml, media_library_item_updated_cb cb, void* p_data ); media_library_unregister_item_updated(media_library* ml, media_library_item_updated_cb cb, void* p_data );
void
media_library_register_progress_cb( media_library* ml, media_library_scan_progress_cb pf_progress, void* p_data );
void void
media_library_reload(media_library* ml); media_library_reload(media_library* ml);
......
...@@ -85,6 +85,8 @@ public: ...@@ -85,6 +85,8 @@ public:
void registerOnItemUpdated(media_library_item_updated_cb cb, void* userData); void registerOnItemUpdated(media_library_item_updated_cb cb, void* userData);
void unregisterOnItemUpdated(media_library_item_updated_cb cb, void* userData); void unregisterOnItemUpdated(media_library_item_updated_cb cb, void* userData);
void registerProgressCb( media_library_scan_progress_cb pf_progress, void* p_data );
public: public:
// Logger needs to be before ml, since ml will take a raw pointer to the logger. // Logger needs to be before ml, since ml will take a raw pointer to the logger.
// yes, it sucks, but unique_ptr is too restrictive, and shared_ptr is overkill. // yes, it sucks, but unique_ptr is too restrictive, and shared_ptr is overkill.
...@@ -107,7 +109,22 @@ private: ...@@ -107,7 +109,22 @@ private:
bool added; bool added;
}; };
struct ProgressUpdateCallbackCtx
{
ProgressUpdateCallbackCtx(media_library* ml, uint8_t percent)
: ml( ml )
, wml( ml->ml )
, percent( percent )
{
}
media_library* ml;
std::weak_ptr<IMediaLibrary> wml;
uint8_t percent;
};
private: private:
std::vector<std::pair<media_library_file_list_changed_cb, void*>> m_onChangeCb; std::vector<std::pair<media_library_file_list_changed_cb, void*>> m_onChangeCb;
std::vector<std::pair<media_library_item_updated_cb, void*>> m_onItemUpdatedCb; std::vector<std::pair<media_library_item_updated_cb, void*>> m_onItemUpdatedCb;
media_library_scan_progress_cb m_progressCb;
void* m_progressData;
}; };
...@@ -415,31 +415,27 @@ intf_start_audio_player(interface *intf, Eina_Array *array, int pos) ...@@ -415,31 +415,27 @@ intf_start_audio_player(interface *intf, Eina_Array *array, int pos)
audio_player_start(intf->p_mini_player, array, pos); audio_player_start(intf->p_mini_player, array, pos);
} }
void static void
intf_scan_progress_start_cb(interface *intf) intf_scan_progress_set_cb(void *p_data, uint8_t percentage)
{ {
interface* intf = (interface*)p_data;
if ( percentage < 100 )
{
if (evas_object_visible_get(intf->scan_progress) == EINA_FALSE) if (evas_object_visible_get(intf->scan_progress) == EINA_FALSE)
{ {
elm_box_pack_after(intf->main_box, intf->scan_progress, intf->nf_content); elm_box_pack_after(intf->main_box, intf->scan_progress, intf->nf_content);
evas_object_show(intf->scan_progress); evas_object_show(intf->scan_progress);
} }
elm_progressbar_value_set(intf->scan_progress, 0); elm_progressbar_value_set(intf->scan_progress, (double)percentage / 100);
} }
else
void {
intf_scan_progress_done_cb(interface *intf)
{
if (evas_object_visible_get(intf->scan_progress) == EINA_TRUE) if (evas_object_visible_get(intf->scan_progress) == EINA_TRUE)
{ {
evas_object_hide(intf->scan_progress); evas_object_hide(intf->scan_progress);
elm_box_unpack(intf->main_box, intf->scan_progress); elm_box_unpack(intf->main_box, intf->scan_progress);
} }
} }
void
intf_scan_progress_set_cb(interface *intf, uint8_t percentage)
{
elm_progressbar_value_set(intf->scan_progress, (double)percentage / 100);
} }
static Evas_Object* static Evas_Object*
...@@ -605,6 +601,9 @@ intf_create(application *app) ...@@ -605,6 +601,9 @@ intf_create(application *app)
ps_register_on_emotion_restart_cb(application_get_playback_service(intf->p_app), intf_on_emotion_restart_cb, intf); ps_register_on_emotion_restart_cb(application_get_playback_service(intf->p_app), intf_on_emotion_restart_cb, intf);
media_library* p_ml = (media_library*)application_get_media_library(intf->p_app);
media_library_register_progress_cb( p_ml, &intf_scan_progress_set_cb, intf );
/* */ /* */
evas_object_show(intf->win); evas_object_show(intf->win);
return intf; return intf;
......
...@@ -123,15 +123,6 @@ intf_ml_file_changed( void* p_user_data ); ...@@ -123,15 +123,6 @@ intf_ml_file_changed( void* p_user_data );
void void
intf_propagate_event(interface *intf, interface_view_event event); intf_propagate_event(interface *intf, interface_view_event event);
void
intf_scan_progress_start_cb(interface *intf);
void
intf_scan_progress_done_cb(interface *intf);
void
intf_scan_progress_set_cb(interface *intf, uint8_t percentage);
/* List view items */ /* List view items */
typedef struct list_sys list_sys; typedef struct list_sys list_sys;
typedef struct list_view list_view; typedef struct list_view list_view;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment