author | zautrix <zautrix> | 2004-10-26 22:56:24 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-26 22:56:24 (UTC) |
commit | 00d623c9391a9bdaeb142f443f1dd09861317608 (patch) (unidiff) | |
tree | 941b77a6da7a5db84ed9f4c00ab18918231cb643 /libkdepim/ksyncmanager.cpp | |
parent | 6385f303bef3cbcd19d097a7b05c30e144d5dd6e (diff) | |
download | kdepimpi-00d623c9391a9bdaeb142f443f1dd09861317608.zip kdepimpi-00d623c9391a9bdaeb142f443f1dd09861317608.tar.gz kdepimpi-00d623c9391a9bdaeb142f443f1dd09861317608.tar.bz2 |
added external time for pisync - kdesync
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index feb184b..e09050e 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -10,96 +10,99 @@ | |||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | // $Id$ | 21 | // $Id$ |
22 | 22 | ||
23 | #include "ksyncmanager.h" | 23 | #include "ksyncmanager.h" |
24 | 24 | ||
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | 26 | ||
27 | #ifndef _WIN32_ | 27 | #ifndef _WIN32_ |
28 | #include <unistd.h> | 28 | #include <unistd.h> |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | 31 | ||
32 | #include "ksyncprofile.h" | 32 | #include "ksyncprofile.h" |
33 | #include "ksyncprefsdialog.h" | 33 | #include "ksyncprefsdialog.h" |
34 | #include "kpimprefs.h" | 34 | #include "kpimprefs.h" |
35 | #include <kmessagebox.h> | 35 | #include <kmessagebox.h> |
36 | 36 | ||
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qprogressbar.h> | 38 | #include <qprogressbar.h> |
39 | #include <qpopupmenu.h> | 39 | #include <qpopupmenu.h> |
40 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
41 | #include <qradiobutton.h> | 41 | #include <qradiobutton.h> |
42 | #include <qbuttongroup.h> | 42 | #include <qbuttongroup.h> |
43 | #include <qtimer.h> | 43 | #include <qtimer.h> |
44 | #include <qmessagebox.h> | 44 | #include <qmessagebox.h> |
45 | #include <qapplication.h> | 45 | #include <qapplication.h> |
46 | #include <qlineedit.h> | 46 | #include <qlineedit.h> |
47 | #include <qdialog.h> | 47 | #include <qdialog.h> |
48 | #include <qlayout.h> | 48 | #include <qlayout.h> |
49 | #include <qtextcodec.h> | 49 | #include <qtextcodec.h> |
50 | #include <qlabel.h> | 50 | #include <qlabel.h> |
51 | #include <qcheckbox.h> | 51 | #include <qcheckbox.h> |
52 | 52 | ||
53 | #include <klocale.h> | 53 | #include <klocale.h> |
54 | #include <kglobal.h> | 54 | #include <kglobal.h> |
55 | #include <kconfig.h> | 55 | #include <kconfig.h> |
56 | #include <kfiledialog.h> | 56 | #include <kfiledialog.h> |
57 | 57 | ||
58 | QDateTime KSyncManager::mRequestedSyncEvent; | ||
59 | |||
60 | |||
58 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) | 61 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) |
59 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) | 62 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) |
60 | { | 63 | { |
61 | mServerSocket = 0; | 64 | mServerSocket = 0; |
62 | bar = new QProgressBar ( 1, 0 ); | 65 | bar = new QProgressBar ( 1, 0 ); |
63 | bar->setCaption (""); | 66 | bar->setCaption (""); |
64 | 67 | ||
65 | int w = 300; | 68 | int w = 300; |
66 | if ( QApplication::desktop()->width() < 320 ) | 69 | if ( QApplication::desktop()->width() < 320 ) |
67 | w = 220; | 70 | w = 220; |
68 | int h = bar->sizeHint().height() ; | 71 | int h = bar->sizeHint().height() ; |
69 | int dw = QApplication::desktop()->width(); | 72 | int dw = QApplication::desktop()->width(); |
70 | int dh = QApplication::desktop()->height(); | 73 | int dh = QApplication::desktop()->height(); |
71 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 74 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
72 | if ( mPrefs->mPassiveSyncAutoStart ) | 75 | if ( mPrefs->mPassiveSyncAutoStart ) |
73 | enableQuick( false ); | 76 | enableQuick( false ); |
74 | 77 | ||
75 | } | 78 | } |
76 | 79 | ||
77 | KSyncManager::~KSyncManager() | 80 | KSyncManager::~KSyncManager() |
78 | { | 81 | { |
79 | delete bar; | 82 | delete bar; |
80 | } | 83 | } |
81 | 84 | ||
82 | 85 | ||
83 | void KSyncManager::fillSyncMenu() | 86 | void KSyncManager::fillSyncMenu() |
84 | { | 87 | { |
85 | if ( mSyncMenu->count() ) | 88 | if ( mSyncMenu->count() ) |
86 | mSyncMenu->clear(); | 89 | mSyncMenu->clear(); |
87 | 90 | ||
88 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); | 91 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); |
89 | mSyncMenu->insertSeparator(); | 92 | mSyncMenu->insertSeparator(); |
90 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); | 93 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); |
91 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); | 94 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); |
92 | clearMenu->insertItem( i18n("For all profiles"), 1 ); | 95 | clearMenu->insertItem( i18n("For all profiles"), 1 ); |
93 | clearMenu->insertSeparator(); | 96 | clearMenu->insertSeparator(); |
94 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); | 97 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); |
95 | mSyncMenu->insertSeparator(); | 98 | mSyncMenu->insertSeparator(); |
96 | if ( mServerSocket == 0 ) { | 99 | if ( mServerSocket == 0 ) { |
97 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 100 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
98 | } else { | 101 | } else { |
99 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 102 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
100 | } | 103 | } |
101 | mSyncMenu->insertSeparator(); | 104 | mSyncMenu->insertSeparator(); |
102 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 105 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
103 | mSyncMenu->insertSeparator(); | 106 | mSyncMenu->insertSeparator(); |
104 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 107 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
105 | config.setGroup("General"); | 108 | config.setGroup("General"); |
@@ -1066,99 +1069,106 @@ void KSyncManager::readFileFromSocket() | |||
1066 | } | 1069 | } |
1067 | } | 1070 | } |
1068 | 1071 | ||
1069 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1072 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1070 | { | 1073 | { |
1071 | mPassWord = pw; | 1074 | mPassWord = pw; |
1072 | mSocket = 0; | 1075 | mSocket = 0; |
1073 | mSyncActionDialog = 0; | 1076 | mSyncActionDialog = 0; |
1074 | blockRC = false; | 1077 | blockRC = false; |
1075 | }; | 1078 | }; |
1076 | 1079 | ||
1077 | void KServerSocket::newConnection ( int socket ) | 1080 | void KServerSocket::newConnection ( int socket ) |
1078 | { | 1081 | { |
1079 | // qDebug("KServerSocket:New connection %d ", socket); | 1082 | // qDebug("KServerSocket:New connection %d ", socket); |
1080 | if ( mSocket ) { | 1083 | if ( mSocket ) { |
1081 | qDebug("KServerSocket::newConnection Socket deleted! "); | 1084 | qDebug("KServerSocket::newConnection Socket deleted! "); |
1082 | delete mSocket; | 1085 | delete mSocket; |
1083 | mSocket = 0; | 1086 | mSocket = 0; |
1084 | } | 1087 | } |
1085 | mSocket = new QSocket( this ); | 1088 | mSocket = new QSocket( this ); |
1086 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1089 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1087 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1090 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1088 | mSocket->setSocket( socket ); | 1091 | mSocket->setSocket( socket ); |
1089 | } | 1092 | } |
1090 | 1093 | ||
1091 | void KServerSocket::discardClient() | 1094 | void KServerSocket::discardClient() |
1092 | { | 1095 | { |
1093 | //qDebug(" KServerSocket::discardClient()"); | 1096 | //qDebug(" KServerSocket::discardClient()"); |
1094 | if ( mSocket ) { | 1097 | if ( mSocket ) { |
1095 | delete mSocket; | 1098 | delete mSocket; |
1096 | mSocket = 0; | 1099 | mSocket = 0; |
1097 | } | 1100 | } |
1098 | //emit endConnect(); | 1101 | //emit endConnect(); |
1099 | } | 1102 | } |
1100 | void KServerSocket::readClient() | 1103 | void KServerSocket::readClient() |
1101 | { | 1104 | { |
1102 | if ( blockRC ) | 1105 | if ( blockRC ) |
1103 | return; | 1106 | return; |
1104 | if ( mSocket == 0 ) { | 1107 | if ( mSocket == 0 ) { |
1105 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | 1108 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); |
1106 | return; | 1109 | return; |
1107 | } | 1110 | } |
1108 | //qDebug("KServerSocket::readClient()"); | 1111 | //qDebug("KServerSocket::readClient()"); |
1109 | if ( mSocket->canReadLine() ) { | 1112 | if ( mSocket->canReadLine() ) { |
1110 | QString line = mSocket->readLine(); | 1113 | QString line = mSocket->readLine(); |
1111 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1114 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1112 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1115 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1113 | if ( tokens[0] == "GET" ) { | 1116 | if ( tokens[0] == "GET" ) { |
1114 | if ( tokens[1] == mPassWord ) | 1117 | if ( tokens[1] == mPassWord ) { |
1115 | //emit sendFile( mSocket ); | 1118 | //emit sendFile( mSocket ); |
1119 | bool ok = false; | ||
1120 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); | ||
1121 | if ( ok ) | ||
1122 | KSyncManager::mRequestedSyncEvent = dt; | ||
1123 | else | ||
1124 | KSyncManager::mRequestedSyncEvent = QDateTime(); | ||
1116 | send_file(); | 1125 | send_file(); |
1126 | } | ||
1117 | else { | 1127 | else { |
1118 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); | 1128 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); |
1119 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1129 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1120 | } | 1130 | } |
1121 | } | 1131 | } |
1122 | if ( tokens[0] == "PUT" ) { | 1132 | if ( tokens[0] == "PUT" ) { |
1123 | if ( tokens[1] == mPassWord ) { | 1133 | if ( tokens[1] == mPassWord ) { |
1124 | //emit getFile( mSocket ); | 1134 | //emit getFile( mSocket ); |
1125 | blockRC = true; | 1135 | blockRC = true; |
1126 | get_file(); | 1136 | get_file(); |
1127 | } | 1137 | } |
1128 | else { | 1138 | else { |
1129 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); | 1139 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); |
1130 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1140 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1131 | } | 1141 | } |
1132 | } | 1142 | } |
1133 | if ( tokens[0] == "STOP" ) { | 1143 | if ( tokens[0] == "STOP" ) { |
1134 | //emit endConnect(); | 1144 | //emit endConnect(); |
1135 | end_connect(); | 1145 | end_connect(); |
1136 | } | 1146 | } |
1137 | } | 1147 | } |
1138 | } | 1148 | } |
1139 | void KServerSocket::end_connect() | 1149 | void KServerSocket::end_connect() |
1140 | { | 1150 | { |
1141 | delete mSyncActionDialog; | 1151 | delete mSyncActionDialog; |
1142 | mSyncActionDialog = 0; | 1152 | mSyncActionDialog = 0; |
1143 | } | 1153 | } |
1144 | void KServerSocket::send_file() | 1154 | void KServerSocket::send_file() |
1145 | { | 1155 | { |
1146 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 1156 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
1147 | if ( mSyncActionDialog ) | 1157 | if ( mSyncActionDialog ) |
1148 | delete mSyncActionDialog; | 1158 | delete mSyncActionDialog; |
1149 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 1159 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
1150 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 1160 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
1151 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 1161 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
1152 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 1162 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
1153 | lay->addWidget( label); | 1163 | lay->addWidget( label); |
1154 | lay->setMargin(7); | 1164 | lay->setMargin(7); |
1155 | lay->setSpacing(7); | 1165 | lay->setSpacing(7); |
1156 | mSyncActionDialog->setFixedSize( 230, 120); | 1166 | mSyncActionDialog->setFixedSize( 230, 120); |
1157 | mSyncActionDialog->show(); | 1167 | mSyncActionDialog->show(); |
1158 | mSyncActionDialog->raise(); | 1168 | mSyncActionDialog->raise(); |
1159 | emit request_file(); | 1169 | emit request_file(); |
1160 | qApp->processEvents(); | 1170 | qApp->processEvents(); |
1161 | QString fileName = mFileName; | 1171 | QString fileName = mFileName; |
1162 | QFile file( fileName ); | 1172 | QFile file( fileName ); |
1163 | if (!file.open( IO_ReadOnly ) ) { | 1173 | if (!file.open( IO_ReadOnly ) ) { |
1164 | delete mSyncActionDialog; | 1174 | delete mSyncActionDialog; |
@@ -1222,97 +1232,99 @@ void KServerSocket::readBackFileFromSocket() | |||
1222 | piFileString = ""; | 1232 | piFileString = ""; |
1223 | emit file_received( false ); | 1233 | emit file_received( false ); |
1224 | blockRC = false; | 1234 | blockRC = false; |
1225 | return ; | 1235 | return ; |
1226 | 1236 | ||
1227 | } | 1237 | } |
1228 | 1238 | ||
1229 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1239 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1230 | QTextStream ts ( &file ); | 1240 | QTextStream ts ( &file ); |
1231 | ts.setEncoding( QTextStream::Latin1 ); | 1241 | ts.setEncoding( QTextStream::Latin1 ); |
1232 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1242 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1233 | ts << piFileString; | 1243 | ts << piFileString; |
1234 | mSocket->close(); | 1244 | mSocket->close(); |
1235 | if ( mSocket->state() == QSocket::Idle ) | 1245 | if ( mSocket->state() == QSocket::Idle ) |
1236 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1246 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1237 | file.close(); | 1247 | file.close(); |
1238 | piFileString = ""; | 1248 | piFileString = ""; |
1239 | emit file_received( true ); | 1249 | emit file_received( true ); |
1240 | delete mSyncActionDialog; | 1250 | delete mSyncActionDialog; |
1241 | mSyncActionDialog = 0; | 1251 | mSyncActionDialog = 0; |
1242 | blockRC = false; | 1252 | blockRC = false; |
1243 | 1253 | ||
1244 | } | 1254 | } |
1245 | 1255 | ||
1246 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 1256 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) |
1247 | { | 1257 | { |
1248 | mPassWord = password; | 1258 | mPassWord = password; |
1249 | mSocket = 0; | 1259 | mSocket = 0; |
1250 | mPort = port; | 1260 | mPort = port; |
1251 | mHost = host; | 1261 | mHost = host; |
1252 | 1262 | ||
1253 | mRetVal = quiet; | 1263 | mRetVal = quiet; |
1254 | mTimerSocket = new QTimer ( this ); | 1264 | mTimerSocket = new QTimer ( this ); |
1255 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1265 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
1256 | } | 1266 | } |
1257 | void KCommandSocket::readFile( QString fn ) | 1267 | void KCommandSocket::readFile( QString fn ) |
1258 | { | 1268 | { |
1259 | if ( !mSocket ) { | 1269 | if ( !mSocket ) { |
1260 | mSocket = new QSocket( this ); | 1270 | mSocket = new QSocket( this ); |
1261 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1271 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1262 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1272 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1263 | } | 1273 | } |
1264 | mFileString = ""; | 1274 | mFileString = ""; |
1265 | mFileName = fn; | 1275 | mFileName = fn; |
1266 | mFirst = true; | 1276 | mFirst = true; |
1267 | mSocket->connectToHost( mHost, mPort ); | 1277 | mSocket->connectToHost( mHost, mPort ); |
1268 | QTextStream os( mSocket ); | 1278 | QTextStream os( mSocket ); |
1269 | os.setEncoding( QTextStream::Latin1 ); | 1279 | os.setEncoding( QTextStream::Latin1 ); |
1270 | os << "GET " << mPassWord << "\r\n"; | 1280 | |
1281 | QString curDt = KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | ||
1282 | os << "GET " << mPassWord << curDt <<"\r\n"; | ||
1271 | mTimerSocket->start( 20000 ); | 1283 | mTimerSocket->start( 20000 ); |
1272 | } | 1284 | } |
1273 | 1285 | ||
1274 | void KCommandSocket::writeFile( QString fileName ) | 1286 | void KCommandSocket::writeFile( QString fileName ) |
1275 | { | 1287 | { |
1276 | if ( !mSocket ) { | 1288 | if ( !mSocket ) { |
1277 | mSocket = new QSocket( this ); | 1289 | mSocket = new QSocket( this ); |
1278 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1290 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1279 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1291 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1280 | } | 1292 | } |
1281 | mFileName = fileName ; | 1293 | mFileName = fileName ; |
1282 | mSocket->connectToHost( mHost, mPort ); | 1294 | mSocket->connectToHost( mHost, mPort ); |
1283 | } | 1295 | } |
1284 | void KCommandSocket::writeFileToSocket() | 1296 | void KCommandSocket::writeFileToSocket() |
1285 | { | 1297 | { |
1286 | QFile file2( mFileName ); | 1298 | QFile file2( mFileName ); |
1287 | if (!file2.open( IO_ReadOnly ) ) { | 1299 | if (!file2.open( IO_ReadOnly ) ) { |
1288 | mRetVal= errorW; | 1300 | mRetVal= errorW; |
1289 | mSocket->close(); | 1301 | mSocket->close(); |
1290 | if ( mSocket->state() == QSocket::Idle ) | 1302 | if ( mSocket->state() == QSocket::Idle ) |
1291 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1303 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1292 | return ; | 1304 | return ; |
1293 | } | 1305 | } |
1294 | QTextStream ts2( &file2 ); | 1306 | QTextStream ts2( &file2 ); |
1295 | ts2.setEncoding( QTextStream::Latin1 ); | 1307 | ts2.setEncoding( QTextStream::Latin1 ); |
1296 | QTextStream os2( mSocket ); | 1308 | QTextStream os2( mSocket ); |
1297 | os2.setEncoding( QTextStream::Latin1 ); | 1309 | os2.setEncoding( QTextStream::Latin1 ); |
1298 | os2 << "PUT " << mPassWord << "\r\n";; | 1310 | os2 << "PUT " << mPassWord << "\r\n";; |
1299 | while ( ! ts2.atEnd() ) { | 1311 | while ( ! ts2.atEnd() ) { |
1300 | os2 << ts2.readLine() << "\r\n"; | 1312 | os2 << ts2.readLine() << "\r\n"; |
1301 | } | 1313 | } |
1302 | mRetVal= successW; | 1314 | mRetVal= successW; |
1303 | file2.close(); | 1315 | file2.close(); |
1304 | mSocket->close(); | 1316 | mSocket->close(); |
1305 | if ( mSocket->state() == QSocket::Idle ) | 1317 | if ( mSocket->state() == QSocket::Idle ) |
1306 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1318 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1307 | } | 1319 | } |
1308 | void KCommandSocket::sendStop() | 1320 | void KCommandSocket::sendStop() |
1309 | { | 1321 | { |
1310 | if ( !mSocket ) { | 1322 | if ( !mSocket ) { |
1311 | mSocket = new QSocket( this ); | 1323 | mSocket = new QSocket( this ); |
1312 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1324 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1313 | } | 1325 | } |
1314 | mSocket->connectToHost( mHost, mPort ); | 1326 | mSocket->connectToHost( mHost, mPort ); |
1315 | QTextStream os2( mSocket ); | 1327 | QTextStream os2( mSocket ); |
1316 | os2.setEncoding( QTextStream::Latin1 ); | 1328 | os2.setEncoding( QTextStream::Latin1 ); |
1317 | os2 << "STOP\r\n"; | 1329 | os2 << "STOP\r\n"; |
1318 | mSocket->close(); | 1330 | mSocket->close(); |