libktorrent  2.2.0
preallocationthread.h
1 /***************************************************************************
2  * Copyright (C) 2005 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef BTPREALLOCATIONTHREAD_H
21 #define BTPREALLOCATIONTHREAD_H
22 
23 #include <qstring.h>
24 #include <qthread.h>
25 #include <qmap.h>
26 #include <qmutex.h>
27 #include <util/constants.h>
28 #include "cachefile.h"
29 #include "ktorrent_export.h"
30 
31 
32 
33 namespace bt
34 {
35 
41  class KTORRENT_EXPORT PreallocationThread : public QThread
42  {
43  public:
44  PreallocationThread();
45  ~PreallocationThread() override;
46 
48  void add(CacheFile::Ptr cache_file);
49 
50  void run() override;
51 
55  void stop();
56 
61  void setErrorMsg(const QString & msg);
62 
64  bool isStopped() const;
65 
67  bool errorHappened() const;
68 
70  const QString & errorMessage() const {return error_msg;}
71 
73  void written(Uint64 nb);
74 
76  Uint64 bytesWritten();
77 
79  void setNotFinished();
80 
82  bool isNotFinished() const;
83 
85  bool isDone() const;
86  private:
87  bool expand(const QString & path, Uint64 max_size);
88 
89  private:
90  QList<CacheFile::Ptr> todo;
91  bool stopped, not_finished, done;
92  QString error_msg;
93  Uint64 bytes_written;
94  mutable QMutex mutex;
95  };
96 
97 }
98 
99 #endif