summaryrefslogtreecommitdiffstats
path: root/consistencycheck.h
blob: b62dfbc2d5e11a2500e8a8aa9cbd3229bd8ce9ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version
  2 of the License, or (at your option) any later version.
*/

#ifndef CONSISTENCYCHECK_H
#define CONSISTENCYCHECK_H

#include <QThread>
#include <QSqlDatabase>
#include <QMutex>
#include <QStringList>
#include <QList>

#include "smdialog.h"

class QPushButton;
class QPlainTextEdit;
class QLabel;
class QString;
class QSqlQuery;
class QFileInfo;
class ConsistencyChecker;

class ConsistencyCheck : public SmDialog {
    Q_OBJECT
	public:
		enum Mode { DbCheck, FsCheck };
		explicit ConsistencyCheck(QWidget *parent = 0, Qt::WindowFlags f = 0);

	private slots:
		void startChecker(int checkerType);
		void addMessage(const QString &message);
		void checkerStarted();
		void checkerFinished();
		void cancelChecker();
		void cleanup();

	private:
		void moveFiles(const QStringList &files);
		QPushButton *mCancelExit;
		QPushButton *mCheckDb;
		QPushButton *mCheckFs;
		QPushButton *mCleanup;
		QPlainTextEdit *mOkDisplay;
		QPlainTextEdit *mErrorDisplay;
		ConsistencyChecker *mChecker;
};

class ConsistencyChecker : public QThread {
	Q_OBJECT
	public:
		enum Status { Ok, Fail };
		explicit ConsistencyChecker(QObject *parent = 0);
		~ConsistencyChecker();
		int mode() const { return mMode; }
		void setMode(int mode) { mMode = mode; }
		int status() const { return mStatus; }
		void setStatus(int status) { mStatus = status; }
		void check();
		const QStringList strayFiles();
		void clearStrayFiles();
		const QList<int> strayIds();
		void clearStrayIds();

	public slots:
		void setCancel(bool cancel);
		void deleteIds(const QList<int> &ids);

	private slots:
		void dbCheck();
		void fsCheck();

	signals:
		void consistencyMsg(const QString &msg);

	protected:
		void run();

	private:
		QString archivePath(const QString &fileName, const QString &md5sum) const;
		void doFsCheck(const QFileInfo &start);
		bool mCanceled;
		int mMode;
		int mStatus;
		QSqlDatabase mDb;
		QSqlQuery *mFileQuery;
		QMutex mCancelMutex;
		QMutex mStrayFilesMutex;
		QMutex mStrayIdsMutex;
		QStringList mStrayFiles;
		QList<int> mStrayIds;
};

#endif // CONSISTENCYCHECK_H