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 @@
media_library::media_library()
: ml( NewMediaLibrary() )
, m_progressCb( nullptr )
, m_progressData( nullptr )
{
if ( ml == nullptr )
throw std::runtime_error( "Failed to initialize MediaLibrary" );
......@@ -110,7 +113,14 @@ media_library::onReloadCompleted( const std::string& entryPoint )
void
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
......@@ -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_create(application *p_app)
{
......@@ -351,6 +367,12 @@ media_library_unregister_item_updated(media_library* ml, media_library_item_upda
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
media_library_reload(media_library* ml)
{
......
......@@ -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 void (*media_library_scan_progress_cb)( void*, uint8_t );
media_library*
media_library_create(application* p_app);
......@@ -92,6 +94,9 @@ media_library_register_item_updated(media_library* ml, media_library_item_update
void
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
media_library_reload(media_library* ml);
......
......@@ -85,6 +85,8 @@ public:
void registerOnItemUpdated(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:
// 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.
......@@ -107,7 +109,22 @@ private:
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:
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;
media_library_scan_progress_cb m_progressCb;
void* m_progressData;
};
......@@ -415,33 +415,29 @@ intf_start_audio_player(interface *intf, Eina_Array *array, int pos)
audio_player_start(intf->p_mini_player, array, pos);
}
void
intf_scan_progress_start_cb(interface *intf)
static void
intf_scan_progress_set_cb(void *p_data, uint8_t percentage)
{
if (evas_object_visible_get(intf->scan_progress) == EINA_FALSE)
interface* intf = (interface*)p_data;
if ( percentage < 100 )
{
elm_box_pack_after(intf->main_box, intf->scan_progress, intf->nf_content);
evas_object_show(intf->scan_progress);
if (evas_object_visible_get(intf->scan_progress) == EINA_FALSE)
{
elm_box_pack_after(intf->main_box, intf->scan_progress, intf->nf_content);
evas_object_show(intf->scan_progress);
}
elm_progressbar_value_set(intf->scan_progress, (double)percentage / 100);
}
elm_progressbar_value_set(intf->scan_progress, 0);
}
void
intf_scan_progress_done_cb(interface *intf)
{
if (evas_object_visible_get(intf->scan_progress) == EINA_TRUE)
else
{
evas_object_hide(intf->scan_progress);
elm_box_unpack(intf->main_box, intf->scan_progress);
if (evas_object_visible_get(intf->scan_progress) == EINA_TRUE)
{
evas_object_hide(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*
create_main_box(interface *intf, Evas_Object *parent)
{
......@@ -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);
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);
return intf;
......
......@@ -123,15 +123,6 @@ intf_ml_file_changed( void* p_user_data );
void
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 */
typedef struct list_sys list_sys;
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