' Gambas class file PUBLIC bAssumeYes AS Boolean = FALSE ' TRUE: apt-get should run with --assume-yes ' this value is set in FProgress.class PUBLIC bSrcOnly AS Boolean = FALSE ' TRUE: only src.rpm(s) are selected PUBLIC SUB Form_Open() ME.Center() ' adjust button size according to it's font size btnHelp.Width = btnHelp.Font.Width(btnHelp.Text) + 36 btnCancel.Width = btnCancel.Font.Width(btnCancel.Text) + 36 btnRun.Width = btnRun.Font.Width(btnRun.Text) + 36 hbxBottom.Height = btnCancel.Font.Height(btnCancel.Text) + 18 END PUBLIC SUB Form_Close() ' stop timer to avoid file missing error in Timer_Timer() *rare case* Timer.Stop ' remove lock file before exit IF Exist(MMain.sLockFile) = TRUE THEN KILL MMain.sLockFile END PUBLIC SUB btnRun_Click() DIM iRet AS Integer ' hold return valu of installation progress DIM iSrcPkg AS Integer ' count src.rpm packages DIM i AS Integer ' loop counter IF lvwMain.Count > 0 THEN ' check src.rpm and arch/noarch.rpm are mixed or not lvwMain.MoveFirst FOR i = 1 TO lvwMain.Count IF File.Ext(File.BaseName(lvwMain.Item.Key)) = "src" THEN INC iSrcPkg ENDIF lvwMain.MoveNext NEXT IF iSrcPkg = lvwMain.Count OR IF iSrcPkg = 0 THEN ' if all file(s) are src.rpm only or not src.rpm only then continue installation IF iSrcPkg = lvwMain.Count THEN bSrcOnly = TRUE ELSE bSrcOnly = FALSE ENDIF ' proceed installation iRet = FProgress.ShowModal() ' if trivial(safe) operation is executed and user continue the operation (= return 2), ' then install again with --assume-yes. IF iRet = 2 THEN bAssumeYes = TRUE iRet = FProgress.ShowModal() bAssumeYes = FALSE ENDIF ' if installation finished successfully, clear the list IF iRet = TRUE THEN lvwMain.Clear() ELSE ' stop installation if src.rpm and arch.rpm are mixed Message.Error(("Source rpm & binary rpm are mixed.\nYou can not install them together.")) ENDIF ENDIF END PUBLIC SUB btnAdd_Click() DIM i AS Integer WITH Dialog .title = ("Select files") .Filter = ["*.rpm", ("RPM packages")] .Path = System.User.Home ' *[Note] Dialog.OpenFile returns FALSE when user clicked OK button. IF .OpenFile(TRUE) = FALSE THEN IF .Paths.Count > 0 THEN FOR i = 0 TO .Paths.Max MMain.AddRPMtolvwMain(.Paths[i]) NEXT ENDIF ENDIF END WITH END PUBLIC SUB btnRemove_Click() DIM aList AS NEW String[] DIM i AS Integer ' check selected line and store key to string array WITH lvwMain IF .Count > 0 THEN .MoveFirst FOR i = 1 TO .Count IF .Item.Selected = TRUE THEN aList.Add(.Item.Key) .MoveNext NEXT ENDIF ' then remove selected line IF aList.Count > 0 THEN FOR i = 0 TO aList.Count - 1 .Remove(aList[i]) NEXT ENDIF END WITH END '' *Just reference* '' if listview is single mode, then works fine with followings. ' IF ListView1.Current <> NULL THEN ' ListView1.Remove(ListView1.Current.Key) ' ENDIF PUBLIC SUB btnCancel_Click() ME.Close() END PUBLIC SUB btnHelp_Click() EXEC ["xdg-open", "/usr/share/doc/rpminstall-" & Application.Version & "/help/index.html"] END PUBLIC SUB Form_KeyPress() IF Key.Code = Key.Escape THEN ME.Close(TRUE) END PUBLIC SUB Timer_Timer() ' timer event is called every 500 ms DIM sLine AS String WITH MMain IF Stat(.sLockFile).Size > 0 THEN .hLockFile = OPEN .sLockFile FOR READ WHILE NOT Eof(.hLockFile) LINE INPUT #.hLockFile, sLine IF File.Ext(sLine) <> "rpm" THEN CONTINUE IF File.Ext(File.BaseName(sLine)) LIKE .sArch OR IF File.Ext(File.BaseName(sLine)) = "noarch" THEN IF lvwMain.Exist(File.Name(sLine)) = FALSE THEN lvwMain.Add(File.Name(sLine), sLine, Picture.Load("rpm.png")) ENDIF ENDIF WEND ' clear lock file .hLockFile = OPEN .sLockFile FOR CREATE .hLockFile.Close() ENDIF END WITH END PUBLIC SUB lvwMain_Drop() DIM sDrop AS String[] DIM i AS Integer ' add dropped file to list sDrop = Split(Drag.Data, "\n\r") FOR i = 0 TO sDrop.Max IF sDrop[i] LIKE "file://*rpm" THEN MMain.AddRPMtolvwMain(Replace(sDrop[i], "file://", "")) ENDIF NEXT END PUBLIC SUB lvwMain_Drag() ' show frame while dragging icons Drag.Show(lvwMain) END