[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/3.5/kdesdk/kbabel/catalogmanager/libcvs
From: Nicolas Goutte <nicolasg () snafu ! de>
Date: 2005-09-18 20:07:52
Message-ID: 1127074072.982173.28349.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 461833 by goutte:
Allow the user to select an encoding for the CVS commit log message
CCBUG:66605
M +86 -8 cvsdialog.cpp
M +11 -0 cvsdialog.h
M +1 -1 cvshandler.cpp
--- branches/KDE/3.5/kdesdk/kbabel/catalogmanager/libcvs/cvsdialog.cpp #461832:461833
@@ -43,12 +43,17 @@
#include <qstring.h>
#include <qstringlist.h>
#include <qtextedit.h>
+#include <qtextcodec.h>
// KDE include files
#include <kconfig.h>
#include <kdebug.h>
#include <kglobal.h>
#include <klocale.h>
#include <kprocess.h>
+#include <ktempfile.h>
+#include <kmessagebox.h>
+#include <kcombobox.h>
+#include <kcharsets.h>
// Project specific include files
#include "cvsdialog.h"
@@ -104,6 +109,18 @@
layout->addWidget( label );
layout->addWidget( logedit );
+ label = new QLabel( i18n( "E&ncoding:" ), this );
+ m_encodingComboBox = new KComboBox( this );
+ label->setBuddy( m_encodingComboBox );
+ layout->addWidget( label );
+ layout->addWidget( m_encodingComboBox );
+ QStringList encodingList;
+ // The last encoding will be added at the top of the list, when the seetings \
will be read. + encodingList << i18n( "Descriptive encoding name", "Recommended \
(%1)" ).arg( "UTF-8" ); + encodingList << i18n( "Descriptive encoding name", \
"Locale (%1)" ).arg( QTextCodec::codecForLocale()->mimeName() ); + encodingList += \
KGlobal::charsets()->descriptiveEncodingNames(); + \
m_encodingComboBox->insertStringList( encodingList ); +
connect( oldMessages, SIGNAL( activated( const QString& ) ),
logedit, SLOT( setText( const QString& ) ) );
}
@@ -191,8 +208,8 @@
// Nothing to do here.
if ( _commandLine.isEmpty( ) ) return;
- output->append( i18n( "[ Starting command ]" ) );
-
+ kdDebug() << "Preparing KProcess" << endl;
+
// Create a new shell process
p = new KProcess;
p->setUseShell( true, "/bin/sh" );
@@ -204,9 +221,60 @@
const QString msg( logedit->text() );
- // Include the commit log message from the input field.
- _commandLine.replace( "@LOGMESSAGE@", KProcess::quote( msg ) );
+ if ( msg.isEmpty() )
+ {
+ // A good commit should never have an empty comment, so ask the user if he \
really wants it. + const int res = KMessageBox::warningContinueCancel( this,
+ i18n( "The commit log message is empty. Do you want to continue?" ) );
+ if ( res != KMessageBox::Continue )
+ return;
+ }
+ m_encoding = KGlobal::charsets()->encodingForName( \
m_encodingComboBox->currentText() ); + QTextCodec* codec = \
QTextCodec::codecForName( m_encoding.utf8() ); +
+ if ( !codec )
+ {
+ KMessageBox::error( this, i18n( "Cannot find encoding: %1" ).arg( m_encoding \
) ); + return;
+ }
+ else if ( !codec->canEncode( msg ) )
+ {
+ const int res = KMessageBox::warningContinueCancel( this,
+ i18n( "The commit log message cannot be encoded in the selected \
encoding: %1.\n" + "Do you want to continue?" ).arg( m_encoding ) );
+ if ( res != KMessageBox::Continue )
+ return;
+ }
+
+ // Write the commit log message from the input field to a temporary file
+ m_tempFile = new KTempFile;
+ m_tempFile->setAutoDelete( true );
+ QTextStream* stream = m_tempFile->textStream();
+ if ( !stream )
+ {
+ kdError() << "Could not create QTextStream for file " << m_tempFile->name();
+ delete m_tempFile;
+ m_tempFile = 0;
+ KMessageBox::error( this, i18n( "Cannot open temporary file for writing. \
Aborting.") ); + return;
+ }
+ stream->setCodec( codec );
+ *stream << msg;
+ m_tempFile->close();
+
+ if ( m_tempFile->status() )
+ {
+ kdError() << "Could not write to file " << m_tempFile->name();
+ delete m_tempFile;
+ m_tempFile = 0;
+ KMessageBox::error( this, i18n( "Cannot write to temporary file. Aborting.") \
); + return;
+ }
+
+ // Change the command line to have the real name of the temporary file
+ _commandLine.replace( "@LOG@FILE@", KProcess::quote( m_tempFile->name() ) );
+
// Update the list of log messages
if ( !msg.isEmpty() ) {
// Remove the message from the list if it already exists
@@ -227,6 +295,8 @@
connect( p, SIGNAL( processExited( KProcess* ) ),
this, SLOT( slotProcessExited( KProcess* ) ) );
+ output->append( i18n( "[ Starting command ]" ) );
+
if ( p->start( KProcess::NotifyOnExit, KProcess::Communication( \
KProcess::AllOutput ) ) ) { // Disable the main button (and the log edit if in \
commit mode) to // indicate activity.
@@ -234,18 +304,21 @@
if ( _cmd == CVS::Commit )
logedit->setEnabled( false );
} else
- kdDebug( ) << "Process could not be started." << endl;
+ {
+ kdError() << "Process could not be started." << endl;
+ KMessageBox::error( this, i18n( "The process could not be started." ) );
+ }
}
void CVSDialog::slotProcessStdout( KProcess*, char * buffer, int len )
{
- output->append( QString::fromUtf8( buffer, len ) );
+ output->append( QString::fromLocal8Bit( buffer, len ) );
// Set the cursor's position at the end of the output.
output->setCursorPosition( output->lines( ), 0 );
// If the command is 'cvs status' or 'cvs diff' collect the output of stdout.
if ( (_cmd == CVS::Status) || (_cmd == CVS::Diff) )
- _statusOutput += QString::fromUtf8( buffer, len );
+ _statusOutput += QString::fromLocal8Bit( buffer, len );
}
void CVSDialog::slotProcessStderr( KProcess*, char * buffer, int len )
@@ -254,7 +327,7 @@
// another color.
QColor oldColor( output->color( ) );
output->setColor( Qt::red );
- output->append( QString::fromUtf8( buffer, len ) );
+ output->append( QString::fromLocal8Bit( buffer, len ) );
output->setColor( oldColor );
output->setCursorPosition( output->lines( ), 0 );
}
@@ -304,6 +377,9 @@
// Set the last log message as the one to be used.
if ( config->readBoolEntry( "PresetLastUsedMessage", false ) )
logedit->setText( logMessages.first( ) );
+
+ m_encoding = config->readEntry( "CVSEncoding", "UTF-8" );
+ m_encodingComboBox->insertItem( i18n( "Descriptive encoding name", "Last choice \
(%1)" ).arg( m_encoding ), 0); }
}
@@ -320,6 +396,8 @@
QStringList::Iterator it;
for ( it = logMessages.begin( ); it != logMessages.end( ) && cnt < 10 ; ++it, \
++cnt )
config->writeEntry( QString( "CommitLogMessage%1" ).arg( cnt ), *it );
+
+ config->writeEntry( "CVSEncoding", m_encoding );
}
}
--- branches/KDE/3.5/kdesdk/kbabel/catalogmanager/libcvs/cvsdialog.h #461832:461833
@@ -48,6 +48,8 @@
class QTextEdit;
// Forwarding KDE classes
class KProcess;
+class KTempFile;
+class KComboBox;
/**
* This class represents the dialog which is used for executing CVS commands
@@ -133,6 +135,15 @@
QString _statusOutput;
QStringList logMessages;
+
+ /// Temporary file (for commits)
+ KTempFile* m_tempFile;
+
+ /// Encoding for the commit log message
+ QString m_encoding;
+
+ /// Combo box for the encoding
+ KComboBox* m_encodingComboBox;
};
#endif // CVSDIALOG_H
--- branches/KDE/3.5/kdesdk/kbabel/catalogmanager/libcvs/cvshandler.cpp \
#461832:461833 @@ -204,7 +204,7 @@
command += "update -dP";
break;
case CVS::Commit:
- command += "commit -m @LOGMESSAGE@";
+ command += "commit -F @LOG@FILE@";
checkToAdd( QStringList( filename ) );
break;
case CVS::Status:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic