1
/***************************************************************************
2
* Copyright (C) 2003 by Ajay Guleria *
3
* ajay_guleria at yahoo dot com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
***************************************************************************/
12
#include "clearcasepart.h"
13
#include "commentdlg.h"
15
#include <qfileinfo.h>
16
#include <qpopupmenu.h>
18
#include <kpopupmenu.h>
20
#include <kdevgenericfactory.h>
23
#include <kmessagebox.h>
24
#include <kapplication.h>
27
#include "kdevmakefrontend.h"
28
#include "kdevdifffrontend.h"
29
#include "kdevappfrontend.h"
30
#include "execcommand.h"
32
#include "kdevmainwindow.h"
33
#include "kdevproject.h"
34
#include "kdevplugininfo.h"
36
#include "clearcasefileinfoprovider.h"
37
#include "clearcasemanipulator.h"
40
static const KDevPluginInfo data("kdevclearcase");
42
typedef KDevGenericFactory<ClearcasePart> ClearcaseFactory;
43
K_EXPORT_COMPONENT_FACTORY( libkdevclearcase, ClearcaseFactory( data ) )
45
ClearcasePart::ClearcasePart( QObject *parent, const char *name, const QStringList & )
46
: KDevVersionControl( &data, parent, name ? name : "ClearcasePart" ),
49
default_uncheckout("-rm"),
50
default_create("-ci"),
52
default_lshistory(""),
53
default_diff("-pred -diff"),
54
default_lscheckout("-recurse")
57
// check if project directory is valid and cache it
58
isValidCCDirectory_ = ClearcaseManipulator::isCCRepository( project()->projectDirectory() );
60
fileInfoProvider_ = new ClearcaseFileinfoProvider(this);
62
setInstance(ClearcaseFactory::instance());
63
connect( core(), SIGNAL(contextMenu(QPopupMenu *, const Context *)),
64
this, SLOT(contextMenu(QPopupMenu *, const Context *)) );
67
ClearcasePart::~ClearcasePart()
72
bool ClearcasePart::isValidDirectory(const QString &dirPath) const {
73
return isValidCCDirectory_;
77
void ClearcasePart::contextMenu(QPopupMenu *popup, const Context *context)
80
if (context->hasType( Context::FileContext )) {
81
const FileContext *fcontext = static_cast<const FileContext*>(context);
82
popupfile_ = fcontext->urls().first().path();
84
QFileInfo fi(popupfile_);
85
popup->insertSeparator();
87
KPopupMenu *sub = new KPopupMenu(popup);
88
QString name = fi.fileName();
89
sub->insertTitle( i18n("Actions for %1").arg(name) );
90
sub->insertItem( i18n("Checkin"),
91
this, SLOT(slotCheckin()) );
92
sub->insertItem( i18n("Checkout"),
93
this, SLOT(slotCheckout()) );
94
sub->insertItem( i18n("Uncheckout"),
95
this, SLOT(slotUncheckout()) );
96
sub->insertSeparator();
97
sub->insertItem( i18n("Create Element"),
98
this, SLOT(slotCreate()) );
99
sub->insertItem( i18n("Remove Element"),
100
this, SLOT(slotRemove()) );
101
sub->insertSeparator();
102
sub->insertItem( i18n("History"),
103
this, SLOT(slotListHistory()) );
104
sub->insertSeparator();
105
sub->insertItem( i18n("Diff"),
106
this, SLOT(slotDiff()) );
108
sub->insertSeparator();
109
sub->insertItem( i18n("List Checkouts"),
110
this, SLOT(slotListCheckouts()) );
112
popup->insertItem(i18n("Clearcase"), sub);
114
if (!project() || !isValidDirectory( project()->projectDirectory() )) {
115
sub->setEnabled( false );
121
void ClearcasePart::slotCheckin()
124
QFileInfo fi(popupfile_);
126
name = fi.fileName();
128
CcaseCommentDlg dlg(FALSE);
129
if (dlg.exec() == QDialog::Rejected)
132
QDomDocument &dom = *this->projectDom();
133
QString message = DomUtil::readEntry(dom,"/kdevclearcase/checkin_options",default_checkin);
134
if(dlg.logMessage().isEmpty())
137
message += "-c \"" + dlg.logMessage() + "\"";
139
QString command("cd ");
140
command += KShellProcess::quote(dir);
142
command += " cleartool checkin ";
143
command += message; // Already quoted, see above
145
command += KShellProcess::quote(name);
147
if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
148
makeFrontend->queueCommand(dir, command);
152
void ClearcasePart::slotCheckout()
155
QFileInfo fi(popupfile_);
157
name = fi.fileName();
159
CcaseCommentDlg dlg(TRUE);
160
if (dlg.exec() == QDialog::Rejected)
163
QDomDocument &dom = *this->projectDom();
164
QString message = DomUtil::readEntry(dom,"/kdevclearcase/checkout_options",default_checkout);
165
if(!dlg.isReserved())
166
message += "-unres ";
167
if(dlg.logMessage().isEmpty())
170
message += "-c \"" + dlg.logMessage() + "\"";
172
QString command("cd ");
173
command += KShellProcess::quote(dir);
174
command += " && cleartool checkout ";
177
command += KShellProcess::quote(name);
179
if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
180
makeFrontend->queueCommand(dir, command);
182
emit finishedFetching(dir);
186
void ClearcasePart::slotUncheckout()
189
QFileInfo fi(popupfile_);
191
name = fi.fileName();
193
QDomDocument &dom = *this->projectDom();
195
QString command("cd ");
196
command += KShellProcess::quote(dir);
197
command += " && cleartool uncheckout ";
198
command += DomUtil::readEntry(dom,"/kdevclearcase/uncheckout_options",default_uncheckout);
200
command += KShellProcess::quote(name);
202
if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
203
makeFrontend->queueCommand(dir, command);
205
emit finishedFetching(dir);
208
void ClearcasePart::slotCreate()
210
QFileInfo fi(popupfile_);
211
QString dir = fi.dirPath();
212
QString name = fi.fileName();
214
QDomDocument &dom = *this->projectDom();
216
// Checking whether current directory is checked out or not is cumbersome so skip it for now
217
QString command("cd ");
218
command += KShellProcess::quote(dir);
220
if(!di.isWritable()) { // Work-around to check if directory is checked out
221
command += " && cleartool co -unres -nc ";
222
command += KShellProcess::quote(dir);
224
command += " && cleartool mkelem ";
226
command += " -elt directory ";
227
command += DomUtil::readEntry(dom,"/kdevclearcase/create_options",default_create);
229
command += KShellProcess::quote(name);
231
if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
232
makeFrontend->queueCommand(dir, command);
234
emit finishedFetching(dir);
238
void ClearcasePart::slotRemove()
240
QFileInfo fi(popupfile_);
241
QString dir = fi.dirPath();
242
QString name = fi.fileName();
244
QDomDocument &dom = *this->projectDom();
246
QString command("cd ");
247
command += KShellProcess::quote(dir);
249
if(!di.isWritable()) { // Work-around to check if directory is checked out
250
command += " && cleartool co -unres -nc ";
251
command += KShellProcess::quote(dir);
253
command += " && cleartool rmname "; // Don't use rm command
254
command += DomUtil::readEntry(dom,"/kdevclearcase/remove_options",default_remove);
256
command += KShellProcess::quote(name);
258
if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
259
makeFrontend->queueCommand(dir, command);
261
emit finishedFetching(dir);
264
void ClearcasePart::slotListHistory()
266
QFileInfo fi(popupfile_);
267
QString dir = fi.dirPath();
268
QString name = fi.fileName();
273
QDomDocument &dom = *this->projectDom();
275
QString command("cd ");
276
command += KShellProcess::quote(dir);
277
command += " && cleartool lshistory ";
278
command += DomUtil::readEntry(dom, "/kdevclearcase/lshistory_options", default_lshistory);
280
command += KShellProcess::quote(name);
282
if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
283
makeFrontend->queueCommand(dir, command);
286
void ClearcasePart::slotDiff()
288
QFileInfo fi(popupfile_);
289
QString dir = fi.dirPath();
290
QString name = fi.fileName();
295
QDomDocument &dom = *this->projectDom();
298
str = DomUtil::readEntry(dom,"/kdevclearcase/diff_options",default_diff);
300
QStringList list = QStringList::split(' ',str);
301
for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) args << *it;
306
ExecCommand* cmv = new ExecCommand( "cleartool", args, dir, env, this );
307
connect( cmv, SIGNAL(finished( const QString&, const QString& )),
308
this, SLOT(slotDiffFinished( const QString&, const QString& )) );
312
void ClearcasePart::slotDiffFinished( const QString& diff, const QString& err )
314
if ( diff.isNull() && err.isNull() ) {
315
kdDebug(9000) << "clearcase diff canceled" << endl;
316
return; // user pressed cancel or an error occured
319
if ( diff.isEmpty() && !err.isEmpty() ) {
320
KMessageBox::detailedError( 0, i18n("Clearcase output errors during diff."), err, i18n("Errors During Diff") );
324
if ( !err.isEmpty() ) {
325
int s = KMessageBox::warningContinueCancelList( 0, i18n("Clearcase outputted errors during diff. Do you still want to continue?"),
326
QStringList::split( "\n", err, false ), i18n("Errors During Diff") );
327
if ( s != KMessageBox::Continue )
331
if ( diff.isEmpty() ) {
332
KMessageBox::information( 0, i18n("There is no difference to the repository."), i18n("No Difference Found") );
336
if (KDevDiffFrontend *diffFrontend = extension<KDevDiffFrontend>("KDevelop/DiffFrontend"))
337
diffFrontend->showDiff( diff );
340
void ClearcasePart::slotListCheckouts()
343
QFileInfo fi(popupfile_);
345
dir = fi.absFilePath();
350
QDomDocument &dom = *this->projectDom();
352
QString command("cd ");
353
command += KShellProcess::quote(dir);
354
command += " && cleartool lsco ";
355
command += DomUtil::readEntry(dom, "/kdevclearcase/lscheckout_options", default_lscheckout);
357
if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
358
makeFrontend->queueCommand(dir, command);
363
#include "clearcasepart.moc"