summaryrefslogtreecommitdiffstats
path: root/vcs/subversion/subversion_core.cpp
blob: 4a647b34058a9c0ba9fa9c0749f57416b9fa490d (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
/**
	 Copyright (C) 2003-2005 Mickael Marchand <[email protected]>

	 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; see the file COPYING.  If not, write to
	 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
	 Boston, MA 02110-1301, USA.
	 */

#include <kparts/part.h>
#include <kdevcore.h>
#include <kdevproject.h>
#include "subversion_part.h"
#include "subversion_core.h"
#include "subversion_widget.h"
#include "svn_blamewidget.h"
#include "svn_logviewwidget.h"
#include "subversiondiff.h"
#include <kdevmainwindow.h>
#include "svn_co.h"
#include <kurlrequester.h>
#include <klineedit.h>
#include <kio/job.h>
#include <kio/jobclasses.h>
#include <kio/netaccess.h>
#include <kdebug.h>
#include <kmainwindow.h>
#include <kapplication.h>
#include <dcopclient.h>
#include <ktempfile.h>
#include <kprocess.h>
#include <kstandarddirs.h>
#include <tqtextcodec.h>
#include <tqtextstream.h>
#include <tqtextbrowser.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <tqregexp.h>

#include <kapplication.h>
#include <kinstance.h>
#include <kaboutdata.h>

using namespace TDEIO;
using namespace SvnGlobal;

subversionCore::subversionCore(subversionPart *part)
// 	: TQObject(NULL, "subversion core"), DCOPObject("subversion") {
	: TQObject(NULL, "subversion core") {
		m_part = part;
		m_widget = new subversionWidget(part, 0 , "subversionprocesswidget");
// 		m_logViewWidget = new SvnLogViewWidget( part, 0 );
// 		m_part->mainWindow()->embedOutputView( m_logViewWidget, i18n( "Subversion Log" ), i18n( "Subversion Log" ) );
//		if ( ! connectDCOPSignal("kded", "ksvnd", "subversionNotify(TQString,int,int,TQString,int,int,long int,TQString)", "notification(TQString,int,int,TQString,int,int,long int,TQString)", false ) )
//			kdWarning() << "Failed to connect to kded dcop signal ! Notifications won't work..." << endl;

        m_fileInfoProvider = new SVNFileInfoProvider( part );
		diffTmpDir = new KTempDir();
		diffTmpDir->setAutoDelete(true);
}

subversionCore::~subversionCore() {
	if ( processWidget() ) {
		m_part->mainWindow()->removeView( processWidget() );
		delete processWidget();
	}
// 	if( m_logViewWidget ){
// 		m_part->mainWindow()->removeView( m_logViewWidget );
// 		delete m_logViewWidget;
// 	}
	delete diffTmpDir;
	//FIXME delete m_fileInfoProvider here?
}

KDevVCSFileInfoProvider *subversionCore::fileInfoProvider() const {
    return m_fileInfoProvider;
}

//not used anymore
// void subversionCore::notification( const TQString& path, int action, int kind, const TQString& mime_type, int content_state ,int prop_state ,long int revision, const TQString& userstring ) {
// 	kdDebug(9036) << "Subversion Notification : "
// 		<< "path : " << path
// 		<< "action: " << action
// 		<< "kind : " << kind
// 		<< "mime_type : " << mime_type
// 		<< "content_state : " << content_state
// 		<< "prop_state : " << prop_state
// 		<< "revision : " << revision
// 		<< "userstring : " << userstring
// 		<< endl;
// 	if ( !userstring.isEmpty() ) {
// 		m_part->mainWindow()->raiseView(processWidget());
// 		processWidget()->append( userstring );
// 	}
// }

subversionWidget *subversionCore::processWidget() const {
// SvnLogViewWidget* subversionCore::processWidget() const {
// 	return processWidget();
// 	return m_logViewWidget;
    return m_widget;
}

void subversionCore::resolve( const KURL::List& list ) {
	KURL servURL = m_part->baseURL();
	if ( servURL.isEmpty() ) servURL="kdevsvn+svn://blah/";
	if ( ! servURL.protocol().startsWith( "kdevsvn+" ) ) {
		servURL.setProtocol( "kdevsvn+" + servURL.protocol() ); //make sure it starts with "svn"
	}
	kdDebug(9036) << "servURL : " << servURL.prettyURL() << endl;
	for ( TQValueListConstIterator<KURL> it = list.begin(); it != list.end() ; ++it ) {
		kdDebug(9036) << "resolving: " << (*it).prettyURL() << endl;
		TQByteArray parms;
		TQDataStream s( parms, IO_WriteOnly );
		int cmd = 11;
		bool recurse = true;
		s << cmd << *it << recurse;
		SimpleJob * job = TDEIO::special(servURL, parms, true);
		job->setWindow( m_part->mainWindow()->main() );
		connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotResult( TDEIO::Job * ) ) );
	}
}

void subversionCore::update( const KURL::List& list ) {
	KURL servURL = "kdevsvn+svn://blah/";
	kdDebug(9036) << "Updating. servURL : " << servURL.prettyURL() << endl;
	
	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	int cmd = 2;
	int rev = -1;
	s << cmd << list << rev << TQString( "HEAD" );
	
	SimpleJob * job = TDEIO::special(servURL, parms, false);
	connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotResult( TDEIO::Job * ) ) );
	initProcessDlg( (TDEIO::Job*)job, i18n("Subversion Update") , i18n("Subversion Update") );
}

void subversionCore::diff( const KURL::List& list, const TQString& where){
	kdDebug(9036) << "diff " << list << endl;
	KURL servURL = "kdevsvn+svn://this_is_a_fake_URL_and_this_is_normal/";
	for ( TQValueListConstIterator<KURL> it = list.begin(); it != list.end() ; ++it ) {
		TQByteArray parms;
		TQDataStream s( parms, IO_WriteOnly );
		int cmd = 13;
		kdDebug(9036) << "diffing : " << (*it).prettyURL() << endl;
		int rev1=-1;
		int rev2=-1;
		TQString revkind1 = where;
		TQString revkind2 = "WORKING";
		s << cmd << *it << *it << rev1 << revkind1 << rev2 << revkind2 << true ;
		TDEIO::SimpleJob * job = TDEIO::special(servURL, parms, true);
		connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotResult( TDEIO::Job * ) ) );
		TDEIO::NetAccess::synchronousRun( job, 0 );
		if ( diffresult.count() > 0 ) {
			//check kompare is available
			if ( !KStandardDirs::findExe( "kompare" ).isNull() ) {
				if (!KStandardDirs::findExe("patch").isNull()){
					// we have patch - so can merge
					KTempDir tmpDir = KTempDir(diffTmpDir->name());
					KTempFile tmpPatch = KTempFile(tmpDir.name());

					// write the patch
					TQTextStream *stream = tmpPatch.textStream();
					stream->setCodec( TQTextCodec::codecForName( "utf8" ) );
					for ( TQStringList::Iterator it2 = diffresult.begin();it2 != diffresult.end() ; ++it2 ) {
						( *stream ) << ( *it2 ) << "\n";
					}
					tmpPatch.close();

					TQString ourCopy = tmpDir.name()+(*it).fileName();

					TDEProcess copy;
					copy << "cp" << (*it).prettyURL(0,KURL::StripFileProtocol) <<  tmpDir.name();
					copy.start(TDEProcess::Block);

					TDEProcess patch;
					patch.setWorkingDirectory(tmpDir.name());
					patch << "patch" << "-R" << ourCopy << tmpPatch.name();
					patch.start(TDEProcess::Block, TDEProcess::All);

					TDEProcess *p = new TDEProcess;
					*p << "kompare" << ourCopy << (*it).prettyURL();
					p->start();
				}
				else{
					// only diff
					KTempFile *tmp = new KTempFile;
					tmp->setAutoDelete(true);
					TQTextStream *stream = tmp->textStream();
					stream->setCodec( TQTextCodec::codecForName( "utf8" ) );
					for ( TQStringList::Iterator it2 = diffresult.begin();it2 != diffresult.end() ; ++it2 ) {
						( *stream ) << ( *it2 ) << "\n";
					}
					tmp->close();
					TDEProcess *p = new TDEProcess;
					*p << "kompare" << "-n" << "-o" << tmp->name();
					p->start();
				}
			} else { //else do it with message box
				Subversion_Diff df;
				for ( TQStringList::Iterator it2 = diffresult.begin();it2 != diffresult.end() ; ++it2 ) {
					df.text->append( *it2 );
				}
				TQFont f = df.font();
				f.setFixedPitch( true );
				df.text->setFont( f );
				df.exec();
			}
		}
		else{
			TQString diffTo = i18n("the local disk checked out copy.");
			if ( where=="HEAD"){
				diffTo=i18n("the current svn HEAD version.");
			}
			KMessageBox::information( 0, i18n("No differences between the file and %1").arg(diffTo), i18n("No difference") );
		}
		diffresult.clear();
	}
}

void subversionCore::diffAsync( const KURL &pathOrUrl1, const KURL &pathOrUrl2,
							int rev1, TQString revKind1, int rev2, TQString revKind2,
							bool recurse, bool pegdiff )
{
	KURL servURL = "kdevsvn+svn://blah/";
	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	int cmd = 13;
	kdDebug(9036) << "diffing async : " << pathOrUrl1 << " and " << pathOrUrl2 << endl;
	s << cmd << pathOrUrl1 << pathOrUrl2 << rev1 << revKind1 << rev2 << revKind2 << recurse;
	s << pegdiff;
	TDEIO::SimpleJob * job = TDEIO::special(servURL, parms, false);
	connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotDiffResult( TDEIO::Job * ) ) );
	initProcessDlg( (TDEIO::Job*)job, pathOrUrl1.prettyURL(), pathOrUrl2.prettyURL() );
}

void subversionCore::commit( const KURL::List& list, bool recurse, bool keeplocks ) {
	KURL servURL = m_part->baseURL();
	if ( servURL.isEmpty() ) servURL="kdevsvn+svn://blah/";
	if ( ! servURL.protocol().startsWith( "kdevsvn+" ) ) {
		servURL.setProtocol( "kdevsvn+" + servURL.protocol() ); //make sure it starts with "svn"
	}
	kdDebug(9036) << "servURL : " << servURL.prettyURL() << endl;
	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	int cmd = 103;
 	s << cmd << recurse << keeplocks;
	for ( TQValueListConstIterator<KURL> it = list.begin(); it != list.end() ; ++it ) {
		kdDebug(9036) << "adding to list: " << (*it).prettyURL() << endl;
		s << *it;
	}
	SimpleJob * job = TDEIO::special(servURL, parms, false);
	connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotResult( TDEIO::Job * ) ) );
	if( list.count() == 1 )
		initProcessDlg( (TDEIO::Job*)job, (*(list.begin())).prettyURL() , i18n("Commit to remote repository") );
	else if( list.count() > 1 )
		initProcessDlg( (TDEIO::Job*)job, i18n("From working copy") , i18n("Commit to remote repository") );
}
// Right now, only one item for each action.
void subversionCore::svnLog( const KURL::List& list,
		int revstart, TQString revKindStart, int revend, TQString revKindEnd,
		bool discorverChangedPath, bool strictNodeHistory )
{
	// ensure that part has repository information. This info is used to retrieve root repository URL
    if( m_part->m_prjInfoMap.count() < 1 )
        clientInfo( KURL(m_part->project()->projectDirectory()), false, m_part->m_prjInfoMap );
	KURL servURL = m_part->baseURL();
	if ( servURL.isEmpty() ) servURL="kdevsvn+svn://blah/";
	if ( ! servURL.protocol().startsWith( "kdevsvn+" ) ) {
		servURL.setProtocol( "kdevsvn+" + servURL.protocol() ); //make sure it starts with "svn"
	}
	kdDebug(9036) << "servURL : " << servURL.prettyURL() << endl;
	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	// prepare arguments
	int cmd = 4;
// 	int revstart = -1, revend = 0;
// 	TQString revKindStart = "HEAD", revKindEnd = "";
// 	bool repositLog = true, discorverChangedPath = true, strictNodeHistory = true;
	s << cmd << revstart << revKindStart << revend << revKindEnd;
	s << discorverChangedPath << strictNodeHistory;
	for ( TQValueListConstIterator<KURL> it = list.begin(); it != list.end() ; ++it ) {
		kdDebug(9036) << "svnCore: adding to list: " << (*it).prettyURL() << endl;
		s << *it;
	}
	SimpleJob * job = TDEIO::special(servURL, parms, false);
	connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotLogResult( TDEIO::Job * ) ) );
	//  progress info. LogView is allowed and meaninful only for one url in KDev3.4
	initProcessDlg( (TDEIO::Job*)job, (*(list.begin())).prettyURL() , i18n("Subversion Log View") );
}

void subversionCore::blame( const KURL &url, UrlMode mode, int revstart, TQString revKindStart, int revend, TQString revKindEnd )
{
	KURL servURL = m_part->baseURL();
	if ( servURL.isEmpty() ) servURL="kdevsvn+svn://blah/";
	if ( ! servURL.protocol().startsWith( "kdevsvn+" ) ) {
		servURL.setProtocol( "kdevsvn+" + servURL.protocol() ); //make sure it starts with "svn"
	}
	kdDebug(9036) << "servURL : " << servURL.prettyURL() << endl;
	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	// prepare arguments
	int cmd = 14;
	s << cmd << url << (int)mode ;
	s << revstart << revKindStart << revend << revKindEnd ;

	SimpleJob * job = TDEIO::special(servURL, parms, false);
	connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotBlameResult( TDEIO::Job * ) ) );
	initProcessDlg( (TDEIO::Job*)job, url.prettyURL() , i18n("Subversion Blame") );
}

void subversionCore::add( const KURL::List& list ) {
	
	KURL servURL = "kdevsvn+svn://blah/";
	kdDebug(9036) << "Deleting servURL : " << servURL.prettyURL() << endl;
	
	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	int cmd = 6;
	s << cmd << list;
	// add/delete/revert works on local copy. Don't need to show progress dialog
	SimpleJob * job = TDEIO::special(servURL, parms, false); 
	job->setWindow( m_part->mainWindow()->main() );
	connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotResult( TDEIO::Job * ) ) );
}

void subversionCore::del( const KURL::List& list ) {
	KURL servURL = "kdevsvn+svn://blah/";
	kdDebug(9036) << "Deleting servURL : " << servURL.prettyURL() << endl;
	
	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	int cmd = 7;
	s << cmd << list;
	// add/delete/revert works on local copy. Don't need to show progress dialog
	SimpleJob * job = TDEIO::special(servURL, parms, false);
	job->setWindow( m_part->mainWindow()->main() );
	connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotResult( TDEIO::Job * ) ) );
}

void subversionCore::revert( const KURL::List& list ) {
	KURL servURL = "kdevsvn+svn://blah/";
	kdDebug(9036) << "Reverting servURL : " << servURL.prettyURL() << endl;
	
	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	int cmd = 8;
	s << cmd << list;
	SimpleJob * job = TDEIO::special(servURL, parms, false);
	job->setWindow( m_part->mainWindow()->main() );
	connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotResult( TDEIO::Job * ) ) );
}

void subversionCore::checkout() {
	svn_co checkoutDlg;

	if ( checkoutDlg.exec() == TQDialog::Accepted ) {
		//checkout :)
		TQByteArray parms;
		TQDataStream s( parms, IO_WriteOnly );
		KURL servURL ( checkoutDlg.serverURL->url() );
		wcPath = checkoutDlg.localDir->url() + "/" + checkoutDlg.newDir->text();
		int cmd = 1;
		int rev = -1;
		s << cmd << servURL << KURL( wcPath ) << rev << TQString( "HEAD" );
		servURL.setProtocol( "kdevsvn+" + servURL.protocol() ); //make sure it starts with "svn"
		SimpleJob * job = TDEIO::special(servURL,parms, true);
		job->setWindow( m_part->mainWindow()->main() );
		connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotEndCheckout( TDEIO::Job * ) ) );
	}
}

void subversionCore::switchTree( const KURL &path, const KURL &repositUrl,
								int revNum, const TQString &revKind, bool recurse )
{
	KURL servURL = "kdevsvn+svn://blah/";
	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	// prepare arguments
	int cmd = 12;
	s << cmd << path << repositUrl ;
	s << recurse << revNum << revKind;

	SimpleJob * job = TDEIO::special(servURL, parms, false);
	connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotResult( TDEIO::Job * ) ) );
	initProcessDlg( (TDEIO::Job*)job, repositUrl.prettyURL() , path.prettyURL() );
}

void subversionCore::switchRelocate( const KURL &path,
									 const KURL &currentUrl, const KURL &newUrl, bool recurse )
{
	KURL servURL = "kdevsvn+svn://blah/";
	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	// prepare arguments
	int cmd = 16;
	s << cmd << path << currentUrl << newUrl << recurse;

	SimpleJob * job = TDEIO::special(servURL, parms, false);
	connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotResult( TDEIO::Job * ) ) );
	// this doesn't contact repository
}

void subversionCore::svnCopy( const KURL &src, int srcRev, const TQString &srcRevKind,
							  const KURL &dest )
{
	KURL servURL = "kdevsvn+svn://blah/";
	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	// prepare arguments
	int cmd = 17;
	s << cmd << src << srcRev << srcRevKind << dest;

	SimpleJob * job = TDEIO::special(servURL, parms, false);
	connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotResult( TDEIO::Job * ) ) );
	initProcessDlg( (TDEIO::Job*)job, src.prettyURL(), dest.prettyURL() );
}

void subversionCore::merge( const KURL &src1, int rev1, TQString revKind1,
							const KURL &src2, int rev2, TQString revKind2, const KURL &wc_path,
							bool recurse, bool ignore_ancestry, bool force, bool dry_run )
{
	KURL servURL = "kdevsvn+svn://blah/";
	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	// prepare arguments
	int cmd = 18;
	s << cmd << src1 << rev1 << revKind1 << src2 << rev2 << revKind2 << wc_path;
	s << recurse << ignore_ancestry << force << dry_run;

	SimpleJob * job = TDEIO::special(servURL, parms, false);
	connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotResult( TDEIO::Job * ) ) );
	initProcessDlg( (TDEIO::Job*)job, src1.prettyURL() + "\n" + src2.prettyURL() ,
					wc_path.prettyURL() );
}

bool subversionCore::clientInfo( KURL path_or_url, bool recurse, TQMap< KURL, SvnInfoHolder> &holderMap )
{
    KURL servURL = "kdevsvn+svn://blah/";
    TQByteArray parms;
    TQDataStream s( parms, IO_WriteOnly );
    int cmd = 15;
    s << cmd << path_or_url << -1 << TQString("UNSPECIFIED") << -1 << TQString("UNSPECIFIED") << recurse;
    SimpleJob *job = TDEIO::special( servURL, parms, false );

    TQMap<TQString,TQString> ma;
    TDEIO::NetAccess::synchronousRun(job, 0, 0, 0, &ma ); // synchronize

    TQValueList<TQString> keys = ma.keys();
    TQValueList<TQString>::Iterator begin = keys.begin(), end = keys.end(), it;
    int curIdx, lastIdx;
    TQRegExp rx( "([0-9]*)(.*)" );
    
    for ( it = begin; it != end; /*++it*/) {
        kdDebug(9036) << "METADATA key: " << *it << " value: " << ma[ *it ] << endl;
        if ( rx.search( *it ) == -1 ) return false; // something is wrong ! :)
        curIdx = lastIdx = rx.cap( 1 ).toInt();
        SvnInfoHolder holder;
        
        while ( curIdx == lastIdx ) {
            if ( rx.cap( 2 ) == "PATH" )
                holder.path = KURL( ma[ *it ] );
            else if ( rx.cap( 2  ) == "URL" )
                holder.url = KURL( ma[*it] );
            else if ( rx.cap( 2  ) == "REV" )
                holder.rev= ma[ *it ].toInt();
            else if ( rx.cap( 2  ) == "KIND" )
                holder.kind = ma[ *it ].toInt();
            else if ( rx.cap( 2  ) == "REPOS_ROOT_URL" )
                holder.reposRootUrl = KURL( ma[*it] );
            else if ( rx.cap( 2  ) == "REPOS_UUID" )
                holder.reposUuid = ma[ *it ];
            
            ++it;
            if ( it == end )
                break;
            if ( rx.search( *it ) == -1 ) return false; // something is wrong ! :)
            curIdx = rx.cap( 1 ).toInt();
        }
        holderMap.insert( holder.path, holder );
    }
    return true;;
}
        
void subversionCore::slotEndCheckout( TDEIO::Job * job ) {
	if ( job->error() ) {
		job->showErrorDialog( m_part->mainWindow()->main() );
		emit checkoutFinished( TQString() );
	} else
		emit checkoutFinished(wcPath);
}

void subversionCore::slotResult( TDEIO::Job * job ) {
    if ( job->error() ){
        job->showErrorDialog( m_part->mainWindow()->main() );
        if( job->error() == ERR_CANNOT_LAUNCH_PROCESS )
            KMessageBox::error( m_part->mainWindow()->main(),
                                i18n("If you have just have installed a new version of TDevelop,"
                                     " and the error message was 'unknown protocol kdevsvn+*',"
                                     " try restarting TDE."
                                    ) );
        return;
    }
    TDEIO::MetaData ma = job->metaData();
	TQValueList<TQString> keys = ma.keys();
	qHeapSort( keys );
	TQValueList<TQString>::Iterator begin = keys.begin(), end = keys.end(), it;

	for ( it = begin; it != end; ++it ) {
// 		kdDebug(9036) << "METADATA : " << *it << ":" << ma[ *it ] << endl;
		if ( ( *it ).endsWith( "string" ) ) {
			m_part->mainWindow()->raiseView(processWidget());
			processWidget()->append( ma[ *it ] );
		}
		//extra check to retrieve the diff output in case with run a diff command
		if ( ( *it ).endsWith( "diffresult" ) ) {
			diffresult << ma[ *it ];
		}
	}
}
void subversionCore::slotLogResult( TDEIO::Job * job )
{
	if ( job->error() ){
		job->showErrorDialog( m_part->mainWindow()->main() );
        if( job->error() == ERR_CANNOT_LAUNCH_PROCESS )
            KMessageBox::error( m_part->mainWindow()->main(),
                                i18n("If you have just have installed a new version of TDevelop,"
                                     " and the error message was 'unknown protocol kdevsvn+*',"
                                     " try restarting TDE."
                                    ) );
		return;
	}

	TQValueList<SvnLogHolder> holderList;

	TDEIO::MetaData ma = job->metaData();
	TQValueList<TQString> keys = ma.keys();
	TQRegExp rx( "([0-9]*)(.*)" );
	int curIdx, lastIdx;
	TQString requestedUrl;

	for (TQValueList<TQString>::Iterator it = keys.begin(); it != keys.end(); /*++it*/ ){
		if ( rx.search( *it ) == -1 ){
			kdDebug(9036) << " Exiting loop at line " << __LINE__ <<endl;
			return; // something is wrong ! :)
		}
		curIdx = lastIdx = rx.cap( 1 ).toInt();
		SvnLogHolder logHolder;
		while ( curIdx == lastIdx ) {
			kdDebug(9036) << "svn log MetaData: " << *it << ":" << ma[ *it ] << endl;

			if ( rx.cap( 2 ) == "author" )
				logHolder.author = ma[*it];
			else if ( rx.cap( 2	 ) == "date" )
				logHolder.date = ma[*it];
			else if ( rx.cap( 2	 ) == "logmsg" )
				logHolder.logMsg = ma[*it];
			else if ( rx.cap( 2	 ) == "pathlist" )
				logHolder.pathList = ma[*it];
			else if ( rx.cap( 2	 ) == "rev" )
				logHolder.rev = ma[*it];
			else if ( rx.cap( 2  ) == "requrl" )
				requestedUrl = ma[*it];

			++it;
			if ( it == keys.end() )
				break;
			if ( rx.search( *it ) == -1 ){
				kdDebug(9036) << " Exiting loop at line " << __LINE__ <<endl;
				break; // something is wrong ! :)
			}
			curIdx = rx.cap( 1 ).toInt();
		}//end of while
		holderList.append( logHolder );
	}
	processWidget()->showLogResult( &holderList, requestedUrl );
	m_part->mainWindow()->raiseView(processWidget());

}

void subversionCore::slotBlameResult( TDEIO::Job * job )
{
    if ( job->error() ){
        job->showErrorDialog( m_part->mainWindow()->main() );
        if( job->error() == ERR_CANNOT_LAUNCH_PROCESS )
            KMessageBox::error( m_part->mainWindow()->main(),
                                i18n("If you have just have installed a new version of TDevelop,"
                                     " and the error message was 'unknown protocol kdevsvn+*',"
                                     " try restarting TDE."
                                    ) );
        return;
    }
	TQValueList<SvnBlameHolder> blameList;

	TDEIO::MetaData ma = job->metaData();
	TQValueList<TQString> keys = ma.keys();
	TQRegExp rx( "([0-9]*)(.*)" );
	int curIdx, lastIdx;

	for (TQValueList<TQString>::Iterator it = keys.begin(); it != keys.end(); /*++it*/ ){
		if ( rx.search( *it ) == -1 ){
			kdDebug(9036) << " Exiting loop at line " << __LINE__ <<endl;
			return; // something is wrong ! :)
		}

		// if metadata has action key, that means a notification for svn_wc_notify_blame_completed
		// Thus, consume this notification
		if ( rx.cap( 2 ) == "action" ){
			curIdx = lastIdx = rx.cap( 1 ).toInt();
			while ( curIdx == lastIdx ){
				++it;
				if ( it == keys.end() ) break;
				if ( rx.search( *it ) == -1 ) continue; // something is wrong
				curIdx = rx.cap( 1 ).toInt();
			}
			continue;
		}
		// get actual blame data
		curIdx = lastIdx = rx.cap( 1 ).toInt();
		SvnBlameHolder blameHolder;
		while ( curIdx == lastIdx ) {
			kdDebug(9036) << "svn blame MetaData: " << *it << ":" << ma[ *it ] << endl;

			if ( rx.cap( 2 ) == "LINE" )
				blameHolder.line= (ma[*it]).toInt();
			else if ( rx.cap( 2	 ) == "REV" )
				blameHolder.rev = (ma[*it]).toLongLong();
			else if ( rx.cap( 2	 ) == "AUTHOR" )
				blameHolder.author= ma[*it];
			else if ( rx.cap( 2	 ) == "DATE" )
				blameHolder.date= ma[*it];
			else if ( rx.cap( 2	 ) == "CONTENT" )
				blameHolder.content = ma[*it];

			++it;
			if ( it == keys.end() )
				break;
			if ( rx.search( *it ) == -1 ){
				kdDebug(9036) << " Exiting loop at line " << __LINE__ <<endl;
				break; // something is wrong ! :)
			}
			curIdx = rx.cap( 1 ).toInt();
		}//end of while
		blameList.append( blameHolder );
// 		blameList.insert( blameHolder.line, blameHolder );
	}
    processWidget()->showBlameResult( &blameList );
    m_part->mainWindow()->raiseView(processWidget());
}

void subversionCore::slotDiffResult( TDEIO::Job * job )
{
	if ( job->error() ){
		job->showErrorDialog( m_part->mainWindow()->main() );
		if( job->error() == ERR_CANNOT_LAUNCH_PROCESS )
			KMessageBox::error( m_part->mainWindow()->main(),
                                                                i18n("If you have just have installed a new version of TDevelop,"
                                                                        " and the error message was 'unknown protocol kdevsvn+*',"
                                                                        " try restarting TDE."
									) );
		return;
	}
	TDEIO::MetaData ma = job->metaData();
	TQValueList<TQString> keys = ma.keys();
	qHeapSort( keys );
	TQValueList<TQString>::Iterator begin = keys.begin(), end = keys.end(), it;
	TQStringList diffList;
	
	for ( it = begin; it != end; ++it ) {
// 		kdDebug(9036) << "METADATA : " << *it << ":" << ma[ *it ] << endl;
		if ( ( *it ).endsWith( "diffresult" ) ) {
			diffList << ma[ *it ];
		}
	}

	if ( diffList.count() > 0 ) {
		//check kompare is available
		if ( !KStandardDirs::findExe( "kompare" ).isNull() ) {
			KTempFile *tmp = new KTempFile;
			tmp->setAutoDelete(true);
			TQTextStream *stream = tmp->textStream();
			stream->setCodec( TQTextCodec::codecForName( "utf8" ) );
			for ( TQStringList::Iterator it2 = diffList.begin();it2 != diffList.end() ; ++it2 ) {
				( *stream ) << ( *it2 ) << "\n";
			}
			tmp->close();
			TDEProcess *p = new TDEProcess;
			*p << "kompare" << "-n" << "-o" << tmp->name();
			p->start();
			
		} else { //else do it with message box
			KMessageBox::information( NULL, i18n("You do not have kompare installed. We recommend you install kompare to view differences graphically.") + "\nhttp://www.caffeinated.me.uk/kompare/" , TQString() , "userDoesNotWantKompare" );
			Subversion_Diff df;
			for ( TQStringList::Iterator it2 = diffList.begin();it2 != diffList.end() ; ++it2 ) {
				df.text->append( *it2 );
			}
			TQFont f = df.font();
			f.setFixedPitch( true );
			df.text->setFont( f );
			df.exec();
		}
	}
	else{
		KMessageBox::information( 0, i18n("No subversion differences") );
	}
}

void subversionCore::initProcessDlg( TDEIO::Job *job, const TQString &src, const TQString &dest )
{
	SvnProgressDlg *progress = new SvnProgressDlg( true );
	progress->setSourceUrl( src );
	progress->setDestUrl( dest );
	progress->setJob( job );
	connect( job, TQT_SIGNAL( totalSize(TDEIO::Job*, TDEIO::filesize_t) ),
			 progress, TQT_SLOT( slotTotalSize (TDEIO::Job*, TDEIO::filesize_t) ) );
	connect( job, TQT_SIGNAL( processedSize(TDEIO::Job*, TDEIO::filesize_t) ),
			 progress, TQT_SLOT( slotProcessedSize(TDEIO::Job*, TDEIO::filesize_t) ) );
}

void subversionCore::createNewProject( const TQString& // dirName
                                       , const KURL& // importURL
                                       , bool // init
                                       ) {

}

#include "subversion_core.moc"