27 #define USE_QT_CURSORS 1
28 #define FORCE_UNICODE_FONT 0
34 #include <QFileDialog>
36 #include <QMessageBox>
38 #include <QInputDialog>
41 #define YUILogComponent "qt-ui"
42 #include <yui/YUILog.h>
45 #include <yui/YEvent.h>
46 #include <yui/YMacro.h>
47 #include <yui/YUISymbols.h>
49 #include "YQSignalBlocker.h"
50 #include "YQApplication.h"
58 #define DEFAULT_MACRO_FILE_NAME "macro.ycp"
64 YUI_CHECK_PTR( packageSelector );
69 event = packageSelector->findDialog()->waitForEvent();
71 catch ( YUIException & uiEx )
75 catch ( std::exception & e)
77 yuiError() <<
"Caught std::exception: " << e.what() <<
"\n"
78 <<
"This is a libzypp problem. Do not file a bug against the UI!"
83 yuiError() <<
"Caught unspecified exception.\n"
84 <<
"This is a libzypp problem. Do not file a bug against the UI!"
98 QWidget * dialog = (QWidget *) YDialog::currentDialog()->widgetRep();
100 QPixmap screenShot = QPixmap::grabWindow( dialog->topLevelWidget()->winId() );
101 XSync( QX11Info::display(),
false );
102 QString fileName ( stl_filename.c_str() );
103 bool interactive =
false;
105 if ( fileName.isEmpty() )
112 if ( screenShotNameTemplate.isEmpty() )
118 QString home = QDir::homePath();
119 char * ssdir = getenv(
"Y2SCREENSHOTS" );
120 QString dir = ssdir ? fromUTF8( ssdir ) :
"yast2-screen-shots";
133 if ( mkdir( toUTF8( dir ).c_str(), 0700 ) == -1 )
142 dir = home +
"/" + dir;
143 (void) mkdir( toUTF8( dir ).c_str(), 0750 );
146 screenShotNameTemplate = dir +
"/%s-%03d.png";
154 const char * baseName =
"yast2";
156 int no = screenShotNo[ baseName ];
157 fileName.sprintf( qPrintable( screenShotNameTemplate ), baseName, no );
158 yuiDebug() <<
"Screenshot: " << fileName << std::endl;
163 _(
"Save screen shot to..." ) );
166 if ( fileName.isEmpty() )
168 yuiDebug() <<
"Save screen shot canceled by user" << std::endl;
172 screenShotNo.insert( baseName, ++no );
180 yuiDebug() <<
"Saving screen shot to " << fileName << std::endl;
181 bool success = screenShot.save( fileName,
"PNG" );
185 yuiError() <<
"Couldn't save screen shot " << fileName << std::endl;
190 YDialog * currentDialog = YDialog::currentDialog(
false );
193 parent = (QWidget *) currentDialog->widgetRep();
195 QMessageBox::warning( parent,
197 QString(
"Couldn't save screen shot\nto %1" ).arg( fileName ),
198 QMessageBox::Ok | QMessageBox::Default,
209 QString(
"*.tgz *.tar.gz" ),
210 QString(
"Save y2logs to..." ) );
213 YDialog * currentDialog = YDialog::currentDialog(
false );
216 parent = (QWidget *) currentDialog->widgetRep();
218 if ( ! fileName.isEmpty() )
220 QString saveLogsCommand =
"/usr/sbin/save_y2logs";
222 if ( access( saveLogsCommand.toLatin1(), X_OK ) == 0 )
224 saveLogsCommand +=
" '" + fileName +
"'";
225 yuiMilestone() <<
"Saving y2logs: " << saveLogsCommand << std::endl;
226 int result = system( qPrintable( saveLogsCommand ) );
230 yuiError() <<
"Error saving y2logs: \"" << saveLogsCommand
231 <<
"\" exited with " << result
234 QMessageBox::warning( parent,
236 QString(
"Couldn't save y2logs to %1 - "
237 "exit code %2" ).arg( fileName ).arg( result ),
238 QMessageBox::Ok | QMessageBox::Default,
239 QMessageBox::NoButton,
240 QMessageBox::NoButton );
244 yuiMilestone() <<
"y2logs saved to " << fileName << std::endl;
249 yuiError() <<
"Error saving y2logs: Command \""
250 << saveLogsCommand <<
"\" not found"
253 QMessageBox::warning( parent,
255 QString(
"Couldn't save y2logs to %1:\n"
256 "Command %2 not found" ).arg( fileName ).arg( saveLogsCommand ),
257 QMessageBox::Ok | QMessageBox::Default,
258 QMessageBox::NoButton,
259 QMessageBox::NoButton );
267 bool okButtonPressed =
false;
269 items <<
"Debug logging off"
270 <<
"Debug logging on";
274 YDialog * currentDialog = YDialog::currentDialog(
false );
277 parent = (QWidget *) currentDialog->widgetRep();
279 QString result = QInputDialog::getItem( parent,
281 _(
"Configure YaST Logging:"),
283 YUILog::debugLoggingEnabled() ? 1 : 0,
285 if ( okButtonPressed )
287 YUILog::enableDebugLogging( result.endsWith(
"on" ) );
288 yuiMilestone() <<
"Changing logging: " << result << std::endl;
296 YDialog * currentDialog = YDialog::currentDialog(
false );
299 parent = (QWidget *) currentDialog->widgetRep();
302 if ( YMacro::recording() )
304 YMacro::endRecording();
307 QMessageBox::information( parent,
308 "YaST2 Macro Recorder",
309 "Macro recording done.",
310 QMessageBox::Ok | QMessageBox::Default,
311 QMessageBox::NoButton,
312 QMessageBox::NoButton );
319 QFileDialog::getSaveFileName( parent,
320 "Select Macro File to Record to",
321 DEFAULT_MACRO_FILE_NAME,
324 QFileDialog::DontUseNativeDialog
327 if ( ! filename.isEmpty() )
329 YMacro::record( toUTF8( filename ) );
340 YDialog * currentDialog = YDialog::currentDialog(
false );
343 parent = (QWidget *) currentDialog->widgetRep();
347 QFileDialog::getOpenFileName( parent,
348 "Select Macro File to Play",
349 DEFAULT_MACRO_FILE_NAME,
350 "*.ycp", 0, QFileDialog::DontUseNativeDialog );
353 if ( ! filename.isEmpty() )
355 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) ...