00001
00002
00003
00004
00005
00006
00007 #ifndef DOMAIN_H
00008 #define DOMAIN_H
00009
00010 #include <qobject.h>
00011 #include "exceptionmanager.h"
00012 #include "common.h"
00013
00014 #define UPDATE_DOMAIN(x) QApplication::postEvent(x, new UpdateDomainEvent(false))
00015 #define UPDATE() QApplication::postEvent(this, new UpdateDomainEvent(false))
00016 #define UPDATE_DM_MASTER(x, f) QApplication::postEvent(x, new UpdateDomainEvent(true, f))
00017
00018 class Domain;
00019 class MainImpl;
00020 class Git;
00021
00022 class UpdateDomainEvent : public QCustomEvent {
00023 public:
00024 explicit UpdateDomainEvent(bool fromMaster, bool force = false)
00025 : QCustomEvent(fromMaster ? QGit::UPD_DM_MST_EV : QGit::UPD_DM_EV), f(force) {}
00026 bool isForced() const { return f; }
00027 private:
00028 bool f;
00029 };
00030
00031 class StateInfo {
00032 public:
00033 StateInfo() { clear(); }
00034 StateInfo& operator=(const StateInfo& newState);
00035 bool operator==(const StateInfo& newState) const;
00036 bool operator!=(const StateInfo& newState) const;
00037 void clear();
00038 const QString sha(bool n = true) const { return (n ? curS.sha : prevS.sha); }
00039 const QString fileName(bool n = true) const { return (n ? curS.fn : prevS.fn); }
00040 const QString diffToSha(bool n = true) const {return(n ? curS.dtSha : prevS.dtSha); }
00041 bool selectItem(bool n = true) const { return( n ? curS.sel : prevS.sel); }
00042 bool isMerge(bool n = true) const { return( n ? curS.isM : prevS.isM); }
00043 bool allMergeFiles(bool n = true) const { return( n ? curS.allM : prevS.allM); }
00044 void setSha(const QString& s) { if (isLocked) nextS.sha = s; else curS.sha = s; }
00045 void setFileName(const QString& s) { if (isLocked) nextS.fn = s; else curS.fn = s; }
00046 void setDiffToSha(const QString& s) { if (isLocked) nextS.dtSha = s; else curS.dtSha = s; }
00047 void setSelectItem(bool b) { if (isLocked) nextS.sel = b; else curS.sel = b; }
00048 void setIsMerge(bool b) { if (isLocked) nextS.isM = b; else curS.isM = b; }
00049 void setAllMergeFiles(bool b) { if (isLocked) nextS.allM = b; else curS.allM = b; }
00050 bool isChanged(uint what = ANY) const;
00051
00052 enum Field {
00053 SHA = 1,
00054 FILE_NAME = 2,
00055 DIFF_TO_SHA = 4,
00056 ALL_MERGE_FILES = 8,
00057 ANY = 15
00058 };
00059
00060 private:
00061 friend class Domain;
00062
00063 bool requestPending() const { return (!nextS.sha.isEmpty() && (nextS != curS)); }
00064 void setLock(bool b) { isLocked = b; if (b) nextS = curS; }
00065 void commit() { prevS = curS; }
00066 void rollBack() {
00067 if (nextS == curS)
00068 nextS.clear();
00069 curS = prevS;
00070 }
00071 bool flushQueue() {
00072 if (requestPending()) {
00073 curS = nextS;
00074 return true;
00075 }
00076 return false;
00077 }
00078
00079 class S {
00080 public:
00081 S() { clear(); }
00082 void clear();
00083 bool operator==(const S& newState) const;
00084 bool operator!=(const S& newState) const;
00085
00086 QString sha;
00087 QString fn;
00088 QString dtSha;
00089 bool sel;
00090 bool isM;
00091 bool allM;
00092 };
00093 S curS;
00094 S prevS;
00095 S nextS;
00096 bool isLocked;
00097 };
00098
00099 class Domain: public QObject {
00100 Q_OBJECT
00101 public:
00102 Domain() {}
00103 Domain(MainImpl* m, Git* git);
00104 void deleteWhenDone();
00105 void setThrowOnDelete(bool b);
00106 bool isThrowOnDeleteRaised(int excpId, SCRef curContext);
00107 MainImpl* m() const;
00108 const QString dragHostName() const;
00109 bool isReadyToDrag() const { return readyToDrag; }
00110 bool setReadyToDrag(bool b);
00111 bool isDragging() const { return dragging; }
00112 bool setDragging(bool b);
00113 bool isDropping() const { return dropping; }
00114 void setDropping(bool b) { dropping = b; }
00115 bool isLinked() const { return linked; }
00116 int tabPos() const { return tabPosition; }
00117 virtual QWidget* tab() = 0;
00118
00119 StateInfo st;
00120
00121 signals:
00122 void updateRequested(StateInfo newSt);
00123 void cancelDomainProcesses();
00124
00125 public slots:
00126 void on_closeAllTabs();
00127
00128 protected slots:
00129 virtual void on_contextMenu(const QString&, int);
00130 void on_tabClosed(int);
00131 void on_updateRequested(StateInfo newSt);
00132 void on_deleteWhenDone();
00133
00134 protected:
00135 virtual void customEvent(QCustomEvent* e);
00136 virtual bool doUpdate(bool force) = 0;
00137 void linkDomain(Domain* d);
00138 void unlinkDomain(Domain* d);
00139
00140 Git* git;
00141 bool busy;
00142 int tabPosition;
00143
00144 private:
00145 void populateState();
00146 void update(bool fromMaster, bool force);
00147 bool flushQueue();
00148 void sendPopupEvent();
00149
00150 EM_DECLARE(exDeleteRequest);
00151 EM_DECLARE(exCancelRequest);
00152
00153 bool readyToDrag;
00154 bool dragging;
00155 bool dropping;
00156 bool linked;
00157 int popupType;
00158 QString popupData;
00159 QString statusBarRequest;
00160 };
00161
00162 #endif