Browse Source

Add action to status button, info box, and add device

wip-main-ui
Jaeha Choi 2 months ago
parent
commit
570d9d1149
Signed by: Jaeha.Choi GPG Key ID: D6133D1D117FF503
  1. 434
      data/ui/UI.glade
  2. 300
      internal/client/ui.go

434
data/ui/UI.glade

@ -2,7 +2,16 @@
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkListStore" id="contactList"/>
<object class="GtkListStore" id="contactList">
<columns>
<!-- column-name Name -->
<column type="gchararray"/>
<!-- column-name Date -->
<column type="gchararray"/>
<!-- column-name PubKey -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkListStore" id="fileList">
<columns>
<!-- column-name Filename -->
@ -11,9 +20,9 @@
<column type="gchararray"/>
<!-- column-name Status -->
<column type="gchararray"/>
<!-- column-name Full path -->
<!-- column-name Full -->
<column type="gchararray"/>
<!-- column-name Size in Bytes -->
<!-- column-name Size1 -->
<column type="gint64"/>
</columns>
</object>
@ -22,11 +31,11 @@
<property name="resizable">False</property>
<property name="default-width">500</property>
<property name="default-height">700</property>
<signal name="key-press-event" handler="keyPress" swapped="no"/>
<signal name="key-press-event" handler="keyPressMainWin" swapped="no"/>
<child>
<object class="GtkNotebook" id="pager">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="can-focus">False</property>
<signal name="switch-page" handler="switchPage" swapped="no"/>
<child>
<object class="GtkBox" id="fileBox">
@ -34,65 +43,98 @@
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkTreeView" id="fileListView">
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">fileList</property>
<property name="enable-grid-lines">horizontal</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="fileSelected">
<property name="mode">multiple</property>
</object>
</child>
<property name="hscrollbar-policy">never</property>
<property name="shadow-type">in</property>
<property name="min-content-width">500</property>
<property name="max-content-width">500</property>
<property name="max-content-height">700</property>
<property name="propagate-natural-height">True</property>
<child>
<object class="GtkTreeViewColumn" id="fileName">
<property name="max-width">150</property>
<property name="title" translatable="yes">Filename</property>
<property name="expand">True</property>
<property name="clickable">True</property>
<property name="sort-column-id">0</property>
<object class="GtkTreeView" id="fileListView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">fileList</property>
<property name="search-column">0</property>
<property name="rubber-banding">True</property>
<property name="enable-grid-lines">horizontal</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="fileSelected">
<property name="mode">multiple</property>
</object>
</child>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
<object class="GtkTreeViewColumn" id="fileName">
<property name="max-width">100</property>
<property name="title" translatable="yes">Filename</property>
<property name="expand">True</property>
<property name="clickable">True</property>
<property name="sort-column-id">0</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="fileSize">
<property name="max-width">50</property>
<property name="title" translatable="yes">Size</property>
<property name="clickable">True</property>
<property name="sort-column-id">4</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
<object class="GtkTreeViewColumn" id="fileSize">
<property name="max-width">50</property>
<property name="title" translatable="yes">Size</property>
<property name="clickable">True</property>
<property name="sort-column-id">4</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="fileStatus">
<property name="max-width">100</property>
<property name="title" translatable="yes">Status</property>
<property name="expand">True</property>
<property name="clickable">True</property>
<property name="sort-column-id">2</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEventBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<signal name="button-release-event" handler="clickEmptySpotFile" swapped="no"/>
<signal name="set-focus-child" handler="clickEmptySpotFile" swapped="no"/>
<child>
<object class="GtkTreeViewColumn" id="fileStatus">
<property name="max-width">200</property>
<property name="title" translatable="yes">Status</property>
<property name="expand">True</property>
<property name="clickable">True</property>
<property name="sort-column-id">2</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
@ -107,7 +149,7 @@
<property name="margin-end">2</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">Selected File(s):</property>
<property name="label" translatable="yes">Total File(s):</property>
</object>
<packing>
<property name="expand">False</property>
@ -123,6 +165,7 @@
<property name="margin-end">2</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">0</property>
</object>
<packing>
<property name="expand">False</property>
@ -138,6 +181,7 @@
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">0</property>
</object>
<packing>
<property name="expand">False</property>
@ -167,7 +211,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>
@ -185,43 +229,198 @@
</packing>
</child>
<child>
<object class="GtkTreeView" id="contactListView">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">contactList</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkTreeViewColumn" id="contactSelect">
<property name="clickable">True</property>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<property name="min-content-width">500</property>
<property name="max-content-width">500</property>
<property name="max-content-height">700</property>
<property name="propagate-natural-height">True</property>
<child>
<object class="GtkCellRendererToggle" id="contactSelectToggle"/>
<object class="GtkTreeView" id="contactListView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">contactList</property>
<property name="search-column">0</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="contactName">
<property name="max-width">150</property>
<property name="title" translatable="yes">Name</property>
<property name="clickable">True</property>
<property name="sort-column-id">0</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="contactDate">
<property name="max-width">100</property>
<property name="title" translatable="yes">Date</property>
<property name="clickable">True</property>
<property name="sort-column-id">1</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="contactPubkey">
<property name="max-width">100</property>
<property name="title" translatable="yes">PubKey</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTreeViewColumn" id="contactName">
<property name="min-width">100</property>
<property name="title" translatable="yes">Name</property>
<property name="clickable">True</property>
<property name="sort-indicator">True</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="contactDate">
<property name="min-width">80</property>
<property name="title" translatable="yes">Date</property>
<property name="clickable">True</property>
<property name="sort-indicator">True</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="contactPubkey">
<property name="title" translatable="yes">PubKey</property>
<property name="clickable">True</property>
<property name="sort-indicator">True</property>
<object class="GtkExpander">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="valign">end</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-top">20</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="label" translatable="yes">&lt;span size="xx-large" weight="bold"&gt;Your Add Code&lt;/span&gt;
Click here to copy your Add Code.
Add Code is active only when this panel is open.</property>
<property name="use-markup">True</property>
<property name="justify">center</property>
<property name="track-visited-links">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<!-- n-columns=6 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="valign">center</property>
<property name="margin-start">50</property>
<property name="margin-end">50</property>
<property name="margin-top">25</property>
<property name="margin-bottom">35</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="column-spacing">10</property>
<property name="row-homogeneous">True</property>
<property name="column-homogeneous">True</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">&lt;span size="xx-large" weight="bold"&gt;0&lt;/span&gt;</property>
<property name="use-markup">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">&lt;span size="xx-large" weight="bold"&gt;0&lt;/span&gt;</property>
<property name="use-markup">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">&lt;span size="xx-large" weight="bold"&gt;0&lt;/span&gt;</property>
<property name="use-markup">True</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">&lt;span size="xx-large" weight="bold"&gt;0&lt;/span&gt;</property>
<property name="use-markup">True</property>
</object>
<packing>
<property name="left-attach">3</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">&lt;span size="xx-large" weight="bold"&gt;0&lt;/span&gt;</property>
<property name="use-markup">True</property>
</object>
<packing>
<property name="left-attach">4</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">&lt;span size="xx-large" weight="bold"&gt;0&lt;/span&gt;</property>
<property name="use-markup">True</property>
</object>
<packing>
<property name="left-attach">5</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Show/Hide Add Code</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
@ -232,7 +431,7 @@
<object class="GtkLabel" id="contactTabLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Manage contacts</property>
<property name="tooltip-text" translatable="yes">Manage known devices</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Contacts</property>
</object>
@ -275,20 +474,26 @@
</object>
</child>
<child>
<object class="GtkListBoxRow">
<object class="GtkListBoxRow" id="statusBoxRow">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkLabel" id="connection_status_label">
<object class="GtkEventBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Click to change status</property>
<property name="label" translatable="yes">Online</property>
<property name="justify">center</property>
<property name="track-visited-links">False</property>
<attributes>
<attribute name="foreground" value="#2626a2a26969"/>
</attributes>
<signal name="button-press-event" handler="statusClick" swapped="no"/>
<child>
<object class="GtkLabel" id="connStatusLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Click to change status</property>
<property name="label" translatable="yes">&lt;span foreground="red"&gt;Offline&lt;/span&gt;</property>
<property name="use-markup">True</property>
<property name="justify">center</property>
<property name="track-visited-links">False</property>
</object>
</child>
</object>
</child>
</object>
@ -300,15 +505,14 @@
<property name="label" translatable="yes">Send</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
<property name="receives-default">False</property>
</object>
</child>
<child>
<object class="GtkButton" id="addButton">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="receives-default">True</property>
<property name="receives-default">False</property>
<property name="relief">none</property>
<signal name="clicked" handler="addButtonClick" object="main_window" swapped="no"/>
<child>
@ -366,4 +570,50 @@
</object>
</child>
</object>
<object class="GtkPopover" id="addCodeEntry">
<property name="can-focus">False</property>
<property name="relative-to">addButton</property>
<property name="position">bottom</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin-start">20</property>
<property name="margin-end">20</property>
<property name="margin-top">10</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">&lt;span size="large" weight="bold"&gt;Add a Device&lt;/span&gt;
Use Add Code to add other devices.</property>
<property name="use-markup">True</property>
<property name="justify">center</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="max-length">6</property>
<property name="placeholder-text" translatable="yes">e.g: 123456</property>
<property name="input-purpose">pin</property>
<signal name="key-press-event" handler="addCodeDone" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

300
internal/client/ui.go

@ -9,12 +9,14 @@ import (
"os"
"path/filepath"
"strconv"
"time"
)
const (
appId = "dev.jaeha.coconut"
)
// File tree view index
const (
fileNameIdx = iota
fileSizeWithUnitIdx
@ -23,23 +25,36 @@ const (
fileSizeInBytes
)
// Contact tree view index
const (
keyName = iota
keyDate
keyFingerprint
)
var AssertFailed = errors.New("type assertion failed")
type UIStatus struct {
builder *gtk.Builder
isFileTab bool
fileListOrder []int
fileMap map[string]struct{}
builder *gtk.Builder
isFileTab bool
onlineStatus bool
fileListOrder []int
keyListOrder []int
totalFileSize int64
totalFileCount int
fileMap map[string]struct{}
}
type preprocessing func(string) ([]interface{}, error)
func initUIStatus() (stat *UIStatus) {
return &UIStatus{
builder: nil,
isFileTab: true,
fileListOrder: []int{fileNameIdx, fileSizeWithUnitIdx, fileStatusIdx, fileFullPath, fileSizeInBytes},
fileMap: map[string]struct{}{},
builder: nil,
isFileTab: true,
onlineStatus: false,
fileListOrder: []int{fileNameIdx, fileSizeWithUnitIdx, fileStatusIdx, fileFullPath, fileSizeInBytes},
keyListOrder: []int{keyName, keyDate, keyFingerprint},
totalFileSize: 0,
totalFileCount: 0,
fileMap: map[string]struct{}{},
}
}
@ -76,9 +91,12 @@ func Start(uiGladePath string) {
// Map the handlers to callback functions, and connect the signals
// to the Builder.
signals := map[string]interface{}{
"switchPage": stat.switchPage,
"addButtonClick": stat.addButtonClick,
"keyPress": stat.keyPress,
"switchPage": stat.switchPage,
"addButtonClick": stat.addButtonClick,
"keyPressMainWin": stat.keyPressMainWin,
"statusClick": stat.statusClick,
"addCodeDone": stat.addCodeDone,
"clickEmptySpotFile": stat.clickEmptySpotFile,
}
stat.builder.ConnectSignals(signals)
@ -128,24 +146,118 @@ func (ui *UIStatus) addButtonClick() {
log.Error("Error while getting filenames")
return
}
fileList, err := ui.getListStoreWithId("fileList")
if err != nil {
return
}
treeView, err := ui.getTreeViewWithId("fileListView")
if err != nil {
return
}
addToListStore(fileList, treeView, filenames, ui.fileListOrder, ui.getFileInfo)
ui.addFilesToListStore(filenames)
}
} else {
// Add contacts
ui.showAddCodeEntry()
}
}
func (ui *UIStatus) keyPress(_ *gtk.Window, event *gdk.Event) {
func (ui *UIStatus) statusClick(_ *gtk.EventBox, event *gdk.Event) {
log.Debug("Status label clicked")
eventButton := gdk.EventButtonNewFromEvent(event)
// If user right-clicks the status label
if gdk.BUTTON_PRIMARY == eventButton.Button() {
label, err := ui.getLabelWithId("connStatusLabel")
if err != nil {
return
}
listBoxRow, err := ui.getListBoxRowWithId("statusBoxRow")
if err != nil {
return
}
// Make status label un-clickable
listBoxRow.SetSensitive(false)
log.Debug(ui.onlineStatus)
if ui.onlineStatus {
label.SetMarkup("<span foreground=\"orange\">Disconnecting...</span>")
go func() {
// TODO: Disconnect user from the relay server
time.Sleep(3 * time.Second)
_ = glib.IdleAdd(func() {
label.SetMarkup("<span foreground=\"red\">Offline</span>")
ui.onlineStatus = !ui.onlineStatus
listBoxRow.SetSensitive(true)
})
}()
} else {
label.SetMarkup("<span foreground=\"orange\">Connecting...</span>")
go func() {
// TODO: Connect user to the relay server
time.Sleep(3 * time.Second)
_ = glib.IdleAdd(func() {
label.SetMarkup("<span foreground=\"green\">Online</span>")
ui.onlineStatus = !ui.onlineStatus
listBoxRow.SetSensitive(true)
})
}()
}
}
}
func (ui *UIStatus) showAddCodeEntry() {
log.Debug("showAddCodeEntry called")
popover, err := ui.getPopoverWithId("addCodeEntry")
if err != nil {
return
}
popover.Popup()
}
func (ui *UIStatus) addCodeDone(entry *gtk.Entry, event *gdk.Event) {
log.Debug("addCodeDone called")
eventKey := gdk.EventKeyNewFromEvent(event)
key := eventKey.KeyVal()
if key == gdk.KEY_Return || key == gdk.KEY_KP_Enter {
text, err := entry.GetText()
if err != nil {
return
}
intVal, err := strconv.ParseInt(text, 10, 32)
if err != nil {
// text is not an integer
log.Debug("Not an integer: ", text)
return
}
popover, err := ui.getPopoverWithId("addCodeEntry")
if err != nil {
return
}
popover.Popdown()
entry.SetText("")
// TODO: Get pubkey based on intVal
log.Debug(intVal)
}
}
func (ui *UIStatus) clickEmptySpotFile(_ *gtk.EventBox, event *gdk.Event) {
log.Debug("clickEmptySpotFile called")
eventButton := gdk.EventButtonNewFromEvent(event)
if eventButton.Button() == gdk.BUTTON_PRIMARY {
fileTreeView, err := ui.getTreeViewWithId("fileListView")
if err != nil {
return
}
ui.unselectAll(fileTreeView)
}
}
func (ui *UIStatus) unselectAll(treeView *gtk.TreeView) {
selection, err := treeView.GetSelection()
if err != nil {
log.Debug(err)
log.Error("Error while getting selected files")
}
selection.UnselectAll()
}
func (ui *UIStatus) keyPressMainWin(_ *gtk.Window, event *gdk.Event) {
log.Debug("KeyPress function called")
eventKey := gdk.EventKeyNewFromEvent(event)
// If pressed key is "Delete" key, remove selected files from the list
@ -191,7 +303,7 @@ func (ui *UIStatus) removeSelected() (err error) {
value, err := listStore.GetValue(iter, fileFullPath)
if err != nil {
log.Debug(err)
log.Error("Error while getting value")
log.Error("Error while getting full path from iterator")
return
}
fullPath, err := value.GetString()
@ -201,35 +313,91 @@ func (ui *UIStatus) removeSelected() (err error) {
return
}
log.Debug("Full path: ", fullPath)
value, err = listStore.GetValue(iter, fileSizeInBytes)
if err != nil {
log.Debug(err)
log.Error("Error while getting value from GetValue")
return
}
goValue, err := value.GoValue()
if err != nil {
log.Debug(err)
log.Error("Error while getting value from GoValue")
return
}
size, ok := goValue.(int64)
if !ok {
log.Debug(AssertFailed)
log.Error("Returned value is not int64")
return
}
// Delete from the map as well
delete(ui.fileMap, fullPath)
_ = listStore.Remove(iter)
ui.totalFileSize -= size
ui.totalFileCount -= 1
})
ui.updateInfoBox()
return nil
}
func addToListStore(listStore *gtk.ListStore, treeView *gtk.TreeView, dataToAdd []string, order []int, f preprocessing) {
for i, data := range dataToAdd {
row, err := f(data)
func (ui *UIStatus) updateInfoBox() {
fileCountLabel, err := ui.getLabelWithId("infoFileCount")
if err != nil {
return
}
fileSizeLabel, err := ui.getLabelWithId("infoFileSize")
if err != nil {
return
}
fileCountLabel.SetLabel(strconv.Itoa(ui.totalFileCount))
fileSizeLabel.SetLabel(sizeAddUnit(ui.totalFileSize))
}
func (ui *UIStatus) addFilesToListStore(fileNames []string) {
fileList, err := ui.getListStoreWithId("fileList")
if err != nil {
return
}
treeView, err := ui.getTreeViewWithId("fileListView")
if err != nil {
return
}
for _, fileName := range fileNames {
// Check if elem already exist
if _, exist := ui.fileMap[fileName]; exist {
log.Debug("Element already added; Skipping...")
continue
}
// Add to set
ui.fileMap[fileName] = struct{}{}
// Get file name without path
_, fName := filepath.Split(fileName)
// Get file size
s, err := os.Stat(fileName)
if err != nil {
log.Debug(err)
log.Error("Error while adding element. continuing")
log.Error("Error while getting stats; Skipping...")
continue
}
// Row is empty if the elem is already added
if row != nil {
iter := listStore.Append()
// Show file full path as a tooltip
treeView.SetTooltipColumn(fileFullPath)
if err = listStore.Set(iter, order, row); err != nil {
log.Debug("Error while adding ", dataToAdd[i])
continue
}
} else {
log.Debug("Element already added; Skipping...")
size := s.Size()
row := []interface{}{fName, sizeAddUnit(size), "Pending", fileName, size}
iter := fileList.Append()
// Show file full path as a tooltip
treeView.SetTooltipColumn(fileFullPath)
if err = fileList.Set(iter, ui.fileListOrder, row); err != nil {
log.Debug("Error while adding ", fileName)
continue
}
ui.totalFileSize += size
ui.totalFileCount += 1
}
ui.updateInfoBox()
}
func (ui *UIStatus) getFileInfo(fileName string) ([]interface{}, error) {
@ -257,7 +425,7 @@ func sizeAddUnit(size int64) (sizeStr string) {
} else if size < 1e+9 {
sizeStr = strconv.Itoa(int(size/1e+6)) + " MB"
} else {
sizeStr = strconv.Itoa(int(size/1e+9)) + " MB"
sizeStr = strconv.Itoa(int(size/1e+9)) + " GB"
}
return sizeStr
}
@ -268,6 +436,54 @@ func (ui *UIStatus) switchPage() {
log.Debug(ui.isFileTab)
}
func (ui *UIStatus) getPopoverWithId(popoverId string) (popover *gtk.Popover, err error) {
object, err := ui.builder.GetObject(popoverId)
if err != nil {
log.Debug(err)
log.Errorf("Error while getting popover with popover id: %s", popoverId)
return nil, err
}
popover, ok := object.(*gtk.Popover)
if ok {
return popover, nil
}
log.Debug(AssertFailed)
log.Error("object is not a popover")
return nil, AssertFailed
}
func (ui *UIStatus) getListBoxRowWithId(listBoxRowId string) (listBoxRow *gtk.ListBoxRow, err error) {
object, err := ui.builder.GetObject(listBoxRowId)
if err != nil {
log.Debug(err)
log.Errorf("Error while getting listBoxRow with listBoxRow id: %s", listBoxRowId)
return nil, err
}
listBoxRow, ok := object.(*gtk.ListBoxRow)
if ok {
return listBoxRow, nil
}
log.Debug(AssertFailed)
log.Error("object is not a listBoxRow")
return nil, AssertFailed
}
func (ui *UIStatus) getLabelWithId(labelId string) (label *gtk.Label, err error) {
object, err := ui.builder.GetObject(labelId)
if err != nil {
log.Debug(err)
log.Errorf("Error while getting label with label id: %s", labelId)
return nil, err
}
label, ok := object.(*gtk.Label)
if ok {
return label, nil
}
log.Debug(AssertFailed)
log.Error("object is not a label")
return nil, AssertFailed
}
func (ui *UIStatus) getButtonWithId(buttonId string) (button *gtk.Button, err error) {
object, err := ui.builder.GetObject(buttonId)
if err != nil {

Loading…
Cancel
Save