summaryrefslogtreecommitdiff
path: root/src/uilocker.h
diff options
context:
space:
mode:
authorChris Bessent <lost.dragonist@gmail.com>2020-01-06 05:17:01 -0700
committerGitHub <noreply@github.com>2020-01-06 05:17:01 -0700
commitdfa600996c49c1b23dca884c963dc917bd9cfc0a (patch)
treec6def4277cc962822d0dcde71fa9148e050f693f /src/uilocker.h
parente69078e2399a88bda7bb9ffae7a3d57db9a4e9cf (diff)
parentd1a788dfad341b32235abc25c2ba1645f8be1ace (diff)
Merge pull request #954 from ModOrganizer2/Develop
Stage for release 2.2.2
Diffstat (limited to 'src/uilocker.h')
-rw-r--r--src/uilocker.h96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/uilocker.h b/src/uilocker.h
new file mode 100644
index 00000000..cc467184
--- /dev/null
+++ b/src/uilocker.h
@@ -0,0 +1,96 @@
+#pragma once
+
+#include <QMainWindow>
+#include <mutex>
+
+class UILockerInterface;
+
+class UILocker
+{
+ friend class UILockerInterface;
+
+public:
+ // reason to show the widget
+ //
+ enum Reasons
+ {
+ NoReason = 0,
+
+ // lock the ui
+ LockUI,
+
+ // because the output is required
+ OutputRequired,
+
+ // to prevent exiting until all processes are completed
+ PreventExit
+ };
+
+ // returned by result()
+ //
+ enum Results
+ {
+ NoResult = 0,
+
+ // the widget is still up
+ StillLocked,
+
+ // force unlock was clicked
+ ForceUnlocked,
+
+ // cancel was clicked
+ Cancelled
+ };
+
+
+ class Session
+ {
+ public:
+ ~Session();
+
+ void unlock();
+ void setInfo(DWORD pid, const QString& name);
+ Results result() const;
+
+ DWORD pid() const;
+ const QString& name() const;
+
+ private:
+ mutable std::mutex m_mutex;
+ DWORD m_pid;
+ QString m_name;
+ };
+
+
+ UILocker();
+ ~UILocker();
+
+ static UILocker& instance();
+
+ void setUserInterface(QWidget* parent);
+
+ std::shared_ptr<Session> lock(Reasons reason);
+ bool locked() const;
+
+ Results result() const;
+
+private:
+ QWidget* m_parent;
+ std::unique_ptr<UILockerInterface> m_ui;
+ std::vector<std::weak_ptr<Session>> m_sessions;
+ std::atomic<Results> m_result;
+ std::vector<QPointer<QWidget>> m_disabled;
+
+ void createUi(Reasons reason);
+
+ void unlockCurrent();
+ void unlock(Session* s);
+ void updateLabel();
+
+ void onForceUnlock();
+ void onCancel();
+
+ void disableAll();
+ void enableAll();
+ void disable(QWidget* w);
+};