Commit 3a253b50 authored by Prince Gupta's avatar Prince Gupta Committed by Jean-Baptiste Kempf
Browse files

qt/mlfoldersmodel: notify operation failure

parent 335ca010
......@@ -119,7 +119,8 @@ void MLFoldersBaseModel::onMlEvent( void* data , const vlc_ml_event_t* event )
if ( event->i_type == VLC_ML_EVENT_ENTRY_POINT_ADDED || event->i_type == VLC_ML_EVENT_ENTRY_POINT_REMOVED ||
event->i_type == VLC_ML_EVENT_ENTRY_POINT_UNBANNED || event->i_type == VLC_ML_EVENT_ENTRY_POINT_BANNED )
{
emit self->onMLEntryPointModified( QPrivateSignal() );
if (!self->failed( event ))
emit self->onMLEntryPointModified( QPrivateSignal() );
}
}
......@@ -138,6 +139,22 @@ std::vector<MLFoldersBaseModel::EntryPoint> MLFoldersModel::entryPoints() const
return r;
}
bool MLFoldersModel::failed(const vlc_ml_event_t *event) const
{
if ( event->i_type == VLC_ML_EVENT_ENTRY_POINT_ADDED && !event->entry_point_added.b_success )
{
emit operationFailed( Add, QUrl::fromEncoded( event->entry_point_added.psz_entry_point ) );
return true;
}
else if ( event->i_type == VLC_ML_EVENT_ENTRY_POINT_REMOVED && !event->entry_point_removed.b_success )
{
emit operationFailed( Remove, QUrl::fromEncoded( event->entry_point_removed.psz_entry_point ) );
return true;
}
return false;
}
void MLFoldersModel::remove( const QUrl &mrl )
{
vlc_ml_remove_folder( ml() , qtu( mrl.toString( QUrl::FullyEncoded ) ) );
......@@ -172,3 +189,19 @@ std::vector<MLFoldersBaseModel::EntryPoint> MLBannedFoldersModel::entryPoints()
return r;
}
bool MLBannedFoldersModel::failed(const vlc_ml_event_t *event) const
{
if ( event->i_type == VLC_ML_EVENT_ENTRY_POINT_BANNED && !event->entry_point_banned.b_success )
{
emit operationFailed( Ban, QUrl::fromEncoded( event->entry_point_banned.psz_entry_point ) );
return true;
}
else if ( event->i_type == VLC_ML_EVENT_ENTRY_POINT_UNBANNED && !event->entry_point_unbanned.b_success )
{
emit operationFailed( Unban, QUrl::fromEncoded( event->entry_point_unbanned.psz_entry_point ) );
return true;
}
return false;
}
......@@ -47,6 +47,14 @@ public:
MRL
};
enum Operation
{
Add,
Remove,
Ban,
Unban
};
MLFoldersBaseModel( QObject *parent = nullptr );
void setCtx(QmlMainContext* ctx);
......@@ -65,6 +73,7 @@ public slots:
signals:
void ctxChanged();
void operationFailed( int op, QUrl url ) const;
void onMLEntryPointModified(QPrivateSignal);
protected:
......@@ -76,6 +85,7 @@ protected:
};
virtual std::vector<EntryPoint> entryPoints() const = 0;
virtual bool failed( const vlc_ml_event_t* event ) const = 0; // will be called outside the main thread
private:
static void onMlEvent( void* data , const vlc_ml_event_t* event );
......@@ -99,6 +109,7 @@ public:
private:
std::vector<EntryPoint> entryPoints() const final;
bool failed( const vlc_ml_event_t* event ) const override;
};
class MLBannedFoldersModel : public MLFoldersBaseModel
......@@ -111,6 +122,7 @@ public:
private:
std::vector<EntryPoint> entryPoints() const final;
bool failed( const vlc_ml_event_t* event ) const override;
};
#endif // ML_FOLDERS_MODEL_HPP
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