gambas-source-code/main/lib/db/gb.db/.src/Connections.class
Benoît Minisini 334c9d8beb [DEVELOPMENT ENVIRONMENT]
* NEW: Experimental "Gambas Software Farm" dialog. It allows to browse a 
  farm server, but voting and installing are not yet possible.
* NEW: Requests to the farm server are now displayed in a modal dialog with
  an optional progress bar.

[FARM SERVER]
* BUG: Fix many bugs.
* NEW: Search software by tags.

[GB.DB]
* BUG: Connections: Fix a not enough argument error.

[GB.FORM]
* NEW: URLLabel is a new control that displays a clickable URL. If the 
 'gb.desktop' component is loaded, then a browser is automatically opened 
  when clicking on the link.

[GB.GUI.BASE]
* NEW: ProgressBar now has a flat look. And a new Border property that
  allows to hide the border.

[GB.NET.CURL]
* NEW: HttpClient and FtpClient now raise a 'Cancel' event when their 
  Stop() method is called.
* BUG: Found a workaround for having accurate upload progress data.
* NEW: HttpClient.CopyFrom() is a new method that allows to fill an 
  HttpClient object with the configuration of another HttpClient object.

[GB.QT4]
* BUG: Do not use 'QEventLoop::DeferredDeletion' anymore, it is deprecated.
  Use qApp->sendPostedEvents() instead.


git-svn-id: svn://localhost/gambas/trunk@6665 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2014-11-23 02:22:57 +00:00

202 lines
4 KiB
Text

' Gambas class file
Export
Class Desktop
Static Property Read Key As String
Static Private $cConn As New Collection
Static Private $aConn As String[]
Static Private $sKey As String
Static Public Sub Exist(Name As String) As Boolean
If $cConn.Exist(Name) Or If Exist("../.connection" &/ Name & ".connection") Then Return True
End
Static Private Sub Init()
Dim sFile As String
If $aConn Then Return
$aConn = New String[]
For Each sFile In Dir("../.connection", "*.connection")
$aConn.Add(File.BaseName(sFile))
Next
End
Static Private Sub ReadConnectionFile(sName As String) As Collection
Dim sPath As String
Dim cData As New Collection
Dim hFile As File
Dim sLine As String
Dim bInConnection As Boolean
Dim aLine As String[]
sPath = "../.connection" &/ sName & ".connection"
If Not Exist(sPath) Then Return
hFile = Open sPath
While Not Eof(hFile)
Line Input #hFile, sLine
If Left(sLine) = "#" Then Continue
If Left(sLine) = "[" Then
bInConnection = sLine = "[Connection]"
Continue
Endif
If bInConnection Then
aLine = Scan(sLine, "*=*")
If aLine.Count < 2 Then Continue
Select Case LCase(aLine[0])
Case "type"
cData["type"] = UnQuote(aLine[1])
Case "path", "host"
cData["host"] = UnQuote(aLine[1])
Case "port"
cData["port"] = UnQuote(aLine[1])
Case "database"
cData["name"] = UnQuote(aLine[1])
Case "ignorecharset"
cData["ignorecharset"] = LCase(aLine[1]) = "true"
Case "user"
cData["user"] = UnQuote(aLine[1])
Case "rememberpassword"
cData["rememberpassword"] = LCase(aLine[1]) = "true"
End Select
Endif
Wend
Close #hFile
Return cData
End
Static Private Sub GetConnectionFrom(sName As String, cData As Collection) As Connection
Dim hConn As Connection
Dim bPassword As Boolean
hConn = New Connection
hConn.Type = cData["type"]
hConn.Host = cData["host"]
hConn.Port = cData["port"]
hConn.Name = cData["name"]
hConn.IgnoreCharset = cData["ignorecharset"]
hConn.User = cData["user"]
bPassword = cData["rememberpassword"]
If bPassword Then
If Component.IsLoaded("gb.desktop") Then
Try hConn.Password = Desktop.Passwords[Application.Name &/ sName]
If Error Then
Error "gb.db: warning: "; Application.Name &/ sName; ": unable to retrieve connection password: "; Error.Text
Endif
Endif
Endif
Return hConn
End
Static Public Sub _get(Name As String) As Connection
Dim hConn As Connection
Dim cData As Collection
Init()
If $cConn.Exist(Name) Then Return $cConn[Name]
cData = ReadConnectionFile(Name)
If Not cData Then Return
hConn = GetConnectionFrom(Name, cData)
$cConn[Name] = hConn
Return hConn
End
Static Public Sub _next() As Connection
Init()
If Not Enum.Index Then Enum.Index = 0
If Enum.Index >= $aConn.Count Then
$sKey = ""
Enum.Stop
Else
Inc Enum.Index
$sKey = $aConn[Enum.Index - 1]
Return _get($sKey)
Endif
End
Static Private Function Key_Read() As String
Return $sKey
End
Static Public Sub Create(Name As String) As Connection
Dim cData As Collection
Dim hConn As Connection
Dim hConnDB As Connection
Dim sPath As String
Init()
cData = ReadConnectionFile(Name)
If Not cData Then Return
hConn = GetConnectionFrom(Name, cData)
sPath = "../.connection" &/ Name & ".template"
If Exist(sPath) Then
hConnDB = New Connection
hConnDB.Type = hConn.Type
hConnDB.Host = hConn.Host
hConnDB.Port = hConn.Port
hConnDB.Open
If Not hConnDB.Databases.Exist(hConn.Name) Then
hConnDB.Databases.Add(hConn.Name)
Endif
hConnDB.Close
hConn.Open
hConn.ApplyTemplate(File.Load(sPath))
hConn.Close
Endif
Return hConn
End