Author: sh-sh-sh
Date: Tue Feb 5 18:25:36 2008
New Revision: 44177
URL: http://svn.opensuse.org/viewcvs/yast?rev=44177&view=rev
Log:
moved YCP out of macro recording / playing
Added:
trunk/core/libyui/src/YCPMacroPlayer.cc
trunk/core/libyui/src/YCPMacroPlayer.h
trunk/core/libyui/src/YCPMacroRecorder.cc
trunk/core/libyui/src/YCPMacroRecorder.h
Removed:
trunk/core/libyui/src/YMacroPlayer.cc
trunk/core/libyui/src/YMacroPlayer.h
trunk/core/libyui/src/YMacroRecorder.cc
Modified:
trunk/core/libyui/src/Makefile.am
trunk/core/libyui/src/YMacroRecorder.h
trunk/core/libyui/src/YUI.h
trunk/core/libyui/src/YUI_builtins.cc
Modified: trunk/core/libyui/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/Makefile.am?rev=44177&r1=44176&r2=44177&view=diff
==============================================================================
--- trunk/core/libyui/src/Makefile.am (original)
+++ trunk/core/libyui/src/Makefile.am Tue Feb 5 18:25:36 2008
@@ -26,6 +26,8 @@
YCPTableItemWriter.cc \
YCPTreeItemParser.cc \
YCPTreeItemWriter.cc \
+ YCPMacroPlayer.cc \
+ YCPMacroRecorder.cc \
YCPPropertyHandler.cc \
YCPValueWidgetID.cc \
YCPWizardCommandParser.cc \
@@ -65,8 +67,6 @@
YLabel.cc \
YLayoutBox.cc \
YLogView.cc \
- YMacroPlayer.cc \
- YMacroRecorder.cc \
YMenuButton.cc \
YMultiLineEdit.cc \
YMultiProgressMeter.cc \
@@ -124,6 +124,8 @@
YCPTreeItem.h \
YCPTreeItemParser.h \
YCPTreeItemWriter.h \
+ YCPMacroPlayer.h \
+ YCPMacroRecorder.h \
YCPPropertyHandler.h \
YCPValueWidgetID.h \
YCPWizardCommandParser.h \
Added: trunk/core/libyui/src/YCPMacroPlayer.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YCPMacroPlayer.cc?rev=44177&view=auto
==============================================================================
--- trunk/core/libyui/src/YCPMacroPlayer.cc (added)
+++ trunk/core/libyui/src/YCPMacroPlayer.cc Tue Feb 5 18:25:36 2008
@@ -0,0 +1,131 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YCPMacroPlayer.cc
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define YUILogComponent "ui-macro"
+#include "YUILog.h"
+
+#include "YUISymbols.h"
+#include "YWidget.h"
+#include "YCPMacroPlayer.h"
+
+
+
+YCPMacroPlayer::YCPMacroPlayer( const string & macroFileName )
+ : YMacroPlayer( macroFileName )
+ , _macro( 0 )
+{
+ _nextBlockNo = -1;
+ readMacroFile( macroFileName );
+}
+
+
+YCPMacroPlayer::~YCPMacroPlayer()
+{
+ yuiDebug() << "Deleting macro player." << endl;
+}
+
+
+
+void YCPMacroPlayer::readMacroFile( const string & macroFileName )
+{
+ clearError();
+ FILE * macroFile = fopen( macroFileName.c_str(), "r" );
+
+ if ( ! macroFile )
+ {
+ setError();
+ yuiError() << "Can't open macro file " << macroFileName << endl;
+ return ;
+ }
+
+ yuiMilestone() << "Loading macro file " << macroFileName << endl;
+
+ Parser parser( macroFile, macroFileName.c_str() );
+ YCodePtr parsed = parser.parse();
+
+ if ( !parsed || parsed->isError() )
+ {
+ setError();
+ yuiError() << "Error parsing macro file " << macroFileName
+ << " -- macro execution aborted"
+ << endl;
+ return;
+ }
+
+ if ( !parsed->isBlock() )
+ {
+ setError();
+ yuiError() << "Macro syntax error in file " << macroFileName
+ << " -- expected YCP block"
+ << endl;
+ return;
+ }
+
+ _macro = static_cast <YBlockPtr> (parsed) ;
+
+ yuiDebug() << "Playing macro from file " << macroFileName
+ << " - " << _macro->statementCount() << " macro blocks"
+ << endl;
+ _nextBlockNo = 0;
+
+ fclose( macroFile );
+}
+
+
+bool YCPMacroPlayer::finished()
+{
+ if ( error() || !_macro || _nextBlockNo < 0 )
+ {
+ yuiWarning() << "Test for error() first before testing finished() !" << endl;
+ return true;
+ }
+ yuiDebug() << "_nextBlockNo: " << _nextBlockNo
+ << ", size: " << _macro->statementCount()
+ << ", finished(): " << boolalpha << ( _nextBlockNo >= _macro->statementCount() )
+ << endl;
+
+ return _nextBlockNo >= _macro->statementCount();
+}
+
+
+YCPValue YCPMacroPlayer::evaluateNextBlock()
+{
+ if ( error() || finished() )
+ {
+ return YCPNull();
+ }
+
+ yuiMilestone() << "Evaluating macro block #" << _nextBlockNo << endl;
+
+ return _macro->evaluate( _nextBlockNo++ );
+}
+
+
+void YCPMacroPlayer::rewind()
+{
+ _nextBlockNo = 0;
+}
+
Added: trunk/core/libyui/src/YCPMacroPlayer.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YCPMacroPlayer.h?rev=44177&view=auto
==============================================================================
--- trunk/core/libyui/src/YCPMacroPlayer.h (added)
+++ trunk/core/libyui/src/YCPMacroPlayer.h Tue Feb 5 18:25:36 2008
@@ -0,0 +1,97 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YCPMacroPlayer.h
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+#ifndef YCPMacroPlayer_h
+#define YCPMacroPlayer_h
+
+#include <string>
+#include
+#include "YMacroPlayer.h"
+
+
+class YCPMacroPlayer: public YMacroPlayer
+{
+public:
+
+ /**
+ * Constructor
+ **/
+ YCPMacroPlayer( const string & macroFileName );
+
+ /**
+ * Destructor
+ **/
+ virtual ~YCPMacroPlayer();
+
+ /**
+ * Report error status
+ **/
+ bool error() const { return _error; }
+
+ /**
+ * Returns "true" if the execution of the entire macro is finished.
+ * Undefined on error, so check for error() first!
+ **/
+ bool finished();
+
+ /**
+ * Return the result of the next macro block and increment the internal
+ * block counter. Returns YCPNull() on any previous error or if finished.
+ * Check for error() or finished() before calling this!
+ **/
+ YCPValue evaluateNextBlock();
+
+ /**
+ * Rewind macro execution - prepare to redo from start
+ **/
+ void rewind();
+
+protected:
+
+ /**
+ * Read and parse a macro file. Sets the internal "error" status.
+ **/
+ void readMacroFile( const string & macroFileName );
+
+ /**
+ * Clear error status
+ **/
+ void clearError() { _error = false; }
+
+ /**
+ * Set error status
+ **/
+ void setError() { _error = true; }
+
+ /**
+ * The parsed macro
+ **/
+ YBlockPtr _macro;
+
+ /**
+ * Error status
+ **/
+ bool _error;
+
+ /**
+ * Number of the next macro block to execute
+ **/
+ int _nextBlockNo;
+};
+
+#endif // YCPMacroPlayer_h
Added: trunk/core/libyui/src/YCPMacroRecorder.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YCPMacroRecorder.cc?rev=44177&view=auto
==============================================================================
--- trunk/core/libyui/src/YCPMacroRecorder.cc (added)
+++ trunk/core/libyui/src/YCPMacroRecorder.cc Tue Feb 5 18:25:36 2008
@@ -0,0 +1,344 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YCPMacroRecorder.cc
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define YUILogComponent "ui-macro"
+#include "YUILog.h"
+
+#include "YUISymbols.h"
+#include "YWidget.h"
+#include "YInputField.h"
+#include "YCPMacroRecorder.h"
+#include "YUIComponent.h"
+#include "YCPValueWidgetID.h"
+#include "YUI.h"
+#include "YUI_util.h"
+
+#ifndef Y2LOG_DATE
+# define Y2LOG_DATE "%Y-%m-%d %H:%M:%S" /* The date format */
+#endif
+
+
+
+#define YMACRO_INDENT " " // 4 blanks
+
+
+YCPMacroRecorder::YCPMacroRecorder( const string & macroFileName )
+ : YMacroRecorder( macroFileName )
+{
+ _screenShotCount = 0;
+ openMacroFile( macroFileName );
+ writeMacroFileHeader();
+}
+
+
+YCPMacroRecorder::~YCPMacroRecorder()
+{
+ writeMacroFileFooter();
+ closeMacroFile();
+}
+
+
+void YCPMacroRecorder::openMacroFile( const string & macroFileName )
+{
+ _macroFile = fopen( macroFileName.c_str(), "w" );
+
+ if ( _macroFile )
+ {
+ yuiMilestone() << "Recording macro to " << macroFileName << endl;
+ }
+ else
+ {
+ yuiError() << "Can't record to macro file " << macroFileName << endl;
+ }
+}
+
+
+void YCPMacroRecorder::closeMacroFile()
+{
+ if ( _macroFile )
+ {
+ fclose( _macroFile );
+ _macroFile = 0;
+ yuiMilestone() << "Macro recording done." << endl;
+ }
+}
+
+
+void YCPMacroRecorder::writeMacroFileHeader()
+{
+ if ( ! _macroFile )
+ return;
+
+ fprintf( _macroFile,
+ "// YaST2 UI macro file generated by UI macro recorder\n"
+ "//\n"
+ "// Qt UI: Alt-Ctrl-Shift-M: start/stop Macro recorder\n"
+ "// Alt-Ctrl-Shift-P: Play macro\n"
+ "//\n"
+ "// Each block will be executed just before the next UserInput().\n"
+ "// 'return' before the closing brace ( '}' ) of each block relinquishes control\n"
+ "// back to the YCP source.\n"
+ "// Inside each block arbitrary YCP code can be added manually.\n"
+ "\n"
+ "{\n"
+ );
+}
+
+
+void YCPMacroRecorder::writeMacroFileFooter()
+{
+ if ( ! _macroFile )
+ return;
+
+ fprintf( _macroFile, "}\n" );
+}
+
+
+void YCPMacroRecorder::recordYcpCodeLocation()
+{
+ extern ExecutionEnvironment ee; // YCP interpreter status
+ ExecutionEnvironment::CallStack callStack( ee.callstack() );
+
+ if ( ! callStack.empty() )
+ {
+ const CallFrame * frame = callStack.back();
+ string functionName;
+
+ if ( frame && frame->called_function.find( "Wizard::UserInput" ) == string::npos )
+ functionName = frame->called_function;
+
+ if ( frame )
+ {
+ if ( functionName.empty() )
+ {
+ fprintf( _macroFile, "%s%s// Source: %s:%d\n",
+ YMACRO_INDENT, YMACRO_INDENT,
+ frame->filename.c_str(),
+ frame->linenumber );
+ }
+ else
+ {
+ fprintf( _macroFile, "%s%s// Source: %s(%s):%d\n",
+ YMACRO_INDENT, YMACRO_INDENT,
+ frame->filename.c_str(),
+ functionName.c_str(),
+ frame->linenumber );
+ }
+ }
+ }
+}
+
+
+void YCPMacroRecorder::recordTimeStamp()
+{
+ time_t now_seconds = time (NULL);
+ struct tm *tm_now = localtime( &now_seconds );
+ char timeStamp[80]; // that's big enough
+ strftime( timeStamp, sizeof( timeStamp ), Y2LOG_DATE, tm_now );
+
+ fprintf( _macroFile, "%s%s// %s\n",
+ YMACRO_INDENT, YMACRO_INDENT,
+ timeStamp );
+}
+
+
+void YCPMacroRecorder::recordComment( string text )
+{
+ fprintf( _macroFile, "%s%s// %s\n",
+ YMACRO_INDENT, YMACRO_INDENT,
+ text.c_str() );
+}
+
+
+void YCPMacroRecorder::beginBlock()
+{
+ if ( ! _macroFile )
+ return;
+
+ fprintf( _macroFile, "%s{\n", YMACRO_INDENT );
+ fprintf( _macroFile, "%s%s//\n", YMACRO_INDENT, YMACRO_INDENT );
+ recordYcpCodeLocation();
+ recordTimeStamp();
+ fprintf( _macroFile, "\n" );
+}
+
+
+void YCPMacroRecorder::endBlock()
+{
+ if ( ! _macroFile )
+ return;
+
+ fprintf( _macroFile, "\n" );
+ fprintf( _macroFile, "%s%sreturn;\n", YMACRO_INDENT, YMACRO_INDENT );
+ fprintf( _macroFile, "%s}\n\n", YMACRO_INDENT );
+}
+
+
+void YCPMacroRecorder::recordUserInput( const YCPValue & input )
+{
+ if ( ! _macroFile )
+ return;
+
+ fprintf( _macroFile, "\n" );
+
+ recordMakeScreenShot();
+
+ if ( input->isVoid() )
+ {
+ fprintf( _macroFile, "%s%sUI::%s();\n",
+ YMACRO_INDENT, YMACRO_INDENT,
+ YUIBuiltin_FakeUserInput );
+ }
+ else
+ {
+ fprintf( _macroFile, "%s%sUI::%s( %s );\n",
+ YMACRO_INDENT, YMACRO_INDENT,
+ YUIBuiltin_FakeUserInput,
+ input->toString().c_str() );
+ }
+
+ fflush( _macroFile ); // sync to disk at this point - for debugging
+
+ yuiDebug() << "Input: " << input << endl;
+}
+
+
+void YCPMacroRecorder::recordMakeScreenShot( bool enabled, const string & fname )
+{
+ if ( ! _macroFile )
+ return;
+
+ // Automatically add a (commented out) UI::MakeScreenShot() statement.
+ //
+ // The screenshot goes to /tmp/yast2-*.png , but since that statement is
+ // commented out anyway this is not a security hazard - the user has to
+ // remove the comment characters to actually trigger any action upon macro
+ // replay, and while he is at it, he can also chose some other directory.
+ //
+ // All this is mainly for the SuSE documentation department anyway who will
+ // use that in a testing environment, not on some ultra-sensitive
+ // server. We need a good default directory here, not some academic
+ // bullshit discussion about creating temp directories with awkward names
+ // and unusable permissions on the fly. Been there, done that, works only
+ // for security theoreticians, not in real life. Those who devise such
+ // schemes never seem to use them in reality.
+ //
+ // End of discussion before it even starts. ;-)
+
+ string filename = fname;
+
+ if ( filename.empty() )
+ {
+ char buffer[256];
+ sprintf( buffer, "/tmp/yast2-%04d", _screenShotCount++ );
+ filename = string( buffer );
+ }
+
+ fprintf( _macroFile, "%s%s%sUI::%s( \"%s\" );\n",
+ YMACRO_INDENT, YMACRO_INDENT,
+ enabled ? "" : "// ",
+ YUIBuiltin_MakeScreenShot, filename.c_str() );
+}
+
+
+void YCPMacroRecorder::recordWidgetProperty( YWidget * widget,
+ const char * propertyName )
+{
+ if ( ! _macroFile )
+ return;
+
+ if ( ! widget )
+ {
+ yuiError() << "Null widget" << endl;
+ return;
+ }
+
+ if ( ! widget->isValid() )
+ {
+ yuiError() << "Invalid widget" << endl;
+ return;
+ }
+
+ if ( ! propertyName )
+ {
+ yuiError() << "Null property name" << endl;
+ return;
+ }
+
+ if ( ! widget->hasId() )
+ {
+ // It's pointless to save properties if the widget doesn't have an ID -
+ // there is no way to restore the property without an ID.
+
+ return;
+ }
+
+ YCPValueWidgetID * widgetId = dynamic_cast ( widget->id() );
+
+ if ( ! widgetId )
+ return;
+
+ YCPTerm idTerm( YUISymbol_id ); // `id()
+ idTerm->add( widgetId->value() ); // `id( `something )
+
+ YInputField * inputField = dynamic_cast (widget);
+
+ if ( inputField && inputField->passwordMode() )
+ {
+ // Don't record passwords in the macro file
+
+ string text = "UI::";
+ text += YUIBuiltin_ChangeWidget;
+ text += "( " + idTerm->toString() + ", \t`";
+ text += YUIProperty_Value;
+ text += ", \"<not recording password in plain text>\" );\t// ";
+ text += widget->widgetClass();
+ text += " \"" + widget->debugLabel() + "\"";
+
+ recordComment( text );
+ }
+ else
+ {
+ YCPValue val = YUI::ui()->evaluateQueryWidget( idTerm, YCPSymbol( propertyName ) );
+
+ fprintf( _macroFile, "%s%sUI::%s( %s,\t`%s,\t%s );\t// %s \"%s\"\n",
+ // UI::ChangeWidget( `id( `something ), `Value, 42 ) // YWidget
+ YMACRO_INDENT, YMACRO_INDENT,
+ YUIBuiltin_ChangeWidget,
+ idTerm->toString().c_str(),
+ propertyName,
+ val->toString().c_str(),
+ widget->widgetClass(),
+ widget->debugLabel().c_str() );
+
+ yuiDebug() << "Recording " << widget->widgetClass()
+ << " status: " << propertyName
+ << ": " << val
+ << endl;
+ }
+}
+
Added: trunk/core/libyui/src/YCPMacroRecorder.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YCPMacroRecorder.h?rev=44177&view=auto
==============================================================================
--- trunk/core/libyui/src/YCPMacroRecorder.h (added)
+++ trunk/core/libyui/src/YCPMacroRecorder.h Tue Feb 5 18:25:36 2008
@@ -0,0 +1,126 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YCPMacroRecorder.h
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+#ifndef YCPMacroRecorder_h
+#define YCPMacroRecorder_h
+
+#include
+#include
+#include
+#include "YMacroRecorder.h"
+
+class YWidget;
+
+class YCPMacroRecorder: public YMacroRecorder
+{
+public:
+
+ /**
+ * Constructor
+ **/
+ YCPMacroRecorder( const string & macroFileName );
+
+ /**
+ * Destructor
+ **/
+ virtual ~YCPMacroRecorder();
+
+ /**
+ * Record one widget property.
+ *
+ * Implemented from YMacroRecorder.
+ **/
+ virtual void recordWidgetProperty( YWidget * widget,
+ const char * propertyName );
+
+ /**
+ * Record a "UI::MakeScreenShot()" statement.
+ *
+ * If 'enabled' is 'false', this statement will be commented out.
+ * If no file name is given, a default file name (with auto-increment) will
+ * be used.
+ *
+ * Implemented from YMacroRecorder.
+ **/
+ virtual void recordMakeScreenShot( bool enabled = false,
+ const string & filename = string() );
+
+ /**
+ * Record one user input.
+ **/
+ void recordUserInput( const YCPValue & input );
+
+ /**
+ * Record a text as a comment.
+ **/
+ void recordComment( string comment_text );
+
+ /**
+ * Begin a macro block that will be executed as a whole.
+ **/
+ void beginBlock();
+
+ /**
+ * End a macro block that will be executed as a whole.
+ **/
+ void endBlock();
+
+protected:
+
+ /**
+ * Open the internally used macro file for writing.
+ *
+ * On error a message is issued to the log file.
+ * All write functions check the internally used macro file prior to using
+ * it, so it is perfectly safe to use them even if the initial open failed.
+ **/
+ void openMacroFile( const string & macroFileName );
+
+ /**
+ * Close the internally used macro file.
+ **/
+ void closeMacroFile();
+
+ /**
+ * Write a standardized macro file header.
+ **/
+ void writeMacroFileHeader();
+
+ /**
+ * Write a standardized macro file footer.
+ **/
+ void writeMacroFileFooter();
+
+ /**
+ * Record file name and line number of current YCP code
+ **/
+ void recordYcpCodeLocation();
+
+ /**
+ * Record a time stamp to match with y2logs
+ **/
+ void recordTimeStamp();
+
+ //
+ // Data members
+ //
+ FILE * _macroFile;
+ int _screenShotCount;
+};
+
+#endif // YCPMacroRecorder_h
Modified: trunk/core/libyui/src/YMacroRecorder.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YMacroRecorder.h?rev=44177&r1=44176&r2=44177&view=diff
==============================================================================
--- trunk/core/libyui/src/YMacroRecorder.h (original)
+++ trunk/core/libyui/src/YMacroRecorder.h Tue Feb 5 18:25:36 2008
@@ -19,40 +19,34 @@
#ifndef YMacroRecorder_h
#define YMacroRecorder_h
-#include
#include <string>
-#include
-#include
class YWidget;
+/**
+ * Abstract base class for macro recorders.
+ **/
class YMacroRecorder
{
-public:
+protected:
/**
* Constructor
**/
YMacroRecorder( const string & macroFileName );
+public:
/**
* Destructor
**/
virtual ~YMacroRecorder();
-
- /**
- * Record one user input.
- **/
- void recordUserInput( const YCPValue & input );
-
-
/**
* Record one widget property.
**/
- void recordWidgetProperty( YWidget * widget,
- const char * propertyName );
+ virtual void recordWidgetProperty( YWidget * widget,
+ const char * propertyName ) = 0;
/**
* Record a "UI::MakeScreenShot()" statement.
@@ -61,69 +55,8 @@
* If no file name is given, a default file name (with auto-increment) will
* be used.
**/
- void recordMakeScreenShot( bool enabled = false,
- const string & filename = string() );
-
- /**
- * Record a text as a comment.
- **/
- void recordComment( string comment_text );
-
- /**
- * Begin a macro block that will be executed as a whole.
- **/
- void beginBlock();
-
- /**
- * End a macro block that will be executed as a whole.
- **/
- void endBlock();
-
-protected:
-
- /**
- * Open the internally used macro file for writing.
- *
- * On error a message is issued to the log file.
- * All write functions check the internally used macro file prior to using
- * it, so it is perfectly safe to use them even if the initial open failed.
- **/
- void openMacroFile( const string & macroFileName );
-
- /**
- * Close the internally used macro file.
- **/
- void closeMacroFile();
-
- /**
- * Write a standardized macro file header.
- **/
- void writeMacroFileHeader();
-
- /**
- * Write a standardized macro file footer.
- **/
- void writeMacroFileFooter();
-
- /**
- * Record file name and line number of current YCP code
- **/
- void recordYcpCodeLocation();
-
- /**
- * Record a time stamp to match with y2logs
- **/
- void recordTimeStamp();
-
- /**
- * The internally used macro file; valid if non-null.
- **/
- FILE * _macroFile;
-
- /**
- * A counter for making screen shots.
- **/
- int _screenShotCount;
+ virtual void recordMakeScreenShot( bool enabled = false,
+ const string & filename = string() ) = 0;
};
#endif // YMacroRecorder_h
Modified: trunk/core/libyui/src/YUI.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YUI.h?rev=44177&r1=44176&r2=44177&view=diff
==============================================================================
--- trunk/core/libyui/src/YUI.h (original)
+++ trunk/core/libyui/src/YUI.h Tue Feb 5 18:25:36 2008
@@ -436,19 +436,19 @@
* Any previous active macro recorder will be terminated (regularly) prior
* to this.
**/
- void recordMacro( string filename );
+ virtual void recordMacro( string filename );
/**
* Stop macro recording if this is in progress.
* Nothing happens when no macro recording is in progress.
**/
- void stopRecordMacro();
+ virtual void stopRecordMacro();
/**
* Play macro in file "filename".
* Any previous macro execution will be terminated prior to this.
**/
- void playMacro( string filename );
+ virtual void playMacro( string filename );
/**
* Return whether macro recording is in progress or not
@@ -541,6 +541,16 @@
YCPValue evaluateCallback( const YCPTerm & term, bool to_wfm );
/**
+ * Set the internal macro recorder and delete any previous one.
+ **/
+ void setMacroRecorder( YMacroRecorder * recorder );
+
+ /**
+ * Set the internal macro player and delete any previous one.
+ **/
+ void setMacroPlayer( YMacroPlayer * player );
+
+ /**
* Delete the internal macro recorder and set the pointer to 0.
**/
void deleteMacroRecorder();
@@ -627,12 +637,12 @@
/**
* The current macro recorder.
**/
- YMacroRecorder *_macroRecorder;
+ YMacroRecorder * _macroRecorder;
/**
* The current macro player.
**/
- YMacroPlayer *_macroPlayer;
+ YMacroPlayer * _macroPlayer;
/**
* Queue for synthetic (faked) user input events.
Modified: trunk/core/libyui/src/YUI_builtins.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YUI_builtins.cc?rev=44177&r1=44176&r2=44177&view=diff
==============================================================================
--- trunk/core/libyui/src/YUI_builtins.cc (original)
+++ trunk/core/libyui/src/YUI_builtins.cc Tue Feb 5 18:25:36 2008
@@ -50,8 +50,8 @@
#include "YUIException.h"
#include "YUISymbols.h"
#include "YDialog.h"
-#include "YMacroRecorder.h"
-#include "YMacroPlayer.h"
+#include "YCPMacroRecorder.h"
+#include "YCPMacroPlayer.h"
#include "YReplacePoint.h"
#include "YShortcut.h"
#include "YWizard.h"
@@ -580,14 +580,19 @@
// Handle macro recording
- if ( _macroRecorder )
+ if ( recordingMacro() )
{
- if ( ! input->isVoid() || wait ) // Don't record empty PollInput() calls
+ YCPMacroRecorder * recorder = dynamic_cast ( macroRecorder() );
+
+ if ( recorder )
{
- _macroRecorder->beginBlock();
- dialog->saveUserInput( _macroRecorder );
- _macroRecorder->recordUserInput( input );
- _macroRecorder->endBlock();
+ if ( ! input->isVoid() || wait ) // Don't record empty PollInput() calls
+ {
+ recorder->beginBlock();
+ dialog->saveUserInput( _macroRecorder );
+ recorder->recordUserInput( input );
+ recorder->endBlock();
+ }
}
}
}
@@ -1161,22 +1166,27 @@
{
recordMacro( filename->value () );
}
-
-
+
+
void YUI::recordMacro( string filename )
{
- deleteMacroRecorder();
- _macroRecorder = new YMacroRecorder( filename );
+ YCPMacroRecorder * recorder = new YCPMacroRecorder( filename );
+ setMacroRecorder( recorder );
}
-void YUI::deleteMacroRecorder()
+void YUI::setMacroRecorder( YMacroRecorder * recorder )
{
if ( _macroRecorder )
- {
delete _macroRecorder;
- _macroRecorder = 0;
- }
+
+ _macroRecorder = recorder;
+}
+
+
+void YUI::deleteMacroRecorder()
+{
+ setMacroRecorder( 0 );
}
@@ -1202,6 +1212,7 @@
}
+
/**
* @builtin PlayMacro
* @short Plays a recorded macro
@@ -1221,30 +1232,36 @@
void YUI::playMacro( string filename )
{
- deleteMacroPlayer();
- _macroPlayer = new YMacroPlayer( filename );
+ YCPMacroPlayer * player = new YCPMacroPlayer( filename );
+ setMacroPlayer( player );
}
void YUI::playNextMacroBlock()
{
- if ( ! _macroPlayer )
+ YCPMacroPlayer * player = 0;
+
+ if ( macroPlayer() )
+ player = dynamic_cast ( macroPlayer() );
+
+ if ( ! player )
{
yuiError() << "No macro player active." << endl;
return;
}
- if ( _macroPlayer->error() || _macroPlayer->finished() )
+
+ if ( player->error() || player->finished() )
{
deleteMacroPlayer();
}
else
{
- if ( ! _macroPlayer->finished() )
+ if ( ! player->finished() )
{
- YCPValue result = _macroPlayer->evaluateNextBlock();
+ YCPValue result = player->evaluateNextBlock();
- if ( _macroPlayer->error() || result.isNull() )
+ if ( player->error() || result.isNull() )
{
yuiError() << "Macro aborted" << endl;
deleteMacroPlayer();
@@ -1254,13 +1271,18 @@
}
-void YUI::deleteMacroPlayer()
+void YUI::setMacroPlayer( YMacroPlayer * player )
{
if ( _macroPlayer )
- {
delete _macroPlayer;
- _macroPlayer = 0;
- }
+
+ _macroPlayer = player;
+}
+
+
+void YUI::deleteMacroPlayer()
+{
+ setMacroPlayer( 0 );
}
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org