[vlc-commits] qt: re-implement SoutChain in a more object-oriented way
Jérôme Froissart
git at videolan.org
Thu Oct 31 00:54:50 CET 2019
vlc | branch: master | Jérôme Froissart <software at froissart.eu> | Mon Oct 28 22:15:48 2019 +0100| [bc8853ad79ff20dd56921b49a642d1009e084ef7] | committer: Jean-Baptiste Kempf
qt: re-implement SoutChain in a more object-oriented way
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bc8853ad79ff20dd56921b49a642d1009e084ef7
---
modules/gui/qt/Makefile.am | 1 +
.../gui/qt/components/sout/profile_selector.cpp | 1 +
modules/gui/qt/components/sout/sout_widgets.cpp | 1 +
modules/gui/qt/dialogs/sout.hpp | 70 +---------
modules/gui/qt/util/soutchain.cpp | 113 ++++++++++++++++
modules/gui/qt/util/soutchain.hpp | 150 +++++++++++++++++++++
6 files changed, 267 insertions(+), 69 deletions(-)
diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index e8ce78a272..9fa20c4653 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -186,6 +186,7 @@ libqt_plugin_la_SOURCES = \
gui/qt/util/customwidgets.cpp gui/qt/util/customwidgets.hpp \
gui/qt/util/searchlineedit.cpp gui/qt/util/searchlineedit.hpp \
gui/qt/util/registry.cpp gui/qt/util/registry.hpp \
+ gui/qt/util/soutchain.cpp gui/qt/util/soutchain.hpp \
gui/qt/util/qt_dirs.cpp gui/qt/util/qt_dirs.hpp \
gui/qt/util/validators.cpp gui/qt/util/validators.hpp \
gui/qt/util/buttons/BrowseButton.cpp \
diff --git a/modules/gui/qt/components/sout/profile_selector.cpp b/modules/gui/qt/components/sout/profile_selector.cpp
index fca708d0c8..82c3eaa1a8 100644
--- a/modules/gui/qt/components/sout/profile_selector.cpp
+++ b/modules/gui/qt/components/sout/profile_selector.cpp
@@ -24,6 +24,7 @@
#include "components/sout/profile_selector.hpp"
#include "components/sout/profiles.hpp"
#include "dialogs/sout.hpp"
+#include "util/soutchain.hpp"
#include <QHBoxLayout>
#include <QToolButton>
diff --git a/modules/gui/qt/components/sout/sout_widgets.cpp b/modules/gui/qt/components/sout/sout_widgets.cpp
index 86528283cf..50e096c81f 100644
--- a/modules/gui/qt/components/sout/sout_widgets.cpp
+++ b/modules/gui/qt/components/sout/sout_widgets.cpp
@@ -25,6 +25,7 @@
#include "components/sout/sout_widgets.hpp"
#include "dialogs/sout.hpp"
+#include "util/soutchain.hpp"
#include "util/qt_dirs.hpp"
#include <vlc_intf_strings.h>
diff --git a/modules/gui/qt/dialogs/sout.hpp b/modules/gui/qt/dialogs/sout.hpp
index e57aa39bc8..b0c38c2e25 100644
--- a/modules/gui/qt/dialogs/sout.hpp
+++ b/modules/gui/qt/dialogs/sout.hpp
@@ -31,80 +31,12 @@
#include "ui_sout.h"
#include "util/qvlcframe.hpp"
+#include "util/soutchain.hpp"
#include <QWizard>
class QPushButton;
-class SoutChain
-{
-public:
- SoutChain( const QString& head = "")
- {
- mrl = head;
- b_first = true;
- b_has_bracket = false;
- }
-
- QString to_string()
- {
- return mrl;
- }
-
- void begin( const QString& module )
- {
- if( !b_first )
- mrl += ":";
- b_first = false;
-
- mrl += module;
- b_has_bracket = false;
- }
- void end()
- {
- if( b_has_bracket )
- mrl += "}";
- }
- void option( const QString& option, const QString& value = "" )
- {
- if( !b_has_bracket )
- mrl += "{";
- else
- mrl += ",";
- b_has_bracket = true;
-
- mrl += option;
-
- if( !value.isEmpty() )
- {
- char *psz = config_StringEscape( qtu(value) );
- if( psz )
- {
- mrl += "=" + qfu( psz );
- free( psz );
- }
- }
- }
- void option( const QString& name, const int i_value, const int i_precision = 10 )
- {
- option( name, QString::number( i_value, i_precision ) );
- }
- void option( const QString& name, const double f_value )
- {
- option( name, QString::number( f_value ) );
- }
-
- void option( const QString& name, const QString& base, const int i_value, const int i_precision = 10 )
- {
- option( name, base + ":" + QString::number( i_value, i_precision ) );
- }
-
-private:
- QString mrl;
- bool b_has_bracket;
- bool b_first;
-};
-
class SoutDialog : public QWizard
{
diff --git a/modules/gui/qt/util/soutchain.cpp b/modules/gui/qt/util/soutchain.cpp
new file mode 100644
index 0000000000..8fd906d903
--- /dev/null
+++ b/modules/gui/qt/util/soutchain.cpp
@@ -0,0 +1,113 @@
+/*****************************************************************************
+ * soutchain.cpp: A class to generate Stream Output Chains
+ ****************************************************************************
+ * Copyright (C) 2019 Jérôme Froissart <software at froiss.art>
+ *
+ * Authors: Jérôme Froissart <software at froiss.art>
+ *
+ * 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.
+ *****************************************************************************/
+
+#include "soutchain.hpp"
+
+QString SoutModule::to_string() const
+{
+ QString s = moduleName;
+
+ if( options.size() > 0 )
+ {
+ s += "{";
+ }
+ OptionsType::const_iterator it;
+ for( it=options.begin(); it!=options.end(); )
+ {
+ s += it->first;
+ if( it->second.to_string().compare("") != 0 )
+ {
+ char *psz = config_StringEscape( qtu(it->second.to_string()) );
+ if( psz )
+ {
+ s += "=" + qfu( psz );
+ free( psz );
+ }
+ }
+ ++it;
+ if( it != options.end() )
+ {
+ s += ",";
+ }
+ }
+ if( options.size() > 0 )
+ {
+ s += "}";
+ }
+ return s;
+}
+
+void SoutModule::option( const QString& option, const SoutOption& value )
+{
+ options.append( OptionPairType( option, value ) );
+}
+void SoutModule::option( const QString& option )
+{
+ options.append( OptionPairType( option, "" ) );
+}
+
+QString SoutChain::getHeader() const
+{
+ return hdr;
+}
+
+QString SoutChain::to_string() const
+{
+ QString chain = hdr;
+ for( int m=0; m<modules.size(); m++ )
+ {
+ chain += modules[m].to_string();
+ if( m < modules.size() - 1 )
+ {
+ chain += ":";
+ }
+ }
+
+ return chain;
+}
+
+void SoutChain::option( const QString& name, const QString& value )
+{
+ if( modules.size() > 0 )
+ {
+ modules.back().option( name, value );
+ }
+}
+void SoutChain::option( const QString& name, const int i_value, const int i_precision )
+{
+ option( name, QString::number( i_value, i_precision ) );
+}
+void SoutChain::option( const QString& name, const double f_value )
+{
+ option( name, QString::number( f_value ) );
+}
+void SoutChain::option( const QString& name, const QString& base, const int i_value, const int i_precision )
+{
+ option( name, base + ":" + QString::number( i_value, i_precision ) );
+}
+void SoutChain::option( const QString& name, const SoutModule& nested )
+{
+ if( modules.size() > 0 )
+ {
+ modules.back().option( name, nested );
+ }
+}
\ No newline at end of file
diff --git a/modules/gui/qt/util/soutchain.hpp b/modules/gui/qt/util/soutchain.hpp
new file mode 100644
index 0000000000..2bfac37764
--- /dev/null
+++ b/modules/gui/qt/util/soutchain.hpp
@@ -0,0 +1,150 @@
+/*****************************************************************************
+ * soutchain.hpp: A class to generate Stream Output Chains
+ ****************************************************************************
+ * Copyright (C) 2019 Jérôme Froissart <software at froiss.art>
+ *
+ * Authors: Jérôme Froissart <software at froiss.art>
+ *
+ * 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 VLC_QT_SOUTCHAIN_HPP_
+#define VLC_QT_SOUTCHAIN_HPP_
+
+#include "qt.hpp"
+
+#include <QMap>
+
+
+class SoutOption;
+
+class SoutModule
+{
+public:
+ SoutModule( const QString& name ) :
+ moduleName( name )
+ {
+ }
+
+ void option( const QString& option, const SoutOption& value );
+ void option( const QString& option );
+ QString to_string() const;
+
+private:
+ typedef QPair<QString, SoutOption> OptionPairType;
+ typedef QList<OptionPairType> OptionsType;
+ const QString moduleName;
+ OptionsType options;
+};
+
+
+class SoutOption
+{
+public:
+ SoutOption( const QString& value ) :
+ kind( String ),
+ stringValue( value ),
+ nestedModule("")
+ {}
+
+ SoutOption( const char* s ) :
+ SoutOption( QString(s) )
+ {}
+
+ SoutOption( const SoutModule& module ) :
+ kind(Nested),
+ nestedModule(module)
+ {}
+
+ QString to_string() const{
+ if( kind == String )
+ {
+ return stringValue;
+ }
+ else
+ {
+ return nestedModule.to_string();
+ }
+ }
+
+private:
+ enum Kind{ String, Nested };
+ const Kind kind;
+ const QString stringValue;
+ const SoutModule nestedModule;
+};
+
+
+/// This class helps building MRLs
+///
+/// An MRL has the following structure:
+/// * a header
+/// * any number of modules, which have
+/// - a name
+/// - any number of key(=value) pairs
+/// values can be nested modules
+///
+/// Example of MRL: HEADERmodule1{a,b=val}:module2:module3{opt,arg=\"value with automatically escaped quotes\",stuff=nestedModule{subkey=subvalue}}
+class SoutChain
+{
+public:
+ SoutChain( const QString& header="" ) :
+ hdr(header)
+ {
+ }
+
+ void clear()
+ {
+ hdr = "";
+ modules.clear();
+ }
+
+ void header( const QString& newHeader )
+ {
+ hdr = newHeader;
+ }
+
+ SoutModule& begin( const QString& module )
+ {
+ modules.append( SoutModule( module ) );
+ return modules.back();
+ }
+
+ // Useless, kept for compatibility with an older API
+ void end()
+ {
+ }
+
+ void module( const SoutModule& module )
+ {
+ modules.append( module );
+ }
+
+ // These should be only in SoutModule, but they are kept in this parent class for compatibility with an older API
+ void option( const QString& name, const QString& value = "" );
+ void option( const QString& name, const int i_value, const int i_precision = 10 );
+ void option( const QString& name, const double f_value );
+ void option( const QString& name, const QString& base, const int i_value, const int i_precision = 10 );
+ void option( const QString& name, const SoutModule& nested );
+
+ QString getHeader() const;
+ QString to_string() const;
+
+private:
+ QString hdr;
+ QList<SoutModule> modules;
+};
+
+#endif // include guard
More information about the vlc-commits
mailing list