summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp236
-rw-r--r--korganizer/mainwindow.h13
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
@@ -29,98 +29,96 @@
#else
#include <qmenubar.h>
#include <qtoolbar.h>
#include <qapplication.h>
//#include <resource.h>
#endif
#include <libkcal/calendarlocal.h>
#include <libkcal/todo.h>
#include <libkdepim/ksyncprofile.h>
#include <libkcal/kincidenceformatter.h>
#include <libkdepim/kpimglobalprefs.h>
#include "calendarview.h"
#include "koviewmanager.h"
#include "datenavigator.h"
#include "koagendaview.h"
#include "koagenda.h"
#include "kodialogmanager.h"
#include "kdialogbase.h"
#include "kapplication.h"
#include "kofilterview.h"
#include "kstandarddirs.h"
#include "koprefs.h"
#include "kfiledialog.h"
#include "koglobals.h"
#include "kglobal.h"
#include "klocale.h"
#include "kconfig.h"
#include "simplealarmclient.h"
#include "externalapphandler.h"
using namespace KCal;
#ifndef _WIN32_
#include <unistd.h>
#else
#include "koimportoldialog.h"
#endif
#include "mainwindow.h"
int globalFlagBlockStartup;
MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
QMainWindow( parent, name )
{
mPassWordPiSync = "abc";
#ifdef DESKTOP_VERSION
setFont( QFont("Arial"), 14 );
#endif
- mCommandSocket = 0;
- mCommandSocketFinish = 0;
mSyncActionDialog = 0;
mServerSocket = 0;
mClosed = false;
//QString confFile = KStandardDirs::appDir() + "config/korganizerrc";
QString confFile = locateLocal("config","korganizerrc");
QFileInfo finf ( confFile );
bool showWarning = !finf.exists();
setIcon(SmallIcon( "ko24" ) );
mBlockAtStartup = true;
mFlagKeyPressed = false;
setCaption("KOrganizer/Pi");
KOPrefs *p = KOPrefs::instance();
KPimGlobalPrefs::instance()->setGlobalConfig();
// if ( QApplication::desktop()->height() > 480 ) {
// if ( p->mHourSize == 4 )
// p->mHourSize = 6;
// }
if ( p->mHourSize > 18 )
p->mHourSize = 18;
QMainWindow::ToolBarDock tbd;
if ( p->mToolBarHor ) {
if ( p->mToolBarUp )
tbd = Bottom;
else
tbd = Top;
}
else {
if ( p->mToolBarUp )
tbd = Right;
else
tbd = Left;
}
if ( KOPrefs::instance()->mUseAppColors )
QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
globalFlagBlockStartup = 1;
iconToolBar = new QPEToolBar( this );
addToolBar (iconToolBar , tbd );
mBlockSaveFlag = false;
mCalendarModifiedFlag = false;
QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this );
splash->setAlignment ( AlignCenter );
setCentralWidget( splash );
#ifndef DESKTOP_VERSION
showMaximized();
#endif
//qDebug("Mainwidget x %d y %d w %d h %d", x(), y(), width(), height ());
setDefaultPreferences();
@@ -1897,374 +1895,244 @@ void MainWindow::enableQuick()
lab.setText( KOPrefs::instance()->mPassiveSyncPort );
lay.setMargin(7);
lay.setSpacing(7);
QLabel label ( i18n("Port number (Default: 9197)"), &dia );
lay.addWidget( &label);
lay.addWidget( &lab);
QLineEdit lepw ( &dia );
lepw.setText( "abc" );
QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
lay.addWidget( &label2);
lay.addWidget( &lepw);
dia.setFixedSize( 230,80 );
dia.setCaption( i18n("Enter port for Pi-Sync") );
QPushButton pb ( "OK", &dia);
lay.addWidget( &pb );
connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
dia.show();
int res = dia.exec();
if ( res )
retfile = lab.text();
else
return;
dia.hide();
passWordPiSync = lepw.text();
qApp->processEvents();
KOPrefs::instance()->mPassiveSyncPort = retfile;
bool ok;
Q_UINT16 port = retfile.toUInt(&ok);
if ( ! ok ) {
KMessageBox::information( this, i18n("No valid port"));
return;
}
qDebug("port %d ", port);
mServerSocket = new KServerSocket ( passWordPiSync, port ,1 );
mServerSocket->setFileName( defaultFileName() );
qDebug("connected ");
if ( !mServerSocket->ok() ) {
qWarning("Failed to bind to port %d", port);
delete mServerSocket;
mServerSocket = 0;
return;
}
connect( mServerSocket, SIGNAL ( saveFile() ), this, SLOT ( save() ) );
connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SLOT ( getFile( bool ) ) );
// connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) );
//connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) );
}
-void MainWindow::sendFile(QSocket* socket)
-{
- setCaption( i18n("Received request for file") );
- qDebug("MainWindow::sendFile(QSocket* s) ");
- if ( mSyncActionDialog )
- delete mSyncActionDialog;
- mSyncActionDialog = new QDialog ( this, "input-dialog", true );
- mSyncActionDialog->setCaption(i18n("KO/Pi - WARNING"));
- QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use\nthis application!\n"), mSyncActionDialog );
- QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
- lay->addWidget( label);
- lay->setMargin(7);
- lay->setSpacing(7);
- mSyncActionDialog->setFixedSize( 200,100 );
- mSyncActionDialog->show();
- qDebug("saving ... ");
- save();
- qApp->processEvents();
- QString fileName = defaultFileName();
- QFile file( fileName );
- if (!file.open( IO_ReadOnly ) ) {
- setCaption( i18n("Error open file") );
- delete mSyncActionDialog;
- mSyncActionDialog = 0;
- qDebug("error open cal file ");
- return ;
-
- }
- setCaption( i18n("Sending file...") );
- QTextStream ts( &file );
- ts.setCodec( QTextCodec::codecForName("utf8") );
- QTextStream os( socket );
- os.setCodec( QTextCodec::codecForName("utf8") );
- //os.setEncoding( QTextStream::UnicodeUTF8 );
- while ( ! ts.atEnd() ) {
- os << ts.readLine() << "\n";
- }
- //os << ts.read();
- socket->close();
- file.close();
- setCaption( i18n("File sent. Waiting to get back synced file") );
- qDebug("file sent ");
-}
+
void MainWindow::getFile( bool success )
{
if ( ! success ) {
setCaption( i18n("Error receiving file. Nothing changed!") );
return;
}
// pending adjust time for watchSavedFile()
//mView->watchSavedFile();
mView->openCalendar( defaultFileName() );
setCaption( i18n("Pi-Sync successful!") );
-
-#if 0
- setCaption( i18n("Receiving synced file...") );
-
- piTime.start();
- piSocket = socket;
- piFileString = "";
- QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
-#endif
-
}
-void MainWindow::readBackFileFromSocket()
-{
- qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
- while ( piSocket->canReadLine () ) {
- piTime.restart();
- QString line = piSocket->readLine ();
- piFileString += line;
- qDebug("readline: %s ", line.latin1());
- setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
- }
- if ( piTime.elapsed () < 3000 ) {
- // wait for more
- qDebug("waitformore ");
- QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
- return;
- }
- QString fileName = defaultFileName();
- QFile file ( fileName );
- if (!file.open( IO_WriteOnly ) ) {
- setCaption( i18n("Error open file for writing!") );
- delete mSyncActionDialog;
- mSyncActionDialog = 0;
- qDebug("error open cal file ");
- piFileString = "";
- return ;
-
- }
-
- mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
- QTextStream ts ( &file );
- ts.setCodec( QTextCodec::codecForName("utf8") );
- qDebug("finish ");
- setCaption( i18n("Writing file to disk...") );
- ts << piFileString;
- setCaption( i18n("File received - reloading calendar...") );
- piSocket->close();
- file.close();
- mView->watchSavedFile();
- mView->openCalendar( defaultFileName() );
- setCaption( i18n("Pi-Sync successful!") );
- delete mSyncActionDialog;
- mSyncActionDialog = 0;
- piFileString = "";
-
-}
-void MainWindow::endConnect()
-{
- setCaption( i18n("No file received - syncing successful") );
- delete mSyncActionDialog;
- mSyncActionDialog = 0;
-}
void MainWindow::performQuick()
{
setCaption( i18n("Please input connection settings") );
QString retfile = "";
QDialog dia ( this, "input-dialog", true );
QLineEdit lab ( &dia );
QVBoxLayout lay( &dia );
QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia );
lay.addWidget( &label);
lab.setText( KOPrefs::instance()->mActiveSyncIP );
lay.setMargin(7);
lay.setSpacing(7);
lay.addWidget( &lab);
QLabel label2 ( i18n("Port number (Default: 9197)"), &dia );
lay.addWidget( &label2);
QLineEdit lab2 ( &dia );
lab2.setText( KOPrefs::instance()->mActiveSyncPort );
lay.addWidget( &lab2);
QLineEdit lepw ( &dia );
lepw.setText( mPassWordPiSync );
QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia );
lay.addWidget( &label3);
lay.addWidget( &lepw);
dia.setFixedSize( 230,200 );
dia.setCaption( i18n("Enter port for Pi-Sync ") );
QPushButton pb ( "OK", &dia);
lay.addWidget( &pb );
connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
dia.show();
int res = dia.exec();
if ( !res ) {
setCaption( i18n("Syncing cancelled!") );
return;
}
mPassWordPiSync = lepw.text();
dia.hide();
KOPrefs::instance()->mActiveSyncPort = lab2.text();
KOPrefs::instance()->mActiveSyncIP = lab.text();
qApp->processEvents();
performQuickQuick();
}
void MainWindow::performQuickQuick()
{
// setCaption( i18n("") );
bool ok;
Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok);
if ( ! ok ) {
setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
return;
}
- mCommandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this );
- connect( mCommandSocket, SIGNAL(commandFinished( bool )), this, SLOT(deleteCommandSocket(bool)) );
+ KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this );
+ connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocket(KCommandSocket*,bool)) );
setCaption( i18n("Sending request for remote file ...") );
QString fileName;
#ifdef _WIN32_
fileName = defaultFileName() +"sync";
#else
fileName = "/tmp/kopitempfile.ics";
#endif
- mCommandSocket->readFile( fileName );
+ commandSocket->readFile( fileName );
}
-void MainWindow::deleteCommandSocket( bool success)
+void MainWindow::deleteCommandSocket(KCommandSocket*s, bool success)
{
if ( ! success ) {
setCaption( i18n("ERROR:Receiving remote file failed.") );
+ delete s;
// pending : send stop
return;
}
QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
- delete mCommandSocket;
+ qDebug("MainWindow::deleteCommandSocket ");
+ delete s;
}
-void MainWindow::deleteCommandSocketFinish()
+void MainWindow::deleteCommandSocketFinish(KCommandSocket* s, bool success )
{
- if ( ! mCommandSocketFinish)
- return;
- // KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() "));
- qDebug("MainWindow::deletemCommandSocketFinish() ");
- delete mCommandSocketFinish;
- mCommandSocketFinish = 0;
+ if ( ! success ) {
+ setCaption( i18n("ERROR:Writing back file failed.") );
+ } else {
+ qDebug("Syncing succesful! ");
+ setCaption( i18n("Pi-Sync succesful!") );
+ }
+ qDebug("MainWindow::deleteCommandSocketFinish ");
+ delete s;
}
void MainWindow::readFileFromSocket()
{
// mTimerCommandSocket->stop();
setCaption( i18n("Receiving remote file ...") );
qDebug("MainWindow::readFileFromSocket() ");
QString fileName;
#ifdef _WIN32_
fileName = defaultFileName() +"sync";
#else
fileName = "/tmp/kopitempfile.ics";
#endif
setCaption( i18n("Remote file saved to temp file.") );
//mCommandSocket = 0;
mCurrentSyncProfile = 2 ; // last file
mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] );
mView->setSyncName( KOPrefs::instance()->mLocalMachineName );
KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
KSyncProfile* temp = new KSyncProfile ();
temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
temp->readConfig(&config);
KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
KOPrefs::instance()->mWriteBackInFuture = 0;
if ( temp->getWriteBackFuture() )
KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
delete temp;
setCaption( i18n("Remote file saved to temp file.") );
if ( ! syncWithFile( fileName , true ) ) {
setCaption( i18n("Syncing failed.") );
qDebug("Syncing failed ");
return;
}
- if ( !mCommandSocketFinish ) {
- mCommandSocketFinish = new QSocket( this );
- connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) );
- }
- mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() );
-
- QString host = KOPrefs::instance()->mActiveSyncIP;
- QFile file2( fileName );
- if (!file2.open( IO_ReadOnly ) ) {
- setCaption( i18n("Error: Cannot open temp file for read.") );
- qDebug("error open cal file ");
- return ;
-
- }
- QTextStream ts2( &file2 );
- ts2.setCodec( QTextCodec::codecForName("utf8") );
- QTextStream os2( mCommandSocketFinish );
- os2.setCodec( QTextCodec::codecForName("utf8") );
- //os.setEncoding( QTextStream::UnicodeUTF8 );
- if ( KOPrefs::instance()->mWriteBackFile ) {
- setCaption( i18n("Sending back synced file...") );
- os2 << "PUT " << mPassWordPiSync << "\r\n";;
- while ( ! ts2.atEnd() ) {
- os2 << ts2.readLine() << "\n";
- }
- } else {
- os2 << "STOP\r\n";
- }
- mCommandSocketFinish->close();
- if ( mCommandSocketFinish->state() == QSocket::Idle )
- QTimer::singleShot( 10, this , SLOT ( deleteCommandSocketFinish()));
- file2.close();
- qDebug("Syncing succesful! ");
- setCaption( i18n("Pi-Sync succesful!") );
-
- // KMessageBox::information( 0, i18n(" Pi-Sync succesful! "));
-
+ KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, KOPrefs::instance()->mActiveSyncPort.toUInt(), KOPrefs::instance()->mActiveSyncIP, this );
+ connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocketFinish(KCommandSocket*,bool)) );
+ if ( KOPrefs::instance()->mWriteBackFile )
+ commandSocket->writeFile( fileName );
+ else
+ commandSocket->sendStop();
}
void MainWindow::syncLocalFile()
{
QString fn =KOPrefs::instance()->mLastSyncedLocalFile;
fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
if ( fn == "" )
return;
//mView->setSyncDevice("local-file" );
if ( syncWithFile( fn, false ) ) {
// Event* e = mView->getLastSyncEvent();
// e->setReadOnly( false );
// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile);
// e->setReadOnly( true );
}
}
bool MainWindow::syncWithFile( QString fn , bool quick )
{
bool ret = false;
QFileInfo info;
info.setFile( fn );
QString mess;
bool loadbup = true;
if ( !info. exists() ) {
mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
mess );
return ret;
}
int result = 0;
if ( !quick ) {
mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
mess,
i18n("Sync"), i18n("Cancel"), 0,
0, 1 );
if ( result )
return false;
}
if ( KOPrefs::instance()->mAskForPreferences )
mView->edit_sync_options();
if ( result == 0 ) {
//qDebug("Now sycing ... ");
if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) )
@@ -2515,101 +2383,106 @@ void KServerSocket::newConnection ( int socket )
delete mSocket;
mSocket = 0;
}
mSocket = new QSocket( this );
connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
mSocket->setSocket( socket );
}
void KServerSocket::discardClient()
{
qDebug(" KServerSocket::discardClient()");
if ( mSocket ) {
qDebug("delete ");
delete mSocket;
mSocket = 0;
}
//emit endConnect();
}
void KServerSocket::readClient()
{
if ( mSocket == 0 ) {
qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
return;
}
qDebug("KServerSocket readClient()");
if ( mSocket->canReadLine() ) {
QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() );
qDebug("KServerSocket socket->canReadLine()");
if ( tokens[0] == "GET" ) {
if ( tokens[1] == mPassWord )
//emit sendFile( mSocket );
send_file();
else {
KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password"));
qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
}
}
if ( tokens[0] == "PUT" ) {
if ( tokens[1] == mPassWord )
//emit getFile( mSocket );
get_file();
else {
KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password"));
qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
}
}
if ( tokens[0] == "STOP" ) {
- emit endConnect();
+ //emit endConnect();
+ end_connect();
}
}
}
-
+void KServerSocket::end_connect()
+{
+ delete mSyncActionDialog;
+ mSyncActionDialog = 0;
+}
void KServerSocket::send_file()
{
qDebug("MainWindow::sendFile(QSocket* s) ");
if ( mSyncActionDialog )
delete mSyncActionDialog;
mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
mSyncActionDialog->setCaption(i18n("Received sync request"));
QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use this application!\n\nIf syncing fails you can close this dialog."), mSyncActionDialog );
QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
lay->addWidget( label);
lay->setMargin(7);
lay->setSpacing(7);
mSyncActionDialog->setFixedSize( 230, 120);
mSyncActionDialog->show();
qDebug("KSS::saving ... ");
emit saveFile();
qApp->processEvents();
QString fileName = mFileName;
QFile file( fileName );
if (!file.open( IO_ReadOnly ) ) {
delete mSyncActionDialog;
mSyncActionDialog = 0;
qDebug("KSS::error open file ");
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( discardClient()));
return ;
}
mSyncActionDialog->setCaption( i18n("Sending file...") );
QTextStream ts( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
QTextStream os( mSocket );
os.setCodec( QTextCodec::codecForName("utf8") );
//os.setEncoding( QTextStream::UnicodeUTF8 );
while ( ! ts.atEnd() ) {
os << ts.readLine() << "\n";
}
//os << ts.read();
file.close();
mSyncActionDialog->setCaption( i18n("Waiting to get back synced file") );
qDebug("file sent ");
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( discardClient()));
}
void KServerSocket::get_file()
{
@@ -2650,118 +2523,155 @@ void KServerSocket::readBackFileFromSocket()
}
// mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
QTextStream ts ( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
qDebug("finish ");
mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
ts << piFileString;
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( discardClient()));
file.close();
delete mSyncActionDialog;
mSyncActionDialog = 0;
piFileString = "";
emit file_received( true );
}
KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
{
mPassWord = password;
mSocket = 0;
mPort = port;
mHost = host;
mRetVal = false;
mTimerSocket = new QTimer ( this );
connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
}
void KCommandSocket::readFile( QString fn )
{
if ( !mSocket ) {
mSocket = new QSocket( this );
connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
}
mFileString = "";
mFileName = fn;
mFirst = true;
mSocket->connectToHost( mHost, mPort );
QTextStream os( mSocket );
os.setEncoding( QTextStream::UnicodeUTF8 );
os << "GET " << mPassWord << "\r\n";
mTimerSocket->start( 10000 );
}
-void KCommandSocket::writeFile( QString )
+void KCommandSocket::writeFile( QString fileName )
{
+ QFile file2( fileName );
+ if (!file2.open( IO_ReadOnly ) ) {
+ mRetVal= false;
+ deleteSocket();
+ return ;
+
+ }
+ if ( !mSocket ) {
+ mSocket = new QSocket( this );
+ connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
+ }
+ QTextStream ts2( &file2 );
+ ts2.setCodec( QTextCodec::codecForName("utf8") );
+ QTextStream os2( mSocket );
+ os2.setCodec( QTextCodec::codecForName("utf8") );
+ os2 << "PUT " << mPassWord << "\r\n";;
+ while ( ! ts2.atEnd() ) {
+ os2 << ts2.readLine() << "\n";
+ }
+ mSocket->close();
+ if ( mSocket->state() == QSocket::Idle )
+ QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
+ file2.close();
+}
+void KCommandSocket::sendStop()
+{
+ if ( !mSocket ) {
+ mSocket = new QSocket( this );
+ connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
+ }
+ QTextStream os2( mSocket );
+ os2.setCodec( QTextCodec::codecForName("utf8") );
+ os2 << "STOP\r\n";
+ mRetVal= true;
+ mSocket->close();
+ if ( mSocket->state() == QSocket::Idle )
+ QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
}
+
void KCommandSocket::startReadFileFromSocket()
{
if ( ! mFirst )
return;
mFirst = false;
mTimerSocket->stop();
mFileString = "";
mTime.start();
QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
}
void KCommandSocket::readFileFromSocket()
{
qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
while ( mSocket->canReadLine () ) {
mTime.restart();
QString line = mSocket->readLine ();
mFileString += line;
qDebug("readline: %s ", line.latin1());
}
if ( mTime.elapsed () < 3000 ) {
// wait for more
qDebug("waitformore ");
QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
return;
}
QString fileName = mFileName;
QFile file ( fileName );
if (!file.open( IO_WriteOnly ) ) {
mFileString = "";
mRetVal = false;
qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
deleteSocket();
return ;
}
// mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
QTextStream ts ( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
qDebug("finish ");
ts << mFileString;
file.close();
mFileString = "";
mRetVal = true;
mSocket->close();
// if state is not idle, deleteSocket(); is called via
// connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
if ( mSocket->state() == QSocket::Idle )
deleteSocket();
}
void KCommandSocket::deleteSocket()
{
- if ( !mSocket)
- return;
if ( mTimerSocket->isActive () ) {
mTimerSocket->stop();
KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
mRetVal = false;
}
- qDebug("KCommandSocket::deleteSocket() %d", mRetVal);
- delete mSocket;
+ qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
+ if ( mSocket)
+ delete mSocket;
mSocket = 0;
- emit commandFinished( mRetVal );
+ emit commandFinished( this, mRetVal );
}
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index 8b76067..5a67765 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -4,209 +4,206 @@
#include <qmainwindow.h>
#include <qtimer.h>
#include <qdict.h>
#include <qfile.h>
#include <qsocket.h>
#include <qtextstream.h>
#include <qregexp.h>
#include <libkcal/incidence.h>
#include "simplealarmclient.h"
class QAction;
class CalendarView;
class KSyncProfile;
#ifdef DESKTOP_VERSION
#define QPEToolBar QToolBar
#define QPEMenuBar QMenuBar
#endif
class QPEToolBar;
#include <qserversocket.h>
#include <qsocket.h>
#include <qnetworkprotocol.h>
class KServerSocket : public QServerSocket
{
Q_OBJECT
public:
KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 );
void newConnection ( int socket ) ;
void setFileName( QString fn ) {mFileName = fn;};
signals:
//void sendFile(QSocket*);
//void getFile(QSocket*);
void file_received( bool );
//void file_sent();
void saveFile();
void endConnect();
private slots:
void discardClient();
void readClient();
void readBackFileFromSocket();
private :
void send_file();
void get_file();
+ void end_connect();
QDialog* mSyncActionDialog;
QSocket* mSocket;
QString mPassWord;
QString mFileName;
QTime piTime;
QString piFileString;
};
class KCommandSocket : public QObject
{
Q_OBJECT
public:
KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
void readFile( QString );
void writeFile( QString );
+ void sendStop();
signals:
- void commandFinished( bool );
+ void commandFinished( KCommandSocket*, bool );
private slots:
void startReadFileFromSocket();
void readFileFromSocket();
void deleteSocket();
private :
QSocket* mSocket;
QString mPassWord;
Q_UINT16 mPort;
QString mHost;
QString mFileName;
QTimer* mTimerSocket;
bool mRetVal;
QTime mTime;
QString mFileString;
bool mFirst;
};
namespace KCal {
class CalendarLocal;
}
using namespace KCal;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget *parent = 0, const char *name = 0, QString command = "");
~MainWindow();
public slots:
virtual void showMaximized ();
void configureAgenda( int );
void recieve( const QCString& msg, const QByteArray& data );
static QString defaultFileName();
static QString resourcePath();
protected slots:
void setCaptionToDates();
int ringSync();
void multiSync( bool askforPrefs = false );
void about();
void licence();
void faq();
void usertrans();
void features();
void synchowto();
void whatsNew();
void keyBindings();
void aboutAutoSaving();;
void aboutKnownBugs();
void processIncidenceSelection( Incidence * );
void importQtopia();
void importBday();
void importOL();
void importIcal();
void importFile( QString, bool );
void quickImportIcal();
void slotModifiedChanged( bool );
void save();
void configureToolBar( int );
void printSel();
void printCal();
void saveCalendar();
void loadCalendar();
void exportVCalendar();
void fillFilterMenu();
void selectFilter( int );
void slotSyncMenu( int );
void syncSSH();
void confSync();
void syncSharp();
void syncPhone();
void syncLocalFile();
bool syncWithFile( QString, bool );
void quickSyncLocalFile();
protected:
void displayText( QString, QString);
void displayFile( QString, QString);
void enableIncidenceActions( bool );
private slots:
QSocket* piSocket;
QString piFileString;
QTime piTime;
- void deleteCommandSocket(bool);
- void deleteCommandSocketFinish();
+ void deleteCommandSocket(KCommandSocket* s, bool success);
+ void deleteCommandSocketFinish(KCommandSocket* s, bool success);
void fillSyncMenu();
- void sendFile(QSocket* s);
void getFile( bool );
void readFileFromSocket();
- void readBackFileFromSocket();
- void endConnect();
private:
//QTimer* mTimerCommandSocket;
QString mPassWordPiSync;
- KCommandSocket* mCommandSocket;
- QSocket* mCommandSocketFinish;
KServerSocket * mServerSocket;
bool mClosed;
void saveOnClose();
int mCurrentSyncProfile;
void enableQuick();
void performQuick();
void performQuickQuick();
void syncRemote( KSyncProfile* , bool ask = true);
bool mFlagKeyPressed;
bool mBlockAtStartup;
QPEToolBar *iconToolBar;
void initActions();
void setDefaultPreferences();
void keyPressEvent ( QKeyEvent * ) ;
void keyReleaseEvent ( QKeyEvent * ) ;
QPopupMenu *configureToolBarMenu;
QPopupMenu *selectFilterMenu;
QPopupMenu *configureAgendaMenu, *syncMenu;
CalendarLocal *mCalendar;
CalendarView *mView;
QString getPassword();
QAction *mNewSubTodoAction;
QAction *mShowAction;
QAction *mEditAction;
QAction *mDeleteAction;
void closeEvent( QCloseEvent* ce );
SimpleAlarmClient mAlarmClient;
QTimer mSaveTimer;
bool mBlockSaveFlag;
bool mCalendarModifiedFlag;
QPixmap loadPixmap( QString );
QDialog * mSyncActionDialog;
};
#endif