Commit 77b988bc authored by Giovanni Panozzo's avatar Giovanni Panozzo Committed by GitHub

Merge pull request #1219 from FreeRDP/exit_strategy

Fixes for the exit strategy
parents 89009c8d 329330ef
......@@ -68,9 +68,10 @@ G_DEFINE_TYPE( RemminaConnectionWindow, remmina_connection_window, GTK_TYPE_WIND
#define FLOATING_TOOLBAR_WIDGET (GTK_CHECK_VERSION(3, 10, 0))
typedef struct _RemminaConnectionHolder RemminaConnectionHolder;
typedef struct _RemminaConnectionHolder RemminaConnectionHolder;
struct _RemminaConnectionWindowPriv
struct _RemminaConnectionWindowPriv
{
RemminaConnectionHolder* cnnhld;
......@@ -122,6 +123,8 @@ G_DEFINE_TYPE( RemminaConnectionWindow, remmina_connection_window, GTK_TYPE_WIND
gboolean kbcaptured;
gboolean mouse_pointer_entered;
RemminaConnectionWindowOnDeleteConfirmMode on_delete_confirm_mode;
};
typedef struct _RemminaConnectionObject
......@@ -416,16 +419,18 @@ gboolean remmina_connection_window_delete(RemminaConnectionWindow* cnnwin)
if (!REMMINA_IS_CONNECTION_WINDOW(cnnwin))
return TRUE;
n = gtk_notebook_get_n_pages(notebook);
if (n > 1)
{
dialog = gtk_message_dialog_new(GTK_WINDOW(cnnwin), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
_("There are %i active connections in the current window. Are you sure to close?"), n);
i = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
if (i != GTK_RESPONSE_YES)
return FALSE;
if (cnnwin->priv->on_delete_confirm_mode != REMMINA_CONNECTION_WINDOW_ONDELETE_NOCONFIRM) {
n = gtk_notebook_get_n_pages(notebook);
if (n > 1)
{
dialog = gtk_message_dialog_new(GTK_WINDOW(cnnwin), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
_("There are %i active connections in the current window. Are you sure to close?"), n);
i = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
if (i != GTK_RESPONSE_YES)
return FALSE;
}
}
remmina_connection_window_close_all_connections(cnnwin);
......@@ -2490,6 +2495,7 @@ remmina_connection_window_new_from_holder(RemminaConnectionHolder* cnnhld)
cnnwin = REMMINA_CONNECTION_WINDOW(g_object_new(REMMINA_TYPE_CONNECTION_WINDOW, NULL));
cnnwin->priv->cnnhld = cnnhld;
cnnwin->priv->on_delete_confirm_mode = REMMINA_CONNECTION_WINDOW_ONDELETE_CONFIRM_IF_2_OR_MORE;
g_signal_connect(G_OBJECT(cnnwin), "delete-event", G_CALLBACK(remmina_connection_window_delete_event), cnnhld);
g_signal_connect(G_OBJECT(cnnwin), "destroy", G_CALLBACK(remmina_connection_window_destroy), cnnhld);
......@@ -3578,7 +3584,7 @@ static void remmina_connection_object_on_connect(RemminaProtocolWidget* gp, Remm
static void cb_autoclose_widget(GtkWidget *widget)
{
gtk_widget_destroy(widget);
remmina_application_cond_exitremmina();
remmina_application_condexit(REMMINA_CONDEXIT_ONDISCONNECT);
}
static void remmina_connection_object_on_disconnect(RemminaProtocolWidget* gp, RemminaConnectionObject* cnnobj)
......@@ -3630,7 +3636,7 @@ static void remmina_connection_object_on_disconnect(RemminaProtocolWidget* gp, R
cnnobj->remmina_file = NULL;
g_free(cnnobj);
remmina_application_cond_exitremmina();
remmina_application_condexit(REMMINA_CONDEXIT_ONDISCONNECT);
}
static void remmina_connection_object_on_desktop_resize(RemminaProtocolWidget* gp, RemminaConnectionObject* cnnobj)
......@@ -3744,5 +3750,12 @@ remmina_connection_window_open_from_file_full(RemminaFile* remminafile, GCallbac
remmina_protocol_widget_open_connection(REMMINA_PROTOCOL_WIDGET(cnnobj->proto), remminafile);
return protocolwidget;
}
void remmina_connection_window_set_delete_confirm_mode(RemminaConnectionWindow* cnnwin, RemminaConnectionWindowOnDeleteConfirmMode mode)
{
cnnwin->priv->on_delete_confirm_mode = mode;
}
......@@ -52,7 +52,6 @@ typedef struct _RemminaConnectionWindowPriv RemminaConnectionWindowPriv;
typedef struct _RemminaConnectionWindow
{
GtkWindow window;
RemminaConnectionWindowPriv* priv;
} RemminaConnectionWindow;
......@@ -62,6 +61,12 @@ typedef struct _RemminaConnectionWindowClass
void (*toolbar_place)(RemminaConnectionWindow *gp);
} RemminaConnectionWindowClass;
typedef enum {
REMMINA_CONNECTION_WINDOW_ONDELETE_CONFIRM_IF_2_OR_MORE = 0,
REMMINA_CONNECTION_WINDOW_ONDELETE_NOCONFIRM = 1
} RemminaConnectionWindowOnDeleteConfirmMode;
GType remmina_connection_window_get_type(void)
G_GNUC_CONST;
......@@ -70,6 +75,7 @@ gboolean remmina_connection_window_open_from_filename(const gchar* filename);
/* Open a new connection window for a given RemminaFile struct. The struct will be freed after the call */
void remmina_connection_window_open_from_file(RemminaFile* remminafile);
gboolean remmina_connection_window_delete(RemminaConnectionWindow* cnnwin);
void remmina_connection_window_set_delete_confirm_mode(RemminaConnectionWindow* cnnwin, RemminaConnectionWindowOnDeleteConfirmMode mode);
GtkWidget* remmina_connection_window_open_from_file_full(RemminaFile* remminafile, GCallback disconnect_cb, gpointer data,
guint* handler);
......
......@@ -84,7 +84,19 @@ void remmina_exec_exitremmina()
g_application_quit(g_application_get_default());
}
void remmina_application_cond_exitremmina()
static gboolean disable_remmina_connection_window_delete_confirm_cb(GtkWidget *widget, gpointer data)
{
TRACE_CALL("disable_remmina_connection_window_delete_confirm_cb");
RemminaConnectionWindow *rcw;
if (REMMINA_IS_CONNECTION_WINDOW(widget)) {
rcw = (RemminaConnectionWindow*)widget;
remmina_connection_window_set_delete_confirm_mode(rcw, REMMINA_CONNECTION_WINDOW_ONDELETE_NOCONFIRM);
}
return TRUE;
}
void remmina_application_condexit(RemminaCondExitType why)
{
TRACE_CALL("remmina_application_check_exitremmina");
......@@ -92,9 +104,23 @@ void remmina_application_cond_exitremmina()
* no main window, no systray menu, no connection window.
* This function is usually called after a disconnection */
if (remmina_widget_pool_count() < 1 && !remmina_main_get_window() && !remmina_icon_is_available())
{
remmina_exec_exitremmina();
switch(why) {
case REMMINA_CONDEXIT_ONDISCONNECT:
// A connection has disconnected, should we exit remmina ?
if (remmina_widget_pool_count() < 1 && !remmina_main_get_window() && !remmina_icon_is_available())
remmina_exec_exitremmina();
break;
case REMMINA_CONDEXIT_ONMAINWINDELETE:
// Main window has been deleted
if (remmina_widget_pool_count() < 1 && !remmina_icon_is_available())
remmina_exec_exitremmina();
break;
case REMMINA_CONDEXIT_ONQUIT:
// Quit command has been sent from main window or appindicator/systray menu
// quit means QUIT.
remmina_widget_pool_foreach(disable_remmina_connection_window_delete_confirm_cb, NULL);
remmina_exec_exitremmina();
break;
}
}
......@@ -220,6 +246,7 @@ void remmina_exec_command(RemminaCommandType command, const gchar* data)
break;
case REMMINA_COMMAND_EXIT:
remmina_widget_pool_foreach(disable_remmina_connection_window_delete_confirm_cb, NULL);
remmina_exec_exitremmina();
break;
......
......@@ -52,9 +52,16 @@ typedef enum
REMMINA_COMMAND_EXIT = 10
} RemminaCommandType;
typedef enum
{
REMMINA_CONDEXIT_ONDISCONNECT = 0,
REMMINA_CONDEXIT_ONQUIT = 1,
REMMINA_CONDEXIT_ONMAINWINDELETE = 2
} RemminaCondExitType;
void remmina_exec_command(RemminaCommandType command, const gchar* data);
void remmina_exec_exitremmina(void);
void remmina_application_cond_exitremmina(void);
void remmina_application_condexit(RemminaCondExitType why);
G_END_DECLS
......
......@@ -134,8 +134,9 @@ static void remmina_main_save_before_destroy()
static gboolean remmina_main_dexit(gpointer data)
{
/* Try to exit remmina after a delete window event */
TRACE_CALL("remmina_main_dexit");
remmina_application_cond_exitremmina();
remmina_application_condexit(REMMINA_CONDEXIT_ONMAINWINDELETE);
return FALSE;
}
......@@ -144,11 +145,10 @@ gboolean remmina_main_on_delete_event(GtkWidget *widget, GdkEvent *event, gpoint
TRACE_CALL("remmina_main_on_delete_event");
remmina_main_save_before_destroy();
/* Exit immediately if there is no systray icon */
if (!remmina_icon_is_available()) {
remminamain->window = NULL;
g_idle_add(remmina_main_dexit, NULL);
}
// Forget the main window: it has been deleted
remminamain->window = NULL;
g_idle_add(remmina_main_dexit, NULL);
return FALSE;
}
......@@ -736,8 +736,9 @@ void remmina_main_on_action_application_preferences(GtkAction *action, gpointer
void remmina_main_on_action_application_quit(GtkAction *action, gpointer user_data)
{
// Called by quit signal in remmina_main.glade
TRACE_CALL("remmina_main_on_action_application_quit");
g_idle_add(remmina_main_dexit, NULL);
remmina_application_condexit(REMMINA_CONDEXIT_ONQUIT);
}
void remmina_main_on_action_view_statusbar(GtkToggleAction *action, gpointer user_data)
......
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