Index: calendar/gui/e-day-view.c
===================================================================
--- calendar/gui/e-day-view.c	(revision 33726)
+++ calendar/gui/e-day-view.c	(working copy)
@@ -1556,12 +1556,16 @@
 	GdkColor color, bg_color;
 	guint16 red, green, blue; 
 	gdouble	cc = 65535.0;
+	ECalComponent *comp;
 	
 	red = day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND].red;
        	green = day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND].green;
        	blue = day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND].blue;
 
-	if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), event->comp_data),
+	comp = e_cal_component_new ();
+	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
+
+	if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (day_view), event->comp_data, comp),
        	     &bg_color)) {
                 GdkColormap *colormap;
        		colormap = gtk_widget_get_colormap (GTK_WIDGET (day_view));
@@ -1577,6 +1581,8 @@
 	else
 		color = widget->style->text[GTK_STATE_ACTIVE];
 
+	g_object_unref (comp);
+
 	return color;
 }
 
Index: calendar/gui/e-week-view-event-item.c
===================================================================
--- calendar/gui/e-week-view-event-item.c	(revision 33726)
+++ calendar/gui/e-week-view-event-item.c	(working copy)
@@ -230,6 +230,7 @@
 	gboolean draw_start_triangle = FALSE, draw_end_triangle = FALSE;
 	GdkRectangle clip_rect;
 	GdkColor bg_color;
+	ECalComponent *comp;
 
 #if 0
 	g_print ("In e_week_view_event_item_draw %i,%i %ix%i\n",
@@ -263,6 +264,9 @@
 	if (x1 == x2 || y1 == y2)
 		return;
 
+	comp = e_cal_component_new ();
+	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
+	
 	icon_x = 0;
 	icon_y = y1 + E_WEEK_VIEW_EVENT_BORDER_HEIGHT + E_WEEK_VIEW_ICON_Y_PAD;
 
@@ -286,8 +290,7 @@
 		rect_x = x1 + E_WEEK_VIEW_EVENT_L_PAD;
 		rect_w = x2 - x1 - E_WEEK_VIEW_EVENT_L_PAD - E_WEEK_VIEW_EVENT_R_PAD + 1;
 
-		if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)),
-									  event->comp_data),
+		if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (week_view), event->comp_data, comp),
 				     &bg_color)) {
 			GdkColormap *colormap;
 
@@ -376,8 +379,7 @@
 			rect_w -= 2;
 		}
 
-		if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)),
-									  event->comp_data),
+		if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (week_view), event->comp_data, comp),
 				     &bg_color)) {
 			GdkColormap *colormap;
 
@@ -481,6 +483,8 @@
 							   max_icon_x, TRUE);
 		}
 	}
+
+	g_object_unref (comp);
 }
 
 
@@ -739,6 +743,7 @@
 	GdkColor bg_color;
 	GdkPoint points[3];
 	gint c1, c2;
+	ECalComponent *comp;
 
 	week_view = E_WEEK_VIEW (GTK_WIDGET (GNOME_CANVAS_ITEM (wveitem)->canvas)->parent);
 
@@ -754,8 +759,10 @@
 	points[2].x = x;
 	points[2].y = y + h - 1;
 
-	if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)),
-								  event->comp_data),
+	comp = e_cal_component_new ();
+	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
+
+	if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (week_view), event->comp_data, comp),
 			     &bg_color)) {
 		GdkColormap *colormap;
 
@@ -767,6 +774,8 @@
 	} else
 		gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]);
 
+	g_object_unref (comp);
+
 	gdk_draw_polygon (drawable, gc, TRUE, points, 3);
 
 	gdk_gc_set_foreground (gc, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER]);
@@ -811,6 +820,7 @@
 	gdouble radius, cx0, cy0, rect_height, rect_width;
 	gboolean gradient;
 	gdouble cc = 65535.0;
+	ECalComponent *comp;
 
 #if 0
 	g_print ("In e_week_view_event_item_draw %i,%i %ix%i\n",
@@ -850,6 +860,9 @@
 	if (x1 == x2 || y1 == y2)
 		return;
 
+	comp = e_cal_component_new ();
+	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
+	
 	icon_x = 0;
 	icon_y = y1 + E_WEEK_VIEW_EVENT_BORDER_HEIGHT + E_WEEK_VIEW_ICON_Y_PAD;
 
@@ -873,8 +886,7 @@
 		rect_x = x1 + E_WEEK_VIEW_EVENT_L_PAD;
 		rect_w = x2 - x1 - E_WEEK_VIEW_EVENT_L_PAD - E_WEEK_VIEW_EVENT_R_PAD + 1;
 		
-		if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)),
-									  event->comp_data),
+		if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (week_view), event->comp_data, comp),
 				     &bg_color)) {
 			GdkColormap *colormap;
 
@@ -1012,8 +1024,7 @@
 		}
 
 		cairo_save (cr);
-		if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)),
-									  event->comp_data),
+		if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (week_view), event->comp_data, comp),
 				     &bg_color)) {
 			GdkColormap *colormap;
 
@@ -1178,6 +1189,7 @@
 		}
 	}
 	cairo_destroy (cr);
+	g_object_unref (comp);
 }
 
 static void
@@ -1425,6 +1437,7 @@
 	GdkPoint points[3];
 	gint c1, c2;
 	cairo_t *cr;
+	ECalComponent *comp;
 
 	week_view = E_WEEK_VIEW (GTK_WIDGET (GNOME_CANVAS_ITEM (wveitem)->canvas)->parent);
 
@@ -1441,8 +1454,10 @@
 	points[2].x = x;
 	points[2].y = y + h - 1;
 
-	if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)),
-								  event->comp_data),
+	comp = e_cal_component_new ();
+	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
+
+	if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (week_view), event->comp_data, comp),
 			     &bg_color)) {
 		GdkColormap *colormap;
 
@@ -1458,6 +1473,8 @@
 		gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]);
 	}
 
+	g_object_unref (comp);
+
 	cairo_save (cr);
 	cairo_set_line_width (cr, 0.7);
 	cairo_move_to (cr, points[0].x, points[0].y);
Index: calendar/gui/e-week-view.c
===================================================================
--- calendar/gui/e-week-view.c	(revision 33726)
+++ calendar/gui/e-week-view.c	(working copy)
@@ -773,12 +773,16 @@
 	GdkColor color, bg_color;
 	guint16 red, green, blue; 
 	gdouble	cc = 65535.0;
+	ECalComponent *comp;
 	
 	red = week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND].red;
        	green = week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND].green;
        	blue = week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND].blue;
 
-	if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)), event->comp_data),
+	comp = e_cal_component_new ();
+	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
+
+	if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (week_view), event->comp_data, comp),
        	     &bg_color)) {
                 GdkColormap *colormap;
        		colormap = gtk_widget_get_colormap (GTK_WIDGET (week_view));
@@ -794,6 +798,8 @@
 	else
 		color = widget->style->text[GTK_STATE_ACTIVE];
 
+	g_object_unref (comp);
+
 	return color;
 }
 
Index: calendar/gui/e-calendar-view.c
===================================================================
--- calendar/gui/e-calendar-view.c	(revision 33726)
+++ calendar/gui/e-calendar-view.c	(working copy)
@@ -2239,7 +2239,46 @@
 
 	return FALSE;
 }
+
+/* e_calendar_view_get_event_background:
+ *
+ * @cal_view:
+ * @comp_data:
+ * @comp: component to which return background color
+ *
+ * returns text representation of background color to use for this @comp
+ */
+
+const char *
+e_calendar_view_get_event_background (ECalendarView *cal_view, ECalModelComponent *comp_data, ECalComponent *comp)
+{
+	GSList *categories_list, *elem;
+	const char *bg_color = NULL;
+
+	g_assert (cal_view != NULL && comp_data != NULL && comp != NULL);
+
+	e_cal_component_get_categories_list (comp, &categories_list);
+	for (elem = categories_list; elem; elem = elem->next) {
+		const char *category_color = e_categories_get_color_for ((const char *) elem->data);
+
+		if (category_color) {
+			if (bg_color) {
+				/* more categories with set color, use rather calendar color */
+				bg_color = NULL;
+				break;
+			}
+			bg_color = category_color;
+		}
+	}
 	
+	if (!bg_color)
+		bg_color = e_cal_model_get_color_for_component (e_calendar_view_get_model (cal_view), comp_data);
+
+	e_cal_component_free_categories_list (categories_list);
+	
+	return bg_color;
+}
+
 #ifdef ENABLE_CAIRO
 void
 draw_curved_rectangle (cairo_t *cr, double x0, double y0,
Index: calendar/gui/e-calendar-view.h
===================================================================
--- calendar/gui/e-calendar-view.h	(revision 33726)
+++ calendar/gui/e-calendar-view.h	(working copy)
@@ -169,6 +169,8 @@
 
 void           e_calendar_view_move_tip (GtkWidget *widget, int x, int y);
 
+const char *   e_calendar_view_get_event_background (ECalendarView *cal_view, ECalModelComponent *comp_data, ECalComponent *comp);
+
 #ifdef ENABLE_CAIRO
 void           draw_curved_rectangle (cairo_t *cr,
                                       double x0,
Index: calendar/gui/e-day-view-top-item.c
===================================================================
--- calendar/gui/e-day-view-top-item.c	(revision 33726)
+++ calendar/gui/e-day-view-top-item.c	(working copy)
@@ -355,8 +355,7 @@
 		       item_x + item_w - 1 - x, item_y + item_h - 1 - y);
 
 	/* Fill it in. */
-	if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)),
-								  event->comp_data),
+	if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (day_view), event->comp_data, comp),
 			     &bg_color)) {
 		GdkColormap *colormap;
 
@@ -609,6 +608,7 @@
 	GdkColor bg_color;
 	GdkPoint points[3];
 	gint c1, c2;
+	ECalComponent *comp;
 
 	day_view = dvtitem->day_view;
 
@@ -630,9 +630,11 @@
 	event = &g_array_index (day_view->long_events, EDayViewEvent,
 				event_num);
 
+	comp = e_cal_component_new ();
+	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
+
 	/* Fill it in. */
-	if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)),
-								  event->comp_data),
+	if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (day_view), event->comp_data, comp),
 			     &bg_color)) {
 		GdkColormap *colormap;
 
@@ -644,6 +646,8 @@
 	} else
 		gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]);
 
+	g_object_unref (comp);
+
 	gdk_draw_polygon (drawable, gc, TRUE, points, 3);
 
 	gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER]);
@@ -895,8 +899,7 @@
 	comp = e_cal_component_new ();
 	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
 
-	if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)),
-								  event->comp_data),
+	if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (day_view), event->comp_data, comp),
 			     &bg_color)) {
 		GdkColormap *colormap;
 
@@ -1196,6 +1199,7 @@
 	GdkPoint points[3];
 	gint c1, c2;
 	cairo_t *cr;
+	ECalComponent *comp;
 
 	cr = gdk_cairo_create (drawable);
 
@@ -1218,10 +1222,13 @@
 
 	event = &g_array_index (day_view->long_events, EDayViewEvent,
 				event_num);
+
+	comp = e_cal_component_new ();
+	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
+
 	cairo_save (cr);
 	/* Fill it in. */
-	if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)),
-								  event->comp_data),
+	if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (day_view), event->comp_data, comp),
 			     &bg_color)) {
 		GdkColormap *colormap;
 
@@ -1235,6 +1242,8 @@
 		gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]);
 	}
 
+	g_object_unref (comp);
+
 	cairo_move_to (cr, points[0].x, points[0].y);
 	cairo_line_to (cr, points[1].x, points[1].y);
 	cairo_line_to (cr, points[2].x, points[2].y);
Index: calendar/gui/e-day-view-main-item.c
===================================================================
--- calendar/gui/e-day-view-main-item.c	(revision 33726)
+++ calendar/gui/e-day-view-main-item.c	(working copy)
@@ -530,6 +530,9 @@
 	event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
 
+	comp = e_cal_component_new ();
+	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
+
 	/* Fill in the event background. Note that for events in the first
 	   column of the day, we might not want to paint over the vertical bar,
 	   since that is used for multiple events. But then you can't see
@@ -537,7 +540,7 @@
 
 	gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND]);
 
-	if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), event->comp_data),
+	if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (day_view), event->comp_data, comp),
 			     &bg_color)) {
 		GdkColormap *colormap;
 
@@ -583,9 +586,6 @@
 			bar_y2 = item_y + item_h - 1;
 	}
 
-	comp = e_cal_component_new ();
-	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
-
 	/* Only fill it in if the event isn't TRANSPARENT. */
 	e_cal_component_get_transparency (comp, &transparency);
 	if (transparency != E_CAL_COMPONENT_TRANSP_TRANSPARENT) {
@@ -1088,7 +1088,11 @@
 
 		event = &g_array_index (day_view->events[day], EDayViewEvent,
 					event_num);
-		if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), event->comp_data),
+
+		comp = e_cal_component_new ();
+		e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
+
+		if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (day_view), event->comp_data, comp),
 				     &bg_color)) {
 			GdkColormap *colormap;
 
@@ -1100,9 +1104,6 @@
 		}
 
 
-		comp = e_cal_component_new ();
-		e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
-
 		/* If the event is TRANSPARENT, skip it. */
 		e_cal_component_get_transparency (comp, &transparency);
 		if (transparency == E_CAL_COMPONENT_TRANSP_TRANSPARENT)
@@ -1160,7 +1161,11 @@
 
 		event = &g_array_index (day_view->long_events, EDayViewEvent,
 					event_num);
-		if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), event->comp_data),
+
+		comp = e_cal_component_new ();
+		e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
+
+		if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (day_view), event->comp_data, comp),
 				     &bg_color)) {
 			GdkColormap *colormap;
 
@@ -1170,9 +1175,6 @@
 			}
 		}
 
-		comp = e_cal_component_new ();
-		e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
-
 		/* If the event is TRANSPARENT, skip it. */
 		e_cal_component_get_transparency (comp, &transparency);
 		if (transparency == E_CAL_COMPONENT_TRANSP_TRANSPARENT)
@@ -1316,6 +1318,9 @@
 	event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
 
+	comp = e_cal_component_new ();
+	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
+
 	/* Fill in the event background. Note that for events in the first
 	   column of the day, we might not want to paint over the vertical bar,
 	   since that is used for multiple events. But then you can't see
@@ -1326,7 +1331,7 @@
 	green = day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND].green;
 	blue = day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND].blue;
 
-	if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), event->comp_data),
+	if (gdk_color_parse (e_calendar_view_get_event_background (E_CALENDAR_VIEW (day_view), event->comp_data, comp),
 			     &bg_color)) {
 		GdkColormap *colormap;
 
@@ -1729,9 +1734,6 @@
 	if (font_options)
 		cairo_font_options_destroy (font_options);
 
-	comp = e_cal_component_new ();
-	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
-
 	/* Only fill it in if the event isn't TRANSPARENT. */
 	e_cal_component_get_transparency (comp, &transparency);
 	if (transparency != E_CAL_COMPONENT_TRANSP_TRANSPARENT) {
Index: calendar/ChangeLog
===================================================================
--- calendar/ChangeLog	(revision 33726)
+++ calendar/ChangeLog	(working copy)
@@ -1,3 +1,25 @@
+2007-06-27  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #308815
+
+	* gui/e-calendar-view.h: (e_calendar_view_get_event_background):
+	* gui/e-calendar-view.c: (e_calendar_view_get_event_background):
+	Added new public function to get background color based on categories.
+	* gui/e-day-view-top-item.c: (e_day_view_top_item_draw_long_event),
+	(e_day_view_top_item_draw_triangle), (e_day_view_top_item_draw_long_event),
+	(e_day_view_top_item_draw_triangle):
+	* gui/e-day-view-main-item.c: (e_day_view_main_item_draw_day_event),
+	(e_day_view_main_item_draw_events_in_vbars),
+	(e_day_view_main_item_draw_long_events_in_vbars),
+	(e_day_view_main_item_draw_day_event):
+	* gui/e-week-view-event-item.c: (e_week_view_event_item_draw),
+	(e_week_view_event_item_draw_triangle), (e_week_view_event_item_draw),
+	(e_week_view_event_item_draw_triangle):
+	* gui/e-week-view.c: (e_week_view_get_text_color):
+	* gui/e-day-view.c: (e_day_view_get_text_color):
+	Using e_calendar_view_get_event_background
+	instead of e_cal_model_get_color_for_component.
+
 2007-06-18  Srinivasa Ragavan  <sragavan@novell.com>
 
         ** Fix for bug #448223 from Gilles Dartiguelongue
