gtd-window.c 21.3 KB
Newer Older
1 2
/* gtd-window.c
 *
3
 * Copyright (C) 2015-2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */

19 20
#define G_LOG_DOMAIN "GtdWindow"

21 22
#include "config.h"

23
#include "interfaces/gtd-activatable.h"
24
#include "interfaces/gtd-provider.h"
25
#include "interfaces/gtd-panel.h"
26
#include "interfaces/gtd-workspace.h"
27
#include "widgets/gtd-menu-button.h"
28
#include "gtd-application.h"
29
#include "gtd-debug.h"
30
#include "gtd-enum-types.h"
31
#include "gtd-task-list-view.h"
32
#include "gtd-manager.h"
33
#include "gtd-manager-protected.h"
34 35
#include "gtd-notification.h"
#include "gtd-notification-widget.h"
36
#include "gtd-omni-area.h"
37
#include "gtd-plugin-manager.h"
38
#include "gtd-task.h"
39
#include "gtd-task-list.h"
40
#include "gtd-window.h"
41
#include "gtd-window-private.h"
42

43
#include <glib/gi18n.h>
44
#include <libpeas/peas.h>
45

46 47 48 49 50 51 52 53 54 55 56 57 58
/**
 * SECTION:gtd-window
 * @short_description:main window
 * @title:GtdWindow
 * @stability:Unstable
 * @see_also:#GtdNotification
 *
 * The #GtdWindow is the main application window of GNOME To Do. Objects should
 * use this class to send notifications (see gtd_window_notify()), cancel notifications
 * (see gtd_window_cancel_notification()), change between selection and normal mode
 * and fine-tune the headerbar.
 */

59
struct _GtdWindow
60
{
61 62 63
  GtkApplicationWindow application;

  GtkHeaderBar       *headerbar;
64 65
  GtkWidget          *headerbar_box;
  GtkRevealer        *headerbar_overlay_revealer;
66
  GtkStack           *stack;
67 68
  GtkWidget          *workspace_box_end;
  GtkWidget          *workspace_box_start;
69 70
  GtkListBox         *workspaces_listbox;
  GtdMenuButton      *workspaces_menu_button;
71

72 73
  GtkEventController *overlay_motion_controller;

74
  GtdNotificationWidget *notification_widget;
75

76
  GPtrArray          *workspace_header_widgets;
77

78
  GtdWorkspace       *current_workspace;
79
  GListStore         *workspaces;
80

81 82
  PeasExtensionSet   *workspaces_set;

83
  guint               toggle_headerbar_revealer_id;
84
};
85

86
typedef struct
87
{
88 89 90 91
  GtdWindow          *window;
  gchar              *primary_text;
  gchar              *secondary_text;
} ErrorData;
92 93


94 95
G_DEFINE_TYPE (GtdWindow, gtd_window, GTK_TYPE_APPLICATION_WINDOW)

96 97 98
static gint             compare_workspaced_func                  (gconstpointer      a,
                                                                  gconstpointer      b,
                                                                  gpointer           user_data);
99

100 101 102 103 104 105 106 107 108 109
static void
setup_development_build (GtdWindow *self)
{
  GtkStyleContext *context;

  g_message (_("This is a development build of To Do. You may experience errors, wrong behaviors, "
               "and data loss."));

  context = gtk_widget_get_style_context (GTK_WIDGET (self));

110
  gtk_style_context_add_class (context, "devel");
111 112 113 114 115 116 117 118 119 120 121
}

static gboolean
is_development_build (void)
{
#ifdef DEVELOPMENT_BUILD
  return TRUE;
#else
  return FALSE;
#endif
}
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

static void
error_data_free (ErrorData *error_data)
{
  g_free (error_data->primary_text);
  g_free (error_data->secondary_text);
  g_free (error_data);
}

static void
error_message_notification_primary_action (GtdNotification *notification,
                                           gpointer         user_data)
{
  error_data_free (user_data);
}

static void
error_message_notification_secondary_action (GtdNotification *notification,
                                             gpointer         user_data)
{
  GtkWidget *message_dialog;
  ErrorData *data;

  data = user_data;
  message_dialog = gtk_message_dialog_new (GTK_WINDOW (data->window),
                                           GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                           GTK_MESSAGE_WARNING,
                                           GTK_BUTTONS_CLOSE,
                                           "%s",
                                           data->primary_text);

  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message_dialog),
                                            "%s",
                                            data->secondary_text);

157 158
  g_signal_connect (message_dialog,
                    "response",
159
                    G_CALLBACK (gtk_window_destroy),
160 161 162
                    NULL);

  gtk_widget_show (message_dialog);
163 164 165 166

  error_data_free (data);
}

167
static void
168
load_geometry (GtdWindow *self)
169
{
170 171
  GSettings *settings;
  GtkWindow *window;
172
  gboolean maximized;
173 174
  gint height;
  gint width;
175

176
  window = GTK_WINDOW (self);
177
  settings = gtd_manager_get_settings (gtd_manager_get_default ());
178

179
  maximized = g_settings_get_boolean (settings, "window-maximized");
180
  g_settings_get (settings, "window-size", "(ii)", &width, &height);
181

182
  gtk_window_set_default_size (window, width, height);
183 184

  if (maximized)
185
    gtk_window_maximize (window);
186 187
}

188
static void
189 190
add_workspace (GtdWindow    *self,
               GtdWorkspace *workspace)
191
{
192
  const gchar *workspace_id;
193

194
  workspace_id = gtd_workspace_get_id (workspace);
195

196
  gtk_stack_add_named (self->stack, GTK_WIDGET (workspace), workspace_id);
197 198 199 200 201 202 203 204 205 206 207 208 209 210
  g_list_store_insert_sorted (self->workspaces, workspace, compare_workspaced_func, self);
}

static void
remove_workspace (GtdWindow    *self,
                  GtdWorkspace *workspace)
{
  guint position;

  if (!g_list_store_find (self->workspaces, workspace, &position))
    return;

  gtk_container_remove (GTK_CONTAINER (self->stack), GTK_WIDGET (workspace));
  g_list_store_remove (self->workspaces, position);
211 212
}

213
static void
214
remove_all_workspace_header_widgets (GtdWindow *self)
215
{
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
  GtkWidget *parent;
  GtkWidget *widget;
  guint i;

  GTD_ENTRY;

  /* remove from the header */
  for (i = 0; i < self->workspace_header_widgets->len; i++)
    {
      widget = g_ptr_array_index (self->workspace_header_widgets, i);
      parent = gtk_widget_get_parent (widget);

      g_assert (parent == GTK_WIDGET (self->workspace_box_start) ||
                parent == GTK_WIDGET (self->workspace_box_end));
      gtk_container_remove (GTK_CONTAINER (parent), widget);
    }
232

233
  g_ptr_array_set_size (self->workspace_header_widgets, 0);
234

235
  GTD_EXIT;
236 237
}

238 239 240 241 242

/*
 * Callbacks
 */

243 244 245 246 247 248 249 250 251 252 253 254
static gboolean
toggle_headerbar_overlay_cb (gpointer user_data)
{
  GtdWindow *self = GTD_WINDOW (user_data);

  gtk_revealer_set_reveal_child (self->headerbar_overlay_revealer,
                                 !gtk_revealer_get_reveal_child (self->headerbar_overlay_revealer));

  self->toggle_headerbar_revealer_id = 0;

  return G_SOURCE_REMOVE;
}
255

256 257 258 259 260 261 262 263 264 265 266 267 268 269
static void
on_action_activate_workspace_activated_cb (GSimpleAction *simple,
                                           GVariant      *state,
                                           gpointer       user_data)
{
  GtdWindow *self;
  const gchar *workspace_id;

  self = GTD_WINDOW (user_data);
  workspace_id = g_variant_get_string (state, NULL);

  gtk_stack_set_visible_child_name (self->stack, workspace_id);
}

270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
static void
on_action_toggle_fullscreen_state_changed_cb (GSimpleAction *simple,
                                              GVariant      *state,
                                              gpointer       user_data)
{
  GtdWindow *self;
  gboolean fullscreen;

  self = GTD_WINDOW (user_data);
  fullscreen = g_variant_get_boolean (state);

  g_clear_handle_id (&self->toggle_headerbar_revealer_id, g_source_remove);

  gtk_header_bar_set_show_title_buttons (self->headerbar, !fullscreen);

  g_object_ref (self->headerbar);
  if (fullscreen)
    {
      gtk_event_controller_set_propagation_phase (self->overlay_motion_controller, GTK_PHASE_BUBBLE);
289
      gtk_container_remove (GTK_CONTAINER (self->headerbar_box), GTK_WIDGET (self->headerbar));
290
      gtk_revealer_set_child (self->headerbar_overlay_revealer, GTK_WIDGET (self->headerbar));
291 292 293 294 295 296 297 298
      gtk_revealer_set_reveal_child (self->headerbar_overlay_revealer, TRUE);
      gtk_window_fullscreen (GTK_WINDOW (self));

      self->toggle_headerbar_revealer_id = g_timeout_add_seconds (2, toggle_headerbar_overlay_cb, self);
    }
  else
    {
      gtk_event_controller_set_propagation_phase (self->overlay_motion_controller, GTK_PHASE_NONE);
299 300
      gtk_revealer_set_child (self->headerbar_overlay_revealer, NULL);
      gtk_revealer_set_reveal_child (self->headerbar_overlay_revealer, FALSE);
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
      gtk_container_add (GTK_CONTAINER (self->headerbar_box), GTK_WIDGET (self->headerbar));
      gtk_window_unfullscreen (GTK_WINDOW (self));
    }
  g_object_unref (self->headerbar);

  g_simple_action_set_state (simple, state);
}

static void
on_overlay_motion_controller_motion_cb (GtkEventControllerMotion *controller,
                                        gdouble                   x,
                                        gdouble                   y,
                                        GtdWindow                *self)
{
  const gint y_threashold = 5;
  GtkWidget *hovered_widget;

  hovered_widget = gtk_widget_pick (GTK_WIDGET (self), x, y, GTK_PICK_DEFAULT);

  /* Show headerbar when hovering it */
  if (hovered_widget &&
      gtk_widget_is_ancestor (hovered_widget, GTK_WIDGET (self->headerbar_overlay_revealer)))
    {
      gtk_revealer_set_reveal_child (self->headerbar_overlay_revealer, TRUE);
      g_clear_handle_id (&self->toggle_headerbar_revealer_id, g_source_remove);
      return;
    }

  if (y <= y_threashold)
    {
      gtk_revealer_set_reveal_child (self->headerbar_overlay_revealer, TRUE);
      g_clear_handle_id (&self->toggle_headerbar_revealer_id, g_source_remove);
    }
  else if (self->toggle_headerbar_revealer_id == 0 &&
           gtk_revealer_get_reveal_child (self->headerbar_overlay_revealer))
    {
      self->toggle_headerbar_revealer_id = g_timeout_add (500, toggle_headerbar_overlay_cb, self);
    }
}

341 342 343 344 345 346 347 348 349 350 351 352 353 354
static gint
compare_workspaced_func (gconstpointer a,
                         gconstpointer b,
                         gpointer      user_data)
{
  gint a_priority;
  gint b_priority;

  a_priority = gtd_workspace_get_priority ((GtdWorkspace *)a);
  b_priority = gtd_workspace_get_priority ((GtdWorkspace *)b);

  return b_priority - a_priority;
}

355
static void
356
on_stack_visible_child_cb (GtkStack   *stack,
357
                           GParamSpec *pspec,
358
                           GtdWindow  *self)
359
{
360
  g_autoptr (GIcon) workspace_icon = NULL;
361
  GtdWorkspace *new_workspace;
362

363
  GTD_ENTRY;
364

365
  remove_all_workspace_header_widgets (self);
366

367 368
  if (self->current_workspace)
    gtd_workspace_deactivate (self->current_workspace);
369

370 371
  new_workspace = GTD_WORKSPACE (gtk_stack_get_visible_child (stack));
  self->current_workspace = new_workspace;
372 373 374 375

  if (!new_workspace)
    GTD_RETURN ();

376
  gtd_workspace_activate (new_workspace);
377

378 379 380
  workspace_icon = gtd_workspace_get_icon (new_workspace);
  gtd_menu_button_set_gicon (self->workspaces_menu_button, workspace_icon);

381
  GTD_EXIT;
382 383
}

384
static void
385 386 387 388 389 390
on_show_error_message_cb (GtdManager                *manager,
                          const gchar               *primary_text,
                          const gchar               *secondary_text,
                          GtdNotificationActionFunc  function,
                          gpointer                   user_data,
                          GtdWindow                 *self)
391 392 393 394 395
{
  GtdNotification *notification;
  ErrorData *error_data;

  error_data = g_new0 (ErrorData, 1);
396
  notification = gtd_notification_new (primary_text, 7500);
397

398
  error_data->window = self;
399 400 401 402 403 404
  error_data->primary_text = g_strdup (primary_text);
  error_data->secondary_text = g_strdup (secondary_text);

  gtd_notification_set_primary_action (notification,
                                       error_message_notification_primary_action,
                                       error_data);
405

406 407 408 409 410 411 412
  if (!function)
    {
      gtd_notification_set_secondary_action (notification,
                                             _("Details"),
                                             error_message_notification_secondary_action,
                                             error_data);
    }
413
  else
414 415 416
    {
      gtd_notification_set_secondary_action (notification, secondary_text, function, user_data);
    }
417

418

419
  gtd_window_notify (self, notification);
420 421
}

422 423 424 425 426 427 428 429
static void
on_show_notification_cb (GtdManager      *manager,
                         GtdNotification *notification,
                         GtdWindow       *self)
{
  gtd_window_notify (self, notification);
}

430
static void
431 432 433 434
on_workspace_added_cb (PeasExtensionSet *extension_set,
                       PeasPluginInfo   *plugin_info,
                       GtdWorkspace     *workspace,
                       GtdWindow        *self)
435 436 437
{
  GTD_ENTRY;

438
  add_workspace (self, g_object_ref_sink (workspace));
439 440 441 442 443

  GTD_EXIT;
}

static void
444 445 446 447
on_workspace_removed_cb (PeasExtensionSet *extension_set,
                         PeasPluginInfo   *plugin_info,
                         GtdWorkspace     *workspace,
                         GtdWindow        *self)
448 449 450
{
  GTD_ENTRY;

451
  remove_workspace (self, workspace);
452 453 454 455

  GTD_EXIT;
}

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
static void
on_workspaces_listbox_row_activated_cb (GtkListBox    *workspaces_listbox,
                                        GtkListBoxRow *row,
                                        GtdWindow     *self)
{
  g_autoptr (GtdWorkspace) workspace = NULL;

  workspace = g_list_model_get_item (G_LIST_MODEL (self->workspaces),
                                     gtk_list_box_row_get_index (row));

  gtk_stack_set_visible_child (self->stack, GTK_WIDGET (workspace));

  gtd_menu_button_popdown (self->workspaces_menu_button);
}

static GtkWidget*
create_workspace_row_func (gpointer item,
                           gpointer user_data)
{
  GtkWidget *label;
  GtkWidget *image;
  GtkWidget *box;

  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
  gtk_widget_set_margin_start (box, 6);
  gtk_widget_set_margin_end (box, 6);
  gtk_widget_set_margin_top (box, 3);
  gtk_widget_set_margin_bottom (box, 3);

  image = gtk_image_new ();
  g_object_bind_property (item, "icon", image, "gicon", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);

  label = gtk_label_new ("");
  gtk_widget_set_hexpand (label, TRUE);
  gtk_label_set_xalign (GTK_LABEL (label), 0.0);
  g_object_bind_property (item, "title", label, "label", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);

  gtk_container_add (GTK_CONTAINER (box), image);
  gtk_container_add (GTK_CONTAINER (box), label);

  return box;
}

499 500 501 502 503

/*
 * GtkWindow overrides
 */

504 505
static void
gtd_window_unmap (GtkWidget *widget)
506
{
507 508
  GSettings *settings;
  GtkWindow *window;
509
  gboolean maximized;
510

511
  window = GTK_WINDOW (widget);
512 513
  settings = gtd_manager_get_settings (gtd_manager_get_default ());
  maximized = gtk_window_is_maximized (window);
514

515
  g_settings_set_boolean (settings, "window-maximized", maximized);
516

517 518 519 520
  if (!maximized)
    {
      gint height;
      gint width;
521

522 523 524
      gtk_window_get_size (window, &width, &height);
      g_settings_set (settings, "window-size", "(ii)", width, height);
    }
525

526 527
  GTK_WIDGET_CLASS (gtd_window_parent_class)->unmap (widget);
}
528 529 530 531 532

/*
 * GObject overrides
 */

533 534 535 536 537 538 539 540 541 542
static void
gtd_window_dispose (GObject *object)
{
  GtdWindow *self = GTD_WINDOW (object);

  g_clear_object (&self->workspaces_set);

  G_OBJECT_CLASS (gtd_window_parent_class)->dispose (object);
}

543
static void
544
gtd_window_finalize (GObject *object)
545 546 547
{
  GtdWindow *self = GTD_WINDOW (object);

548
  g_clear_handle_id (&self->toggle_headerbar_revealer_id, g_source_remove);
549 550
  g_clear_object (&self->workspaces);

551
  G_OBJECT_CLASS (gtd_window_parent_class)->finalize (object);
552 553
}

554 555 556
static void
gtd_window_constructed (GObject *object)
{
557
  GtdManager *manager;
558
  GtdWindow *self;
559

560 561
  self = GTD_WINDOW (object);

562 563
  G_OBJECT_CLASS (gtd_window_parent_class)->constructed (object);

564 565
  /* Load stored size */
  load_geometry (GTD_WINDOW (object));
566

567 568 569 570
  manager = gtd_manager_get_default ();
  g_signal_connect (manager, "show-error-message", G_CALLBACK (on_show_error_message_cb), self);
  g_signal_connect (manager, "show-notification", G_CALLBACK (on_show_notification_cb), self);

571
  /* Workspaces */
572 573 574
  self->workspaces_set = peas_extension_set_new (peas_engine_get_default (),
                                                 GTD_TYPE_WORKSPACE,
                                                 NULL);
575

576 577 578
  peas_extension_set_foreach (self->workspaces_set,
                              (PeasExtensionSetForeachFunc) on_workspace_added_cb,
                              self);
579

580 581 582 583
  g_object_connect (self->workspaces_set,
                    "signal::extension-added", G_CALLBACK (on_workspace_added_cb), self,
                    "signal::extension-removed", G_CALLBACK (on_workspace_removed_cb), self,
                    NULL);
584 585 586 587 588 589 590 591
}

static void
gtd_window_class_init (GtdWindowClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

592
  object_class->dispose = gtd_window_dispose;
593
  object_class->finalize = gtd_window_finalize;
594
  object_class->constructed = gtd_window_constructed;
595

596
  widget_class->unmap = gtd_window_unmap;
597

598
  g_type_ensure (GTD_TYPE_MENU_BUTTON);
599
  g_type_ensure (GTD_TYPE_NOTIFICATION_WIDGET);
600
  g_type_ensure (GTD_TYPE_OMNI_AREA);
601

602
  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/todo/ui/gtd-window.ui");
603

604
  gtk_widget_class_bind_template_child (widget_class, GtdWindow, headerbar);
605 606
  gtk_widget_class_bind_template_child (widget_class, GtdWindow, headerbar_box);
  gtk_widget_class_bind_template_child (widget_class, GtdWindow, headerbar_overlay_revealer);
607
  gtk_widget_class_bind_template_child (widget_class, GtdWindow, notification_widget);
608
  gtk_widget_class_bind_template_child (widget_class, GtdWindow, overlay_motion_controller);
609
  gtk_widget_class_bind_template_child (widget_class, GtdWindow, stack);
610 611
  gtk_widget_class_bind_template_child (widget_class, GtdWindow, workspace_box_end);
  gtk_widget_class_bind_template_child (widget_class, GtdWindow, workspace_box_start);
612 613
  gtk_widget_class_bind_template_child (widget_class, GtdWindow, workspaces_menu_button);
  gtk_widget_class_bind_template_child (widget_class, GtdWindow, workspaces_listbox);
614

615
  gtk_widget_class_bind_template_callback (widget_class, on_overlay_motion_controller_motion_cb);
616
  gtk_widget_class_bind_template_callback (widget_class, on_stack_visible_child_cb);
617
  gtk_widget_class_bind_template_callback (widget_class, on_workspaces_listbox_row_activated_cb);
618 619 620 621 622
}

static void
gtd_window_init (GtdWindow *self)
{
623 624
  static const GActionEntry entries[] = {
    { "activate-workspace", on_action_activate_workspace_activated_cb, "s" },
625
    { "toggle-fullscreen", NULL, NULL, "false", on_action_toggle_fullscreen_state_changed_cb },
626 627 628 629 630 631 632
  };

  g_action_map_add_action_entries (G_ACTION_MAP (self),
                                   entries,
                                   G_N_ELEMENTS (entries),
                                   self);

633
  self->workspace_header_widgets = g_ptr_array_new_with_free_func (g_object_unref);
634
  self->workspaces = g_list_store_new (GTD_TYPE_WORKSPACE);
635

636
  gtk_widget_init_template (GTK_WIDGET (self));
637

638 639 640 641 642 643
  gtk_list_box_bind_model (self->workspaces_listbox,
                           G_LIST_MODEL (self->workspaces),
                           create_workspace_row_func,
                           self,
                           NULL);

644 645 646
  /* Development build */
  if (is_development_build ())
    setup_development_build (self);
647
}
648

649 650
GtkWidget*
gtd_window_new (GtdApplication *application)
651
{
652 653 654
  return g_object_new (GTD_TYPE_WINDOW,
                       "application", application,
                       NULL);
655
}
656 657 658 659

/**
 * gtd_window_notify:
 * @window: a #GtdWindow
660
 * @notification: a #GtdNotification
661 662 663 664
 *
 * Shows a notification on the top of the main window.
 */
void
665
gtd_window_notify (GtdWindow       *self,
666
                   GtdNotification *notification)
667
{
668
  g_return_if_fail (GTD_IS_WINDOW (self));
669

670
  gtd_notification_widget_notify (self->notification_widget, notification);
671 672 673 674 675
}

/**
 * gtd_window_cancel_notification:
 * @window: a #GtdManager
676
 * @notification: a #GtdNotification
677
 *
678
 * Cancels @notification.
679 680
 */
void
681
gtd_window_cancel_notification (GtdWindow       *self,
682
                                GtdNotification *notification)
683
{
684
  g_return_if_fail (GTD_IS_WINDOW (self));
685

686
  gtd_notification_widget_cancel (self->notification_widget, notification);
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
/**
 * gtd_window_embed_widget_in_header:
 * @self: a #GtdWindow
 * @widget: a #GtkWidget
 * @position: either @GTK_POS_LEFT or @GTK_POS_RIGHT
 *
 * Embeds @widget into @self's header bar.
 */
void
gtd_window_embed_widget_in_header (GtdWindow       *self,
                                   GtkWidget       *widget,
                                   GtkPositionType  position)
{
  g_return_if_fail (GTD_IS_WINDOW (self));
  g_return_if_fail (GTK_IS_WIDGET (widget));

  GTD_ENTRY;

  /* add to header */
  switch (position)
    {
    case GTK_POS_RIGHT:
      gtk_container_add (GTK_CONTAINER (self->workspace_box_end), widget);
      break;

    case GTK_POS_LEFT:
      gtk_container_add (GTK_CONTAINER (self->workspace_box_start), widget);
      break;

    case GTK_POS_TOP:
    case GTK_POS_BOTTOM:
    default:
      g_warning ("Invalid position passed");
      return;
    }

  g_ptr_array_add (self->workspace_header_widgets, g_object_ref (widget));

  GTD_EXIT;

}