author | ulf69 <ulf69> | 2004-10-07 01:08:56 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-07 01:08:56 (UTC) |
commit | 3338b7239dc2e5cdff95ebc76b6905e6385a5833 (patch) (side-by-side diff) | |
tree | b7a90a8cf3254fd41a609237b41b9d0f73b2d8c8 /korganizer/calendarview.cpp | |
parent | 0406c1ac252f2fa631f7a486e73b0a97d09874f9 (diff) | |
download | kdepimpi-3338b7239dc2e5cdff95ebc76b6905e6385a5833.zip kdepimpi-3338b7239dc2e5cdff95ebc76b6905e6385a5833.tar.gz kdepimpi-3338b7239dc2e5cdff95ebc76b6905e6385a5833.tar.bz2 |
implemented birthday lookup via QCop
-rw-r--r-- | korganizer/calendarview.cpp | 103 |
1 files changed, 101 insertions, 2 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 1de2759..b3b4cdb 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -70,32 +70,33 @@ #include <libkcal/icalformat.h> #include <libkcal/vcalformat.h> #include <libkcal/scheduler.h> #include <libkcal/calendarlocal.h> #include <libkcal/journal.h> #include <libkcal/calfilter.h> #include <libkcal/attendee.h> #include <libkcal/dndfactory.h> #include <libkcal/freebusy.h> #include <libkcal/filestorage.h> #include <libkcal/calendarresources.h> #include <libkcal/qtopiaformat.h> #include "../kalarmd/alarmdialog.h" #ifndef DESKTOP_VERSION #include <libkcal/sharpformat.h> +#include <externalapphandler.h> #endif #include <libkcal/phoneformat.h> #ifndef KORG_NOMAIL #include "komailclient.h" #endif #ifndef KORG_NOPRINTER #include "calprinter.h" #endif #ifndef KORG_NOPLUGINS #include "kocore.h" #endif #include "koeventeditor.h" #include "kotodoeditor.h" #include "koprefs.h" #include "koeventviewerdialog.h" #include "publishdialog.h" @@ -449,32 +450,40 @@ void CalendarView::init() mEventEditor = mDialogManager->getEventEditor(); mTodoEditor = mDialogManager->getTodoEditor(); mFlagEditDescription = false; mSuspendTimer = new QTimer( this ); mAlarmTimer = new QTimer( this ); mRecheckAlarmTimer = new QTimer( this ); connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); mAlarmDialog = new AlarmDialog( this ); connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); mAlarmDialog->setServerNotification( false ); mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); + + +#ifndef DESKTOP_VERSION +//US listen for arriving address resultsets + connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), + this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); +#endif + } CalendarView::~CalendarView() { // kdDebug() << "~CalendarView()" << endl; //qDebug("CalendarView::~CalendarView() "); delete mDialogManager; delete mViewManager; delete mStorage; delete mDateFrame ; delete beamDialog; //kdDebug() << "~CalendarView() done" << endl; } void CalendarView::timerAlarm() { @@ -1311,33 +1320,35 @@ void CalendarView::syncExternal( int mode ) } delete calendar; updateView(); return ;//syncOK; } void CalendarView::syncSharp() { syncExternal( 0 ); } //#include <kabc/stdaddressbook.h> bool CalendarView::importBday() { -#if 0 +#ifndef KORG_NOKABC + +#ifdef DESKTOP_VERSION KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); KABC::AddressBook::Iterator it; int count = 0; for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { ++count; } QProgressBar bar(count,0 ); int w = 300; if ( QApplication::desktop()->width() < 320 ) w = 220; int h = bar.sizeHint().height() ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); bar.show(); bar.setCaption (i18n("Reading addressbook - close to abort!") ); @@ -1352,36 +1363,124 @@ bool CalendarView::importBday() qApp->processEvents(); //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); if ( (*it).birthday().date().isValid() ){ a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) ++addCount; } QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); if ( anni.isValid() ){ a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) ++addCount; } } updateView(); topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); -#endif +#else //DESKTOP_VERSION + + ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); + // the result should now arrive through method insertBirthdays + +#endif //DESKTOP_VERSION + +#endif //KORG_NOKABC + + return true; } +// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI +void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, + const QStringList& anniversaryList, const QStringList& realNameList, + const QStringList& emailList, const QStringList& assembledNameList, + const QStringList& uidList) +{ + qDebug("CalendarView::insertBirthdays"); + if (uid == this->name()) + { + int count = birthdayList.count(); + int addCount = 0; + KCal::Attendee* a = 0; + + qDebug("CalView 1 %i", count); + + QProgressBar bar(count,0 ); + int w = 300; + if ( QApplication::desktop()->width() < 320 ) + w = 220; + int h = bar.sizeHint().height() ; + int dw = QApplication::desktop()->width(); + int dh = QApplication::desktop()->height(); + bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); + bar.show(); + bar.setCaption (i18n("inserting birthdays - close to abort!") ); + qApp->processEvents(); + + QDate birthday; + QDate anniversary; + QString realName; + QString email; + QString assembledName; + QString uid; + bool ok = true; + for ( int i = 0; i < count; i++) + { + if ( ! bar.isVisible() ) + return; + bar.setProgress( i ); + qApp->processEvents(); + + qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); + + birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); + if (!ok) + qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); + + anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); + if (!ok) + qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); + realName = realNameList[i]; + email = emailList[i]; + assembledName = assembledNameList[i]; + uid = uidList[i]; + + if ( birthday.isValid() ){ + a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, + KCal::Attendee::ReqParticipant,uid) ; + if ( addAnniversary( birthday, assembledName, a, true ) ) + ++addCount; + } + + if ( anniversary.isValid() ){ + a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, + KCal::Attendee::ReqParticipant,uid) ; + if ( addAnniversary( anniversary, assembledName, a, false ) ) + ++addCount; + } + } + + updateView(); + topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); + + } + +} + + + bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) { //qDebug("addAnni "); Event * ev = new Event(); if ( a ) { ev->addAttendee( a ); } QString kind; if ( birthday ) kind = i18n( "Birthday" ); else kind = i18n( "Anniversary" ); ev->setSummary( name + " - " + kind ); ev->setOrganizer( "nobody@nowhere" ); ev->setCategories( kind ); ev->setDtStart( QDateTime(date) ); |