Source code of file oscpmwin_v0.1.2.189/askupload.pas from the
osCommerce Product Manager for Windows.
0000: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001: osCommerce Product Manager for Windows (oscpmwin).
0002: Copyright �2003,2004,2005 by Mario A. Valdez-Ramirez.
0003:
0004: You can contact Mario A. Valdez-Ramirez
0005: by email at mario@mariovaldez.org or paper mail at
0006: Olmos 809, San Nicolas, NL. 66495, Mexico.
0007:
0008: This program is free software; you can redistribute it and/or modify
0009: it under the terms of the GNU General Public License as published by
0010: the Free Software Foundation; either version 2 of the License, or (at
0011: your option) any later version.
0012:
0013: This program is distributed in the hope that it will be useful, but
0014: WITHOUT ANY WARRANTY; without even the implied warranty of
0015: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0016: General Public License for more details.
0017:
0018: You should have received a copy of the GNU General Public License
0019: along with this program; if not, write to the Free Software
0020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0021: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0022: unit askupload;
0023:
0024: interface
0025:
0026: uses
0027: Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
0028: Dialogs, StdCtrls, Buttons, ExtCtrls;
0029:
0030: type
0031: Topm_Form_UploadImage = class(TForm)
0032: opm_BitBtn_UploadOk: TBitBtn;
0033: opm_BitBtn_UploadCancel: TBitBtn;
0034: opm_BitBtn_UploadSelectFile: TBitBtn;
0035: opm_Edit_UploadFileName: TEdit;
0036: opm_Edit_UploadNewName: TEdit;
0037: opm_label_UploadNewName: TLabel;
0038: opm_RadioGroup_UploadFormat: TRadioGroup;
0039: opm_OpenDialog_Upload: TOpenDialog;
0040: opm_ComboBox_UploadDir: TComboBox;
0041: opm_label_UploadDir: TLabel;
0042: procedure FormCreate(Sender: TObject);
0043: procedure FormShow(Sender: TObject);
0044: procedure opm_BitBtn_UploadSelectFileClick(Sender: TObject);
0045: procedure opm_BitBtn_UploadOkClick(Sender: TObject);
0046: procedure opm_RadioGroup_UploadFormatClick(Sender: TObject);
0047: private
0048: FUNCTION PRopm_FixNewName (ImageName : STRING; JPEGWanted : BOOLEAN) : STRING;
0049: public
0050: { Public declarations }
0051: end;
0052:
0053: var
0054: opm_Form_UploadImage: Topm_Form_UploadImage;
0055:
0056: implementation
0057:
0058: {$R *.dfm}
0059:
0060:
0061: Uses gnugettext, main, oscpmdata, balloons, dataman, imageman;
0062:
0063:
0064: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0065: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0066: procedure Topm_Form_UploadImage.FormCreate(Sender: TObject);
0067: begin
0068: TranslateComponent (self);
0069: end;
0070:
0071: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0072: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0073: procedure Topm_Form_UploadImage.FormShow(Sender: TObject);
0074: begin
0075: opm_Form_UploadImage.Caption := _('Upload product image');
0076: opm_RadioGroup_UploadFormat.ItemIndex := 0;
0077: opm_Edit_UploadFileName.Text := '';
0078: opm_Edit_UploadNewName.Text := '';
0079: end;
0080:
0081: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0082: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0083: procedure Topm_Form_UploadImage.opm_BitBtn_UploadSelectFileClick (Sender: TObject);
0084: begin
0085: opm_OpenDialog_Upload.DefaultExt := opmC_Def_UploadExt;
0086: opm_OpenDialog_Upload.FileName := opmC_Def_UploadFilename;
0087: opm_OpenDialog_Upload.Filter := _('Image files') + '|' + opmC_Def_UploadFilter + '|' + _('All files (*.*)');
0088: opm_OpenDialog_Upload.Title := _('Uploading image file...');
0089: IF (opm_OpenDialog_Upload.Execute = TRUE) THEN
0090: BEGIN
0091: opm_Edit_UploadFileName.Text := opm_OpenDialog_Upload.FileName;
0092: opm_Edit_UploadNewName.Text := PRopm_FixNewName (FNopm_CleanUploadName (ExtractFileName (opm_OpenDialog_Upload.FileName)), (opm_RadioGroup_UploadFormat.ItemIndex = 0));
0093: END
0094: ELSE
0095: BEGIN
0096: opm_Edit_UploadFileName.Text := '';
0097: opm_Edit_UploadNewName.Text := '';
0098: END;
0099: end;
0100:
0101:
0102: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0103: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0104: FUNCTION Topm_Form_UploadImage.PRopm_FixNewName (ImageName : STRING; JPEGWanted : BOOLEAN) : STRING;
0105: BEGIN
0106: IF (JPEGWanted = TRUE) THEN
0107: BEGIN
0108: IF ((FNopm_ImageNameIsJPEG (ImageName) = FALSE) AND (ImageName <> '')) THEN
0109: BEGIN
0110: ImageName := COPY (ImageName, 1, LENGTH (ImageName) - LENGTH (ExtractFileExt (ImageName)));
0111: ImageName := ImageName + '.jpg';
0112: END;
0113: END
0114: ELSE
0115: BEGIN
0116: IF ((FNopm_ImageNameIsPNG (ImageName) = FALSE) AND (ImageName <> '')) THEN
0117: BEGIN
0118: ImageName := COPY (ImageName, 1, LENGTH (ImageName) - LENGTH (ExtractFileExt (ImageName)));
0119: ImageName := ImageName + '.png';
0120: END;
0121: END;
0122: PRopm_FixNewName := ImageName;
0123: END;
0124:
0125:
0126: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0127: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0128: procedure Topm_Form_UploadImage.opm_BitBtn_UploadOkClick(Sender: TObject);
0129: VAR
0130: TmpStr : STRING;
0131: begin
0132: TmpStr := FNopm_CleanUploadName (ExtractFileName (opm_Edit_UploadNewName.Text));
0133: IF (TmpStr = '') THEN
0134: TmpStr := FNopm_CleanUploadName (ExtractFileName (opm_OpenDialog_Upload.FileName));
0135: opm_Edit_UploadNewName.Text := PRopm_FixNewName (TmpStr, (opm_RadioGroup_UploadFormat.ItemIndex = 0))
0136: end;
0137:
0138: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0139: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0140: procedure Topm_Form_UploadImage.opm_RadioGroup_UploadFormatClick (Sender: TObject);
0141: VAR
0142: TmpStr : STRING;
0143: begin
0144: TmpStr := FNopm_CleanUploadName (ExtractFileName (opm_Edit_UploadNewName.Text));
0145: IF (TmpStr = '') THEN
0146: TmpStr := FNopm_CleanUploadName (ExtractFileName (opm_OpenDialog_Upload.FileName));
0147: opm_Edit_UploadNewName.Text := PRopm_FixNewName (TmpStr, (opm_RadioGroup_UploadFormat.ItemIndex = 0))
0148: end;
0149:
0150: end.