author | zautrix <zautrix> | 2004-10-04 19:29:05 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-04 19:29:05 (UTC) |
commit | dfc6d084410456037bf6f26f741e7b938085de88 (patch) (unidiff) | |
tree | 6c05462c68067b37af3766020667328f8da839f8 | |
parent | 144952942e57780587739a46253cc7305c79f27c (diff) | |
download | kdepimpi-dfc6d084410456037bf6f26f741e7b938085de88.zip kdepimpi-dfc6d084410456037bf6f26f741e7b938085de88.tar.gz kdepimpi-dfc6d084410456037bf6f26f741e7b938085de88.tar.bz2 |
more sync
-rw-r--r-- | korganizer/mainwindow.cpp | 236 | ||||
-rw-r--r-- | korganizer/mainwindow.h | 13 |
2 files changed, 78 insertions, 171 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index da73caf..bce2a54 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp | |||
@@ -1,270 +1,268 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | 2 | ||
3 | #include <qaction.h> | 3 | #include <qaction.h> |
4 | #include <qpopupmenu.h> | 4 | #include <qpopupmenu.h> |
5 | #include <qpainter.h> | 5 | #include <qpainter.h> |
6 | #include <qwhatsthis.h> | 6 | #include <qwhatsthis.h> |
7 | #include <qpushbutton.h> | 7 | #include <qpushbutton.h> |
8 | #include <qmessagebox.h> | 8 | #include <qmessagebox.h> |
9 | #include <qlineedit.h> | 9 | #include <qlineedit.h> |
10 | #include <qtextcodec.h> | 10 | #include <qtextcodec.h> |
11 | #include <qfile.h> | 11 | #include <qfile.h> |
12 | #include <qdir.h> | 12 | #include <qdir.h> |
13 | #include <qapp.h> | 13 | #include <qapp.h> |
14 | #include <qfileinfo.h> | 14 | #include <qfileinfo.h> |
15 | #include <qlabel.h> | 15 | #include <qlabel.h> |
16 | #include <qmap.h> | 16 | #include <qmap.h> |
17 | #include <qwmatrix.h> | 17 | #include <qwmatrix.h> |
18 | #include <qtextbrowser.h> | 18 | #include <qtextbrowser.h> |
19 | #include <qtextstream.h> | 19 | #include <qtextstream.h> |
20 | #ifndef DESKTOP_VERSION | 20 | #ifndef DESKTOP_VERSION |
21 | #include <qpe/global.h> | 21 | #include <qpe/global.h> |
22 | #include <qpe/qpemenubar.h> | 22 | #include <qpe/qpemenubar.h> |
23 | #include <qpe/qpetoolbar.h> | 23 | #include <qpe/qpetoolbar.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | #include <qtopia/alarmserver.h> | 26 | #include <qtopia/alarmserver.h> |
27 | #include <qtopia/qcopenvelope_qws.h> | 27 | #include <qtopia/qcopenvelope_qws.h> |
28 | #include <unistd.h> // for sleep | 28 | #include <unistd.h> // for sleep |
29 | #else | 29 | #else |
30 | #include <qmenubar.h> | 30 | #include <qmenubar.h> |
31 | #include <qtoolbar.h> | 31 | #include <qtoolbar.h> |
32 | #include <qapplication.h> | 32 | #include <qapplication.h> |
33 | //#include <resource.h> | 33 | //#include <resource.h> |
34 | 34 | ||
35 | #endif | 35 | #endif |
36 | #include <libkcal/calendarlocal.h> | 36 | #include <libkcal/calendarlocal.h> |
37 | #include <libkcal/todo.h> | 37 | #include <libkcal/todo.h> |
38 | #include <libkdepim/ksyncprofile.h> | 38 | #include <libkdepim/ksyncprofile.h> |
39 | #include <libkcal/kincidenceformatter.h> | 39 | #include <libkcal/kincidenceformatter.h> |
40 | #include <libkdepim/kpimglobalprefs.h> | 40 | #include <libkdepim/kpimglobalprefs.h> |
41 | 41 | ||
42 | #include "calendarview.h" | 42 | #include "calendarview.h" |
43 | #include "koviewmanager.h" | 43 | #include "koviewmanager.h" |
44 | #include "datenavigator.h" | 44 | #include "datenavigator.h" |
45 | #include "koagendaview.h" | 45 | #include "koagendaview.h" |
46 | #include "koagenda.h" | 46 | #include "koagenda.h" |
47 | #include "kodialogmanager.h" | 47 | #include "kodialogmanager.h" |
48 | #include "kdialogbase.h" | 48 | #include "kdialogbase.h" |
49 | #include "kapplication.h" | 49 | #include "kapplication.h" |
50 | #include "kofilterview.h" | 50 | #include "kofilterview.h" |
51 | #include "kstandarddirs.h" | 51 | #include "kstandarddirs.h" |
52 | #include "koprefs.h" | 52 | #include "koprefs.h" |
53 | #include "kfiledialog.h" | 53 | #include "kfiledialog.h" |
54 | #include "koglobals.h" | 54 | #include "koglobals.h" |
55 | #include "kglobal.h" | 55 | #include "kglobal.h" |
56 | #include "klocale.h" | 56 | #include "klocale.h" |
57 | #include "kconfig.h" | 57 | #include "kconfig.h" |
58 | #include "simplealarmclient.h" | 58 | #include "simplealarmclient.h" |
59 | #include "externalapphandler.h" | 59 | #include "externalapphandler.h" |
60 | 60 | ||
61 | using namespace KCal; | 61 | using namespace KCal; |
62 | #ifndef _WIN32_ | 62 | #ifndef _WIN32_ |
63 | #include <unistd.h> | 63 | #include <unistd.h> |
64 | #else | 64 | #else |
65 | #include "koimportoldialog.h" | 65 | #include "koimportoldialog.h" |
66 | #endif | 66 | #endif |
67 | #include "mainwindow.h" | 67 | #include "mainwindow.h" |
68 | 68 | ||
69 | int globalFlagBlockStartup; | 69 | int globalFlagBlockStartup; |
70 | MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : | 70 | MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : |
71 | QMainWindow( parent, name ) | 71 | QMainWindow( parent, name ) |
72 | { | 72 | { |
73 | mPassWordPiSync = "abc"; | 73 | mPassWordPiSync = "abc"; |
74 | #ifdef DESKTOP_VERSION | 74 | #ifdef DESKTOP_VERSION |
75 | setFont( QFont("Arial"), 14 ); | 75 | setFont( QFont("Arial"), 14 ); |
76 | #endif | 76 | #endif |
77 | mCommandSocket = 0; | ||
78 | mCommandSocketFinish = 0; | ||
79 | mSyncActionDialog = 0; | 77 | mSyncActionDialog = 0; |
80 | mServerSocket = 0; | 78 | mServerSocket = 0; |
81 | mClosed = false; | 79 | mClosed = false; |
82 | //QString confFile = KStandardDirs::appDir() + "config/korganizerrc"; | 80 | //QString confFile = KStandardDirs::appDir() + "config/korganizerrc"; |
83 | QString confFile = locateLocal("config","korganizerrc"); | 81 | QString confFile = locateLocal("config","korganizerrc"); |
84 | QFileInfo finf ( confFile ); | 82 | QFileInfo finf ( confFile ); |
85 | bool showWarning = !finf.exists(); | 83 | bool showWarning = !finf.exists(); |
86 | setIcon(SmallIcon( "ko24" ) ); | 84 | setIcon(SmallIcon( "ko24" ) ); |
87 | mBlockAtStartup = true; | 85 | mBlockAtStartup = true; |
88 | mFlagKeyPressed = false; | 86 | mFlagKeyPressed = false; |
89 | setCaption("KOrganizer/Pi"); | 87 | setCaption("KOrganizer/Pi"); |
90 | KOPrefs *p = KOPrefs::instance(); | 88 | KOPrefs *p = KOPrefs::instance(); |
91 | KPimGlobalPrefs::instance()->setGlobalConfig(); | 89 | KPimGlobalPrefs::instance()->setGlobalConfig(); |
92 | // if ( QApplication::desktop()->height() > 480 ) { | 90 | // if ( QApplication::desktop()->height() > 480 ) { |
93 | // if ( p->mHourSize == 4 ) | 91 | // if ( p->mHourSize == 4 ) |
94 | // p->mHourSize = 6; | 92 | // p->mHourSize = 6; |
95 | // } | 93 | // } |
96 | if ( p->mHourSize > 18 ) | 94 | if ( p->mHourSize > 18 ) |
97 | p->mHourSize = 18; | 95 | p->mHourSize = 18; |
98 | QMainWindow::ToolBarDock tbd; | 96 | QMainWindow::ToolBarDock tbd; |
99 | if ( p->mToolBarHor ) { | 97 | if ( p->mToolBarHor ) { |
100 | if ( p->mToolBarUp ) | 98 | if ( p->mToolBarUp ) |
101 | tbd = Bottom; | 99 | tbd = Bottom; |
102 | else | 100 | else |
103 | tbd = Top; | 101 | tbd = Top; |
104 | } | 102 | } |
105 | else { | 103 | else { |
106 | if ( p->mToolBarUp ) | 104 | if ( p->mToolBarUp ) |
107 | tbd = Right; | 105 | tbd = Right; |
108 | else | 106 | else |
109 | tbd = Left; | 107 | tbd = Left; |
110 | } | 108 | } |
111 | if ( KOPrefs::instance()->mUseAppColors ) | 109 | if ( KOPrefs::instance()->mUseAppColors ) |
112 | QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); | 110 | QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); |
113 | globalFlagBlockStartup = 1; | 111 | globalFlagBlockStartup = 1; |
114 | iconToolBar = new QPEToolBar( this ); | 112 | iconToolBar = new QPEToolBar( this ); |
115 | addToolBar (iconToolBar , tbd ); | 113 | addToolBar (iconToolBar , tbd ); |
116 | mBlockSaveFlag = false; | 114 | mBlockSaveFlag = false; |
117 | mCalendarModifiedFlag = false; | 115 | mCalendarModifiedFlag = false; |
118 | 116 | ||
119 | QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this ); | 117 | QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this ); |
120 | splash->setAlignment ( AlignCenter ); | 118 | splash->setAlignment ( AlignCenter ); |
121 | setCentralWidget( splash ); | 119 | setCentralWidget( splash ); |
122 | #ifndef DESKTOP_VERSION | 120 | #ifndef DESKTOP_VERSION |
123 | showMaximized(); | 121 | showMaximized(); |
124 | #endif | 122 | #endif |
125 | //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 ()); |
126 | setDefaultPreferences(); | 124 | setDefaultPreferences(); |
127 | mCalendar = new CalendarLocal(); | 125 | mCalendar = new CalendarLocal(); |
128 | mView = new CalendarView( mCalendar, this,"mCalendar " ); | 126 | mView = new CalendarView( mCalendar, this,"mCalendar " ); |
129 | mView->hide(); | 127 | mView->hide(); |
130 | //mView->resize(splash->size() ); | 128 | //mView->resize(splash->size() ); |
131 | initActions(); | 129 | initActions(); |
132 | #ifndef DESKTOP_VERSION | 130 | #ifndef DESKTOP_VERSION |
133 | iconToolBar->show(); | 131 | iconToolBar->show(); |
134 | qApp->processEvents(); | 132 | qApp->processEvents(); |
135 | #endif | 133 | #endif |
136 | //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 ()); |
137 | int vh = height() ; | 135 | int vh = height() ; |
138 | int vw = width(); | 136 | int vw = width(); |
139 | //qDebug("Toolbar hei %d ",iconToolBar->height() ); | 137 | //qDebug("Toolbar hei %d ",iconToolBar->height() ); |
140 | if ( iconToolBar->orientation () == Qt:: Horizontal ) { | 138 | if ( iconToolBar->orientation () == Qt:: Horizontal ) { |
141 | vh -= iconToolBar->height(); | 139 | vh -= iconToolBar->height(); |
142 | } else { | 140 | } else { |
143 | vw -= iconToolBar->height(); | 141 | vw -= iconToolBar->height(); |
144 | } | 142 | } |
145 | //mView->setMaximumSize( splash->size() ); | 143 | //mView->setMaximumSize( splash->size() ); |
146 | //mView->resize( splash->size() ); | 144 | //mView->resize( splash->size() ); |
147 | //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 ()); |
148 | mView->readSettings(); | 146 | mView->readSettings(); |
149 | bool oldOpened = false; | 147 | bool oldOpened = false; |
150 | bool newFile = false; | 148 | bool newFile = false; |
151 | if( !QFile::exists( defaultFileName() ) ) { | 149 | if( !QFile::exists( defaultFileName() ) ) { |
152 | QFileInfo finfo ( defaultFileName() ); | 150 | QFileInfo finfo ( defaultFileName() ); |
153 | QString oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/Applications/korganizer/mycalendar.ics"); | 151 | QString oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/Applications/korganizer/mycalendar.ics"); |
154 | qDebug("oldfile %s ", oldFile.latin1()); | 152 | qDebug("oldfile %s ", oldFile.latin1()); |
155 | 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"; |
156 | finfo.setFile( oldFile ); | 154 | finfo.setFile( oldFile ); |
157 | if (finfo.exists() ) { | 155 | if (finfo.exists() ) { |
158 | KMessageBox::information( this, message); | 156 | KMessageBox::information( this, message); |
159 | mView->openCalendar( oldFile ); | 157 | mView->openCalendar( oldFile ); |
160 | qApp->processEvents(); | 158 | qApp->processEvents(); |
161 | } else { | 159 | } else { |
162 | oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/korganizer/mycalendar.ics"); | 160 | oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/korganizer/mycalendar.ics"); |
163 | finfo.setFile( oldFile ); | 161 | finfo.setFile( oldFile ); |
164 | if (finfo.exists() ) { | 162 | if (finfo.exists() ) { |
165 | KMessageBox::information( this, message); | 163 | KMessageBox::information( this, message); |
166 | mView->openCalendar( oldFile ); | 164 | mView->openCalendar( oldFile ); |
167 | qApp->processEvents(); | 165 | qApp->processEvents(); |
168 | } | 166 | } |
169 | } | 167 | } |
170 | mView->saveCalendar( defaultFileName() ); | 168 | mView->saveCalendar( defaultFileName() ); |
171 | newFile = true; | 169 | newFile = true; |
172 | } | 170 | } |
173 | 171 | ||
174 | QTime neededSaveTime = QDateTime::currentDateTime().time(); | 172 | QTime neededSaveTime = QDateTime::currentDateTime().time(); |
175 | if ( ! oldOpened ) | 173 | if ( ! oldOpened ) |
176 | mView->openCalendar( defaultFileName() ); | 174 | mView->openCalendar( defaultFileName() ); |
177 | int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() ); | 175 | int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() ); |
178 | qDebug("KO: Calendar loading time: %d ms",msNeeded ); | 176 | qDebug("KO: Calendar loading time: %d ms",msNeeded ); |
179 | 177 | ||
180 | if ( KOPrefs::instance()->mLanguageChanged ) { | 178 | if ( KOPrefs::instance()->mLanguageChanged ) { |
181 | KOPrefs::instance()->setCategoryDefaults(); | 179 | KOPrefs::instance()->setCategoryDefaults(); |
182 | int count = mView->addCategories(); | 180 | int count = mView->addCategories(); |
183 | KOPrefs::instance()->mLanguageChanged = false; | 181 | KOPrefs::instance()->mLanguageChanged = false; |
184 | } | 182 | } |
185 | processIncidenceSelection( 0 ); | 183 | processIncidenceSelection( 0 ); |
186 | connect( mView, SIGNAL( incidenceSelected( Incidence * ) ), | 184 | connect( mView, SIGNAL( incidenceSelected( Incidence * ) ), |
187 | SLOT( processIncidenceSelection( Incidence * ) ) ); | 185 | SLOT( processIncidenceSelection( Incidence * ) ) ); |
188 | connect( mView, SIGNAL( modifiedChanged( bool ) ), | 186 | connect( mView, SIGNAL( modifiedChanged( bool ) ), |
189 | SLOT( slotModifiedChanged( bool ) ) ); | 187 | SLOT( slotModifiedChanged( bool ) ) ); |
190 | 188 | ||
191 | 189 | ||
192 | connect( &mSaveTimer, SIGNAL( timeout() ), SLOT( save() ) ); | 190 | connect( &mSaveTimer, SIGNAL( timeout() ), SLOT( save() ) ); |
193 | mView->setModified( false ); | 191 | mView->setModified( false ); |
194 | mBlockAtStartup = false; | 192 | mBlockAtStartup = false; |
195 | mView->setModified( false ); | 193 | mView->setModified( false ); |
196 | setCentralWidget( mView ); | 194 | setCentralWidget( mView ); |
197 | globalFlagBlockStartup = 0; | 195 | globalFlagBlockStartup = 0; |
198 | mView->show(); | 196 | mView->show(); |
199 | delete splash; | 197 | delete splash; |
200 | if ( newFile ) | 198 | if ( newFile ) |
201 | mView->updateConfig(); | 199 | mView->updateConfig(); |
202 | // qApp->processEvents(); | 200 | // qApp->processEvents(); |
203 | //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 ()); |
204 | fillSyncMenu(); | 202 | fillSyncMenu(); |
205 | mView->viewManager()->agendaView()->setStartHour( KOPrefs::instance()->mDayBegins ); | 203 | mView->viewManager()->agendaView()->setStartHour( KOPrefs::instance()->mDayBegins ); |
206 | if ( showWarning ) { | 204 | if ( showWarning ) { |
207 | KMessageBox::information( this, | 205 | KMessageBox::information( this, |
208 | "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"); |
209 | qApp->processEvents(); | 207 | qApp->processEvents(); |
210 | mView->dialogManager()->showSyncOptions(); | 208 | mView->dialogManager()->showSyncOptions(); |
211 | } | 209 | } |
212 | 210 | ||
213 | //US listen for result adressed from Ka/Pi | 211 | //US listen for result adressed from Ka/Pi |
214 | #ifndef DESKTOP_VERSION | 212 | #ifndef DESKTOP_VERSION |
215 | 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 & ))); |
216 | #endif | 214 | #endif |
217 | } | 215 | } |
218 | MainWindow::~MainWindow() | 216 | MainWindow::~MainWindow() |
219 | { | 217 | { |
220 | //qDebug("MainWindow::~MainWindow() "); | 218 | //qDebug("MainWindow::~MainWindow() "); |
221 | //save toolbar location | 219 | //save toolbar location |
222 | delete mServerSocket; | 220 | delete mServerSocket; |
223 | delete mCalendar; | 221 | delete mCalendar; |
224 | delete KOPrefs::instance(); | 222 | delete KOPrefs::instance(); |
225 | delete KIncidenceFormatter::instance(); | 223 | delete KIncidenceFormatter::instance(); |
226 | 224 | ||
227 | 225 | ||
228 | } | 226 | } |
229 | void MainWindow::showMaximized () | 227 | void MainWindow::showMaximized () |
230 | { | 228 | { |
231 | #ifndef DESKTOP_VERSION | 229 | #ifndef DESKTOP_VERSION |
232 | if ( ! globalFlagBlockStartup ) | 230 | if ( ! globalFlagBlockStartup ) |
233 | if ( mClosed ) | 231 | if ( mClosed ) |
234 | mView->goToday(); | 232 | mView->goToday(); |
235 | #endif | 233 | #endif |
236 | QWidget::showMaximized () ; | 234 | QWidget::showMaximized () ; |
237 | mClosed = false; | 235 | mClosed = false; |
238 | } | 236 | } |
239 | void MainWindow::closeEvent( QCloseEvent* ce ) | 237 | void MainWindow::closeEvent( QCloseEvent* ce ) |
240 | { | 238 | { |
241 | 239 | ||
242 | 240 | ||
243 | 241 | ||
244 | if ( ! KOPrefs::instance()->mAskForQuit ) { | 242 | if ( ! KOPrefs::instance()->mAskForQuit ) { |
245 | saveOnClose(); | 243 | saveOnClose(); |
246 | mClosed = true; | 244 | mClosed = true; |
247 | ce->accept(); | 245 | ce->accept(); |
248 | return; | 246 | return; |
249 | 247 | ||
250 | } | 248 | } |
251 | 249 | ||
252 | switch( QMessageBox::information( this, "KO/Pi", | 250 | switch( QMessageBox::information( this, "KO/Pi", |
253 | i18n("Do you really want\nto close KO/Pi?"), | 251 | i18n("Do you really want\nto close KO/Pi?"), |
254 | i18n("Close"), i18n("No"), | 252 | i18n("Close"), i18n("No"), |
255 | 0, 0 ) ) { | 253 | 0, 0 ) ) { |
256 | case 0: | 254 | case 0: |
257 | saveOnClose(); | 255 | saveOnClose(); |
258 | mClosed = true; | 256 | mClosed = true; |
259 | ce->accept(); | 257 | ce->accept(); |
260 | break; | 258 | break; |
261 | case 1: | 259 | case 1: |
262 | ce->ignore(); | 260 | ce->ignore(); |
263 | break; | 261 | break; |
264 | case 2: | 262 | case 2: |
265 | 263 | ||
266 | default: | 264 | default: |
267 | break; | 265 | break; |
268 | } | 266 | } |
269 | 267 | ||
270 | 268 | ||
@@ -1753,1015 +1751,927 @@ void MainWindow::loadCalendar() | |||
1753 | { | 1751 | { |
1754 | 1752 | ||
1755 | QString fn = KOPrefs::instance()->mLastLoadFile; | 1753 | QString fn = KOPrefs::instance()->mLastLoadFile; |
1756 | fn = KFileDialog::getOpenFileName( fn, i18n("Load backup filename"), this ); | 1754 | fn = KFileDialog::getOpenFileName( fn, i18n("Load backup filename"), this ); |
1757 | 1755 | ||
1758 | if ( fn == "" ) | 1756 | if ( fn == "" ) |
1759 | return; | 1757 | return; |
1760 | QFileInfo info; | 1758 | QFileInfo info; |
1761 | info.setFile( fn ); | 1759 | info.setFile( fn ); |
1762 | QString mess; | 1760 | QString mess; |
1763 | bool loadbup = true; | 1761 | bool loadbup = true; |
1764 | if ( info. exists() ) { | 1762 | if ( info. exists() ) { |
1765 | mess = i18n("Backup file from:\n%1\nLoading backup\nfile will delete\nyour current Data!\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 1763 | mess = i18n("Backup file from:\n%1\nLoading backup\nfile will delete\nyour current Data!\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
1766 | int result = QMessageBox::warning( this, "KO/Pi: Warning!", | 1764 | int result = QMessageBox::warning( this, "KO/Pi: Warning!", |
1767 | mess, | 1765 | mess, |
1768 | i18n("Load!"), i18n("Cancel"), 0, | 1766 | i18n("Load!"), i18n("Cancel"), 0, |
1769 | 0, 1 ); | 1767 | 0, 1 ); |
1770 | if ( result != 0 ) { | 1768 | if ( result != 0 ) { |
1771 | loadbup = false; | 1769 | loadbup = false; |
1772 | } | 1770 | } |
1773 | } else { | 1771 | } else { |
1774 | QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 1772 | QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
1775 | i18n("Backup file\ndoes not exist!\nNothing loaded!"), 0, 0, | 1773 | i18n("Backup file\ndoes not exist!\nNothing loaded!"), 0, 0, |
1776 | 0, 1 ); | 1774 | 0, 1 ); |
1777 | 1775 | ||
1778 | return; | 1776 | return; |
1779 | } | 1777 | } |
1780 | if ( loadbup ) { | 1778 | if ( loadbup ) { |
1781 | mView->openCalendar( fn ); | 1779 | mView->openCalendar( fn ); |
1782 | KOPrefs::instance()->mLastLoadFile = fn; | 1780 | KOPrefs::instance()->mLastLoadFile = fn; |
1783 | mess = i18n("KO/Pi:Loaded %1").arg(fn) ; | 1781 | mess = i18n("KO/Pi:Loaded %1").arg(fn) ; |
1784 | setCaption(mess); | 1782 | setCaption(mess); |
1785 | } | 1783 | } |
1786 | 1784 | ||
1787 | } | 1785 | } |
1788 | void MainWindow::quickImportIcal() | 1786 | void MainWindow::quickImportIcal() |
1789 | { | 1787 | { |
1790 | importFile( KOPrefs::instance()->mLastImportFile, false ); | 1788 | importFile( KOPrefs::instance()->mLastImportFile, false ); |
1791 | } | 1789 | } |
1792 | void MainWindow::importFile( QString fn, bool quick ) | 1790 | void MainWindow::importFile( QString fn, bool quick ) |
1793 | { | 1791 | { |
1794 | QFileInfo info; | 1792 | QFileInfo info; |
1795 | info.setFile( fn ); | 1793 | info.setFile( fn ); |
1796 | QString mess; | 1794 | QString mess; |
1797 | bool loadbup = true; | 1795 | bool loadbup = true; |
1798 | if ( !info. exists() ) { | 1796 | if ( !info. exists() ) { |
1799 | mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30)); | 1797 | mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30)); |
1800 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 1798 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
1801 | mess ); | 1799 | mess ); |
1802 | return; | 1800 | return; |
1803 | } | 1801 | } |
1804 | int result = 0; | 1802 | int result = 0; |
1805 | if ( !quick ) { | 1803 | if ( !quick ) { |
1806 | 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 )); | 1804 | 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 )); |
1807 | result = QMessageBox::warning( this, "KO/Pi: Warning!", | 1805 | result = QMessageBox::warning( this, "KO/Pi: Warning!", |
1808 | mess, | 1806 | mess, |
1809 | "Import", "Cancel", 0, | 1807 | "Import", "Cancel", 0, |
1810 | 0, 1 ); | 1808 | 0, 1 ); |
1811 | } | 1809 | } |
1812 | if ( result == 0 ) { | 1810 | if ( result == 0 ) { |
1813 | if ( mView->openCalendar( fn, true )) { | 1811 | if ( mView->openCalendar( fn, true )) { |
1814 | KOPrefs::instance()->mLastImportFile = fn; | 1812 | KOPrefs::instance()->mLastImportFile = fn; |
1815 | setCaption(i18n("Imported file successfully")); | 1813 | setCaption(i18n("Imported file successfully")); |
1816 | } else { | 1814 | } else { |
1817 | setCaption(i18n("Error importing file")); | 1815 | setCaption(i18n("Error importing file")); |
1818 | } | 1816 | } |
1819 | } | 1817 | } |
1820 | } | 1818 | } |
1821 | 1819 | ||
1822 | void MainWindow::importIcal() | 1820 | void MainWindow::importIcal() |
1823 | { | 1821 | { |
1824 | 1822 | ||
1825 | QString fn =KOPrefs::instance()->mLastImportFile; | 1823 | QString fn =KOPrefs::instance()->mLastImportFile; |
1826 | 1824 | ||
1827 | fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this ); | 1825 | fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this ); |
1828 | if ( fn == "" ) | 1826 | if ( fn == "" ) |
1829 | return; | 1827 | return; |
1830 | importFile( fn, true ); | 1828 | importFile( fn, true ); |
1831 | 1829 | ||
1832 | } | 1830 | } |
1833 | 1831 | ||
1834 | void MainWindow::exportVCalendar() | 1832 | void MainWindow::exportVCalendar() |
1835 | { | 1833 | { |
1836 | QString fn = KOPrefs::instance()->mLastVcalFile; | 1834 | QString fn = KOPrefs::instance()->mLastVcalFile; |
1837 | fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this ); | 1835 | fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this ); |
1838 | if ( fn == "" ) | 1836 | if ( fn == "" ) |
1839 | return; | 1837 | return; |
1840 | QFileInfo info; | 1838 | QFileInfo info; |
1841 | info.setFile( fn ); | 1839 | info.setFile( fn ); |
1842 | QString mes; | 1840 | QString mes; |
1843 | bool createbup = true; | 1841 | bool createbup = true; |
1844 | if ( info. exists() ) { | 1842 | if ( info. exists() ) { |
1845 | mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); | 1843 | mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); |
1846 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, | 1844 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, |
1847 | i18n("Overwrite!"), i18n("Cancel"), 0, | 1845 | i18n("Overwrite!"), i18n("Cancel"), 0, |
1848 | 0, 1 ); | 1846 | 0, 1 ); |
1849 | if ( result != 0 ) { | 1847 | if ( result != 0 ) { |
1850 | createbup = false; | 1848 | createbup = false; |
1851 | } | 1849 | } |
1852 | } | 1850 | } |
1853 | if ( createbup ) { | 1851 | if ( createbup ) { |
1854 | if ( mView->exportVCalendar( fn ) ) { | 1852 | if ( mView->exportVCalendar( fn ) ) { |
1855 | KOPrefs::instance()->mLastVcalFile = fn; | 1853 | KOPrefs::instance()->mLastVcalFile = fn; |
1856 | if ( fn.length() > 20 ) | 1854 | if ( fn.length() > 20 ) |
1857 | mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ; | 1855 | mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ; |
1858 | else | 1856 | else |
1859 | mes = i18n("KO/Pi:Exported to %1").arg(fn ); | 1857 | mes = i18n("KO/Pi:Exported to %1").arg(fn ); |
1860 | setCaption(mes); | 1858 | setCaption(mes); |
1861 | } | 1859 | } |
1862 | } | 1860 | } |
1863 | 1861 | ||
1864 | } | 1862 | } |
1865 | QString MainWindow::getPassword( ) | 1863 | QString MainWindow::getPassword( ) |
1866 | { | 1864 | { |
1867 | QString retfile = ""; | 1865 | QString retfile = ""; |
1868 | QDialog dia ( this, "input-dialog", true ); | 1866 | QDialog dia ( this, "input-dialog", true ); |
1869 | QLineEdit lab ( &dia ); | 1867 | QLineEdit lab ( &dia ); |
1870 | lab.setEchoMode( QLineEdit::Password ); | 1868 | lab.setEchoMode( QLineEdit::Password ); |
1871 | QVBoxLayout lay( &dia ); | 1869 | QVBoxLayout lay( &dia ); |
1872 | lay.setMargin(7); | 1870 | lay.setMargin(7); |
1873 | lay.setSpacing(7); | 1871 | lay.setSpacing(7); |
1874 | lay.addWidget( &lab); | 1872 | lay.addWidget( &lab); |
1875 | dia.setFixedSize( 230,50 ); | 1873 | dia.setFixedSize( 230,50 ); |
1876 | dia.setCaption( i18n("Enter password") ); | 1874 | dia.setCaption( i18n("Enter password") ); |
1877 | QPushButton pb ( "OK", &dia); | 1875 | QPushButton pb ( "OK", &dia); |
1878 | lay.addWidget( &pb ); | 1876 | lay.addWidget( &pb ); |
1879 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 1877 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
1880 | dia.show(); | 1878 | dia.show(); |
1881 | int res = dia.exec(); | 1879 | int res = dia.exec(); |
1882 | if ( res ) | 1880 | if ( res ) |
1883 | retfile = lab.text(); | 1881 | retfile = lab.text(); |
1884 | dia.hide(); | 1882 | dia.hide(); |
1885 | qApp->processEvents(); | 1883 | qApp->processEvents(); |
1886 | return retfile; | 1884 | return retfile; |
1887 | 1885 | ||
1888 | } | 1886 | } |
1889 | 1887 | ||
1890 | void MainWindow::enableQuick() | 1888 | void MainWindow::enableQuick() |
1891 | { | 1889 | { |
1892 | QString passWordPiSync = "bhdrvmk"; | 1890 | QString passWordPiSync = "bhdrvmk"; |
1893 | QString retfile = ""; | 1891 | QString retfile = ""; |
1894 | QDialog dia ( this, "input-dialog", true ); | 1892 | QDialog dia ( this, "input-dialog", true ); |
1895 | QLineEdit lab ( &dia ); | 1893 | QLineEdit lab ( &dia ); |
1896 | QVBoxLayout lay( &dia ); | 1894 | QVBoxLayout lay( &dia ); |
1897 | lab.setText( KOPrefs::instance()->mPassiveSyncPort ); | 1895 | lab.setText( KOPrefs::instance()->mPassiveSyncPort ); |
1898 | lay.setMargin(7); | 1896 | lay.setMargin(7); |
1899 | lay.setSpacing(7); | 1897 | lay.setSpacing(7); |
1900 | QLabel label ( i18n("Port number (Default: 9197)"), &dia ); | 1898 | QLabel label ( i18n("Port number (Default: 9197)"), &dia ); |
1901 | lay.addWidget( &label); | 1899 | lay.addWidget( &label); |
1902 | lay.addWidget( &lab); | 1900 | lay.addWidget( &lab); |
1903 | 1901 | ||
1904 | QLineEdit lepw ( &dia ); | 1902 | QLineEdit lepw ( &dia ); |
1905 | lepw.setText( "abc" ); | 1903 | lepw.setText( "abc" ); |
1906 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 1904 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
1907 | lay.addWidget( &label2); | 1905 | lay.addWidget( &label2); |
1908 | lay.addWidget( &lepw); | 1906 | lay.addWidget( &lepw); |
1909 | dia.setFixedSize( 230,80 ); | 1907 | dia.setFixedSize( 230,80 ); |
1910 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 1908 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
1911 | QPushButton pb ( "OK", &dia); | 1909 | QPushButton pb ( "OK", &dia); |
1912 | lay.addWidget( &pb ); | 1910 | lay.addWidget( &pb ); |
1913 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 1911 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
1914 | dia.show(); | 1912 | dia.show(); |
1915 | int res = dia.exec(); | 1913 | int res = dia.exec(); |
1916 | if ( res ) | 1914 | if ( res ) |
1917 | retfile = lab.text(); | 1915 | retfile = lab.text(); |
1918 | else | 1916 | else |
1919 | return; | 1917 | return; |
1920 | dia.hide(); | 1918 | dia.hide(); |
1921 | passWordPiSync = lepw.text(); | 1919 | passWordPiSync = lepw.text(); |
1922 | qApp->processEvents(); | 1920 | qApp->processEvents(); |
1923 | KOPrefs::instance()->mPassiveSyncPort = retfile; | 1921 | KOPrefs::instance()->mPassiveSyncPort = retfile; |
1924 | bool ok; | 1922 | bool ok; |
1925 | Q_UINT16 port = retfile.toUInt(&ok); | 1923 | Q_UINT16 port = retfile.toUInt(&ok); |
1926 | if ( ! ok ) { | 1924 | if ( ! ok ) { |
1927 | KMessageBox::information( this, i18n("No valid port")); | 1925 | KMessageBox::information( this, i18n("No valid port")); |
1928 | return; | 1926 | return; |
1929 | } | 1927 | } |
1930 | qDebug("port %d ", port); | 1928 | qDebug("port %d ", port); |
1931 | mServerSocket = new KServerSocket ( passWordPiSync, port ,1 ); | 1929 | mServerSocket = new KServerSocket ( passWordPiSync, port ,1 ); |
1932 | mServerSocket->setFileName( defaultFileName() ); | 1930 | mServerSocket->setFileName( defaultFileName() ); |
1933 | qDebug("connected "); | 1931 | qDebug("connected "); |
1934 | if ( !mServerSocket->ok() ) { | 1932 | if ( !mServerSocket->ok() ) { |
1935 | qWarning("Failed to bind to port %d", port); | 1933 | qWarning("Failed to bind to port %d", port); |
1936 | delete mServerSocket; | 1934 | delete mServerSocket; |
1937 | mServerSocket = 0; | 1935 | mServerSocket = 0; |
1938 | return; | 1936 | return; |
1939 | } | 1937 | } |
1940 | connect( mServerSocket, SIGNAL ( saveFile() ), this, SLOT ( save() ) ); | 1938 | connect( mServerSocket, SIGNAL ( saveFile() ), this, SLOT ( save() ) ); |
1941 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SLOT ( getFile( bool ) ) ); | 1939 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SLOT ( getFile( bool ) ) ); |
1942 | // connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) ); | 1940 | // connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) ); |
1943 | //connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) ); | 1941 | //connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) ); |
1944 | } | 1942 | } |
1945 | void MainWindow::sendFile(QSocket* socket) | 1943 | |
1946 | { | ||
1947 | setCaption( i18n("Received request for file") ); | ||
1948 | qDebug("MainWindow::sendFile(QSocket* s) "); | ||
1949 | if ( mSyncActionDialog ) | ||
1950 | delete mSyncActionDialog; | ||
1951 | mSyncActionDialog = new QDialog ( this, "input-dialog", true ); | ||
1952 | mSyncActionDialog->setCaption(i18n("KO/Pi - WARNING")); | ||
1953 | QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use\nthis application!\n"), mSyncActionDialog ); | ||
1954 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | ||
1955 | lay->addWidget( label); | ||
1956 | lay->setMargin(7); | ||
1957 | lay->setSpacing(7); | ||
1958 | mSyncActionDialog->setFixedSize( 200,100 ); | ||
1959 | mSyncActionDialog->show(); | ||
1960 | qDebug("saving ... "); | ||
1961 | save(); | ||
1962 | qApp->processEvents(); | ||
1963 | QString fileName = defaultFileName(); | ||
1964 | QFile file( fileName ); | ||
1965 | if (!file.open( IO_ReadOnly ) ) { | ||
1966 | setCaption( i18n("Error open file") ); | ||
1967 | delete mSyncActionDialog; | ||
1968 | mSyncActionDialog = 0; | ||
1969 | qDebug("error open cal file "); | ||
1970 | return ; | ||
1971 | |||
1972 | } | ||
1973 | setCaption( i18n("Sending file...") ); | ||
1974 | QTextStream ts( &file ); | ||
1975 | ts.setCodec( QTextCodec::codecForName("utf8") ); | ||
1976 | QTextStream os( socket ); | ||
1977 | os.setCodec( QTextCodec::codecForName("utf8") ); | ||
1978 | //os.setEncoding( QTextStream::UnicodeUTF8 ); | ||
1979 | while ( ! ts.atEnd() ) { | ||
1980 | os << ts.readLine() << "\n"; | ||
1981 | } | ||
1982 | //os << ts.read(); | ||
1983 | socket->close(); | ||
1984 | file.close(); | ||
1985 | setCaption( i18n("File sent. Waiting to get back synced file") ); | ||
1986 | qDebug("file sent "); | ||
1987 | } | ||
1988 | void MainWindow::getFile( bool success ) | 1944 | void MainWindow::getFile( bool success ) |
1989 | { | 1945 | { |
1990 | if ( ! success ) { | 1946 | if ( ! success ) { |
1991 | setCaption( i18n("Error receiving file. Nothing changed!") ); | 1947 | setCaption( i18n("Error receiving file. Nothing changed!") ); |
1992 | return; | 1948 | return; |
1993 | } | 1949 | } |
1994 | // pending adjust time for watchSavedFile() | 1950 | // pending adjust time for watchSavedFile() |
1995 | //mView->watchSavedFile(); | 1951 | //mView->watchSavedFile(); |
1996 | mView->openCalendar( defaultFileName() ); | 1952 | mView->openCalendar( defaultFileName() ); |
1997 | setCaption( i18n("Pi-Sync successful!") ); | 1953 | setCaption( i18n("Pi-Sync successful!") ); |
1998 | 1954 | ||
1999 | |||
2000 | #if 0 | ||
2001 | setCaption( i18n("Receiving synced file...") ); | ||
2002 | |||
2003 | piTime.start(); | ||
2004 | piSocket = socket; | ||
2005 | piFileString = ""; | ||
2006 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | ||
2007 | #endif | ||
2008 | |||
2009 | } | 1955 | } |
2010 | void MainWindow::readBackFileFromSocket() | ||
2011 | { | ||
2012 | qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | ||
2013 | while ( piSocket->canReadLine () ) { | ||
2014 | piTime.restart(); | ||
2015 | QString line = piSocket->readLine (); | ||
2016 | piFileString += line; | ||
2017 | qDebug("readline: %s ", line.latin1()); | ||
2018 | setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | ||
2019 | 1956 | ||
2020 | } | ||
2021 | if ( piTime.elapsed () < 3000 ) { | ||
2022 | // wait for more | ||
2023 | qDebug("waitformore "); | ||
2024 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | ||
2025 | return; | ||
2026 | } | ||
2027 | QString fileName = defaultFileName(); | ||
2028 | QFile file ( fileName ); | ||
2029 | if (!file.open( IO_WriteOnly ) ) { | ||
2030 | setCaption( i18n("Error open file for writing!") ); | ||
2031 | delete mSyncActionDialog; | ||
2032 | mSyncActionDialog = 0; | ||
2033 | qDebug("error open cal file "); | ||
2034 | piFileString = ""; | ||
2035 | return ; | ||
2036 | |||
2037 | } | ||
2038 | |||
2039 | mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | ||
2040 | QTextStream ts ( &file ); | ||
2041 | ts.setCodec( QTextCodec::codecForName("utf8") ); | ||
2042 | qDebug("finish "); | ||
2043 | setCaption( i18n("Writing file to disk...") ); | ||
2044 | ts << piFileString; | ||
2045 | setCaption( i18n("File received - reloading calendar...") ); | ||
2046 | piSocket->close(); | ||
2047 | file.close(); | ||
2048 | mView->watchSavedFile(); | ||
2049 | mView->openCalendar( defaultFileName() ); | ||
2050 | setCaption( i18n("Pi-Sync successful!") ); | ||
2051 | delete mSyncActionDialog; | ||
2052 | mSyncActionDialog = 0; | ||
2053 | piFileString = ""; | ||
2054 | 1957 | ||
2055 | |||
2056 | } | ||
2057 | void MainWindow::endConnect() | ||
2058 | { | ||
2059 | setCaption( i18n("No file received - syncing successful") ); | ||
2060 | delete mSyncActionDialog; | ||
2061 | mSyncActionDialog = 0; | ||
2062 | } | ||
2063 | void MainWindow::performQuick() | 1958 | void MainWindow::performQuick() |
2064 | { | 1959 | { |
2065 | 1960 | ||
2066 | setCaption( i18n("Please input connection settings") ); | 1961 | setCaption( i18n("Please input connection settings") ); |
2067 | QString retfile = ""; | 1962 | QString retfile = ""; |
2068 | QDialog dia ( this, "input-dialog", true ); | 1963 | QDialog dia ( this, "input-dialog", true ); |
2069 | QLineEdit lab ( &dia ); | 1964 | QLineEdit lab ( &dia ); |
2070 | QVBoxLayout lay( &dia ); | 1965 | QVBoxLayout lay( &dia ); |
2071 | QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia ); | 1966 | QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia ); |
2072 | lay.addWidget( &label); | 1967 | lay.addWidget( &label); |
2073 | lab.setText( KOPrefs::instance()->mActiveSyncIP ); | 1968 | lab.setText( KOPrefs::instance()->mActiveSyncIP ); |
2074 | lay.setMargin(7); | 1969 | lay.setMargin(7); |
2075 | lay.setSpacing(7); | 1970 | lay.setSpacing(7); |
2076 | lay.addWidget( &lab); | 1971 | lay.addWidget( &lab); |
2077 | QLabel label2 ( i18n("Port number (Default: 9197)"), &dia ); | 1972 | QLabel label2 ( i18n("Port number (Default: 9197)"), &dia ); |
2078 | lay.addWidget( &label2); | 1973 | lay.addWidget( &label2); |
2079 | QLineEdit lab2 ( &dia ); | 1974 | QLineEdit lab2 ( &dia ); |
2080 | lab2.setText( KOPrefs::instance()->mActiveSyncPort ); | 1975 | lab2.setText( KOPrefs::instance()->mActiveSyncPort ); |
2081 | lay.addWidget( &lab2); | 1976 | lay.addWidget( &lab2); |
2082 | 1977 | ||
2083 | QLineEdit lepw ( &dia ); | 1978 | QLineEdit lepw ( &dia ); |
2084 | lepw.setText( mPassWordPiSync ); | 1979 | lepw.setText( mPassWordPiSync ); |
2085 | QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia ); | 1980 | QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia ); |
2086 | lay.addWidget( &label3); | 1981 | lay.addWidget( &label3); |
2087 | lay.addWidget( &lepw); | 1982 | lay.addWidget( &lepw); |
2088 | 1983 | ||
2089 | dia.setFixedSize( 230,200 ); | 1984 | dia.setFixedSize( 230,200 ); |
2090 | dia.setCaption( i18n("Enter port for Pi-Sync ") ); | 1985 | dia.setCaption( i18n("Enter port for Pi-Sync ") ); |
2091 | QPushButton pb ( "OK", &dia); | 1986 | QPushButton pb ( "OK", &dia); |
2092 | lay.addWidget( &pb ); | 1987 | lay.addWidget( &pb ); |
2093 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 1988 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
2094 | dia.show(); | 1989 | dia.show(); |
2095 | int res = dia.exec(); | 1990 | int res = dia.exec(); |
2096 | if ( !res ) { | 1991 | if ( !res ) { |
2097 | setCaption( i18n("Syncing cancelled!") ); | 1992 | setCaption( i18n("Syncing cancelled!") ); |
2098 | return; | 1993 | return; |
2099 | } | 1994 | } |
2100 | mPassWordPiSync = lepw.text(); | 1995 | mPassWordPiSync = lepw.text(); |
2101 | dia.hide(); | 1996 | dia.hide(); |
2102 | KOPrefs::instance()->mActiveSyncPort = lab2.text(); | 1997 | KOPrefs::instance()->mActiveSyncPort = lab2.text(); |
2103 | KOPrefs::instance()->mActiveSyncIP = lab.text(); | 1998 | KOPrefs::instance()->mActiveSyncIP = lab.text(); |
2104 | qApp->processEvents(); | 1999 | qApp->processEvents(); |
2105 | performQuickQuick(); | 2000 | performQuickQuick(); |
2106 | } | 2001 | } |
2107 | 2002 | ||
2108 | void MainWindow::performQuickQuick() | 2003 | void MainWindow::performQuickQuick() |
2109 | { | 2004 | { |
2110 | // setCaption( i18n("") ); | 2005 | // setCaption( i18n("") ); |
2111 | 2006 | ||
2112 | bool ok; | 2007 | bool ok; |
2113 | Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); | 2008 | Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); |
2114 | if ( ! ok ) { | 2009 | if ( ! ok ) { |
2115 | setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 2010 | setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
2116 | return; | 2011 | return; |
2117 | } | 2012 | } |
2118 | mCommandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this ); | 2013 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this ); |
2119 | connect( mCommandSocket, SIGNAL(commandFinished( bool )), this, SLOT(deleteCommandSocket(bool)) ); | 2014 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocket(KCommandSocket*,bool)) ); |
2120 | setCaption( i18n("Sending request for remote file ...") ); | 2015 | setCaption( i18n("Sending request for remote file ...") ); |
2121 | QString fileName; | 2016 | QString fileName; |
2122 | #ifdef _WIN32_ | 2017 | #ifdef _WIN32_ |
2123 | fileName = defaultFileName() +"sync"; | 2018 | fileName = defaultFileName() +"sync"; |
2124 | #else | 2019 | #else |
2125 | fileName = "/tmp/kopitempfile.ics"; | 2020 | fileName = "/tmp/kopitempfile.ics"; |
2126 | #endif | 2021 | #endif |
2127 | mCommandSocket->readFile( fileName ); | 2022 | commandSocket->readFile( fileName ); |
2128 | } | 2023 | } |
2129 | void MainWindow::deleteCommandSocket( bool success) | 2024 | void MainWindow::deleteCommandSocket(KCommandSocket*s, bool success) |
2130 | { | 2025 | { |
2131 | if ( ! success ) { | 2026 | if ( ! success ) { |
2132 | setCaption( i18n("ERROR:Receiving remote file failed.") ); | 2027 | setCaption( i18n("ERROR:Receiving remote file failed.") ); |
2028 | delete s; | ||
2133 | // pending : send stop | 2029 | // pending : send stop |
2134 | return; | 2030 | return; |
2135 | 2031 | ||
2136 | } | 2032 | } |
2137 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 2033 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
2138 | delete mCommandSocket; | 2034 | qDebug("MainWindow::deleteCommandSocket "); |
2035 | delete s; | ||
2139 | } | 2036 | } |
2140 | void MainWindow::deleteCommandSocketFinish() | 2037 | void MainWindow::deleteCommandSocketFinish(KCommandSocket* s, bool success ) |
2141 | { | 2038 | { |
2142 | if ( ! mCommandSocketFinish) | 2039 | if ( ! success ) { |
2143 | return; | 2040 | setCaption( i18n("ERROR:Writing back file failed.") ); |
2144 | // KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() ")); | 2041 | } else { |
2145 | qDebug("MainWindow::deletemCommandSocketFinish() "); | 2042 | qDebug("Syncing succesful! "); |
2146 | delete mCommandSocketFinish; | 2043 | setCaption( i18n("Pi-Sync succesful!") ); |
2147 | mCommandSocketFinish = 0; | 2044 | } |
2045 | qDebug("MainWindow::deleteCommandSocketFinish "); | ||
2046 | delete s; | ||
2148 | } | 2047 | } |
2149 | void MainWindow::readFileFromSocket() | 2048 | void MainWindow::readFileFromSocket() |
2150 | { | 2049 | { |
2151 | // mTimerCommandSocket->stop(); | 2050 | // mTimerCommandSocket->stop(); |
2152 | setCaption( i18n("Receiving remote file ...") ); | 2051 | setCaption( i18n("Receiving remote file ...") ); |
2153 | qDebug("MainWindow::readFileFromSocket() "); | 2052 | qDebug("MainWindow::readFileFromSocket() "); |
2154 | QString fileName; | 2053 | QString fileName; |
2155 | #ifdef _WIN32_ | 2054 | #ifdef _WIN32_ |
2156 | fileName = defaultFileName() +"sync"; | 2055 | fileName = defaultFileName() +"sync"; |
2157 | #else | 2056 | #else |
2158 | fileName = "/tmp/kopitempfile.ics"; | 2057 | fileName = "/tmp/kopitempfile.ics"; |
2159 | #endif | 2058 | #endif |
2160 | 2059 | ||
2161 | setCaption( i18n("Remote file saved to temp file.") ); | 2060 | setCaption( i18n("Remote file saved to temp file.") ); |
2162 | //mCommandSocket = 0; | 2061 | //mCommandSocket = 0; |
2163 | mCurrentSyncProfile = 2 ; // last file | 2062 | mCurrentSyncProfile = 2 ; // last file |
2164 | mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); | 2063 | mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); |
2165 | mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); | 2064 | mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); |
2166 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 2065 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
2167 | KSyncProfile* temp = new KSyncProfile (); | 2066 | KSyncProfile* temp = new KSyncProfile (); |
2168 | temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 2067 | temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
2169 | temp->readConfig(&config); | 2068 | temp->readConfig(&config); |
2170 | KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | 2069 | KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); |
2171 | KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); | 2070 | KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); |
2172 | KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); | 2071 | KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); |
2173 | KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); | 2072 | KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); |
2174 | KOPrefs::instance()->mWriteBackInFuture = 0; | 2073 | KOPrefs::instance()->mWriteBackInFuture = 0; |
2175 | if ( temp->getWriteBackFuture() ) | 2074 | if ( temp->getWriteBackFuture() ) |
2176 | KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 2075 | KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
2177 | KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); | 2076 | KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); |
2178 | delete temp; | 2077 | delete temp; |
2179 | setCaption( i18n("Remote file saved to temp file.") ); | 2078 | setCaption( i18n("Remote file saved to temp file.") ); |
2180 | if ( ! syncWithFile( fileName , true ) ) { | 2079 | if ( ! syncWithFile( fileName , true ) ) { |
2181 | setCaption( i18n("Syncing failed.") ); | 2080 | setCaption( i18n("Syncing failed.") ); |
2182 | qDebug("Syncing failed "); | 2081 | qDebug("Syncing failed "); |
2183 | return; | 2082 | return; |
2184 | } | 2083 | } |
2185 | 2084 | ||
2186 | if ( !mCommandSocketFinish ) { | 2085 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, KOPrefs::instance()->mActiveSyncPort.toUInt(), KOPrefs::instance()->mActiveSyncIP, this ); |
2187 | mCommandSocketFinish = new QSocket( this ); | 2086 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocketFinish(KCommandSocket*,bool)) ); |
2188 | connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) ); | 2087 | if ( KOPrefs::instance()->mWriteBackFile ) |
2189 | } | 2088 | commandSocket->writeFile( fileName ); |
2190 | mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); | 2089 | else |
2191 | 2090 | commandSocket->sendStop(); | |
2192 | QString host = KOPrefs::instance()->mActiveSyncIP; | ||
2193 | QFile file2( fileName ); | ||
2194 | if (!file2.open( IO_ReadOnly ) ) { | ||
2195 | setCaption( i18n("Error: Cannot open temp file for read.") ); | ||
2196 | qDebug("error open cal file "); | ||
2197 | return ; | ||
2198 | |||
2199 | } | ||
2200 | QTextStream ts2( &file2 ); | ||
2201 | ts2.setCodec( QTextCodec::codecForName("utf8") ); | ||
2202 | QTextStream os2( mCommandSocketFinish ); | ||
2203 | os2.setCodec( QTextCodec::codecForName("utf8") ); | ||
2204 | //os.setEncoding( QTextStream::UnicodeUTF8 ); | ||
2205 | if ( KOPrefs::instance()->mWriteBackFile ) { | ||
2206 | setCaption( i18n("Sending back synced file...") ); | ||
2207 | os2 << "PUT " << mPassWordPiSync << "\r\n";; | ||
2208 | while ( ! ts2.atEnd() ) { | ||
2209 | os2 << ts2.readLine() << "\n"; | ||
2210 | } | ||
2211 | } else { | ||
2212 | os2 << "STOP\r\n"; | ||
2213 | } | ||
2214 | mCommandSocketFinish->close(); | ||
2215 | if ( mCommandSocketFinish->state() == QSocket::Idle ) | ||
2216 | QTimer::singleShot( 10, this , SLOT ( deleteCommandSocketFinish())); | ||
2217 | file2.close(); | ||
2218 | qDebug("Syncing succesful! "); | ||
2219 | setCaption( i18n("Pi-Sync succesful!") ); | ||
2220 | |||
2221 | // KMessageBox::information( 0, i18n(" Pi-Sync succesful! ")); | ||
2222 | |||
2223 | } | 2091 | } |
2224 | 2092 | ||
2225 | void MainWindow::syncLocalFile() | 2093 | void MainWindow::syncLocalFile() |
2226 | { | 2094 | { |
2227 | 2095 | ||
2228 | QString fn =KOPrefs::instance()->mLastSyncedLocalFile; | 2096 | QString fn =KOPrefs::instance()->mLastSyncedLocalFile; |
2229 | 2097 | ||
2230 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); | 2098 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); |
2231 | if ( fn == "" ) | 2099 | if ( fn == "" ) |
2232 | return; | 2100 | return; |
2233 | //mView->setSyncDevice("local-file" ); | 2101 | //mView->setSyncDevice("local-file" ); |
2234 | if ( syncWithFile( fn, false ) ) { | 2102 | if ( syncWithFile( fn, false ) ) { |
2235 | // Event* e = mView->getLastSyncEvent(); | 2103 | // Event* e = mView->getLastSyncEvent(); |
2236 | // e->setReadOnly( false ); | 2104 | // e->setReadOnly( false ); |
2237 | // e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); | 2105 | // e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); |
2238 | // e->setReadOnly( true ); | 2106 | // e->setReadOnly( true ); |
2239 | } | 2107 | } |
2240 | 2108 | ||
2241 | } | 2109 | } |
2242 | 2110 | ||
2243 | bool MainWindow::syncWithFile( QString fn , bool quick ) | 2111 | bool MainWindow::syncWithFile( QString fn , bool quick ) |
2244 | { | 2112 | { |
2245 | bool ret = false; | 2113 | bool ret = false; |
2246 | QFileInfo info; | 2114 | QFileInfo info; |
2247 | info.setFile( fn ); | 2115 | info.setFile( fn ); |
2248 | QString mess; | 2116 | QString mess; |
2249 | bool loadbup = true; | 2117 | bool loadbup = true; |
2250 | if ( !info. exists() ) { | 2118 | if ( !info. exists() ) { |
2251 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 2119 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
2252 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 2120 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
2253 | mess ); | 2121 | mess ); |
2254 | return ret; | 2122 | return ret; |
2255 | } | 2123 | } |
2256 | int result = 0; | 2124 | int result = 0; |
2257 | if ( !quick ) { | 2125 | if ( !quick ) { |
2258 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 2126 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
2259 | result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 2127 | result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
2260 | mess, | 2128 | mess, |
2261 | i18n("Sync"), i18n("Cancel"), 0, | 2129 | i18n("Sync"), i18n("Cancel"), 0, |
2262 | 0, 1 ); | 2130 | 0, 1 ); |
2263 | if ( result ) | 2131 | if ( result ) |
2264 | return false; | 2132 | return false; |
2265 | } | 2133 | } |
2266 | if ( KOPrefs::instance()->mAskForPreferences ) | 2134 | if ( KOPrefs::instance()->mAskForPreferences ) |
2267 | mView->edit_sync_options(); | 2135 | mView->edit_sync_options(); |
2268 | if ( result == 0 ) { | 2136 | if ( result == 0 ) { |
2269 | //qDebug("Now sycing ... "); | 2137 | //qDebug("Now sycing ... "); |
2270 | if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) ) | 2138 | if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) ) |
2271 | setCaption( i18n("Synchronization successful") ); | 2139 | setCaption( i18n("Synchronization successful") ); |
2272 | else | 2140 | else |
2273 | setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | 2141 | setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); |
2274 | if ( ! quick ) | 2142 | if ( ! quick ) |
2275 | KOPrefs::instance()->mLastSyncedLocalFile = fn; | 2143 | KOPrefs::instance()->mLastSyncedLocalFile = fn; |
2276 | slotModifiedChanged( true ); | 2144 | slotModifiedChanged( true ); |
2277 | } | 2145 | } |
2278 | return ret; | 2146 | return ret; |
2279 | } | 2147 | } |
2280 | void MainWindow::quickSyncLocalFile() | 2148 | void MainWindow::quickSyncLocalFile() |
2281 | { | 2149 | { |
2282 | //mView->setSyncDevice("local-file" ); | 2150 | //mView->setSyncDevice("local-file" ); |
2283 | //qDebug("quickSyncLocalFile() "); | 2151 | //qDebug("quickSyncLocalFile() "); |
2284 | if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) { | 2152 | if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) { |
2285 | // Event* e = mView->getLastSyncEvent(); | 2153 | // Event* e = mView->getLastSyncEvent(); |
2286 | // e->setReadOnly( false ); | 2154 | // e->setReadOnly( false ); |
2287 | // e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); | 2155 | // e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); |
2288 | // e->setReadOnly( true ); | 2156 | // e->setReadOnly( true ); |
2289 | 2157 | ||
2290 | } | 2158 | } |
2291 | } | 2159 | } |
2292 | 2160 | ||
2293 | void MainWindow::confSync() | 2161 | void MainWindow::confSync() |
2294 | { | 2162 | { |
2295 | mView->confSync(); | 2163 | mView->confSync(); |
2296 | fillSyncMenu(); | 2164 | fillSyncMenu(); |
2297 | } | 2165 | } |
2298 | void MainWindow::syncRemote( KSyncProfile* prof, bool ask) | 2166 | void MainWindow::syncRemote( KSyncProfile* prof, bool ask) |
2299 | { | 2167 | { |
2300 | QString question; | 2168 | QString question; |
2301 | if ( ask ) { | 2169 | if ( ask ) { |
2302 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 2170 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
2303 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), | 2171 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), |
2304 | question, | 2172 | question, |
2305 | i18n("Yes"), i18n("No"), | 2173 | i18n("Yes"), i18n("No"), |
2306 | 0, 0 ) != 0 ) | 2174 | 0, 0 ) != 0 ) |
2307 | return; | 2175 | return; |
2308 | } | 2176 | } |
2309 | QString command = prof->getPreSyncCommand(); | 2177 | QString command = prof->getPreSyncCommand(); |
2310 | int fi; | 2178 | int fi; |
2311 | if ( (fi = command.find("$PWD$")) > 0 ) { | 2179 | if ( (fi = command.find("$PWD$")) > 0 ) { |
2312 | QString pwd = getPassword(); | 2180 | QString pwd = getPassword(); |
2313 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | 2181 | command = command.left( fi )+ pwd + command.mid( fi+5 ); |
2314 | 2182 | ||
2315 | } | 2183 | } |
2316 | int maxlen = 30; | 2184 | int maxlen = 30; |
2317 | if ( QApplication::desktop()->width() > 320 ) | 2185 | if ( QApplication::desktop()->width() > 320 ) |
2318 | maxlen += 25; | 2186 | maxlen += 25; |
2319 | setCaption ( i18n( "Copy remote file to local machine..." ) ); | 2187 | setCaption ( i18n( "Copy remote file to local machine..." ) ); |
2320 | int fileSize = 0; | 2188 | int fileSize = 0; |
2321 | int result = system ( command ); | 2189 | int result = system ( command ); |
2322 | // 0 : okay | 2190 | // 0 : okay |
2323 | // 256: no such file or dir | 2191 | // 256: no such file or dir |
2324 | // | 2192 | // |
2325 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); | 2193 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); |
2326 | if ( result != 0 ) { | 2194 | if ( result != 0 ) { |
2327 | int len = maxlen; | 2195 | int len = maxlen; |
2328 | while ( len < command.length() ) { | 2196 | while ( len < command.length() ) { |
2329 | command.insert( len , "\n" ); | 2197 | command.insert( len , "\n" ); |
2330 | len += maxlen +2; | 2198 | len += maxlen +2; |
2331 | } | 2199 | } |
2332 | 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) ; | 2200 | 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) ; |
2333 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), | 2201 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), |
2334 | question, | 2202 | question, |
2335 | i18n("Okay!")) ; | 2203 | i18n("Okay!")) ; |
2336 | setCaption ("KO/Pi"); | 2204 | setCaption ("KO/Pi"); |
2337 | return; | 2205 | return; |
2338 | } | 2206 | } |
2339 | setCaption ( i18n( "Copying succeed." ) ); | 2207 | setCaption ( i18n( "Copying succeed." ) ); |
2340 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 2208 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
2341 | if ( syncWithFile( prof->getLocalTempFile(), true ) ) { | 2209 | if ( syncWithFile( prof->getLocalTempFile(), true ) ) { |
2342 | // Event* e = mView->getLastSyncEvent(); | 2210 | // Event* e = mView->getLastSyncEvent(); |
2343 | // e->setReadOnly( false ); | 2211 | // e->setReadOnly( false ); |
2344 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 2212 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
2345 | // e->setReadOnly( true ); | 2213 | // e->setReadOnly( true ); |
2346 | if ( KOPrefs::instance()->mWriteBackFile ) { | 2214 | if ( KOPrefs::instance()->mWriteBackFile ) { |
2347 | command = prof->getPostSyncCommand(); | 2215 | command = prof->getPostSyncCommand(); |
2348 | int fi; | 2216 | int fi; |
2349 | if ( (fi = command.find("$PWD$")) > 0 ) { | 2217 | if ( (fi = command.find("$PWD$")) > 0 ) { |
2350 | QString pwd = getPassword(); | 2218 | QString pwd = getPassword(); |
2351 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | 2219 | command = command.left( fi )+ pwd + command.mid( fi+5 ); |
2352 | 2220 | ||
2353 | } | 2221 | } |
2354 | setCaption ( i18n( "Writing back file ..." ) ); | 2222 | setCaption ( i18n( "Writing back file ..." ) ); |
2355 | result = system ( command ); | 2223 | result = system ( command ); |
2356 | qDebug("KO: Writing back file result: %d ", result); | 2224 | qDebug("KO: Writing back file result: %d ", result); |
2357 | if ( result != 0 ) { | 2225 | if ( result != 0 ) { |
2358 | setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 2226 | setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
2359 | return; | 2227 | return; |
2360 | } else { | 2228 | } else { |
2361 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 2229 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
2362 | } | 2230 | } |
2363 | } | 2231 | } |
2364 | } | 2232 | } |
2365 | return; | 2233 | return; |
2366 | } | 2234 | } |
2367 | void MainWindow::syncSSH() | 2235 | void MainWindow::syncSSH() |
2368 | { | 2236 | { |
2369 | // not used anymore | 2237 | // not used anymore |
2370 | QTime timer; | 2238 | QTime timer; |
2371 | timer.start(); | 2239 | timer.start(); |
2372 | //qDebug("MainWindow::syncssh() "); | 2240 | //qDebug("MainWindow::syncssh() "); |
2373 | KOPrefs *p = KOPrefs::instance(); | 2241 | KOPrefs *p = KOPrefs::instance(); |
2374 | QString localFile = p->mLocalTempFile; | 2242 | QString localFile = p->mLocalTempFile; |
2375 | QString remoteIP = p->mRemoteIP; | 2243 | QString remoteIP = p->mRemoteIP; |
2376 | QString remoteUser = p->mRemoteUser; | 2244 | QString remoteUser = p->mRemoteUser; |
2377 | QString remoteFile = p->mRemoteFile; | 2245 | QString remoteFile = p->mRemoteFile; |
2378 | if ( p->mUsePassWd && p->mRemotePassWd.length() > 0 ) | 2246 | if ( p->mUsePassWd && p->mRemotePassWd.length() > 0 ) |
2379 | remoteUser += ":" + p->mRemotePassWd; | 2247 | remoteUser += ":" + p->mRemotePassWd; |
2380 | 2248 | ||
2381 | QString question = i18n("Do you really want\nto remote sync?\n \n") + | 2249 | QString question = i18n("Do you really want\nto remote sync?\n \n") + |
2382 | i18n("IP: " ) +remoteIP +"\n" + | 2250 | i18n("IP: " ) +remoteIP +"\n" + |
2383 | i18n("User: " ) + remoteUser +"\n" ; | 2251 | i18n("User: " ) + remoteUser +"\n" ; |
2384 | int maxlen = 30; | 2252 | int maxlen = 30; |
2385 | if ( QApplication::desktop()->width() > 320 ) | 2253 | if ( QApplication::desktop()->width() > 320 ) |
2386 | maxlen += 25; | 2254 | maxlen += 25; |
2387 | if ( remoteFile.length() > maxlen ) | 2255 | if ( remoteFile.length() > maxlen ) |
2388 | question += i18n("Remote file:\n..." ) + remoteFile.right(maxlen) +"\n"; | 2256 | question += i18n("Remote file:\n..." ) + remoteFile.right(maxlen) +"\n"; |
2389 | else | 2257 | else |
2390 | question += i18n("Remote file:\n " ) + remoteFile +"\n"; | 2258 | question += i18n("Remote file:\n " ) + remoteFile +"\n"; |
2391 | if ( localFile.length() > maxlen ) | 2259 | if ( localFile.length() > maxlen ) |
2392 | question += i18n("Local temp file:\n..." ) + localFile.right(maxlen) +"\n"; | 2260 | question += i18n("Local temp file:\n..." ) + localFile.right(maxlen) +"\n"; |
2393 | else | 2261 | else |
2394 | question += i18n("Local temp file:\n " ) + localFile +"\n"; | 2262 | question += i18n("Local temp file:\n " ) + localFile +"\n"; |
2395 | 2263 | ||
2396 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), | 2264 | if ( QMessageBox::information( this, i18n("KO/Pi Sync"), |
2397 | question, | 2265 | question, |
2398 | i18n("Yes"), i18n("No"), | 2266 | i18n("Yes"), i18n("No"), |
2399 | 0, 0 ) != 0 ) | 2267 | 0, 0 ) != 0 ) |
2400 | return; | 2268 | return; |
2401 | // if ( !p->mUsePassWd ) { | 2269 | // if ( !p->mUsePassWd ) { |
2402 | // QString pass = getPassword(); | 2270 | // QString pass = getPassword(); |
2403 | // if ( pass.length() > 0 ) | 2271 | // if ( pass.length() > 0 ) |
2404 | // remoteUser += ":" + pass; | 2272 | // remoteUser += ":" + pass; |
2405 | // } | 2273 | // } |
2406 | QString command = "scp " + remoteUser + "@" + remoteIP +":" + remoteFile +" " +localFile; | 2274 | QString command = "scp " + remoteUser + "@" + remoteIP +":" + remoteFile +" " +localFile; |
2407 | setCaption ( i18n( "Copy remote file to local machine..." ) ); | 2275 | setCaption ( i18n( "Copy remote file to local machine..." ) ); |
2408 | int fileSize = 0; | 2276 | int fileSize = 0; |
2409 | int result = system ( command ); | 2277 | int result = system ( command ); |
2410 | // 0 : okay | 2278 | // 0 : okay |
2411 | // 256: no such file or dir | 2279 | // 256: no such file or dir |
2412 | // | 2280 | // |
2413 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); | 2281 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); |
2414 | if ( result != 0 ) { | 2282 | if ( result != 0 ) { |
2415 | int len = maxlen; | 2283 | int len = maxlen; |
2416 | while ( len < command.length() ) { | 2284 | while ( len < command.length() ) { |
2417 | command.insert( len , "\n" ); | 2285 | command.insert( len , "\n" ); |
2418 | len += maxlen +2; | 2286 | len += maxlen +2; |
2419 | } | 2287 | } |
2420 | 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) ; | 2288 | 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) ; |
2421 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), | 2289 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), |
2422 | question, | 2290 | question, |
2423 | i18n("Okay!")) ; | 2291 | i18n("Okay!")) ; |
2424 | setCaption ("KO/Pi"); | 2292 | setCaption ("KO/Pi"); |
2425 | return; | 2293 | return; |
2426 | } | 2294 | } |
2427 | 2295 | ||
2428 | 2296 | ||
2429 | setCaption ( i18n( "Copying succeed." ) ); | 2297 | setCaption ( i18n( "Copying succeed." ) ); |
2430 | //mView->setSyncDevice("ssh-scp" ); | 2298 | //mView->setSyncDevice("ssh-scp" ); |
2431 | if ( syncWithFile(localFile , true ) ) { | 2299 | if ( syncWithFile(localFile , true ) ) { |
2432 | // Event* e = mView->getLastSyncEvent(); | 2300 | // Event* e = mView->getLastSyncEvent(); |
2433 | // e->setReadOnly( false ); | 2301 | // e->setReadOnly( false ); |
2434 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 2302 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
2435 | // e->setReadOnly( true ); | 2303 | // e->setReadOnly( true ); |
2436 | if ( KOPrefs::instance()->mWriteBackFile ) { | 2304 | if ( KOPrefs::instance()->mWriteBackFile ) { |
2437 | command = "scp " + localFile +" " +remoteUser + "@" + remoteIP +":" + remoteFile ; | 2305 | command = "scp " + localFile +" " +remoteUser + "@" + remoteIP +":" + remoteFile ; |
2438 | setCaption ( i18n( "Writing back file ..." ) ); | 2306 | setCaption ( i18n( "Writing back file ..." ) ); |
2439 | result = system ( command ); | 2307 | result = system ( command ); |
2440 | if ( result != 0 ) { | 2308 | if ( result != 0 ) { |
2441 | int len = maxlen; | 2309 | int len = maxlen; |
2442 | while ( len < command.length() ) { | 2310 | while ( len < command.length() ) { |
2443 | command.insert( len , "\n" ); | 2311 | command.insert( len , "\n" ); |
2444 | len += maxlen +2; | 2312 | len += maxlen +2; |
2445 | } | 2313 | } |
2446 | 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) ; | 2314 | 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) ; |
2447 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), | 2315 | QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), |
2448 | question, | 2316 | question, |
2449 | i18n("Okay!")) ; | 2317 | i18n("Okay!")) ; |
2450 | setCaption ("KO/Pi"); | 2318 | setCaption ("KO/Pi"); |
2451 | return; | 2319 | return; |
2452 | } else { | 2320 | } else { |
2453 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 2321 | setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
2454 | } | 2322 | } |
2455 | } | 2323 | } |
2456 | } | 2324 | } |
2457 | return; | 2325 | return; |
2458 | #if 0 | 2326 | #if 0 |
2459 | system ("scp zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics /home/polo/Applications/korganizer/z_sync.ics"); | 2327 | system ("scp zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics /home/polo/Applications/korganizer/z_sync.ics"); |
2460 | while ( timer.elapsed() < 5000 ) | 2328 | while ( timer.elapsed() < 5000 ) |
2461 | qApp->processEvents(); | 2329 | qApp->processEvents(); |
2462 | 2330 | ||
2463 | qDebug("MainWindow::merging) "); | 2331 | qDebug("MainWindow::merging) "); |
2464 | mView->syncCalendar( "/home/polo/Applications/korganizer/z_sync.ics", 0 ); | 2332 | mView->syncCalendar( "/home/polo/Applications/korganizer/z_sync.ics", 0 ); |
2465 | while ( mBlockSaveFlag ) | 2333 | while ( mBlockSaveFlag ) |
2466 | qApp->processEvents(); | 2334 | qApp->processEvents(); |
2467 | save(); | 2335 | save(); |
2468 | system ("scp /home/polo/Applications/korganizer/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics"); | 2336 | system ("scp /home/polo/Applications/korganizer/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics"); |
2469 | #endif | 2337 | #endif |
2470 | 2338 | ||
2471 | } | 2339 | } |
2472 | 2340 | ||
2473 | 2341 | ||
2474 | void MainWindow::syncSharp() | 2342 | void MainWindow::syncSharp() |
2475 | { | 2343 | { |
2476 | if ( mCalendarModifiedFlag ) | 2344 | if ( mCalendarModifiedFlag ) |
2477 | save(); | 2345 | save(); |
2478 | mView->syncSharp(); | 2346 | mView->syncSharp(); |
2479 | slotModifiedChanged( true ); | 2347 | slotModifiedChanged( true ); |
2480 | 2348 | ||
2481 | } | 2349 | } |
2482 | void MainWindow::syncPhone() | 2350 | void MainWindow::syncPhone() |
2483 | { | 2351 | { |
2484 | if ( mCalendarModifiedFlag ) | 2352 | if ( mCalendarModifiedFlag ) |
2485 | save(); | 2353 | save(); |
2486 | mView->syncPhone(); | 2354 | mView->syncPhone(); |
2487 | slotModifiedChanged( true ); | 2355 | slotModifiedChanged( true ); |
2488 | 2356 | ||
2489 | } | 2357 | } |
2490 | 2358 | ||
2491 | void MainWindow::printSel( ) | 2359 | void MainWindow::printSel( ) |
2492 | { | 2360 | { |
2493 | mView->viewManager()->agendaView()->agenda()->printSelection(); | 2361 | mView->viewManager()->agendaView()->agenda()->printSelection(); |
2494 | } | 2362 | } |
2495 | 2363 | ||
2496 | void MainWindow::printCal() | 2364 | void MainWindow::printCal() |
2497 | { | 2365 | { |
2498 | mView->print();//mCp->showDialog(); | 2366 | mView->print();//mCp->showDialog(); |
2499 | } | 2367 | } |
2500 | 2368 | ||
2501 | 2369 | ||
2502 | 2370 | ||
2503 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 2371 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
2504 | { | 2372 | { |
2505 | mPassWord = pw; | 2373 | mPassWord = pw; |
2506 | mSocket = 0; | 2374 | mSocket = 0; |
2507 | mSyncActionDialog = 0; | 2375 | mSyncActionDialog = 0; |
2508 | }; | 2376 | }; |
2509 | 2377 | ||
2510 | void KServerSocket::newConnection ( int socket ) | 2378 | void KServerSocket::newConnection ( int socket ) |
2511 | { | 2379 | { |
2512 | qDebug("KServerSocket:New connection %d ", socket); | 2380 | qDebug("KServerSocket:New connection %d ", socket); |
2513 | if ( mSocket ) { | 2381 | if ( mSocket ) { |
2514 | qDebug("KServerSocket::newConnection Socket deleted! "); | 2382 | qDebug("KServerSocket::newConnection Socket deleted! "); |
2515 | delete mSocket; | 2383 | delete mSocket; |
2516 | mSocket = 0; | 2384 | mSocket = 0; |
2517 | } | 2385 | } |
2518 | mSocket = new QSocket( this ); | 2386 | mSocket = new QSocket( this ); |
2519 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 2387 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
2520 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 2388 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
2521 | mSocket->setSocket( socket ); | 2389 | mSocket->setSocket( socket ); |
2522 | } | 2390 | } |
2523 | 2391 | ||
2524 | void KServerSocket::discardClient() | 2392 | void KServerSocket::discardClient() |
2525 | { | 2393 | { |
2526 | qDebug(" KServerSocket::discardClient()"); | 2394 | qDebug(" KServerSocket::discardClient()"); |
2527 | if ( mSocket ) { | 2395 | if ( mSocket ) { |
2528 | qDebug("delete "); | 2396 | qDebug("delete "); |
2529 | delete mSocket; | 2397 | delete mSocket; |
2530 | mSocket = 0; | 2398 | mSocket = 0; |
2531 | } | 2399 | } |
2532 | //emit endConnect(); | 2400 | //emit endConnect(); |
2533 | } | 2401 | } |
2534 | void KServerSocket::readClient() | 2402 | void KServerSocket::readClient() |
2535 | { | 2403 | { |
2536 | if ( mSocket == 0 ) { | 2404 | if ( mSocket == 0 ) { |
2537 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | 2405 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); |
2538 | return; | 2406 | return; |
2539 | } | 2407 | } |
2540 | qDebug("KServerSocket readClient()"); | 2408 | qDebug("KServerSocket readClient()"); |
2541 | if ( mSocket->canReadLine() ) { | 2409 | if ( mSocket->canReadLine() ) { |
2542 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() ); | 2410 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() ); |
2543 | qDebug("KServerSocket socket->canReadLine()"); | 2411 | qDebug("KServerSocket socket->canReadLine()"); |
2544 | if ( tokens[0] == "GET" ) { | 2412 | if ( tokens[0] == "GET" ) { |
2545 | if ( tokens[1] == mPassWord ) | 2413 | if ( tokens[1] == mPassWord ) |
2546 | //emit sendFile( mSocket ); | 2414 | //emit sendFile( mSocket ); |
2547 | send_file(); | 2415 | send_file(); |
2548 | else { | 2416 | else { |
2549 | KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); | 2417 | KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); |
2550 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 2418 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
2551 | } | 2419 | } |
2552 | } | 2420 | } |
2553 | if ( tokens[0] == "PUT" ) { | 2421 | if ( tokens[0] == "PUT" ) { |
2554 | if ( tokens[1] == mPassWord ) | 2422 | if ( tokens[1] == mPassWord ) |
2555 | //emit getFile( mSocket ); | 2423 | //emit getFile( mSocket ); |
2556 | get_file(); | 2424 | get_file(); |
2557 | else { | 2425 | else { |
2558 | KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); | 2426 | KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); |
2559 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 2427 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
2560 | } | 2428 | } |
2561 | } | 2429 | } |
2562 | if ( tokens[0] == "STOP" ) { | 2430 | if ( tokens[0] == "STOP" ) { |
2563 | emit endConnect(); | 2431 | //emit endConnect(); |
2432 | end_connect(); | ||
2564 | } | 2433 | } |
2565 | } | 2434 | } |
2566 | } | 2435 | } |
2567 | 2436 | void KServerSocket::end_connect() | |
2437 | { | ||
2438 | delete mSyncActionDialog; | ||
2439 | mSyncActionDialog = 0; | ||
2440 | } | ||
2568 | void KServerSocket::send_file() | 2441 | void KServerSocket::send_file() |
2569 | { | 2442 | { |
2570 | qDebug("MainWindow::sendFile(QSocket* s) "); | 2443 | qDebug("MainWindow::sendFile(QSocket* s) "); |
2571 | if ( mSyncActionDialog ) | 2444 | if ( mSyncActionDialog ) |
2572 | delete mSyncActionDialog; | 2445 | delete mSyncActionDialog; |
2573 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 2446 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
2574 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 2447 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
2575 | QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use this application!\n\nIf syncing fails you can close this dialog."), mSyncActionDialog ); | 2448 | QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use this application!\n\nIf syncing fails you can close this dialog."), mSyncActionDialog ); |
2576 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 2449 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
2577 | lay->addWidget( label); | 2450 | lay->addWidget( label); |
2578 | lay->setMargin(7); | 2451 | lay->setMargin(7); |
2579 | lay->setSpacing(7); | 2452 | lay->setSpacing(7); |
2580 | mSyncActionDialog->setFixedSize( 230, 120); | 2453 | mSyncActionDialog->setFixedSize( 230, 120); |
2581 | mSyncActionDialog->show(); | 2454 | mSyncActionDialog->show(); |
2582 | qDebug("KSS::saving ... "); | 2455 | qDebug("KSS::saving ... "); |
2583 | emit saveFile(); | 2456 | emit saveFile(); |
2584 | qApp->processEvents(); | 2457 | qApp->processEvents(); |
2585 | QString fileName = mFileName; | 2458 | QString fileName = mFileName; |
2586 | QFile file( fileName ); | 2459 | QFile file( fileName ); |
2587 | if (!file.open( IO_ReadOnly ) ) { | 2460 | if (!file.open( IO_ReadOnly ) ) { |
2588 | delete mSyncActionDialog; | 2461 | delete mSyncActionDialog; |
2589 | mSyncActionDialog = 0; | 2462 | mSyncActionDialog = 0; |
2590 | qDebug("KSS::error open file "); | 2463 | qDebug("KSS::error open file "); |
2591 | mSocket->close(); | 2464 | mSocket->close(); |
2592 | if ( mSocket->state() == QSocket::Idle ) | 2465 | if ( mSocket->state() == QSocket::Idle ) |
2593 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 2466 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
2594 | return ; | 2467 | return ; |
2595 | 2468 | ||
2596 | } | 2469 | } |
2597 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 2470 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
2598 | QTextStream ts( &file ); | 2471 | QTextStream ts( &file ); |
2599 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 2472 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
2600 | QTextStream os( mSocket ); | 2473 | QTextStream os( mSocket ); |
2601 | os.setCodec( QTextCodec::codecForName("utf8") ); | 2474 | os.setCodec( QTextCodec::codecForName("utf8") ); |
2602 | //os.setEncoding( QTextStream::UnicodeUTF8 ); | 2475 | //os.setEncoding( QTextStream::UnicodeUTF8 ); |
2603 | while ( ! ts.atEnd() ) { | 2476 | while ( ! ts.atEnd() ) { |
2604 | os << ts.readLine() << "\n"; | 2477 | os << ts.readLine() << "\n"; |
2605 | } | 2478 | } |
2606 | //os << ts.read(); | 2479 | //os << ts.read(); |
2607 | file.close(); | 2480 | file.close(); |
2608 | mSyncActionDialog->setCaption( i18n("Waiting to get back synced file") ); | 2481 | mSyncActionDialog->setCaption( i18n("Waiting to get back synced file") ); |
2609 | qDebug("file sent "); | 2482 | qDebug("file sent "); |
2610 | mSocket->close(); | 2483 | mSocket->close(); |
2611 | if ( mSocket->state() == QSocket::Idle ) | 2484 | if ( mSocket->state() == QSocket::Idle ) |
2612 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 2485 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
2613 | } | 2486 | } |
2614 | void KServerSocket::get_file() | 2487 | void KServerSocket::get_file() |
2615 | { | 2488 | { |
2616 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 2489 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
2617 | 2490 | ||
2618 | piTime.start(); | 2491 | piTime.start(); |
2619 | piFileString = ""; | 2492 | piFileString = ""; |
2620 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 2493 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
2621 | } | 2494 | } |
2622 | 2495 | ||
2623 | 2496 | ||
2624 | void KServerSocket::readBackFileFromSocket() | 2497 | void KServerSocket::readBackFileFromSocket() |
2625 | { | 2498 | { |
2626 | qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 2499 | qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
2627 | while ( mSocket->canReadLine () ) { | 2500 | while ( mSocket->canReadLine () ) { |
2628 | piTime.restart(); | 2501 | piTime.restart(); |
2629 | QString line = mSocket->readLine (); | 2502 | QString line = mSocket->readLine (); |
2630 | piFileString += line; | 2503 | piFileString += line; |
2631 | qDebug("readline: %s ", line.latin1()); | 2504 | qDebug("readline: %s ", line.latin1()); |
2632 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 2505 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
2633 | 2506 | ||
2634 | } | 2507 | } |
2635 | if ( piTime.elapsed () < 3000 ) { | 2508 | if ( piTime.elapsed () < 3000 ) { |
2636 | // wait for more | 2509 | // wait for more |
2637 | qDebug("waitformore "); | 2510 | qDebug("waitformore "); |
2638 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 2511 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
2639 | return; | 2512 | return; |
2640 | } | 2513 | } |
2641 | QString fileName = mFileName; | 2514 | QString fileName = mFileName; |
2642 | QFile file ( fileName ); | 2515 | QFile file ( fileName ); |
2643 | if (!file.open( IO_WriteOnly ) ) { | 2516 | if (!file.open( IO_WriteOnly ) ) { |
2644 | delete mSyncActionDialog; | 2517 | delete mSyncActionDialog; |
2645 | mSyncActionDialog = 0; | 2518 | mSyncActionDialog = 0; |
2646 | qDebug("error open cal file "); | 2519 | qDebug("error open cal file "); |
2647 | piFileString = ""; | 2520 | piFileString = ""; |
2648 | emit file_received( false ); | 2521 | emit file_received( false ); |
2649 | return ; | 2522 | return ; |
2650 | 2523 | ||
2651 | } | 2524 | } |
2652 | 2525 | ||
2653 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 2526 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
2654 | QTextStream ts ( &file ); | 2527 | QTextStream ts ( &file ); |
2655 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 2528 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
2656 | qDebug("finish "); | 2529 | qDebug("finish "); |
2657 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 2530 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
2658 | ts << piFileString; | 2531 | ts << piFileString; |
2659 | mSocket->close(); | 2532 | mSocket->close(); |
2660 | if ( mSocket->state() == QSocket::Idle ) | 2533 | if ( mSocket->state() == QSocket::Idle ) |
2661 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 2534 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
2662 | file.close(); | 2535 | file.close(); |
2663 | delete mSyncActionDialog; | 2536 | delete mSyncActionDialog; |
2664 | mSyncActionDialog = 0; | 2537 | mSyncActionDialog = 0; |
2665 | piFileString = ""; | 2538 | piFileString = ""; |
2666 | emit file_received( true ); | 2539 | emit file_received( true ); |
2667 | 2540 | ||
2668 | } | 2541 | } |
2669 | 2542 | ||
2670 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 2543 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) |
2671 | { | 2544 | { |
2672 | mPassWord = password; | 2545 | mPassWord = password; |
2673 | mSocket = 0; | 2546 | mSocket = 0; |
2674 | mPort = port; | 2547 | mPort = port; |
2675 | mHost = host; | 2548 | mHost = host; |
2676 | 2549 | ||
2677 | mRetVal = false; | 2550 | mRetVal = false; |
2678 | mTimerSocket = new QTimer ( this ); | 2551 | mTimerSocket = new QTimer ( this ); |
2679 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 2552 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
2680 | } | 2553 | } |
2681 | void KCommandSocket::readFile( QString fn ) | 2554 | void KCommandSocket::readFile( QString fn ) |
2682 | { | 2555 | { |
2683 | if ( !mSocket ) { | 2556 | if ( !mSocket ) { |
2684 | mSocket = new QSocket( this ); | 2557 | mSocket = new QSocket( this ); |
2685 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 2558 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
2686 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 2559 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
2687 | } | 2560 | } |
2688 | mFileString = ""; | 2561 | mFileString = ""; |
2689 | mFileName = fn; | 2562 | mFileName = fn; |
2690 | mFirst = true; | 2563 | mFirst = true; |
2691 | mSocket->connectToHost( mHost, mPort ); | 2564 | mSocket->connectToHost( mHost, mPort ); |
2692 | QTextStream os( mSocket ); | 2565 | QTextStream os( mSocket ); |
2693 | os.setEncoding( QTextStream::UnicodeUTF8 ); | 2566 | os.setEncoding( QTextStream::UnicodeUTF8 ); |
2694 | os << "GET " << mPassWord << "\r\n"; | 2567 | os << "GET " << mPassWord << "\r\n"; |
2695 | mTimerSocket->start( 10000 ); | 2568 | mTimerSocket->start( 10000 ); |
2696 | } | 2569 | } |
2697 | 2570 | ||
2698 | void KCommandSocket::writeFile( QString ) | 2571 | void KCommandSocket::writeFile( QString fileName ) |
2699 | { | 2572 | { |
2573 | QFile file2( fileName ); | ||
2574 | if (!file2.open( IO_ReadOnly ) ) { | ||
2575 | mRetVal= false; | ||
2576 | deleteSocket(); | ||
2577 | return ; | ||
2578 | |||
2579 | } | ||
2580 | if ( !mSocket ) { | ||
2581 | mSocket = new QSocket( this ); | ||
2582 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | ||
2583 | } | ||
2584 | QTextStream ts2( &file2 ); | ||
2585 | ts2.setCodec( QTextCodec::codecForName("utf8") ); | ||
2586 | QTextStream os2( mSocket ); | ||
2587 | os2.setCodec( QTextCodec::codecForName("utf8") ); | ||
2588 | os2 << "PUT " << mPassWord << "\r\n";; | ||
2589 | while ( ! ts2.atEnd() ) { | ||
2590 | os2 << ts2.readLine() << "\n"; | ||
2591 | } | ||
2592 | mSocket->close(); | ||
2593 | if ( mSocket->state() == QSocket::Idle ) | ||
2594 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | ||
2595 | file2.close(); | ||
2596 | } | ||
2700 | 2597 | ||
2598 | void KCommandSocket::sendStop() | ||
2599 | { | ||
2600 | if ( !mSocket ) { | ||
2601 | mSocket = new QSocket( this ); | ||
2602 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | ||
2603 | } | ||
2604 | QTextStream os2( mSocket ); | ||
2605 | os2.setCodec( QTextCodec::codecForName("utf8") ); | ||
2606 | os2 << "STOP\r\n"; | ||
2607 | mRetVal= true; | ||
2608 | mSocket->close(); | ||
2609 | if ( mSocket->state() == QSocket::Idle ) | ||
2610 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | ||
2701 | } | 2611 | } |
2612 | |||
2702 | void KCommandSocket::startReadFileFromSocket() | 2613 | void KCommandSocket::startReadFileFromSocket() |
2703 | { | 2614 | { |
2704 | if ( ! mFirst ) | 2615 | if ( ! mFirst ) |
2705 | return; | 2616 | return; |
2706 | mFirst = false; | 2617 | mFirst = false; |
2707 | mTimerSocket->stop(); | 2618 | mTimerSocket->stop(); |
2708 | mFileString = ""; | 2619 | mFileString = ""; |
2709 | mTime.start(); | 2620 | mTime.start(); |
2710 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 2621 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
2711 | 2622 | ||
2712 | } | 2623 | } |
2713 | void KCommandSocket::readFileFromSocket() | 2624 | void KCommandSocket::readFileFromSocket() |
2714 | { | 2625 | { |
2715 | qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 2626 | qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
2716 | while ( mSocket->canReadLine () ) { | 2627 | while ( mSocket->canReadLine () ) { |
2717 | mTime.restart(); | 2628 | mTime.restart(); |
2718 | QString line = mSocket->readLine (); | 2629 | QString line = mSocket->readLine (); |
2719 | mFileString += line; | 2630 | mFileString += line; |
2720 | qDebug("readline: %s ", line.latin1()); | 2631 | qDebug("readline: %s ", line.latin1()); |
2721 | } | 2632 | } |
2722 | if ( mTime.elapsed () < 3000 ) { | 2633 | if ( mTime.elapsed () < 3000 ) { |
2723 | // wait for more | 2634 | // wait for more |
2724 | qDebug("waitformore "); | 2635 | qDebug("waitformore "); |
2725 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 2636 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
2726 | return; | 2637 | return; |
2727 | } | 2638 | } |
2728 | QString fileName = mFileName; | 2639 | QString fileName = mFileName; |
2729 | QFile file ( fileName ); | 2640 | QFile file ( fileName ); |
2730 | if (!file.open( IO_WriteOnly ) ) { | 2641 | if (!file.open( IO_WriteOnly ) ) { |
2731 | mFileString = ""; | 2642 | mFileString = ""; |
2732 | mRetVal = false; | 2643 | mRetVal = false; |
2733 | qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); | 2644 | qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); |
2734 | deleteSocket(); | 2645 | deleteSocket(); |
2735 | return ; | 2646 | return ; |
2736 | 2647 | ||
2737 | } | 2648 | } |
2738 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 2649 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
2739 | QTextStream ts ( &file ); | 2650 | QTextStream ts ( &file ); |
2740 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 2651 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
2741 | qDebug("finish "); | 2652 | qDebug("finish "); |
2742 | ts << mFileString; | 2653 | ts << mFileString; |
2743 | file.close(); | 2654 | file.close(); |
2744 | mFileString = ""; | 2655 | mFileString = ""; |
2745 | mRetVal = true; | 2656 | mRetVal = true; |
2746 | mSocket->close(); | 2657 | mSocket->close(); |
2747 | // if state is not idle, deleteSocket(); is called via | 2658 | // if state is not idle, deleteSocket(); is called via |
2748 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 2659 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
2749 | if ( mSocket->state() == QSocket::Idle ) | 2660 | if ( mSocket->state() == QSocket::Idle ) |
2750 | deleteSocket(); | 2661 | deleteSocket(); |
2751 | } | 2662 | } |
2752 | 2663 | ||
2753 | void KCommandSocket::deleteSocket() | 2664 | void KCommandSocket::deleteSocket() |
2754 | { | 2665 | { |
2755 | if ( !mSocket) | ||
2756 | return; | ||
2757 | if ( mTimerSocket->isActive () ) { | 2666 | if ( mTimerSocket->isActive () ) { |
2758 | mTimerSocket->stop(); | 2667 | mTimerSocket->stop(); |
2759 | KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); | 2668 | KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); |
2760 | mRetVal = false; | 2669 | mRetVal = false; |
2761 | } | 2670 | } |
2762 | qDebug("KCommandSocket::deleteSocket() %d", mRetVal); | 2671 | qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); |
2763 | delete mSocket; | 2672 | if ( mSocket) |
2673 | delete mSocket; | ||
2764 | mSocket = 0; | 2674 | mSocket = 0; |
2765 | emit commandFinished( mRetVal ); | 2675 | emit commandFinished( this, mRetVal ); |
2766 | } | 2676 | } |
2767 | 2677 | ||
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h index 8b76067..5a67765 100644 --- a/korganizer/mainwindow.h +++ b/korganizer/mainwindow.h | |||
@@ -1,212 +1,209 @@ | |||
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 <qfile.h> | 7 | #include <qfile.h> |
8 | #include <qsocket.h> | 8 | #include <qsocket.h> |
9 | #include <qtextstream.h> | 9 | #include <qtextstream.h> |
10 | #include <qregexp.h> | 10 | #include <qregexp.h> |
11 | 11 | ||
12 | #include <libkcal/incidence.h> | 12 | #include <libkcal/incidence.h> |
13 | #include "simplealarmclient.h" | 13 | #include "simplealarmclient.h" |
14 | 14 | ||
15 | class QAction; | 15 | class QAction; |
16 | class CalendarView; | 16 | class CalendarView; |
17 | class KSyncProfile; | 17 | class KSyncProfile; |
18 | #ifdef DESKTOP_VERSION | 18 | #ifdef DESKTOP_VERSION |
19 | 19 | ||
20 | #define QPEToolBar QToolBar | 20 | #define QPEToolBar QToolBar |
21 | #define QPEMenuBar QMenuBar | 21 | #define QPEMenuBar QMenuBar |
22 | #endif | 22 | #endif |
23 | class QPEToolBar; | 23 | class QPEToolBar; |
24 | #include <qserversocket.h> | 24 | #include <qserversocket.h> |
25 | #include <qsocket.h> | 25 | #include <qsocket.h> |
26 | #include <qnetworkprotocol.h> | 26 | #include <qnetworkprotocol.h> |
27 | 27 | ||
28 | class KServerSocket : public QServerSocket | 28 | class KServerSocket : public QServerSocket |
29 | { | 29 | { |
30 | Q_OBJECT | 30 | Q_OBJECT |
31 | 31 | ||
32 | public: | 32 | public: |
33 | KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); | 33 | KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); |
34 | 34 | ||
35 | void newConnection ( int socket ) ; | 35 | void newConnection ( int socket ) ; |
36 | void setFileName( QString fn ) {mFileName = fn;}; | 36 | void setFileName( QString fn ) {mFileName = fn;}; |
37 | 37 | ||
38 | signals: | 38 | signals: |
39 | //void sendFile(QSocket*); | 39 | //void sendFile(QSocket*); |
40 | //void getFile(QSocket*); | 40 | //void getFile(QSocket*); |
41 | void file_received( bool ); | 41 | void file_received( bool ); |
42 | //void file_sent(); | 42 | //void file_sent(); |
43 | void saveFile(); | 43 | void saveFile(); |
44 | void endConnect(); | 44 | void endConnect(); |
45 | private slots: | 45 | private slots: |
46 | void discardClient(); | 46 | void discardClient(); |
47 | void readClient(); | 47 | void readClient(); |
48 | void readBackFileFromSocket(); | 48 | void readBackFileFromSocket(); |
49 | private : | 49 | private : |
50 | void send_file(); | 50 | void send_file(); |
51 | void get_file(); | 51 | void get_file(); |
52 | void end_connect(); | ||
52 | QDialog* mSyncActionDialog; | 53 | QDialog* mSyncActionDialog; |
53 | QSocket* mSocket; | 54 | QSocket* mSocket; |
54 | QString mPassWord; | 55 | QString mPassWord; |
55 | QString mFileName; | 56 | QString mFileName; |
56 | QTime piTime; | 57 | QTime piTime; |
57 | QString piFileString; | 58 | QString piFileString; |
58 | }; | 59 | }; |
59 | 60 | ||
60 | class KCommandSocket : public QObject | 61 | class KCommandSocket : public QObject |
61 | { | 62 | { |
62 | Q_OBJECT | 63 | Q_OBJECT |
63 | 64 | ||
64 | public: | 65 | public: |
65 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); | 66 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); |
66 | void readFile( QString ); | 67 | void readFile( QString ); |
67 | void writeFile( QString ); | 68 | void writeFile( QString ); |
69 | void sendStop(); | ||
68 | 70 | ||
69 | 71 | ||
70 | signals: | 72 | signals: |
71 | void commandFinished( bool ); | 73 | void commandFinished( KCommandSocket*, bool ); |
72 | private slots: | 74 | private slots: |
73 | void startReadFileFromSocket(); | 75 | void startReadFileFromSocket(); |
74 | void readFileFromSocket(); | 76 | void readFileFromSocket(); |
75 | void deleteSocket(); | 77 | void deleteSocket(); |
76 | private : | 78 | private : |
77 | QSocket* mSocket; | 79 | QSocket* mSocket; |
78 | QString mPassWord; | 80 | QString mPassWord; |
79 | Q_UINT16 mPort; | 81 | Q_UINT16 mPort; |
80 | QString mHost; | 82 | QString mHost; |
81 | QString mFileName; | 83 | QString mFileName; |
82 | QTimer* mTimerSocket; | 84 | QTimer* mTimerSocket; |
83 | bool mRetVal; | 85 | bool mRetVal; |
84 | QTime mTime; | 86 | QTime mTime; |
85 | QString mFileString; | 87 | QString mFileString; |
86 | bool mFirst; | 88 | bool mFirst; |
87 | }; | 89 | }; |
88 | 90 | ||
89 | namespace KCal { | 91 | namespace KCal { |
90 | class CalendarLocal; | 92 | class CalendarLocal; |
91 | } | 93 | } |
92 | 94 | ||
93 | using namespace KCal; | 95 | using namespace KCal; |
94 | 96 | ||
95 | class MainWindow : public QMainWindow | 97 | class MainWindow : public QMainWindow |
96 | { | 98 | { |
97 | Q_OBJECT | 99 | Q_OBJECT |
98 | public: | 100 | public: |
99 | MainWindow( QWidget *parent = 0, const char *name = 0, QString command = ""); | 101 | MainWindow( QWidget *parent = 0, const char *name = 0, QString command = ""); |
100 | ~MainWindow(); | 102 | ~MainWindow(); |
101 | public slots: | 103 | public slots: |
102 | virtual void showMaximized (); | 104 | virtual void showMaximized (); |
103 | void configureAgenda( int ); | 105 | void configureAgenda( int ); |
104 | void recieve( const QCString& msg, const QByteArray& data ); | 106 | void recieve( const QCString& msg, const QByteArray& data ); |
105 | static QString defaultFileName(); | 107 | static QString defaultFileName(); |
106 | static QString resourcePath(); | 108 | static QString resourcePath(); |
107 | protected slots: | 109 | protected slots: |
108 | void setCaptionToDates(); | 110 | void setCaptionToDates(); |
109 | int ringSync(); | 111 | int ringSync(); |
110 | void multiSync( bool askforPrefs = false ); | 112 | void multiSync( bool askforPrefs = false ); |
111 | void about(); | 113 | void about(); |
112 | void licence(); | 114 | void licence(); |
113 | void faq(); | 115 | void faq(); |
114 | void usertrans(); | 116 | void usertrans(); |
115 | void features(); | 117 | void features(); |
116 | void synchowto(); | 118 | void synchowto(); |
117 | void whatsNew(); | 119 | void whatsNew(); |
118 | void keyBindings(); | 120 | void keyBindings(); |
119 | void aboutAutoSaving();; | 121 | void aboutAutoSaving();; |
120 | void aboutKnownBugs(); | 122 | void aboutKnownBugs(); |
121 | 123 | ||
122 | void processIncidenceSelection( Incidence * ); | 124 | void processIncidenceSelection( Incidence * ); |
123 | 125 | ||
124 | void importQtopia(); | 126 | void importQtopia(); |
125 | void importBday(); | 127 | void importBday(); |
126 | void importOL(); | 128 | void importOL(); |
127 | void importIcal(); | 129 | void importIcal(); |
128 | void importFile( QString, bool ); | 130 | void importFile( QString, bool ); |
129 | void quickImportIcal(); | 131 | void quickImportIcal(); |
130 | 132 | ||
131 | void slotModifiedChanged( bool ); | 133 | void slotModifiedChanged( bool ); |
132 | 134 | ||
133 | void save(); | 135 | void save(); |
134 | void configureToolBar( int ); | 136 | void configureToolBar( int ); |
135 | void printSel(); | 137 | void printSel(); |
136 | void printCal(); | 138 | void printCal(); |
137 | void saveCalendar(); | 139 | void saveCalendar(); |
138 | void loadCalendar(); | 140 | void loadCalendar(); |
139 | void exportVCalendar(); | 141 | void exportVCalendar(); |
140 | void fillFilterMenu(); | 142 | void fillFilterMenu(); |
141 | void selectFilter( int ); | 143 | void selectFilter( int ); |
142 | 144 | ||
143 | void slotSyncMenu( int ); | 145 | void slotSyncMenu( int ); |
144 | void syncSSH(); | 146 | void syncSSH(); |
145 | void confSync(); | 147 | void confSync(); |
146 | void syncSharp(); | 148 | void syncSharp(); |
147 | void syncPhone(); | 149 | void syncPhone(); |
148 | void syncLocalFile(); | 150 | void syncLocalFile(); |
149 | bool syncWithFile( QString, bool ); | 151 | bool syncWithFile( QString, bool ); |
150 | void quickSyncLocalFile(); | 152 | void quickSyncLocalFile(); |
151 | 153 | ||
152 | 154 | ||
153 | protected: | 155 | protected: |
154 | void displayText( QString, QString); | 156 | void displayText( QString, QString); |
155 | void displayFile( QString, QString); | 157 | void displayFile( QString, QString); |
156 | 158 | ||
157 | void enableIncidenceActions( bool ); | 159 | void enableIncidenceActions( bool ); |
158 | 160 | ||
159 | private slots: | 161 | private slots: |
160 | QSocket* piSocket; | 162 | QSocket* piSocket; |
161 | QString piFileString; | 163 | QString piFileString; |
162 | QTime piTime; | 164 | QTime piTime; |
163 | void deleteCommandSocket(bool); | 165 | void deleteCommandSocket(KCommandSocket* s, bool success); |
164 | void deleteCommandSocketFinish(); | 166 | void deleteCommandSocketFinish(KCommandSocket* s, bool success); |
165 | void fillSyncMenu(); | 167 | void fillSyncMenu(); |
166 | void sendFile(QSocket* s); | ||
167 | void getFile( bool ); | 168 | void getFile( bool ); |
168 | void readFileFromSocket(); | 169 | void readFileFromSocket(); |
169 | void readBackFileFromSocket(); | ||
170 | void endConnect(); | ||
171 | private: | 170 | private: |
172 | //QTimer* mTimerCommandSocket; | 171 | //QTimer* mTimerCommandSocket; |
173 | QString mPassWordPiSync; | 172 | QString mPassWordPiSync; |
174 | KCommandSocket* mCommandSocket; | ||
175 | QSocket* mCommandSocketFinish; | ||
176 | KServerSocket * mServerSocket; | 173 | KServerSocket * mServerSocket; |
177 | bool mClosed; | 174 | bool mClosed; |
178 | void saveOnClose(); | 175 | void saveOnClose(); |
179 | int mCurrentSyncProfile; | 176 | int mCurrentSyncProfile; |
180 | void enableQuick(); | 177 | void enableQuick(); |
181 | void performQuick(); | 178 | void performQuick(); |
182 | void performQuickQuick(); | 179 | void performQuickQuick(); |
183 | void syncRemote( KSyncProfile* , bool ask = true); | 180 | void syncRemote( KSyncProfile* , bool ask = true); |
184 | bool mFlagKeyPressed; | 181 | bool mFlagKeyPressed; |
185 | bool mBlockAtStartup; | 182 | bool mBlockAtStartup; |
186 | QPEToolBar *iconToolBar; | 183 | QPEToolBar *iconToolBar; |
187 | void initActions(); | 184 | void initActions(); |
188 | void setDefaultPreferences(); | 185 | void setDefaultPreferences(); |
189 | void keyPressEvent ( QKeyEvent * ) ; | 186 | void keyPressEvent ( QKeyEvent * ) ; |
190 | void keyReleaseEvent ( QKeyEvent * ) ; | 187 | void keyReleaseEvent ( QKeyEvent * ) ; |
191 | QPopupMenu *configureToolBarMenu; | 188 | QPopupMenu *configureToolBarMenu; |
192 | QPopupMenu *selectFilterMenu; | 189 | QPopupMenu *selectFilterMenu; |
193 | QPopupMenu *configureAgendaMenu, *syncMenu; | 190 | QPopupMenu *configureAgendaMenu, *syncMenu; |
194 | CalendarLocal *mCalendar; | 191 | CalendarLocal *mCalendar; |
195 | CalendarView *mView; | 192 | CalendarView *mView; |
196 | QString getPassword(); | 193 | QString getPassword(); |
197 | QAction *mNewSubTodoAction; | 194 | QAction *mNewSubTodoAction; |
198 | 195 | ||
199 | QAction *mShowAction; | 196 | QAction *mShowAction; |
200 | QAction *mEditAction; | 197 | QAction *mEditAction; |
201 | QAction *mDeleteAction; | 198 | QAction *mDeleteAction; |
202 | void closeEvent( QCloseEvent* ce ); | 199 | void closeEvent( QCloseEvent* ce ); |
203 | SimpleAlarmClient mAlarmClient; | 200 | SimpleAlarmClient mAlarmClient; |
204 | QTimer mSaveTimer; | 201 | QTimer mSaveTimer; |
205 | bool mBlockSaveFlag; | 202 | bool mBlockSaveFlag; |
206 | bool mCalendarModifiedFlag; | 203 | bool mCalendarModifiedFlag; |
207 | QPixmap loadPixmap( QString ); | 204 | QPixmap loadPixmap( QString ); |
208 | QDialog * mSyncActionDialog; | 205 | QDialog * mSyncActionDialog; |
209 | }; | 206 | }; |
210 | 207 | ||
211 | 208 | ||
212 | #endif | 209 | #endif |