1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
(*
Tux Commander - UError - Error system functions
Copyright (C) 2009 Tomas Bzatek <tbzatek@users.sourceforge.net>
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, SysUtils, 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 g_set_error_from_exception(Error: PPGError; E: Exception);
procedure ShowError(Parent: TCustomGTKForm; const Text: string; Error: PGError);
implementation
uses 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 g_set_error_from_exception(Error: PPGError; E: Exception);
begin
g_set_error(Error, G_IO_ERROR, integer(G_IO_ERROR_FAILED), 'Exception raised: %s', PChar(E.Message));
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,
'<span size="large" weight="ultrabold">%s</span>'#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.
|