[vlc-commits] [Git][videolan/vlc][master] 7 commits: qt: add "url" role to MLFoldersBaseModel
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Sun Sep 15 10:13:15 UTC 2024
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
13c855a3 by Fatih Uzunoglu at 2024-09-15T10:01:15+00:00
qt: add "url" role to MLFoldersBaseModel
- - - - -
f788b1b7 by Fatih Uzunoglu at 2024-09-15T10:01:15+00:00
qt: add "url" role to MLAlbumTrackModel
- - - - -
e62abf09 by Fatih Uzunoglu at 2024-09-15T10:01:15+00:00
qt: add "url" role to NetworkMediaModel
- - - - -
dcf54f45 by Fatih Uzunoglu at 2024-09-15T10:01:15+00:00
qt: add "url" role to PlaylistListModel
- - - - -
86de5f77 by Fatih Uzunoglu at 2024-09-15T10:01:15+00:00
qt: add `url` property to PlayerController
- - - - -
5d328a68 by Fatih Uzunoglu at 2024-09-15T10:01:15+00:00
qt: add invokable `urlListToMimeData()` to MainCtx
- - - - -
1ddeb93b by Fatih Uzunoglu at 2024-09-15T10:01:15+00:00
qt: provide MIME data in DragItem with type "text/uri-list" as per RFC-2483
- - - - -
15 changed files:
- modules/gui/qt/maininterface/mainctx.cpp
- modules/gui/qt/maininterface/mainctx.hpp
- modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
- modules/gui/qt/medialibrary/mlalbumtrackmodel.hpp
- modules/gui/qt/medialibrary/mlfoldersmodel.cpp
- modules/gui/qt/network/networkmediamodel.cpp
- modules/gui/qt/network/networkmediamodel.hpp
- modules/gui/qt/player/player_controller.cpp
- modules/gui/qt/player/player_controller.hpp
- modules/gui/qt/player/player_controller_p.hpp
- modules/gui/qt/player/qml/controlbarcontrols/ArtworkInfoWidget.qml
- modules/gui/qt/playlist/playlist_model.cpp
- modules/gui/qt/playlist/playlist_model.hpp
- modules/gui/qt/playlist/qml/PlaylistListView.qml
- modules/gui/qt/widgets/qml/DragItem.qml
Changes:
=====================================
modules/gui/qt/maininterface/mainctx.cpp
=====================================
@@ -673,6 +673,50 @@ void MainCtx::setVideoSurfaceProvider(VideoSurfaceProvider* videoSurfaceProvider
emit hasEmbededVideoChanged(m_videoSurfaceProvider && m_videoSurfaceProvider->hasVideoEmbed());
}
+QJSValue MainCtx::urlListToMimeData(const QJSValue &array) {
+ // NOTE: Due to a Qt regression since 17318c4
+ // (Nov 11, 2022), it is not possible to
+ // use RFC-2483 compliant string here.
+ // This regression was later corrected by
+ // c25f53b (Jul 31, 2024).
+ // NOTE: Qt starts supporting string list since
+ // 17318c4, so starting from 6.5.0 a string
+ // list can be used which is not affected
+ // by the said issue. For Qt versions below
+ // 6.5.0, use byte array which is used as is
+ // by Qt.
+ assert(array.property("length").toInt() > 0);
+
+ QJSEngine* const engine = qjsEngine(this);
+ assert(engine);
+
+ QJSValue data;
+#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
+ QString string;
+ for (int i = 0; i < array.property(QStringLiteral("length")).toInt(); ++i)
+ {
+ QString decodedUrl;
+ const QJSValue element = array.property(i);
+ if (element.isUrl())
+ // QJSValue does not have `toUrl()`
+ decodedUrl = QJSManagedValue(element, engine).toUrl().toString(QUrl::FullyEncoded);
+ else if (element.isString())
+ // If the element is string, we assume it is already encoded
+ decodedUrl = element.toString();
+ else
+ Q_UNREACHABLE(); // Assertion failure in debug builds
+ string += decodedUrl + QStringLiteral("\r\n");
+ }
+ string.chop(2);
+ data = engine->toScriptValue(string);
+#else
+ data = array;
+#endif
+ QJSValue ret = engine->newObject();
+ ret.setProperty(QStringLiteral("text/uri-list"), data);
+ return ret;
+}
+
VideoSurfaceProvider* MainCtx::getVideoSurfaceProvider() const
{
return m_videoSurfaceProvider;
=====================================
modules/gui/qt/maininterface/mainctx.hpp
=====================================
@@ -267,6 +267,8 @@ public:
(QT_VERSION >= QT_VERSION_CHECK(6, 4, 0));
}
+ Q_INVOKABLE QJSValue urlListToMimeData(const QJSValue& array);
+
/**
* @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/medialibrary/mlalbumtrackmodel.cpp
=====================================
@@ -60,6 +60,8 @@ QVariant MLAlbumTrackModel::itemRoleData(MLItem *item, const int role) const
return QVariant::fromValue( getFirstSymbol( ml_track->getAlbumTitle() ) );
case TRACK_ARTIST_FIRST_SYMBOL:
return QVariant::fromValue( getFirstSymbol( ml_track->getArtist() ) );
+ case TRACK_URL:
+ return QUrl(ml_track->getMRL());
default :
return QVariant();
}
@@ -80,6 +82,7 @@ QHash<int, QByteArray> MLAlbumTrackModel::roleNames() const
{ TRACK_TITLE_FIRST_SYMBOL, "title_first_symbol"},
{ TRACK_ALBUM_FIRST_SYMBOL, "album_title_first_symbol"},
{ TRACK_ARTIST_FIRST_SYMBOL, "main_artist_first_symbol"},
+ { TRACK_URL, "url" }
};
}
=====================================
modules/gui/qt/medialibrary/mlalbumtrackmodel.hpp
=====================================
@@ -41,6 +41,7 @@ public:
TRACK_DURATION,
TRACK_ALBUM,
TRACK_ARTIST,
+ TRACK_URL,
TRACK_TITLE_FIRST_SYMBOL,
TRACK_ALBUM_FIRST_SYMBOL,
=====================================
modules/gui/qt/medialibrary/mlfoldersmodel.cpp
=====================================
@@ -94,6 +94,7 @@ QHash<int, QByteArray> MLFoldersBaseModel::roleNames() const
return {
{DisplayUrl, "display_url"},
{Banned, "banned"},
+ {MRL, "url"}
};
}
=====================================
modules/gui/qt/network/networkmediamodel.cpp
=====================================
@@ -557,6 +557,8 @@ QVariant NetworkMediaModel::data( const QModelIndex& index, int role ) const
return {};
}
+ case URL:
+ return item->uri;
default:
return basedata(*item, role);
}
@@ -574,6 +576,7 @@ QHash<int, QByteArray> NetworkMediaModel::roleNames() const
roles[NETWORK_MEDIA] = "media";
roles[NETWORK_MEDIA_PROGRESS] = "progress";
roles[NETWORK_MEDIA_DURATION] = "duration";
+ roles[URL] = "url";
return roles;
}
=====================================
modules/gui/qt/network/networkmediamodel.hpp
=====================================
@@ -115,6 +115,7 @@ public:
NETWORK_MEDIA,
NETWORK_MEDIA_PROGRESS,
NETWORK_MEDIA_DURATION,
+ URL
};
Q_PROPERTY(MainCtx* ctx READ getCtx WRITE setCtx NOTIFY ctxChanged)
=====================================
modules/gui/qt/player/player_controller.cpp
=====================================
@@ -291,6 +291,7 @@ static void on_player_current_media_changed(vlc_player_t *, input_item_t *new_m
that->UpdateName( newMediaPtr.get() );
that->UpdateArt( newMediaPtr.get() );
that->UpdateMeta( newMediaPtr.get() );
+ that->m_url = vlc::wrap_cptr( input_item_GetURI( newMediaPtr.get() ) ).get();
{
vlc_player_locker lock{ that->m_player };
@@ -2121,6 +2122,7 @@ PRIMITIVETYPE_GETTER(QString, getTitle, m_title)
PRIMITIVETYPE_GETTER(QString, getArtist, m_artist)
PRIMITIVETYPE_GETTER(QString, getAlbum, m_album)
PRIMITIVETYPE_GETTER(QUrl, getArtwork, m_artwork)
+PRIMITIVETYPE_GETTER(QUrl, getUrl, m_url)
// High resolution time fed by SMPTE timer
PRIMITIVETYPE_GETTER(QString, highResolutionTime, m_highResolutionTime)
=====================================
modules/gui/qt/player/player_controller.hpp
=====================================
@@ -110,6 +110,7 @@ public:
Q_PROPERTY(QString name READ getName NOTIFY nameChanged FINAL)
Q_PROPERTY(float buffering READ getBuffering NOTIFY bufferingChanged FINAL)
Q_PROPERTY(float rate READ getRate WRITE setRate NOTIFY rateChanged FINAL)
+ Q_PROPERTY(QUrl url READ getUrl NOTIFY inputChanged FINAL)
Q_PROPERTY(VLCTick time READ getTime WRITE setTime NOTIFY timeChanged FINAL)
Q_PROPERTY(VLCTick remainingTime READ getRemainingTime NOTIFY remainingTimeChanged FINAL)
@@ -297,6 +298,7 @@ public slots:
void restorePlaybackPos();
void openVLsub();
void acknowledgeRestoreCallback();
+ QUrl getUrl() const;
//tracks
TrackListModel* getVideoTracks();
=====================================
modules/gui/qt/player/player_controller_p.hpp
=====================================
@@ -175,6 +175,7 @@ public:
QString m_artist;
QString m_album;
QUrl m_artwork;
+ QUrl m_url;
};
#endif /* QVLC_INPUT_MANAGER_P_H_ */
=====================================
modules/gui/qt/player/qml/controlbarcontrols/ArtworkInfoWidget.qml
=====================================
@@ -105,7 +105,8 @@ AbstractButton {
resolve([{
"title": Player.title,
"cover": (!!Player.artwork && Player.artwork.toString() !== "") ? Player.artwork
- : VLCStyle.noArtAlbumCover
+ : VLCStyle.noArtAlbumCover,
+ "url": Player.url
}])
}
=====================================
modules/gui/qt/playlist/playlist_model.cpp
=====================================
@@ -490,6 +490,8 @@ PlaylistListModel::data(const QModelIndex &index, int role) const
return d->m_items[row].getAlbum();
case ArtworkRole:
return d->m_items[row].getArtwork();
+ case UrlRole:
+ return d->m_items[row].getUrl();
default:
return {};
}
=====================================
modules/gui/qt/playlist/playlist_model.hpp
=====================================
@@ -49,7 +49,8 @@ public:
IsCurrentRole,
ArtistRole,
AlbumRole,
- ArtworkRole
+ ArtworkRole,
+ UrlRole
};
PlaylistListModel(QObject *parent = nullptr);
=====================================
modules/gui/qt/playlist/qml/PlaylistListView.qml
=====================================
@@ -78,7 +78,8 @@ T.Pane {
const item = root.model.itemAt(index)
return {
"title": item.title,
- "cover": (!!item.artwork && item.artwork.toString() !== "") ? item.artwork : VLCStyle.noArtAlbumCover
+ "cover": (!!item.artwork && item.artwork.toString() !== "") ? item.artwork : VLCStyle.noArtAlbumCover,
+ "url": item.url
}
}))
}
=====================================
modules/gui/qt/widgets/qml/DragItem.qml
=====================================
@@ -137,16 +137,22 @@ Item {
_data = data
const covers = []
+ let mimeData = []
for (let i in indexes) {
if (covers.length === _maxCovers)
break
- const cover = _getCover(indexes[i], data[i])
+ const element = data[i]
+ const cover = _getCover(indexes[i], element)
if (!cover)
continue
covers.push(cover)
+
+ const url = element.url ?? element.mrl
+ if (url)
+ mimeData.push(url)
}
if (covers.length === 0)
@@ -156,6 +162,10 @@ Item {
})
_covers = covers
+
+ if (mimeData.length > 0) {
+ Drag.mimeData = MainCtx.urlListToMimeData(mimeData)
+ }
}
function _setInputItems(inputItems) {
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9ffa52c9a0a365586fcb27764afee20a1f5dcfc4...1ddeb93b6751e96d88a6c99bef117e0c363bc3e1
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9ffa52c9a0a365586fcb27764afee20a1f5dcfc4...1ddeb93b6751e96d88a6c99bef117e0c363bc3e1
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