6 #include <QCoreApplication>
14 #include <QTextCursor>
15 #include <QMessageBox>
16 #include <QApplication>
20 UserActionManager* UserActionManager::inst =
nullptr;
22 UserActionManager::UserActionManager(
QObject *parent)
23 :
QObject(parent), mStartRecording(-1),
24 mRecordHashAttribute(true),
26 mThreadedAction(nullptr)
29 mSettingDumpAction =
new SettingsItemCheckbox(
33 "eXpert Settings:Debug",
34 "Specifies whether hal opens an extra window to list all executed instances of UserAction"
36 connect(mSettingDumpAction,&SettingsItemCheckbox::boolChanged,
this,&UserActionManager::handleSettingDumpActionChanged);
40 void UserActionManager::executeActionBlockThread(
UserAction *act)
46 mThreadedAction = act;
47 Q_EMIT triggerExecute();
54 void UserActionManager::handleTriggerExecute()
56 mThreadedAction->exec();
59 void UserActionManager::handleSettingDumpActionChanged(
bool wantDump)
61 if (!wantDump && mDumpAction)
63 mDumpAction->deleteLater();
64 mDumpAction =
nullptr;
68 void UserActionManager::addExecutedAction(
UserAction* act)
70 mActionHistory.append(act);
72 if (mSettingDumpAction->value().toBool())
81 mDumpAction->insertPlainText(act->
debugDump());
87 void UserActionManager::setStartRecording()
89 mStartRecording = mActionHistory.size();
92 void UserActionManager::crashDump(
int sig)
95 mRecordHashAttribute =
false;
96 setStopRecording(
QString(
"hal_crashdump_signal%1.xml").arg(sig));
101 int n = mActionHistory.size();
102 if (
n>mStartRecording && !macroFilename.
isEmpty())
112 for (
int i=mStartRecording; i<
n; i++)
118 if (mRecordHashAttribute)
140 QMessageBox::warning(qApp->activeWindow(),
"Save Macro Failed",
"Cannot save macro to file\n<" + macroFilename +
">",
143 mStartRecording = -1;
147 mStartRecording = -1;
151 void UserActionManager::playMacro(
const QString& macroFilename)
154 bool parseActions =
false;
157 mStartRecording = mActionHistory.size();
158 while (!xmlIn.
atEnd())
164 if (xmlIn.
name() ==
"actions")
166 else if (parseActions)
169 if (act) mActionHistory.append(act);
174 if (xmlIn.
name() ==
"actions")
175 parseActions =
false;
185 int endMacro = mActionHistory.size();
186 for (
int i=mStartRecording; i<endMacro; i++)
195 mStartRecording = -1;
205 qDebug() <<
"cannot parse user action" << actionTagName;
223 bool UserActionManager::hasRecorded()
const
225 return isRecording() && mActionHistory.size() > mStartRecording;
228 bool UserActionManager::isRecording()
const
230 return mStartRecording >= 0;
235 mActionFactory.insert(fac->
tagname(),fac);
244 void UserActionManager::testUndo()
246 bool yesWeCan =
true;
247 if (mActionHistory.isEmpty())
251 auto it = mActionHistory.end() - 1;
253 while (it != mActionHistory.begin() &&
254 (*it)->undoAction() &&
255 (*it)->compoundOrder() > 0)
257 if (!(*it)->undoAction())
260 Q_EMIT canUndoLastAction(yesWeCan);
263 void UserActionManager::undoLastAction()
265 if (mActionHistory.isEmpty())
return;
267 while (!mActionHistory.isEmpty())
269 UserAction* lastAction = mActionHistory.takeLast();
276 int n = mActionHistory.size();
279 while (mActionHistory.size() >
n)
280 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
QThread * currentThread()
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)