kohelper.cpp
00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2005 Reinhold Kainhofer <reinhold@kainhofer.com> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 00023 */ 00024 00025 #include <tqcolor.h> 00026 00027 #include <kdebug.h> 00028 00029 #include <libkcal/incidence.h> 00030 #include <libkcal/calendar.h> 00031 #include <libkcal/calendarresources.h> 00032 #include <libkcal/resourcecalendar.h> 00033 00034 #include "koprefs.h" 00035 #include "kohelper.h" 00036 00037 TQColor KOHelper::resourceColor( KCal::Calendar*calendar, KCal::Incidence*incidence ) 00038 { 00039 TQColor resourceColor = TQColor(); //Default invalid color 00040 //FIXME: dynamic_cast are dirty, Better We implements interface to get the color 00041 // from the calendar 00042 KCal::CalendarResources *calendarResource = dynamic_cast<KCal::CalendarResources*>( calendar ); 00043 00044 if ( calendarResource ) { 00045 KCal::ResourceCalendar *resourceCalendar = calendarResource->resource( incidence ); 00046 00047 if( resourceCalendar ) { 00048 TQString identifier = resourceCalendar->identifier(); 00049 resourceColor = *KOPrefs::instance()->resourceColor( identifier ); 00050 00051 if ( !resourceCalendar->subresources().isEmpty() ) { 00052 identifier = resourceCalendar->subresourceIdentifier( incidence ); 00053 if ( identifier.isEmpty() ) 00054 identifier = resourceCalendar->identifier(); 00055 TQColor subrescolor( *KOPrefs::instance()->resourceColor( identifier ) ); 00056 if ( subrescolor.isValid() ) 00057 resourceColor = subrescolor; 00058 } 00059 } 00060 // } else { 00061 // kdDebug(5850) << "resourceColor: Calendar is not a CalendarResources" <<endl; 00062 } 00063 return resourceColor; 00064 }