6 #include <QCoreApplication>
13 #include <QTextCursor>
14 #include <QMessageBox>
15 #include <QApplication>
19 UserActionManager* UserActionManager::inst =
nullptr;
21 UserActionManager::UserActionManager(
QObject *parent)
22 :
QObject(parent), mStartRecording(-1),
23 mRecordHashAttribute(true),
25 mThreadedAction(nullptr)
28 mSettingDumpAction =
new SettingsItemCheckbox(
32 "eXpert Settings:Debug",
33 "Specifies whether hal opens an extra window to list all executed instances of UserAction"
35 connect(mSettingDumpAction,&SettingsItemCheckbox::boolChanged,
this,&UserActionManager::handleSettingDumpActionChanged);
39 void UserActionManager::executeActionBlockThread(
UserAction *act)
43 mThreadedAction = act;
44 Q_EMIT triggerExecute();
48 void UserActionManager::handleTriggerExecute()
50 mThreadedAction->exec();
53 void UserActionManager::handleSettingDumpActionChanged(
bool wantDump)
55 if (!wantDump && mDumpAction)
57 mDumpAction->deleteLater();
58 mDumpAction =
nullptr;
62 void UserActionManager::addExecutedAction(
UserAction* act)
64 mActionHistory.append(act);
66 if (mSettingDumpAction->value().toBool())
75 mDumpAction->insertPlainText(act->
debugDump());
81 void UserActionManager::setStartRecording()
83 mStartRecording = mActionHistory.size();
86 void UserActionManager::crashDump(
int sig)
89 mRecordHashAttribute =
false;
90 setStopRecording(
QString(
"hal_crashdump_signal%1.xml").arg(sig));
95 int n = mActionHistory.size();
96 if (
n>mStartRecording && !macroFilename.
isEmpty())
106 for (
int i=mStartRecording; i<
n; i++)
112 if (mRecordHashAttribute)
134 QMessageBox::warning(qApp->activeWindow(),
"Save Macro Failed",
"Cannot save macro to file\n<" + macroFilename +
">",
137 mStartRecording = -1;
141 mStartRecording = -1;
145 void UserActionManager::playMacro(
const QString& macroFilename)
148 bool parseActions =
false;
151 mStartRecording = mActionHistory.size();
152 while (!xmlIn.
atEnd())
158 if (xmlIn.
name() ==
"actions")
160 else if (parseActions)
163 if (act) mActionHistory.append(act);
168 if (xmlIn.
name() ==
"actions")
169 parseActions =
false;
179 int endMacro = mActionHistory.size();
180 for (
int i=mStartRecording; i<endMacro; i++)
189 mStartRecording = -1;
199 qDebug() <<
"cannot parse user action" << actionTagName;
217 bool UserActionManager::hasRecorded()
const
219 return isRecording() && mActionHistory.size() > mStartRecording;
222 bool UserActionManager::isRecording()
const
224 return mStartRecording >= 0;
229 mActionFactory.insert(fac->
tagname(),fac);
238 void UserActionManager::testUndo()
240 bool yesWeCan =
true;
241 if (mActionHistory.isEmpty())
245 auto it = mActionHistory.end() - 1;
247 while (it != mActionHistory.begin() &&
248 (*it)->undoAction() &&
249 (*it)->compoundOrder() > 0)
251 if (!(*it)->undoAction())
254 Q_EMIT canUndoLastAction(yesWeCan);
257 void UserActionManager::undoLastAction()
259 if (mActionHistory.isEmpty())
return;
261 while (!mActionHistory.isEmpty())
263 UserAction* lastAction = mActionHistory.takeLast();
270 int n = mActionHistory.size();
273 while (mActionHistory.size() >
n)
274 mActionHistory.takeLast();
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this submitted means any form of or written communication sent to the Licensor or its including but not limited to communication on electronic mailing source code control and issue tracking systems that are managed or on behalf of
The UserActionFactory is the abstract base class for registration.
virtual UserAction * newAction() const =0
The UserAction class is the abstract base class for user interactions.
virtual QString tagname() const =0
int compoundOrder() const
QString debugDump() const
QString cryptographicHash(int recordNo) const
virtual void setObject(const UserActionObject &obj)
void setCompoundOrder(int cmpord)
virtual void readFromXml(QXmlStreamReader &xmlIn)
UserAction * undoAction() const
virtual void writeToXml(QXmlStreamWriter &xmlOut) const
virtual UserActionObject object() const
Handles and manages user actions related proccesses.
The UserActionObject class represents a single object used in UserAction.
void readFromXml(QXmlStreamReader &xmlIn)
void writeToXml(QXmlStreamWriter &xmlOut) const
#define log_warning(channel,...)
void append(const T &value)
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
bool isEmpty() const const
QString number(int n, int base)
std::string toStdString() const const
bool isEmpty() const const
bool isNull() const const
int toInt(bool *ok, int base) const const
QString toString() const const
QStringRef value(const QString &namespaceUri, const QString &name) const const
QXmlStreamAttributes attributes() const const
bool hasError() const const
bool isEndElement() const const
bool isStartElement() const const
QStringRef name() const const
QXmlStreamReader::TokenType readNext()
void writeAttribute(const QString &qualifiedName, const QString &value)
void writeStartDocument()
void writeStartElement(const QString &qualifiedName)