Commit 12d3bee7 authored by Paweł Wegner's avatar Paweł Wegner
Browse files

Cloudbrowser: don't show player when playing audio.

parent 6df7ff2e
......@@ -69,7 +69,8 @@ Window::Window(QWidget* player_widget)
connect(this, &Window::cloudChanged, this, &Window::listDirectory);
connect(this, &Window::showPlayer, this,
[this]() {
if (container()->isVisible()) {
ItemModel* item = directory_model_.get(last_played_);
if (item && item->item()->type() != IItem::FileType::Audio) {
container()->hide();
contentItem()->setFocus(false);
}
......@@ -77,11 +78,8 @@ Window::Window(QWidget* player_widget)
Qt::QueuedConnection);
connect(this, &Window::hidePlayer, this,
[this]() {
stop();
if (container()->isHidden()) {
container()->show();
contentItem()->setFocus(true);
}
container()->show();
contentItem()->setFocus(true);
},
Qt::QueuedConnection);
connect(this, &Window::runListDirectory, this, [this]() { listDirectory(); },
......@@ -179,6 +177,14 @@ void Window::onPlayFileFromUrl(QString url) {
}
}
void Window::keyPressEvent(QKeyEvent* e) {
if (e->key() == Qt::Key_Q) {
stop();
e->accept();
}
QQuickView::keyPressEvent(e);
}
void Window::clearCurrentDirectoryList() {
directory_model_.clear();
last_played_ = -1;
......@@ -205,9 +211,7 @@ void Window::initializeMediaPlayer(QWidget* player_widget) {
media_player_.setNsobject(reinterpret_cast<void*>(player_widget->winId()));
#endif
media_player_.eventManager().onPlaying([this]() {
if (media_player_.videoTrackCount() > 0) emit showPlayer();
});
media_player_.eventManager().onPlaying([this]() { emit showPlayer(); });
media_player_.eventManager().onStopped([this]() { emit hidePlayer(); });
media_player_.eventManager().onEndReached([this]() { emit playNext(); });
}
......@@ -251,8 +255,8 @@ bool Window::goBack() {
void Window::play(int item_id) {
ItemModel* item = directory_model_.get(item_id);
stop();
contentItem()->setFocus(false);
if (item->item()->type() != IItem::FileType::Audio)
contentItem()->setFocus(false);
last_played_ = item_id;
item_data_request_ = cloud_provider_->getItemDataAsync(
item->item()->id(), [this](IItem::Pointer i) {
......@@ -368,6 +372,11 @@ void DirectoryModel::addItem(IItem::Pointer item, Window* w) {
Qt::QueuedConnection);
}
ItemModel* DirectoryModel::get(int id) const {
if (id < 0 || id >= list_.size()) return nullptr;
return list_[id].get();
}
void DirectoryModel::clear() {
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
list_.clear();
......
......@@ -86,7 +86,7 @@ class DirectoryModel : public QAbstractListModel {
QVariant data(const QModelIndex& index, int) const;
void addItem(IItem::Pointer, Window* w);
ItemModel* get(int id) const { return list_[id].get(); }
ItemModel* get(int id) const;
void clear();
......@@ -138,6 +138,9 @@ class Window : public QQuickView {
void playNext();
void currentItemChanged(int index);
protected:
void keyPressEvent(QKeyEvent* e);
private:
friend class CloudProviderCallback;
friend class DirectoryModel;
......
......@@ -65,12 +65,6 @@ Item {
downloadProgress.visible = total != 0;
downloadProgress.value = now / total;
}
onShowPlayer: {
directory.focus = false;
}
onHidePlayer: {
directory.focus = true;
}
onCurrentItemChanged: {
directory.currentIndex = index;
}
......@@ -140,8 +134,6 @@ Item {
downloadFileDialog.open();
} else if (event.key === Qt.Key_F5)
window.listDirectory();
else if (event.key === Qt.Key_Q)
window.stop();
}
FileDialog {
property var file
......
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