[vlc-devel] [PATCH 03/29] qt: remove native ToolbarEditor dialog

Fatih Uzunoglu fuzun54 at outlook.com
Thu Apr 1 22:22:15 UTC 2021


the hybrid (native dialog + qml context)
toolbar editor dialog has a lot of drawbacks
and causes many problems. A proper QML dialog
for the toolbar editor is going to replace
the hybrid (old) one.
---
 modules/gui/qt/Makefile.am                    |   2 -
 .../gui/qt/dialogs/toolbar/toolbareditor.cpp  | 208 ------------------
 .../gui/qt/dialogs/toolbar/toolbareditor.hpp  |  55 -----
 po/POTFILES.in                                |   2 -
 4 files changed, 267 deletions(-)
 delete mode 100644 modules/gui/qt/dialogs/toolbar/toolbareditor.cpp
 delete mode 100644 modules/gui/qt/dialogs/toolbar/toolbareditor.hpp

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 7857c8390a..add710cd4b 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -112,7 +112,6 @@ libqt_plugin_la_SOURCES = \
 	gui/qt/dialogs/sout/sout.cpp gui/qt/dialogs/sout/sout.hpp \
 	gui/qt/dialogs/sout/sout_widgets.cpp \
 	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 \
@@ -316,7 +315,6 @@ nodist_libqt_plugin_la_SOURCES = \
 	gui/qt/dialogs/sout/profile_selector.moc.cpp \
 	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 \
diff --git a/modules/gui/qt/dialogs/toolbar/toolbareditor.cpp b/modules/gui/qt/dialogs/toolbar/toolbareditor.cpp
deleted file mode 100644
index 121f8b3d1f..0000000000
--- a/modules/gui/qt/dialogs/toolbar/toolbareditor.cpp
+++ /dev/null
@@ -1,208 +0,0 @@
-/*****************************************************************************
- * Copyright (C) 2019 VLC authors and VideoLAN
- *
- * 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 "toolbareditor.hpp"
-#include "util/i18n.hpp"
-#include "util/systempalette.hpp"
-#include "util/qml_main_context.hpp"
-#include "player/playercontrolbarmodel.hpp"
-#include "maininterface/main_interface.hpp"
-
-#include <QInputDialog>
-#include <QQuickItem>
-#include <QtQml/QQmlContext>
-#include <QQmlEngine>
-
-#define PROFILE_NAME_1 "Minimalist Style"
-#define VALUE_1 "0;64;3;1;4;64;11;64;34;64;9;64;33 | 3;0;1;4"
-#define PROFILE_NAME_2 "One-Liner Style"
-#define VALUE_2 "0;64;3;1;4;64;7;9;8;64;64;11;10;12;13;#33 | 17;3;0;1;4;18"
-#define PROFILE_NAME_3 "Simplest Style"
-#define VALUE_3 "33;#0;4;1;#7 | 3;0;4"
-
-ToolbarEditorDialog::ToolbarEditorDialog( QWidget *_w, intf_thread_t *_p_intf)
-    : QVLCDialog( _w,  _p_intf )
-{
-    setWindowTitle( qtr( "Toolbars Editor" ) );
-    setWindowRole( "vlc-toolbars-editor" );
-    setMinimumWidth( 800 );
-    setMinimumHeight( 600 );
-
-    /* Profile */
-    QGridLayout *mainLayout = new QGridLayout( this );
-    QHBoxLayout *profileBoxLayout = new QHBoxLayout();
-
-    profileCombo = new QComboBox;
-
-    QToolButton *newButton = new QToolButton;
-    newButton->setIcon( QIcon( ":/new.svg" ) );
-    newButton->setToolTip( qtr("New profile") );
-    QToolButton *deleteButton = new QToolButton;
-    deleteButton->setIcon( QIcon( ":/toolbar/clear.svg" ) );
-    deleteButton->setToolTip( qtr( "Delete the current profile" ) );
-
-    profileBoxLayout->addWidget( new QLabel( qtr( "Select profile:" ) ) );
-    profileBoxLayout->addWidget( profileCombo );
-    profileBoxLayout->addWidget( newButton );
-    profileBoxLayout->addWidget( deleteButton );
-
-    mainLayout->addLayout( profileBoxLayout, 0, 0, 1, 9 );
-
-    /* Fill combos */
-    int i_size = getSettings()->beginReadArray( "ToolbarProfiles" );
-    for( int i = 0; i < i_size; i++ )
-    {
-        getSettings()->setArrayIndex(i);
-        profileCombo->addItem( getSettings()->value( "ProfileName" ).toString(),
-                               getSettings()->value( "Value" ).toString() );
-    }
-    getSettings()->endArray();
-
-    /* Load defaults ones if we have no combos */
-    if( i_size == 0 )
-    {
-        profileCombo->addItem( qtr("Default Style"), PlayerControlBarModel::getSerializedDefaultStyle() );
-        profileCombo->addItem( PROFILE_NAME_1, QString( VALUE_1 ) );
-        profileCombo->addItem( PROFILE_NAME_2, QString( VALUE_2 ) );
-        profileCombo->addItem( PROFILE_NAME_3, QString( VALUE_3 ) );
-        profileCombo->setCurrentIndex(0);
-    }
-    else
-    {
-        profileCombo->setCurrentIndex( -1 );
-    }
-
-    /* Drag and Drop */
-    editorView = new QQuickWidget(this);
-    editorView->setClearColor(Qt::transparent);
-    QQmlContext* rootCtx = editorView->rootContext();
-    QQmlEngine* engine = editorView->engine();
-
-    intf_sys_t* p_sys = p_intf->p_sys;
-    MainInterface* mainInterface = p_sys->p_mi;
-
-    rootCtx->setContextProperty( "player", p_sys->p_mainPlayerController );
-    rootCtx->setContextProperty( "i18n", new I18n(engine) );
-    rootCtx->setContextProperty( "mainctx", new QmlMainContext(p_intf, mainInterface, engine));
-    rootCtx->setContextProperty( "mainInterface", mainInterface);
-    rootCtx->setContextProperty( "topWindow", mainInterface->windowHandle());
-    rootCtx->setContextProperty( "systemPalette", new SystemPalette(engine));
-    rootCtx->setContextProperty( "medialib", nullptr );
-    rootCtx->setContextProperty( "toolbareditor",  this);
-    rootCtx->setContextProperty( "rootPlayer", nullptr );
-
-    editorView->setSource( QUrl ( QStringLiteral("qrc:/dialogs/ToolbarEditor.qml") ) );
-
-    mainLayout->addWidget(editorView, 0, 0);
-
-    editorView->setResizeMode( QQuickWidget::SizeRootObjectToView );
-
-    mainLayout->addWidget( editorView, 1, 0, 1, 9 );
-    editorView->show();
-
-    /* Buttons */
-    QDialogButtonBox *okCancel = new QDialogButtonBox;
-    QPushButton *okButton = new QPushButton( qtr( "Cl&ose" ), this );
-    okButton->setDefault( true );
-    QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ), this );
-    okCancel->addButton( okButton, QDialogButtonBox::AcceptRole );
-    okCancel->addButton( cancelButton, QDialogButtonBox::RejectRole );
-
-    BUTTONACT( deleteButton, deleteProfile() );
-    BUTTONACT( newButton, newProfile() );
-    CONNECT( profileCombo, currentIndexChanged( int ), this, changeProfile( int ) );
-    BUTTONACT( okButton, close() );
-    BUTTONACT( cancelButton, cancel() );
-    mainLayout->addWidget( okCancel, 2, 0, 1, 9 );
-}
-ToolbarEditorDialog::~ToolbarEditorDialog()
-{
-    getSettings()->beginWriteArray( "ToolbarProfiles" );
-    for( int i = 0; i < profileCombo->count(); i++ )
-    {
-        getSettings()->setArrayIndex(i);
-        getSettings()->setValue( "ProfileName", profileCombo->itemText( i ) );
-        getSettings()->setValue( "Value", profileCombo->itemData( i ) );
-    }
-    getSettings()->endArray();
-}
-
-void ToolbarEditorDialog::close()
-{
-    emit saveConfig();
-    accept();
-}
-
-void ToolbarEditorDialog::cancel()
-{
-    reject();
-}
-
-void ToolbarEditorDialog::newProfile()
-{
-    bool ok;
-    QString name =  QInputDialog::getText( this, qtr( "Profile Name" ),
-                                           qtr( "Please enter the new profile name." ), QLineEdit::Normal, 0, &ok );
-    if( !ok ) return;
-
-    QVariant config;
-    QMetaObject::invokeMethod(editorView->rootObject(),"getProfileConfig",
-                              Q_RETURN_ARG(QVariant, config));
-
-    profileCombo->addItem( name, config.toString() );
-    profileCombo->setCurrentIndex( profileCombo->count() - 1 );
-}
-
-void ToolbarEditorDialog::deleteProfile()
-{
-    profileCombo->removeItem( profileCombo->currentIndex() );
-}
-
-void ToolbarEditorDialog::changeProfile( int i )
-{
-    QStringList qs_list = profileCombo->itemData( i ).toString().split( "|" );
-    if( qs_list.count() < 2 )
-        return;
-
-    QStringList align_list_main = qs_list[0].split("#");
-    QStringList align_list_mini = qs_list[1].split("#");
-
-    emit updatePlayerModel("MainPlayerToolbar-left", align_list_main[0]);
-    if(align_list_main.size() >= 2)
-        emit updatePlayerModel("MainPlayerToolbar-center", align_list_main[1]);
-    else
-        emit updatePlayerModel("MainPlayerToolbar-center", "");
-    if(align_list_main.size() >= 3)
-        emit updatePlayerModel("MainPlayerToolbar-right", align_list_main[2]);
-    else
-        emit updatePlayerModel("MainPlayerToolbar-right", "");
-
-    emit updatePlayerModel("MiniPlayerToolbar-left", align_list_mini[0]);
-    if(align_list_mini.size() >= 2)
-        emit updatePlayerModel("MiniPlayerToolbar-center", align_list_mini[1]);
-    else
-        emit updatePlayerModel("MiniPlayerToolbar-center", "");
-    if(align_list_mini.size() >= 3)
-        emit updatePlayerModel("MiniPlayerToolbar-right", align_list_mini[2]);
-    else
-        emit updatePlayerModel("MiniPlayerToolbar-right", "");
-}
diff --git a/modules/gui/qt/dialogs/toolbar/toolbareditor.hpp b/modules/gui/qt/dialogs/toolbar/toolbareditor.hpp
deleted file mode 100644
index 01d27b0efc..0000000000
--- a/modules/gui/qt/dialogs/toolbar/toolbareditor.hpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/*****************************************************************************
- * Copyright (C) 2019 VLC authors and VideoLAN
- *
- * 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_TOOLBAREDITOR_DIALOG_H_
-#define QVLC_TOOLBAREDITOR_DIALOG_H_ 1
-
-#include "widgets/native/qvlcframe.hpp"                                 /* QVLCDialog */
-#include "util/qml_main_context.hpp"
-#include "dialogs/sout/profile_selector.hpp"
-
-#include <QAbstractListModel>
-#include <QVector>
-#include <QQuickWidget>
-
-class ToolbarEditorDialog : public QVLCDialog
-{
-    Q_OBJECT
-public:
-    ToolbarEditorDialog( QWidget *, intf_thread_t *);
-    virtual ~ToolbarEditorDialog();
-
-public slots:
-    Q_INVOKABLE void close();
-    Q_INVOKABLE void cancel();
-
-private slots:
-    void newProfile();
-    void deleteProfile();
-    void changeProfile( int );
-
-private:
-    QComboBox *profileCombo;
-    QQuickWidget *editorView;
-
-signals:
-    void updatePlayerModel(QString toolbarName,QString config);
-    void saveConfig();
-};
-
-#endif
diff --git a/po/POTFILES.in b/po/POTFILES.in
index eafb5c6adb..d060836721 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -752,8 +752,6 @@ modules/gui/qt/dialogs/preferences/preferences.cpp
 modules/gui/qt/dialogs/preferences/preferences.hpp
 modules/gui/qt/dialogs/sout/sout.cpp
 modules/gui/qt/dialogs/sout/sout.hpp
-modules/gui/qt/dialogs/toolbar/toolbareditor.cpp
-modules/gui/qt/dialogs/toolbar/toolbareditor.hpp
 modules/gui/qt/dialogs/vlm/vlm.cpp
 modules/gui/qt/dialogs/vlm/vlm.hpp
 modules/gui/qt/dialogs/dialogs_provider.cpp
-- 
2.27.0



More information about the vlc-devel mailing list