Refactor login usage.

- factor out the signal tracking code as a helper class,
- move login logic from MainWindow to LoginWidget,
- add new signals to the LoginWidget to interact with MainWindow,
- add login sequence docs to LoginWidget class,
- improve docs for login methods,
- add LoginState class to handle login states.