about summary refs log tree commit diff stats
path: root/go.sum
Commit message (Expand)AuthorAgeFilesLines
* Fix special characters in address.PersonalNameDrew DeVault2019-05-251-0/+2
* Update go-imap and go-imap-idleSimon Ser2019-05-191-14/+11
* Implement :reply -q and :reply -aDrew DeVault2019-05-161-0/+2
* Implement (basic form) of :replyDrew DeVault2019-05-161-0/+2
* Copy sent emails to the Sent folderDrew DeVault2019-05-151-0/+2
* Implement sending emails /o/Drew DeVault2019-05-141-0/+2
* Add :send-message, prepares & writes email to /tmpDrew DeVault2019-05-141-0/+5
* Update go-imap to 1.0.0-beta.4Simon Ser2019-04-291-38/+22
* go get git.sr.ht/~sircmpwn/go-libvtermElias Naur2019-04-211-0/+2
* Add basic filter implementationDrew DeVault2019-03-311-0/+6
* Implement :pipeDrew DeVault2019-03-301-0/+2
* Add body fetching support codeDrew DeVault2019-03-291-0/+4
* Improve cursor handling in embedded terminalDrew DeVault2019-03-211-0/+6
* Fix cursor handling in embedded terminalDrew DeVault2019-03-211-0/+2
* Forward key events to child terminalDrew DeVault2019-03-211-0/+4
* Handle terminal title, login shellDrew DeVault2019-03-171-0/+11
* Add basic terminal widgetDrew DeVault2019-03-171-0/+10
* Rename :cd -> :cf, add :cdDrew DeVault2019-03-151-0/+2
* Implement key bindings subsystemDrew DeVault2019-03-151-0/+9
* Flesh out command parsing & handlingDrew DeVault2019-03-101-0/+2
* Add missing go.sum entriesElias Naur2019-02-101-0/+6
* Initialize worker in account widgetDrew DeVault2019-01-131-0/+6
* Add basic account widget, populate real acct viewsDrew DeVault2019-01-131-0/+11
='#n36'>36 37 38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89


               

             

                                          

                                                




                                          
                                
                                        
                                  


                                               





                                                                          











                                                             





































                                                                     












                                                                         
package widgets

import (
	"log"

	"git.sr.ht/~sircmpwn/aerc2/config"
	"git.sr.ht/~sircmpwn/aerc2/lib/ui"
	"git.sr.ht/~sircmpwn/aerc2/worker"
	"git.sr.ht/~sircmpwn/aerc2/worker/types"
)

type AccountView struct {
	conf         *config.AccountConfig
	grid         *ui.Grid
	logger       *log.Logger
	onInvalidate func(d ui.Drawable)
	worker       *types.Worker
}

func NewAccountView(conf *config.AccountConfig,
	logger *log.Logger, statusbar ui.Drawable) (*AccountView, error) {

	worker, err := worker.NewWorker(conf.Source, logger)
	if err != nil {
		return nil, err
	}

	grid := ui.NewGrid().Rows([]ui.GridSpec{
		{ui.SIZE_WEIGHT, 1},
		{ui.SIZE_EXACT, 1},
	}).Columns([]ui.GridSpec{
		{ui.SIZE_EXACT, 20},
		{ui.SIZE_WEIGHT, 1},
	})
	grid.AddChild(ui.NewBordered(
		ui.NewFill('s'), ui.BORDER_RIGHT)).Span(2, 1)
	grid.AddChild(ui.NewFill('.')).At(0, 1)
	grid.AddChild(statusbar).At(1, 1)

	acct := &AccountView{
		conf:   conf,
		grid:   grid,
		logger: logger,
		worker: worker,
	}

	go worker.Backend.Run()
	go func() {
		for {
			msg := <-worker.Messages
			msg = worker.ProcessMessage(msg)
			// TODO: dispatch to appropriate handlers
		}
	}()

	worker.PostAction(&types.Configure{Config: conf}, nil)
	worker.PostAction(&types.Connect{}, acct.connected)

	return acct, nil
}

func (acct *AccountView) connected(msg types.WorkerMessage) {
	switch msg := msg.(type) {
	case *types.Done:
		acct.logger.Println("Connected.")
		acct.worker.PostAction(&types.ListDirectories{}, nil)
	case *types.CertificateApprovalRequest:
		// TODO: Ask the user
		acct.logger.Println("Approving certificate")
		acct.worker.PostAction(&types.ApproveCertificate{
			Message:  types.RespondTo(msg),
			Approved: true,
		}, acct.connected)
	default:
		acct.logger.Println("Connection failed.")
	}
}

func (acct *AccountView) OnInvalidate(onInvalidate func(d ui.Drawable)) {
	acct.grid.OnInvalidate(onInvalidate)
}

func (acct *AccountView) Invalidate() {
	acct.grid.Invalidate()
}

func (acct *AccountView) Draw(ctx *ui.Context) {
	acct.grid.Draw(ctx)
}