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

0001 /****************************************************************************************
0002  * Copyright (c) 2012 Matěj Laitl <matej@laitl.cz>                                      *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef STATSYNCING_PROCESS_H
0018 #define STATSYNCING_PROCESS_H
0019 
0020 #include "statsyncing/Options.h"
0021 #include "statsyncing/Provider.h"
0022 
0023 #include <QDialog>
0024 #include <QMap>
0025 #include <QPointer>
0026 
0027 #include <ThreadWeaver/Queue>
0028 #include <ThreadWeaver/Job>
0029 #include <ThreadWeaver/ThreadWeaver>
0030 
0031 class QDialog;
0032 namespace ThreadWeaver {
0033     class Job;
0034 }
0035 
0036 namespace StatSyncing
0037 {
0038     class ChooseProvidersPage;
0039     class MatchedTracksModel;
0040     class MatchedTracksPage;
0041     class ProvidersModel;
0042 
0043     /**
0044      * Class that is responsible for one synchronization process from track matching
0045      * to committing synchronized values back to storage. This class should live in a main
0046      * thread and is event-based.
0047      *
0048      * Process auto-deletes itself when it is done with its work.
0049      */
0050     class Process : public QObject
0051     {
0052         Q_OBJECT
0053 
0054         public:
0055             enum Mode {
0056                 Interactive,
0057                 NonInteractive,
0058             };
0059 
0060             /**
0061              * Creates the synchronization process that will offer user to synchronize
0062              * @p checkedFields of @p providers. If @p mode is Interactive,
0063              * introductory dialog will be shown that allows subset of fields and
0064              * providers to be chosen. Otherwise performs the syncing in the background
0065              * and shows a window only if conflict occurs.
0066              * @param providers the providers
0067              * @param preSelectedProviders the preselected providers
0068              * @param checkedFields the fields
0069              * @param mode the mode
0070              * @param parent the parent QObject
0071              */
0072             Process( const ProviderPtrList &providers, const ProviderPtrSet &preSelectedProviders,
0073                      qint64 checkedFields, Mode mode, QObject *parent = nullptr );
0074             ~Process() override;
0075 
0076         public Q_SLOTS:
0077             /**
0078              * Starts the process.
0079              */
0080             void start();
0081 
0082             /**
0083              * Raises and activates possible UI window related to this synchronization
0084              * process.
0085              */
0086             void raise();
0087 
0088         private Q_SLOTS:
0089             void slotMatchTracks();
0090             void slotTracksMatched( ThreadWeaver::JobPointer job );
0091             void slotBack();
0092             void slotSynchronize();
0093             void slotLogSynchronization( ThreadWeaver::JobPointer job );
0094             void slotSaveSizeAndDelete();
0095             void slotDeleteDialog();
0096 
0097         private:
0098             Q_DISABLE_COPY( Process )
0099 
0100             Mode m_mode;
0101             Options m_options;
0102             ProvidersModel *m_providersModel;
0103             qint64 m_checkedFields;
0104             MatchedTracksModel *m_matchedTracksModel;
0105             TrackList m_tracksToScrobble;
0106 
0107             // gets deleted when MainWindow is deleted
0108             QPointer<QDialog> m_dialog;
0109             QPointer<ChooseProvidersPage> m_providersPage;
0110             QPointer<MatchedTracksPage> m_tracksPage;
0111     };
0112 
0113 } // namespace StatSyncing
0114 
0115 #endif // STATSYNCING_PROCESS_H