' Gambas class file
PRIVATE hUpdateInfo AS File 'handler to read update-watch-info file
PRIVATE cPackages AS NEW Collection 'store app data: Key=Package name, [0]=Status, [1]=Summary, [2]=Download Size, [3]=Install Size
PRIVATE sAppName AS String 'store app name globaly (used for reading apt-cache's output)
PUBLIC SUB Form_Open()
DIM sLine AS String 'store each line read from update-watch-info file
DIM sPkgList AS String 'store list of packages (for apt-cache command)
DIM sPkgName AS String 'store package name
DIM sRes AS String 'store outpu of apt-cache
'set number of columns
cvwPackage.Columns.Count = 2
cvwPackage.Columns[0].Text = ("Package")
cvwPackage.Columns[1].Text = ("Description")
'adjust button size to fit to text
btnHelp.Width = btnHelp.Font.Width(btnHelp.Text) + 20
btnUpgrade.Width = btnUpgrade.Font.Width(btnUpgrade.Text) + 20
btnRun.Width = btnRun.Font.Width(btnRun.Text) + 20
btnReboot.Width = btnReboot.Font.Width(btnReboot.Text) + 20
btnClose.Width = btnClose.Font.Width(btnClose.Text) + 20
hbxBottom.Height = btnClose.Font.Height(btnClose.Text) + 12
'read update-watch-info file if any updates exist
IF Stat(FMain.sPathInfo).Size > 0 THEN
hUpdateInfo = OPEN FMain.sPathInfo FOR READ
WHILE NOT Eof(hUpdateInfo)
LINE INPUT #hUpdateInfo, sLine
'split with ":"
sPkgName = Split(sLine, ":")[1]
'split virsion number for allow-duplicated packages. (ex. kernel#2.6.35-20vl6)
sPkgName = Split(sPkgName, "#")[0]
'remove .32bit for compat32 packages (ex. compat32-glibc.32bit)
IF sPkgName LIKE "*.32bit" THEN sPkgName = Left(sPkgName, (Len(sPkgName) - 6))
PRINT sPkgName
cPackages.Add([Split(sLine, ":")[0], "", "", ""], sPkgName)
sPkgList = sPkgList & " " & Split(sLine, ":")[1]
WEND
SHELL "apt-cache show " & sPkgList FOR READ AS "AptCache"
ELSE
'even if there is no update packges foud, run AptCache_Kill() to
'finish setup Flist form
AptCache_Kill()
ENDIF
'position window
ME.Center()
END
PUBLIC SUB AptCache_Read()
DIM sLine AS String
'read output from apt-cache command and store information to collection
LINE INPUT #LAST, sLine
IF InStr(sLine, ": ") THEN
SELECT CASE Split(sLine, ":")[0]
CASE "Package" 'Name
sLine = Right(sLine, Len(sLine) - 9) ' pacakge name
sAppName = sLine ' hold current app name
CASE "Summary"
cPackages[sAppName][1] = Right(sLine, Len(sLine) - 9)
CASE "Size"
cPackages[sAppName][2] = Right(sLine, Len(sLine) - 6)
CASE "Installed Size"
cPackages[sAppName][3] = Right(sLine, Len(sLine) - 16)
CASE "Version"
'do nothing
CASE "Description"
'do nothing
END SELECT
' ELSE
' ' assume only description has multi line text
' IF sAppName <> "" THEN
' cApplications[sAppName][idDesc] &= sLine & "
"
' ENDIF
ENDIF
END
PUBLIC SUB AptCache_Kill()
DIM aElement AS String[]
DIM iInstSize AS Integer = 0 'total install size
DIM iDLSize AS Integer = 0 'total download size
DIM sRes AS String 'store output from rpm command
'create package list after apt-cache command is finished
FOR EACH aElement IN cPackages
SELECT CASE aElement[0]
CASE "new"
AddTreeviewItem(("New"), cPackages.Key, aElement[1])
iDLSize = iDLSize + aElement[2]
iInstSize = iInstSize + aElement[3]
CASE "upgrade"
AddTreeviewItem(("Upgrade"), cPackages.Key, aElement[1])
'get current installed size
EXEC ["rpm", "-q", "--queryformat", "%{size}", cPackages.Key] TO sRes
iDLSize = iDLSize + aElement[2]
iInstSize = iInstSize + aElement[3] - CInt(sRes)
CASE "remove"
AddTreeviewItem(("Remove"), cPackages.Key, aElement[1])
'get current installed size
EXEC ["rpm", "-q", "--queryformat", "%{size}", cPackages.Key] TO sRes
iInstSize = iInstSize - CInt(sRes)
CASE "hold"
AddTreeviewItem(("Hold"), cPackages.Key, aElement[1])
CASE "duplicate"
AddTreeviewItem(("Duplicate"), cPackages.Key, aElement[1])
END SELECT
NEXT
'scroll up treeview
cvwPackage.MoveFirst
TRY cvwPackage.Item.EnsureVisible
'change icon and text, show/hide treeeview and so on...
SELECT CASE FMain.sNotifStatus
CASE "REBOOT"
pbxIcon.Picture = Stock["48/error"]
tlbTitle.Text = ("Reboot required
\n
\nTo complete the update of your system, restart your system.")
'hide treeview
cvwPackage.Visible = FALSE
hbxTop.Expand = TRUE
FList.Height = FList.Height - (cvwPackage.Height + FList.Spacing)
CASE "DUPLICATE"
pbxIcon.Picture = Picture["/usr/share/pixmaps/update-watch-orange.png"]
tlbTitle.Text = ("Duplicated version warning
\n
\nMultiple version packages found.
\nRun synaptic and resolve this problem.")
cvwPackage.Enabled = TRUE
CASE "UPDATE"
pbxIcon.Picture = Picture["/usr/share/pixmaps/update-watch-red.png"]
IF FMain.iHold >= 1 THEN
tlbTitle.Text = ("Upgrade hold packages found
\n
\nPlease run package manager to update it.")
cvwPackage.Enabled = TRUE
btnRun.Visible = TRUE
ELSE IF FMain.iUpgrade + FMain.iNew + FMain.iRemove >= 1 THEN
tlbTitle.Text = ("") & CStr(FMain.iUpgrade + FMain.iNew + FMain.iRemove) & (" update found
\n
\nIt may includes security fixes.
\nPlease update immediately.")
btnUpgrade.Visible = TRUE
cvwPackage.Enabled = TRUE
IF iInstSize >= 0 THEN
tlbInfo.Text = ("Total download size: ") & ConvUnit(iDLSize) & (" ") & ("(Used disk spaces after installation: ") & ConvUnit(iInstSize) & (")")
ELSE
tlbInfo.Text = ("Total download size: ") & ConvUnit(iDLSize) & (" ") & ("(Freed disk spaces after installation: ") & ConvUnit(Abs(iInstSize)) & (")")
ENDIF
ENDIF
CASE "NOUPDATE"
pbxIcon.Picture = Picture["update-watch.png"]
tlbTitle.Text = ("No updates found
\n
\nYour system seems now up-to-date.")
'hide treeview
cvwPackage.Visible = FALSE
hbxTop.Expand = TRUE
FList.Height = FList.Height - (cvwPackage.Height + FList.Spacing)
END SELECT
'set focus on close button
btnClose.SetFocus
END
PUBLIC SUB btnClose_Click()
ME.Close()
END
PUBLIC SUB btnHelp_Click()
FMain.hMenuHelp_Click()
END
PUBLIC SUB btnUpgrade_Click()
FMain.hMenuApply_Click()
ME.Close
END
PUBLIC SUB btnRun_Click()
FMain.hMenuRun_Click()
END
PUBLIC SUB btnReboot_Click()
EXEC ["/usr/bin/shutdown", "-r", "now"]
ME.Close
END
PUBLIC SUB AddTreeviewItem(sStatus AS String, sName AS String, sSummary AS String)
'add parent node in treeview
IF cvwPackage.Exist(sStatus) = FALSE THEN cvwPackage.Add(sStatus, sStatus)
' add each package
cvwPackage.Add(sName, sName, "", sStatus)
cvwPackage.Item[1] = sSummary
cvwPackage.Item.EnsureVisible
END
FUNCTION ConvUnit(sSize AS String) AS String
DIM iConv AS Integer = 0
DIM fConv AS Float = 0
IF Val(sSize) < 1024 THEN
RETURN sSize & ("Byte")
ELSE IF Val(sSize) < 1048576 THEN
iConv = Int(Val(sSize) / 1024)
RETURN Str(iConv) & ("KB")
ELSE
fConv = Val(sSize) / 1024 / 1024
RETURN Str(Format(fConv, "####.#")) & ("MB")
ENDIF
END