-rw-r--r-- | korganizer/koprefs.cpp | 6 | ||||
-rw-r--r-- | korganizer/koprefs.h | 3 | ||||
-rw-r--r-- | korganizer/mainwindow.cpp | 134 | ||||
-rw-r--r-- | korganizer/mainwindow.h | 1 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 68 | ||||
-rw-r--r-- | libkcal/phoneformat.h | 2 |
6 files changed, 188 insertions, 26 deletions
diff --git a/korganizer/koprefs.cpp b/korganizer/koprefs.cpp index c28da9a..716a125 100644 --- a/korganizer/koprefs.cpp +++ b/korganizer/koprefs.cpp @@ -72,16 +72,22 @@ KOPrefs::KOPrefs() : mDefaultViewFont = QFont("helvetica",10); mDefaultMonthViewFont = QFont("helvetica",8); mMarcusBainsFont= QFont("helvetica",10); mDateNavigatorFont= QFont("helvetica",10, QFont::Bold); mEditBoxFont = QFont("helvetica",12); mJornalViewFont = QFont("helvetica",12); KPrefs::setCurrentGroup("General"); + + + addItemString("Ex2PhoneDevice",&mEx2PhoneDevice,"/dev/ircomm"); + addItemString("Ex2PhoneConnection",&mEx2PhoneConnection,"irda"); + addItemString("Ex2PhoneModel",&mEx2PhoneModel,"6310i"); + addItemBool("Enable Group Scheduling",&mEnableGroupScheduling,false); addItemBool("ShowIconNewTodo",&mShowIconNewTodo,true); addItemBool("ShowIconNewEvent",&mShowIconNewEvent,true); addItemBool("ShowIconSearch",&mShowIconSearch,true); addItemBool("ShowIconList",&mShowIconList,true); addItemBool("ShowIconDay1",&mShowIconDay1,true); addItemBool("ShowIconDay5",&mShowIconDay5,true); diff --git a/korganizer/koprefs.h b/korganizer/koprefs.h index d9ac851..a1ba8b3 100644 --- a/korganizer/koprefs.h +++ b/korganizer/koprefs.h @@ -205,16 +205,19 @@ class KOPrefs : public KPimPrefs QString mRemoteIP; QString mRemoteUser; QString mRemotePassWd; QString mRemoteFile; QString mLocalTempFile; QString mPhoneDevice; QString mPhoneConnection; QString mPhoneModel; + QString mEx2PhoneDevice; + QString mEx2PhoneConnection; + QString mEx2PhoneModel; int mLastSyncTime; int mSyncAlgoPrefs; int mRingSyncAlgoPrefs; QStringList mSyncProfileNames; QStringList mExternSyncProfiles; QString mLocalMachineName; void setCategoryColor(QString cat,const QColor & color); diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index de94b8c..ef73a78 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp @@ -8,16 +8,18 @@ #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 <qspinbox.h> +#include <qcheckbox.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> @@ -30,16 +32,17 @@ #include <qmenubar.h> #include <qtoolbar.h> #include <qapplication.h> //#include <resource.h> #endif #include <libkcal/calendarlocal.h> #include <libkcal/todo.h> +#include <libkcal/phoneformat.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" @@ -61,16 +64,65 @@ using namespace KCal; #ifndef _WIN32_ #include <unistd.h> #else #include "koimportoldialog.h" #endif #include "mainwindow.h" +class KOex2phonePrefs : public QDialog +{ + public: + KOex2phonePrefs( QWidget *parent=0, const char *name=0 ) : + QDialog( parent, name, true ) + { + setCaption( i18n("Export to phone options") ); + QVBoxLayout* lay = new QVBoxLayout( this ); + lay->setSpacing( 3 ); + lay->setMargin( 3 ); + + lay->addWidget(new QLabel( i18n("Please read phone sync howto to\nknow more about the connection settings."), this ) ); + QHBox* temphb; + temphb = new QHBox( this ); + new QLabel( i18n("I/O device: "), temphb ); + mPhoneDevice = new QLineEdit( temphb); + lay->addWidget( temphb ); + temphb = new QHBox( this ); + new QLabel( i18n("Connection: "), temphb ); + mPhoneConnection = new QLineEdit( temphb); + lay->addWidget( temphb ); + temphb = new QHBox( this ); + new QLabel( i18n("Model(opt.): "), temphb ); + mPhoneModel = new QLineEdit( temphb); + lay->addWidget( temphb ); + mWriteBackFuture= new QCheckBox( i18n("Write back events in future only"), this ); + mWriteBackFuture->setChecked( true ); + lay->addWidget( mWriteBackFuture ); + temphb = new QHBox( this ); + new QLabel( i18n("Max. weeks in future: ") , temphb ); + mWriteBackFutureWeeks= new QSpinBox(1,104, 1, temphb); + mWriteBackFutureWeeks->setValue( 8 ); + lay->addWidget( temphb ); + QPushButton * ok = new QPushButton( i18n("Export!"), this ); + lay->addWidget( ok ); + QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); + lay->addWidget( cancel ); + connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); + connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); + resize( 220, 220 ); + + } + +public: + QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; + QCheckBox* mWriteBackFuture; + QSpinBox* mWriteBackFutureWeeks; +}; + int globalFlagBlockStartup; MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : QMainWindow( parent, name ) { mPassWordPiSync = "abc"; #ifdef DESKTOP_VERSION setFont( QFont("Arial"), 14 ); #endif @@ -648,16 +700,25 @@ void MainWindow::initActions() this ); action->addTo( importMenu ); connect( action, SIGNAL( activated() ), SLOT( saveCalendar() ) ); importMenu->insertSeparator(); action = new QAction( "import_qtopia", i18n("Export VCalendar"), 0, this ); action->addTo( importMenu ); connect( action, SIGNAL( activated() ), SLOT( exportVCalendar() ) ); + + + //LR + QPopupMenu *ex2phone = new QPopupMenu( this ); + ex2phone->insertItem(i18n("Complete calendar..."), 1 ); + ex2phone->insertItem(i18n("Filtered calendar..."), 2 ); + connect( ex2phone, SIGNAL( activated(int) ), this, SLOT( exportToPhone( int)) ); + importMenu->insertItem( i18n("Export to phone"), ex2phone ); + importMenu->insertSeparator(); action = new QAction( "manage cat", i18n("Manage new categories..."), 0, this ); action->addTo( importMenu ); connect( action, SIGNAL( activated() ), mView, SLOT( manageCategories() ) ); #ifndef DESKTOP_VERSION importMenu->insertSeparator(); action = new QAction( "beam all", i18n("Beam complete calendar..."), 0, @@ -1082,23 +1143,96 @@ void MainWindow::slotSyncMenu( int action ) } else syncRemote( temp ); } } delete temp; mBlockSaveFlag = false; } +void MainWindow::exportToPhone( int mode ) +{ + + //ex2phone->insertItem(i18n("Complete calendar..."), 1 ); + //ex2phone->insertItem(i18n("Filtered calendar..."), 2 ); + KOex2phonePrefs ex2phone; + ex2phone.mPhoneConnection->setText( KOPrefs::instance()->mEx2PhoneConnection ); + ex2phone.mPhoneDevice->setText( KOPrefs::instance()->mEx2PhoneDevice ); + ex2phone.mPhoneModel->setText( KOPrefs::instance()->mEx2PhoneModel ); + + if ( !ex2phone.exec() ) { + return; + } + KOPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); + KOPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); + KOPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); + + int inFuture = 0; + if ( ex2phone.mWriteBackFuture->isChecked() ) + inFuture = ex2phone.mWriteBackFutureWeeks->value(); + QPtrList<Incidence> delSel; + if ( mode == 1 ) + delSel = mCalendar->rawIncidences(); + if ( mode == 2 ) + delSel = mCalendar->incidences(); + CalendarLocal* cal = new CalendarLocal(); + cal->setLocalTime(); + Incidence *incidence = delSel.first(); + QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); + QDateTime end = cur.addDays( ( inFuture +1 ) *7 ); + while ( incidence ) { + if ( incidence->type() != "journal" ) { + bool add = true; + if ( inFuture ) { + QDateTime dt; + if ( incidence->type() == "Todo" ) { + Todo * t = (Todo*)incidence; + if ( t->hasDueDate() ) + dt = t->dtDue(); + else + dt = cur.addSecs( 62 ); + } + else { + bool ok; + dt = incidence->getNextOccurence( cur, &ok ); + if ( !ok ) + dt = cur.addSecs( -62 ); + } + if ( dt < cur || dt > end ) { + add = false; + } + } + if ( add ) { + Incidence *in = incidence->clone(); + cal->addIncidence( in ); + } + } + incidence = delSel.next(); + } + PhoneFormat::writeConfig( KOPrefs::instance()->mEx2PhoneDevice, + KOPrefs::instance()->mEx2PhoneConnection, + KOPrefs::instance()->mEx2PhoneModel ); + + setCaption( i18n("Writing to phone...")); + if ( PhoneFormat::writeToPhone( cal ) ) + setCaption( i18n("Export to phone successful!")); + else + setCaption( i18n("Error exporting to phone!")); + delete cal; +} + + void MainWindow::setDefaultPreferences() { KOPrefs *p = KOPrefs::instance(); p->mCompactDialogs = true; p->mConfirm = true; // p->mEnableQuickTodo = false; + } QString MainWindow::resourcePath() { return KGlobal::iconLoader()->iconPath(); } void MainWindow::displayText( QString text ,QString cap ) diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h index 7b24b88..74c7f45 100644 --- a/korganizer/mainwindow.h +++ b/korganizer/mainwindow.h @@ -139,16 +139,17 @@ class MainWindow : public QMainWindow void configureToolBar( int ); void printSel(); void printCal(); void saveCalendar(); void loadCalendar(); void exportVCalendar(); void fillFilterMenu(); void selectFilter( int ); + void exportToPhone( int ); void slotSyncMenu( int ); void confSync(); void syncSharp(); void syncPhone(); void syncPi(); void syncLocalFile(); bool syncWithFile( QString, bool ); diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 29c1ae6..b2a62b1 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp @@ -79,18 +79,29 @@ public: }; PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) { mProfileName = profileName; - + writeConfig( device, connection, model ); +} + +PhoneFormat::~PhoneFormat() +{ +} +void PhoneFormat::writeConfig( QString device, QString connection, QString model ) +{ +#ifdef _WIN32_ + QString fileName = qApp->applicationDirPath () +"\\gammurc"; +#else QString fileName = QDir::homeDirPath() +"/.gammurc"; +#endif //qDebug("save %d ", load ); QString content; bool write = false; bool addPort = true, addConnection = true, addModel = true; QFile file( fileName ); if ( QFile::exists( fileName) ) { if (!file.open( IO_ReadOnly ) ) { qDebug("Error: cannot open %s ", fileName.latin1() ); @@ -171,20 +182,17 @@ PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, qDebug("Error: cannot write file %s ", fileName.latin1() ); return; } qDebug("Writing file %s ", fileName.latin1() ); QTextStream ts( &file ); ts << content ; file.close(); } -} -PhoneFormat::~PhoneFormat() -{ } #if 0 int PhoneFormat::initDevice(GSM_StateMachine *s) { GSM_ReadConfig(NULL, &s->Config[0], 0); s->ConfigNum = 1; GSM_Config *cfg = &s->Config[0]; if ( ! mConnection.isEmpty() ) { @@ -564,35 +572,59 @@ void PhoneFormat::afterSave( Incidence* inc) csum = PhoneFormat::getCsumEvent( (Event*) inc ); else csum = PhoneFormat::getCsumTodo( (Todo*) inc ); inc->setCsum( mProfileName, QString::number( csum )); inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); } + +bool PhoneFormat::writeToPhone( Calendar * calendar) +{ +#ifdef _WIN32_ + QString fileName = locateLocal("tmp", "tempfile.vcs"); +#else + QString fileName = "/tmp/kdepimtemp.vcs"; +#endif + + VCalFormat vfsave; + vfsave.setLocalTime ( true ); + if ( ! vfsave.save( calendar, fileName ) ) + return false; + // 4 call kammu +#ifdef DESKTOP_VERSION + QString command ="./kammu --restore " + fileName ; +#else + QString command ="kammu --restore " + fileName ; +#endif + int ret; + while ( (ret = system ( command.latin1())) != 0 ) { + qDebug("Error S::command returned %d. asking users", ret); + int retval = KMessageBox::warningContinueCancel(0, + i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone access"),i18n("Retry"),i18n("Cancel")); + if ( retval != KMessageBox::Continue ) + return false; + } + return true; +} bool PhoneFormat::save( Calendar *calendar) { QLabel status ( i18n(" Opening device ..."), 0 ); int w = status.sizeHint().width()+20 ; if ( w < 200 ) w = 230; int h = status.sizeHint().height()+20 ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); status.setCaption(i18n("Writing to phone...") ); status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); status.show(); status.raise(); qApp->processEvents(); QString message; -#ifdef _WIN32_ - QString fileName = locateLocal("tmp", "tempfile.vcs"); -#else - QString fileName = "/tmp/kdepimtemp.vcs"; -#endif // 1 remove events which should be deleted QPtrList<Event> er = calendar->rawEvents(); Event* ev = er.first(); while ( ev ) { if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { calendar->deleteEvent( ev ); } else { @@ -609,34 +641,18 @@ bool PhoneFormat::save( Calendar *calendar) } else { if ( to->isCompleted()) { calendar->deleteTodo( to ); } } to = tl.next(); } // 3 save file - VCalFormat vfsave; - vfsave.setLocalTime ( true ); - if ( ! vfsave.save( calendar, fileName ) ) + if ( !writeToPhone( calendar ) ) return false; - // 4 call kammu -#ifdef DESKTOP_VERSION - QString command ="./kammu --restore " + fileName ; -#else - QString command ="kammu --restore " + fileName ; -#endif - int ret; - while ( (ret = system ( command.latin1())) != 0 ) { - qDebug("Error S::command returned %d. asking users", ret); - int retval = KMessageBox::warningContinueCancel(0, - i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); - if ( retval != KMessageBox::Continue ) - return false; - } // 5 reread data message = i18n(" Rereading all data ... "); status.setText ( message ); qApp->processEvents(); CalendarLocal* calendarTemp = new CalendarLocal(); calendarTemp->setTimeZoneId( calendar->timeZoneId()); if ( ! load( calendarTemp,calendar) ){ diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h index 2d1ff79..61e8160 100644 --- a/libkcal/phoneformat.h +++ b/libkcal/phoneformat.h @@ -43,16 +43,18 @@ class PhoneFormat : public QObject { bool load( Calendar * ,Calendar * ); bool save( Calendar * ); bool fromString( Calendar *, const QString & ); QString toString( Calendar * ); static ulong getCsum( const QStringList & ); static ulong getCsumTodo( Todo* to ); static ulong getCsumEvent( Event* ev ); + static void writeConfig( QString device,QString connection, QString model ); + static bool writeToPhone( Calendar * ); private: void copyEvent( Event* to, Event* from ); void copyTodo( Todo* to, Todo* from ); //int initDevice(GSM_StateMachine *s); QString mProfileName; void afterSave( Incidence* ); }; |