Source code of file oscpmwin_v0.4.1.683/askupload.pas from the
osCommerce Product Manager for Windows.
0000: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001: osCommerce Product Manager for Windows (oscpmwin).
0002: Copyright �2003-2006 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: SysUtils, Forms,
0028: Dialogs, StdCtrls, Buttons, ExtCtrls, Controls, Classes;
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_ComboBox_UploadDir: TComboBox;
0040: opm_label_UploadDir: TLabel;
0041: procedure FormCreate(Sender: TObject);
0042: procedure FormShow(Sender: TObject);
0043: procedure opm_BitBtn_UploadSelectFileClick(Sender: TObject);
0044: procedure opm_BitBtn_UploadOkClick(Sender: TObject);
0045: procedure opm_RadioGroup_UploadFormatClick(Sender: TObject);
0046: private
0047: FUNCTION PRopm_FixNewName (ImageName : STRING; JPEGWanted : BOOLEAN) : STRING;
0048: public
0049: { Public declarations }
0050: end;
0051:
0052:
0053: VAR
0054: opm_Form_UploadImage : Topm_Form_UploadImage;
0055: opm_Selected_FileName : STRING;
0056:
0057:
0058: implementation
0059:
0060: {$R *.dfm}
0061:
0062:
0063: Uses gnugettext, dataman, imageman, openpicdlg;
0064:
0065:
0066: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0067: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0068: procedure Topm_Form_UploadImage.FormCreate(Sender: TObject);
0069: begin
0070: opm_Selected_FileName := '';
0071: TranslateComponent (self);
0072: end;
0073:
0074: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0075: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0076: procedure Topm_Form_UploadImage.FormShow(Sender: TObject);
0077: begin
0078: opm_Form_UploadImage.Caption := _('Upload product image');
0079: opm_RadioGroup_UploadFormat.ItemIndex := 0;
0080: opm_Edit_UploadFileName.Text := '';
0081: opm_Edit_UploadNewName.Text := '';
0082: opm_Selected_FileName := '';
0083: end;
0084:
0085: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0086: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0087: procedure Topm_Form_UploadImage.opm_BitBtn_UploadSelectFileClick (Sender: TObject);
0088: VAR
0089: OpenDialog : opmT_OpenPictureDialog;
0090: BEGIN
0091: OpenDialog := opmT_OpenPictureDialog.Create (opm_Form_UploadImage);
0092: OpenDialog.DefaultExt := opmC_Def_UploadExt;
0093: OpenDialog.FileName := opmC_Def_UploadFilename;
0094: OpenDialog.Filter := _('Image files') + '|' + opmC_Def_UploadFilter + '|' + _('All files (*.*)');
0095: OpenDialog.Title := _('Uploading image file...');
0096: IF (OpenDialog.Execute = TRUE) THEN
0097: BEGIN
0098: opm_Selected_FileName := OpenDialog.FileName;
0099: opm_Edit_UploadFileName.Text := opm_Selected_FileName;
0100: opm_Edit_UploadNewName.Text := PRopm_FixNewName (FNopm_CleanUploadName (ExtractFileName (opm_Selected_FileName)), (opm_RadioGroup_UploadFormat.ItemIndex = 0));
0101: END
0102: ELSE
0103: BEGIN
0104: opm_Selected_FileName := '';
0105: opm_Edit_UploadFileName.Text := '';
0106: opm_Edit_UploadNewName.Text := '';
0107: END;
0108: OpenDialog.Free;
0109: END;
0110:
0111:
0112: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0113: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0114: FUNCTION Topm_Form_UploadImage.PRopm_FixNewName (ImageName : STRING; JPEGWanted : BOOLEAN) : STRING;
0115: BEGIN
0116: IF (JPEGWanted = TRUE) THEN
0117: BEGIN
0118: IF ((FNopm_ImageNameIsJPEG (ImageName) = FALSE) AND (ImageName <> '')) THEN
0119: BEGIN
0120: ImageName := COPY (ImageName, 1, LENGTH (ImageName) - LENGTH (ExtractFileExt (ImageName)));
0121: ImageName := ImageName + '.jpg';
0122: END;
0123: END
0124: ELSE
0125: BEGIN
0126: IF ((FNopm_ImageNameIsPNG (ImageName) = FALSE) AND (ImageName <> '')) THEN
0127: BEGIN
0128: ImageName := COPY (ImageName, 1, LENGTH (ImageName) - LENGTH (ExtractFileExt (ImageName)));
0129: ImageName := ImageName + '.png';
0130: END;
0131: END;
0132: PRopm_FixNewName := ImageName;
0133: END;
0134:
0135:
0136: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0137: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0138: procedure Topm_Form_UploadImage.opm_BitBtn_UploadOkClick(Sender: TObject);
0139: VAR
0140: TmpStr : STRING;
0141: begin
0142: TmpStr := FNopm_CleanUploadName (ExtractFileName (opm_Edit_UploadNewName.Text));
0143: IF (TmpStr = '') THEN
0144: TmpStr := FNopm_CleanUploadName (ExtractFileName (opm_Selected_FileName));
0145: opm_Edit_UploadNewName.Text := PRopm_FixNewName (TmpStr, (opm_RadioGroup_UploadFormat.ItemIndex = 0))
0146: end;
0147:
0148: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0149: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0150: procedure Topm_Form_UploadImage.opm_RadioGroup_UploadFormatClick (Sender: TObject);
0151: VAR
0152: TmpStr : STRING;
0153: begin
0154: TmpStr := FNopm_CleanUploadName (ExtractFileName (opm_Edit_UploadNewName.Text));
0155: IF (TmpStr = '') THEN
0156: TmpStr := FNopm_CleanUploadName (ExtractFileName (opm_Selected_FileName));
0157: opm_Edit_UploadNewName.Text := PRopm_FixNewName (TmpStr, (opm_RadioGroup_UploadFormat.ItemIndex = 0))
0158: end;
0159:
0160:
0161:
0162:
0163:
0164: end.