1 /*
2 	Author: Marco Costalba (C) 2005-2007
3 
4 	Copyright: See COPYING file that comes with this distribution
5 
6 */
7 #ifndef ANNOTATE_H
8 #define ANNOTATE_H
9 
10 #include <QObject>
11 #include <QTime>
12 #include "exceptionmanager.h"
13 #include "common.h"
14 
15 class Git;
16 class FileHistory;
17 class MyProcess;
18 
19 
20 class RangeInfo {
21 public:
RangeInfo()22 	RangeInfo() { clear(); }
RangeInfo(int s,int e,bool m)23 	RangeInfo(int s, int e, bool m) : start(s), end(e), modified(m) {}
clear()24 	void clear() { start = end = 0; modified = false; }
25 	int start, end; // ranges count file lines from 1 like patches diffs
26 	bool modified;
27 };
28 typedef QHash<QString, RangeInfo> Ranges;
29 
30 class Annotate : public QObject {
31 Q_OBJECT
32 public:
33 	Annotate(Git* parent, QObject* guiObj);
34 	void deleteWhenDone();
35 	const FileAnnotation* lookupAnnotation(SCRef sha);
36 	bool start(const FileHistory* fh);
isCanceled()37 	bool isCanceled() { return canceled; }
38 	const QString getAncestor(SCRef sha, int* shaIdx);
39 	bool getRange(SCRef sha, RangeInfo* r);
40 	bool seekPosition(int* rangeStart, int* rangeEnd, SCRef fromSha, SCRef toSha);
41 	const QString computeRanges(SCRef sha, int paraFrom, int paraTo, SCRef target = "");
42 
43 signals:
44 	void annotateReady(Annotate*, bool, const QString&);
45 
46 private slots:
47 	void on_deleteWhenDone();
48 	void slotComputeDiffs();
49 
50 private:
51 	void annotateFileHistory();
52 	void doAnnotate(const ShaString& sha);
53 	FileAnnotation* getFileAnnotation(SCRef sha);
54 	void setInitialAnnotation(SCRef fileSha, FileAnnotation* fa);
55 	const QString setupAuthor(SCRef origAuthor, int annId);
56 	bool setAnnotation(SCRef diff, SCRef aut, SCList pAnn, SList nAnn, int ofs = 0);
57 	bool getNextLine(SCRef d, int& idx, QString& line);
58 	static void unify(SList dst, SCList src);
59 	const QString getPatch(SCRef sha, int parentNum = 0);
60 	bool getNextSection(SCRef d, int& idx, QString& sec, SCRef target);
61 	void updateRange(RangeInfo* r, SCRef diff, bool reverse);
62 	void updateCrossRanges(SCRef cnk, bool rev, int oStart, int oLineCnt, RangeInfo* r);
63 	bool isDescendant(SCRef sha, SCRef target);
64 
65 	EM_DECLARE(exAnnCanceled);
66 
67 	Git* git;
68 	QObject* gui;
69 	const FileHistory* fh;
70 	AnnotateHistory ah;
71 	bool cancelingAnnotate;
72 	bool annotateRunning;
73 	bool annotateActivity;
74 	bool isError;
75 	int annNumLen;
76 	int annId;
77 	int annFilesNum;
78 	ShaVect histRevOrder; // TODO use reference
79 	bool valid;
80 	bool canceled;
81 	QTime processingTime;
82 	Ranges ranges;
83 };
84 
85 #endif
86