| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: (C) 2012 Red Hat, Inc. (www.redhat.com) |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "evolution-ews-config.h" |
| 7 |
|
| 8 |
#include <string.h> |
| 9 |
#include <unistd.h> |
| 10 |
#include <glib/gi18n-lib.h> |
| 11 |
|
| 12 |
#include <gtk/gtk.h> |
| 13 |
#include <libedataserver/libedataserver.h> |
| 14 |
#include <libedataserverui/libedataserverui.h> |
| 15 |
|
| 16 |
#include <e-util/e-util.h> |
| 17 |
#include <mail/em-folder-tree.h> |
| 18 |
#include <mail/em-folder-utils.h> |
| 19 |
#include <libemail-engine/libemail-engine.h> |
| 20 |
#include <shell/e-shell.h> |
| 21 |
#include <shell/e-shell-sidebar.h> |
| 22 |
#include <shell/e-shell-view.h> |
| 23 |
#include <shell/e-shell-window.h> |
| 24 |
|
| 25 |
#include "common/e-ews-connection.h" |
| 26 |
#include "common/e-ews-connection-utils.h" |
| 27 |
#include "common/e-source-ews-folder.h" |
| 28 |
|
| 29 |
#include "e-ews-edit-folder-permissions.h" |
| 30 |
|
| 31 |
#include "camel/camel-ews-store.h" |
| 32 |
#include "camel/camel-ews-store-summary.h" |
| 33 |
|
| 34 |
#include "e-ews-config-utils.h" |
| 35 |
#include "e-ews-search-user.h" |
| 36 |
#include "e-ews-subscribe-foreign-folder.h" |
| 37 |
|
| 38 |
struct RunWithFeedbackData |
| 39 |
{ |
| 40 |
GtkWindow *parent; |
| 41 |
GtkWidget *dialog; |
| 42 |
GCancellable *cancellable; |
| 43 |
GObject *with_object; |
| 44 |
EEwsSetupFunc thread_func; |
| 45 |
EEwsSetupFunc idle_func; |
| 46 |
EEwsSetupFunc finish_idle_func; |
| 47 |
gpointer user_data; |
| 48 |
GDestroyNotify free_user_data; |
| 49 |
GError *error; |
| 50 |
gboolean run_modal; |
| 51 |
}; |
| 52 |
|
| 53 |
static void |
| 54 |
free_run_with_feedback_data (gpointer ptr) |
| 55 |
{ |
| 56 |
struct RunWithFeedbackData *rfd = ptr; |
| 57 |
|
| 58 |
if (!rfd) |
| 59 |
return; |
| 60 |
|
| 61 |
if (rfd->dialog) |
| 62 |
gtk_widget_destroy (rfd->dialog); |
| 63 |
|
| 64 |
g_object_unref (rfd->cancellable); |
| 65 |
g_object_unref (rfd->with_object); |
| 66 |
|
| 67 |
if (rfd->free_user_data) |
| 68 |
rfd->free_user_data (rfd->user_data); |
| 69 |
|
| 70 |
g_clear_error (&rfd->error); |
| 71 |
|
| 72 |
g_slice_free (struct RunWithFeedbackData, rfd); |
| 73 |
} |
| 74 |
|
| 75 |
static gboolean |
| 76 |
run_with_feedback_idle (gpointer user_data) |
| 77 |
{ |
| 78 |
struct RunWithFeedbackData *rfd = user_data; |
| 79 |
gboolean was_cancelled = FALSE; |
| 80 |
|
| 81 |
g_return_val_if_fail (rfd != NULL, FALSE); |
| 82 |
|
| 83 |
if (!g_cancellable_is_cancelled (rfd->cancellable)) { |
| 84 |
if (rfd->idle_func && !rfd->error) |
| 85 |
rfd->idle_func (rfd->with_object, rfd->user_data, rfd->cancellable, &rfd->error); |
| 86 |
|
| 87 |
was_cancelled = g_cancellable_is_cancelled (rfd->cancellable); |
| 88 |
|
| 89 |
if (rfd->dialog) { |
| 90 |
gtk_widget_destroy (rfd->dialog); |
| 91 |
rfd->dialog = NULL; |
| 92 |
} |
| 93 |
} else { |
| 94 |
was_cancelled = TRUE; |
| 95 |
} |
| 96 |
|
| 97 |
if (rfd->finish_idle_func) |
| 98 |
rfd->finish_idle_func (rfd->with_object, rfd->user_data, rfd->cancellable, &rfd->error); |
| 99 |
|
| 100 |
if (!was_cancelled) { |
| 101 |
if (rfd->error) { |
| 102 |
g_dbus_error_strip_remote_error (rfd->error); |
| 103 |
|
| 104 |
e_notice (rfd->parent, GTK_MESSAGE_ERROR, "%s", rfd->error->message); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
free_run_with_feedback_data (rfd); |
| 109 |
|
| 110 |
return FALSE; |
| 111 |
} |
| 112 |
|
| 113 |
static gpointer |
| 114 |
run_with_feedback_thread (gpointer user_data) |
| 115 |
{ |
| 116 |
struct RunWithFeedbackData *rfd = user_data; |
| 117 |
|
| 118 |
g_return_val_if_fail (rfd != NULL, NULL); |
| 119 |
g_return_val_if_fail (rfd->thread_func != NULL, NULL); |
| 120 |
|
| 121 |
if (!g_cancellable_is_cancelled (rfd->cancellable)) |
| 122 |
rfd->thread_func (rfd->with_object, rfd->user_data, rfd->cancellable, &rfd->error); |
| 123 |
|
| 124 |
g_idle_add (run_with_feedback_idle, rfd); |
| 125 |
|
| 126 |
return NULL; |
| 127 |
} |
| 128 |
|
| 129 |
static void |
| 130 |
run_with_feedback_response_cb (GtkWidget *dialog, |
| 131 |
gint resonse_id, |
| 132 |
struct RunWithFeedbackData *rfd) |
| 133 |
{ |
| 134 |
g_return_if_fail (rfd != NULL); |
| 135 |
|
| 136 |
rfd->dialog = NULL; |
| 137 |
|
| 138 |
g_cancellable_cancel (rfd->cancellable); |
| 139 |
|
| 140 |
gtk_widget_destroy (dialog); |
| 141 |
} |
| 142 |
|
| 143 |
static void |
| 144 |
e_ews_config_utils_run_in_thread_with_feedback_general (GtkWindow *parent, |
| 145 |
GObject *with_object, |
| 146 |
const gchar *description, |
| 147 |
EEwsSetupFunc thread_func, |
| 148 |
EEwsSetupFunc idle_func, |
| 149 |
gpointer user_data, |
| 150 |
GDestroyNotify free_user_data, |
| 151 |
gboolean run_modal) |
| 152 |
{ |
| 153 |
GtkWidget *dialog, *label, *content, *spinner, *box; |
| 154 |
struct RunWithFeedbackData *rfd; |
| 155 |
|
| 156 |
g_return_if_fail (with_object != NULL); |
| 157 |
g_return_if_fail (description != NULL); |
| 158 |
g_return_if_fail (thread_func != NULL); |
| 159 |
|
| 160 |
dialog = gtk_dialog_new_with_buttons ( |
| 161 |
"", |
| 162 |
parent, |
| 163 |
GTK_DIALOG_MODAL, |
| 164 |
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
| 165 |
NULL); |
| 166 |
|
| 167 |
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); |
| 168 |
|
| 169 |
spinner = e_spinner_new (); |
| 170 |
e_spinner_start (E_SPINNER (spinner)); |
| 171 |
gtk_box_pack_start (GTK_BOX (box), spinner, FALSE, FALSE, 0); |
| 172 |
|
| 173 |
label = gtk_label_new (description); |
| 174 |
gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0); |
| 175 |
|
| 176 |
gtk_widget_show_all (box); |
| 177 |
|
| 178 |
content = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); |
| 179 |
|
| 180 |
gtk_container_add (GTK_CONTAINER (content), box); |
| 181 |
gtk_container_set_border_width (GTK_CONTAINER (content), 12); |
| 182 |
|
| 183 |
rfd = g_slice_new0 (struct RunWithFeedbackData); |
| 184 |
rfd->parent = parent; |
| 185 |
rfd->dialog = dialog; |
| 186 |
rfd->cancellable = g_cancellable_new (); |
| 187 |
rfd->with_object = g_object_ref (with_object); |
| 188 |
rfd->thread_func = thread_func; |
| 189 |
rfd->idle_func = idle_func; |
| 190 |
rfd->finish_idle_func = NULL; |
| 191 |
rfd->user_data = user_data; |
| 192 |
rfd->free_user_data = free_user_data; |
| 193 |
rfd->error = NULL; |
| 194 |
rfd->run_modal = run_modal; |
| 195 |
|
| 196 |
g_signal_connect (dialog, "response", G_CALLBACK (run_with_feedback_response_cb), rfd); |
| 197 |
|
| 198 |
if (run_modal) { |
| 199 |
GThread *thread; |
| 200 |
GCancellable *cancellable; |
| 201 |
|
| 202 |
cancellable = g_object_ref (rfd->cancellable); |
| 203 |
|
| 204 |
thread = g_thread_new (NULL, run_with_feedback_thread, rfd); |
| 205 |
g_thread_unref (thread); |
| 206 |
|
| 207 |
gtk_dialog_run (GTK_DIALOG (dialog)); |
| 208 |
|
| 209 |
g_cancellable_cancel (cancellable); |
| 210 |
g_object_unref (cancellable); |
| 211 |
} else { |
| 212 |
GThread *thread; |
| 213 |
|
| 214 |
gtk_widget_show (dialog); |
| 215 |
|
| 216 |
thread = g_thread_new (NULL, run_with_feedback_thread, rfd); |
| 217 |
g_thread_unref (thread); |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
void |
| 222 |
e_ews_config_utils_run_in_thread_with_feedback (GtkWindow *parent, |
| 223 |
GObject *with_object, |
| 224 |
const gchar *description, |
| 225 |
EEwsSetupFunc thread_func, |
| 226 |
EEwsSetupFunc idle_func, |
| 227 |
gpointer user_data, |
| 228 |
GDestroyNotify free_user_data) |
| 229 |
{ |
| 230 |
e_ews_config_utils_run_in_thread_with_feedback_general (parent, with_object, description, thread_func, idle_func, user_data, free_user_data, FALSE); |
| 231 |
} |
| 232 |
|
| 233 |
void |
| 234 |
e_ews_config_utils_run_in_thread_with_feedback_modal (GtkWindow *parent, |
| 235 |
GObject *with_object, |
| 236 |
const gchar *description, |
| 237 |
EEwsSetupFunc thread_func, |
| 238 |
EEwsSetupFunc idle_func, |
| 239 |
gpointer user_data, |
| 240 |
GDestroyNotify free_user_data) |
| 241 |
{ |
| 242 |
e_ews_config_utils_run_in_thread_with_feedback_general (parent, with_object, description, thread_func, idle_func, user_data, free_user_data, TRUE); |
| 243 |
} |
| 244 |
|
| 245 |
void |
| 246 |
e_ews_config_utils_run_in_thread (GObject *with_object, |
| 247 |
EEwsSetupFunc thread_func, |
| 248 |
EEwsSetupFunc idle_func, |
| 249 |
gpointer user_data, |
| 250 |
GDestroyNotify free_user_data, |
| 251 |
GCancellable *cancellable) |
| 252 |
{ |
| 253 |
struct RunWithFeedbackData *rfd; |
| 254 |
GThread *thread; |
| 255 |
|
| 256 |
g_return_if_fail (with_object != NULL); |
| 257 |
g_return_if_fail (thread_func != NULL); |
| 258 |
|
| 259 |
rfd = g_slice_new0 (struct RunWithFeedbackData); |
| 260 |
rfd->parent = NULL; |
| 261 |
rfd->dialog = NULL; |
| 262 |
rfd->cancellable = cancellable ? g_object_ref (cancellable) : g_cancellable_new (); |
| 263 |
rfd->with_object = g_object_ref (with_object); |
| 264 |
rfd->thread_func = thread_func; |
| 265 |
rfd->idle_func = NULL; |
| 266 |
rfd->finish_idle_func = idle_func; |
| 267 |
rfd->user_data = user_data; |
| 268 |
rfd->free_user_data = free_user_data; |
| 269 |
rfd->error = NULL; |
| 270 |
rfd->run_modal = FALSE; |
| 271 |
|
| 272 |
thread = g_thread_new (NULL, run_with_feedback_thread, rfd); |
| 273 |
g_thread_unref (thread); |
| 274 |
} |
| 275 |
|
| 276 |
typedef struct _TryCredentialsData { |
| 277 |
CamelEwsSettings *ews_settings; |
| 278 |
const gchar *connect_url; |
| 279 |
EEwsConfigUtilTryCredentialsFunc try_credentials_func; |
| 280 |
gpointer user_data; |
| 281 |
EEwsConnection *conn; |
| 282 |
} TryCredentialsData; |
| 283 |
|
| 284 |
static gboolean |
| 285 |
ews_config_utils_try_credentials_sync (ECredentialsPrompter *prompter, |
| 286 |
ESource *source, |
| 287 |
const ENamedParameters *credentials, |
| 288 |
gboolean *out_authenticated, |
| 289 |
gpointer user_data, |
| 290 |
GCancellable *cancellable, |
| 291 |
GError **error) |
| 292 |
{ |
| 293 |
TryCredentialsData *data = user_data; |
| 294 |
ESourceAuthenticationResult auth_result; |
| 295 |
gchar *hosturl; |
| 296 |
gboolean res = TRUE; |
| 297 |
|
| 298 |
hosturl = camel_ews_settings_dup_hosturl (data->ews_settings); |
| 299 |
data->conn = e_ews_connection_new (source, data->connect_url ? data->connect_url : hosturl, data->ews_settings); |
| 300 |
g_free (hosturl); |
| 301 |
|
| 302 |
e_ews_connection_update_credentials (data->conn, credentials); |
| 303 |
|
| 304 |
if (data->try_credentials_func) |
| 305 |
auth_result = data->try_credentials_func (data->conn, credentials, data->user_data, cancellable, error); |
| 306 |
else |
| 307 |
auth_result = e_ews_connection_try_credentials_sync (data->conn, credentials, NULL, NULL, NULL, cancellable, error); |
| 308 |
|
| 309 |
if (auth_result == E_SOURCE_AUTHENTICATION_ACCEPTED) { |
| 310 |
*out_authenticated = TRUE; |
| 311 |
} else if (auth_result == E_SOURCE_AUTHENTICATION_REJECTED) { |
| 312 |
*out_authenticated = FALSE; |
| 313 |
g_clear_object (&data->conn); |
| 314 |
g_clear_error (error); |
| 315 |
} else { |
| 316 |
res = FALSE; |
| 317 |
g_clear_object (&data->conn); |
| 318 |
} |
| 319 |
|
| 320 |
return res; |
| 321 |
} |
| 322 |
|
| 323 |
EEwsConnection * |
| 324 |
e_ews_config_utils_open_connection_for (ESource *source, |
| 325 |
CamelEwsSettings *ews_settings, |
| 326 |
const gchar *connect_url, |
| 327 |
EEwsConfigUtilTryCredentialsFunc try_credentials_func, |
| 328 |
gpointer user_data, |
| 329 |
GCancellable *cancellable, |
| 330 |
GError **perror) |
| 331 |
{ |
| 332 |
EEwsConnection *conn = NULL; |
| 333 |
GError *local_error = NULL; |
| 334 |
|
| 335 |
g_return_val_if_fail (source != NULL, NULL); |
| 336 |
g_return_val_if_fail (ews_settings != NULL, NULL); |
| 337 |
|
| 338 |
/* use the one from mailer, if there, otherwise open new */ |
| 339 |
conn = e_ews_connection_find ( |
| 340 |
connect_url && *connect_url ? connect_url : camel_ews_settings_get_hosturl (ews_settings), |
| 341 |
ews_settings); |
| 342 |
if (conn) { |
| 343 |
if (try_credentials_func && |
| 344 |
try_credentials_func (conn, NULL, user_data, cancellable, perror) != E_SOURCE_AUTHENTICATION_ACCEPTED) { |
| 345 |
g_clear_object (&conn); |
| 346 |
} |
| 347 |
return conn; |
| 348 |
} |
| 349 |
|
| 350 |
while (!conn && !g_cancellable_is_cancelled (cancellable) && !local_error) { |
| 351 |
if (e_ews_connection_utils_get_without_password (ews_settings)) { |
| 352 |
ESourceAuthenticationResult result; |
| 353 |
gchar *hosturl; |
| 354 |
|
| 355 |
hosturl = camel_ews_settings_dup_hosturl (ews_settings); |
| 356 |
conn = e_ews_connection_new (source, connect_url && *connect_url ? connect_url : hosturl, ews_settings); |
| 357 |
g_free (hosturl); |
| 358 |
|
| 359 |
e_ews_connection_update_credentials (conn, NULL); |
| 360 |
|
| 361 |
if (try_credentials_func) |
| 362 |
result = try_credentials_func (conn, NULL, user_data, cancellable, &local_error); |
| 363 |
else |
| 364 |
result = e_ews_connection_try_credentials_sync (conn, NULL, NULL, NULL, NULL, cancellable, &local_error); |
| 365 |
|
| 366 |
if (result != E_SOURCE_AUTHENTICATION_ACCEPTED) { |
| 367 |
g_clear_object (&conn); |
| 368 |
if (result != E_SOURCE_AUTHENTICATION_REJECTED || local_error) |
| 369 |
break; |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
if (!conn) { |
| 374 |
EShell *shell; |
| 375 |
TryCredentialsData data; |
| 376 |
|
| 377 |
e_ews_connection_utils_force_off_ntlm_auth_check (); |
| 378 |
g_clear_error (&local_error); |
| 379 |
|
| 380 |
shell = e_shell_get_default (); |
| 381 |
|
| 382 |
data.ews_settings = g_object_ref (ews_settings); |
| 383 |
data.connect_url = connect_url && *connect_url ? connect_url : NULL; |
| 384 |
data.try_credentials_func = try_credentials_func; |
| 385 |
data.user_data = user_data; |
| 386 |
data.conn = NULL; |
| 387 |
|
| 388 |
e_credentials_prompter_loop_prompt_sync (e_shell_get_credentials_prompter (shell), |
| 389 |
source, E_CREDENTIALS_PROMPTER_PROMPT_FLAG_ALLOW_SOURCE_SAVE, |
| 390 |
ews_config_utils_try_credentials_sync, &data, cancellable, &local_error); |
| 391 |
|
| 392 |
if (data.conn) |
| 393 |
conn = g_object_ref (data.conn); |
| 394 |
|
| 395 |
g_clear_object (&data.ews_settings); |
| 396 |
g_clear_object (&data.conn); |
| 397 |
} |
| 398 |
} |
| 399 |
|
| 400 |
if (local_error) |
| 401 |
g_propagate_error (perror, local_error); |
| 402 |
|
| 403 |
return conn; |
| 404 |
} |
| 405 |
|
| 406 |
enum { |
| 407 |
COL_FOLDER_ICON = 0, /* G_TYPE_STRING */ |
| 408 |
COL_FOLDER_NAME, /* G_TYPE_STRING */ |
| 409 |
COL_FOLDER_SIZE, /* G_TYPE_STRING */ |
| 410 |
COL_FOLDER_FLAGS, /* G_TYPE_UINT */ |
| 411 |
N_COLUMNS |
| 412 |
}; |
| 413 |
|
| 414 |
typedef struct |
| 415 |
{ |
| 416 |
GtkDialog *dialog; |
| 417 |
GtkGrid *spinner_grid; |
| 418 |
|
| 419 |
ESourceRegistry *registry; |
| 420 |
ESource *source; |
| 421 |
CamelEwsSettings *ews_settings; |
| 422 |
CamelEwsStore *ews_store; |
| 423 |
|
| 424 |
GHashTable *folder_sizes; |
| 425 |
GCancellable *cancellable; |
| 426 |
GError *error; |
| 427 |
} FolderSizeDialogData; |
| 428 |
|
| 429 |
static gint |
| 430 |
folder_tree_model_sort (GtkTreeModel *model, |
| 431 |
GtkTreeIter *a, |
| 432 |
GtkTreeIter *b, |
| 433 |
gpointer unused) |
| 434 |
{ |
| 435 |
gchar *aname, *bname; |
| 436 |
guint32 aflags, bflags; |
| 437 |
gint ret = -2; |
| 438 |
|
| 439 |
gtk_tree_model_get ( |
| 440 |
model, a, |
| 441 |
COL_FOLDER_NAME, &aname, |
| 442 |
COL_FOLDER_FLAGS, &aflags, |
| 443 |
-1); |
| 444 |
|
| 445 |
gtk_tree_model_get ( |
| 446 |
model, b, |
| 447 |
COL_FOLDER_NAME, &bname, |
| 448 |
COL_FOLDER_FLAGS, &bflags, |
| 449 |
-1); |
| 450 |
|
| 451 |
/* Inbox is always first. */ |
| 452 |
if ((aflags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_INBOX) |
| 453 |
ret = -1; |
| 454 |
else if ((bflags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_INBOX) |
| 455 |
ret = 1; |
| 456 |
else { |
| 457 |
if (aname != NULL && bname != NULL) |
| 458 |
ret = g_utf8_collate (aname, bname); |
| 459 |
else if (aname == bname) |
| 460 |
ret = 0; |
| 461 |
else if (aname == NULL) |
| 462 |
ret = -1; |
| 463 |
else |
| 464 |
ret = 1; |
| 465 |
} |
| 466 |
|
| 467 |
g_free (aname); |
| 468 |
g_free (bname); |
| 469 |
|
| 470 |
return ret; |
| 471 |
} |
| 472 |
|
| 473 |
static void |
| 474 |
folder_sizes_tree_populate (GtkTreeStore *store, |
| 475 |
CamelFolderInfo *folder_info, |
| 476 |
GtkTreeIter *parent, |
| 477 |
FolderSizeDialogData *fsd) |
| 478 |
{ |
| 479 |
while (folder_info != NULL) { |
| 480 |
GtkTreeIter iter; |
| 481 |
const gchar *icon_name; |
| 482 |
const gchar *folder_size; |
| 483 |
|
| 484 |
icon_name = em_folder_utils_get_icon_name (folder_info->flags); |
| 485 |
if (g_strcmp0 (icon_name, "folder") == 0) { |
| 486 |
CamelFolder *folder; |
| 487 |
|
| 488 |
folder = camel_store_get_folder_sync ( |
| 489 |
CAMEL_STORE (fsd->ews_store), folder_info->full_name, 0, NULL, NULL); |
| 490 |
|
| 491 |
if (folder != NULL) { |
| 492 |
if (em_utils_folder_is_drafts (fsd->registry, folder)) |
| 493 |
icon_name = "accessories-text-editor"; |
| 494 |
|
| 495 |
g_object_unref (folder); |
| 496 |
} |
| 497 |
} |
| 498 |
|
| 499 |
folder_size = g_hash_table_lookup (fsd->folder_sizes, folder_info->full_name); |
| 500 |
|
| 501 |
gtk_tree_store_append (store, &iter, parent); |
| 502 |
gtk_tree_store_set (store, &iter, |
| 503 |
COL_FOLDER_ICON, icon_name, |
| 504 |
COL_FOLDER_NAME, folder_info->display_name, |
| 505 |
COL_FOLDER_SIZE, folder_size, |
| 506 |
COL_FOLDER_FLAGS, folder_info->flags, |
| 507 |
-1); |
| 508 |
|
| 509 |
if (folder_info->child != NULL) |
| 510 |
folder_sizes_tree_populate (store, folder_info->child, &iter, fsd); |
| 511 |
|
| 512 |
folder_info = folder_info->next; |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
static gboolean |
| 517 |
ews_settings_get_folder_sizes_idle (gpointer user_data) |
| 518 |
{ |
| 519 |
GtkWidget *widget; |
| 520 |
GtkCellRenderer *renderer; |
| 521 |
GtkTreeStore *tree_store; |
| 522 |
GtkBox *content_area; |
| 523 |
FolderSizeDialogData *fsd = user_data; |
| 524 |
CamelFolderInfo *root; |
| 525 |
|
| 526 |
g_return_val_if_fail (fsd != NULL, FALSE); |
| 527 |
|
| 528 |
if (g_cancellable_is_cancelled (fsd->cancellable)) |
| 529 |
goto cleanup; |
| 530 |
|
| 531 |
/* Hide progress bar. Set status */ |
| 532 |
gtk_widget_destroy (GTK_WIDGET (fsd->spinner_grid)); |
| 533 |
|
| 534 |
if (fsd->folder_sizes != NULL) { |
| 535 |
GtkWidget *scrolledwindow, *tree_view; |
| 536 |
|
| 537 |
scrolledwindow = gtk_scrolled_window_new (NULL, NULL); |
| 538 |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), |
| 539 |
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
| 540 |
gtk_widget_show (scrolledwindow); |
| 541 |
|
| 542 |
/* Tree View */ |
| 543 |
tree_view = gtk_tree_view_new (); |
| 544 |
renderer = gtk_cell_renderer_pixbuf_new (); |
| 545 |
gtk_tree_view_insert_column_with_attributes ( |
| 546 |
GTK_TREE_VIEW (tree_view), |
| 547 |
-1, |
| 548 |
NULL, |
| 549 |
renderer, |
| 550 |
"icon-name", |
| 551 |
COL_FOLDER_ICON, |
| 552 |
NULL); |
| 553 |
|
| 554 |
renderer = gtk_cell_renderer_text_new (); |
| 555 |
gtk_tree_view_insert_column_with_attributes ( |
| 556 |
GTK_TREE_VIEW (tree_view), |
| 557 |
-1, |
| 558 |
_("Folder"), |
| 559 |
renderer, |
| 560 |
"text", |
| 561 |
COL_FOLDER_NAME, |
| 562 |
NULL); |
| 563 |
|
| 564 |
renderer = gtk_cell_renderer_text_new (); |
| 565 |
gtk_tree_view_insert_column_with_attributes ( |
| 566 |
GTK_TREE_VIEW (tree_view), |
| 567 |
-1, |
| 568 |
_("Size"), |
| 569 |
renderer, |
| 570 |
"text", |
| 571 |
COL_FOLDER_SIZE, |
| 572 |
NULL); |
| 573 |
|
| 574 |
/* Model for TreeView */ |
| 575 |
tree_store = gtk_tree_store_new ( |
| 576 |
N_COLUMNS, |
| 577 |
/* COL_FOLDER_ICON */ G_TYPE_STRING, |
| 578 |
/* COL_FOLDER_NAME */ G_TYPE_STRING, |
| 579 |
/* COL_FOLDER_SIZE */ G_TYPE_STRING, |
| 580 |
/* COL_FOLDER_FLAGS */ G_TYPE_UINT); |
| 581 |
|
| 582 |
gtk_tree_sortable_set_default_sort_func ( |
| 583 |
GTK_TREE_SORTABLE (tree_store), |
| 584 |
folder_tree_model_sort, NULL, NULL); |
| 585 |
|
| 586 |
gtk_tree_sortable_set_sort_column_id ( |
| 587 |
GTK_TREE_SORTABLE (tree_store), |
| 588 |
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, |
| 589 |
GTK_SORT_ASCENDING); |
| 590 |
|
| 591 |
gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (tree_store)); |
| 592 |
|
| 593 |
root = camel_store_get_folder_info_sync ( |
| 594 |
CAMEL_STORE (fsd->ews_store), NULL, |
| 595 |
CAMEL_STORE_FOLDER_INFO_RECURSIVE, |
| 596 |
NULL, NULL); |
| 597 |
|
| 598 |
folder_sizes_tree_populate (tree_store, root, NULL, fsd); |
| 599 |
|
| 600 |
camel_folder_info_free (root); |
| 601 |
|
| 602 |
gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); |
| 603 |
gtk_container_add (GTK_CONTAINER (scrolledwindow), tree_view); |
| 604 |
widget = scrolledwindow; |
| 605 |
} else if (fsd->error) { |
| 606 |
gchar *msg = g_strconcat (_("Unable to retrieve folder size information"), "\n", |
| 607 |
fsd->error->message, NULL); |
| 608 |
widget = gtk_label_new (msg); |
| 609 |
g_free (msg); |
| 610 |
} else { |
| 611 |
widget = gtk_label_new (_("Unable to retrieve folder size information")); |
| 612 |
} |
| 613 |
|
| 614 |
gtk_widget_show_all (widget); |
| 615 |
|
| 616 |
/* Pack into content_area */ |
| 617 |
content_area = GTK_BOX (gtk_dialog_get_content_area (fsd->dialog)); |
| 618 |
gtk_box_pack_start (content_area, widget, TRUE, TRUE, 6); |
| 619 |
|
| 620 |
cleanup: |
| 621 |
g_hash_table_destroy (fsd->folder_sizes); |
| 622 |
g_object_unref (fsd->registry); |
| 623 |
g_object_unref (fsd->source); |
| 624 |
g_object_unref (fsd->ews_settings); |
| 625 |
g_object_unref (fsd->ews_store); |
| 626 |
g_object_unref (fsd->cancellable); |
| 627 |
g_clear_error (&fsd->error); |
| 628 |
g_slice_free (FolderSizeDialogData, fsd); |
| 629 |
|
| 630 |
return FALSE; |
| 631 |
} |
| 632 |
|
| 633 |
static gpointer |
| 634 |
ews_settings_get_folder_sizes_thread (gpointer user_data) |
| 635 |
{ |
| 636 |
FolderSizeDialogData *fsd = user_data; |
| 637 |
EEwsConnection *cnc; |
| 638 |
|
| 639 |
g_return_val_if_fail (fsd != NULL, NULL); |
| 640 |
|
| 641 |
cnc = e_ews_config_utils_open_connection_for ( |
| 642 |
fsd->source, |
| 643 |
fsd->ews_settings, |
| 644 |
NULL, NULL, NULL, |
| 645 |
fsd->cancellable, |
| 646 |
&fsd->error); |
| 647 |
|
| 648 |
if (cnc) { |
| 649 |
EEwsAdditionalProps *add_props; |
| 650 |
EEwsExtendedFieldURI *ext_uri; |
| 651 |
GSList *ids, *l, *folders_ids = NULL, *folders_list = NULL; |
| 652 |
|
| 653 |
fsd->folder_sizes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); |
| 654 |
|
| 655 |
/* Use MAPI property to retrieve folder size */ |
| 656 |
add_props = e_ews_additional_props_new (); |
| 657 |
|
| 658 |
/* PidTagMessageSizeExtended */ |
| 659 |
ext_uri = e_ews_extended_field_uri_new (); |
| 660 |
ext_uri->prop_tag = g_strdup_printf ("%d", 0x0e08); |
| 661 |
ext_uri->prop_type = g_strdup ("Long"); |
| 662 |
add_props->extended_furis = g_slist_prepend (add_props->extended_furis, ext_uri); |
| 663 |
|
| 664 |
ids = camel_ews_store_summary_get_folders (fsd->ews_store->summary, NULL, FALSE); |
| 665 |
for (l = ids; l != NULL; l = l->next) { |
| 666 |
EwsFolderId *fid; |
| 667 |
fid = e_ews_folder_id_new (l->data, NULL, FALSE); |
| 668 |
folders_ids = g_slist_prepend (folders_ids, fid); |
| 669 |
} |
| 670 |
folders_ids = g_slist_reverse (folders_ids); |
| 671 |
|
| 672 |
e_ews_connection_get_folder_sync ( |
| 673 |
cnc, EWS_PRIORITY_MEDIUM, "Default", |
| 674 |
add_props, folders_ids, &folders_list, |
| 675 |
fsd->cancellable, &fsd->error); |
| 676 |
|
| 677 |
for (l = folders_list; l != NULL; l = l->next) { |
| 678 |
const EEwsFolder *folder = l->data; |
| 679 |
const EwsFolderId *folder_id; |
| 680 |
gchar *folder_full_name; |
| 681 |
gchar *folder_size; |
| 682 |
|
| 683 |
if (!folder || e_ews_folder_is_error (folder)) |
| 684 |
continue; |
| 685 |
|
| 686 |
folder_id = e_ews_folder_get_id (folder); |
| 687 |
if (!folder_id) |
| 688 |
continue; |
| 689 |
|
| 690 |
folder_full_name = camel_ews_store_summary_get_folder_full_name ( |
| 691 |
fsd->ews_store->summary, folder_id->id, NULL); |
| 692 |
folder_size = g_format_size_full (e_ews_folder_get_size (folder), G_FORMAT_SIZE_IEC_UNITS); |
| 693 |
|
| 694 |
g_hash_table_insert (fsd->folder_sizes, folder_full_name, folder_size); |
| 695 |
} |
| 696 |
|
| 697 |
g_slist_free_full (folders_list, g_object_unref); |
| 698 |
g_slist_free_full (folders_ids, (GDestroyNotify) e_ews_folder_id_free); |
| 699 |
g_slist_free_full (ids, g_free); |
| 700 |
e_ews_additional_props_free (add_props); |
| 701 |
g_object_unref (cnc); |
| 702 |
} |
| 703 |
|
| 704 |
g_idle_add (ews_settings_get_folder_sizes_idle, fsd); |
| 705 |
|
| 706 |
return NULL; |
| 707 |
} |
| 708 |
|
| 709 |
static void |
| 710 |
folder_sizes_dialog_response_cb (GObject *dialog, |
| 711 |
gint response_id, |
| 712 |
gpointer data) |
| 713 |
{ |
| 714 |
GCancellable *cancellable = data; |
| 715 |
|
| 716 |
g_cancellable_cancel (cancellable); |
| 717 |
g_object_unref (cancellable); |
| 718 |
|
| 719 |
gtk_widget_destroy (GTK_WIDGET (dialog)); |
| 720 |
} |
| 721 |
|
| 722 |
void |
| 723 |
e_ews_config_utils_run_folder_sizes_dialog (GtkWindow *parent, |
| 724 |
ESourceRegistry *registry, |
| 725 |
ESource *source, |
| 726 |
CamelEwsStore *ews_store) |
| 727 |
{ |
| 728 |
GtkBox *content_area; |
| 729 |
GtkWidget *spinner, *alignment, *dialog; |
| 730 |
GtkWidget *spinner_label; |
| 731 |
GCancellable *cancellable; |
| 732 |
GThread *thread; |
| 733 |
FolderSizeDialogData *fsd; |
| 734 |
|
| 735 |
g_return_if_fail (ews_store != NULL); |
| 736 |
|
| 737 |
cancellable = g_cancellable_new (); |
| 738 |
|
| 739 |
dialog = gtk_dialog_new_with_buttons ( |
| 740 |
_("Folder Sizes"), |
| 741 |
parent, |
| 742 |
GTK_DIALOG_DESTROY_WITH_PARENT, |
| 743 |
_("_Close"), GTK_RESPONSE_ACCEPT, |
| 744 |
NULL); |
| 745 |
|
| 746 |
g_signal_connect (dialog, "response", G_CALLBACK (folder_sizes_dialog_response_cb), cancellable); |
| 747 |
|
| 748 |
fsd = g_slice_new0 (FolderSizeDialogData); |
| 749 |
fsd->dialog = GTK_DIALOG (dialog); |
| 750 |
|
| 751 |
gtk_window_set_default_size (GTK_WINDOW (fsd->dialog), 250, 300); |
| 752 |
|
| 753 |
content_area = GTK_BOX (gtk_dialog_get_content_area (fsd->dialog)); |
| 754 |
|
| 755 |
spinner = e_spinner_new (); |
| 756 |
e_spinner_start (E_SPINNER (spinner)); |
| 757 |
spinner_label = gtk_label_new (_("Fetching folder list…")); |
| 758 |
|
| 759 |
fsd->spinner_grid = GTK_GRID (gtk_grid_new ()); |
| 760 |
gtk_grid_set_column_spacing (fsd->spinner_grid, 6); |
| 761 |
gtk_grid_set_column_homogeneous (fsd->spinner_grid, FALSE); |
| 762 |
gtk_orientable_set_orientation (GTK_ORIENTABLE (fsd->spinner_grid), GTK_ORIENTATION_HORIZONTAL); |
| 763 |
|
| 764 |
alignment = gtk_alignment_new (1.0, 0.5, 0.0, 1.0); |
| 765 |
gtk_container_add (GTK_CONTAINER (alignment), spinner); |
| 766 |
gtk_misc_set_alignment (GTK_MISC (spinner_label), 0.0, 0.5); |
| 767 |
|
| 768 |
gtk_container_add (GTK_CONTAINER (fsd->spinner_grid), alignment); |
| 769 |
gtk_container_add (GTK_CONTAINER (fsd->spinner_grid), spinner_label); |
| 770 |
|
| 771 |
/* Pack the TreeView into dialog's content area */ |
| 772 |
gtk_box_pack_start (content_area, GTK_WIDGET (fsd->spinner_grid), TRUE, TRUE, 6); |
| 773 |
gtk_widget_show_all (GTK_WIDGET (fsd->dialog)); |
| 774 |
|
| 775 |
fsd->registry = g_object_ref (registry); |
| 776 |
fsd->source = g_object_ref (source); |
| 777 |
fsd->ews_store = g_object_ref (ews_store); |
| 778 |
fsd->ews_settings = CAMEL_EWS_SETTINGS (camel_service_ref_settings (CAMEL_SERVICE (ews_store))); |
| 779 |
fsd->cancellable = g_object_ref (cancellable); |
| 780 |
|
| 781 |
thread = g_thread_new (NULL, ews_settings_get_folder_sizes_thread, fsd); |
| 782 |
g_thread_unref (thread); |
| 783 |
|
| 784 |
/* Start the dialog */ |
| 785 |
gtk_widget_show (GTK_WIDGET (dialog)); |
| 786 |
} |
| 787 |
|
| 788 |
static void |
| 789 |
action_global_subscribe_foreign_folder_cb (EUIAction *action, |
| 790 |
GVariant *parameter, |
| 791 |
gpointer user_data) |
| 792 |
{ |
| 793 |
EShellView *shell_view = user_data; |
| 794 |
EShell *shell; |
| 795 |
EShellBackend *shell_backend; |
| 796 |
EShellWindow *shell_window; |
| 797 |
EClientCache *client_cache; |
| 798 |
CamelSession *session = NULL; |
| 799 |
|
| 800 |
g_return_if_fail (E_IS_SHELL_VIEW (shell_view)); |
| 801 |
|
| 802 |
shell_window = e_shell_view_get_shell_window (shell_view); |
| 803 |
shell = e_shell_window_get_shell (shell_window); |
| 804 |
shell_backend = e_shell_get_backend_by_name (shell, "mail"); |
| 805 |
|
| 806 |
if (shell_backend) |
| 807 |
g_object_get (G_OBJECT (shell_backend), "session", &session, NULL); |
| 808 |
|
| 809 |
if (!session) |
| 810 |
return; |
| 811 |
|
| 812 |
client_cache = e_shell_get_client_cache (shell); |
| 813 |
|
| 814 |
e_ews_subscribe_foreign_folder (GTK_WINDOW (shell_window), session, NULL, client_cache); |
| 815 |
|
| 816 |
g_object_unref (session); |
| 817 |
} |
| 818 |
|
| 819 |
static const EUIActionEntry global_ews_mail_entries[] = { |
| 820 |
{ "ews-mail-global-subscribe-foreign-folder", |
| 821 |
NULL, |
| 822 |
N_("Subscribe to folder of other EWS user…"), |
| 823 |
NULL, |
| 824 |
NULL, |
| 825 |
action_global_subscribe_foreign_folder_cb, NULL, NULL, NULL } |
| 826 |
}; |
| 827 |
|
| 828 |
static const EUIActionEntry global_ews_book_entries[] = { |
| 829 |
{ "ews-contact-global-subscribe-foreign-folder", |
| 830 |
NULL, |
| 831 |
N_("Subscribe to folder of other EWS user…"), |
| 832 |
NULL, |
| 833 |
NULL, |
| 834 |
action_global_subscribe_foreign_folder_cb, NULL, NULL, NULL } |
| 835 |
}; |
| 836 |
|
| 837 |
static const EUIActionEntry global_ews_cal_entries[] = { |
| 838 |
{ "ews-calendar-global-subscribe-foreign-folder", |
| 839 |
NULL, |
| 840 |
N_("Subscribe to folder of other EWS user…"), |
| 841 |
NULL, |
| 842 |
NULL, |
| 843 |
action_global_subscribe_foreign_folder_cb, NULL, NULL, NULL } |
| 844 |
}; |
| 845 |
|
| 846 |
static const EUIActionEntry global_ews_task_entries[] = { |
| 847 |
{ "ews-task-global-subscribe-foreign-folder", |
| 848 |
NULL, |
| 849 |
N_("Subscribe to folder of other EWS user…"), |
| 850 |
NULL, |
| 851 |
NULL, |
| 852 |
action_global_subscribe_foreign_folder_cb, NULL, NULL, NULL } |
| 853 |
}; |
| 854 |
|
| 855 |
static const EUIActionEntry global_ews_memo_entries[] = { |
| 856 |
{ "ews-memo-global-subscribe-foreign-folder", |
| 857 |
NULL, |
| 858 |
N_("Subscribe to folder of other EWS user…"), |
| 859 |
NULL, |
| 860 |
NULL, |
| 861 |
action_global_subscribe_foreign_folder_cb, NULL, NULL, NULL } |
| 862 |
}; |
| 863 |
|
| 864 |
static gboolean |
| 865 |
ews_ui_has_ews_account (EShellView *shell_view, |
| 866 |
CamelSession *in_session) |
| 867 |
{ |
| 868 |
CamelSession *session = in_session; |
| 869 |
EShell *shell; |
| 870 |
gboolean has_any = FALSE; |
| 871 |
|
| 872 |
g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), FALSE); |
| 873 |
if (in_session) |
| 874 |
g_return_val_if_fail (CAMEL_IS_SESSION (in_session), FALSE); |
| 875 |
|
| 876 |
shell = e_shell_window_get_shell (e_shell_view_get_shell_window (shell_view)); |
| 877 |
|
| 878 |
if (!session) { |
| 879 |
EShellBackend *shell_backend; |
| 880 |
|
| 881 |
shell_backend = e_shell_get_backend_by_name (shell, "mail"); |
| 882 |
|
| 883 |
if (shell_backend) { |
| 884 |
g_object_get (G_OBJECT (shell_backend), "session", &session, NULL); |
| 885 |
} |
| 886 |
} |
| 887 |
|
| 888 |
if (session) { |
| 889 |
ESourceRegistry *registry; |
| 890 |
GList *services, *link; |
| 891 |
|
| 892 |
registry = e_shell_get_registry (shell); |
| 893 |
services = camel_session_list_services (session); |
| 894 |
|
| 895 |
for (link = services; link && !has_any; link = g_list_next (link)) { |
| 896 |
CamelService *service = link->data; |
| 897 |
|
| 898 |
if (CAMEL_IS_EWS_STORE (service)) { |
| 899 |
ESource *source; |
| 900 |
|
| 901 |
source = e_source_registry_ref_source (registry, camel_service_get_uid (service)); |
| 902 |
has_any = source && e_source_registry_check_enabled (registry, source); |
| 903 |
|
| 904 |
g_clear_object (&source); |
| 905 |
} |
| 906 |
} |
| 907 |
|
| 908 |
g_list_free_full (services, g_object_unref); |
| 909 |
} |
| 910 |
|
| 911 |
if (session && session != in_session) |
| 912 |
g_object_unref (session); |
| 913 |
|
| 914 |
return has_any; |
| 915 |
} |
| 916 |
|
| 917 |
static gboolean |
| 918 |
get_ews_store_from_folder_tree (EShellView *shell_view, |
| 919 |
gchar **pfolder_path, |
| 920 |
CamelStore **pstore) |
| 921 |
{ |
| 922 |
EShellSidebar *shell_sidebar; |
| 923 |
EMFolderTree *folder_tree; |
| 924 |
gchar *selected_path = NULL; |
| 925 |
CamelStore *selected_store = NULL; |
| 926 |
gboolean found = FALSE; |
| 927 |
|
| 928 |
/* Get hold of Folder Tree */ |
| 929 |
shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); |
| 930 |
g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL); |
| 931 |
if (em_folder_tree_get_selected (folder_tree, &selected_store, &selected_path) || |
| 932 |
em_folder_tree_store_root_selected (folder_tree, &selected_store)) { |
| 933 |
if (selected_store) { |
| 934 |
CamelProvider *provider = camel_service_get_provider (CAMEL_SERVICE (selected_store)); |
| 935 |
|
| 936 |
if (provider && g_ascii_strcasecmp (provider->protocol, "ews") == 0) { |
| 937 |
found = TRUE; |
| 938 |
|
| 939 |
if (pstore) |
| 940 |
*pstore = g_object_ref (selected_store); |
| 941 |
|
| 942 |
if (pfolder_path) |
| 943 |
*pfolder_path = selected_path; |
| 944 |
else |
| 945 |
g_free (selected_path); |
| 946 |
|
| 947 |
selected_path = NULL; |
| 948 |
} |
| 949 |
|
| 950 |
g_object_unref (selected_store); |
| 951 |
} |
| 952 |
|
| 953 |
g_free (selected_path); |
| 954 |
} |
| 955 |
|
| 956 |
g_object_unref (folder_tree); |
| 957 |
|
| 958 |
return found; |
| 959 |
} |
| 960 |
|
| 961 |
static void |
| 962 |
action_folder_sizes_cb (EUIAction *action, |
| 963 |
GVariant *parameter, |
| 964 |
gpointer user_data) |
| 965 |
{ |
| 966 |
EShellView *shell_view = user_data; |
| 967 |
GtkWindow *parent; |
| 968 |
CamelSession *session; |
| 969 |
CamelStore *store = NULL; |
| 970 |
ESourceRegistry *registry; |
| 971 |
ESource *source; |
| 972 |
|
| 973 |
if (!get_ews_store_from_folder_tree (shell_view, NULL, &store)) |
| 974 |
return; |
| 975 |
|
| 976 |
g_return_if_fail (store != NULL); |
| 977 |
|
| 978 |
parent = GTK_WINDOW (e_shell_view_get_shell_window (shell_view)); |
| 979 |
|
| 980 |
session = camel_service_ref_session (CAMEL_SERVICE (store)); |
| 981 |
registry = e_mail_session_get_registry (E_MAIL_SESSION (session)); |
| 982 |
source = e_source_registry_ref_source (registry, camel_service_get_uid (CAMEL_SERVICE (store))); |
| 983 |
|
| 984 |
e_ews_config_utils_run_folder_sizes_dialog (parent, registry, source, CAMEL_EWS_STORE (store)); |
| 985 |
|
| 986 |
g_object_unref (source); |
| 987 |
g_object_unref (session); |
| 988 |
g_object_unref (store); |
| 989 |
} |
| 990 |
|
| 991 |
static void |
| 992 |
action_subscribe_foreign_folder_cb (EUIAction *action, |
| 993 |
GVariant *parameter, |
| 994 |
gpointer user_data) |
| 995 |
{ |
| 996 |
EShellView *shell_view = user_data; |
| 997 |
GtkWindow *parent; |
| 998 |
EShell *shell; |
| 999 |
EShellBackend *backend; |
| 1000 |
EClientCache *client_cache; |
| 1001 |
CamelSession *session = NULL; |
| 1002 |
CamelStore *store = NULL; |
| 1003 |
|
| 1004 |
if (!get_ews_store_from_folder_tree (shell_view, NULL, &store)) |
| 1005 |
return; |
| 1006 |
|
| 1007 |
parent = GTK_WINDOW (e_shell_view_get_shell_window (shell_view)); |
| 1008 |
backend = e_shell_view_get_shell_backend (shell_view); |
| 1009 |
g_object_get (G_OBJECT (backend), "session", &session, NULL); |
| 1010 |
|
| 1011 |
shell = e_shell_backend_get_shell (backend); |
| 1012 |
client_cache = e_shell_get_client_cache (shell); |
| 1013 |
|
| 1014 |
e_ews_subscribe_foreign_folder (parent, session, store, client_cache); |
| 1015 |
|
| 1016 |
g_object_unref (session); |
| 1017 |
g_object_unref (store); |
| 1018 |
} |
| 1019 |
|
| 1020 |
static void |
| 1021 |
action_folder_permissions_mail_cb (EUIAction *action, |
| 1022 |
GVariant *parameter, |
| 1023 |
gpointer user_data) |
| 1024 |
{ |
| 1025 |
EShellView *shell_view = user_data; |
| 1026 |
EShell *shell; |
| 1027 |
EShellWindow *shell_window; |
| 1028 |
ESourceRegistry *registry; |
| 1029 |
GtkWindow *parent; |
| 1030 |
CamelStore *store = NULL; |
| 1031 |
CamelEwsStore *ews_store; |
| 1032 |
EwsFolderId *folder_id = NULL; |
| 1033 |
gchar *folder_path = NULL; |
| 1034 |
|
| 1035 |
if (!get_ews_store_from_folder_tree (shell_view, &folder_path, &store)) |
| 1036 |
return; |
| 1037 |
|
| 1038 |
ews_store = CAMEL_EWS_STORE (store); |
| 1039 |
g_return_if_fail (ews_store != NULL); |
| 1040 |
|
| 1041 |
shell_window = e_shell_view_get_shell_window (shell_view); |
| 1042 |
parent = GTK_WINDOW (shell_window); |
| 1043 |
shell = e_shell_window_get_shell (shell_window); |
| 1044 |
registry = e_shell_get_registry (shell); |
| 1045 |
|
| 1046 |
if (folder_path && *folder_path) { |
| 1047 |
gchar *str_folder_id = NULL; |
| 1048 |
|
| 1049 |
str_folder_id = camel_ews_store_summary_get_folder_id_from_name (ews_store->summary, folder_path); |
| 1050 |
if (!str_folder_id) { |
| 1051 |
e_notice (parent, GTK_MESSAGE_ERROR, _("Cannot edit permissions of folder “%s”, choose other folder."), folder_path); |
| 1052 |
} else { |
| 1053 |
gchar *str_change_key; |
| 1054 |
|
| 1055 |
str_change_key = camel_ews_store_summary_get_change_key ( |
| 1056 |
ews_store->summary, str_folder_id, NULL); |
| 1057 |
|
| 1058 |
folder_id = e_ews_folder_id_new (str_folder_id, str_change_key, FALSE); |
| 1059 |
|
| 1060 |
g_free (str_change_key); |
| 1061 |
} |
| 1062 |
|
| 1063 |
g_free (str_folder_id); |
| 1064 |
} else { |
| 1065 |
g_clear_pointer (&folder_path, g_free); |
| 1066 |
|
| 1067 |
folder_id = e_ews_folder_id_new ("msgfolderroot", NULL, TRUE); |
| 1068 |
} |
| 1069 |
|
| 1070 |
if (folder_id) { |
| 1071 |
ESource *source; |
| 1072 |
CamelService *service; |
| 1073 |
CamelSettings *settings; |
| 1074 |
const gchar *uid; |
| 1075 |
|
| 1076 |
service = CAMEL_SERVICE (store); |
| 1077 |
uid = camel_service_get_uid (service); |
| 1078 |
source = e_source_registry_ref_source (registry, uid); |
| 1079 |
if (source) { |
| 1080 |
settings = camel_service_ref_settings (service); |
| 1081 |
|
| 1082 |
e_ews_edit_folder_permissions ( |
| 1083 |
parent, |
| 1084 |
registry, |
| 1085 |
source, |
| 1086 |
CAMEL_EWS_SETTINGS (settings), |
| 1087 |
camel_service_get_display_name (service), |
| 1088 |
folder_path ? folder_path : camel_service_get_display_name (service), |
| 1089 |
folder_id, |
| 1090 |
E_EWS_FOLDER_TYPE_MAILBOX); |
| 1091 |
|
| 1092 |
g_object_unref (settings); |
| 1093 |
g_object_unref (source); |
| 1094 |
} else { |
| 1095 |
g_warn_if_reached (); |
| 1096 |
} |
| 1097 |
} |
| 1098 |
|
| 1099 |
g_object_unref (store); |
| 1100 |
g_free (folder_path); |
| 1101 |
e_ews_folder_id_free (folder_id); |
| 1102 |
} |
| 1103 |
|
| 1104 |
static void |
| 1105 |
ews_ui_enable_actions (EUIActionGroup *action_group, |
| 1106 |
const EUIActionEntry *entries, |
| 1107 |
guint n_entries, |
| 1108 |
gboolean can_show, |
| 1109 |
gboolean is_online) |
| 1110 |
{ |
| 1111 |
gint ii; |
| 1112 |
|
| 1113 |
g_return_if_fail (action_group != NULL); |
| 1114 |
g_return_if_fail (entries != NULL); |
| 1115 |
|
| 1116 |
for (ii = 0; ii < n_entries; ii++) { |
| 1117 |
EUIAction *action; |
| 1118 |
|
| 1119 |
action = e_ui_action_group_get_action (action_group, entries[ii].name); |
| 1120 |
if (!action) |
| 1121 |
continue; |
| 1122 |
|
| 1123 |
e_ui_action_set_visible (action, can_show); |
| 1124 |
if (can_show) |
| 1125 |
e_ui_action_set_sensitive (action, is_online); |
| 1126 |
} |
| 1127 |
} |
| 1128 |
|
| 1129 |
static const EUIActionEntry mail_account_context_entries[] = { |
| 1130 |
{ "mail-ews-folder-sizes", |
| 1131 |
NULL, |
| 1132 |
N_("Folder Sizes…"), |
| 1133 |
NULL, |
| 1134 |
NULL, |
| 1135 |
action_folder_sizes_cb, NULL, NULL, NULL }, |
| 1136 |
|
| 1137 |
{ "mail-ews-subscribe-foreign-folder", |
| 1138 |
NULL, |
| 1139 |
N_("Subscribe to folder of other user…"), |
| 1140 |
NULL, |
| 1141 |
NULL, |
| 1142 |
action_subscribe_foreign_folder_cb, NULL, NULL, NULL } |
| 1143 |
}; |
| 1144 |
|
| 1145 |
static const EUIActionEntry mail_folder_context_entries[] = { |
| 1146 |
{ "mail-ews-folder-permissions", |
| 1147 |
"folder-new", |
| 1148 |
N_("Permissions…"), |
| 1149 |
NULL, |
| 1150 |
N_("Edit EWS folder permissions"), |
| 1151 |
action_folder_permissions_mail_cb, NULL, NULL, NULL } |
| 1152 |
}; |
| 1153 |
|
| 1154 |
static void |
| 1155 |
ews_ui_update_actions_mail_cb (EShellView *shell_view, |
| 1156 |
gpointer user_data) |
| 1157 |
{ |
| 1158 |
EShellBackend *backend; |
| 1159 |
CamelSession *session = NULL; |
| 1160 |
EUIActionGroup *action_group; |
| 1161 |
EUIManager *ui_manager; |
| 1162 |
EShellSidebar *shell_sidebar; |
| 1163 |
EMFolderTree *folder_tree; |
| 1164 |
CamelStore *selected_store = NULL; |
| 1165 |
gchar *selected_path = NULL; |
| 1166 |
gboolean account_node = FALSE, folder_node = FALSE; |
| 1167 |
gboolean online, has_ews_account; |
| 1168 |
|
| 1169 |
shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); |
| 1170 |
g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL); |
| 1171 |
if (em_folder_tree_get_selected (folder_tree, &selected_store, &selected_path) || |
| 1172 |
em_folder_tree_store_root_selected (folder_tree, &selected_store)) { |
| 1173 |
if (selected_store) { |
| 1174 |
CamelProvider *provider = camel_service_get_provider (CAMEL_SERVICE (selected_store)); |
| 1175 |
|
| 1176 |
if (provider && g_ascii_strcasecmp (provider->protocol, "ews") == 0) { |
| 1177 |
account_node = !selected_path || !*selected_path; |
| 1178 |
folder_node = !account_node; |
| 1179 |
} |
| 1180 |
|
| 1181 |
g_object_unref (selected_store); |
| 1182 |
} |
| 1183 |
} |
| 1184 |
g_object_unref (folder_tree); |
| 1185 |
|
| 1186 |
g_free (selected_path); |
| 1187 |
|
| 1188 |
ui_manager = e_shell_view_get_ui_manager (shell_view); |
| 1189 |
action_group = e_ui_manager_get_action_group (ui_manager, "mail"); |
| 1190 |
|
| 1191 |
backend = e_shell_view_get_shell_backend (shell_view); |
| 1192 |
g_object_get (G_OBJECT (backend), "session", &session, NULL); |
| 1193 |
|
| 1194 |
online = session && camel_session_get_online (session); |
| 1195 |
|
| 1196 |
has_ews_account = account_node || folder_node || ews_ui_has_ews_account (shell_view, session); |
| 1197 |
|
| 1198 |
if (session) |
| 1199 |
g_object_unref (session); |
| 1200 |
|
| 1201 |
ews_ui_enable_actions (action_group, mail_account_context_entries, G_N_ELEMENTS (mail_account_context_entries), account_node, online); |
| 1202 |
ews_ui_enable_actions (action_group, mail_folder_context_entries, G_N_ELEMENTS (mail_folder_context_entries), account_node || folder_node, online); |
| 1203 |
ews_ui_enable_actions (action_group, global_ews_mail_entries, G_N_ELEMENTS (global_ews_mail_entries), has_ews_account, online); |
| 1204 |
} |
| 1205 |
|
| 1206 |
static void |
| 1207 |
ews_ui_init_mail (EShellView *shell_view) |
| 1208 |
{ |
| 1209 |
static const gchar *eui = |
| 1210 |
"<eui>" |
| 1211 |
"<menu id='main-menu'>" |
| 1212 |
"<submenu action='file-menu'>" |
| 1213 |
"<placeholder id='long-running-actions'>" |
| 1214 |
"<item action='ews-mail-global-subscribe-foreign-folder'/>" |
| 1215 |
"</placeholder>" |
| 1216 |
"</submenu>" |
| 1217 |
"</menu>" |
| 1218 |
"<menu id='mail-folder-popup'>" |
| 1219 |
"<placeholder id='mail-folder-popup-actions'>" |
| 1220 |
"<item action='mail-ews-folder-sizes'/>" |
| 1221 |
"<item action='mail-ews-subscribe-foreign-folder'/>" |
| 1222 |
"<item action='mail-ews-folder-permissions'/>" |
| 1223 |
"</placeholder>" |
| 1224 |
"</menu>" |
| 1225 |
"</eui>"; |
| 1226 |
|
| 1227 |
EUIManager *ui_manager; |
| 1228 |
|
| 1229 |
ui_manager = e_shell_view_get_ui_manager (shell_view); |
| 1230 |
|
| 1231 |
e_ui_manager_add_actions (ui_manager, "mail", GETTEXT_PACKAGE, |
| 1232 |
mail_account_context_entries, G_N_ELEMENTS (mail_account_context_entries), shell_view); |
| 1233 |
e_ui_manager_add_actions (ui_manager, "mail", GETTEXT_PACKAGE, |
| 1234 |
mail_folder_context_entries, G_N_ELEMENTS (mail_folder_context_entries), shell_view); |
| 1235 |
e_ui_manager_add_actions_with_eui_data (ui_manager, "mail", GETTEXT_PACKAGE, |
| 1236 |
global_ews_mail_entries, G_N_ELEMENTS (global_ews_mail_entries), shell_view, eui); |
| 1237 |
|
| 1238 |
/* Decide whether we want this option to be visible or not */ |
| 1239 |
g_signal_connect (shell_view, "update-actions", G_CALLBACK (ews_ui_update_actions_mail_cb), NULL); |
| 1240 |
} |
| 1241 |
|
| 1242 |
static gboolean |
| 1243 |
get_selected_ews_source (EShellView *shell_view, |
| 1244 |
ESource **selected_source, |
| 1245 |
ESourceRegistry **registry) |
| 1246 |
{ |
| 1247 |
ESource *source; |
| 1248 |
EShellSidebar *shell_sidebar; |
| 1249 |
ESourceSelector *selector = NULL; |
| 1250 |
|
| 1251 |
g_return_val_if_fail (shell_view != NULL, FALSE); |
| 1252 |
|
| 1253 |
shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); |
| 1254 |
g_return_val_if_fail (shell_sidebar != NULL, FALSE); |
| 1255 |
|
| 1256 |
g_object_get (shell_sidebar, "selector", &selector, NULL); |
| 1257 |
g_return_val_if_fail (selector != NULL, FALSE); |
| 1258 |
|
| 1259 |
source = e_source_selector_ref_primary_selection (selector); |
| 1260 |
if (source) { |
| 1261 |
ESourceBackend *backend_ext = NULL; |
| 1262 |
|
| 1263 |
if (e_source_has_extension (source, E_SOURCE_EXTENSION_ADDRESS_BOOK)) |
| 1264 |
backend_ext = e_source_get_extension (source, E_SOURCE_EXTENSION_ADDRESS_BOOK); |
| 1265 |
else if (e_source_has_extension (source, E_SOURCE_EXTENSION_CALENDAR)) |
| 1266 |
backend_ext = e_source_get_extension (source, E_SOURCE_EXTENSION_CALENDAR); |
| 1267 |
else if (e_source_has_extension (source, E_SOURCE_EXTENSION_MEMO_LIST)) |
| 1268 |
backend_ext = e_source_get_extension (source, E_SOURCE_EXTENSION_MEMO_LIST); |
| 1269 |
else if (e_source_has_extension (source, E_SOURCE_EXTENSION_TASK_LIST)) |
| 1270 |
backend_ext = e_source_get_extension (source, E_SOURCE_EXTENSION_TASK_LIST); |
| 1271 |
else if (e_source_has_extension (source, E_SOURCE_EXTENSION_MAIL_ACCOUNT)) |
| 1272 |
backend_ext = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_ACCOUNT); |
| 1273 |
|
| 1274 |
if (!backend_ext || |
| 1275 |
g_strcmp0 (e_source_backend_get_backend_name (backend_ext), "ews") != 0) { |
| 1276 |
g_object_unref (source); |
| 1277 |
source = NULL; |
| 1278 |
} |
| 1279 |
} |
| 1280 |
|
| 1281 |
if (source && registry) |
| 1282 |
*registry = g_object_ref (e_source_selector_get_registry (selector)); |
| 1283 |
|
| 1284 |
g_object_unref (selector); |
| 1285 |
|
| 1286 |
if (selected_source) |
| 1287 |
*selected_source = source; |
| 1288 |
else if (source) |
| 1289 |
g_object_unref (source); |
| 1290 |
|
| 1291 |
return source != NULL; |
| 1292 |
} |
| 1293 |
|
| 1294 |
/* how many menu entries are defined; all calendar/tasks/memos/contacts |
| 1295 |
* actions should have same count */ |
| 1296 |
#define EWS_ESOURCE_NUM_ENTRIES 1 |
| 1297 |
|
| 1298 |
static void |
| 1299 |
update_ews_source_entries_cb (EShellView *shell_view, |
| 1300 |
const EUIActionEntry *entries) |
| 1301 |
{ |
| 1302 |
EUIActionGroup *action_group; |
| 1303 |
EShell *shell; |
| 1304 |
EShellWindow *shell_window; |
| 1305 |
ESource *source = NULL; |
| 1306 |
const EUIActionEntry *global_entries = NULL; |
| 1307 |
guint n_global_entries = 0; |
| 1308 |
const gchar *group; |
| 1309 |
gboolean is_ews_source, is_online; |
| 1310 |
|
| 1311 |
g_return_if_fail (E_IS_SHELL_VIEW (shell_view)); |
| 1312 |
g_return_if_fail (entries != NULL); |
| 1313 |
|
| 1314 |
if (strstr (entries->name, "calendar")) { |
| 1315 |
group = "calendar"; |
| 1316 |
global_entries = global_ews_cal_entries; |
| 1317 |
n_global_entries = G_N_ELEMENTS (global_ews_cal_entries); |
| 1318 |
} else if (strstr (entries->name, "tasks")) { |
| 1319 |
group = "tasks"; |
| 1320 |
global_entries = global_ews_task_entries; |
| 1321 |
n_global_entries = G_N_ELEMENTS (global_ews_task_entries); |
| 1322 |
} else if (strstr (entries->name, "memos")) { |
| 1323 |
group = "memos"; |
| 1324 |
global_entries = global_ews_memo_entries; |
| 1325 |
n_global_entries = G_N_ELEMENTS (global_ews_memo_entries); |
| 1326 |
} else if (strstr (entries->name, "contacts")) { |
| 1327 |
group = "contacts"; |
| 1328 |
global_entries = global_ews_book_entries; |
| 1329 |
n_global_entries = G_N_ELEMENTS (global_ews_book_entries); |
| 1330 |
} else { |
| 1331 |
g_return_if_reached (); |
| 1332 |
} |
| 1333 |
|
| 1334 |
is_ews_source = get_selected_ews_source (shell_view, &source, NULL); |
| 1335 |
|
| 1336 |
if (is_ews_source) { |
| 1337 |
if (!source || !e_source_has_extension (source, E_SOURCE_EXTENSION_EWS_FOLDER)) |
| 1338 |
is_ews_source = FALSE; |
| 1339 |
|
| 1340 |
if (is_ews_source) { |
| 1341 |
ESource *clicked_source = NULL; |
| 1342 |
|
| 1343 |
g_object_get (G_OBJECT (shell_view), "clicked-source", &clicked_source, NULL); |
| 1344 |
|
| 1345 |
if (clicked_source && clicked_source != source) |
| 1346 |
is_ews_source = FALSE; |
| 1347 |
|
| 1348 |
g_clear_object (&clicked_source); |
| 1349 |
} |
| 1350 |
|
| 1351 |
if (is_ews_source) { |
| 1352 |
ESourceEwsFolder *ews_folder = e_source_get_extension (source, E_SOURCE_EXTENSION_EWS_FOLDER); |
| 1353 |
|
| 1354 |
/* Require both ChangeKey and folder's Id, but GAL can have a ':' in the Id, |
| 1355 |
which should be ignored, because it's not a valid folder Id. */ |
| 1356 |
if (!e_source_ews_folder_get_id (ews_folder) || |
| 1357 |
g_strcmp0 (e_source_ews_folder_get_id (ews_folder), "") == 0 || |
| 1358 |
!e_source_ews_folder_get_change_key (ews_folder) || |
| 1359 |
g_strcmp0 (e_source_ews_folder_get_change_key (ews_folder), "") == 0 || |
| 1360 |
strchr (e_source_ews_folder_get_id (ews_folder), ':') != NULL) |
| 1361 |
is_ews_source = FALSE; |
| 1362 |
} |
| 1363 |
} |
| 1364 |
|
| 1365 |
g_clear_object (&source); |
| 1366 |
|
| 1367 |
shell_window = e_shell_view_get_shell_window (shell_view); |
| 1368 |
shell = e_shell_window_get_shell (shell_window); |
| 1369 |
|
| 1370 |
is_online = shell && e_shell_get_online (shell); |
| 1371 |
action_group = e_ui_manager_get_action_group (e_shell_view_get_ui_manager (shell_view), group); |
| 1372 |
|
| 1373 |
ews_ui_enable_actions (action_group, entries, EWS_ESOURCE_NUM_ENTRIES, is_ews_source, is_online); |
| 1374 |
ews_ui_enable_actions (action_group, global_entries, n_global_entries, |
| 1375 |
ews_ui_has_ews_account (shell_view, NULL), is_online); |
| 1376 |
} |
| 1377 |
|
| 1378 |
static void |
| 1379 |
setup_ews_source_actions (EShellView *shell_view, |
| 1380 |
const EUIActionEntry *entries, |
| 1381 |
guint n_entries, |
| 1382 |
const gchar *eui) |
| 1383 |
{ |
| 1384 |
EUIManager *ui_manager; |
| 1385 |
const EUIActionEntry *global_entries = NULL; |
| 1386 |
guint n_global_entries = 0; |
| 1387 |
const gchar *group; |
| 1388 |
|
| 1389 |
g_return_if_fail (shell_view != NULL); |
| 1390 |
g_return_if_fail (entries != NULL); |
| 1391 |
g_return_if_fail (n_entries > 0); |
| 1392 |
g_return_if_fail (n_entries == EWS_ESOURCE_NUM_ENTRIES); |
| 1393 |
|
| 1394 |
if (strstr (entries->name, "calendar")) { |
| 1395 |
group = "calendar"; |
| 1396 |
global_entries = global_ews_cal_entries; |
| 1397 |
n_global_entries = G_N_ELEMENTS (global_ews_cal_entries); |
| 1398 |
} else if (strstr (entries->name, "tasks")) { |
| 1399 |
group = "tasks"; |
| 1400 |
global_entries = global_ews_task_entries; |
| 1401 |
n_global_entries = G_N_ELEMENTS (global_ews_task_entries); |
| 1402 |
} else if (strstr (entries->name, "memos")) { |
| 1403 |
group = "memos"; |
| 1404 |
global_entries = global_ews_memo_entries; |
| 1405 |
n_global_entries = G_N_ELEMENTS (global_ews_memo_entries); |
| 1406 |
} else if (strstr (entries->name, "contacts")) { |
| 1407 |
group = "contacts"; |
| 1408 |
global_entries = global_ews_book_entries; |
| 1409 |
n_global_entries = G_N_ELEMENTS (global_ews_book_entries); |
| 1410 |
} else { |
| 1411 |
g_return_if_reached (); |
| 1412 |
} |
| 1413 |
|
| 1414 |
ui_manager = e_shell_view_get_ui_manager (shell_view); |
| 1415 |
e_ui_manager_add_actions (ui_manager, group, GETTEXT_PACKAGE, entries, n_entries, shell_view); |
| 1416 |
e_ui_manager_add_actions_with_eui_data (ui_manager, group, GETTEXT_PACKAGE, global_entries, n_global_entries, shell_view, eui); |
| 1417 |
|
| 1418 |
g_signal_connect (shell_view, "update-actions", G_CALLBACK (update_ews_source_entries_cb), (gpointer) entries); |
| 1419 |
} |
| 1420 |
|
| 1421 |
static void |
| 1422 |
action_folder_permissions_source_cb (EUIAction *action, |
| 1423 |
GVariant *parameter, |
| 1424 |
gpointer user_data) |
| 1425 |
{ |
| 1426 |
EShellView *shell_view = user_data; |
| 1427 |
ESourceRegistry *registry = NULL; |
| 1428 |
ESource *source = NULL, *parent_source; |
| 1429 |
ESourceEwsFolder *folder_ext; |
| 1430 |
ESourceCamel *extension; |
| 1431 |
CamelSettings *settings; |
| 1432 |
const gchar *extension_name; |
| 1433 |
const gchar *action_name; |
| 1434 |
EwsFolderId *folder_id; |
| 1435 |
EEwsFolderType folder_type; |
| 1436 |
|
| 1437 |
g_return_if_fail (action != NULL); |
| 1438 |
g_return_if_fail (shell_view != NULL); |
| 1439 |
g_return_if_fail (get_selected_ews_source (shell_view, &source, ®istry)); |
| 1440 |
g_return_if_fail (source != NULL); |
| 1441 |
g_return_if_fail (e_source_has_extension (source, E_SOURCE_EXTENSION_EWS_FOLDER)); |
| 1442 |
g_return_if_fail (g_action_get_name (G_ACTION (action)) != NULL); |
| 1443 |
|
| 1444 |
folder_ext = e_source_get_extension (source, E_SOURCE_EXTENSION_EWS_FOLDER); |
| 1445 |
folder_id = e_source_ews_folder_dup_folder_id (folder_ext); |
| 1446 |
g_return_if_fail (folder_id != NULL); |
| 1447 |
|
| 1448 |
parent_source = e_source_registry_ref_source (registry, e_source_get_parent (source)); |
| 1449 |
|
| 1450 |
extension_name = e_source_camel_get_extension_name ("ews"); |
| 1451 |
extension = e_source_get_extension (parent_source, extension_name); |
| 1452 |
settings = e_source_camel_get_settings (extension); |
| 1453 |
|
| 1454 |
action_name = g_action_get_name (G_ACTION (action)); |
| 1455 |
folder_type = E_EWS_FOLDER_TYPE_MAILBOX; |
| 1456 |
if (strstr (action_name, "calendar") != NULL) |
| 1457 |
folder_type = E_EWS_FOLDER_TYPE_CALENDAR; |
| 1458 |
else if (strstr (action_name, "contacts") != NULL) |
| 1459 |
folder_type = E_EWS_FOLDER_TYPE_CONTACTS; |
| 1460 |
else if (strstr (action_name, "tasks") != NULL) |
| 1461 |
folder_type = E_EWS_FOLDER_TYPE_TASKS; |
| 1462 |
|
| 1463 |
e_ews_edit_folder_permissions ( |
| 1464 |
NULL, |
| 1465 |
registry, |
| 1466 |
source, |
| 1467 |
CAMEL_EWS_SETTINGS (settings), |
| 1468 |
e_source_get_display_name (parent_source), |
| 1469 |
e_source_get_display_name (source), |
| 1470 |
folder_id, |
| 1471 |
folder_type); |
| 1472 |
|
| 1473 |
g_object_unref (source); |
| 1474 |
g_object_unref (parent_source); |
| 1475 |
g_object_unref (registry); |
| 1476 |
e_ews_folder_id_free (folder_id); |
| 1477 |
} |
| 1478 |
|
| 1479 |
static void |
| 1480 |
ews_ui_init_calendar (EShellView *shell_view) |
| 1481 |
{ |
| 1482 |
static const gchar *eui = |
| 1483 |
"<eui>" |
| 1484 |
"<menu id='main-menu'>" |
| 1485 |
"<submenu action='file-menu'>" |
| 1486 |
"<placeholder id='long-running-actions'>" |
| 1487 |
"<item action='ews-calendar-global-subscribe-foreign-folder'/>" |
| 1488 |
"</placeholder>" |
| 1489 |
"</submenu>" |
| 1490 |
"</menu>" |
| 1491 |
"<menu id='calendar-popup'>" |
| 1492 |
"<placeholder id='calendar-popup-actions'>" |
| 1493 |
"<item action='calendar-ews-folder-permissions'/>" |
| 1494 |
"</placeholder>" |
| 1495 |
"</menu>" |
| 1496 |
"</eui>"; |
| 1497 |
|
| 1498 |
static const EUIActionEntry entries[] = { |
| 1499 |
{ "calendar-ews-folder-permissions", |
| 1500 |
"folder-new", |
| 1501 |
N_("Permissions…"), |
| 1502 |
NULL, |
| 1503 |
N_("Edit EWS calendar permissions"), |
| 1504 |
action_folder_permissions_source_cb, NULL, NULL, NULL } |
| 1505 |
}; |
| 1506 |
|
| 1507 |
setup_ews_source_actions (shell_view, entries, G_N_ELEMENTS (entries), eui); |
| 1508 |
} |
| 1509 |
|
| 1510 |
static void |
| 1511 |
ews_ui_init_tasks (EShellView *shell_view) |
| 1512 |
{ |
| 1513 |
static const gchar *eui = |
| 1514 |
"<eui>" |
| 1515 |
"<menu id='main-menu'>" |
| 1516 |
"<submenu action='file-menu'>" |
| 1517 |
"<placeholder id='long-running-actions'>" |
| 1518 |
"<item action='ews-task-global-subscribe-foreign-folder'/>" |
| 1519 |
"</placeholder>" |
| 1520 |
"</submenu>" |
| 1521 |
"</menu>" |
| 1522 |
"<menu id='task-list-popup'>" |
| 1523 |
"<placeholder id='task-list-popup-actions'>" |
| 1524 |
"<item action='tasks-ews-folder-permissions'/>" |
| 1525 |
"</placeholder>" |
| 1526 |
"</menu>" |
| 1527 |
"</eui>"; |
| 1528 |
|
| 1529 |
static EUIActionEntry entries[] = { |
| 1530 |
{ "tasks-ews-folder-permissions", |
| 1531 |
"folder-new", |
| 1532 |
N_("Permissions…"), |
| 1533 |
NULL, |
| 1534 |
N_("Edit EWS tasks permissions"), |
| 1535 |
action_folder_permissions_source_cb, NULL, NULL, NULL } |
| 1536 |
}; |
| 1537 |
|
| 1538 |
setup_ews_source_actions (shell_view, entries, G_N_ELEMENTS (entries), eui); |
| 1539 |
} |
| 1540 |
|
| 1541 |
static void |
| 1542 |
ews_ui_init_memos (EShellView *shell_view) |
| 1543 |
{ |
| 1544 |
static const gchar *eui = |
| 1545 |
"<eui>" |
| 1546 |
"<menu id='main-menu'>" |
| 1547 |
"<submenu action='file-menu'>" |
| 1548 |
"<placeholder id='long-running-actions'>" |
| 1549 |
"<item action='ews-memo-global-subscribe-foreign-folder'/>" |
| 1550 |
"</placeholder>" |
| 1551 |
"</submenu>" |
| 1552 |
"</menu>" |
| 1553 |
"<menu id='memo-list-popup'>" |
| 1554 |
"<placeholder id='memo-list-popup-actions'>" |
| 1555 |
"<item action='memos-ews-folder-permissions'/>" |
| 1556 |
"</placeholder>" |
| 1557 |
"</menu>" |
| 1558 |
"</eui>"; |
| 1559 |
|
| 1560 |
static const EUIActionEntry entries[] = { |
| 1561 |
{ "memos-ews-folder-permissions", |
| 1562 |
"folder-new", |
| 1563 |
N_("Permissions…"), |
| 1564 |
NULL, |
| 1565 |
N_("Edit EWS memos permissions"), |
| 1566 |
action_folder_permissions_source_cb, NULL, NULL, NULL } |
| 1567 |
}; |
| 1568 |
|
| 1569 |
setup_ews_source_actions (shell_view, entries, G_N_ELEMENTS (entries), eui); |
| 1570 |
} |
| 1571 |
|
| 1572 |
static void |
| 1573 |
ews_ui_init_contacts (EShellView *shell_view) |
| 1574 |
{ |
| 1575 |
static const gchar *eui = |
| 1576 |
"<eui>" |
| 1577 |
"<menu id='main-menu'>" |
| 1578 |
"<submenu action='file-menu'>" |
| 1579 |
"<placeholder id='long-running-actions'>" |
| 1580 |
"<item action='ews-contact-global-subscribe-foreign-folder'/>" |
| 1581 |
"</placeholder>" |
| 1582 |
"</submenu>" |
| 1583 |
"</menu>" |
| 1584 |
"<menu id='address-book-popup'>" |
| 1585 |
"<placeholder id='address-book-popup-actions'>" |
| 1586 |
"<item action='contacts-ews-folder-permissions'/>" |
| 1587 |
"</placeholder>" |
| 1588 |
"</menu>" |
| 1589 |
"</eui>"; |
| 1590 |
|
| 1591 |
static const EUIActionEntry entries[] = { |
| 1592 |
{ "contacts-ews-folder-permissions", |
| 1593 |
"folder-new", |
| 1594 |
N_("Permissions…"), |
| 1595 |
NULL, |
| 1596 |
N_("Edit EWS contacts permissions"), |
| 1597 |
action_folder_permissions_source_cb, NULL, NULL, NULL } |
| 1598 |
}; |
| 1599 |
|
| 1600 |
setup_ews_source_actions (shell_view, entries, G_N_ELEMENTS (entries), eui); |
| 1601 |
} |
| 1602 |
|
| 1603 |
void |
| 1604 |
e_ews_config_utils_init_ui (EShellView *shell_view, |
| 1605 |
const gchar *ui_manager_id) |
| 1606 |
{ |
| 1607 |
g_return_if_fail (shell_view != NULL); |
| 1608 |
g_return_if_fail (ui_manager_id != NULL); |
| 1609 |
|
| 1610 |
if (g_strcmp0 (ui_manager_id, "org.gnome.evolution.mail") == 0) |
| 1611 |
ews_ui_init_mail (shell_view); |
| 1612 |
else if (g_strcmp0 (ui_manager_id, "org.gnome.evolution.calendars") == 0) |
| 1613 |
ews_ui_init_calendar (shell_view); |
| 1614 |
else if (g_strcmp0 (ui_manager_id, "org.gnome.evolution.tasks") == 0) |
| 1615 |
ews_ui_init_tasks (shell_view); |
| 1616 |
else if (g_strcmp0 (ui_manager_id, "org.gnome.evolution.memos") == 0) |
| 1617 |
ews_ui_init_memos (shell_view); |
| 1618 |
else if (g_strcmp0 (ui_manager_id, "org.gnome.evolution.contacts") == 0) |
| 1619 |
ews_ui_init_contacts (shell_view); |
| 1620 |
} |
| 1621 |
|
| 1622 |
gboolean |
| 1623 |
e_ews_config_utils_is_online (void) |
| 1624 |
{ |
| 1625 |
EShell *shell; |
| 1626 |
|
| 1627 |
shell = e_shell_get_default (); |
| 1628 |
|
| 1629 |
return shell && e_shell_get_online (shell); |
| 1630 |
} |
| 1631 |
|
| 1632 |
GtkWindow * |
| 1633 |
e_ews_config_utils_get_widget_toplevel_window (GtkWidget *widget) |
| 1634 |
{ |
| 1635 |
if (!widget) |
| 1636 |
return NULL; |
| 1637 |
|
| 1638 |
if (!GTK_IS_WINDOW (widget)) |
| 1639 |
widget = gtk_widget_get_toplevel (widget); |
| 1640 |
|
| 1641 |
if (GTK_IS_WINDOW (widget)) |
| 1642 |
return GTK_WINDOW (widget); |
| 1643 |
|
| 1644 |
return NULL; |
| 1645 |
} |
| 1646 |
|
| 1647 |
static gpointer |
| 1648 |
ews_config_utils_unref_in_thread (gpointer user_data) |
| 1649 |
{ |
| 1650 |
g_object_unref (user_data); |
| 1651 |
|
| 1652 |
return NULL; |
| 1653 |
} |
| 1654 |
|
| 1655 |
void |
| 1656 |
e_ews_config_utils_unref_in_thread (GObject *object) |
| 1657 |
{ |
| 1658 |
GThread *thread; |
| 1659 |
|
| 1660 |
g_return_if_fail (object != NULL); |
| 1661 |
g_return_if_fail (G_IS_OBJECT (object)); |
| 1662 |
|
| 1663 |
thread = g_thread_new (NULL, ews_config_utils_unref_in_thread, object); |
| 1664 |
g_thread_unref (thread); |
| 1665 |
} |