(* Tux Commander - UError - Error system functions Copyright (C) 2009 Tomas Bzatek Check for updates on tuxcmd.sourceforge.net This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) unit UError; interface uses glib2, gtk2, Classes, ULibc, GTKForms; // Ported from gioerror.h type GIOErrorEnum = (G_IO_ERROR_FAILED, G_IO_ERROR_NOT_FOUND, G_IO_ERROR_EXISTS, G_IO_ERROR_IS_DIRECTORY, G_IO_ERROR_NOT_DIRECTORY, G_IO_ERROR_NOT_EMPTY, G_IO_ERROR_NOT_REGULAR_FILE, G_IO_ERROR_NOT_SYMBOLIC_LINK, G_IO_ERROR_NOT_MOUNTABLE_FILE, G_IO_ERROR_FILENAME_TOO_LONG, G_IO_ERROR_INVALID_FILENAME, G_IO_ERROR_TOO_MANY_LINKS, G_IO_ERROR_NO_SPACE, G_IO_ERROR_INVALID_ARGUMENT, G_IO_ERROR_PERMISSION_DENIED, G_IO_ERROR_NOT_SUPPORTED, G_IO_ERROR_NOT_MOUNTED, G_IO_ERROR_ALREADY_MOUNTED, G_IO_ERROR_CLOSED, G_IO_ERROR_CANCELLED, G_IO_ERROR_PENDING, G_IO_ERROR_READ_ONLY, G_IO_ERROR_CANT_CREATE_BACKUP, G_IO_ERROR_WRONG_ETAG, G_IO_ERROR_TIMED_OUT, G_IO_ERROR_WOULD_RECURSE, G_IO_ERROR_BUSY, G_IO_ERROR_WOULD_BLOCK, G_IO_ERROR_HOST_NOT_FOUND, G_IO_ERROR_WOULD_MERGE, G_IO_ERROR_FAILED_HANDLED, G_IO_ERROR_TOO_MANY_OPEN_FILES, G_IO_ERROR_NOT_INITIALIZED, G_IO_ERROR_ADDRESS_IN_USE, G_IO_ERROR_PARTIAL_INPUT, G_IO_ERROR_INVALID_DATA); function g_io_error_quark: TGQuark; function G_IO_ERROR: TGQuark; function g_io_error_from_errno(err_no: gint): GIOErrorEnum; procedure ShowError(Parent: TCustomGTKForm; const Text: string; Error: PGError); implementation uses SysUtils, UCoreUtils, UGnome; (********************************************************************************************************************************) function g_io_error_quark: TGQuark; begin Result := g_quark_from_static_string('g-io-error-quark'); end; function G_IO_ERROR: TGQuark; begin Result := g_io_error_quark; end; function g_io_error_from_errno(err_no: gint): GIOErrorEnum; begin case err_no of EEXIST: Result := G_IO_ERROR_EXISTS; EISDIR: Result := G_IO_ERROR_IS_DIRECTORY; EACCES: Result := G_IO_ERROR_PERMISSION_DENIED; ENAMETOOLONG: Result := G_IO_ERROR_FILENAME_TOO_LONG; ENOENT: Result := G_IO_ERROR_NOT_FOUND; ENOTDIR: Result := G_IO_ERROR_NOT_DIRECTORY; EROFS: Result := G_IO_ERROR_READ_ONLY; ELOOP: Result := G_IO_ERROR_TOO_MANY_LINKS; ENOSPC: Result := G_IO_ERROR_NO_SPACE; ENOMEM: Result := G_IO_ERROR_NO_SPACE; EINVAL: Result := G_IO_ERROR_INVALID_ARGUMENT; EPERM: Result := G_IO_ERROR_PERMISSION_DENIED; ECANCELED: Result := G_IO_ERROR_CANCELLED; ENOTEMPTY: Result := G_IO_ERROR_NOT_EMPTY; ENOTSUP: Result := G_IO_ERROR_NOT_SUPPORTED; ETIMEDOUT: Result := G_IO_ERROR_TIMED_OUT; EBUSY: Result := G_IO_ERROR_BUSY; EAGAIN: Result := G_IO_ERROR_WOULD_BLOCK; EMFILE: Result := G_IO_ERROR_TOO_MANY_OPEN_FILES; EADDRINUSE: Result := G_IO_ERROR_ADDRESS_IN_USE; else Result := G_IO_ERROR_FAILED; end; end; (********************************************************************************************************************************) procedure ShowError(Parent: TCustomGTKForm; const Text: string; Error: PGError); var Dialog: PGtkWidget; error_str: PChar; begin if Error <> nil then error_str := Error^.message else error_str := ''; if @gtk_message_dialog_new_with_markup <> nil then dialog := gtk_message_dialog_new_with_markup (PGtkWindow(Parent.FWidget), GTK_DIALOG_MODAL or GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, '%s'#10#10'%s', PChar(Text), error_str) else dialog := gtk_message_dialog_new (PGtkWindow(Parent.FWidget), GTK_DIALOG_MODAL or GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, '%s'#10#10'%s', PChar(Text), error_str); gtk_window_set_title (PGtkWindow(dialog), ''); gtk_dialog_run (PGtkDialog(Dialog)); gtk_widget_destroy (PGtkWidget(Dialog)); end; end.