File indexing completed on 2024-05-05 04:49:26

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Téo Mrnjavac <teo@kde.org>                                        *
0003  * Copyright (c) 2009 Daniel Dewald <Daniel.Dewald@time-shift.de>                       *
0004  * Copyright (c) 2012 Ralf Engels <ralf-engels@gmx.de>                                  *
0005  *                                                                                      *
0006  * This program is free software; you can redistribute it and/or modify it under        *
0007  * the terms of the GNU General Public License as published by the Free Software        *
0008  * Foundation; either version 2 of the License, or (at your option) any later           *
0009  * version.                                                                             *
0010  *                                                                                      *
0011  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0012  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0013  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0014  *                                                                                      *
0015  * You should have received a copy of the GNU General Public License along with         *
0016  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0017  ****************************************************************************************/
0018 
0019 #ifndef FILENAMELAYOUTWIDGET_H
0020 #define FILENAMELAYOUTWIDGET_H
0021 
0022 #include "amarok_export.h"
0023 
0024 #include <QWidget>
0025 
0026 class Token;
0027 class TokenPool;
0028 class TokenDropTarget;
0029 
0030 class QStackedWidget;
0031 class QLabel;
0032 class QFrame;
0033 class QComboBox;
0034 class QPushButton;
0035 class QVBoxLayout;
0036 class QHBoxLayout;
0037 
0038 class QLineEdit;
0039 
0040 //Holds the TokenLayoutWidget and TokenPool and handles their interaction. Also holds a number of case and substitution options for the filename scheme.
0041 class AMAROK_EXPORT FilenameLayoutWidget : public QWidget
0042 {
0043     Q_OBJECT
0044 
0045     public:
0046 
0047         enum Type
0048         {
0049               Unknown = 0
0050             , Ignore
0051             , TrackNumber
0052             , Title
0053             , Artist
0054             , Composer
0055             , Year
0056             , Album
0057             , AlbumArtist
0058             , Comment
0059             , Genre
0060             , FileType
0061             , Folder
0062             , Initial
0063             , DiscNumber
0064             , Space
0065             , Slash
0066             , Dot
0067             , Dash
0068             , Underscore
0069             , CollectionRoot
0070         };
0071 
0072         explicit FilenameLayoutWidget( QWidget *parent = nullptr );
0073         ~FilenameLayoutWidget() override {}
0074 
0075         QString getParsableScheme() const;
0076 
0077         void setScheme( const QString &scheme );
0078 
0079     public Q_SLOTS:
0080         virtual void onAccept();
0081 
0082     Q_SIGNALS:
0083         /** emitted when either the scheme, option checkboxes or the replace edits change */
0084         void schemeChanged();
0085 
0086     private Q_SLOTS:
0087         void toggleAdvancedMode();
0088 
0089         /* Updates the update preset button */
0090         void slotUpdatePresetButton();
0091         void slotFormatPresetSelected( int );
0092         void slotAddFormat();
0093         void slotRemoveFormat();
0094         void slotUpdateFormat();
0095 
0096     private:
0097         /** Set the advanced mode, blending out several "advanced" widgets */
0098         void setAdvancedMode( bool isAdvanced );
0099 
0100         /* Iterates over the elements of the TokenLayoutWidget bar
0101            (really over the elements of a QList that stores the indexes
0102            of the tokens) and generates a string that TagGuesser can digest. */
0103         QString dropTargetScheme() const;
0104 
0105         /** Fills the m_dropTarget according to the given string scheme. */
0106         void inferScheme( const QString &scheme );
0107 
0108         bool m_advancedMode;
0109 
0110     protected:
0111 
0112         /** Set's several configuration options.
0113             Don't move this function to the constructor. It calls virtuals. */
0114         void populateConfiguration();
0115 
0116         /** Populates the preset combo box */
0117         void populateFormatList( const QString &custom );
0118 
0119         /** Saves the preset combo box */
0120         void saveFormatList() const;
0121 
0122         virtual Token* createToken(qint64 value) const;
0123 
0124         /** Returns a styled token to be used in as pre and
0125             postfix on the schema editing line. */
0126         virtual Token* createStaticToken(qint64 value) const;
0127 
0128         QVBoxLayout *m_mainLayout;
0129 
0130         QComboBox *m_presetCombo;
0131         QPushButton *m_addPresetButton;
0132         QPushButton *m_updatePresetButton;
0133         QPushButton *m_removePresetButton;
0134 
0135         QPushButton *m_advancedButton;
0136 
0137         TokenPool *m_tokenPool;
0138         QStackedWidget *m_schemeStack;
0139         QHBoxLayout *m_schemaLineLayout;
0140         TokenDropTarget *m_dropTarget;
0141 
0142         QLabel *m_syntaxLabel;
0143         QFrame *m_filenameLayout;
0144         QLineEdit *m_filenameLayoutEdit;
0145 
0146         /** The name of the category used for storing the configuration */
0147         QString m_configCategory;
0148 };
0149 
0150 
0151 #endif    //FILENAMELAYOUTWIDGET_H
0152