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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
|
/*
* e-task-shell-sidebar.c
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* 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 Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "e-task-shell-sidebar.h"
#include <string.h>
#include <glib/gi18n.h>
#include "e-util/e-util.h"
#include "calendar/gui/e-task-list-selector.h"
#include "calendar/gui/misc.h"
#define E_TASK_SHELL_SIDEBAR_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_TASK_SHELL_SIDEBAR, ETaskShellSidebarPrivate))
typedef struct _ConnectClosure ConnectClosure;
struct _ETaskShellSidebarPrivate {
GtkWidget *selector;
/* The default client is for ECalModel. It follows the
* sidebar's primary selection, even if the highlighted
* source is not selected. The tricky part is we don't
* update the property until the client is successfully
* opened. So the user first highlights a source, then
* sometime later we update our default-client property
* which is bound by an EBinding to ECalModel. */
EClient *default_client;
/* Not referenced, only for pointer comparison. */
ESource *connecting_default_source_instance;
EActivity *connecting_default_client;
};
struct _ConnectClosure {
ETaskShellSidebar *task_shell_sidebar;
EActivity *activity;
/* For error messages. */
gchar *unique_display_name;
};
enum {
PROP_0,
PROP_DEFAULT_CLIENT,
PROP_SELECTOR
};
enum {
CLIENT_ADDED,
CLIENT_REMOVED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
G_DEFINE_DYNAMIC_TYPE (
ETaskShellSidebar,
e_task_shell_sidebar,
E_TYPE_SHELL_SIDEBAR)
static ConnectClosure *
connect_closure_new (ETaskShellSidebar *task_shell_sidebar,
ESource *source)
{
ConnectClosure *closure;
EAlertSink *alert_sink;
GCancellable *cancellable;
ESourceRegistry *registry;
ESourceSelector *selector;
EShellView *shell_view;
EShellBackend *shell_backend;
EShellContent *shell_content;
EShellSidebar *shell_sidebar;
gchar *text;
shell_sidebar = E_SHELL_SIDEBAR (task_shell_sidebar);
shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
shell_backend = e_shell_view_get_shell_backend (shell_view);
shell_content = e_shell_view_get_shell_content (shell_view);
selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
registry = e_source_selector_get_registry (selector);
closure = g_slice_new0 (ConnectClosure);
closure->task_shell_sidebar = g_object_ref (task_shell_sidebar);
closure->activity = e_activity_new ();
closure->unique_display_name =
e_source_registry_dup_unique_display_name (
registry, source, E_SOURCE_EXTENSION_TASK_LIST);
text = g_strdup_printf (
_("Opening task list '%s'"),
closure->unique_display_name);
e_activity_set_text (closure->activity, text);
g_free (text);
alert_sink = E_ALERT_SINK (shell_content);
e_activity_set_alert_sink (closure->activity, alert_sink);
cancellable = g_cancellable_new ();
e_activity_set_cancellable (closure->activity, cancellable);
g_object_unref (cancellable);
e_shell_backend_add_activity (shell_backend, closure->activity);
return closure;
}
static void
connect_closure_free (ConnectClosure *closure)
{
g_clear_object (&closure->task_shell_sidebar);
g_clear_object (&closure->activity);
g_free (closure->unique_display_name);
g_slice_free (ConnectClosure, closure);
}
static gboolean
task_shell_sidebar_map_uid_to_source (GValue *value,
GVariant *variant,
gpointer user_data)
{
ESourceRegistry *registry;
ESource *source;
const gchar *uid;
registry = E_SOURCE_REGISTRY (user_data);
uid = g_variant_get_string (variant, NULL);
if (uid != NULL && *uid != '\0')
source = e_source_registry_ref_source (registry, uid);
else
source = e_source_registry_ref_default_task_list (registry);
g_value_take_object (value, source);
return (source != NULL);
}
static GVariant *
task_shell_sidebar_map_source_to_uid (const GValue *value,
const GVariantType *expected_type,
gpointer user_data)
{
GVariant *variant = NULL;
ESource *source;
source = g_value_get_object (value);
if (source != NULL) {
const gchar *uid;
uid = e_source_get_uid (source);
variant = g_variant_new_string (uid);
}
return variant;
}
static void
task_shell_sidebar_emit_client_added (ETaskShellSidebar *task_shell_sidebar,
EClient *client)
{
guint signal_id = signals[CLIENT_ADDED];
g_signal_emit (task_shell_sidebar, signal_id, 0, client);
}
static void
task_shell_sidebar_emit_client_removed (ETaskShellSidebar *task_shell_sidebar,
EClient *client)
{
guint signal_id = signals[CLIENT_REMOVED];
g_signal_emit (task_shell_sidebar, signal_id, 0, client);
}
static void
task_shell_sidebar_handle_connect_error (EActivity *activity,
const gchar *unique_display_name,
const GError *error)
{
EAlertSink *alert_sink;
gboolean offline_error;
alert_sink = e_activity_get_alert_sink (activity);
offline_error = g_error_matches (
error, E_CLIENT_ERROR, E_CLIENT_ERROR_REPOSITORY_OFFLINE);
if (e_activity_handle_cancellation (activity, error)) {
/* do nothing */
} else if (offline_error) {
e_alert_submit (
alert_sink,
"calendar:prompt-no-contents-offline-tasks",
unique_display_name,
NULL);
} else {
e_alert_submit (
alert_sink,
"calendar:failed-open-tasks",
unique_display_name,
error->message,
NULL);
}
}
static void
task_shell_sidebar_client_connect_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
EClient *client;
ConnectClosure *closure = user_data;
GError *error = NULL;
client = e_client_selector_get_client_finish (
E_CLIENT_SELECTOR (source_object), result, &error);
/* Sanity check. */
g_return_if_fail (
((client != NULL) && (error == NULL)) ||
((client == NULL) && (error != NULL)));
if (error != NULL) {
task_shell_sidebar_handle_connect_error (
closure->activity,
closure->unique_display_name,
error);
g_error_free (error);
goto exit;
}
e_activity_set_state (closure->activity, E_ACTIVITY_COMPLETED);
e_task_shell_sidebar_add_client (closure->task_shell_sidebar, client);
g_object_unref (client);
exit:
connect_closure_free (closure);
}
static void
task_shell_sidebar_default_connect_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
EClient *client;
ESource *source;
ConnectClosure *closure = user_data;
ETaskShellSidebarPrivate *priv;
GError *error = NULL;
priv = E_TASK_SHELL_SIDEBAR_GET_PRIVATE (closure->task_shell_sidebar);
client = e_client_selector_get_client_finish (
E_CLIENT_SELECTOR (source_object), result, &error);
/* Sanity check. */
g_return_if_fail (
((client != NULL) && (error == NULL)) ||
((client == NULL) && (error != NULL)));
g_clear_object (&priv->connecting_default_client);
if (error != NULL) {
task_shell_sidebar_handle_connect_error (
closure->activity,
closure->unique_display_name,
error);
g_error_free (error);
goto exit;
}
e_activity_set_state (closure->activity, E_ACTIVITY_COMPLETED);
source = e_client_get_source (client);
if (source == priv->connecting_default_source_instance)
priv->connecting_default_source_instance = NULL;
if (priv->default_client != NULL)
g_object_unref (priv->default_client);
priv->default_client = g_object_ref (client);
g_object_notify (
G_OBJECT (closure->task_shell_sidebar), "default-client");
g_object_unref (client);
exit:
connect_closure_free (closure);
}
static void
task_shell_sidebar_set_default (ETaskShellSidebar *task_shell_sidebar,
ESource *source)
{
ETaskShellSidebarPrivate *priv;
ESourceSelector *selector;
ConnectClosure *closure;
priv = task_shell_sidebar->priv;
selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
/* already loading that source as default source */
if (source == priv->connecting_default_source_instance)
return;
/* Cancel the previous request if unfinished. */
if (priv->connecting_default_client != NULL) {
e_activity_cancel (priv->connecting_default_client);
g_object_unref (priv->connecting_default_client);
priv->connecting_default_client = NULL;
}
closure = connect_closure_new (task_shell_sidebar, source);
/* it's only for pointer comparison, no need to ref it */
priv->connecting_default_source_instance = source;
priv->connecting_default_client = g_object_ref (closure->activity);
e_client_selector_get_client (
E_CLIENT_SELECTOR (selector), source,
e_activity_get_cancellable (closure->activity),
task_shell_sidebar_default_connect_cb, closure);
}
static void
task_shell_sidebar_row_changed_cb (ETaskShellSidebar *task_shell_sidebar,
GtkTreePath *tree_path,
GtkTreeIter *tree_iter,
GtkTreeModel *tree_model)
{
ESourceSelector *selector;
ESource *source;
selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
source = e_source_selector_ref_source_by_path (selector, tree_path);
/* XXX This signal gets emitted a lot while the model is being
* rebuilt, during which time we won't get a valid ESource.
* ESourceSelector should probably block this signal while
* rebuilding the model, but we'll be forgiving and not
* emit a warning. */
if (source == NULL)
return;
if (e_source_selector_source_is_selected (selector, source))
e_task_shell_sidebar_add_source (task_shell_sidebar, source);
else
e_task_shell_sidebar_remove_source (task_shell_sidebar, source);
g_object_unref (source);
}
static void
task_shell_sidebar_primary_selection_changed_cb (ETaskShellSidebar *task_shell_sidebar,
ESourceSelector *selector)
{
ESource *source;
source = e_source_selector_ref_primary_selection (selector);
if (source == NULL)
return;
task_shell_sidebar_set_default (task_shell_sidebar, source);
g_object_unref (source);
}
static void
task_shell_sidebar_restore_state_cb (EShellWindow *shell_window,
EShellView *shell_view,
EShellSidebar *shell_sidebar)
{
ETaskShellSidebarPrivate *priv;
ESourceRegistry *registry;
ESourceSelector *selector;
GSettings *settings;
GtkTreeModel *model;
priv = E_TASK_SHELL_SIDEBAR_GET_PRIVATE (shell_sidebar);
selector = E_SOURCE_SELECTOR (priv->selector);
registry = e_source_selector_get_registry (selector);
model = gtk_tree_view_get_model (GTK_TREE_VIEW (selector));
g_signal_connect_swapped (
registry, "source-removed",
G_CALLBACK (e_task_shell_sidebar_remove_source), shell_sidebar);
g_signal_connect_swapped (
model, "row-changed",
G_CALLBACK (task_shell_sidebar_row_changed_cb),
shell_sidebar);
g_signal_connect_swapped (
selector, "primary-selection-changed",
G_CALLBACK (task_shell_sidebar_primary_selection_changed_cb),
shell_sidebar);
/* This will trigger our "row-changed" signal handler for each
* task list source, so the appropriate ECalClients get added to
* the ECalModel, which will then create view objects to display
* the task list content. This all happens asynchronously. */
e_source_selector_update_all_rows (selector);
/* Bind GObject properties to settings keys. */
settings = g_settings_new ("org.gnome.evolution.calendar");
g_settings_bind_with_mapping (
settings, "primary-tasks",
selector, "primary-selection",
G_SETTINGS_BIND_DEFAULT,
task_shell_sidebar_map_uid_to_source,
task_shell_sidebar_map_source_to_uid,
g_object_ref (registry),
(GDestroyNotify) g_object_unref);
g_object_unref (settings);
}
static void
task_shell_sidebar_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_DEFAULT_CLIENT:
g_value_set_object (
value,
e_task_shell_sidebar_get_default_client (
E_TASK_SHELL_SIDEBAR (object)));
return;
case PROP_SELECTOR:
g_value_set_object (
value,
e_task_shell_sidebar_get_selector (
E_TASK_SHELL_SIDEBAR (object)));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
task_shell_sidebar_dispose (GObject *object)
{
ETaskShellSidebarPrivate *priv;
priv = E_TASK_SHELL_SIDEBAR_GET_PRIVATE (object);
if (priv->selector != NULL) {
g_object_unref (priv->selector);
priv->selector = NULL;
}
if (priv->default_client != NULL) {
g_object_unref (priv->default_client);
priv->default_client = NULL;
}
if (priv->connecting_default_client != NULL) {
e_activity_cancel (priv->connecting_default_client);
g_object_unref (priv->connecting_default_client);
priv->connecting_default_client = NULL;
}
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_task_shell_sidebar_parent_class)->dispose (object);
}
static void
task_shell_sidebar_constructed (GObject *object)
{
ETaskShellSidebarPrivate *priv;
EShell *shell;
EShellView *shell_view;
EShellWindow *shell_window;
EShellSidebar *shell_sidebar;
EClientCache *client_cache;
GtkContainer *container;
GtkWidget *widget;
AtkObject *a11y;
priv = E_TASK_SHELL_SIDEBAR_GET_PRIVATE (object);
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (e_task_shell_sidebar_parent_class)->constructed (object);
shell_sidebar = E_SHELL_SIDEBAR (object);
shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
shell_window = e_shell_view_get_shell_window (shell_view);
shell = e_shell_window_get_shell (shell_window);
container = GTK_CONTAINER (shell_sidebar);
widget = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (
GTK_SCROLLED_WINDOW (widget),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (
GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN);
gtk_container_add (container, widget);
gtk_widget_show (widget);
container = GTK_CONTAINER (widget);
client_cache = e_shell_get_client_cache (shell);
widget = e_task_list_selector_new (client_cache, shell_view);
gtk_container_add (container, widget);
a11y = gtk_widget_get_accessible (widget);
atk_object_set_name (a11y, _("Task List Selector"));
priv->selector = g_object_ref (widget);
gtk_widget_show (widget);
/* Restore widget state from the last session once
* the shell view is fully initialized and visible. */
g_signal_connect (
shell_window, "shell-view-created::tasks",
G_CALLBACK (task_shell_sidebar_restore_state_cb),
shell_sidebar);
}
static guint32
task_shell_sidebar_check_state (EShellSidebar *shell_sidebar)
{
ETaskShellSidebar *task_shell_sidebar;
ESourceSelector *selector;
ESourceRegistry *registry;
ESource *source;
gboolean is_writable = FALSE;
gboolean is_removable = FALSE;
gboolean is_remote_creatable = FALSE;
gboolean is_remote_deletable = FALSE;
gboolean in_collection = FALSE;
gboolean refresh_supported = FALSE;
gboolean has_primary_source = FALSE;
guint32 state = 0;
task_shell_sidebar = E_TASK_SHELL_SIDEBAR (shell_sidebar);
selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
source = e_source_selector_ref_primary_selection (selector);
registry = e_source_selector_get_registry (selector);
if (source != NULL) {
EClient *client;
ESource *collection;
has_primary_source = TRUE;
is_writable = e_source_get_writable (source);
is_removable = e_source_get_removable (source);
is_remote_creatable = e_source_get_remote_creatable (source);
is_remote_deletable = e_source_get_remote_deletable (source);
collection = e_source_registry_find_extension (
registry, source, E_SOURCE_EXTENSION_COLLECTION);
if (collection != NULL) {
in_collection = TRUE;
g_object_unref (collection);
}
client = e_client_selector_ref_cached_client (
E_CLIENT_SELECTOR (selector), source);
if (client != NULL) {
refresh_supported =
e_client_check_refresh_supported (client);
g_object_unref (client);
}
g_object_unref (source);
}
if (has_primary_source)
state |= E_TASK_SHELL_SIDEBAR_HAS_PRIMARY_SOURCE;
if (is_writable)
state |= E_TASK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_WRITABLE;
if (is_removable)
state |= E_TASK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_REMOVABLE;
if (is_remote_creatable)
state |= E_TASK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_REMOTE_CREATABLE;
if (is_remote_deletable)
state |= E_TASK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_REMOTE_DELETABLE;
if (in_collection)
state |= E_TASK_SHELL_SIDEBAR_PRIMARY_SOURCE_IN_COLLECTION;
if (refresh_supported)
state |= E_TASK_SHELL_SIDEBAR_SOURCE_SUPPORTS_REFRESH;
return state;
}
static void
task_shell_sidebar_client_removed (ETaskShellSidebar *task_shell_sidebar,
ECalClient *client)
{
ESourceSelector *selector;
ESource *source;
source = e_client_get_source (E_CLIENT (client));
selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
e_source_selector_unselect_source (selector, source);
}
static void
e_task_shell_sidebar_class_init (ETaskShellSidebarClass *class)
{
GObjectClass *object_class;
EShellSidebarClass *shell_sidebar_class;
g_type_class_add_private (class, sizeof (ETaskShellSidebarPrivate));
object_class = G_OBJECT_CLASS (class);
object_class->get_property = task_shell_sidebar_get_property;
object_class->dispose = task_shell_sidebar_dispose;
object_class->constructed = task_shell_sidebar_constructed;
shell_sidebar_class = E_SHELL_SIDEBAR_CLASS (class);
shell_sidebar_class->check_state = task_shell_sidebar_check_state;
class->client_removed = task_shell_sidebar_client_removed;
g_object_class_install_property (
object_class,
PROP_DEFAULT_CLIENT,
g_param_spec_object (
"default-client",
"Default Task ECalClient",
"Default client for task operations",
E_TYPE_CAL_CLIENT,
G_PARAM_READABLE));
g_object_class_install_property (
object_class,
PROP_SELECTOR,
g_param_spec_object (
"selector",
"Source Selector Widget",
"This widget displays groups of task lists",
E_TYPE_SOURCE_SELECTOR,
G_PARAM_READABLE));
signals[CLIENT_ADDED] = g_signal_new (
"client-added",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ETaskShellSidebarClass, client_added),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
E_TYPE_CAL_CLIENT);
signals[CLIENT_REMOVED] = g_signal_new (
"client-removed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ETaskShellSidebarClass, client_removed),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
E_TYPE_CAL_CLIENT);
}
static void
e_task_shell_sidebar_class_finalize (ETaskShellSidebarClass *class)
{
}
static void
e_task_shell_sidebar_init (ETaskShellSidebar *task_shell_sidebar)
{
task_shell_sidebar->priv =
E_TASK_SHELL_SIDEBAR_GET_PRIVATE (task_shell_sidebar);
/* Postpone widget construction until we have a shell view. */
}
void
e_task_shell_sidebar_type_register (GTypeModule *type_module)
{
/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
* function, so we have to wrap it with a public function in
* order to register types from a separate compilation unit. */
e_task_shell_sidebar_register_type (type_module);
}
GtkWidget *
e_task_shell_sidebar_new (EShellView *shell_view)
{
g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
return g_object_new (
E_TYPE_TASK_SHELL_SIDEBAR,
"shell-view", shell_view, NULL);
}
ECalClient *
e_task_shell_sidebar_get_default_client (ETaskShellSidebar *task_shell_sidebar)
{
g_return_val_if_fail (
E_IS_TASK_SHELL_SIDEBAR (task_shell_sidebar), NULL);
return (ECalClient *) task_shell_sidebar->priv->default_client;
}
ESourceSelector *
e_task_shell_sidebar_get_selector (ETaskShellSidebar *task_shell_sidebar)
{
g_return_val_if_fail (
E_IS_TASK_SHELL_SIDEBAR (task_shell_sidebar), NULL);
return E_SOURCE_SELECTOR (task_shell_sidebar->priv->selector);
}
void
e_task_shell_sidebar_add_client (ETaskShellSidebar *task_shell_sidebar,
EClient *client)
{
ESource *source;
ESourceSelector *selector;
g_return_if_fail (E_IS_TASK_SHELL_SIDEBAR (task_shell_sidebar));
g_return_if_fail (E_IS_CAL_CLIENT (client));
source = e_client_get_source (client);
selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
e_source_selector_select_source (selector, source);
task_shell_sidebar_emit_client_added (task_shell_sidebar, client);
}
void
e_task_shell_sidebar_add_source (ETaskShellSidebar *task_shell_sidebar,
ESource *source)
{
ESourceSelector *selector;
ConnectClosure *closure;
g_return_if_fail (E_IS_TASK_SHELL_SIDEBAR (task_shell_sidebar));
g_return_if_fail (E_IS_SOURCE (source));
selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
e_source_selector_select_source (selector, source);
closure = connect_closure_new (task_shell_sidebar, source);
e_client_selector_get_client (
E_CLIENT_SELECTOR (selector), source,
e_activity_get_cancellable (closure->activity),
task_shell_sidebar_client_connect_cb, closure);
}
void
e_task_shell_sidebar_remove_source (ETaskShellSidebar *task_shell_sidebar,
ESource *source)
{
ESourceSelector *selector;
EClient *client;
g_return_if_fail (E_IS_TASK_SHELL_SIDEBAR (task_shell_sidebar));
g_return_if_fail (E_IS_SOURCE (source));
selector = e_task_shell_sidebar_get_selector (task_shell_sidebar);
client = e_client_selector_ref_cached_client (
E_CLIENT_SELECTOR (selector), source);
if (client != NULL) {
task_shell_sidebar_emit_client_removed (
task_shell_sidebar, client);
g_object_unref (client);
}
}
|