[vlc-commits] [Git][videolan/vlc][master] 5 commits: qt: improve PlaylistController insertion implementation
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Mon Aug 29 21:36:50 UTC 2022
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
0db43fcf by Prince Gupta at 2022-08-29T21:22:44+00:00
qt: improve PlaylistController insertion implementation
- - - - -
937717c8 by Prince Gupta at 2022-08-29T21:22:44+00:00
qt: resolve win symlinks when inserting into playlist
- - - - -
eccdf929 by Prince Gupta at 2022-08-29T21:22:44+00:00
qt: implement function to associate subtitle file from qml
- - - - -
4e6123ca by Prince Gupta at 2022-08-29T21:22:44+00:00
qml: handle subtitle and text drops
- - - - -
63ac5078 by Prince Gupta at 2022-08-29T21:22:44+00:00
qt: remove drop filter from interface window handler
global drop events are already handled on qml side
no need to handle it twice
ref #27190
- - - - -
9 changed files:
- modules/gui/qt/maininterface/interface_window_handler.cpp
- modules/gui/qt/maininterface/mainctx.cpp
- modules/gui/qt/maininterface/mainctx.hpp
- modules/gui/qt/maininterface/qml/MainInterface.qml
- modules/gui/qt/player/player_controller.cpp
- modules/gui/qt/player/player_controller.hpp
- modules/gui/qt/playlist/playlist_controller.cpp
- modules/gui/qt/playlist/playlist_controller.hpp
- modules/gui/qt/playlist/qml/PlaylistListView.qml
Changes:
=====================================
modules/gui/qt/maininterface/interface_window_handler.cpp
=====================================
@@ -217,29 +217,6 @@ bool InterfaceWindowHandler::eventFilter(QObject*, QEvent* event)
}
break;
}
- case QEvent::DragEnter:
- {
- auto enterEvent = static_cast<QDragEnterEvent*>(event);
- enterEvent->acceptProposedAction();
- return true;
- }
- case QEvent::DragMove:
- {
- auto moveEvent = static_cast<QDragMoveEvent*>(event);
- moveEvent->acceptProposedAction();
- return true;
- }
- case QEvent::DragLeave:
- {
- event->accept();
- return true;
- }
- case QEvent::Drop:
- {
- auto dropEvent = static_cast<QDropEvent*>(event);
- m_mainCtx->dropEventPlay(dropEvent, true);
- return true;
- }
case QEvent::Close:
{
bool ret = m_mainCtx->onWindowClose(m_window);
=====================================
modules/gui/qt/maininterface/mainctx.cpp
=====================================
@@ -646,80 +646,6 @@ void MainCtx::updateSystrayTooltipStatus( PlayerController::PlayingState )
VLCMenuBar::updateSystrayMenu( this, p_intf );
}
-
-/************************************************************************
- * D&D Events
- ************************************************************************/
-
-/**
- * dropEventPlay
- *
- * Event called if something is dropped onto a VLC window
- * \param event the event in question
- * \param b_play whether to play the file immediately
- * \return nothing
- */
-void MainCtx::dropEventPlay( QDropEvent *event, bool b_play )
-{
- if( event->possibleActions() & ( Qt::CopyAction | Qt::MoveAction | Qt::LinkAction ) )
- event->setDropAction( Qt::CopyAction );
- else
- return;
-
- const QMimeData *mimeData = event->mimeData();
-
- /* D&D of a subtitles file, add it on the fly */
- if( mimeData->urls().count() == 1 && THEMIM->hasInput() )
- {
- if( !THEMIM->AddAssociatedMedia(SPU_ES, mimeData->urls()[0].toString(), true, true, true) )
- {
- event->accept();
- return;
- }
- }
-
- QVector<vlc::playlist::Media> medias;
- for( const QUrl &url: mimeData->urls() )
- {
- if( url.isValid() )
- {
- QString mrl = toURI( url.toEncoded().constData() );
-#ifdef _WIN32
- QFileInfo info( url.toLocalFile() );
- if( info.exists() && info.isSymLink() )
- {
- QString target = info.symLinkTarget();
- QUrl url;
- if( QFile::exists( target ) )
- {
- url = QUrl::fromLocalFile( target );
- }
- else
- {
- url.setUrl( target );
- }
- mrl = toURI( url.toEncoded().constData() );
- }
-#endif
- if( mrl.length() > 0 )
- medias.push_back( vlc::playlist::Media{ mrl, QString {} });
- }
- }
-
- /* Browsers give content as text if you dnd the addressbar,
- so check if mimedata has valid url in text and use it
- if we didn't get any normal Urls()*/
- if( !mimeData->hasUrls() && mimeData->hasText() &&
- QUrl(mimeData->text()).isValid() )
- {
- QString mrl = toURI( mimeData->text() );
- medias.push_back( vlc::playlist::Media{ mrl, QString {} });
- }
- if (!medias.empty())
- THEMPL->append(medias, b_play);
- event->accept();
-}
-
/************************************************************************
* Events stuff
************************************************************************/
=====================================
modules/gui/qt/maininterface/mainctx.hpp
=====================================
@@ -271,7 +271,6 @@ public:
unsigned char patch)
{ return QT_VERSION_CHECK(major, minor, patch); };
- void dropEventPlay( QDropEvent* event, bool b_play );
/**
* @brief ask for the application to terminate
* @return true if the application can be close right away, false if it will be delayed
=====================================
modules/gui/qt/maininterface/qml/MainInterface.qml
=====================================
@@ -131,12 +131,30 @@ Item {
DropArea {
anchors.fill: parent
onDropped: {
+ var urls = []
if (drop.hasUrls) {
- var list = []
- for (var i = 0; i < drop.urls.length; i++){
- list.push(drop.urls[i])
+
+ for (var i = 0; i < drop.urls.length; i++)
+ urls.push(drop.urls[i])
+
+ } else if (drop.hasText) {
+ /* Browsers give content as text if you dnd the addressbar,
+ so check if mimedata has valid url in text and use it
+ if we didn't get any normal Urls()*/
+
+ urls.push(drop.text)
+ }
+
+ if (urls.length > 0) {
+ /* D&D of a subtitles file, add it on the fly */
+ if (Player.isPlaying && urls.length == 1) {
+ if (Player.associateSubtitleFile(urls[0])) {
+ drop.accept()
+ return
+ }
}
- mainPlaylistController.append(list, true)
+
+ mainPlaylistController.append(urls, true)
drop.accept()
}
}
=====================================
modules/gui/qt/player/player_controller.cpp
=====================================
@@ -1890,6 +1890,11 @@ void PlayerController::setArt( input_item_t *p_item, QString fileUrl )
}
}
+bool PlayerController::associateSubtitleFile(const QString &uri)
+{
+ return AddAssociatedMedia(SPU_ES, uri, true, true, true) == VLC_SUCCESS;
+}
+
int PlayerController::AddAssociatedMedia(es_format_category_e cat, const QString &uri, bool select, bool notify, bool check_ext)
{
Q_D(PlayerController);
=====================================
modules/gui/qt/player/player_controller.hpp
=====================================
@@ -374,6 +374,11 @@ public slots:
// High resolution time fed by SMPTE timer
QString highResolutionTime() const;
+
+ // associates subtitle file to currently playing media
+ // returns true on success
+ bool associateSubtitleFile(const QString &uri);
+
signals:
//playback
void playingStateChanged( PlayingState state );
=====================================
modules/gui/qt/playlist/playlist_controller.cpp
=====================================
@@ -52,6 +52,45 @@ static QVector<RAW> toRaw(const QVector<WRAPPER> &items)
return vec;
}
+static QUrl resolveWinSymlinks(const QUrl &mrl)
+{
+#ifdef _WIN32
+ QFileInfo info (mrl.toLocalFile());
+ if ( info.isSymLink() )
+ {
+ QString target = info.symLinkTarget();
+ return QFile::exists(target) ? QUrl::fromLocalFile(target) : mrl;
+ }
+#endif
+ return mrl;
+}
+
+QVector<Media> toMediaList(const QVariantList &sources)
+{
+ QVector<Media> mediaList;
+ std::transform(sources.begin(), sources.end(),
+ std::back_inserter(mediaList), [](const QVariant& value) {
+ if (value.canConvert<QUrl>() || value.canConvert<QString>())
+ {
+ QUrl mrl = value.canConvert<QString>()
+ ? QUrl::fromUserInput(value.value<QString>())
+ : value.value<QUrl>();
+
+ if (mrl.isLocalFile())
+ mrl = resolveWinSymlinks(mrl);
+
+ return Media(mrl.toString(QUrl::None), mrl.fileName());
+ } else if (value.canConvert<QmlInputItem>())
+ {
+ const QmlInputItem & item = value.value<QmlInputItem>();
+ return Media(item.item.get());
+ }
+ return Media{};
+ });
+
+ return mediaList;
+}
+
extern "C" { // for C callbacks
@@ -330,45 +369,14 @@ PlaylistItem PlaylistControllerModel::getCurrentItem() const
void PlaylistControllerModel::append(const QVariantList& sourceList, bool startPlaying)
{
- QVector<Media> mediaList;
- std::transform(sourceList.begin(), sourceList.end(),
- std::back_inserter(mediaList), [](const QVariant& value) {
- if (value.canConvert<QUrl>())
- {
- auto mrl = value.value<QUrl>();
- return Media(mrl.toString(QUrl::None), mrl.fileName());
- }
- else if (value.canConvert<QString>())
- {
- auto mrl = value.value<QString>();
- return Media(mrl, mrl);
- }
- return Media{};
- });
- append(mediaList, startPlaying);
+ append(toMediaList(sourceList), startPlaying);
}
void PlaylistControllerModel::insert(unsigned index, const QVariantList& sourceList, bool startPlaying)
{
- QVector<Media> mediaList;
- std::transform(sourceList.begin(), sourceList.end(),
- std::back_inserter(mediaList), [](const QVariant& value) {
- if (value.canConvert<QUrl>())
- {
- auto mrl = value.value<QUrl>();
- return Media(mrl.toString(QUrl::None), mrl.fileName());
- }
- else if (value.canConvert<QString>())
- {
- auto mrl = value.value<QString>();
- return Media(mrl, mrl);
- }
- return Media{};
- });
- insert(index, mediaList, startPlaying);
+ insert(index, toMediaList(sourceList), startPlaying);
}
-
void
PlaylistControllerModel::append(const QVector<Media> &media, bool startPlaying)
{
@@ -443,24 +451,6 @@ PlaylistControllerModel::remove(const QVector<PlaylistItem> &items, ssize_t inde
throw std::bad_alloc();
}
-void
-PlaylistControllerModel::insert(int index, const QVariantList & items)
-{
- QVector<vlc::playlist::Media> medias;
-
- for (const QVariant & variant : items)
- {
- if (variant.canConvert<QmlInputItem>() == false)
- continue;
-
- const QmlInputItem & item = variant.value<QmlInputItem>();
-
- medias.push_back(vlc::playlist::Media(item.item.get()));
- }
-
- insert(index, medias, false);
-}
-
void
PlaylistControllerModel::shuffle()
{
=====================================
modules/gui/qt/playlist/playlist_controller.hpp
=====================================
@@ -112,8 +112,6 @@ public:
void move(const QVector<PlaylistItem> &, size_t target, ssize_t indexHint);
void remove(const QVector<PlaylistItem> &, ssize_t indexHint);
- Q_INVOKABLE void insert(int index, const QVariantList & items /* QList<QmlInputItem> */);
-
Q_INVOKABLE void shuffle();
void sort(const QVector<vlc_playlist_sort_criterion> &);
=====================================
modules/gui/qt/playlist/qml/PlaylistListView.qml
=====================================
@@ -98,7 +98,7 @@ Control {
console.warn("can't convert items to input items");
return
}
- mainPlaylistController.insert(index, inputItems)
+ mainPlaylistController.insert(index, inputItems, false)
})
// NOTE: Dropping an external item (i.e. filesystem) into the queue.
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/012c7a930fa3824ce50c11c3906aad8cac30104d...63ac5078a89bf569d7f2f9f0167985a5fac75570
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/012c7a930fa3824ce50c11c3906aad8cac30104d...63ac5078a89bf569d7f2f9f0167985a5fac75570
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