Commit 09c25bb5 authored by Felipe Borges's avatar Felipe Borges 👣

session, display: Handle disconnection

It also ads the frdp_display_is_open() public API to verify
whether a connection attempt has been made.
parent 1e5faf3e
......@@ -39,6 +39,7 @@ enum
{
RDP_INITIALIZED,
RDP_CONNECTED,
RDP_DISCONNECTED,
LAST_SIGNAL
};
......@@ -47,7 +48,7 @@ static guint signals[LAST_SIGNAL];
static gboolean
frdp_display_is_initialized (FrdpDisplay *self)
{
return self->priv->session != NULL;
return self->priv->session != NULL && frdp_display_is_open (self);
}
static gboolean
......@@ -156,6 +157,17 @@ frdp_display_scroll_event (GtkWidget *widget,
return TRUE;
}
static void
frdp_display_disconnected (GObject *source_object,
gpointer user_data)
{
FrdpDisplay *self = FRDP_DISPLAY (user_data);
g_signal_emit (self, signals[RDP_DISCONNECTED], 0);
g_debug ("rdp disconnected");
}
static void
frdp_display_open_host_cb (GObject *source_object,
GAsyncResult *result,
......@@ -282,6 +294,12 @@ frdp_display_class_init (FrdpDisplayClass *klass)
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
signals[RDP_DISCONNECTED] = g_signal_new ("rdp-disconnected",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
}
static void
......@@ -311,6 +329,10 @@ frdp_display_open_host (FrdpDisplay *self,
self->priv->session = frdp_session_new (self);
g_signal_connect (self->priv->session, "rdp-disconnected",
G_CALLBACK (frdp_display_disconnected),
self);
frdp_session_connect (self->priv->session,
host,
port,
......@@ -321,6 +343,12 @@ frdp_display_open_host (FrdpDisplay *self,
g_signal_emit (self, signals[RDP_INITIALIZED], 0);
}
gboolean
frdp_display_is_open (FrdpDisplay *self)
{
return frdp_session_is_open (self->priv->session);
}
void
frdp_display_set_scaling (FrdpDisplay *self,
gboolean scaling)
......
......@@ -44,6 +44,8 @@ void frdp_display_open_host (FrdpDisplay *display,
const gchar *host,
guint port);
gboolean frdp_display_is_open (FrdpDisplay *display);
void frdp_display_set_scaling (FrdpDisplay *display,
gboolean scaling);
......
......@@ -37,6 +37,8 @@ struct _FrdpSessionPrivate
double scale;
guint update_id;
gboolean is_connected;
};
G_DEFINE_TYPE_WITH_PRIVATE (FrdpSession, frdp_session, G_TYPE_OBJECT)
......@@ -52,6 +54,15 @@ enum
PROP_SCALING
};
enum
{
RDP_CONNECTED,
RDP_DISCONNECTED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
struct frdp_context
{
rdpContext context;
......@@ -276,6 +287,16 @@ frdp_post_connect (freerdp *freerdp_session)
return TRUE;
}
static gboolean
idle_close (gpointer user_data)
{
FrdpSession *self = (FrdpSession*) user_data;
g_signal_emit (self, signals[RDP_DISCONNECTED], 0);
return FALSE;
}
static gboolean
update (gpointer user_data)
{
......@@ -332,6 +353,8 @@ update (gpointer user_data)
}
if (freerdp_shall_disconnect (priv->freerdp_session)) {
g_idle_add ((GSourceFunc) idle_close, self);
return FALSE;
}
......@@ -345,19 +368,20 @@ frdp_session_connect_thread (GTask *task,
GCancellable *cancellable)
{
FrdpSession *self = (FrdpSession*) source_object;
gboolean result;
result = freerdp_connect (self->priv->freerdp_session);
self->priv->is_connected = freerdp_connect (self->priv->freerdp_session);
g_signal_connect (self->priv->display, "draw",
G_CALLBACK (frdp_session_draw), self);
g_signal_connect (self->priv->display, "configure-event",
G_CALLBACK (frdp_session_configure_event), self);
frdp_session_set_scaling (self, TRUE);
if (self->priv->is_connected) {
g_signal_connect (self->priv->display, "draw",
G_CALLBACK (frdp_session_draw), self);
g_signal_connect (self->priv->display, "configure-event",
G_CALLBACK (frdp_session_configure_event), self);
frdp_session_set_scaling (self, TRUE);
self->priv->update_id = g_idle_add ((GSourceFunc) update, self);
self->priv->update_id = g_idle_add ((GSourceFunc) update, self);
}
g_task_return_boolean (task, result);
g_task_return_boolean (task, self->priv->is_connected);
}
static void
......@@ -499,6 +523,12 @@ frdp_session_class_init (FrdpSessionClass *klass)
"scaling",
TRUE,
G_PARAM_READWRITE));
signals[RDP_DISCONNECTED] = g_signal_new ("rdp-disconnected",
FRDP_TYPE_SESSION,
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
}
static void
......@@ -520,6 +550,8 @@ frdp_session_init (FrdpSession *self)
freerdp_context_new (priv->freerdp_session);
((frdpContext *) priv->freerdp_session->context)->self = self;
self->priv->is_connected = FALSE;
}
FrdpSession*
......@@ -561,6 +593,12 @@ frdp_session_connect_finish (FrdpSession *self,
return g_task_propagate_boolean (G_TASK (result), error);
}
gboolean
frdp_session_is_open (FrdpSession *self)
{
return self->priv->is_connected;
}
void
frdp_session_mouse_event (FrdpSession *self,
FrdpMouseEvent event,
......
......@@ -68,6 +68,8 @@ gboolean frdp_session_connect_finish (FrdpSession *self,
GAsyncResult *result,
GError **error);
gboolean frdp_session_is_open (FrdpSession *self);
void frdp_session_mouse_event (FrdpSession *self,
FrdpMouseEvent event,
guint16 x,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment