summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp32
-rw-r--r--korganizer/mainwindow.h1
2 files changed, 19 insertions, 14 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index ebe761a..2e6b5c8 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -1,587 +1,588 @@
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 <qmessagebox.h> 7#include <qmessagebox.h>
8#include <qlineedit.h> 8#include <qlineedit.h>
9#include <qtextcodec.h> 9#include <qtextcodec.h>
10#include <qfile.h> 10#include <qfile.h>
11#include <qdir.h> 11#include <qdir.h>
12#include <qapp.h> 12#include <qapp.h>
13#include <qfileinfo.h> 13#include <qfileinfo.h>
14#include <qlabel.h> 14#include <qlabel.h>
15#include <qmap.h> 15#include <qmap.h>
16#include <qwmatrix.h> 16#include <qwmatrix.h>
17#include <qtextbrowser.h> 17#include <qtextbrowser.h>
18#include <qtextstream.h> 18#include <qtextstream.h>
19#ifndef DESKTOP_VERSION 19#ifndef DESKTOP_VERSION
20#include <qpe/global.h> 20#include <qpe/global.h>
21#include <qpe/qpemenubar.h> 21#include <qpe/qpemenubar.h>
22#include <qpe/qpetoolbar.h> 22#include <qpe/qpetoolbar.h>
23#include <qpe/resource.h> 23#include <qpe/resource.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <qtopia/alarmserver.h> 25#include <qtopia/alarmserver.h>
26#include <qtopia/qcopenvelope_qws.h> 26#include <qtopia/qcopenvelope_qws.h>
27#else 27#else
28#include <qmenubar.h> 28#include <qmenubar.h>
29#include <qtoolbar.h> 29#include <qtoolbar.h>
30#include <qapplication.h> 30#include <qapplication.h>
31//#include <resource.h> 31//#include <resource.h>
32 32
33#endif 33#endif
34#include <libkcal/calendarlocal.h> 34#include <libkcal/calendarlocal.h>
35#include <libkcal/todo.h> 35#include <libkcal/todo.h>
36#include <libkdepim/ksyncprofile.h> 36#include <libkdepim/ksyncprofile.h>
37#include <libkcal/kincidenceformatter.h> 37#include <libkcal/kincidenceformatter.h>
38#include <libkdepim/kpimglobalprefs.h> 38#include <libkdepim/kpimglobalprefs.h>
39 39
40#include "calendarview.h" 40#include "calendarview.h"
41#include "koviewmanager.h" 41#include "koviewmanager.h"
42#include "datenavigator.h" 42#include "datenavigator.h"
43#include "koagendaview.h" 43#include "koagendaview.h"
44#include "koagenda.h" 44#include "koagenda.h"
45#include "kodialogmanager.h" 45#include "kodialogmanager.h"
46#include "kdialogbase.h" 46#include "kdialogbase.h"
47#include "kapplication.h" 47#include "kapplication.h"
48#include "kofilterview.h" 48#include "kofilterview.h"
49#include "kstandarddirs.h" 49#include "kstandarddirs.h"
50#include "koprefs.h" 50#include "koprefs.h"
51#include "kfiledialog.h" 51#include "kfiledialog.h"
52#include "koglobals.h" 52#include "koglobals.h"
53#include "kglobal.h" 53#include "kglobal.h"
54#include "klocale.h" 54#include "klocale.h"
55#include "kconfig.h" 55#include "kconfig.h"
56#include "simplealarmclient.h" 56#include "simplealarmclient.h"
57#include "externalapphandler.h" 57#include "externalapphandler.h"
58 58
59using namespace KCal; 59using namespace KCal;
60#ifndef _WIN32_ 60#ifndef _WIN32_
61#include <unistd.h> 61#include <unistd.h>
62#else 62#else
63#include "koimportoldialog.h" 63#include "koimportoldialog.h"
64#endif 64#endif
65#include "mainwindow.h" 65#include "mainwindow.h"
66 66
67int globalFlagBlockStartup; 67int globalFlagBlockStartup;
68MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : 68MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
69 QMainWindow( parent, name ) 69 QMainWindow( parent, name )
70{ 70{
71 71
72#ifdef DESKTOP_VERSION 72#ifdef DESKTOP_VERSION
73 setFont( QFont("Arial"), 14 ); 73 setFont( QFont("Arial"), 14 );
74#endif 74#endif
75 mCommandSocket = 0; 75 mCommandSocket = 0;
76 mCommandSocketFinish = 0;
76 mSyncActionDialog = 0; 77 mSyncActionDialog = 0;
77 mServerSocket = 0; 78 mServerSocket = 0;
78 mClosed = false; 79 mClosed = false;
79 //QString confFile = KStandardDirs::appDir() + "config/korganizerrc"; 80 //QString confFile = KStandardDirs::appDir() + "config/korganizerrc";
80 QString confFile = locateLocal("config","korganizerrc"); 81 QString confFile = locateLocal("config","korganizerrc");
81 QFileInfo finf ( confFile ); 82 QFileInfo finf ( confFile );
82 bool showWarning = !finf.exists(); 83 bool showWarning = !finf.exists();
83 setIcon(SmallIcon( "ko24" ) ); 84 setIcon(SmallIcon( "ko24" ) );
84 mBlockAtStartup = true; 85 mBlockAtStartup = true;
85 mFlagKeyPressed = false; 86 mFlagKeyPressed = false;
86 setCaption("KOrganizer/Pi"); 87 setCaption("KOrganizer/Pi");
87 KOPrefs *p = KOPrefs::instance(); 88 KOPrefs *p = KOPrefs::instance();
88 KPimGlobalPrefs::instance()->setGlobalConfig(); 89 KPimGlobalPrefs::instance()->setGlobalConfig();
89 // if ( QApplication::desktop()->height() > 480 ) { 90 // if ( QApplication::desktop()->height() > 480 ) {
90// if ( p->mHourSize == 4 ) 91// if ( p->mHourSize == 4 )
91// p->mHourSize = 6; 92// p->mHourSize = 6;
92// } 93// }
93 if ( p->mHourSize > 18 ) 94 if ( p->mHourSize > 18 )
94 p->mHourSize = 18; 95 p->mHourSize = 18;
95 QMainWindow::ToolBarDock tbd; 96 QMainWindow::ToolBarDock tbd;
96 if ( p->mToolBarHor ) { 97 if ( p->mToolBarHor ) {
97 if ( p->mToolBarUp ) 98 if ( p->mToolBarUp )
98 tbd = Bottom; 99 tbd = Bottom;
99 else 100 else
100 tbd = Top; 101 tbd = Top;
101 } 102 }
102 else { 103 else {
103 if ( p->mToolBarUp ) 104 if ( p->mToolBarUp )
104 tbd = Right; 105 tbd = Right;
105 else 106 else
106 tbd = Left; 107 tbd = Left;
107 } 108 }
108 if ( KOPrefs::instance()->mUseAppColors ) 109 if ( KOPrefs::instance()->mUseAppColors )
109 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 110 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
110 globalFlagBlockStartup = 1; 111 globalFlagBlockStartup = 1;
111 iconToolBar = new QPEToolBar( this ); 112 iconToolBar = new QPEToolBar( this );
112 addToolBar (iconToolBar , tbd ); 113 addToolBar (iconToolBar , tbd );
113 mBlockSaveFlag = false; 114 mBlockSaveFlag = false;
114 mCalendarModifiedFlag = false; 115 mCalendarModifiedFlag = false;
115 116
116 QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this ); 117 QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this );
117 splash->setAlignment ( AlignCenter ); 118 splash->setAlignment ( AlignCenter );
118 setCentralWidget( splash ); 119 setCentralWidget( splash );
119#ifndef DESKTOP_VERSION 120#ifndef DESKTOP_VERSION
120 showMaximized(); 121 showMaximized();
121#endif 122#endif
122 //qDebug("Mainwidget x %d y %d w %d h %d", x(), y(), width(), height ()); 123 //qDebug("Mainwidget x %d y %d w %d h %d", x(), y(), width(), height ());
123 setDefaultPreferences(); 124 setDefaultPreferences();
124 mCalendar = new CalendarLocal(); 125 mCalendar = new CalendarLocal();
125 mView = new CalendarView( mCalendar, this,"mCalendar " ); 126 mView = new CalendarView( mCalendar, this,"mCalendar " );
126 mView->hide(); 127 mView->hide();
127 //mView->resize(splash->size() ); 128 //mView->resize(splash->size() );
128 initActions(); 129 initActions();
129#ifndef DESKTOP_VERSION 130#ifndef DESKTOP_VERSION
130 iconToolBar->show(); 131 iconToolBar->show();
131 qApp->processEvents(); 132 qApp->processEvents();
132#endif 133#endif
133 //qDebug("Splashwidget x %d y %d w %d h %d", splash-> x(), splash->y(), splash->width(),splash-> height ()); 134 //qDebug("Splashwidget x %d y %d w %d h %d", splash-> x(), splash->y(), splash->width(),splash-> height ());
134 int vh = height() ; 135 int vh = height() ;
135 int vw = width(); 136 int vw = width();
136 //qDebug("Toolbar hei %d ",iconToolBar->height() ); 137 //qDebug("Toolbar hei %d ",iconToolBar->height() );
137 if ( iconToolBar->orientation () == Qt:: Horizontal ) { 138 if ( iconToolBar->orientation () == Qt:: Horizontal ) {
138 vh -= iconToolBar->height(); 139 vh -= iconToolBar->height();
139 } else { 140 } else {
140 vw -= iconToolBar->height(); 141 vw -= iconToolBar->height();
141 } 142 }
142 //mView->setMaximumSize( splash->size() ); 143 //mView->setMaximumSize( splash->size() );
143 //mView->resize( splash->size() ); 144 //mView->resize( splash->size() );
144 //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ()); 145 //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ());
145 mView->readSettings(); 146 mView->readSettings();
146 bool oldOpened = false; 147 bool oldOpened = false;
147 bool newFile = false; 148 bool newFile = false;
148 if( !QFile::exists( defaultFileName() ) ) { 149 if( !QFile::exists( defaultFileName() ) ) {
149 QFileInfo finfo ( defaultFileName() ); 150 QFileInfo finfo ( defaultFileName() );
150 QString oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/Applications/korganizer/mycalendar.ics"); 151 QString oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/Applications/korganizer/mycalendar.ics");
151 qDebug("oldfile %s ", oldFile.latin1()); 152 qDebug("oldfile %s ", oldFile.latin1());
152 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"; 153 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";
153 finfo.setFile( oldFile ); 154 finfo.setFile( oldFile );
154 if (finfo.exists() ) { 155 if (finfo.exists() ) {
155 KMessageBox::information( this, message); 156 KMessageBox::information( this, message);
156 mView->openCalendar( oldFile ); 157 mView->openCalendar( oldFile );
157 qApp->processEvents(); 158 qApp->processEvents();
158 } else { 159 } else {
159 oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/korganizer/mycalendar.ics"); 160 oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/korganizer/mycalendar.ics");
160 finfo.setFile( oldFile ); 161 finfo.setFile( oldFile );
161 if (finfo.exists() ) { 162 if (finfo.exists() ) {
162 KMessageBox::information( this, message); 163 KMessageBox::information( this, message);
163 mView->openCalendar( oldFile ); 164 mView->openCalendar( oldFile );
164 qApp->processEvents(); 165 qApp->processEvents();
165 } 166 }
166 } 167 }
167 mView->saveCalendar( defaultFileName() ); 168 mView->saveCalendar( defaultFileName() );
168 newFile = true; 169 newFile = true;
169 } 170 }
170 171
171 QTime neededSaveTime = QDateTime::currentDateTime().time(); 172 QTime neededSaveTime = QDateTime::currentDateTime().time();
172 if ( ! oldOpened ) 173 if ( ! oldOpened )
173 mView->openCalendar( defaultFileName() ); 174 mView->openCalendar( defaultFileName() );
174 int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() ); 175 int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() );
175 qDebug("KO: Calendar loading time: %d ms",msNeeded ); 176 qDebug("KO: Calendar loading time: %d ms",msNeeded );
176 177
177 if ( KOPrefs::instance()->mLanguageChanged ) { 178 if ( KOPrefs::instance()->mLanguageChanged ) {
178 KOPrefs::instance()->setCategoryDefaults(); 179 KOPrefs::instance()->setCategoryDefaults();
179 int count = mView->addCategories(); 180 int count = mView->addCategories();
180 KOPrefs::instance()->mLanguageChanged = false; 181 KOPrefs::instance()->mLanguageChanged = false;
181 } 182 }
182 processIncidenceSelection( 0 ); 183 processIncidenceSelection( 0 );
183 connect( mView, SIGNAL( incidenceSelected( Incidence * ) ), 184 connect( mView, SIGNAL( incidenceSelected( Incidence * ) ),
184 SLOT( processIncidenceSelection( Incidence * ) ) ); 185 SLOT( processIncidenceSelection( Incidence * ) ) );
185 connect( mView, SIGNAL( modifiedChanged( bool ) ), 186 connect( mView, SIGNAL( modifiedChanged( bool ) ),
186 SLOT( slotModifiedChanged( bool ) ) ); 187 SLOT( slotModifiedChanged( bool ) ) );
187 188
188 189
189 connect( &mSaveTimer, SIGNAL( timeout() ), SLOT( save() ) ); 190 connect( &mSaveTimer, SIGNAL( timeout() ), SLOT( save() ) );
190 mView->setModified( false ); 191 mView->setModified( false );
191 mBlockAtStartup = false; 192 mBlockAtStartup = false;
192 mView->setModified( false ); 193 mView->setModified( false );
193 setCentralWidget( mView ); 194 setCentralWidget( mView );
194 globalFlagBlockStartup = 0; 195 globalFlagBlockStartup = 0;
195 mView->show(); 196 mView->show();
196 delete splash; 197 delete splash;
197 if ( newFile ) 198 if ( newFile )
198 mView->updateConfig(); 199 mView->updateConfig();
199 // qApp->processEvents(); 200 // qApp->processEvents();
200 //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ()); 201 //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ());
201 fillSyncMenu(); 202 fillSyncMenu();
202 mView->viewManager()->agendaView()->setStartHour( KOPrefs::instance()->mDayBegins ); 203 mView->viewManager()->agendaView()->setStartHour( KOPrefs::instance()->mDayBegins );
203 if ( showWarning ) { 204 if ( showWarning ) {
204 KMessageBox::information( this, 205 KMessageBox::information( this,
205 "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"); 206 "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");
206 qApp->processEvents(); 207 qApp->processEvents();
207 mView->dialogManager()->showSyncOptions(); 208 mView->dialogManager()->showSyncOptions();
208 } 209 }
209 210
210 //US listen for result adressed from Ka/Pi 211 //US listen for result adressed from Ka/Pi
211#ifndef DESKTOP_VERSION 212#ifndef DESKTOP_VERSION
212 connect(qApp, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & ))); 213 connect(qApp, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & )));
213#endif 214#endif
214} 215}
215MainWindow::~MainWindow() 216MainWindow::~MainWindow()
216{ 217{
217 //qDebug("MainWindow::~MainWindow() "); 218 //qDebug("MainWindow::~MainWindow() ");
218 //save toolbar location 219 //save toolbar location
219 delete mServerSocket; 220 delete mServerSocket;
220 delete mCalendar; 221 delete mCalendar;
221 delete KOPrefs::instance(); 222 delete KOPrefs::instance();
222 delete KIncidenceFormatter::instance(); 223 delete KIncidenceFormatter::instance();
223 224
224 225
225} 226}
226void MainWindow::showMaximized () 227void MainWindow::showMaximized ()
227{ 228{
228#ifndef DESKTOP_VERSION 229#ifndef DESKTOP_VERSION
229 if ( ! globalFlagBlockStartup ) 230 if ( ! globalFlagBlockStartup )
230 if ( mClosed ) 231 if ( mClosed )
231 mView->goToday(); 232 mView->goToday();
232#endif 233#endif
233 QWidget::showMaximized () ; 234 QWidget::showMaximized () ;
234 mClosed = false; 235 mClosed = false;
235} 236}
236void MainWindow::closeEvent( QCloseEvent* ce ) 237void MainWindow::closeEvent( QCloseEvent* ce )
237{ 238{
238 239
239 240
240 241
241 if ( ! KOPrefs::instance()->mAskForQuit ) { 242 if ( ! KOPrefs::instance()->mAskForQuit ) {
242 saveOnClose(); 243 saveOnClose();
243 mClosed = true; 244 mClosed = true;
244 ce->accept(); 245 ce->accept();
245 return; 246 return;
246 247
247 } 248 }
248 249
249 switch( QMessageBox::information( this, "KO/Pi", 250 switch( QMessageBox::information( this, "KO/Pi",
250 i18n("Do you really want\nto close KO/Pi?"), 251 i18n("Do you really want\nto close KO/Pi?"),
251 i18n("Close"), i18n("No"), 252 i18n("Close"), i18n("No"),
252 0, 0 ) ) { 253 0, 0 ) ) {
253 case 0: 254 case 0:
254 saveOnClose(); 255 saveOnClose();
255 mClosed = true; 256 mClosed = true;
256 ce->accept(); 257 ce->accept();
257 break; 258 break;
258 case 1: 259 case 1:
259 ce->ignore(); 260 ce->ignore();
260 break; 261 break;
261 case 2: 262 case 2:
262 263
263 default: 264 default:
264 break; 265 break;
265 } 266 }
266 267
267 268
268} 269}
269 270
270void MainWindow::recieve( const QCString& cmsg, const QByteArray& data ) 271void MainWindow::recieve( const QCString& cmsg, const QByteArray& data )
271{ 272{
272 QDataStream stream( data, IO_ReadOnly ); 273 QDataStream stream( data, IO_ReadOnly );
273 // QMessageBox::about( this, "About KOrganizer/Pi", "*" +msg +"*" ); 274 // QMessageBox::about( this, "About KOrganizer/Pi", "*" +msg +"*" );
274 //QString datamess; 275 //QString datamess;
275 //qDebug("message "); 276 //qDebug("message ");
276 qDebug("KO: QCOP message received: %s ", cmsg.data() ); 277 qDebug("KO: QCOP message received: %s ", cmsg.data() );
277 278
278 if ( cmsg == "-writeFile" ) { 279 if ( cmsg == "-writeFile" ) {
279 // I made from the "-writeFile" an "-writeAlarm" 280 // I made from the "-writeFile" an "-writeAlarm"
280 mView->viewManager()->showWhatsNextView(); 281 mView->viewManager()->showWhatsNextView();
281 mCalendar->checkAlarmForIncidence( 0, true); 282 mCalendar->checkAlarmForIncidence( 0, true);
282 showMaximized(); 283 showMaximized();
283 raise(); 284 raise();
284 return; 285 return;
285 } 286 }
286 287
287 if ( cmsg == "-writeFile" ) { 288 if ( cmsg == "-writeFile" ) {
288 // I made from the "-writeFile" an "-writeAlarm" 289 // I made from the "-writeFile" an "-writeAlarm"
289 mView->viewManager()->showWhatsNextView(); 290 mView->viewManager()->showWhatsNextView();
290 mCalendar->checkAlarmForIncidence( 0, true); 291 mCalendar->checkAlarmForIncidence( 0, true);
291 showMaximized(); 292 showMaximized();
292 raise(); 293 raise();
293 return; 294 return;
294 295
295 } 296 }
296 if ( cmsg == "-writeFileSilent" ) { 297 if ( cmsg == "-writeFileSilent" ) {
297 // I made from the "-writeFile" an "-writeAlarm" 298 // I made from the "-writeFile" an "-writeAlarm"
298 // mView->viewManager()->showWhatsNextView(); 299 // mView->viewManager()->showWhatsNextView();
299 mCalendar->checkAlarmForIncidence( 0, true); 300 mCalendar->checkAlarmForIncidence( 0, true);
300 //showMaximized(); 301 //showMaximized();
301 //raise(); 302 //raise();
302 hide(); 303 hide();
303 return; 304 return;
304 } 305 }
305 if ( cmsg == "-newCountdown" ) { 306 if ( cmsg == "-newCountdown" ) {
306 qDebug("newCountdown "); 307 qDebug("newCountdown ");
307 308
308 } 309 }
309 QString msg ; 310 QString msg ;
310 QString allmsg = cmsg; 311 QString allmsg = cmsg;
311 while ( allmsg.length() > 0 ) { 312 while ( allmsg.length() > 0 ) {
312 int nextC = allmsg.find( "-", 1 ); 313 int nextC = allmsg.find( "-", 1 );
313 if ( nextC == -1 ) { 314 if ( nextC == -1 ) {
314 msg = allmsg; 315 msg = allmsg;
315 allmsg = ""; 316 allmsg = "";
316 } else{ 317 } else{
317 msg = allmsg.left( nextC ); 318 msg = allmsg.left( nextC );
318 allmsg = allmsg.mid( nextC, allmsg.length()-nextC ); 319 allmsg = allmsg.mid( nextC, allmsg.length()-nextC );
319 } 320 }
320 //qDebug("msg: %s all: %s ", msg.latin1(), allmsg.latin1() ); 321 //qDebug("msg: %s all: %s ", msg.latin1(), allmsg.latin1() );
321 if ( msg == "-newEvent" ) { 322 if ( msg == "-newEvent" ) {
322 mView->newEvent(); 323 mView->newEvent();
323 } 324 }
324 if ( msg == "-newTodo" ) { 325 if ( msg == "-newTodo" ) {
325 mView->newTodo(); 326 mView->newTodo();
326 327
327 } 328 }
328 if ( msg == "-showWN" ) { 329 if ( msg == "-showWN" ) {
329 mView->viewManager()->showWhatsNextView(); 330 mView->viewManager()->showWhatsNextView();
330 } 331 }
331 if ( msg == "-showTodo" ) { 332 if ( msg == "-showTodo" ) {
332 mView->viewManager()->showTodoView(); 333 mView->viewManager()->showTodoView();
333 } 334 }
334 if ( msg == "-showList" ) { 335 if ( msg == "-showList" ) {
335 mView->viewManager()->showListView(); 336 mView->viewManager()->showListView();
336 } 337 }
337 else if ( msg == "-showDay" ) { 338 else if ( msg == "-showDay" ) {
338 mView->viewManager()->showDayView(); 339 mView->viewManager()->showDayView();
339 } 340 }
340 else if ( msg == "-showWWeek" ) { 341 else if ( msg == "-showWWeek" ) {
341 mView->viewManager()->showWorkWeekView(); 342 mView->viewManager()->showWorkWeekView();
342 } 343 }
343 else if ( msg == "-ringSync" ) { 344 else if ( msg == "-ringSync" ) {
344 multiSync( false ); 345 multiSync( false );
345 } 346 }
346 else if ( msg == "-showWeek" ) { 347 else if ( msg == "-showWeek" ) {
347 mView->viewManager()->showWeekView(); 348 mView->viewManager()->showWeekView();
348 } 349 }
349 else if ( msg == "-showTodo" ) { 350 else if ( msg == "-showTodo" ) {
350 mView->viewManager()->showTodoView(); 351 mView->viewManager()->showTodoView();
351 } 352 }
352 else if ( msg == "-showJournal" ) { 353 else if ( msg == "-showJournal" ) {
353 mView->dateNavigator()->selectDates( 1 ); 354 mView->dateNavigator()->selectDates( 1 );
354 mView->dateNavigator()->selectToday(); 355 mView->dateNavigator()->selectToday();
355 mView->viewManager()->showJournalView(); 356 mView->viewManager()->showJournalView();
356 } 357 }
357 else if ( msg == "-showKO" ) { 358 else if ( msg == "-showKO" ) {
358 mView->viewManager()->showNextXView(); 359 mView->viewManager()->showNextXView();
359 } 360 }
360 else if ( msg == "-showWNext" || msg == "nextView()" ) { 361 else if ( msg == "-showWNext" || msg == "nextView()" ) {
361 mView->viewManager()->showWhatsNextView(); 362 mView->viewManager()->showWhatsNextView();
362 } 363 }
363 else if ( msg == "-showNextXView" ) { 364 else if ( msg == "-showNextXView" ) {
364 mView->viewManager()->showNextXView(); 365 mView->viewManager()->showNextXView();
365 } 366 }
366 367
367 368
368 } 369 }
369 370
370 showMaximized(); 371 showMaximized();
371 raise(); 372 raise();
372} 373}
373 374
374QPixmap MainWindow::loadPixmap( QString name ) 375QPixmap MainWindow::loadPixmap( QString name )
375{ 376{
376 return SmallIcon( name ); 377 return SmallIcon( name );
377 378
378} 379}
379void MainWindow::initActions() 380void MainWindow::initActions()
380{ 381{
381 //KOPrefs::instance()->mShowFullMenu 382 //KOPrefs::instance()->mShowFullMenu
382 iconToolBar->clear(); 383 iconToolBar->clear();
383 KOPrefs *p = KOPrefs::instance(); 384 KOPrefs *p = KOPrefs::instance();
384 //QPEMenuBar *menuBar1;// = new QPEMenuBar( iconToolBar ); 385 //QPEMenuBar *menuBar1;// = new QPEMenuBar( iconToolBar );
385 386
386 QPopupMenu *viewMenu = new QPopupMenu( this ); 387 QPopupMenu *viewMenu = new QPopupMenu( this );
387 QPopupMenu *actionMenu = new QPopupMenu( this ); 388 QPopupMenu *actionMenu = new QPopupMenu( this );
388 QPopupMenu *importMenu = new QPopupMenu( this ); 389 QPopupMenu *importMenu = new QPopupMenu( this );
389 selectFilterMenu = new QPopupMenu( this ); 390 selectFilterMenu = new QPopupMenu( this );
390 selectFilterMenu->setCheckable( true ); 391 selectFilterMenu->setCheckable( true );
391 syncMenu = new QPopupMenu( this ); 392 syncMenu = new QPopupMenu( this );
392 configureAgendaMenu = new QPopupMenu( this ); 393 configureAgendaMenu = new QPopupMenu( this );
393 configureToolBarMenu = new QPopupMenu( this ); 394 configureToolBarMenu = new QPopupMenu( this );
394 QPopupMenu *helpMenu = new QPopupMenu( this ); 395 QPopupMenu *helpMenu = new QPopupMenu( this );
395 if ( KOPrefs::instance()->mShowFullMenu ) { 396 if ( KOPrefs::instance()->mShowFullMenu ) {
396 QMenuBar *menuBar1; 397 QMenuBar *menuBar1;
397 menuBar1 = menuBar(); 398 menuBar1 = menuBar();
398 menuBar1->insertItem( i18n("File"), importMenu ); 399 menuBar1->insertItem( i18n("File"), importMenu );
399 menuBar1->insertItem( i18n("View"), viewMenu ); 400 menuBar1->insertItem( i18n("View"), viewMenu );
400 menuBar1->insertItem( i18n("Actions"), actionMenu ); 401 menuBar1->insertItem( i18n("Actions"), actionMenu );
401 menuBar1->insertItem( i18n("Synchronize"), syncMenu ); 402 menuBar1->insertItem( i18n("Synchronize"), syncMenu );
402 menuBar1->insertItem( i18n("AgendaSize"),configureAgendaMenu ); 403 menuBar1->insertItem( i18n("AgendaSize"),configureAgendaMenu );
403 //menuBar1->insertItem( i18n("Toolbar"),configureToolBarMenu ); 404 //menuBar1->insertItem( i18n("Toolbar"),configureToolBarMenu );
404 menuBar1->insertItem( i18n("Filter"),selectFilterMenu ); 405 menuBar1->insertItem( i18n("Filter"),selectFilterMenu );
405 menuBar1->insertItem( i18n("Help"), helpMenu ); 406 menuBar1->insertItem( i18n("Help"), helpMenu );
406 } else { 407 } else {
407 QPEMenuBar *menuBar1; 408 QPEMenuBar *menuBar1;
408 menuBar1 = new QPEMenuBar( iconToolBar ); 409 menuBar1 = new QPEMenuBar( iconToolBar );
409 QPopupMenu *menuBar = new QPopupMenu( this ); 410 QPopupMenu *menuBar = new QPopupMenu( this );
410 menuBar1->insertItem( i18n("ME"), menuBar); 411 menuBar1->insertItem( i18n("ME"), menuBar);
411 menuBar->insertItem( i18n("File"), importMenu ); 412 menuBar->insertItem( i18n("File"), importMenu );
412 menuBar->insertItem( i18n("View"), viewMenu ); 413 menuBar->insertItem( i18n("View"), viewMenu );
413 menuBar->insertItem( i18n("Actions"), actionMenu ); 414 menuBar->insertItem( i18n("Actions"), actionMenu );
414 menuBar->insertItem( i18n("Synchronize"), syncMenu ); 415 menuBar->insertItem( i18n("Synchronize"), syncMenu );
415 menuBar->insertItem( i18n("AgendaSize"),configureAgendaMenu ); 416 menuBar->insertItem( i18n("AgendaSize"),configureAgendaMenu );
416 menuBar->insertItem( i18n("Toolbar"),configureToolBarMenu ); 417 menuBar->insertItem( i18n("Toolbar"),configureToolBarMenu );
417 menuBar->insertItem( i18n("Filter"),selectFilterMenu ); 418 menuBar->insertItem( i18n("Filter"),selectFilterMenu );
418 menuBar->insertItem( i18n("Help"), helpMenu ); 419 menuBar->insertItem( i18n("Help"), helpMenu );
419 //menuBar1->setMaximumWidth( menuBar1->sizeHint().width() ); 420 //menuBar1->setMaximumWidth( menuBar1->sizeHint().width() );
420 menuBar1->setMaximumSize( menuBar1->sizeHint( )); 421 menuBar1->setMaximumSize( menuBar1->sizeHint( ));
421 } 422 }
422 connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) ); 423 connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) );
423 connect ( selectFilterMenu, SIGNAL( activated ( int ) ), this, SLOT (selectFilter( int ) ) ); 424 connect ( selectFilterMenu, SIGNAL( activated ( int ) ), this, SLOT (selectFilter( int ) ) );
424 connect ( selectFilterMenu, SIGNAL( aboutToShow () ), this, SLOT (fillFilterMenu() ) ); 425 connect ( selectFilterMenu, SIGNAL( aboutToShow () ), this, SLOT (fillFilterMenu() ) );
425 426
426 // ****************** 427 // ******************
427 QAction *action; 428 QAction *action;
428 QIconSet icon; 429 QIconSet icon;
429 // QPopupMenu *configureMenu= new QPopupMenu( menuBar ); 430 // QPopupMenu *configureMenu= new QPopupMenu( menuBar );
430 configureToolBarMenu->setCheckable( true ); 431 configureToolBarMenu->setCheckable( true );
431 432
432 QString pathString = ""; 433 QString pathString = "";
433 if ( !p->mToolBarMiniIcons ) { 434 if ( !p->mToolBarMiniIcons ) {
434 if ( QApplication::desktop()->width() < 480 ) 435 if ( QApplication::desktop()->width() < 480 )
435 pathString += "icons16/"; 436 pathString += "icons16/";
436 } else 437 } else
437 pathString += "iconsmini/"; 438 pathString += "iconsmini/";
438 configureAgendaMenu->setCheckable( true ); 439 configureAgendaMenu->setCheckable( true );
439 configureAgendaMenu->insertItem(i18n("Toggle Allday"), 1 ); 440 configureAgendaMenu->insertItem(i18n("Toggle Allday"), 1 );
440 configureAgendaMenu->insertSeparator(); 441 configureAgendaMenu->insertSeparator();
441 configureAgendaMenu->insertItem(i18n("Tiny"), 4 ); 442 configureAgendaMenu->insertItem(i18n("Tiny"), 4 );
442 configureAgendaMenu->insertItem(i18n("Small"), 6 ); 443 configureAgendaMenu->insertItem(i18n("Small"), 6 );
443 configureAgendaMenu->insertItem(i18n("Medium"), 8 ); 444 configureAgendaMenu->insertItem(i18n("Medium"), 8 );
444 configureAgendaMenu->insertItem(i18n("Normal"), 10 ); 445 configureAgendaMenu->insertItem(i18n("Normal"), 10 );
445 configureAgendaMenu->insertItem(i18n("Large"), 12 ); 446 configureAgendaMenu->insertItem(i18n("Large"), 12 );
446 configureAgendaMenu->insertItem(i18n("Big"), 14 ); 447 configureAgendaMenu->insertItem(i18n("Big"), 14 );
447 configureAgendaMenu->insertItem(i18n("Bigger"), 16 ); 448 configureAgendaMenu->insertItem(i18n("Bigger"), 16 );
448 configureAgendaMenu->insertItem(i18n("Biggest"), 18 ); 449 configureAgendaMenu->insertItem(i18n("Biggest"), 18 );
449 //configureMenu->insertItem( "AgendaSize",configureAgendaMenu ); 450 //configureMenu->insertItem( "AgendaSize",configureAgendaMenu );
450 451
451 icon = loadPixmap( pathString + "configure" ); 452 icon = loadPixmap( pathString + "configure" );
452 action = new QAction( i18n("Configure"),icon, i18n("Configure..."), 0, this ); 453 action = new QAction( i18n("Configure"),icon, i18n("Configure..."), 0, this );
453 action->addTo( actionMenu ); 454 action->addTo( actionMenu );
454 connect( action, SIGNAL( activated() ), 455 connect( action, SIGNAL( activated() ),
455 mView, SLOT( edit_options() ) ); 456 mView, SLOT( edit_options() ) );
456 actionMenu->insertSeparator(); 457 actionMenu->insertSeparator();
457 icon = loadPixmap( pathString + "newevent" ); 458 icon = loadPixmap( pathString + "newevent" );
458 configureToolBarMenu->insertItem(i18n("Stretched TB"), 5 ); 459 configureToolBarMenu->insertItem(i18n("Stretched TB"), 5 );
459 configureToolBarMenu->insertSeparator(); 460 configureToolBarMenu->insertSeparator();
460 configureToolBarMenu->insertItem(icon, i18n("New Event..."), 10 ); 461 configureToolBarMenu->insertItem(icon, i18n("New Event..."), 10 );
461 QAction* ne_action = new QAction( i18n("New Event..."), icon, i18n("New Event..."), 0, this ); 462 QAction* ne_action = new QAction( i18n("New Event..."), icon, i18n("New Event..."), 0, this );
462 ne_action->addTo( actionMenu ); 463 ne_action->addTo( actionMenu );
463 connect( ne_action, SIGNAL( activated() ), 464 connect( ne_action, SIGNAL( activated() ),
464 mView, SLOT( newEvent() ) ); 465 mView, SLOT( newEvent() ) );
465 icon = loadPixmap( pathString + "newtodo" ); 466 icon = loadPixmap( pathString + "newtodo" );
466 configureToolBarMenu->insertItem(icon, i18n("New Todo..."), 20 ); 467 configureToolBarMenu->insertItem(icon, i18n("New Todo..."), 20 );
467 QAction* nt_action = new QAction( i18n("New Todo..."), icon, i18n("New Todo..."), 0, this ); 468 QAction* nt_action = new QAction( i18n("New Todo..."), icon, i18n("New Todo..."), 0, this );
468 nt_action->addTo( actionMenu ); 469 nt_action->addTo( actionMenu );
469 connect( nt_action, SIGNAL( activated() ), 470 connect( nt_action, SIGNAL( activated() ),
470 mView, SLOT( newTodo() ) ); 471 mView, SLOT( newTodo() ) );
471 icon = loadPixmap( pathString + "navi" ); 472 icon = loadPixmap( pathString + "navi" );
472 action = new QAction( i18n("Toggle DateNavigator"), icon, i18n("Toggle DateNavigator"), 0, this ); 473 action = new QAction( i18n("Toggle DateNavigator"), icon, i18n("Toggle DateNavigator"), 0, this );
473 action->addTo( viewMenu ); 474 action->addTo( viewMenu );
474 connect( action, SIGNAL( activated() ), 475 connect( action, SIGNAL( activated() ),
475 mView, SLOT( toggleDateNavigatorWidget() ) ); 476 mView, SLOT( toggleDateNavigatorWidget() ) );
476 icon = loadPixmap( pathString + "filter" ); 477 icon = loadPixmap( pathString + "filter" );
477 action = new QAction( i18n("Toggle FilterView"), icon, i18n("Toggle FilterView"), 0, this ); 478 action = new QAction( i18n("Toggle FilterView"), icon, i18n("Toggle FilterView"), 0, this );
478 action->addTo( viewMenu ); 479 action->addTo( viewMenu );
479 connect( action, SIGNAL( activated() ), 480 connect( action, SIGNAL( activated() ),
480 mView, SLOT( toggleFilter() ) ); 481 mView, SLOT( toggleFilter() ) );
481 482
482 483
483 viewMenu->insertSeparator(); 484 viewMenu->insertSeparator();
484 icon = loadPixmap( pathString + "picker" ); 485 icon = loadPixmap( pathString + "picker" );
485 action = new QAction( i18n("Date Picker"), icon, i18n("Date Picker"), 0, this ); 486 action = new QAction( i18n("Date Picker"), icon, i18n("Date Picker"), 0, this );
486 action->addTo( viewMenu ); 487 action->addTo( viewMenu );
487 connect( action, SIGNAL( activated() ), 488 connect( action, SIGNAL( activated() ),
488 mView, SLOT( showDatePicker() ) ); 489 mView, SLOT( showDatePicker() ) );
489 action->addTo( iconToolBar ); 490 action->addTo( iconToolBar );
490 viewMenu->insertSeparator(); 491 viewMenu->insertSeparator();
491 icon = loadPixmap( pathString + "list" ); 492 icon = loadPixmap( pathString + "list" );
492 configureToolBarMenu->insertItem(icon, i18n("List View"), 30 ); 493 configureToolBarMenu->insertItem(icon, i18n("List View"), 30 );
493 QAction* showlist_action = new QAction( i18n("List View"), icon, i18n("List View"), 0, this ); 494 QAction* showlist_action = new QAction( i18n("List View"), icon, i18n("List View"), 0, this );
494 showlist_action->addTo( viewMenu ); 495 showlist_action->addTo( viewMenu );
495 connect( showlist_action, SIGNAL( activated() ), 496 connect( showlist_action, SIGNAL( activated() ),
496 mView->viewManager(), SLOT( showListView() ) ); 497 mView->viewManager(), SLOT( showListView() ) );
497 498
498 499
499 icon = loadPixmap( pathString + "day" ); 500 icon = loadPixmap( pathString + "day" );
500 configureToolBarMenu->insertItem(icon, i18n("Day View"), 40 ); 501 configureToolBarMenu->insertItem(icon, i18n("Day View"), 40 );
501 QAction* day1_action = new QAction( i18n("Day View"), icon, i18n("Day View"), 0, this ); 502 QAction* day1_action = new QAction( i18n("Day View"), icon, i18n("Day View"), 0, this );
502 day1_action->addTo( viewMenu ); 503 day1_action->addTo( viewMenu );
503 // action->addTo( toolBar ); 504 // action->addTo( toolBar );
504 connect( day1_action, SIGNAL( activated() ), 505 connect( day1_action, SIGNAL( activated() ),
505 mView->viewManager(), SLOT( showDayView() ) ); 506 mView->viewManager(), SLOT( showDayView() ) );
506 507
507 icon = loadPixmap( pathString + "workweek" ); 508 icon = loadPixmap( pathString + "workweek" );
508 configureToolBarMenu->insertItem(icon, i18n("Work Week"), 50 ); 509 configureToolBarMenu->insertItem(icon, i18n("Work Week"), 50 );
509 QAction* day5_action = new QAction( i18n("Work Week"), icon, i18n("Work Week"), 0, this ); 510 QAction* day5_action = new QAction( i18n("Work Week"), icon, i18n("Work Week"), 0, this );
510 day5_action->addTo( viewMenu ); 511 day5_action->addTo( viewMenu );
511 connect( day5_action, SIGNAL( activated() ), 512 connect( day5_action, SIGNAL( activated() ),
512 mView->viewManager(), SLOT( showWorkWeekView() ) ); 513 mView->viewManager(), SLOT( showWorkWeekView() ) );
513 514
514 icon = loadPixmap( pathString + "week" ); 515 icon = loadPixmap( pathString + "week" );
515 configureToolBarMenu->insertItem(icon, i18n("Week"), 60 ); 516 configureToolBarMenu->insertItem(icon, i18n("Week"), 60 );
516 QAction* day7_action = new QAction( i18n("Week"), icon, i18n("Week"), 0, this ); 517 QAction* day7_action = new QAction( i18n("Week"), icon, i18n("Week"), 0, this );
517 day7_action->addTo( viewMenu ); 518 day7_action->addTo( viewMenu );
518 connect( day7_action, SIGNAL( activated() ), 519 connect( day7_action, SIGNAL( activated() ),
519 mView->viewManager(), SLOT( showWeekView() ) ); 520 mView->viewManager(), SLOT( showWeekView() ) );
520 521
521 icon = loadPixmap( pathString + "month" ); 522 icon = loadPixmap( pathString + "month" );
522 configureToolBarMenu->insertItem(icon, i18n("Month"), 70 ); 523 configureToolBarMenu->insertItem(icon, i18n("Month"), 70 );
523 QAction* month_action = new QAction( i18n("Month"), icon, i18n("Month"), 0, this ); 524 QAction* month_action = new QAction( i18n("Month"), icon, i18n("Month"), 0, this );
524 month_action->addTo( viewMenu ); 525 month_action->addTo( viewMenu );
525 connect( month_action, SIGNAL( activated() ), 526 connect( month_action, SIGNAL( activated() ),
526 mView->viewManager(), SLOT( showMonthView() ) ); 527 mView->viewManager(), SLOT( showMonthView() ) );
527 528
528 icon = loadPixmap( pathString + "todo" ); 529 icon = loadPixmap( pathString + "todo" );
529 configureToolBarMenu->insertItem(icon, i18n("Todo View"), 80 ); 530 configureToolBarMenu->insertItem(icon, i18n("Todo View"), 80 );
530 QAction* todoview_action = new QAction( i18n("Todo View"), icon, i18n("Todo View"), 0, this ); 531 QAction* todoview_action = new QAction( i18n("Todo View"), icon, i18n("Todo View"), 0, this );
531 todoview_action->addTo( viewMenu ); 532 todoview_action->addTo( viewMenu );
532 connect( todoview_action, SIGNAL( activated() ), 533 connect( todoview_action, SIGNAL( activated() ),
533 mView->viewManager(), SLOT( showTodoView() ) ); 534 mView->viewManager(), SLOT( showTodoView() ) );
534 535
535 icon = loadPixmap( pathString + "journal" ); 536 icon = loadPixmap( pathString + "journal" );
536 configureToolBarMenu->insertItem(icon, i18n("Journal"), 90 ); 537 configureToolBarMenu->insertItem(icon, i18n("Journal"), 90 );
537 QAction* viewjournal_action = new QAction( i18n("Journal"), icon, i18n("Journal"), 0, this ); 538 QAction* viewjournal_action = new QAction( i18n("Journal"), icon, i18n("Journal"), 0, this );
538 viewjournal_action->addTo( viewMenu ); 539 viewjournal_action->addTo( viewMenu );
539 connect( viewjournal_action, SIGNAL( activated() ), 540 connect( viewjournal_action, SIGNAL( activated() ),
540 mView->viewManager(), SLOT( showJournalView() ) ); 541 mView->viewManager(), SLOT( showJournalView() ) );
541 542
542 icon = loadPixmap( pathString + "xdays" ); 543 icon = loadPixmap( pathString + "xdays" );
543 configureToolBarMenu->insertItem(icon, i18n("Next days"), 100,4 ); 544 configureToolBarMenu->insertItem(icon, i18n("Next days"), 100,4 );
544 QAction* xdays_action = new QAction( i18n("Next days"), icon, i18n("Next days"), 0, this ); 545 QAction* xdays_action = new QAction( i18n("Next days"), icon, i18n("Next days"), 0, this );
545 xdays_action->addTo( viewMenu ); 546 xdays_action->addTo( viewMenu );
546 connect( xdays_action, SIGNAL( activated() ), 547 connect( xdays_action, SIGNAL( activated() ),
547 mView->viewManager(), SLOT( showNextXView() ) ); 548 mView->viewManager(), SLOT( showNextXView() ) );
548 549
549 icon = loadPixmap( pathString + "whatsnext" ); 550 icon = loadPixmap( pathString + "whatsnext" );
550 configureToolBarMenu->insertItem(icon, i18n("What's Next"), 110, 4 ); 551 configureToolBarMenu->insertItem(icon, i18n("What's Next"), 110, 4 );
551 QAction* whatsnext_action = new QAction( i18n("What's Next"), icon, i18n("What's Next"), 0, this ); 552 QAction* whatsnext_action = new QAction( i18n("What's Next"), icon, i18n("What's Next"), 0, this );
552 whatsnext_action->addTo( viewMenu ); 553 whatsnext_action->addTo( viewMenu );
553 connect( whatsnext_action, SIGNAL( activated() ), 554 connect( whatsnext_action, SIGNAL( activated() ),
554 mView->viewManager(), SLOT( showWhatsNextView() ) ); 555 mView->viewManager(), SLOT( showWhatsNextView() ) );
555 556
556#if 0 557#if 0
557 action = new QAction( "view_timespan", "Time Span", 0, this ); 558 action = new QAction( "view_timespan", "Time Span", 0, this );
558 action->addTo( viewMenu ); 559 action->addTo( viewMenu );
559 connect( action, SIGNAL( activated() ), 560 connect( action, SIGNAL( activated() ),
560 mView->viewManager(), SLOT( showTimeSpanView() ) ); 561 mView->viewManager(), SLOT( showTimeSpanView() ) );
561#endif 562#endif
562 563
563 mNewSubTodoAction = new QAction( "new_subtodo", i18n("New Sub-Todo..."), 0, 564 mNewSubTodoAction = new QAction( "new_subtodo", i18n("New Sub-Todo..."), 0,
564 this ); 565 this );
565 mNewSubTodoAction->addTo( actionMenu ); 566 mNewSubTodoAction->addTo( actionMenu );
566 connect( mNewSubTodoAction, SIGNAL( activated() ), 567 connect( mNewSubTodoAction, SIGNAL( activated() ),
567 mView, SLOT( newSubTodo() ) ); 568 mView, SLOT( newSubTodo() ) );
568 569
569 actionMenu->insertSeparator(); 570 actionMenu->insertSeparator();
570 571
571 mShowAction = new QAction( "show_incidence", i18n("Show..."), 0, this ); 572 mShowAction = new QAction( "show_incidence", i18n("Show..."), 0, this );
572 mShowAction->addTo( actionMenu ); 573 mShowAction->addTo( actionMenu );
573 connect( mShowAction, SIGNAL( activated() ), 574 connect( mShowAction, SIGNAL( activated() ),
574 mView, SLOT( showIncidence() ) ); 575 mView, SLOT( showIncidence() ) );
575 576
576 mEditAction = new QAction( "edit_incidence", i18n("Edit..."), 0, this ); 577 mEditAction = new QAction( "edit_incidence", i18n("Edit..."), 0, this );
577 mEditAction->addTo( actionMenu ); 578 mEditAction->addTo( actionMenu );
578 connect( mEditAction, SIGNAL( activated() ), 579 connect( mEditAction, SIGNAL( activated() ),
579 mView, SLOT( editIncidence() ) ); 580 mView, SLOT( editIncidence() ) );
580 581
581 mDeleteAction = new QAction( "delete_incidence", i18n("Delete..."), 0, this ); 582 mDeleteAction = new QAction( "delete_incidence", i18n("Delete..."), 0, this );
582 mDeleteAction->addTo( actionMenu ); 583 mDeleteAction->addTo( actionMenu );
583 connect( mDeleteAction, SIGNAL( activated() ), 584 connect( mDeleteAction, SIGNAL( activated() ),
584 mView, SLOT( deleteIncidence() ) ); 585 mView, SLOT( deleteIncidence() ) );
585 586
586 actionMenu->insertSeparator(); 587 actionMenu->insertSeparator();
587 588
@@ -1472,979 +1473,982 @@ void MainWindow::keyPressEvent ( QKeyEvent * e )
1472 mFlagKeyPressed = true; 1473 mFlagKeyPressed = true;
1473 KOPrefs *p = KOPrefs::instance(); 1474 KOPrefs *p = KOPrefs::instance();
1474 bool showSelectedDates = false; 1475 bool showSelectedDates = false;
1475 int size; 1476 int size;
1476 int pro = 0; 1477 int pro = 0;
1477 //qDebug("MainWindow::keyPressEvent "); 1478 //qDebug("MainWindow::keyPressEvent ");
1478 switch ( e->key() ) { 1479 switch ( e->key() ) {
1479 case Qt::Key_Right: 1480 case Qt::Key_Right:
1480 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton) 1481 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton)
1481 mView->goNextMonth(); 1482 mView->goNextMonth();
1482 else 1483 else
1483 mView->goNext(); 1484 mView->goNext();
1484 showSelectedDates = true; 1485 showSelectedDates = true;
1485 break; 1486 break;
1486 case Qt::Key_Left: 1487 case Qt::Key_Left:
1487 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 1488 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
1488 mView->goPreviousMonth(); 1489 mView->goPreviousMonth();
1489 else 1490 else
1490 mView->goPrevious(); 1491 mView->goPrevious();
1491 showSelectedDates = true; 1492 showSelectedDates = true;
1492 break; 1493 break;
1493 case Qt::Key_Down: 1494 case Qt::Key_Down:
1494 mView->viewManager()->agendaView()->scrollOneHourDown(); 1495 mView->viewManager()->agendaView()->scrollOneHourDown();
1495 break; 1496 break;
1496 case Qt::Key_Up: 1497 case Qt::Key_Up:
1497 mView->viewManager()->agendaView()->scrollOneHourUp(); 1498 mView->viewManager()->agendaView()->scrollOneHourUp();
1498 break; 1499 break;
1499 case Qt::Key_I: 1500 case Qt::Key_I:
1500 mView->showIncidence(); 1501 mView->showIncidence();
1501 break; 1502 break;
1502 case Qt::Key_Delete: 1503 case Qt::Key_Delete:
1503 case Qt::Key_Backspace: 1504 case Qt::Key_Backspace:
1504 mView->deleteIncidence(); 1505 mView->deleteIncidence();
1505 break; 1506 break;
1506 case Qt::Key_D: 1507 case Qt::Key_D:
1507 mView->viewManager()->showDayView(); 1508 mView->viewManager()->showDayView();
1508 showSelectedDates = true; 1509 showSelectedDates = true;
1509 break; 1510 break;
1510 case Qt::Key_O: 1511 case Qt::Key_O:
1511 mView->toggleFilerEnabled( ); 1512 mView->toggleFilerEnabled( );
1512 break; 1513 break;
1513 case Qt::Key_0: 1514 case Qt::Key_0:
1514 case Qt::Key_1: 1515 case Qt::Key_1:
1515 case Qt::Key_2: 1516 case Qt::Key_2:
1516 case Qt::Key_3: 1517 case Qt::Key_3:
1517 case Qt::Key_4: 1518 case Qt::Key_4:
1518 case Qt::Key_5: 1519 case Qt::Key_5:
1519 case Qt::Key_6: 1520 case Qt::Key_6:
1520 case Qt::Key_7: 1521 case Qt::Key_7:
1521 case Qt::Key_8: 1522 case Qt::Key_8:
1522 case Qt::Key_9: 1523 case Qt::Key_9:
1523 pro = e->key()-48; 1524 pro = e->key()-48;
1524 if ( pro == 0 ) 1525 if ( pro == 0 )
1525 pro = 10; 1526 pro = 10;
1526 if ( e->state() == Qt::ControlButton) 1527 if ( e->state() == Qt::ControlButton)
1527 pro += 10; 1528 pro += 10;
1528 break; 1529 break;
1529 case Qt::Key_M: 1530 case Qt::Key_M:
1530 mView->viewManager()->showMonthView(); 1531 mView->viewManager()->showMonthView();
1531 showSelectedDates = true; 1532 showSelectedDates = true;
1532 break; 1533 break;
1533 case Qt::Key_Insert: 1534 case Qt::Key_Insert:
1534 mView->newEvent(); 1535 mView->newEvent();
1535 break; 1536 break;
1536 case Qt::Key_S : 1537 case Qt::Key_S :
1537 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton) 1538 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton)
1538 mView->newSubTodo(); 1539 mView->newSubTodo();
1539 else 1540 else
1540 mView->dialogManager()->showSearchDialog(); 1541 mView->dialogManager()->showSearchDialog();
1541 break; 1542 break;
1542 case Qt::Key_Y : 1543 case Qt::Key_Y :
1543 case Qt::Key_Z : 1544 case Qt::Key_Z :
1544 mView->viewManager()->showWorkWeekView(); 1545 mView->viewManager()->showWorkWeekView();
1545 showSelectedDates = true; 1546 showSelectedDates = true;
1546 break; 1547 break;
1547 case Qt::Key_U : 1548 case Qt::Key_U :
1548 mView->viewManager()->showWeekView(); 1549 mView->viewManager()->showWeekView();
1549 showSelectedDates = true; 1550 showSelectedDates = true;
1550 break; 1551 break;
1551 case Qt::Key_H : 1552 case Qt::Key_H :
1552 keyBindings(); 1553 keyBindings();
1553 break; 1554 break;
1554 case Qt::Key_W: 1555 case Qt::Key_W:
1555 mView->viewManager()->showWhatsNextView(); 1556 mView->viewManager()->showWhatsNextView();
1556 break; 1557 break;
1557 case Qt::Key_L: 1558 case Qt::Key_L:
1558 mView->viewManager()->showListView(); 1559 mView->viewManager()->showListView();
1559 break; 1560 break;
1560 case Qt::Key_N: 1561 case Qt::Key_N:
1561 mView->viewManager()->showNextXView(); 1562 mView->viewManager()->showNextXView();
1562 showSelectedDates = true; 1563 showSelectedDates = true;
1563 break; 1564 break;
1564 case Qt::Key_V: 1565 case Qt::Key_V:
1565 mView->viewManager()->showTodoView(); 1566 mView->viewManager()->showTodoView();
1566 break; 1567 break;
1567 case Qt::Key_C: 1568 case Qt::Key_C:
1568 mView->viewManager()->agendaView()->setStartHour( QTime::currentTime ().hour() ); 1569 mView->viewManager()->agendaView()->setStartHour( QTime::currentTime ().hour() );
1569 break; 1570 break;
1570 case Qt::Key_P: 1571 case Qt::Key_P:
1571 mView->showDatePicker( ); 1572 mView->showDatePicker( );
1572 break; 1573 break;
1573 case Qt::Key_F: 1574 case Qt::Key_F:
1574 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 1575 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
1575 mView->editFilters(); 1576 mView->editFilters();
1576 else 1577 else
1577 mView->toggleFilter(); 1578 mView->toggleFilter();
1578 break; 1579 break;
1579 case Qt::Key_X: 1580 case Qt::Key_X:
1580 mView->toggleDateNavigatorWidget(); 1581 mView->toggleDateNavigatorWidget();
1581 break; 1582 break;
1582 case Qt::Key_Space: 1583 case Qt::Key_Space:
1583 mView->toggleExpand(); 1584 mView->toggleExpand();
1584 break; 1585 break;
1585 case Qt::Key_A: 1586 case Qt::Key_A:
1586 mView->toggleAllDaySize(); 1587 mView->toggleAllDaySize();
1587 break; 1588 break;
1588 case Qt::Key_T: 1589 case Qt::Key_T:
1589 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 1590 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
1590 mView->newTodo(); 1591 mView->newTodo();
1591 else { 1592 else {
1592 mView->goToday(); 1593 mView->goToday();
1593 showSelectedDates = true; 1594 showSelectedDates = true;
1594 } 1595 }
1595 break; 1596 break;
1596 case Qt::Key_J: 1597 case Qt::Key_J:
1597 mView->viewManager()->showJournalView(); 1598 mView->viewManager()->showJournalView();
1598 break; 1599 break;
1599 case Qt::Key_B: 1600 case Qt::Key_B:
1600 mView->editIncidenceDescription();; 1601 mView->editIncidenceDescription();;
1601 break; 1602 break;
1602 // case Qt::Key_Return: 1603 // case Qt::Key_Return:
1603 case Qt::Key_E: 1604 case Qt::Key_E:
1604 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 1605 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
1605 mView->newEvent(); 1606 mView->newEvent();
1606 else 1607 else
1607 mView->editIncidence(); 1608 mView->editIncidence();
1608 break; 1609 break;
1609 case Qt::Key_Plus: 1610 case Qt::Key_Plus:
1610 size = p->mHourSize +2; 1611 size = p->mHourSize +2;
1611 if ( size <= 18 ) 1612 if ( size <= 18 )
1612 configureAgenda( size ); 1613 configureAgenda( size );
1613 break; 1614 break;
1614 case Qt::Key_Minus: 1615 case Qt::Key_Minus:
1615 size = p->mHourSize - 2; 1616 size = p->mHourSize - 2;
1616 if ( size >= 4 ) 1617 if ( size >= 4 )
1617 configureAgenda( size ); 1618 configureAgenda( size );
1618 break; 1619 break;
1619 1620
1620 1621
1621 default: 1622 default:
1622 e->ignore(); 1623 e->ignore();
1623 } 1624 }
1624 if ( pro > 0 ) { 1625 if ( pro > 0 ) {
1625 mView->selectFilter( pro-1 ); 1626 mView->selectFilter( pro-1 );
1626 } 1627 }
1627 if ( showSelectedDates ) { 1628 if ( showSelectedDates ) {
1628 ;// setCaptionToDates(); 1629 ;// setCaptionToDates();
1629 } 1630 }
1630 1631
1631} 1632}
1632 1633
1633void MainWindow::fillFilterMenu() 1634void MainWindow::fillFilterMenu()
1634{ 1635{
1635 selectFilterMenu->clear(); 1636 selectFilterMenu->clear();
1636 bool disable = false; 1637 bool disable = false;
1637 if ( mView->filterView()->filtersEnabled() ) { 1638 if ( mView->filterView()->filtersEnabled() ) {
1638 selectFilterMenu->insertItem(i18n ( "Turn filter off" ), 0 ); 1639 selectFilterMenu->insertItem(i18n ( "Turn filter off" ), 0 );
1639 } 1640 }
1640 else { 1641 else {
1641 selectFilterMenu->insertItem(i18n ( "Turn filter on" ), 0 ); 1642 selectFilterMenu->insertItem(i18n ( "Turn filter on" ), 0 );
1642 disable = true; 1643 disable = true;
1643 } 1644 }
1644 selectFilterMenu->insertSeparator(); 1645 selectFilterMenu->insertSeparator();
1645 QPtrList<CalFilter> fili = mView->filters(); 1646 QPtrList<CalFilter> fili = mView->filters();
1646 CalFilter *curfilter = mView->filterView()->selectedFilter(); 1647 CalFilter *curfilter = mView->filterView()->selectedFilter();
1647 CalFilter *filter = fili.first(); 1648 CalFilter *filter = fili.first();
1648 int iii = 1; 1649 int iii = 1;
1649 while(filter) { 1650 while(filter) {
1650 selectFilterMenu->insertItem( filter->name(), iii ); 1651 selectFilterMenu->insertItem( filter->name(), iii );
1651 if ( filter == curfilter) 1652 if ( filter == curfilter)
1652 selectFilterMenu->setItemChecked( iii, true ); 1653 selectFilterMenu->setItemChecked( iii, true );
1653 if ( disable ) 1654 if ( disable )
1654 selectFilterMenu->setItemEnabled( iii, false ); 1655 selectFilterMenu->setItemEnabled( iii, false );
1655 filter = fili.next(); 1656 filter = fili.next();
1656 ++iii; 1657 ++iii;
1657 } 1658 }
1658} 1659}
1659void MainWindow::selectFilter( int fil ) 1660void MainWindow::selectFilter( int fil )
1660{ 1661{
1661 if ( fil == 0 ) { 1662 if ( fil == 0 ) {
1662 mView->toggleFilerEnabled( ); 1663 mView->toggleFilerEnabled( );
1663 } else { 1664 } else {
1664 mView->selectFilter( fil-1 ); 1665 mView->selectFilter( fil-1 );
1665 } 1666 }
1666} 1667}
1667void MainWindow::configureToolBar( int item ) 1668void MainWindow::configureToolBar( int item )
1668{ 1669{
1669 1670
1670 configureToolBarMenu->setItemChecked( item, !configureToolBarMenu-> isItemChecked ( item ) ); 1671 configureToolBarMenu->setItemChecked( item, !configureToolBarMenu-> isItemChecked ( item ) );
1671 KOPrefs *p = KOPrefs::instance(); 1672 KOPrefs *p = KOPrefs::instance();
1672 p-> mShowIconStretch= configureToolBarMenu->isItemChecked( 5 ); 1673 p-> mShowIconStretch= configureToolBarMenu->isItemChecked( 5 );
1673 p-> mShowIconNewEvent= configureToolBarMenu->isItemChecked( 10 ); 1674 p-> mShowIconNewEvent= configureToolBarMenu->isItemChecked( 10 );
1674 p->mShowIconNewTodo = configureToolBarMenu->isItemChecked( 20 ); 1675 p->mShowIconNewTodo = configureToolBarMenu->isItemChecked( 20 );
1675 p-> mShowIconSearch= configureToolBarMenu->isItemChecked( 120 ); 1676 p-> mShowIconSearch= configureToolBarMenu->isItemChecked( 120 );
1676 p-> mShowIconList= configureToolBarMenu->isItemChecked( 30 ); 1677 p-> mShowIconList= configureToolBarMenu->isItemChecked( 30 );
1677 p-> mShowIconDay1= configureToolBarMenu->isItemChecked( 40 ); 1678 p-> mShowIconDay1= configureToolBarMenu->isItemChecked( 40 );
1678 p-> mShowIconDay5= configureToolBarMenu->isItemChecked( 50 ); 1679 p-> mShowIconDay5= configureToolBarMenu->isItemChecked( 50 );
1679 p-> mShowIconDay7= configureToolBarMenu->isItemChecked( 60 ); 1680 p-> mShowIconDay7= configureToolBarMenu->isItemChecked( 60 );
1680 p-> mShowIconMonth= configureToolBarMenu->isItemChecked( 70 ); 1681 p-> mShowIconMonth= configureToolBarMenu->isItemChecked( 70 );
1681 p-> mShowIconTodoview= configureToolBarMenu->isItemChecked( 80 ); 1682 p-> mShowIconTodoview= configureToolBarMenu->isItemChecked( 80 );
1682 p-> mShowIconBackFast= configureToolBarMenu->isItemChecked( 200 ); 1683 p-> mShowIconBackFast= configureToolBarMenu->isItemChecked( 200 );
1683 p-> mShowIconBack = configureToolBarMenu->isItemChecked( 210 ); 1684 p-> mShowIconBack = configureToolBarMenu->isItemChecked( 210 );
1684 p-> mShowIconToday= configureToolBarMenu->isItemChecked( 130 ); 1685 p-> mShowIconToday= configureToolBarMenu->isItemChecked( 130 );
1685 p-> mShowIconForward= configureToolBarMenu->isItemChecked( 220 ); 1686 p-> mShowIconForward= configureToolBarMenu->isItemChecked( 220 );
1686 p-> mShowIconForwardFast= configureToolBarMenu->isItemChecked( 230 ); 1687 p-> mShowIconForwardFast= configureToolBarMenu->isItemChecked( 230 );
1687 p-> mShowIconNextDays= configureToolBarMenu->isItemChecked( 100 ); 1688 p-> mShowIconNextDays= configureToolBarMenu->isItemChecked( 100 );
1688 p-> mShowIconNext= configureToolBarMenu->isItemChecked( 110 ); 1689 p-> mShowIconNext= configureToolBarMenu->isItemChecked( 110 );
1689 p-> mShowIconJournal= configureToolBarMenu->isItemChecked( 90 ); 1690 p-> mShowIconJournal= configureToolBarMenu->isItemChecked( 90 );
1690 p-> mShowIconWhatsThis= configureToolBarMenu->isItemChecked( 300 ); 1691 p-> mShowIconWhatsThis= configureToolBarMenu->isItemChecked( 300 );
1691 // initActions(); 1692 // initActions();
1692} 1693}
1693 1694
1694void MainWindow::setCaptionToDates() 1695void MainWindow::setCaptionToDates()
1695{ 1696{
1696 QString selDates; 1697 QString selDates;
1697 selDates = KGlobal::locale()->formatDate(mView->startDate(), true); 1698 selDates = KGlobal::locale()->formatDate(mView->startDate(), true);
1698 if (mView->startDate() < mView->endDate() ) 1699 if (mView->startDate() < mView->endDate() )
1699 selDates += " - " + KGlobal::locale()->formatDate(mView->endDate(), true); 1700 selDates += " - " + KGlobal::locale()->formatDate(mView->endDate(), true);
1700 setCaption( i18n("Dates: ") + selDates ); 1701 setCaption( i18n("Dates: ") + selDates );
1701 1702
1702} 1703}
1703// parameter item == 0: reinit 1704// parameter item == 0: reinit
1704void MainWindow::configureAgenda( int item ) 1705void MainWindow::configureAgenda( int item )
1705{ 1706{
1706 1707
1707 KOPrefs *p = KOPrefs::instance(); 1708 KOPrefs *p = KOPrefs::instance();
1708 1709
1709 int i; 1710 int i;
1710 if ( item == 1 ) { 1711 if ( item == 1 ) {
1711 mView->toggleAllDaySize(); 1712 mView->toggleAllDaySize();
1712 return; 1713 return;
1713 } 1714 }
1714 // do not allow 4 for widgets higher than 480 1715 // do not allow 4 for widgets higher than 480
1715 // if ( QApplication::desktop()->height() > 480 ) { 1716 // if ( QApplication::desktop()->height() > 480 ) {
1716// if ( item == 4 ) 1717// if ( item == 4 )
1717// item = 6; 1718// item = 6;
1718// } 1719// }
1719 for ( i = 4; i <= 18; i= i+2 ) 1720 for ( i = 4; i <= 18; i= i+2 )
1720 configureAgendaMenu->setItemChecked( i, false ); 1721 configureAgendaMenu->setItemChecked( i, false );
1721 configureAgendaMenu->setItemChecked( item, true ); 1722 configureAgendaMenu->setItemChecked( item, true );
1722 if ( p->mHourSize == item ) 1723 if ( p->mHourSize == item )
1723 return; 1724 return;
1724 p->mHourSize=item; 1725 p->mHourSize=item;
1725 mView->viewManager()->agendaView()->updateConfig(); 1726 mView->viewManager()->agendaView()->updateConfig();
1726} 1727}
1727 1728
1728void MainWindow::saveCalendar() 1729void MainWindow::saveCalendar()
1729{ 1730{
1730 QString fn = KOPrefs::instance()->mLastSaveFile; 1731 QString fn = KOPrefs::instance()->mLastSaveFile;
1731 fn = KFileDialog::getSaveFileName( fn, i18n("Save backup filename"), this ); 1732 fn = KFileDialog::getSaveFileName( fn, i18n("Save backup filename"), this );
1732 1733
1733 if ( fn == "" ) 1734 if ( fn == "" )
1734 return; 1735 return;
1735 QFileInfo info; 1736 QFileInfo info;
1736 info.setFile( fn ); 1737 info.setFile( fn );
1737 QString mes; 1738 QString mes;
1738 bool createbup = true; 1739 bool createbup = true;
1739 if ( info. exists() ) { 1740 if ( info. exists() ) {
1740 mes = i18n("Backup file\nalready exists!\nOld backup file from:\n%1\nOverwrite?\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )) ; 1741 mes = i18n("Backup file\nalready exists!\nOld backup file from:\n%1\nOverwrite?\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )) ;
1741 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 1742 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
1742 i18n("Overwrite!"), i18n("Cancel"), 0, 1743 i18n("Overwrite!"), i18n("Cancel"), 0,
1743 0, 1 ); 1744 0, 1 );
1744 if ( result != 0 ) { 1745 if ( result != 0 ) {
1745 createbup = false; 1746 createbup = false;
1746 } 1747 }
1747 } 1748 }
1748 if ( createbup ) { 1749 if ( createbup ) {
1749 mView->saveCalendar( fn ); 1750 mView->saveCalendar( fn );
1750 mes = i18n("KO/Pi:Saved %1").arg(fn); 1751 mes = i18n("KO/Pi:Saved %1").arg(fn);
1751 KOPrefs::instance()->mLastSaveFile = fn; 1752 KOPrefs::instance()->mLastSaveFile = fn;
1752 setCaption(mes); 1753 setCaption(mes);
1753 } 1754 }
1754} 1755}
1755void MainWindow::loadCalendar() 1756void MainWindow::loadCalendar()
1756{ 1757{
1757 1758
1758 QString fn = KOPrefs::instance()->mLastLoadFile; 1759 QString fn = KOPrefs::instance()->mLastLoadFile;
1759 fn = KFileDialog::getOpenFileName( fn, i18n("Load backup filename"), this ); 1760 fn = KFileDialog::getOpenFileName( fn, i18n("Load backup filename"), this );
1760 1761
1761 if ( fn == "" ) 1762 if ( fn == "" )
1762 return; 1763 return;
1763 QFileInfo info; 1764 QFileInfo info;
1764 info.setFile( fn ); 1765 info.setFile( fn );
1765 QString mess; 1766 QString mess;
1766 bool loadbup = true; 1767 bool loadbup = true;
1767 if ( info. exists() ) { 1768 if ( info. exists() ) {
1768 mess = i18n("Backup file from:\n%1\nLoading backup\nfile will delete\nyour current Data!\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 1769 mess = i18n("Backup file from:\n%1\nLoading backup\nfile will delete\nyour current Data!\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
1769 int result = QMessageBox::warning( this, "KO/Pi: Warning!", 1770 int result = QMessageBox::warning( this, "KO/Pi: Warning!",
1770 mess, 1771 mess,
1771 i18n("Load!"), i18n("Cancel"), 0, 1772 i18n("Load!"), i18n("Cancel"), 0,
1772 0, 1 ); 1773 0, 1 );
1773 if ( result != 0 ) { 1774 if ( result != 0 ) {
1774 loadbup = false; 1775 loadbup = false;
1775 } 1776 }
1776 } else { 1777 } else {
1777 QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 1778 QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1778 i18n("Backup file\ndoes not exist!\nNothing loaded!"), 0, 0, 1779 i18n("Backup file\ndoes not exist!\nNothing loaded!"), 0, 0,
1779 0, 1 ); 1780 0, 1 );
1780 1781
1781 return; 1782 return;
1782 } 1783 }
1783 if ( loadbup ) { 1784 if ( loadbup ) {
1784 mView->openCalendar( fn ); 1785 mView->openCalendar( fn );
1785 KOPrefs::instance()->mLastLoadFile = fn; 1786 KOPrefs::instance()->mLastLoadFile = fn;
1786 mess = i18n("KO/Pi:Loaded %1").arg(fn) ; 1787 mess = i18n("KO/Pi:Loaded %1").arg(fn) ;
1787 setCaption(mess); 1788 setCaption(mess);
1788 } 1789 }
1789 1790
1790} 1791}
1791void MainWindow::quickImportIcal() 1792void MainWindow::quickImportIcal()
1792{ 1793{
1793 importFile( KOPrefs::instance()->mLastImportFile, false ); 1794 importFile( KOPrefs::instance()->mLastImportFile, false );
1794} 1795}
1795void MainWindow::importFile( QString fn, bool quick ) 1796void MainWindow::importFile( QString fn, bool quick )
1796{ 1797{
1797 QFileInfo info; 1798 QFileInfo info;
1798 info.setFile( fn ); 1799 info.setFile( fn );
1799 QString mess; 1800 QString mess;
1800 bool loadbup = true; 1801 bool loadbup = true;
1801 if ( !info. exists() ) { 1802 if ( !info. exists() ) {
1802 mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30)); 1803 mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30));
1803 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 1804 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1804 mess ); 1805 mess );
1805 return; 1806 return;
1806 } 1807 }
1807 int result = 0; 1808 int result = 0;
1808 if ( !quick ) { 1809 if ( !quick ) {
1809 mess = i18n( "Import file \n...%1\nfrom:\n%2\nDuplicated entries\nwill not be imported!\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 1810 mess = i18n( "Import file \n...%1\nfrom:\n%2\nDuplicated entries\nwill not be imported!\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
1810 result = QMessageBox::warning( this, "KO/Pi: Warning!", 1811 result = QMessageBox::warning( this, "KO/Pi: Warning!",
1811 mess, 1812 mess,
1812 "Import", "Cancel", 0, 1813 "Import", "Cancel", 0,
1813 0, 1 ); 1814 0, 1 );
1814 } 1815 }
1815 if ( result == 0 ) { 1816 if ( result == 0 ) {
1816 if ( mView->openCalendar( fn, true )) { 1817 if ( mView->openCalendar( fn, true )) {
1817 KOPrefs::instance()->mLastImportFile = fn; 1818 KOPrefs::instance()->mLastImportFile = fn;
1818 setCaption(i18n("Imported file successfully")); 1819 setCaption(i18n("Imported file successfully"));
1819 } else { 1820 } else {
1820 setCaption(i18n("Error importing file")); 1821 setCaption(i18n("Error importing file"));
1821 } 1822 }
1822 } 1823 }
1823} 1824}
1824 1825
1825void MainWindow::importIcal() 1826void MainWindow::importIcal()
1826{ 1827{
1827 1828
1828 QString fn =KOPrefs::instance()->mLastImportFile; 1829 QString fn =KOPrefs::instance()->mLastImportFile;
1829 1830
1830 fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this ); 1831 fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this );
1831 if ( fn == "" ) 1832 if ( fn == "" )
1832 return; 1833 return;
1833 importFile( fn, true ); 1834 importFile( fn, true );
1834 1835
1835} 1836}
1836 1837
1837void MainWindow::exportVCalendar() 1838void MainWindow::exportVCalendar()
1838{ 1839{
1839 QString fn = KOPrefs::instance()->mLastVcalFile; 1840 QString fn = KOPrefs::instance()->mLastVcalFile;
1840 fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this ); 1841 fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this );
1841 if ( fn == "" ) 1842 if ( fn == "" )
1842 return; 1843 return;
1843 QFileInfo info; 1844 QFileInfo info;
1844 info.setFile( fn ); 1845 info.setFile( fn );
1845 QString mes; 1846 QString mes;
1846 bool createbup = true; 1847 bool createbup = true;
1847 if ( info. exists() ) { 1848 if ( info. exists() ) {
1848 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); 1849 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
1849 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 1850 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
1850 i18n("Overwrite!"), i18n("Cancel"), 0, 1851 i18n("Overwrite!"), i18n("Cancel"), 0,
1851 0, 1 ); 1852 0, 1 );
1852 if ( result != 0 ) { 1853 if ( result != 0 ) {
1853 createbup = false; 1854 createbup = false;
1854 } 1855 }
1855 } 1856 }
1856 if ( createbup ) { 1857 if ( createbup ) {
1857 if ( mView->exportVCalendar( fn ) ) { 1858 if ( mView->exportVCalendar( fn ) ) {
1858 KOPrefs::instance()->mLastVcalFile = fn; 1859 KOPrefs::instance()->mLastVcalFile = fn;
1859 if ( fn.length() > 20 ) 1860 if ( fn.length() > 20 )
1860 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ; 1861 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ;
1861 else 1862 else
1862 mes = i18n("KO/Pi:Exported to %1").arg(fn ); 1863 mes = i18n("KO/Pi:Exported to %1").arg(fn );
1863 setCaption(mes); 1864 setCaption(mes);
1864 } 1865 }
1865 } 1866 }
1866 1867
1867} 1868}
1868#include <qpushbutton.h> 1869#include <qpushbutton.h>
1869QString MainWindow::getPassword( ) 1870QString MainWindow::getPassword( )
1870{ 1871{
1871 QString retfile = ""; 1872 QString retfile = "";
1872 QDialog dia ( this, "input-dialog", true ); 1873 QDialog dia ( this, "input-dialog", true );
1873 QLineEdit lab ( &dia ); 1874 QLineEdit lab ( &dia );
1874 lab.setEchoMode( QLineEdit::Password ); 1875 lab.setEchoMode( QLineEdit::Password );
1875 QVBoxLayout lay( &dia ); 1876 QVBoxLayout lay( &dia );
1876 lay.setMargin(7); 1877 lay.setMargin(7);
1877 lay.setSpacing(7); 1878 lay.setSpacing(7);
1878 lay.addWidget( &lab); 1879 lay.addWidget( &lab);
1879 dia.setFixedSize( 230,50 ); 1880 dia.setFixedSize( 230,50 );
1880 dia.setCaption( i18n("Enter password") ); 1881 dia.setCaption( i18n("Enter password") );
1881 QPushButton pb ( "OK", &dia); 1882 QPushButton pb ( "OK", &dia);
1882 lay.addWidget( &pb ); 1883 lay.addWidget( &pb );
1883 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 1884 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
1884 dia.show(); 1885 dia.show();
1885 int res = dia.exec(); 1886 int res = dia.exec();
1886 if ( res ) 1887 if ( res )
1887 retfile = lab.text(); 1888 retfile = lab.text();
1888 dia.hide(); 1889 dia.hide();
1889 qApp->processEvents(); 1890 qApp->processEvents();
1890 return retfile; 1891 return retfile;
1891 1892
1892} 1893}
1893 1894
1894void MainWindow::enableQuick() 1895void MainWindow::enableQuick()
1895{ 1896{
1896 QString retfile = ""; 1897 QString retfile = "";
1897 QDialog dia ( this, "input-dialog", true ); 1898 QDialog dia ( this, "input-dialog", true );
1898 QLineEdit lab ( &dia ); 1899 QLineEdit lab ( &dia );
1899 QVBoxLayout lay( &dia ); 1900 QVBoxLayout lay( &dia );
1900 lab.setText( KOPrefs::instance()->mPassiveSyncPort ); 1901 lab.setText( KOPrefs::instance()->mPassiveSyncPort );
1901 lay.setMargin(7); 1902 lay.setMargin(7);
1902 lay.setSpacing(7); 1903 lay.setSpacing(7);
1903 QLabel label ( i18n("Port number (Default: 9197)"), &dia ); 1904 QLabel label ( i18n("Port number (Default: 9197)"), &dia );
1904 lay.addWidget( &label); 1905 lay.addWidget( &label);
1905 lay.addWidget( &lab); 1906 lay.addWidget( &lab);
1906 dia.setFixedSize( 230,80 ); 1907 dia.setFixedSize( 230,80 );
1907 dia.setCaption( i18n("Enter port for Easy-Pi-Sync") ); 1908 dia.setCaption( i18n("Enter port for Easy-Pi-Sync") );
1908 QPushButton pb ( "OK", &dia); 1909 QPushButton pb ( "OK", &dia);
1909 lay.addWidget( &pb ); 1910 lay.addWidget( &pb );
1910 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 1911 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
1911 dia.show(); 1912 dia.show();
1912 int res = dia.exec(); 1913 int res = dia.exec();
1913 if ( res ) 1914 if ( res )
1914 retfile = lab.text(); 1915 retfile = lab.text();
1915 else 1916 else
1916 return; 1917 return;
1917 dia.hide(); 1918 dia.hide();
1918 qApp->processEvents(); 1919 qApp->processEvents();
1919 KOPrefs::instance()->mPassiveSyncPort = retfile; 1920 KOPrefs::instance()->mPassiveSyncPort = retfile;
1920 bool ok; 1921 bool ok;
1921 Q_UINT16 port = retfile.toUInt(&ok); 1922 Q_UINT16 port = retfile.toUInt(&ok);
1922 if ( ! ok ) { 1923 if ( ! ok ) {
1923 qDebug("no valid port "); 1924 qDebug("no valid port ");
1924 return; 1925 return;
1925 } 1926 }
1926 qDebug("port %d ", port); 1927 qDebug("port %d ", port);
1927 mServerSocket = new KServerSocket ( port ,1 ); 1928 mServerSocket = new KServerSocket ( port ,1 );
1928 qDebug("connected "); 1929 qDebug("connected ");
1929 if ( !mServerSocket->ok() ) { 1930 if ( !mServerSocket->ok() ) {
1930 qWarning("Failed to bind to port %d", port); 1931 qWarning("Failed to bind to port %d", port);
1931 delete mServerSocket; 1932 delete mServerSocket;
1932 mServerSocket = 0; 1933 mServerSocket = 0;
1933 return; 1934 return;
1934 } 1935 }
1935 connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) ); 1936 connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) );
1936 connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) ); 1937 connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) );
1937} 1938}
1938void MainWindow::sendFile(QSocket* socket) 1939void MainWindow::sendFile(QSocket* socket)
1939{ 1940{
1940 setCaption( i18n("Received request for file") ); 1941 setCaption( i18n("Received request for file") );
1941 qDebug("MainWindow::sendFile(QSocket* s) "); 1942 qDebug("MainWindow::sendFile(QSocket* s) ");
1942 if ( mSyncActionDialog ) 1943 if ( mSyncActionDialog )
1943 delete mSyncActionDialog; 1944 delete mSyncActionDialog;
1944 mSyncActionDialog = new QDialog ( this, "input-dialog", true ); 1945 mSyncActionDialog = new QDialog ( this, "input-dialog", true );
1945 mSyncActionDialog->setCaption(i18n("KO/Pi - WARNING")); 1946 mSyncActionDialog->setCaption(i18n("KO/Pi - WARNING"));
1946 QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use\nthis application!\n"), mSyncActionDialog ); 1947 QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use\nthis application!\n"), mSyncActionDialog );
1947 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1948 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1948 lay->addWidget( label); 1949 lay->addWidget( label);
1949 lay->setMargin(7); 1950 lay->setMargin(7);
1950 lay->setSpacing(7); 1951 lay->setSpacing(7);
1951 mSyncActionDialog->setFixedSize( 200,100 ); 1952 mSyncActionDialog->setFixedSize( 200,100 );
1952 mSyncActionDialog->show(); 1953 mSyncActionDialog->show();
1953 qApp->processEvents(); 1954 qApp->processEvents();
1954 qDebug("saving ... "); 1955 qDebug("saving ... ");
1955 save(); 1956 save();
1956 QString fileName = defaultFileName(); 1957 QString fileName = defaultFileName();
1957 QFile file( fileName ); 1958 QFile file( fileName );
1958 if (!file.open( IO_ReadOnly ) ) { 1959 if (!file.open( IO_ReadOnly ) ) {
1959 setCaption( i18n("Error open file") ); 1960 setCaption( i18n("Error open file") );
1960 delete mSyncActionDialog; 1961 delete mSyncActionDialog;
1961 mSyncActionDialog = 0; 1962 mSyncActionDialog = 0;
1962 qDebug("error open cal file "); 1963 qDebug("error open cal file ");
1963 return ; 1964 return ;
1964 1965
1965 } 1966 }
1966 setCaption( i18n("Sending file...") ); 1967 setCaption( i18n("Sending file...") );
1967 QTextStream ts( &file ); 1968 QTextStream ts( &file );
1968 ts.setCodec( QTextCodec::codecForName("utf8") ); 1969 ts.setCodec( QTextCodec::codecForName("utf8") );
1969 QTextStream os( socket ); 1970 QTextStream os( socket );
1970 os.setCodec( QTextCodec::codecForName("utf8") ); 1971 os.setCodec( QTextCodec::codecForName("utf8") );
1971 //os.setEncoding( QTextStream::UnicodeUTF8 ); 1972 //os.setEncoding( QTextStream::UnicodeUTF8 );
1972 while ( ! ts.atEnd() ) { 1973 while ( ! ts.atEnd() ) {
1973 os << ts.readLine() << "\n"; 1974 os << ts.readLine() << "\n";
1974 } 1975 }
1975 //os << ts.read(); 1976 //os << ts.read();
1976 socket->close(); 1977 socket->close();
1977 file.close(); 1978 file.close();
1978 setCaption( i18n("File sent. Waiting to get back synced file") ); 1979 setCaption( i18n("File sent. Waiting to get back synced file") );
1979 qDebug("file sent "); 1980 qDebug("file sent ");
1980} 1981}
1981void MainWindow::getFile(QSocket* socket) 1982void MainWindow::getFile(QSocket* socket)
1982{ 1983{
1983 setCaption( i18n("Receiving synced file...") ); 1984 setCaption( i18n("Receiving synced file...") );
1984 qDebug("MainWindow::sendFile(QSocket* s) ");
1985 1985
1986 QString fileName = defaultFileName(); 1986 QString fileName = defaultFileName();
1987 QFile file( fileName ); 1987 QFile file( fileName );
1988 if (!file.open( IO_WriteOnly ) ) { 1988 if (!file.open( IO_WriteOnly ) ) {
1989 setCaption( i18n("Error open file") ); 1989 setCaption( i18n("Error open file") );
1990 delete mSyncActionDialog; 1990 delete mSyncActionDialog;
1991 mSyncActionDialog = 0; 1991 mSyncActionDialog = 0;
1992 qDebug("error open cal file "); 1992 qDebug("error open cal file ");
1993 return ; 1993 return ;
1994 1994
1995 } 1995 }
1996 1996
1997 mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1997 mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1998 QTextStream ts( &file ); 1998 QTextStream ts( &file );
1999 ts.setCodec( QTextCodec::codecForName("utf8") ); 1999 ts.setCodec( QTextCodec::codecForName("utf8") );
2000 bool first = true; 2000 bool first = true;
2001 while ( socket->canReadLine () || first ) { 2001 while ( socket->canReadLine () || first ) {
2002 first = false; 2002 first = false;
2003 while ( socket->canReadLine () ) { 2003 while ( socket->canReadLine () ) {
2004 ts << socket->readLine (); 2004 ts << socket->readLine ();
2005 } 2005 }
2006 socket->waitForMore ( 5000 ); 2006 socket->waitForMore ( 5000 );
2007 } 2007 }
2008 setCaption( i18n("File received - reloading calendar...") ); 2008 setCaption( i18n("File received - reloading calendar...") );
2009 file.close(); 2009 file.close();
2010 socket->close(); 2010 socket->close();
2011 mView->watchSavedFile(); 2011 mView->watchSavedFile();
2012 mView->openCalendar( defaultFileName() ); 2012 mView->openCalendar( defaultFileName() );
2013 setCaption( i18n("Easy-Pi-Sync successful!") ); 2013 setCaption( i18n("Easy-Pi-Sync successful!") );
2014 delete mSyncActionDialog; 2014 delete mSyncActionDialog;
2015 mSyncActionDialog = 0; 2015 mSyncActionDialog = 0;
2016 2016
2017 2017
2018} 2018}
2019void MainWindow::endConnect() 2019void MainWindow::endConnect()
2020{ 2020{
2021 setCaption( i18n("No file received - syncing successful") ); 2021 setCaption( i18n("No file received - syncing successful") );
2022 delete mSyncActionDialog; 2022 delete mSyncActionDialog;
2023 mSyncActionDialog = 0; 2023 mSyncActionDialog = 0;
2024} 2024}
2025void MainWindow::performQuick() 2025void MainWindow::performQuick()
2026{ 2026{
2027 setCaption( i18n("Please input connection settings") ); 2027 setCaption( i18n("Please input connection settings") );
2028 QString retfile = ""; 2028 QString retfile = "";
2029 QDialog dia ( this, "input-dialog", true ); 2029 QDialog dia ( this, "input-dialog", true );
2030 QLineEdit lab ( &dia ); 2030 QLineEdit lab ( &dia );
2031 QVBoxLayout lay( &dia ); 2031 QVBoxLayout lay( &dia );
2032 QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia ); 2032 QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia );
2033 lay.addWidget( &label); 2033 lay.addWidget( &label);
2034 lab.setText( KOPrefs::instance()->mActiveSyncIP ); 2034 lab.setText( KOPrefs::instance()->mActiveSyncIP );
2035 lay.setMargin(7); 2035 lay.setMargin(7);
2036 lay.setSpacing(7); 2036 lay.setSpacing(7);
2037 lay.addWidget( &lab); 2037 lay.addWidget( &lab);
2038 QLabel label2 ( i18n("Port number (Default: 9197)"), &dia ); 2038 QLabel label2 ( i18n("Port number (Default: 9197)"), &dia );
2039 lay.addWidget( &label2); 2039 lay.addWidget( &label2);
2040 QLineEdit lab2 ( &dia ); 2040 QLineEdit lab2 ( &dia );
2041 lab2.setText( KOPrefs::instance()->mActiveSyncPort ); 2041 lab2.setText( KOPrefs::instance()->mActiveSyncPort );
2042 lay.addWidget( &lab2); 2042 lay.addWidget( &lab2);
2043 dia.setFixedSize( 230,200 ); 2043 dia.setFixedSize( 230,200 );
2044 dia.setCaption( i18n("Enter port for Easy-Pi-Sync ") ); 2044 dia.setCaption( i18n("Enter port for Easy-Pi-Sync ") );
2045 QPushButton pb ( "OK", &dia); 2045 QPushButton pb ( "OK", &dia);
2046 lay.addWidget( &pb ); 2046 lay.addWidget( &pb );
2047 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2047 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2048 dia.show(); 2048 dia.show();
2049 int res = dia.exec(); 2049 int res = dia.exec();
2050 if ( !res ) { 2050 if ( !res ) {
2051 setCaption( i18n("Syncing cancelled!") ); 2051 setCaption( i18n("Syncing cancelled!") );
2052 return; 2052 return;
2053 } 2053 }
2054 dia.hide(); 2054 dia.hide();
2055 KOPrefs::instance()->mActiveSyncPort = lab2.text(); 2055 KOPrefs::instance()->mActiveSyncPort = lab2.text();
2056 KOPrefs::instance()->mActiveSyncIP = lab.text(); 2056 KOPrefs::instance()->mActiveSyncIP = lab.text();
2057 qApp->processEvents(); 2057 qApp->processEvents();
2058 performQuickQuick(); 2058 performQuickQuick();
2059} 2059}
2060 2060
2061void MainWindow::performQuickQuick() 2061void MainWindow::performQuickQuick()
2062{ 2062{
2063 // setCaption( i18n("") ); 2063 // setCaption( i18n("") );
2064 2064
2065 bool ok; 2065 bool ok;
2066 Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); 2066 Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok);
2067 if ( ! ok ) { 2067 if ( ! ok ) {
2068 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 2068 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
2069 return; 2069 return;
2070 } 2070 }
2071 if ( mCommandSocket ) 2071 if ( !mCommandSocket ) {
2072 delete mCommandSocket; 2072 mCommandSocket = new QSocket( this );
2073 mCommandSocket = new QSocket( this ); 2073 // delete mCommandSocket;
2074 connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) ); 2074 //mCommandSocket = new QSocket( this );
2075 connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) );
2076 }
2075 QString host = KOPrefs::instance()->mActiveSyncIP; 2077 QString host = KOPrefs::instance()->mActiveSyncIP;
2076 mCommandSocket->connectToHost( host, port ); 2078 mCommandSocket->connectToHost( host, port );
2077 QTextStream os( mCommandSocket ); 2079 QTextStream os( mCommandSocket );
2078 os.setEncoding( QTextStream::UnicodeUTF8 ); 2080 os.setEncoding( QTextStream::UnicodeUTF8 );
2079 os << "GET\r\n"; 2081 os << "GET\r\n";
2080 setCaption( i18n("Sending request for remote file ...") ); 2082 setCaption( i18n("Sending request for remote file ...") );
2081 2083
2082} 2084}
2083void MainWindow::readFileFromSocket() 2085void MainWindow::readFileFromSocket()
2084{ 2086{
2085 setCaption( i18n("Receiving remote file ...") ); 2087 setCaption( i18n("Receiving remote file ...") );
2086 qDebug("MainWindow::readFileFromSocket() "); 2088 qDebug("MainWindow::readFileFromSocket() ");
2087QString fileName; 2089QString fileName;
2088#ifdef _WIN32_ 2090#ifdef _WIN32_
2089 fileName = defaultFileName() +"sync"; 2091 fileName = defaultFileName() +"sync";
2090#else 2092#else
2091 fileName = "/tmp/kopitempfile.ics"; 2093 fileName = "/tmp/kopitempfile.ics";
2092#endif 2094#endif
2093 QFile file( fileName ); 2095 QFile file( fileName );
2094 if (!file.open( IO_WriteOnly ) ) { 2096 if (!file.open( IO_WriteOnly ) ) {
2095 setCaption( i18n("Error: Cannot open temp file for write.") ); 2097 setCaption( i18n("Error: Cannot open temp file for write.") );
2096 qDebug("Error open calender file for writing: %s",fileName.latin1() ); 2098 qDebug("Error open calender file for writing: %s",fileName.latin1() );
2097 return ; 2099 return ;
2098 } 2100 }
2099 2101
2100 //QTextStream os2( mCommandSocket ); 2102 //QTextStream os2( mCommandSocket );
2101 //os2.setEncoding( QTextStream::UnicodeUTF8 ); 2103 //os2.setEncoding( QTextStream::UnicodeUTF8 );
2102 2104
2103 QTextStream ts( &file ); 2105 QTextStream ts( &file );
2104 ts.setCodec( QTextCodec::codecForName("utf8") ); 2106 ts.setCodec( QTextCodec::codecForName("utf8") );
2105 bool first = true; 2107 bool first = true;
2106 while ( mCommandSocket->canReadLine () || first) { 2108 while ( mCommandSocket->canReadLine () || first) {
2107 first = false; 2109 first = false;
2108 while ( mCommandSocket->canReadLine () ) { 2110 while ( mCommandSocket->canReadLine () ) {
2109 ts << mCommandSocket->readLine (); 2111 ts << mCommandSocket->readLine ();
2110 } 2112 }
2111 mCommandSocket->waitForMore ( 5000 ); 2113 mCommandSocket->waitForMore ( 5000 );
2112 } 2114 }
2113 file.close(); 2115 file.close();
2114 mCommandSocket->close(); 2116 mCommandSocket->close();
2115 delete mCommandSocket; 2117 //delete mCommandSocket;
2116 setCaption( i18n("Remote file saved to temp file.") ); 2118 setCaption( i18n("Remote file saved to temp file.") );
2117 mCommandSocket = 0; 2119 //mCommandSocket = 0;
2118 mCurrentSyncProfile = 2 ; // last file 2120 mCurrentSyncProfile = 2 ; // last file
2119 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); 2121 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] );
2120 mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); 2122 mView->setSyncName( KOPrefs::instance()->mLocalMachineName );
2121 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2123 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2122 KSyncProfile* temp = new KSyncProfile (); 2124 KSyncProfile* temp = new KSyncProfile ();
2123 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2125 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2124 temp->readConfig(&config); 2126 temp->readConfig(&config);
2125 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 2127 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2126 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); 2128 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
2127 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 2129 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
2128 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 2130 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
2129 KOPrefs::instance()->mWriteBackInFuture = 0; 2131 KOPrefs::instance()->mWriteBackInFuture = 0;
2130 if ( temp->getWriteBackFuture() ) 2132 if ( temp->getWriteBackFuture() )
2131 KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 2133 KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
2132 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); 2134 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
2133 2135
2134 setCaption( i18n("Remote file saved to temp file.") ); 2136 setCaption( i18n("Remote file saved to temp file.") );
2135 if ( ! syncWithFile( fileName , true ) ) { 2137 if ( ! syncWithFile( fileName , true ) ) {
2136 setCaption( i18n("Syncing failed.") ); 2138 setCaption( i18n("Syncing failed.") );
2137 qDebug("Syncing failed "); 2139 qDebug("Syncing failed ");
2138 return; 2140 return;
2139 } 2141 }
2140 2142
2141 mCommandSocket = new QSocket( this ); 2143 if ( !mCommandSocketFinish ) {
2142 QString host = KOPrefs::instance()->mActiveSyncIP; 2144 mCommandSocketFinish = new QSocket( this );
2143 mCommandSocket->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); 2145 }
2146 mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() );
2144 2147
2148 QString host = KOPrefs::instance()->mActiveSyncIP;
2145 QFile file2( fileName ); 2149 QFile file2( fileName );
2146 if (!file2.open( IO_ReadOnly ) ) { 2150 if (!file2.open( IO_ReadOnly ) ) {
2147 setCaption( i18n("Error: Cannot open temp file for read.") ); 2151 setCaption( i18n("Error: Cannot open temp file for read.") );
2148 qDebug("error open cal file "); 2152 qDebug("error open cal file ");
2149 return ; 2153 return ;
2150 2154
2151 } 2155 }
2152 setCaption( i18n("Sending back synced file...") ); 2156 setCaption( i18n("Sending back synced file...") );
2153 QTextStream ts2( &file2 ); 2157 QTextStream ts2( &file2 );
2154 ts2.setCodec( QTextCodec::codecForName("utf8") ); 2158 ts2.setCodec( QTextCodec::codecForName("utf8") );
2155 QTextStream os2( mCommandSocket ); 2159 QTextStream os2( mCommandSocketFinish );
2156 os2.setCodec( QTextCodec::codecForName("utf8") ); 2160 os2.setCodec( QTextCodec::codecForName("utf8") );
2157 //os.setEncoding( QTextStream::UnicodeUTF8 ); 2161 //os.setEncoding( QTextStream::UnicodeUTF8 );
2158 if ( KOPrefs::instance()->mWriteBackFile ) { 2162 if ( KOPrefs::instance()->mWriteBackFile ) {
2159 os2 << "PUT\r\n"; 2163 os2 << "PUT\r\n";
2160 while ( ! ts2.atEnd() ) { 2164 while ( ! ts2.atEnd() ) {
2161 os2 << ts2.readLine() << "\n"; 2165 os2 << ts2.readLine() << "\n";
2162 } 2166 }
2163 } else { 2167 } else {
2164 os2 << "STOP\r\n"; 2168 os2 << "STOP\r\n";
2165 } 2169 }
2166 mCommandSocket->close(); 2170 mCommandSocketFinish->close();
2167 file.close(); 2171 file.close();
2168 delete mCommandSocket; 2172 //delete ( mCommandSocket);
2169 mCommandSocket = 0; 2173 //mCommandSocket = 0;
2170 qDebug("Syncing succesful! "); 2174 qDebug("Syncing succesful! ");
2171 setCaption( i18n("Easy-Pi-Sync succesful!") ); 2175 setCaption( i18n("Easy-Pi-Sync succesful!") );
2172 2176
2173 2177
2174} 2178}
2175 2179
2176void MainWindow::syncLocalFile() 2180void MainWindow::syncLocalFile()
2177{ 2181{
2178 2182
2179 QString fn =KOPrefs::instance()->mLastSyncedLocalFile; 2183 QString fn =KOPrefs::instance()->mLastSyncedLocalFile;
2180 2184
2181 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); 2185 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
2182 if ( fn == "" ) 2186 if ( fn == "" )
2183 return; 2187 return;
2184 //mView->setSyncDevice("local-file" ); 2188 //mView->setSyncDevice("local-file" );
2185 if ( syncWithFile( fn, false ) ) { 2189 if ( syncWithFile( fn, false ) ) {
2186 // Event* e = mView->getLastSyncEvent(); 2190 // Event* e = mView->getLastSyncEvent();
2187// e->setReadOnly( false ); 2191// e->setReadOnly( false );
2188// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); 2192// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile);
2189// e->setReadOnly( true ); 2193// e->setReadOnly( true );
2190 } 2194 }
2191 2195
2192} 2196}
2193 2197
2194bool MainWindow::syncWithFile( QString fn , bool quick ) 2198bool MainWindow::syncWithFile( QString fn , bool quick )
2195{ 2199{
2196 bool ret = false; 2200 bool ret = false;
2197 QFileInfo info; 2201 QFileInfo info;
2198 info.setFile( fn ); 2202 info.setFile( fn );
2199 QString mess; 2203 QString mess;
2200 bool loadbup = true; 2204 bool loadbup = true;
2201 if ( !info. exists() ) { 2205 if ( !info. exists() ) {
2202 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 2206 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
2203 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2207 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2204 mess ); 2208 mess );
2205 return ret; 2209 return ret;
2206 } 2210 }
2207 int result = 0; 2211 int result = 0;
2208 if ( !quick ) { 2212 if ( !quick ) {
2209 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 2213 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
2210 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2214 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2211 mess, 2215 mess,
2212 i18n("Sync"), i18n("Cancel"), 0, 2216 i18n("Sync"), i18n("Cancel"), 0,
2213 0, 1 ); 2217 0, 1 );
2214 if ( result ) 2218 if ( result )
2215 return false; 2219 return false;
2216 } 2220 }
2217 if ( KOPrefs::instance()->mAskForPreferences ) 2221 if ( KOPrefs::instance()->mAskForPreferences )
2218 mView->edit_sync_options(); 2222 mView->edit_sync_options();
2219 if ( result == 0 ) { 2223 if ( result == 0 ) {
2220 //qDebug("Now sycing ... "); 2224 //qDebug("Now sycing ... ");
2221 if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) ) 2225 if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) )
2222 setCaption( i18n("Synchronization successful") ); 2226 setCaption( i18n("Synchronization successful") );
2223 else 2227 else
2224 setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 2228 setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
2225 if ( ! quick ) 2229 if ( ! quick )
2226 KOPrefs::instance()->mLastSyncedLocalFile = fn; 2230 KOPrefs::instance()->mLastSyncedLocalFile = fn;
2227 slotModifiedChanged( true ); 2231 slotModifiedChanged( true );
2228 } 2232 }
2229 return ret; 2233 return ret;
2230} 2234}
2231void MainWindow::quickSyncLocalFile() 2235void MainWindow::quickSyncLocalFile()
2232{ 2236{
2233 //mView->setSyncDevice("local-file" ); 2237 //mView->setSyncDevice("local-file" );
2234 //qDebug("quickSyncLocalFile() "); 2238 //qDebug("quickSyncLocalFile() ");
2235 if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) { 2239 if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) {
2236 // Event* e = mView->getLastSyncEvent(); 2240 // Event* e = mView->getLastSyncEvent();
2237// e->setReadOnly( false ); 2241// e->setReadOnly( false );
2238// e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); 2242// e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile);
2239// e->setReadOnly( true ); 2243// e->setReadOnly( true );
2240 2244
2241 } 2245 }
2242} 2246}
2243 2247
2244void MainWindow::confSync() 2248void MainWindow::confSync()
2245{ 2249{
2246 mView->confSync(); 2250 mView->confSync();
2247 fillSyncMenu(); 2251 fillSyncMenu();
2248} 2252}
2249void MainWindow::syncRemote( KSyncProfile* prof, bool ask) 2253void MainWindow::syncRemote( KSyncProfile* prof, bool ask)
2250{ 2254{
2251 QString question; 2255 QString question;
2252 if ( ask ) { 2256 if ( ask ) {
2253 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 2257 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
2254 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 2258 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2255 question, 2259 question,
2256 i18n("Yes"), i18n("No"), 2260 i18n("Yes"), i18n("No"),
2257 0, 0 ) != 0 ) 2261 0, 0 ) != 0 )
2258 return; 2262 return;
2259 } 2263 }
2260 QString command = prof->getPreSyncCommand(); 2264 QString command = prof->getPreSyncCommand();
2261 int fi; 2265 int fi;
2262 if ( (fi = command.find("$PWD$")) > 0 ) { 2266 if ( (fi = command.find("$PWD$")) > 0 ) {
2263 QString pwd = getPassword(); 2267 QString pwd = getPassword();
2264 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2268 command = command.left( fi )+ pwd + command.mid( fi+5 );
2265 2269
2266 } 2270 }
2267 int maxlen = 30; 2271 int maxlen = 30;
2268 if ( QApplication::desktop()->width() > 320 ) 2272 if ( QApplication::desktop()->width() > 320 )
2269 maxlen += 25; 2273 maxlen += 25;
2270 setCaption ( i18n( "Copy remote file to local machine..." ) ); 2274 setCaption ( i18n( "Copy remote file to local machine..." ) );
2271 int fileSize = 0; 2275 int fileSize = 0;
2272 int result = system ( command ); 2276 int result = system ( command );
2273 // 0 : okay 2277 // 0 : okay
2274 // 256: no such file or dir 2278 // 256: no such file or dir
2275 // 2279 //
2276 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 2280 qDebug("KO: Remote copy result(0 = okay): %d ",result );
2277 if ( result != 0 ) { 2281 if ( result != 0 ) {
2278 int len = maxlen; 2282 int len = maxlen;
2279 while ( len < command.length() ) { 2283 while ( len < command.length() ) {
2280 command.insert( len , "\n" ); 2284 command.insert( len , "\n" );
2281 len += maxlen +2; 2285 len += maxlen +2;
2282 } 2286 }
2283 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 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) ;
2284 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 2288 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2285 question, 2289 question,
2286 i18n("Okay!")) ; 2290 i18n("Okay!")) ;
2287 setCaption ("KO/Pi"); 2291 setCaption ("KO/Pi");
2288 return; 2292 return;
2289 } 2293 }
2290 setCaption ( i18n( "Copying succeed." ) ); 2294 setCaption ( i18n( "Copying succeed." ) );
2291 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 2295 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
2292 if ( syncWithFile( prof->getLocalTempFile(), true ) ) { 2296 if ( syncWithFile( prof->getLocalTempFile(), true ) ) {
2293// Event* e = mView->getLastSyncEvent(); 2297// Event* e = mView->getLastSyncEvent();
2294// e->setReadOnly( false ); 2298// e->setReadOnly( false );
2295// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2299// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2296// e->setReadOnly( true ); 2300// e->setReadOnly( true );
2297 if ( KOPrefs::instance()->mWriteBackFile ) { 2301 if ( KOPrefs::instance()->mWriteBackFile ) {
2298 command = prof->getPostSyncCommand(); 2302 command = prof->getPostSyncCommand();
2299 int fi; 2303 int fi;
2300 if ( (fi = command.find("$PWD$")) > 0 ) { 2304 if ( (fi = command.find("$PWD$")) > 0 ) {
2301 QString pwd = getPassword(); 2305 QString pwd = getPassword();
2302 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2306 command = command.left( fi )+ pwd + command.mid( fi+5 );
2303 2307
2304 } 2308 }
2305 setCaption ( i18n( "Writing back file ..." ) ); 2309 setCaption ( i18n( "Writing back file ..." ) );
2306 result = system ( command ); 2310 result = system ( command );
2307 qDebug("KO: Writing back file result: %d ", result); 2311 qDebug("KO: Writing back file result: %d ", result);
2308 if ( result != 0 ) { 2312 if ( result != 0 ) {
2309 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 2313 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
2310 return; 2314 return;
2311 } else { 2315 } else {
2312 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 2316 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2313 } 2317 }
2314 } 2318 }
2315 } 2319 }
2316 return; 2320 return;
2317} 2321}
2318void MainWindow::syncSSH() 2322void MainWindow::syncSSH()
2319{ 2323{
2320 // not used anymore 2324 // not used anymore
2321 QTime timer; 2325 QTime timer;
2322 timer.start(); 2326 timer.start();
2323 //qDebug("MainWindow::syncssh() "); 2327 //qDebug("MainWindow::syncssh() ");
2324 KOPrefs *p = KOPrefs::instance(); 2328 KOPrefs *p = KOPrefs::instance();
2325 QString localFile = p->mLocalTempFile; 2329 QString localFile = p->mLocalTempFile;
2326 QString remoteIP = p->mRemoteIP; 2330 QString remoteIP = p->mRemoteIP;
2327 QString remoteUser = p->mRemoteUser; 2331 QString remoteUser = p->mRemoteUser;
2328 QString remoteFile = p->mRemoteFile; 2332 QString remoteFile = p->mRemoteFile;
2329 if ( p->mUsePassWd && p->mRemotePassWd.length() > 0 ) 2333 if ( p->mUsePassWd && p->mRemotePassWd.length() > 0 )
2330 remoteUser += ":" + p->mRemotePassWd; 2334 remoteUser += ":" + p->mRemotePassWd;
2331 2335
2332 QString question = i18n("Do you really want\nto remote sync?\n \n") + 2336 QString question = i18n("Do you really want\nto remote sync?\n \n") +
2333 i18n("IP: " ) +remoteIP +"\n" + 2337 i18n("IP: " ) +remoteIP +"\n" +
2334 i18n("User: " ) + remoteUser +"\n" ; 2338 i18n("User: " ) + remoteUser +"\n" ;
2335 int maxlen = 30; 2339 int maxlen = 30;
2336 if ( QApplication::desktop()->width() > 320 ) 2340 if ( QApplication::desktop()->width() > 320 )
2337 maxlen += 25; 2341 maxlen += 25;
2338 if ( remoteFile.length() > maxlen ) 2342 if ( remoteFile.length() > maxlen )
2339 question += i18n("Remote file:\n..." ) + remoteFile.right(maxlen) +"\n"; 2343 question += i18n("Remote file:\n..." ) + remoteFile.right(maxlen) +"\n";
2340 else 2344 else
2341 question += i18n("Remote file:\n " ) + remoteFile +"\n"; 2345 question += i18n("Remote file:\n " ) + remoteFile +"\n";
2342 if ( localFile.length() > maxlen ) 2346 if ( localFile.length() > maxlen )
2343 question += i18n("Local temp file:\n..." ) + localFile.right(maxlen) +"\n"; 2347 question += i18n("Local temp file:\n..." ) + localFile.right(maxlen) +"\n";
2344 else 2348 else
2345 question += i18n("Local temp file:\n " ) + localFile +"\n"; 2349 question += i18n("Local temp file:\n " ) + localFile +"\n";
2346 2350
2347 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 2351 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2348 question, 2352 question,
2349 i18n("Yes"), i18n("No"), 2353 i18n("Yes"), i18n("No"),
2350 0, 0 ) != 0 ) 2354 0, 0 ) != 0 )
2351 return; 2355 return;
2352 // if ( !p->mUsePassWd ) { 2356 // if ( !p->mUsePassWd ) {
2353 // QString pass = getPassword(); 2357 // QString pass = getPassword();
2354 // if ( pass.length() > 0 ) 2358 // if ( pass.length() > 0 )
2355 // remoteUser += ":" + pass; 2359 // remoteUser += ":" + pass;
2356 // } 2360 // }
2357 QString command = "scp " + remoteUser + "@" + remoteIP +":" + remoteFile +" " +localFile; 2361 QString command = "scp " + remoteUser + "@" + remoteIP +":" + remoteFile +" " +localFile;
2358 setCaption ( i18n( "Copy remote file to local machine..." ) ); 2362 setCaption ( i18n( "Copy remote file to local machine..." ) );
2359 int fileSize = 0; 2363 int fileSize = 0;
2360 int result = system ( command ); 2364 int result = system ( command );
2361 // 0 : okay 2365 // 0 : okay
2362 // 256: no such file or dir 2366 // 256: no such file or dir
2363 // 2367 //
2364 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 2368 qDebug("KO: Remote copy result(0 = okay): %d ",result );
2365 if ( result != 0 ) { 2369 if ( result != 0 ) {
2366 int len = maxlen; 2370 int len = maxlen;
2367 while ( len < command.length() ) { 2371 while ( len < command.length() ) {
2368 command.insert( len , "\n" ); 2372 command.insert( len , "\n" );
2369 len += maxlen +2; 2373 len += maxlen +2;
2370 } 2374 }
2371 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) ; 2375 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) ;
2372 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 2376 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2373 question, 2377 question,
2374 i18n("Okay!")) ; 2378 i18n("Okay!")) ;
2375 setCaption ("KO/Pi"); 2379 setCaption ("KO/Pi");
2376 return; 2380 return;
2377 } 2381 }
2378 2382
2379 2383
2380 setCaption ( i18n( "Copying succeed." ) ); 2384 setCaption ( i18n( "Copying succeed." ) );
2381 //mView->setSyncDevice("ssh-scp" ); 2385 //mView->setSyncDevice("ssh-scp" );
2382 if ( syncWithFile(localFile , true ) ) { 2386 if ( syncWithFile(localFile , true ) ) {
2383// Event* e = mView->getLastSyncEvent(); 2387// Event* e = mView->getLastSyncEvent();
2384// e->setReadOnly( false ); 2388// e->setReadOnly( false );
2385// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2389// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2386// e->setReadOnly( true ); 2390// e->setReadOnly( true );
2387 if ( KOPrefs::instance()->mWriteBackFile ) { 2391 if ( KOPrefs::instance()->mWriteBackFile ) {
2388 command = "scp " + localFile +" " +remoteUser + "@" + remoteIP +":" + remoteFile ; 2392 command = "scp " + localFile +" " +remoteUser + "@" + remoteIP +":" + remoteFile ;
2389 setCaption ( i18n( "Writing back file ..." ) ); 2393 setCaption ( i18n( "Writing back file ..." ) );
2390 result = system ( command ); 2394 result = system ( command );
2391 if ( result != 0 ) { 2395 if ( result != 0 ) {
2392 int len = maxlen; 2396 int len = maxlen;
2393 while ( len < command.length() ) { 2397 while ( len < command.length() ) {
2394 command.insert( len , "\n" ); 2398 command.insert( len , "\n" );
2395 len += maxlen +2; 2399 len += maxlen +2;
2396 } 2400 }
2397 question = i18n("Sorry, the copy back command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; 2401 question = i18n("Sorry, the copy back command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ;
2398 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 2402 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2399 question, 2403 question,
2400 i18n("Okay!")) ; 2404 i18n("Okay!")) ;
2401 setCaption ("KO/Pi"); 2405 setCaption ("KO/Pi");
2402 return; 2406 return;
2403 } else { 2407 } else {
2404 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 2408 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2405 } 2409 }
2406 } 2410 }
2407 } 2411 }
2408 return; 2412 return;
2409#if 0 2413#if 0
2410 system ("scp zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics /home/polo/Applications/korganizer/z_sync.ics"); 2414 system ("scp zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics /home/polo/Applications/korganizer/z_sync.ics");
2411 while ( timer.elapsed() < 5000 ) 2415 while ( timer.elapsed() < 5000 )
2412 qApp->processEvents(); 2416 qApp->processEvents();
2413 2417
2414 qDebug("MainWindow::merging) "); 2418 qDebug("MainWindow::merging) ");
2415 mView->syncCalendar( "/home/polo/Applications/korganizer/z_sync.ics", 0 ); 2419 mView->syncCalendar( "/home/polo/Applications/korganizer/z_sync.ics", 0 );
2416 while ( mBlockSaveFlag ) 2420 while ( mBlockSaveFlag )
2417 qApp->processEvents(); 2421 qApp->processEvents();
2418 save(); 2422 save();
2419 system ("scp /home/polo/Applications/korganizer/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics"); 2423 system ("scp /home/polo/Applications/korganizer/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics");
2420#endif 2424#endif
2421 2425
2422} 2426}
2423 2427
2424 2428
2425void MainWindow::syncSharp() 2429void MainWindow::syncSharp()
2426{ 2430{
2427 if ( mCalendarModifiedFlag ) 2431 if ( mCalendarModifiedFlag )
2428 save(); 2432 save();
2429 mView->syncSharp(); 2433 mView->syncSharp();
2430 slotModifiedChanged( true ); 2434 slotModifiedChanged( true );
2431 2435
2432} 2436}
2433void MainWindow::syncPhone() 2437void MainWindow::syncPhone()
2434{ 2438{
2435 if ( mCalendarModifiedFlag ) 2439 if ( mCalendarModifiedFlag )
2436 save(); 2440 save();
2437 mView->syncPhone(); 2441 mView->syncPhone();
2438 slotModifiedChanged( true ); 2442 slotModifiedChanged( true );
2439 2443
2440} 2444}
2441 2445
2442void MainWindow::printSel( ) 2446void MainWindow::printSel( )
2443{ 2447{
2444 mView->viewManager()->agendaView()->agenda()->printSelection(); 2448 mView->viewManager()->agendaView()->agenda()->printSelection();
2445} 2449}
2446 2450
2447void MainWindow::printCal() 2451void MainWindow::printCal()
2448{ 2452{
2449 mView->print();//mCp->showDialog(); 2453 mView->print();//mCp->showDialog();
2450} 2454}
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index 9bb2302..5985d56 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -1,186 +1,187 @@
1#ifndef KORGE_MAINWINDOW_H 1#ifndef KORGE_MAINWINDOW_H
2#define KORGE_MAINWINDOW_H 2#define KORGE_MAINWINDOW_H
3 3
4#include <qmainwindow.h> 4#include <qmainwindow.h>
5#include <qtimer.h> 5#include <qtimer.h>
6#include <qdict.h> 6#include <qdict.h>
7#include <qregexp.h> 7#include <qregexp.h>
8 8
9#include <libkcal/incidence.h> 9#include <libkcal/incidence.h>
10#include "simplealarmclient.h" 10#include "simplealarmclient.h"
11 11
12class QAction; 12class QAction;
13class CalendarView; 13class CalendarView;
14class KSyncProfile; 14class KSyncProfile;
15#ifdef DESKTOP_VERSION 15#ifdef DESKTOP_VERSION
16 16
17#define QPEToolBar QToolBar 17#define QPEToolBar QToolBar
18#define QPEMenuBar QMenuBar 18#define QPEMenuBar QMenuBar
19#endif 19#endif
20class QPEToolBar; 20class QPEToolBar;
21#include <qserversocket.h> 21#include <qserversocket.h>
22#include <qsocket.h> 22#include <qsocket.h>
23#include <qnetworkprotocol.h> 23#include <qnetworkprotocol.h>
24 24
25class KServerSocket : public QServerSocket 25class KServerSocket : public QServerSocket
26{ 26{
27 Q_OBJECT 27 Q_OBJECT
28 28
29public: 29public:
30 KServerSocket ( Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ) : 30 KServerSocket ( Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ) :
31 QServerSocket( port, backlog, parent, name ){;}; 31 QServerSocket( port, backlog, parent, name ){;};
32 void newConnection ( int socket ) 32 void newConnection ( int socket )
33 { 33 {
34 qDebug("KServerSocket:New connection %d ", socket); 34 qDebug("KServerSocket:New connection %d ", socket);
35 QSocket* s = new QSocket( this ); 35 QSocket* s = new QSocket( this );
36 connect( s, SIGNAL(readyRead()), this, SLOT(readClient()) ); 36 connect( s, SIGNAL(readyRead()), this, SLOT(readClient()) );
37 connect( s, SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 37 connect( s, SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
38 s->setSocket( socket ); 38 s->setSocket( socket );
39 } 39 }
40 40
41signals: 41signals:
42 void sendFile(QSocket*); 42 void sendFile(QSocket*);
43 void getFile(QSocket*); 43 void getFile(QSocket*);
44 void endConnect(); 44 void endConnect();
45private slots: 45private slots:
46 void discardClient() 46 void discardClient()
47 { 47 {
48 QSocket* socket = (QSocket*)sender(); 48 QSocket* socket = (QSocket*)sender();
49 delete socket; 49 delete socket;
50 //emit endConnect(); 50 //emit endConnect();
51 } 51 }
52 void readClient() 52 void readClient()
53 { 53 {
54 qDebug("readClient() "); 54 qDebug("readClient() ");
55 QSocket* socket = (QSocket*)sender(); 55 QSocket* socket = (QSocket*)sender();
56 if ( socket->canReadLine() ) { 56 if ( socket->canReadLine() ) {
57 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), socket->readLine() ); 57 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), socket->readLine() );
58 if ( tokens[0] == "GET" ) { 58 if ( tokens[0] == "GET" ) {
59 emit sendFile( socket ); 59 emit sendFile( socket );
60 } 60 }
61 if ( tokens[0] == "PUT" ) { 61 if ( tokens[0] == "PUT" ) {
62 emit getFile( socket ); 62 emit getFile( socket );
63 } 63 }
64 if ( tokens[0] == "STOP" ) { 64 if ( tokens[0] == "STOP" ) {
65 emit endConnect(); 65 emit endConnect();
66 } 66 }
67 } 67 }
68 } 68 }
69}; 69};
70 70
71 71
72namespace KCal { 72namespace KCal {
73class CalendarLocal; 73class CalendarLocal;
74} 74}
75 75
76using namespace KCal; 76using namespace KCal;
77 77
78class MainWindow : public QMainWindow 78class MainWindow : public QMainWindow
79{ 79{
80 Q_OBJECT 80 Q_OBJECT
81 public: 81 public:
82 MainWindow( QWidget *parent = 0, const char *name = 0, QString command = ""); 82 MainWindow( QWidget *parent = 0, const char *name = 0, QString command = "");
83 ~MainWindow(); 83 ~MainWindow();
84 public slots: 84 public slots:
85 virtual void showMaximized (); 85 virtual void showMaximized ();
86 void configureAgenda( int ); 86 void configureAgenda( int );
87 void recieve( const QCString& msg, const QByteArray& data ); 87 void recieve( const QCString& msg, const QByteArray& data );
88 static QString defaultFileName(); 88 static QString defaultFileName();
89 static QString resourcePath(); 89 static QString resourcePath();
90 protected slots: 90 protected slots:
91 void setCaptionToDates(); 91 void setCaptionToDates();
92 int ringSync(); 92 int ringSync();
93 void multiSync( bool askforPrefs = false ); 93 void multiSync( bool askforPrefs = false );
94 void about(); 94 void about();
95 void licence(); 95 void licence();
96 void faq(); 96 void faq();
97 void usertrans(); 97 void usertrans();
98 void features(); 98 void features();
99 void synchowto(); 99 void synchowto();
100 void whatsNew(); 100 void whatsNew();
101 void keyBindings(); 101 void keyBindings();
102 void aboutAutoSaving();; 102 void aboutAutoSaving();;
103 void aboutKnownBugs(); 103 void aboutKnownBugs();
104 104
105 void processIncidenceSelection( Incidence * ); 105 void processIncidenceSelection( Incidence * );
106 106
107 void importQtopia(); 107 void importQtopia();
108 void importBday(); 108 void importBday();
109 void importOL(); 109 void importOL();
110 void importIcal(); 110 void importIcal();
111 void importFile( QString, bool ); 111 void importFile( QString, bool );
112 void quickImportIcal(); 112 void quickImportIcal();
113 113
114 void slotModifiedChanged( bool ); 114 void slotModifiedChanged( bool );
115 115
116 void save(); 116 void save();
117 void configureToolBar( int ); 117 void configureToolBar( int );
118 void printSel(); 118 void printSel();
119 void printCal(); 119 void printCal();
120 void saveCalendar(); 120 void saveCalendar();
121 void loadCalendar(); 121 void loadCalendar();
122 void exportVCalendar(); 122 void exportVCalendar();
123 void fillFilterMenu(); 123 void fillFilterMenu();
124 void selectFilter( int ); 124 void selectFilter( int );
125 125
126 void slotSyncMenu( int ); 126 void slotSyncMenu( int );
127 void syncSSH(); 127 void syncSSH();
128 void confSync(); 128 void confSync();
129 void syncSharp(); 129 void syncSharp();
130 void syncPhone(); 130 void syncPhone();
131 void syncLocalFile(); 131 void syncLocalFile();
132 bool syncWithFile( QString, bool ); 132 bool syncWithFile( QString, bool );
133 void quickSyncLocalFile(); 133 void quickSyncLocalFile();
134 134
135 135
136 protected: 136 protected:
137 void displayText( QString, QString); 137 void displayText( QString, QString);
138 void displayFile( QString, QString); 138 void displayFile( QString, QString);
139 139
140 void enableIncidenceActions( bool ); 140 void enableIncidenceActions( bool );
141 141
142 private slots: 142 private slots:
143 void fillSyncMenu(); 143 void fillSyncMenu();
144 void sendFile(QSocket* s); 144 void sendFile(QSocket* s);
145 void getFile(QSocket* socket); 145 void getFile(QSocket* socket);
146 void readFileFromSocket(); 146 void readFileFromSocket();
147 void endConnect(); 147 void endConnect();
148 private: 148 private:
149 QSocket* mCommandSocket; 149 QSocket* mCommandSocket;
150 QSocket* mCommandSocketFinish;
150 KServerSocket * mServerSocket; 151 KServerSocket * mServerSocket;
151 bool mClosed; 152 bool mClosed;
152 void saveOnClose(); 153 void saveOnClose();
153 int mCurrentSyncProfile; 154 int mCurrentSyncProfile;
154 void enableQuick(); 155 void enableQuick();
155 void performQuick(); 156 void performQuick();
156 void performQuickQuick(); 157 void performQuickQuick();
157 void syncRemote( KSyncProfile* , bool ask = true); 158 void syncRemote( KSyncProfile* , bool ask = true);
158 bool mFlagKeyPressed; 159 bool mFlagKeyPressed;
159 bool mBlockAtStartup; 160 bool mBlockAtStartup;
160 QPEToolBar *iconToolBar; 161 QPEToolBar *iconToolBar;
161 void initActions(); 162 void initActions();
162 void setDefaultPreferences(); 163 void setDefaultPreferences();
163 void keyPressEvent ( QKeyEvent * ) ; 164 void keyPressEvent ( QKeyEvent * ) ;
164 void keyReleaseEvent ( QKeyEvent * ) ; 165 void keyReleaseEvent ( QKeyEvent * ) ;
165 QPopupMenu *configureToolBarMenu; 166 QPopupMenu *configureToolBarMenu;
166 QPopupMenu *selectFilterMenu; 167 QPopupMenu *selectFilterMenu;
167 QPopupMenu *configureAgendaMenu, *syncMenu; 168 QPopupMenu *configureAgendaMenu, *syncMenu;
168 CalendarLocal *mCalendar; 169 CalendarLocal *mCalendar;
169 CalendarView *mView; 170 CalendarView *mView;
170 QString getPassword(); 171 QString getPassword();
171 QAction *mNewSubTodoAction; 172 QAction *mNewSubTodoAction;
172 173
173 QAction *mShowAction; 174 QAction *mShowAction;
174 QAction *mEditAction; 175 QAction *mEditAction;
175 QAction *mDeleteAction; 176 QAction *mDeleteAction;
176 void closeEvent( QCloseEvent* ce ); 177 void closeEvent( QCloseEvent* ce );
177 SimpleAlarmClient mAlarmClient; 178 SimpleAlarmClient mAlarmClient;
178 QTimer mSaveTimer; 179 QTimer mSaveTimer;
179 bool mBlockSaveFlag; 180 bool mBlockSaveFlag;
180 bool mCalendarModifiedFlag; 181 bool mCalendarModifiedFlag;
181 QPixmap loadPixmap( QString ); 182 QPixmap loadPixmap( QString );
182 QDialog * mSyncActionDialog; 183 QDialog * mSyncActionDialog;
183}; 184};
184 185
185 186
186#endif 187#endif