home *** CD-ROM | disk | FTP | other *** search
/ Freelog 11 / Freelog011.iso / BestOf / PhoenixMail / Source / phoenix / FMOnline.pas < prev    next >
Pascal/Delphi Source File  |  1999-02-20  |  8KB  |  254 lines

  1. {*****************************************************************************
  2.  *
  3.  *  FMOnline.pas - Fetch and send mails  (12-August-1998)
  4.  *
  5.  *  Copyright (c) 1998-99 Michael Haller
  6.  *
  7.  *  Author:     Michael Haller
  8.  *  E-mail:     michael@discountdrive.com
  9.  *  Homepage:   http://www.discountdrive.com/sunrise
  10.  *
  11.  *  This program is free software; you can redistribute it and/or
  12.  *  modify it under the terms of the GNU General Public License
  13.  *  as published by the Free Software Foundation;
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
  23.  *
  24.  *----------------------------------------------------------------------------
  25.  *
  26.  *  Revision history:
  27.  *
  28.  *     DATE     REV                 DESCRIPTION
  29.  *  ----------- --- ----------------------------------------------------------
  30.  *
  31.  *****************************************************************************}
  32.  
  33. unit FMOnline;
  34.  
  35. interface
  36.  
  37. uses
  38.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  39.   StdCtrls, LangSup, PXStuff, ExtCtrls, ShellAPI;
  40.  
  41. type
  42.   TOnlineForm = class(TForm)
  43.     Panel1: TPanel;
  44.     Notebook1: TNotebook;
  45.     Label1: TLabel;
  46.     Image3: TImage;
  47.     Button4: TButton;
  48.     Button7: TButton;
  49.     GroupBox3: TGroupBox;
  50.     Label2: TLabel;
  51.     Label6: TLabel;
  52.     Image4: TImage;
  53.     Button3: TButton;
  54.     Button5: TButton;
  55.     GroupBox4: TGroupBox;
  56.     Label7: TLabel;
  57.     Label5: TLabel;
  58.     Image5: TImage;
  59.     Label16: TLabel;
  60.     Button1: TButton;
  61.     Button6: TButton;
  62.     GroupBox5: TGroupBox;
  63.     Label17: TLabel;
  64.     Edit1: TEdit;
  65.     Label18: TLabel;
  66.     Image6: TImage;
  67.     GroupBox6: TGroupBox;
  68.     Button10: TButton;
  69.     Edit2: TEdit;
  70.     Button11: TButton;
  71.     Label20: TLabel;
  72.     Panel2: TPanel;
  73.     Label9: TLabel;
  74.     Label10: TLabel;
  75.     Label13: TLabel;
  76.     Label15: TLabel;
  77.     procedure FormCreate(Sender: TObject);
  78.     procedure Button7Click(Sender: TObject);
  79.     procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  80.     procedure FormDestroy(Sender: TObject);
  81.     procedure Button5Click(Sender: TObject);
  82.   private
  83.     { Private declarations }
  84.   public
  85.     { Public declarations }
  86.     CommandList: TStringList;
  87.     OnlineTyp: Byte;
  88.     procedure SetCancelOpportunitiesFalse;
  89.     procedure ShowStatusMessage;
  90.     procedure DialUpNetwork;
  91.   end;
  92.  
  93. var
  94.   OnlineForm: TOnlineForm;
  95.  
  96. implementation
  97.  
  98. {$R *.DFM}
  99.  
  100. uses
  101.   Main, TDOnline;
  102.  
  103. procedure TOnlineForm.SetCancelOpportunitiesFalse;
  104. begin
  105.   MainForm.StatusBar1.Panels[2].Text := '';
  106.   MainForm.StatusBar1.Panels[3].Text := '';
  107.   MainForm.Label5.Caption := '';
  108.   MainForm.Label4.Caption := '';
  109.   MainForm.CancelOnlineOperation1.Enabled := False;
  110.   MainForm.SpeedButton12.Enabled := False;
  111. end;
  112.  
  113. procedure TOnlineForm.ShowStatusMessage;
  114. var
  115.   S1, S2: String;
  116. begin
  117.   try
  118.     SetCancelOpportunitiesFalse;
  119.     Screen.Cursor := crDefault;
  120.     try if bDUNNormalQuit then MainForm.DialUp1.GoOffline; except end;
  121.     if MainForm.Terminating or ((not bAskToGoOffline) and (Abort)) then begin
  122.       MainForm.OnlineThreadCounter := 0;
  123.       MainForm.OnlineThreadTerminated := True;
  124.       Exit;
  125.     end;
  126.     PlaySound(sSoundFile3);
  127.     if bViewStatusAtEnd or bAskToGoOffline then begin
  128.       if AvailableMailCount > 0 then begin
  129.         MainForm.ListBox1.Items[58];
  130.         S1 := Format(MainForm.ListBox1.Items[59], [IntToStr(FetchedMailCount), IntToStr(AvailableMailCount)]);
  131.       end else S1 := MainForm.ListBox1.Items[60];
  132.       if SendMailCount = 1 then S2 := MainForm.ListBox1.Items[61] else
  133.         if SendMailCount > 1 then S2 := Format(MainForm.ListBox1.Items[62], [IntToStr(SendMailCount)]) else
  134.           S2 := MainForm.ListBox1.Items[63];
  135.       if OnlineTyp = 1 then Label7.Caption := S1;
  136.       if OnlineTyp = 2 then Label7.Caption := S2;
  137.       if OnlineTyp = 3 then Label7.Caption := S1+' '+S2;
  138.       if bAskToGoOffline then begin
  139.         Label6.Caption := Label9.Caption;
  140.         Label5.Visible := True;
  141.         Button5.Visible := True;
  142.         Button3.Caption := Label10.Caption;
  143.       end else begin
  144.         Label6.Caption := Label13.Caption;
  145.         Label5.Visible := False;
  146.         Button5.Visible := False;
  147.         Button3.Caption := Button4.Caption;
  148.       end;
  149.       NoteBook1.ActivePage := 'Offline';
  150.       MainForm.ShowPhoenixMail1Click(Self);
  151.       ShowModal;
  152.     end;
  153.   except end;
  154.   MainForm.OnlineThreadCounter := 0;
  155.   MainForm.OnlineThreadTerminated := True;
  156. end;
  157.  
  158. procedure TOnlineForm.DialUpNetwork;
  159. begin
  160.   Screen.Cursor := crDefault;
  161.   try
  162.     OnlineThread.Name := MainForm.ListBox1.Items[80];
  163.     if MainForm.DialUp1.PossibleConnections.IndexOf(sDUNConnection) <> -1 then
  164.       if MainForm.DialUp1.CurrentConnection = '' then begin  //if offline
  165.         MainForm.DialUp1.ConnectTo := sDUNConnection;
  166.         MainForm.DialUp1.Password := sDUNPassword;
  167.         if bDUNAskForPassword then MainForm.DialUp1.Password := '';
  168.         MainForm.DialUp1.Username := sDUNUsername;
  169.         OnlineThread.AddToLog(1, 'Connecting to Dial Up Network...');
  170.         if MainForm.DialUp1.Password = '' then begin
  171.           Notebook1.ActivePage := 'DUN';
  172.           ActiveControl := Edit2;
  173.           MainForm.ShowPhoenixMail1Click(Self);
  174.           if ShowModal = mrCancel then begin
  175.             MainForm.DialUp1.GoOffline;
  176.             OnlineThread.ShowError(MainForm.ListBox1.Items[82]);
  177.             Exit;
  178.           end else MainForm.DialUp1.Password := Edit1.Text;
  179.         end;
  180.         MainForm.DialUp1.GoOnline;
  181.         repeat
  182.           Application.HandleMessage;
  183.           if Abort then begin MainForm.DialUp1.GoOffline; Exit; end;
  184.         until (MainForm.DialUp1.CurrentConnection <> '');
  185.       end;
  186.   except
  187.     on Error: Exception do begin
  188.       MainForm.DialUp1.GoOffline; OnlineThread.ShowError(Error.Message);
  189.     end;
  190.   end;
  191. end;
  192.  
  193. procedure TOnlineForm.FormCreate(Sender: TObject);
  194.  
  195.   procedure SetBitmapToImage(var S: TImage; I: Integer);
  196.   var
  197.     Bitmap: TBitmap;
  198.   begin
  199.     Bitmap := TBitmap.Create;
  200.     MainForm.ImageList3.GetBitmap(I, Bitmap);
  201.     S.Picture.Bitmap.Assign(Bitmap);
  202.     Bitmap.Free;
  203.   end;
  204.  
  205. begin
  206.   AttachLanguageToForm(Self);
  207.   if bOfficeFonts then Font.Name := sOfficeFontName;
  208.   GroupBox3.Caption := Label15.Caption;
  209.   Caption := 'Phoenix Mail - '+MainForm.ListBox1.Items[36];
  210.   if ColorScheme or LowColor then begin
  211.     SetBitmapToImage(Image3, 12);
  212.     SetBitmapToImage(Image4, 10);
  213.     SetBitmapToImage(Image5, 11);
  214.     Image3.Transparent := True;
  215.     Image4.Transparent := True;
  216.     Image5.Transparent := True;
  217.     Image6.Transparent := True;
  218.   end;
  219.   Image6.Picture.Bitmap.Assign(Image4.Picture.Bitmap);
  220.   Image3.Width := 28;
  221.   Image4.Width := 28;
  222.   Image5.Width := 28;
  223.   Image6.Width := 28;
  224.   Edit1.PasswordChar := '*';
  225.   Edit2.PasswordChar := '*';
  226.   CommandList := TStringList.Create;
  227. end;
  228.  
  229. procedure TOnlineForm.Button7Click(Sender: TObject);
  230. begin
  231.   if FileExists(sProtocolFile) then
  232.     ShellExecute(Handle, 'open', PChar(sProtocolFile), '', PChar(ExtractFilePath(sProtocolFile)), SW_SHOWNORMAL);
  233. end;
  234.  
  235. procedure TOnlineForm.Edit1KeyPress(Sender: TObject; var Key: Char);
  236. begin
  237.   if Key = #13 then begin Key := #0; ModalResult := mrOK; end;
  238. end;
  239.  
  240. procedure TOnlineForm.FormDestroy(Sender: TObject);
  241. begin
  242.   CommandList.Free;
  243. end;
  244.  
  245. procedure TOnlineForm.Button5Click(Sender: TObject);
  246. begin
  247.   MainForm.DialUp1.GoOffline;
  248. end;
  249.  
  250. initialization
  251.   OnlineForm := nil;
  252.  
  253. end.
  254.