vlc | branch: master | Benjamin Arnaud <benjamin.arn...@videolabs.io> | Fri Feb 19 11:25:30 2021 +0100| [30208b538f77753d6cf1fcb76ee8d775c7eb6734] | committer: Pierre Lamot
qt: Create PlaylistsDialog Signed-off-by: Pierre Lamot <pie...@videolabs.io> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=30208b538f77753d6cf1fcb76ee8d775c7eb6734 --- modules/gui/qt/Makefile.am | 2 + modules/gui/qt/dialogs/playlists/playlists.cpp | 224 +++++++++++++++++++++++++ modules/gui/qt/dialogs/playlists/playlists.hpp | 78 +++++++++ po/POTFILES.in | 2 + 4 files changed, 306 insertions(+) diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am index 6057040f99..7de2b03424 100644 --- a/modules/gui/qt/Makefile.am +++ b/modules/gui/qt/Makefile.am @@ -114,6 +114,7 @@ libqt_plugin_la_SOURCES = \ gui/qt/dialogs/sout/sout_widgets.hpp \ gui/qt/dialogs/toolbar/toolbareditor.cpp gui/qt/dialogs/toolbar/toolbareditor.hpp \ gui/qt/dialogs/vlm/vlm.cpp gui/qt/dialogs/vlm/vlm.hpp \ + gui/qt/dialogs/playlists/playlists.cpp gui/qt/dialogs/playlists/playlists.hpp \ gui/qt/maininterface/compositor.hpp \ gui/qt/maininterface/compositor.cpp \ gui/qt/maininterface/compositor_dummy.hpp \ @@ -314,6 +315,7 @@ nodist_libqt_plugin_la_SOURCES = \ gui/qt/dialogs/sout/sout.moc.cpp \ gui/qt/dialogs/sout/sout_widgets.moc.cpp \ gui/qt/dialogs/toolbar/toolbareditor.moc.cpp \ + gui/qt/dialogs/playlists/playlists.moc.cpp \ gui/qt/maininterface/compositor_dummy.moc.cpp \ gui/qt/maininterface/interface_window_handler.moc.cpp \ gui/qt/maininterface/main_interface.moc.cpp \ diff --git a/modules/gui/qt/dialogs/playlists/playlists.cpp b/modules/gui/qt/dialogs/playlists/playlists.cpp new file mode 100644 index 0000000000..0bff47f81a --- /dev/null +++ b/modules/gui/qt/dialogs/playlists/playlists.cpp @@ -0,0 +1,224 @@ +/***************************************************************************** + * playlists.cpp : Playlists + **************************************************************************** + * Copyright (C) 2021 the VideoLAN team + * + * Authors: Benjamin Arnaud <bun...@omega.gg> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "playlists.hpp" + +// VLC includes +#include <vlc_media_library.h> +#include <maininterface/main_interface.hpp> +#include <medialibrary/mlplaylistlistmodel.hpp> +#include <medialibrary/mlqmltypes.hpp> + +// Qt includes +#include <QGroupBox> +#include <QVBoxLayout> +#include <QTreeView> +#include <QLabel> +#include <QLineEdit> +#include <QDialogButtonBox> +#include <QPushButton> + +//------------------------------------------------------------------------------------------------- +// Ctor / dtor +//------------------------------------------------------------------------------------------------- + +PlaylistsDialog::PlaylistsDialog(intf_thread_t * _p_intf) : QVLCFrame(_p_intf) +{ + MainInterface * mainInterface = p_intf->p_sys->p_mi; + + assert(mainInterface->hasMediaLibrary()); + + setWindowFlags(Qt::Tool); + + setWindowRole("vlc-playlists"); + + setWindowTitle(qtr("Add to Playlist")); + + setWindowOpacity(var_InheritFloat(p_intf, "qt-opacity")); + + //--------------------------------------------------------------------------------------------- + // Existing Playlists + + QGroupBox * groupBox = new QGroupBox(qtr("Existing Playlist")); + + m_playlists = new QTreeView(this); + + connect(m_playlists, &QTreeView::clicked, this, &PlaylistsDialog::onClicked); + connect(m_playlists, &QTreeView::doubleClicked, this, &PlaylistsDialog::onDoubleClicked); + + m_model = new MLPlaylistListModel(vlc_ml_instance_get(_p_intf), m_playlists); + + m_model->setMl(mainInterface->getMediaLibrary()); + + m_playlists->setModel(m_model); + + QVBoxLayout * layoutPlaylists = new QVBoxLayout(groupBox); + + layoutPlaylists->addWidget(m_playlists); + + //--------------------------------------------------------------------------------------------- + // New Playlist + + QLabel * labelNew = new QLabel(this); + + labelNew->setText(qtr("New Playlist")); + + // FIXME: Add and configure a QValidator. + m_lineEdit = new QLineEdit(this); + + connect(m_lineEdit, &QLineEdit::textEdited, this, &PlaylistsDialog::onTextEdited); + + QHBoxLayout * layoutNew = new QHBoxLayout; + + layoutNew->addWidget(labelNew); + layoutNew->addWidget(m_lineEdit); + + //--------------------------------------------------------------------------------------------- + // Buttons + + QDialogButtonBox * buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel, + Qt::Horizontal, this); + + m_button = buttonBox->button(QDialogButtonBox::Ok); + + m_button->setEnabled(false); + + connect(buttonBox, &QDialogButtonBox::accepted, this, &PlaylistsDialog::onAccepted); + connect(buttonBox, &QDialogButtonBox::rejected, this, &PlaylistsDialog::close); + + m_label = new QLabel(this); + + QHBoxLayout * layoutButtons = new QHBoxLayout; + + layoutButtons->addWidget(m_label); + layoutButtons->addWidget(buttonBox); + + //--------------------------------------------------------------------------------------------- + + QVBoxLayout * layout = new QVBoxLayout(this); + + layout->addWidget(groupBox); + layout->addLayout(layoutNew); + layout->addLayout(layoutButtons); + + // FIXME: Is this the right default size ? + restoreWidgetPosition("Playlists", QSize(320, 320)); + + updateGeometry(); +} + +PlaylistsDialog::~PlaylistsDialog() /* override */ +{ + saveWidgetPosition("Playlists"); +} + +//------------------------------------------------------------------------------------------------- +// Interface +//------------------------------------------------------------------------------------------------- + +/* Q_INVOKABLE */ void PlaylistsDialog::setMedias(const QVariantList & medias) +{ + m_ids = medias; + + m_label->setText(qtr("%1 Media(s)").arg(m_ids.count())); +} + +//------------------------------------------------------------------------------------------------- +// Events +//------------------------------------------------------------------------------------------------- + +void PlaylistsDialog::hideEvent(QHideEvent *) /* override */ +{ + // NOTE: We clear the lineEdit when hiding the dialog. + m_lineEdit->clear(); +} + +void PlaylistsDialog::keyPressEvent(QKeyEvent * event) /* override */ +{ + int key = event->key(); + + // FIXME: For some reason we have to do this manually on here. Shouldn't QDialogButtonBox do + // this automatically ? + if (key == Qt::Key_Return || key == Qt::Key_Enter) + { + if (m_button->isEnabled()) + onAccepted(); + + return; + } + + QVLCFrame::keyPressEvent(event); +} + +//------------------------------------------------------------------------------------------------- +// Private slots +//------------------------------------------------------------------------------------------------- + +void PlaylistsDialog::onClicked() +{ + // NOTE: We clear the lineEdit when the list is selected. + m_lineEdit->clear(); + + m_button->setEnabled(true); +} + +void PlaylistsDialog::onDoubleClicked() +{ + if (m_button->isEnabled() == false) + return; + + onAccepted(); +} + +//------------------------------------------------------------------------------------------------- + +void PlaylistsDialog::onTextEdited() +{ + // NOTE: We clear the list selection when we edit the 'new playlist' field. + m_playlists->clearSelection(); + + if (m_lineEdit->text().isEmpty()) + m_button->setEnabled(false); + else + m_button->setEnabled(true); +} + +void PlaylistsDialog::onAccepted() +{ + MLItemId id; + + QString text = m_lineEdit->text(); + + if (text.isEmpty()) + id = m_model->getItemId(m_playlists->currentIndex().row()); + else + id = m_model->create(text); + + m_model->append(id, m_ids); + + close(); +} diff --git a/modules/gui/qt/dialogs/playlists/playlists.hpp b/modules/gui/qt/dialogs/playlists/playlists.hpp new file mode 100644 index 0000000000..3d33f988ff --- /dev/null +++ b/modules/gui/qt/dialogs/playlists/playlists.hpp @@ -0,0 +1,78 @@ +/***************************************************************************** + * playlists.hpp : playlists + **************************************************************************** + * Copyright (C) 2021 the VideoLAN team + * + * Authors: Benjamin Arnaud <bun...@omega.gg> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifndef QVLC_PLAYLISTS_H_ +#define QVLC_PLAYLISTS_H_ 1 + +// VLC includes +#include <widgets/native/qvlcframe.hpp> +#include <util/singleton.hpp> + +// Forward declarations +class MLPlaylistListModel; +class QTreeView; +class QLineEdit; +class QLabel; +class QPushButton; + +class PlaylistsDialog : public QVLCFrame, public Singleton<PlaylistsDialog> +{ + Q_OBJECT + +private: // Ctor / dtor + PlaylistsDialog(intf_thread_t *); + + ~PlaylistsDialog() override; + +public: // Interface + Q_INVOKABLE void setMedias(const QVariantList & medias); + +protected: // Events + void hideEvent(QHideEvent * event) override; + + void keyPressEvent(QKeyEvent * event) override; + +private slots: + void onClicked (); + void onDoubleClicked(); + + void onTextEdited(); + + void onAccepted(); + +private: + QVariantList m_ids; + + MLPlaylistListModel * m_model; + + QTreeView * m_playlists; + QLineEdit * m_lineEdit; + + QLabel * m_label; + + QPushButton * m_button; + +private: + friend class Singleton<PlaylistsDialog>; +}; + +#endif diff --git a/po/POTFILES.in b/po/POTFILES.in index a7870b93d0..7e525cd659 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -760,6 +760,8 @@ modules/gui/qt/dialogs/dialogs_provider.cpp modules/gui/qt/dialogs/dialogs_provider.hpp modules/gui/qt/dialogs/extensions/extensions_manager.cpp modules/gui/qt/dialogs/extensions/extensions_manager.hpp +modules/gui/qt/dialogs/playlists/playlists.cpp +modules/gui/qt/dialogs/playlists/playlists.hpp modules/gui/qt/maininterface/main_interface.cpp modules/gui/qt/maininterface/main_interface.hpp modules/gui/qt/maininterface/main_interface_win32.cpp _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits