Commit 53f241fe authored by Paweł Wegner's avatar Paweł Wegner
Browse files

Cloudbrowser: embedded player into QWidget.

parent afa50272
......@@ -41,7 +41,7 @@ AC_ARG_WITH([examples], AS_HELP_STRING([--with-examples]))
AM_CONDITIONAL([EXAMPLES], [test "x$with_examples" = "xyes"])
AS_IF([test "x$with_examples" = "xyes"], [
PKG_CHECK_MODULES(QT, [Qt5Core Qt5Gui Qt5Quick], [
PKG_CHECK_MODULES(QT, [Qt5Core Qt5Gui Qt5Quick Qt5Widgets], [
QT_PATH="$(eval $PKG_CONFIG --variable=exec_prefix Qt5Core)"
QT_HOST_PATH="$(eval $PKG_CONFIG --variable=host_bins Qt5Core)"
AC_PATH_PROGS(MOC, [moc-qt5 moc], moc, ["${QT_HOST_PATH}" "${QT_PATH}/bin"])
......
......@@ -38,16 +38,16 @@
using namespace cloudstorage;
Window::Window()
Window::Window(QWidget* player_widget)
: image_provider_(new ImageProvider),
vlc_instance_(0, nullptr),
media_player_(vlc_instance_),
last_played_(-1) {
last_played_(-1),
container_() {
qRegisterMetaType<ItemPointer>();
qRegisterMetaType<ImagePointer>();
setClearBeforeRendering(false);
initializeMediaPlayer();
initializeMediaPlayer(player_widget);
QStringList clouds;
for (auto p : ICloudStorage::create()->providers())
......@@ -68,11 +68,17 @@ Window::Window()
connect(this, &Window::runPlayerFromUrl, this, &Window::onPlayFileFromUrl);
connect(this, &Window::cloudChanged, this, &Window::listDirectory);
connect(this, &Window::showPlayer, this,
[this]() { contentItem()->setVisible(false); }, Qt::QueuedConnection);
[this]() {
if (container()) container()->hide();
},
Qt::QueuedConnection);
connect(this, &Window::hidePlayer, this,
[this]() {
media_player_.stop();
contentItem()->setVisible(true);
stop();
if (container()) {
container()->show();
container()->setFocus();
}
},
Qt::QueuedConnection);
connect(this, &Window::runListDirectory, this, [this]() { listDirectory(); },
......@@ -169,15 +175,6 @@ void Window::onPlayFileFromUrl(QString url) {
}
}
void Window::keyPressEvent(QKeyEvent* e) {
QQuickView::keyPressEvent(e);
if (e->isAccepted()) return;
if (e->key() == Qt::Key_Q)
stop();
else if (e->key() == Qt::Key_P)
media_player_.pause();
}
void Window::clearCurrentDirectoryList() {
directory_model_.clear();
last_played_ = -1;
......@@ -195,13 +192,13 @@ void Window::saveCloudAccessToken() {
}
}
void Window::initializeMediaPlayer() {
void Window::initializeMediaPlayer(QWidget* player_widget) {
#ifdef Q_OS_LINUX
media_player_.setXwindow(winId());
media_player_.setXwindow(player_widget->winId());
#elif defined Q_OS_WIN
media_player_.setHwnd(reinterpret_cast<void*>(winId()));
media_player_.setHwnd(reinterpret_cast<void*>(player_widget->winId()));
#elif defined Q_OS_DARWIN
media_player_.setNsobject(reinterpret_cast<void*>(winId()));
media_player_.setNsobject(reinterpret_cast<void*>(player_widget->winId()));
#endif
media_player_.eventManager().onPlaying([this]() {
......
......@@ -29,6 +29,7 @@
#include <QAbstractListModel>
#include <QQuickImageProvider>
#include <QQuickView>
#include <QQuickWidget>
#include <future>
#include <vlcpp/vlc.hpp>
......@@ -95,7 +96,7 @@ class DirectoryModel : public QAbstractListModel {
class Window : public QQuickView {
public:
Window();
Window(QWidget* player_widget);
~Window();
ImageProvider* imageProvider() { return image_provider_; }
......@@ -115,6 +116,10 @@ class Window : public QQuickView {
void onPlayFileFromUrl(QString url);
std::mutex& stream_mutex() const { return stream_mutex_; }
VLC::MediaPlayer& media_player() { return media_player_; }
void set_container(QWidget* w) { container_ = w; }
QWidget* container() const { return container_; }
signals:
void openBrowser(QString url);
......@@ -132,16 +137,13 @@ class Window : public QQuickView {
void runClearDirectory();
void playNext();
protected:
void keyPressEvent(QKeyEvent*);
private:
friend class CloudProviderCallback;
friend class DirectoryModel;
void clearCurrentDirectoryList();
void saveCloudAccessToken();
void initializeMediaPlayer();
void initializeMediaPlayer(QWidget* player_widget);
void startDirectoryClear(std::function<void()>);
ICloudProvider::Hints fromJson(const QJsonObject&) const;
......@@ -161,6 +163,7 @@ class Window : public QQuickView {
DirectoryModel directory_model_;
mutable std::mutex stream_mutex_;
int last_played_;
QWidget* container_;
Q_OBJECT
};
......
......@@ -21,20 +21,55 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <QGuiApplication>
#include <QApplication>
#include <QResizeEvent>
#include <iostream>
#include <vlcpp/vlc.hpp>
#include "Window.h"
class MainWidget : public QWidget {
public:
MainWidget()
: player_widget_(this),
window_(&player_widget_),
container_(createWindowContainer(&window_, this)) {
window_.set_container(container_);
container_->setFocus();
player_widget_.show();
}
protected:
void resizeEvent(QResizeEvent* e) {
QWidget::resizeEvent(e);
player_widget_.resize(e->size());
container_->resize(e->size());
}
void keyPressEvent(QKeyEvent* e) {
QWidget::keyPressEvent(e);
if (e->isAccepted()) return;
if (e->key() == Qt::Key_Q)
window_.stop();
else if (e->key() == Qt::Key_P)
window_.media_player().pause();
}
private:
QWidget player_widget_;
Window window_;
QWidget* container_;
};
int main(int argc, char* argv[]) {
try {
QGuiApplication app(argc, argv);
QApplication app(argc, argv);
app.setOrganizationName("VideoLAN");
app.setApplicationName("cloudbrowser");
Window window;
window.resize(800, 600);
window.show();
MainWidget widget;
widget.resize(800, 600);
widget.show();
return app.exec();
} catch (const std::exception& e) {
......
......@@ -42,7 +42,7 @@ Item {
}
}
}
Connections {
Connections {
target: window
onOpenBrowser: {
browser.visible = true;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment