summaryrefslogtreecommitdiffabout
path: root/kaddressbook/old_mainwindow.cpp
blob: 7a445c71de9772e3343a9c481b247c02e20d3255 (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
#include <qlabel.h>
#include <qapp.h>
#include <qmessagebox.h>
#include <qaction.h>

#include <kdebug.h>	// defined kdDebug()
#include <klocale.h>	// defines i18n (microkde)

#include "kabprefs.h"

#ifndef DESKTOP_VERSION
#include <qpe/qpetoolbar.h>
#include <qpe/qpemenubar.h>
#include <qpe/resource.h>
#else
#include <qtoolbar.h>
#include <qmenubar.h>
#include <resource.h>
#endif

/*
#include <stdlib.h>

#include <qaction.h>
#include <qpainter.h>
#include <qwhatsthis.h>
#include <qpopupmenu.h>
#include <qmessagebox.h>
#include <qlineedit.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qwmatrix.h> 
#ifndef DESKTOP_VERSION
#include <qpe/global.h>
#include <qpe/qpemenubar.h>
#include <qpe/qpetoolbar.h>
#include <qpe/resource.h>
#include <qpe/qpeapplication.h>
#include <qtopia/alarmserver.h> 
#include <qtopia/qcopenvelope_qws.h> 
#else
#include <qtoolbar.h>
#include <qdir.h>
#include <qapplication.h>
//#include <resource.h>
#endif

#include <libkcal/calendarlocal.h>
#include <libkcal/todo.h>

//#include "calendarview.h"
//#include "koviewmanager.h"
//#include "koagendaview.h"
//#include "kodialogmanager.h"
//#include "kdialogbase.h"
//#include "koprefs.h"
//#include "kfiledialog.h"
//#include "koglobals.h"

//#include "kconfig.h"
//#include "simplealarmclient.h"
*/
//US using namespace KACore;


#include "mainwindow.h"

MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
    QMainWindow( parent, name )
{
    
#ifdef DESKTOP_VERSION
    setFont( QFont("Arial"), 14 );
#endif
//    mBlockAtStartup = true;
    kdDebug() << "MainWindow()::MainWindow()" << endl;
//    mFlagKeyPressed = false;
    setCaption("KAddressbook/Pi");
    
    KABPrefs *p = KABPrefs::instance();
    if ( QApplication::desktop()->height() > 480 ) {
//US        if ( p->mHourSize == 4 )
//US            p->mHourSize = 6;
    }  
                    
    QMainWindow::ToolBarDock tbd;
    if ( p->mToolBarHor ) {
        if ( p->mToolBarUp )
            tbd = Bottom;
        else
            tbd = Top;
    }
    else {
        if ( p->mToolBarUp )
            tbd = Right;
        else
            tbd = Left;
    }

    iconToolBar = new QPEToolBar( this );
    addToolBar (iconToolBar , tbd );
    
/*US    
    mBlockSaveFlag = false;
    mCalendarModifiedFlag = false;  
*/    
    QLabel* splash  = new QLabel(i18n("KA/Pi is starting ... "), this );
    splash->setAlignment ( AlignCenter );
    setCentralWidget( splash );
#ifndef DESKTOP_VERSION
    showMaximized();
#endif
    qDebug("Mainwidget x %d y %d w %d  h %d",  x(), y(), width(), height ());
//    setDefaultPreferences();
/*    mCalendar = new CalendarLocal();
    mView = new CalendarView( mCalendar, this,"mCalendar " );
    mView->hide();
    //mView->resize(splash->size() );
*/    
    initActions(); 
    
#ifndef DESKTOP_VERSION
//US    iconToolBar->show(); 
    qApp->processEvents();
#endif
    qDebug("Splashwidget x %d y %d w %d  h %d", splash-> x(), splash->y(), splash->width(),splash-> height ());
    
    int vh = height() ;
    int vw = width();
    qDebug("Toolbar hei %d ",iconToolBar->height() );
/*US    if ( iconToolBar->orientation () == Qt:: Horizontal ) {
        vh -=  iconToolBar->height();
    } else {
        vw -= iconToolBar->height();
    }
*/    
    //mView->setMaximumSize( splash->size() );
    //mView->resize( splash->size() );
    //qDebug("MainView x %d y %d w %d  h %d",  mView->x(),mView-> y(), mView->width(), mView->height ());
/*    mView->readSettings(); 
    if( !QFile::exists( defaultFileName() ) ) {
        mView->saveCalendar( defaultFileName() );
    }
    mView->openCalendar( defaultFileName() );
    processIncidenceSelection( 0 );
    connect( mView, SIGNAL( incidenceSelected( Incidence * ) ),
             SLOT( processIncidenceSelection( Incidence * ) ) );
    connect( mView, SIGNAL( modifiedChanged( bool ) ),
             SLOT( slotModifiedChanged( bool ) ) );
    connect( mView, SIGNAL( signalmodified() ),
             SLOT( checkAlarms( ) ) );

    connect( &mSaveTimer, SIGNAL( timeout() ), SLOT( save() ) );
    connect( &alarmTimer, SIGNAL( timeout() ), SLOT( writeAlarm() ) );
    mView->setModified( false );
    mBlockAtStartup = false;
    mView->setModified( false );
    setCentralWidget( mView );
    mView->show();
*/    
    delete splash; 
    
    qApp->processEvents();
//US    qDebug("MainView x %d y %d w %d  h %d",  mView->x(),mView-> y(), mView->width(), mView->height ());

}
MainWindow::~MainWindow()
{
    qDebug("MainWindow::~MainWindow() ");
    kdDebug() << "MainWindow()::~MainWindow()" << endl;
    //save toolbar location 
/*    
    KOPrefs *p = KOPrefs::instance();
    p->mToolBarHor = ( iconToolBar->orientation () == Qt:: Horizontal );
    p->mToolBarUp = iconToolBar->x() > width()/2 ||
        iconToolBar->y() > height()/2;
    alarmTimer.stop();
    mView->writeSettings();
    writeAlarm();
    if ( mCalendarModifiedFlag )
        save();
    delete mCalendar;
*/    
}


void MainWindow::closeEvent( QCloseEvent* ce )
{

    if ( ! KABPrefs::instance()->mAskForQuit ) {

        ce->accept();
        return;

    }

   switch( QMessageBox::information( this, "KA/Pi",
                                      i18n("Do you really want\nto close KA/Pi?"),
                                      i18n("Close!"), i18n("No"), 
				      0, 0 ) ) {
    case 0:
        ce->accept();
        break;
    case 1:
        ce->ignore(); 
	break;
    case 2:
       
    default:
      break;
    }


}


void MainWindow::recieve( const QCString& cmsg, const QByteArray& data )
{
/*
    QDataStream stream( data, IO_ReadOnly );
    // QMessageBox::about( this, "About KOrganizer/Pi", "*" +msg +"*" );
   
    
    if ( cmsg == "-writeFile" ) {
        mView->viewManager()->showWhatsNextView();
        save();
        setCaption( i18n("File written on AD request"));
        showMaximized();
        raise();
#ifndef DESKTOP_VERSION
        QCopEnvelope e3("kosaved", "blabla");
#endif
        return;
       
    }
    if ( cmsg == "-newCountdown" ) {
       qDebug("newCountdown ");
       
    }
    QString msg ;;
    QString allmsg = cmsg;
    while ( allmsg.length() > 0 ) {
        int nextC = allmsg.find( "-", 1 );
        if ( nextC == -1 ) {
            msg = allmsg;
            allmsg = "";
        } else{
            msg = allmsg.left( nextC );
            allmsg = allmsg.mid( nextC,  allmsg.length()-nextC );
        }
        //qDebug("msg: %s  all: %s ", msg.latin1(), allmsg.latin1() );
        if ( msg == "-newEvent" ) {
            mView->newEvent();
        }
        if ( msg == "-newTodo" ) {
            mView->newTodo();
            
        } 
        if ( msg == "-showWN" ) {
            mView->viewManager()->showWhatsNextView();
        }
        if ( msg == "-showTodo" ) {
            mView->viewManager()->showTodoView();
        }
        if ( msg == "-showList"  ) {
            mView->viewManager()->showListView();
        }
        else if ( msg == "-showDay" ) {
            mView->viewManager()->showDayView();
        }
        else if ( msg == "-showWWeek"  ) {
            mView->viewManager()->showWorkWeekView();
        }
        else if ( msg == "-showWeek" ) {
            mView->viewManager()->showWeekView();
        }
        else if ( msg == "-showTodo" ) {
            mView->viewManager()->showTodoView();
        }
        else if ( msg == "-showJournal"  ) {
            mView->viewManager()->showJournalView();
        }
        else if ( msg == "-showKO" ) {
            mView->viewManager()->showNextXView();
        }
        else if ( msg == "-showWNext" ) {
            mView->viewManager()->showWhatsNextView();
        }
    }

    showMaximized();
    raise();
*/    
}


QPixmap MainWindow::loadPixmap( QString name )
{
  return KGlobal::iconLoader().loadPixmap( name );
/*US use the advanced version of the iconloader
#ifdef DESKTOP_VERSION
    QPixmap pixmapLoader; 
    QString file;
    file = QDir::homeDirPath()+"/kaddressbook/pics/" + name+".png";
    //qDebug("pixmap name %s ", file.latin1());
    pixmapLoader.load( file );
    return pixmapLoader;
#else
 return Resource::loadPixmap( name ); 
#endif
*/
}

void MainWindow::initActions()
{
    iconToolBar->clear();
    KABPrefs *p = KABPrefs::instance();
    QPEMenuBar *menuBar1 = new QPEMenuBar( iconToolBar );
    Q3PopupMenu *menuBar = new Q3PopupMenu( this );
    menuBar1->insertItem( "ME", menuBar);
    Q3PopupMenu *fileMenu = new Q3PopupMenu( this );
    Q3PopupMenu *editMenu = new Q3PopupMenu( this );
    Q3PopupMenu *viewMenu = new Q3PopupMenu( this );
    Q3PopupMenu *settingsMenu = new Q3PopupMenu( this );
    Q3PopupMenu *importMenu = new Q3PopupMenu( this );

    menuBar1->setMaximumWidth( menuBar1->sizeHint().width() );

    QIconSet icon;


    icon = loadPixmap( pathString + "newtodo" );
    configureToolBarMenu->insertItem(icon, "New todo", 20 );
    QAction* nt_action = new QAction( "New Todo", icon, "New Todo...", 0, this );
    nt_action->addTo( actionMenu );
    connect( nt_action, SIGNAL( activated() ),
             mView, SLOT( newTodo() ) );
    
/*
    QAction *action;
    QIconSet icon;
    // QPopupMenu *configureMenu= new QPopupMenu( menuBar );
    configureToolBarMenu = new QPopupMenu( this );
    configureToolBarMenu->setCheckable( true );
#ifdef DESKTOP_VERSION
    QString pathString = ""; 
#else
    QString pathString = "kaddressbook/"; 
#endif
    if ( QApplication::desktop()->width() < 480 ) 
        pathString += "icons16/";
    configureAgendaMenu = new QPopupMenu( menuBar );
    configureAgendaMenu->setCheckable( true );
    configureAgendaMenu->insertItem("Toggle Allday", 1 ); 
    configureAgendaMenu->insertSeparator(); 
    configureAgendaMenu->insertItem("Tiny", 4 ); 
    configureAgendaMenu->insertItem("Small", 6 );
    configureAgendaMenu->insertItem("Medium", 8 );
    configureAgendaMenu->insertItem("Normal", 10 );  
    configureAgendaMenu->insertItem("Large", 12 );  
    configureAgendaMenu->insertItem("Big", 14 );    
    configureAgendaMenu->insertItem("Bigger", 16 );   
    configureAgendaMenu->insertItem("Biggest", 18 );   
    //configureMenu->insertItem( "AgendaSize",configureAgendaMenu  );  
    icon = loadPixmap( pathString + "newevent" );  
    icon = loadPixmap( pathString + "newevent" ); 
    configureToolBarMenu->insertItem("Stretched TB", 5 ); 
    configureToolBarMenu->insertSeparator(); 
    configureToolBarMenu->insertItem(icon, "New event", 10 );
    QAction* ne_action = new QAction( "New Event", icon, "New Event...", 0, this );
    ne_action->addTo( actionMenu );
*/    
/*
    connect( ne_action, SIGNAL( activated() ),
             mView, SLOT( newEvent() ) );
    icon = loadPixmap( pathString + "newtodo" ); 
    configureToolBarMenu->insertItem(icon, "New todo", 20 ); 
    QAction* nt_action = new QAction( "New Todo", icon, "New Todo...", 0, this );
    nt_action->addTo( actionMenu );
    connect( nt_action, SIGNAL( activated() ),
             mView, SLOT( newTodo() ) );

    action = new QAction( "Toggle FilterView", QPixmap(), "Toggle FilterView", 0, this );
    action->addTo( viewMenu );
    connect( action, SIGNAL( activated() ),
             mView, SLOT( toggleFilter() ) );

    viewMenu->insertSeparator();
    icon = loadPixmap( pathString + "picker" );
    action = new QAction( "Date Picker", icon, "Date Picker", 0, this );
    action->addTo( viewMenu );
    connect( action, SIGNAL( activated() ),
             mView, SLOT( showDatePicker() ) );
    action->addTo( iconToolBar  );
    viewMenu->insertSeparator();
    icon = loadPixmap( pathString + "list" );  
    configureToolBarMenu->insertItem(icon, "Event list", 30 ); 
    QAction* showlist_action = new QAction( "List", icon, "List", 0, this );
    showlist_action->addTo( viewMenu );
    connect( showlist_action, SIGNAL( activated() ),
             mView->viewManager(), SLOT( showListView() ) );


    icon = loadPixmap( pathString + "day" );  
    configureToolBarMenu->insertItem(icon, "One day", 40 ); 
    QAction* day1_action = new QAction( "Day", icon, "Day", 0, this );
    day1_action->addTo( viewMenu );
    //  action->addTo( toolBar );
    connect( day1_action, SIGNAL( activated() ),
             mView->viewManager(), SLOT( showDayView() ) );

    icon = loadPixmap( pathString + "workweek" ); 
    configureToolBarMenu->insertItem(icon, "Work week", 50 );  
    QAction* day5_action = new QAction( "Work Week", icon, "Work Week", 0, this );
    day5_action->addTo( viewMenu );
    connect( day5_action, SIGNAL( activated() ),
             mView->viewManager(), SLOT( showWorkWeekView() ) );

    icon = loadPixmap( pathString + "week" );
    configureToolBarMenu->insertItem(icon, "Week", 60 );    
    QAction* day7_action = new QAction( "Week", icon, "Week", 0, this );
    day7_action->addTo( viewMenu );
    connect( day7_action, SIGNAL( activated() ),
             mView->viewManager(), SLOT( showWeekView() ) );

    icon = loadPixmap( pathString + "month" ); 
    configureToolBarMenu->insertItem(icon, "Month", 70 );  
    QAction* month_action = new QAction( "Month", icon, "Month", 0, this );
    month_action->addTo( viewMenu );
    connect( month_action, SIGNAL( activated() ),
             mView->viewManager(), SLOT( showMonthView() ) );

    icon = loadPixmap( pathString + "todo" );  
    configureToolBarMenu->insertItem(icon, "Todo list", 80 );  
    QAction* todoview_action = new QAction( "Todo", icon, "Todo", 0, this );
    todoview_action->addTo( viewMenu );
    connect( todoview_action, SIGNAL( activated() ),
             mView->viewManager(), SLOT( showTodoView() ) );

    icon = loadPixmap( pathString + "journal" );  
    configureToolBarMenu->insertItem(icon, "Journal", 90 );  
    QAction* viewjournal_action = new QAction( "Journal", icon, "Journal", 0, this );
    viewjournal_action->addTo( viewMenu );
    connect( viewjournal_action, SIGNAL( activated() ),
             mView->viewManager(), SLOT( showJournalView() ) );

    icon = loadPixmap( pathString + "xdays" );  
    configureToolBarMenu->insertItem(icon, "Next days", 100,4 );  
    QAction* xdays_action = new QAction( "Next days", icon, "Next Days", 0, this );
    xdays_action->addTo( viewMenu );
    connect( xdays_action, SIGNAL( activated() ),
             mView->viewManager(), SLOT( showNextXView() ) );

    icon = loadPixmap( pathString + "whatsnext" );  
    configureToolBarMenu->insertItem(icon, "Whats next", 110, 4 );  
    QAction* whatsnext_action = new QAction( "What's Next", icon, "What's Next", 0, this ); 
    whatsnext_action->addTo( viewMenu );
    connect( whatsnext_action, SIGNAL( activated() ),
             mView->viewManager(), SLOT( showWhatsNextView() ) );

#if 0
    action = new QAction( "view_timespan", "Time Span", 0, this );
    action->addTo( viewMenu );
    connect( action, SIGNAL( activated() ),
             mView->viewManager(), SLOT( showTimeSpanView() ) );
#endif

    menuBar->insertItem( "View", viewMenu );


#if 0
    QPopupMenu *navigationMenu = new QPopupMenu( menuBar );
  
    action = new QAction( "Go backward", "Go Backward", 0, navigationMenu );
    action->addTo( navigationMenu );
    connect( action, SIGNAL( activated() ),
             mView, SLOT( goPrevious() ) );

    action = new QAction( "Go forward", "Go Forward", 0, navigationMenu );
    action->addTo( navigationMenu );
    connect( action, SIGNAL( activated() ),
             mView, SLOT( goNext() ) );

    menuBar->insertItem( "Go", navigationMenu );
#endif


  

 

    mNewSubTodoAction = new QAction( "new_subtodo", "New Sub-Todo...", 0,
                                     this );
    mNewSubTodoAction->addTo( actionMenu );
    connect( mNewSubTodoAction, SIGNAL( activated() ),
             mView, SLOT( newSubTodo() ) );

    actionMenu->insertSeparator();

    mShowAction = new QAction( "show_incidence", "Show...", 0, this );
    mShowAction->addTo( actionMenu );
    connect( mShowAction, SIGNAL( activated() ),
             mView, SLOT( showIncidence() ) );

    mEditAction = new QAction( "edit_incidence", "Edit...", 0, this );
    mEditAction->addTo( actionMenu );
    connect( mEditAction, SIGNAL( activated() ),
             mView, SLOT( editIncidence() ) );

    mDeleteAction = new QAction( "delete_incidence", "Delete...", 0, this );
    mDeleteAction->addTo( actionMenu );
    connect( mDeleteAction, SIGNAL( activated() ),
             mView, SLOT( deleteIncidence() ) );

    actionMenu->insertSeparator();

    action = new QAction( "purge_completed", i18n("Purge Completed"), 0,
                          this );
    action->addTo( actionMenu );
    connect( action, SIGNAL( activated() ), mView, SLOT( purgeCompleted() ) );

    icon = loadPixmap( pathString + "search" );  
    QAction* search_action = new QAction( "search", icon, "Search...", 0, this );
    configureToolBarMenu->insertItem(icon, "Search", 120 , 4);  
    search_action->addTo( actionMenu );
    connect( search_action, SIGNAL( activated() ),
             mView->dialogManager(), SLOT( showSearchDialog() ) );

    icon = loadPixmap( pathString + "today" );  
    configureToolBarMenu->insertItem(icon, "Today", 130);  
    QAction* today_action = new QAction( "Today", icon, "Go to Today", 0, this );
    today_action->addTo( actionMenu );
    connect( today_action, SIGNAL( activated() ),
             mView, SLOT( goToday() ) );

    //#if 0
    actionMenu->insertSeparator();

    action = new QAction( "configure", "Configure...", 0, this );
    action->addTo( actionMenu );
    connect( action, SIGNAL( activated() ),
             mView, SLOT( edit_options() ) );
    //#endif

    // actionMenu->insertSeparator();
    action = new QAction( "import_qtopia", "Import (*.ics/*.vcs) file", 0,
                          this );
    action->addTo( importMenu );
    connect( action, SIGNAL( activated() ), SLOT( importIcal() ) );
    action = new QAction( "import_quick", "Import last file", 0,
                          this );
    action->addTo( importMenu );
    connect( action, SIGNAL( activated() ), SLOT( quickImportIcal() ) );
    importMenu->insertSeparator();
    action = new QAction( "import_qtopia", "Import Opie/Qtopia Cal.", 0,
                          this );
    action->addTo( importMenu );
    importMenu->insertSeparator();
    connect( action, SIGNAL( activated() ), SLOT( importQtopia() ) );

    action = new QAction( "load_cal", "Load Calendar Backup", 0,
                          this );
    action->addTo( importMenu );
    connect( action, SIGNAL( activated() ), SLOT( loadCalendar() ) );

    action = new QAction( "save_cal", "Save Calendar Backup", 0,
                          this );
    action->addTo( importMenu );
    connect( action, SIGNAL( activated() ), SLOT( saveCalendar() ) );

    importMenu->insertSeparator();
    action = new QAction( "import_qtopia", "Export VCalendar", 0,
                          this );
    action->addTo( importMenu );
    connect( action, SIGNAL( activated() ), SLOT( exportVCalendar() ) );
  

    QPopupMenu *syncMenu = new QPopupMenu( this );
    action = new QAction( "syncssh", "Remote via ssh/scp(not implemented)", 0,
                          this );
    action->addTo( syncMenu );
    connect( action, SIGNAL( activated() ), SLOT( syncSSH() ) );
    action = new QAction( "synclocal", "With local file(not implemented)", 0,
                          this );
    action->addTo( syncMenu );
    connect( action, SIGNAL( activated() ), SLOT( syncLocalFile() ) );
    action = new QAction( "quicksynclocal", "With last file(not implemented)", 0,
                          this );
    action->addTo( syncMenu );
    connect( action, SIGNAL( activated() ), SLOT( quickSyncLocalFile() ) );

    menuBar->insertItem( "Actions", actionMenu );
    menuBar->insertItem( "Load/Save", importMenu );
    menuBar->insertItem( "Synchronize", syncMenu );
    //menuBar->insertItem( "Configure",configureMenu );
    //configureMenu->insertItem( "Toolbar",configureToolBarMenu  ); 
    menuBar->insertItem( "AgendaSize",configureAgendaMenu  ); 
    menuBar->insertItem( "Toolbar",configureToolBarMenu ); 
    QPopupMenu *helpMenu = new QPopupMenu( menuBar );
    icon = loadPixmap( "korganizer/korganizer" ); 
    action = new QAction( "Key bindings", "Key Bindings...", 0, this );
    action->addTo( helpMenu );
    connect( action, SIGNAL( activated() ),
             SLOT( keyBindings() ) ); 
    action = new QAction( "Auto saving", "Auto saving...", 0, this );
    action->addTo( helpMenu );
    connect( action, SIGNAL( activated() ),
             SLOT( aboutAutoSaving() ) ); 
    action = new QAction( "Problemd", "Known Problems...", 0,this );
    action->addTo( helpMenu );
    connect( action, SIGNAL( activated() ),
             SLOT( aboutKnownBugs() ) ); 
    action = new QAction( "about", "About...", 0, this );
    action->addTo( helpMenu );
    connect( action, SIGNAL( activated() ),
             SLOT( about() ) );
    menuBar->insertItem( "Help", helpMenu );  
*/
    //menuBar->insertSeparator();

    // ******************************************************
    // menubar icons 
    
    
    iconToolBar->setHorizontalStretchable (true ); 
    //menuBar->insertItem( iconToolBar );
    //xdays_action
/*
    if (p-> mShowIconNewEvent)
        ne_action->addTo( iconToolBar  );
    if (p->mShowIconNewTodo )
        nt_action->addTo( iconToolBar  );
    if (p-> mShowIconSearch)
        search_action->addTo( iconToolBar  );
    if (p-> mShowIconNext)
        whatsnext_action->addTo( iconToolBar  );
    if (p-> mShowIconNextDays)
        xdays_action->addTo( iconToolBar  );
    if (p-> mShowIconList)
        showlist_action->addTo( iconToolBar  );
    if (p-> mShowIconDay1)
        day1_action->addTo( iconToolBar  );
    if (p-> mShowIconDay5)
        day5_action->addTo( iconToolBar  );
    if (p-> mShowIconDay7)
        day7_action->addTo( iconToolBar  );
    if (p-> mShowIconMonth)
        month_action->addTo( iconToolBar  );
    if (p-> mShowIconTodoview)
        todoview_action->addTo( iconToolBar  );
    if (p-> mShowIconJournal)
        viewjournal_action->addTo( iconToolBar  );
    icon = loadPixmap( pathString + "2leftarrowB" );
    configureToolBarMenu->insertItem(icon, "Prev. month", 200, 14);  
    if (p-> mShowIconBackFast) {
        action = new QAction( "Prev month", icon, "Go Backward",0 , this );
        connect( action, SIGNAL( activated() ),
                 mView, SLOT( goPreviousMonth() ) );
        action->addTo( iconToolBar  );
    }
    icon = loadPixmap( pathString + "1leftarrowB" );
    configureToolBarMenu->insertItem(icon, "Go previous", 210,15);  
    if (p-> mShowIconBack) {
        action = new QAction( "Go previous", icon, "Go Backward",0 , this );
        connect( action, SIGNAL( activated() ),
                 mView, SLOT( goPrevious() ) );
        action->addTo( iconToolBar  );
    }
    if (p-> mShowIconToday) 
        today_action->addTo( iconToolBar  );
    icon = loadPixmap( pathString + "1rightarrowB" );
    configureToolBarMenu->insertItem(icon, "Go next", 220); 
    if (p-> mShowIconForward) {
        action = new QAction( "Go next", icon, "Go Backward",0 , this );
        connect( action, SIGNAL( activated() ),
                 mView, SLOT( goNext() ) );
        action->addTo( iconToolBar  );
    }
    icon = loadPixmap( pathString + "2rightarrowB" );
    configureToolBarMenu->insertItem(icon, "Next month", 230);  
    if (p-> mShowIconForwardFast) {
        action = new QAction( "Next month", icon, "Go Backward",0 , this );
        connect( action, SIGNAL( activated() ),
                 mView, SLOT( goNextMonth() ) );
        action->addTo( iconToolBar  );
    }
*/  
   
    configureToolBarMenu->insertItem("WhatsThis", 300); 
/*
    if (p-> mShowIconNewEvent)
        configureToolBarMenu->setItemChecked( 10, true );
    if (p->mShowIconNewTodo )
        configureToolBarMenu->setItemChecked( 20, true );
    if (p-> mShowIconSearch)
        configureToolBarMenu->setItemChecked( 120, true );
    if (p-> mShowIconList)
        configureToolBarMenu->setItemChecked( 30, true );
    if (p-> mShowIconDay1)
        configureToolBarMenu->setItemChecked( 40, true );
    if (p-> mShowIconDay5)
        configureToolBarMenu->setItemChecked( 50, true );
    if (p-> mShowIconDay7)
        configureToolBarMenu->setItemChecked( 60, true );
    if (p-> mShowIconMonth)
        configureToolBarMenu->setItemChecked( 70, true );
    if (p-> mShowIconTodoview)
        configureToolBarMenu->setItemChecked( 80, true );
    if (p-> mShowIconBackFast)
        configureToolBarMenu->setItemChecked( 200, true );
    if (p-> mShowIconBack) 
        configureToolBarMenu->setItemChecked( 210, true );
    if (p-> mShowIconToday)
        configureToolBarMenu->setItemChecked( 130, true ); 
    if (p-> mShowIconForward)
        configureToolBarMenu->setItemChecked( 220, true );
    if (p-> mShowIconForwardFast)
        configureToolBarMenu->setItemChecked( 230, true );
    if (p-> mShowIconNextDays)
        configureToolBarMenu->setItemChecked( 100, true );
    if (p-> mShowIconNext)
        configureToolBarMenu->setItemChecked( 110, true );
    if (p-> mShowIconJournal)
        configureToolBarMenu->setItemChecked( 90, true );
    if (p-> mShowIconWhatsThis)
        configureToolBarMenu->setItemChecked( 300, true );

    QLabel* dummy = new QLabel( iconToolBar );
    dummy->setBackgroundColor( iconToolBar->backgroundColor() );
    if (!p-> mShowIconStretch)
        iconToolBar->setStretchableWidget ( dummy ) ;
    else
        configureToolBarMenu->setItemChecked( 5, true );
    if (p-> mShowIconWhatsThis)
        QWhatsThis::whatsThisButton (  iconToolBar );
    connect( configureToolBarMenu, SIGNAL( activated( int ) ),this,  SLOT(configureToolBar( int ) ) ); 
    configureAgenda( p->mHourSize );
    connect( configureAgendaMenu, SIGNAL( activated( int ) ),this,  SLOT(configureAgenda( int ) ) );
*/    
}
/*
void MainWindow::setDefaultPreferences()
{
    KOPrefs *p = KOPrefs::instance();

    p->mCompactDialogs = true;
    p->mConfirm = true;
    p->mEnableQuickTodo = false;
}
*/
void MainWindow::about()
{
    QMessageBox::about( this, "About KOrganizer/Pi",
                        "KOrganizer/Platform-independent\n"
                        "(KO/Pi) 1.6.0e - "
#ifdef DESKTOP_VERSION
                        "Desktop Edition\n"
#else
                        "PDA-Edition\n"
                        "for: Zaurus 5500 / 7x0 / 8x0\n"
#endif
                        "(c) 2004 Lutz Rogowski\n"
                        "Email:lutz@pi-sync.net\n"
                        "KO/Pi is based on KOrganizer\n"
                        "(c) 2002,2003 Cornelius Schumacher\n"
                        "Email: schumacher@kde.org\n"
                        "KOrganizer/Pi is licensed\n"
                        "under the GPL.\n"
                        "KO/Pi can be compiled for\n"
                        "Linux, Zaurus-PDA and Windows\n"
                        "www.korganizer.org\n" );
}
/*
void MainWindow::keyBindings()
{
    QMessageBox* msg;
    msg = new QMessageBox( "Key bindings  KOrganizer/Pi",
                           "Space: Toggle Fullscreen | P: Date Picker\n"
                           "H: This dialog | I: Show info | S: Search\n"
                           "F: Toggle Filterview | 1-4: Select Filter\n"
                           "N: Show next days | W: Whats next\n "
                           "V: Todo view | L: Event list view\n"
                           "T: Goto today | T+<ctrl>: New Todo\n"
                           "E: Edit item | E+<ctrl>: New Event\n"
                           "5: Work week view | 7: Week view\n"
                           "D: One day view | M: Month view\n"
                           "+,- : Zoom in/out Agenda | A: Toggle Allday\n"
                           "<ctrl>+<up>/<down>: Scroll todo view\n"
                           "<right>,C: Next week | <right>+<ctrl>: Next month\n"
                           "<left>,X: Prev. week | <left>+<ctrl>: Prev. month\n"
                           "<del>,<backspace>: Delete sel. item\n",
                           QMessageBox::NoIcon,
                           QMessageBox::Ok,
                           QMessageBox::NoButton,
                           QMessageBox::NoButton );
    msg->exec();
    delete msg;
  
}
void MainWindow::aboutAutoSaving()
{
    QMessageBox* msg;
    msg = new QMessageBox(  "Auto Saving in  KOrganizer/Pi",
                            "After changing something, the data is\n"
                            "automatically saved to the file\n"
                            "~/Applications/korganizer/mycalendar.ics\n "
                            "after (configureable) one minute.\n"
                            "For safety reasons there is  one autosaving\n"
                            "after 10 minutes (of idle time) again. The \n"
                            "data is saved automatically when closing KO/Pi\n"
                            "You can create a backup file \n"
                            "with: Load/Save - Save Calendar Backup\n",
                            QMessageBox::NoIcon,
                            QMessageBox::Ok,
                            QMessageBox::NoButton,
                            QMessageBox::NoButton);
    msg->exec();
    delete msg;
  
                          
}
void MainWindow::aboutKnownBugs()
{
    QMessageBox* msg;
    msg = new QMessageBox(  "Known Problems in  KOrganizer/Pi",
                            "1) The QWhatsThis help is not working.\n"
                            "There is only a black rectangle displayed\n"
                            "when clicking on an event.\n "
                            "2) Audio alarm is available!\n"
                            "as an additional small application\n"
                            "3) Syncing is missing.\n"
                            "Syncing via ssh/scp will be available in\n"
                            "KOrganizer/Pi 2.0\n"
                            "\n"
                            "Please report unexpected behaviour to\n"
                            "lutz@pi-sync.net\n",
                            QMessageBox::NoIcon,
                            QMessageBox::Ok,
                            QMessageBox::NoButton,
                            QMessageBox::NoButton);
    msg->exec();
    delete msg;
  
}

QString MainWindow::defaultFileName()
{
#ifndef DESKTOP_VERSION
    return Global::applicationFileName( "korganizer", "mycalendar.ics" );
#else
    // pending
    QString file;
    file = QDir::homeDirPath()+"/korganizer/mycalendar.ics";
    return QDir::convertSeparators( file );
#endif
}

void MainWindow::processIncidenceSelection( Incidence *incidence )
{
    if ( !incidence ) {
        enableIncidenceActions( false );
  
        mNewSubTodoAction->setEnabled( false );  
        setCaptionToDates();
        return;
        
  }
 
  QString startString = "";
  if ( incidence->type() != "Todo" ) { 
      if ( incidence->dtStart().date() < incidence->dtEnd().date()   ) { 
          startString = ": "+incidence->dtStart().time().toString().left(5);
          startString += " "+ incidence->dtStart().date().toString();
          startString += "-"+incidence->dtEnd().time().toString().left(5);
          startString += " "+ incidence->dtEnd().date().toString();
      
      } else {
          if ( incidence->dtStart().time() != incidence->dtEnd().time() )
              startString = ": "+incidence->dtStart().time().toString().left(5)+"-"+incidence->dtEnd().time().toString().left(5);
          startString +=" "+incidence->dtStart().date().toString(); 
      }
       
  }
   else
       startString = ": (Prio "+QString::number( (( KCal::Todo*)incidence)->priority() ) +") "+QString::number( (( KCal::Todo*)incidence)->percentComplete() ) +"\% completed";

   setCaption( incidence->summary()+startString);
   
   enableIncidenceActions( true );
  
  if ( incidence->type() == "Event" ) {
    mShowAction->setText( i18n("Show Event...") );
    mEditAction->setText( i18n("Edit Event...") );
    mDeleteAction->setText( i18n("Delete Event...") );

    mNewSubTodoAction->setEnabled( false );
  } else if ( incidence->type() == "Todo" ) {
    mShowAction->setText( i18n("Show Todo...") );
    mEditAction->setText( i18n("Edit Todo...") );
    mDeleteAction->setText( i18n("Delete Todo...") );

    mNewSubTodoAction->setEnabled( true );
  } else {
    mShowAction->setText( i18n("Show...") );
    mShowAction->setText( i18n("Edit...") );
    mShowAction->setText( i18n("Delete...") );

    mNewSubTodoAction->setEnabled( false );
  }
}

void MainWindow::enableIncidenceActions( bool enabled )
{
  mShowAction->setEnabled( enabled );
  mEditAction->setEnabled( enabled );
  mDeleteAction->setEnabled( enabled );
}

void MainWindow::importQtopia()
{
#ifndef DESKTOP_VERSION
    int result = QMessageBox::warning( this, "KO/Pi: Warning!",
                                       "When importing a calendar twice\n"
                                       "duplicated events will be ignored!\n"
                                       "You can create a backup file with\n"
                                       "Load/Save - Save Calendar Backup\n"
                                       "to revert importing",
                                       "Import!", "Cancel", 0,
                                       0, 1 );
    if ( result == 0 ) {
        QString datebook = Global::applicationFileName( "datebook", "datebook.xml");
        QString todolist = Global::applicationFileName( "todolist", "todolist.xml");
        QString categories = QString( getenv( "HOME" ) ) + "/Settings/Categories.xml";
        mView->importQtopia( categories, datebook, todolist );
    }
#else
 int result = QMessageBox::warning( this, "KO/Pi: Warning!",
                                       "NOT SUPPORTED \n"
                                       "ON DESKTOP!\n",
                                       "OK", "Cancel", 0,
                                       0, 1 );

#endif 
}
void MainWindow::checkAlarms()
{ 
    if ( mBlockAtStartup )
        return;
    alarmTimer.start( 1000 * 3);
  
}
void MainWindow::slotModifiedChanged( bool changed )
{
    if ( mBlockAtStartup )
        return;
    int msec;
  // we store the changes after 1 minute, 
  // and for safety reasons after 10 minutes again
  if ( !mBlockSaveFlag )
      msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000;
  else
      msec = 1000 * 600;
  mSaveTimer.start( msec, true ); // 1 minute
  qDebug("KO: Saving File in %d secs!", msec/1000);
  mCalendarModifiedFlag = true;
}
void MainWindow::writeAlarm()
{
    if ( mBlockAtStartup )
        return;
    //QCopEnvelope e3("koalarm", "-showWN");
    QDateTime nextA ;
    QDateTime reference ( QDate( 2000, 1, 1 ) ); 
    QString summary; 
    alarmTimer.stop();
    Calendar* cal =  mView->calendar();
    if ( ! cal ){
        qDebug("KO: Calendar undefined. No alarm notification");
        return;
    }
    nextA = cal->nextAlarm( 720 );
    summary = cal->nextSummary();
    qDebug("KO: Next Alarm %s %s", nextA.toString().latin1(), summary.latin1());
    if (  nextA < QDateTime::currentDateTime().addDays(  720-1 ) ) {
        KConfig *config = KOGlobals::config();
        config->setGroup("NextSystemAlarm");
        QString date, sum;
        date = config->readEntry("TimeDateinSecs", "xxx");
        bool ok = false;
        int shsecs = date.toInt(&ok );
        QDateTime scheduledAlarm;
        QDateTime eventDateTime =  cal->nextAlarmEvent();
        sum = config->readEntry("Summary", "sss");
        if ( ok ) {
            scheduledAlarm = reference.addSecs( shsecs );
            //qDebug("sheduledAlarm %s ", scheduledAlarm.toString().latin1());
            if ( scheduledAlarm == nextA && sum == summary ) {
                qDebug("KO: Same alarm time+summary - nothing to do! ");
                return;
            }
        }
        if ( ok ) {
            // delete alarm from system
            //qDebug("delete Alarm %s ", scheduledAlarm.toString().latin1());
#ifndef DESKTOP_VERSION
            AlarmServer::deleteAlarm ( scheduledAlarm,"koalarm"  , sum.latin1() );
#endif          
        }
        // add new alarm to system
        qDebug("KO: Add Alarm: %s ", nextA.toString().latin1() );
#ifndef DESKTOP_VERSION
        AlarmServer::addAlarm ( nextA,"koalarm", summary.latin1() );
#endif  
        // write new alarm to config file
        //qDebug("Entry %s %s  ", date.latin1(), sum.latin1());
        int secs = reference.secsTo( nextA );
        //qDebug(" secs %d ", secs);
        setCaption( i18n("Next Alarm: ")+ nextA.toString() +"-"+summary );
        config->writeEntry("TimeDateinSecs",QString::number ( secs ));
        config->writeEntry("Summary",summary);
        config->writeEntry("TimeDate",nextA.toString());
        config->writeEntry("WriteDateTime",QDateTime::currentDateTime().toString()); 
        config->writeEntry("EventStartDateTime",eventDateTime.toString());
        config->writeEntry("SystemNotifyInSecs",QString::number (QDateTime::currentDateTime().secsTo( nextA  ) ));
        config->sync();
        
    }
}
void MainWindow::save()
{
    if ( mBlockSaveFlag ) 
        return;
 
  mBlockSaveFlag = true;
  QTime neededSaveTime = QDateTime::currentDateTime().time();
  setCaption("KO/Pi:Saving Data to File ..." );
  qDebug("KO: Start saving data to file!");
  mView->saveCalendar( defaultFileName() );
  int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() );
  qDebug("KO: Needed %d ms for saving.",msNeeded );
  QString savemes;
  savemes.sprintf("KO/Pi:File Saved. Needed %d sec, %d ms",(msNeeded/1000)%100,msNeeded%1000  );
  setCaption(savemes); 
  mCalendarModifiedFlag = false;
  mBlockSaveFlag = false;
}

void MainWindow::keyReleaseEvent ( QKeyEvent * e) 
{
    if ( !e->isAutoRepeat() ) {
          mFlagKeyPressed = false;
    }
}
void MainWindow::keyPressEvent ( QKeyEvent * e ) 
{
    qApp->processEvents();
    if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
        e->ignore();
        // qDebug("  ignore  %d",e->isAutoRepeat()  );
        return;
    }
    if (! e->isAutoRepeat() )
        mFlagKeyPressed = true;
    KOPrefs *p = KOPrefs::instance();
    bool showSelectedDates = false;
    int size;
    //qDebug("MainWindow::keyPressEvent ");
    switch ( e->key() ) {
    case Qt::Key_Right:
        if ( e->state() == Qt::ControlButton )
            mView->goNextMonth();
        else
            mView->goNext();
        showSelectedDates = true;
        break;
    case Qt::Key_Left:
        if ( e->state() == Qt::ControlButton )
            mView->goPreviousMonth();
        else
            mView->goPrevious();
        showSelectedDates = true;
        break;
    case Qt::Key_Down:
        mView->viewManager()->agendaView()->scrollOneHourDown();
        break;
    case Qt::Key_Up:
        mView->viewManager()->agendaView()->scrollOneHourUp();
        break;             
    case Qt::Key_I:
        mView->showIncidence();
        break;
    case Qt::Key_Delete:
    case Qt::Key_Backspace:
        mView->deleteIncidence();
        break;
    case Qt::Key_D:
        mView->viewManager()->showDayView();
        showSelectedDates = true;
        break;
    case Qt::Key_0:
        mView->toggleFilerEnabled( );
        break;
    case Qt::Key_1:
        mView->selectFilter( 0 );
        break;
    case Qt::Key_2:
        mView->selectFilter( 1 );
        break;
    case Qt::Key_3:
        mView->selectFilter( 2 );
        break;
    case Qt::Key_4:
        mView->selectFilter( 3 );
        break;
    case Qt::Key_5:
        mView->viewManager()->showWorkWeekView();
        showSelectedDates = true;
        break;
    case Qt::Key_7:
        mView->viewManager()->showWeekView();
        showSelectedDates = true;
        break;
    case Qt::Key_M:
        mView->viewManager()->showMonthView();
        showSelectedDates = true;
        break;
    case Qt::Key_Insert:
        mView->newEvent();
        break;
    case Qt::Key_S :
            mView->dialogManager()->showSearchDialog();
        break;
    case Qt::Key_H :
        keyBindings();
        break;
    case Qt::Key_W:
        mView->viewManager()->showWhatsNextView();
        break; 
    case Qt::Key_L:
        mView->viewManager()->showListView();
        break; 
    case Qt::Key_N:
        mView->viewManager()->showNextXView();
        showSelectedDates = true;
        break; 
    case Qt::Key_V:
        mView->viewManager()->showTodoView();
        break; 
    case Qt::Key_C:
        mView->goNext();
        showSelectedDates = true;
        break;       
    case Qt::Key_P:
        mView->showDatePicker( );
        break;      
    case Qt::Key_F:
        mView->toggleFilter();
        break;          
    case Qt::Key_X:
        mView->goPrevious();
        showSelectedDates = true;
        break;      
    case Qt::Key_Space:
        mView->toggleExpand();
        break;     
    case Qt::Key_A:
        mView->toggleAllDaySize();
        break; 
    case Qt::Key_T:
        if ( e->state() == Qt::ControlButton )
            mView->newTodo();
        else {
            mView->goToday();
            showSelectedDates = true;
        }
        break;
    case Qt::Key_J:
        mView->viewManager()->showJournalView();
        break;
    case Qt::Key_Return:  
    case Qt::Key_E:  
        if ( e->state() == Qt::ControlButton )
            mView->newEvent();
        else
            mView->editIncidence();
        break;
    case Qt::Key_Plus:
        size = p->mHourSize +2;
        if ( size <= 18 )
            configureAgenda( size );
        break;
    case Qt::Key_Minus:
        size = p->mHourSize - 2;
        if ( size >= 4 )
            configureAgenda( size );
        break;
       

    default:
        e->ignore();
    }
    
    if ( showSelectedDates ) {
        ;//  setCaptionToDates();
    }

}

void MainWindow::configureToolBar( int item  )
{

    configureToolBarMenu->setItemChecked( item, !configureToolBarMenu-> isItemChecked ( item ) );
    KOPrefs *p = KOPrefs::instance();
    p-> mShowIconStretch= configureToolBarMenu->isItemChecked( 5 );
    p-> mShowIconNewEvent= configureToolBarMenu->isItemChecked( 10 );
    p->mShowIconNewTodo = configureToolBarMenu->isItemChecked( 20 );
    p-> mShowIconSearch= configureToolBarMenu->isItemChecked( 120 );
    p-> mShowIconList= configureToolBarMenu->isItemChecked( 30 );
    p-> mShowIconDay1= configureToolBarMenu->isItemChecked( 40 );
    p-> mShowIconDay5= configureToolBarMenu->isItemChecked( 50 );
    p-> mShowIconDay7= configureToolBarMenu->isItemChecked( 60 );
    p-> mShowIconMonth= configureToolBarMenu->isItemChecked( 70 );
    p-> mShowIconTodoview= configureToolBarMenu->isItemChecked( 80 );
    p-> mShowIconBackFast= configureToolBarMenu->isItemChecked( 200 );
    p-> mShowIconBack = configureToolBarMenu->isItemChecked( 210 );
    p-> mShowIconToday= configureToolBarMenu->isItemChecked( 130 ); 
    p-> mShowIconForward= configureToolBarMenu->isItemChecked( 220 );
    p-> mShowIconForwardFast= configureToolBarMenu->isItemChecked( 230 );
    p-> mShowIconNextDays= configureToolBarMenu->isItemChecked( 100 );
    p-> mShowIconNext= configureToolBarMenu->isItemChecked( 110 );
    p-> mShowIconJournal= configureToolBarMenu->isItemChecked( 90 );
    p-> mShowIconWhatsThis= configureToolBarMenu->isItemChecked( 300 ); 
    initActions();
}

void MainWindow::setCaptionToDates()
{
    QString selDates;
    selDates = mView->startDate().toString();
    if  (mView->startDate() < mView->endDate() )
        selDates += " - " + mView->endDate().toString();
    setCaption( "Dates: " + selDates );
    
}
// parameter item == 0: reinit
void MainWindow::configureAgenda( int item )
{  

    KOPrefs *p = KOPrefs::instance();

    int i;
    if ( item == 1 ) {
        mView->toggleAllDaySize();
        return;
    }
    // do not allow 4 for widgets higher than 480
    if ( QApplication::desktop()->height() > 480 ) {
        if ( item == 4 )
            item = 6;
    }
    for ( i = 4; i <= 18; i= i+2 )
        configureAgendaMenu->setItemChecked( i, false );
    configureAgendaMenu->setItemChecked( item, true );
    if ( p->mHourSize == item )
        return;
    p->mHourSize=item;
    mView->viewManager()->agendaView()->updateConfig();
}

void  MainWindow::saveCalendar()
{ 
    QString fn =  KOPrefs::instance()->mLastSaveFile;
    fn =  KFileDialog::getSaveFileName( fn, "Save backup filename", this );

    if ( fn == "" )
        return;
   QFileInfo info;
   info.setFile( fn );
   QString mes;
   bool createbup = true;
   if ( info. exists() ) { 
       mes.sprintf(  "Backup file\nalready exists!\nOld backup file from:\n%s\nOverwrite?\n",info.lastModified ().toString().latin1()  );
       int result = QMessageBox::warning( this, "KO/Pi: Warning!",mes,
                                          "Overwrite!", "Cancel", 0,
                                          0, 1 );
       if ( result != 0 ) {
           createbup = false;
       }
   }
   if ( createbup ) {
       mView->saveCalendar( fn ); 
       mes.sprintf("KO/Pi:Saved %s",fn.latin1()  );
       KOPrefs::instance()->mLastSaveFile = fn;
       setCaption(mes);
   }
}
void  MainWindow::loadCalendar()
{
   
    QString fn =   KOPrefs::instance()->mLastLoadFile;
    fn =  KFileDialog::getOpenFileName( fn, "Load backup filename", this );
    
    if ( fn == "" )
        return;
    QFileInfo info;
    info.setFile( fn );
    QString mess;
    bool loadbup = true;
    if ( info. exists() ) {
       mess.sprintf(  "Backup file from:\n%s\nLoading  backup\nfile will delete\nyour current Data!\n",info.lastModified ().toString().latin1()  );
       int result = QMessageBox::warning( this, "KO/Pi: Warning!",
                                          mess,
                                          "Load!", "Cancel", 0,
                                          0, 1 );
       if ( result != 0 ) {
           loadbup = false;
       }
    } else {
        QMessageBox::warning( this, "KO/Pi: Warning!",
                                          "Backup file\ndoes not exist!\n"
                                          "Nothing loaded!", 0, 0,
                                          0, 1 );

        return;
    }
   if ( loadbup ) {
       mView->openCalendar( fn );
       KOPrefs::instance()->mLastLoadFile = fn;
       mess.sprintf("KO/Pi:Loaded %s",fn.latin1()  );
       setCaption(mess);
   }

}
void  MainWindow::quickImportIcal()
{
    importFile( KOPrefs::instance()->mLastImportFile, false );
}
void MainWindow::importFile( QString  fn, bool quick )
{
    QFileInfo info;
    info.setFile( fn );
    QString mess;
    bool loadbup = true;
    if ( !info. exists() ) {
        mess=  "Import file \n..."+fn.right( 30)+ "\ndoes not exist!\nNothing imported!\n";
       int result = QMessageBox::warning( this, "KO/Pi: Warning!",
                                          mess );
       return;
    } 
    int result = 0;
    if ( !quick ) { 
    mess.sprintf(  "Import file \n..."+fn.right( 25)+"\nfrom:\n%s\nDuplicated entries\nwill not be imported!\n",info.lastModified ().toString().latin1()  );
     result = QMessageBox::warning( this, "KO/Pi: Warning!",
                                       mess,
                                       "Import", "Cancel", 0,
                                       0, 1 );
    }
    if ( result == 0 ) {
        if ( mView->openCalendar( fn, true )) {
            KOPrefs::instance()->mLastImportFile = fn;
            setCaption(i18n("   "));
            setCaption(i18n("Imported file successfully"));
        } else {
            setCaption(i18n("Error importing file"));
        }
    }
}
void   MainWindow::importIcal()
{
 
    QString fn =KOPrefs::instance()->mLastImportFile;

    fn =KFileDialog:: getOpenFileName( fn, "Import filename(*.ics/*.vcs)", this );
    if ( fn == "" )
        return;
    importFile(  fn, true );
        
}

void MainWindow::exportVCalendar()
{
    QString fn =  KOPrefs::instance()->mLastVcalFile;
    fn =  KFileDialog::getSaveFileName( fn, "Export vcal filename(*.vcs)", this );
    if ( fn == "" )
        return;
   QFileInfo info;
   info.setFile( fn );
   QString mes;
   bool createbup = true;
   if ( info. exists() ) { 
       mes.sprintf(  i18n("Save file\nalready exists!\nOld save file from:\n%s\nOverwrite?\n"),info.lastModified ().toString().latin1()  );
       int result = QMessageBox::warning( this, "KO/Pi: Warning!",mes,
                                          "Overwrite!", "Cancel", 0,
                                          0, 1 );
       if ( result != 0 ) {
           createbup = false;
       }
   }
   if ( createbup ) {
       if ( mView->exportVCalendar( fn ) ) { 
       KOPrefs::instance()->mLastVcalFile = fn; 
       if ( fn.length() > 20 )
           mes.sprintf(i18n("KO/Pi:Exported to ...%s"),(fn.right(20)).latin1()  );
       else
           mes.sprintf(i18n("KO/Pi:Exported to %s"),fn.latin1()  );
       setCaption(mes);
       }
   }

}

QString  MainWindow::getPassword( )
{ 
    QString retfile = "";
    QDialog dia ( this, "input-dialog", true ); 
    QLineEdit lab ( &dia ); 
    lab.setEchoMode( QLineEdit::Password );
    QVBoxLayout lay( &dia );
    lay.setMargin(7); 
    lay.setSpacing(7); 
    lay.addWidget( &lab);
    dia.setFixedSize( 230,50 );
    dia.setCaption( i18n("Input password") );
    dia.show();
    int res = dia.exec();
    if ( res )
        retfile = lab.text();
    return retfile;

}
#ifndef _WIN32_
#include <unistd.h>
#endif
void MainWindow::syncLocalFile()
{

    QString fn =KOPrefs::instance()->mLastSyncedLocalFile;

    fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
    if ( fn == "" )
        return;
    syncWithFile(  fn, false );

}

void  MainWindow::syncWithFile( QString fn , bool quick )
{
    QFileInfo info;
    info.setFile( fn );
    QString mess;
    bool loadbup = true;
    if ( !info. exists() ) {
        mess.sprintf( i18n( "Sync file \n...%s\ndoes not exist!\nNothing synced!\n"),fn.right( 30).latin1() );
       int result = QMessageBox::warning( this, "KO/Pi: Warning!",
                                          mess );
       return;
    } 
    int result = 0;
    if ( !quick ) { 
    mess.sprintf(  "Sync with file \n..."+fn.right( 25)+"\nfrom:\n%s\n",info.lastModified ().toString().latin1()  );
     result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
                                       mess,
                                       i18n("Sync"), i18n("Cancel"), 0,
                                       0, 1 );
    }
    if ( KOPrefs::instance()->mAskForPreferences )
        mView->edit_sync_options(); 
    if ( result == 0 ) {
        qDebug("Now sycing ... ");
        mView->syncCalendar( fn, true );
        if ( ! quick )
            KOPrefs::instance()->mLastSyncedLocalFile = fn;
    }

}

void MainWindow::quickSyncLocalFile()
{
    qDebug("quickSyncLocalFile() ");
    syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false );
}

void MainWindow::syncSSH()
{   
    QTime timer; 
    timer.start();
    qDebug("MainWindow::syncssh() ");
    KOPrefs *p = KOPrefs::instance();
    QString localFile =  p->mLocalTempFile;
    QString remoteIP = p->mRemoteIP;
    QString remoteUser = p->mRemoteUser;
    QString remoteFile = p->mRemoteFile;
    if ( p->mUsePassWd &&  p->mRemotePassWd.length() > 0  )
        remoteUser += ":" + p->mRemotePassWd;

    QString question = i18n("Do you really want\nto remote sync?\n \n") +
        i18n("IP: " ) +remoteIP  +"\n" +
        i18n("User: " ) + remoteUser +"\n" ;
    int maxlen = 30;
    if ( QApplication::desktop()->width() > 320 ) 
        maxlen += 25;
    if ( remoteFile.length() > maxlen )
        question  +=   i18n("Remote file:\n..." ) + remoteFile.right(maxlen) +"\n";
    else
        question  +=   i18n("Remote file:\n " ) + remoteFile +"\n";
    if ( localFile.length() > maxlen )
        question  +=   i18n("Local temp file:\n..." ) + localFile.right(maxlen) +"\n";
    else
        question  +=   i18n("Local temp file:\n " ) + localFile +"\n";
        
    if ( QMessageBox::information( this, "KO/Pi Sync",
                                   question,
                                   i18n("Yes"), i18n("No"), 
                                   0, 0 ) != 0 )
        return;
    if ( !p->mUsePassWd ) {
        QString pass = getPassword();
        if ( pass.length() > 0 )
            remoteUser += ":" + pass;
    }
    QString command = "scp " + remoteUser + "@" + remoteIP +":" + remoteFile +"  " +localFile;
    setCaption ( i18n( "Copy remote file to local machine..." ) );
    int fileSize = 0;
    int result = system ( command );
    // 0 : okay
    // 256: no such file or dir
    //
    qDebug("KO: Remote copy result(0 = okay): %d ",result );
    if ( result != 0 ) {
        int len = maxlen;
        while ( len <  command.length() ) {
            command.insert( len , "\n" );
            len += maxlen +2;
        }
        question = i18n("Sorry, the copy command failed!\nCommand was:\n") + command + "\n \nTry command on console to get more\ndetailed info about the reason.\n";
        QMessageBox::information( this, "KO/Pi Sync - ERROR",
                                  question,
                                  i18n("Okay!")) ;
        return;
    }


    setCaption ( i18n( "Copying succeed. Syncing not yet implemented" ) );
    syncWithFile(localFile , true );
    return;
#if 0
    system ("scp zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics /home/polo/Applications/korganizer/z_sync.ics");
      while ( timer.elapsed() < 5000 )
          qApp->processEvents();

    qDebug("MainWindow::merging) ");
    mView->syncCalendar( "/home/polo/Applications/korganizer/z_sync.ics", 0 );
    while ( mBlockSaveFlag ) 
        qApp->processEvents();
    save();
     system ("scp /home/polo/Applications/korganizer/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics");
#endif

}
*/