Debian Codegraph @

ui/syncing-modal.go

raw symbols SCIP
1 // gomuks - A terminal Matrix client written in Go.
2 // Copyright (C) 2020 Tulir Asokan
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
13 //
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17 package ui
18
19 import (
20 "time"
21
22 "go.mau.fi/mauview"
23 )
24
25 type SyncingModal struct {
26 parent *MainView
27 text *mauview.TextView
28 progress *mauview.ProgressBar
29 }
30
31 func NewSyncingModal(parent *MainView) (mauview.Component, *SyncingModal) {
32 sm := &SyncingModal{
33 parent: parent,
34 progress: mauview.NewProgressBar(),
35 text: mauview.NewTextView(),
36 }
37 return mauview.Center(
38 mauview.NewBox(
39 mauview.NewFlex().
40 SetDirection(mauview.FlexRow).
41 AddFixedComponent(sm.progress, 1).
42 AddFixedComponent(mauview.Center(sm.text, 40, 1), 1)).
43 SetTitle("Synchronizing"),
44 42, 4).
45 SetAlwaysFocusChild(true), sm
46 }
47
48 func (sm *SyncingModal) SetMessage(text string) {
49 sm.text.SetText(text)
50 }
51
52 func (sm *SyncingModal) SetIndeterminate() {
53 sm.progress.SetIndeterminate(true)
54 sm.parent.parent.app.SetRedrawTicker(100 * time.Millisecond)
55 sm.parent.parent.app.Redraw()
56 }
57
58 func (sm *SyncingModal) SetSteps(max int) {
59 sm.progress.SetMax(max)
60 sm.progress.SetIndeterminate(false)
61 sm.parent.parent.app.SetRedrawTicker(1 * time.Minute)
62 sm.parent.parent.Render()
63 }
64
65 func (sm *SyncingModal) Step() {
66 sm.progress.Increment(1)
67 }
68
69 func (sm *SyncingModal) Close() {
70 sm.parent.HideModal()
71 }