KDevelop API Documentation

subversion_part.cpp

Go to the documentation of this file.
00001 /* Copyright (C) 2003
00002      Mickael Marchand <marchand@kde.org>
00003 
00004      This program is free software; you can redistribute it and/or
00005      modify it under the terms of the GNU General Public
00006      License as published by the Free Software Foundation; either
00007      version 2 of the License, or (at your option) any later version.
00008 
00009      This program is distributed in the hope that it will be useful,
00010      but WITHOUT ANY WARRANTY; without even the implied warranty of
00011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012      General Public License for more details.
00013 
00014      You should have received a copy of the GNU General Public License
00015      along with this program; see the file COPYING.  If not, write to
00016      the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017      Boston, MA 02111-1307, USA.
00018      */
00019 
00020 #include <qwhatsthis.h>
00021 #include <kiconloader.h>
00022 #include <klocale.h>
00023 #include <kdevgenericfactory.h>
00024 #include <kaction.h>
00025 #include <kpopupmenu.h>
00026 
00027 #include "kdevcore.h"
00028 #include "kdevmainwindow.h"
00029 #include "subversion_core.h"
00030 #include "subversion_part.h"
00031 #include "subversion_widget.h"
00032 #include "subversionoptionswidgetimpl.h"
00033 #include "subversionprojectwidget.h"
00034 #include "urlutil.h"
00035 #include <qvbox.h>
00036 #include <kdialogbase.h>
00037 #include <kparts/part.h>
00038 #include <kdevpartcontroller.h>
00039 #include <kdevproject.h>
00040 #include <domutil.h>
00041 #include <kurlrequester.h>
00042 #include <qradiobutton.h>
00043 #include <kdebug.h>
00044 #include <qwidget.h>
00045 
00046 static const KAboutData data("kdevsubversion", I18N_NOOP("Subversion"), "1.0");
00047 
00048 typedef KDevGenericFactory<subversionPart> subversionFactory;
00049 K_EXPORT_COMPONENT_FACTORY( libkdevsubversion, subversionFactory( &data ) )
00050 
00051 //bool g_projectWasJustCreated = false;
00052 
00053 subversionPart::subversionPart(QObject *parent, const char *name, const QStringList& )
00054     : KDevVersionControl("KDevsubversionPart", "kdevsubversionpart", parent, name ? name : "Subversion" ) {
00055     setInstance(subversionFactory::instance());
00056     m_projWidget = 0;
00057 
00058     m_impl = new subversionCore( this );
00059 
00060     m_checkout_recurse = true;
00061     m_update_recurse = true;
00062     m_switch_recurse = true;
00063     m_add_recurse = true;
00064     m_remove_force = true;
00065     m_commit_recurse = true;
00066     m_diff_recurse = true;
00067     m_merge_recurse = true;
00068     m_merge_overwrite = true;
00069     m_relocate_recurse = true;
00070     m_revert_recurse = true;
00071     m_resolve_recurse = true;
00072     m_move_force = true;
00073     m_propset_recurse = true;
00074     m_propget_recurse = true;
00075     m_proplist_recurse = true;
00076 
00077     //m_impl->processWidget()->setIcon( SmallIcon("db") );
00078 
00079     setupActions();
00080 
00081     connect( m_impl, SIGNAL(checkoutFinished(QString)), SIGNAL(finishedFetching(QString)) );
00082 
00083     // Context menu
00084     connect( core(), SIGNAL(contextMenu(QPopupMenu *, const Context *)), this, SLOT(contextMenu(QPopupMenu *, const Context *)) );
00085     connect( core(), SIGNAL(projectConfigWidget(KDialogBase*)), this, SLOT(projectConfigWidget(KDialogBase*)) );
00086     connect( core(), SIGNAL(stopButtonClicked(KDevPlugin*)), this, SLOT(slotStopButtonClicked(KDevPlugin*)) );
00087     connect( core(), SIGNAL(projectOpened()), this, SLOT(slotProjectOpened()) );
00088     connect( core(), SIGNAL(projectClosed()), this, SLOT(slotProjectClosed()) );
00089 
00090     m_impl->processWidget()->setCaption(i18n( "Subversion Output" ));
00091     mainWindow()->embedOutputView( (QWidget*)m_impl->processWidget(), i18n( "Subversion" ), i18n( "Subversion messages" ) );
00092     QWhatsThis::add((QWidget*)m_impl->processWidget(), i18n("<b>Subversion</b><p>Subversion operations window."));
00093     setVersionControl( this );
00094 }
00095 
00096 subversionPart::~subversionPart() {
00097     if ( m_projWidget ){
00098         delete (subversionProjectWidget*) m_projWidget;
00099         m_projWidget = 0;
00100     }
00101     delete m_impl;
00102 }
00103 
00104 void subversionPart::setupActions() {
00105     actionCommit = new KAction( i18n("&Commit to Repository"), 0, this,
00106             SLOT(slotActionCommit()), actionCollection(), "subversion_commit" );
00107     actionCommit->setToolTip( i18n("Commit file(s)") );
00108     actionCommit->setWhatsThis( i18n("<b>Commit file(s)</b><p>Commits file to repository if modified.") );
00109 
00110     /*    actionDiff = new KAction( i18n("&Difference Between Revisions"), 0, this, SLOT(slotActionDiff()),
00111                 actionCollection(), "subversion_diff" );
00112                 actionDiff->setToolTip( i18n("Build difference") );
00113                 actionDiff->setWhatsThis( i18n("<b>Build difference</b><p>Builds difference between releases.") );
00114                 */
00115     actionAdd = new KAction( i18n("&Add to Repository"), 0, this, SLOT(slotActionAdd()),
00116             actionCollection(), "subversion_add" );
00117     actionAdd->setToolTip( i18n("Add file to repository") );
00118     actionAdd->setWhatsThis( i18n("<b>Add file to repository</b><p>Adds file to repository.") );
00119 
00120     actionRemove = new KAction( i18n("&Remove From Repository"), 0, this,
00121             SLOT(slotActionRemove()), actionCollection(), "subversion_remove" );
00122     actionRemove->setToolTip( i18n("Remove from repository") );
00123     actionRemove->setWhatsThis( i18n("<b>Remove from repository</b><p>Removes file(s) from repository.") );
00124 
00125     actionUpdate = new KAction( i18n("&Update"), 0, this,
00126             SLOT(slotActionUpdate()), actionCollection(), "subversion_update" );
00127     actionUpdate->setToolTip( i18n("Update") );
00128     actionUpdate->setWhatsThis( i18n("<b>Update</b><p>Updates file(s) from repository.") );
00129 
00130     actionAddToIgnoreList = new KAction( i18n("&Ignore in Subversion Operations"), 0,
00131             this, SLOT(slotActionAddToIgnoreList()), actionCollection(), "subversion_ignore" );
00132     actionAddToIgnoreList->setToolTip( i18n("Ignore in Subversion operations") );
00133     actionAddToIgnoreList->setWhatsThis( i18n("<b>Ignore in Subversion operations</b><p>Ignores file(s).") );
00134 
00135     actionRemoveFromIgnoreList = new KAction( i18n("Do &Not Ignore in Subversion Operations"), 0,
00136             this, SLOT(slotActionRemoveFromIgnoreList()), actionCollection(), "subversion_donot_ignore" );
00137     actionRemoveFromIgnoreList->setToolTip( i18n("Do not ignore in Subversion operations") );
00138     actionRemoveFromIgnoreList->setWhatsThis( i18n("<b>Do not ignore in Subversion operations</b><p>Do not ignore file(s).") );
00139 }
00140 
00141 QWidget* subversionPart::newProjectWidget( QWidget* parent ) {
00142     if ( !m_projWidget )
00143         m_projWidget = new subversionProjectWidget(parent,"projectwidget");
00144     return m_projWidget;
00145 }
00146 
00147 void subversionPart::projectConfigWidget( KDialogBase *dlg ) {
00148     QVBox *vbox = dlg->addVBoxPage( i18n("Subversion") );
00149     subversionOptionsWidgetImpl *w = new subversionOptionsWidgetImpl( (QWidget *)vbox, this, "svn config widget" );
00150     connect( dlg, SIGNAL(okClicked()), w, SLOT(accept()) );
00151 }
00152 
00153 void subversionPart::createNewProject( const QString& dirname ) {
00154     if ( !m_projWidget ) return;
00155 
00156     m_impl->createNewProject( dirname, KURL( m_projWidget->importURL->url() ), m_projWidget->yes->isChecked() );
00157 
00158 }
00159 
00160 bool subversionPart::fetchFromRepository() {
00161     m_impl->checkout();
00162         return true;
00163 }
00164 
00165 KDevVCSFileInfoProvider * subversionPart::fileInfoProvider() const {
00166     return 0;
00167 }
00168 
00169 bool subversionPart::isValidDirectory( const QString& dirPath) {
00170     QString svn = "/.svn/";
00171     QDir svndir( dirPath + svn );
00172     QString entriesFileName = dirPath + svn + "entries";
00173 
00174     return svndir.exists() &&
00175         QFile::exists( entriesFileName );
00176 }
00177 
00178 void subversionPart::contextMenu( QPopupMenu *popup, const Context *context ) {
00179 // If the current project doesn't support SVN, we don't
00180 // want to confuse the user with a SVN popup menu.
00181 if(!project() || !isValidDirectory(project()->projectDirectory()))
00182   return;
00183   
00184     kdDebug() << "contextMenu()" << endl;
00185     if (context->hasType( Context::FileContext ) ||
00186             context->hasType( Context::EditorContext ))
00187     {
00188 
00189         if (context->hasType( Context::FileContext ))
00190         {
00191             kdDebug() << "Requested for a FileContext" << endl;
00192             const FileContext *fcontext = static_cast<const FileContext*>( context );
00193             m_urls = fcontext->urls();
00194         }
00195         else
00196         {
00197             kdDebug() << "Requested for an EditorContext" << endl;
00198             const EditorContext *editorContext = static_cast<const EditorContext*>( context );
00199             m_urls << editorContext->url();
00200         }
00201         // THis stuff should end up into prepareOperation()
00202         URLUtil::dump( m_urls );
00203         if (m_urls.count() <= 0)
00204             return;
00205 
00206         KPopupMenu *subMenu = new KPopupMenu( popup );
00207                 if (context->hasType( Context::FileContext ))
00208             popup->insertSeparator();
00209 
00210         int id = subMenu->insertItem( actionCommit->text(), this, SLOT(slotCommit()) );
00211         // CvsService let to do log and diff operations only on one file (or directory) at time
00212         /*        if (m_urls.count() == 1)
00213                             {
00214                             subMenu->insertItem( actionDiff->text(), this, SLOT(slotDiff()) );
00215                             subMenu->insertItem( actionLog->text(), this, SLOT(slotLog()) );
00216                             }*/
00217         subMenu->setWhatsThis(id, i18n("<b>Commit file(s)</b><p>Commits file to repository if modified."));
00218         id = subMenu->insertItem( actionAdd->text(), this, SLOT(slotAdd()) );
00219         subMenu->setWhatsThis(id, i18n("<b>Add file to repository</b><p>Adds file to repository."));
00220         id = subMenu->insertItem( actionRemove->text(), this, SLOT(slotRemove()) );
00221         subMenu->setWhatsThis(id, i18n("<b>Remove from repository</b><p>Removes file(s) from repository."));
00222 
00223         subMenu->insertSeparator();
00224         id = subMenu->insertItem( actionUpdate->text(), this, SLOT(slotUpdate()) );
00225         subMenu->setWhatsThis(id, i18n("<b>Update</b><p>Updates file(s) from repository."));
00226 
00227         subMenu->insertSeparator();
00228         id = subMenu->insertItem( actionAddToIgnoreList->text(), this, SLOT(slotAddToIgnoreList()) );
00229         subMenu->setWhatsThis(id, i18n("<b>Ignore in Subversion operations</b><p>Ignores file(s)."));
00230         id = subMenu->insertItem( actionRemoveFromIgnoreList->text(), this, SLOT(slotRemoveFromIgnoreList()) );
00231         subMenu->setWhatsThis(id, i18n("<b>Do not ignore in Subversion operations</b><p>Do not ignore file(s)."));
00232 
00233         // Now insert in parent menu
00234         popup->insertItem( i18n("Subversion"), subMenu );
00235     }
00236 }
00237 
00238 bool subversionPart::urlFocusedDocument( KURL &url ) {
00239     KParts::ReadOnlyPart *part = dynamic_cast<KParts::ReadOnlyPart*>( partController()->activePart() );
00240     if ( part ) {
00241         if (part->url().isLocalFile() ) {
00242             url = part->url();
00243             return true;
00244         }
00245     }
00246     return false;
00247 }
00248 
00249 void subversionPart::slotActionUpdate() {
00250     kdDebug() << "subversion: slotActionUpdate()" << endl;
00251     KURL doc;
00252     if (urlFocusedDocument( doc )) {
00253         m_impl->update( doc );
00254     }
00255 }
00256 
00257 void subversionPart::slotUpdate() {
00258     m_impl->update (m_urls);
00259 }
00260 
00261 void subversionPart::slotActionCommit() {
00262     kdDebug() << "subversion: slotActionCommit()" << endl;
00263     KURL doc;
00264     if (urlFocusedDocument( doc )) {
00265         m_impl->commit( doc );
00266     }
00267 }
00268 
00269 void subversionPart::slotCommit() {
00270     m_impl->commit (m_urls);
00271 }
00272 
00273 void subversionPart::slotProjectOpened() {
00274     kdDebug() << "subversion :projectOpened" << endl;
00275 /*  if ( g_projectWasJustCreated ) {
00276         //saveOptions();
00277         g_projectWasJustCreated = false;
00278     }   */
00279     //loadOptions();
00281     //connect( project(), SIGNAL(addedFilesToProject(const QStringList&)), this, SLOT(slotAddFilesToProject(const QStringList &)) );
00282     //connect( project(), SIGNAL(removedFilesFromProject(const QStringList&)), this, SLOT(slotRemovedFilesFromProject(const QStringList &)) );
00283 }
00284 
00285 void subversionPart::slotProjectClosed() {
00286     kdDebug() << "subversion :projectClosed" << endl;
00287     //saveOptions();
00289     //disconnect( project(), SIGNAL(addedFilesToProject(const QStringList&)), this, SLOT(slotAddFilesToProject(const QStringList &)) );
00290     //disconnect( project(), SIGNAL(removedFilesFromProject(const QStringList&)), this, SLOT(slotRemovedFilesFromProject(const QStringList &)) );
00291 }
00292 
00293 void subversionPart::savePartialProjectSession(QDomElement* dom) {
00294     kdDebug() << "subversion : savePartialProjectSession" << endl;
00295     QDomDocument doc = dom->ownerDocument();
00296     QDomElement svn = doc.createElement( "subversion" );
00297     svn.setAttribute("recursecheckout", m_checkout_recurse);
00298     svn.setAttribute("recurseupdate", m_update_recurse);
00299     svn.setAttribute("recurseswitch", m_switch_recurse);
00300     svn.setAttribute("recurseadd", m_add_recurse);
00301     svn.setAttribute("forceremove",m_remove_force);
00302     svn.setAttribute("recursecommit",m_commit_recurse);
00303     svn.setAttribute("recursediff", m_diff_recurse);
00304     svn.setAttribute("recursemerge", m_merge_recurse);
00305     svn.setAttribute("forcemerge", m_merge_overwrite);
00306     svn.setAttribute("recurserelocate", m_relocate_recurse);
00307     svn.setAttribute("recurserevert", m_revert_recurse);
00308     svn.setAttribute("recurseresolve", m_resolve_recurse);
00309     svn.setAttribute("forcemove", m_move_force);
00310     svn.setAttribute("recursepropset", m_propset_recurse);
00311     svn.setAttribute("recursepropget", m_propget_recurse);
00312     svn.setAttribute("recurseproplist", m_proplist_recurse);
00313     svn.setAttribute( "base", base.url() );
00314     dom->appendChild( svn );
00315 }
00316 
00317 void subversionPart::restorePartialProjectSession(const QDomElement* dom) {
00318     kdDebug() << "subversion : restorePartialProjectSession" << endl;
00319     QDomElement svn = dom->namedItem("subversion").toElement();
00320 
00321     m_checkout_recurse = svn.attribute( "recursecheckout", "1" ).toInt();
00322     m_update_recurse = svn.attribute("recurseupdate","1").toInt();
00323     m_switch_recurse = svn.attribute("recurseswitch","1").toInt();
00324     m_add_recurse = svn.attribute("recurseadd","1").toInt();
00325     m_remove_force = svn.attribute("forceremove","1").toInt();
00326     m_commit_recurse = svn.attribute("recursecommit","1").toInt();
00327     m_diff_recurse = svn.attribute("recursediff","1").toInt();
00328     m_merge_recurse = svn.attribute("recursemerge","1").toInt();
00329     m_merge_overwrite = svn.attribute("forcemerge","1").toInt();
00330     m_relocate_recurse = svn.attribute("recurserelocate","1").toInt();
00331     m_revert_recurse = svn.attribute("recurserevert","1").toInt();
00332     m_move_force = svn.attribute("forcemove","1").toInt();
00333     m_resolve_recurse = svn.attribute("recurseresolve","1").toInt();
00334     m_propset_recurse = svn.attribute("recursepropset","1").toInt();
00335     m_propget_recurse = svn.attribute("recursepropget","1").toInt();
00336     m_proplist_recurse = svn.attribute("recurseproplist","1").toInt();
00337     base = svn.attribute( "base", "" );
00338 }
00339 
00340 #include "subversion_part.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