summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp7
-rw-r--r--libkdepim/phoneaccess.cpp2
2 files changed, 5 insertions, 4 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 3555dc6..281434e 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -251,99 +251,97 @@ ulong PhoneFormat::getCsumEvent( Event* event )
attList << list.join("");
attList << event->categoriesStr();
//qDebug("csum cat %s", event->categoriesStr().latin1());
attList << event->secrecyStr();
return PhoneFormat::getCsum(attList );
}
ulong PhoneFormat::getCsum( const QStringList & attList)
{
int max = attList.count();
ulong cSum = 0;
int j,k,i;
int add;
for ( i = 0; i < max ; ++i ) {
QString s = attList[i];
if ( ! s.isEmpty() ){
j = s.length();
for ( k = 0; k < j; ++k ) {
int mul = k +1;
add = s[k].unicode ();
if ( k < 16 )
mul = mul * mul;
int ii = i+1;
add = add * mul *ii*ii*ii;
cSum += add;
}
}
}
//QString dump = attList.join(",");
//qDebug("csum: %d %s", cSum,dump.latin1());
return cSum;
}
//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
#include <stdlib.h>
#define DEBUGMODE false
bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
{
QString fileName;
#ifdef _WIN32_
fileName = locateLocal("tmp", "phonefile.vcs");
#else
fileName = "/tmp/phonefile.vcs";
#endif
QString command;
- int ret = PhoneAccess::readFromPhone( fileName );
- if ( ret != 0 ) {
- qDebug("Error::command returned %d", ret);
+ if ( ! PhoneAccess::readFromPhone( fileName )) {
return false;
}
VCalFormat vfload;
vfload.setLocalTime ( true );
qDebug("loading file ...");
if ( ! vfload.load( calendar, fileName ) )
return false;
QPtrList<Event> er = calendar->rawEvents();
Event* ev = er.first();
qDebug("reading events... ");
while ( ev ) {
QStringList cat = ev->categories();
if ( cat.contains( "MeetingDEF" )) {
ev->setCategories( QStringList() );
}
int id = ev->pilotId();
Event *event;
event = existingCal->event( mProfileName ,QString::number( id ) );
if ( event ) {
event = (Event*)event->clone();
copyEvent( event, ev );
calendar->deleteEvent( ev );
calendar->addEvent( event);
}
else
event = ev;
uint cSum;
cSum = PhoneFormat::getCsumEvent( event );
event->setCsum( mProfileName, QString::number( cSum ));
event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
event->setID( mProfileName,QString::number( id ) );
ev = er.next();
}
{
qDebug("reading todos... ");
QPtrList<Todo> tr = calendar->rawTodos();
Todo* ev = tr.first();
while ( ev ) {
QStringList cat = ev->categories();
if ( cat.contains( "MeetingDEF" )) {
ev->setCategories( QStringList() );
}
int id = ev->pilotId();
Todo *event;
event = existingCal->todo( mProfileName ,QString::number( id ) );
if ( event ) {
@@ -442,98 +440,101 @@ void PhoneFormat::copyTodo( Todo* to, Todo* from )
if ( !cat.contains( nCat )) {
cat << nCat;
}
}
to->setCategories( cat );
if ( from->isCompleted() ) {
to->setCompleted( true );
if( from->completed().isValid() )
to->setCompleted( from->completed() );
} else {
// set percentcomplete only, if to->isCompleted()
if ( to->isCompleted() )
to->setPercentComplete(from->percentComplete());
}
if( to->priority() == 2 && from->priority() == 1 )
; //skip
else if (to->priority() == 4 && from->priority() == 5 )
;
else
to->setPriority(from->priority());
}
#include <qcstring.h>
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 );
+ QString id = calendar->timeZoneId();
+ calendar->setLocalTime();
if ( ! vfsave.save( calendar, fileName ) )
return false;
+ calendar->setTimeZoneId( id );
return PhoneAccess::writeToPhone( fileName );
}
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;
// 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();
}
// 2 remove todos which should be deleted
QPtrList<Todo> tl = calendar->rawTodos();
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
if ( !writeToPhone( calendar ) )
return false;
// 5 reread data
message = i18n(" Rereading all data ... ");
status.setText ( message );
diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp
index 5fafa1f..8298aa6 100644
--- a/libkdepim/phoneaccess.cpp
+++ b/libkdepim/phoneaccess.cpp
@@ -118,56 +118,56 @@ void PhoneAccess::writeConfig( QString device, QString connection, QString model
qDebug("Error: cannot write file %s ", fileName.latin1() );
return;
}
qDebug("Writing file %s ", fileName.latin1() );
QTextStream ts( &file );
ts << content ;
file.close();
}
}
bool PhoneAccess::writeToPhone( QString fileName)
{
#ifdef DESKTOP_VERSION
#ifdef _WIN32_
QString command ="kammu --restore " + fileName ;
#else
QString command ="./kammu --restore " + fileName ;
#endif
#else
QString command ="kammu --restore " + fileName ;
#endif
int ret;
while ( (ret = system ( command.latin1())) != 0 ) {
qDebug("Error S::command returned %d.", ret);
int retval = KMessageBox::warningContinueCancel(0,
i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel"));
if ( retval != KMessageBox::Continue )
return false;
}
return true;
}
bool PhoneAccess::readFromPhone( QString fileName)
{
#ifdef DESKTOP_VERSION
#ifdef _WIN32_
QString command ="kammu --backup " + fileName + " -yes" ;
#else
QString command ="./kammu --backup " + fileName + " -yes" ;
#endif
#else
QString command ="kammu --backup " + fileName + " -yes" ;
#endif
int ret;
while ( (ret = system ( command.latin1())) != 0 ) {
- qDebug("Error S::command returned %d.", ret);
+ qDebug("Error reading from phone:Command returned %d", ret);
int retval = KMessageBox::warningContinueCancel(0,
i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel"));
if ( retval != KMessageBox::Continue )
return false;
}
return true;
}