Use m_netcon->deleteLater() to avoid use-after-free

Net_Connection::socketError() emits disconnected(), which causes
MainWindow::ClientStatusChanged() to invoke NJClient::Disconnect().
Since socketError() invokes Kill() after emitting disconnected() we
should postpone deleting m_netcon.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Use public status codes in NJClient

NJClient::GetStatus() reports public status codes while the m_status field uses
a different set of numeric literals with the same meaning.

The following table shows how the numeric and public status codes relate:

m_status NJC                     Comment
-1       NJC_STATUS_PRECONNECT   Initial state
0        NJC_STATUS_PRECONNECT   Connecting
1000     NJC_STATUS_CANTCONNECT  Error connecting to remote host
1001     NJC_STATUS_INVALIDAUTH  Auth failure or proto version mismatch
1002     NJC_STATUS_DISCONNECTED Unexpected disconnect
*        NJC_STATUS_OK           Auth success

This patch switches m_status over to the public status codes.  This makes
NJClient easier to understand.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Simplify NJClient status state machine

The NJClient m_status and m_in_auth fields together form a state
machine.  Get rid of m_in_auth and make the states explicit in m_status.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Add connecting state to MainWindow state machine

Keep track of when the client is connecting to the server.  During this
time it is possible to disconnect.

This fixes a bug where it is possible to connect to a new jam session
when the client is already connecting.  When this happens the audio
stream is opened twice and the metronome runs at double speed!

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Add reconnect with exponential back-off

If the server cannot be reached immediately it may be a transient
network error.  Try to reconnect after 3 seconds.  If that fails, try a
few more times with longer wait times each iteration.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>