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

0001 /****************************************************************************************
0002  * Copyright (c) 2006 Mike Diehl <madpenguin8@yahoo.com>                                *
0003  * Copyright (c) 2008 Téo Mrnjavac <teo@kde.org>                                        *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #ifndef AMAROK_ORGANIZECOLLECTIONDIALOG_H
0019 #define AMAROK_ORGANIZECOLLECTIONDIALOG_H
0020 
0021 #include "amarok_export.h"
0022 #include "core/meta/forward_declarations.h"
0023 
0024 #include "widgets/FilenameLayoutWidget.h"
0025 #include "ui_OrganizeCollectionOptions.h"
0026 
0027 #include <QDialog>
0028 #include <QDialogButtonBox>
0029 #include <QWidget>
0030 
0031 namespace Ui
0032 {
0033     class OrganizeCollectionDialogBase;
0034 }
0035 
0036 class TrackOrganizer;
0037 
0038 
0039 /** A couple of options used in the filename layout dialog and the UmsCollection configuration dialog. */
0040 class AMAROK_EXPORT OrganizeCollectionOptionWidget : public QGroupBox, public Ui::OrganizeCollectionsOptions
0041 {
0042     Q_OBJECT
0043 
0044     public:
0045         explicit OrganizeCollectionOptionWidget( QWidget *parent = nullptr );
0046 
0047         bool asciiOnly() const { return asciiCheck->isChecked(); }
0048         void setAsciiOnly( bool enable ) { asciiCheck->setChecked( enable ); }
0049         bool vfatCompatible() const { return vfatCheck->isChecked(); }
0050         void setVfatCompatible( bool enable ) { vfatCheck->setChecked( enable ); }
0051         bool postfixThe() const { return ignoreTheCheck->isChecked(); }
0052         void setPostfixThe( bool enable ) { ignoreTheCheck->setChecked( enable ); }
0053         bool replaceSpaces() const { return spaceCheck->isChecked(); }
0054         void setReplaceSpaces( bool enable ) { spaceCheck->setChecked( enable ); }
0055         QString regexpText() const { return regexpEdit->text(); }
0056         void setRegexpText( const QString &text ) { regexpEdit->setText( text ); }
0057         QString replaceText() const { return replaceEdit->text(); }
0058         void setReplaceText( const QString &text ) { replaceEdit->setText( text ); }
0059 
0060     Q_SIGNALS:
0061         void optionsChanged();
0062 };
0063 
0064 
0065 /** A FilenameLayoutWidget that set's the needed tokens for organizing a collection.
0066     Note: This widget is also used in the UmsCollection dialog at
0067     src/core-impl/collections/umsCollection/UmsCollection.cpp */
0068 class AMAROK_EXPORT OrganizeCollectionWidget : public FilenameLayoutWidget
0069 {
0070     Q_OBJECT
0071 
0072     public:
0073         explicit OrganizeCollectionWidget( QWidget *parent = nullptr );
0074         ~OrganizeCollectionWidget() override {}
0075 
0076     protected:
0077         QString buildFormatTip() const;
0078 };
0079 
0080 
0081 class AMAROK_EXPORT OrganizeCollectionDialog : public QDialog
0082 {
0083     Q_OBJECT
0084 
0085     public:
0086 
0087         explicit OrganizeCollectionDialog( const Meta::TrackList &tracks,
0088                                            const QStringList &folders,
0089                                            const QString &targetExtension = QString(),
0090                                            QWidget *parent = nullptr,
0091                                            const char *name = nullptr,
0092                                            bool modal = true,
0093                                            const QString &caption = QString(),
0094                                            QFlags<QDialogButtonBox::StandardButton> buttonMask = QDialogButtonBox::Ok|QDialogButtonBox::Cancel );
0095 
0096         ~OrganizeCollectionDialog() override;
0097 
0098         QMap<Meta::TrackPtr, QString> getDestinations() const;
0099         bool overwriteDestinations() const;
0100 
0101     public Q_SLOTS:
0102         void slotUpdatePreview();
0103         void slotDialogAccepted();
0104 
0105     private Q_SLOTS:
0106         void processPreviewPaths();
0107         void previewNextBatch();
0108         void slotOverwriteModeChanged();
0109 
0110     private:
0111         QString buildFormatString() const;
0112 
0113         Ui::OrganizeCollectionDialogBase *ui;
0114 
0115         TrackOrganizer *m_trackOrganizer;
0116         Meta::TrackList m_allTracks;
0117         QString m_targetFileExtension;
0118 
0119         QStringList m_originals;
0120         QStringList m_previews;
0121         QString m_previewPrefix;
0122         bool m_conflict;
0123 
0124     private Q_SLOTS:
0125         void slotEnableOk( int currentCollectionRootIndex );
0126 };
0127 
0128 #endif  //AMAROK_ORGANIZECOLLECTIONDIALOG_H