1 /* This file is part of Clementine.
2    Copyright 2010, David Sansome <me@davidsansome.com>
3 
4    Clementine is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8 
9    Clementine is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef ORGANISEDIALOG_H
19 #define ORGANISEDIALOG_H
20 
21 #include <memory>
22 
23 #include <QDialog>
24 #include <QFuture>
25 #include <QMap>
26 #include <QUrl>
27 
28 #include "gtest/gtest_prod.h"
29 
30 #include "core/organise.h"
31 #include "core/organiseformat.h"
32 #include "core/song.h"
33 #include "library/librarybackend.h"
34 
35 class LibraryWatcher;
36 class OrganiseErrorDialog;
37 class TaskManager;
38 class Ui_OrganiseDialog;
39 class LibraryBackend;
40 
41 class QAbstractItemModel;
42 
43 class OrganiseDialog : public QDialog {
44   Q_OBJECT
45 
46  public:
47   OrganiseDialog(TaskManager* task_manager, LibraryBackend* backend = nullptr,
48                  QWidget* parent = nullptr);
49   ~OrganiseDialog();
50 
51   static const char* kDefaultFormat;
52   static const char* kSettingsGroup;
53 
54   QSize sizeHint() const;
55 
56   void SetDestinationModel(QAbstractItemModel* model, bool devices = false);
57 
58   // These functions return true if any songs were actually added to the dialog.
59   // SetSongs returns immediately, SetUrls and SetFilenames load the songs in
60   // the background.
61   bool SetSongs(const SongList& songs);
62   bool SetUrls(const QList<QUrl>& urls);
63   bool SetFilenames(const QStringList& filenames);
64 
65   void SetCopy(bool copy);
66 
67 signals:
68   void FileCopied(int);
69 
70  public slots:
71   void accept();
72 
73  protected:
74   void showEvent(QShowEvent*);
75   void resizeEvent(QResizeEvent*);
76 
77  private slots:
78   void Reset();
79 
80   void InsertTag(const QString& tag);
81   void UpdatePreviews();
82 
83   void OrganiseFinished(const QStringList& files_with_errors);
84 
85  private:
86   SongList LoadSongsBlocking(const QStringList& filenames);
87   void SetLoadingSongs(bool loading);
88 
89   static Organise::NewSongInfoList ComputeNewSongsFilenames(
90       const SongList& songs, const OrganiseFormat& format);
91 
92   Ui_OrganiseDialog* ui_;
93   TaskManager* task_manager_;
94   LibraryBackend* backend_;
95 
96   OrganiseFormat format_;
97 
98   QFuture<SongList> songs_future_;
99   SongList songs_;
100   Organise::NewSongInfoList new_songs_info_;
101   quint64 total_size_;
102 
103   std::unique_ptr<OrganiseErrorDialog> error_dialog_;
104 
105   bool resized_by_user_;
106 
107   FRIEND_TEST(OrganiseDialogTest, ComputeNewSongsFilenamesTest);
108 };
109 
110 #endif  // ORGANISEDIALOG_H
111