summaryrefslogtreecommitdiffabout
path: root/korganizer/mainwindow.cpp
Unidiff
Diffstat (limited to 'korganizer/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp134
1 files changed, 134 insertions, 0 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index de94b8c..ef73a78 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -1,92 +1,144 @@
1#include <stdlib.h> 1#include <stdlib.h>
2 2
3#include <qaction.h> 3#include <qaction.h>
4#include <qpopupmenu.h> 4#include <qpopupmenu.h>
5#include <qpainter.h> 5#include <qpainter.h>
6#include <qwhatsthis.h> 6#include <qwhatsthis.h>
7#include <qpushbutton.h> 7#include <qpushbutton.h>
8#include <qmessagebox.h> 8#include <qmessagebox.h>
9#include <qlineedit.h> 9#include <qlineedit.h>
10#include <qtextcodec.h> 10#include <qtextcodec.h>
11#include <qfile.h> 11#include <qfile.h>
12#include <qdir.h> 12#include <qdir.h>
13#include <qapp.h> 13#include <qapp.h>
14#include <qfileinfo.h> 14#include <qfileinfo.h>
15#include <qlabel.h> 15#include <qlabel.h>
16#include <qspinbox.h>
17#include <qcheckbox.h>
16#include <qmap.h> 18#include <qmap.h>
17#include <qwmatrix.h> 19#include <qwmatrix.h>
18#include <qtextbrowser.h> 20#include <qtextbrowser.h>
19#include <qtextstream.h> 21#include <qtextstream.h>
20#ifndef DESKTOP_VERSION 22#ifndef DESKTOP_VERSION
21#include <qpe/global.h> 23#include <qpe/global.h>
22#include <qpe/qpemenubar.h> 24#include <qpe/qpemenubar.h>
23#include <qpe/qpetoolbar.h> 25#include <qpe/qpetoolbar.h>
24#include <qpe/resource.h> 26#include <qpe/resource.h>
25#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
26#include <qtopia/alarmserver.h> 28#include <qtopia/alarmserver.h>
27#include <qtopia/qcopenvelope_qws.h> 29#include <qtopia/qcopenvelope_qws.h>
28#include <unistd.h> // for sleep 30#include <unistd.h> // for sleep
29#else 31#else
30#include <qmenubar.h> 32#include <qmenubar.h>
31#include <qtoolbar.h> 33#include <qtoolbar.h>
32#include <qapplication.h> 34#include <qapplication.h>
33//#include <resource.h> 35//#include <resource.h>
34 36
35#endif 37#endif
36#include <libkcal/calendarlocal.h> 38#include <libkcal/calendarlocal.h>
37#include <libkcal/todo.h> 39#include <libkcal/todo.h>
40#include <libkcal/phoneformat.h>
38#include <libkdepim/ksyncprofile.h> 41#include <libkdepim/ksyncprofile.h>
39#include <libkcal/kincidenceformatter.h> 42#include <libkcal/kincidenceformatter.h>
40#include <libkdepim/kpimglobalprefs.h> 43#include <libkdepim/kpimglobalprefs.h>
41 44
42#include "calendarview.h" 45#include "calendarview.h"
43#include "koviewmanager.h" 46#include "koviewmanager.h"
44#include "datenavigator.h" 47#include "datenavigator.h"
45#include "koagendaview.h" 48#include "koagendaview.h"
46#include "koagenda.h" 49#include "koagenda.h"
47#include "kodialogmanager.h" 50#include "kodialogmanager.h"
48#include "kdialogbase.h" 51#include "kdialogbase.h"
49#include "kapplication.h" 52#include "kapplication.h"
50#include "kofilterview.h" 53#include "kofilterview.h"
51#include "kstandarddirs.h" 54#include "kstandarddirs.h"
52#include "koprefs.h" 55#include "koprefs.h"
53#include "kfiledialog.h" 56#include "kfiledialog.h"
54#include "koglobals.h" 57#include "koglobals.h"
55#include "kglobal.h" 58#include "kglobal.h"
56#include "klocale.h" 59#include "klocale.h"
57#include "kconfig.h" 60#include "kconfig.h"
58#include "simplealarmclient.h" 61#include "simplealarmclient.h"
59#include "externalapphandler.h" 62#include "externalapphandler.h"
60 63
61using namespace KCal; 64using namespace KCal;
62#ifndef _WIN32_ 65#ifndef _WIN32_
63#include <unistd.h> 66#include <unistd.h>
64#else 67#else
65#include "koimportoldialog.h" 68#include "koimportoldialog.h"
66#endif 69#endif
67#include "mainwindow.h" 70#include "mainwindow.h"
68 71
72class KOex2phonePrefs : public QDialog
73{
74 public:
75 KOex2phonePrefs( QWidget *parent=0, const char *name=0 ) :
76 QDialog( parent, name, true )
77 {
78 setCaption( i18n("Export to phone options") );
79 QVBoxLayout* lay = new QVBoxLayout( this );
80 lay->setSpacing( 3 );
81 lay->setMargin( 3 );
82
83 lay->addWidget(new QLabel( i18n("Please read phone sync howto to\nknow more about the connection settings."), this ) );
84 QHBox* temphb;
85 temphb = new QHBox( this );
86 new QLabel( i18n("I/O device: "), temphb );
87 mPhoneDevice = new QLineEdit( temphb);
88 lay->addWidget( temphb );
89 temphb = new QHBox( this );
90 new QLabel( i18n("Connection: "), temphb );
91 mPhoneConnection = new QLineEdit( temphb);
92 lay->addWidget( temphb );
93 temphb = new QHBox( this );
94 new QLabel( i18n("Model(opt.): "), temphb );
95 mPhoneModel = new QLineEdit( temphb);
96 lay->addWidget( temphb );
97 mWriteBackFuture= new QCheckBox( i18n("Write back events in future only"), this );
98 mWriteBackFuture->setChecked( true );
99 lay->addWidget( mWriteBackFuture );
100 temphb = new QHBox( this );
101 new QLabel( i18n("Max. weeks in future: ") , temphb );
102 mWriteBackFutureWeeks= new QSpinBox(1,104, 1, temphb);
103 mWriteBackFutureWeeks->setValue( 8 );
104 lay->addWidget( temphb );
105 QPushButton * ok = new QPushButton( i18n("Export!"), this );
106 lay->addWidget( ok );
107 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
108 lay->addWidget( cancel );
109 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
110 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
111 resize( 220, 220 );
112
113 }
114
115public:
116 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel;
117 QCheckBox* mWriteBackFuture;
118 QSpinBox* mWriteBackFutureWeeks;
119};
120
69int globalFlagBlockStartup; 121int globalFlagBlockStartup;
70MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : 122MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
71 QMainWindow( parent, name ) 123 QMainWindow( parent, name )
72{ 124{
73 mPassWordPiSync = "abc"; 125 mPassWordPiSync = "abc";
74#ifdef DESKTOP_VERSION 126#ifdef DESKTOP_VERSION
75 setFont( QFont("Arial"), 14 ); 127 setFont( QFont("Arial"), 14 );
76#endif 128#endif
77 mSyncActionDialog = 0; 129 mSyncActionDialog = 0;
78 mServerSocket = 0; 130 mServerSocket = 0;
79 mClosed = false; 131 mClosed = false;
80 //QString confFile = KStandardDirs::appDir() + "config/korganizerrc"; 132 //QString confFile = KStandardDirs::appDir() + "config/korganizerrc";
81 QString confFile = locateLocal("config","korganizerrc"); 133 QString confFile = locateLocal("config","korganizerrc");
82 QFileInfo finf ( confFile ); 134 QFileInfo finf ( confFile );
83 bool showWarning = !finf.exists(); 135 bool showWarning = !finf.exists();
84 setIcon(SmallIcon( "ko24" ) ); 136 setIcon(SmallIcon( "ko24" ) );
85 mBlockAtStartup = true; 137 mBlockAtStartup = true;
86 mFlagKeyPressed = false; 138 mFlagKeyPressed = false;
87 setCaption("KOrganizer/Pi"); 139 setCaption("KOrganizer/Pi");
88 KOPrefs *p = KOPrefs::instance(); 140 KOPrefs *p = KOPrefs::instance();
89 KPimGlobalPrefs::instance()->setGlobalConfig(); 141 KPimGlobalPrefs::instance()->setGlobalConfig();
90 // if ( QApplication::desktop()->height() > 480 ) { 142 // if ( QApplication::desktop()->height() > 480 ) {
91// if ( p->mHourSize == 4 ) 143// if ( p->mHourSize == 4 )
92// p->mHourSize = 6; 144// p->mHourSize = 6;
@@ -632,48 +684,57 @@ void MainWindow::initActions()
632#ifdef _WIN32_ 684#ifdef _WIN32_
633 importMenu->insertSeparator(); 685 importMenu->insertSeparator();
634 action = new QAction( "import_ol", i18n("Import from OL"), 0, 686 action = new QAction( "import_ol", i18n("Import from OL"), 0,
635 this ); 687 this );
636 action->addTo( importMenu ); 688 action->addTo( importMenu );
637 connect( action, SIGNAL( activated() ), SLOT( importOL() ) ); 689 connect( action, SIGNAL( activated() ), SLOT( importOL() ) );
638#endif 690#endif
639#endif 691#endif
640 692
641 importMenu->insertSeparator(); 693 importMenu->insertSeparator();
642 action = new QAction( "load_cal", i18n("Load Calendar Backup"), 0, 694 action = new QAction( "load_cal", i18n("Load Calendar Backup"), 0,
643 this ); 695 this );
644 action->addTo( importMenu ); 696 action->addTo( importMenu );
645 connect( action, SIGNAL( activated() ), SLOT( loadCalendar() ) ); 697 connect( action, SIGNAL( activated() ), SLOT( loadCalendar() ) );
646 698
647 action = new QAction( "save_cal", i18n("Save Calendar Backup"), 0, 699 action = new QAction( "save_cal", i18n("Save Calendar Backup"), 0,
648 this ); 700 this );
649 action->addTo( importMenu ); 701 action->addTo( importMenu );
650 connect( action, SIGNAL( activated() ), SLOT( saveCalendar() ) ); 702 connect( action, SIGNAL( activated() ), SLOT( saveCalendar() ) );
651 703
652 importMenu->insertSeparator(); 704 importMenu->insertSeparator();
653 action = new QAction( "import_qtopia", i18n("Export VCalendar"), 0, 705 action = new QAction( "import_qtopia", i18n("Export VCalendar"), 0,
654 this ); 706 this );
655 action->addTo( importMenu ); connect( action, SIGNAL( activated() ), SLOT( exportVCalendar() ) ); 707 action->addTo( importMenu ); connect( action, SIGNAL( activated() ), SLOT( exportVCalendar() ) );
708
709
710 //LR
711 QPopupMenu *ex2phone = new QPopupMenu( this );
712 ex2phone->insertItem(i18n("Complete calendar..."), 1 );
713 ex2phone->insertItem(i18n("Filtered calendar..."), 2 );
714 connect( ex2phone, SIGNAL( activated(int) ), this, SLOT( exportToPhone( int)) );
715 importMenu->insertItem( i18n("Export to phone"), ex2phone );
716
656 importMenu->insertSeparator(); 717 importMenu->insertSeparator();
657 action = new QAction( "manage cat", i18n("Manage new categories..."), 0, 718 action = new QAction( "manage cat", i18n("Manage new categories..."), 0,
658 this ); 719 this );
659 action->addTo( importMenu ); 720 action->addTo( importMenu );
660 connect( action, SIGNAL( activated() ), mView, SLOT( manageCategories() ) ); 721 connect( action, SIGNAL( activated() ), mView, SLOT( manageCategories() ) );
661#ifndef DESKTOP_VERSION 722#ifndef DESKTOP_VERSION
662 importMenu->insertSeparator(); 723 importMenu->insertSeparator();
663 action = new QAction( "beam all", i18n("Beam complete calendar..."), 0, 724 action = new QAction( "beam all", i18n("Beam complete calendar..."), 0,
664 this ); 725 this );
665 action->addTo( importMenu ); 726 action->addTo( importMenu );
666 connect( action, SIGNAL( activated() ), mView, SLOT( beamCalendar() ) ); 727 connect( action, SIGNAL( activated() ), mView, SLOT( beamCalendar() ) );
667 728
668 action = new QAction( "beam all", i18n("Beam filtered calendar..."), 0, 729 action = new QAction( "beam all", i18n("Beam filtered calendar..."), 0,
669 this ); 730 this );
670 action->addTo( importMenu ); 731 action->addTo( importMenu );
671 connect( action, SIGNAL( activated() ), mView, SLOT( beamFilteredCalendar()) ); 732 connect( action, SIGNAL( activated() ), mView, SLOT( beamFilteredCalendar()) );
672#else 733#else
673 importMenu->insertSeparator(); 734 importMenu->insertSeparator();
674 icon = loadPixmap( pathString + "print" ); 735 icon = loadPixmap( pathString + "print" );
675 action = new QAction( i18n("Print calendar..."),icon,i18n("Print calendar..."), 0, this ); 736 action = new QAction( i18n("Print calendar..."),icon,i18n("Print calendar..."), 0, this );
676 action->addTo( importMenu ); 737 action->addTo( importMenu );
677 connect( action, SIGNAL( activated() ), 738 connect( action, SIGNAL( activated() ),
678 this, SLOT( printCal() ) ); 739 this, SLOT( printCal() ) );
679 740
@@ -1066,55 +1127,128 @@ void MainWindow::slotSyncMenu( int action )
1066 1127
1067 } else if ( action >= 1003 ) { 1128 } else if ( action >= 1003 ) {
1068 if ( temp->getIsLocalFileSync() ) { 1129 if ( temp->getIsLocalFileSync() ) {
1069 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 1130 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
1070 KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); 1131 KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName();
1071 } else { 1132 } else {
1072 if ( temp->getIsPhoneSync() ) { 1133 if ( temp->getIsPhoneSync() ) {
1073 KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; 1134 KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
1074 KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); 1135 KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
1075 KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); 1136 KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
1076 syncPhone(); 1137 syncPhone();
1077 } else if ( temp->getIsPiSync() ) { 1138 } else if ( temp->getIsPiSync() ) {
1078 mPassWordPiSync = temp->getRemotePw(); 1139 mPassWordPiSync = temp->getRemotePw();
1079 KOPrefs::instance()->mActiveSyncPort = temp->getRemotePort(); 1140 KOPrefs::instance()->mActiveSyncPort = temp->getRemotePort();
1080 KOPrefs::instance()->mActiveSyncIP = temp->getRemoteIP(); 1141 KOPrefs::instance()->mActiveSyncIP = temp->getRemoteIP();
1081 syncPi(); 1142 syncPi();
1082 } else 1143 } else
1083 syncRemote( temp ); 1144 syncRemote( temp );
1084 1145
1085 } 1146 }
1086 } 1147 }
1087 delete temp; 1148 delete temp;
1088 mBlockSaveFlag = false; 1149 mBlockSaveFlag = false;
1089} 1150}
1151void MainWindow::exportToPhone( int mode )
1152{
1153
1154 //ex2phone->insertItem(i18n("Complete calendar..."), 1 );
1155 //ex2phone->insertItem(i18n("Filtered calendar..."), 2 );
1156 KOex2phonePrefs ex2phone;
1157 ex2phone.mPhoneConnection->setText( KOPrefs::instance()->mEx2PhoneConnection );
1158 ex2phone.mPhoneDevice->setText( KOPrefs::instance()->mEx2PhoneDevice );
1159 ex2phone.mPhoneModel->setText( KOPrefs::instance()->mEx2PhoneModel );
1160
1161 if ( !ex2phone.exec() ) {
1162 return;
1163 }
1164 KOPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text();
1165 KOPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text();
1166 KOPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text();
1167
1168 int inFuture = 0;
1169 if ( ex2phone.mWriteBackFuture->isChecked() )
1170 inFuture = ex2phone.mWriteBackFutureWeeks->value();
1171 QPtrList<Incidence> delSel;
1172 if ( mode == 1 )
1173 delSel = mCalendar->rawIncidences();
1174 if ( mode == 2 )
1175 delSel = mCalendar->incidences();
1176 CalendarLocal* cal = new CalendarLocal();
1177 cal->setLocalTime();
1178 Incidence *incidence = delSel.first();
1179 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1180 QDateTime end = cur.addDays( ( inFuture +1 ) *7 );
1181 while ( incidence ) {
1182 if ( incidence->type() != "journal" ) {
1183 bool add = true;
1184 if ( inFuture ) {
1185 QDateTime dt;
1186 if ( incidence->type() == "Todo" ) {
1187 Todo * t = (Todo*)incidence;
1188 if ( t->hasDueDate() )
1189 dt = t->dtDue();
1190 else
1191 dt = cur.addSecs( 62 );
1192 }
1193 else {
1194 bool ok;
1195 dt = incidence->getNextOccurence( cur, &ok );
1196 if ( !ok )
1197 dt = cur.addSecs( -62 );
1198 }
1199 if ( dt < cur || dt > end ) {
1200 add = false;
1201 }
1202 }
1203 if ( add ) {
1204 Incidence *in = incidence->clone();
1205 cal->addIncidence( in );
1206 }
1207 }
1208 incidence = delSel.next();
1209 }
1210 PhoneFormat::writeConfig( KOPrefs::instance()->mEx2PhoneDevice,
1211 KOPrefs::instance()->mEx2PhoneConnection,
1212 KOPrefs::instance()->mEx2PhoneModel );
1213
1214 setCaption( i18n("Writing to phone..."));
1215 if ( PhoneFormat::writeToPhone( cal ) )
1216 setCaption( i18n("Export to phone successful!"));
1217 else
1218 setCaption( i18n("Error exporting to phone!"));
1219 delete cal;
1220}
1221
1222
1090void MainWindow::setDefaultPreferences() 1223void MainWindow::setDefaultPreferences()
1091{ 1224{
1092 KOPrefs *p = KOPrefs::instance(); 1225 KOPrefs *p = KOPrefs::instance();
1093 1226
1094 p->mCompactDialogs = true; 1227 p->mCompactDialogs = true;
1095 p->mConfirm = true; 1228 p->mConfirm = true;
1096 // p->mEnableQuickTodo = false; 1229 // p->mEnableQuickTodo = false;
1230
1097} 1231}
1098 1232
1099QString MainWindow::resourcePath() 1233QString MainWindow::resourcePath()
1100{ 1234{
1101 return KGlobal::iconLoader()->iconPath(); 1235 return KGlobal::iconLoader()->iconPath();
1102} 1236}
1103 1237
1104void MainWindow::displayText( QString text ,QString cap ) 1238void MainWindow::displayText( QString text ,QString cap )
1105{ 1239{
1106 QDialog dia( this, "name", true ); ; 1240 QDialog dia( this, "name", true ); ;
1107 dia.setCaption( cap ); 1241 dia.setCaption( cap );
1108 QVBoxLayout* lay = new QVBoxLayout( &dia ); 1242 QVBoxLayout* lay = new QVBoxLayout( &dia );
1109 lay->setSpacing( 3 ); 1243 lay->setSpacing( 3 );
1110 lay->setMargin( 3 ); 1244 lay->setMargin( 3 );
1111 QTextBrowser tb ( &dia ); 1245 QTextBrowser tb ( &dia );
1112 lay->addWidget( &tb ); 1246 lay->addWidget( &tb );
1113 tb.setText( text ); 1247 tb.setText( text );
1114#ifdef DESKTOP_VERSION 1248#ifdef DESKTOP_VERSION
1115 dia.resize( 640, 480); 1249 dia.resize( 640, 480);
1116#else 1250#else
1117 dia.showMaximized(); 1251 dia.showMaximized();
1118#endif 1252#endif
1119 dia.exec(); 1253 dia.exec();
1120} 1254}