summaryrefslogtreecommitdiffstats
path: root/vcs/subversion/integrator/svnintegratordlg.cpp
blob: cc074f8b1dc4ec1e597254fca252c1f05cf87f83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/***************************************************************************
 *   Copyright (C) 2004 by Alexander Dymo                                  *
 *   adymo@kdevelop.org                                                    *
 *   Copyright (C) 2004                                                    *
 *   Mickael Marchand <marchand@kde.org>                                   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/
#include "svnintegratordlg.h"
#include "blockingkprocess.h"
#include <kurl.h>
#include <kio/jobclasses.h>
#include <kio/job.h>
#include <kurlrequester.h>
#include <kdebug.h>
#include <tqradiobutton.h>
#include <kio/scheduler.h>
#include <kprocess.h>
#include <kdeversion.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <kdebug.h>

#include <kio/netaccess.h>

using namespace KIO;

SvnIntegratorDlg::SvnIntegratorDlg( TQWidget *tqparent, const char *name )
        : SvnIntegratorDlgBase( tqparent, name )
{
    repos1->setMode( KFile::Directory );
}

void SvnIntegratorDlg::accept()
{
    // to let ioslave know which protocol it should start.
    KURL protocolUrl = KURL("kdevsvn+svn://blah/");
    KURL servURL( repos1->url() );
    if ( servURL.isEmpty() ) return;
    
    kdDebug( 9036 ) << "servURL : " << servURL.prettyURL() << endl;
    if ( createProject->isChecked() )
    {
        KURL::List list;
        list << servURL; // project root directory
        KURL miscURL = servURL.url();
        miscURL.setPath( servURL.path() + "/tags/" );
        list << miscURL;
        miscURL.setPath( servURL.path() + "/branches/" );
        list << miscURL;
        miscURL.setPath( servURL.path() + "/trunk/" );
        list << miscURL;

        TQByteArray parms;
        TQDataStream s( parms, IO_WriteOnly );
        int cmd = 10; // MKDIR(list)
        s << cmd << list;
        KIO::SimpleJob* job = KIO::special( protocolUrl, parms, true );
        if( !NetAccess::synchronousRun( job, 0 ) ){
            KMessageBox::error( this, i18n("Unable to create project directories on repository") );
            return;
        }

        TQByteArray parms2;
        TQDataStream s2( parms2, IO_WriteOnly );
        cmd = 5; //IMPORT
        servURL.setPath( servURL.path() + "/trunk/" );
        s2 << cmd << servURL << KURL::fromPathOrURL( m_projectLocation );
        KIO::SimpleJob* importJob = KIO::special( protocolUrl, parms2, true );
        if( !NetAccess::synchronousRun( importJob, 0 ) ){
            KMessageBox::error( this, i18n("Unable to import into repository.") );
            return;
        }
    }
    //delete the template directory and checkout a fresh one from the server
    BlockingKProcess *rmproc = new BlockingKProcess();
    *rmproc << "rm";
    *rmproc << "-f" << "-r" << m_projectLocation;
    rmproc->start();
    
    delete rmproc;
    rmproc = NULL;

    TQByteArray parms3;
    TQDataStream s3( parms3, IO_WriteOnly );
    int cmd2 = 1; //CHECKOUT
    int rev = -1;
    
    s3 << cmd2 << servURL << KURL::fromPathOrURL( m_projectLocation ) << rev << TQString( "HEAD" );
    SimpleJob *job2 = KIO::special( protocolUrl, parms3, true );
    if( ! NetAccess::synchronousRun( job2, 0 ) ){
        // Checkout failed
        KMessageBox::error(this, i18n("Unable to checkout from repository.") );
        return;
    }
}

void SvnIntegratorDlg::init( const TQString &projectName, const TQString &projectLocation )
{
    m_name = projectName;
    m_projectLocation = projectLocation;
}

TQWidget *SvnIntegratorDlg::self()
{
    return const_cast<SvnIntegratorDlg*>( this );
}

#include "svnintegratordlg.moc"