File indexing completed on 2024-05-05 04:48:27

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Téo Mrnjavac <teo@kde.org>                                        *
0003  * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0004  * Copyright (c) 2009 Daniel Dewald <Daniel.Dewald@time.shift.de>                       *
0005  * Copyright (c) 2012 Ralf Engels <ralf-engels@gmx.de>                                  *
0006  *                                                                                      *
0007  * This program is free software; you can redistribute it and/or modify it under        *
0008  * the terms of the GNU General Public License as published by the Free Software        *
0009  * Foundation; either version 2 of the License, or (at your option) any later           *
0010  * version.                                                                             *
0011  *                                                                                      *
0012  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0013  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0014  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0015  *                                                                                      *
0016  * You should have received a copy of the GNU General Public License along with         *
0017  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0018  ****************************************************************************************/
0019 
0020 #ifndef TAGGUESSERDIALOG_H
0021 #define TAGGUESSERDIALOG_H
0022 
0023 #include "amarok_export.h"
0024 #include "widgets/FilenameLayoutWidget.h"
0025 
0026 #include "ui_TagGuessOptions.h"
0027 
0028 #include <QDialog>
0029 
0030 #include <QMap>
0031 #include <QString>
0032 
0033 class QLabel;
0034 class QFileInfo;
0035 class TagGuessOptionWidget : public QWidget, public Ui::TagGuessOptions
0036 {
0037     Q_OBJECT
0038 
0039     public:
0040         explicit TagGuessOptionWidget( QWidget *parent = nullptr );
0041 
0042         int getCaseOptions();
0043         bool getWhitespaceOptions();
0044         bool getUnderscoreOptions();
0045 
0046     Q_SIGNALS:
0047         void changed();
0048 
0049     private Q_SLOTS:
0050         // Handles the radiobuttons
0051         void editStateEnable( bool checked );
0052 
0053     private:
0054         QList<QRadioButton*> m_caseEditRadioButtons;
0055 };
0056 
0057 
0058 
0059 /** This widget allows the user to define a filename scheme from which to guess tags. */
0060 class AMAROK_EXPORT TagGuesserWidget : public FilenameLayoutWidget
0061 {
0062     Q_OBJECT
0063 
0064     public:
0065         explicit TagGuesserWidget( QWidget *parent = nullptr );
0066         ~TagGuesserWidget() override {}
0067 
0068     protected:
0069         Token* createToken(qint64 value) const override;
0070 };
0071 
0072 
0073 class AMAROK_EXPORT TagGuesserDialog : public QDialog
0074 {
0075     Q_OBJECT
0076 
0077     public:
0078         explicit TagGuesserDialog( const QString &fileName, QWidget *parent = nullptr );
0079 
0080         QMap<qint64,QString> guessedTags();
0081 
0082         /** Sets the filename to show colored preview from. */
0083         void setFileName( const QString& fileName );
0084 
0085     public Q_SLOTS:
0086         virtual void onAccept();
0087 
0088     private Q_SLOTS:
0089         /** Updates the result texts and the colored filename. */
0090         void updatePreview();
0091 
0092     private:
0093 
0094         /** @Returns a filename with the same number of directory
0095             levels as the scheme.
0096             Also removes the extension.
0097         */
0098         QString parsableFileName( const QFileInfo &fileInfo ) const;
0099 
0100         /** @Returns the fileName with added path. */
0101         QString getParsableFileName();
0102 
0103         /**
0104         *   @Returns a colored version of the filename
0105         */
0106         QString coloredFileName(const QMap<qint64, QString> &tags );
0107 
0108         /**
0109          * @Returns color name for specified metadata field
0110          */
0111         static QString fieldColor( qint64 field );
0112 
0113 
0114         /** Filename to guess from. */
0115         QString m_fileName;
0116 
0117         TagGuesserWidget* m_layoutWidget;
0118         QLabel* m_filenamePreview;
0119         TagGuessOptionWidget* m_optionsWidget;
0120 };
0121 
0122 
0123 #endif /* TAGGUESSERDIALOG_H */
0124