[vlc-commits] [Git][videolan/vlc][master] 4 commits: medialibrary: Add the 'vlc_ml_playlist_rename' function

Steve Lhomme (@robUx4) gitlab at videolan.org
Sun May 21 06:19:58 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
6ffca1a9 by Benjamin Arnaud at 2023-05-21T06:06:06+00:00
medialibrary: Add the 'vlc_ml_playlist_rename' function

- - - - -
ce75e001 by Benjamin Arnaud at 2023-05-21T06:06:06+00:00
qt/mlplaylist: Add the 'setName' function

- - - - -
e82611d0 by Benjamin Arnaud at 2023-05-21T06:06:06+00:00
qt/mlplaylistlistmodel: Add the 'showDialogRename' function

- - - - -
cc5bed90 by Benjamin Arnaud at 2023-05-21T06:06:06+00:00
qt/qml_menu_wrapper/playlist: Add the 'rename' action

- - - - -


7 changed files:

- include/vlc_media_library.h
- modules/gui/qt/medialibrary/mlplaylist.cpp
- modules/gui/qt/medialibrary/mlplaylist.hpp
- modules/gui/qt/medialibrary/mlplaylistlistmodel.cpp
- modules/gui/qt/medialibrary/mlplaylistlistmodel.hpp
- modules/gui/qt/menus/qml_menu_wrapper.cpp
- modules/misc/medialibrary/medialibrary.cpp


Changes:

=====================================
include/vlc_media_library.h
=====================================
@@ -600,7 +600,8 @@ enum vlc_ml_control
     VLC_ML_PLAYLIST_APPEND, /**< arg1: playlist id; arg2: media id; can fail */
     VLC_ML_PLAYLIST_INSERT, /**< arg1: playlist id; arg2: media id; arg3: position; can fail */
     VLC_ML_PLAYLIST_MOVE,   /**< arg1: playlist id; arg2: from; arg3: to; can fail */
-    VLC_ML_PLAYLIST_REMOVE  /**< arg1: playlist id; arg2: position; can fail */
+    VLC_ML_PLAYLIST_REMOVE, /**< arg1: playlist id; arg2: position; can fail */
+    VLC_ML_PLAYLIST_RENAME  /**< arg1: playlist id; arg2: const char*; can fail */
 };
 
 /**
@@ -1200,6 +1201,14 @@ vlc_ml_playlist_remove( vlc_medialibrary_t * p_ml, int64_t i_playlist_id, uint32
     return vlc_ml_control( p_ml, VLC_ML_PLAYLIST_REMOVE, i_playlist_id, i_position );
 }
 
+static inline int
+vlc_ml_playlist_rename( vlc_medialibrary_t * p_ml, int64_t i_playlist_id, const char* name )
+{
+    assert( p_ml != NULL );
+
+    return vlc_ml_control( p_ml, VLC_ML_PLAYLIST_RENAME, i_playlist_id, name );
+}
+
 static inline vlc_ml_media_t* vlc_ml_get_media( vlc_medialibrary_t* p_ml, int64_t i_media_id )
 {
     return (vlc_ml_media_t*)vlc_ml_get( p_ml, VLC_ML_GET_MEDIA, i_media_id );


=====================================
modules/gui/qt/medialibrary/mlplaylist.cpp
=====================================
@@ -44,6 +44,11 @@ QString MLPlaylist::getName() const
     return m_name;
 }
 
+void MLPlaylist::setName(const QString & name)
+{
+    m_name = name;
+}
+
 //-------------------------------------------------------------------------------------------------
 
 VLCTick MLPlaylist::getDuration() const


=====================================
modules/gui/qt/medialibrary/mlplaylist.hpp
=====================================
@@ -35,6 +35,7 @@ public:
 
 public: // Interface
     QString getName() const;
+    void setName(const QString & name);
 
     VLCTick getDuration() const;
 


=====================================
modules/gui/qt/medialibrary/mlplaylistlistmodel.cpp
=====================================
@@ -25,8 +25,8 @@
 // VLC includes
 #include <vlc_media_library.h>
 #include "qt.hpp"
-
 #include "util/vlctick.hpp"
+#include "dialogs/dialogs_provider.hpp"
 
 // MediaLibrary includes
 #include "mlhelper.hpp"
@@ -161,8 +161,6 @@ void appendMediaIntoPlaylist(vlc_medialibrary_t* ml, int64_t playlistId, const s
     return result;
 }
 
-//-------------------------------------------------------------------------------------------------
-
 /* Q_INVOKABLE */ bool MLPlaylistListModel::deletePlaylists(const QVariantList & ids)
 {
     assert(m_mediaLib);
@@ -203,6 +201,47 @@ void appendMediaIntoPlaylist(vlc_medialibrary_t* ml, int64_t playlistId, const s
 
 //-------------------------------------------------------------------------------------------------
 
+/* Q_INVOKABLE */ bool MLPlaylistListModel::showDialogRename(const QModelIndex & index)
+{
+    int row = index.row();
+
+    if (row < 0 || row >= rowCount())
+        return false;
+
+    MLPlaylist * playlist = static_cast<MLPlaylist *> (item(row));
+
+    QString name = playlist->getName();
+
+    static DialogsProvider * provider = DialogsProvider::getInstance();
+
+    bool ok = false;
+
+    QString result = provider->getTextDialog(NULL, qtr("Rename playlist"),
+                                             qtr("Please enter the new playlist name:"),
+                                             name, &ok).toString();
+
+    if (ok == false || result.isEmpty() || result == name)
+        return false;
+
+    int64_t id = playlist->getId().id;
+
+    m_mediaLib->runOnMLThread(this,
+    // ML thread
+    [id, result](vlc_medialibrary_t * ml)
+    {
+        vlc_ml_playlist_rename(ml, id, qtu(result));
+    });
+
+    // NOTE: We want the change to be visible right away.
+    playlist->setName(result);
+
+    emit dataChanged(index, index, { PLAYLIST_NAME });
+
+    return true;
+}
+
+//-------------------------------------------------------------------------------------------------
+
 /* Q_INVOKABLE */ MLItemId MLPlaylistListModel::getItemId(int index) const
 {
     if (index < 0 || index >= rowCount())


=====================================
modules/gui/qt/medialibrary/mlplaylistlistmodel.hpp
=====================================
@@ -68,6 +68,8 @@ public: // Interface
 
     Q_INVOKABLE bool deletePlaylists(const QVariantList & ids);
 
+    Q_INVOKABLE bool showDialogRename(const QModelIndex & index);
+
     MLItemId getItemId(int index) const;
 
 public: // QAbstractItemModel implementation


=====================================
modules/gui/qt/menus/qml_menu_wrapper.cpp
=====================================
@@ -658,6 +658,17 @@ void PlaylistListContextMenu::popup(const QModelIndexList & selected, QPoint pos
         ml->addToPlaylist(ids);
     });
 
+    if (ids.count() == 1)
+    {
+        action = m_menu->addAction(qtr("Rename"));
+
+        QModelIndex index = selected.first();
+
+        connect(action, &QAction::triggered, [this, index]() {
+            m_model->showDialogRename(index);
+        });
+    }
+
     action = m_menu->addAction(qtr("Delete"));
 
     connect(action, &QAction::triggered, [this, ids]() {


=====================================
modules/misc/medialibrary/medialibrary.cpp
=====================================
@@ -722,6 +722,18 @@ int MediaLibrary::Control( int query, va_list args )
                 return VLC_EGENERIC;
             return VLC_SUCCESS;
         }
+        case VLC_ML_PLAYLIST_RENAME:
+        {
+            auto priorityAccess = m_ml->acquirePriorityAccess();
+
+            auto playlist = m_ml->playlist( va_arg( args, int64_t ) );
+            if ( playlist == nullptr )
+                return VLC_EGENERIC;
+            const char * name = va_arg( args, const char * );
+            if ( playlist->setName(name) == false )
+                return VLC_EGENERIC;
+            return VLC_SUCCESS;
+        }
         default:
             return VLC_EGENERIC;
     }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/62587d48feb8fbbeb9e8a374242c2c40e2b751f7...cc5bed909645705b835d28181145a059bf9f2f6f

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/62587d48feb8fbbeb9e8a374242c2c40e2b751f7...cc5bed909645705b835d28181145a059bf9f2f6f
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list