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

« back to all changes in this revision

Viewing changes to vcs/cvsservice/cvspartimpl.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 Mario Scalas                                    *
3
 
 *   mario.scalas@libero.it                                                *
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 <qfile.h>
13
 
#include <qfileinfo.h>
14
 
#include <qdir.h>
15
 
#include<qcheckbox.h>
16
 
 
17
 
#include <kapplication.h>
18
 
#include <kmessagebox.h>
19
 
#include <kdebug.h>
20
 
#include <kdeversion.h>
21
 
#include <klocale.h>
22
 
#include <kprocess.h>
23
 
#include <kstandarddirs.h>
24
 
#include <kmainwindow.h>
25
 
#include <dcopref.h>
26
 
// CvsService stuff
27
 
#include <repository_stub.h>
28
 
#include <cvsservice_stub.h>
29
 
#include <cvsjob_stub.h>
30
 
// KDevelop SDK stuff
31
 
#include <urlutil.h>
32
 
#include <kdevproject.h>
33
 
#include <kdevmainwindow.h>
34
 
#include <kdevcore.h>
35
 
#include <kdevdifffrontend.h>
36
 
#include <kdevmakefrontend.h>
37
 
#include <kdevpartcontroller.h>
38
 
// Part's widgets
39
 
#include "cvsprocesswidget.h"
40
 
#include "checkoutdialog.h"
41
 
#include "commitdlg.h"
42
 
#include "tagdialog.h"
43
 
#include "diffdialog.h"
44
 
#include "releaseinputdialog.h"
45
 
#include "cvslogdialog.h"
46
 
#include "editorsdialog.h"
47
 
#include "annotatedialog.h"
48
 
 
49
 
#include "changelog.h"
50
 
#include "cvsoptions.h"
51
 
#include "cvsdir.h"
52
 
#include "cvsentry.h"
53
 
#include "jobscheduler.h"
54
 
#include "cvsfileinfoprovider.h"
55
 
 
56
 
#include "cvspart.h"
57
 
#include "cvspartimpl.h"
58
 
 
59
 
///////////////////////////////////////////////////////////////////////////////
60
 
// class Constants
61
 
///////////////////////////////////////////////////////////////////////////////
62
 
 
63
 
// Nice name (relative to projectDirectory()) ;-)
64
 
const QString CvsServicePartImpl::changeLogFileName( "ChangeLog" );
65
 
// Four spaces for every log line (except the first, which includes the
66
 
// developers name)
67
 
const QString CvsServicePartImpl::changeLogPrependString( "    " );
68
 
 
69
 
///////////////////////////////////////////////////////////////////////////////
70
 
// class CvsServicePartImpl
71
 
///////////////////////////////////////////////////////////////////////////////
72
 
 
73
 
CvsServicePartImpl::CvsServicePartImpl( CvsServicePart *part, const char *name )
74
 
    : QObject( this, name? name : "cvspartimpl" ),
75
 
    m_scheduler( 0 ), m_part( part ), m_widget( 0 )
76
 
{
77
 
    if (requestCvsService())
78
 
    {
79
 
        m_widget = new CvsProcessWidget( m_cvsService, part, 0, "cvsprocesswidget" );
80
 
        m_scheduler = new DirectScheduler( m_widget );
81
 
        m_fileInfoProvider = new CVSFileInfoProvider( part, m_cvsService );
82
 
    
83
 
        connect( core(), SIGNAL(projectOpened()), this, SLOT(slotProjectOpened()) );
84
 
    }
85
 
    else
86
 
    {
87
 
        kdDebug(9006) << "CvsServicePartImpl::CvsServicePartImpl(): somebody kills me because"
88
 
            "I could not request a valid CvsService!!!! :-((( " << endl;
89
 
    }
90
 
 
91
 
}
92
 
 
93
 
///////////////////////////////////////////////////////////////////////////////
94
 
 
95
 
CvsServicePartImpl::~CvsServicePartImpl()
96
 
{
97
 
    if (processWidget())
98
 
    {
99
 
        // Inform toplevel, that the output view is gone
100
 
        mainWindow()->removeView( m_widget );
101
 
        delete m_widget;
102
 
    }
103
 
    delete m_scheduler;
104
 
    //delete m_fileInfoProvider;
105
 
    releaseCvsService();
106
 
}
107
 
 
108
 
///////////////////////////////////////////////////////////////////////////////
109
 
 
110
 
bool CvsServicePartImpl::prepareOperation( const KURL::List &someUrls, CvsOperation op )
111
 
{
112
 
    kdDebug(9006) << k_funcinfo << endl;
113
 
 
114
 
    bool correctlySetup = (m_cvsService != 0) && (m_repository != 0);
115
 
    if (!correctlySetup)
116
 
    {
117
 
        kdDebug(9006) << "DCOP CvsService is not available!!!" << endl;
118
 
        return false;
119
 
    }
120
 
 
121
 
    KURL::List urls = someUrls;
122
 
    URLUtil::dump( urls, "Requested CVS operation for: " );
123
 
 
124
 
    if (!m_part->project())
125
 
    {
126
 
        kdDebug(9006) << k_funcinfo << "No project???" << endl;
127
 
        KMessageBox::sorry( 0, i18n("Open a project first.\nOperation will be aborted.") );
128
 
        return false;
129
 
    }
130
 
 
131
 
    if (m_widget->isAlreadyWorking())
132
 
    {
133
 
        if (KMessageBox::warningYesNo( 0,
134
 
            i18n("Another CVS operation is executing: do you want to cancel it \n"
135
 
                "and start this new one?"),
136
 
            i18n("CVS: Operation Already Pending ")) == KMessageBox::Yes)
137
 
        {
138
 
            m_widget->cancelJob();
139
 
        }
140
 
        else // Operation canceled
141
 
        {
142
 
            kdDebug(9006) << k_funcinfo << "Operation canceled by user request" << endl;
143
 
            return false;
144
 
        }
145
 
    }
146
 
 
147
 
    validateURLs( projectDirectory(),  urls, op );
148
 
    if (urls.count() <= 0) // who knows? ;)
149
 
    {
150
 
        kdDebug(9006) << "CvsServicePartImpl::prepareOperation(): No valid document URL selected!!!" << endl;
151
 
        KMessageBox::sorry( 0, i18n("None of the file(s) you selected seem to be valid for repository.") );
152
 
        return false;
153
 
    }
154
 
 
155
 
    URLUtil::dump( urls );
156
 
    // Save for later use
157
 
    m_urlList = urls;
158
 
    m_lastOperation = op;
159
 
 
160
 
    return true;
161
 
}
162
 
 
163
 
///////////////////////////////////////////////////////////////////////////////
164
 
 
165
 
void CvsServicePartImpl::doneOperation( const KURL::List &/*someUrls*/, CvsOperation /*op*/ )
166
 
{
167
 
    kdDebug(9006) << k_funcinfo << endl;
168
 
 
169
 
    // @ todo notify clients (filetree) about changed status?)
170
 
}
171
 
 
172
 
///////////////////////////////////////////////////////////////////////////////
173
 
 
174
 
const KURL::List &CvsServicePartImpl::urlList() const
175
 
{
176
 
    return m_urlList;
177
 
}
178
 
 
179
 
///////////////////////////////////////////////////////////////////////////////
180
 
 
181
 
QStringList CvsServicePartImpl::fileList( bool relativeToProjectDir ) const
182
 
{
183
 
    if (relativeToProjectDir)
184
 
        return URLUtil::toRelativePaths( projectDirectory(), urlList() );
185
 
    else
186
 
        return urlList().toStringList();
187
 
}
188
 
 
189
 
///////////////////////////////////////////////////////////////////////////////
190
 
 
191
 
bool CvsServicePartImpl::isRegisteredInRepository( const QString &projectDirectory, const KURL &url )
192
 
{
193
 
    kdDebug(9006) << k_funcinfo << endl;
194
 
 
195
 
    // KURL::directory() is a bit tricky when used on file or _dir_ paths ;-)
196
 
    KURL projectURL = KURL::fromPathOrURL( projectDirectory );
197
 
    kdDebug(9006) << k_funcinfo << "projectURL = " << projectURL.url() << endl;
198
 
    kdDebug(9006) << k_funcinfo << "url        = " << url.url() << endl;
199
 
 
200
 
    if ( projectURL == url)
201
 
    {
202
 
        CVSDir cvsdir = CVSDir( projectDirectory );
203
 
        return cvsdir.isValid();
204
 
    }
205
 
    else
206
 
    {
207
 
        CVSDir cvsdir = CVSDir( url.directory() );
208
 
 
209
 
        if (!cvsdir.isValid())
210
 
        {
211
 
            kdDebug(9006) << k_funcinfo << " Error: " << cvsdir.path() << " is not a valid CVS directory " << endl;
212
 
            return false;
213
 
        }
214
 
        CVSEntry entry = cvsdir.fileStatus( url.fileName() );
215
 
        return entry.isValid();
216
 
    }
217
 
}
218
 
 
219
 
///////////////////////////////////////////////////////////////////////////////
220
 
 
221
 
void CvsServicePartImpl::validateURLs( const QString &projectDirectory, KURL::List &urls, CvsOperation op )
222
 
{
223
 
    kdDebug(9006) << k_funcinfo << endl;
224
 
 
225
 
    // If files are to be added, we can avoid to check them to see if they are registered in the
226
 
    // repository ;)
227
 
    if (op == opAdd)
228
 
    {
229
 
        kdDebug(9006) << "This is a Cvs Add operation and will not be checked against repository ;-)" << endl;
230
 
        return;
231
 
    }
232
 
    QValueList<KURL>::iterator it = urls.begin();
233
 
    while (it != urls.end())
234
 
    {
235
 
        if (!CvsServicePartImpl::isRegisteredInRepository( projectDirectory, (*it) ))
236
 
        {
237
 
            kdDebug(9006) << "Warning: file " << (*it).path() << " does NOT belong to repository and will not be used" << endl;
238
 
 
239
 
            it = urls.erase( it );
240
 
        }
241
 
        else
242
 
        {
243
 
            kdDebug(9006) << "Warning: file " << (*it).path() << " is in repository and will be accepted" << endl;
244
 
 
245
 
            ++it;
246
 
        }
247
 
    }
248
 
}
249
 
 
250
 
///////////////////////////////////////////////////////////////////////////////
251
 
 
252
 
void CvsServicePartImpl::addToIgnoreList( const QString &projectDirectory, const KURL &url )
253
 
{
254
 
    kdDebug(9006) << k_funcinfo << endl;
255
 
 
256
 
    if ( url.path() == projectDirectory )
257
 
    {
258
 
        kdDebug(9006) << "Can't add to ignore list current project directory " << endl;
259
 
        return;
260
 
    }
261
 
 
262
 
    CVSDir cvsdir( url.directory() );
263
 
    cvsdir.ignoreFile( url.fileName() );
264
 
}
265
 
 
266
 
void CvsServicePartImpl::addToIgnoreList( const QString &projectDirectory, const KURL::List &urls )
267
 
{
268
 
    for (size_t i=0; i<urls.count(); ++i)
269
 
    {
270
 
        addToIgnoreList( projectDirectory, urls[i] );
271
 
    }
272
 
}
273
 
 
274
 
///////////////////////////////////////////////////////////////////////////////
275
 
 
276
 
void CvsServicePartImpl::removeFromIgnoreList( const QString &/*projectDirectory*/, const KURL &url )
277
 
{
278
 
    kdDebug(9006) << k_funcinfo << endl;
279
 
 
280
 
    QStringList ignoreLines;
281
 
 
282
 
    CVSDir cvsdir( url.directory() );
283
 
    cvsdir.doNotIgnoreFile( url.fileName() );
284
 
}
285
 
 
286
 
void CvsServicePartImpl::removeFromIgnoreList( const QString &projectDirectory, const KURL::List &urls )
287
 
{
288
 
    for (size_t i=0; i<urls.count(); ++i)
289
 
    {
290
 
        removeFromIgnoreList( projectDirectory, urls[i] );
291
 
    }
292
 
}
293
 
 
294
 
///////////////////////////////////////////////////////////////////////////////
295
 
 
296
 
bool CvsServicePartImpl::isValidDirectory( const QDir &dir ) const
297
 
{
298
 
    CVSDir cvsdir( dir );
299
 
 
300
 
    return cvsdir.isValid();
301
 
}
302
 
 
303
 
///////////////////////////////////////////////////////////////////////////////
304
 
 
305
 
CvsProcessWidget *CvsServicePartImpl::processWidget() const
306
 
{
307
 
    return m_widget;
308
 
}
309
 
 
310
 
///////////////////////////////////////////////////////////////////////////////
311
 
 
312
 
KDevMainWindow *CvsServicePartImpl::mainWindow() const
313
 
{
314
 
    return m_part->mainWindow();
315
 
}
316
 
 
317
 
///////////////////////////////////////////////////////////////////////////////
318
 
 
319
 
QString CvsServicePartImpl::projectDirectory() const
320
 
{
321
 
    return m_part->project() ? m_part->project()->projectDirectory() : QString::null;
322
 
}
323
 
 
324
 
///////////////////////////////////////////////////////////////////////////////
325
 
 
326
 
KDevCore *CvsServicePartImpl::core() const
327
 
{
328
 
    return m_part->core();
329
 
}
330
 
 
331
 
///////////////////////////////////////////////////////////////////////////////
332
 
 
333
 
KDevDiffFrontend *CvsServicePartImpl::diffFrontend() const
334
 
{
335
 
    return m_part->extension<KDevDiffFrontend>("KDevelop/DiffFrontend");
336
 
}
337
 
 
338
 
///////////////////////////////////////////////////////////////////////////////
339
 
 
340
 
void CvsServicePartImpl::login()
341
 
{
342
 
    DCOPRef job = m_cvsService->login( this->projectDirectory() );
343
 
 
344
 
    m_scheduler->schedule( job );
345
 
}
346
 
 
347
 
///////////////////////////////////////////////////////////////////////////////
348
 
 
349
 
void CvsServicePartImpl::logout()
350
 
{
351
 
    DCOPRef job = m_cvsService->logout( this->projectDirectory() );
352
 
 
353
 
    m_scheduler->schedule( job );
354
 
}
355
 
 
356
 
///////////////////////////////////////////////////////////////////////////////
357
 
 
358
 
bool CvsServicePartImpl::checkout()
359
 
{
360
 
    kdDebug(9006) << k_funcinfo << endl;
361
 
 
362
 
    CheckoutDialog dlg( m_cvsService, mainWindow()->main()->centralWidget() );
363
 
 
364
 
    if ( dlg.exec() == QDialog::Accepted )
365
 
    {
366
 
        DCOPRef job = m_cvsService->checkout( dlg.workDir(), dlg.serverPath(),
367
 
            dlg.module(), dlg.tag(), dlg.pruneDirs(), "", false
368
 
        );
369
 
        if (!m_cvsService->ok()) {
370
 
            KMessageBox::sorry( mainWindow()->main(), i18n( "Unable to checkout" ) );
371
 
        } else {
372
 
                // Save the path for later retrieval since slotCheckoutFinished(bool,int)
373
 
                // will use it for return the info to the caller.
374
 
                        modulePath = dlg.workDir() + dlg.module();
375
 
 
376
 
                m_scheduler->schedule( job );
377
 
                connect( processWidget(), SIGNAL(jobFinished(bool,int)), this, SLOT(slotCheckoutFinished(bool,int)) );
378
 
                        return true;
379
 
                }
380
 
    }
381
 
        return false;
382
 
}
383
 
 
384
 
///////////////////////////////////////////////////////////////////////////////
385
 
 
386
 
void CvsServicePartImpl::commit( const KURL::List& urlList )
387
 
{
388
 
    kdDebug(9006) << k_funcinfo << endl;
389
 
    kdDebug(9006) << "Commit requested for " << urlList.count() << " file(s)." << endl;
390
 
 
391
 
    if (!prepareOperation( urlList, opCommit ))
392
 
        return;
393
 
 
394
 
    CommitDialog dlg( projectDirectory() + "/ChangeLog" );
395
 
    if (dlg.exec() == QDialog::Rejected)
396
 
        return;
397
 
 
398
 
    CvsOptions *options = CvsOptions::instance();
399
 
    QString logString = dlg.logMessage().join( "\n" );
400
 
 
401
 
    DCOPRef cvsJob = m_cvsService->commit( fileList(), logString, options->recursiveWhenCommitRemove() );
402
 
    if (!m_cvsService->ok())
403
 
    {
404
 
        kdDebug( 9006 ) << "Commit of " << fileList().join( ", " ) << " failed!!!" << endl;
405
 
        return;
406
 
    }
407
 
 
408
 
    m_scheduler->schedule( cvsJob );
409
 
    connect( processWidget(), SIGNAL(jobFinished(bool,int)), this, SLOT(slotJobFinished(bool,int)) );
410
 
 
411
 
    // 2. if requested to do so, add an entry to the Changelog too
412
 
    if (dlg.mustAddToChangeLog())
413
 
    {
414
 
        // 2.1 Modify the Changelog
415
 
        ChangeLogEntry entry;
416
 
        entry.addLines( dlg.logMessage() );
417
 
        entry.addToLog( dlg.changeLogFileName() );
418
 
 
419
 
        kdDebug( 9006 ) << " *** ChangeLog entry : " <<
420
 
            entry.toString( changeLogPrependString ) << endl;
421
 
    }
422
 
 
423
 
    doneOperation( KURL::List( fileList() ), opCommit );
424
 
}
425
 
 
426
 
///////////////////////////////////////////////////////////////////////////////
427
 
 
428
 
void CvsServicePartImpl::update( const KURL::List& urlList )
429
 
{
430
 
    kdDebug(9006) << k_funcinfo << endl;
431
 
 
432
 
    if (!prepareOperation( urlList, opCommit ))
433
 
        return;
434
 
 
435
 
    CvsOptions *options = CvsOptions::instance();
436
 
    ReleaseInputDialog dlg( mainWindow()->main()->centralWidget() );
437
 
    if (dlg.exec() == QDialog::Rejected)
438
 
        return;
439
 
 
440
 
    QString additionalOptions = dlg.release();
441
 
    if (dlg.isRevert())
442
 
        additionalOptions = additionalOptions + " " + options->revertOptions();
443
 
 
444
 
    DCOPRef cvsJob = m_cvsService->update( fileList(),
445
 
        options->recursiveWhenUpdate(),
446
 
        options->createDirsWhenUpdate(),
447
 
        options->pruneEmptyDirsWhenUpdate(),
448
 
        additionalOptions );
449
 
 
450
 
    m_scheduler->schedule( cvsJob );
451
 
    connect( processWidget(), SIGNAL(jobFinished(bool,int)), this, SLOT(slotJobFinished(bool,int)) );
452
 
 
453
 
    doneOperation();
454
 
}
455
 
 
456
 
///////////////////////////////////////////////////////////////////////////////
457
 
 
458
 
void CvsServicePartImpl::add( const KURL::List& urlList, bool binary )
459
 
{
460
 
    kdDebug(9006) << k_funcinfo << endl;
461
 
 
462
 
    if (!prepareOperation( urlList, opAdd ))
463
 
        return;
464
 
 
465
 
    DCOPRef cvsJob = m_cvsService->add( fileList(), binary );
466
 
 
467
 
    m_scheduler->schedule( cvsJob );
468
 
    connect( processWidget(), SIGNAL(jobFinished(bool,int)), this, SLOT(slotJobFinished(bool,int)) );
469
 
 
470
 
    doneOperation();
471
 
}
472
 
 
473
 
///////////////////////////////////////////////////////////////////////////////
474
 
 
475
 
void CvsServicePartImpl::annotate( const KURL::List& urlList )
476
 
{
477
 
    kdDebug(9006) << k_funcinfo << endl;
478
 
 
479
 
    if (!prepareOperation( urlList, opAnnotate ))
480
 
        return;
481
 
 
482
 
    //get the directory of the file we want to annotate
483
 
    QString tagFilename = URLUtil::directory(projectDirectory()+"/"+fileList()[0]);
484
 
    //CVS stores tag information in the ./CVS/Tag file
485
 
    tagFilename += "/CVS/Tag";
486
 
 
487
 
 
488
 
    //Check if such a Tag file exists, and try to read the tag/branch from it
489
 
    QFile fileTag(tagFilename);
490
 
    QString strRev = "";  //default revision is empty ...
491
 
    if (fileTag.exists()) { //... but if there is a Tag file, we get the revision from there
492
 
        if ( fileTag.open( IO_ReadOnly ) ) {
493
 
            QTextStream stream( &fileTag );
494
 
            QString line;
495
 
            line = stream.readLine();
496
 
            if (line.startsWith("T")) { //the line always starts with a "T"...
497
 
                strRev = line.right(line.length()-1); //...and after this there is the tag name
498
 
                kdDebug(9006) << "The found revision is:  >>" << strRev << "<<" <<endl;
499
 
            }
500
 
            fileTag.close();
501
 
        }
502
 
    }
503
 
    
504
 
    AnnotateDialog * f = new AnnotateDialog( m_cvsService );
505
 
    f->show();
506
 
    //the dialog will do all the work, just give him the file and the revision to start with
507
 
    f->startFirstAnnotate( fileList()[0], strRev );
508
 
 
509
 
    doneOperation();
510
 
}
511
 
 
512
 
///////////////////////////////////////////////////////////////////////////////
513
 
 
514
 
void CvsServicePartImpl::unedit( const KURL::List& urlList)
515
 
{
516
 
    kdDebug(9006) << k_funcinfo << endl;
517
 
 
518
 
    int s = KMessageBox::questionYesNo( 0,
519
 
        i18n("Do you really want to unedit the selected files?"),
520
 
        i18n("CVS - Unedit Files"),
521
 
        i18n("Unedit"),
522
 
        i18n("Do Not Unedit"),
523
 
        "askUneditingFiles" );
524
 
    if (s == KMessageBox::No) {
525
 
        return;
526
 
    }
527
 
 
528
 
    if (!prepareOperation( urlList, opUnEdit ))
529
 
        return;
530
 
 
531
 
    DCOPRef cvsJob = m_cvsService->unedit( fileList() );
532
 
 
533
 
    m_scheduler->schedule( cvsJob );
534
 
    connect( processWidget(), SIGNAL(jobFinished(bool,int)), this, SLOT(slotJobFinished(bool,int)) );
535
 
 
536
 
    doneOperation();
537
 
}
538
 
 
539
 
///////////////////////////////////////////////////////////////////////////////
540
 
 
541
 
void CvsServicePartImpl::edit( const KURL::List& urlList)
542
 
{
543
 
    kdDebug(9006) << k_funcinfo << endl;
544
 
 
545
 
    if (!prepareOperation( urlList, opEdit ))
546
 
        return;
547
 
 
548
 
    DCOPRef cvsJob = m_cvsService->edit( fileList() );
549
 
 
550
 
    m_scheduler->schedule( cvsJob );
551
 
    connect( processWidget(), SIGNAL(jobFinished(bool,int)), this, SLOT(slotJobFinished(bool,int)) );
552
 
 
553
 
    doneOperation();
554
 
}
555
 
 
556
 
///////////////////////////////////////////////////////////////////////////////
557
 
 
558
 
void CvsServicePartImpl::editors( const KURL::List& urlList)
559
 
{
560
 
    kdDebug(9006) << k_funcinfo << endl;
561
 
 
562
 
    if (!prepareOperation( urlList, opEditors ))
563
 
        return;
564
 
 
565
 
    EditorsDialog * f = new EditorsDialog( m_cvsService );
566
 
    f->show();
567
 
    //the dialog will do all the work
568
 
    f->startjob( fileList()[0] );
569
 
 
570
 
    doneOperation();
571
 
}
572
 
 
573
 
///////////////////////////////////////////////////////////////////////////////
574
 
 
575
 
void CvsServicePartImpl::remove( const KURL::List& urlList )
576
 
{
577
 
    kdDebug(9006) << k_funcinfo << endl;
578
 
 
579
 
    if (!prepareOperation( urlList, opRemove ))
580
 
        return;
581
 
 
582
 
    DCOPRef cvsJob = m_cvsService->remove( fileList(), true );
583
 
 
584
 
    m_scheduler->schedule( cvsJob );
585
 
    connect( processWidget(), SIGNAL(jobFinished(bool,int)),
586
 
        this, SLOT(slotJobFinished(bool,int)) );
587
 
 
588
 
    doneOperation();
589
 
}
590
 
 
591
 
///////////////////////////////////////////////////////////////////////////////
592
 
 
593
 
void CvsServicePartImpl::removeStickyFlag( const KURL::List& urlList )
594
 
{
595
 
        kdDebug(9006) << k_funcinfo << endl;
596
 
 
597
 
    if (!prepareOperation( urlList, opUpdate ))
598
 
        return;
599
 
 
600
 
    CvsOptions *options = CvsOptions::instance();
601
 
 
602
 
    DCOPRef cvsJob = m_cvsService->update( fileList(),
603
 
        options->recursiveWhenUpdate(),
604
 
        options->createDirsWhenUpdate(),
605
 
        options->pruneEmptyDirsWhenUpdate(),
606
 
        "-A" );
607
 
 
608
 
    m_scheduler->schedule( cvsJob );
609
 
    connect( processWidget(), SIGNAL(jobFinished(bool,int)),
610
 
        this, SLOT(slotJobFinished(bool,int)) );
611
 
 
612
 
    doneOperation();
613
 
}
614
 
 
615
 
///////////////////////////////////////////////////////////////////////////////
616
 
 
617
 
void CvsServicePartImpl::log( const KURL::List& urlList )
618
 
{
619
 
    kdDebug(9006) << k_funcinfo << endl;
620
 
 
621
 
    if (!prepareOperation( urlList, opLog ))
622
 
        return;
623
 
 
624
 
    CVSLogDialog* f = new CVSLogDialog( m_cvsService );
625
 
    f->show();
626
 
    // Form will do all the work
627
 
    f->startLog( projectDirectory(), fileList()[0] );
628
 
 
629
 
    doneOperation();
630
 
}
631
 
 
632
 
///////////////////////////////////////////////////////////////////////////////
633
 
 
634
 
void CvsServicePartImpl::diff( const KURL::List& urlList )
635
 
{
636
 
    kdDebug(9006) << k_funcinfo << endl;
637
 
 
638
 
    if (!prepareOperation( urlList, opDiff ))
639
 
        return;
640
 
    
641
 
    CVSDir cvsdir = CVSDir( urlList[0].directory() );
642
 
    CVSEntry entry = cvsdir.fileStatus( urlList[0].fileName() );
643
 
 
644
 
    DiffDialog dlg(entry);
645
 
    if (dlg.exec() != QDialog::Accepted)
646
 
        return;
647
 
 
648
 
    CvsOptions *options = CvsOptions::instance();
649
 
    DCOPRef cvsJob = m_cvsService->diff( fileList()[0], dlg.revA(),
650
 
                dlg.revB(), options->diffOptions(), options->contextLines() );
651
 
    if (!m_cvsService->ok())
652
 
    {
653
 
        KMessageBox::sorry( 0, i18n("Sorry, cannot diff."),
654
 
            i18n("Error During Diff") );
655
 
        return;
656
 
    }
657
 
 
658
 
    m_scheduler->schedule( cvsJob );
659
 
    connect( processWidget(), SIGNAL(jobFinished(bool,int)),
660
 
        this, SLOT(slotDiffFinished(bool,int)) );
661
 
 
662
 
    doneOperation();
663
 
}
664
 
 
665
 
///////////////////////////////////////////////////////////////////////////////
666
 
 
667
 
void CvsServicePartImpl::tag( const KURL::List& urlList )
668
 
{
669
 
    kdDebug(9006) << k_funcinfo << endl;
670
 
 
671
 
    if (!prepareOperation( urlList, opTag ))
672
 
        return;
673
 
 
674
 
    TagDialog dlg( i18n("Creating Tag/Branch for files ..."),
675
 
        mainWindow()->main()->centralWidget() );
676
 
    if (dlg.exec() != QDialog::Accepted)
677
 
        return;
678
 
 
679
 
    DCOPRef cvsJob = m_cvsService->createTag( fileList(), dlg.tagName(),
680
 
        dlg.isBranch(), dlg.force() );
681
 
 
682
 
    m_scheduler->schedule( cvsJob );
683
 
    connect( processWidget(), SIGNAL(jobFinished(bool,int)),
684
 
        this, SLOT(slotJobFinished(bool,int)) );
685
 
 
686
 
    doneOperation();
687
 
}
688
 
 
689
 
///////////////////////////////////////////////////////////////////////////////
690
 
 
691
 
void CvsServicePartImpl::unTag( const KURL::List& urlList )
692
 
{
693
 
    kdDebug(9006) << k_funcinfo << endl;
694
 
 
695
 
    if (!prepareOperation( urlList, opUnTag ))
696
 
        return;
697
 
 
698
 
    TagDialog dlg( i18n("Removing Tag from files ..."),
699
 
        mainWindow()->main()->centralWidget() );
700
 
    dlg.tagAsBranchCheck->hide();
701
 
    if (dlg.exec() != QDialog::Accepted)
702
 
        return;
703
 
 
704
 
    DCOPRef cvsJob = m_cvsService->deleteTag( fileList(), dlg.tagName(),
705
 
        dlg.isBranch(), dlg.force() );
706
 
 
707
 
    m_scheduler->schedule( cvsJob );
708
 
    connect( processWidget(), SIGNAL(jobFinished(bool,int)),
709
 
        this, SLOT(slotJobFinished(bool,int)) );
710
 
 
711
 
    doneOperation();
712
 
}
713
 
 
714
 
///////////////////////////////////////////////////////////////////////////////
715
 
 
716
 
void CvsServicePartImpl::addToIgnoreList( const KURL::List& urlList )
717
 
{
718
 
    addToIgnoreList( projectDirectory(), urlList );
719
 
}
720
 
 
721
 
///////////////////////////////////////////////////////////////////////////////
722
 
 
723
 
void CvsServicePartImpl::removeFromIgnoreList( const KURL::List& urlList )
724
 
{
725
 
    removeFromIgnoreList( projectDirectory(), urlList );
726
 
}
727
 
 
728
 
///////////////////////////////////////////////////////////////////////////////
729
 
 
730
 
/**
731
 
* \FIXME Current implementation doesn't use CvsService :-( I just ported the
732
 
* old code which relies on buildcvs.sh script. [marios]
733
 
*/
734
 
void CvsServicePartImpl::createNewProject( const QString &dirName,
735
 
    const QString &cvsRsh, const QString &location,
736
 
    const QString &message, const QString &module, const QString &vendor,
737
 
    const QString &release, bool mustInitRoot )
738
 
{
739
 
    kdDebug( 9006 ) << "====> CvsServicePartImpl::createNewProject( const QString& )" << endl;
740
 
 
741
 
    CvsOptions *options = CvsOptions::instance();
742
 
    options->setCvsRshEnvVar( cvsRsh );
743
 
    options->setLocation( location );
744
 
/*
745
 
        //virtual DCOPRef import( const QString& workingDir, const QString& repository, const QString& module, const QString& ignoreList, const QString& comment, const
746
 
    QString filesToIgnore;
747
 
        DCOPRef cvsJob = m_cvsService->import( dirName, location, module, filesToIgnore, message, vendor, release, false );
748
 
 
749
 
    m_scheduler->schedule( cvsJob );
750
 
    connect( processWidget(), SIGNAL(jobFinished(bool,int)), this, SLOT(slotCheckoutFinished(bool,int)) );
751
 
*/
752
 
        QString rsh_preamble;
753
 
    if ( !options->cvsRshEnvVar().isEmpty() )
754
 
        rsh_preamble = "CVS_RSH=" + KShellProcess::quote( options->cvsRshEnvVar() );
755
 
 
756
 
    QString init;
757
 
    if (mustInitRoot)
758
 
    {
759
 
        init = rsh_preamble + " cvs -d " + KShellProcess::quote( options->location() ) + " init && ";
760
 
    }
761
 
    QString cmdLine = init + "cd " + KShellProcess::quote(dirName) +
762
 
        " && " + rsh_preamble +
763
 
        " cvs -d " + KShellProcess::quote(options->location()) +
764
 
        " import -m " + KShellProcess::quote(message) + " " +
765
 
        KShellProcess::quote(module) + " " +
766
 
        KShellProcess::quote(vendor) + " " +
767
 
        KShellProcess::quote(release) +
768
 
        // CVS build-up magic here ...
769
 
        " && sh " +
770
 
        locate("data","kdevcvsservice/buildcvs.sh") + " . " +
771
 
        KShellProcess::quote(module) + " " +
772
 
        KShellProcess::quote(location);
773
 
 
774
 
    kdDebug( 9006 ) << "  ** Will run the following command: " << endl << cmdLine << endl;
775
 
    kdDebug( 9006 ) << "  ** on directory: " << dirName << endl;
776
 
 
777
 
    if (KDevMakeFrontend *makeFrontend = m_part->extension<KDevMakeFrontend>("KDevelop/MakeFrontend"))
778
 
        makeFrontend->queueCommand( dirName, cmdLine );
779
 
}
780
 
 
781
 
///////////////////////////////////////////////////////////////////////////////
782
 
 
783
 
bool CvsServicePartImpl::requestCvsService()
784
 
{
785
 
    QCString appId;
786
 
    QString error;
787
 
 
788
 
    if (KApplication::startServiceByDesktopName( "cvsservice",
789
 
        QStringList(), &error, &appId ))
790
 
    {
791
 
        QString msg = i18n( "Unable to find the Cervisia KPart. \n"
792
 
            "Cervisia Integration will not be available. Please check your\n"
793
 
            "Cervisia installation and re-try. Reason was:\n" ) + error;
794
 
        KMessageBox::error( processWidget(), msg, "DCOP Error" );
795
 
 
796
 
        return false;
797
 
    }
798
 
    else
799
 
    {
800
 
        m_cvsService = new CvsService_stub( appId, "CvsService" );
801
 
        m_repository = new Repository_stub( appId, "CvsRepository" );
802
 
    }
803
 
 
804
 
    return true;
805
 
}
806
 
 
807
 
///////////////////////////////////////////////////////////////////////////////
808
 
 
809
 
void CvsServicePartImpl::releaseCvsService()
810
 
{
811
 
    if (m_cvsService)
812
 
        m_cvsService->quit();
813
 
    delete m_cvsService;
814
 
    m_cvsService = 0;
815
 
    delete m_repository;
816
 
    m_repository = 0;
817
 
}
818
 
 
819
 
///////////////////////////////////////////////////////////////////////////////
820
 
 
821
 
void CvsServicePartImpl::flushJobs()
822
 
{
823
 
    processWidget()->cancelJob();
824
 
}
825
 
 
826
 
///////////////////////////////////////////////////////////////////////////////
827
 
 
828
 
void CvsServicePartImpl::addFilesToProject( const QStringList &filesToAdd )
829
 
{
830
 
    kdDebug( 9006 ) << k_funcinfo << " " << filesToAdd << endl;
831
 
 
832
 
    QStringList filesInCVS = checkFileListAgainstCVS( filesToAdd );
833
 
    if (filesInCVS.isEmpty())
834
 
        return;
835
 
 
836
 
    kdDebug( 9006 ) << k_funcinfo << " " << filesInCVS << endl;
837
 
 
838
 
    int s = KMessageBox::questionYesNo( 0,
839
 
        i18n("Do you want the files to be added to CVS repository too?"),
840
 
        i18n("CVS - New Files Added to Project"),
841
 
        KStdGuiItem::add(),
842
 
        i18n("Do Not Add"),
843
 
        i18n("askWhenAddingNewFiles") );
844
 
    if (s == KMessageBox::Yes)
845
 
    {
846
 
        kdDebug( 9006 ) << "Adding these files: " << filesInCVS.join( ", " ) << endl;
847
 
 
848
 
        const KURL::List urls = KURL::List( filesInCVS );
849
 
        URLUtil::dump( urls );
850
 
        add( urls );
851
 
    }
852
 
}
853
 
 
854
 
///////////////////////////////////////////////////////////////////////////////
855
 
 
856
 
void CvsServicePartImpl::removedFilesFromProject(const QStringList &filesToRemove)
857
 
{
858
 
    kdDebug( 9006 ) << k_funcinfo << endl;
859
 
 
860
 
    QStringList filesInCVS = checkFileListAgainstCVS( filesToRemove );
861
 
    if (filesInCVS.isEmpty())
862
 
        return;
863
 
 
864
 
    int s = KMessageBox::warningContinueCancel( 0,
865
 
        i18n("Do you want them to be removed from CVS repository too?\nWarning: They will be removed from disk too."),
866
 
        i18n("CVS - Files Removed From Project"),
867
 
        KStdGuiItem::del(),
868
 
        i18n("askWhenRemovingFiles") );
869
 
 
870
 
    if (s == KMessageBox::Continue)
871
 
    {
872
 
        kdDebug( 9006 ) << "Removing these files: " << filesInCVS.join( ", " ) << endl;
873
 
        const KURL::List urls = KURL::List( filesInCVS );
874
 
        URLUtil::dump( urls );
875
 
        remove( urls );
876
 
    }
877
 
}
878
 
 
879
 
///////////////////////////////////////////////////////////////////////////////
880
 
 
881
 
QStringList CvsServicePartImpl::checkFileListAgainstCVS( const QStringList &filesToCheck ) const
882
 
{
883
 
    QStringList filesInCVS;
884
 
    for (QStringList::const_iterator it = filesToCheck.begin(); it != filesToCheck.end(); ++it )
885
 
    {
886
 
        const QString &fn = (*it);
887
 
        QFileInfo fi( fn );
888
 
        if (fi.isRelative())
889
 
            fi = projectDirectory() + QDir::separator() + fn;
890
 
        if (isValidDirectory( fi.dirPath( true ) ))
891
 
            filesInCVS += ( fi.filePath() );
892
 
    }
893
 
 
894
 
    return filesInCVS;
895
 
}
896
 
 
897
 
///////////////////////////////////////////////////////////////////////////////
898
 
 
899
 
void CvsServicePartImpl::emitFileStateModified( const KURL::List &/*urls*/, VCSFileInfo::FileState &/*commonState*/ )
900
 
{
901
 
}
902
 
 
903
 
///////////////////////////////////////////////////////////////////////////////
904
 
 
905
 
KDevVCSFileInfoProvider *CvsServicePartImpl::fileInfoProvider() const
906
 
{
907
 
    return m_fileInfoProvider;
908
 
}
909
 
 
910
 
///////////////////////////////////////////////////////////////////////////////
911
 
// SLOTS here!
912
 
///////////////////////////////////////////////////////////////////////////////
913
 
 
914
 
void CvsServicePartImpl::slotDiffFinished( bool normalExit, int exitStatus )
915
 
{
916
 
    core()->running( m_part, false );
917
 
 
918
 
    QString diff = processWidget()->output().join("\n"),
919
 
        err = processWidget()->errors().join("\n");
920
 
 
921
 
    kdDebug( 9006 ) << "diff = " << diff << endl;
922
 
    kdDebug( 9006 ) << "err = " << err << endl;
923
 
 
924
 
    if (normalExit)
925
 
        kdDebug( 9006 ) << " *** Process died nicely with exit status = " <<
926
 
            exitStatus << endl;
927
 
    else
928
 
        kdDebug( 9999 ) << " *** Process was killed with exit status = " <<
929
 
            exitStatus << endl;
930
 
 
931
 
    // Now show a message about operation ending status
932
 
    if (diff.isEmpty() && (exitStatus != 0))
933
 
    {
934
 
        KMessageBox::information( 0, i18n("Operation aborted (process killed)."),
935
 
            i18n("CVS Diff") );
936
 
        return;
937
 
    }
938
 
    if ( diff.isEmpty() && !err.isEmpty() )
939
 
    {
940
 
        KMessageBox::detailedError( 0, i18n("CVS outputted errors during diff."),
941
 
            err, i18n("Errors During Diff") );
942
 
        return;
943
 
    }
944
 
 
945
 
    if ( !err.isEmpty() )
946
 
    {
947
 
        int s = KMessageBox::warningContinueCancelList( 0,
948
 
            i18n("CVS output errors during diff. Do you still want to continue?"),
949
 
            QStringList::split( "\n", err, false ), i18n("Errors During Diff")
950
 
        );
951
 
        if ( s != KMessageBox::Continue )
952
 
            return;
953
 
    }
954
 
 
955
 
    if ( diff.isEmpty() )
956
 
    {
957
 
        KMessageBox::information( 0, i18n("There is no difference to the repository."),
958
 
            i18n("No Difference Found") );
959
 
        return;
960
 
    }
961
 
 
962
 
    Q_ASSERT( diffFrontend() );
963
 
    diffFrontend()->showDiff( diff );
964
 
}
965
 
 
966
 
///////////////////////////////////////////////////////////////////////////////
967
 
 
968
 
void CvsServicePartImpl::slotCheckoutFinished( bool exitStatus, int )
969
 
{
970
 
    kdDebug(9006) << "CvsServicePartImpl::slotCheckoutFinished(): job ended with status == "
971
 
        << exitStatus << endl;
972
 
    // Return a null string if the operation was not succesfull
973
 
    if (!exitStatus)
974
 
        modulePath = QString::null;
975
 
 
976
 
    kdDebug(9006) << "   I'll emit modulePath == " << modulePath << endl;
977
 
 
978
 
    emit checkoutFinished( modulePath );
979
 
}
980
 
 
981
 
///////////////////////////////////////////////////////////////////////////////
982
 
 
983
 
void CvsServicePartImpl::slotJobFinished( bool /*exitStatus*/, int exitCode )
984
 
{
985
 
    // Return a null string if the operation was not succesfull
986
 
    kdDebug(9006) << "CvsServicePartImpl::slotJobFinished(): job ended with code == "
987
 
        << exitCode << endl;
988
 
/*
989
 
    // Operation has been successfull
990
 
    if (!exitStatus)
991
 
        return;
992
 
 
993
 
    // 1. Assemble the CVSFileInfoList
994
 
    // 2. notify all clients
995
 
*/
996
 
}
997
 
 
998
 
///////////////////////////////////////////////////////////////////////////////
999
 
 
1000
 
void CvsServicePartImpl::slotProjectOpened()
1001
 
{
1002
 
    kdDebug(9006) << "CvsServicePartImpl::slotProjectOpened(): setting work directory to "
1003
 
        << projectDirectory() << endl;
1004
 
 
1005
 
    if ( m_repository )
1006
 
    {
1007
 
        m_repository->setWorkingCopy( projectDirectory() );
1008
 
    }
1009
 
}
1010
 
 
1011
 
 
1012
 
#include "cvspartimpl.moc"