Ejemplo n.º 1
0
/* Sensitizes the UI Component menu/toolbar calendar commands based on the
 * number of selected events. (This will always be 0 or 1 currently.)  If enable
 * is FALSE, all will be disabled.  Otherwise, the currently-selected number of
 * events will be used.
 */
void
calendar_control_sensitize_calendar_commands (BonoboControl *control, GnomeCalendar *gcal, gboolean enable)
{
	BonoboUIComponent *uic;
	GtkWidget *view;
	ECalMenu *menu;
	ECalModel *model;
	GPtrArray *events;
	GList *selected, *l;
	ECalMenuTargetSelect *t;

	uic = bonobo_control_get_ui_component (control);
	g_return_if_fail (uic != NULL);

	if (bonobo_ui_component_get_container (uic) == CORBA_OBJECT_NIL)
		return;

	view = gnome_calendar_get_current_view_widget (gcal);

	menu = gnome_calendar_get_calendar_menu (gcal);
	model = e_calendar_view_get_model((ECalendarView *)view);
	events = g_ptr_array_new();
	selected = e_calendar_view_get_selected_events((ECalendarView *)view);
	for (l=selected;l;l=g_list_next(l)) {
		ECalendarViewEvent *event = l->data;
		if (event && event->comp_data)
			g_ptr_array_add (events, e_cal_model_copy_component_data(event->comp_data));
	}
	g_list_free(selected);

	t = e_cal_menu_target_new_select(menu, model, events);
	if (!enable)
		t->target.mask = ~0;

	sensitize_items(uic, calendar_sensitize_table, t->target.mask);
#if 0
	/* retrieve read-onlyness of the default client */
	e_cal = e_cal_model_get_default_client (gnome_calendar_get_calendar_model (gcal));
	if (e_cal)
		e_cal_is_read_only (e_cal, &default_read_only, NULL);
	else
		default_read_only = TRUE;
#endif

	e_menu_update_target((EMenu *)menu, (EMenuTarget *)t);
}
Ejemplo n.º 2
0
void
dates_cal_open_cb (ECal *ecal, ECalendarStatus status, DatesData *d)
{
    gboolean read_only;
    GError *error = NULL;
    const char *ecal_name;
    ESource *source;
    ESourceGroup *group;
    GtkTreeIter iter;
    gchar *primary_uid;
    GSList *selected_list;
    gboolean selected;
	gchar * cal_name;
	
#ifdef DEBUG
    if (d->debug & DATES_DEBUG_CALENDAR)
	g_debug ("Calendar opened, setting up...");
#endif

    if (status != E_CALENDAR_STATUS_OK)
	{
		g_warning ("Error '%d' opening ecal", status);
		g_object_unref (ecal);
		if (d->first_load) {
			GtkWidget *dialog = gtk_message_dialog_new (
				GTK_WINDOW (d->main_window),
				GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
				GTK_MESSAGE_ERROR,
				GTK_BUTTONS_CLOSE,
				_("Dates failed to open the system calendar. "
				  "You will not be able to view or create "
				  "events; this may be remedied by restarting."));
			gtk_dialog_run (GTK_DIALOG (dialog));
		}
		return;
    }
	
    source = e_cal_get_source (ecal);

    ecal_name = e_source_peek_name (source);

    if (!e_cal_is_read_only (ecal, &read_only, &error))
	{
		g_warning ("Error querying calendar's read-only status: %s",
				   error->message);
		g_error_free (error);
		g_object_unref (ecal);
		return;
    }

	/* 
	 * Work around the fact that eds-dbus seems to be returning the wrong
	 * value for e_cal_is_read_only on the calendar itself for the http
	 * backend. But on the events themselves it is fine
	 */
	group = e_source_peek_group (source);
	if (strncmp (e_source_group_peek_base_uri (group), "webcal://", 9) == 0)
		read_only = TRUE;
	
    selected_list = gconf_client_get_list (gconf_client_get_default (),
					   CALENDAR_GCONF_SELECTED, GCONF_VALUE_STRING, NULL);
#ifdef DEBUG
		if (d->debug & DATES_DEBUG_CALENDAR)
			g_debug ("selected_list %p: is in uids %d",
					 selected_list,
					 is_in_uids (selected_list, source));
#endif
	
    if (selected_list && is_in_uids (selected_list, source))
	{
		dates_view_add_calendar (d->view, ecal);
		g_signal_connect (G_OBJECT (ecal), "backend_died",
						  G_CALLBACK (dates_backend_died_cb), d);
		selected = TRUE;
    }
	else
	{
		selected = FALSE;
    }
	
    if ((!read_only) && (selected))
	{
		if (!d->dcal)
			d->dcal = ecal;
		else
		{
			/* Find out if it's the default calendar */
			primary_uid = gconf_client_get_string (
				gconf_client_get_default (),
				CALENDAR_GCONF_PRIMARY, NULL);
			if (primary_uid) {
				if (strcmp (e_source_peek_uid (source),
							primary_uid) == 0)
					d->dcal = ecal;
				g_free (primary_uid);
			}
		}

		d->cal_loaded = TRUE;
	
		if (d->TBNew)
		{
#ifdef DEBUG
			if (d->debug & DATES_DEBUG_CALENDAR)
				g_debug ("*** Setting TBNew button sensitive ***");
#endif
			gtk_widget_set_sensitive (d->TBNew, TRUE);
		}
    }
	else
	{
#ifdef DEBUG
		if (d->debug & DATES_DEBUG_CALENDAR)
			g_debug ("*** RO %d, Selected %d ***", read_only, selected);
#endif
	}

	if (ecal_name && !read_only)
		cal_name = g_strdup (ecal_name);
	else if (ecal_name)
		cal_name = g_strconcat (ecal_name, _(" (Read Only)"), NULL);
	else if (!read_only)
		cal_name = g_strdup (_("Unknown"));
	else
		cal_name = g_strconcat (_("Unknown"), _(" (Read Only)"), NULL);
		
    gtk_list_store_insert_with_values (d->cal_list_store, &iter, G_MAXINT,
								COL_CALNAME, cal_name,
								COL_CALPTR, ecal,
								COL_NOTREADONLY, !read_only,
								COL_SELECTED, selected,
								-1);

	g_free (cal_name);
	
#ifdef DEBUG
    if (d->debug & DATES_DEBUG_CALENDAR)
		g_debug ("Calendar added.");
#endif

	dates_platform_cal_open (d);
}