27 #define USE_QT_CURSORS 1 28 #define FORCE_UNICODE_FONT 0 34 #include <QFileDialog> 36 #include <QMessageBox> 38 #include <QInputDialog> 43 #define YUILogComponent "qt-ui" 44 #include <yui/YUILog.h> 47 #include <yui/YEvent.h> 48 #include <yui/YMacro.h> 49 #include <yui/YUISymbols.h> 51 #include "YQSignalBlocker.h" 52 #include "YQApplication.h" 60 #define DEFAULT_MACRO_FILE_NAME "macro.ycp" 66 YUI_CHECK_PTR( packageSelector );
71 event = packageSelector->findDialog()->waitForEvent();
73 catch ( YUIException & uiEx )
77 catch ( std::exception & e)
79 yuiError() <<
"Caught std::exception: " << e.what() <<
"\n" 80 <<
"This is a libzypp problem. Do not file a bug against the UI!" 85 yuiError() <<
"Caught unspecified exception.\n" 86 <<
"This is a libzypp problem. Do not file a bug against the UI!" 100 QWidget * dialog = (QWidget *) YDialog::currentDialog()->widgetRep();
101 QWindow * window = dialog->windowHandle();
102 QPixmap screenShot = window->screen()->grabWindow( window->winId() );
103 XSync( QX11Info::display(),
false );
104 QString fileName ( stl_filename.c_str() );
105 bool interactive =
false;
107 if ( fileName.isEmpty() )
114 if ( screenShotNameTemplate.isEmpty() )
120 QString home = QDir::homePath();
121 char * ssdir = getenv(
"Y2SCREENSHOTS" );
122 QString dir = ssdir ? fromUTF8( ssdir ) :
"yast2-screen-shots";
135 if ( mkdir( toUTF8( dir ).c_str(), 0700 ) == -1 )
144 dir = home +
"/" + dir;
145 (void) mkdir( toUTF8( dir ).c_str(), 0750 );
148 screenShotNameTemplate = dir +
"/%s-%03d.png";
156 const char * baseName =
"yast2";
158 int no = screenShotNo[ baseName ];
159 fileName.sprintf( qPrintable( screenShotNameTemplate ), baseName, no );
160 yuiDebug() <<
"Screenshot: " << fileName << std::endl;
165 _(
"Save screen shot to..." ) );
168 if ( fileName.isEmpty() )
170 yuiDebug() <<
"Save screen shot canceled by user" << std::endl;
174 screenShotNo.insert( baseName, ++no );
182 yuiDebug() <<
"Saving screen shot to " << fileName << std::endl;
183 bool success = screenShot.save( fileName,
"PNG" );
187 yuiError() <<
"Couldn't save screen shot " << fileName << std::endl;
192 YDialog * currentDialog = YDialog::currentDialog(
false );
195 parent = (QWidget *) currentDialog->widgetRep();
197 QMessageBox::warning( parent,
199 QString(
"Couldn't save screen shot\nto %1" ).arg( fileName ),
200 QMessageBox::Ok | QMessageBox::Default,
211 QString(
"*.tgz *.tar.gz" ),
212 QString(
"Save y2logs to..." ) );
215 YDialog * currentDialog = YDialog::currentDialog(
false );
218 parent = (QWidget *) currentDialog->widgetRep();
220 if ( ! fileName.isEmpty() )
222 QString saveLogsCommand =
"/usr/sbin/save_y2logs";
224 if ( access( saveLogsCommand.toLatin1(), X_OK ) == 0 )
226 saveLogsCommand +=
" '" + fileName +
"'";
227 yuiMilestone() <<
"Saving y2logs: " << saveLogsCommand << std::endl;
228 int result = system( qPrintable( saveLogsCommand ) );
232 yuiError() <<
"Error saving y2logs: \"" << saveLogsCommand
233 <<
"\" exited with " << result
236 QMessageBox::warning( parent,
238 QString(
"Couldn't save y2logs to %1 - " 239 "exit code %2" ).arg( fileName ).arg( result ),
240 QMessageBox::Ok | QMessageBox::Default,
241 QMessageBox::NoButton,
242 QMessageBox::NoButton );
246 yuiMilestone() <<
"y2logs saved to " << fileName << std::endl;
251 yuiError() <<
"Error saving y2logs: Command \"" 252 << saveLogsCommand <<
"\" not found" 255 QMessageBox::warning( parent,
257 QString(
"Couldn't save y2logs to %1:\n" 258 "Command %2 not found" ).arg( fileName ).arg( saveLogsCommand ),
259 QMessageBox::Ok | QMessageBox::Default,
260 QMessageBox::NoButton,
261 QMessageBox::NoButton );
269 bool okButtonPressed =
false;
271 items <<
"Debug logging off" 272 <<
"Debug logging on";
276 YDialog * currentDialog = YDialog::currentDialog(
false );
279 parent = (QWidget *) currentDialog->widgetRep();
281 QString result = QInputDialog::getItem( parent,
283 _(
"Configure YaST Logging:"),
285 YUILog::debugLoggingEnabled() ? 1 : 0,
287 if ( okButtonPressed )
289 YUILog::enableDebugLogging( result.endsWith(
"on" ) );
290 yuiMilestone() <<
"Changing logging: " << result << std::endl;
298 YDialog * currentDialog = YDialog::currentDialog(
false );
301 parent = (QWidget *) currentDialog->widgetRep();
304 if ( YMacro::recording() )
306 YMacro::endRecording();
309 QMessageBox::information( parent,
310 "YaST2 Macro Recorder",
311 "Macro recording done.",
312 QMessageBox::Ok | QMessageBox::Default,
313 QMessageBox::NoButton,
314 QMessageBox::NoButton );
321 QFileDialog::getSaveFileName( parent,
322 "Select Macro File to Record to",
323 DEFAULT_MACRO_FILE_NAME,
326 QFileDialog::DontUseNativeDialog
329 if ( ! filename.isEmpty() )
331 YMacro::record( toUTF8( filename ) );
342 YDialog * currentDialog = YDialog::currentDialog(
false );
345 parent = (QWidget *) currentDialog->widgetRep();
349 QFileDialog::getOpenFileName( parent,
350 "Select Macro File to Play",
351 DEFAULT_MACRO_FILE_NAME,
352 "*.ycp", 0, QFileDialog::DontUseNativeDialog );
355 if ( ! filename.isEmpty() )
357 YMacro::play( toUTF8( filename ) );
void askConfigureLogging()
Open dialog to configure logging.
void makeScreenShot(std::string filename)
Make a screen shot in .png format and save it to 'filename'.
void askSaveLogs()
Open file selection box and let the user save y2logs to that location.
virtual YEvent * runPkgSelection(YWidget *packageSelector)
UI-specific runPkgSeleciton method: Start the package selection.
void toggleRecordMacro()
Toggle macro recording (activated by Ctrl-Shift-Alt-M): Stop macro recording if it is in progress...
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
virtual std::string askForSaveFileName(const std::string &startWith, const std::string &filter, const std::string &headline)
Open a file selection box and prompt the user for a file to save data to.
void busyCursor()
Show mouse cursor indicating busy state.
void normalCursor()
Show normal mouse cursor not indicating busy status.
void askPlayMacro()
Open file selection box and ask for a macro file to play (activated by Ctrl-Shift-Alt-P) ...