[go: up one dir, main page]

File: domain.h

package info (click to toggle)
qgit 2.12-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,364 kB
  • sloc: cpp: 13,251; xml: 47; sh: 25; javascript: 16; makefile: 3
file content (161 lines) | stat: -rw-r--r-- 4,582 bytes parent folder | download
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
	Author: Marco Costalba (C) 2005-2007

	Copyright: See COPYING file that comes with this distribution

*/
#ifndef DOMAIN_H
#define DOMAIN_H

#include <QObject>
#include <QEvent>
#include "exceptionmanager.h"
#include "common.h"

#define UPDATE_DOMAIN(x)       QApplication::postEvent(x, new UpdateDomainEvent(false))
#define UPDATE()               QApplication::postEvent(this, new UpdateDomainEvent(false))
#define UPDATE_DM_MASTER(x, f) QApplication::postEvent(x, new UpdateDomainEvent(true, f))

class Domain;
class FileHistory;
class Git;
class MainImpl;

class UpdateDomainEvent : public QEvent {
public:
	explicit UpdateDomainEvent(bool fromMaster, bool force = false)
	: QEvent(fromMaster ? (QEvent::Type)QGit::UPD_DM_MST_EV
	                    : (QEvent::Type)QGit::UPD_DM_EV), f(force) {}
	bool isForced() const { return f; }
private:
	bool f;
};

class StateInfo {
public:
	StateInfo() { clear(); }
	StateInfo(const StateInfo& otherState);
	StateInfo& operator=(const StateInfo& newState);
	bool operator==(const StateInfo& newState) const;
	bool operator!=(const StateInfo& newState) const;
	void clear();
	const QString sha(bool n = true) const { return (n ? curS.sha : prevS.sha); }
	const QString fileName(bool n = true) const { return (n ? curS.fn : prevS.fn); }
	const QString diffToSha(bool n = true) const {return(n ? curS.dtSha : prevS.dtSha); }
	bool selectItem(bool n = true) const { return (n ? curS.sel : prevS.sel); }
	bool isMerge(bool n = true) const { return (n ? curS.isM : prevS.isM); }
	bool allMergeFiles(bool n = true) const { return (n ? curS.allM : prevS.allM); }
	void setSha(const QString& s) { if (isLocked) nextS.sha = s; else curS.sha = s; }
	void setFileName(const QString& s) { if (isLocked) nextS.fn = s; else curS.fn = s; }
	void setDiffToSha(const QString& s) { if (isLocked) nextS.dtSha = s; else curS.dtSha = s; }
	void setSelectItem(bool b) { if (isLocked) nextS.sel = b; else curS.sel = b; }
	void setIsMerge(bool b) { if (isLocked) nextS.isM = b; else curS.isM = b; }
	void setAllMergeFiles(bool b) { if (isLocked) nextS.allM = b; else curS.allM = b; }
	bool isChanged(uint what = ANY) const;

	enum Field {
		SHA             = 1,
		FILE_NAME       = 2,
		DIFF_TO_SHA     = 4,
		ALL_MERGE_FILES = 8,
		ANY             = 15
	};

private:
	friend class Domain;

	bool requestPending() const { return (!nextS.sha.isEmpty() && (nextS != curS)); }
	void setLock(bool b) { isLocked = b; if (b) nextS = curS; }
	void commit() { prevS = curS; }
	void rollBack() {
		if (nextS == curS)
			nextS.clear(); // invalidate to avoid infinite loop
		curS = prevS;
	}
	bool flushQueue() {
		if (requestPending()) {
			curS = nextS;
			return true;
		}
		return false;
	}

	class S {
	public:
		S() { clear(); }
		void clear();
		bool operator==(const S& newState) const;
		bool operator!=(const S& newState) const;

		QString sha;
		QString fn;
		QString dtSha;
		bool sel;
		bool isM;
		bool allM;
	};
	S curS;  // current state, what returns from StateInfo::sha()
	S prevS; // previous good state, used to rollBack in case state update fails
	S nextS; // next queued state, waiting for current update to finish
	bool isLocked;
};

class Domain: public QObject {
Q_OBJECT
public:
	Domain() {}
	Domain(MainImpl* m, Git* git, bool isMain);
	virtual ~Domain();
	void deleteWhenDone(); // will delete when no more run() are pending
	void showStatusBarMessage(const QString& msg, int timeout = 0);
	void setThrowOnDelete(bool b);
	bool isThrowOnDeleteRaised(int excpId, SCRef curContext);
	MainImpl* m() const;
	FileHistory* model() const { return fileHistory; }
	bool isLinked() const { return linked; }
	QWidget* tabPage() const { return container; }
	virtual bool isMatch(SCRef) { return false; }

	StateInfo st;

signals:
	void updateRequested(StateInfo newSt);
	void cancelDomainProcesses();

public slots:
	void on_closeAllTabs();

protected slots:
	virtual void on_contextMenu(const QString&, int);
	void on_updateRequested(StateInfo newSt);
	void on_deleteWhenDone();

protected:
	virtual void clear(bool complete = true);
	virtual bool event(QEvent* e);
	virtual bool doUpdate(bool force) = 0;
	void linkDomain(Domain* d);
	void unlinkDomain(Domain* d);
	void setTabCaption(const QString& caption);

	Git* git;
	QWidget* container;
	bool busy;

private:
	void populateState();
	void update(bool fromMaster, bool force);
	bool flushQueue();
	void sendPopupEvent();

	EM_DECLARE(exDeleteRequest);
	EM_DECLARE(exCancelRequest);

	FileHistory* fileHistory;
	bool linked;
	int popupType;
	QString popupData;
	QString statusBarRequest;
};

#endif