Source code of file oscpmwin/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: TRY
0092: OpenDialog := opmT_OpenPictureDialog.Create (opm_Form_UploadImage);
0093: TRY
0094: OpenDialog.DefaultExt := opmC_Def_UploadExt;
0095: OpenDialog.FileName := opmC_Def_UploadFilename;
0096: OpenDialog.Filter := _('Image files') + '|' + opmC_Def_UploadFilter + '|' + _('All files (*.*)');
0097: OpenDialog.Title := _('Uploading image file...');
0098: IF (OpenDialog.Execute = TRUE) THEN
0099: BEGIN
0100: opm_Selected_FileName := OpenDialog.FileName;
0101: opm_Edit_UploadFileName.Text := opm_Selected_FileName;
0102: opm_Edit_UploadNewName.Text := PRopm_FixNewName (FNopm_CleanUploadName (ExtractFileName (opm_Selected_FileName)), (opm_RadioGroup_UploadFormat.ItemIndex = 0));
0103: END
0104: ELSE
0105: BEGIN
0106: opm_Selected_FileName := '';
0107: opm_Edit_UploadFileName.Text := '';
0108: opm_Edit_UploadNewName.Text := '';
0109: END;
0110: FINALLY
0111: OpenDialog.Free;
0112: END;
0113: EXCEPT
0114: opm_Selected_FileName := '';
0115: opm_Edit_UploadFileName.Text := '';
0116: opm_Edit_UploadNewName.Text := '';
0117: END;
0118: END;
0119:
0120:
0121: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0122: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0123: FUNCTION Topm_Form_UploadImage.PRopm_FixNewName (ImageName : STRING; JPEGWanted : BOOLEAN) : STRING;
0124: BEGIN
0125: IF (JPEGWanted = TRUE) THEN
0126: BEGIN
0127: IF ((FNopm_ImageNameIsJPEG (ImageName) = FALSE) AND (ImageName <> '')) THEN
0128: BEGIN
0129: ImageName := COPY (ImageName, 1, LENGTH (ImageName) - LENGTH (ExtractFileExt (ImageName)));
0130: ImageName := ImageName + '.jpg';
0131: END;
0132: END
0133: ELSE
0134: BEGIN
0135: IF ((FNopm_ImageNameIsPNG (ImageName) = FALSE) AND (ImageName <> '')) THEN
0136: BEGIN
0137: ImageName := COPY (ImageName, 1, LENGTH (ImageName) - LENGTH (ExtractFileExt (ImageName)));
0138: ImageName := ImageName + '.png';
0139: END;
0140: END;
0141: PRopm_FixNewName := ImageName;
0142: END;
0143:
0144:
0145: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0146: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0147: procedure Topm_Form_UploadImage.opm_BitBtn_UploadOkClick(Sender: TObject);
0148: VAR
0149: TmpStr : STRING;
0150: begin
0151: TmpStr := FNopm_CleanUploadName (ExtractFileName (opm_Edit_UploadNewName.Text));
0152: IF (TmpStr = '') THEN
0153: TmpStr := FNopm_CleanUploadName (ExtractFileName (opm_Selected_FileName));
0154: opm_Edit_UploadNewName.Text := PRopm_FixNewName (TmpStr, (opm_RadioGroup_UploadFormat.ItemIndex = 0))
0155: end;
0156:
0157: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0158: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0159: procedure Topm_Form_UploadImage.opm_RadioGroup_UploadFormatClick (Sender: TObject);
0160: VAR
0161: TmpStr : STRING;
0162: begin
0163: TmpStr := FNopm_CleanUploadName (ExtractFileName (opm_Edit_UploadNewName.Text));
0164: IF (TmpStr = '') THEN
0165: TmpStr := FNopm_CleanUploadName (ExtractFileName (opm_Selected_FileName));
0166: opm_Edit_UploadNewName.Text := PRopm_FixNewName (TmpStr, (opm_RadioGroup_UploadFormat.ItemIndex = 0))
0167: end;
0168:
0169:
0170:
0171:
0172:
0173: end.