[vlc-commits] [Git][videolan/vlc][master] 5 commits: qt/custom_menus: Create BookmarkMenu
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Fri Mar 18 20:11:59 UTC 2022
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
b19c5f04 by Benjamin Arnaud at 2022-03-18T19:47:57+00:00
qt/custom_menus: Create BookmarkMenu
- - - - -
628595ec by Benjamin Arnaud at 2022-03-18T19:47:57+00:00
qt/menus: Add the 'BookmarkMenu' in the navigation menu
- - - - -
3da08ba5 by Benjamin Arnaud at 2022-03-18T19:47:57+00:00
qt/mlbookmarkmodel: Fix the 'setData' default role value
- - - - -
3ceb6e96 by Benjamin Arnaud at 2022-03-18T19:47:57+00:00
qt/mlbookmarkmodel: Add a default title in the 'add' function
This feature was missing on VLC4, the behavior on this patch is similar to VLC3.
- - - - -
e61b6074 by Benjamin Arnaud at 2022-03-18T19:47:57+00:00
vlc_intf_strings: Rename 'Custom Bookmarks' to 'Bookmarks'
- - - - -
6 changed files:
- include/vlc_intf_strings.h
- modules/gui/qt/medialibrary/mlbookmarkmodel.cpp
- modules/gui/qt/medialibrary/mlbookmarkmodel.hpp
- modules/gui/qt/menus/custom_menus.cpp
- modules/gui/qt/menus/custom_menus.hpp
- modules/gui/qt/menus/menus.cpp
Changes:
=====================================
include/vlc_intf_strings.h
=====================================
@@ -55,7 +55,7 @@
#define I_MENU_CODECINFO N_("&Codec Information")
#define I_MENU_MSG N_("&Messages")
#define I_MENU_GOTOTIME N_("Jump to Specific &Time")
-#define I_MENU_BOOKMARK N_("Custom &Bookmarks")
+#define I_MENU_BOOKMARK N_("&Bookmarks")
#define I_MENU_VLM N_("&VLM Configuration")
#define I_MENU_ABOUT N_("&About")
=====================================
modules/gui/qt/medialibrary/mlbookmarkmodel.cpp
=====================================
@@ -275,8 +275,20 @@ void MLBookmarkModel::add()
m_mediaLib->runOnMLThread(this,
//ML thread
- [mediaId = m_currentMediaId, currentTime](vlc_medialibrary_t* ml){
- vlc_ml_media_add_bookmark( ml, mediaId, MS_FROM_VLC_TICK( currentTime ) );
+ [mediaId = m_currentMediaId, currentTime, count = rowCount()](vlc_medialibrary_t* ml)
+ {
+ int64_t time = MS_FROM_VLC_TICK(currentTime);
+
+ vlc_ml_media_add_bookmark(ml, mediaId, time);
+
+ ml_unique_ptr<vlc_ml_media_t> media { vlc_ml_get_media(ml, mediaId) };
+
+ if (media)
+ {
+ QString name = QString("%1 #%2").arg(media->psz_title).arg(count);
+
+ vlc_ml_media_update_bookmark(ml, mediaId, time, qtu(name), nullptr);
+ }
},
//UI thread
[this](){
=====================================
modules/gui/qt/medialibrary/mlbookmarkmodel.hpp
=====================================
@@ -39,7 +39,7 @@ public:
virtual ~MLBookmarkModel();
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole ) const override;
- bool setData( const QModelIndex& index, const QVariant& value, int role ) override;
+ bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole ) override;
Qt::ItemFlags flags( const QModelIndex & ) const override;
int rowCount( const QModelIndex& index = {} ) const override;
int columnCount( const QModelIndex& index = {} ) const override;
=====================================
modules/gui/qt/menus/custom_menus.cpp
=====================================
@@ -28,6 +28,13 @@
#include "custom_menus.hpp"
#include "util/renderer_manager.hpp"
+// MediaLibrary includes
+#include "medialibrary/mlbookmarkmodel.hpp"
+
+// Dialogs includes
+#include "dialogs/dialogs_provider.hpp"
+
+// Qt includes
#include <QMenu>
#include <QAction>
#include <QActionGroup>
@@ -409,3 +416,98 @@ void RecentMenu::onModelReset()
else
onRowInserted({}, 0, nb_rows - 1);
}
+
+// BookmarkMenu
+
+BookmarkMenu::BookmarkMenu(MLBookmarkModel * model, MediaLib * ml, QWidget * parent)
+ : QMenu(parent), m_model(model), m_ml(ml)
+{
+ setTearOffEnabled(true);
+
+ // FIXME: Do we really need a translation call for the string shortcut ?
+ addAction(qtr("&Manage"), THEDP, &DialogsProvider::bookmarksDialog, qtr("Ctrl+B"));
+
+ addSeparator();
+
+ onModelReset();
+
+ connect(m_model, &MLBookmarkModel::rowsInserted, this, &BookmarkMenu::onRowsInserted);
+ connect(m_model, &MLBookmarkModel::rowsRemoved, this, &BookmarkMenu::onRowsRemoved);
+
+ connect(m_model, &MLBookmarkModel::dataChanged, this, &BookmarkMenu::onDataChanged);
+
+ connect(m_model, &MLBookmarkModel::modelReset, this, &BookmarkMenu::onModelReset);
+}
+
+// Private slots
+
+void BookmarkMenu::onRowsInserted(const QModelIndex &, int first, int last)
+{
+ QAction * before;
+
+ if (first < m_actions.count())
+ before = m_actions.at(first);
+ else
+ before = nullptr;
+
+ for (int i = first; i <= last; i++)
+ {
+ QModelIndex index = m_model->index(i, 0);
+
+ QString name = m_model->data(index, Qt::DisplayRole).toString();
+
+ QAction * action = new QAction(name, this);
+
+ // NOTE: We are adding sequentially *before* the next action in the list.
+ insertAction(before, action);
+
+ m_actions.insert(i, action);
+
+ connect(action, &QAction::triggered, [this, action]()
+ {
+ QModelIndex index = m_model->index(m_actions.indexOf(action), 0);
+
+ m_model->select(index);
+ });
+ }
+}
+
+void BookmarkMenu::onRowsRemoved(const QModelIndex &, int first, int last)
+{
+ for (int i = first; i <= last; i++)
+ {
+ delete m_actions.at(i);
+ }
+
+ QList<QAction *>::iterator begin = m_actions.begin();
+
+ m_actions.erase(begin + first, begin + last);
+}
+
+void BookmarkMenu::onDataChanged(const QModelIndex & topLeft,
+ const QModelIndex & bottomRight, const QVector<int> &)
+{
+ for (int i = topLeft.row(); i <= bottomRight.row(); i++)
+ {
+ QModelIndex index = m_model->index(i, 0);
+
+ QString name = m_model->data(index, Qt::DisplayRole).toString();
+
+ m_actions.at(i)->setText(name);
+ }
+}
+
+void BookmarkMenu::onModelReset()
+{
+ for (QAction * action : m_actions)
+ {
+ delete action;
+ }
+
+ m_actions.clear();
+
+ int count = m_model->rowCount();
+
+ if (count)
+ onRowsInserted(QModelIndex(), 0, count - 1);
+}
=====================================
modules/gui/qt/menus/custom_menus.hpp
=====================================
@@ -27,6 +27,7 @@
#include "medialibrary/mlrecentsmodel.hpp"
class QAbstractListModel;
+class MLBookmarkModel;
class RendererAction : public QAction
{
@@ -145,5 +146,28 @@ private:
QList<QAction *> m_actions;
};
+class BookmarkMenu : public QMenu
+{
+ Q_OBJECT
+
+public:
+ BookmarkMenu(MLBookmarkModel * model, MediaLib * ml, QWidget * parent = nullptr);
+
+private slots:
+ void onRowsInserted(const QModelIndex & parent, int first, int last);
+ void onRowsRemoved (const QModelIndex & parent, int first, int last);
+
+ void onDataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight,
+ const QVector<int> & roles = QVector<int>());
+
+ void onModelReset();
+
+private:
+ MLBookmarkModel * m_model = nullptr;
+
+ MediaLib * m_ml = nullptr;
+
+ QList<QAction *> m_actions;
+};
#endif // CUSTOM_MENUS_HPP
=====================================
modules/gui/qt/menus/menus.cpp
=====================================
@@ -46,6 +46,7 @@
#include "util/varchoicemodel.hpp"
#include "medialibrary/medialib.hpp"
#include "medialibrary/mlrecentsmodel.hpp"
+#include "medialibrary/mlbookmarkmodel.hpp"
#include <QMenu>
@@ -480,15 +481,23 @@ void VLCMenuBar::NavigMenu( qt_intf_t *p_intf, QMenu *menu )
menu->addMenu( submenu );
menu->addMenu( new CheckableListMenu( qtr("&Program") , THEMIM->getPrograms(), CheckableListMenu::GROUPED , menu) );
- if (p_intf->p_mi && p_intf->p_mi->hasMediaLibrary() )
+ MainCtx * mi = p_intf->p_mi;
+
+ if (mi && p_intf->p_mi->hasMediaLibrary() )
{
- submenu = new QMenu( qfut( I_MENU_BOOKMARK ), menu );
- submenu->setTearOffEnabled( true );
- addDPStaticEntry( submenu, qtr( "&Manage" ), "",
- &DialogsProvider::bookmarksDialog, "Ctrl+B" );
- submenu->addSeparator();
- action = menu->addMenu( submenu );
- action->setData( "bookmark" );
+ MediaLib * mediaLib = mi->getMediaLibrary();
+
+ MLBookmarkModel * model = new MLBookmarkModel(mediaLib, p_intf->p_player, nullptr);
+
+ BookmarkMenu * bookmarks = new BookmarkMenu(model, mediaLib, menu);
+
+ model->setParent(bookmarks);
+
+ bookmarks->setTitle(qfut(I_MENU_BOOKMARK));
+
+ action = menu->addMenu(bookmarks);
+
+ action->setData("bookmark");
}
menu->addSeparator();
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e33c274d9471ae4e5eebcff6023626fcd83b7980...e61b6074acdea3c719925114f6d27314b6b7b53a
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e33c274d9471ae4e5eebcff6023626fcd83b7980...e61b6074acdea3c719925114f6d27314b6b7b53a
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