root/lang/pascal/GeckoComponents/HelperDlg.pas

Revision 4545, 5.3 kB (checked in by plus7, 12 months ago)

implement nsIHelperAppLauncherDialog

  • Property svn:executable set to *
Line 
1(* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is GeckoComponents for Delphi.
15 *
16 * The Initial Developer of the Original Code is NOSE Takafumi.
17 * Portions created by the Initial Developer are Copyright (C) 2008
18 * the Initial Developer. All Rights Reserved.
19 *
20 * Contributor(s):
21 *
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 2 or later (the "GPL"), or
24 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25 * in which case the provisions of the GPL or the LGPL are applicable instead
26 * of those above. If you wish to allow use of your version of this file only
27 * under the terms of either the GPL or the LGPL, and not to allow others to
28 * use your version of this file under the terms of the MPL, indicate your
29 * decision by deleting the provisions above and replace them with the notice
30 * and other provisions required by the GPL or the LGPL. If you do not delete
31 * the provisions above, a recipient may use your version of this file under
32 * the terms of any one of the MPL, the GPL or the LGPL.
33 *
34 * ***** END LICENSE BLOCK ***** *)
35unit HelperDlg;
36
37interface
38
39uses
40  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
41  Dialogs, nsXPCOM,nsXPCOMGlue, nsTypes, StdCtrls, nsMIMEInfo,nsHelperAppLauncher
42  ,nsGeckoStrings,nsNetUtil,nsError,nsDownload, ExtCtrls, ShellAPI, ImgList,
43  nsInit;
44
45type
46  THelperDlg = class(TForm)
47    btnSave: TButton;
48    btnCancel: TButton;
49    Label1: TLabel;
50    Label2: TLabel;
51    SaveDialog1: TSaveDialog;
52    btnExecute: TButton;
53    Label3: TLabel;
54    Label4: TLabel;
55    Label5: TLabel;
56    Label6: TLabel;
57    Image1: TImage;
58    lblName: TLabel;
59    lblMime: TLabel;
60    lblSource: TLabel;
61    chkRememberThisPref: TCheckBox;
62    edtURI: TEdit;
63  private
64    { Private �錾 }
65  public
66    procedure DrawIconByExt(Extension:String);
67    procedure Show(aLauncher: nsIHelperAppLauncher; aContext: nsISupports; aReason: PRUint32); safecall;
68    function PromptForSaveToFile(aLauncher: nsIHelperAppLauncher; aWindowContext: nsISupports; const aDefaultFile: PWideChar; const aSuggestedFileExtension: PWideChar): nsILocalFile; safecall;
69  end;
70
71{var
72  HelperDlgForm: THelperDlg;}
73
74implementation
75
76{$R *.dfm}
77
78procedure THelperDlg.DrawIconByExt(Extension:String);
79var
80  SHFileInfo:TShFileInfo;
81  IconHandle:HICON;
82  icon:TIcon;
83begin
84  SHGetFileInfo(
85    PChar('.'+Extension),
86    0, SHFileInfo, Sizeof(TSHFileInfo),
87    SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES or
88    SHGFI_ICON or SHGFI_TYPENAME);
89  IconHandle := SHFileInfo.hIcon;
90  DrawIconEx(
91    Image1.Canvas.Handle,
92    0,0,
93    IconHandle, 32, 32, 0, 0,
94    DI_NORMAL);
95  DestroyIcon(IconHandle);
96end;
97
98procedure THelperDlg.Show(aLauncher: nsIHelperAppLauncher; aContext: nsISupports; aReason: PRUint32);
99var
100  spec:IInterfacedCString;
101  filename:IInterfacedString;
102  host:IInterfacedCString;
103  ContentType:IInterfacedCString;
104  Desc:IInterfacedString;
105  AppDesc:IInterfacedString;
106  ext:IInterfacedCString;
107  openWith:nsILocalFile;
108  modalResult:Integer;
109begin
110  spec:=NewCString;
111  aLauncher.Source.GetSpec(spec.ACString);
112  edtURI.Text:=spec.ToString;
113
114  host:=NewCString;
115  aLauncher.Source.GetHost(host.ACString);
116  lblSource.Caption := host.ToString;
117
118  ContentType:=NewCString;
119  Desc:=NewString;
120  aLauncher.MIMEInfo.GetMIMEType(ContentType.ACString);
121  aLauncher.MIMEInfo.GetDescription(Desc.AString);
122  lblMime.Caption := Desc.ToString + '(' + ContentType.ToString + ')';
123
124  filename:=NewString;
125  aLauncher.GetSuggestedFileName(filename.AString);
126  lblName.Caption := filename.ToString ;
127
128  ext:=NewCString;
129  aLauncher.MIMEInfo.GetPrimaryExtension(ext.ACString);
130  DrawIconByExt(ext.ToString);
131
132  modalResult:=ShowModal;
133
134  if modalResult = mrOk then  begin
135    aLauncher.SaveToDisk(nil,chkRememberThisPref.Checked);
136  end
137  else if ModalResult=mrYes then begin // �֋X�I��rYes���s�v�Ɖ�����ǂ��Ȃ��ȁB
138    AppDesc:=NewString;
139    aLauncher.MIMEInfo.GetDefaultDescription(Appdesc.AString);
140    NS_NewLocalFile(AppDesc.AString,false,openWith);
141    aLauncher.LaunchWithApplication(openWith,chkRememberThisPref.Checked);
142  end
143  else aLauncher.Cancel(NS_ERROR_ABORT);
144end;
145
146function THelperDlg.PromptForSaveToFile(aLauncher: nsIHelperAppLauncher; aWindowContext: nsISupports; const aDefaultFile: PWideChar; const aSuggestedFileExtension: PWideChar): nsILocalFile;
147var
148  thefile:nsILocalFile;
149begin
150  SaveDialog1.Filter:='�S�Ẵt�@�C�� (*.*)|*.*';
151  SaveDialog1.FileName := String(aDefaultFile);
152  SaveDialog1.Execute;
153  if SaveDialog1.FileName<>'' then
154  begin
155    NS_NewNativeLocalFile(NewCString(SaveDialog1.FileName).ACString,false,thefile);
156    Result:=thefile;
157  end;
158end;
159
160
161end.
Note: See TracBrowser for help on using the browser.