summaryrefslogtreecommitdiffstats
path: root/quanta/src/quanta_init.cpp
blob: 155a376b1ff81992a88aedda809b41f150e38a52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
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
/***************************************************************************
                          quanta.cpp  -  description
                             -------------------
    begin                : ?? ???  9 13:29:57 EEST 2000
    copyright            : (C) 2000 by Dmitry Poplavsky & Alexander Yakovlev <pdima@users.sourceforge.net,yshurik@linuxfan.com>
                           (C) 2001-2004 by Andras Mantia <amantia@kde.org>
                           (C) 2000, 2003 by Eric Laffoon <sequitur@kde.org>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

// include files for QT
#include <tqdir.h>
#include <tqprinter.h>
#include <tqpainter.h>
#include <tqtabwidget.h>
#include <tqwidgetstack.h>
#include <tqlayout.h>
#include <tqeventloop.h>
#include <tqtimer.h>
#include <tqdom.h>
#include <tqfile.h>
#include <tqfileinfo.h>
#include <tqtextcodec.h>
#include <tqpopupmenu.h>
#include <tqdatetime.h>
#include <tqradiobutton.h>

// include files for KDE
#include <dcopclient.h>
#include <kaccel.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <kmessagebox.h>
#include <tdefiledialog.h>
#include <kglobal.h>
#include <kmenubar.h>
#include <klocale.h>
#include <tdeconfig.h>
#include <tdehtmlview.h>
#include <kstandarddirs.h>
#include <kstatusbar.h>
#include <kaction.h>
#include <kstdaction.h>
#include <kpopupmenu.h>
#include <kprocess.h>
#include <kprogress.h>
#include <ktip.h>
#include <tdeio/netaccess.h>
#include <ktabwidget.h>
#include <tdemultitabbar.h>
#include <tdetexteditor/view.h>

#include "wkafkapart.h"
#include "kafkacommon.h"
#include "undoredo.h"
#include <dom/dom_string.h>

// application specific includes

#include "quanta_init.h"
#include "quanta.h"
#include "viewmanager.h"
#include "quantadoc.h"
#include "resource.h"
#include "document.h"
#include "qextfileinfo.h"

#include "project.h"
#include "debuggermanager.h"

#include "wkafkapart.h"
#include "whtmlpart.h"
#include "annotationoutput.h"
#include "messageoutput.h"

#include "tagaction.h"

#include "filestreeview.h"
#include "projecttreeview.h"
#include "doctreeview.h"
#include "structtreeview.h"
#include "templatestreeview.h"
#include "tagattributetree.h"
#include "scripttreeview.h"
#include "toolbartabwidget.h"

#ifdef ENABLE_CVSSERVICE
#include "cvsservice.h"
#endif

#include "quantaplugin.h"
#include "quantaplugininterface.h"


#include "parser.h"
#include "filemasks.h"
#include "dirtydlg.h"
#include "dirtydialog.h"

#include "dtds.h"
#include "qpevents.h"
#include "quantabookmarks.h"

#include "tagactionmanager.h"
#include "tagactionset.h"

extern TQMap<int, TQString> replacementMap;

QuantaInit::QuantaInit(QuantaApp * quantaApp)
        : TQObject()
{
  m_quanta = quantaApp;
  connect(this, TQT_SIGNAL(hideSplash()), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotHideSplash()));
}

QuantaInit::~QuantaInit()
{
}


/** Delayed initialization. */
void QuantaInit::initQuanta()
{
  m_config = quantaApp->m_config;
  parser = new Parser();

  TQStringList tmpDirs = TDEGlobal::dirs()->resourceDirs("tmp");
  TQDir dir;
  tmpDir = tmpDirs[0];
  for (uint i = 0; i < tmpDirs.count(); i++)
  {
    if (tmpDirs[i].contains("kde-"))
       tmpDir = tmpDirs[i];
  }
  dir.mkdir(tmpDir + "quanta");
  tmpDir += "quanta/quanta";

  scriptBeginRx.setCaseSensitive(false);
  scriptBeginRx.setPattern("(<script)");
  scriptEndRx.setCaseSensitive(false);
  scriptEndRx.setPattern("(/script>)");

  initStatusBar();

  //defaultDocType must be read before the Project object is created!!
  m_config->setGroup("General Options");
  qConfig.defaultDocType = m_config->readEntry("Default DTD",DEFAULT_DTD);
  if (! DTDs::ref()->find(qConfig.defaultDocType))
     qConfig.defaultDocType = DEFAULT_DTD;
  DTDs::ref()->find("dtd"); //load on startup

  initView();
  initDocument();  // after initView because of init of treeViews
  initProject();
  initActions();


  DTDs::ref();  // create the class, must be before readOptions() !
  readOptions();
  initPlugins();  // needs to be before createGUI because some actions are created inside
  readAbbreviations();

  // Initialize debugger
  m_quanta->m_debugger = new DebuggerManager(TQT_TQOBJECT(m_quanta));
  connect(Project::ref(), TQT_SIGNAL(newProjectLoaded(const TQString &, const KURL &, const KURL &)),
          m_quanta->m_debugger, TQT_SLOT(slotNewProjectLoaded(const TQString &, const KURL &, const KURL &)));
  connect(Project::ref(), TQT_SIGNAL(eventHappened(const TQString &, const TQString &, const TQString &)),
          m_quanta->m_debugger, TQT_SLOT(slotHandleEvent(const TQString &, const TQString &, const TQString &)));
  connect(m_quanta->m_debugger, TQT_SIGNAL(hideSplash()), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotHideSplash()));

  //m_quanta->KDockMainWindow::createGUI( TQString(), false /* conserveMemory */ );
  m_quanta->createShellGUI(true);

  addToolTreeView(m_quanta->fTab, i18n("Files"), UserIcon("ftab"), KDockWidget::DockLeft);
  addToolTreeView(m_quanta->dTab, i18n("Documentation"), BarIcon("contents"), KDockWidget::DockRight);
  addToolTreeView(m_quanta->aTab, i18n("Attribute Editor"), UserIcon("tag_misc"), KDockWidget::DockRight);
  addToolTreeView(ProjectTreeView::ref(), i18n("Project"), UserIcon("ptab"), KDockWidget::DockLeft);
  addToolTreeView(TemplatesTreeView::ref(), i18n("Templates"), UserIcon("ttab"), KDockWidget::DockLeft);
  addToolTreeView(StructTreeView::ref(), i18n("Document Structure"), BarIcon("view_sidetree"), KDockWidget::DockLeft);
  addToolTreeView(m_quanta->scriptTab, i18n("Scripts"), BarIcon("run"), KDockWidget::DockLeft);
  m_quanta->m_messageOutputView = addToolTreeView(m_quanta->m_messageOutput, i18n("Messages"), SmallIcon("openterm"), KDockWidget::DockBottom);
  m_quanta->m_problemsOutputView = addToolTreeView(m_quanta->m_problemOutput, i18n("Problems"), SmallIcon("info"), KDockWidget::DockBottom);
  m_quanta->m_annotationOutputView = addToolTreeView(m_quanta->m_annotationOutput, i18n("Annotations"), SmallIcon("stamp"), KDockWidget::DockBottom);

  // Restore the dock layout
  m_config->setGroup  ("General Options");
  TQString layout = m_config->readEntry("Window layout", "Default");
  int mdiMode = m_config->readNumEntry("MDI mode", -1);
  if (mdiMode != -1 && layout != "Default")
  {
      m_quanta->readDockConfig(m_config); //FIXME: This causes the visible widget construction on startup, but is needed to restore the window layout...
      if (mdiMode != KMdi::IDEAlMode)
        m_quanta->setToolviewStyle(qConfig.toolviewTabs);
  }

  m_quanta->initTabWidget(true);
  qConfig.windowLayout = "Custom";
  //FIXME: This is a hack to workaround the starting problem when we are in Toplevel mode.
  //Without this, the editor becomes the child of the widget holding the menus and toolbars...
  if (mdiMode == KMdi::ToplevelMode)
  {
      m_quanta->switchToChildframeMode();
      TQTimer::singleShot(0, TQT_TQOBJECT(m_quanta), TQT_SLOT(switchToToplevelMode()));
  }

  // Always hide debugger toolbar at this point
  m_quanta->toolBar("debugger_toolbar")->hide();

  m_quanta->m_pluginInterface->setPluginMenu(static_cast<TQPopupMenu*>(m_quanta->factory()->container("plugins", m_quanta)));
 m_quanta->m_pluginInterface->buildPluginMenu();
//TODO: Remove after upgrade from 3.1 is not supported
  TQDomDocument doc;
  doc.setContent(KXMLGUIFactory::readConfigFile(m_quanta->xmlFile(), m_quanta->instance()));
  TQDomNodeList nodeList = doc.elementsByTagName("ActionProperties");
  TQDomNode node = nodeList.item(0).firstChild();
  while (!node.isNull())
  {
    if (node.nodeName() == "Action")
    {
      TQDomElement el = node.toElement();
      m_quanta->oldShortcuts.insert(el.attribute("name"), el.attribute("shortcut"));
      node = node.nextSibling();
      el.parentNode().removeChild(el);
    } else
    {
      node = node.nextSibling();
    }
  }

  m_quanta->applyMainWindowSettings(m_config);

  m_quanta->m_tagsMenu =   static_cast<TQPopupMenu*>(m_quanta->factory()->container("tags", m_quanta));
  KMenuBar *mb = m_quanta->menuBar();
  for (uint i = 0 ; i < mb->count(); i++)
  {
       if (mb->text(mb->idAt(i)) == i18n("&Settings"))
       {
          mb->insertItem(i18n("&Window"), m_quanta->windowMenu(), -1, i);
          break;
       }
  }
  TDEActionMenu *toolviewMenu = (TDEActionMenu*)(m_quanta->actionCollection()->action("tdemdi_toolview_menu"));
  if (toolviewMenu)
     toolviewMenu->plug(m_quanta->windowMenu());

  TQPopupMenu *toolbarsMenu  = (TQPopupMenu*)(m_quanta->guiFactory())->container("toolbars_load", m_quanta);
  connect(toolbarsMenu, TQT_SIGNAL(aboutToShow()), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotBuildPrjToolbarsMenu()));

  TQPopupMenu *contextMenu = (TQPopupMenu*)(m_quanta->guiFactory())->container("popup_editor", m_quanta);
  connect(contextMenu, TQT_SIGNAL(aboutToShow()), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotContextMenuAboutToShow()));

  connect(m_quanta->m_messageOutput, TQT_SIGNAL(clicked(const TQString&, int, int)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(gotoFileAndLine(const TQString&, int, int)));
  connect(m_quanta->m_problemOutput, TQT_SIGNAL(clicked(const TQString&, int, int)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(gotoFileAndLine(const TQString&, int, int)));
  connect(m_quanta->m_annotationOutput->currentFileAnnotations(), TQT_SIGNAL(clicked(const TQString&, int, int)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(gotoFileAndLine(const TQString&, int, int)));
  connect(m_quanta->m_annotationOutput, TQT_SIGNAL(clicked(const TQString&, int, int)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(gotoFileAndLine(const TQString&, int, int)));

  m_quanta->slotFileNew();
  m_quanta->slotNewStatus();
  initToolBars();
  Project::ref()->setProjectToolbarVisible(m_quanta->factory()->container("project_toolbar", m_quanta)->isShown());
  Project::ref()->slotShowProjectToolbar(Project::ref()->hasProject());
  KTipDialog::showTip(m_quanta);

  //get the PID of this running instance
  qConfig.quantaPID = TQString::number(int(getpid()), 10);
  qConfig.backupDirPath = TDEGlobal::instance()->dirs()->saveLocation("data", resourceDir + "backups/");

  m_quanta->autosaveTimer = new TQTimer(m_quanta);
  connect(m_quanta->autosaveTimer, TQT_SIGNAL(timeout()), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotAutosaveTimer()));
  m_quanta->autosaveTimer->start(qConfig.autosaveInterval * 60000, false);

  connect(m_quanta->m_doc, TQT_SIGNAL(hideSplash()), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotHideSplash()));
  connect(parser, TQT_SIGNAL(rebuildStructureTree(bool)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotReloadStructTreeView(bool)));

  // Read list of characters
  TQFile file(locate("appdata","chars"));
  if ( file.open(IO_ReadOnly) ) {    // file opened successfully
    TQTextStream t( &file );        // use a text stream
    t.setEncoding(TQTextStream::UnicodeUTF8);
    TQString s;
    while (!t.eof())
    {
      s = t.readLine();
      charList << i18n(s.utf8()); // line excluding '\n'
      int begin = s.find("(&") + 1;
      if (begin == 1)
          continue;
      int length = s.find(";)") - begin + 1;
      TQString s2 = s.mid(begin, length - 1);
      replacementMap[s[0].unicode()] = s2;
    }
    file.close();
  }

  TQString infoCss = tmpDir;
  infoCss.replace(TQRegExp("/quanta$"),"");
  infoCss += "/info.css";
  QExtFileInfo::copy(KURL().fromPathOrURL(qConfig.globalDataDir + resourceDir + "scripts/info.css"), KURL().fromPathOrURL(infoCss));

  checkRuntimeDependencies();
  ViewManager::ref()->activeDocument()->view()->setFocus();

  m_quanta->refreshTimer = new TQTimer(m_quanta);
  connect(m_quanta->refreshTimer, TQT_SIGNAL(timeout()), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotReparse()));
  m_quanta->refreshTimer->start( qConfig.refreshFrequency*1000, false ); //update the structure tree every 5 seconds
  if (qConfig.instantUpdate || qConfig.refreshFrequency == 0)
  {
    m_quanta->refreshTimer->stop();
  }

}

void QuantaInit::initToolBars()
{
 if (m_quanta->m_toolbarList.count() == 0)
   m_quanta->slotLoadToolbarForDTD(Project::ref()->defaultDTD());
}

void QuantaInit::initStatusBar()
{
  m_quanta->statusbarTimer = new TQTimer(m_quanta);
  connect(m_quanta->statusbarTimer,TQT_SIGNAL(timeout()),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(statusBarTimeout()));

  progressBar = new KProgress(m_quanta->statusBar());
  progressBar->setTextEnabled(false);
  progressBar->setMaximumHeight(progressBar->fontMetrics().height());
  progressBar->show();
  m_quanta->statusBar()->insertItem(i18n(IDS_DEFAULT),IDS_STATUS, 1);
  m_quanta->statusBar()->addWidget(progressBar);
  m_quanta->statusBar()->insertItem("",               IDS_INS_OVR  );
  m_quanta->statusBar()->insertFixedItem(" * ",       IDS_MODIFIED );
  m_quanta->statusBar()->insertFixedItem(i18n("Line: 00000 Col: 000"), IDS_STATUS_CLM, true);

  m_quanta->statusBar()->changeItem("", IDS_INS_OVR);
  m_quanta->statusBar()->changeItem("", IDS_MODIFIED);
  m_quanta->statusBar()->changeItem("", IDS_STATUS_CLM);
  m_quanta->statusBar()->setItemAlignment(IDS_STATUS, AlignLeft);
}


void QuantaInit::initDocument()
{
  m_quanta->m_doc = new QuantaDoc(0L);
  connect(m_quanta->m_doc, TQT_SIGNAL(newStatus()),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotNewStatus()));
}

void QuantaInit::initProject()
{
  Project *m_project = Project::ref(m_quanta);

  connect(m_project, TQT_SIGNAL(getTreeStatus(TQStringList *)),
          pTab, TQT_SLOT(slotGetTreeStatus(TQStringList *)));
  connect(m_project, TQT_SIGNAL(loadToolbarFile(const KURL &)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotLoadToolbarFile(const KURL &)));
  connect(m_project, TQT_SIGNAL(getUserToolbarFiles(KURL::List *)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotGetUserToolbarFiles(KURL::List *)));
  connect(m_project, TQT_SIGNAL(openFiles(const KURL::List &, const TQString&)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotFileOpen(const KURL::List &, const TQString&)));
  connect(m_project, TQT_SIGNAL(openFile(const KURL &, const TQString&)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotFileOpen(const KURL &, const TQString&)));
  connect(m_project, TQT_SIGNAL(closeFile(const KURL &)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotFileClose(const KURL &)));
  connect(m_project, TQT_SIGNAL(reloadTree(ProjectList *, bool, const TQStringList &)),
          pTab, TQT_SLOT(slotReloadTree(ProjectList *, bool, const TQStringList &)));
  connect(m_project, TQT_SIGNAL(closeFiles()), ViewManager::ref(), TQT_SLOT(closeAll()));
  connect(m_project, TQT_SIGNAL(eventHappened(const TQString&, const TQString&, const TQString& )), QPEvents::ref(TQT_TQOBJECT(m_quanta)), TQT_SLOT(slotEventHappened(const TQString&, const TQString&, const TQString& )));

  connect(m_quanta->fTab, TQT_SIGNAL(insertDirInProject(const KURL&)),
          m_project, TQT_SLOT(slotAddDirectory(const KURL&)));

  connect(m_quanta->fTab, TQT_SIGNAL(insertFileInProject(const KURL&)),
          m_project, TQT_SLOT(slotInsertFile(const KURL&)));

  connect(TemplatesTreeView::ref(), TQT_SIGNAL(insertDirInProject(const KURL&)),
          m_project, TQT_SLOT(slotAddDirectory(const KURL&)));

  connect(TemplatesTreeView::ref(), TQT_SIGNAL(insertFileInProject(const KURL&)),
          m_project, TQT_SLOT(slotInsertFile(const KURL&)));
  connect(TemplatesTreeView::ref(), TQT_SIGNAL(downloadTemplate()),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotDownloadTemplate()));
  connect(TemplatesTreeView::ref(), TQT_SIGNAL(uploadTemplate(const TQString&)), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotUploadTemplate(const TQString&)));

  // inform project if something was renamed
  connect(pTab, TQT_SIGNAL(renamed(const KURL&, const KURL&)),
          m_project, TQT_SLOT(slotRenamed(const KURL&, const KURL&)));
  connect(m_quanta->fTab, TQT_SIGNAL(renamed(const KURL&, const KURL&)),
          m_project, TQT_SLOT(slotRenamed(const KURL&, const KURL&)));
  connect(tTab, TQT_SIGNAL(renamed(const KURL&, const KURL&)),
          m_project, TQT_SLOT(slotRenamed(const KURL&, const KURL&)));

  connect(pTab, TQT_SIGNAL(insertToProject(const KURL&)),
          m_project, TQT_SLOT(slotInsertFile(const KURL&)));
  connect(pTab, TQT_SIGNAL(removeFromProject(const KURL&)),
          m_project, TQT_SLOT(slotRemove(const KURL&)));
  connect(pTab, TQT_SIGNAL(uploadSingleURL(const KURL&, const TQString&, bool, bool)),
          m_project, TQT_SLOT(slotUploadURL(const KURL&, const TQString&, bool, bool)));
  connect(pTab, TQT_SIGNAL(rescanProjectDir()), m_project, TQT_SLOT(slotRescanPrjDir()));
  connect(pTab, TQT_SIGNAL(showProjectOptions()), m_project, TQT_SLOT(slotOptions()));
  connect(pTab, TQT_SIGNAL(uploadProject()), m_project, TQT_SLOT(slotUpload()));

  connect(m_quanta->dTab, TQT_SIGNAL(reloadProjectDocs()), m_project, TQT_SLOT(slotReloadProjectDocs()));
  connect(m_project, TQT_SIGNAL(reloadProjectDocs()), m_quanta->dTab, TQT_SLOT(slotReloadProjectDocs()));
  connect(m_project, TQT_SIGNAL(addProjectDoc(const KURL&)), m_quanta->dTab, TQT_SLOT(slotAddProjectDoc(const KURL&)));

  connect(m_project, TQT_SIGNAL(enableMessageWidget()),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotShowMessagesView()));

  connect(m_project, TQT_SIGNAL(messages(const TQString&)),
          m_quanta->m_messageOutput, TQT_SLOT(showMessage(const TQString&)));

  connect(m_project, TQT_SIGNAL(newStatus()),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotNewStatus()));

  connect(m_project, TQT_SIGNAL(newProjectLoaded(const TQString &, const KURL &, const KURL &)),
          TemplatesTreeView::ref(), TQT_SLOT(slotNewProjectLoaded(const TQString &, const KURL &, const KURL &)));
  connect(m_project, TQT_SIGNAL(newProjectLoaded(const TQString &, const KURL &, const KURL &)),
          pTab, TQT_SLOT(slotNewProjectLoaded(const TQString &, const KURL &, const KURL &)));
  connect(m_project, TQT_SIGNAL(newProjectLoaded(const TQString &, const KURL &, const KURL &)),
          m_quanta->fTab, TQT_SLOT(slotNewProjectLoaded(const TQString &, const KURL &, const KURL &)));
  connect(m_project, TQT_SIGNAL(newProjectLoaded(const TQString &, const KURL &, const KURL &)),
          m_quanta->annotationOutput(), TQT_SLOT(updateAnnotations()));

  connect(pTab, TQT_SIGNAL(changeFileDescription(const KURL&, const TQString&)),
          m_project, TQT_SLOT(slotFileDescChanged(const KURL&, const TQString&)));
  connect(pTab, TQT_SIGNAL(changeUploadStatus(const KURL&, int)),
          m_project, TQT_SLOT(slotUploadStatusChanged(const KURL&, int)));
  connect(pTab, TQT_SIGNAL(changeDocumentFolderStatus(const KURL&, bool)),
          m_project, TQT_SLOT(slotChangeDocumentFolderStatus(const KURL&, bool)));

  connect(m_project, TQT_SIGNAL(hideSplash()), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotHideSplash()));

  connect(m_project, TQT_SIGNAL(statusMsg(const TQString &)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotStatusMsg(const TQString & )));
}

void QuantaInit::initView()
{
  ViewManager *m_viewManager = ViewManager::ref(TQT_TQOBJECT(m_quanta));
  connect(m_quanta, TQT_SIGNAL(viewActivated (KMdiChildView *)), m_viewManager, TQT_SLOT(slotViewActivated(KMdiChildView*)));
  connect(m_quanta, TQT_SIGNAL(lastChildViewClosed()), m_viewManager, TQT_SLOT(slotLastViewClosed()));
//   connect(m_quanta, TQT_SIGNAL(viewDeactivated(KMdiChildView *)), m_viewManager, TQT_SLOT(slotViewDeactivated(KMdiChildView*)));
  KafkaDocument *m_kafkaDocument = KafkaDocument::ref(0, 0, "KafkaPart");
  m_kafkaDocument->getKafkaWidget()->view()->setMinimumHeight(50);
  m_kafkaDocument->readConfig(quantaApp->config());
  loadVPLConfig();
  ToolbarTabWidget *toolBarTab = ToolbarTabWidget::ref(quantaApp);
  connect(toolBarTab, TQT_SIGNAL(iconTextModeChanged()), quantaApp, TQT_SLOT(slotRefreshActiveWindow()));

  //set the toolview and close button style before the GUI is created
  m_config->setGroup("General Options");
  int iconTextMode = m_config->readNumEntry("IconTextMode", TDEToolBar::IconOnly);
  toolBarTab->setIconText(TDEToolBar::IconText(iconTextMode));
  qConfig.toolviewTabs = m_config->readNumEntry("MDI style", KMdi::IconOnly);
  m_quanta->initTabWidget();

  m_quanta->setStandardMDIMenuEnabled(false);
  m_quanta->setManagedDockPositionModeEnabled(true);

  m_quanta->fTab = new FilesTreeView(m_config, m_quanta, "filestree");
  m_quanta->aTab = new EnhancedTagAttributeTree(m_quanta, "TagAttributes");
  pTab = ProjectTreeView::ref(m_quanta, "Project");
  tTab = TemplatesTreeView::ref(m_quanta, "Templates");  // creates the treeview
  m_quanta->dTab = new DocTreeView(m_quanta, "Docs");
  StructTreeView *sTab = StructTreeView::ref(m_quanta ,"Struct");
  m_quanta->scriptTab = new ScriptTreeView(m_quanta, "Scripts");

  m_quanta->m_messageOutput = new MessageOutput(m_quanta, "Messages");
  m_quanta->m_messageOutput->setFocusPolicy(TQ_NoFocus);
  m_quanta->m_messageOutput->showMessage(i18n("Message Window..."));
  connect(m_quanta, TQT_SIGNAL(showMessage(const TQString&, bool)), m_quanta->m_messageOutput, TQT_SLOT(showMessage(const TQString&, bool)));
  connect(m_quanta, TQT_SIGNAL(clearMessages()), m_quanta->m_messageOutput, TQT_SLOT(clear()));

  m_quanta->m_problemOutput = new MessageOutput(m_quanta, "Problems");
  m_quanta->m_problemOutput->setFocusPolicy(TQ_NoFocus);
  m_quanta->m_annotationOutput = new AnnotationOutput(m_quanta, "Annotations");
  m_quanta->m_annotationOutput->setFocusPolicy(TQ_NoFocus);

  m_quanta->createPreviewPart();
  m_quanta->createDocPart();

  connect(m_quanta, TQT_SIGNAL(reloadAllTrees()),
          m_quanta->fTab, TQT_SLOT(slotReloadAllTrees()));

  connect(pTab, TQT_SIGNAL(loadToolbarFile  (const KURL&)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotLoadToolbarFile(const KURL&)));
  connect(m_viewManager, TQT_SIGNAL(viewActivated(const KURL&)),
          pTab, TQT_SLOT(slotViewActivated(const KURL&)));

  connect(m_viewManager, TQT_SIGNAL(documentClosed(const KURL&)),
          pTab, TQT_SLOT(slotDocumentClosed(const KURL&)));
  connect(m_viewManager, TQT_SIGNAL(documentClosed(const KURL&)),
          tTab, TQT_SLOT(slotDocumentClosed(const KURL&)));
  connect(m_viewManager, TQT_SIGNAL(documentClosed(const KURL&)),
          m_quanta->scriptTab, TQT_SLOT(slotDocumentClosed(const KURL&)));
  connect(m_viewManager, TQT_SIGNAL(documentClosed(const KURL&)),
          m_quanta->fTab, TQT_SLOT(slotDocumentClosed(const KURL&)));

  connect(tTab, TQT_SIGNAL(insertFile  (const KURL &)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotInsertFile(const KURL &)));

  connect(m_quanta->scriptTab, TQT_SIGNAL(openFileInPreview(const KURL &)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotOpenFileInPreview(const KURL &)));
  connect(m_quanta->scriptTab, TQT_SIGNAL(showPreviewWidget(bool)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotShowPreviewWidget(bool)));
  connect(m_quanta->scriptTab, TQT_SIGNAL(assignActionToScript(const KURL &, const TQString&)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotAssignActionToScript(const KURL &, const TQString&)));
  connect(m_quanta->scriptTab, TQT_SIGNAL(downloadScript()), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotDownloadScript()));
  connect(m_quanta->scriptTab, TQT_SIGNAL(uploadScript(const TQString&)), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotUploadScript(const TQString&)));
  connect(m_quanta->dTab, TQT_SIGNAL(downloadDoc()), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotDownloadDoc()));

  connect(m_quanta->m_htmlPart, TQT_SIGNAL(onURL(const TQString&)),
              TQT_TQOBJECT(m_quanta), TQT_SLOT(slotStatusMsg(const TQString&)));
  connect(m_quanta->m_htmlPartDoc, TQT_SIGNAL(onURL(const TQString&)),
                 TQT_TQOBJECT(m_quanta), TQT_SLOT(slotStatusMsg(const TQString&)));

  connect(sTab, TQT_SIGNAL(newCursorPosition(int,int)), TQT_TQOBJECT(m_quanta), TQT_SLOT(setCursorPosition(int,int)));
  connect(sTab, TQT_SIGNAL(selectArea(int,int,int,int)), TQT_TQOBJECT(m_quanta), TQT_SLOT( selectArea(int,int,int,int)));
  connect(sTab, TQT_SIGNAL(selectTagArea(Node*)), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotSelectTagArea(Node*)));
  connect(sTab, TQT_SIGNAL(needReparse()), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotForceReparse()));
  connect(sTab, TQT_SIGNAL(showGroupsForDTEP(const TQString&, bool)), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotShowGroupsForDTEP(const TQString&, bool)));
  connect(sTab, TQT_SIGNAL(openFile(const KURL &)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT  (slotFileOpen(const KURL &)));
  connect(sTab, TQT_SIGNAL(openImage  (const KURL&)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotImageOpen(const KURL&)));
  connect(sTab, TQT_SIGNAL(showProblemMessage(const TQString&)),
          m_quanta->m_problemOutput, TQT_SLOT(showMessage(const TQString&)));
  connect(sTab, TQT_SIGNAL(clearProblemOutput()),
          m_quanta->m_problemOutput, TQT_SLOT(clear()));
  connect(parser, TQT_SIGNAL(nodeTreeChanged()), sTab, TQT_SLOT(slotNodeTreeChanged()));

  connect(m_quanta->dTab, TQT_SIGNAL(openURL(const TQString&)), TQT_TQOBJECT(m_quanta), TQT_SLOT(openDoc(const TQString&)));

  connect(m_viewManager, TQT_SIGNAL(dragInsert(TQDropEvent *)), tTab, TQT_SLOT(slotDragInsert(TQDropEvent *)));

  qConfig.windowLayout = "Default";
}

KMdiToolViewAccessor* QuantaInit::addToolTreeView(TQWidget *widget, const TQString &name, const TQPixmap &icon, KDockWidget::DockPosition position)
{
  widget->setIcon(icon);
  widget->setCaption(name);
  return m_quanta->addToolWindow(widget, m_quanta->prevDockPosition(widget, position), m_quanta->getMainDockWidget());
}

void QuantaInit::readOptions()
{
  m_config->setGroup("General Options");

  qConfig.markupMimeTypes = m_config->readEntry("Markup mimetypes", qConfig.markupMimeTypes);
  qConfig.scriptMimeTypes = m_config->readEntry("Script mimetypes", qConfig.scriptMimeTypes);
  qConfig.imageMimeTypes = m_config->readEntry("Image mimetypes", qConfig.imageMimeTypes);
  qConfig.textMimeTypes = m_config->readEntry("Text mimetypes", qConfig.textMimeTypes);

  qConfig.tagCase = m_config->readNumEntry("Capitals for tags", 0);
  qConfig.attrCase = m_config->readNumEntry("Capitals for attr", 0);
  qConfig.attrValueQuotation = (m_config->readEntry("Attribute quotation", "double") == "double" )? '"':'\'';
  qConfig.closeOptionalTags = m_config->readBoolEntry("Close tag if optional", true);
  qConfig.closeTags = m_config->readBoolEntry("Close tags", true);
  qConfig.useAutoCompletion = m_config->readBoolEntry("Auto completion",true);
  qConfig.updateClosingTags = m_config->readBoolEntry("Update Closing Tags", true);
  qConfig.replaceAccented = m_config->readBoolEntry("Replace Accented Chars", false);
  qConfig.replaceNotInEncoding = m_config->readBoolEntry("Replace Chars Not In Current Encoding", true);


  qConfig.defaultEncoding = m_config->readEntry("Default encoding", "UTF8");

  StructTreeView::ref()->setFollowCursor( m_config->readBoolEntry("Follow Cursor", true));

  qConfig.previewPosition   = m_config->readEntry("Preview area","Editor");
  qConfig.docPosition   = m_config->readEntry("Documentation area","Tab");

  qConfig.smartTagInsertion = m_config->readBoolEntry("Smart Tag Insertion", false);
  TDEAction *action = quantaApp->actionCollection()->action("smart_tag_insertion");
  (static_cast<TDEToggleAction* >(action))->setChecked(qConfig.smartTagInsertion);

  TQSize s(800,580);
  m_quanta->resize( m_config->readSizeEntry("Geometry", &s));
  qConfig.autosaveInterval = m_config->readNumEntry("Autosave interval", 1);

  qConfig.enableDTDToolbar = m_config->readBoolEntry("Show DTD Toolbar",true);
  m_quanta->showDTDToolbar->setChecked(qConfig.enableDTDToolbar);
  qConfig.showCloseButtons = m_config->readEntry("Close Buttons", "ShowDelayed");
//  m_quanta->initTabWidget(true);
  m_quanta->fileRecent ->loadEntries(m_config);
  qConfig.showHiddenFiles = m_config->readBoolEntry("Show Hidden Files", true);
  qConfig.saveTrees = m_config->readBoolEntry("Save Local Trees", true);
  int maxRecentItems = m_config->readNumEntry("Recent Files Limit", 32);
  m_quanta->fileRecent->setMaxItems(maxRecentItems);

  m_config->setGroup("Parser options");
  qConfig.showEmptyNodes = m_config->readBoolEntry("Show Empty Nodes", false);
  qConfig.showClosingTags = m_config->readBoolEntry("Show Closing Tags", false);
  qConfig.instantUpdate = m_config->readBoolEntry("Instant Update", false);
  qConfig.refreshFrequency = m_config->readNumEntry("Refresh frequency",5);
  qConfig.expandLevel = m_config->readNumEntry("Expand Level", 4);
  qConfig.showDTDSelectDialog = m_config->readBoolEntry("Show DTD Select Dialog", true);

  m_quanta->m_previewVisible = false;
  m_quanta->m_noFramesPreview = false;

  m_quanta->showVPLAction->setChecked( false );


//KNewStuff config
   m_config->setGroup("KNewStuff");
   TQString str = m_config->readEntry("ProvidersUrl");
   if (str.isEmpty())
   {
      m_config->writeEntry( "ProvidersUrl", "http://quanta.tdewebdev.org/newstuff/providers.xml" );
      m_config->sync();
   }


  Project::ref()->readConfig(m_config); // project
}

void QuantaInit::openLastFiles()
{

  // Reload previously opened files only if setting allows
  m_config->setGroup("General Options");
  if (!m_config->readBoolEntry("Reload Files", true))
  {
    m_quanta->setParserEnabled(true);
    m_quanta->reparse(true);
    return;
  }
  // we need to check config
  // because project now can be
  // in load stage ( remote prj )
  m_config->setGroup("Projects");
  TQString pu = QuantaCommon::readPathEntry(m_config, "Last Project");

  KURL u;
  QuantaCommon::setUrl(u, pu);
  bool isPrj = true;
  if (pu.isEmpty())
     isPrj = false;
  if (!u.isValid())
     isPrj = false;

  m_config->setGroup("General Options");

  TQStringList urls = QuantaCommon::readPathListEntry(m_config, "List of opened files");
  TQStringList encodings = QuantaCommon::readPathListEntry(m_config, "Encoding of opened files");
  m_quanta->m_doc->blockSignals(true);
  m_quanta->setParserEnabled(false);
  uint i = 0;
  for ( TQStringList::Iterator it = urls.begin(); it != urls.end(); ++it )
  {
    KURL fu;
    QuantaCommon::setUrl(fu, *it);

    if (!ViewManager::ref()->isOpened(fu) && (!isPrj || fu.isLocalFile()))
      m_quanta->slotFileOpen(fu, encodings[i]);
    i++;
  }
  m_config->sync();
  m_quanta->m_doc->blockSignals(false);
  m_quanta->setParserEnabled(true);
  m_quanta->reparse(true);
  Document *w = ViewManager::ref()->activeDocument();
  if (w) //w==0 might happen on quick close on startup
  {
    m_quanta->setTitle(w->url().prettyURL(0, KURL::StripFileProtocol) );
//    m_quanta->slotUpdateStatus(w);//FIXME:
  }
}

/** Loads the initial project */
void QuantaInit::loadInitialProject(const TQString& url)
{
  if(url.isNull())
  {
    if(runningQuantas() == 1)
    {
      // Get config
      TDEConfig *config = m_quanta->config();
      config->setGroup("General Options");

      // Reload last project if setting is enabled
      Project::ref()->loadLastProject(config->readBoolEntry("Reload Project", true));
    }
  }
  else
    Project::ref()->slotOpenProject(KURL( url ));
}


void QuantaInit::initActions()
{
    TDEActionCollection *ac = m_quanta->actionCollection();
    new TDEAction(i18n("Annotate..."), 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotAnnotate()),ac, "annotate");
    m_quanta->editTagAction = new TDEAction( i18n( "&Edit Current Tag..." ), CTRL+Key_E,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotEditCurrentTag() ),
                        TQT_TQOBJECT(ac), "edit_current_tag" );
    m_quanta->selectTagAreaAction = new TDEAction( i18n( "&Select Current Tag Area" ), 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotSelectTagArea() ),
                        TQT_TQOBJECT(ac), "select_tag_area" );
    new TDEAction( i18n( "E&xpand Abbreviation" ), CTRL+SHIFT+Key_J,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotExpandAbbreviation() ),
                        TQT_TQOBJECT(ac), "expand_abbreviation" );

    new TDEAction(i18n("&Report Bug..."), 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotReportBug()), TQT_TQOBJECT(ac), "help_reportbug"); //needed, because quanta_be bugs should be reported for quanta

    //Kate actions

//Edit menu
    KStdAction::undo(TQT_TQOBJECT(m_quanta), TQT_SLOT(slotUndo()), ac);
    KStdAction::redo(TQT_TQOBJECT(m_quanta), TQT_SLOT(slotRedo()), ac);
    KStdAction::cut(TQT_TQOBJECT(m_quanta), TQT_SLOT(slotCut()), ac);
    KStdAction::copy(TQT_TQOBJECT(m_quanta), TQT_SLOT(slotCopy()), ac) ;
    KStdAction::pasteText(TQT_TQOBJECT(m_quanta), TQT_SLOT(slotPaste()), ac);

//help
   (void) new TDEAction(i18n("Ti&p of the Day"), "idea", "", TQT_TQOBJECT(m_quanta),
      TQT_SLOT(slotHelpTip()), TQT_TQOBJECT(ac), "help_tip");

    // File actions
    //
    KStdAction::openNew( TQT_TQOBJECT(m_quanta), TQT_SLOT( slotFileNew()  ), ac);
    KStdAction::open   ( TQT_TQOBJECT(m_quanta), TQT_SLOT( slotFileOpen() ), ac, "file_open");
    (void) new TDEAction(i18n("Close Other Tabs"), 0, ViewManager::ref(), TQT_SLOT(slotCloseOtherTabs()), TQT_TQOBJECT(ac), "close_other_tabs");

    m_quanta->fileRecent =  KStdAction::openRecent(TQT_TQOBJECT(m_quanta), TQT_SLOT(slotFileOpenRecent(const KURL&)),
                                         ac, "file_open_recent");
    m_quanta->fileRecent->setToolTip(i18n("Open / Open Recent"));
    connect(m_quanta->fileRecent, TQT_SIGNAL(activated()), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotFileOpen()));

    (void) new TDEAction( i18n( "Close All" ), 0, TQT_TQOBJECT(m_quanta),
                        TQT_SLOT( slotFileCloseAll() ),
                        TQT_TQOBJECT(ac), "file_close_all" );

    m_quanta->saveAction = KStdAction::save(TQT_TQOBJECT(m_quanta), TQT_SLOT( slotFileSave() ), ac);

    KStdAction::saveAs( TQT_TQOBJECT(m_quanta), TQT_SLOT( slotFileSaveAs() ), ac );

    m_quanta->saveAllAction = new TDEAction( i18n( "Save All..." ), "save_all", SHIFT+TDEStdAccel::shortcut(TDEStdAccel::Save).keyCodeQt(),
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotFileSaveAll() ),
                        TQT_TQOBJECT(ac), "file_save_all" );
    (void)  new TDEAction(i18n("Reloa&d"), "revert", SHIFT+Key_F5, TQT_TQOBJECT(m_quanta),
                        TQT_SLOT(slotFileReload()), TQT_TQOBJECT(ac), "file_reload");
//    (void)  new TDEAction(i18n("Reload All "), 0, 0, m_quanta,
//                        TQT_SLOT(slotFileReloadAll()), TQT_TQOBJECT(ac), "file_reload_all");

    (void) new TDEAction( i18n( "Save as Local Template..." ), 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotFileSaveAsLocalTemplate() ),
                        TQT_TQOBJECT(ac), "save_local_template" );

    (void) new TDEAction( i18n( "Save Selection to Local Template File..." ), 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotFileSaveSelectionAsLocalTemplate() ),
                        TQT_TQOBJECT(ac), "save_selection_local_template" );

    KStdAction::quit( TQT_TQOBJECT(m_quanta), TQT_SLOT( slotFileQuit() ), ac );

    // Edit actions

    (void) new TDEAction( i18n( "Find in Files..." ),
                        SmallIcon("filefind"), CTRL+ALT+Key_F,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotEditFindInFiles() ),
                        TQT_TQOBJECT(ac), "find_in_files" );

    TDEAction* aux = TagActionManager::self()->actionCollection()->action("apply_source_indentation");
    aux->setEnabled(false);
    ac->insert(aux);

    // Tool actions

    (void) new TDEAction( i18n( "&Context Help..." ), CTRL+Key_H,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotContextHelp() ),
                        TQT_TQOBJECT(ac), "context_help" );

    (void) new TDEAction( i18n( "Tag &Attributes..." ), ALT+Key_Down,
                        m_quanta->m_doc, TQT_SLOT( slotAttribPopup() ),
                        TQT_TQOBJECT(ac), "tag_attributes" );

    (void) new TDEAction( i18n( "&Change the DTD..." ), 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotChangeDTD() ),
                        TQT_TQOBJECT(ac), "change_dtd" );

    (void) new TDEAction( i18n( "&Edit DTD Settings..." ), 0,
    TQT_TQOBJECT(m_quanta), TQT_SLOT( slotEditDTD() ),
    TQT_TQOBJECT(ac), "edit_dtd" );

    (void) new TDEAction( i18n( "&Load && Convert DTD..." ), 0,
                        DTDs::ref(), TQT_SLOT( slotLoadDTD() ),
                        TQT_TQOBJECT(ac), "load_dtd" );
    (void) new TDEAction( i18n( "Load DTD E&ntities..." ), 0,
                        DTDs::ref(), TQT_SLOT( slotLoadEntities() ),
                        TQT_TQOBJECT(ac), "load_entities" );

    (void) new TDEAction( i18n( "Load DTD &Package (DTEP)..." ), 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotLoadDTEP() ),
                        TQT_TQOBJECT(ac), "load_dtep" );

    (void) new TDEAction( i18n( "Send DTD Package (DTEP) in E&mail..." ), "mail_send", 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotEmailDTEP() ),
                        TQT_TQOBJECT(ac), "send_dtep" );

    (void) new TDEAction( i18n( "&Download DTD Package (DTEP)..." ), "network", 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotDownloadDTEP() ),
                        TQT_TQOBJECT(ac), "download_dtep" );
    (void) new TDEAction( i18n( "&Upload DTD Package (DTEP)..." ), "network", 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotUploadDTEP() ),
                        TQT_TQOBJECT(ac), "upload_dtep" );
/*
    (void) new TDEAction( i18n( "&Upload DTD Package (DTEP)..." ), 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotUploadDTEP() ),
                        TQT_TQOBJECT(ac), "send_dtep" );
*/
    (void) new TDEAction( i18n( "&Document Properties" ), 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotDocumentProperties() ),
                        TQT_TQOBJECT(ac), "tools_document_properties" );

    (void) new TDEAction ( i18n ("F&ormat XML Code"), 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotCodeFormatting() ),
                        TQT_TQOBJECT(ac), "tools_code_formatting");

    (void) new TDEAction( i18n( "&Convert Tag && Attribute Case..."), 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT(slotConvertCase()),
                        TQT_TQOBJECT(ac), "tools_change_case");

    // View actions


    m_quanta->showSourceAction =
      new TDEToggleAction( i18n( "&Source Editor"), UserIcon ("view_text"), ALT+Key_F9,
                         TQT_TQOBJECT(m_quanta), TQT_SLOT( slotShowSourceEditor()),
                         TQT_TQOBJECT(ac), "show_quanta_editor");
    m_quanta->showSourceAction->setExclusiveGroup("view");

    m_quanta->showVPLAction =
      new TDEToggleAction( i18n( "&VPL Editor"), UserIcon ("vpl"), CTRL+SHIFT+Key_F9,
      TQT_TQOBJECT(m_quanta), TQT_SLOT( slotShowVPLOnly() ),
                          TQT_TQOBJECT(ac), "show_kafka_view");
    m_quanta->showVPLAction->setExclusiveGroup("view");

    m_quanta->showVPLSourceAction =
      new TDEToggleAction( i18n("VPL && So&urce Editors"), UserIcon ("vpl_text"), Key_F9,
                         TQT_TQOBJECT(m_quanta), TQT_SLOT( slotShowVPLAndSourceEditor() ),
                          TQT_TQOBJECT(ac), "show_kafka_and_quanta");
    m_quanta->showVPLSourceAction->setExclusiveGroup("view");
    /**kafkaSelectAction = new TDESelectAction(i18n("Main &View"), 0, ac,"show_kafka");
    TQStringList list2;
    list2.append(i18n("&Source Editor"));
    list2.append(i18n("&VPL Editor (experimental)"));
    list2.append(i18n("&Both Editors"));
    kafkaSelectAction->setItems(list2);
    connect(kafkaSelectAction, TQT_SIGNAL(activated(int)), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotShowKafkaPartl(int)));*/


    (void) new TDEAction( i18n( "&Reload Preview" ), "reload",
                        TDEStdAccel::shortcut(TDEStdAccel::Reload).keyCodeQt(),
                        TQT_TQOBJECT(m_quanta), TQT_SLOT(slotRepaintPreview()),
                        TQT_TQOBJECT(ac), "reload" );

    (void) new TDEAction( i18n( "&Previous File" ), "1leftarrow", TDEStdAccel::back(),
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotBack() ),
                        TQT_TQOBJECT(ac), "previous_file" );

    (void) new TDEAction( i18n( "&Next File" ), "1rightarrow", TDEStdAccel::forward(),
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotForward() ),
                        TQT_TQOBJECT(ac), "next_file" );

    // Options actions
    //

    (void) new TDEAction( i18n( "Configure &Actions..." ), UserIcon("ball"),0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotOptionsConfigureActions() ),
                        TQT_TQOBJECT(ac), "configure_actions" );

    KStdAction::showMenubar(TQT_TQOBJECT(m_quanta), TQT_SLOT(slotShowMenuBar()), ac, "options_show_menubar");
    KStdAction::keyBindings(TQT_TQOBJECT(m_quanta), TQT_SLOT( slotOptionsConfigureKeys() ), ac, "configure_shortcuts");
    KStdAction::configureToolbars(TQT_TQOBJECT(m_quanta), TQT_SLOT( slotOptionsConfigureToolbars() ), ac, "options_configure_toolbars");
    KStdAction::preferences(TQT_TQOBJECT(m_quanta), TQT_SLOT( slotOptions() ), ac, "general_options");
    new TDEAction(i18n("Configure Pre&view..."), SmallIcon("konqueror"), 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotPreviewOptions()), TQT_TQOBJECT(ac), "preview_options");

    // Toolbars actions
    m_quanta->projectToolbarFiles = new TDERecentFilesAction(i18n("Load &Project Toolbar"),0,
                                                           TQT_TQOBJECT(m_quanta), TQT_SLOT(slotLoadToolbarFile(const KURL&)),
                                                           TQT_TQOBJECT(ac), "toolbars_load_project");

    new TDEAction(i18n("Load &Global Toolbar..."), 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotLoadGlobalToolbar()), TQT_TQOBJECT(ac), "toolbars_load_global");
    new TDEAction(i18n("Load &Local Toolbar..."), 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotLoadToolbar()), TQT_TQOBJECT(ac), "toolbars_load_user");
    new TDEAction(i18n("Save as &Local Toolbar..."), 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotSaveLocalToolbar()), TQT_TQOBJECT(ac), "toolbars_save_local");
    new TDEAction(i18n("Save as &Project Toolbar..."), 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotSaveProjectToolbar()), TQT_TQOBJECT(ac), "toolbars_save_project");
    new TDEAction(i18n("&New User Toolbar..."),  0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotAddToolbar()), TQT_TQOBJECT(ac), "toolbars_add");
    new TDEAction(i18n("&Remove User Toolbar..."), 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotRemoveToolbar()), TQT_TQOBJECT(ac), "toolbars_remove");
    new TDEAction(i18n("Re&name User Toolbar..."), 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotRenameToolbar()), TQT_TQOBJECT(ac), "toolbars_rename");
    new TDEAction(i18n("Send Toolbar in E&mail..."), "mail_send", 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotSendToolbar()), TQT_TQOBJECT(ac), "toolbars_send");
    new TDEAction(i18n("&Upload Toolbar..." ), "network", 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotUploadToolbar()), TQT_TQOBJECT(ac), "toolbars_upload" );
    new TDEAction(i18n("&Download Toolbar..." ), "network", 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotDownloadToolbar()), TQT_TQOBJECT(ac), "toolbars_download" );

    TDEToggleAction *toggle = new TDEToggleAction( i18n("Smart Tag Insertion"), 0, TQT_TQOBJECT(ac), "smart_tag_insertion");
    connect(toggle, TQT_SIGNAL(toggled(bool)), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotSmartTagInsertion()));

    m_quanta->showDTDToolbar=new TDEToggleAction(i18n("Show DTD Toolbar"), 0, TQT_TQOBJECT(ac), "view_dtd_toolbar");

    connect(m_quanta->showDTDToolbar, TQT_SIGNAL(toggled(bool)), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotToggleDTDToolbar(bool)));
    m_quanta->showDTDToolbar->setCheckedState(i18n("Hide DTD Toolbar"));

    new TDEAction(i18n("Complete Text"), CTRL+Key_Space,
                TQT_TQOBJECT(m_quanta), TQT_SLOT(slotShowCompletion()), ac,"show_completion");
    new TDEAction(i18n("Completion Hints"), CTRL+SHIFT+Key_Space,
                TQT_TQOBJECT(m_quanta), TQT_SLOT(slotShowCompletionHint()), ac,"show_completion_hint");

    KStdAction::back(TQT_TQOBJECT(m_quanta), TQT_SLOT( slotBack() ), ac, "w_back");
    KStdAction::forward(TQT_TQOBJECT(m_quanta), TQT_SLOT( slotForward() ), ac, "w_forward");

    new TDEAction(i18n("Open File: none"), 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotOpenFileUnderCursor()), TQT_TQOBJECT(ac), "open_file_under_cursor");
    new TDEAction(i18n("Upload..."), 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotUploadFile()), TQT_TQOBJECT(ac), "upload_file");
    new TDEAction(i18n("Delete File"), 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotDeleteFile()), TQT_TQOBJECT(ac), "delete_file");

    TQString ss = i18n("Upload Opened Project Files...");
/*    new TDEAction(i18n("Upload Opened Project Files"), 0, TQT_TQOBJECT(m_quanta), TQT_SLOT(slotUploadOpenedFiles()), TQT_TQOBJECT(ac), "upload_opened_files"); */

    TQString error;
    int el, ec;
    m_quanta->m_actions = new TQDomDocument();
//load the global actions
    TQFile f(qConfig.globalDataDir + resourceDir + "actions.rc");
    if ( f.open( IO_ReadOnly ))
    {
      if (m_quanta->m_actions->setContent(&f, &error, &el, &ec))
      {
        TQDomElement docElem = m_quanta->m_actions->documentElement();

        TQDomNode n = docElem.firstChild();
        while( !n.isNull() ) {
          TQDomElement e = n.toElement(); // try to convert the node to an element.
          if( !e.isNull() ) { // the node was really an element.
              bool toggable = (e.attribute("toggable", "") == "true");
              new TagAction(&e, m_quanta, toggable);
          }
          n = n.nextSibling();
        }
      } else
        kdError(24000) << TQString("Error %1 at (%2, %3) in %4").arg(error).arg(el).arg(ec).arg(f.name()) << endl;
      f.close();
    }
    m_quanta->m_actions->clear();
//read the user defined actions
    TQString s = locateLocal("appdata","actions.rc");
    if (!s.isEmpty())
    {
      f.setName(s);
      if ( f.open( IO_ReadOnly ))
      {
        if (m_quanta->m_actions->setContent(&f, &error, &el, &ec))
        {
          TQDomElement docElem = m_quanta->m_actions->documentElement();

          TQDomNode n = docElem.firstChild();
          while( !n.isNull() ) {
            TQDomElement e = n.toElement(); // try to convert the node to an element.
            if( !e.isNull())
            { // the node was really an element.
                delete ac->action(e.attribute("name").ascii());
                bool toggable = (e.attribute("toggable", "") == "true");
                new TagAction(&e, m_quanta, toggable);
            }
            n = n.nextSibling();
          }
        } else
        kdError(24000) << TQString("Error %1 at (%2, %3) in %4").arg(error).arg(el).arg(ec).arg(f.name()) << endl;
        f.close();
      }
    } else
    {
      m_quanta->m_actions->setContent(s);
    }

    // create the preview action
    m_quanta->showPreviewAction =
      new TDEToolBarPopupAction( i18n( "&Preview" ), "preview", Key_F6,
                         TQT_TQOBJECT(m_quanta), TQT_SLOT( slotToggleShowPreview() ),
                         TQT_TQOBJECT(ac), "show_preview" );

    TDEAction *act = new TDEAction( i18n( "Preview Without Frames" ), "", 0,
                                  TQT_TQOBJECT(m_quanta), TQT_SLOT(slotShowNoFramesPreview()),
                                  TQT_TQOBJECT(ac), "show_preview_no_frames" );
    act->plug(m_quanta->showPreviewAction->popupMenu());

    act = new TDEAction( i18n( "View with &Konqueror" ), "konqueror", Key_F12,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotViewInKFM() ),
                        TQT_TQOBJECT(ac), "view_with_konqueror" );
    act->plug(m_quanta->showPreviewAction->popupMenu());


    act = ac->action("view_with_firefox");
    if (act)
      act->plug(m_quanta->showPreviewAction->popupMenu());

    act = ac->action("view_with_mozilla");
    if (act)
      act->plug(m_quanta->showPreviewAction->popupMenu());

    act = ac->action("view_with_netscape");
    if (act)
      act->plug(m_quanta->showPreviewAction->popupMenu());

    act = ac->action("view_with_opera");
    if (act)
      act->plug(m_quanta->showPreviewAction->popupMenu());

    act = new TDEAction( i18n( "View with L&ynx" ), "terminal", 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotViewInLynx() ),
                        TQT_TQOBJECT(ac), "view_with_lynx" );
    act->plug(m_quanta->showPreviewAction->popupMenu());


    (void) new TDEAction( i18n( "Table Editor..." ), "quick_table", 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotTagEditTable() ),
                        TQT_TQOBJECT(ac), "tag_edit_table" );

    (void) new TDEAction( i18n( "Quick List..." ), "quick_list", 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotTagQuickList() ),
                        TQT_TQOBJECT(ac), "tag_quick_list" );

    (void) new TDEAction( i18n( "Color..." ), "colorize", CTRL+SHIFT+Key_C,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotTagColor() ),
                        TQT_TQOBJECT(ac), "tag_color" );


    (void) new TDEAction( i18n( "Email..." ), "tag_mail", 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotTagMail() ),
                        TQT_TQOBJECT(ac), "tag_mail" );

    (void) new TDEAction( i18n( "Misc. Tag..." ), "tag_misc", CTRL+SHIFT+Key_T,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotTagMisc() ),
                        TQT_TQOBJECT(ac), "tag_misc" );

    (void) new TDEAction( i18n( "Frame Wizard..." ), "frame", 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotFrameWizard() ),
                        TQT_TQOBJECT(ac), "tag_frame_wizard" );

    (void) new TDEAction( i18n( "Paste &HTML Quoted" ), "editpaste", 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotPasteHTMLQuoted() ),
                        TQT_TQOBJECT(ac), "edit_paste_html_quoted" );

    (void) new TDEAction( i18n( "Paste &URL Encoded" ), "editpaste", 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotPasteURLEncoded() ),
                        TQT_TQOBJECT(ac), "edit_paste_url_encoded" );

    (void) new TDEAction( i18n( "Insert CSS..." ),"css", 0,
                        TQT_TQOBJECT(m_quanta), TQT_SLOT( slotInsertCSS() ),
                        TQT_TQOBJECT(ac), "insert_css" );

    // special-character combo
    TDEAction* char_action = new TDEAction(
                        i18n( "Insert Special Character" ), "charset", 0,
                        TQT_TQOBJECT(ac), "insert_char" );
    connect( char_action, TQT_SIGNAL(activated()),
             TQT_TQOBJECT(m_quanta), TQT_SLOT(slotInsertChar()) );

    connect(m_quanta, TQT_SIGNAL(eventHappened(const TQString&, const TQString&, const TQString& )), QPEvents::ref(TQT_TQOBJECT(m_quanta)), TQT_SLOT(slotEventHappened(const TQString&, const TQString&, const TQString& )));
    connect(m_quanta->doc(), TQT_SIGNAL(eventHappened(const TQString&, const TQString&, const TQString& )), QPEvents::ref(TQT_TQOBJECT(m_quanta)), TQT_SLOT(slotEventHappened(const TQString&, const TQString&, const TQString& )));
    connect(ViewManager::ref(), TQT_SIGNAL(eventHappened(const TQString&, const TQString&, const TQString& )), QPEvents::ref(TQT_TQOBJECT(m_quanta)), TQT_SLOT(slotEventHappened(const TQString&, const TQString&, const TQString& )));

    QuantaBookmarks *m_bookmarks = new QuantaBookmarks(ViewManager::ref(TQT_TQOBJECT(m_quanta)));
    m_bookmarks->createActions(ac);
    connect(m_bookmarks, TQT_SIGNAL(gotoFileAndLine(const TQString&, int, int)), TQT_TQOBJECT(m_quanta), TQT_SLOT(gotoFileAndLine(const TQString&, int, int)));
}

/** Initialize the plugin architecture. */
void QuantaInit::initPlugins()
{
  // TODO : read option from plugins.rc to see if we should validate the plugins

  m_quanta->m_pluginInterface = QuantaPluginInterface::ref(m_quanta);

  connect(m_quanta->m_pluginInterface, TQT_SIGNAL(hideSplash()),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotHideSplash()));
  connect(m_quanta->m_pluginInterface, TQT_SIGNAL(statusMsg(const TQString &)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotStatusMsg(const TQString & )));

  m_quanta->m_pluginInterface->readConfig();
  if (!m_quanta->m_pluginInterface->pluginAvailable("KFileReplace"))
  {
    delete m_quanta->actionCollection()->action("find_in_files");
  }
}


void QuantaInit::recoverCrashed(TQStringList& recoveredFileNameList)
{
  m_quanta->m_doc->blockSignals(true);

  execCommandPS("ps -C quanta -C quanta_be -o pid --no-headers");
  m_PIDlist = TQStringList::split("\n", m_quanta->m_scriptOutput);

  m_config->setGroup("Projects");
  TQString pu = QuantaCommon::readPathEntry(m_config, "Last Project");

  KURL u;
  QuantaCommon::setUrl(u, pu);
  bool isPrj = true;
  if (pu.isEmpty())
     isPrj = false;
  if (!u.isValid())
     isPrj = false;

  m_config->reparseConfiguration();
  m_config->setGroup("General Options");

  TQStringList backedUpUrlsList = QuantaCommon::readPathListEntry(m_config, "List of backedup files");
  TQStringList autosavedUrlsList = QuantaCommon::readPathListEntry(m_config, "List of autosaved files");

  TQStringList::ConstIterator backedUpUrlsEndIt = backedUpUrlsList.constEnd();
  for (TQStringList::ConstIterator backedUpUrlsIt = backedUpUrlsList.constBegin();
       backedUpUrlsIt != backedUpUrlsEndIt; ++backedUpUrlsIt )
  {
    // when quanta crashes and file autoreloading option is on
    // then if user restarts quanta, the backup copies will reload
    TQString backedUpFileName = (*backedUpUrlsIt).left((*backedUpUrlsIt).findRev(".")); //the filename without the PID
    bool notFound;
    TQString autosavedPath = searchPathListEntry(backedUpFileName, autosavedUrlsList, notFound);
    if (!autosavedPath.isEmpty()) //the current item was autosaved and is not in use by another Quanta
    {
      KURL originalVersion;
      KURL autosavedVersion;
      QuantaCommon::setUrl(originalVersion, backedUpFileName);
      QuantaCommon::setUrl(autosavedVersion, autosavedPath);
      bool isUntitledDocument = false;
      if (autosavedVersion.path().right(1) == "U")
        isUntitledDocument = true;
      if (!isPrj || originalVersion.isLocalFile())
      {
        //find some information about local files
        TDEIO::UDSEntry entry;
        TDEIO::NetAccess::stat(originalVersion, entry, m_quanta);
        KFileItem* item= new KFileItem(entry, originalVersion, false, true);
        TQString origTime = item->timeString();
        TDEIO::filesize_t origSize = item->size();
        delete item;
        TDEIO::NetAccess::stat(autosavedVersion, entry, m_quanta);
        item= new KFileItem(entry, autosavedVersion, false, true);
        TQString backupTime = item->timeString();
        TDEIO::filesize_t backupSize = item->size();
        delete item;

        if (TQFileInfo(autosavedPath).exists()) //if the backup file exists
        {
          emit hideSplash();
          DirtyDlg *dlg = new DirtyDlg(autosavedVersion.path(), originalVersion.path(), false, m_quanta);
          dlg->setCaption(i18n("Restore File"));
          DirtyDialog *w = static_cast<DirtyDialog*>(dlg->mainWidget());
          w->textLabel->setText(i18n("<qt>A backup copy of a file was found:<br><br>"
            "Original file: <b>%1</b><br>"
            "Original file size: <b>%2</b><br>"
            "Original file last modified on: <b>%3</b><br><br>"
            "Backup file size: <b>%4</b><br>"
            "Backup created on: <b>%5</b><br><br>"
            "</qt>")
            .arg(originalVersion.prettyURL(0, KURL::StripFileProtocol ))
            .arg(TDEIO::convertSize(origSize)).arg(origTime)
            .arg(TDEIO::convertSize(backupSize)).arg(backupTime));
          w->buttonLoad->setText(i18n("&Restore the file from backup"));
          w->buttonIgnore->setText(i18n("Do &not restore the file from backup"));
          delete w->warningLabel;
          w->warningLabel = 0L;
          w->setMinimumHeight(320);
          dlg->adjustSize();
          if (TDEStandardDirs::findExe("kompare").isEmpty() || isUntitledDocument)
          {
            w->buttonCompare->setEnabled(false);
            w->buttonLoad->setChecked(true);
          }
          if (dlg->exec())
          {
            //backup the current version and restore it from the autosaved backup
            KURL backupURL = originalVersion;
            backupURL.setPath(backupURL.path() + "." + TQString::number(getpid(),10) + ".backup");
            QExtFileInfo::copy(originalVersion, backupURL, -1, true, false, m_quanta);
            QExtFileInfo::copy(autosavedVersion, originalVersion, -1, true, false, m_quanta);
            //we save a list of autosaved file names so "KQApplicationPrivate::init()"
            //can open them. If autosavedVersion.path().right(1) == "U" then we are recovering
            //an untitled document
            if(isUntitledDocument)
              m_quanta->slotFileOpen(autosavedVersion,
                                    m_quanta->defaultEncoding());  // load initial files
            else
              recoveredFileNameList += backedUpFileName;
          }
          delete dlg;
          TQFile::remove(autosavedPath); //we don't need the backup anymore
       }
      }
      //remove the auto-backup file from the list
      m_config->setGroup("General Options");
      TQStringList autosavedFilesEntryList = QuantaCommon::readPathListEntry(m_config, "List of autosaved files");
      TQStringList::Iterator entryIt = autosavedFilesEntryList.begin();
      while(entryIt != autosavedFilesEntryList.end())
      {
        if ((*entryIt) == KURL::fromPathOrURL(autosavedPath).url())
          entryIt = autosavedFilesEntryList.remove(entryIt);
        else
          ++entryIt;
      }
      m_config->writePathEntry("List of autosaved files", autosavedFilesEntryList);

      autosavedUrlsList = autosavedFilesEntryList;
    }

    if (notFound)
    {
      //remove processed items
      m_config->setGroup("General Options");

      TQStringList backedupFilesEntryList = QuantaCommon::readPathListEntry(m_config, "List of backedup files");
      TQStringList::Iterator entryIt = backedupFilesEntryList.begin();
      while (entryIt != backedupFilesEntryList.end())
      {
        if ((*entryIt) == (*backedUpUrlsIt))
          entryIt = backedupFilesEntryList.remove(entryIt);
        else
          ++entryIt;
      }
      m_config->writePathEntry("List of backedup files", backedupFilesEntryList);
    }
  }

  //clean up auto-backup list, just in case of an old Quanta was used before
  TQStringList::Iterator entryIt = autosavedUrlsList.begin();
  while (entryIt != autosavedUrlsList.end())
  {
    TQString quPID = retrievePID((*entryIt));

    //check if the file is opened by another running Quanta or not
    bool isOrphan = true;
    TQStringList::ConstIterator PIDEndIt = m_PIDlist.constEnd();
    for (TQStringList::ConstIterator PIDIt = m_PIDlist.constBegin(); PIDIt != PIDEndIt; ++PIDIt )
    {
      if ((*PIDIt) == quPID && qConfig.quantaPID != quPID)
      {
        isOrphan = false; //the file is opened
        break;
      }
    }
    if (isOrphan)
      entryIt = autosavedUrlsList.remove(entryIt);
    else
      ++entryIt;
  }
  m_config->writePathEntry("List of autosaved files", autosavedUrlsList);



}

 void QuantaInit::execCommandPS(const TQString& cmd)
 {

  //We create a TDEProcess that executes the "ps" *nix command to get the PIDs of the
  //other instances of quanta actually running
  TDEProcess *execCommand = new TDEProcess();
  *(execCommand) << TQStringList::split(" ",cmd);

  connect(execCommand, TQT_SIGNAL(receivedStdout(TDEProcess*,char*,int)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotGetScriptOutput(TDEProcess*,char*,int)));
  connect(execCommand, TQT_SIGNAL(receivedStderr(TDEProcess*,char*,int)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotGetScriptError(TDEProcess*,char*,int)));
  connect(execCommand, TQT_SIGNAL(processExited(TDEProcess*)),
          TQT_TQOBJECT(m_quanta), TQT_SLOT(slotProcessExited(TDEProcess*)));

  if (!execCommand->start(TDEProcess::NotifyOnExit,TDEProcess::All))
  {
    KMessageBox::error(m_quanta, i18n("Failed to query for running Quanta instances."));
  }
  else
  {
    //To avoid lock-ups, start a timer.
    TQTimer *timer = new TQTimer(m_quanta);
    connect(timer, TQT_SIGNAL(timeout()),
            TQT_TQOBJECT(m_quanta), TQT_SLOT(slotProcessTimeout()));
    timer->start(180*1000, true);
    QExtFileInfo internalFileInfo;
    m_quanta->m_loopStarted = true;
    internalFileInfo.enter_loop();
    delete timer;
  }
 }


 TQString QuantaInit::searchPathListEntry(const TQString& url, const TQStringList& autosavedUrlsList, bool &notFound)
{
  TQString backedUpUrlHashedPath = retrieveHashedPath('.' + Document::hashFilePath(url));
  notFound = true;
  TQStringList::ConstIterator autosavedUrlsEndIt = autosavedUrlsList.constEnd();
  for (TQStringList::ConstIterator autosavedUrlsIt = autosavedUrlsList.constBegin();
       autosavedUrlsIt != autosavedUrlsEndIt;
       ++autosavedUrlsIt)
  {
    TQString quPID = retrievePID((*autosavedUrlsIt));

    //check if the file is opened by another running Quanta or not
    bool isOrphan = true;
    TQStringList::ConstIterator PIDEndIt = m_PIDlist.constEnd();
    for (TQStringList::ConstIterator PIDIt = m_PIDlist.constBegin(); PIDIt != PIDEndIt; ++PIDIt )
    {
      if ((*PIDIt) == quPID && qConfig.quantaPID != quPID)
      {
        isOrphan = false; //the file is opened
        break;
      }
    }

    if (backedUpUrlHashedPath ==  retrieveHashedPath((*autosavedUrlsIt)))
    {
      notFound = false;
      if (isOrphan)
        return KURL::fromPathOrURL(*autosavedUrlsIt).path(); //the url was autosaved to this file
    }

  }
  return TQString();
}

/** Retrieves hashed path from the name of a backup file */
TQString QuantaInit::retrieveHashedPath(const TQString& filename)
{
  int lastPoint = filename.findRev(".");
  int Ppos = filename.find("P", lastPoint);
  return filename.mid(lastPoint + 1,
                      Ppos - lastPoint);
}


/** Retrieves PID from the name of a backup file */
TQString QuantaInit::retrievePID(const TQString& filename)
{
 TQString strPID = TQString();
 strPID = filename.mid(filename.findRev("P") + 1);

 if (strPID.isEmpty())
  strPID = filename.mid(filename.findRev("N") + 1);

 if (strPID.endsWith("U"))
   strPID = strPID.left(strPID.length() - 1);

 return strPID;
}


void QuantaInit::loadVPLConfig()
{
  //load the VPL options
  m_config->setGroup("Kafka Synchronization options");
  qConfig.quantaRefreshOnFocus = (m_config->readEntry("Source refresh", "delay") == "focus");
  qConfig.quantaRefreshDelay = m_config->readNumEntry("Source refresh delay", 500);
  qConfig.kafkaRefreshOnFocus = (m_config->readEntry("Kafka refresh", "focus") == "focus");
  qConfig.kafkaRefreshDelay = m_config->readNumEntry("Kafka refresh delay", 4000);
  /**reloadUpdateTimers();*/

  m_config->setGroup("Kafka Indentation options");
  qConfig.inlineNodeIndentation = m_config->readBoolEntry("Inline Node Indentation");
}

struct Dependency{
  TQString name;
  TQString execName;
  TQString url;
  TQString description;
  enum Type{
    Executable = 0,
    Plugin
  };
  Type type;
};

void QuantaInit::checkRuntimeDependencies()
{

  TQValueList<Dependency> dependencies;
  Dependency dependency;
  dependency.name = "Kommander";
  dependency.execName = "kmdr-executor";
  dependency.url = "http://kommander.tdewebdev.org";
  dependency.description = i18n("various script based dialogs including the Quick Start dialog");
  dependency.type = Dependency::Executable;
  dependencies.append(dependency);

  dependency.name = "Tidy";
  dependency.execName = "tidy";
  dependency.url = "http://tidy.sourceforge.net";
  dependency.description = i18n("HTML syntax checking");
  dependency.type = Dependency::Executable;
  dependencies.append(dependency);

  dependency.name = "Kompare";
  dependency.execName = "kompare";
  dependency.url = "http://bruggie.dnsalias.org/kompare";
  dependency.description = i18n("comparing of files by content");
  dependency.type = Dependency::Executable;
  dependencies.append(dependency);


  dependency.name = i18n("Control Center (tdebase)");
  dependency.execName = "tdecmshell";
  dependency.url = "http://www.kde.org";
  dependency.description = i18n("preview browser configuration");
  dependency.type = Dependency::Executable;
  dependencies.append(dependency);

  dependency.name = "GPG (OpenPGP)";
  dependency.execName = "gpg";
  dependency.url = "http://www.gnupg.de";
  dependency.description = i18n("preview browser configuration");
  dependency.type = Dependency::Executable;
  dependencies.append(dependency);

  dependency.name = "KFileReplace";
  dependency.execName = "KFileReplace";
  dependency.url = "http://tdefilereplace.tdewebdev.org";
  dependency.description = i18n("search and replace in files");
  dependency.type = Dependency::Plugin;
  dependencies.append(dependency);

  dependency.name = "KXSLDbg";
  dependency.execName = "XSLT Debugger";
  dependency.url = "http://xsldbg.sourceforge.net/";
  dependency.description = i18n("XSLT debugging");
  dependency.type = Dependency::Plugin;
  dependencies.append(dependency);


  dependency.name = "KImageMapEditor";
  dependency.execName = "KImageMapEditor";
  dependency.url = "http://www.nongnu.org/kimagemap/";
  dependency.description = i18n("editing HTML image maps");
  dependency.type = Dependency::Plugin;
  dependencies.append(dependency);


  dependency.name = "KLinkStatus";
  dependency.execName = "Link Checker";
  dependency.url = "http://kde-apps.org/content/show.php?content=12318";
  dependency.description = i18n("link validity checking");
  dependency.type = Dependency::Plugin;
  dependencies.append(dependency);

  dependency.name = "Cervisia";
  dependency.execName = "CVS Management (Cervisia)";
  dependency.url = "http://www.kde.org/apps/cervisia";
  dependency.description = i18n("CVS management plugin");
  dependency.type = Dependency::Plugin;
  dependencies.append(dependency);

  TQString errorStr;
  TQString stdErrorMsg = i18n("<br><b>-    %1</b> [<i>%2</i>] - %3 will not be available;");
  for (TQValueList<Dependency>::ConstIterator it = dependencies.constBegin(); it != dependencies.constEnd(); ++it)
  {
    dependency = *it;
    if (dependency.type == Dependency::Executable)
    {
      if (TDEStandardDirs::findExe(dependency.execName).isNull())
        errorStr += TQString(stdErrorMsg).arg(dependency.name).arg(dependency.url).arg(dependency.description);

    } else
    if (dependency.type == Dependency::Plugin)
    {
      if (!QuantaPlugin::validatePlugin(m_quanta->m_pluginInterface->plugin(dependency.execName)))
        errorStr += TQString(stdErrorMsg).arg(dependency.name).arg(dependency.url).arg(dependency.description);
    }
  }

#ifdef ENABLE_CVSSERVICE
  TQString error;
  TQCString appId;

  TDEApplication::startServiceByDesktopName("cvsservice", TQStringList(), &error,
                                            &appId);
  if (appId.isEmpty())
  {
     errorStr += TQString(stdErrorMsg).arg("Cervisia (cvsservice)").arg("http://www.kde.org/apps/cervisia").arg(i18n("integrated CVS management"));
  } else
  {
     CVSService::ref(m_quanta->actionCollection())->setAppId(appId);
     connect(CVSService::ref(), TQT_SIGNAL(clearMessages()), m_quanta->m_messageOutput, TQT_SLOT(clear()));
     connect(CVSService::ref(), TQT_SIGNAL(showMessage(const TQString&, bool)), m_quanta->m_messageOutput, TQT_SLOT(showMessage(const TQString&, bool)));
     connect(CVSService::ref(), TQT_SIGNAL(commandExecuted(const TQString&, const TQStringList&)), TQT_TQOBJECT(m_quanta), TQT_SLOT(slotCVSCommandExecuted(const TQString&, const TQStringList&)));
     //connect(CVSService::ref(), TQT_SIGNAL(statusMsg(const TQString &)),  TQT_TQOBJECT(m_quanta), TQT_SLOT(slotStatusMsg(const TQString & )));
     m_quanta->fTab->plugCVSMenu();
     pTab->plugCVSMenu();
  }
#endif

  if (!errorStr.isEmpty())
  {
      m_quanta->slotHideSplash();
      errorStr[errorStr.length() - 1] = '.';
      KMessageBox::information(m_quanta, "<qt>" + i18n("Some applications required for full functionality are missing:<br>") + errorStr + i18n("<br><br>You may download the applications from the specified locations.</qt>"), i18n("Missing Applications"), "RuntimeDependencyCheck");
  }
}

void QuantaInit::readAbbreviations()
{
  TQDomDocument doc;
  TQString groupName;
  bool mainAbbrevFileFound = false;
  TQStringList mainFileList;
  mainFileList << qConfig.globalDataDir + resourceDir + "abbreviations.xml";
  mainFileList << TDEGlobal::dirs()->saveLocation("data") + resourceDir + "abbreviations.xml";
  for (uint i = 0; i < mainFileList.count(); i++)
  {
     if (!TQFile::exists(mainFileList[i]))
       continue;
     TQFile file(mainFileList[i]);
     if (file.open(IO_ReadOnly))
     {
        if (doc.setContent(&file))
        {
          TQDomNodeList groupList = doc.elementsByTagName("Group");
          for (uint groupIdx = 0; groupIdx < groupList.count(); groupIdx++)
          {
             Abbreviation abbrev;
             TQDomElement el = groupList.item(groupIdx).toElement();
             groupName = el.attribute("name");
             TQDomNodeList dtepList = el.elementsByTagName("DTEP");
             for (uint dtepListIdx = 0; dtepListIdx < dtepList.count(); dtepListIdx++)
             {
               abbrev.dteps.append(dtepList.item(dtepListIdx).toElement().attribute("name"));
             }
             TQDomNodeList nodeList = el.elementsByTagName("Template");
             for (uint nodeIdx = 0; nodeIdx < nodeList.count(); nodeIdx++)
             {
               TQDomElement e = nodeList.item(nodeIdx).toElement();
               abbrev.abbreviations.insert(e.attribute("name")+" "+e.attribute("description"), e.attribute("code"));
             }
             qConfig.abbreviations.insert(groupName, abbrev);
          }
        }
        mainAbbrevFileFound = true;
        file.close();
     }
  }
  if (mainAbbrevFileFound) return;
//Compatibility code: read the abbreviations files from the DTEP directories
//TODO: Remove when upgrade from 3.2 is not supported.
 TQStringList filenameList = DTDs::ref()->fileNameList(false);
 TQStringList::Iterator it;
 for (it = filenameList.begin(); it != filenameList.end(); ++it)
 {
    int pos =(*it).find('|');
    TQString dirName = (*it).mid(pos + 1);
    TQString dtepName = (*it).left(pos);
    KURL dirURL(dirName);
    dirURL.setFileName("");
    dirName = dirURL.path(1);
    TQString abbrevFile = dirName;
    TQString tmpStr = dirName;
    TQStringList resourceDirs = TDEGlobal::dirs()->resourceDirs("data");
    bool dirFound = false;
    for (uint i = 0; i < resourceDirs.count(); i++)
    {
      if (tmpStr.startsWith(resourceDirs[i]))
      {
        dirFound = true;
        tmpStr = tmpStr.right(tmpStr.length() - resourceDirs[i].length());
        break;
      }
    }
    if (dirFound)
    {
      abbrevFile = TDEGlobal::dirs()->saveLocation("data", tmpStr) +"/";
    }
    abbrevFile.append("abbreviations");
    if (!TQFile::exists(abbrevFile))
        abbrevFile = dirName + "abbreviations";
    TQFile f(abbrevFile);
    if (f.open(IO_ReadOnly))
    {
      if (doc.setContent(&f))
      {
        Abbreviation abbrev;
        TQDomNodeList nodeList = doc.elementsByTagName("Template");
        for (uint i = 0; i < nodeList.count(); i++)
        {
          TQDomElement e = nodeList.item(i).toElement();
          abbrev.abbreviations.insert(e.attribute("name")+" "+e.attribute("description"), e.attribute("code"));
        }
        abbrev.dteps.append(dtepName);
        qConfig.abbreviations.insert(DTDs::ref()->getDTDNickNameFromName(dtepName), abbrev);
      }
      f.close();
    }
 }
}


int QuantaInit::runningQuantas()
{
  QCStringList list = kapp->dcopClient()->registeredApplications();
  int i = 0;
  for (QCStringList::iterator it = list.begin(); it != list.end(); ++it)
  {
    if (TQString(*it).startsWith("quanta", false))
      ++i;
  }
  return i;
}

#include "quanta_init.moc"