~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to vcs/clearcase/clearcasepart.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2003 by Ajay Guleria                                    *
3
 
 *   ajay_guleria at yahoo dot com                                         *
4
 
 *                                                                         *
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.                                   *
9
 
 *                                                                         *
10
 
 ***************************************************************************/
11
 
 
12
 
#include "clearcasepart.h"
13
 
#include "commentdlg.h"
14
 
 
15
 
#include <qfileinfo.h>
16
 
#include <qpopupmenu.h>
17
 
 
18
 
#include <kpopupmenu.h>
19
 
#include <kdebug.h>
20
 
#include <kdevgenericfactory.h>
21
 
#include <klocale.h>
22
 
#include <kprocess.h>
23
 
#include <kmessagebox.h>
24
 
#include <kapplication.h>
25
 
 
26
 
#include "kdevcore.h"
27
 
#include "kdevmakefrontend.h"
28
 
#include "kdevdifffrontend.h"
29
 
#include "kdevappfrontend.h"
30
 
#include "execcommand.h"
31
 
#include "domutil.h"
32
 
#include "kdevmainwindow.h"
33
 
#include "kdevproject.h"
34
 
#include "kdevplugininfo.h"
35
 
 
36
 
#include "clearcasefileinfoprovider.h"
37
 
#include "clearcasemanipulator.h"
38
 
 
39
 
 
40
 
static const KDevPluginInfo data("kdevclearcase");
41
 
 
42
 
typedef KDevGenericFactory<ClearcasePart> ClearcaseFactory;
43
 
K_EXPORT_COMPONENT_FACTORY( libkdevclearcase, ClearcaseFactory( data ) )
44
 
 
45
 
ClearcasePart::ClearcasePart( QObject *parent, const char *name, const QStringList & )
46
 
        : KDevVersionControl( &data, parent, name ? name : "ClearcasePart" ),
47
 
          default_checkin(""),
48
 
          default_checkout(""),
49
 
          default_uncheckout("-rm"),
50
 
          default_create("-ci"),
51
 
          default_remove("-f"),
52
 
          default_lshistory(""),
53
 
          default_diff("-pred -diff"),
54
 
          default_lscheckout("-recurse")
55
 
{
56
 
 
57
 
    // check if project directory is valid and cache it
58
 
    isValidCCDirectory_ = ClearcaseManipulator::isCCRepository( project()->projectDirectory() );
59
 
 
60
 
    fileInfoProvider_ = new ClearcaseFileinfoProvider(this);
61
 
 
62
 
    setInstance(ClearcaseFactory::instance());
63
 
    connect( core(), SIGNAL(contextMenu(QPopupMenu *, const Context *)),
64
 
             this, SLOT(contextMenu(QPopupMenu *, const Context *)) );
65
 
}
66
 
 
67
 
ClearcasePart::~ClearcasePart()
68
 
{}
69
 
 
70
 
 
71
 
 
72
 
bool ClearcasePart::isValidDirectory(const QString &dirPath) const {
73
 
    return isValidCCDirectory_;
74
 
}
75
 
 
76
 
 
77
 
void ClearcasePart::contextMenu(QPopupMenu *popup, const Context *context)
78
 
{
79
 
 
80
 
    if (context->hasType( Context::FileContext )) {
81
 
        const FileContext *fcontext = static_cast<const FileContext*>(context);
82
 
        popupfile_ = fcontext->urls().first().path();
83
 
 
84
 
        QFileInfo fi(popupfile_);
85
 
        popup->insertSeparator();
86
 
 
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()) );
107
 
 
108
 
        sub->insertSeparator();
109
 
        sub->insertItem( i18n("List Checkouts"),
110
 
                         this, SLOT(slotListCheckouts()) );
111
 
 
112
 
        popup->insertItem(i18n("Clearcase"), sub);
113
 
 
114
 
        if (!project() || !isValidDirectory( project()->projectDirectory() )) {
115
 
            sub->setEnabled( false );
116
 
        }
117
 
    }
118
 
}
119
 
 
120
 
 
121
 
void ClearcasePart::slotCheckin()
122
 
{
123
 
    QString dir, name;
124
 
    QFileInfo fi(popupfile_);
125
 
    dir = fi.dirPath();
126
 
    name = fi.fileName();
127
 
 
128
 
    CcaseCommentDlg dlg(FALSE);
129
 
    if (dlg.exec() == QDialog::Rejected)
130
 
        return;
131
 
 
132
 
    QDomDocument &dom = *this->projectDom();
133
 
    QString message = DomUtil::readEntry(dom,"/kdevclearcase/checkin_options",default_checkin);
134
 
    if(dlg.logMessage().isEmpty())
135
 
        message += "-nc ";
136
 
    else
137
 
        message += "-c \"" + dlg.logMessage() + "\"";
138
 
 
139
 
    QString command("cd ");
140
 
    command += KShellProcess::quote(dir);
141
 
    command += " && ";
142
 
    command += " cleartool checkin ";
143
 
    command += message; // Already quoted, see above
144
 
    command += " ";
145
 
    command += KShellProcess::quote(name);
146
 
 
147
 
    if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
148
 
        makeFrontend->queueCommand(dir, command);
149
 
}
150
 
 
151
 
 
152
 
void ClearcasePart::slotCheckout()
153
 
{
154
 
    QString dir, name;
155
 
    QFileInfo fi(popupfile_);
156
 
    dir = fi.dirPath();
157
 
    name = fi.fileName();
158
 
 
159
 
    CcaseCommentDlg dlg(TRUE);
160
 
    if (dlg.exec() == QDialog::Rejected)
161
 
        return;
162
 
 
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())
168
 
       message += "-nc ";
169
 
    else
170
 
       message += "-c \"" + dlg.logMessage() + "\"";
171
 
 
172
 
    QString command("cd ");
173
 
    command += KShellProcess::quote(dir);
174
 
    command += " && cleartool checkout ";
175
 
    command += message;
176
 
    command += " ";
177
 
    command += KShellProcess::quote(name);
178
 
 
179
 
    if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
180
 
        makeFrontend->queueCommand(dir, command);
181
 
 
182
 
    emit finishedFetching(dir);
183
 
}
184
 
 
185
 
 
186
 
void ClearcasePart::slotUncheckout()
187
 
{
188
 
    QString dir, name;
189
 
    QFileInfo fi(popupfile_);
190
 
    dir = fi.dirPath();
191
 
    name = fi.fileName();
192
 
 
193
 
    QDomDocument &dom = *this->projectDom();
194
 
 
195
 
    QString command("cd ");
196
 
    command += KShellProcess::quote(dir);
197
 
    command += " && cleartool uncheckout ";
198
 
    command += DomUtil::readEntry(dom,"/kdevclearcase/uncheckout_options",default_uncheckout);
199
 
    command += " ";
200
 
    command += KShellProcess::quote(name);
201
 
 
202
 
    if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
203
 
        makeFrontend->queueCommand(dir, command);
204
 
 
205
 
    emit finishedFetching(dir);
206
 
}
207
 
 
208
 
void ClearcasePart::slotCreate()
209
 
{
210
 
    QFileInfo fi(popupfile_);
211
 
    QString dir = fi.dirPath();
212
 
    QString name = fi.fileName();
213
 
 
214
 
    QDomDocument &dom = *this->projectDom();
215
 
 
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);
219
 
    QFileInfo di(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);
223
 
    }
224
 
    command += " && cleartool mkelem ";
225
 
    if(fi.isDir())
226
 
        command += " -elt directory ";
227
 
    command += DomUtil::readEntry(dom,"/kdevclearcase/create_options",default_create);
228
 
    command += " ";
229
 
    command += KShellProcess::quote(name);
230
 
 
231
 
    if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
232
 
        makeFrontend->queueCommand(dir, command);
233
 
 
234
 
    emit finishedFetching(dir);
235
 
}
236
 
 
237
 
 
238
 
void ClearcasePart::slotRemove()
239
 
{
240
 
    QFileInfo fi(popupfile_);
241
 
    QString dir = fi.dirPath();
242
 
    QString name = fi.fileName();
243
 
 
244
 
    QDomDocument &dom = *this->projectDom();
245
 
 
246
 
    QString command("cd ");
247
 
    command += KShellProcess::quote(dir);
248
 
    QFileInfo di(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);
252
 
    }
253
 
    command += " && cleartool rmname "; // Don't use rm command
254
 
    command += DomUtil::readEntry(dom,"/kdevclearcase/remove_options",default_remove);
255
 
    command += " ";
256
 
    command += KShellProcess::quote(name);
257
 
 
258
 
    if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
259
 
        makeFrontend->queueCommand(dir, command);
260
 
 
261
 
    emit finishedFetching(dir);
262
 
}
263
 
 
264
 
void ClearcasePart::slotListHistory()
265
 
{
266
 
    QFileInfo fi(popupfile_);
267
 
    QString dir = fi.dirPath();
268
 
    QString name = fi.fileName();
269
 
    QStringList args;
270
 
    QStringList env;
271
 
    QString str;
272
 
 
273
 
    QDomDocument &dom = *this->projectDom();
274
 
 
275
 
    QString command("cd ");
276
 
    command += KShellProcess::quote(dir);
277
 
    command += " && cleartool lshistory ";
278
 
    command += DomUtil::readEntry(dom, "/kdevclearcase/lshistory_options", default_lshistory);
279
 
    command += " ";
280
 
    command += KShellProcess::quote(name);
281
 
 
282
 
    if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
283
 
        makeFrontend->queueCommand(dir, command);
284
 
}
285
 
 
286
 
void ClearcasePart::slotDiff()
287
 
{
288
 
    QFileInfo fi(popupfile_);
289
 
    QString dir = fi.dirPath();
290
 
    QString name = fi.fileName();
291
 
    QStringList args;
292
 
    QStringList env;
293
 
    QString str;
294
 
 
295
 
    QDomDocument &dom = *this->projectDom();
296
 
 
297
 
    args << "diff";
298
 
    str = DomUtil::readEntry(dom,"/kdevclearcase/diff_options",default_diff);
299
 
    if (str.length()) {
300
 
        QStringList list = QStringList::split(' ',str);
301
 
        for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) args << *it;
302
 
    }
303
 
 
304
 
    args << name;
305
 
 
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& )) );
309
 
}
310
 
 
311
 
 
312
 
void ClearcasePart::slotDiffFinished( const QString& diff, const QString& err )
313
 
{
314
 
    if ( diff.isNull() && err.isNull() ) {
315
 
        kdDebug(9000) << "clearcase diff canceled" << endl;
316
 
        return; // user pressed cancel or an error occured
317
 
    }
318
 
 
319
 
    if ( diff.isEmpty() && !err.isEmpty() ) {
320
 
        KMessageBox::detailedError( 0, i18n("Clearcase output errors during diff."), err, i18n("Errors During Diff") );
321
 
        return;
322
 
    }
323
 
 
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 )
328
 
            return;
329
 
    }
330
 
 
331
 
    if ( diff.isEmpty() ) {
332
 
        KMessageBox::information( 0, i18n("There is no difference to the repository."), i18n("No Difference Found") );
333
 
        return;
334
 
    }
335
 
 
336
 
    if (KDevDiffFrontend *diffFrontend = extension<KDevDiffFrontend>("KDevelop/DiffFrontend"))
337
 
        diffFrontend->showDiff( diff );
338
 
}
339
 
 
340
 
void ClearcasePart::slotListCheckouts()
341
 
{
342
 
    QString dir;
343
 
    QFileInfo fi(popupfile_);
344
 
    if (fi.isDir()) {
345
 
        dir = fi.absFilePath();
346
 
    } else {
347
 
        dir = fi.dirPath();
348
 
    }
349
 
 
350
 
    QDomDocument &dom = *this->projectDom();
351
 
 
352
 
    QString command("cd ");
353
 
    command += KShellProcess::quote(dir);
354
 
    command += " && cleartool lsco ";
355
 
    command += DomUtil::readEntry(dom, "/kdevclearcase/lscheckout_options", default_lscheckout);
356
 
 
357
 
    if (KDevMakeFrontend *makeFrontend = extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
358
 
        makeFrontend->queueCommand(dir, command);
359
 
 
360
 
}
361
 
 
362
 
 
363
 
#include "clearcasepart.moc"