www.pudn.com > imgport.rar > Unit1.pas, change:2009-03-26,size:12644b


(* 
     Unit1.pas 
 
     Project Full Name: imageprinter 
     http://sourceforge.net/projects/imageprinter/ 
 
 
     Copyright (C) 2007 - 2008    Ibadov Tariel   <tariel@code-industry.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. 
 
 
*) 
 
 
unit Unit1;  
 
{$mode objfpc}{$H+} 
 
interface 
 
uses 
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls, 
  Buttons, StdCtrls, EditBtn, Windows , Registry, ComCtrls; 
 
type 
 
  { TForm1 } 
 
  TForm1 = class(TForm) 
    Bevel1: TBevel; 
    btCancel: TButton; 
    btOk: TButton; 
    btOk1: TButton; 
    btPath: TButton; 
    btPath1: TButton; 
    Button1: TButton; 
    CheckBox1: TCheckBox; 
    CheckBox2: TCheckBox; 
    CheckBox3: TCheckBox; 
    CheckBox4: TCheckBox; 
    chraw: TCheckBox; 
    ch_multipage: TCheckBox; 
    Edit1: TEdit; 
    Label10: TLabel; 
    Label11: TLabel; 
    Label12: TLabel; 
    Label13: TLabel; 
    Label14: TLabel; 
    Label15: TLabel; 
    Label3: TLabel; 
    Label4: TLabel; 
    Label5: TLabel; 
    Label6: TLabel; 
    Label7: TLabel; 
    Label8: TLabel; 
    Label9: TLabel; 
    l_uplhome: TLabel; 
    Memo1: TMemo; 
    chDefaultProgram: TRadioButton; 
    chSelectProgram: TRadioButton; 
    teFileName: TEdit; 
    EDPath: TEdit; 
    EDPath1: TEdit; 
      GroupBox1: TGroupBox; 
      GroupBox2: TGroupBox; 
      GroupBox3: TGroupBox; 
      GroupBox4: TGroupBox; 
      GroupBox6: TGroupBox; 
      Label1: TLabel; 
      Label2: TLabel; 
      Notebok1: TNotebook; 
      OpenDialog1: TOpenDialog; 
      Page1: TPage; 
      Page2: TPage; 
      Page3: TPage; 
      Panel3: TPanel; 
      bmpRadioButton: TRadioButton; 
      pngRadioButton: TRadioButton; 
      jpgRadioButton: TRadioButton; 
      RadioButton1: TRadioButton; 
      RadioButton2: TRadioButton; 
      RadioButton3: TRadioButton; 
      tifRadioButton: TRadioButton; 
      pdfRadioButton: TRadioButton; 
      SelectDirectoryDialog1: TSelectDirectoryDialog; 
      SpeedButton2: TSpeedButton; 
      TrackBar1: TTrackBar; 
      procedure bmpRadioButtonChange(Sender: TObject); 
      procedure btOk1Click(Sender: TObject); 
      procedure btPath1Click(Sender: TObject); 
      procedure Button1Click(Sender: TObject); 
      procedure chDefaultProgramChange(Sender: TObject); 
      procedure CheckBox1Click(Sender: TObject); 
      procedure CheckBox3Change(Sender: TObject); 
      procedure chrawChange(Sender: TObject); 
      procedure chSelectProgramClick(Sender: TObject); 
      procedure FormCreate(Sender: TObject); 
      procedure FormShow(Sender: TObject); 
      procedure jpgRadioButtonChange(Sender: TObject); 
      procedure Label13Click(Sender: TObject); 
      procedure Label14Click(Sender: TObject); 
      procedure Label8Click(Sender: TObject); 
      procedure l_uplhomeClick(Sender: TObject); 
      procedure l_uplhomeMouseEnter(Sender: TObject); 
      procedure l_uplhomeMouseLeave(Sender: TObject); 
      procedure pdfRadioButtonChange(Sender: TObject); 
      procedure pngRadioButtonChange(Sender: TObject); 
      procedure SBPathClick(Sender: TObject); 
      procedure BtOkClick(Sender: TObject); 
 
      procedure BtCancelClick(Sender: TObject); 
      procedure tifRadioButtonChange(Sender: TObject); 
      procedure TrackBar1Change(Sender: TObject); 
 
  private 
    { private declarations } 
      _openpr:boolean; 
  public 
    { public declarations } 
    showprogress, 
    img_format, 
    compressTIFF:string; 
    procedure savereg; 
  end;  
 
var 
  Form1: TForm1;  
 
implementation 
 
 
 
{ TForm1 } 
 
 
procedure TForm1.savereg; 
var 
  extPath, 
  Path:string; 
  Registry:TRegistry; 
begin 
 
 
  if CheckBox2.Checked then showprogress:='true' else showprogress:='false'; 
 
  if RadioButton1.Checked then  compressTIFF:='LZW'; 
  if RadioButton2.Checked then  compressTIFF:='G4'; 
  if RadioButton3.Checked then  compressTIFF:='G3'; 
 
  Path:=EDPath.Text; 
  if Length(Path)>2 then  begin 
       if Path[Length(Path)]<>'\' then 
          Path:=Path+'\'; 
  end; 
 
  extPath:=EDPath1.Text; 
 
  Registry:=TRegistry.Create; 
  Registry.RootKey:=HKEY_LOCAL_MACHINE; 
 
  if not Registry.OpenKey('SOFTWARE\ImagePrinter',false) then  begin 
       MessageBox(HWND_DESKTOP,'Error save options! Reinstall ImagePrinter! ','ImagePrinter',MB_OK); 
       close; 
  end; 
 
  if (CheckBox1.Checked) then 
     Registry.WriteString('ext_app','true') 
  else 
     Registry.WriteString('ext_app','false'); 
 
 
  if (extPath>'') then 
     Registry.WriteString('ext_app_name',extPath) 
  else 
     Registry.WriteString('ext_app_name','none'); 
 
  if (chDefaultProgram.Checked) then 
      Registry.WriteString('ext_app_default','true') 
  else 
      Registry.WriteString('ext_app_default','false'); 
 
 
 
  if (ch_multipage.Checked) then 
     Registry.WriteString('multipage_tiff','true') 
  else 
     Registry.WriteString('multipage_tiff','false'); 
 
 
  Registry.WriteString('image_name',teFileName.Text); 
  Registry.WriteString('path',Path); 
  Registry.WriteString('format',img_format); 
  Registry.WriteString('format_ext',compressTIFF); 
  Registry.WriteString('ShowProgress',showprogress); 
  Registry.WriteString('q_jpg',IntToStr(TrackBar1.Position)); 
  if (CheckBox3.Checked) then 
     Registry.WriteString('original_name','true') 
  else 
     Registry.WriteString('original_name','false'); 
 
  if (CheckBox4.Checked) then 
     Registry.WriteString('one_file','true') 
  else 
     Registry.WriteString('one_file','false'); 
 
  Registry.CloseKey; 
  Registry.Destroy; 
 
end; 
 
 
procedure TForm1.BtOkClick(Sender: TObject); 
begin 
  savereg; 
  close; 
end; 
 
 
procedure TForm1.BtCancelClick(Sender: TObject); 
begin 
  close; 
end; 
 
 
procedure TForm1.SBPathClick(Sender: TObject); 
begin 
     if EDPath.Text > '' then 
        SelectDirectoryDialog1.InitialDir:=EDPath.Text; 
     if SelectDirectoryDialog1.Execute then 
     begin 
          EDPath.Text:=SelectDirectoryDialog1.FileName; 
     end; 
end; 
 
 
procedure TForm1.FormShow(Sender: TObject); 
var 
  Registry:TRegistry; 
  s:string; 
begin 
  Registry:=TRegistry.Create; 
  Registry.RootKey:=HKEY_LOCAL_MACHINE; 
  if not Registry.OpenKey('SOFTWARE\ImagePrinter',false) then 
  begin 
       MessageBox(HWND_DESKTOP,'Error read options ! Reinstall ImagePrinter! ','ImagePrinter',MB_OK); 
       Exit; 
  end; 
  s:=Registry.ReadString('ext_app_name'); 
  if ((s<>'none')and(s<>'')) then begin 
     EDPath1.Text:=s; 
  end; 
  if (Registry.ReadString('ext_app')='true') then 
    CheckBox1.Checked:=true; 
 
  if (Registry.ReadString('ext_app_default')='true') then 
    chDefaultProgram.Checked:=true 
  else 
  begin 
    chDefaultProgram.Checked:=false; 
    chSelectProgram.Checked:=true; 
  end; 
 
  CheckBox1Click(nil); 
  chDefaultProgramChange(nil); 
 
  s:=Registry.ReadString('original_name'); 
  if (s='true') then  CheckBox3.Checked:=true; 
  teFileName.Text:=Registry.ReadString('image_name'); 
  s:=Registry.ReadString('one_file'); 
  if (s='true') then  CheckBox4.Checked:=true; 
  s:=Registry.ReadString('multipage_tiff'); 
  if (s='true') then  ch_multipage.Checked:=true; 
 
  s:=Registry.ReadString('q_jpg'); 
  if s >'' then 
  begin 
    try 
       TrackBar1.Position:=StrToInt(s); 
    except 
       TrackBar1.Position:=100; 
    end; 
  end else TrackBar1.Position:=100; 
  TrackBar1Change(nil); 
   
  EDPath.Text:=Registry.ReadString('path'); 
  img_format:=Registry.ReadString('format'); 
  compressTIFF:=Registry.ReadString('format_ext'); 
  showprogress:=Registry.ReadString('ShowProgress'); 
  Registry.CloseKey; 
  Registry.Free; 
 
       if img_format='pdf' then 
          pdfRadioButton.Checked:=true; 
       if img_format='tif' then 
          tifRadioButton.Checked:=true; 
       if img_format='png' then 
          pngRadioButton.Checked:=true; 
       if img_format='jpg' then 
          jpgRadioButton.Checked:=true; 
       if img_format='bmp' then 
          bmpRadioButton.Checked:=true; 
           
       if compressTIFF='LZW' then 
          RadioButton1.Checked:=true; 
       if compressTIFF='G4' then 
          RadioButton2.Checked:=true; 
       if compressTIFF='G3' then 
          RadioButton3.Checked:=true; 
 
       if compressTIFF='G3' then 
          RadioButton3.Checked:=true; 
 
       if img_format='raw' then 
          chraw.Checked:=true; 
           
       if showprogress='true' then 
          CheckBox2.Checked:=true; 
end; 
 
procedure TForm1.jpgRadioButtonChange(Sender: TObject); 
begin 
  img_format:='jpg'; 
  GroupBox4.Visible:=false; 
  GroupBox6.Visible:=true; 
end; 
 
procedure TForm1.Label13Click(Sender: TObject); 
begin 
  ShellExecute(Handle, 'open','http://code-industry.net/downloads.php', '', nil,1); 
end; 
 
procedure TForm1.Label14Click(Sender: TObject); 
begin 
  ShellExecute(Handle, 'open','http://code-industry.net/public/download/ImagePrinterPro.zip', '', nil,1); 
end; 
 
procedure TForm1.Label8Click(Sender: TObject); 
begin 
  ShellExecute(Handle, 'open','http://www.gnu.org/copyleft/gpl.html', '', nil,1); 
end; 
 
 
procedure TForm1.l_uplhomeClick(Sender: TObject); 
begin 
  ShellExecute(Handle, 'open','http://code-industry.net/index.html', '', nil,1); 
end; 
 
procedure TForm1.l_uplhomeMouseEnter(Sender: TObject); 
begin 
  (Sender as TLabel).Font.Color:=clBlue; 
end; 
 
procedure TForm1.l_uplhomeMouseLeave(Sender: TObject); 
begin 
  (Sender as TLabel).Font.Color:=clBlack; 
end; 
 
 
 
procedure TForm1.pdfRadioButtonChange(Sender: TObject); 
begin 
  img_format:='pdf'; 
  GroupBox4.Visible:=false; 
  GroupBox6.Visible:=true; 
end; 
 
procedure TForm1.pngRadioButtonChange(Sender: TObject); 
begin 
  img_format:='png'; 
  GroupBox4.Visible:=false; 
  GroupBox6.Visible:=false; 
end; 
 
procedure TForm1.bmpRadioButtonChange(Sender: TObject); 
begin 
  img_format:='bmp'; 
  GroupBox4.Visible:=false; 
  GroupBox6.Visible:=false; 
end; 
 
procedure TForm1.btOk1Click(Sender: TObject); 
begin 
  savereg; 
end; 
 
procedure TForm1.tifRadioButtonChange(Sender: TObject); 
begin 
  img_format:='tif'; 
  GroupBox4.Visible:=True; 
  GroupBox6.Visible:=false; 
end; 
 
procedure TForm1.TrackBar1Change(Sender: TObject); 
begin 
  Edit1.Text:=IntToStr(TrackBar1.Position)+'%'; 
end; 
 
 
 
procedure TForm1.btPath1Click(Sender: TObject); 
begin 
     if _openpr then exit; 
     _openpr:=true; 
     if EDPath1.Text > '' then 
        OpenDialog1.InitialDir:=EDPath.Text; 
     if OpenDialog1.Execute then 
     begin 
          EDPath1.Text:=OpenDialog1.FileName; 
     end else begin 
          chSelectProgram.Checked:=false; 
          chDefaultProgram.Checked:=true; 
     end; 
 
     _openpr:=false; 
end; 
 
procedure TForm1.Button1Click(Sender: TObject); 
begin 
 
  ShellExecute(Handle,nil,'net', 'stop Spooler',  nil, SW_HIDE	); 
  Sleep(2000); 
  ShellExecute(Handle,nil,'net','start Spooler',  nil, SW_HIDE	); 
 
end; 
 
procedure TForm1.chDefaultProgramChange(Sender: TObject); 
begin 
  EDPath1.Enabled:=not chDefaultProgram.Checked; 
  btPath1.Enabled:=not chDefaultProgram.Checked; 
end; 
 
 
 
 
procedure TForm1.CheckBox1Click(Sender: TObject); 
begin 
  EDPath1.Enabled:=CheckBox1.Checked; 
  btPath1.Enabled:=CheckBox1.Checked; 
  chDefaultProgram.Enabled:=CheckBox1.Checked; 
  chSelectProgram.Enabled:=CheckBox1.Checked; 
  chDefaultProgramChange(nil); 
end; 
 
procedure TForm1.CheckBox3Change(Sender: TObject); 
begin 
   teFileName.Enabled:= not CheckBox3.Checked; 
end; 
 
 
procedure TForm1.chrawChange(Sender: TObject); 
begin 
  if chraw.Checked then 
  begin 
       img_format:='raw'; 
       GroupBox1.Enabled:=False; 
       CheckBox4.Enabled:=false; 
  end 
  else 
  begin 
       GroupBox1.Enabled:=true; 
       CheckBox4.Enabled:=true; 
       tifRadioButton.Checked:=true; 
  end 
 
end; 
 
procedure TForm1.chSelectProgramClick(Sender: TObject); 
begin 
 // if _openpr then exit; 
 // if (chSelectProgram.Checked=true) and (EDPath1.Text='') then 
 //    btPath1Click(nil); 
end; 
 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
   _openpr:=false; 
end; 
 
 
 
 
 
 
 
 
initialization 
  {$I Unit1.lrs} 
 
end.