summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koprefs.cpp5
-rw-r--r--korganizer/koprefs.h4
-rw-r--r--korganizer/mainwindow.cpp317
-rw-r--r--korganizer/mainwindow.h65
4 files changed, 386 insertions, 5 deletions
diff --git a/korganizer/koprefs.cpp b/korganizer/koprefs.cpp
index 5d7db4f..0034715 100644
--- a/korganizer/koprefs.cpp
+++ b/korganizer/koprefs.cpp
@@ -168,49 +168,52 @@ KOPrefs::KOPrefs() :
// qDebug(" KPrefs::setCurrentGroup(Fonts); ");
addItemFont("TimeBar Font",&mTimeBarFont);
addItemFont("MonthView Font",&mMonthViewFont);
addItemFont("AgendaView Font",&mAgendaViewFont);
addItemFont("MarcusBains Font",&mMarcusBainsFont);
addItemFont("TimeLabels Font",&mTimeLabelsFont);
addItemFont("TodoView Font",&mTodoViewFont);
addItemFont("ListView Font",&mListViewFont);
addItemFont("DateNavigator Font",&mDateNavigatorFont);
addItemFont("EditBox Font",&mEditBoxFont);
addItemFont("JournalView Font",&mJornalViewFont);
addItemFont("WhatsNextView Font",&mWhatsNextFont);
addItemFont("EventView Font",&mEventViewFont);
// KPrefs::setCurrentGroup("SyncProfiles");
// addItemString("LocalMachineName",&mLocalMachineName, "undefined");
// addItemStringList("SyncProfileNames",&mSyncProfileNames);
// addItemStringList("ExternSyncProfiles",&mExternSyncProfileNames);
KPrefs::setCurrentGroup("RemoteSyncing");
// addItemBool("UsePasswd",&mUsePassWd,false);
// addItemBool("WriteBackFile",&mWriteBackFile,true);
// addItemBool("WriteBackExistingOnly",&mWriteBackExistingOnly,false);
// addItemBool("AskForPreferences",&mAskForPreferences,true);
-// addItemBool("ShowSyncSummary",&mShowSyncSummary,true);
+// addItemBool("ShowSyncSummary",&mShowSyncSummary,true);
+ addItemString("PassiveSyncPort",&mPassiveSyncPort,"9197" );
+ addItemString("ActiveSyncPort",&mActiveSyncPort,"9197" );
+ addItemString("ActiveSyncIP",&mActiveSyncIP,"192.168.0.40" );
addItemBool("ShowSyncEvents",&mShowSyncEvents,false);
addItemInt("LastSyncTime",&mLastSyncTime,0);
addItemInt("SyncAlgoPrefs",&mSyncAlgoPrefs,3);
addItemInt("RingSyncAlgoPrefs",&mRingSyncAlgoPrefs,3);
#ifdef _WIN32_
QString hdp= locateLocal("data","korganizer")+"\\\\";
#else
QString hdp= locateLocal("data","korganizer")+"/";
#endif
// addItemString("RemoteIP",&mRemoteIP, "192.168.0.65");
// addItemString("RemoteUser",&mRemoteUser, "zaurus");
// addItemString("RemotePassWd",&mRemotePassWd, "");
// addItemString("RemoteFile", &mRemoteFile, hdp+"mycalendar.ics");
// addItemString("LocalTempFile",&mLocalTempFile, "/tmp/tempsyncfile.ics" );
KPrefs::setCurrentGroup("LoadSaveFileNames");
addItemString("LastImportFile", &mLastImportFile ,hdp +"import.ics" );
addItemString("LastVcalFile", &mLastVcalFile ,hdp +"export.vcs" );
addItemString("LastSaveFile", &mLastSaveFile ,hdp +"mybackup.ics" );
addItemString("LastLoadFile", &mLastLoadFile ,hdp +"mybackup.ics" );
addItemString("LastSyncedLocalFile", &mLastSyncedLocalFile ,hdp +"lastsync.ics" );
diff --git a/korganizer/koprefs.h b/korganizer/koprefs.h
index 33eda60..696433e 100644
--- a/korganizer/koprefs.h
+++ b/korganizer/koprefs.h
@@ -258,48 +258,52 @@ class KOPrefs : public KPimPrefs
bool mUseHighlightLightColor;
bool mListViewMonthTimespan;
bool mWNViewShowsParents;
bool mWNViewShowLocation;
bool mTodoViewShowsPercentage;
bool mTodoViewUsesCatColors;
bool mTodoViewUsesSmallFont;
bool mTodoViewUsesForegroundColor;
bool mMonthViewUsesForegroundColor;
bool mHightlightDateTimeEdit;
bool mUseQuicksave;
bool mShortDateInViewer;
QStringList mLocationDefaults;
QStringList mEventSummaryUser;
QStringList mTodoSummaryUser;
bool mUseInternalAlarmNotification;
int mAlarmPlayBeeps;
int mAlarmSuspendTime;
int mAlarmSuspendCount;
int mAlarmBeepInterval;
+ QString mPassiveSyncPort;
+ QString mActiveSyncPort;
+ QString mActiveSyncIP;
+
//US I copied the following settings into KPimGlobalPrefs
// that allows us later to easily remove the settings from here.
int mPreferredDate;
QString mUserDateFormatLong;
QString mUserDateFormatShort;
int mPreferredLanguage;
int mPreferredTime;
bool mWeekStartsOnSunday;
QString mTimeZoneId;
bool mUseDaylightsaving;
int mDaylightsavingStart;
int mDaylightsavingEnd;
private:
QDict<QColor> mCategoryColors;
QColor mDefaultCategoryColor;
QFont mDefaultTimeBarFont;
QFont mDefaultViewFont;
QFont mDefaultMonthViewFont;
QString mName;
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 6315c64..f2e1bf8 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -1,32 +1,33 @@
#include <stdlib.h>
#include <qaction.h>
#include <qpopupmenu.h>
#include <qpainter.h>
#include <qwhatsthis.h>
#include <qmessagebox.h>
#include <qlineedit.h>
+#include <qtextcodec.h>
#include <qfile.h>
#include <qdir.h>
#include <qapp.h>
#include <qfileinfo.h>
#include <qlabel.h>
#include <qmap.h>
#include <qwmatrix.h>
#include <qtextbrowser.h>
#include <qtextstream.h>
#ifndef DESKTOP_VERSION
#include <qpe/global.h>
#include <qpe/qpemenubar.h>
#include <qpe/qpetoolbar.h>
#include <qpe/resource.h>
#include <qpe/qpeapplication.h>
#include <qtopia/alarmserver.h>
#include <qtopia/qcopenvelope_qws.h>
#else
#include <qmenubar.h>
#include <qtoolbar.h>
#include <qapplication.h>
//#include <resource.h>
#endif
@@ -50,49 +51,51 @@
#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 )
{
#ifdef DESKTOP_VERSION
setFont( QFont("Arial"), 14 );
#endif
-
+ mCommandSocket = 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;
}
@@ -192,49 +195,49 @@ MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
mView->show();
delete splash;
if ( newFile )
mView->updateConfig();
// qApp->processEvents();
//qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ());
fillSyncMenu();
mView->viewManager()->agendaView()->setStartHour( KOPrefs::instance()->mDayBegins );
if ( showWarning ) {
KMessageBox::information( this,
"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");
qApp->processEvents();
mView->dialogManager()->showSyncOptions();
}
//US listen for result adressed from Ka/Pi
#ifndef DESKTOP_VERSION
connect(qApp, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & )));
#endif
}
MainWindow::~MainWindow()
{
//qDebug("MainWindow::~MainWindow() ");
//save toolbar location
-
+ delete mServerSocket;
delete mCalendar;
delete KOPrefs::instance();
delete KIncidenceFormatter::instance();
}
void MainWindow::showMaximized ()
{
#ifndef DESKTOP_VERSION
if ( ! globalFlagBlockStartup )
if ( mClosed )
mView->goToday();
#endif
QWidget::showMaximized () ;
mClosed = false;
}
void MainWindow::closeEvent( QCloseEvent* ce )
{
if ( ! KOPrefs::instance()->mAskForQuit ) {
saveOnClose();
mClosed = true;
@@ -841,48 +844,57 @@ void MainWindow::initActions()
configureToolBarMenu->setItemChecked( 110, true );
if (p-> mShowIconJournal)
configureToolBarMenu->setItemChecked( 90, true );
if (p-> mShowIconWhatsThis)
configureToolBarMenu->setItemChecked( 300, true );
QLabel* dummy = new QLabel( iconToolBar );
dummy->setBackgroundColor( iconToolBar->backgroundColor() );
if (!p-> mShowIconStretch)
iconToolBar->setStretchableWidget ( dummy ) ;
else
configureToolBarMenu->setItemChecked( 5, true );
if (p-> mShowIconWhatsThis)
QWhatsThis::whatsThisButton ( iconToolBar );
connect( configureToolBarMenu, SIGNAL( activated( int ) ),this, SLOT(configureToolBar( int ) ) );
configureAgenda( p->mHourSize );
connect( configureAgendaMenu, SIGNAL( activated( int ) ),this, SLOT(configureAgenda( int ) ) );
}
void MainWindow::fillSyncMenu()
{
if ( syncMenu->count() )
syncMenu->clear();
syncMenu->insertItem( i18n("Configure..."), 0 );
syncMenu->insertSeparator();
+ if ( mServerSocket == 0 ) {
+ syncMenu->insertItem( i18n("Enable Easy-Pi-Sync"), 2 );
+ } else {
+ syncMenu->insertItem( i18n("Disable Easy-Pi-Sync"), 3 );
+ }
+ syncMenu->insertSeparator();
+ syncMenu->insertItem( i18n("New Easy-Pi-Sync!"), 4 );
+ syncMenu->insertItem( i18n("Quick Easy-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 ();
temp->setName( prof[0] );
temp->writeConfig(&config);
temp->setName( prof[1] );
temp->writeConfig(&config);
temp->setName( prof[2] );
temp->writeConfig(&config);
config.setGroup("General");
config.writeEntry("SyncProfileNames",prof);
config.writeEntry("ExternSyncProfiles","Sharp_DTM");
config.sync();
delete temp;
}
@@ -975,64 +987,83 @@ void MainWindow::multiSync( bool askforPrefs )
return;
}
mView->setSyncDevice(i18n("Multiple profiles") );
KOPrefs::instance()->mSyncAlgoPrefs = KOPrefs::instance()->mRingSyncAlgoPrefs;
if ( askforPrefs ) {
mView->edit_sync_options();
KOPrefs::instance()->mRingSyncAlgoPrefs = KOPrefs::instance()->mSyncAlgoPrefs;
}
setCaption(i18n("Multiple sync started.") );
qApp->processEvents();
int num = ringSync() ;
if ( num > 1 )
ringSync();
mBlockSaveFlag = false;
if ( num )
save();
if ( num )
setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) );
else
setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
return;
}
void MainWindow::slotSyncMenu( int action )
{
- //qDebug("syncaction %d ", action);
+ qDebug("syncaction %d ", action);
if ( action == 0 ) {
// seems to be a Qt2 event handling bug
// syncmenu.clear causes a segfault at first time
// when we call it after the main event loop, it is ok
// same behaviour when calling OM/Pi via QCOP for the first time
QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
//confSync();
return;
}
if ( action == 1 ) {
multiSync( true );
return;
}
+ 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();
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();
if ( action == 1000 ) {
syncSharp();
} else if ( action == 1001 ) {
syncLocalFile();
@@ -1839,48 +1870,328 @@ QString MainWindow::getPassword( )
{
QString retfile = "";
QDialog dia ( this, "input-dialog", true );
QLineEdit lab ( &dia );
lab.setEchoMode( QLineEdit::Password );
QVBoxLayout lay( &dia );
lay.setMargin(7);
lay.setSpacing(7);
lay.addWidget( &lab);
dia.setFixedSize( 230,50 );
dia.setCaption( i18n("Enter password") );
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();
dia.hide();
qApp->processEvents();
return retfile;
}
+void MainWindow::enableQuick()
+{
+ QString retfile = "";
+ QDialog dia ( this, "input-dialog", true );
+ QLineEdit lab ( &dia );
+ QVBoxLayout lay( &dia );
+ 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);
+ dia.setFixedSize( 230,80 );
+ dia.setCaption( i18n("Enter port for Easy-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();
+ qApp->processEvents();
+ KOPrefs::instance()->mPassiveSyncPort = retfile;
+ bool ok;
+ Q_UINT16 port = retfile.toUInt(&ok);
+ if ( ! ok ) {
+ qDebug("no valid port ");
+ return;
+ }
+ qDebug("port %d ", port);
+ mServerSocket = new KServerSocket ( port ,1 );
+ qDebug("connected ");
+ if ( !mServerSocket->ok() ) {
+ qWarning("Failed to bind to port %d", port);
+ delete mServerSocket;
+ mServerSocket = 0;
+ return;
+ }
+ 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) ");
+ 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();
+ qApp->processEvents();
+ qDebug("saving ... ");
+ save();
+ 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(QSocket* socket)
+{
+ setCaption( i18n("Receiving synced file...") );
+ qDebug("MainWindow::sendFile(QSocket* s) ");
+
+ QString fileName = defaultFileName();
+ QFile file( fileName );
+ if (!file.open( IO_WriteOnly ) ) {
+ setCaption( i18n("Error open file") );
+ delete mSyncActionDialog;
+ mSyncActionDialog = 0;
+ qDebug("error open cal file ");
+ return ;
+
+ }
+
+ mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
+ QTextStream ts( &file );
+ ts.setCodec( QTextCodec::codecForName("utf8") );
+ bool first = true;
+ while ( socket->canReadLine () || first ) {
+ first = false;
+ while ( socket->canReadLine () ) {
+ ts << socket->readLine ();
+ }
+ socket->waitForMore ( 5000 );
+ }
+ setCaption( i18n("File received - reloading calendar...") );
+ file.close();
+ socket->close();
+ mView->watchSavedFile();
+ mView->openCalendar( defaultFileName() );
+ setCaption( i18n("Easy-Pi-Sync successful!") );
+ delete mSyncActionDialog;
+ mSyncActionDialog = 0;
+
+
+}
+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);
+ dia.setFixedSize( 230,200 );
+ dia.setCaption( i18n("Enter port for Easy-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;
+ }
+ 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;
+ }
+ if ( mCommandSocket )
+ delete mCommandSocket;
+ mCommandSocket = new QSocket( this );
+ connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) );
+ QString host = KOPrefs::instance()->mActiveSyncIP;
+ mCommandSocket->connectToHost( host, port );
+ QTextStream os( mCommandSocket );
+ os.setEncoding( QTextStream::UnicodeUTF8 );
+ os << "GET\r\n";
+ setCaption( i18n("Sending request for remote file ...") );
+
+}
+void MainWindow::readFileFromSocket()
+{
+ setCaption( i18n("Receiving remote file ...") );
+ qDebug("MainWindow::readFileFromSocket() ");
+QString fileName;
+#ifdef _WIN32_
+ fileName = defaultFileName() +"sync";
+#else
+ fileName = "/tmp/kopitempfile.ics";
+#endif
+ QFile file( fileName );
+ if (!file.open( IO_WriteOnly ) ) {
+ setCaption( i18n("Error: Cannot open temp file for write.") );
+ qDebug("Error open calender file for writing: %s",fileName.latin1() );
+ return ;
+ }
+
+ //QTextStream os2( mCommandSocket );
+ //os2.setEncoding( QTextStream::UnicodeUTF8 );
+
+ QTextStream ts( &file );
+ ts.setCodec( QTextCodec::codecForName("utf8") );
+ bool first = true;
+ while ( mCommandSocket->canReadLine () || first) {
+ first = false;
+ while ( mCommandSocket->canReadLine () ) {
+ ts << mCommandSocket->readLine ();
+ }
+ mCommandSocket->waitForMore ( 5000 );
+ }
+ file.close();
+ mCommandSocket->close();
+ delete mCommandSocket;
+ 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();
+
+ setCaption( i18n("Remote file saved to temp file.") );
+ if ( ! syncWithFile( fileName , true ) ) {
+ setCaption( i18n("Syncing failed.") );
+ qDebug("Syncing failed ");
+ return;
+ }
+
+ mCommandSocket = new QSocket( this );
+ QString host = KOPrefs::instance()->mActiveSyncIP;
+ mCommandSocket->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() );
+
+ QFile file2( fileName );
+ if (!file2.open( IO_ReadOnly ) ) {
+ setCaption( i18n("Error: Cannot open temp file for read.") );
+ qDebug("error open cal file ");
+ return ;
+
+ }
+ setCaption( i18n("Sending back synced file...") );
+ QTextStream ts2( &file2 );
+ ts2.setCodec( QTextCodec::codecForName("utf8") );
+ QTextStream os2( mCommandSocket );
+ os2.setCodec( QTextCodec::codecForName("utf8") );
+ //os.setEncoding( QTextStream::UnicodeUTF8 );
+ if ( KOPrefs::instance()->mWriteBackFile ) {
+ os2 << "PUT\r\n";
+ while ( ! ts2.atEnd() ) {
+ os2 << ts2.readLine() << "\n";
+ }
+ } else {
+ os2 << "STOP\r\n";
+ }
+ mCommandSocket->close();
+ file.close();
+ delete mCommandSocket;
+ mCommandSocket = 0;
+ qDebug("Syncing succesful! ");
+ setCaption( i18n("Easy-Pi-Sync succesful!") );
+
+
+}
+
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;
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index 47a7a90..58081f6 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -1,43 +1,94 @@
#ifndef KORGE_MAINWINDOW_H
#define KORGE_MAINWINDOW_H
#include <qmainwindow.h>
#include <qtimer.h>
#include <qdict.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 ( Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ) :
+ QServerSocket( port, backlog, parent, name ){;};
+ void newConnection ( int socket )
+ {
+ qDebug("KServerSocket:New connection %d ", socket);
+ QSocket* s = new QSocket( this );
+ connect( s, SIGNAL(readyRead()), this, SLOT(readClient()) );
+ connect( s, SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
+ s->setSocket( socket );
+ }
+
+signals:
+ void sendFile(QSocket*);
+ void getFile(QSocket*);
+ void endConnect();
+private slots:
+ void discardClient()
+ {
+ QSocket* socket = (QSocket*)sender();
+ delete socket;
+ emit endConnect();
+ }
+ void readClient()
+ {
+ qDebug("readClient() ");
+ QSocket* socket = (QSocket*)sender();
+ if ( socket->canReadLine() ) {
+ QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), socket->readLine() );
+ if ( tokens[0] == "GET" ) {
+ emit sendFile( socket );
+ }
+ if ( tokens[0] == "PUT" ) {
+ emit getFile( socket );
+ }
+ if ( tokens[0] == "STOP" ) {
+ emit endConnect();
+ }
+ }
+ }
+};
+
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();
@@ -67,57 +118,69 @@ class MainWindow : public QMainWindow
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:
+ void fillSyncMenu();
+ void sendFile(QSocket* s);
+ void getFile(QSocket* socket);
+ void readFileFromSocket();
+ void endConnect();
private:
+ QSocket* mCommandSocket;
+ KServerSocket * mServerSocket;
bool mClosed;
void saveOnClose();
int mCurrentSyncProfile;
+ void enableQuick();
+ void performQuick();
+ void performQuickQuick();
void syncRemote( KSyncProfile* , bool ask = true);
- void fillSyncMenu();
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