Ejemplo n.º 1
0
/* Ctrl+C signal handler */
static void signal_handler(int sig_no)
{
	tilp_info(_("Signal SIGINT (Ctrl+C) caught...\n"));
	tilp_exit();
	tilp_info(_("Done.\n"));

	exit(0);
}
Ejemplo n.º 2
0
TILP_EXPORT void
on_treeview1_drag_data_get(GtkWidget * widget,
			   GdkDragContext * drag_context,
			   GtkSelectionData * data,
			   guint info, guint _time, gpointer user_data)
{
	if (info == TARGET_ROOTWIN) 
	{
		tilp_info("I was dropped on the rootwin\n");
	} 
	else
	{
		gtk_selection_data_set(data, data->target, 8, 
				       (guchar *)name_to_drag, 
				       strlen(name_to_drag));
	}
}
Ejemplo n.º 3
0
gint display_clock_dbox()
{
	GError* error = NULL;
	GtkWidget *dbox;
	gint result;
	int err;

	if(!(ticalcs_calc_features(calc_handle) & OPS_CLOCK))
	{
		gif->msg_box1(_("Error"), _("No clock support!"));
		return -1;
	}

	err = ticalcs_calc_isready(calc_handle);
	if(err)
	{
		tilp_err(err);
		return -1;
	}

	if(tilp_calc_check_version("2.08") < 0)
		return -1;

	err = ticalcs_calc_get_clock(calc_handle, &tmp_clk);
	if(err)
	{
		tilp_err(err);
		return -1;
	}

	tilp_info("%02i/%02i/%02i %02i:%02i:%02i, %s, %s\n", tmp_clk.day,
		tmp_clk.month, tmp_clk.year, tmp_clk.hours,
		tmp_clk.minutes, tmp_clk.seconds,
		(tmp_clk.time_format == 12) ? "12" : "24",
		ticalcs_clock_format2date(options.calc_model, tmp_clk.date_format));

	builder = gtk_builder_new();
	if (!gtk_builder_add_from_file (builder, tilp_paths_build_builder("clock.ui"), &error))
	{
		g_warning (_("Couldn't load builder file: %s\n"), error->message);
		g_error_free (error);
		return 0; // THIS RETURNS !
	}
	gtk_builder_connect_signals(builder, NULL);

	dbox = GTK_WIDGET (gtk_builder_get_object (builder, "clock_dbox"));
	gtk_dialog_set_alternative_button_order(GTK_DIALOG(dbox), GTK_RESPONSE_OK,
	                                        GTK_RESPONSE_CANCEL,-1);
	update_fields(&tmp_clk);
	modified = FALSE;

	result = gtk_dialog_run(GTK_DIALOG(dbox));
	switch (result) 
	{
	case GTK_RESPONSE_OK:
		if(modified == FALSE)
			break;

		tilp_info("%02i/%02i/%02i %02i:%02i:%02i, %s, %s\n",
			tmp_clk.day, tmp_clk.month, tmp_clk.year,
			tmp_clk.hours, tmp_clk.minutes, tmp_clk.seconds,
			(tmp_clk.time_format == 12) ? "12" : "24",
			ticalcs_clock_format2date(options.calc_model, tmp_clk.date_format));

		err = ticalcs_calc_isready(calc_handle);
		if(err)
		{
			tilp_err(err);
			return -1;
		}

		err = ticalcs_calc_set_clock(calc_handle, &tmp_clk);
		if(err)
		{
			tilp_err(err);
			return -1;
		}

		modified = FALSE;
		break;
	case GTK_RESPONSE_HELP:
		break;
	default:
		break;
	}
	gtk_widget_destroy(dbox);

	return 0;
}
Ejemplo n.º 4
0
/*
  This function take as input parameter an error code and displays it
  in a message box.

  This function is 'buffered': if one or more error messages appear 
  during startup (console or terminal), they will be displayed in the GUI.
 */
int tilp_err(int errcode)
{
	char *s = NULL;	
	char *utf;
	gsize bw;

	/* Push error messages (if any)*/
	if(errcode)
		stack = g_list_append(stack, GINT_TO_POINTER(errcode));

	/* Pop error messages */
	if (!(working_mode & MODE_INI)) 
	{
		int i;
		for (i = 0; i < (int)g_list_length(stack); i++) 
		{
			int err = GPOINTER_TO_INT((g_list_nth(stack, i))->data);

			/* Retrieve the error message */
			err = ticables_error_get(err, &s);
			if (err) 
			{
				g_free(s);
				err = tifiles_error_get(err, &s);
				if (err) 
				{
					g_free(s);
					err = ticalcs_error_get(err, &s);
					if (err) 
					{
						// next level: error for TiLP
						g_free(s);
					}
					else
					{
					    // ticalcs error => reset
					    tilp_device_reset();
					}
				}
			}
			else
			{
			    // ticables error => reset
			    tilp_device_reset();
			}			

			utf = g_locale_to_utf8(s, -1, NULL, &bw, NULL);
			gif->msg_box1(_("Error"), utf);
		}
		g_list_free(stack);
		stack = NULL;
	} 
	else 
	{
		int err = errcode;

		/* Retrieve the error message */
		err = ticables_error_get(err, &s);
		if (err)
		{
			g_free(s);
			err = ticalcs_error_get(err, &s);
			if (err)
			{
				g_free(s);
				err = ticalcs_error_get(err, &s);
				if (err) 
				{
					// next level: error for TiLP
					g_free(s);
				}
			}
		}

		if(s)
			tilp_info("%s\n", s);
	}

	//free(s);
	return errcode;
}
Ejemplo n.º 5
0
/*
  This function must be the first function to call in your function 'main'.
  It initializes the TiLP core engine.
*/
int tilp_init(int *argc, char ***argv)
{
	/* Display program version */
	tilp_cmdline_version();

	/* Initialize platform independant paths */
	tilp_paths_init();

	/* Init i18n support */
#ifdef ENABLE_NLS
	tilp_info("setlocale: %s", setlocale(LC_ALL, ""));
  	tilp_info("bindtextdomain: %s", bindtextdomain(PACKAGE, inst_paths.locale_dir));
  	bind_textdomain_codeset(PACKAGE, "UTF-8"/*"ISO-8859-15"*/);
  	tilp_info("textdomain: %s", textdomain(PACKAGE));
#endif

	/* Initialize callbacks with default functions */ 
	tilp_gif_set_default();

	/* Initialize/reload config */
	tilp_config_default();
	tilp_config_read();

	/* Scan and modify command line and change to working folder*/
	tilp_cmdline_scan(argc, argv);
	tilp_file_chdir(options.working_dir);

	/* Catch 'Ctrl-C' */
	signal(SIGINT, signal_handler);

	/* Check the version of libraries and init framework */
	if (strcmp(ticonv_version_get(), TILP_REQUIRES_LIBCONV_VERSION) < 0) 
		tilp_error(_("libticonv library version is %s but %s mini required.\n"), ticonv_version_get(), TILP_REQUIRES_LIBCONV_VERSION);

	if (strcmp(tifiles_version_get(), TILP_REQUIRES_LIBFILES_VERSION) < 0) 
		tilp_error(_("libtifiles library version is %s but %s mini required.\n"), tifiles_version_get(), TILP_REQUIRES_LIBFILES_VERSION);
	
	if (strcmp(ticables_version_get(), TILP_REQUIRES_LIBCABLES_VERSION) < 0) 
		tilp_error(_("libticables library version is %s but %s mini required.\n"), ticables_version_get(), TILP_REQUIRES_LIBCABLES_VERSION);
	
	if (strcmp(ticalcs_version_get(), TILP_REQUIRES_LIBCALCS_VERSION) < 0) 
		tilp_error(_("libticalcs library version is %s but %s mini required.\n"), ticalcs_version_get(), TILP_REQUIRES_LIBCALCS_VERSION);

	ticables_library_init();
	tifiles_library_init();
	ticalcs_library_init();

	/* Check for USB support */
	options.usb_avail = ticables_is_usb_enabled();

	/* Set cable & calc */
	if(options.auto_detect && options.usb_avail)
	{
		int ret;
		CableModel cable;
		CalcModel calc;
		CablePort port;

		ret = tilp_device_probe_usb(&cable, &port, &calc);
		if(!ret)
		{
			options.cable_model = cable;
			options.cable_port = port;
			options.calc_model = calc;
		}
	}

	tilp_device_open();

	/* 
	   If we are in command line mode, does the required operation
	   and exit else fallback on a graphic interface.
	 */
	if((working_mode & MODE_CMD) && !(working_mode & MODE_GUI))
	{
		int ret;

		ret = tilp_cmdline_send();
		exit(ret);
	}
	else if(working_mode == MODE_INI)
		exit(0);

	return 0;
}