diff --git a/applications/wikihelp/src/Utils.pas b/applications/wikihelp/src/Utils.pas new file mode 100644 index 000000000..dfc76101f --- /dev/null +++ b/applications/wikihelp/src/Utils.pas @@ -0,0 +1,724 @@ +UNIT Utils; + +INTERFACE + +{$H+} + +uses Classes,SysUtils,Graphics,Forms,Process,Dialogs,Clipbrd,FileUtil,Translations +{$IFDEF MSWINDOWS} +,Registry,Windows +{$ENDIF} +; + +{$IFNDEF FPC} +CONST + DirectorySeparator = '\'; +{$ENDIF} + +type + TRoundToRange = -37..37; + TProcessinfoTyp = (piOpen,piPrint); + {$ifdef WINDOWS} + PFNSHGetFolderPath = Function(Ahwnd: HWND; Csidl: Integer; Token: THandle; Flags: DWord; Path: PChar): HRESULT; stdcall; + {$endif} + +function ClearDir (Path: string): boolean; +function RPos(const Substr: string; const S: string): Integer; +FUNCTION IsNumeric(s: STRING): boolean; +FUNCTION StrTimeToValue(val : string) : LongInt; +procedure DrawText(Canvas : TCanvas;Rect : TRect;Str : string;CenterV : Boolean = False;CenterH : Boolean = False); +function InstallExt(Extension, ExtDescription, FileDescription,OpenWith, ParamString: string; IconIndex: Integer = 0): Boolean; +function SystemUserName : string; +function HTTPEncode(const str : String) : string; +function StripHTML(S: string): string; +function ValidateFileName(old : string) : string; +function ValidateFileDir(old : string) : string; +function ValidateDate(D : string) : string; +function GetTempPath : string; +function GetConfigDir(app : string) : string; +function GetGlobalConfigDir(app : string) : string; +function SizeToText(size : Longint) : string; +function GetMainIconHandle : Cardinal; +function CanWriteToProgramDir : Boolean; +function OpenBrowser(Site : string) : Boolean; +function HexToBin(h: STRING): dword; +procedure LoadLanguage(lang : string); +function RoundTo(const AValue : extended ; const ADigit : TRoundToRange) : extended ; +function TimeTotext(Seconds : Integer) : string; +procedure ExecProcess(CommandLine : string;CurDir : string = '';Waitfor : Boolean = True); +procedure ExecVisualProcess(CommandLine : string;CurDir : string = '';Waitfor : Boolean = True); +function ExecProcessEx(CommandLine : string;CurDir : string = '') : string; +function GetProcessforExtension(InfoTyp : TProcessinfoTyp;Extension : string) : string; +function GetMimeTypeforExtension(Extension : string) : string; +function GetSystemLang : string; + +IMPLEMENTATION + +function ExecProcessEx(CommandLine : string;CurDir : string = '') : string; +const + READ_BYTES = 2048; +var + process : TProcess; + ms: tmemorystream; + bytesread: integer; + n: longint; + tmps: tstringlist; + err : string; +begin + BytesRead := 0; + Process := TProcess.Create(nil); + Process.Options := [poUsePipes]; + Process.ShowWindow := swoHide; + Process.CommandLine := CommandLine; + if CurDir <> '' then + Process.CurrentDirectory := CurDir; + BytesRead := 0; + MS := TmemoryStream.create; + try + Process.Execute; + while Process.Running do + begin + MS.SetSize(BytesRead+READ_BYTES); + n := Process.OutPut.Read((MS.Memory+BytesRead)^,READ_BYTES); + if n > 0 then + inc(BytesRead,n) + else + sleep(50); + end; + except + on e : exception do + err := err+#13+e.Message; + end; + MS.SetSize(BytesRead+READ_BYTES); + n := Process.OutPut.Read((MS.Memory+BytesRead)^,READ_BYTES); + if n > 0 then + inc(Bytesread,n); + MS.SetSize(BytesRead); + Process.Free; + tmps := TStringList.Create; + tmps.LoadFromStream(MS); + Result := tmps.Text; + tmps.Free; + MS.Free; + if err <> '' then + Result := 'errors:'+err+#13+Result; +end; + +procedure ExecProcess(CommandLine : string;CurDir : string = '';Waitfor : Boolean = True); +var +{$IFDEF WINDOWS} + SUInfo: TStartupInfo; + ProcInfo: TProcessInformation; + CmdLine: string; + Res: Boolean; +{$ELSE} + process : TProcess; +{$ENDIF} +begin +{$IFDEF WINDOWS} + FillChar(SUInfo, SizeOf(SUInfo), #0); + with SUInfo do begin + cb := SizeOf(SUInfo); + dwFlags := STARTF_USESHOWWINDOW; + wShowWindow := SW_HIDE + end; + Res := CreateProcess(NIL, PChar(CommandLine), NIL, NIL, FALSE, + CREATE_NEW_CONSOLE or + NORMAL_PRIORITY_CLASS, NIL, + PChar(CurDir), + SUInfo, ProcInfo); + { Wait for it to finish. } + if Res and Waitfor then + WaitForSingleObject(ProcInfo.hProcess, INFINITE); +{$ELSE} + Process := TProcess.Create(nil); + if CurDir <> '' then + Process.CurrentDirectory := CurDir; + Process.CommandLine := CommandLine; + if Waitfor then + Process.Options := [poNewConsole{poNoConsole},poWaitOnExit] + else + Process.Options := [poNewConsole{poNoConsole}]; +// Process.ShowWindow := swoHide; + Process.Execute; + if Waitfor then Process.Free; +{$ENDIF} +end; + +procedure ExecVisualProcess(CommandLine : string;CurDir : string = '';Waitfor : Boolean = True); +var + process : TProcess; +begin + Process := TProcess.Create(nil); + if CurDir <> '' then + Process.CurrentDirectory := CurDir; + Process.CommandLine := CommandLine; + if Waitfor then + Process.Options := [poWaitOnExit] + else + Process.Options := []; + Process.Execute; + if Waitfor then Process.Free; +end; + +function TimeTotext(Seconds : Integer) : string; +var + tmp : Integer; +begin + if Seconds > 60*60 then + begin + Result := IntToStr(Trunc(Seconds/(60*60))) +' h'; + tmp := Seconds mod (60*60); + Result := Result +' '+IntToStr(Trunc(tmp/(60))) +' m'; + tmp := Seconds mod 60; + Result := Result +' '+IntToStr(tmp) +' s'; + end + else if Seconds > 60 then + begin + Result := IntToStr(Trunc(Seconds/(60))) +' m'; + tmp := Seconds mod 60; + Result := Result +' '+IntToStr(tmp) +' s'; + end + else + begin + Result := IntToStr(Seconds)+' s'; + end +end; + +function RoundTo(const AValue : extended ; const ADigit : TRoundToRange) : extended ; +var X : extended ; i : integer ; +begin + X := 1.0 ; + for i := 1 to Abs(ADigit) do X := X * 10 ; + if ADigit<0 then + Result := Round(AValue * X) / X + else + Result := Round(AValue / X) * X; +end; + +function HexToBin(h: STRING): dword; + FUNCTION HexDigitToInt(c: Char): Integer; + BEGIN + IF (c >= '0') AND (c <= '9') THEN Result := Ord(c) - Ord('0') + ELSE IF (c >= 'A') AND (c <= 'F') THEN Result := Ord(c) - Ord('A') + 10 + ELSE IF (c >= 'a') AND (c <= 'f') THEN Result := Ord(c) - Ord('a') + 10 + ELSE Result := -1; + END; +VAR + buf: ARRAY[0..16] OF Byte; + digit1: Integer; + bytes: Integer; + index: Integer; +BEGIN + bytes := 0; + index := 0; + result := 0; + IF frac(length(h) / 2) = 0.5 THEN + h := '0' + h; + WHILE (bytes < 16) DO + BEGIN + if length(h) > index+1 then + digit1 := HexDigitToInt(h[index + 1]) + else + digit1 := -1; + IF digit1 < 0 THEN + break; + buf[bytes] := (digit1 SHL 4) OR HexDigitToInt(h[index + 2]); + Inc(index, 2); + Inc(bytes); + END; + dec(bytes); + FOR index := bytes DOWNTO 0 DO + Result := Result + (buf[index] shl ((bytes-index)*8)); +END; + +procedure LoadLanguage(lang: string); +begin + if FileExists(ProgramDirectory+'languages'+Directoryseparator+Lang+'.po') then + TranslateUnitResourceStrings('uintfstrconsts',ProgramDirectory+'languages'+Directoryseparator+Lang+'.po'); +// TranslateResourcestrings(ProgramDirectory+'languages'+Directoryseparator+Lang+'.mo'); +end; + +function GetProcessforExtension(InfoTyp : TProcessinfoTyp;Extension : string) : string; +{$ifdef MSWINDOWS} +var + reg : TRegistry; + ot : string; + FileClass: string; + chrResult: array[0..1023] of Char; + wrdReturn: DWORD; +{$endif} +begin +{$ifdef WINDOWS} + case InfoTyp of + piOpen:ot := 'open'; + piPrint:ot := 'print'; + end; + Result := ''; + Reg := TRegistry.Create(KEY_READ); + Reg.RootKey := HKEY_CLASSES_ROOT; + FileClass := ''; + if Reg.OpenKeyReadOnly(ExtractFileExt('.'+Extension)) then + begin + FileClass := Reg.ReadString(''); + Reg.CloseKey; + end; + if FileClass <> '' then begin + if Reg.OpenKeyReadOnly(FileClass + '\Shell\'+ot+'\Command') then + begin + wrdReturn := ExpandEnvironmentStrings(PChar(StringReplace(Reg.ReadString(''),'%1','%s',[rfReplaceAll])), chrResult, 1024); + if wrdReturn = 0 then + Result := StringReplace(Reg.ReadString(''),'%1','%s',[rfReplaceAll]) + else + Result := Trim(chrResult); + Reg.CloseKey; + end; + end; + Reg.Free; +{$ELSE} +{$endif} +end; + +function GetMimeTypeforExtension(Extension : string) : string; +{$ifdef MSWINDOWS} +var + reg : TRegistry; +{$endif} +begin +{$ifdef WINDOWS} + Result := ''; + Reg := TRegistry.Create(KEY_READ); + Reg.RootKey := HKEY_CLASSES_ROOT; + if Reg.OpenKeyReadOnly(ExtractFileExt('.'+Extension)) then + begin + Result := Reg.ReadString('Content Type'); + Reg.CloseKey; + end; + Reg.Free; +{$ELSE} +{$endif} +end; + +function GetSystemLang: string; +{$IFDEF WINDOWS} +var + Ident: Integer; + MyLang: PChar; +const + Size: Integer = 250; +{$ENDIF} +begin +{$IFDEF WINDOWS} + GetMem(MyLang, Size); + Ident:=GetSystemDefaultLangID; + VerLanguageName(Ident, MyLang, Size); + Result:=StrPas(MyLang); + FreeMem(MyLang); +{$ELSE} + Result := GetEnvironmentVariable('LANG'); +{$ENDIF} +end; + +function OpenBrowser(Site : string) : Boolean; +var + cmd : string; + proc : TProcess; +begin + cmd := GetProcessforExtension(piOpen,'html'); + {$ifndef WINDOWS} + cmd := ExecProcessEx('gconftool-2 --get /desktop/gnome/url-handlers/http/command'); + if (cmd = '') or (pos('errors',cmd) > 0) then + cmd := GetEnvironmentVariable('BROWSER'); + if (cmd = '') then + cmd := 'kfmclient openURL %s'; + {$ENDIF} + if cmd = '' then exit; + proc := TProcess.Create(nil); + proc.CommandLine := StringReplace(cmd,'%s',Site,[rfReplaceAll]); + proc.Options := [poNewConsole]; + proc.Execute; + while Proc.Running do + Application.ProcessMessages; + proc.free; +end; + + +function CanWriteToProgramDir : Boolean; +var + f : TextFile; +begin + AssignFile(f,ExtractFilePath(Application.Exename)+'writetest.tmp'); + try + Rewrite(f); + except + Result := False; + exit; + end; + CloseFile(f); + SysUtils.DeleteFile(ExtractFilePath(Application.Exename)+'writetest.tmp'); + Result := True; +end; + +function SizeToText(size : Longint) : string; +begin + if size > 1024*1024*1024 then + Result := FormatFloat('0.00',size/(1024*1024*1024))+' Gb' + else if size > 1024*1024 then + Result := FormatFloat('0.00',size/(1024*1024))+' Mb' + else if size > 1024 then + Result := FormatFloat('0.00',size/(1024))+' Kb' + else + Result := IntToStr(size)+' byte' +end; + +function GetMainIconHandle : Cardinal; +begin +{$ifdef MSWINDOWS} + Result := LoadIcon(hInstance, 'MAINICON'); +{$else} + Result := 0; +{$endif} +end; + +function GetConfigDir(app : string) : string; +begin +{$IFDEF MSWINDOWS} + Result := copy(GetAppConfigDir(False),0,length(GetAppConfigDir(False))-length(ApplicationName))+app; +{$ELSE} + Result:=GetEnvironmentVariable('HOME'); + If (Result<>'') then + Result:=IncludeTrailingPathDelimiter(Result)+'.'+app; +{$ENDIF} + Result := IncludeTrailingPathDelimiter(result); +end; + +function GetGlobalConfigDir(app : string) : string; +{$IFDEF MSWINDOWS} +const + CSIDL_COMMON_APPDATA = $0023; // All Users\Application Data + CSIDL_FLAG_CREATE = $8000; { (force creation of requested folder if it doesn't exist yet) } +var + Path: array [0..1024] of char; + P : Pointer; + SHGetFolderPath : PFNSHGetFolderPath = Nil; + CFGDLLHandle : THandle = 0; +{$ENDIF} +begin +{$IFDEF MSWINDOWS} + CFGDLLHandle:=LoadLibrary('shell32.dll'); + if (CFGDLLHandle<>0) then + begin + P:=GetProcAddress(CFGDLLHandle,'SHGetFolderPathA'); + If (P=Nil) then + begin + FreeLibrary(CFGDLLHandle); + CFGDllHandle:=0; + end + else + SHGetFolderPath:=PFNSHGetFolderPath(P); + end; + If (P=Nil) then + begin + CFGDLLHandle:=LoadLibrary('shfolder.dll'); + if (CFGDLLHandle<>0) then + begin + P:=GetProcAddress(CFGDLLHandle,'SHGetFolderPathA'); + If (P=Nil) then + begin + FreeLibrary(CFGDLLHandle); + CFGDllHandle:=0; + end + else + ShGetFolderPath:=PFNSHGetFolderPath(P); + end; + end; + Result := ExtractFilePath(Application.Exename); + If (@ShGetFolderPath<>Nil) then + if SHGetFolderPath(0,CSIDL_COMMON_APPDATA or CSIDL_FLAG_CREATE,0,0,@PATH[0])=S_OK then + Result:=IncludeTrailingPathDelimiter(StrPas(@Path[0]))+app; +{$ELSE} +{$ENDIF} + Result := IncludeTrailingPathDelimiter(result); +end; + +function GetTempPath : string; +{$IFDEF MSWINDOWS} +var + TD : PChar; +{$ENDIF} +begin +{$IFDEF MSWINDOWS} + GetMem(TD, 256); + try + FillChar(TD^, 256, 0); + Windows.GetTempPath(256, TD); + Result := TD; + finally + FreeMem(TD, 256); + end; +{$ELSE} + Result := '/temp'; +{$ENDIF} +end; + +function ValidateFileDir(old: string): string; +begin + Result := old; + if DirectorySeparator <> '/' then + Result := StringReplace(Result,'/','',[rfReplaceAll]); + Result := StringReplace(Result,'@','',[rfReplaceAll]); + Result := StringReplace(Result,';','',[rfReplaceAll]); +end; + +function ValidateDate(D : string) : string; +begin + if pos('.',D) > 0 then + Result := StringReplace(D,'-','.',[rfReplaceAll]); + if length(D) = 4 then + Result := '01.01.'+D; +end; + +function ValidateFileName(old : string) : string; +begin + Result := StringReplace(old,'\','',[rfReplaceAll]); + Result := StringReplace(Result,'/','',[rfReplaceAll]); + Result := StringReplace(Result,'@','',[rfReplaceAll]); + Result := StringReplace(Result,';','',[rfReplaceAll]); +end; + +function StripHTML(S: string): string; +var + TagBegin, TagEnd, TagLength: integer; +begin + TagBegin := Pos( '<', S); // search position of first < + + while (TagBegin > 0) do begin // while there is a < in S + TagEnd := Pos('>', S); // find the matching > + TagLength := TagEnd - TagBegin + 1; + Delete(S, TagBegin, TagLength); // delete the tag + TagBegin:= Pos( '<', S); // search for next < + end; + + S := Stringreplace(S,' ',' ',[rfReplaceAll]); + S := Stringreplace(S,'&','&',[rfReplaceAll]); + S := Stringreplace(S,'<','<',[rfReplaceAll]); + S := Stringreplace(S,'>','>',[rfReplaceAll]); + S := Stringreplace(S,'"','"',[rfReplaceAll]); + Result := S; // give the result +end; + +function HTTPEncode(const str : String) : string; +const + noconvert = ['A'..'Z','a'..'z','*','@','.','_','-','0'..'9','$','!','''','(',')']; + hex2str : array[0..15] of char = '0123456789ABCDEF'; +var + i : integer; + c : char; +begin + Result := ''; + for i:=1 to length(str) do + begin + c:=str[i]; + if c in noconvert then + Result:=Result+c + else + Result:=Result+'%'+hex2str[ord(c) shr 4]+hex2str[ord(c) and $f]; + end; +end; + +{$IFDEF MSWINDOWS} +function SystemUserName : string; +var userNameBuffer : string[255]; + sizeBuffer : DWord; +begin + SizeBuffer := 256; + getUserName(@userNameBuffer+1, sizeBuffer); + result := userNameBuffer; +end; +{$ELSIF LINUX} +{$IFNDEF WINDOWS} +function SystemUserName : string; +begin + Result := GetEnvironmentVariable('USERNAME'); + if Result = '' then + Result := GetEnvironmentVariable('USER'); +end; +{$ENDIF} +{$ELSE} +function SystemUserName : string; +begin +end; +{$ENDIF} + +function InstallExt(Extension, ExtDescription, FileDescription,OpenWith, ParamString: string; IconIndex: Integer = 0): Boolean; +{$IFDEF MSWINDOWS} +var + Reg: TRegistry; +{$ENDIF} +begin + Result := False; + if Extension <> '' then + begin +{$IFDEF MSWINDOWS} + if Extension[1] <> '.' then + Extension := '.' + Extension; + Reg := TRegistry.Create; + try + Reg.RootKey := HKEY_CLASSES_ROOT; + if Reg.OpenKey(Extension, True) then + begin + Reg.WriteString('', ExtDescription); + if Reg.OpenKey('\' + ExtDescription, True) then + begin + Reg.WriteString('', FileDescription); + if Reg.OpenKey('DefaultIcon', True) then + begin + Reg.WriteString('', Format('%s,%d', [OpenWith, IconIndex])); + if Reg.OpenKey('\' + ExtDescription + '\Shell\Open\Command', True) then + begin + Reg.WriteString('', Format('"%s" "%s"', [OpenWith, ParamString])); + Result:=True; + end; + end; + end; + end; + finally + Reg.Free; + end; +{$ENDIF} + end; +end; + +procedure DrawText(Canvas : TCanvas;Rect : TRect;Str : string;CenterV : Boolean = False;CenterH : Boolean = False); +var + TextPosY, + TextPosX: Integer; +begin + TextPosX := Rect.Left; + if CenterH then + TextPosX := TextPosX+((Rect.Right-Rect.Left-Canvas.TextWidth(Str)) div 2); + TextPosY := Rect.Top; + if CenterV then + TextPosY := TextPosY+((Rect.Bottom-Rect.Top)-Canvas.TextHeight(Str)) div 2; + Canvas.TextOut(TextPosX,TextPosY,Str); +end; + +FUNCTION StrTimeToValue(val : string) : LongInt; +var + i : Integer; + un : string; +begin + //TODO:replace ',' with system delemiter + un := ''; + FOR i := 1 TO length(val) DO + IF NOT ((Char(Val[i]) IN ['0'..'9']) or (Char(Val[i]) = DecimalSeparator)) THEN + begin + un := trim(copy(Val,i,length(Val))); + break; + end; + if copy(Val,0,i-1) = '' then + begin + Result := -1; + exit; + end; + if (UpperCase(un) = 'MS') or (un = '') then + Result := Round(StrToFloat(copy(Val,0,i-1))) + else if UpperCase(un) = 'S' then + Result := Round(1000*StrToFloat(copy(Val,0,i-1))) + else if UpperCase(un) = 'M' then + Result := Round(60*1000*StrToFloat(copy(Val,0,i-1))) + else + Result := -1; +end; + +FUNCTION IsNumeric(s: STRING): boolean; +VAR + i : integer; + hassign: boolean; +BEGIN + // TODO:Replace ',' with Systemdelemiter + // geändert von schnullerbacke + // DecimalSeparator auf . gesetzt falls , + // doppeltes Vorkommen von sign verhindert + if DecimalSeparator = ',' then begin + // replace DecimalSeparator wenn nötig + i:= Pos(',', s); + s[i]:= '.'; + end; + Result:= (Pos('.', s) > 0) and (length(s) > 0); + if Result then begin + // lösche DecimalSeparator + Delete(s, i, 1); + hassign:= (Pos('-', s) > 0) or (Pos('+',s) > 0); + if hassign then begin + // lösche Vorkommen eines signs + i:= Pos('-', s); + if i = 0 then i:= Pos('+', s); + if i > 0 then Delete(s, i, 1); + end; + i:= 1; + while (i <= length(s)) and Result do begin + // nur noch Test auf Digit nötig + Result:= (Char(s[i]) IN ['0'..'9']); + IF Result then inc(i); + END; // of while (i <= length(s)) and Result do begin + end; // of if Result then begin +END; + +function RPos(const Substr: string; const S: string): Integer; +var + SL, i : Integer; +begin + SL := Length(Substr); + i := Length(S); + if (Substr = '') or (S = '') or (SL > i) then begin + Result := 0; + Exit; + end; + + while i >= SL do begin + if S[i] = Substr[SL] then begin + if Copy(S, i - SL + 1, SL) = Substr then begin + Result := i - SL + 1; + Exit; + end; + end; + Dec(i); + end; + Result := i; +end; + + { Make sure given file path is ended with backslash ("\") } + { Clears Directory: Removes all files and directories contained } +function ClearDir (Path: string): boolean; +var + Res: integer; + SRec: SysUtils.TSearchRec; +begin + Result := false; + try + if copy(path,length(path)-1,1) <> DirectorySeparator then + Path := Path+DirectorySeparator; + Res := FindFirst (Path + '*.*', faAnyFile, SRec); + while Res = 0 do + begin + if (SRec.Attr = faDirectory) and (SRec.Name[1] <> '.') then + begin + ClearDir (Path + SRec.Name); { Clear before removing } + if not RemoveDir (pchar(Path + SRec.Name)) then + exit; + end + else + SysUtils.DeleteFile(Path + SRec.Name); + Res := FindNext(SRec); + end; + SysUtils.FindClose(SRec); + Result := true; + except + end; +end; + + +END. + + diff --git a/applications/wikihelp/src/uappconsts.pas b/applications/wikihelp/src/uappconsts.pas new file mode 100644 index 000000000..0aa550cbf --- /dev/null +++ b/applications/wikihelp/src/uappconsts.pas @@ -0,0 +1,22 @@ +unit uAppconsts; + +{$mode objfpc}{$H+} + +interface + +const + vAppName = 'wikihelp'; + vRevision = 2; + vVersion = 0.5; + vProgramname = 'WikiHelp'; + vTimeOutYear = 0; + vTimeOutMonth = 0; + vTimeOutDay = 0; + vCopyright = '2007 Christian Ulrich'; + vTracker_url = 'mantis.ullihome.de'; + vProject_id = 5; + +implementation + +end. + diff --git a/applications/wikihelp/src/umain.lfm b/applications/wikihelp/src/umain.lfm new file mode 100644 index 000000000..da28322f2 --- /dev/null +++ b/applications/wikihelp/src/umain.lfm @@ -0,0 +1,160 @@ +object fWikiHelp: TfWikiHelp + Left = 324 + Height = 322 + Top = 221 + Width = 428 + HorzScrollBar.Page = 427 + VertScrollBar.Page = 321 + ActiveControl = eWikiPage + Caption = 'WikiHelp' + OnClose = FormClose + OnCreate = FormCreate + object lWikiPage: TLabel + Left = 8 + Height = 14 + Top = 8 + Width = 44 + Caption = 'WikiPage' + Color = clNone + ParentColor = False + end + object lPageOffset: TLabel + Left = 8 + Height = 14 + Top = 60 + Width = 58 + Caption = 'lPageOffset' + Color = clNone + ParentColor = False + end + object eFoundPages: TLabel + Left = 8 + Height = 14 + Top = 104 + Width = 66 + Caption = 'eFoundPages' + Color = clNone + ParentColor = False + end + object lOutputDir: TLabel + Left = 8 + Height = 14 + Top = 240 + Width = 51 + Caption = 'Output Dir' + Color = clNone + ParentColor = False + end + object lLanguage: TLabel + Left = 288 + Height = 14 + Top = 8 + Width = 48 + Caption = 'Language' + Color = clNone + ParentColor = False + end + object eWikiPage: TEdit + Left = 8 + Height = 23 + Top = 28 + Width = 268 + Anchors = [akTop, akLeft, akRight] + TabOrder = 0 + Text = 'http://www.ullihome.de/index.php/' + end + object ePageOffset: TEdit + Left = 8 + Height = 23 + Top = 76 + Width = 412 + Anchors = [akTop, akLeft, akRight] + TabOrder = 1 + end + object lbFoundPages: TListBox + Left = 8 + Height = 95 + Top = 120 + Width = 332 + Anchors = [akTop, akLeft, akRight, akBottom] + TabOrder = 2 + end + object bSearch: TButton + Left = 345 + Height = 25 + Top = 120 + Width = 75 + Anchors = [akTop, akRight] + BorderSpacing.InnerBorder = 4 + Caption = 'Search' + OnClick = bSearchClick + TabOrder = 3 + end + object bCreate: TButton + Left = 345 + Height = 25 + Top = 286 + Width = 75 + Anchors = [akRight, akBottom] + BorderSpacing.InnerBorder = 4 + Caption = 'Create' + OnClick = bCreateClick + TabOrder = 4 + end + object pbProgress: TProgressBar + Left = 8 + Height = 20 + Top = 287 + Width = 332 + Anchors = [akLeft, akRight, akBottom] + Max = 100 + end + object eOutputDir: TDirectoryEdit + Left = 8 + Height = 23 + Top = 259 + Width = 332 + ButtonWidth = 23 + NumGlyphs = 1 + Anchors = [akLeft, akRight, akBottom] + ParentColor = False + TabOrder = 5 + end + object cbLanguage: TComboBox + Left = 288 + Height = 21 + Top = 28 + Width = 132 + Anchors = [akTop, akRight] + AutoCompleteText = [cbactEndOfLineComplete, cbactSearchAscending] + Items.Strings = ( + 'Special:Allpages' + 'Spezial:Allpages' + ) + MaxLength = 0 + OnSelect = cbLanguageSelect + TabOrder = 6 + end + object cbAddLinkedPages: TCheckBox + Left = 8 + Height = 13 + Top = 220 + Width = 103 + Caption = 'Add linked Pages' + TabOrder = 7 + end + object Properties: TXMLPropStorage + StoredValues = < + item + Name = 'OUTPUTDIR' + end + item + Name = 'WIKIPAGE' + end + item + Name = 'PAGEOFFSET' + end> + left = 4 + top = 4 + end +end diff --git a/applications/wikihelp/src/umain.lrs b/applications/wikihelp/src/umain.lrs new file mode 100644 index 000000000..a0cb397a7 --- /dev/null +++ b/applications/wikihelp/src/umain.lrs @@ -0,0 +1,44 @@ +{ Das ist eine automatisch erzeugte Lazarus-Ressourcendatei } + +LazarusResources.Add('TfWikiHelp','FORMDATA',[ + 'TPF0'#10'TfWikiHelp'#9'fWikiHelp'#4'Left'#3'D'#1#6'Height'#3'B'#1#3'Top'#3 + +#221#0#5'Width'#3#172#1#18'HorzScrollBar.Page'#3#171#1#18'VertScrollBar.Page' + +#3'A'#1#13'ActiveControl'#7#9'eWikiPage'#7'Caption'#6#8'WikiHelp'#7'OnClose' + +#7#9'FormClose'#8'OnCreate'#7#10'FormCreate'#0#6'TLabel'#9'lWikiPage'#4'Left' + +#2#8#6'Height'#2#14#3'Top'#2#8#5'Width'#2','#7'Caption'#6#8'WikiPage'#5'Colo' + +'r'#7#6'clNone'#11'ParentColor'#8#0#0#6'TLabel'#11'lPageOffset'#4'Left'#2#8#6 + +'Height'#2#14#3'Top'#2'<'#5'Width'#2':'#7'Caption'#6#11'lPageOffset'#5'Color' + +#7#6'clNone'#11'ParentColor'#8#0#0#6'TLabel'#11'eFoundPages'#4'Left'#2#8#6'H' + +'eight'#2#14#3'Top'#2'h'#5'Width'#2'B'#7'Caption'#6#11'eFoundPages'#5'Color' + +#7#6'clNone'#11'ParentColor'#8#0#0#6'TLabel'#10'lOutputDir'#4'Left'#2#8#6'He' + +'ight'#2#14#3'Top'#3#240#0#5'Width'#2'3'#7'Caption'#6#10'Output Dir'#5'Color' + +#7#6'clNone'#11'ParentColor'#8#0#0#6'TLabel'#9'lLanguage'#4'Left'#3' '#1#6'H' + +'eight'#2#14#3'Top'#2#8#5'Width'#2'0'#7'Caption'#6#8'Language'#5'Color'#7#6 + +'clNone'#11'ParentColor'#8#0#0#5'TEdit'#9'eWikiPage'#4'Left'#2#8#6'Height'#2 + +#23#3'Top'#2#28#5'Width'#3#12#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0 + +#8'TabOrder'#2#0#4'Text'#6'!http://www.ullihome.de/index.php/'#0#0#5'TEdit' + +#11'ePageOffset'#4'Left'#2#8#6'Height'#2#23#3'Top'#2'L'#5'Width'#3#156#1#7'A' + +'nchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'TabOrder'#2#1#0#0#8'TListBox' + +#12'lbFoundPages'#4'Left'#2#8#6'Height'#2'_'#3'Top'#2'x'#5'Width'#3'L'#1#7'A' + +'nchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#8'TabOrder'#2#2#0#0#7 + +'TButton'#7'bSearch'#4'Left'#3'Y'#1#6'Height'#2#25#3'Top'#2'x'#5'Width'#2'K' + +#7'Anchors'#11#5'akTop'#7'akRight'#0#25'BorderSpacing.InnerBorder'#2#4#7'Cap' + +'tion'#6#6'Search'#7'OnClick'#7#12'bSearchClick'#8'TabOrder'#2#3#0#0#7'TButt' + +'on'#7'bCreate'#4'Left'#3'Y'#1#6'Height'#2#25#3'Top'#3#30#1#5'Width'#2'K'#7 + +'Anchors'#11#7'akRight'#8'akBottom'#0#25'BorderSpacing.InnerBorder'#2#4#7'Ca' + +'ption'#6#6'Create'#7'OnClick'#7#12'bCreateClick'#8'TabOrder'#2#4#0#0#12'TPr' + +'ogressBar'#10'pbProgress'#4'Left'#2#8#6'Height'#2#20#3'Top'#3#31#1#5'Width' + +#3'L'#1#7'Anchors'#11#6'akLeft'#7'akRight'#8'akBottom'#0#3'Max'#2'd'#0#0#14 + +'TDirectoryEdit'#10'eOutputDir'#4'Left'#2#8#6'Height'#2#23#3'Top'#3#3#1#5'Wi' + +'dth'#3'L'#1#11'ButtonWidth'#2#23#9'NumGlyphs'#2#1#7'Anchors'#11#6'akLeft'#7 + +'akRight'#8'akBottom'#0#11'ParentColor'#8#8'TabOrder'#2#5#0#0#9'TComboBox'#10 + +'cbLanguage'#4'Left'#3' '#1#6'Height'#2#21#3'Top'#2#28#5'Width'#3#132#0#7'An' + +'chors'#11#5'akTop'#7'akRight'#0#16'AutoCompleteText'#11#22'cbactEndOfLineCo' + +'mplete'#20'cbactSearchAscending'#0#13'Items.Strings'#1#6#16'Special:Allpage' + +'s'#6#16'Spezial:Allpages'#0#9'MaxLength'#2#0#8'OnSelect'#7#16'cbLanguageSel' + +'ect'#8'TabOrder'#2#6#0#0#9'TCheckBox'#16'cbAddLinkedPages'#4'Left'#2#8#6'He' + +'ight'#2#13#3'Top'#3#220#0#5'Width'#2'g'#7'Caption'#6#16'Add linked Pages'#8 + +'TabOrder'#2#7#0#0#15'TXMLPropStorage'#10'Properties'#12'StoredValues'#14#1#4 + +'Name'#6#9'OUTPUTDIR'#0#1#4'Name'#6#8'WIKIPAGE'#0#1#4'Name'#6#10'PAGEOFFSET' + +#0#0#4'left'#2#4#3'top'#2#4#0#0#0 +]); diff --git a/applications/wikihelp/src/umain.pas b/applications/wikihelp/src/umain.pas new file mode 100644 index 000000000..b07d1d936 --- /dev/null +++ b/applications/wikihelp/src/umain.pas @@ -0,0 +1,563 @@ +unit uMain; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, + Buttons,httpsend, ComCtrls, Utils, xmlread,dom, EditBtn, FileUtil, + XMLPropStorage,Clipbrd; + +type + + { TfWikiHelp } + + TfWikiHelp = class(TForm) + bSearch: TButton; + bCreate: TButton; + eOutputDir: TDirectoryEdit; + ePageOffset: TEdit; + eWikiPage: TEdit; + eFoundPages: TLabel; + lOutputDir: TLabel; + lbFoundPages: TListBox; + lPageOffset: TLabel; + lWikiPage: TLabel; + pbProgress: TProgressBar; + Properties: TXMLPropStorage; + cbLanguage: TComboBox; + lLanguage: TLabel; + cbAddLinkedPages: TCheckBox; + procedure bCreateClick(Sender: TObject); + procedure bSearchClick(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); + procedure cbLanguageSelect(Sender: TObject); + private + { private declarations } + SpecialPageURL : string; + ExportPageURL : string; + ImageTagName : string; + public + { public declarations } + procedure Wiki2Html(wname : string;OutputDir : string;content : string); + end; + +var + fWikiHelp: TfWikiHelp; + +implementation + +uses uAppconsts; + +{ TfWikiHelp } + +procedure TfWikiHelp.bSearchClick(Sender: TObject); +var + http : THttpSend; + ss : TStringStream; + s : string; +begin + lbFoundPages.Items.Clear; + ss := TStringStream.Create(''); + http := THttpSend.Create; + http.HTTPMethod('GET',eWikiPage.Text+SpecialPageURL); + http.Document.SaveToStream(ss); + http.Free; + s := ss.DataString; + s := copy(s,pos('
',s),length(s)); + s := copy(s,0,pos(' |