File: cervisiapart.cpp

package info (click to toggle)
cervisia 4:17.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 7,548 kB
  • sloc: cpp: 14,364; xml: 393; makefile: 3; sh: 3
file content (1998 lines) | stat: -rw-r--r-- 64,789 bytes parent folder | download | duplicates (2)
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
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
/*
 *  Copyright (C) 1999-2002 Bernd Gehrmann
 *                          bernd@mail.berlios.de
 *  Copyright (c) 2002-2005 Christian Loose <christian.loose@kdemail.net>
 *
 * 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 "cervisiapart.h"

#include <qlabel.h>
#include <qmessagebox.h>
#include <qpushbutton.h>
#include <qmenu.h>
#include <qtextstream.h>
#include <QSplitter>
#include <QList>
#include <QStatusBar>

#include <kaboutdata.h>
#include <knotification.h>
#include <kshell.h>
#include <kpropertiesdialog.h>
#include <kstandardaction.h>
#include <kxmlguifactory.h>
#include <krun.h>
#include <QDebug>
#include <kmessagebox.h>
#include <ktoolinvocation.h>
#include <kactioncollection.h>
#include <ktoggleaction.h>
#include <krecentfilesaction.h>
#include <KLocalizedString>
#include <kparts/guiactivateevent.h>
#include <KConfig>
#include <KConfigGroup>
#include <KSharedConfig>

#include <repositoryinterface.h>
#include <QFileDialog>
#include "progressdialog.h"
#include "logdialog.h"
#include "diffdialog.h"
#include "resolvedialog.h"
#include "annotatedialog.h"
#include "annotatecontroller.h"
#include "commitdialog.h"
#include "updatedialog.h"
#include "checkoutdialog.h"
#include "tagdialog.h"
#include "mergedialog.h"
#include "historydialog.h"
#include "updateview.h"
#include "updateview_items.h"
#include "protocolview.h"
#include "repositorydialog.h"
#include "settingsdialog.h"
#include "changelogdialog.h"
#include "watchersdialog.h"
#include "cvsinitdialog.h"
#include "misc.h"
#include "cvsserviceinterface.h"
#include "globalignorelist.h"
#include "patchoptiondialog.h"
#include "addignoremenu.h"
#include "editwithmenu.h"
#include "debug.h"

#include "cvsjobinterface.h"
#include "version.h"

using Cervisia::TagDialog;

K_PLUGIN_FACTORY( CervisiaFactory, registerPlugin<CervisiaPart>(); )
#include <cervisiapart.moc>

CervisiaPart::CervisiaPart( QWidget *parentWidget,
                            QObject *parent, const QVariantList& /*args*/ )
    : KParts::ReadOnlyPart( parent )
    , hasRunningJob( false )
    , opt_hideFiles( false )
    , opt_hideUpToDate( false )
    , opt_hideRemoved( false )
    , opt_hideNotInCVS( false )
    , opt_hideEmptyDirectories( false )
    , opt_createDirs( false )
    , opt_pruneDirs( false )
    , opt_updateRecursive( true )
    , opt_commitRecursive( true )
    , opt_doCVSEdit( false )
    , recent( 0 )
    , cvsService( 0 )
    , m_statusBar(new KParts::StatusBarExtension(this))
    , m_browserExt( 0 )
    , filterLabel( 0 )
    , m_editWithAction(0)
    , m_currentEditMenu(0)
    , m_addIgnoreAction(0)
    , m_currentIgnoreMenu(0)
    , m_jobType(Unknown)
{
    setComponentName("cervisiapart", i18n("Cervisia"));

    m_browserExt = new CervisiaBrowserExtension( this );

    // start the cvs D-Bus service
    QString error;
    if( KToolInvocation::startServiceByDesktopName("org.kde.cvsservice5", QStringList(), &error, &m_cvsServiceInterfaceName) )
    {
        KMessageBox::sorry(0, i18n("Starting cvsservice failed with message: ") + error, "Cervisia");
    }
    else
      // create a reference to the service
      cvsService = new OrgKdeCervisia5CvsserviceCvsserviceInterface(m_cvsServiceInterfaceName, "/CvsService",QDBusConnection::sessionBus(), this);
    //qCDebug(log_cervisia) << "m_cvsServiceInterfaceName:" << m_cvsServiceInterfaceName;
    //kdDebug(8050) << "cvsService->service():" << cvsService->service()<<endl;
    // Create UI
    KConfigGroup conf( config(), "LookAndFeel");
    bool splitHorz = conf.readEntry("SplitHorizontally",true);

    // When we couldn't start the D-Bus service, we just display a QLabel with
    // an explaination
    if( cvsService )
    {
        Qt::Orientation o = splitHorz ? Qt::Vertical : Qt::Horizontal;
        splitter = new QSplitter(o, parentWidget);
        // avoid PartManager's warning that Part's window can't handle focus
        splitter->setFocusPolicy( Qt::StrongFocus );

        update = new UpdateView(*config(), splitter);
        update->setFocusPolicy( Qt::StrongFocus );
        update->setContextMenuPolicy(Qt::CustomContextMenu);
        update->setFocus();
        connect( update, SIGNAL(customContextMenuRequested(const QPoint &)),
                 this, SLOT(popupRequested(const QPoint &)) );

        connect( update, SIGNAL(fileOpened(QString)),
                 this, SLOT(openFile(QString)) );
        protocol = new ProtocolView(m_cvsServiceInterfaceName, splitter);
        protocol->setFocusPolicy( Qt::StrongFocus );

        setWidget(splitter);
    }
    else
    {
        setWidget(new QLabel(i18n("This KPart is non-functional, because the "
                                  "cvs D-Bus service could not be started."),
                             parentWidget));
    }

    if( cvsService )
    {
        setupActions();
        readSettings();
        connect(update, SIGNAL(itemSelectionChanged()), this, SLOT(updateActions()));
    }

    setXMLFile( "cervisiaui.rc" );

    QTimer::singleShot(0, this, SLOT(slotSetupStatusBar()));
}

CervisiaPart::~CervisiaPart()
{
    // stop the cvs DCOP service and delete reference
    if( cvsService )
    {
        writeSettings();
        cvsService->quit();
        delete cvsService;
    }
}

KConfig *CervisiaPart::config()
{
    KSharedConfigPtr tmp = KSharedConfig::openConfig();
    return tmp.data(); // the pointer won't get invalid even if the temporary tmp object is
                       // destroyed
}

bool CervisiaPart::openUrl( const QUrl &u )
{
    // right now, we are unfortunately not network-aware
    if( !u.isLocalFile() )
    {
        KMessageBox::sorry(widget(),
                           i18n("Remote CVS working folders are not "
                                "supported."),
                           "Cervisia");
        return false;
    }

    if( hasRunningJob )
    {
        KMessageBox::sorry(widget(),
                           i18n("You cannot change to a different folder "
                                "while there is a running cvs job."),
                           "Cervisia");
        return false;
    }

    // make a deep copy as if we're called via KRecentFilesAction::urlSelected()
    // KRecentFilesAction::addUrl() makes the URL invalid
    const QUrl deepCopy(u);

    return openSandbox(deepCopy);
}


void CervisiaPart::slotSetupStatusBar()
{
    // create the active filter indicator and add it to the statusbar
    filterLabel = new QLabel("UR", m_statusBar->statusBar());
    filterLabel->setFixedSize(filterLabel->sizeHint());
    filterLabel->setText("");
    filterLabel->setToolTip(
                  i18n("F - All files are hidden, the tree shows only folders\n"
                       "N - All up-to-date files are hidden\n"
                       "R - All removed files are hidden"));
    m_statusBar->addStatusBarItem(filterLabel, 0, true);
}

void CervisiaPart::setupActions()
{
    QAction *action;
    QString hint;
    //
    // File Menu
    //
    action  = new QAction(QIcon::fromTheme("document-open"), i18n("Open Sandbox..."), this);
    actionCollection()->addAction("file_open", action);
    actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_O));
    connect(action, SIGNAL(triggered(bool)), SLOT(slotOpenSandbox()));
    hint = i18n("Opens a CVS working folder in the main window");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    recent = new KRecentFilesAction( i18n("Recent Sandboxes"), this );
    actionCollection()->addAction("file_open_recent", recent);
    connect(recent, SIGNAL(urlSelected(QUrl)), SLOT(openUrl(QUrl))),

    action  = new QAction(i18n("&Insert ChangeLog Entry..."), this);
    actionCollection()->addAction("insert_changelog_entry", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotChangeLog()));
    hint = i18n("Inserts a new intro into the file ChangeLog in the toplevel folder");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(QIcon::fromTheme("vcs-update-cvs-cervisia"), i18n("&Update"), this);
    actionCollection()->addAction("file_update", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotUpdate()));
    actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_U));
    hint = i18n("Updates (cvs update) the selected files and folders");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(QIcon::fromTheme("vcs-status-cvs-cervisia"), i18n("&Status"), this);
    actionCollection()->addAction("file_status", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotStatus()));
    actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::Key_F5));
    hint = i18n("Updates the status (cvs -n update) of the selected files and folders");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("&Edit"), this);
    actionCollection()->addAction("file_edit", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotOpen()));
    hint = i18n("Opens the marked file for editing");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("Reso&lve..."), this);
    actionCollection()->addAction("file_resolve", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotResolve()));
    hint = i18n("Opens the resolve dialog with the selected file");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(QIcon::fromTheme("vcs-commit-cvs-cervisia"), i18n("&Commit..."), this);
    actionCollection()->addAction("file_commit", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotCommit()));
    actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::Key_NumberSign));
    hint = i18n("Commits the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(QIcon::fromTheme("vcs-add-cvs-cervisia"), i18n("&Add to Repository..."), this);
    actionCollection()->addAction("file_add", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotAdd()));
    action->setIconText(i18n("Add"));
    actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::Key_Insert));
    hint = i18n("Adds (cvs add) the selected files to the repository");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("Add &Binary..."), this);
    actionCollection()->addAction("file_add_binary", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotAddBinary()));
    hint = i18n("Adds (cvs -kb add) the selected files as binaries to the repository");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(QIcon::fromTheme("vcs-remove-cvs-cervisia"), i18n("&Remove From Repository..."), this);
    actionCollection()->addAction("file_remove", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotRemove()));
    action->setIconText(i18n("Remove"));
    actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::Key_Delete));
    hint = i18n("Removes (cvs remove) the selected files from the repository");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("Rever&t"), this);
    actionCollection()->addAction("file_revert_local_changes", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotRevert()));
    hint = i18n("Reverts (cvs update -C) the selected files (only cvs 1.11)");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("&Properties"), this);
    actionCollection()->addAction("file_properties", action );
    connect(action, SIGNAL(triggered()), SLOT(slotFileProperties()));

    //
    // View Menu
    //
    action  = new QAction(QIcon::fromTheme("process-stop"), i18n("Stop"), this);
    actionCollection()->addAction("stop_job", action );
    connect(action, SIGNAL(triggered(bool)), protocol, SLOT(cancelJob()));
    actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::Key_Escape));
    action->setEnabled( false );
    hint = i18n("Stops any running sub-processes");
    action->setToolTip( hint );
    action->setWhatsThis( hint );


    action  = new QAction(i18n("Browse &Log..."), this);
    actionCollection()->addAction("view_log", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotBrowseLog()));
    actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_L));
    hint = i18n("Shows the revision tree of the selected file");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

#if 0
    action = new QAction( i18n("Browse Multi-File Log..."), 0,
                          this, SLOT(slotBrowseMultiLog()),
                          actionCollection() );
#endif
    action  = new QAction(i18n("&Annotate..."), this);
    actionCollection()->addAction("view_annotate", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotAnnotate()));
    actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_A));
    hint = i18n("Shows a blame-annotated view of the selected file");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(QIcon::fromTheme("vcs-diff-cvs-cervisia"), i18n("&Difference to Repository (BASE)..."), this);
    actionCollection()->addAction("view_diff_base", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotDiffBase()));
    actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_D));
    hint = i18n("Shows the differences of the selected file to the checked out version (tag BASE)");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(QIcon::fromTheme("vcs-diff-cvs-cervisia"), i18n("Difference to Repository (HEAD)..."), this);
    actionCollection()->addAction("view_diff_head", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotDiffHead()));
    actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_H));
    hint = i18n("Shows the differences of the selected file to the newest version in the repository (tag HEAD)");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("Last &Change..."), this);
    actionCollection()->addAction("view_last_change", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotLastChange()));
    hint = i18n("Shows the differences between the last two revisions of the selected file");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("&History..."), this);
    actionCollection()->addAction("view_history", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotHistory()));
    hint = i18n("Shows the CVS history as reported by the server");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("&Unfold File Tree"), this);
    actionCollection()->addAction("view_unfold_tree", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotUnfoldTree()));

    hint = i18n("Opens all branches of the file tree");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("&Fold File Tree"), this);
    actionCollection()->addAction("view_fold_tree", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotFoldTree()));
    hint = i18n("Closes all branches of the file tree");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    //
    // Advanced Menu
    //
    action  = new QAction(i18n("&Tag/Branch..."), this);
    actionCollection()->addAction("create_tag", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotCreateTag()));
    hint = i18n("Creates a tag or branch for the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("&Delete Tag..."), this);
    actionCollection()->addAction("delete_tag", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotDeleteTag()));
    hint = i18n("Deletes a tag from the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("&Update to Tag/Date..."), this);
    actionCollection()->addAction("update_to_tag", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotUpdateToTag()));
    hint = i18n("Updates the selected files to a given tag, branch or date");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("Update to &HEAD"), this);
    actionCollection()->addAction("update_to_head", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotUpdateToHead()));
    hint = i18n("Updates the selected files to the HEAD revision");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("&Merge..."), this);
    actionCollection()->addAction("merge", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotMerge()));
    hint = i18n("Merges a branch or a set of modifications into the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("&Add Watch..."), this);
    actionCollection()->addAction("add_watch", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotAddWatch()));
    hint = i18n("Adds a watch for the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("&Remove Watch..."), this);
    actionCollection()->addAction("remove_watch", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotRemoveWatch()));
    hint = i18n("Removes a watch from the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("Show &Watchers"), this);
    actionCollection()->addAction("show_watchers", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotShowWatchers()));
    hint = i18n("Shows the watchers of the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("Ed&it Files"), this);
    actionCollection()->addAction("edit_files", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotEdit()));
    hint = i18n("Edits (cvs edit) the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("U&nedit Files"), this);
    actionCollection()->addAction("unedit_files", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotUnedit()));
    hint = i18n("Unedits (cvs unedit) the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("Show &Editors"), this);
    actionCollection()->addAction("show_editors", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotShowEditors()));
    hint = i18n("Shows the editors of the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("&Lock Files"), this);
    actionCollection()->addAction("lock_files", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotLock()));
    hint = i18n("Locks the selected files, so that others cannot modify them");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("Unl&ock Files"), this);
    actionCollection()->addAction("unlock_files", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotUnlock()));
    hint = i18n("Unlocks the selected files");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("Create &Patch Against Repository..."), this);
    actionCollection()->addAction("make_patch", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotMakePatch()));
    hint = i18n("Creates a patch from the modifications in your sandbox");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    //
    // Repository Menu
    //
    action  = new QAction(i18n("&Create..."), this);
    actionCollection()->addAction("repository_create", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotCreateRepository()));

    action  = new QAction(i18n("&Checkout..."), this);
    actionCollection()->addAction("repository_checkout", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotCheckout()));
    hint = i18n("Allows you to checkout a module from a repository");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("&Import..."), this);
    actionCollection()->addAction("repository_import", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotImport()));
    hint = i18n("Allows you to import a module into a repository");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(i18n("&Repositories..."), this);
    actionCollection()->addAction("show_repositories", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotRepositories()));
    hint = i18n("Configures a list of repositories you regularly use");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    //
    // Settings menu
    //
    action  = new KToggleAction(i18n("Hide All &Files"), this);
    actionCollection()->addAction("settings_hide_files", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotHideFiles()));
    hint = i18n("Determines whether only folders are shown");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new KToggleAction(i18n("Hide Unmodified Files"), this);
    actionCollection()->addAction("settings_hide_uptodate", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotHideUpToDate()));
    hint = i18n("Determines whether files with status up-to-date or "
                "unknown are hidden");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new KToggleAction(i18n("Hide Removed Files"), this);
    actionCollection()->addAction("settings_hide_removed", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotHideRemoved()));
    hint = i18n("Determines whether removed files are hidden");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new KToggleAction(i18n("Hide Non-CVS Files"), this);
    actionCollection()->addAction("settings_hide_notincvs", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotHideNotInCVS()));
    hint = i18n("Determines whether files not in CVS are hidden");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new KToggleAction(i18n("Hide Empty Folders"), this);
    actionCollection()->addAction("settings_hide_empty_directories", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotHideEmptyDirectories()));
    hint = i18n("Determines whether folders without visible entries are hidden");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new KToggleAction(i18n("Create &Folders on Update"), this);
    actionCollection()->addAction("settings_create_dirs", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotCreateDirs()));
    hint = i18n("Determines whether updates create folders");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new KToggleAction(i18n("&Prune Empty Folders on Update"), this);
    actionCollection()->addAction("settings_prune_dirs", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotPruneDirs()));
    hint = i18n("Determines whether updates remove empty folders");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new KToggleAction(i18n("&Update Recursively"), this);
    actionCollection()->addAction("settings_update_recursively", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotUpdateRecursive()));
    hint = i18n("Determines whether updates are recursive");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new KToggleAction(i18n("C&ommit && Remove Recursively"), this);
    actionCollection()->addAction("settings_commit_recursively", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotCommitRecursive()));
    hint = i18n("Determines whether commits and removes are recursive");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new KToggleAction(i18n("Do cvs &edit Automatically When Necessary"), this);
    actionCollection()->addAction("settings_do_cvs_edit", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotDoCVSEdit()));
    hint = i18n("Determines whether automatic cvs editing is active");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action  = new QAction(QIcon::fromTheme("configure"), i18n("Configure Cervisia..."), this);
    actionCollection()->addAction("configure_cervisia", action );
    connect(action, SIGNAL(triggered(bool)), SLOT(slotConfigure()));
    hint = i18n("Allows you to configure the Cervisia KPart");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    //
    // Help Menu
    //
    action = KStandardAction::help( this, SLOT(slotHelp()), actionCollection());

    action  = new QAction(i18n("CVS &Manual"), this);
    actionCollection()->addAction("help_cvs_manual", action);
    connect(action, SIGNAL(triggered(bool)), SLOT(slotCVSInfo()));
    hint = i18n("Opens the help browser with the CVS documentation");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    //
    // Folder context menu
    //
    action  = new KToggleAction(i18n("Unfold Folder"), this);
    actionCollection()->addAction("unfold_folder", action);
    connect(action, SIGNAL(triggered(bool)), SLOT(slotUnfoldFolder()));
}


void CervisiaPart::popupRequested(const QPoint& p)
{
    QString xmlName = "context_popup";
    QTreeWidgetItem *item = update->itemAt(p);

    // context menu for non-cvs files
    if( isFileItem(item) )
    {
        UpdateItem* fileItem = static_cast<UpdateItem*>(item);
        if( fileItem->entry().m_status == Cervisia::NotInCVS )
            xmlName = "noncvs_context_popup";
    }

    // context menu for folders
    if( isDirItem(item) && update->fileSelection().isEmpty() )
    {
        xmlName = "folder_context_popup";
        KToggleAction* action = static_cast<KToggleAction*>(actionCollection()->action("unfold_folder"));
        action->setChecked(item->isExpanded());
    }

    if( QMenu* popup = static_cast<QMenu*>(hostContainer(xmlName)) )
    {
        if( isFileItem(item) )
        {
            // get name of selected file
            QString selectedFile;
            update->getSingleSelection(&selectedFile);

            if( !selectedFile.isEmpty() )
            {
                m_currentEditMenu = new Cervisia::EditWithMenu(QUrl::fromLocalFile(sandbox + '/' + selectedFile), popup);

                if( m_currentEditMenu->menu() )
                    m_editWithAction = popup->insertMenu(popup->actions().at(1),
                                                         m_currentEditMenu->menu());
            }
        }

        // Add to Ignore List Menu
        if( xmlName == "noncvs_context_popup" )
        {
            // remove old 'Add to Ignore List' menu
            if( m_addIgnoreAction && popup->actions().contains(m_addIgnoreAction) )
            {
                popup->removeAction(m_addIgnoreAction);
                delete m_currentIgnoreMenu;

                m_addIgnoreAction   = 0;
                m_currentIgnoreMenu = 0;
            }

            QStringList list = update->multipleSelection();
            m_currentIgnoreMenu = new Cervisia::AddIgnoreMenu(sandbox, list, popup);
            if( m_currentIgnoreMenu->menu() )
                m_addIgnoreAction = popup->insertMenu(actionCollection()->action("file_add"),
                                                      m_currentIgnoreMenu->menu());
        }

        popup->exec(update->viewport()->mapToGlobal(p));

        // remove old 'Edit with...' menu
        if( m_editWithAction && popup->actions().contains(m_editWithAction) )
        {
            popup->removeAction(m_editWithAction);
            delete m_currentEditMenu;

            m_editWithAction  = 0;
            m_currentEditMenu = 0;
        }
    }
    else
        qCDebug(log_cervisia) << "can't get XML definition for" << xmlName << ", factory()=" << factory();
}

void CervisiaPart::updateActions()
{
    bool hassandbox = !sandbox.isEmpty();
    stateChanged("has_sandbox", hassandbox ? StateNoReverse : StateReverse);

    bool single = update->hasSingleSelection();
    stateChanged("has_single_selection", single ? StateNoReverse
                                                : StateReverse);

    bool singleFolder = (update->multipleSelection().count() == 1);
    stateChanged("has_single_folder", singleFolder ? StateNoReverse
                                                   : StateReverse);

    //    bool nojob = !( actionCollection()->action( "stop_job" )->isEnabled() );
    bool selected = (update->currentItem() != 0);
    bool nojob = !hasRunningJob && selected;

    stateChanged("item_selected", selected ? StateNoReverse : StateReverse);
    stateChanged("has_no_job", nojob ? StateNoReverse : StateReverse);
    stateChanged("has_running_job", hasRunningJob ? StateNoReverse
                                                  : StateReverse);

}


KAboutData* CervisiaPart::createAboutData()
{
    KAboutData* about = new KAboutData(
                            "cervisiapart", i18n("Cervisia Part"),
                            CERVISIA_VERSION, i18n("A CVS frontend"),
                            KAboutLicense::GPL,
                            i18n("Copyright (c) 1999-2002 Bernd Gehrmann\n"
                                  "Copyright (c) 2002-2008 the Cervisia authors"),
                            QString(), QLatin1String("http://cervisia.kde.org"));

    about->addAuthor(i18n("Bernd Gehrmann"), i18n("Original author and former "
                     "maintainer"), "bernd@mail.berlios.de");
    about->addAuthor(i18n("Christian Loose"), i18n("Maintainer"),
                     "christian.loose@kdemail.net");
    about->addAuthor(i18n("Andr\303\251 W\303\266bbeking"), i18n("Developer"),
                     "woebbeking@kde.org");
    about->addAuthor(i18n("Carlos Woelz"), i18n("Documentation"),
                     "carloswoelz@imap-mail.com");

    about->addCredit(i18n("Richard Moore"), i18n("Conversion to KPart"),
                     "rich@kde.org");
    about->addCredit(i18n("Laurent Montel"), i18n("Conversion to D-Bus"),
                     "montel@kde.org");
    about->addCredit(i18n("Martin Koller"), i18n("Port to KDE Frameworks 5"),
                     "kollix@aon.at");

    return about;
}


void CervisiaPart::slotOpenSandbox()
{
    QString dirname = QFileDialog::getExistingDirectory(widget(), i18n("Open Sandbox"));

    if (dirname.isEmpty())
        return;

    openSandbox(QUrl::fromLocalFile(dirname));
}


void CervisiaPart::slotChangeLog()
{
    // Modal dialog
    ChangeLogDialog dlg(*config(), widget());
    if (dlg.readFile(sandbox + "/ChangeLog"))
    {
        if (dlg.exec())
            changelogstr = dlg.message();
    }
}


void CervisiaPart::slotOpen()
{
    QStringList filenames = update->fileSelection();
    if (filenames.isEmpty())
        return;
    openFiles(filenames);
}


void CervisiaPart::openFile(QString filename)
{
    QStringList files;
    files << filename;
    openFiles(files);
}


void CervisiaPart::openFiles(const QStringList &filenames)
{
    // call cvs edit automatically?
    if( opt_doCVSEdit )
    {
        QStringList files;

        // only edit read-only files
        QStringList::ConstIterator it  = filenames.begin();
        QStringList::ConstIterator end = filenames.end();
        for( ; it != end; ++it )
        {
            if( !QFileInfo(*it).isWritable() )
                files << *it;
        }

        if( files.count() )
        {
            QDBusReply<QDBusObjectPath> job = cvsService->edit(files);

            ProgressDialog dlg(widget(), "Edit", cvsService->service(),job, "edit", i18n("CVS Edit"));
            if( !dlg.execute() )
                return;
        }
    }

    // Now open the files by using KRun
    QDir dir(sandbox);

    QStringList::ConstIterator it  = filenames.begin();
    QStringList::ConstIterator end = filenames.end();
    for( ; it != end; ++it )
    {
        KRun* run = new KRun(QUrl::fromLocalFile(dir.absoluteFilePath(*it)), 0);
        run->setRunExecutables(false);
    }
}


void CervisiaPart::slotResolve()
{
    QString filename;
    update->getSingleSelection(&filename);
    if (filename.isEmpty())
        return;

    // Non-modal dialog
    ResolveDialog *l = new ResolveDialog(*config());
    if (l->parseFile(filename))
        l->show();
    else
        delete l;
}


void CervisiaPart::slotUpdate()
{
    updateSandbox();
}


void CervisiaPart::slotStatus()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    update->prepareJob(opt_updateRecursive, UpdateView::UpdateNoAct);

    QDBusReply<QDBusObjectPath> cvsJobPath= cvsService->simulateUpdate(list, opt_updateRecursive,
                                                opt_createDirs, opt_pruneDirs);

    // get command line from cvs job
    QString cmdline;
    QDBusObjectPath cvsJob = cvsJobPath;
    if(cvsJob.path().isEmpty())
       return;

    OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJob.path(),QDBusConnection::sessionBus(), this);
    QDBusReply<QString> reply = cvsjobinterface.cvsCommand();
    if( reply.isValid() )
        cmdline = reply;

    if( protocol->startJob(true) )
    {
        showJobStart(cmdline);
        connect( protocol, SIGNAL(receivedLine(QString)), update, SLOT(processUpdateLine(QString)) );
        connect( protocol, SIGNAL(jobFinished(bool,int)), update, SLOT(finishJob(bool,int)) );
        connect( protocol, SIGNAL(jobFinished(bool,int)), this, SLOT(slotJobFinished()) );
    }
}


void CervisiaPart::slotUpdateToTag()
{
    UpdateDialog *l = new UpdateDialog(cvsService, widget() );

    if (l->exec())
    {
        QString tagopt;
        if (l->byTag())
        {
            tagopt = "-r ";
            tagopt += l->tag();
        }
        else
        {
            tagopt = "-D ";
            tagopt += KShell::quoteArg(l->date());
        }
        tagopt += ' ';
        updateSandbox(tagopt);
    }
    delete l;
}


void CervisiaPart::slotUpdateToHead()
{
    updateSandbox("-A");
}


void CervisiaPart::slotRevert()
{
    updateSandbox("-C");
}


void CervisiaPart::slotMerge()
{
    MergeDialog dlg(cvsService, widget());

    if (dlg.exec())
    {
        QString tagopt;
        if (dlg.byBranch())
        {
            tagopt = "-j ";
            tagopt += dlg.branch();
        }
        else
        {
            tagopt = "-j ";
            tagopt += dlg.tag1();
            tagopt += " -j ";
            tagopt += dlg.tag2();
        }
        tagopt += ' ';
        updateSandbox(tagopt);
    }
}


void CervisiaPart::slotCommit()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    // modal dialog
    CommitDialog dlg(*config(), cvsService, widget());
    dlg.setLogMessage(changelogstr);
    dlg.setLogHistory(recentCommits);
    dlg.setFileList(list);

    if (dlg.exec())
    {
        // get new list of files
        list = dlg.fileList();
        if( list.isEmpty() )
            return;

        QString msg = dlg.logMessage();
        if( !recentCommits.contains( msg ) )
        {
            recentCommits.prepend( msg );
            while (recentCommits.count() > 50)
                recentCommits.removeLast();

            KConfigGroup conf( config(), "CommitLogs" );
            conf.writeEntry( sandbox, recentCommits );
        }

        update->prepareJob(opt_commitRecursive, UpdateView::Commit);

        QDBusReply<QDBusObjectPath> cvsJobPath = cvsService->commit(list, dlg.logMessage(),
                                             opt_commitRecursive);
        QString cmdline;
        QDBusObjectPath cvsJob = cvsJobPath;
        qCDebug(log_cervisia) << " commit: cvsJob.path():" << cvsJob.path();
        qCDebug(log_cervisia) << " list:" << list << "dlg.logMessage():" << dlg.logMessage()
                     << "opt_commitRecursive" << opt_commitRecursive;
        if(cvsJob.path().isEmpty())
           return;

        OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJob.path(),QDBusConnection::sessionBus(), this);
        QDBusReply<QString> reply = cvsjobinterface.cvsCommand();
        if( reply.isValid() )
            cmdline = reply;


        if( protocol->startJob() )
        {
            m_jobType = Commit;
            showJobStart(cmdline);
            connect( protocol, SIGNAL(jobFinished(bool,int)), update, SLOT(finishJob(bool,int)) );
            connect( protocol, SIGNAL(jobFinished(bool,int)), this, SLOT(slotJobFinished()) );
        }
    }
}


void CervisiaPart::slotAdd()
{
    addOrRemove(AddRemoveDialog::Add);
}


void CervisiaPart::slotAddBinary()
{
    addOrRemove(AddRemoveDialog::AddBinary);
}


void CervisiaPart::slotRemove()
{
    addOrRemove(AddRemoveDialog::Remove);
}


void CervisiaPart::slotFileProperties()
{
    QString filename;
    update->getSingleSelection(&filename);
    if( filename.isEmpty() )
        return;

    // Create URL from selected filename
    QDir dir(sandbox);

    // show file properties dialog
    KPropertiesDialog dlg(QUrl::fromLocalFile(dir.absoluteFilePath(filename)), widget());
    dlg.exec();
}


void CervisiaPart::updateSandbox(const QString &extraopt)
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    update->prepareJob(opt_updateRecursive, UpdateView::Update);

    QDBusReply<QDBusObjectPath> cvsJobPath = cvsService->update(list, opt_updateRecursive,
                        opt_createDirs, opt_pruneDirs, extraopt);

    // get command line from cvs job
    QString cmdline;
    QDBusObjectPath cvsJob = cvsJobPath;
    if(cvsJob.path().isEmpty())
        return;
    OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJob.path(),QDBusConnection::sessionBus(), this);
    QDBusReply<QString> reply = cvsjobinterface.cvsCommand();

    if( reply.isValid() )
        cmdline = reply;

    if( protocol->startJob(true) )
    {
        showJobStart(cmdline);
        connect( protocol, SIGNAL(receivedLine(QString)), update, SLOT(processUpdateLine(QString)) );
        connect( protocol, SIGNAL(jobFinished(bool,int)), update, SLOT(finishJob(bool,int)) );
        connect( protocol, SIGNAL(jobFinished(bool,int)), this, SLOT(slotJobFinished()) );
    }
}


void CervisiaPart::addOrRemove(AddRemoveDialog::ActionType action)
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    // modal dialog
    AddRemoveDialog dlg(action, widget());
    dlg.setFileList(list);

    if (dlg.exec())
    {
        QDBusReply<QDBusObjectPath> cvsJob;

        switch (action)
        {
            case AddRemoveDialog::Add:
                update->prepareJob(false, UpdateView::Add);
                cvsJob = cvsService->add(list, false);
            break;

            case AddRemoveDialog::AddBinary:
                update->prepareJob(false, UpdateView::Add);
                cvsJob = cvsService->add(list, true);
            break;

            case AddRemoveDialog::Remove:
                update->prepareJob(opt_commitRecursive, UpdateView::Remove);
                cvsJob = cvsService->remove(list, opt_commitRecursive);
            break;
        }

        // get command line from cvs job
        QString cmdline;
        QDBusObjectPath cvsJobPath = cvsJob;
        if(cvsJobPath.path().isEmpty())
           return;

        OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJobPath.path(),QDBusConnection::sessionBus(), this);
        QDBusReply<QString> reply = cvsjobinterface.cvsCommand();

        if( reply.isValid() )
            cmdline = reply;

        if (protocol->startJob())
        {
            showJobStart(cmdline);
            connect( protocol, SIGNAL(jobFinished(bool,int)),
                     update, SLOT(finishJob(bool,int)) );
            connect( protocol, SIGNAL(jobFinished(bool,int)),
                     this, SLOT(slotJobFinished()) );
        }
    }
}

void CervisiaPart::slotBrowseLog()
{
    QString filename;
    update->getSingleSelection(&filename);
    if (filename.isEmpty())
        return;

    // Non-modal dialog
    LogDialog *l = new LogDialog(*CervisiaPart::config());
    if (l->parseCvsLog(cvsService, filename))
        l->show();
    else
        delete l;
}


void CervisiaPart::slotAnnotate()
{
    QString filename, revision;
    update->getSingleSelection(&filename, &revision);

    if (filename.isEmpty())
        return;

    // Non-modal dialog
    AnnotateDialog* dlg = new AnnotateDialog(*config());
    AnnotateController ctl(dlg, cvsService);
    ctl.showDialog(filename, revision);
}


void CervisiaPart::slotDiffBase()
{
    showDiff(QLatin1String("BASE"));
}


void CervisiaPart::slotDiffHead()
{
    showDiff(QLatin1String("HEAD"));
}


void CervisiaPart::slotAddWatch()
{
    addOrRemoveWatch(WatchDialog::Add);
}


void CervisiaPart::slotRemoveWatch()
{
    addOrRemoveWatch(WatchDialog::Remove);
}


void CervisiaPart::addOrRemoveWatch(WatchDialog::ActionType action)
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    WatchDialog dlg(action, widget());

    if (dlg.exec() && dlg.events() != WatchDialog::None)
    {
        QDBusReply<QDBusObjectPath> cvsJob;

        if (action == WatchDialog::Add)
            cvsJob = cvsService->addWatch(list, dlg.events());
        else
            cvsJob = cvsService->removeWatch(list, dlg.events());

        QString cmdline;
        QDBusObjectPath cvsJobPath = cvsJob;
        if(cvsJobPath.path().isEmpty())
           return;

        OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJobPath.path(),QDBusConnection::sessionBus(), this);
        QDBusReply<QString> reply = cvsjobinterface.cvsCommand();

        if( reply.isValid() )
           cmdline = reply;

        if( protocol->startJob() )
        {
            showJobStart(cmdline);
            connect( protocol, SIGNAL(jobFinished(bool,int)),
                     this,     SLOT(slotJobFinished()) );
        }
    }
}


void CervisiaPart::slotShowWatchers()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    // Non-modal dialog
    WatchersDialog* dlg = new WatchersDialog(*config());
    if( dlg->parseWatchers(cvsService, list) )
        dlg->show();
    else
        delete dlg;
}


void CervisiaPart::slotEdit()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    QDBusReply<QDBusObjectPath> cvsJobPath = cvsService->edit(list);

    QString cmdline;
    QDBusObjectPath cvsJob = cvsJobPath;
    if(cvsJob.path().isEmpty())
       return;

    OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJob.path(),QDBusConnection::sessionBus(), this);
    QDBusReply<QString> reply = cvsjobinterface.cvsCommand();

    if( reply.isValid() )
        cmdline = reply;

    if( protocol->startJob() )
    {
        showJobStart(cmdline);
        connect( protocol, SIGNAL(jobFinished(bool,int)),
                 this,     SLOT(slotJobFinished()) );
    }
}


void CervisiaPart::slotUnedit()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    QDBusReply<QDBusObjectPath> cvsJob = cvsService->unedit(list);

    QString cmdline;
    QDBusObjectPath cvsJobPath = cvsJob;
    if(cvsJobPath.path().isEmpty())
        return;

    OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJobPath.path(),QDBusConnection::sessionBus(), this);
    QDBusReply<QString> reply = cvsjobinterface.cvsCommand();

    if( reply.isValid() )
        cmdline = reply;

    if( protocol->startJob() )
    {
        showJobStart(cmdline);
        connect( protocol, SIGNAL(jobFinished(bool,int)),
                 this,     SLOT(slotJobFinished()) );
    }
}


void CervisiaPart::slotLock()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    QDBusReply<QDBusObjectPath> cvsJobPath = cvsService->lock(list);
    QDBusObjectPath cvsJob = cvsJobPath;
    if(cvsJob.path().isEmpty())
      return;
    QString cmdline;
    OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJob.path(),QDBusConnection::sessionBus(), this);
    QDBusReply<QString> reply = cvsjobinterface.cvsCommand();

    if( reply.isValid() )
        cmdline = reply;

    if( protocol->startJob() )
    {
        showJobStart(cmdline);
        connect( protocol, SIGNAL(jobFinished(bool,int)),
                 this,     SLOT(slotJobFinished()) );
    }
}


void CervisiaPart::slotUnlock()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    QDBusReply<QDBusObjectPath> cvsJobPath = cvsService->unlock(list);
    QDBusObjectPath cvsJob = cvsJobPath;
    if(cvsJob.path().isEmpty())
      return;

    QString cmdline;
    OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJob.path(),QDBusConnection::sessionBus(), this);
    QDBusReply<QString> reply = cvsjobinterface.cvsCommand();

    if( reply.isValid() )
        cmdline = reply;

    if( protocol->startJob() )
    {
        showJobStart(cmdline);
        connect( protocol, SIGNAL(jobFinished(bool,int)),
                 this,     SLOT(slotJobFinished()) );
    }
}


void CervisiaPart::slotShowEditors()
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    QDBusReply<QDBusObjectPath> cvsJobPath = cvsService->editors(list);
    QDBusObjectPath cvsJob = cvsJobPath;
    if(cvsJob.path().isEmpty())
       return;

    QString cmdline;
    OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJob.path(),QDBusConnection::sessionBus(), this);
    QDBusReply<QString> reply = cvsjobinterface.cvsCommand();

    if( reply.isValid() )
        cmdline = reply;

    if( protocol->startJob() )
    {
        showJobStart(cmdline);
        connect( protocol, SIGNAL(jobFinished(bool,int)),
                 this,     SLOT(slotJobFinished()) );
    }
}


void CervisiaPart::slotMakePatch()
{
    Cervisia::PatchOptionDialog optionDlg;
    if( optionDlg.exec() == QDialog::Rejected )
        return;

    QString format      = optionDlg.formatOption();
    QString diffOptions = optionDlg.diffOptions();

    QDBusReply<QDBusObjectPath> job = cvsService->makePatch(diffOptions, format);
    if( !job.isValid() )
        return;

    ProgressDialog dlg(widget(), "Diff", cvsService->service(),job, "", i18n("CVS Diff"));
    if( !dlg.execute() )
        return;

    QString fileName = QFileDialog::getSaveFileName();
    if( fileName.isEmpty() )
        return;

    if( !Cervisia::CheckOverwrite(fileName) )
        return;

    QFile f(fileName);
    if( !f.open(QIODevice::WriteOnly) )
    {
        KMessageBox::sorry(widget(),
                           i18n("Could not open file for writing."),
                           "Cervisia");
        return;
    }

    QTextStream t(&f);
    QString line;
    while( dlg.getLine(line) )
        t << line << '\n';

    f.close();
}


void CervisiaPart::slotImport()
{
    CheckoutDialog dlg(*config(), cvsService, CheckoutDialog::Import, widget());

    if( !dlg.exec() )
        return;

    QDBusReply<QDBusObjectPath> cvsJobPath = cvsService->import(dlg.workingDirectory(), dlg.repository(),
                                        dlg.module(), dlg.ignoreFiles(),
                                        dlg.comment(), dlg.vendorTag(),
                                        dlg.releaseTag(), dlg.importBinary(),
                                        dlg.useModificationTime());


    QDBusObjectPath cvsJob = cvsJobPath;
    QString cmdline;
    ////qDebug()<<" cvsJob.path() :"<<cvsJob.path()<<endl;
    if(cvsJob.path().isEmpty())
        return;
    OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJob.path(),QDBusConnection::sessionBus(), this);
    QDBusReply<QString> reply = cvsjobinterface.cvsCommand();

    if( reply.isValid() )
        cmdline = reply;

    if( protocol->startJob() )
    {
        showJobStart(cmdline);
        connect( protocol, SIGNAL(jobFinished(bool,int)),
                 this,     SLOT(slotJobFinished()) );
    }
}


void CervisiaPart::slotCreateRepository()
{
    Cervisia::CvsInitDialog dlg(widget());

    if( !dlg.exec() )
        return;

    QDBusReply<QDBusObjectPath> cvsJobPath = cvsService->createRepository(dlg.directory());
    QDBusObjectPath cvsJob = cvsJobPath;
    QString cmdline;
    if(cvsJob.path().isEmpty())
       return;
    OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJob.path(),QDBusConnection::sessionBus(), this);
    QDBusReply<QString> reply = cvsjobinterface.cvsCommand();

    if( reply.isValid() )
        cmdline = reply;

    if( protocol->startJob() )
    {
        showJobStart(cmdline);
        connect( protocol, SIGNAL(jobFinished(bool,int)),
                 this,     SLOT(slotJobFinished()) );
    }
}


void CervisiaPart::slotCheckout()
{
    CheckoutDialog dlg(*config(), cvsService, CheckoutDialog::Checkout, widget());

    if( !dlg.exec() )
        return;

    QDBusReply<QDBusObjectPath> cvsJobPath = cvsService->checkout(dlg.workingDirectory(), dlg.repository(),
                                          dlg.module(), dlg.branch(), opt_pruneDirs,
                                          dlg.alias(), dlg.exportOnly(), dlg.recursive());
    QDBusObjectPath cvsJob = cvsJobPath;
    QString cmdline;
    OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJob.path(),QDBusConnection::sessionBus(), this);
    QDBusReply<QString> reply = cvsjobinterface.cvsCommand();

    if( reply.isValid() )
        cmdline = reply;

    if( protocol->startJob() )
    {
        showJobStart(cmdline);
        connect( protocol, SIGNAL(jobFinished(bool,int)),
                 this,     SLOT(slotJobFinished()) );
    }
}


void CervisiaPart::slotRepositories()
{
    RepositoryDialog *l = new RepositoryDialog(*config(), cvsService, m_cvsServiceInterfaceName, widget());
    l->show();
}


void CervisiaPart::slotCreateTag()
{
    createOrDeleteTag(TagDialog::Create);
}


void CervisiaPart::slotDeleteTag()
{
    createOrDeleteTag(TagDialog::Delete);
}


void CervisiaPart::createOrDeleteTag(TagDialog::ActionType action)
{
    QStringList list = update->multipleSelection();
    if (list.isEmpty())
        return;

    TagDialog dlg(action, cvsService, widget());

    if (dlg.exec())
    {
        QDBusReply<QDBusObjectPath> cvsJob;

        if( action == TagDialog::Create )
            cvsJob = cvsService->createTag(list, dlg.tag(), dlg.branchTag(),
                                           dlg.forceTag());
        else
            cvsJob = cvsService->deleteTag(list, dlg.tag(), dlg.branchTag(),
                                           dlg.forceTag());
    QDBusObjectPath cvsJobPath = cvsJob;
        QString cmdline;
        OrgKdeCervisia5CvsserviceCvsjobInterface cvsjobinterface(m_cvsServiceInterfaceName,cvsJobPath.path(),QDBusConnection::sessionBus(), this);
        QDBusReply<QString> reply = cvsjobinterface.cvsCommand();

        if( reply.isValid() )
           cmdline = reply;

        if( protocol->startJob() )
        {
            showJobStart(cmdline);
            connect( protocol, SIGNAL(jobFinished(bool,int)),
                     this,     SLOT(slotJobFinished()) );
        }
    }
}



void CervisiaPart::slotLastChange()
{
    QString filename, revA, revB;
    update->getSingleSelection(&filename, &revA);
    if (filename.isEmpty())
        return;

    int pos, lastnumber = 0;
    bool ok;
    if ( (pos = revA.lastIndexOf('.')) == -1
         || (lastnumber=revA.right(revA.length()-pos-1).toUInt(&ok), !ok) )
    {
        KMessageBox::sorry(widget(),
                           i18n("The revision looks invalid."),
                           "Cervisia");
        return;
    }
    if (lastnumber == 0)
    {
        KMessageBox::sorry(widget(),
                           i18n("This is the first revision of the branch."),
                           "Cervisia");
        return;
    }
    revB = revA.left(pos+1);
    revB += QString::number(lastnumber-1);

    // Non-modal dialog
    DiffDialog *l = new DiffDialog(*config());
    if (l->parseCvsDiff(cvsService, filename, revB, revA))
        l->show();
    else
        delete l;
}


void CervisiaPart::slotHistory()
{
    // Non-modal dialog
    HistoryDialog *l = new HistoryDialog(*config());
    if (l->parseHistory(cvsService))
        l->show();
    else
        delete l;
}


void CervisiaPart::slotHideFiles()
{
    opt_hideFiles = !opt_hideFiles;
    setFilter();
}


void CervisiaPart::slotHideUpToDate()
{
    opt_hideUpToDate = !opt_hideUpToDate;
    setFilter();
}


void CervisiaPart::slotHideRemoved()
{
    opt_hideRemoved = !opt_hideRemoved;
    setFilter();
}


void CervisiaPart::slotHideNotInCVS()
{
    opt_hideNotInCVS = !opt_hideNotInCVS;
    setFilter();
}


void CervisiaPart::slotHideEmptyDirectories()
{
    opt_hideEmptyDirectories = !opt_hideEmptyDirectories;
    setFilter();
}


void CervisiaPart::slotFoldTree()
{
    update->foldTree();
    setFilter();
}

void CervisiaPart::slotUnfoldTree()
{
    update->unfoldTree();
    setFilter();
}


void CervisiaPart::slotUnfoldFolder()
{
    update->unfoldSelectedFolders();
    setFilter();
}


void CervisiaPart::slotCreateDirs()
{
    opt_createDirs = !opt_createDirs;
}


void CervisiaPart::slotPruneDirs()
{
    opt_pruneDirs = !opt_pruneDirs;
}


void CervisiaPart::slotUpdateRecursive()
{
    opt_updateRecursive = !opt_updateRecursive;
}


void CervisiaPart::slotCommitRecursive()
{
    opt_commitRecursive = !opt_commitRecursive;
}


void CervisiaPart::slotDoCVSEdit()
{
    opt_doCVSEdit = !opt_doCVSEdit;
}

void CervisiaPart::slotConfigure()
{
    KConfig *conf = config();
    SettingsDialog *l = new SettingsDialog( conf, widget() );
    l->exec();

    bool splitHorz = conf->group( "LookAndFeel" ).readEntry("SplitHorizontally",true);
    splitter->setOrientation( splitHorz ?
                              Qt::Vertical :
                              Qt::Horizontal);
    delete l;
}

void CervisiaPart::slotHelp()
{
    emit setStatusBarText( i18n("Invoking help on Cervisia") );
    KToolInvocation::startServiceByDesktopName("khelpcenter", QString("help:/cervisia/index.html"));
}


void CervisiaPart::slotCVSInfo()
{
    emit setStatusBarText( i18n("Invoking help on CVS") );
    KToolInvocation::startServiceByDesktopName("khelpcenter", QString("info:/cvs/Top"));
}


void CervisiaPart::showJobStart(const QString &cmdline)
{
    hasRunningJob = true;
    actionCollection()->action( "stop_job" )->setEnabled( true );

    emit setStatusBarText( cmdline );
    updateActions();
}


void CervisiaPart::showDiff(const QString& revision)
{
    QString fileName;
    update->getSingleSelection(&fileName);

    if (fileName.isEmpty())
        return;

    // Non-modal dialog
    DiffDialog *l = new DiffDialog(*config());
    if (l->parseCvsDiff(cvsService, fileName, revision, QString()))
        l->show();
    else
        delete l;
}


void CervisiaPart::slotJobFinished()
{
    actionCollection()->action( "stop_job" )->setEnabled( false );
    hasRunningJob = false;
    emit setStatusBarText( i18n("Done") );
    updateActions();

    disconnect( protocol, SIGNAL(receivedLine(QString)),
                update,   SLOT(processUpdateLine(QString)) );

    if( m_jobType == Commit )
    {
        KNotification::event("cvs_commit_done",
                             i18n("A CVS commit to repository %1 is done",
                              repository), QPixmap(), widget()->parentWidget());
        m_jobType = Unknown;
    }
}


bool CervisiaPart::openSandbox(const QUrl& url)
{
    // Do we have a cvs service?
    if( !cvsService )
        return false;
    OrgKdeCervisia5RepositoryInterface cvsRepository( m_cvsServiceInterfaceName, "/CvsRepository",QDBusConnection::sessionBus());

    // change the working copy directory for the cvs D-Bus service
    QDBusReply<bool> reply = cvsRepository.setWorkingCopy(url.path());

    if( !reply.isValid() || !reply.value() )
    {
        KMessageBox::sorry(widget(),
                           i18n("This is not a CVS folder.\n"
                           "If you did not intend to use Cervisia, you can "
                           "switch view modes within Konqueror."),
                           "Cervisia");

        // remove path from recent sandbox menu
        recent->removeUrl( url );

        return false;
    }

    changelogstr = "";
    sandbox      = "";
    repository   = "";

    // get path of sandbox for recent sandbox menu
    sandbox = cvsRepository.workingCopy();
    recent->addUrl( url );

    // get repository for the caption of the window
    repository = cvsRepository.location();
    emit setWindowCaption(sandbox + '(' + repository + ')');

    // set m_url member for tabbed window modus of Konqueror
    setUrl(url);

    // *NOTICE*
    // The order is important here. We have to set the url member before
    // calling this function because the progress dialog uses the enter_loop()/
    // exit_loop() methods. Those methods result in a call to queryExit() in
    // cervisiashell.cpp which then uses the url member to save the last used
    // directory.
    if( cvsRepository.retrieveCvsignoreFile() )
        Cervisia::GlobalIgnoreList().retrieveServerIgnoreList(cvsService,
                                                              repository);
    QDir::setCurrent(sandbox);
    update->openDirectory(sandbox);
    setFilter();

    KConfig *conf = config();
    bool dostatus = conf->group( "General" ).readEntry(repository.contains(":")?
                                                       "StatusForRemoteRepos" :
                                                       "StatusForLocalRepos",
                                                       false);
    if (dostatus)
    {
        update->topLevelItem(0)->setSelected(true);
        slotStatus();
    }

    //load the recentCommits for this app from the KConfig app
    recentCommits = conf->group( "CommitLogs" ).readEntry( sandbox,QStringList() );

    return true;
}


void CervisiaPart::setFilter()
{
    UpdateView::Filter filter = UpdateView::Filter(0);
    if (opt_hideFiles)
        filter = UpdateView::Filter(filter | UpdateView::OnlyDirectories);
    if (opt_hideUpToDate)
        filter = UpdateView::Filter(filter | UpdateView::NoUpToDate);
    if (opt_hideRemoved)
        filter = UpdateView::Filter(filter | UpdateView::NoRemoved);
    if (opt_hideNotInCVS)
        filter = UpdateView::Filter(filter | UpdateView::NoNotInCVS);
    if (opt_hideEmptyDirectories)
        filter = UpdateView::Filter(filter | UpdateView::NoEmptyDirectories);
    update->setFilter(filter);

    QString str;
    if (opt_hideFiles)
        str = 'F';
    else
        {
            if (opt_hideUpToDate)
                str += 'N';
            if (opt_hideRemoved)
                str += 'R';
        }

    if( filterLabel )
        filterLabel->setText(str);
}


void CervisiaPart::readSettings()
{
    const KConfigGroup config( this->config(), "Session");
    recent->loadEntries( config );

    // Unfortunately, the KConfig systems sucks and we have to live
    // with all entries in one group for session management.

    opt_createDirs = config.readEntry("Create Dirs", true);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_create_dirs" )))
    ->setChecked( opt_createDirs );

    opt_pruneDirs = config.readEntry("Prune Dirs", true);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_prune_dirs" )))
    ->setChecked( opt_pruneDirs );

    opt_updateRecursive = config.readEntry("Update Recursive", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_update_recursively" )))
    ->setChecked( opt_updateRecursive );

    opt_commitRecursive = config.readEntry("Commit Recursive", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_commit_recursively" )))
    ->setChecked( opt_commitRecursive );

    opt_doCVSEdit = config.readEntry("Do cvs edit", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_do_cvs_edit" )))
    ->setChecked( opt_doCVSEdit );

    opt_hideFiles = config.readEntry("Hide Files", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_hide_files" )))
    ->setChecked( opt_hideFiles );

    opt_hideUpToDate = config.readEntry("Hide UpToDate Files", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_hide_uptodate" )))
    ->setChecked( opt_hideUpToDate );

    opt_hideRemoved = config.readEntry("Hide Removed Files", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_hide_removed" )))
    ->setChecked( opt_hideRemoved );

    opt_hideNotInCVS = config.readEntry("Hide Non CVS Files", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_hide_notincvs" )))
    ->setChecked( opt_hideNotInCVS );

    opt_hideEmptyDirectories = config.readEntry("Hide Empty Directories", false);
    (static_cast<KToggleAction *> (actionCollection()->action( "settings_hide_empty_directories" )))
    ->setChecked( opt_hideEmptyDirectories );

    setFilter();

    int splitterpos1 = config.readEntry("Splitter Pos 1", 0);
    int splitterpos2 = config.readEntry("Splitter Pos 2", 0);
    if (splitterpos1)
    {
        QList<int> sizes;
        sizes << splitterpos1;
        sizes << splitterpos2;
        splitter->setSizes(sizes);
    }
}


void CervisiaPart::writeSettings()
{
    KConfigGroup config( this->config(), "Session");
    recent->saveEntries( config );

    config.writeEntry("Create Dirs", opt_createDirs);
    config.writeEntry("Prune Dirs", opt_pruneDirs);
    config.writeEntry("Update Recursive", opt_updateRecursive);
    config.writeEntry("Commit Recursive", opt_commitRecursive);
    config.writeEntry("Do cvs edit", opt_doCVSEdit);
    config.writeEntry("Hide Files", opt_hideFiles);
    config.writeEntry("Hide UpToDate Files", opt_hideUpToDate);
    config.writeEntry("Hide Removed Files", opt_hideRemoved);
    config.writeEntry("Hide Non CVS Files", opt_hideNotInCVS);
    config.writeEntry("Hide Empty Directories", opt_hideEmptyDirectories);
    QList<int> sizes = splitter->sizes();
    config.writeEntry("Splitter Pos 1", sizes[0]);
    config.writeEntry("Splitter Pos 2", sizes[1]);

    // write to disk
    config.sync();
}


void CervisiaPart::guiActivateEvent(KParts::GUIActivateEvent* event)
{
    if( event->activated() && cvsService )
    {
        // initial setup of the menu items' state
        updateActions();
    }

    // don't call this as it overwrites Konqueror's caption (if you have a
    // Konqueror with more than one view and switch back to Cervisia)
    //
    // KParts::ReadOnlyPart::guiActivateEvent(event);
}


CervisiaBrowserExtension::CervisiaBrowserExtension( CervisiaPart *p )
    : KParts::BrowserExtension( p )
{
}

CervisiaBrowserExtension::~CervisiaBrowserExtension()
{

}

// Local Variables:
// c-basic-offset: 4
// End: