summaryrefslogtreecommitdiffstats
path: root/ksystemlog/src/ksystemlog.cpp
blob: a8cc0a31a6c60bed671a1560e3affe252051c3b1 (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
/***************************************************************************
 *   Copyright (C) 2005 by Nicolas Ternisien                               *
 *   [email protected]                                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/


//TQt includes
#include <tqdragobject.h>

#include <tqpixmap.h>
#include <tqpainter.h>
#include <tqpaintdevicemetrics.h>
#include <tqwhatsthis.h>
#include <tqtooltip.h>

#include <tqlistview.h>


//KDE includes
#include <kmessagebox.h>

#include <twin.h>
#include <kprinter.h>
#include <kglobal.h>
#include <klocale.h>

#include <kiconloader.h>

#include <kservice.h>

#include <kmenubar.h>
#include <kstatusbar.h>
#include <kkeydialog.h>

#include <kfiledialog.h>

#include <kaccel.h>

#include <kconfig.h>

//For compatibility with old versions of KDE
#include <tdeversion.h>

#include <dcopclient.h>

#include <kurl.h>
#include <kurldrag.h>
#include <kurlrequesterdlg.h>
#include <ktoolbarbutton.h>
#include <kedittoolbar.h>
#include <kdebug.h>
#include <kiconloader.h>

#include <kstdaccel.h>
#include <kaction.h>
#include <kstdaction.h>

//Project includes
#include "ksystemlog.h"

#include "ksystemlogConfig.h"

#include "options.h"

#include "loggerDialog.h"

#include "logListItem.h"
#include "logLevel.h"
#include "logFile.h"

#include "readerFactory.h"

KSystemLog::KSystemLog() :
	KMainWindow(0, "ksystemlog"),
	printer(NULL),
	detailDialog(NULL),
	loadingDialog(NULL),
	tabs(NULL)
	{

	//Accept Drag and Drop
	setAcceptDrops(true);
	
	//Initialize the Status Bar
	setupStatusBar();
		
	//Initialize the find manager
	findManager=new FindManager(this, "find_manager");

	//Setup existing log levels
	Globals::setupLogLevels();
	
	//Setup existing log modes
	Globals::setupLogModes();
	
	//Setup the Actions
	setupActions();

	//Create the GUI from XML configuration
	createGUI();

	//Setup the main tab bar
	setupTabBar();
		
	//TabBar widget becomes the central place of the KMainWindow
	setCentralWidget(tabs);

	//Setup the Progress Bar Dialog
	setupProgressDialog();
	
	//Apply the saved mainwindow settings, if any, and ask the mainwindow
	//to automatically save settings if changed: window size, toolbar
	//position, icon size, etc.
	setAutoSaveSettings();
	
	//TODO Try to find an improvement of this _big_ hack
	//Set its default size, the first time KSystemLog is loaded
	if (!initialGeometrySet())
		resize(600,450);
	
	//Show before reading the config because users can think that KSystemLog 
	//have not been launched if it takes too long time to start.
	show();
	
	// Apply the create the main window and ask the mainwindow to
	// automatically save settings if changed: window size, toolbar
	// position, icon size, etc.  Also to add actions for the statusbar
	// toolbar, and keybindings if necessary.
	setupGUI();

	//Read the configuration and display each tab saved
	readConfig();
	
}

void KSystemLog::setupTabBar() {
	tabs=new KTabWidget(this, "tabs");
	
	connect(tabs, TQT_SIGNAL(currentChanged(TQWidget*)), TQT_TQOBJECT(this), TQT_SLOT(currentTabChanged(TQWidget*)));
	
	TQPushButton* tabNewTabButton=new TQPushButton(SmallIcon("tab_new"), "", tabs);	
	connect(tabNewTabButton, TQT_SIGNAL(clicked()), TQT_TQOBJECT(this), TQT_SLOT(newTab()));
	
	TQToolTip::add(tabNewTabButton, i18n("Create a new tab"));
	TQWhatsThis::add(tabNewTabButton, i18n("Creates a new tab which can display another log."));
	
	TQPushButton* tabCloseTabButton=new TQPushButton(SmallIcon("tab_remove"), "", tabs);
	connect(tabCloseTabButton, TQT_SIGNAL(clicked()), TQT_TQOBJECT(this), TQT_SLOT(closeTab()));
	
	TQToolTip::add(tabCloseTabButton, i18n("Close the current tab"));
	TQWhatsThis::add(tabCloseTabButton, i18n("Closes the current tab."));
	
	tabs->setCornerWidget(tabNewTabButton, TQt::TopLeft);
	tabs->setCornerWidget(tabCloseTabButton, TQt::TopRight);
	
}

KSystemLog::~KSystemLog() {
	//Save config here until a better solution is found
	saveConfig();
	
	if (detailDialog!=NULL)
		delete detailDialog;

	if (loadingDialog!=NULL)
		delete loadingDialog;
		
	if (slotLogAction!=NULL)
		delete slotLogAction;
	
}



LogManager* KSystemLog::activeLogManager() {
	if (tabs==NULL) {
		kdDebug() << "Call to tabs widget which is not initialized" << endl;
		return(NULL);
	}
		
	View* currentView=static_cast<View*> (tabs->currentPage());
	
	TQPtrListIterator<LogManager> it(logManagers);
	
	LogManager* manager=it.current();
	while(manager!=NULL) {
		
		if (manager->getView()==currentView) {
			return(manager);
		}
		
		++it;
		manager=it.current();
	}
	
	
	//Normally it's an impossible case (I hope... ;-)
	kdDebug() << "No active log manager found" << endl;
	return(NULL);
}


void KSystemLog::currentTabChanged(TQWidget* /*widget*/) {
	kdDebug() << "Tab has changed" << endl;
	
	LogManager* currentManager=activeLogManager();
	
	//If the tab changed, we suppose that the selection changes too
	slotSelectionChanged();
	
	//Update the status bar
	updateStatusBar();
	
	//Update the Group By menu
	updateGroupBy();
	
	//Management of Resume and Pause actions
	if (currentManager->isParsingPaused()) {
		pauseParsingAction->setEnabled(false);
		resumeParsingAction->setEnabled(true);
	}
	else {
		pauseParsingAction->setEnabled(true);
		resumeParsingAction->setEnabled(false);
	}
	

	//Change the title of the window
	changeCaption(currentManager->getLogMode()->name);
	
	//If the tab name has been change, regive it its old name
	changeTab(currentManager->getView(), currentManager->getLogMode()->name);
	
	//Modify the menu button to help the user know what is the currently log mode
	//setModeToAction(currentManager->getLogMode(), true);
	KToggleAction* action=getCorrespondingLogAction(currentManager->getLogMode());
	if (action!=NULL)
		action->setChecked(true);
	
	setCurrentLogManager(currentManager);

	
	if (detailDialog!=NULL) {
		detailDialog->setView(currentManager->getView());
	}
	
}


void KSystemLog::setupStatusBar() {
	statusBar()->insertItem("", STATUS_BAR_LINE_COUNT, 0, true);
	statusBar()->insertItem("", STATUS_BAR_LAST_MODIFICATION, 0, true);
	
	//Displays the Status Bar
	statusBar()->show();
}

void KSystemLog::setupActions() {

	KStdAction::open(TQT_TQOBJECT(this), TQT_SLOT(fileOpen()), actionCollection(), "file_open");
	actionCollection()->action("file_open")->setToolTip(i18n("Open a file in KSystemLog"));
	actionCollection()->action("file_open")->setWhatsThis(i18n("Opens a file in KSystemLog and displays its content in the current tab."));	
	
	//TODO Not used for the moment
	//KStdAction::print(TQT_TQOBJECT(this), TQT_SLOT(filePrint()), actionCollection());
	
	saveAction=KStdAction::saveAs(TQT_TQOBJECT(this), NULL, actionCollection(), "file_save");
	//TODO Retrieve the system's shortcut of the save action (and not Save as...)
	saveAction->setShortcut(CTRL+Key_S);
	saveAction->setToolTip(i18n("Save the selection to a file"));
	saveAction->setWhatsThis(i18n("Saves the selection to a file. This action is useful if you want to create an attachment or a backup of a particular log."));	
	saveAction->setEnabled(false);
	
	KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT(quit()), actionCollection(), "file_quit");
	actionCollection()->action("file_quit")->setToolTip(i18n("Quit KSystemLog"));
	actionCollection()->action("file_quit")->setWhatsThis(i18n("Quits KSystemLog."));	
	
	copyAction=KStdAction::copy(TQT_TQOBJECT(this), NULL, actionCollection(), "copy");
	copyAction->setToolTip(i18n("Copy the selection to the clipboard"));
	copyAction->setWhatsThis(i18n("Copies the selection to the clipboard. This action is useful if you want to paste the selection in a chat or an email."));	
	copyAction->setEnabled(false);
	
	expandAllAction=new KAction(i18n("Ex&pand All"), NULL, CTRL+Key_X, TQT_TQOBJECT(this), NULL, actionCollection(), "expand_all" );
	expandAllAction->setToolTip(i18n("Expand all categories"));
	expandAllAction->setWhatsThis(i18n("<qt>This action opens all main categories. This is enabled only if an option has been selected in the <b>Group By</b> menu.</qt>"));
	expandAllAction->setEnabled(false);
	
	collapseAllAction=new KAction(i18n("Col&lapse All"), NULL, CTRL+Key_L, TQT_TQOBJECT(this), NULL, actionCollection(), "collapse_all" );
	collapseAllAction->setToolTip(i18n("Collapse all categories"));
	collapseAllAction->setWhatsThis(i18n("<qt>This action closes all main categories. This is enabled only if an option has been selected in the <b>Group By</b> menu.</qt>"));
	collapseAllAction->setEnabled(false);
	
	sendMailAction=new KAction(i18n("&Email Selection..."), "mail_generic", CTRL+Key_M, TQT_TQOBJECT(this), NULL, actionCollection(), "send_mail" );
	sendMailAction->setToolTip(i18n("Send the selection by mail"));
	sendMailAction->setWhatsThis(i18n("Sends the selection by mail. Simply select the important lines and click on this menu entry to send the selection to a friend or a mailing list."));	
	sendMailAction->setEnabled(false);
	
	logMessageAction=new KAction(i18n("&Send Message..."), "filenew", CTRL+Key_L, TQT_TQOBJECT(this), TQT_SLOT(slotLogMessage()), actionCollection(), "log_message" );
	logMessageAction->setToolTip(i18n("Send a message to the log system"));
	logMessageAction->setWhatsThis(i18n("This action will open a dialog which lets you send a message to the log system."));
	
	KStdAction::selectAll(TQT_TQOBJECT(this), TQT_SLOT(slotSelectAll()), actionCollection(), "select_all");
	actionCollection()->action("select_all")->setToolTip(i18n("Select all lines of the current log"));
	actionCollection()->action("select_all")->setWhatsThis(i18n("Selects all lines of the current log. This action is useful if you want, for example, to save all the content of the current log in a file."));
	
	KStdAction::find(findManager, TQT_SLOT(slotFind()), actionCollection(), "find");
	KStdAction::findNext(findManager, TQT_SLOT(slotFindNext()), actionCollection(), "find_next");

	//TODO Find a solution to display at the right place this action (see Akregator interface)
	filterBarAction=new KToggleAction(i18n("Show &Filter Bar"), TQString(), 0, TQT_TQOBJECT(this), TQT_SLOT(slotToggleFilterBar()), actionCollection(), "toggle_filter_bar");
#if defined(KDE_MAKE_VERSION) && TDE_VERSION >= KDE_MAKE_VERSION(3,3,0)
	filterBarAction->setEnabled(true);
#else
	filterBarAction->setEnabled(false);
#endif

	KStdAction::preferences(TQT_TQOBJECT(this), TQT_SLOT(slotOptions()), actionCollection());
	
	newTabAction=new KAction(i18n("&New Tab"), "tab_new", CTRL+Key_T, TQT_TQOBJECT(this), TQT_SLOT(newTab()), actionCollection(), "new_tab" );
	newTabAction->setToolTip(i18n("Create a new tab"));
	newTabAction->setWhatsThis(i18n("Creates a new tab which can display another log."));
	
	closeTabAction=new KAction(i18n("&Close Tab"), "tab_remove", CTRL+Key_W, TQT_TQOBJECT(this), TQT_SLOT(closeTab()), actionCollection(), "close_tab" );
	closeTabAction->setToolTip(i18n("Close the current tab"));
	closeTabAction->setWhatsThis(i18n("Closes the current tab."));
	
	duplicateTabAction=new KAction(i18n("&Duplicate Tab"), "tab_duplicate", SHIFT+CTRL+Key_N, TQT_TQOBJECT(this), TQT_SLOT(duplicateTab()), actionCollection(), "duplicate_tab" );
	duplicateTabAction->setToolTip(i18n("Duplicate the current tab"));
	duplicateTabAction->setWhatsThis(i18n("Duplicates the current tab."));
	
	moveTabLeftAction=new KAction(i18n("Move Tab &Left"), "1leftarrow", SHIFT+CTRL+Key_Left, TQT_TQOBJECT(this), TQT_SLOT(moveTabLeft()), actionCollection(), "move_tab_left" );
	moveTabLeftAction->setToolTip(i18n("Move the current tab to the left"));
	moveTabLeftAction->setWhatsThis(i18n("Moves the current tab to the left."));
	
	moveTabRightAction=new KAction(i18n("Move Tab &Right"), "1rightarrow", SHIFT+CTRL+Key_Right, TQT_TQOBJECT(this), TQT_SLOT(moveTabRight()), actionCollection(), "move_tab_right" );
	moveTabRightAction->setToolTip(i18n("Move the current tab to the right"));
	moveTabRightAction->setWhatsThis(i18n("Moves the current tab to the right."));
	
	
	reloadAction=new KAction(i18n("&Reload"), "reload", Key_F5, TQT_TQOBJECT(this), TQT_SLOT(reloadCurrent()), actionCollection(), "reload" );
	reloadAction->setToolTip(i18n("Reload the current log"));
	reloadAction->setWhatsThis(i18n("Reloads the current log, if you want to be sure that the view is correctly updated."));
	
	resumeParsingAction=new KAction(i18n("Resu&me Parsing"), "player_play", CTRL+Key_M, TQT_TQOBJECT(this), TQT_SLOT(resumeParsing()), actionCollection(), "resume_parsing");
	resumeParsingAction->setToolTip(i18n("Resume the watching of the current log"));
	resumeParsingAction->setWhatsThis(i18n("Resumes the watching of the current log. This action is only available when the user has already paused the reading."));
	resumeParsingAction->setEnabled(true);
	
	pauseParsingAction=new KAction(i18n("S&top Parsing"), "player_stop", CTRL+Key_P, TQT_TQOBJECT(this), TQT_SLOT(pauseParsing()), actionCollection(), "pause_parsing");
	pauseParsingAction->setToolTip(i18n("Pause the watching of the current log"));
	pauseParsingAction->setWhatsThis(i18n("Pauses the watching of the current log. This action is particularly useful when the system is writing too many lines to log files, causing KSystemLog to reload too frequently."));

	detailAction=new KAction(i18n("&Details"), "viewmag", ALT+Key_Return, TQT_TQOBJECT(this), TQT_SLOT(slotDetails()), actionCollection(), "details");
	detailAction->setToolTip(i18n("Display details on the currently selected line"));
	detailAction->setWhatsThis(i18n("Displays a dialog box which contains details on the currently selected line. You are able to navigate through the logs from this dialog box with the <b>Previous</b> / <b>Next</b> buttons."));
	detailAction->setEnabled(false);

	tooltipEnabledAction=new KToggleAction(i18n("&Enable Detailed Tooltips"), 0, actionCollection(), "enable_tooltip");
	tooltipEnabledAction->setToolTip(i18n("Disable/Enable the tooltips on the current view"));
	tooltipEnabledAction->setWhatsThis(i18n("Disables/Enables the tooltips displayed when the cursor hovers a log line."));
	
	
	connect(tooltipEnabledAction, TQT_SIGNAL(toggled(bool)), TQT_TQOBJECT(this), TQT_SLOT(slotTooltipEnabled(bool)));
	
	newLinesDisplayedAction=new KToggleAction(i18n("&Display New Lines"), 0, actionCollection(), "display_new_line");
	newLinesDisplayedAction->setToolTip(i18n("Display or not new lines if the log changes"));
	newLinesDisplayedAction->setWhatsThis(i18n("Displays or not the new lines if the log changes. This option is useful when you want to see an old log lines and that KSystemLog often refreshes the current view."));
	
	connect(newLinesDisplayedAction, TQT_SIGNAL(toggled(bool)), TQT_TQOBJECT(this), TQT_SLOT(slotNewLinesDisplayed(bool)));

	setupGroupBy();

	setupLogActions();
	
	
}

void KSystemLog::setupLogActions() {
	
	//Define a macro allowing the connection of the signal from log action to the slotLogAction object
	#if defined(KDE_MAKE_VERSION) && TDE_VERSION >= KDE_MAKE_VERSION(3,4,0)
		#define CONNECTED_SLOT(action) connect(action, TQT_SIGNAL(activated(KAction::ActivationReason, TQt::ButtonState)), slotLogAction, TQT_SLOT(slotLogAction(KAction::ActivationReason, TQt::ButtonState)));
	#else
		#define CONNECTED_SLOT(action) connect(action, TQT_SIGNAL(activated()), slotLogAction, TQT_SLOT(slotLogAction()));
	#endif
	
	
	//Construct the slotLogAction object
	slotLogAction=new SlotLogAction(this);
	
	TQString exclusiveGroup="LogActions";

	//System Log Action
	KToggleAction* systemAction=new KToggleAction(i18n("S&ystem Log"), SYSTEM_MODE_ICON, 0, NULL, NULL, actionCollection(), "system_log" );
	systemAction->setToolTip(i18n("Display the system log."));
	systemAction->setWhatsThis(i18n("Displays the system log in the current tab. This log is generally used by non-specialized processes (like \"sudo\" or \"fsck\" commands)"));
	systemAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[systemAction]=Globals::systemMode;
	CONNECTED_SLOT(systemAction)
	
	//Kernel Log Action
	KToggleAction* kernelAction=new KToggleAction(i18n("&Kernel Log"), KERNEL_MODE_ICON, 0, NULL, NULL, actionCollection(), "kernel_log" );
	kernelAction->setToolTip(i18n("Display the kernel log."));
	kernelAction->setWhatsThis(i18n("<qt>Displays the kernel log in the current tab. This log is only useful for users who want to know why the Kernel does not detect their hardware or what is the cause of the last <i>kernel panic/oops</i>.</qt>"));
	kernelAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[kernelAction]=Globals::kernelMode;
	CONNECTED_SLOT(kernelAction)
	
	//Boot Log Action
	KToggleAction* bootAction=new KToggleAction(i18n("&Boot Log"), BOOT_MODE_ICON, 0, NULL, NULL, actionCollection(), "boot_log" );
	bootAction->setToolTip(i18n("Display the boot log."));
	bootAction->setWhatsThis(i18n("<qt>Displays the boot log in the current tab. This log is useful if you want to verify if all startup services have been correctly started.</qt>"));
	bootAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[bootAction]=Globals::bootMode;
	CONNECTED_SLOT(bootAction)
	
	//Authentication Log Action
	KToggleAction* authenticationAction=new KToggleAction(i18n("A&uthentication Log"), AUTHENTICATION_MODE_ICON, 0, NULL, NULL, actionCollection(), "authentication_log" );
	authenticationAction->setToolTip(i18n("Display the authentication log."));
	authenticationAction->setWhatsThis(i18n("<qt>Displays the authentication log in the current tab. This log displays all log in made by each user of the system, and can help you to know if someone tried to crack your system.</qt>"));
	authenticationAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[authenticationAction]=Globals::authenticationMode;
	CONNECTED_SLOT(authenticationAction)
	
	//Daemon Log Action
	KToggleAction* daemonAction=new KToggleAction(i18n("&Daemons Log"), DAEMON_MODE_ICON, 0, NULL, NULL, actionCollection(), "daemon_log" );
	daemonAction->setToolTip(i18n("Display the daemons log."));
	daemonAction->setWhatsThis(i18n("<qt>Displays the daemons log in the current tab. The daemons are all processes launched in the background of the system. See this log if you want to know what it occurs in the background of your system.</qt>"));
	daemonAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[daemonAction]=Globals::daemonMode;
	CONNECTED_SLOT(daemonAction)
	
	//Cron Log Action
	KToggleAction* cronAction=new KToggleAction(i18n("&Planned Tasks Log"), CRON_MODE_ICON, 0, NULL, NULL, actionCollection(), "cron_log" );
	cronAction->setToolTip(i18n("Display the planned tasks log (or Cron log)."));
	cronAction->setWhatsThis(i18n("<qt>Displays the planned tasks log in the current tab. Cron process is a program in charged of launching planned tasks on your system, like security checks, or auto-restarting of some services. Use this menu to see the last-launched processes.</qt>"));
	cronAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[cronAction]=Globals::cronMode;
	CONNECTED_SLOT(cronAction)
	
	//Xorg Log Action
	KToggleAction* xorgAction=new KToggleAction(i18n("&X.org Log"), XORG_MODE_ICON, 0, NULL, NULL, actionCollection(), "xorg_log" );
	xorgAction->setToolTip(i18n("Display the X.org log."));
	xorgAction->setWhatsThis(i18n("<qt>Displays the X.org log in the current tab. X.org is the service which displays on screen your desktop and manage your graphical hardware. See this log if you want to know why you do not have 3D accelerations or why your input device is not recognized.</qt>"));
	xorgAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[xorgAction]=Globals::xorgMode;
	CONNECTED_SLOT(xorgAction)
	
	//ACPId Log Action
	KToggleAction* acpidAction=new KToggleAction(i18n("&ACPI Log"), ACPID_MODE_ICON, 0, NULL, NULL, actionCollection(), "acpid_log" );
	acpidAction->setToolTip(i18n("Display the ACPI log."));
	acpidAction->setWhatsThis(i18n("<qt>Displays the ACPI log in the current tab. ACPI is used to manage the hardware components of your computer, like notebook batteries, reset buttons...</qt>"));
	acpidAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[acpidAction]=Globals::acpidMode;
	CONNECTED_SLOT(acpidAction)

	//Cups Log Action
	KToggleAction* cupsAction=new KToggleAction(i18n("&Cups Log"), CUPS_MODE_ICON, 0, NULL, NULL, actionCollection(), "cups_log" );
	cupsAction->setToolTip(i18n("Display the Cups log."));
	cupsAction->setWhatsThis(i18n("<qt>Displays the CUPS log in the current tab. CUPS is the program which manage printing on your computer.</qt>"));
	cupsAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[cupsAction]=Globals::cupsMode;
	CONNECTED_SLOT(cupsAction)

	//Cups Access Log Action
	KToggleAction* cupsAccessAction=new KToggleAction(i18n("&Cups Web Log"), CUPS_ACCESS_MODE_ICON, 0, NULL, NULL, actionCollection(), "cups_access_log" );
	cupsAccessAction->setToolTip(i18n("Display the CUPS Web Server Access log."));
	cupsAccessAction->setWhatsThis(i18n("<qt>Displays the CUPS Web Server Access log in the current tab. CUPS is the program which manage printing on your computer. This log saves all requests performed to the CUPS embedded web server (default: <i>http://localhost:631</i>).</qt>"));
	cupsAccessAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[cupsAccessAction]=Globals::cupsAccessMode;
	CONNECTED_SLOT(cupsAccessAction)
	

	//Apache Log Action
	KToggleAction* apacheAction=new KToggleAction(i18n("&Apache log"), APACHE_MODE_ICON, 0, NULL, NULL, actionCollection(), "apache_log" );
	apacheAction->setToolTip(i18n("Display the Apache log."));
	apacheAction->setWhatsThis(i18n("<qt>Displays the Apache log in the current tab. Apache is the main used Web server in the world.</qt>"));
	apacheAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[apacheAction]=Globals::apacheMode;
	CONNECTED_SLOT(apacheAction)

	//Apache Access Log Action
	KToggleAction* apacheAccessAction=new KToggleAction(i18n("&Apache Web log"), APACHE_ACCESS_MODE_ICON, 0, NULL, NULL, actionCollection(), "apache_access_log" );
	apacheAccessAction->setToolTip(i18n("Display the Apache Access log."));
	apacheAccessAction->setWhatsThis(i18n("<qt>Displays the Apache Access log in the current tab. CUPS is the program which manage printing on your computer. This log saves all requests performed by the Apache web server.</qt>"));
	apacheAccessAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[apacheAccessAction]=Globals::apacheAccessMode;
	CONNECTED_SLOT(apacheAccessAction)
	
	//Postfix Log Action
	KToggleAction* postfixAction=new KToggleAction(i18n("&Postfix Log"), POSTFIX_MODE_ICON, 0, NULL, NULL, actionCollection(), "postfix_log" );
	postfixAction->setToolTip(i18n("Display the Postfix log."));
	postfixAction->setWhatsThis(i18n("<qt>Displays the Postfix log in the current tab. Postfix is the most known and used mail server in the Linux world.</qt>"));
	postfixAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[postfixAction]=Globals::postfixMode;
	CONNECTED_SLOT(postfixAction)
	
	//Samba Log Action
	KToggleAction* sambaAction=new KToggleAction(i18n("&Samba Log"), SAMBA_MODE_ICON, 0, NULL, NULL, actionCollection(), "samba_log" );
	sambaAction->setToolTip(i18n("Display the Samba log."));
	sambaAction->setWhatsThis(i18n("<qt>Displays the Samba log in the current tab. Samba is the file sharing server which interacts with Microsoft Windows network.</qt>"));
	sambaAction->setExclusiveGroup(exclusiveGroup);
	mapActionLogModes[sambaAction]=Globals::sambaMode;
	CONNECTED_SLOT(sambaAction)
	
}


void KSystemLog::reloadCurrent() {
	LogManager* manager=activeLogManager();
	
	if (manager!=NULL) {
		manager->reload();
	}
	
}


void KSystemLog::reloadAll() {
	TQPtrListIterator<LogManager> it(logManagers);
	
	//Inform the Loading Dialog on how many Log Managers we have to load
	loadingDialog->setTabCount(logManagers.count());
	
	int index=1;
	
	LogMode* mode;
	
	LogManager* current=it.current();
	while(current!=NULL) {
		
		//Inform the Loading Dialog that there is a new loading
		loadingDialog->setCurrentTab(index);

		//TODO Experimental Code... The manager is now using the Log mode passed in parameter
		mode=current->getLogMode();
		
		//The no log mode does not have to be reloaded
		if (mode==Globals::noMode) {
			++it;
			current=it.current();
			index++;
			continue;
		}
		
		
		if (mode!=Globals::openingMode)
			current->initialize(mode);
		
		current->reload();
		
		++it;
		current=it.current();
		index++;
	}
	
	//Reposition the count total to its default value
	loadingDialog->setTabCount(0);

}

void KSystemLog::slotSelectionChanged() {
	//kdDebug() << "KSystemLog selectionChanged()" << endl;
	
	LogListItem* item=activeLogManager()->getView()->getFirstSelectedItem();
	
	bool selection;
	
	//No item selected
	if (item==NULL) {
		selection=false;
	}
	else {
		selection=true;
	}

	copyAction->setEnabled(selection);
	saveAction->setEnabled(selection);
	detailAction->setEnabled(selection);
	sendMailAction->setEnabled(selection);

	if (detailDialog!=NULL) {
		detailDialog->selectionChanged();
	}
}

void KSystemLog::moveTabLeft() {
	LogManager* currentManager=activeLogManager();
	
	int position=tabs->indexOf(currentManager->getView());
	
	if (position<=0)
		return;

	logManagers.remove(position);
	
	logManagers.insert(position-1, currentManager);
	
	tabs->moveTab(position, position-1);

}

void KSystemLog::moveTabRight() {
	LogManager* currentManager=activeLogManager();
	
	int position=tabs->indexOf(currentManager->getView());
	
	if (position>=tabs->count()-1)
		return;
		
	logManagers.remove(position);
		
	logManagers.insert(position+1, currentManager);
	
	tabs->moveTab(position, position+1);
	
}


LogManager* KSystemLog::duplicateTab() {
	LogManager* currentManager=activeLogManager();
	
	LogManager* newManager=newTab();
	
	LogMode* mode=currentManager->getLogMode();
	if (mode==Globals::openingMode) {
		//We retrieve the path of the URL of the first file of the file list of the current manager ;-)
		ReaderFactory::lastOpenedURL=currentManager->getLogFiles().first()->url;

		this->load(mode, newManager);
	}
	else {
		this->load(mode, newManager);
	}
	
	//Returns the newly created LogManager
	return(newManager);
}


LogManager* KSystemLog::newTab() {
	LogManager* manager=new LogManager(this, loadingDialog);
	
	//Signals from LogManager to Main Class
	connect(manager, TQT_SIGNAL(changeTitle(View*, const TQString&)), TQT_TQOBJECT(this), TQT_SLOT(changeTab(View*, const TQString& )));
	connect(manager, TQT_SIGNAL(changeTitle(View*, const TQIconSet&, const TQString&)), TQT_TQOBJECT(this), TQT_SLOT(changeTab(View*, const TQIconSet&, const TQString&)));
	connect(manager, TQT_SIGNAL(changeCaption(const TQString&)), TQT_TQOBJECT(this), TQT_SLOT(setCaption(const TQString&)));
	connect(manager, TQT_SIGNAL(changeStatusbar(const TQString&)), TQT_TQOBJECT(this), TQT_SLOT(changeStatusbar(const TQString&)));
	connect(manager, TQT_SIGNAL(logUpdated(int)), TQT_TQOBJECT(this), TQT_SLOT(logUpdated(int)));
	connect(manager, TQT_SIGNAL(reloaded()), TQT_TQOBJECT(this), TQT_SLOT(logManagerReloaded()));
	connect(manager, TQT_SIGNAL(GUIUpdated()), TQT_TQOBJECT(this), TQT_SLOT(updateGUI()));
	connect(manager, TQT_SIGNAL(detailsCalled()), TQT_TQOBJECT(this), TQT_SLOT(slotDetails()));
	connect(manager, TQT_SIGNAL(selectionChanged()), TQT_TQOBJECT(this), TQT_SLOT(slotSelectionChanged()));
	
	//Signals from Main Actions to LogManager
	connect(expandAllAction, TQT_SIGNAL(activated()), manager, TQT_SLOT(slotExpandAll()));
	connect(collapseAllAction, TQT_SIGNAL(activated()), manager, TQT_SLOT(slotCollapseAll()));
	connect(saveAction, TQT_SIGNAL(activated()), manager, TQT_SLOT(slotFileSave()));
	connect(copyAction, TQT_SIGNAL(activated()), manager, TQT_SLOT(slotCopyToClipboard()));
	connect(sendMailAction, TQT_SIGNAL(activated()), manager, TQT_SLOT(slotSendMail()));
	
	logManagers.append(manager);
	
	tabs->insertTab(manager->getView(), SmallIcon(NO_MODE_ICON), i18n("No Log"));
	
#if defined(KDE_MAKE_VERSION) && TDE_VERSION >= KDE_MAKE_VERSION(3,4,0)
	if (tabs->count()>1) {
		tabs->setTabBarHidden(false);
	}
	else {
		tabs->setTabBarHidden(true);
	}
#endif

	tabs->setCurrentPage(tabs->count()-1);
	
	//Correctly initialize the Status Bar
	updateStatusBar();

	//Returns the newly created LogManager
	return(manager);
}

void KSystemLog::changeTab(View* view, const TQString& label) {
	tabs->changeTab(view, label);
}

void KSystemLog::changeTab(View* view, const TQIconSet& icon, const TQString& label) {
	tabs->changeTab(view, icon, label);
}

int KSystemLog::getIndex(LogManager* manager) {
	
	TQPtrListIterator<LogManager> it(logManagers);
	
	LogManager* temp=it.current();
	int pos=0;
	while(temp!=NULL) {
		
		if (temp==manager) {
			return(pos);
		}
		
		++pos;
		++it;
		temp=it.current();
	}

	//Should never happen
	kdDebug() << "Log manager not found in the list" << endl;
	return(-1);
}


void KSystemLog::setCurrentLogManager(LogManager* currentManager) {
	currentManager->setCurrent(true);
	
	TQPtrListIterator<LogManager> it(logManagers);
	
	LogManager* manager=it.current();
	while(manager!=NULL) {
		if (manager!=currentManager) {
			manager->setCurrent(false);
		}
		
		++it;
		manager=it.current();
	}

	
}

void KSystemLog::closeTab() {
	if (tabs->count()==1)
		return;
	
	LogManager* currentManager=activeLogManager();
	
	tabs->removePage(currentManager->getView());
	
	logManagers.remove(currentManager);
	
	this->setCurrentLogManager(logManagers.last());
	
	//TODO Delete the current Manager correctly ! (this crash KSystemLog)
	//TODO Do correctly the disconnection of signal (disconnect(... ...)) before deleting the object
	//currentManager
	//delete currentManager;
	
	
	/* 
	//TODO Strange result : (mail this to KDE Developer)
	if (tabs->count()==2) {
		tabs->removePage(currentView);
		
		View* currentView=activeView();
		tabs->removePage(currentView);
	}
	else {
		tabs->removePage(currentView);	
	}
	*/
	
#if defined(KDE_MAKE_VERSION) && TDE_VERSION >= KDE_MAKE_VERSION(3,4,0)
	if (tabs->count()==1) {
		tabs->setTabBarHidden(true);
	}
#endif
	
}


void KSystemLog::quit() {
	saveConfig();
	
	kapp->quit();
}

void KSystemLog::slotToggleFilterBar() {

	//Update the configuration
	KSystemLogConfig::setToggleFilterBar(filterBarAction->isChecked());
	
	//And call an updating method on each Log Manager
	TQPtrListIterator<LogManager> it(logManagers);
	
	LogManager* current=it.current();
	while (current!=NULL) {
		
		current->toggleFilterBar();
		
		++it;
		current=it.current();
	}
	
	
}

void KSystemLog::slotDetails() {
	LogListItem* item=activeLogManager()->getView()->getFirstSelectedItem();
	
	//If no item are selected, we don't open the dialog
	if (item==NULL)
		return;
	
	//If the dialog has not been created, we create it
	if (detailDialog==NULL) {
		detailDialog=new DetailDialog(activeLogManager()->getView(), this, "detail_dialog");
		connect(activeLogManager()->getView()->getLogList(), TQT_SIGNAL(selectionChanged()), detailDialog, TQT_SLOT(selectionChanged()));
		//connect(activeLogManager()->getView()->getLogList(), TQT_SIGNAL(triggerUpdate()), detailDialog, TQT_SLOT(selectionChanged()));
	}

	detailDialog->show();

}

void KSystemLog::slotSelectAll() {
	activeLogManager()->getView()->getLogList()->selectAll(true);
}

void KSystemLog::slotTooltipEnabled(bool enabled) {
	KSystemLogConfig::setTooltipEnabled(enabled);

	TQPtrListIterator<LogManager> it(logManagers);
	while(it.current()!=NULL) {
		(it.current())->setTooltipEnabled(enabled);
		++it;
	}
	
}

void KSystemLog::slotNewLinesDisplayed(bool displayed) {
	KSystemLogConfig::setNewLinesDisplayed(displayed);

	TQPtrListIterator<LogManager> it(logManagers);
	while(it.current()!=NULL) {
		(it.current())->setNewLinesDisplayed(displayed);
		++it;
	}


}


void KSystemLog::logUpdated(int /*lines*/) {
	kdDebug() << "KSystemLog logUpdated()" << endl;

	updateStatusBar();
}

void KSystemLog::updateStatusBar() {
	LogManager* currentManager=activeLogManager();

	TQString lineCount=i18n("1 log line.", "%n log lines.", currentManager->getView()->getItemCount());
	
	statusBar()->changeItem(lineCount, STATUS_BAR_LINE_COUNT);
	
	TQString time=i18n("Last updated: %1.").arg(currentManager->getLastUpdate().toString(Qt::LocalDate));
	
	statusBar()->changeItem(time, STATUS_BAR_LAST_MODIFICATION);


}


void KSystemLog::pauseParsing() {
	activeLogManager()->setParsingPaused(true);

	//Desactivate the pause action, and activate the resume one
	resumeParsingAction->setEnabled(true);
	pauseParsingAction->setEnabled(false);
}

void KSystemLog::resumeParsing() {
	activeLogManager()->setParsingPaused(false);

	//Desactivate the resume action, and activate the pause one
	resumeParsingAction->setEnabled(false);
	pauseParsingAction->setEnabled(true);
}

//If no actions are selected, than all are deselected
void KSystemLog::deactiveLogActions() {
	TQValueList<KToggleAction*> actions=mapActionLogModes.keys();
	
	KToggleAction* action;
	TQValueList<KToggleAction*>::iterator it;
	for (it=actions.begin(); it!=actions.end(); ++it) {
		action=*it;
		
		action->setChecked(false);
	}
	
}

KToggleAction* KSystemLog::getCorrespondingLogAction(LogMode* mode) {
	//Special case for no and opening mode
	//TODO Maybe use a list for "special" log mode, and pre-test the parameter with it
	if (mode==Globals::noMode || mode==Globals::openingMode)
		return(NULL);

	TQValueList<KToggleAction*> keys=mapActionLogModes.keys();
	
	TQValueList<KToggleAction*>::iterator it;
	
	KToggleAction* key;
	
	
	for (it=keys.begin(); it!=keys.end(); ++it) {
		key=*it;
		
		if (mapActionLogModes[key]==mode)
			return(key);
	}	

	kdDebug() << "Strange : The corresponding log action does not exist" << endl;	
	return(NULL);
}


KToggleAction* KSystemLog::getLogAction(const char* name) {
	return( static_cast<KToggleAction*> (actionCollection()->action(name)) );
}

#if defined(KDE_MAKE_VERSION) && TDE_VERSION >= KDE_MAKE_VERSION(3,4,0)
void KSystemLog::logActionClicked(const TQObject* sender, KAction::ActivationReason reason, TQt::ButtonState state) {
#else
void KSystemLog::logActionClicked(const TQObject* sender) {
#endif
	
	KToggleAction* action=getLogAction(sender->name());
	
	LogMode* mode=mapActionLogModes[action];
	
	if (mode==NULL) {
		kdDebug() << "Strange : The selected mode does not exist" << endl;
		return;
	}
	
	//TODO Be sure that the + is the right symbol to combine TQt Constants
	//If the user uses the middle button OR left button + shift OR left button + control : = it opens the log in a new tab
#if defined(KDE_MAKE_VERSION) && TDE_VERSION >= KDE_MAKE_VERSION(3,4,0)
	if (state==Qt::MidButton || (state==TQt::ControlButton+Qt::LeftButton) || (state==TQt::ShiftButton+Qt::LeftButton))
		newTab();
#endif
	
	this->load(mode, activeLogManager());
	
	//If don't know why it needs a false parameter (useful if user reclick on the same log mode than previous one)
	action->setChecked(false);


}

void KSystemLog::fileOpen() {
	//Open a standard Filedialog
	KURL openingFileName(KFileDialog::getOpenURL(TQString(), TQString(), this, i18n("Open Location")));
	kdDebug() << "Opening file : " << openingFileName.url() << endl;
	
	if (!openingFileName.isEmpty()) {
		if (openingFileName.isValid()) {
			//Deactive the old action mode
			deactiveLogActions();
			
			ReaderFactory::lastOpenedURL=openingFileName;
			//Launch the actualizing
			this->load(Globals::openingMode, activeLogManager());
		}
		else {
			TQString message(i18n("Malformed URL. Unable to open this file."));
			KMessageBox::error(this, message, i18n("Unable to open this file."), KMessageBox::Notify);
		}
	}
}

/**
 * This slot is called whenever the File->Print menu is selected,
 * the Print shortcut is pressed (usually CTRL+P) or the Print toolbar
 * button is clicked
 */
void KSystemLog::filePrint() {
	if (!printer)
		printer=new KPrinter();
	
	if (printer->setup(this)) {
		// setup the printer.  with TQt, you always "print" to a
		// TQPainter.. whether the output medium is a pixmap, a screen,
		// or paper
		TQPainter p;
		p.begin(printer);
		
		// we let our view do the actual printing
		TQPaintDeviceMetrics metrics(printer);
		activeLogManager()->getView()->print(&p, metrics.height(), metrics.width());
		
		// and send the result to the printer
		p.end();
	}
}


void KSystemLog::slotOptions() {
	kdDebug() << "Launching the option dialog box..." << endl;

	Options dialog(this, "config_dialog", false);
	if (dialog.exec()) {
		//Once the option dialog is close, we can make a simple reloading of each LogManager
		reloadAll();
	}

}

void KSystemLog::slotLogMessage() {
	kdDebug() << "Launching the Send message dialog box..." << endl;

	//TODO Create a pointer if this dialog begun non-modal
	LoggerDialog dialog(this, "logger_dialog");
	dialog.exec();

}


void KSystemLog::changeStatusbar(const TQString& text) {
	//Display this text on the statusbar
	statusBar()->message(text);
}

void KSystemLog::changeCaption(const TQString& text) {
	//Display this text on the caption
	setCaption(text);
}

void KSystemLog::setupProgressDialog() {
	//TODO Move this to the LoadingDialog constructor
	loadingDialog=new LoadingDialog((TQWidget*)this, "progress_dialog", true);
	loadingDialog->setAllowCancel(false);
	loadingDialog->setAutoClose(false);
	loadingDialog->setMinimumDuration(500);
	loadingDialog->progressBar()->setTotalSteps(100);

}


void KSystemLog::readConfig() {
	kdDebug() << "Reading KSystemLog configuration..." << endl;
	
	//Filter Bar is displayed depending on the config file
	filterBarAction->setChecked(KSystemLogConfig::toggleFilterBar());
	
	TQValueList<int> groupByTypes=KSystemLogConfig::groupBy();
	TQValueList<int> groupByColumns=KSystemLogConfig::groupByColumns();
	
	TQValueList<int>::iterator itGroupBy=groupByTypes.begin();
	TQValueList<int>::iterator itGroupByColumn=groupByColumns.begin();

	TQValueList<int> modes=KSystemLogConfig::logModes();
	TQStringList fileList=KSystemLogConfig::openedURLs();
	
	TQValueList<int>::iterator it;
	TQStringList::iterator itString=fileList.begin();
	
	//Inform the Loading Dialog on how many Log Managers we have to load
	loadingDialog->setTabCount(modes.count());
	loadingDialog->setFirstLoading(true);
	
	int index=1;
	
	int mode;
	LogMode* logMode;
	
	for(it=modes.begin(); it!=modes.end(); ++it) {
		mode=*it;
		
		logMode=Globals::logModes.at(mode);
		//If the mode is not valid, we go to the next one
		if (logMode==NULL) {
			++index;
			++itGroupByColumn;
			++itGroupBy;
			continue;
		}
		
		//The specific opening file special case
		if (logMode==Globals::openingMode) {
			//If this file is not valid, we go to the next mode
			if (itString==fileList.end()) {
				++itString;
				++index;
				++itGroupByColumn;
				++itGroupBy;
				continue;
			}
			
			KURL file(*itString);
			
			//If this file is not valid, we go to the next mode
			if (!file.isValid()) {
				++itString;
				++index;
				++itGroupByColumn;
				++itGroupBy;
				continue;
			}
			
			ReaderFactory::lastOpenedURL=file;
			
			++itString;
		}
		
		//Inform the Loading Dialog that there is a new loading
		loadingDialog->setCurrentTab(index);
		
		//Create a new tab
		LogManager* manager=newTab();
		
		//If this file is not valid, we go to the next mode
		if (logMode==Globals::noMode) {
			++index;
			++itGroupByColumn;
			++itGroupBy;
			continue;
		}
		
		//Test the value from config file
		groupByType groupBy;
		if (itGroupBy==groupByTypes.end())
			groupBy=NO_GROUP_BY;
		else
			groupBy=(groupByType) (*itGroupBy);
		
		//Test the value from config file
		int groupByColumn;
		if (itGroupByColumn==groupByColumns.end())
			groupByColumn=-1;
		else
			groupByColumn=*itGroupByColumn;

		//Retrieve the group by parameters from configuration, and set them to the new manager
		manager->setGroupBy(groupBy, groupByColumn);
		
		//Open the matching mode to this tab
		this->load(logMode, activeLogManager());
			

		++index;
		++itGroupByColumn;
		++itGroupBy;
		
	}
	
	int selection=KSystemLogConfig::selectedTab();
	if (selection<0 || selection>=(int)logManagers.count())
		selection=0;

	kdDebug() << "Selection=" << selection << endl;
	
	tabs->setCurrentPage(selection);


	//Initialize the displaying of new items from config file
	bool value=KSystemLogConfig::newLinesDisplayed();
	newLinesDisplayedAction->setChecked(value);
	slotNewLinesDisplayed(value);

	//Initialize the enabling of Tooltip from config file
	value=KSystemLogConfig::tooltipEnabled();
	tooltipEnabledAction->setChecked(value);
	slotTooltipEnabled(value);
	
	//Reposition the count total to its default value
	loadingDialog->setTabCount(0);
	loadingDialog->setFirstLoading(false);
	
}


void KSystemLog::saveConfig() {
	kdDebug() << "Last configuration saving..." << endl;
	
	TQValueList<int> intList;
	TQStringList stringList;
	
	TQPtrListIterator<LogManager> it(logManagers);
	
	LogManager* manager=it.current();
	
	while(manager!=NULL) {
		//If it's an opening mode, then we save its open file
		if (manager->getLogMode()==Globals::openingMode) {
			//We retrieve the path of the URL of the first file of the file list of the current manager ;-)
			TQString file(manager->getLogFiles().first()->url.path());
			
			stringList.push_back(file);
		}
		
		intList.push_back(manager->getLogMode()->id);
		
		++it;
		manager=it.current();
	}
	
	//Save the log modes
	KSystemLogConfig::setLogModes(intList);
	
	//Save the file list (even if it is empty)
	KSystemLogConfig::setOpenedURLs(stringList);
	
	/**
	 * Save the group by type and the column
	 */
	TQValueList<int> groupByTypes;
	TQValueList<int> groupByColumns;
	
	it=logManagers;
	manager=it.current();
	while(manager!=NULL) {
		groupByTypes.push_back(manager->getGroupBy());
		groupByColumns.push_back(manager->getGroupByColumn());
		
		++it;
		manager=it.current();
	}
	
	//Save the group by types
	KSystemLogConfig::setGroupBy(groupByTypes);
	
	//Save the sort columns
	KSystemLogConfig::setGroupByColumns(groupByColumns);

	//Save the last selected tab
	KSystemLogConfig::setSelectedTab(tabs->currentPageIndex());

	it=logManagers;
	manager=it.current();
	while(manager!=NULL) {
		manager->saveConfig();
		
		++it;
		manager=it.current();
	}
	
	//Write the config to the file
	KSystemLogConfig::writeConfig();
}

void KSystemLog::logManagerReloaded() {
	//Update the detail dialog (because for the first reading, the logUpdated() signal is not sent)
	if (detailDialog!=NULL) {
		detailDialog->selectionChanged();
	}
	
	//Update Group By, because the currentTabChanged() slot is not called the first time we load a reader
	updateGroupBy();

	updateStatusBar();
	
	
	kdDebug() << "Log List reloaded..." << endl;
}

void KSystemLog::load(LogMode* logMode, LogManager* manager) {
	loadingDialog->setFirstLoading(true);
	
	if (manager==NULL || logMode==NULL) {
		kdDebug() << "Error while reloading a manager" << endl;
		return;
	}
	
	//The manager is now using the Log mode passed in parameter
	manager->initialize(logMode);
	
	//Launch the reading
	manager->reload();
	
	loadingDialog->setFirstLoading(false);

}


/** 
 * the 'config' object points to the session managed
 * config file.  anything you write here will be available
 * later when this app is restored
 */
void KSystemLog::saveProperties(KConfig* /*config*/) {
	kdDebug() << "saveProperties method." << endl;
}

/**
 * the 'config' object points to the session managed
 * config file.  this function is automatically called whenever
 * the app is being restored.  read in here whatever you wrote
 * in 'saveProperties'
 */
void KSystemLog::readProperties(KConfig* /*config*/) {
	kdDebug() << "readProperties method." << endl;
}

void KSystemLog::dragEnterEvent(TQDragEnterEvent *event) {
	//Accept URI drops only
	event->accept(KURLDrag::canDecode(event));
}

void KSystemLog::setupGroupBy() {
	groupBy=new KActionMenu(i18n("Group By"), SmallIcon(GROUP_BY_ICON), TQT_TQOBJECT(this), "group_by");
	actionCollection()->insert(groupBy);

	KPopupMenu* menu=groupBy->popupMenu();
	
	menu->insertItem(SmallIcon(NO_GROUP_BY_ICON), i18n("None"), NO_GROUP_BY);
	
	menu->insertSeparator();
	
	menu->insertItem(SmallIcon(GROUP_BY_LOG_LEVEL_ICON), i18n("Log Level"), GROUP_BY_LOG_LEVEL);

	menu->insertItem(SmallIcon(GROUP_BY_DAY_ICON), i18n("Day"), GROUP_BY_DAY);

	menu->insertItem(SmallIcon(GROUP_BY_HOUR_ICON), i18n("Hour"), GROUP_BY_HOUR);
	
	menu->insertItem(SmallIcon(GROUP_BY_LOG_FILE_ICON), i18n("Log File"), GROUP_BY_LOG_FILE);
	
	menu->insertSeparator();

	connect(menu, TQT_SIGNAL(activated(int)), TQT_TQOBJECT(this), TQT_SLOT(groupByChanged(int)));
	
}

void KSystemLog::groupByChanged(int group) {
	KPopupMenu* menu=groupBy->popupMenu();

	for(int i=0; i<(int) menu->count(); ++i) {
		menu->setItemChecked(menu->idAt(i), false);
	}
	
	menu->setItemChecked(group, true);
	
	LogManager* manager=activeLogManager();
	if (manager==NULL)
		return;
	
	int column=group-DEFAULT_GROUP_BY_COUNT;
	
	//If column<0, it means that we use a standard group by
	if (column<0) {
		kdDebug() << "Using a normal Group By : " << (groupByType)group << endl;
		manager->setGroupBy((groupByType)group);
	}
	//Else we use a specifical column
	else {
		kdDebug() << "Using a column Group By : column=" << column << endl;
		manager->setGroupBy(GROUP_BY_COLUMN, column);
	}
	
	reloadCurrent();
	
}

void KSystemLog::updateGroupBy() {

	kdDebug() << "Updating group by..." << endl;
	
	KPopupMenu* menu=groupBy->popupMenu();
	
	//First : removing old KAction
	//The deleting begins at default groupby count + 2 separator (in the menu)
	int deleting=DEFAULT_GROUP_BY_COUNT+2;
	int end=menu->count();
	for (int i=deleting; i<end; ++i) {
		menu->removeItemAt(deleting);
	}
	

	LogManager* manager=activeLogManager();
	
	if (manager==NULL) {
		return;
	}
	else {
		//Management of Expand and Collapse actions
		if (manager->getGroupBy()!=NO_GROUP_BY) {
			expandAllAction->setEnabled(true);
			collapseAllAction->setEnabled(true);
		}
		else {
			expandAllAction->setEnabled(false);
			collapseAllAction->setEnabled(false);
		}

		LogViewColumns* columns=manager->getColumns();
		if (columns==NULL)
			return;
		
		int id=DEFAULT_GROUP_BY_COUNT;
		LogViewColumns::Iterator it;
		LogViewColumn* column;
		for(it=columns->begin(); it!=columns->end(); it++) {
			column=*it;
			
			if (column->isGrouped) {
				menu->insertItem(column->columnName, id);
			}

			++id;
		}
		
	}
	
	//Get the selected GroupBy from (new) current LogManager and select it in the popup menu
	
	//First Deselect all items
	for(int i=0; i<(int) menu->count(); ++i) {
		menu->setItemChecked(menu->idAt(i), false);
	}
	
	
	//Then get the active manager and its group by value
	int selection=manager->getGroupBy();
	
	//If no selection, the first item is checked
	if (selection==0) {
		menu->setItemChecked(NO_GROUP_BY, true);
	}
	//If it's one of the predefined selection, we select the right item
	else if (selection!=GROUP_BY_COLUMN) {
		menu->setItemChecked(selection, true);
	}
	//Else, we select the corresponding column
	else {
		selection=selection + manager->getGroupByColumn();
		menu->setItemChecked(selection, true);
	}
	
		
	//Manage the disabling of default GroupBy choice
	LogViewColumns* columns=manager->getColumns();
	menu->setItemEnabled(GROUP_BY_LOG_LEVEL, columns->isGroupByLogLevel());
	menu->setItemEnabled(GROUP_BY_DAY, columns->isGroupByDay());
	menu->setItemEnabled(GROUP_BY_HOUR, columns->isGroupByHour());
	menu->setItemEnabled(GROUP_BY_LOG_FILE, columns->isGroupByLogFile());
	
}

/**
 * This is a very simplistic implementation of a drop event.  we
 * will only accept a dropped URL.  the TQt dnd code can do *much*
 * much more, so please read the docs there
 */
void KSystemLog::dropEvent(TQDropEvent *event) {
	KURL::List urls;
	
	//See if we can decode a URI
	if (KURLDrag::decode(event, urls) && !urls.isEmpty()) {
		//Several URI have been found
		ReaderFactory::lastOpenedURL=urls.first();
		
		this->load(Globals::openingMode, activeLogManager());
	}
}

void KSystemLog::updateGUI() {
	kapp->processEvents();
}


#include "ksystemlog.moc"