-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewer.pas
183 lines (145 loc) · 5.01 KB
/
viewer.pas
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
{ $Id$
OpenXP Library: TMimeViewer class
Copyright (C) 2000, Markus Kaemmerer <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
{$I xpdefine.inc}
unit viewer;
interface
type
// Viewer for one specific message type
TMessageViewer = class
private
fProg: String; // selected viewer
fExt: String; // file extension for selected viewer
public
constructor Init; //todo: rename into Create, conforming to classes
procedure GetFromMimeType(const MimeType: String);
procedure GetFromExtension(const Extension: String);
procedure UseInternal;
function IsInternal: Boolean;
procedure ViewFile(const Filename: String; Fileattach:boolean);
property Prog: String read fProg write fProg;
property Ext: String read fExt write fExt;
end;
implementation
uses
sysutils,
database, xp0, xp1, xp1o, fileio, typeform,
xpglobal;
{ TMessageViewer }
constructor TMessageViewer.Init;
begin
inherited Create;
UseInternal;
fExt := '';
end;
procedure TMessageViewer.GetFromMimeType(const MimeType: String);
function SeekMimeType(const MimeType: string): boolean;
begin
dbSeek(mimebase, mtiTyp, UpperCase(MimeType));
SeekMimeType :=not dbBOF(mimebase) and not dbEOF(mimebase) and
(UpperCase(MimeType) = UpperCase(dbReadStr(mimebase,'typ')));
end;
begin
if MimeType = '' then exit;
// is there a match for MimeTyp?
if SeekMimeType(MimeType) then
begin
fProg := dbReadNStr(mimebase,mimeb_programm);
fExt := '.' + dbReadNStr(mimebase,mimeb_extension);
end else
if SeekMimeType(LeftStr(MimeType, cposx('/',MimeType))+'*') then
begin
fProg := dbReadNStr(mimebase,mimeb_programm);
fExt := '.' + dbReadNStr(mimebase,mimeb_extension);
end;
end;
procedure TMessageViewer.GetFromExtension(const Extension: String);
begin
{ HJT 19.02.2006 Start, fuer nachfolgende Aufrufe wird }
{ sonst der vormalige Viewer aufgerufen }
fProg := '';
fExt := '';
{ HJT 19.02.2006 End }
if Extension = '' then exit;
dbSeek(mimebase,mtiExt,UpperCase(mid(Extension,2)));
if dbFound then
begin
fProg := dbReadNStr(mimebase,mimeb_programm);
fExt := Extension;
end;
end;
procedure TMessageViewer.UseInternal;
begin
fProg := '';
end;
function TMessageViewer.IsInternal: Boolean;
begin
Result := fProg = '';
end;
procedure TMessageViewer.ViewFile(const Filename: String; Fileattach: Boolean);
var p : Integer;
prog,
orgfn,
fn1,
parfn : string;
begin
fn1:='';
orgfn:= Filename;
// orgfn:=iifs(viewer.fn<>'',GetFileDir(fn)+GetFileName(viewer.fn),'');
if (not ValidFileName(orgfn) or FileExists(orgfn)) and (fExt<>'') and
(cpos('.',filename)>0) then
orgfn:= ChangeFileExt(filename, fExt);
if not fileattach then begin
if stricmp(filename,orgfn) or not ValidFileName(orgfn) or (cpos(' ',orgfn)>0)
then orgfn:=TempS(_filesize(filename)+5000);
if copyfile(Filename,orgfn) then fn1:=orgfn;
end;
prog:=fProg;
orgfn:=iifs(fn1<>'',fn1,Filename);
// Tempdatei bei aktivem DELVTMP nach TMP-????.??? umbenennen
if not fileattach and delviewtmp then Begin
parfn:=TempS(_filesize(Filename)+5000);
parfn:=LeftStr(parfn,length(parfn)-8)+TempFilePrefix+RightStr(parfn,8);
end else parfn:=orgfn;
// Korrekte File-extension verwenden
ParFN := ChangeFileExt(ParFN, ExtractFileExt(Orgfn));
RenameFile(orgfn,parfn);
p:=pos('$FILE',UpperCase(prog));
if p=0 then prog:=prog+' '+parfn
else prog:=LeftStr(prog,p-1)+parfn+mid(prog,p+5);
(* urep(prog,'$TYPE',viewer.typ);
urep(prog,'$EXT',viewer.ext); *)
if not XPWinShell(prog,parfn,600,1,fileattach) then
if not fileattach and (fn1<>'') then DeleteFile(parfn);
end;
{
$Log: viewer.pas,v $
Revision 1.7 2002/12/14 07:31:28 dodi
- using new types
Revision 1.6 2002/12/06 14:27:27 dodi
- updated uses, comments and todos
Revision 1.5 2002/12/02 14:04:29 dodi
made xpmenu internal tool
Revision 1.4 2001/10/11 09:00:40 mk
- external viewer files now with correct file extension
Revision 1.3 2001/10/10 22:04:09 mk
- enabled use of external mime viewers again
Revision 1.2 2001/09/10 15:58:01 ml
- Kylix-compatibility (xpdefines written small)
- removed div. hints and warnings
Revision 1.1 2000/11/18 21:42:17 mk
- implemented new Viewer handling class TMessageViewer
}
end.