1 /*
2     This file is part of Android File Transfer For Linux.
3     Copyright (C) 2015-2020  Vladimir Menshakov
4 
5     This library is free software; you can redistribute it and/or modify it
6     under the terms of the GNU Lesser General Public License as published by
7     the Free Software Foundation; either version 2.1 of the License,
8     or (at your option) any later version.
9 
10     This library is distributed in the hope that it will be useful, but
11     WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13     Lesser General Public License for more details.
14 
15     You should have received a copy of the GNU Lesser General Public License
16     along with this library; if not, write to the Free Software Foundation,
17     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 #ifndef AFTL_QT_FILEUPLOADER_H
21 #define AFTL_QT_FILEUPLOADER_H
22 
23 #include <QObject>
24 #include <QThread>
25 #include <QDateTime>
26 #include <mtp/types.h>
27 #include <memory>
28 
29 class MtpObjectsModel;
30 struct Command;
31 class CommandQueue;
32 
33 namespace mtp
34 {
35 	struct ObjectId;
36 	class Library;
37 	DECLARE_PTR(Library);
38 }
39 
40 class FileUploader : public QObject
41 {
42 	Q_OBJECT
43 
44 private:
45 	MtpObjectsModel	*	_model;
46 	QThread				_workerThread;
47 	CommandQueue *		_worker;
48 	qint64				_total;
49 	QDateTime			_startedAt;
50 	bool				_aborted;
51 
52 private slots:
53 	void onTotal(qint64 total);
54 	void onProgress(qint64 current);
55 	void onStarted(const QString &file);
56 	void onFinished();
57 
58 public:
59 	explicit FileUploader(MtpObjectsModel * model, QObject *parent = 0);
60 	~FileUploader();
61 
62 	void tryCreateLibrary();
63 	mtp::LibraryPtr library() const;
64 
65 	void upload(QStringList files);
66 	void importMusic(const QString & path);
67 	void download(const QString &path, const QVector<mtp::ObjectId> & objectIds);
68 
69 public slots:
70 	void abort();
71 
72 signals:
73 	void executeCommand(Command *cmd);
74 
75 	//incoming signals (from worker)
76 	void uploadStarted(QString file);
77 	void uploadProgress(float);
78 	void uploadSpeed(qint64);
79 	void finished();
80 };
81 
82 #endif // FILEUPLOADER_H
83