KDevelop API Documentation

checkoutdialog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Mario Scalas                                    *
00003  *   mario.scalas@libero.it                                                *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00012 #include <qcheckbox.h>
00013 #include <qlineedit.h>
00014 #include <qpushbutton.h>
00015 #include <qcombobox.h>
00016 #include <qfile.h>
00017 #include <qtextstream.h>
00018 
00019 #include <klistview.h>
00020 #include <kurlrequester.h>
00021 #include <klocale.h>
00022 #include <kmessagebox.h>
00023 #include <kfiledialog.h>
00024 #include <kcursor.h>
00025 #include <kdebug.h>
00026 #include <kapplication.h>
00027 
00028 #include <dcopref.h>
00029 #include <cvsjob_stub.h>
00030 #include <repository_stub.h>
00031 #include <cvsservice_stub.h>
00032 
00033 #include "checkoutdialogbase.h"
00034 
00035 #include "checkoutdialog.h"
00036 
00038 // Constants
00040 
00041 const QString SSS( ":" );  // Server String Separator :)
00042 
00044 // class ModuleListViewItem
00046 
00047 class ModuleListViewItem : public KListViewItem
00048 {
00049 public:
00050     ModuleListViewItem( KListView *listview,
00051         const QString &moduleAlias, const QString &moduleRealPath )
00052         : KListViewItem( listview )
00053     {
00054         setAlias( moduleAlias );
00055         setRealPath( moduleRealPath );
00056     }
00057 
00058     void setAlias( const QString &aName ) { setText( 0, aName); }
00059     QString alias() const { return text(0); }
00060     void setRealPath( const QString &aRealPath ) { setText(1, aRealPath); }
00061     QString realPath() const { return text(1); }
00062 
00063 //    virtual QString text() const { return name(); }
00064 };
00065 
00067 // class CheckoutDialog
00069 
00070 CheckoutDialog::CheckoutDialog( CvsService_stub *cvsService,
00071     QWidget *parent, const char *name, WFlags ) :
00072     DCOPObject( "CheckoutDialogDCOPIface" ),
00073     KDialogBase( parent, name? name : "checkoutdialog", true, i18n("CVS Checkout"),
00074         Ok | Cancel, Ok, true ),
00075     m_service( cvsService ), m_job( 0 )
00076 {
00077     m_base = new CheckoutDialogBase( this, "checkoutdialogbase" );
00078     setMainWidget( m_base );
00079 
00080     connect( m_base->fetchModulesButton, SIGNAL(clicked()),
00081         this, SLOT(slotFetchModulesList()) );
00082     connect( m_base->modulesListView, SIGNAL(executed(QListViewItem*)),
00083         this, SLOT(slotModuleSelected(QListViewItem*)) );
00084 
00085     // Avoid displaying 'file:/' when displaying the file
00086     m_base->workURLRequester->setShowLocalProtocol( false );
00087     m_base->workURLRequester->setMode( KFile::Directory );
00088 
00089     // Grab the entries from $HOME/.cvspass
00090     fetchUserCvsRepositories();
00091     // And suggest to use the default projects dir set in KDevelop's preferences
00092     KConfig *config = kapp->config();
00093     config->setGroup("General Options");
00094     QString defaultProjectsDir = config->readPathEntry("DefaultProjectsDir", QDir::homeDirPath()+"/");
00095     setWorkDir( defaultProjectsDir );
00096 }
00097 
00099 
00100 CheckoutDialog::~CheckoutDialog()
00101 {
00102     delete m_job;
00103 }
00104 
00106 
00107 QString CheckoutDialog::serverPath() const
00108 {
00109     return m_base->serverPaths->currentText();
00110 }
00111 
00113 
00114 void CheckoutDialog::fillServerPaths( const QStringList &serverPaths )
00115 {
00116     m_base->serverPaths->insertStringList( serverPaths );
00117 }
00118 
00120 
00121 QString CheckoutDialog::workDir() const
00122 {
00123     return m_base->workURLRequester->url();
00124 }
00125 
00127 
00128 void CheckoutDialog::setWorkDir( const QString &aDir )
00129 {
00130     m_base->workURLRequester->setURL( aDir );
00131 }
00132 
00134 
00135 bool CheckoutDialog::pruneDirs() const
00136 {
00137     return m_base->pruneDirsCheck->isChecked();
00138 }
00139 
00141 
00142 QString CheckoutDialog::tag() const
00143 {
00144     return m_base->tagEdit->text();
00145 }
00146 
00148 
00149 QString CheckoutDialog::module() const
00150 {
00151     return m_base->moduleEdit->text();
00152 }
00153 
00155 
00156 void CheckoutDialog::slotFetchModulesList()
00157 {
00158     setCursor( KCursor::waitCursor() );
00159 
00160     if (serverPath().isEmpty() || workDir().isEmpty())
00161         return;
00162 
00163     DCOPRef job = m_service->moduleList( serverPath() );
00164     if (!m_service->ok())
00165         return;
00166 
00167     m_job = new CvsJob_stub( job.app(), job.obj() );
00168     // We only need to know when it finishes and then will grab the output
00169     // by using m_job->output() :-)
00170     connectDCOPSignal( job.app(), job.obj(), "jobFinished(bool,int)", "slotJobExited(bool,int)", true );
00171     connectDCOPSignal( job.app(), job.obj(), "receivedStdout(QString)", "receivedOutput(QString)", true );
00172 
00173     kdDebug() << "Running: " << m_job->cvsCommand() << endl;
00174     m_job->execute();
00175 }
00176 
00178 
00179 void CheckoutDialog::slotJobExited( bool /*normalExit*/, int /*exitStatus*/ )
00180 {
00181     kdDebug(9006) << "CheckoutDialog::slotModulesListFetched() here!" << endl;
00182 
00183     kdDebug(9006) << "Received: " << m_job->output().join( "\n" ) << endl;
00184 
00185 //    m_base->modulesListView->insertStringList( m_job->output() );
00186 }
00187 
00189 
00190 void CheckoutDialog::slotReceivedOutput( QString someOutput )
00191 {
00192     kdDebug( 9006 ) << " Received output: " << someOutput << endl;
00193 
00194     setCursor( KCursor::arrowCursor() );
00195 
00196     // Fill the modules KListView if the list obtained is not empty
00197     // QStringList modules = m_job->output();
00198     QStringList modules = QStringList::split( "\n", someOutput );
00199     if (modules.count() <= 0)
00200         return;
00201 
00202     QStringList::iterator it = modules.begin();
00203     for ( ; it != modules.end(); ++it )
00204     {
00205         QStringList l = QStringList::split( " ", (*it) );
00206         // Now, l[0] is the module name, l[1] is ... another string ;-)
00207         new ModuleListViewItem( m_base->modulesListView, l[0], l[1] );
00208     }
00209 }
00210 
00211 void CheckoutDialog::slotReceivedErrors( QString someErrors )
00212 {
00213     kdDebug( 9006 ) << " Received errors: " << someErrors << endl;
00214 }
00215 
00217 
00218 void CheckoutDialog::slotModuleSelected( QListViewItem * )
00219 {
00220     ModuleListViewItem *aModuleItem = static_cast<ModuleListViewItem*>(
00221         m_base->modulesListView->selectedItem()
00222     );
00223     if (!aModuleItem)
00224         return;
00225 
00226     m_base->moduleEdit->setText( aModuleItem->alias() );
00227 }
00228 
00230 
00231 void CheckoutDialog::fetchUserCvsRepositories()
00232 {
00233     QStringList repositories;
00234 
00235     QFile cvspass( QDir::homeDirPath() + QDir::separator() + ".cvspass" );
00236     if (!cvspass.open( IO_ReadOnly ))
00237         return;
00238     QByteArray data = cvspass.readAll();
00239     cvspass.close();
00240 
00241     QTextIStream istream( data );
00242     // Entries are like:
00243     // /1 :pserver:marios@cvs.kde.org:2401/home/kde Ahz:UIK?=d ?
00244     // /1 :pserver:mario@xamel:2401/home/cvsroot aJT_d'K?=d ?
00245     while (!istream.eof()) {
00246         QString line = istream.readLine();
00247         QStringList lineElements = QStringList::split( " ", line );
00248         if (lineElements.count() > 1) {
00249             repositories << lineElements[ 1 ];
00250         }
00251     }
00252 
00253     fillServerPaths( repositories );
00254 }
00255 
00257 
00258 void CheckoutDialog::slotOk()
00259 {
00260     QString errorMessage = QString::null;
00261 
00262     if (!(workDir().length() > 0) && QFile::exists( workDir() ))
00263         errorMessage = i18n( "Please, choose a valid working directory" );
00264     else if (!(serverPath().length() > 0))
00265         errorMessage = i18n( "Please, choose a CVS server." );
00266     else if (!(module().length() > 0))
00267         errorMessage = i18n( "Please, fill the CVS module field." );
00268 
00269     if (errorMessage.isNull())
00270         KDialogBase::slotOk();
00271     else
00272         KMessageBox::error( 0, errorMessage );
00273 }
00274 
00275 
00276 #include "checkoutdialog.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:59 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003