From: Jonas B. <jb...@us...> - 2006-08-27 20:03:45
|
Update of /cvsroot/krusader/krusader_kde3/krusader/UserAction In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv21858/krusader/UserAction Modified Files: kraction.cpp kraction.h Log Message: ADDED: UserAction: Outputcollectionwindow can now save the buffer In addition I managed to replace the toggle-fixed-width-font-button with a checkbox on hte left side of baseline buttongroup of KDialogBase Index: kraction.cpp =================================================================== RCS file: /cvsroot/krusader/krusader_kde3/krusader/UserAction/kraction.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** kraction.cpp 27 Aug 2006 15:16:49 -0000 1.18 --- kraction.cpp 27 Aug 2006 20:03:41 -0000 1.19 *************** *** 17,26 **** --- 17,30 ---- #include <qtextedit.h> #include <qvbox.h> + #include <qlayout.h> #include <qsplitter.h> #include <qpushbutton.h> + #include <qcheckbox.h> + #include <qfile.h> #include <qlabel.h> #include <kaction.h> #include <kurl.h> #include <kmessagebox.h> + #include <kfiledialog.h> #include "kraction.h" #include "expander.h" *************** *** 37,43 **** ////////////////////////////////// KrActionProcDlg ///////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// ! KrActionProcDlg::KrActionProcDlg( QString caption, bool enableStderr, QWidget *parent ) : ! KDialogBase( parent, 0, false, caption, KDialogBase::User1 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Cancel ), _stdout(0), _stderr(0) { setButtonOK( i18n( "Close" ) ); --- 41,48 ---- ////////////////////////////////// KrActionProcDlg ///////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// ! #include <qlayout.h> KrActionProcDlg::KrActionProcDlg( QString caption, bool enableStderr, QWidget *parent ) : ! KDialogBase( parent, 0, false, caption, KDialogBase::User1 | KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Cancel ), ! _stdout(0), _stderr(0), _currentTextEdit(0) { setButtonOK( i18n( "Close" ) ); *************** *** 46,49 **** --- 51,56 ---- setButtonCancel( KGuiItem(i18n("Kill"), i18n( "Kill the running process" )) ); + setButtonText(KDialogBase::User1, i18n("Save as") ); + QVBox *page = makeVBoxMainWidget(); // do we need to separate stderr and stdout? *************** *** 72,75 **** --- 79,86 ---- } + _currentTextEdit = _stdout; + connect( _stderr, SIGNAL( clicked(int, int) ), SLOT( currentTextEditChanged() ) ); + connect( _stdout, SIGNAL( clicked(int, int) ), SLOT( currentTextEditChanged() ) ); + krConfig->setGroup( "UserActions" ); normalFont = krConfig->readFontEntry( "Normal Font", _UserActions_NormalFont ); *************** *** 78,86 **** toggleFixedFont( startupState ); ! setButtonText(KDialogBase::User1, i18n("Use font with fixed width") ); ! QPushButton* fixedButton = actionButton( KDialogBase::User1 ); ! fixedButton->setToggleButton( true ); ! fixedButton->setOn( startupState ); ! connect( fixedButton, SIGNAL( toggled(bool) ), SLOT( toggleFixedFont(bool) ) ); } --- 89,101 ---- toggleFixedFont( startupState ); ! // HACK This fetches the layout of the buttonbox from KDialogBase, although it is not accessable with KDialogBase's API ! // None the less it's quite save to use since this implementation hasn't changed since KDE-3.3 (I haven't looked at earlier ! // versions since we don't support them) and now all work is done in KDE-4. ! QWidget* buttonBox = static_cast<QWidget*>( actionButton(KDialogBase::Ok)->parent() ); ! QBoxLayout* buttonBoxLayout = static_cast<QBoxLayout*>( buttonBox->layout() ); ! QCheckBox* useFixedFont = new QCheckBox( i18n("Use font with fixed width"), buttonBox ); ! buttonBoxLayout->insertWidget( 0, useFixedFont ); ! useFixedFont->setChecked( startupState ); ! connect( useFixedFont, SIGNAL( toggled(bool) ), SLOT( toggleFixedFont(bool) ) ); } *************** *** 112,115 **** --- 127,171 ---- } + void KrActionProcDlg::slotUser1() { + QString filename = KFileDialog::getSaveFileName(QString::null, i18n("*.txt|Text files\n*|all files"), this); + if ( filename.isEmpty() ) + return; + QFile file( filename ); + int answer = KMessageBox::Yes; + if ( file.exists() ) + answer = KMessageBox::warningYesNoCancel( this, //parent + i18n("This file already Exists.\nDo you want to overwrite it or append the output?"), //text + i18n("Overwrite or append?"), //caption + i18n("Overwrite"), //label for Yes-Button + i18n("Append") //label for No-Button + ); + if ( answer == KMessageBox::Cancel ) + return; + bool open; + if ( answer == KMessageBox::No ) // this means to append + open = file.open( IO_WriteOnly | IO_Append ); + else + open = file.open( IO_WriteOnly ); + + if ( ! open ) { + KMessageBox::error( this, + i18n("Can't open %1 for writing!\nNothing exported.").arg(filename), + i18n("Export failed!") + ); + return; + } + + QTextStream stream( &file ); + stream << _currentTextEdit->text(); + file.close(); + } + + void KrActionProcDlg::currentTextEditChanged() { + if ( _stderr && _stderr->hasFocus() ) + _currentTextEdit = _stderr; + else + _currentTextEdit = _stdout; + } + ////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////// KrActionProc //////////////////////////////////////////// Index: kraction.h =================================================================== RCS file: /cvsroot/krusader/krusader_kde3/krusader/UserAction/kraction.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** kraction.h 27 Aug 2006 15:16:49 -0000 1.5 --- kraction.h 27 Aug 2006 20:03:41 -0000 1.6 *************** *** 111,115 **** /** * This diesplays the output of a process ! * @author Shie Erlich */ class KrActionProcDlg: public KDialogBase { --- 111,115 ---- /** * This diesplays the output of a process ! * @author Shie Erlich, Jonas Bähr */ class KrActionProcDlg: public KDialogBase { *************** *** 122,134 **** void addStdout( KProcess *proc, char *buffer, int buflen ); void toggleFixedFont( bool state ); private: ! QTextEdit *_stdout, *_stderr; QFont normalFont, fixedFont; }; /** * This executes a command of a UserAction ! * @author Shie Erlich * @todo jonas: call a list of commands separately (I began it but it doesn't work) */ --- 122,137 ---- void addStdout( KProcess *proc, char *buffer, int buflen ); void toggleFixedFont( bool state ); + void slotUser1(); ///< This is used to save the buffer to disc private: ! QTextEdit *_stdout, *_stderr, *_currentTextEdit; QFont normalFont, fixedFont; + private slots: + void currentTextEditChanged(); }; /** * This executes a command of a UserAction ! * @author Shie Erlich, Jonas Bähr * @todo jonas: call a list of commands separately (I began it but it doesn't work) */ |