1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
/*
* Remmina - The GTK+ Remote Desktop Client
* Copyright (C) 2010 Vic Lee
* Copyright (C) 2014-2015 Antenore Gatta, Fabio Castelli, Giovanni Panozzo
* Copyright (C) 2016-2019 Antenore Gatta, Giovanni Panozzo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. * If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. * If you
* do not wish to do so, delete this exception statement from your
* version. * If you delete this exception statement from all source
* files in the program, then also delete it here.
*
*/
#include "common/remmina_plugin.h"
#include <X11/Xlib.h>
#include "nx_plugin.h"
#include "nx_session_manager.h"
static void remmina_nx_session_manager_set_sensitive(RemminaProtocolWidget *gp, gboolean sensitive)
{
TRACE_CALL(__func__);
RemminaPluginNxData *gpdata = GET_PLUGIN_DATA(gp);
if (gpdata->attach_session) {
gtk_dialog_set_response_sensitive(GTK_DIALOG(gpdata->manager_dialog), REMMINA_NX_EVENT_TERMINATE, sensitive);
gtk_dialog_set_response_sensitive(GTK_DIALOG(gpdata->manager_dialog), REMMINA_NX_EVENT_ATTACH, sensitive);
}else {
gtk_dialog_set_response_sensitive(GTK_DIALOG(gpdata->manager_dialog), REMMINA_NX_EVENT_TERMINATE, sensitive);
gtk_dialog_set_response_sensitive(GTK_DIALOG(gpdata->manager_dialog), REMMINA_NX_EVENT_RESTORE, sensitive);
}
}
static gboolean remmina_nx_session_manager_selection_func(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path,
gboolean path_currently_selected, gpointer user_data)
{
TRACE_CALL(__func__);
RemminaProtocolWidget *gp = (RemminaProtocolWidget*)user_data;
RemminaPluginNxData *gpdata = GET_PLUGIN_DATA(gp);
gpdata->manager_selected = FALSE;
if (path_currently_selected) {
remmina_nx_session_manager_set_sensitive(gp, FALSE);
return TRUE;
}
if (!gtk_tree_model_get_iter(model, &gpdata->iter, path))
return TRUE;
gpdata->manager_selected = TRUE;
remmina_nx_session_manager_set_sensitive(gp, TRUE);
return TRUE;
}
static void remmina_nx_session_manager_send_signal(RemminaPluginNxData *gpdata, gint event_type)
{
TRACE_CALL(__func__);
guchar dummy = (guchar)event_type;
/* Signal the NX thread to resume execution */
if (write(gpdata->event_pipe[1], &dummy, 1)) {
}
}
static void remmina_nx_session_manager_on_response(GtkWidget *dialog, gint response_id, RemminaProtocolWidget *gp)
{
TRACE_CALL(__func__);
RemminaPluginNxData *gpdata = GET_PLUGIN_DATA(gp);
gint event_type;
remmina_nx_session_manager_set_sensitive(gp, FALSE);
if (response_id <= 0) {
event_type = REMMINA_NX_EVENT_CANCEL;
}else {
event_type = response_id;
}
if (response_id == REMMINA_NX_EVENT_TERMINATE && gpdata->manager_selected) {
remmina_nx_session_iter_set(gpdata->nx, &gpdata->iter, REMMINA_NX_SESSION_COLUMN_STATUS, _("Terminating"));
}
if (response_id != REMMINA_NX_EVENT_TERMINATE) {
gtk_widget_destroy(dialog);
gpdata->manager_dialog = NULL;
}
if (response_id != REMMINA_NX_EVENT_TERMINATE && response_id != REMMINA_NX_EVENT_CANCEL) {
remmina_plugin_nx_service->protocol_plugin_init_show(gp);
}
remmina_nx_session_manager_send_signal(gpdata, event_type);
}
/* Handle double click on a row in the NX Session manager
* Automatically close the dialog using the default response id */
void remmina_nx_session_manager_on_row_activated(GtkTreeView *tree, GtkTreePath *path, GtkTreeViewColumn *column, RemminaProtocolWidget *gp)
{
TRACE_CALL(__func__);
RemminaPluginNxData *gpdata = GET_PLUGIN_DATA(gp);
remmina_plugin_nx_service->log_printf("[NX] Default response_id %d\n",
gpdata->default_response);
if (gpdata->default_response >= 0) {
gtk_dialog_response(GTK_DIALOG(gpdata->manager_dialog), gpdata->default_response);
}
}
static gboolean remmina_nx_session_manager_main(RemminaProtocolWidget *gp)
{
TRACE_CALL(__func__);
RemminaPluginNxData *gpdata = GET_PLUGIN_DATA(gp);
RemminaFile *remminafile;
GtkWidget *dialog;
gchar *s;
GtkWidget *scrolledwindow;
GtkWidget *tree;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
remminafile = remmina_plugin_nx_service->protocol_plugin_get_file(gp);
gpdata->default_response = -1;
if (!gpdata->manager_started) {
remmina_plugin_nx_service->protocol_plugin_init_hide(gp);
dialog = gtk_dialog_new();
s = g_strdup_printf(_("NX Sessions on %s"), remmina_plugin_nx_service->file_get_string(remminafile, "server"));
gtk_window_set_title(GTK_WINDOW(dialog), s);
g_free(s);
if (gpdata->attach_session) {
gtk_dialog_add_button(GTK_DIALOG(dialog), _("Attach"), REMMINA_NX_EVENT_ATTACH);
/* Set default response id for attach */
gpdata->default_response = REMMINA_NX_EVENT_ATTACH;
}else {
gtk_dialog_add_button(GTK_DIALOG(dialog), _("Restore"), REMMINA_NX_EVENT_RESTORE);
gtk_dialog_add_button(GTK_DIALOG(dialog), _("Start"), REMMINA_NX_EVENT_START);
/* Set default response id for restore */
gpdata->default_response = REMMINA_NX_EVENT_RESTORE;
}
gtk_dialog_add_button(GTK_DIALOG(dialog), _("_Cancel"), REMMINA_NX_EVENT_CANCEL);
gtk_dialog_add_button(GTK_DIALOG(dialog), _("Terminate"), REMMINA_NX_EVENT_TERMINATE);
gtk_window_set_default_size(GTK_WINDOW(dialog), 640, 300);
gpdata->manager_dialog = dialog;
scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
gtk_widget_show(scrolledwindow);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), scrolledwindow, TRUE, TRUE, 0);
tree = gtk_tree_view_new();
gtk_container_add(GTK_CONTAINER(scrolledwindow), tree);
gtk_widget_show(tree);
remmina_nx_session_set_tree_view(gpdata->nx, GTK_TREE_VIEW(tree));
/* Handle double click on the row */
g_signal_connect(G_OBJECT(tree), "row-activated",
G_CALLBACK(remmina_nx_session_manager_on_row_activated), gp);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("#", renderer, "text", REMMINA_NX_SESSION_COLUMN_ID, NULL);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sort_column_id(column, REMMINA_NX_SESSION_COLUMN_ID);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes(_("Type"), renderer, "text", REMMINA_NX_SESSION_COLUMN_TYPE,
NULL);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sort_column_id(column, REMMINA_NX_SESSION_COLUMN_TYPE);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes(_("Display"), renderer, "text",
REMMINA_NX_SESSION_COLUMN_DISPLAY, NULL);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sort_column_id(column, REMMINA_NX_SESSION_COLUMN_DISPLAY);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes(_("Status"), renderer, "text",
REMMINA_NX_SESSION_COLUMN_STATUS, NULL);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sort_column_id(column, REMMINA_NX_SESSION_COLUMN_STATUS);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes(_("Name"), renderer, "text", REMMINA_NX_SESSION_COLUMN_NAME,
NULL);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sort_column_id(column, REMMINA_NX_SESSION_COLUMN_NAME);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)),
remmina_nx_session_manager_selection_func, gp, NULL);
g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(remmina_nx_session_manager_on_response), gp);
gpdata->manager_started = TRUE;
}
gpdata->manager_selected = FALSE;
if (gpdata->manager_dialog) {
remmina_nx_session_manager_set_sensitive(gp, FALSE);
gtk_widget_show(gpdata->manager_dialog);
}
if (remmina_nx_session_has_error(gpdata->nx)) {
dialog = gtk_message_dialog_new((gpdata->manager_dialog ? GTK_WINDOW(gpdata->manager_dialog) : NULL),
GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s",
remmina_nx_session_get_error(gpdata->nx));
remmina_nx_session_clear_error(gpdata->nx);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
remmina_nx_session_manager_send_signal(gpdata, 0);
}
gpdata->session_manager_start_handler = 0;
return FALSE;
}
void remmina_nx_session_manager_start(RemminaProtocolWidget *gp)
{
TRACE_CALL(__func__);
RemminaPluginNxData *gpdata = GET_PLUGIN_DATA(gp);
if (gpdata->session_manager_start_handler == 0) {
gpdata->session_manager_start_handler = IDLE_ADD((GSourceFunc)remmina_nx_session_manager_main, gp);
}
}
|