KDevelop API Documentation

vcs/clearcase/clearcasepart.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2003 by Ajay Guleria * 00003 * ajay_guleria at yahoo dot com * 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 "clearcasepart.h" 00013 #include "commentdlg.h" 00014 00015 #include <qfileinfo.h> 00016 #include <qpopupmenu.h> 00017 00018 #include <kpopupmenu.h> 00019 #include <kdebug.h> 00020 #include <kdevgenericfactory.h> 00021 #include <klocale.h> 00022 #include <kprocess.h> 00023 #include <kmessagebox.h> 00024 #include <kapplication.h> 00025 00026 #include "kdevcore.h" 00027 #include "kdevmakefrontend.h" 00028 #include "kdevdifffrontend.h" 00029 #include "kdevappfrontend.h" 00030 #include "execcommand.h" 00031 #include "domutil.h" 00032 #include "kdevmainwindow.h" 00033 00034 static const KAboutData data("kdevclearcase", I18N_NOOP("Clearcase"), "1.0"); 00035 00036 typedef KDevGenericFactory<ClearcasePart> ClearcaseFactory; 00037 K_EXPORT_COMPONENT_FACTORY( libkdevclearcase, ClearcaseFactory( &data ) ) 00038 00039 ClearcasePart::ClearcasePart( QObject *parent, const char *name, const QStringList & ) 00040 : KDevPlugin( "Clearcase", "clearcase", parent, name ? name : "ClearcasePart" ), 00041 default_checkin(""),default_checkout(""),default_uncheckout("-rm"), 00042 default_create("-ci"),default_remove("-f"),default_diff("-pred -diff") 00043 { 00044 setInstance(ClearcaseFactory::instance()); 00045 connect( core(), SIGNAL(contextMenu(QPopupMenu *, const Context *)), 00046 this, SLOT(contextMenu(QPopupMenu *, const Context *)) ); 00047 00048 } 00049 00050 ClearcasePart::~ClearcasePart() 00051 {} 00052 00053 00054 void ClearcasePart::contextMenu(QPopupMenu *popup, const Context *context) 00055 { 00056 if (context->hasType( Context::FileContext )) { 00057 const FileContext *fcontext = static_cast<const FileContext*>(context); 00058 popupfile = fcontext->fileName(); 00059 00060 // check if this file belongs to a clearcase directory 00061 // i.e. is the file /view/<view_name/vobs/... format? 00062 QString s1 = popupfile.section('/', 1, 1); 00063 QString s2 = popupfile.section('/', 2, 2); 00064 QString s3 = popupfile.section('/', 3, 3); 00065 if(s1 == "view" && s3 == "vobs" || s1 == "vobs") 00066 viewname = s2; 00067 else 00068 return; 00069 00070 QFileInfo fi(popupfile); 00071 popup->insertSeparator(); 00072 00073 KPopupMenu *sub = new KPopupMenu(popup); 00074 QString name = fi.fileName(); 00075 sub->insertTitle( i18n("Actions for %1").arg(name) ); 00076 sub->insertItem( i18n("Checkin"), 00077 this, SLOT(slotCheckin()) ); 00078 sub->insertItem( i18n("Checkout"), 00079 this, SLOT(slotCheckout()) ); 00080 sub->insertItem( i18n("Uncheckout"), 00081 this, SLOT(slotUncheckout()) ); 00082 sub->insertSeparator(); 00083 sub->insertItem( i18n("Create Element"), 00084 this, SLOT(slotCreate()) ); 00085 sub->insertItem( i18n("Remove Element"), 00086 this, SLOT(slotRemove()) ); 00087 sub->insertSeparator(); 00088 sub->insertItem( i18n("Diff"), 00089 this, SLOT(slotDiff()) ); 00090 00091 popup->insertItem(i18n("Clearcase"), sub); 00092 } 00093 } 00094 00095 void ClearcasePart::slotCheckin() 00096 { 00097 QString dir, name; 00098 QFileInfo fi(popupfile); 00099 if (fi.isDir()) { 00100 dir = fi.absFilePath(); 00101 name = "."; 00102 } else { 00103 dir = fi.dirPath(); 00104 name = fi.fileName(); 00105 } 00106 00107 CcaseCommentDlg dlg(FALSE); 00108 if (dlg.exec() == QDialog::Rejected) 00109 return; 00110 00111 QDomDocument &dom = *this->projectDom(); 00112 QString message = DomUtil::readEntry(dom,"/kdevclearcase/checkin_options",default_checkin); 00113 if(dlg.logMessage().isEmpty()) 00114 message += "-nc "; 00115 else 00116 message += "-c \"" + dlg.logMessage() + "\""; 00117 00118 QString command("cd "); 00119 command += KShellProcess::quote(dir); 00120 command += " && "; 00121 command += " cleartool checkin "; 00122 command += message; // Already quoted, see above 00123 command += " "; 00124 command += KShellProcess::quote(name); 00125 00126 makeFrontend()->queueCommand(dir, command); 00127 } 00128 00129 00130 void ClearcasePart::slotCheckout() 00131 { 00132 QString dir, name; 00133 QFileInfo fi(popupfile); 00134 if (fi.isDir()) { 00135 dir = fi.absFilePath(); 00136 name = "."; 00137 } else { 00138 dir = fi.dirPath(); 00139 name = fi.fileName(); 00140 } 00141 00142 CcaseCommentDlg dlg(TRUE); 00143 if (dlg.exec() == QDialog::Rejected) 00144 return; 00145 00146 QDomDocument &dom = *this->projectDom(); 00147 QString message = DomUtil::readEntry(dom,"/kdevclearcase/checkout_options",default_checkout); 00148 if(!dlg.isReserved()) 00149 message += "-unres "; 00150 if(dlg.logMessage().isEmpty()) 00151 message += "-nc "; 00152 else 00153 message += "-c \"" + dlg.logMessage() + "\""; 00154 00155 QString command("cd "); 00156 command += KShellProcess::quote(dir); 00157 command += " && cleartool checkout "; 00158 command += message; 00159 command += " "; 00160 command += KShellProcess::quote(name); 00161 00162 makeFrontend()->queueCommand(dir, command); 00163 } 00164 00165 00166 void ClearcasePart::slotUncheckout() 00167 { 00168 QString dir, name; 00169 QFileInfo fi(popupfile); 00170 if (fi.isDir()) { 00171 dir = fi.absFilePath(); 00172 name = "."; 00173 } else { 00174 dir = fi.dirPath(); 00175 name = fi.fileName(); 00176 } 00177 00178 QDomDocument &dom = *this->projectDom(); 00179 00180 QString command("cd "); 00181 command += KShellProcess::quote(dir); 00182 command += " && cleartool uncheckout "; 00183 command += DomUtil::readEntry(dom,"/kdevclearcase/uncheckout_options",default_uncheckout); 00184 command += " "; 00185 command += KShellProcess::quote(name); 00186 00187 makeFrontend()->queueCommand(dir, command); 00188 } 00189 00190 void ClearcasePart::slotCreate() 00191 { 00192 QFileInfo fi(popupfile); 00193 QString dir = fi.dirPath(); 00194 QString name = fi.fileName(); 00195 00196 QDomDocument &dom = *this->projectDom(); 00197 00198 // Checking whether current directory is checked out or not is cumbersome so skip it for now 00199 QString command("cd "); 00200 command += KShellProcess::quote(dir); 00201 QFileInfo di(dir); 00202 if(!di.isWritable()) { // Work-around to check if directory is checked out 00203 command += " && cleartool co -unres -nc "; 00204 command += KShellProcess::quote(dir); 00205 } 00206 command += " && cleartool mkelem "; 00207 if(fi.isDir()) 00208 command += " -elt directory "; 00209 command += DomUtil::readEntry(dom,"/kdevclearcase/create_options",default_create); 00210 command += " "; 00211 command += KShellProcess::quote(name); 00212 00213 makeFrontend()->queueCommand(dir, command); 00214 } 00215 00216 00217 void ClearcasePart::slotRemove() 00218 { 00219 QFileInfo fi(popupfile); 00220 QString dir = fi.dirPath(); 00221 QString name = fi.fileName(); 00222 00223 QDomDocument &dom = *this->projectDom(); 00224 00225 QString command("cd "); 00226 command += KShellProcess::quote(dir); 00227 QFileInfo di(dir); 00228 if(!di.isWritable()) { // Work-around to check if directory is checked out 00229 command += " && cleartool co -unres -nc "; 00230 command += KShellProcess::quote(dir); 00231 } 00232 command += " && cleartool rmname "; // Don't use rm command 00233 command += DomUtil::readEntry(dom,"/kdevclearcase/remove_options",default_remove); 00234 command += " "; 00235 command += KShellProcess::quote(name); 00236 00237 makeFrontend()->queueCommand(dir, command); 00238 } 00239 00240 00241 void ClearcasePart::slotDiff() 00242 { 00243 QFileInfo fi(popupfile); 00244 QString dir = fi.dirPath(); 00245 QString name = fi.fileName(); 00246 QStringList args; 00247 QStringList env; 00248 QString str; 00249 00250 QDomDocument &dom = *this->projectDom(); 00251 00252 args << "diff"; 00253 str = DomUtil::readEntry(dom,"/kdevclearcase/diff_options",default_diff); 00254 if (str.length()) { 00255 QStringList list = QStringList::split(' ',str); 00256 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) args << *it; 00257 } 00258 args << name; 00259 00260 ExecCommand* cmv = new ExecCommand( "cleartool", args, dir, env, this ); 00261 connect( cmv, SIGNAL(finished( const QString&, const QString& )), 00262 this, SLOT(slotDiffFinished( const QString&, const QString& )) ); 00263 } 00264 00265 void ClearcasePart::slotDiffFinished( const QString& diff, const QString& err ) 00266 { 00267 if ( diff.isNull() && err.isNull() ) { 00268 kdDebug(9000) << "clearcase diff canceled" << endl; 00269 return; // user pressed cancel or an error occured 00270 } 00271 00272 if ( diff.isEmpty() && !err.isEmpty() ) { 00273 KMessageBox::detailedError( 0, i18n("Clearcase outputted errors during diff."), err, i18n("Errors During Diff") ); 00274 return; 00275 } 00276 00277 if ( !err.isEmpty() ) { 00278 int s = KMessageBox::warningContinueCancelList( 0, i18n("Clearcase outputted errors during diff. Do you still want to continue?"), 00279 QStringList::split( "\n", err, false ), i18n("Errors During Diff") ); 00280 if ( s != KMessageBox::Continue ) 00281 return; 00282 } 00283 00284 if ( diff.isEmpty() ) { 00285 KMessageBox::information( 0, i18n("There is no difference to the repository."), i18n("No Difference Found") ); 00286 return; 00287 } 00288 00289 Q_ASSERT( diffFrontend() ); 00290 diffFrontend()->showDiff( diff ); 00291 } 00292 00293 #include "clearcasepart.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:53 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003