commitdlg.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "commitdlg.h"
00014
00015 #include <qlayout.h>
00016 #include <qlabel.h>
00017 #include <qtextedit.h>
00018 #include <qpushbutton.h>
00019 #include <qregexp.h>
00020 #include <kprocess.h>
00021 #include <kapplication.h>
00022 #include <klocale.h>
00023 #include <klineedit.h>
00024 #include <kmessagebox.h>
00025 #include <kdebug.h>
00026
00027 #include <stdlib.h>
00028
00029 #include "execcommand.h"
00030
00031 CommitDialog::CommitDialog( QWidget *parent, const char *name )
00032 : KDialogBase( parent, name, true, i18n("Perforce Submit"), Ok|Cancel|Details )
00033 {
00034 QWidget *w = new QWidget( this, "main widget" );
00035 setMainWidget( w );
00036
00037 edit = new QTextEdit( w );
00038 QFontMetrics fm(edit->fontMetrics());
00039 edit->setMinimumSize(fm.width("0")*40, fm.lineSpacing()*3);
00040
00041 QVBoxLayout *layout = new QVBoxLayout( w, 0, spacingHint() );
00042 QLabel *editLabel = new QLabel(i18n("&Enter description:"), w);
00043 editLabel->setBuddy(edit);
00044 layout->addWidget(editLabel);
00045 layout->addWidget(edit);
00046
00047 w = new QWidget( this, "details widget" );
00048
00049 clientEdit = new KLineEdit( w );
00050 userEdit = new KLineEdit( w );
00051 filesBox = new KListBox( w );
00052
00053 layout = new QVBoxLayout( w, 0, spacingHint() );
00054 QLabel *clientLabel = new QLabel(i18n("C&lient:"), w);
00055 clientLabel->setBuddy(clientEdit);
00056 layout->addWidget(clientLabel);
00057 layout->addWidget( clientEdit );
00058 QLabel *userLabel = new QLabel(i18n("&User:"), w);
00059 userLabel->setBuddy(userEdit);
00060 layout->addWidget( userLabel );
00061 layout->addWidget( userEdit );
00062 QLabel *filesLabel = new QLabel(i18n("&File(s):"), w);
00063 filesLabel->setBuddy(filesBox);
00064 layout->addWidget( filesLabel );
00065 layout->addWidget( filesBox );
00066
00067 setDetailsWidget( w );
00068 autoGuess();
00069 edit->setFocus();
00070 }
00071
00072 CommitDialog::~CommitDialog()
00073 {
00074 }
00075
00076 void CommitDialog::autoGuess()
00077 {
00078 char *cenv;
00079
00080 cenv = getenv( "P4USER" );
00081 if ( cenv ) {
00082 setUser( QString::fromLocal8Bit( cenv ) );
00083 }
00084
00085 cenv = getenv( "P4CLIENT" );
00086 if ( cenv ) {
00087 setClient( QString::fromLocal8Bit( cenv ) );
00088 }
00089 }
00090
00091 void CommitDialog::setFiles( const QStringList& lst )
00092 {
00093 filesBox->clear();
00094 setDepotFiles( lst );
00095 }
00096
00097 void CommitDialog::setDepotFiles( const QStringList& lst )
00098 {
00099 QStringList args;
00100
00101 args << "files";
00102 for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
00103 args << (*it);
00104 }
00105
00106 ExecCommand* cmd = new ExecCommand( "p4", args, QString::null, QStringList(), this );
00107 connect( cmd, SIGNAL(finished( const QString&, const QString& )),
00108 this, SLOT(getFilesFinished( const QString&, const QString& )) );
00109 }
00110
00111 void CommitDialog::getFilesFinished( const QString& out, const QString& )
00112 {
00113 QStringList lst = QStringList::split( QChar('\n'), out );
00114 for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
00115 int pos = (*it).find( QChar('#') );
00116 if ( pos > 1 && (*it).startsWith( "//" ) ) {
00117 filesBox->insertItem( (*it).left( pos ) );
00118 }
00119 }
00120 }
00121
00122 QString CommitDialog::changeList() const
00123 {
00124 QString lst;
00125
00126 lst += "Change: new\n"
00127 "Client: " + client() + "\n"
00128 "User: " + user() + "\n"
00129 "Status: new\n"
00130 "Description:\n ";
00131
00132 lst += logMessage().replace(QRegExp("\n"), "\n ") + "\n\n";
00133
00134 lst += "Files:\n";
00135
00136 for ( uint i = 0; i < filesBox->count(); ++i ) {
00137 lst += " " + filesBox->text( i ) + "\n";
00138 }
00139
00140 return lst;
00141 }
00142
00143 void CommitDialog::accept()
00144 {
00145 if ( client().isEmpty() ) {
00146 setDetails( true );
00147 KMessageBox::error( this, i18n("Please enter the P4 client name.") );
00148 clientEdit->setFocus();
00149 } else if ( user().isEmpty() ) {
00150 setDetails( true );
00151 KMessageBox::error( this, i18n("Please enter the P4 user.") );
00152 userEdit->setFocus();
00153 } else if ( filesBox->count() == 0 ) {
00154 setDetails( true );
00155 KMessageBox::error( this, i18n("The changelist does not contain any files.") );
00156 } else {
00157 KDialogBase::accept();
00158 }
00159 }
00160
00161 #include "commitdlg.moc"
This file is part of the documentation for KDevelop Version 3.1.2.