QColor KOHelper::resourceColor( KCal::Calendar *calendar, KCal::Incidence *incidence ) { QColor resourceColor = QColor(); //Default invalid color //FIXME: dynamic_cast are dirty, Better We implements interface to get // the color from the calendar KCal::CalendarResources *calendarResource = dynamic_cast<KCal::CalendarResources*>( calendar ); if ( calendarResource ) { KCal::ResourceCalendar *resourceCalendar = calendarResource->resource( incidence ); if ( resourceCalendar ) { QString identifier = resourceCalendar->identifier(); resourceColor = KOPrefs::instance()->resourceColor( identifier ); if ( !resourceCalendar->subresources().isEmpty() ) { identifier = resourceCalendar->subresourceIdentifier( incidence ); if ( identifier.isEmpty() ) { identifier = resourceCalendar->identifier(); } QColor subrescolor( KOPrefs::instance()->resourceColor( identifier ) ); if ( subrescolor.isValid() ) { resourceColor = subrescolor; } } } } return resourceColor; }
void ResourceView::assignColor() { ResourceItem *item = currentItem(); if(!item) return; // A color without initialized is a color invalid QColor myColor; KCal::ResourceCalendar *cal = item->resource(); QString identifier = cal->identifier(); if(item->isSubresource()) identifier = item->resourceIdentifier(); QColor defaultColor = *KOPrefs::instance()->resourceColor(identifier); int result = KColorDialog::getColor(myColor, defaultColor); if(result == KColorDialog::Accepted) { KOPrefs::instance()->setResourceColor(identifier, myColor); item->setResourceColor(myColor); item->update(); emitResourcesChanged(); } }
QColor KOHelper::resourceColor( KCal::Calendar*calendar, KCal::Incidence*incidence ) { QColor resourceColor = QColor(); //Default invalid color //FIXME: dynamic_cast are dirty, Better We implements interface to get the color // from the calendar KCal::CalendarResources *calendarResource = dynamic_cast<KCal::CalendarResources*>( calendar ); if ( calendarResource ) { KCal::ResourceCalendar *resourceCalendar = calendarResource->resource( incidence ); if( resourceCalendar ) { QString identifier = resourceCalendar->identifier(); resourceColor = *KOPrefs::instance()->resourceColor( identifier ); if ( !resourceCalendar->subresources().isEmpty() ) { identifier = resourceCalendar->subresourceIdentifier( incidence ); if ( identifier.isEmpty() ) identifier = resourceCalendar->identifier(); QColor subrescolor( *KOPrefs::instance()->resourceColor( identifier ) ); if ( subrescolor.isValid() ) resourceColor = subrescolor; } } // } else { // kdDebug(5850) << "resourceColor: Calendar is not a CalendarResources" <<endl; } return resourceColor; }
void StdCalendar::addFileResource( const QString &fileName, const QString &resName ) { KCal::ResourceCalendar *resource = 0; if ( !fileName.isEmpty() ) { KUrl url( fileName ); if ( url.isLocalFile() ) { kDebug() << "Local resource at" << url; resource = mManager->createResource( "file" ); if ( resource ) { resource->setValue( "File", url.toLocalFile() ); } } else { kDebug() << "Remote Resource at" << url; resource = mManager->createResource( "remote" ); if ( resource ) { resource->setValue( "URL", url.url() ); } } if ( resource ) { resource->setTimeSpec( KSystemTimeZones::local() ); resource->setResourceName( resName ); mManager->add( resource ); mManager->setStandardResource( resource ); } } }
void ResourceView::disableColor() { ResourceItem *item = currentItem(); if ( !item ) return; QColor colorInvalid; KCal::ResourceCalendar *cal = item->resource(); QString identifier = cal->identifier(); if ( item->isSubresource() ) identifier = item->resourceIdentifier(); KOPrefs::instance()->setResourceColor( identifier, colorInvalid ); item->setResourceColor( colorInvalid ); item->update(); emitResourcesChanged(); }
int main (int argc, char *argv[]) { const QByteArray& ba=QByteArray("test"); delete (void *)0; const KLocalizedString name=ki18n("myName"); KAboutData aboutData( ba, ba, name, ba, name); KCmdLineArgs::init( argc, argv, &aboutData ); KApplication khello; KCal::ResourceCalendar* cal; KCal::ResourceCached* resource; resource=new KCal::ResourceLocal("/tmp/test.ics"); cal=resource; cal->load(); KCal::Todo* todo1 = new KCal::Todo(); todo1->setSummary("test todo"); cal->addTodo(todo1); KCal::Event* event1 = new KCal::Event(); event1->setRelatedTo(todo1); event1->setDtStart(KDateTime::currentLocalDateTime()); event1->setDtEnd(KDateTime::currentLocalDateTime()); cal->addEvent(event1); KABC::Lock *lock = cal->lock(); cal->save(); lock->unlock(); }
QString KOHelper::resourceLabel(KCal::Calendar * calendar, KCal::Incidence * incidence) { KCal::CalendarResources *calendarResource = dynamic_cast<KCal::CalendarResources*>( calendar ); if ( !calendarResource || ! incidence ) return QString(); KCal::ResourceCalendar *resourceCalendar = calendarResource->resource( incidence ); if( resourceCalendar ) { if ( !resourceCalendar->subresources().isEmpty() ) { QString subRes = resourceCalendar->subresourceIdentifier( incidence ); if ( subRes.isEmpty() ) return resourceCalendar->resourceName(); return resourceCalendar->labelForSubresource( subRes ); } return resourceCalendar->resourceName(); } return QString(); }