summaryrefslogtreecommitdiffabout
path: root/korganizer
Side-by-side diff
Diffstat (limited to 'korganizer') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp94
-rw-r--r--korganizer/mainwindow.h2
2 files changed, 27 insertions, 69 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index bce2a54..fe7e6d3 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -863,27 +863,24 @@ void MainWindow::initActions()
void MainWindow::fillSyncMenu()
{
if ( syncMenu->count() )
syncMenu->clear();
syncMenu->insertItem( i18n("Configure..."), 0 );
syncMenu->insertSeparator();
if ( mServerSocket == 0 ) {
syncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
} else {
syncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
}
syncMenu->insertSeparator();
- syncMenu->insertItem( i18n("New Pi-Sync!"), 4 );
- syncMenu->insertItem( i18n("Quick Pi-Sync!"), 5 );
- syncMenu->insertSeparator();
syncMenu->insertItem( i18n("Multiple sync"), 1 );
syncMenu->insertSeparator();
KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
config.setGroup("General");
QStringList prof = config.readListEntry("SyncProfileNames");
KOPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined");
if ( prof.count() < 3 ) {
prof.clear();
prof << i18n("Sharp_DTM");
prof << i18n("Local_file");
prof << i18n("Last_file");
KSyncProfile* temp = new KSyncProfile ();
@@ -943,24 +940,29 @@ int MainWindow::ringSync()
if ( i == 0 ) {
syncSharp();
} else {
if ( temp->getIsLocalFileSync() ) {
if ( syncWithFile( temp->getRemoteFileName( ), true ) )
KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName();
} else {
if ( temp->getIsPhoneSync() ) {
KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
syncPhone();
+ } else if ( temp->getIsPiSync() ) {
+ mPassWordPiSync = temp->getRemotePw();
+ KOPrefs::instance()->mActiveSyncPort = temp->getRemotePort();
+ KOPrefs::instance()->mActiveSyncIP = temp->getRemoteIP();
+ syncPi();
} else
syncRemote( temp, false );
}
}
timer.start();
setCaption(i18n("Multiple sync in progress ... please wait!") );
while ( timer.elapsed () < 2000 ) {
qApp->processEvents();
#ifndef _WIN32_
sleep (1);
#endif
@@ -1027,32 +1029,24 @@ void MainWindow::slotSyncMenu( int action )
}
if ( action == 2 ) {
enableQuick();
QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
return;
}
if ( action == 3 ) {
delete mServerSocket;
mServerSocket = 0;
QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
return;
}
- if ( action == 4 ) {
- performQuick();
- return;
- }
- if ( action == 5 ) {
- performQuickQuick();
- return;
- }
if (mBlockSaveFlag)
return;
mBlockSaveFlag = true;
mCurrentSyncProfile = action - 1000 ;
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();
@@ -1073,24 +1067,29 @@ void MainWindow::slotSyncMenu( int action )
quickSyncLocalFile();
} else if ( action >= 1003 ) {
if ( temp->getIsLocalFileSync() ) {
if ( syncWithFile( temp->getRemoteFileName( ), false ) )
KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName();
} else {
if ( temp->getIsPhoneSync() ) {
KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
syncPhone();
+ } else if ( temp->getIsPiSync() ) {
+ mPassWordPiSync = temp->getRemotePw();
+ KOPrefs::instance()->mActiveSyncPort = temp->getRemotePort();
+ KOPrefs::instance()->mActiveSyncIP = temp->getRemoteIP();
+ syncPi();
} else
syncRemote( temp );
}
}
delete temp;
mBlockSaveFlag = false;
}
void MainWindow::setDefaultPreferences()
{
KOPrefs *p = KOPrefs::instance();
@@ -1946,65 +1945,26 @@ 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!") );
}
-void MainWindow::performQuick()
+void MainWindow::syncPi()
{
-
- 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.") );
@@ -2368,56 +2328,54 @@ void MainWindow::printCal()
KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
{
mPassWord = pw;
mSocket = 0;
mSyncActionDialog = 0;
};
void KServerSocket::newConnection ( int socket )
{
- qDebug("KServerSocket:New connection %d ", socket);
+ // qDebug("KServerSocket:New connection %d ", socket);
if ( mSocket ) {
qDebug("KServerSocket::newConnection Socket deleted! ");
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()");
+ //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()");
+ //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 );
@@ -2431,25 +2389,25 @@ void KServerSocket::readClient()
//emit endConnect();
end_connect();
}
}
}
void KServerSocket::end_connect()
{
delete mSyncActionDialog;
mSyncActionDialog = 0;
}
void KServerSocket::send_file()
{
- qDebug("MainWindow::sendFile(QSocket* s) ");
+ //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 ... ");
@@ -2469,73 +2427,71 @@ void KServerSocket::send_file()
}
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 ");
+ mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( discardClient()));
}
void KServerSocket::get_file()
{
mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
piTime.start();
piFileString = "";
QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
}
void KServerSocket::readBackFileFromSocket()
{
- qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
+ //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
while ( mSocket->canReadLine () ) {
piTime.restart();
QString line = mSocket->readLine ();
piFileString += line;
- qDebug("readline: %s ", line.latin1());
+ //qDebug("readline: %s ", line.latin1());
mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
}
if ( piTime.elapsed () < 3000 ) {
// wait for more
- qDebug("waitformore ");
+ //qDebug("waitformore ");
QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
return;
}
QString fileName = mFileName;
QFile file ( fileName );
if (!file.open( IO_WriteOnly ) ) {
delete mSyncActionDialog;
mSyncActionDialog = 0;
qDebug("error open cal file ");
piFileString = "";
emit file_received( false );
return ;
}
// 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 );
}
@@ -2572,106 +2528,108 @@ 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()) );
}
+ mSocket->connectToHost( mHost, mPort );
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";
}
+ mRetVal= true;
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()) );
}
+ mSocket->connectToHost( mHost, mPort );
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 ());
+ //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
while ( mSocket->canReadLine () ) {
mTime.restart();
QString line = mSocket->readLine ();
mFileString += line;
- qDebug("readline: %s ", line.latin1());
+ //qDebug("readline: %s ", line.latin1());
}
if ( mTime.elapsed () < 3000 ) {
// wait for more
- qDebug("waitformore ");
+ //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 ( 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 );
+ //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
if ( mSocket)
delete mSocket;
mSocket = 0;
emit commandFinished( this, mRetVal );
}
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index 5a67765..f8b2334 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -138,24 +138,25 @@ class MainWindow : public QMainWindow
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 syncPi();
void syncLocalFile();
bool syncWithFile( QString, bool );
void quickSyncLocalFile();
protected:
void displayText( QString, QString);
void displayFile( QString, QString);
void enableIncidenceActions( bool );
private slots:
@@ -166,25 +167,24 @@ class MainWindow : public QMainWindow
void deleteCommandSocketFinish(KCommandSocket* s, bool success);
void fillSyncMenu();
void getFile( bool );
void readFileFromSocket();
private:
//QTimer* mTimerCommandSocket;
QString mPassWordPiSync;
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;