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
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
|
/***************************************************************************
kompare_part.cpp - description
-------------------
begin : Sun Mar 4 2001
copyright : (C) 2001-2004 Otto Bruggeman
(C) 2001-2003 John Firebaugh
(C) 2004 Jeff Snyder
email : otto.bruggeman@home.nl
jfirebaugh@kde.org
jeff@caffeinated.me.uk
****************************************************************************/
/***************************************************************************
**
** 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.
**
***************************************************************************/
#include "kompare_qsplitter.h" // make sure we get there first
#include <tqlayout.h>
#include <tqwidget.h>
#include <kaction.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kfiletreeview.h>
#include <kfiledialog.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kstdaction.h>
#include <kinstance.h>
#include <ktempfile.h>
#include <kparts/genericfactory.h>
//#include <ktempdir.h>
#include <kio/netaccess.h>
#include "diffmodel.h"
#include "komparelistview.h"
#include "kompareconnectwidget.h"
#include "diffsettings.h"
#include "viewsettings.h"
#include "kompareprefdlg.h"
#include "komparesaveoptionswidget.h"
#include "komparesplitter.h"
#include "kompare_part.h"
typedef KParts::GenericFactory<KomparePart> KomparePartFactory;
K_EXPORT_COMPONENT_FACTORY( libkomparepart, KomparePartFactory )
ViewSettings* KomparePart::m_viewSettings = 0L;
DiffSettings* KomparePart::m_diffSettings = 0L;
KomparePart::KomparePart( TQWidget *parentWidget, const char *widgetName,
TQObject *tqparent, const char *name, const TQStringList & /*args*/ ) :
KParts::ReadWritePart(tqparent, name),
m_tempDiff( 0 ),
m_info()
{
// we need an instance
setInstance( KomparePartFactory::instance() );
if( !m_viewSettings ) {
m_viewSettings = new ViewSettings( 0 );
}
if( !m_diffSettings ) {
m_diffSettings = new DiffSettings( 0 );
}
readProperties( kapp->config() );
// This creates the "Model creator" and connects the signals and slots
m_modelList = new Diff2::KompareModelList( m_diffSettings, m_info, this, "komparemodellist" );
connect( m_modelList, TQT_SIGNAL(status( Kompare::tqStatus )),
this, TQT_SLOT(slotSettqStatus( Kompare::tqStatus )) );
connect( m_modelList, TQT_SIGNAL(setStatusBarModelInfo( int, int, int, int, int )),
this, TQT_SIGNAL(setStatusBarModelInfo( int, int, int, int, int )) );
connect( m_modelList, TQT_SIGNAL(error( TQString )),
this, TQT_SLOT(slotShowError( TQString )) );
connect( m_modelList, TQT_SIGNAL(applyAllDifferences( bool )),
this, TQT_SLOT(updateActions()) );
connect( m_modelList, TQT_SIGNAL(applyDifference( bool )),
this, TQT_SLOT(updateActions()) );
connect( m_modelList, TQT_SIGNAL(applyAllDifferences( bool )),
this, TQT_SIGNAL(appliedChanged()) );
connect( m_modelList, TQT_SIGNAL(applyDifference( bool )),
this, TQT_SIGNAL(appliedChanged()) );
connect( m_modelList, TQT_SIGNAL( setModified( bool ) ),
this, TQT_SLOT( slotSetModified( bool ) ) );
// This is the stuff to connect the "interface" of the kompare part to the model inside
connect( m_modelList, TQT_SIGNAL(modelsChanged(const Diff2::DiffModelList*)),
this, TQT_SIGNAL(modelsChanged(const Diff2::DiffModelList*)) );
connect( m_modelList, TQT_SIGNAL(setSelection(const Diff2::DiffModel*, const Diff2::Difference*)),
this, TQT_SIGNAL(setSelection(const Diff2::DiffModel*, const Diff2::Difference*)) );
connect( this, TQT_SIGNAL(selectionChanged(const Diff2::DiffModel*, const Diff2::Difference*)),
m_modelList, TQT_SLOT(slotSelectionChanged(const Diff2::DiffModel*, const Diff2::Difference*)) );
connect( m_modelList, TQT_SIGNAL(setSelection(const Diff2::Difference*)),
this, TQT_SIGNAL(setSelection(const Diff2::Difference*)) );
connect( this, TQT_SIGNAL(selectionChanged(const Diff2::Difference*)),
m_modelList, TQT_SLOT(slotSelectionChanged(const Diff2::Difference*)) );
connect( m_modelList, TQT_SIGNAL(applyDifference(bool)),
this, TQT_SIGNAL(applyDifference(bool)) );
connect( m_modelList, TQT_SIGNAL(applyAllDifferences(bool)),
this, TQT_SIGNAL(applyAllDifferences(bool)) );
connect( m_modelList, TQT_SIGNAL(applyDifference(const Diff2::Difference*, bool)),
this, TQT_SIGNAL(applyDifference(const Diff2::Difference*, bool)) );
// This creates the splitterwidget and connects the signals and slots
m_splitter = new KompareSplitter ( m_viewSettings, parentWidget, widgetName );
connect( m_modelList, TQT_SIGNAL(setSelection(const Diff2::DiffModel*, const Diff2::Difference*)),
m_splitter, TQT_SLOT(slotSetSelection(const Diff2::DiffModel*, const Diff2::Difference*)) );
// connect( m_splitter, TQT_SIGNAL(selectionChanged(const Diff2::Difference*, const Diff2::Difference*)),
// m_modelList, TQT_SLOT(slotSelectionChanged(const Diff2::Difference*, const Diff2::Difference*)) );
connect( m_modelList, TQT_SIGNAL(setSelection(const Diff2::Difference*)),
m_splitter, TQT_SLOT(slotSetSelection(const Diff2::Difference*)) );
connect( m_splitter, TQT_SIGNAL(selectionChanged(const Diff2::Difference*)),
m_modelList, TQT_SLOT(slotSelectionChanged(const Diff2::Difference*)) );
connect( m_modelList, TQT_SIGNAL(applyDifference(bool)),
m_splitter, TQT_SLOT(slotApplyDifference(bool)) );
connect( m_modelList, TQT_SIGNAL(applyAllDifferences(bool)),
m_splitter, TQT_SLOT(slotApplyAllDifferences(bool)) );
connect( m_modelList, TQT_SIGNAL(applyDifference(const Diff2::Difference*, bool)),
m_splitter, TQT_SLOT(slotApplyDifference(const Diff2::Difference*, bool)) );
connect( this, TQT_SIGNAL(configChanged()), m_splitter, TQT_SIGNAL(configChanged()) );
// notify the part that this is our internal widget
setWidget( m_splitter->parentWidget() );
setupActions();
// set our XML-UI resource file
setXMLFile( "komparepartui.rc" );
// we are read-write by default -> uhm what if we are opened by lets say konq in RO mode ?
// Then we should not be doing this...
setReadWrite( true );
// we are not modified since we haven't done anything yet
setModified( false );
}
KomparePart::~KomparePart()
{
// This is the only place allowed to call cleanUpTemporaryFiles
// because before there might still be a use for them (when swapping)
cleanUpTemporaryFiles();
}
void KomparePart::setupActions()
{
// create our actions
m_saveAll = new KAction( i18n("Save &All"), "save_all", 0,
this, TQT_SLOT(saveAll()),
actionCollection(), "file_save_all" );
m_saveDiff = new KAction( i18n("Save .&diff..."), 0,
this, TQT_SLOT(saveDiff()),
actionCollection(), "file_save_diff" );
m_swap = new KAction( i18n( "Swap Source with Destination" ), 0,
this, TQT_SLOT(slotSwap()),
actionCollection(), "file_swap" );
m_diffStats = new KAction( i18n( "Show Statistics" ), 0,
this, TQT_SLOT(slotShowDiffstats()),
actionCollection(), "file_diffstats" );
KStdAction::preferences(this, TQT_SLOT(optionsPreferences()), actionCollection());
}
void KomparePart::updateActions()
{
m_saveAll->setEnabled ( m_modelList->isModified() );
m_saveDiff->setEnabled ( m_modelList->mode() == Kompare::ComparingFiles || m_modelList->mode() == Kompare::ComparingDirs );
m_swap->setEnabled ( m_modelList->mode() == Kompare::ComparingFiles || m_modelList->mode() == Kompare::ComparingDirs );
m_diffStats->setEnabled( m_modelList->modelCount() > 0 );
}
void KomparePart::setEncoding( const TQString& encoding )
{
kdDebug() << "Encoding: " << encoding << endl;
m_modelList->setEncoding( encoding );
}
bool KomparePart::openDiff( const KURL& url )
{
kdDebug(8103) << "Url = " << url.url() << endl;
emit kompareInfo( &m_info );
m_info.mode = Kompare::ShowingDiff;
m_info.source = url;
bool result = false;
m_info.localSource = fetchURL( url );
if ( !m_info.localSource.isEmpty() )
{
kdDebug(8103) << "Download succeeded " << endl;
result = m_modelList->openDiff( m_info.localSource );
updateActions();
updateCaption();
updatetqStatus();
}
else
{
kdDebug(8103) << "Download failed !" << endl;
}
return result;
}
bool KomparePart::openDiff( const TQString& diffOutput )
{
bool value = false;
emit kompareInfo( &m_info );
m_info.mode = Kompare::ShowingDiff;
if ( m_modelList->parseDiffOutput( diffOutput ) == 0 )
{
value = true;
m_modelList->show();
updateActions();
updateCaption();
updatetqStatus();
}
return value;
}
bool KomparePart::openDiff3( const KURL& diff3Url )
{
// FIXME: Implement this !!!
kdDebug(8103) << "Not implemented yet. Filename is: " << diff3Url.url() << endl;
return false;
}
bool KomparePart::openDiff3( const TQString& diff3Output )
{
// FIXME: Implement this !!!
kdDebug(8103) << "Not implemented yet. diff3 output is: " << endl;
kdDebug(8103) << diff3Output << endl;
return false;
}
bool KomparePart::exists( const TQString& url )
{
TQFileInfo fi( url );
return fi.exists();
}
const TQString KomparePart::fetchURL( const KURL& url )
{
TQString tempFileName( "" );
if ( !url.isLocalFile() )
{
if ( ! KIO::NetAccess::download( url, tempFileName, widget() ) )
{
slotShowError( i18n( "<qt>The URL <b>%1</b> cannot be downloaded.</qt>" ).tqarg( url.prettyURL() ) );
tempFileName = "";
}
return tempFileName;
}
else
{
// is Local already, check if exists
if ( exists( url.path() ) )
return url.path();
else
{
slotShowError( i18n( "<qt>The URL <b>%1</b> does not exist on your system.</qt>" ).tqarg( url.prettyURL() ) );
return tempFileName;
}
}
}
void KomparePart::cleanUpTemporaryFiles()
{
// i hope a local file will not be removed if it was not downloaded...
if ( !m_info.localSource.isEmpty() )
KIO::NetAccess::removeTempFile( m_info.localSource );
if ( !m_info.localDestination.isEmpty() )
KIO::NetAccess::removeTempFile( m_info.localDestination );
}
void KomparePart::compare( const KURL& source, const KURL& destination )
{
m_info.source = source;
m_info.destination = destination;
m_info.localSource = fetchURL( source );
m_info.localDestination = fetchURL( destination );
emit kompareInfo( &m_info );
if ( !m_info.localSource.isEmpty() && !m_info.localDestination.isEmpty() )
{
m_modelList->compare( m_info.localSource, m_info.localDestination );
updateActions();
updateCaption();
updatetqStatus();
}
}
void KomparePart::compareFiles( const KURL& sourceFile, const KURL& destinationFile )
{
emit kompareInfo( &m_info );
m_info.mode = Kompare::ComparingFiles;
m_info.source = sourceFile;
m_info.destination = destinationFile;
m_info.localSource = fetchURL( sourceFile );
m_info.localDestination = fetchURL( destinationFile );
if ( !m_info.localSource.isEmpty() && !m_info.localDestination.isEmpty() )
{
m_modelList->compareFiles( m_info.localSource, m_info.localDestination );
updateActions();
updateCaption();
updatetqStatus();
}
}
void KomparePart::compareDirs( const KURL& sourceDirectory, const KURL& destinationDirectory )
{
emit kompareInfo( &m_info );
m_info.mode = Kompare::ComparingDirs;
m_info.source = sourceDirectory;
m_info.destination = destinationDirectory;
m_info.localSource = fetchURL( sourceDirectory );
m_info.localDestination = fetchURL( destinationDirectory );
if ( !m_info.localSource.isEmpty() && !m_info.localDestination.isEmpty() )
{
m_modelList->compareDirs( m_info.localSource, m_info.localDestination );
updateActions();
updateCaption();
updatetqStatus();
}
}
void KomparePart::compare3Files( const KURL& /*originalFile*/, const KURL& /*changedFile1*/, const KURL& /*changedFile2*/ )
{
// FIXME: actually implement this some day :)
updateActions();
updateCaption();
updatetqStatus();
}
void KomparePart::openFileAndDiff( const KURL& file, const KURL& diffFile )
{
emit kompareInfo( &m_info );
m_info.source = file;
m_info.destination = diffFile;
m_info.localSource = fetchURL( file );
m_info.localDestination = fetchURL( diffFile );
m_info.mode = Kompare::BlendingFile;
if ( !m_info.localSource.isEmpty() && !m_info.localDestination.isEmpty() )
{
m_modelList->openFileAndDiff( m_info.localSource, m_info.localDestination );
updateActions();
updateCaption();
updatetqStatus();
}
}
void KomparePart::openDirAndDiff ( const KURL& dir, const KURL& diffFile )
{
emit kompareInfo( &m_info );
m_info.source = dir;
m_info.destination = diffFile;
m_info.localSource = fetchURL( dir );
m_info.localDestination = fetchURL( diffFile );
m_info.mode = Kompare::BlendingDir;
if ( !m_info.localSource.isEmpty() && !m_info.localDestination.isEmpty() )
{
m_modelList->openDirAndDiff( m_info.localSource, m_info.localDestination );
updateActions();
updateCaption();
updatetqStatus();
}
}
bool KomparePart::openFile()
{
// This is called from openURL
// This is a little inefficient but i will do it anyway
openDiff( m_url );
return true;
}
bool KomparePart::saveAll()
{
bool result = m_modelList->saveAll();
updateActions();
updateCaption();
updatetqStatus();
return result;
}
void KomparePart::saveDiff()
{
KDialogBase* dlg = new KDialogBase( widget(), "save_options",
true /* modal */, i18n("Diff Options"),
KDialogBase::Ok|KDialogBase::Cancel );
KompareSaveOptionsWidget* w = new KompareSaveOptionsWidget(
m_info.localSource,
m_info.localDestination,
m_diffSettings, dlg );
dlg->setMainWidget( w );
dlg->setButtonOK( KStdGuiItem::save() );
if( dlg->exec() ) {
w->saveOptions();
KConfig* config = instance()->config();
saveProperties( config );
config->sync();
while ( 1 )
{
KURL url = KFileDialog::getSaveURL( m_info.destination.url(),
i18n("*.diff *.dif *.patch|Patch Files"), widget(), i18n( "Save .diff" ) );
if ( KIO::NetAccess::exists( url, false, widget() ) )
{
int result = KMessageBox::warningYesNoCancel( widget(), i18n("The file exists or is write-protected; do you want to overwrite it?"), i18n("File Exists"), i18n("Overwrite"), i18n("Do Not Overwrite") );
if ( result == KMessageBox::Cancel )
{
break;
}
else if ( result == KMessageBox::No )
{
continue;
}
else
{
kdDebug(8103) << "URL = " << url.prettyURL() << endl;
kdDebug(8103) << "Directory = " << w->directory() << endl;
kdDebug(8103) << "DiffSettings = " << m_diffSettings << endl;
m_modelList->saveDiff( url.url(), w->directory(), m_diffSettings );
break;
}
}
else
{
kdDebug(8103) << "URL = " << url.prettyURL() << endl;
kdDebug(8103) << "Directory = " << w->directory() << endl;
kdDebug(8103) << "DiffSettings = " << m_diffSettings << endl;
m_modelList->saveDiff( url.url(), w->directory(), m_diffSettings );
break;
}
}
}
delete dlg;
}
KAboutData *KomparePart::createAboutData()
{
KAboutData *about = new KAboutData("kompare", I18N_NOOP("KomparePart"), "3.2");
about->addAuthor("John Firebaugh", "Author", "jfirebaugh@kde.org");
about->addAuthor("Otto Bruggeman", "Author", "otto.bruggeman@home.nl" );
return about;
}
void KomparePart::slotSettqStatus( enum Kompare::tqStatus status )
{
updateActions();
switch( status ) {
case Kompare::RunningDiff:
emit setStatusBarText( i18n( "Running diff..." ) );
break;
case Kompare::Parsing:
emit setStatusBarText( i18n( "Parsing diff output..." ) );
break;
case Kompare::FinishedParsing:
updatetqStatus();
break;
case Kompare::FinishedWritingDiff:
updatetqStatus();
emit diffURLChanged();
break;
default:
break;
}
}
void KomparePart::updateCaption()
{
TQString source = m_info.source.prettyURL();
TQString destination = m_info.destination.prettyURL();
TQString text;
switch ( m_info.mode )
{
case Kompare::ComparingFiles :
case Kompare::ComparingDirs :
case Kompare::BlendingFile :
case Kompare::BlendingDir :
text = source + ":" + destination;
break;
case Kompare::ShowingDiff :
text = source;
break;
default:
break;
}
emit setWindowCaption( text );
}
void KomparePart::updatetqStatus()
{
TQString source = m_info.source.prettyURL();
TQString destination = m_info.destination.prettyURL();
TQString text;
switch ( m_info.mode )
{
case Kompare::ComparingFiles :
text = i18n( "Comparing file %1 with file %2" )
.tqarg( source )
.tqarg( destination );
break;
case Kompare::ComparingDirs :
text = i18n( "Comparing files in %1 with files in %2" )
.tqarg( source )
.tqarg( destination );
break;
case Kompare::ShowingDiff :
text = i18n( "Viewing diff output from %1" ).tqarg( source );
break;
case Kompare::BlendingFile :
text = i18n( "Blending diff output from %1 into file %2" )
.tqarg( source )
.tqarg( destination );
break;
case Kompare::BlendingDir :
text = i18n( "Blending diff output from %1 into folder %2" )
.tqarg( m_info.source.prettyURL() )
.tqarg( m_info.destination.prettyURL() );
break;
default:
break;
}
emit setStatusBarText( text );
}
void KomparePart::slotShowError( TQString error )
{
KMessageBox::error( widget(), error );
}
void KomparePart::slotSwap()
{
if ( isModified() )
{
int query = KMessageBox::warningYesNoCancel
(
widget(),
i18n( "You have made changes to the destination file(s).\n"
"Would you like to save them?" ),
i18n( "Save Changes?" ),
KStdGuiItem::save(),
KStdGuiItem::discard()
);
if ( query == KMessageBox::Yes )
m_modelList->saveAll();
if ( query == KMessageBox::Cancel )
return; // Abort prematurely so no swapping
}
// Swap the info in the Kompare::Info struct
KURL url = m_info.source;
m_info.source = m_info.destination;
m_info.destination = url;
TQString string = m_info.localSource;
m_info.localSource = m_info.localDestination;
m_info.localDestination = string;
// Update window caption and statusbar text
updateCaption();
updatetqStatus();
m_modelList->swap();
}
void KomparePart::slotShowDiffstats( void )
{
// Fetch all the args needed for komparestatsmessagebox
// oldfile, newfile, diffformat, noofhunks, noofdiffs
TQString oldFile;
TQString newFile;
TQString diffFormat;
int filesInDiff;
int noOfHunks;
int noOfDiffs;
oldFile = m_modelList->selectedModel() ? m_modelList->selectedModel()->sourceFile() : TQString( "" );
newFile = m_modelList->selectedModel() ? m_modelList->selectedModel()->destinationFile() : TQString( "" );
if ( m_modelList->selectedModel() )
{
switch( m_info.format ) {
case Kompare::Unified :
diffFormat = i18n( "Unified" );
break;
case Kompare::Context :
diffFormat = i18n( "Context" );
break;
case Kompare::RCS :
diffFormat = i18n( "RCS" );
break;
case Kompare::Ed :
diffFormat = i18n( "Ed" );
break;
case Kompare::Normal :
diffFormat = i18n( "Normal" );
break;
case Kompare::UnknownFormat :
default:
diffFormat = i18n( "Unknown" );
break;
}
}
else
{
diffFormat = "";
}
filesInDiff = m_modelList->modelCount();
noOfHunks = m_modelList->selectedModel() ? m_modelList->selectedModel()->hunkCount() : 0;
noOfDiffs = m_modelList->selectedModel() ? m_modelList->selectedModel()->differenceCount() : 0;
if ( m_modelList->modelCount() == 0 ) { // no diff loaded yet
KMessageBox::information( 0L, i18n(
"No diff file, or no 2 files have been diffed. "
"Therefore no stats are available."),
i18n("Diff Statistics"), TQString(), false );
}
else if ( m_modelList->modelCount() == 1 ) { // 1 file in diff, or 2 files compared
KMessageBox::information( 0L, i18n(
"Statistics:\n"
"\n"
"Old file: %1\n"
"New file: %2\n"
"\n"
"Format: %3\n"
"Number of hunks: %4\n"
"Number of differences: %5")
.tqarg(oldFile).tqarg(newFile).tqarg(diffFormat)
.tqarg(noOfHunks).tqarg(noOfDiffs),
i18n("Diff Statistics"), TQString(), false );
} else { // more than 1 file in diff, or 2 directories compared
KMessageBox::information( 0L, i18n(
"Statistics:\n"
"\n"
"Number of files in diff file: %1\n"
"Format: %2\n"
"\n"
"Current old file: %3\n"
"Current new file: %4\n"
"\n"
"Number of hunks: %5\n"
"Number of differences: %6")
.tqarg(filesInDiff).tqarg(diffFormat).tqarg(oldFile)
.tqarg(newFile).tqarg(noOfHunks).tqarg(noOfDiffs),
i18n("Diff Statistics"), TQString(), false );
}
}
bool KomparePart::queryClose()
{
if( !isModified() ) return true;
int query = KMessageBox::warningYesNoCancel
(
widget(),
i18n("You have made changes to the destination file(s).\n"
"Would you like to save them?" ),
i18n( "Save Changes?" ),
KStdGuiItem::save(),
KStdGuiItem::discard()
);
if( query == KMessageBox::Cancel )
return false;
if( query == KMessageBox::Yes )
return m_modelList->saveAll();
return true;
}
int KomparePart::readProperties( KConfig *config )
{
m_viewSettings->loadSettings( config );
m_diffSettings->loadSettings( config );
emit configChanged();
return 0;
}
int KomparePart::saveProperties( KConfig *config )
{
m_viewSettings->saveSettings( config );
m_diffSettings->saveSettings( config );
return 0;
}
void KomparePart::optionsPreferences()
{
// show preferences
KomparePrefDlg* pref = new KomparePrefDlg( m_viewSettings, m_diffSettings );
connect( pref, TQT_SIGNAL(applyClicked()), this, TQT_SIGNAL(configChanged()) );
if ( pref->exec() )
emit configChanged();
}
void KomparePart::slotSetModified( bool modified )
{
kdDebug() << "KomparePart::slotSetModified( " << modified << " );" << endl;
setModified( modified );
updateActions();
updateCaption();
}
#include "kompare_part.moc"
|