-rw-r--r-- | libkcal/phoneformat.cpp | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 1a9ccbc..7e1c9cd 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp @@ -1,240 +1,225 @@ /* This file is part of libkcal. Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <qdatetime.h> #include <qstring.h> #include <qapplication.h> #include <qptrlist.h> #include <qregexp.h> #include <qmessagebox.h> #include <qclipboard.h> #include <qfile.h> #include <qtextstream.h> #include <qtextcodec.h> #include <qxml.h> #include <qlabel.h> #include <kdebug.h> #include <klocale.h> #include <kglobal.h> #include "calendar.h" #include "alarm.h" #include "recurrence.h" #include "calendarlocal.h" #include "phoneformat.h" #include "syncdefines.h" using namespace KCal; -//CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 - -//ARSD silentalarm = 0 -// 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly -// 12 RFRQ -// 13 RPOS pos = 4. monday in month -// 14 RDYS days: 1 mon/ 2 tue .. 64 sun -// 15 REND 0 = no end/ 1 = end -// 16 REDT rec end dt -//ALSD -//ALED -//MDAY - class PhoneParser : public QObject { public: PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { ; } bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s) { int id = ToDo->Location; Todo *todo; todo = existingCalendar->todo( mProfileName ,QString::number( id ) ); if (todo ) todo = (Todo *)todo->clone(); else todo = new Todo; todo->setID( mProfileName,QString::number( id ) ); todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); int priority; switch (ToDo->Priority) { case GSM_Priority_Low : priority = 1; break; case GSM_Priority_Medium : priority = 3; break; case GSM_Priority_High : priority = 5; break; default :priority = 3 ; break; } todo->setPriority( priority ); GSM_Phone_Functions *Phone; Phone=s->Phone.Functions; int j; GSM_DateTime* dtp; bool alarm = false; QDateTime alarmDt; GSM_Category Category; int error; QString completedString = "no"; for (j=0;j<ToDo->EntriesNum;j++) { //qDebug(" for todo %d",ToDo->Location ); switch (ToDo->Entries[j].EntryType) { case TODO_END_DATETIME: dtp = &ToDo->Entries[j].Date ; todo->setDtDue (fromGSM ( dtp )); break; case TODO_COMPLETED: if ( ToDo->Entries[j].Number == 1 ) { todo->setCompleted( true ); completedString = "yes"; } else { todo->setCompleted( false ); } break; case TODO_ALARM_DATETIME: dtp = &ToDo->Entries[j].Date ; alarm = true; alarmDt = fromGSM ( dtp ); break; case TODO_SILENT_ALARM_DATETIME: dtp = &ToDo->Entries[j].Date ; alarm = true; alarmDt = fromGSM ( dtp ); break; case TODO_TEXT: //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); break; case TODO_PRIVATE: if ( ToDo->Entries[j].Number == 1 ) todo->setSecrecy( Incidence::SecrecyPrivate ); else todo->setSecrecy( Incidence::SecrecyPublic ); break; case TODO_CATEGORY: Category.Location = ToDo->Entries[j].Number; Category.Type = Category_ToDo; error=Phone->GetCategory(s, &Category); if (error == ERR_NONE) { QStringList cat = todo->categories(); QString nCat = QString ( (const char*)Category.Name ); if ( !nCat.isEmpty() ) if ( !cat.contains( nCat )) { cat << nCat; todo->setCategories( cat ); } } break; case TODO_CONTACTID: #if 0 // not supported entry.Location = ToDo->Entries[j].Number; entry.MemoryType = MEM_ME; error=Phone->GetMemory(s, &entry); if (error == ERR_NONE) { name = GSM_PhonebookGetEntryName(&entry); if (name != NULL) { printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number); } else { printmsg("Contact ID : %d\n",ToDo->Entries[j].Number); } } else { printmsg("Contact : %d\n",ToDo->Entries[j].Number); } #endif break; case TODO_PHONE: #if 0 // not supported printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); #endif break; } } QString alarmString = ""; - // strange 0 semms to mean: alarm enabled if ( alarm ) { Alarm *alarm; if ( todo->alarms().count() > 0 ) alarm = todo->alarms().first(); else { alarm = new Alarm( todo ); todo->addAlarm( alarm ); } alarm->setType( Alarm::Audio ); alarm->setEnabled( true ); int alarmOffset = alarmDt.secsTo( todo->dtStart() ); alarm->setStartOffset( alarmOffset ); alarmString = QString::number( alarmOffset ); } // csum ***************************************** QStringList attList; uint cSum; if ( todo->hasDueDate() ) attList << dtToString ( todo->dtDue() ); attList << QString::number( id ); attList << todo->summary(); attList << completedString; attList << QString::number( todo->priority() ); attList << alarmString; attList << todo->categoriesStr(); attList << todo->secrecyStr(); cSum = PhoneFormat::getCsum(attList ); todo->setCsum( mProfileName, QString::number( cSum )); mCalendar->addTodo( todo); return true; } bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry* Note) { int id = Note->Location; Event *event; event = existingCalendar->event( mProfileName ,QString::number( id ) ); if ( event ) event = (Event*)event->clone(); else event = new Event; event->setID( mProfileName,QString::number( id ) ); event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); int i = 0; bool repeating = false; int repeat_dayofweek = -1; int repeat_day = -1; int repeat_weekofmonth = -1; int repeat_month = -1; int repeat_frequency = -1; int rec_type = -1; GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; GSM_DateTime* dtp; bool alarm = false; QDateTime alarmDt; repeat_startdate.Day = 0; repeat_stopdate.Day = 0; for (i=0;i<Note->EntriesNum;i++) { //qDebug(" for ev"); @@ -602,177 +587,176 @@ ulong PhoneFormat::getCsum( const QStringList & attList) } } } 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 profileName, QString device,QString connection, QString model ) { mProfileName = profileName; GSM_StateMachine s; qDebug(" load "); s.opened = false; s.msg = NULL; s.ConfigNum = 0; #if 0 static char *cp; static INI_Section *cfg = NULL; cfg=GSM_FindGammuRC(); int i; for (i = 0; i <= MAX_CONFIG_NUM; i++) { if (cfg!=NULL) { cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false); if (cp) di.coding = cp; s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false); if (s.Config[i].Localize) { s.msg=INI_ReadFile(s.Config[i].Localize, true); } else { #if !defined(WIN32) && defined(LOCALE_PATH) locale = setlocale(LC_MESSAGES, NULL); if (locale != NULL) { snprintf(locale_file, 200, "%s/gammu_%c%c.txt", LOCALE_PATH, tolower(locale[0]), tolower(locale[1])); s.msg = INI_ReadFile(locale_file, true); } #endif } } /* Wanted user specific configuration? */ if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; s.ConfigNum++; /* We want to use only one file descriptor for global and state machine debug output */ s.Config[i].UseGlobalDebugFile = true; /* We wanted to read just user specified configuration. */ {break;} } #endif setlocale(LC_ALL, ""); GSM_ReadConfig(NULL, &s.Config[0], 0); s.ConfigNum = 1; GSM_Config *cfg = &s.Config[0]; - di.coding = "utf8"; if ( ! connection.isEmpty() ) { cfg->Connection = strdup(connection.latin1()); cfg->DefaultConnection = false; qDebug("Connection set %s ", cfg->Connection ); } if ( ! device.isEmpty() ) { cfg->Device = strdup(device.latin1()); cfg->DefaultDevice = false; qDebug("Device set %s ", cfg->Device); } if ( ! model.isEmpty() ) { strcpy(cfg->Model,model.latin1() ); cfg->DefaultModel = false; qDebug("Model set %s ",cfg->Model ); } int error=GSM_InitConnection(&s,3); - qDebug(" init %d %d", error, ERR_NONE); + qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); if ( error != ERR_NONE ) return false; - // fromString2Cal( calendar, existngCal, &s, "Event" ); GSM_Phone_Functions *Phone; GSM_CalendarEntry note; bool start = true; Phone=s.Phone.Functions; bool gshutdown = false; PhoneParser handler( calendar, profileName ); int ccc = 0; - while (!gshutdown && ccc++ < 3) { + qDebug("Debug: only 10 calender items are downloaded "); + while (!gshutdown && ccc++ < 10) { qDebug("readEvent %d ", ccc); error=Phone->GetNextCalendar(&s,¬e,start); if (error == ERR_EMPTY) break; start = false; handler.readEvent( existingCal, ¬e ); } start = true; GSM_ToDoEntry ToDo; ccc = 0; while (!gshutdown) { error = Phone->GetNextToDo(&s, &ToDo, start); if (error == ERR_EMPTY) break; start = false; - qDebug("readTodo %d ", ++ccc); + qDebug("ReadTodo %d ", ++ccc); handler.readTodo( existingCal, &ToDo, &s); } error=GSM_TerminateConnection(&s); return true; } bool PhoneFormat::save( Calendar *calendar) { #if 0 QLabel status ( i18n("Processing/adding events ..."), 0 ); int w = status.sizeHint().width()+20 ; if ( w < 200 ) w = 200; int h = status.sizeHint().height()+20 ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); status.setCaption(i18n("Writing DTM Data") ); status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); status.show(); status.raise(); qApp->processEvents(); bool debug = DEBUGMODE; QString codec = "utf8"; QString answer; QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; QString command; QPtrList<Event> er = calendar->rawEvents(); Event* ev = er.first(); QString fileName = "/tmp/kopitempout"; int i = 0; QString changeString = ePrefix; QString deleteString = ePrefix; bool deleteEnt = false; bool changeEnt = false; QString message = i18n("Processing event # "); int procCount = 0; while ( ev ) { //qDebug("i %d ", ++i); if ( true /*ev->zaurusStat() != -2*/ ) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); QString eString = getEventString( ev ); if (/* ev->zaurusStat() == -3 */ true) { // delete // deleting empty strings does not work. // we write first and x and then delete the record with the x eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); changeString += eString + "\n"; deleteString += eString + "\n"; deleteEnt = true; changeEnt = true; } else if ( /*ev->zaurusId() == -1*/true ) { // add new command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; system ( command.utf8() ); QFile file( fileName ); if (!file.open( IO_ReadOnly ) ) { return false; } QTextStream ts( &file ); ts.setCodec( QTextCodec::codecForName("utf8") ); |