summaryrefslogtreecommitdiffabout
path: root/libkcal/phoneformat.cpp
Side-by-side diff
Diffstat (limited to 'libkcal/phoneformat.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp68
1 files changed, 42 insertions, 26 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 29c1ae6..b2a62b1 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -75,26 +75,37 @@ public:
}
return datestr + timestr;
}
};
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() );
return;
}
QString line;
while ( file.readLine( line, 1024 ) > 0 ) {
@@ -167,28 +178,25 @@ PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection,
content += "\n";
}
if ( write ) {
if (!file.open( IO_WriteOnly ) ) {
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() ) {
cfg->Connection = strdup(mConnection.latin1());
cfg->DefaultConnection = false;
qDebug("Connection set %s ", cfg->Connection );
@@ -560,43 +568,67 @@ void PhoneFormat::afterSave( Incidence* inc)
{
uint csum;
inc->removeID( mProfileName );
if ( inc->type() == "Event")
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 {
}
ev = er.next();
}
@@ -605,42 +637,26 @@ bool PhoneFormat::save( Calendar *calendar)
Todo* to = tl.first();
while ( to ) {
if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
calendar->deleteTodo( to );
} 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) ){
qDebug("error reloading calendar ");
delete calendarTemp;
return false;
}