Exemplo n.º 1
0
static void on_permissions_cb(GtkAction *action, EShellView *shell_view)
{
    EShellSidebar *shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
    ESourceSelector *selector;
    g_object_get (shell_sidebar, "selector", &selector, NULL);
    ESource *source = e_source_selector_peek_primary_selection (selector);
    ESourceGroup *group = e_source_peek_group (source);
    EeeAccount *account;

    if (!e_source_is_3e (source))
      {
        display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (selector)), _("This action is available only for 3e calendars."));
        g_object_unref (selector);
        return;
      }

    if (!eee_plugin_online)
    {
        display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (selector)), _("This action is not available with 3e plugin in offline mode."));
        g_object_unref (selector);
        return;
    }

    g_object_unref (selector);

    account = eee_accounts_manager_find_account_by_source(mgr(), source);
    acl_gui_create(mgr(), account, source);

}
Exemplo n.º 2
0
static void on_delete_cb(GtkAction *action, EShellView *shell_view)
{
    EShellSidebar *shell_sidebar = e_shell_view_get_shell_sidebar(shell_view);
    ESourceSelector *selector;
    g_object_get(shell_sidebar, "selector", &selector, NULL);
    ESource *source = e_source_selector_peek_primary_selection(selector);

    if (e_alert_run_dialog_for_args(GTK_WINDOW(shell_view),
                    "calendar:prompt-delete-calendar", e_source_peek_name(source), NULL) != GTK_RESPONSE_YES)
    {
        g_object_unref (selector);
        return;
    }

    ESourceGroup *group = e_source_peek_group(source);
    char *calname = (char *)e_source_get_property(source, "eee-calname");
    EeeAccount *account;
    GError *err = NULL;

    if (!eee_plugin_online)
    {
        display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (selector)), _("This action is not available with 3e plugin in offline mode."));
        g_object_unref (selector);
        return;
    }

    if (!e_source_is_3e_owned_calendar(source))
    {
        display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (selector)), _("This action is available only for 3e calendars."));
        g_object_unref (selector);
        return;
    }

    g_object_unref (selector);

    account = eee_accounts_manager_find_account_by_source(mgr(), source);
    if (eee_account_delete_calendar(account, calname))
    {
        // get ECal and remove calendar from the server
        ECalClient *ecal = e_cal_client_new(source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, &err);
        if (!e_client_remove_sync((EClient *)ecal, NULL, &err))
        {
            g_warning("** EEE ** ECal remove failed (%d:%s)", err->code, err->message);
            g_clear_error(&err);
        }
        g_object_unref(ecal);

        e_source_group_remove_source(group, source);
    }
    eee_account_disconnect(account);
    eee_accounts_manager_restart_sync(mgr());
}
Exemplo n.º 3
0
Boolean CheckCookie(FILE *fp)
{
  int     iNewCookie, iOldCookie;
  long    lSave_offset;
  char    buffer[256];
  char    *msgPtr, *errPtr;
  char    *keystr;
  char    *retbuf;
  fpos_t  filepos;
  char    *mc_pos;
  int     i;
  Boolean bGoodCookie = TRUE;

  /**************************************************************************/
  /* Save file pointer initial setting                                      */
  /**************************************************************************/
  lSave_offset = ftell (fp);

  /**************************************************************************/
  /* Set file pointer to beginning of file                                  */
  /**************************************************************************/
  fseek (fp, 0, SEEK_SET);

  /**************************************************************************/
  /* Calculate magic cookie                                                 */
  /**************************************************************************/
  iNewCookie = CalculateMagicCookie(fp);
#ifdef DEBUG
  printf("New Magic Cookie: %d\n", iNewCookie);
#endif

  /**************************************************************************/
  /* Find location in header of old cookie and retrieve it.                 */
  /**************************************************************************/
  keystr = (char *)NULL;
  retbuf = buffer;
  i = 0;
  while ( !keystr && retbuf && (i < MAX_HEADER_LINES) ) {
    fgetpos(fp, &filepos);
    retbuf = fgets(buffer, 80, fp);
    keystr = strstr (buffer, "$KEY:");
    i++;
  }

  if (!keystr) {
#ifdef DEBUG
     printf("No '$KEY' keyword in file header. File is invalid.\n");
#endif
     msgPtr = GETMESSAGE(5, 67,
	 "Create Action can only edit files that were created\n\
and edited by Create Action.");
     errPtr = XtNewString(msgPtr);
     display_error_message(CreateActionAppShell, errPtr);
     XtFree(errPtr);
     bGoodCookie = FALSE;
     fseek (fp, lSave_offset, SEEK_SET);
     return(bGoodCookie);
  }
Exemplo n.º 4
0
int
color_env_parse(char *env)

{
	char	   *p;
	char	   *min;
	char	   *max;
	char	   *str;
	int			len;
	color_entry *ce;

	/* initialization */
	color_ansi = (char **) malloc(COLOR_ANSI_SLOTS * sizeof(char *));
	max_color_ansi = COLOR_ANSI_SLOTS;

	/* color slot 0 is always "0" */
	color_slot("0");

	if (env != NULL)
	{
		p = strtok(env, ":");
		while (p != NULL)
		{
			if ((min = strchr(p, '=')) != NULL &&
				(max = strchr(min, ',')) != NULL &&
				(str = strchr(max, '#')) != NULL)
			{
				ce = (color_entry *) malloc(sizeof(color_entry));
				len = min - p;
				ce->tag = (char *) malloc(len + 1);
				strncpy(ce->tag, p, len);
				ce->tag[len] = '\0';
				ce->min = atoi(++min);
				ce->max = atoi(++max);
				ce->color = color_slot(++str);

				ce->next = entries;
				entries = ce;
			}
			else
			{
				if (min != NULL)
				{
					len = min - p;
				}
				else
				{
					len = strlen(p);
				}
				display_error_message(" %.*s: bad color entry", len, p);
			}
			p = strtok(NULL, ":");
		}
	}
	return 0;
}
Exemplo n.º 5
0
void handle_errors(int error, int operation)
{
   static int retry_attempts = NUM_OF_RETRIES;

   if (error == BUS_ERROR || error == UNABLE_TO_CONNECT || error == BUS_INIT_ERROR)
   {
      display_error_message(error, FALSE);
      retry_attempts = NUM_OF_RETRIES;
      clear_trouble_codes();
      num_of_codes_reported = 0;
      mil_is_on = FALSE;
      broadcast_dialog_message(MSG_READY, 0); // tell everyone that we're done
   }
   else    // if we received "BUS BUSY", "DATA ERROR", "<DATA ERROR", SERIAL_ERROR, or RUBBISH,
   {       // try to re-send the request, do nothing if successful and alert user if failed:
      if(retry_attempts > 0) //
      {
         retry_attempts--;
         switch (operation)
         {
            case READ_CODES:
            case READ_PENDING:
            case NUM_OF_CODES:  // if we are currently reading codes,
               broadcast_dialog_message(MSG_READ_CODES, 0); // try reading again
               break;

            case CLEAR_CODES:   // if we are currently clearing codes,
               broadcast_dialog_message(MSG_CLEAR_CODES, 0);  // try clearing again
               break;
         }
      }
      else
      {
         display_error_message(error, FALSE);
         retry_attempts = NUM_OF_RETRIES; // reset the number of retry attempts
         clear_trouble_codes();
         num_of_codes_reported = 0;
         mil_is_on = FALSE;
         broadcast_dialog_message(MSG_READY, 0); // tell everyone that we're done
      }
   }
}
Exemplo n.º 6
0
	void surface_manager::display_error_message(const std::string& aTitle, const std::string& aMessage) const
	{
		for (auto i = iSurfaces.begin(); i != iSurfaces.end(); ++i)
		{
			if ((*i)->destroyed())
				continue;
			if ((*i)->surface_type() == surface_type::Window && static_cast<i_native_window&>((*i)->native_surface()).is_active())
			{
				display_error_message((*i)->native_surface(), aTitle, aMessage);
				return;
			}
		}
		iBasicServices.display_error_dialog(aTitle.c_str(), aMessage.c_str(), 0);
	}
/**
 *  Display error message and stop boot process.
 */
void display_error_msg()
{
	fb_config = fbcon_display();

	if (fb_config)
	{
		fbcon_clear();
		display_error_message();   // No point in checking the return value here
	}

	// Invalid state. Nothing to be done but contacting the OEM.
	// Stop boot process.
	dprintf(CRITICAL,"ERROR: blocking boot process\n");
	for(;;);
}
/**
 * Display the basic layout of the screen (done only once).
 */
static void display_initial_screen(uint32_t pin_length)
{
    if (g_initial_screen_displayed == true)
		return;

    fb_config = fbcon_display();

    if (fb_config)
	{
		fbcon_clear();

		if (display_error_message())
		    display_error_msg(); /* This will never return */
		display_initial_delay();

		mdelay(INITIAL_DELAY_MSECONDS);

		g_pin_frames_y_location = ((fb_config->height)*PIN_RELATIVE_Y_LOCATION);

		uint32_t total_pin_length = pin_length*MDTP_PIN_DIGIT_WIDTH + DIGIT_SPACE*(pin_length - 1);
		uint32_t complete_pin_centered = (fb_config->width - total_pin_length)/2;

		for (uint32_t i=0; i<pin_length; i++)
		{
			g_pin_frames_x_location[i] = complete_pin_centered + i*(DIGIT_SPACE+MDTP_PIN_DIGIT_WIDTH);
		}

		for (uint32_t i=0; i<pin_length; i++)
		{
			display_digit(g_pin_frames_x_location[i], g_pin_frames_y_location, 0);
		}

		display_ok_button();

		g_initial_screen_displayed = true;
	}
	else
	{
	    dprintf(CRITICAL,"ERROR: fbcon_config struct is NULL\n");
	    display_error_msg(); /* This will never return */
	}
}
Exemplo n.º 9
0
static void
do_save_calendar_rdf (FormatHandler *handler,
                      ESourceSelector *selector,
                      ECalClientSourceType type,
                      gchar *dest_uri)
{

	/*
	 * According to some documentation about CSV, newlines 'are' allowed
	 * in CSV-files. But you 'do' have to put the value between quotes.
	 * The helper 'string_needsquotes' will check for that
	 *
	 * http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm
	 * http://www.creativyst.com/cgi-bin/Prod/15/eg/csv2xml.pl
	 */

	ESource *primary_source;
	EClient *source_client;
	GError *error = NULL;
	GSList *objects = NULL;
	gchar *temp = NULL;
	GOutputStream *stream;

	if (!dest_uri)
		return;

	/* open source client */
	primary_source = e_source_selector_ref_primary_selection (selector);
	source_client = e_cal_client_connect_sync (
		primary_source, type, NULL, &error);
	g_object_unref (primary_source);

	/* Sanity check. */
	g_return_if_fail (
		((source_client != NULL) && (error == NULL)) ||
		((source_client == NULL) && (error != NULL)));

	if (source_client == NULL) {
		display_error_message (
			gtk_widget_get_toplevel (GTK_WIDGET (selector)),
			error->message);
		g_error_free (error);
		return;
	}

	stream = open_for_writing (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (selector))), dest_uri, &error);

	if (stream && e_cal_client_get_object_list_as_comps_sync (E_CAL_CLIENT (source_client), "#t", &objects, NULL, NULL)) {
		GSList *iter;

		xmlBufferPtr buffer = xmlBufferCreate ();
		xmlDocPtr doc = xmlNewDoc ((xmlChar *) "1.0");
		xmlNodePtr fnode;

		doc->children = xmlNewDocNode (doc, NULL, (const guchar *)"rdf:RDF", NULL);
		xmlSetProp (doc->children, (const guchar *)"xmlns:rdf", (const guchar *)"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
		xmlSetProp (doc->children, (const guchar *)"xmlns", (const guchar *)"http://www.w3.org/2002/12/cal/ical#");

		fnode = xmlNewChild (doc->children, NULL, (const guchar *)"Vcalendar", NULL);

		/* Should Evolution publicise these? */
		xmlSetProp (fnode, (const guchar *)"xmlns:x-wr", (const guchar *)"http://www.w3.org/2002/12/cal/prod/Apple_Comp_628d9d8459c556fa#");
		xmlSetProp (fnode, (const guchar *)"xmlns:x-lic", (const guchar *)"http://www.w3.org/2002/12/cal/prod/Apple_Comp_628d9d8459c556fa#");

		/* Not sure if it's correct like this */
		xmlNewChild (fnode, NULL, (const guchar *)"prodid", (const guchar *)"-//" PACKAGE_STRING "//iCal 1.0//EN");

		/* Assuming GREGORIAN is the only supported calendar scale */
		xmlNewChild (fnode, NULL, (const guchar *)"calscale", (const guchar *)"GREGORIAN");

		temp = calendar_config_get_timezone ();
		xmlNewChild (fnode, NULL, (const guchar *)"x-wr:timezone", (guchar *) temp);
		g_free (temp);

		xmlNewChild (fnode, NULL, (const guchar *)"method", (const guchar *)"PUBLISH");

		xmlNewChild (fnode, NULL, (const guchar *)"x-wr:relcalid", (guchar *) e_source_get_uid (primary_source));

		xmlNewChild (fnode, NULL, (const guchar *)"x-wr:calname", (guchar *) e_source_get_display_name (primary_source));

		/* Version of this RDF-format */
		xmlNewChild (fnode, NULL, (const guchar *)"version", (const guchar *)"2.0");

		for (iter = objects; iter; iter = iter->next) {
			ECalComponent *comp = iter->data;
			const gchar *temp_constchar;
			gchar *tmp_str = NULL;
			GSList *temp_list;
			ECalComponentDateTime temp_dt;
			struct icaltimetype *temp_time;
			gint *temp_int;
			ECalComponentText temp_comptext;
			xmlNodePtr c_node = xmlNewChild (fnode, NULL, (const guchar *)"component", NULL);
			xmlNodePtr node = xmlNewChild (c_node, NULL, (const guchar *)"Vevent", NULL);

			/* Getting the stuff */
			e_cal_component_get_uid (comp, &temp_constchar);
			tmp_str = g_strdup_printf ("#%s", temp_constchar);
			xmlSetProp (node, (const guchar *)"about", (guchar *) tmp_str);
			g_free (tmp_str);
			add_string_to_rdf (node, "uid",temp_constchar);

			e_cal_component_get_summary (comp, &temp_comptext);
			add_string_to_rdf (node, "summary", temp_comptext.value);

			e_cal_component_get_description_list (comp, &temp_list);
			add_list_to_rdf (node, "description", temp_list, ECALCOMPONENTTEXT);
			if (temp_list)
				e_cal_component_free_text_list (temp_list);

			e_cal_component_get_categories_list (comp, &temp_list);
			add_list_to_rdf (node, "categories", temp_list, CONSTCHAR);
			if (temp_list)
				e_cal_component_free_categories_list (temp_list);

			e_cal_component_get_comment_list (comp, &temp_list);
			add_list_to_rdf (node, "comment", temp_list, ECALCOMPONENTTEXT);

			if (temp_list)
				e_cal_component_free_text_list (temp_list);

			e_cal_component_get_completed (comp, &temp_time);
			add_time_to_rdf (node, "completed", temp_time);
			if (temp_time)
				e_cal_component_free_icaltimetype (temp_time);

			e_cal_component_get_created (comp, &temp_time);
			add_time_to_rdf (node, "created", temp_time);
			if (temp_time)
				e_cal_component_free_icaltimetype (temp_time);

			e_cal_component_get_contact_list (comp, &temp_list);
			add_list_to_rdf (node, "contact", temp_list, ECALCOMPONENTTEXT);
			if (temp_list)
				e_cal_component_free_text_list (temp_list);

			e_cal_component_get_dtstart (comp, &temp_dt);
			add_time_to_rdf (node, "dtstart", temp_dt.value ? temp_dt.value : NULL);
			e_cal_component_free_datetime (&temp_dt);

			e_cal_component_get_dtend (comp, &temp_dt);
			add_time_to_rdf (node, "dtend", temp_dt.value ? temp_dt.value : NULL);
			e_cal_component_free_datetime (&temp_dt);

			e_cal_component_get_due (comp, &temp_dt);
			add_time_to_rdf (node, "due", temp_dt.value ? temp_dt.value : NULL);
			e_cal_component_free_datetime (&temp_dt);

			e_cal_component_get_percent (comp, &temp_int);
			add_nummeric_to_rdf (node, "percentComplete", temp_int);

			e_cal_component_get_priority (comp, &temp_int);
			add_nummeric_to_rdf (node, "priority", temp_int);

			e_cal_component_get_url (comp, &temp_constchar);
			add_string_to_rdf (node, "URL", temp_constchar);

			if (e_cal_component_has_attendees (comp)) {
				e_cal_component_get_attendee_list (comp, &temp_list);
				add_list_to_rdf (node, "attendee", temp_list, ECALCOMPONENTATTENDEE);
				if (temp_list)
					e_cal_component_free_attendee_list (temp_list);
			}

			e_cal_component_get_location (comp, &temp_constchar);
			add_string_to_rdf (node, "location", temp_constchar);

			e_cal_component_get_last_modified (comp, &temp_time);
			add_time_to_rdf (node, "lastModified",temp_time);

			/* Important note!
			 * The documentation is not requiring this!
			 *
			 * if (temp_time) e_cal_component_free_icaltimetype (temp_time);
			 *
			 * Please uncomment and fix documentation if untrue
			 * http://www.gnome.org/projects/evolution/developer-doc/libecal/ECalComponent.html
			 *	#e-cal-component-get-last-modified
			 */
		}

		/* I used a buffer rather than xmlDocDump: I want gio support */
		xmlNodeDump (buffer, doc, doc->children, 2, 1);

		g_output_stream_write_all (stream, xmlBufferContent (buffer), xmlBufferLength (buffer), NULL, NULL, &error);
		g_output_stream_close (stream, NULL, NULL);

		e_cal_client_free_ecalcomp_slist (objects);

		xmlBufferFree (buffer);
		xmlFreeDoc (doc);
	}

	if (stream)
		g_object_unref (stream);

	g_object_unref (source_client);

	if (error != NULL) {
		display_error_message (
			gtk_widget_get_toplevel (GTK_WIDGET (selector)),
			error->message);
		g_error_free (error);
	}
}
Exemplo n.º 10
0
static void
do_save_calendar_csv (FormatHandler *handler,
                      ESourceSelector *selector,
                      ECalClientSourceType type,
                      gchar *dest_uri)
{

	/*
	 * According to some documentation about CSV, newlines 'are' allowed
	 * in CSV-files. But you 'do' have to put the value between quotes.
	 * The helper 'string_needsquotes' will check for that
	 *
	 * http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm
	 * http://www.creativyst.com/cgi-bin/Prod/15/eg/csv2xml.pl
	 */

	ESource *primary_source;
	EClient *source_client;
	GError *error = NULL;
	GSList *objects = NULL;
	GOutputStream *stream;
	GString *line = NULL;
	CsvConfig *config = NULL;
	CsvPluginData *d = handler->data;
	const gchar *tmp = NULL;

	if (!dest_uri)
		return;

	/* open source client */
	primary_source = e_source_selector_ref_primary_selection (selector);
	source_client = e_cal_client_connect_sync (
		primary_source, type, NULL, &error);
	g_object_unref (primary_source);

	/* Sanity check. */
	g_return_if_fail (
		((source_client != NULL) && (error == NULL)) ||
		((source_client == NULL) && (error != NULL)));

	if (source_client == NULL) {
		display_error_message (
			gtk_widget_get_toplevel (GTK_WIDGET (selector)),
			error);
		g_error_free (error);
		return;
	}

	config = g_new (CsvConfig, 1);

	tmp = gtk_entry_get_text (GTK_ENTRY (d->delimiter_entry));
	config->delimiter = userstring_to_systemstring (tmp ? tmp:", ");
	tmp = gtk_entry_get_text (GTK_ENTRY (d->newline_entry));
	config->newline = userstring_to_systemstring (tmp ? tmp:"\\n");
	tmp = gtk_entry_get_text (GTK_ENTRY (d->quote_entry));
	config->quote = userstring_to_systemstring (tmp ? tmp:"\"");
	config->header = gtk_toggle_button_get_active (
		GTK_TOGGLE_BUTTON (d->header_check));

	stream = open_for_writing (
		GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (selector))),
		dest_uri, &error);

	if (stream && e_cal_client_get_object_list_as_comps_sync (E_CAL_CLIENT (source_client), "#t", &objects, NULL, NULL)) {
		GSList *iter;

		if (config->header) {

			gint i = 0;

			static const gchar *labels[] = {
				 N_("UID"),
				 N_("Summary"),
				 N_("Description List"),
				 N_("Categories List"),
				 N_("Comment List"),
				 N_("Completed"),
				 N_("Created"),
				 N_("Contact List"),
				 N_("Start"),
				 N_("End"),
				 N_("Due"),
				 N_("percent Done"),
				 N_("Priority"),
				 N_("URL"),
				 N_("Attendees List"),
				 N_("Location"),
				 N_("Modified"),
			};

			line = g_string_new ("");
			for (i = 0; i < G_N_ELEMENTS (labels); i++) {
				if (i > 0)
					g_string_append (line, config->delimiter);
				g_string_append (line, _(labels[i]));
			}

			g_string_append (line, config->newline);

			g_output_stream_write_all (
				stream, line->str, line->len,
				NULL, NULL, NULL);
			g_string_free (line, TRUE);
		}

		for (iter = objects; iter; iter = iter->next) {
			ECalComponent *comp = iter->data;
			gchar *delimiter_temp = NULL;
			const gchar *temp_constchar;
			GSList *temp_list;
			ECalComponentDateTime temp_dt;
			struct icaltimetype *temp_time;
			gint *temp_int;
			ECalComponentText temp_comptext;

			line = g_string_new ("");

			/* Getting the stuff */
			e_cal_component_get_uid (comp, &temp_constchar);
			line = add_string_to_csv (line, temp_constchar, config);

			e_cal_component_get_summary (comp, &temp_comptext);
			line = add_string_to_csv (
				line, temp_comptext.value, config);

			e_cal_component_get_description_list (comp, &temp_list);
			line = add_list_to_csv (
				line, temp_list, config, ECALCOMPONENTTEXT);
			if (temp_list)
				e_cal_component_free_text_list (temp_list);

			e_cal_component_get_categories_list (comp, &temp_list);
			line = add_list_to_csv (
				line, temp_list, config, CONSTCHAR);
			if (temp_list)
				e_cal_component_free_categories_list (temp_list);

			e_cal_component_get_comment_list (comp, &temp_list);
			line = add_list_to_csv (
				line, temp_list, config, ECALCOMPONENTTEXT);
			if (temp_list)
				e_cal_component_free_text_list (temp_list);

			e_cal_component_get_completed (comp, &temp_time);
			line = add_time_to_csv (line, temp_time, config);
			if (temp_time)
				e_cal_component_free_icaltimetype (temp_time);

			e_cal_component_get_created (comp, &temp_time);
			line = add_time_to_csv (line, temp_time, config);
			if (temp_time)
				e_cal_component_free_icaltimetype (temp_time);

			e_cal_component_get_contact_list (comp, &temp_list);
			line = add_list_to_csv (
				line, temp_list, config, ECALCOMPONENTTEXT);
			if (temp_list)
				e_cal_component_free_text_list (temp_list);

			e_cal_component_get_dtstart (comp, &temp_dt);
			line = add_time_to_csv (
				line, temp_dt.value ?
				temp_dt.value : NULL, config);
			e_cal_component_free_datetime (&temp_dt);

			e_cal_component_get_dtend (comp, &temp_dt);
			line = add_time_to_csv (
				line, temp_dt.value ?
				temp_dt.value : NULL, config);
			e_cal_component_free_datetime (&temp_dt);

			e_cal_component_get_due (comp, &temp_dt);
			line = add_time_to_csv (
				line, temp_dt.value ?
				temp_dt.value : NULL, config);
			e_cal_component_free_datetime (&temp_dt);

			e_cal_component_get_percent (comp, &temp_int);
			line = add_nummeric_to_csv (line, temp_int, config);

			e_cal_component_get_priority (comp, &temp_int);
			line = add_nummeric_to_csv (line, temp_int, config);

			e_cal_component_get_url (comp, &temp_constchar);
			line = add_string_to_csv (line, temp_constchar, config);

			if (e_cal_component_has_attendees (comp)) {
				e_cal_component_get_attendee_list (comp, &temp_list);
				line = add_list_to_csv (
					line, temp_list, config,
					ECALCOMPONENTATTENDEE);
				if (temp_list)
					e_cal_component_free_attendee_list (temp_list);
			} else {
				line = add_list_to_csv (
					line, NULL, config,
					ECALCOMPONENTATTENDEE);
			}

			e_cal_component_get_location (comp, &temp_constchar);
			line = add_string_to_csv (line, temp_constchar, config);

			e_cal_component_get_last_modified (comp, &temp_time);

			/* Append a newline (record delimiter) */
			delimiter_temp = config->delimiter;
			config->delimiter = config->newline;

			line = add_time_to_csv (line, temp_time, config);

			/* And restore for the next record */
			config->delimiter = delimiter_temp;

			/* Important note!
			 * The documentation is not requiring this!
			 *
			 * if (temp_time)
			 *     e_cal_component_free_icaltimetype (temp_time);
			 *
			 * Please uncomment and fix documentation if untrue
			 * http://www.gnome.org/projects/evolution/
			 *	developer-doc/libecal/ECalComponent.html
			 *	#e-cal-component-get-last-modified
			 */
			g_output_stream_write_all (
				stream, line->str, line->len,
				NULL, NULL, &error);

			/* It's written, so we can free it */
			g_string_free (line, TRUE);
		}

		g_output_stream_close (stream, NULL, NULL);

		e_cal_client_free_ecalcomp_slist (objects);
	}

	if (stream)
		g_object_unref (stream);

	g_object_unref (source_client);

	g_free (config->delimiter);
	g_free (config->quote);
	g_free (config->newline);
	g_free (config);

	if (error != NULL) {
		display_error_message (
			gtk_widget_get_toplevel (GTK_WIDGET (selector)),
			error);
		g_error_free (error);
	}
}
Exemplo n.º 11
0
// heart of the trouble_code_reader module:
int tr_code_proc(int msg, DIALOG *d, int c)
{
   static char vehicle_response[1024];        // character buffer for car response
   static int first_read_occured = FALSE;
   static int receiving_response = FALSE;    // flag, "are we receiving response?"
   static int verifying_connection = FALSE;  // flag, "are we verifying connection?"
   static int current_request = CRQ_NONE;    // NUM_OF_CODES, READ_CODES, CLEAR_CODES
   int response_status = EMPTY;              // EMPTY, DATA, PROMPT
   int response_type;                        // BUS_BUSY, BUS_ERROR, DATA_ERROR, etc.
   int pending_codes_cnt = 0;
   char comport_buffer[256];                  // temporary storage for comport data
   char buf1[64];
   char buf2[64];

   switch (msg)
   {
      case MSG_IDLE:
         if (!first_read_occured)
         {
            if (!simulate)
               read_codes();
            first_read_occured = TRUE;
            return D_O_K;
         }
         
         if (simulate)
            break;
         
         if (comport.status == READY)
         {
            if (!receiving_response)
            {
               if (verifying_connection)
               {
                  send_command("0100"); // send request that requires a response
                  receiving_response = TRUE; // now we're waiting for response
                  vehicle_response[0] = 0; //get buffer ready for the response
                  start_serial_timer(OBD_REQUEST_TIMEOUT); // start the timer
               }
               else if (current_request == READ_PENDING)
               {
                  send_command("07");   // request "pending" codes
                  receiving_response = TRUE;     // and receiving response
                  vehicle_response[0] = '\0';    // clear the buffer
                  start_serial_timer(OBD_REQUEST_TIMEOUT); // start the timer...
               }
            }
            else
            {
               response_status = read_comport(comport_buffer);

               if (response_status == DATA) // if data detected in com port buffer
               {
                  // append contents of comport_buffer to vehicle_response:
                  strcat(vehicle_response, comport_buffer);
                  start_serial_timer(OBD_REQUEST_TIMEOUT);  // we got data, reset the timer
               }
               else if (response_status == PROMPT) // if ">" is detected
               {
                  receiving_response = FALSE; // we're not waiting for response any more
                  stop_serial_timer();        // stop the timer
                  // append contents of comport_buffer to vehicle_response:
                  strcat(vehicle_response, comport_buffer);

                  if (verifying_connection)     // *** if we are verifying connection ***
                  {  // NOTE: we only get here if we got "NO DATA" somewhere else
                     response_type = process_response("0100", vehicle_response);
                     verifying_connection = FALSE; // we're not verifying connection anymore

                     if (response_type == HEX_DATA) // if everything seems to be fine now,
                     {
                        if (current_request == CLEAR_CODES)
                           alert("There may have been a temporary loss of connection.", "Please try clearing codes again.", NULL, "OK", NULL, 0, 0);
                        else if (current_request == NUM_OF_CODES)
                           alert("There may have been a temporary loss of connection.", "Please try reading codes again.", NULL, "OK", NULL, 0, 0);
                        else if (current_request == READ_CODES)
                        {
                           current_request = READ_PENDING;
                           break;
                        }
                     }
                     else if (response_type == ERR_NO_DATA)
                     {
                        if (current_request == CLEAR_CODES) // if we were clearing codes,
                           alert("Communication problem: vehicle did not confirm successful", "deletion of trouble codes.  Please check connection to the vehicle,", "make sure the ignition is ON, and try clearing the codes again.", "OK", NULL, 0, 0);
                        else // if we were reading codes or requesting number or DTCs
                           alert("There may have been a loss of connection.", "Please check connection to the vehicle,", "and make sure the ignition is ON", "OK", NULL, 0, 0);
                     }
                     else
                        display_error_message(response_type, FALSE);
                        
                     broadcast_dialog_message(MSG_READY, 0); // tell everyone we're done
                  }

                  else if (current_request == NUM_OF_CODES) // *** if we are getting number of codes ***
                  {
                     response_type = process_response("0101", vehicle_response);

                     if (response_type == ERR_NO_DATA)   // if we received "NO DATA"
                        verifying_connection = TRUE;  // verify connection
                     else if (response_type != HEX_DATA) // if we got an error,
                        handle_errors(response_type, NUM_OF_CODES);  // handle it
                     else    // if process response returned HEX_DATA (i.e. there are no errors)
                     {  // extract # of codes from vehicle_response
                        num_of_codes_reported = handle_num_of_codes(vehicle_response);
                     
                        send_command("03");   // request "stored" codes
                        current_request = READ_CODES;  // we're reading stored codes now
                        receiving_response = TRUE;     // and receiving response
                        vehicle_response[0] = '\0';    // clear the buffer
                        start_serial_timer(OBD_REQUEST_TIMEOUT); // start the timer...
                     }
                  }
                  else if (current_request == READ_CODES) // if we are reading codes,
                  {
                     response_type = process_response("03", vehicle_response);

                     if (response_type == ERR_NO_DATA) // vehicle didn't respond, check connection
                     {
                        if (num_of_codes_reported > 0)
                           verifying_connection = TRUE;
                        else
                           current_request = READ_PENDING;
                     }
                     else if (response_type == HEX_DATA)
                     {
                        handle_read_codes(vehicle_response, FALSE);
                        current_request = READ_PENDING;
                     }
                     else  // if we got an error
                        handle_errors(response_type, READ_CODES);
                  }
                  else if(current_request == READ_PENDING) // if we are reading pending codes,
                  {
                     response_type = process_response("07", vehicle_response);

                     if (response_type == ERR_NO_DATA)
                     {
                        if (get_number_of_codes() == 0 && num_of_codes_reported == 0)
                           alert("No Diagnostic Trouble Codes (DTCs) detected", NULL, NULL, "OK", NULL, 0, 0);
                     }
                     else if(response_type != HEX_DATA) // if we got an error,
                     {
                        handle_errors(response_type, READ_PENDING);
                        break;
                     }
                     else  // if there were *no* errors,
                        pending_codes_cnt = handle_read_codes(vehicle_response, TRUE);

                     // if number of DTCs reported by 0101 request does not equal either number or total DTCs or just stored DTCs
                     if ((get_number_of_codes() != num_of_codes_reported) && (get_number_of_codes() - pending_codes_cnt != num_of_codes_reported))
                     {
                        sprintf(buf1, "Vehicle reported %i Diagnostic Trouble Codes (DTCs).", num_of_codes_reported);
                        sprintf(buf2, "However, %i non-pending DTC(s) have been successfully read.", get_number_of_codes() - pending_codes_cnt);
                        alert(buf1, buf2, "Try reading codes again.", "OK", NULL, 0, 0);
                     }

                     populate_trouble_codes_list();
                     broadcast_dialog_message(MSG_READY, 0); // tell everyone we're done
                  }
                  else if(current_request == CLEAR_CODES)
                  {
                     response_type = process_response("04", vehicle_response);

                     if (response_type == ERR_NO_DATA)// vehicle didn't respond, check connection
                        verifying_connection = TRUE;
                     else if(response_type != HEX_DATA) // if we got an error,
                        handle_errors(response_type, CLEAR_CODES);
                     else // if everything's fine (received confirmation)
                     {
                        clear_trouble_codes();
                        num_of_codes_reported = 0;
                        mil_is_on = FALSE;
                        broadcast_dialog_message(MSG_READY, 0);
                     }
                  }
               }
               else if (serial_time_out)     // if request timed out,
               {
                  stop_serial_timer();
                  receiving_response = FALSE;
                  num_of_codes_reported = 0;
                  mil_is_on = FALSE;
                  clear_trouble_codes();
                  broadcast_dialog_message(MSG_READY, 0);

                  if(alert("Device is not responding.", "Please check that it is connected", "and the port settings are correct", "OK",  "&Configure Port", 27, 'c') == 2)
                     display_options();   // let the user choose correct settings

                  while (comport.status == NOT_OPEN)
                  {
                     if (alert("Port is not ready.", "Please check that you specified the correct port", "and that no other application is using it", "&Configure Port", "&Ignore", 'c', 'i') == 1)
                        display_options(); // let the user choose correct settings
                     else
                        comport.status = USER_IGNORED;
                  }
               }
            }
         }
         break;  // end case MSG_IDLE

      case MSG_START:
         first_read_occured = FALSE;
         num_of_codes_reported = 0;
         mil_is_on = FALSE;
         // fall through
         
      case MSG_READY:
         receiving_response = FALSE;
         verifying_connection = FALSE;
         current_request = CRQ_NONE;
         break;

      case MSG_READ_CODES:
         if (comport.status == READY)
         {
            send_command("0101"); // request number of trouble codes
            start_serial_timer(OBD_REQUEST_TIMEOUT); // start the timer
            current_request = NUM_OF_CODES;
            receiving_response = TRUE; // now we're waiting for response
            vehicle_response[0] = 0;
            clear_trouble_codes();
            num_of_codes_reported = 0;
            mil_is_on = FALSE;
         }
         else
            serial_time_out = TRUE;
         break;

      case MSG_CLEAR_CODES:
         if (comport.status == READY)
         {
            send_command("04"); // "clear codes" request
            current_request = CLEAR_CODES;
            receiving_response = TRUE; // now we're waiting for response
            vehicle_response[0] = 0;
            start_serial_timer(OBD_REQUEST_TIMEOUT); // start the timer
         }
         else
            serial_time_out = TRUE;
         break;

      case MSG_END:
         stop_serial_timer();
         break;
   }

   return D_O_K;
}  // end of tr_codes_proc()
Exemplo n.º 12
0
Arquivo: main.c Projeto: 33d/gbsim
int main(int argc, char* argv[]) {
	int r = 0;

	char* elf_file = NULL;
	int gdb_port = 0;

	for (char** arg = &argv[1]; *arg != NULL; ++arg) {
		if (strcmp("-d", *arg) == 0)
			gdb_port = atoi(*(++arg));
		else
			elf_file = *arg;
	}
	if (elf_file == NULL) {
		fprintf(stderr, "Give me a .elf file to load\n");
		return 1;
	}

	elf_firmware_t f;
	elf_read_firmware(elf_file, &f);
	avr_t* avr = avr_make_mcu_by_name("atmega328p");
	if (!avr) {
		fprintf(stderr, "Unsupported cpu atmega328p\n");
		return 1;
	}

	avr_init(avr);
	if (gdb_port != 0) {
		avr->gdb_port = gdb_port;
		avr_gdb_init(avr);
	}
	avr->frequency = 16000000;
	avr_load_firmware(avr, &f);

	pcd8544_init(avr, &lcd);
	avr_connect_irq(avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 2),
			lcd.irq + IRQ_PCD8544_DC);
	avr_connect_irq(avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 1),
			lcd.irq + IRQ_PCD8544_CS);
	avr_connect_irq(avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 0),
			lcd.irq + IRQ_PCD8544_RST);
	avr_connect_irq(avr_io_getirq(avr, AVR_IOCTL_SPI_GETIRQ(0), SPI_IRQ_OUTPUT),
			lcd.irq + IRQ_PCD8544_SPI_IN);

	gb_keypad_init(avr, &keypad);
	for (int i = 0; i < keydefs_length; i++) {
		const keydef_t *k = keydefs + i;
		avr_connect_irq(keypad.irq + k->keypad_key,
				avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ(k->port), k->pin));

		// Start with the pin high
		avr_ioport_t* port = (avr_ioport_t*) avr->io[k->avr_port].w.param;
		key_io[i].pin_mask = (1<<k->pin);
		key_io[i].pull_value = &port->external.pull_value;
		port->external.pull_mask |= key_io[i].pin_mask;
		port->external.pull_value |= key_io[i].pin_mask;
		gb_keypad_press(&keypad, k->keypad_key, 1);
	}

	if (display_init()) {
		lcd_ram_mutex = SDL_CreateMutex();
		SDL_Thread* avr_thread = SDL_CreateThread(avr_run_thread, "avr-thread", avr);
		main_loop();
		SDL_LockMutex(lcd_ram_mutex);
		quit_flag = 1;
		SDL_UnlockMutex(lcd_ram_mutex);
		int avr_thread_return;
		SDL_WaitThread(avr_thread, &avr_thread_return);
		SDL_DestroyMutex(lcd_ram_mutex);
	} else {
		r = 1;
		fprintf(stderr, "%s\n", display_error_message());
	}

	display_destroy();

	return r;
}
Exemplo n.º 13
0
static void
do_save_calendar_ical (FormatHandler *handler,
                       ESourceSelector *selector,
		       EClientCache *client_cache,
                       gchar *dest_uri)
{
	ESource *primary_source;
	EClient *source_client;
	GError *error = NULL;
	GSList *objects = NULL;
	icalcomponent *top_level = NULL;

	if (!dest_uri)
		return;

	/* open source client */
	primary_source = e_source_selector_ref_primary_selection (selector);
	source_client = e_client_cache_get_client_sync (client_cache,
		primary_source, e_source_selector_get_extension_name (selector), 30, NULL, &error);
	g_object_unref (primary_source);

	/* Sanity check. */
	g_return_if_fail (
		((source_client != NULL) && (error == NULL)) ||
		((source_client == NULL) && (error != NULL)));

	if (error != NULL) {
		display_error_message (
			gtk_widget_get_toplevel (GTK_WIDGET (selector)),
			error->message);
		g_error_free (error);
		return;
	}

	/* create destination file */
	top_level = e_cal_util_new_top_level ();

	e_cal_client_get_object_list_sync (
		E_CAL_CLIENT (source_client), "#t", &objects, NULL, &error);

	if (objects != NULL) {
		CompTzData tdata;
		GOutputStream *stream;
		GSList *iter;

		tdata.zones = g_hash_table_new (g_str_hash, g_str_equal);
		tdata.client = E_CAL_CLIENT (source_client);

		for (iter = objects; iter; iter = iter->next) {
			icalcomponent *icalcomp = icalcomponent_new_clone (iter->data);

			icalcomponent_foreach_tzid (icalcomp, insert_tz_comps, &tdata);
			icalcomponent_add_component (top_level, icalcomp);
		}

		g_hash_table_foreach (tdata.zones, (GHFunc) append_tz_to_comp, top_level);

		g_hash_table_destroy (tdata.zones);
		tdata.zones = NULL;

		/* save the file */
		stream = open_for_writing (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (selector))), dest_uri, &error);

		if (stream) {
			gchar *ical_str = icalcomponent_as_ical_string_r (top_level);

			g_output_stream_write_all (stream, ical_str, strlen (ical_str), NULL, NULL, &error);
			g_output_stream_close (stream, NULL, NULL);

			g_object_unref (stream);
			g_free (ical_str);
		}

		e_cal_client_free_icalcomp_slist (objects);
	}

	if (error != NULL) {
		display_error_message (
			gtk_widget_get_toplevel (GTK_WIDGET (selector)),
			error->message);
		g_error_free (error);
	}

	/* terminate */
	g_object_unref (source_client);
	icalcomponent_free (top_level);
}