vlc | branch: master | Abel Tesfaye <[email protected]> | Thu Jul 25 13:30:07 2019 +0300| [c0891a6f1ce5cc1e3f1bdec6b28038e9063863b8] | committer: Jean-Baptiste Kempf
qt: make ml_folders_model Signed-off-by: Jean-Baptiste Kempf <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c0891a6f1ce5cc1e3f1bdec6b28038e9063863b8 --- modules/gui/qt/Makefile.am | 3 + .../qt/components/mediacenter/ml_folders_model.cpp | 147 +++++++++++++++++++++ .../qt/components/mediacenter/ml_folders_model.hpp | 80 +++++++++++ 3 files changed, 230 insertions(+) diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am index bdf5dcd5cf..2932cf2426 100644 --- a/modules/gui/qt/Makefile.am +++ b/modules/gui/qt/Makefile.am @@ -112,6 +112,8 @@ libqt_plugin_la_SOURCES = \ gui/qt/components/settings.hpp \ gui/qt/components/audio_device_model.cpp \ gui/qt/components/audio_device_model.hpp \ + gui/qt/components/mediacenter/ml_folders_model.hpp \ + gui/qt/components/mediacenter/ml_folders_model.cpp \ gui/qt/components/voutwindow/videosurface.cpp \ gui/qt/components/voutwindow/videosurface.hpp \ gui/qt/components/voutwindow/qvoutwindow.cpp \ @@ -269,6 +271,7 @@ nodist_libqt_plugin_la_SOURCES = \ gui/qt/components/selectable_list_model.moc.cpp \ gui/qt/components/settings.moc.cpp \ gui/qt/components/audio_device_model.moc.cpp \ + gui/qt/components/mediacenter/ml_folders_model.moc.cpp \ gui/qt/components/voutwindow/videosurface.moc.cpp \ gui/qt/components/voutwindow/qvoutwindow.moc.cpp \ gui/qt/components/voutwindow/qvoutwindowdummy.moc.cpp \ diff --git a/modules/gui/qt/components/mediacenter/ml_folders_model.cpp b/modules/gui/qt/components/mediacenter/ml_folders_model.cpp new file mode 100644 index 0000000000..e7469830e7 --- /dev/null +++ b/modules/gui/qt/components/mediacenter/ml_folders_model.cpp @@ -0,0 +1,147 @@ +/***************************************************************************** + * Copyright (C) 2019 VLC authors and VideoLAN + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * ( at your option ) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#include "ml_folders_model.hpp" +#include <cassert> + +MlFoldersModel::MlFoldersModel( vlc_medialibrary_t *p_ml , QObject *parent ) + : QAbstractListModel( parent ) + ,m_ml( p_ml ) + ,m_ml_event_handle( nullptr , [this](vlc_ml_event_callback_t* cb ) { + assert( m_ml != nullptr ); + vlc_ml_event_unregister_callback( m_ml , cb ); +}) +{ + assert( p_ml ); + connect( this , &MlFoldersModel::onMLEntryPointModified , this , &MlFoldersModel::update ); + m_ml_event_handle.reset( vlc_ml_event_register_callback( m_ml , onMlEvent , this ) ); + update(); +} + +int MlFoldersModel::rowCount( QModelIndex const & ) const +{ + return m_mrls.count(); +} +int MlFoldersModel::columnCount( QModelIndex const & ) const +{ + return 3; +} + +QVariant MlFoldersModel::data( const QModelIndex &index , + int role) const { + if ( index.isValid() ) + { + switch ( role ) + { + case Qt::DisplayRole : + if ( index.column() == 1 ) + return QVariant::fromValue( m_mrls[index.row()].toDisplayString( QUrl::RemovePassword | QUrl::PreferLocalFile | QUrl::NormalizePathSegments ) ); + break; + case CustomCheckBoxRole : + return ( index.row() %2 ) ? //TODO: if mrl banned? + Qt::Checked : Qt::Unchecked; + break; + default : + return {}; + } + } + return {}; +} + +void MlFoldersModel::removeAt( int index ) +{ + vlc_ml_remove_folder( m_ml , qtu( m_mrls[index].toString() ) ); +} + +void MlFoldersModel::add( QUrl mrl ) +{ + vlc_ml_add_folder( m_ml , qtu( mrl.toString( QUrl::None ) ) ); +} + +void MlFoldersModel::update() +{ + beginResetModel(); + + m_mrls.clear(); + + vlc_ml_entry_point_list_t * entrypoints; + vlc_ml_list_folder( m_ml , &entrypoints ); //TODO: get list of banned folders as well + + for ( unsigned int i=0 ; i<entrypoints->i_nb_items ; i++ ) + m_mrls.append( QUrl::fromUserInput( entrypoints->p_items[i].psz_mrl ) ); + + endResetModel(); + +} + +Qt::ItemFlags MlFoldersModel::flags ( const QModelIndex & index ) const { + Qt::ItemFlags defaultFlags = QAbstractListModel::flags( index ); + if ( index.isValid() ){ + return defaultFlags; + } + return defaultFlags; +} + +bool MlFoldersModel::setData( const QModelIndex &index , + const QVariant &value , int role){ + if( !index.isValid() ) + return false; + + else if( role == CustomCheckBoxRole ){ + if( !value.toBool() ){ + vlc_ml_unban_folder(m_ml, qtu( m_mrls[index.row()].toString() ) ); + } + else{ + vlc_ml_ban_folder( m_ml , qtu( m_mrls[index.row()].toString() ) ); + } + } + else if(role == CustomRemoveRole){ + removeAt( index.row() ); + } + + return true; +} +void MlFoldersModel::onMlEvent( void* data , const vlc_ml_event_t* event ) +{ + auto self = static_cast<MlFoldersModel*>( data ); + 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(); + } +} + + QVariant MlFoldersModel::headerData( int section , Qt::Orientation orientation , int /*role*/) const + { + if ( orientation == Qt::Horizontal ) { + switch ( section ) { + case 0: + return qtr("Banned"); + + case 1: + return qtr("Path"); + + case 2: + return qtr("Remove"); + + default: + return qtr("Unknown"); + } + } + return QVariant(); + } diff --git a/modules/gui/qt/components/mediacenter/ml_folders_model.hpp b/modules/gui/qt/components/mediacenter/ml_folders_model.hpp new file mode 100644 index 0000000000..2ef0f568bb --- /dev/null +++ b/modules/gui/qt/components/mediacenter/ml_folders_model.hpp @@ -0,0 +1,80 @@ +/***************************************************************************** + * Copyright (C) 2019 VLC authors and VideoLAN + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * ( at your option ) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifndef ML_FOLDERS_MODEL_HPP +#define ML_FOLDERS_MODEL_HPP + +#ifdef HAVE_CONFIG_H + +# include "config.h" + +#endif + +#include "qt.hpp" +#include <QAbstractListModel> +#include <QUrl> +#include <QList> +#include "components/mediacenter/mlhelper.hpp" + +#include <vlc_media_library.h> + +class MlFoldersModel : public QAbstractListModel +{ + Q_OBJECT +public: + MlFoldersModel( vlc_medialibrary_t *p_ml , QObject * parent = nullptr ); + + int rowCount( QModelIndex const &parent = {} ) const override; + int columnCount (QModelIndex const &parent = {} ) const override; + + QVariant data( QModelIndex const &index , const int role = Qt::DisplayRole ) const override; + + Qt::ItemFlags flags ( const QModelIndex & index ) const ; + + bool setData( const QModelIndex &index , const QVariant &value , + int role ); + + static void onMlEvent( void* data , const vlc_ml_event_t* event ); + QVariant headerData( int section , Qt::Orientation orientation , int role ) const override; + + enum Roles + { + CustomCheckBoxRole = Qt::UserRole + 1, + CustomRemoveRole + }; +private: + QList<QUrl> m_mrls; + vlc_medialibrary_t *m_ml; + + using EventCallbackPtr = std::unique_ptr<vlc_ml_event_callback_t, + std::function<void( vlc_ml_event_callback_t* )>> ; + + EventCallbackPtr m_ml_event_handle; +signals: + void limitChanged(); + void onMLEntryPointModified(); + +public slots: + void update(); + void removeAt( int index ); + void add( QUrl mrl ); + + +}; + +#endif // ML_FOLDERS_MODEL_HPP _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
