summaryrefslogtreecommitdiffabout
path: root/korganizer/mainwindow.cpp
Unidiff
Diffstat (limited to 'korganizer/mainwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp554
1 files changed, 22 insertions, 532 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index e3324ee..f7766f8 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -105,104 +105,102 @@ class KOex2phonePrefs : public QDialog
105 mWriteBackFutureWeeks->setValue( 8 ); 105 mWriteBackFutureWeeks->setValue( 8 );
106 lay->addWidget( temphb ); 106 lay->addWidget( temphb );
107 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ntodo/calendar data on phone!"), this ) ); 107 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ntodo/calendar data on phone!"), this ) );
108 lab->setAlignment (AlignHCenter ); 108 lab->setAlignment (AlignHCenter );
109 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); 109 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
110 lay->addWidget( ok ); 110 lay->addWidget( ok );
111 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 111 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
112 lay->addWidget( cancel ); 112 lay->addWidget( cancel );
113 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 113 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
114 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 114 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
115 resize( 220, 240 ); 115 resize( 220, 240 );
116 116
117 } 117 }
118 118
119public: 119public:
120 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; 120 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel;
121 QCheckBox* mWriteBackFuture; 121 QCheckBox* mWriteBackFuture;
122 QSpinBox* mWriteBackFutureWeeks; 122 QSpinBox* mWriteBackFutureWeeks;
123}; 123};
124 124
125int globalFlagBlockStartup; 125int globalFlagBlockStartup;
126MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : 126MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
127 QMainWindow( parent, name ) 127 QMainWindow( parent, name )
128{ 128{
129 mPassWordPiSync = "abc"; 129
130#ifdef DESKTOP_VERSION 130#ifdef DESKTOP_VERSION
131 setFont( QFont("Arial"), 14 ); 131 setFont( QFont("Arial"), 14 );
132#endif 132#endif
133 mServerSocket = 0; 133 mServerSocket = 0;
134 mClosed = false; 134 mClosed = false;
135 //QString confFile = KStandardDirs::appDir() + "config/korganizerrc"; 135 //QString confFile = KStandardDirs::appDir() + "config/korganizerrc";
136 QString confFile = locateLocal("config","korganizerrc"); 136 QString confFile = locateLocal("config","korganizerrc");
137 QFileInfo finf ( confFile ); 137 QFileInfo finf ( confFile );
138 bool showWarning = !finf.exists(); 138 bool showWarning = !finf.exists();
139 setIcon(SmallIcon( "ko24" ) ); 139 setIcon(SmallIcon( "ko24" ) );
140 mBlockAtStartup = true; 140 mBlockAtStartup = true;
141 mFlagKeyPressed = false; 141 mFlagKeyPressed = false;
142 setCaption("KOrganizer/Pi"); 142 setCaption("KOrganizer/Pi");
143 KOPrefs *p = KOPrefs::instance(); 143 KOPrefs *p = KOPrefs::instance();
144 KPimGlobalPrefs::instance()->setGlobalConfig(); 144 KPimGlobalPrefs::instance()->setGlobalConfig();
145 // if ( QApplication::desktop()->height() > 480 ) {
146// if ( p->mHourSize == 4 )
147// p->mHourSize = 6;
148// }
149 if ( p->mHourSize > 18 ) 145 if ( p->mHourSize > 18 )
150 p->mHourSize = 18; 146 p->mHourSize = 18;
151 QMainWindow::ToolBarDock tbd; 147 QMainWindow::ToolBarDock tbd;
152 if ( p->mToolBarHor ) { 148 if ( p->mToolBarHor ) {
153 if ( p->mToolBarUp ) 149 if ( p->mToolBarUp )
154 tbd = Bottom; 150 tbd = Bottom;
155 else 151 else
156 tbd = Top; 152 tbd = Top;
157 } 153 }
158 else { 154 else {
159 if ( p->mToolBarUp ) 155 if ( p->mToolBarUp )
160 tbd = Right; 156 tbd = Right;
161 else 157 else
162 tbd = Left; 158 tbd = Left;
163 } 159 }
164 if ( KOPrefs::instance()->mUseAppColors ) 160 if ( KOPrefs::instance()->mUseAppColors )
165 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 161 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
166 globalFlagBlockStartup = 1; 162 globalFlagBlockStartup = 1;
167 iconToolBar = new QPEToolBar( this ); 163 iconToolBar = new QPEToolBar( this );
168 addToolBar (iconToolBar , tbd ); 164 addToolBar (iconToolBar , tbd );
169 mBlockSaveFlag = false;
170 mCalendarModifiedFlag = false; 165 mCalendarModifiedFlag = false;
171 166
172 QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this ); 167 QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this );
173 splash->setAlignment ( AlignCenter ); 168 splash->setAlignment ( AlignCenter );
174 setCentralWidget( splash ); 169 setCentralWidget( splash );
175#ifndef DESKTOP_VERSION 170#ifndef DESKTOP_VERSION
176 showMaximized(); 171 showMaximized();
177#endif 172#endif
178 //qDebug("Mainwidget x %d y %d w %d h %d", x(), y(), width(), height ()); 173 //qDebug("Mainwidget x %d y %d w %d h %d", x(), y(), width(), height ());
179 setDefaultPreferences(); 174 setDefaultPreferences();
180 mCalendar = new CalendarLocal(); 175 mCalendar = new CalendarLocal();
181 mView = new CalendarView( mCalendar, this,"mCalendar " ); 176 mView = new CalendarView( mCalendar, this,"mCalendar " );
182 mView->hide(); 177 mView->hide();
183 //mView->resize(splash->size() ); 178 //mView->resize(splash->size() );
184 initActions(); 179 initActions();
180 mSyncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)mView, KSyncManager::KOPI, KOPrefs::instance(), syncMenu);
181 mSyncManager->setBlockSave(false);
182 mView->setSyncManager(mSyncManager);
185#ifndef DESKTOP_VERSION 183#ifndef DESKTOP_VERSION
186 iconToolBar->show(); 184 iconToolBar->show();
187 qApp->processEvents(); 185 qApp->processEvents();
188#endif 186#endif
189 //qDebug("Splashwidget x %d y %d w %d h %d", splash-> x(), splash->y(), splash->width(),splash-> height ()); 187 //qDebug("Splashwidget x %d y %d w %d h %d", splash-> x(), splash->y(), splash->width(),splash-> height ());
190 int vh = height() ; 188 int vh = height() ;
191 int vw = width(); 189 int vw = width();
192 //qDebug("Toolbar hei %d ",iconToolBar->height() ); 190 //qDebug("Toolbar hei %d ",iconToolBar->height() );
193 if ( iconToolBar->orientation () == Qt:: Horizontal ) { 191 if ( iconToolBar->orientation () == Qt:: Horizontal ) {
194 vh -= iconToolBar->height(); 192 vh -= iconToolBar->height();
195 } else { 193 } else {
196 vw -= iconToolBar->height(); 194 vw -= iconToolBar->height();
197 } 195 }
198 //mView->setMaximumSize( splash->size() ); 196 //mView->setMaximumSize( splash->size() );
199 //mView->resize( splash->size() ); 197 //mView->resize( splash->size() );
200 //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ()); 198 //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ());
201 mView->readSettings(); 199 mView->readSettings();
202 bool newFile = false; 200 bool newFile = false;
203 if( !QFile::exists( defaultFileName() ) ) { 201 if( !QFile::exists( defaultFileName() ) ) {
204 QFileInfo finfo ( defaultFileName() ); 202 QFileInfo finfo ( defaultFileName() );
205 QString oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/Applications/korganizer/mycalendar.ics"); 203 QString oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/Applications/korganizer/mycalendar.ics");
206 qDebug("oldfile %s ", oldFile.latin1()); 204 qDebug("oldfile %s ", oldFile.latin1());
207 QString message = "You are starting KO/Pi for the\nfirst time after updating to a\nversion >= 1.9.1. The location of the\ndefault calendar file has changed.\nA mycalendar.ics file was detected\nat the old location.\nThis file will be loaded now\nand stored at the new location!\n(Config file location has changed, too!)\nPlease read menu Help-What's New!\n"; 205 QString message = "You are starting KO/Pi for the\nfirst time after updating to a\nversion >= 1.9.1. The location of the\ndefault calendar file has changed.\nA mycalendar.ics file was detected\nat the old location.\nThis file will be loaded now\nand stored at the new location!\n(Config file location has changed, too!)\nPlease read menu Help-What's New!\n";
208 finfo.setFile( oldFile ); 206 finfo.setFile( oldFile );
@@ -231,49 +229,59 @@ MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
231 if ( KOPrefs::instance()->mLanguageChanged ) { 229 if ( KOPrefs::instance()->mLanguageChanged ) {
232 KOPrefs::instance()->setCategoryDefaults(); 230 KOPrefs::instance()->setCategoryDefaults();
233 int count = mView->addCategories(); 231 int count = mView->addCategories();
234 KOPrefs::instance()->mLanguageChanged = false; 232 KOPrefs::instance()->mLanguageChanged = false;
235 } 233 }
236 processIncidenceSelection( 0 ); 234 processIncidenceSelection( 0 );
237 connect( mView, SIGNAL( incidenceSelected( Incidence * ) ), 235 connect( mView, SIGNAL( incidenceSelected( Incidence * ) ),
238 SLOT( processIncidenceSelection( Incidence * ) ) ); 236 SLOT( processIncidenceSelection( Incidence * ) ) );
239 connect( mView, SIGNAL( modifiedChanged( bool ) ), 237 connect( mView, SIGNAL( modifiedChanged( bool ) ),
240 SLOT( slotModifiedChanged( bool ) ) ); 238 SLOT( slotModifiedChanged( bool ) ) );
241 239
242 240
243 connect( &mSaveTimer, SIGNAL( timeout() ), SLOT( save() ) ); 241 connect( &mSaveTimer, SIGNAL( timeout() ), SLOT( save() ) );
244 mView->setModified( false ); 242 mView->setModified( false );
245 mBlockAtStartup = false; 243 mBlockAtStartup = false;
246 mView->setModified( false ); 244 mView->setModified( false );
247 setCentralWidget( mView ); 245 setCentralWidget( mView );
248 globalFlagBlockStartup = 0; 246 globalFlagBlockStartup = 0;
249 mView->show(); 247 mView->show();
250 delete splash; 248 delete splash;
251 if ( newFile ) 249 if ( newFile )
252 mView->updateConfig(); 250 mView->updateConfig();
253 // qApp->processEvents(); 251 // qApp->processEvents();
254 //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ()); 252 //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ());
255 fillSyncMenu(); 253 //fillSyncMenu();
254
255
256 connect(mSyncManager , SIGNAL( save() ), this, SLOT( save() ) );
257 connect(mSyncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) );
258 connect(mSyncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) );
259 mSyncManager->setDefaultFileName( defaultFileName());
260 mSyncManager->fillSyncMenu();
261
262
263
256 mView->viewManager()->agendaView()->setStartHour( KOPrefs::instance()->mDayBegins ); 264 mView->viewManager()->agendaView()->setStartHour( KOPrefs::instance()->mDayBegins );
257 if ( showWarning ) { 265 if ( showWarning ) {
258 KMessageBox::information( this, 266 KMessageBox::information( this,
259 "You are starting KO/Pi for the first time.\nPlease read menu: Help-What's New,\nif you did an update!\nPlease choose your timezone in the \nConfigure Dialog TAB Time Zone!\nPlease choose your language\nin the TAB Locale!\nYou get the Configure Dialog\nvia Menu: Actions - Configure....\nClick OK to show the Configure Dialog!\n", "KO/Pi information"); 267 "You are starting KO/Pi for the first time.\nPlease read menu: Help-What's New,\nif you did an update!\nPlease choose your timezone in the \nConfigure Dialog TAB Time Zone!\nPlease choose your language\nin the TAB Locale!\nYou get the Configure Dialog\nvia Menu: Actions - Configure....\nClick OK to show the Configure Dialog!\n", "KO/Pi information");
260 qApp->processEvents(); 268 qApp->processEvents();
261 mView->dialogManager()->showSyncOptions(); 269 mView->dialogManager()->showSyncOptions();
262 } 270 }
263 271
264 //US listen for result adressed from Ka/Pi 272 //US listen for result adressed from Ka/Pi
265#ifndef DESKTOP_VERSION 273#ifndef DESKTOP_VERSION
266 connect(qApp, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & ))); 274 connect(qApp, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & )));
267#endif 275#endif
268} 276}
269MainWindow::~MainWindow() 277MainWindow::~MainWindow()
270{ 278{
271 //qDebug("MainWindow::~MainWindow() "); 279 //qDebug("MainWindow::~MainWindow() ");
272 //save toolbar location 280 //save toolbar location
273 delete mServerSocket; 281 delete mServerSocket;
274 delete mCalendar; 282 delete mCalendar;
275 delete KOPrefs::instance(); 283 delete KOPrefs::instance();
276 delete KIncidenceFormatter::instance(); 284 delete KIncidenceFormatter::instance();
277 285
278 286
279} 287}
@@ -374,49 +382,49 @@ void MainWindow::recieve( const QCString& cmsg, const QByteArray& data )
374 //qDebug("msg: %s all: %s ", msg.latin1(), allmsg.latin1() ); 382 //qDebug("msg: %s all: %s ", msg.latin1(), allmsg.latin1() );
375 if ( msg == "-newEvent" ) { 383 if ( msg == "-newEvent" ) {
376 mView->newEvent(); 384 mView->newEvent();
377 } 385 }
378 if ( msg == "-newTodo" ) { 386 if ( msg == "-newTodo" ) {
379 mView->newTodo(); 387 mView->newTodo();
380 388
381 } 389 }
382 if ( msg == "-showWN" ) { 390 if ( msg == "-showWN" ) {
383 mView->viewManager()->showWhatsNextView(); 391 mView->viewManager()->showWhatsNextView();
384 } 392 }
385 if ( msg == "-showTodo" ) { 393 if ( msg == "-showTodo" ) {
386 mView->viewManager()->showTodoView(); 394 mView->viewManager()->showTodoView();
387 } 395 }
388 if ( msg == "-showList" ) { 396 if ( msg == "-showList" ) {
389 mView->viewManager()->showListView(); 397 mView->viewManager()->showListView();
390 } 398 }
391 else if ( msg == "-showDay" ) { 399 else if ( msg == "-showDay" ) {
392 mView->viewManager()->showDayView(); 400 mView->viewManager()->showDayView();
393 } 401 }
394 else if ( msg == "-showWWeek" ) { 402 else if ( msg == "-showWWeek" ) {
395 mView->viewManager()->showWorkWeekView(); 403 mView->viewManager()->showWorkWeekView();
396 } 404 }
397 else if ( msg == "-ringSync" ) { 405 else if ( msg == "-ringSync" ) {
398 multiSync( false ); 406 mSyncManager->multiSync( false );
399 } 407 }
400 else if ( msg == "-showWeek" ) { 408 else if ( msg == "-showWeek" ) {
401 mView->viewManager()->showWeekView(); 409 mView->viewManager()->showWeekView();
402 } 410 }
403 else if ( msg == "-showTodo" ) { 411 else if ( msg == "-showTodo" ) {
404 mView->viewManager()->showTodoView(); 412 mView->viewManager()->showTodoView();
405 } 413 }
406 else if ( msg == "-showJournal" ) { 414 else if ( msg == "-showJournal" ) {
407 mView->dateNavigator()->selectDates( 1 ); 415 mView->dateNavigator()->selectDates( 1 );
408 mView->dateNavigator()->selectToday(); 416 mView->dateNavigator()->selectToday();
409 mView->viewManager()->showJournalView(); 417 mView->viewManager()->showJournalView();
410 } 418 }
411 else if ( msg == "-showKO" ) { 419 else if ( msg == "-showKO" ) {
412 mView->viewManager()->showNextXView(); 420 mView->viewManager()->showNextXView();
413 } 421 }
414 else if ( msg == "-showWNext" || msg == "nextView()" ) { 422 else if ( msg == "-showWNext" || msg == "nextView()" ) {
415 mView->viewManager()->showWhatsNextView(); 423 mView->viewManager()->showWhatsNextView();
416 } 424 }
417 else if ( msg == "-showNextXView" ) { 425 else if ( msg == "-showNextXView" ) {
418 mView->viewManager()->showNextXView(); 426 mView->viewManager()->showNextXView();
419 } 427 }
420 428
421 429
422 } 430 }
@@ -919,276 +927,49 @@ void MainWindow::initActions()
919 configureToolBarMenu->setItemChecked( 220, true ); 927 configureToolBarMenu->setItemChecked( 220, true );
920 if (p-> mShowIconForwardFast) 928 if (p-> mShowIconForwardFast)
921 configureToolBarMenu->setItemChecked( 230, true ); 929 configureToolBarMenu->setItemChecked( 230, true );
922 if (p-> mShowIconNextDays) 930 if (p-> mShowIconNextDays)
923 configureToolBarMenu->setItemChecked( 100, true ); 931 configureToolBarMenu->setItemChecked( 100, true );
924 if (p-> mShowIconNext) 932 if (p-> mShowIconNext)
925 configureToolBarMenu->setItemChecked( 110, true ); 933 configureToolBarMenu->setItemChecked( 110, true );
926 if (p-> mShowIconJournal) 934 if (p-> mShowIconJournal)
927 configureToolBarMenu->setItemChecked( 90, true ); 935 configureToolBarMenu->setItemChecked( 90, true );
928 if (p-> mShowIconWhatsThis) 936 if (p-> mShowIconWhatsThis)
929 configureToolBarMenu->setItemChecked( 300, true ); 937 configureToolBarMenu->setItemChecked( 300, true );
930 938
931 QLabel* dummy = new QLabel( iconToolBar ); 939 QLabel* dummy = new QLabel( iconToolBar );
932 dummy->setBackgroundColor( iconToolBar->backgroundColor() ); 940 dummy->setBackgroundColor( iconToolBar->backgroundColor() );
933 if (!p-> mShowIconStretch) 941 if (!p-> mShowIconStretch)
934 iconToolBar->setStretchableWidget ( dummy ) ; 942 iconToolBar->setStretchableWidget ( dummy ) ;
935 else 943 else
936 configureToolBarMenu->setItemChecked( 5, true ); 944 configureToolBarMenu->setItemChecked( 5, true );
937 if (p-> mShowIconWhatsThis) 945 if (p-> mShowIconWhatsThis)
938 QWhatsThis::whatsThisButton ( iconToolBar ); 946 QWhatsThis::whatsThisButton ( iconToolBar );
939 connect( configureToolBarMenu, SIGNAL( activated( int ) ),this, SLOT(configureToolBar( int ) ) ); 947 connect( configureToolBarMenu, SIGNAL( activated( int ) ),this, SLOT(configureToolBar( int ) ) );
940 configureAgenda( p->mHourSize ); 948 configureAgenda( p->mHourSize );
941 connect( configureAgendaMenu, SIGNAL( activated( int ) ),this, SLOT(configureAgenda( int ) ) ); 949 connect( configureAgendaMenu, SIGNAL( activated( int ) ),this, SLOT(configureAgenda( int ) ) );
942} 950}
943void MainWindow::fillSyncMenu()
944{
945 if ( syncMenu->count() )
946 syncMenu->clear();
947 syncMenu->insertItem( i18n("Configure..."), 0 );
948 syncMenu->insertSeparator();
949 if ( mServerSocket == 0 ) {
950 syncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
951 } else {
952 syncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
953 }
954 syncMenu->insertSeparator();
955 syncMenu->insertItem( i18n("Multiple sync"), 1 );
956 syncMenu->insertSeparator();
957 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
958 config.setGroup("General");
959 QStringList prof = config.readListEntry("SyncProfileNames");
960 KOPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined");
961 if ( prof.count() < 3 ) {
962 prof.clear();
963 prof << i18n("Sharp_DTM");
964 prof << i18n("Local_file");
965 prof << i18n("Last_file");
966 KSyncProfile* temp = new KSyncProfile ();
967 temp->setName( prof[0] );
968 temp->writeConfig(&config);
969 temp->setName( prof[1] );
970 temp->writeConfig(&config);
971 temp->setName( prof[2] );
972 temp->writeConfig(&config);
973 config.setGroup("General");
974 config.writeEntry("SyncProfileNames",prof);
975 config.writeEntry("ExternSyncProfiles","Sharp_DTM");
976 config.sync();
977 delete temp;
978 }
979 KOPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
980 KOPrefs::instance()->mSyncProfileNames = prof;
981 int i;
982 for ( i = 0; i < prof.count(); ++i ) {
983
984 syncMenu->insertItem( prof[i], 1000+i );
985 if ( i == 2 )
986 syncMenu->insertSeparator();
987 }
988 QDir app_dir;
989 if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
990 syncMenu->setItemEnabled( false , 1000 );
991 }
992}
993
994int MainWindow::ringSync()
995{
996 int syncedProfiles = 0;
997 int i;
998 QTime timer;
999 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
1000 QStringList syncProfileNames = KOPrefs::instance()->mSyncProfileNames;
1001 KSyncProfile* temp = new KSyncProfile ();
1002 KOPrefs::instance()->mAskForPreferences = false;
1003 for ( i = 0; i < syncProfileNames.count(); ++i ) {
1004 mCurrentSyncProfile = i;
1005 temp->setName(syncProfileNames[mCurrentSyncProfile]);
1006 temp->readConfig(&config);
1007 if ( temp->getIncludeInRingSync() && ( i < 1 || i > 2 )) {
1008 setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
1009 ++syncedProfiles;
1010 // KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
1011 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
1012 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
1013 KOPrefs::instance()->mWriteBackInFuture = 0;
1014 if ( temp->getWriteBackFuture() )
1015 KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
1016 KOPrefs::instance()->mShowSyncSummary = false;
1017 mView->setSyncDevice(syncProfileNames[i] );
1018 mView->setSyncName( KOPrefs::instance()->mLocalMachineName );
1019 if ( i == 0 ) {
1020 syncSharp();
1021 } else {
1022 if ( temp->getIsLocalFileSync() ) {
1023 if ( syncWithFile( temp->getRemoteFileName( ), true ) )
1024 KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName();
1025 } else {
1026 if ( temp->getIsPhoneSync() ) {
1027 KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
1028 KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
1029 KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
1030 syncPhone();
1031 } else if ( temp->getIsPiSync() ) {
1032 mPassWordPiSync = temp->getRemotePw();
1033 KOPrefs::instance()->mActiveSyncPort = temp->getRemotePort();
1034 KOPrefs::instance()->mActiveSyncIP = temp->getRemoteIP();
1035 syncPi();
1036 } else
1037 syncRemote( temp, false );
1038 951
1039 }
1040 }
1041 timer.start();
1042 setCaption(i18n("Multiple sync in progress ... please wait!") );
1043 while ( timer.elapsed () < 2000 ) {
1044 qApp->processEvents();
1045#ifndef _WIN32_
1046 sleep (1);
1047#endif
1048 }
1049
1050 }
1051
1052 }
1053 delete temp;
1054 return syncedProfiles;
1055}
1056
1057void MainWindow::multiSync( bool askforPrefs )
1058{
1059 if (mBlockSaveFlag)
1060 return;
1061 mBlockSaveFlag = true;
1062 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
1063 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
1064 question,
1065 i18n("Yes"), i18n("No"),
1066 0, 0 ) != 0 ) {
1067 mBlockSaveFlag = false;
1068 setCaption(i18n("Aborted! Nothing synced!"));
1069 return;
1070 }
1071 mView->setSyncDevice(i18n("Multiple profiles") );
1072 KOPrefs::instance()->mSyncAlgoPrefs = KOPrefs::instance()->mRingSyncAlgoPrefs;
1073 if ( askforPrefs ) {
1074 mView->edit_sync_options();
1075 KOPrefs::instance()->mRingSyncAlgoPrefs = KOPrefs::instance()->mSyncAlgoPrefs;
1076 }
1077 setCaption(i18n("Multiple sync started.") );
1078 qApp->processEvents();
1079 int num = ringSync() ;
1080 if ( num > 1 )
1081 ringSync();
1082 mBlockSaveFlag = false;
1083 if ( num )
1084 save();
1085 if ( num )
1086 setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) );
1087 else
1088 setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
1089 return;
1090}
1091void MainWindow::slotSyncMenu( int action )
1092{
1093 qDebug("syncaction %d ", action);
1094 if ( action == 0 ) {
1095
1096 // seems to be a Qt2 event handling bug
1097 // syncmenu.clear causes a segfault at first time
1098 // when we call it after the main event loop, it is ok
1099 // same behaviour when calling OM/Pi via QCOP for the first time
1100 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
1101 //confSync();
1102
1103 return;
1104 }
1105 if ( action == 1 ) {
1106 multiSync( true );
1107 return;
1108 }
1109 if ( action == 2 ) {
1110 enableQuick();
1111 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
1112 return;
1113 }
1114 if ( action == 3 ) {
1115 delete mServerSocket;
1116 mServerSocket = 0;
1117 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
1118 return;
1119 }
1120
1121 if (mBlockSaveFlag)
1122 return;
1123 mBlockSaveFlag = true;
1124 mCurrentSyncProfile = action - 1000 ;
1125 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] );
1126 mView->setSyncName( KOPrefs::instance()->mLocalMachineName );
1127 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
1128 KSyncProfile* temp = new KSyncProfile ();
1129 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
1130 temp->readConfig(&config);
1131 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
1132 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
1133 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
1134 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
1135 KOPrefs::instance()->mWriteBackInFuture = 0;
1136 if ( temp->getWriteBackFuture() )
1137 KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
1138 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
1139 if ( action == 1000 ) {
1140 syncSharp();
1141
1142 } else if ( action == 1001 ) {
1143 syncLocalFile();
1144
1145 } else if ( action == 1002 ) {
1146 quickSyncLocalFile();
1147
1148 } else if ( action >= 1003 ) {
1149 if ( temp->getIsLocalFileSync() ) {
1150 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
1151 KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName();
1152 } else {
1153 if ( temp->getIsPhoneSync() ) {
1154 KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
1155 KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
1156 KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
1157 syncPhone();
1158 } else if ( temp->getIsPiSync() ) {
1159 mPassWordPiSync = temp->getRemotePw();
1160 KOPrefs::instance()->mActiveSyncPort = temp->getRemotePort();
1161 KOPrefs::instance()->mActiveSyncIP = temp->getRemoteIP();
1162 syncPi();
1163 } else
1164 syncRemote( temp );
1165
1166 }
1167 }
1168 delete temp;
1169 mBlockSaveFlag = false;
1170}
1171void MainWindow::exportToPhone( int mode ) 952void MainWindow::exportToPhone( int mode )
1172{ 953{
1173 954
1174 //ex2phone->insertItem(i18n("Complete calendar..."), 1 ); 955 //ex2phone->insertItem(i18n("Complete calendar..."), 1 );
1175 //ex2phone->insertItem(i18n("Filtered calendar..."), 2 ); 956 //ex2phone->insertItem(i18n("Filtered calendar..."), 2 );
1176 KOex2phonePrefs ex2phone; 957 KOex2phonePrefs ex2phone;
1177 958
1178 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); 959 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection );
1179 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); 960 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice );
1180 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); 961 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel );
1181 if ( mode == 1 ) 962 if ( mode == 1 )
1182 ex2phone.setCaption(i18n("Export complete calendar")); 963 ex2phone.setCaption(i18n("Export complete calendar"));
1183 if ( mode == 2 ) 964 if ( mode == 2 )
1184 ex2phone.setCaption(i18n("Export filtered calendar")); 965 ex2phone.setCaption(i18n("Export filtered calendar"));
1185 966
1186 if ( !ex2phone.exec() ) { 967 if ( !ex2phone.exec() ) {
1187 return; 968 return;
1188 } 969 }
1189 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); 970 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text();
1190 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); 971 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text();
1191 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); 972 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text();
1192 973
1193 int inFuture = 0; 974 int inFuture = 0;
1194 if ( ex2phone.mWriteBackFuture->isChecked() ) 975 if ( ex2phone.mWriteBackFuture->isChecked() )
@@ -1563,80 +1344,79 @@ void MainWindow::importQtopia()
1563 i18n("Not supported \non desktop!\n"), 1344 i18n("Not supported \non desktop!\n"),
1564 i18n("Ok"), i18n("Cancel"), 0, 1345 i18n("Ok"), i18n("Cancel"), 0,
1565 0, 1 ); 1346 0, 1 );
1566 1347
1567#endif 1348#endif
1568} 1349}
1569 1350
1570void MainWindow::saveOnClose() 1351void MainWindow::saveOnClose()
1571{ 1352{
1572 KOPrefs *p = KOPrefs::instance(); 1353 KOPrefs *p = KOPrefs::instance();
1573 p->mToolBarHor = ( iconToolBar->orientation () == Qt:: Horizontal ); 1354 p->mToolBarHor = ( iconToolBar->orientation () == Qt:: Horizontal );
1574 p->mToolBarUp = iconToolBar->x() > width()/2 || 1355 p->mToolBarUp = iconToolBar->x() > width()/2 ||
1575 iconToolBar->y() > height()/2; 1356 iconToolBar->y() > height()/2;
1576 mView->writeSettings(); 1357 mView->writeSettings();
1577 if ( mCalendarModifiedFlag || mView->checkFileChanged( defaultFileName())) 1358 if ( mCalendarModifiedFlag || mView->checkFileChanged( defaultFileName()))
1578 save(); 1359 save();
1579} 1360}
1580void MainWindow::slotModifiedChanged( bool changed ) 1361void MainWindow::slotModifiedChanged( bool changed )
1581{ 1362{
1582 if ( mBlockAtStartup ) 1363 if ( mBlockAtStartup )
1583 return; 1364 return;
1584 int msec; 1365 int msec;
1585 // we store the changes after 1 minute, 1366 // we store the changes after 1 minute,
1586 // and for safety reasons after 10 minutes again 1367 // and for safety reasons after 10 minutes again
1587 if ( !mBlockSaveFlag ) 1368 if ( !mSyncManager->blockSave() )
1588 msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000; 1369 msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000;
1589 else 1370 else
1590 msec = 1000 * 600; 1371 msec = 1000 * 600;
1591 mSaveTimer.start( msec, true ); // 1 minute 1372 mSaveTimer.start( msec, true ); // 1 minute
1592 qDebug("KO: Saving File in %d secs!", msec/1000); 1373 qDebug("KO: Saving File in %d secs!", msec/1000);
1593 mCalendarModifiedFlag = true; 1374 mCalendarModifiedFlag = true;
1594} 1375}
1595void MainWindow::save() 1376void MainWindow::save()
1596{ 1377{
1597 if ( mBlockSaveFlag ) 1378 if ( mSyncManager->blockSave() )
1598 return; 1379 return;
1599 bool store = mBlockSaveFlag; 1380 mSyncManager->setBlockSave(true);
1600 mBlockSaveFlag = true;
1601 if ( mView->checkFileVersion( defaultFileName()) ) { 1381 if ( mView->checkFileVersion( defaultFileName()) ) {
1602 1382
1603 QTime neededSaveTime = QDateTime::currentDateTime().time(); 1383 QTime neededSaveTime = QDateTime::currentDateTime().time();
1604 setCaption(i18n("KO/Pi:Saving Data to File ..." )); 1384 setCaption(i18n("KO/Pi:Saving Data to File ..." ));
1605 qDebug("KO: Start saving data to file!"); 1385 qDebug("KO: Start saving data to file!");
1606 mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1386 mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1607 mView->saveCalendar( defaultFileName() ); 1387 mView->saveCalendar( defaultFileName() );
1608 1388
1609 int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() ); 1389 int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() );
1610 mView->watchSavedFile(); 1390 mView->watchSavedFile();
1611 qDebug("KO: Needed %d ms for saving.",msNeeded ); 1391 qDebug("KO: Needed %d ms for saving.",msNeeded );
1612 QString savemes; 1392 QString savemes;
1613 savemes.sprintf(i18n("KO/Pi:File Saved. Needed %d sec, %d ms"),(msNeeded/1000)%100,msNeeded%1000 ); 1393 savemes.sprintf(i18n("KO/Pi:File Saved. Needed %d sec, %d ms"),(msNeeded/1000)%100,msNeeded%1000 );
1614 setCaption(savemes); 1394 setCaption(savemes);
1615 } else 1395 } else
1616 setCaption(i18n("Saving cancelled!")); 1396 setCaption(i18n("Saving cancelled!"));
1617 mCalendarModifiedFlag = false; 1397 mCalendarModifiedFlag = false;
1618 mBlockSaveFlag = store; 1398 mSyncManager->setBlockSave( false );
1619} 1399}
1620 1400
1621void MainWindow::keyReleaseEvent ( QKeyEvent * e) 1401void MainWindow::keyReleaseEvent ( QKeyEvent * e)
1622{ 1402{
1623 if ( !e->isAutoRepeat() ) { 1403 if ( !e->isAutoRepeat() ) {
1624 mFlagKeyPressed = false; 1404 mFlagKeyPressed = false;
1625 } 1405 }
1626} 1406}
1627void MainWindow::keyPressEvent ( QKeyEvent * e ) 1407void MainWindow::keyPressEvent ( QKeyEvent * e )
1628{ 1408{
1629 qApp->processEvents(); 1409 qApp->processEvents();
1630 if ( e->isAutoRepeat() && !mFlagKeyPressed ) { 1410 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
1631 e->ignore(); 1411 e->ignore();
1632 // qDebug(" ignore %d",e->isAutoRepeat() ); 1412 // qDebug(" ignore %d",e->isAutoRepeat() );
1633 return; 1413 return;
1634 } 1414 }
1635 if (! e->isAutoRepeat() ) 1415 if (! e->isAutoRepeat() )
1636 mFlagKeyPressed = true; 1416 mFlagKeyPressed = true;
1637 KOPrefs *p = KOPrefs::instance(); 1417 KOPrefs *p = KOPrefs::instance();
1638 bool showSelectedDates = false; 1418 bool showSelectedDates = false;
1639 int size; 1419 int size;
1640 int pro = 0; 1420 int pro = 0;
1641 //qDebug("MainWindow::keyPressEvent "); 1421 //qDebug("MainWindow::keyPressEvent ");
1642 switch ( e->key() ) { 1422 switch ( e->key() ) {
@@ -2008,341 +1788,51 @@ void MainWindow::exportVCalendar()
2008 info.setFile( fn ); 1788 info.setFile( fn );
2009 QString mes; 1789 QString mes;
2010 bool createbup = true; 1790 bool createbup = true;
2011 if ( info. exists() ) { 1791 if ( info. exists() ) {
2012 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); 1792 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
2013 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 1793 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
2014 i18n("Overwrite!"), i18n("Cancel"), 0, 1794 i18n("Overwrite!"), i18n("Cancel"), 0,
2015 0, 1 ); 1795 0, 1 );
2016 if ( result != 0 ) { 1796 if ( result != 0 ) {
2017 createbup = false; 1797 createbup = false;
2018 } 1798 }
2019 } 1799 }
2020 if ( createbup ) { 1800 if ( createbup ) {
2021 if ( mView->exportVCalendar( fn ) ) { 1801 if ( mView->exportVCalendar( fn ) ) {
2022 KOPrefs::instance()->mLastVcalFile = fn; 1802 KOPrefs::instance()->mLastVcalFile = fn;
2023 if ( fn.length() > 20 ) 1803 if ( fn.length() > 20 )
2024 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ; 1804 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ;
2025 else 1805 else
2026 mes = i18n("KO/Pi:Exported to %1").arg(fn ); 1806 mes = i18n("KO/Pi:Exported to %1").arg(fn );
2027 setCaption(mes); 1807 setCaption(mes);
2028 } 1808 }
2029 } 1809 }
2030 1810
2031} 1811}
2032QString MainWindow::getPassword( )
2033{
2034 QString retfile = "";
2035 QDialog dia ( this, "input-dialog", true );
2036 QLineEdit lab ( &dia );
2037 lab.setEchoMode( QLineEdit::Password );
2038 QVBoxLayout lay( &dia );
2039 lay.setMargin(7);
2040 lay.setSpacing(7);
2041 lay.addWidget( &lab);
2042 dia.setFixedSize( 230,50 );
2043 dia.setCaption( i18n("Enter password") );
2044 QPushButton pb ( "OK", &dia);
2045 lay.addWidget( &pb );
2046 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2047 dia.show();
2048 int res = dia.exec();
2049 if ( res )
2050 retfile = lab.text();
2051 dia.hide();
2052 qApp->processEvents();
2053 return retfile;
2054
2055}
2056 1812
2057void MainWindow::enableQuick() 1813void MainWindow::syncFileRequest()
2058{ 1814{
2059 QDialog dia ( this, "input-dialog", true ); 1815 save();
2060 QLineEdit lab ( &dia );
2061 QVBoxLayout lay( &dia );
2062 lab.setText( KOPrefs::instance()->mPassiveSyncPort );
2063 lay.setMargin(7);
2064 lay.setSpacing(7);
2065 QLabel label ( i18n("Port number (Default: 9197)"), &dia );
2066 lay.addWidget( &label);
2067 lay.addWidget( &lab);
2068
2069 QLineEdit lepw ( &dia );
2070 lepw.setText( KOPrefs::instance()->mPassiveSyncPw );
2071 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
2072 lay.addWidget( &label2);
2073 lay.addWidget( &lepw);
2074 dia.setFixedSize( 230,80 );
2075 dia.setCaption( i18n("Enter port for Pi-Sync") );
2076 QPushButton pb ( "OK", &dia);
2077 lay.addWidget( &pb );
2078 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2079 dia.show();
2080 if ( ! dia.exec() )
2081 return;
2082 dia.hide();
2083 qApp->processEvents();
2084 KOPrefs::instance()->mPassiveSyncPw = lepw.text();
2085 KOPrefs::instance()->mPassiveSyncPort = lab.text();
2086 bool ok;
2087 Q_UINT16 port = KOPrefs::instance()->mPassiveSyncPort.toUInt(&ok);
2088 if ( ! ok ) {
2089 KMessageBox::information( this, i18n("No valid port"));
2090 return;
2091 }
2092 //qDebug("port %d ", port);
2093 mServerSocket = new KServerSocket ( KOPrefs::instance()->mPassiveSyncPw, port ,1 );
2094 mServerSocket->setFileName( defaultFileName() );
2095 //qDebug("connected ");
2096 if ( !mServerSocket->ok() ) {
2097 KMessageBox::information( this, i18n("Failed to bind or\nlisten to the port!"));
2098 delete mServerSocket;
2099 mServerSocket = 0;
2100 return;
2101 }
2102 connect( mServerSocket, SIGNAL ( saveFile() ), this, SLOT ( save() ) );
2103 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SLOT ( getFile( bool ) ) );
2104} 1816}
2105
2106void MainWindow::getFile( bool success ) 1817void MainWindow::getFile( bool success )
2107{ 1818{
2108 if ( ! success ) { 1819 if ( ! success ) {
2109 setCaption( i18n("Error receiving file. Nothing changed!") ); 1820 setCaption( i18n("Error receiving file. Nothing changed!") );
2110 return; 1821 return;
2111 } 1822 }
2112 mView->watchSavedFile(); 1823 mView->watchSavedFile();
2113 mView->openCalendar( defaultFileName() ); 1824 mView->openCalendar( defaultFileName() );
2114 setCaption( i18n("Pi-Sync successful!") ); 1825 setCaption( i18n("Pi-Sync successful!") );
2115 1826
2116} 1827}
2117 1828
2118
2119void MainWindow::syncPi()
2120{
2121 qApp->processEvents();
2122 bool ok;
2123 Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok);
2124 if ( ! ok ) {
2125 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
2126 return;
2127 }
2128 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this );
2129 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
2130 setCaption( i18n("Sending request for remote file ...") );
2131 commandSocket->readFile( syncFileName() );
2132}
2133
2134void MainWindow::deleteCommandSocket(KCommandSocket*s, int state)
2135{
2136 qDebug("MainWindow::deleteCommandSocket %d", state);
2137
2138 //enum { success, errorW, errorR, quiet };
2139 if ( state == KCommandSocket::errorR ) {
2140 setCaption( i18n("ERROR: Receiving remote file failed.") );
2141 delete s;
2142 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, KOPrefs::instance()->mActiveSyncPort.toUInt(), KOPrefs::instance()->mActiveSyncIP, this );
2143 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
2144 commandSocket->sendStop();
2145 return;
2146
2147 } else if ( state == KCommandSocket::errorW ) {
2148 setCaption( i18n("ERROR:Writing back file failed.") );
2149
2150 } else if ( state == KCommandSocket::successR ) {
2151 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
2152
2153 } else if ( state == KCommandSocket::successW ) {
2154 setCaption( i18n("Pi-Sync succesful!") );
2155 }
2156
2157 delete s;
2158}
2159
2160void MainWindow::readFileFromSocket()
2161{
2162 QString fileName = syncFileName();
2163 setCaption( i18n("Remote file saved to temp file.") );
2164 if ( ! syncWithFile( fileName , true ) ) {
2165 setCaption( i18n("Syncing failed.") );
2166 qDebug("Syncing failed ");
2167 return;
2168 }
2169 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, KOPrefs::instance()->mActiveSyncPort.toUInt(), KOPrefs::instance()->mActiveSyncIP, this );
2170 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
2171 if ( KOPrefs::instance()->mWriteBackFile )
2172 commandSocket->writeFile( fileName );
2173 else {
2174 commandSocket->sendStop();
2175 setCaption( i18n("Pi-Sync succesful!") );
2176 }
2177}
2178
2179void MainWindow::syncLocalFile()
2180{
2181
2182 QString fn =KOPrefs::instance()->mLastSyncedLocalFile;
2183
2184 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
2185 if ( fn == "" )
2186 return;
2187 //mView->setSyncDevice("local-file" );
2188 if ( syncWithFile( fn, false ) ) {
2189 // Event* e = mView->getLastSyncEvent();
2190// e->setReadOnly( false );
2191// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile);
2192// e->setReadOnly( true );
2193 }
2194
2195}
2196
2197bool MainWindow::syncWithFile( QString fn , bool quick )
2198{
2199 bool ret = false;
2200 QFileInfo info;
2201 info.setFile( fn );
2202 QString mess;
2203 bool loadbup = true;
2204 if ( !info. exists() ) {
2205 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
2206 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2207 mess );
2208 return ret;
2209 }
2210 int result = 0;
2211 if ( !quick ) {
2212 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
2213 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2214 mess,
2215 i18n("Sync"), i18n("Cancel"), 0,
2216 0, 1 );
2217 if ( result )
2218 return false;
2219 }
2220 if ( KOPrefs::instance()->mAskForPreferences )
2221 mView->edit_sync_options();
2222 if ( result == 0 ) {
2223 //qDebug("Now sycing ... ");
2224 if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) )
2225 setCaption( i18n("Synchronization successful") );
2226 else
2227 setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
2228 if ( ! quick )
2229 KOPrefs::instance()->mLastSyncedLocalFile = fn;
2230 slotModifiedChanged( true );
2231 }
2232 return ret;
2233}
2234void MainWindow::quickSyncLocalFile()
2235{
2236 //mView->setSyncDevice("local-file" );
2237 //qDebug("quickSyncLocalFile() ");
2238 if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) {
2239 // Event* e = mView->getLastSyncEvent();
2240// e->setReadOnly( false );
2241// e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile);
2242// e->setReadOnly( true );
2243
2244 }
2245}
2246
2247void MainWindow::confSync()
2248{
2249 mView->confSync();
2250 fillSyncMenu();
2251}
2252void MainWindow::syncRemote( KSyncProfile* prof, bool ask)
2253{
2254 QString question;
2255 if ( ask ) {
2256 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
2257 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2258 question,
2259 i18n("Yes"), i18n("No"),
2260 0, 0 ) != 0 )
2261 return;
2262 }
2263 QString command = prof->getPreSyncCommand();
2264 int fi;
2265 if ( (fi = command.find("$PWD$")) > 0 ) {
2266 QString pwd = getPassword();
2267 command = command.left( fi )+ pwd + command.mid( fi+5 );
2268
2269 }
2270 int maxlen = 30;
2271 if ( QApplication::desktop()->width() > 320 )
2272 maxlen += 25;
2273 setCaption ( i18n( "Copy remote file to local machine..." ) );
2274 int fileSize = 0;
2275 int result = system ( command );
2276 // 0 : okay
2277 // 256: no such file or dir
2278 //
2279 qDebug("KO: Remote copy result(0 = okay): %d ",result );
2280 if ( result != 0 ) {
2281 int len = maxlen;
2282 while ( len < command.length() ) {
2283 command.insert( len , "\n" );
2284 len += maxlen +2;
2285 }
2286 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ;
2287 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2288 question,
2289 i18n("Okay!")) ;
2290 setCaption ("KO/Pi");
2291 return;
2292 }
2293 setCaption ( i18n( "Copying succeed." ) );
2294 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
2295 if ( syncWithFile( prof->getLocalTempFile(), true ) ) {
2296// Event* e = mView->getLastSyncEvent();
2297// e->setReadOnly( false );
2298// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2299// e->setReadOnly( true );
2300 if ( KOPrefs::instance()->mWriteBackFile ) {
2301 command = prof->getPostSyncCommand();
2302 int fi;
2303 if ( (fi = command.find("$PWD$")) > 0 ) {
2304 QString pwd = getPassword();
2305 command = command.left( fi )+ pwd + command.mid( fi+5 );
2306
2307 }
2308 setCaption ( i18n( "Writing back file ..." ) );
2309 result = system ( command );
2310 qDebug("KO: Writing back file result: %d ", result);
2311 if ( result != 0 ) {
2312 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
2313 return;
2314 } else {
2315 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2316 }
2317 }
2318 }
2319 return;
2320}
2321
2322void MainWindow::syncSharp()
2323{
2324 if ( mCalendarModifiedFlag )
2325 save();
2326 mView->syncSharp();
2327 slotModifiedChanged( true );
2328
2329}
2330void MainWindow::syncPhone()
2331{
2332 if ( mCalendarModifiedFlag )
2333 save();
2334 mView->syncPhone();
2335 slotModifiedChanged( true );
2336
2337}
2338
2339void MainWindow::printSel( ) 1829void MainWindow::printSel( )
2340{ 1830{
2341 mView->viewManager()->agendaView()->agenda()->printSelection(); 1831 mView->viewManager()->agendaView()->agenda()->printSelection();
2342} 1832}
2343 1833
2344void MainWindow::printCal() 1834void MainWindow::printCal()
2345{ 1835{
2346 mView->print();//mCp->showDialog(); 1836 mView->print();//mCp->showDialog();
2347} 1837}
2348 1838