File: planner-task-view.c

package info (click to toggle)
planner 0.14.6-7
  • links: PTS
  • area: main
  • in suites: buster
  • size: 14,600 kB
  • sloc: ansic: 67,239; sh: 10,242; xml: 3,928; sql: 886; makefile: 665; python: 3
file content (821 lines) | stat: -rw-r--r-- 24,093 bytes parent folder | download | duplicates (2)
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
809
810
811
812
813
814
815
816
817
818
819
820
821
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2003-2005 Imendio AB
 * Copyright (C) 2002 CodeFactory AB
 * Copyright (C) 2002 Richard Hult <richard@imendio.com>
 * Copyright (C) 2002 Mikael Hallendal <micke@imendio.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <config.h>
#include <string.h>
#include <time.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <libplanner/mrp-task.h>
#include "planner-task-view.h"
#include "libplanner/mrp-paths.h"
#include "planner-conf.h"
#include "planner-cell-renderer-date.h"
#include "planner-task-dialog.h"
#include "planner-property-dialog.h"
#include "planner-gantt-model.h"
#include "planner-task-tree.h"
#include "planner-table-print-sheet.h"
#include "planner-column-dialog.h"


struct _PlannerTaskViewPriv {
	GtkWidget              *tree;
	GtkWidget              *frame;
	PlannerTablePrintSheet *print_sheet;
	GtkUIManager           *ui_manager;
	GtkActionGroup         *actions;
	guint                   merged_id;
};

static void          task_view_finalize                     (GObject         *object);
static void          task_view_activate                     (PlannerView     *view);
static void          task_view_deactivate                   (PlannerView     *view);
static void          task_view_setup                        (PlannerView     *view,
							     PlannerWindow   *main_window);
static const gchar  *task_view_get_label                    (PlannerView     *view);
static const gchar  *task_view_get_menu_label               (PlannerView     *view);
static const gchar  *task_view_get_icon                     (PlannerView     *view);
static const gchar  *task_view_get_name                     (PlannerView     *view);
static GtkWidget    *task_view_get_widget                   (PlannerView     *view);
static void          task_view_print_init                   (PlannerView     *view,
							     PlannerPrintJob *job);
static void          task_view_print                        (PlannerView     *view,
							     gint             page_nr);
static gint          task_view_print_get_n_pages            (PlannerView     *view);
static void          task_view_print_cleanup                (PlannerView     *view);
static void          task_view_tree_view_columns_changed_cb (GtkTreeView     *tree_view,
							     PlannerView     *view);
static void          task_view_tree_view_destroy_cb         (GtkTreeView     *tree_view,
							     PlannerView     *view);
static void          task_view_project_loaded_cb            (MrpProject      *project,
							     PlannerView     *view);
static void          task_view_insert_task_cb               (GtkAction       *action,
							     gpointer         data);
static void          task_view_insert_tasks_cb              (GtkAction       *action,
							     gpointer         data);
static void          task_view_remove_task_cb               (GtkAction       *action,
							     gpointer         data);
static void          task_view_edit_task_cb                 (GtkAction       *action,
							     gpointer         data);
static void          task_view_select_all_cb                (GtkAction       *action,
							     gpointer         data);
static void          task_view_unlink_task_cb               (GtkAction       *action,
							     gpointer         data);
static void          task_view_link_tasks_cb                (GtkAction       *action,
							     gpointer         data);
static void          task_view_indent_task_cb               (GtkAction       *action,
							     gpointer         data);
static void          task_view_move_task_up_cb              (GtkAction       *action,
							     gpointer         data);
static void          task_view_move_task_down_cb            (GtkAction       *action,
							     gpointer         data);
static void          task_view_unindent_task_cb             (GtkAction       *action,
							     gpointer         data);
static void          task_view_reset_constraint_cb          (GtkAction       *action,
							     gpointer         data);
static void          task_view_edit_custom_props_cb         (GtkAction       *action,
							     gpointer         data);
static void          task_view_highlight_critical_cb        (GtkAction       *action,
							     gpointer         data);
static void          task_view_nonstandard_days_cb          (GtkAction       *action,
							     gpointer         data);
static void          task_view_edit_columns_cb              (GtkAction       *action,
							     gpointer         data);
static void          task_view_selection_changed_cb         (PlannerTaskTree *tree,
							     PlannerView     *view);
static void          task_view_relations_changed_cb         (PlannerTaskTree *tree,
							     MrpTask         *task,
							     MrpRelation     *relation,
							     PlannerView     *view);
static void          task_view_update_ui                    (PlannerView     *view);
static void          task_view_save_columns                 (PlannerView     *view);
static void          task_view_load_columns                 (PlannerView     *view);


static PlannerViewClass *parent_class = NULL;

static const GtkActionEntry entries[] = {
	{ "InsertTask",      "planner-stock-insert-task",      N_("_Insert Task"),
	  "<Control>i",        N_("Insert a new task"),
          G_CALLBACK (task_view_insert_task_cb) },
	{ "InsertTasks",     "planner-stock-insert-task",      N_("In_sert Tasks..."),
	  NULL,                NULL,
	  G_CALLBACK (task_view_insert_tasks_cb) },
	{ "RemoveTask",      "planner-stock-remove-task",      N_("_Remove Task"),
	  "<Control>d",        N_("Remove the selected tasks"),
	  G_CALLBACK (task_view_remove_task_cb) },
	{ "EditTask",        NULL,                             N_("_Edit Task"),
	  "<Shift><Control>e", NULL,
	  G_CALLBACK (task_view_edit_task_cb) },
	{ "SelectAll",       NULL,                             N_("Select _All"),
	  "<Control>a",        N_("Select all tasks"),
	  G_CALLBACK (task_view_select_all_cb) },
	{ "UnlinkTask",      "planner-stock-unlink-task",      N_("_Unlink Task"),
	  NULL,                N_("Unlink the selected tasks"),
	  G_CALLBACK (task_view_unlink_task_cb) },
	{ "LinkTasks",       "planner-stock-link-task",        N_("_Link Tasks"),
	  NULL,                N_("Link the selected tasks"),
	  G_CALLBACK (task_view_link_tasks_cb) },
	{ "IndentTask",      "planner-stock-indent-task",      N_("I_ndent Task"),
	  "<Shift><Control>i", N_("Indent the selected tasks"),
	  G_CALLBACK (task_view_indent_task_cb) },
	{ "UnindentTask",    "planner-stock-unindent-task",    N_("Unin_dent Task"),
	  "<Shift><Control>u", N_("Unindent the selected tasks"),
	  G_CALLBACK (task_view_unindent_task_cb) },
	{ "MoveTaskUp",      "planner-stock-move-task-up",     N_("Move Task _Up"),
	  NULL,                N_("Move the selected tasks upwards"),
	  G_CALLBACK (task_view_move_task_up_cb) },
	{ "MoveTaskDown",    "planner-stock-move-task-down",   N_("Move Task Do_wn"),
	  NULL,                N_("Move the selected tasks downwards"),
	  G_CALLBACK (task_view_move_task_down_cb) },
	{ "ResetConstraint", "planner-stock-reset-constraint", N_("Reset _Constraint"),
          NULL,                NULL,
	  G_CALLBACK (task_view_reset_constraint_cb) },
	{ "EditCustomProps", GTK_STOCK_PROPERTIES,             N_("_Edit Custom Properties..."),
	  NULL,                NULL,
	  G_CALLBACK (task_view_edit_custom_props_cb) },
	{ "EditColumns",       NULL,                           N_("Edit _Visible Columns"),
	  NULL,                N_("Edit visible columns"),
	  G_CALLBACK (task_view_edit_columns_cb) }
};

static const GtkToggleActionEntry toggle_entries[] = {
	{ "HighlightCriticalTasks", NULL, N_("_Highlight Critical Tasks"), NULL, NULL,
	  G_CALLBACK (task_view_highlight_critical_cb), FALSE },
	{ "NonstandardDays", NULL, N_("_Nonstandard Days"), NULL, NULL,
	  G_CALLBACK (task_view_nonstandard_days_cb), FALSE }
};

#define CRITICAL_PATH_KEY  "highlight-critical-path"
#define NOSTDDAYS_PATH_KEY "display-nonstandard-days"

G_DEFINE_TYPE (PlannerTaskView, planner_task_view, PLANNER_TYPE_VIEW);


static void
planner_task_view_class_init (PlannerTaskViewClass *klass)
{
	GObjectClass     *o_class;
	PlannerViewClass *view_class;

	parent_class = g_type_class_peek_parent (klass);

	o_class = (GObjectClass *) klass;
	view_class = PLANNER_VIEW_CLASS (klass);

	o_class->finalize = task_view_finalize;

	view_class->setup = task_view_setup;
	view_class->get_label = task_view_get_label;
	view_class->get_menu_label = task_view_get_menu_label;
	view_class->get_icon = task_view_get_icon;
	view_class->get_name = task_view_get_name;
	view_class->get_widget = task_view_get_widget;
	view_class->activate = task_view_activate;
	view_class->deactivate = task_view_deactivate;
	view_class->print_init = task_view_print_init;
	view_class->print_get_n_pages = task_view_print_get_n_pages;
	view_class->print = task_view_print;
	view_class->print_cleanup = task_view_print_cleanup;
}

static void
planner_task_view_init (PlannerTaskView *view)
{
	view->priv = g_new0 (PlannerTaskViewPriv, 1);
}

static void
task_view_finalize (GObject *object)
{
	PlannerTaskView *view;

	view = PLANNER_TASK_VIEW (object);

	if (PLANNER_VIEW (view)->activated) {
		task_view_deactivate (PLANNER_VIEW (view));
	}

	g_free (view->priv);

	if (G_OBJECT_CLASS (parent_class)->finalize) {
		(*G_OBJECT_CLASS (parent_class)->finalize) (object);
	}
}

static void
task_view_activate (PlannerView *view)
{
	PlannerTaskViewPriv *priv;
	gboolean             show_critical;
	gboolean             show_nostd_days;
	gchar               *filename;

	priv = PLANNER_TASK_VIEW (view)->priv;

	priv->actions = gtk_action_group_new ("TaskView");
	gtk_action_group_set_translation_domain (priv->actions, GETTEXT_PACKAGE);

	gtk_action_group_add_actions (priv->actions, entries,
				      G_N_ELEMENTS (entries),
				      view);
	gtk_action_group_add_toggle_actions (priv->actions, toggle_entries,
					     G_N_ELEMENTS (toggle_entries),
					     view);

	gtk_ui_manager_insert_action_group (priv->ui_manager, priv->actions, 0);
	filename = mrp_paths_get_ui_dir ("task-view.ui");
	priv->merged_id = gtk_ui_manager_add_ui_from_file (priv->ui_manager,
							   filename,
							   NULL);
	g_free (filename);
	gtk_ui_manager_ensure_update (priv->ui_manager);

	/* Set the initial UI state. */
	show_critical =   planner_conf_get_bool (CRITICAL_PATH_KEY, "task");
	show_nostd_days = planner_conf_get_bool (NOSTDDAYS_PATH_KEY, "task");
	planner_task_tree_set_highlight_critical (PLANNER_TASK_TREE (priv->tree),
						  show_critical);
	planner_task_tree_set_nonstandard_days (PLANNER_TASK_TREE (priv->tree),
						show_nostd_days);

	gtk_toggle_action_set_active (
		GTK_TOGGLE_ACTION (gtk_action_group_get_action (priv->actions, "HighlightCriticalTasks")),
		show_critical);

	gtk_toggle_action_set_active (
		GTK_TOGGLE_ACTION (gtk_action_group_get_action (priv->actions, "NonstandardDays")),
		show_nostd_days);

	task_view_selection_changed_cb (PLANNER_TASK_TREE (priv->tree), view);

	gtk_widget_grab_focus (priv->tree);
}

static void
task_view_deactivate (PlannerView *view)
{
	PlannerTaskViewPriv *priv;

	priv = PLANNER_TASK_VIEW (view)->priv;
	gtk_ui_manager_remove_ui (priv->ui_manager, priv->merged_id);
	gtk_ui_manager_remove_action_group (priv->ui_manager, priv->actions);
	g_object_unref (priv->actions);
	priv->actions = NULL;
}

static void
task_view_setup (PlannerView *view, PlannerWindow *main_window)
{
	PlannerTaskViewPriv *priv;

	priv = PLANNER_TASK_VIEW (view)->priv;

	priv->ui_manager = planner_window_get_ui_manager (main_window);
}

static const gchar *
task_view_get_label (PlannerView *view)
{
	return _("Tasks");
}

static const gchar *
task_view_get_menu_label (PlannerView *view)
{
	return _("_Tasks");
}

static const gchar *
task_view_get_icon (PlannerView *view)
{
	static gchar *filename = NULL;

	if (!filename) {
		filename = mrp_paths_get_image_dir ("tasks.png");
	}

	return filename;
}

static const gchar *
task_view_get_name (PlannerView *view)
{
	return "task_view";
}

static GtkWidget *
task_view_get_widget (PlannerView *view)
{
	PlannerTaskViewPriv *priv;
	MrpProject          *project;
	GtkWidget           *sw;
	PlannerGanttModel   *model;

	priv = PLANNER_TASK_VIEW (view)->priv;

	if (priv->tree == NULL) {
		project = planner_window_get_project (view->main_window);

		g_signal_connect (project,
				  "loaded",
				  G_CALLBACK (task_view_project_loaded_cb),
				  view);

		sw = gtk_scrolled_window_new (NULL, NULL);
		gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
						GTK_POLICY_AUTOMATIC,
						GTK_POLICY_AUTOMATIC);

		priv->frame = gtk_frame_new (NULL);
		gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), GTK_SHADOW_IN);

		gtk_container_add (GTK_CONTAINER (priv->frame), sw);

		model = planner_gantt_model_new (project);

		priv->tree = planner_task_tree_new (view->main_window,
						    model,
						    TRUE,
						    FALSE,
						    /* i18n: WBS is sort for work breakdown structure, and is a
						     * project management term. You might want to leave it
						     * untranslated unless there is a localized term for it.
						     */
						    COL_WBS, _("WBS"),
						    COL_NAME, _("Name"),
						    COL_START, _("Start"),
						    COL_FINISH, _("Finish"),
						    COL_WORK, _("Work"),
						    COL_DURATION, _("Duration"),
						    COL_SLACK, _("Slack"),
						    COL_COST, _("Cost"),
						    COL_ASSIGNED_TO, _("Assigned to"),
						    /* i18n: The string "% Complete" will be used in the header
						     * of a column containing values from 0 upto 100, indicating
						     * what part of a task has been completed.
						     * xgettext:no-c-format
						     */
						    COL_COMPLETE, _("% Complete"),
						    -1);

		g_object_unref (model);

		task_view_load_columns (view);

		gtk_container_add (GTK_CONTAINER (sw), priv->tree);

		g_signal_connect (priv->tree,
				  "columns-changed",
				  G_CALLBACK (task_view_tree_view_columns_changed_cb),
				  view);

		g_signal_connect (priv->tree,
				  "destroy",
				  G_CALLBACK (task_view_tree_view_destroy_cb),
				  view);

		g_signal_connect (priv->tree,
				  "selection-changed",
				  G_CALLBACK (task_view_selection_changed_cb),
				  view);

		g_signal_connect (priv->tree,
				  "relation-added",
				  G_CALLBACK (task_view_relations_changed_cb),
				  view);

		g_signal_connect (priv->tree,
				  "relation-removed",
				  G_CALLBACK (task_view_relations_changed_cb),
				  view);

		gtk_widget_show (priv->tree);
		gtk_widget_show (sw);
		gtk_widget_show (priv->frame);
	}

	return priv->frame;
}

static void
task_view_tree_view_columns_changed_cb (GtkTreeView *tree_view,
					PlannerView *view)
{
	task_view_save_columns (view);
}

static void
task_view_tree_view_destroy_cb (GtkTreeView *tree_view,
				PlannerView *view)
{
	/* Block, we don't want to save the column configuration when they are
	 * removed by the destruction.
	 */
	g_signal_handlers_block_by_func (tree_view,
					 task_view_tree_view_columns_changed_cb,
					 view);
}

static void
task_view_project_loaded_cb (MrpProject  *project,
			     PlannerView *view)
{
	PlannerTaskViewPriv *priv;
	GtkTreeModel        *model;

	priv = PLANNER_TASK_VIEW (view)->priv;

	model = GTK_TREE_MODEL (planner_gantt_model_new (project));

	planner_task_tree_set_model (PLANNER_TASK_TREE (priv->tree),
				     PLANNER_GANTT_MODEL (model));

	g_object_unref (model);
}

/* Command callbacks. */

static void
task_view_insert_task_cb (GtkAction *action,
			  gpointer   data)
{
	PlannerTaskView *view;

	view = PLANNER_TASK_VIEW (data);

	planner_task_tree_insert_task (PLANNER_TASK_TREE (view->priv->tree));
}

static void
task_view_insert_tasks_cb (GtkAction *action,
			   gpointer   data)
{
	PlannerTaskView *view;

	view = PLANNER_TASK_VIEW (data);

	planner_task_tree_insert_tasks (PLANNER_TASK_TREE (view->priv->tree));
}

static void
task_view_remove_task_cb (GtkAction *action,
			  gpointer   data)
{
	PlannerTaskView *view;

	view = PLANNER_TASK_VIEW (data);

	planner_task_tree_remove_task (PLANNER_TASK_TREE (view->priv->tree));
}

static void
task_view_edit_task_cb (GtkAction *action,
			gpointer   data)
{
	PlannerTaskView *view;

	view = PLANNER_TASK_VIEW (data);

	planner_task_tree_edit_task (PLANNER_TASK_TREE (view->priv->tree),
				     PLANNER_TASK_DIALOG_PAGE_GENERAL);
}

static void
task_view_select_all_cb (GtkAction *action,
			 gpointer   data)
{
	PlannerTaskView *view;

	view = PLANNER_TASK_VIEW (data);

	planner_task_tree_select_all (PLANNER_TASK_TREE (view->priv->tree));
}

static void
task_view_unlink_task_cb (GtkAction *action,
			  gpointer   data)
{
	PlannerTaskView *view;

	view = PLANNER_TASK_VIEW (data);

	planner_task_tree_unlink_task (PLANNER_TASK_TREE (view->priv->tree));
}

static void
task_view_link_tasks_cb (GtkAction *action,
			 gpointer   data)
{
	PlannerTaskView *view;

	view = PLANNER_TASK_VIEW (data);

	planner_task_tree_link_tasks (PLANNER_TASK_TREE (view->priv->tree),
				      MRP_RELATION_FS);
}

static void
task_view_indent_task_cb (GtkAction *action,
			  gpointer   data)
{
	PlannerTaskView *view;

	view = PLANNER_TASK_VIEW (data);

	planner_task_tree_indent_task (PLANNER_TASK_TREE (view->priv->tree));
}

static void
task_view_move_task_up_cb (GtkAction *action,
			   gpointer   data)
{
	PlannerTaskView *view;

	view = PLANNER_TASK_VIEW (data);

	planner_task_tree_move_task_up (PLANNER_TASK_TREE (view->priv->tree));
}

static void
task_view_move_task_down_cb (GtkAction *action,
			     gpointer   data)
{
	PlannerTaskView *view;

	view = PLANNER_TASK_VIEW (data);

	planner_task_tree_move_task_down (PLANNER_TASK_TREE (view->priv->tree));
}

static void
task_view_unindent_task_cb (GtkAction *action,
			    gpointer   data)
{
	PlannerTaskView *view;

	view = PLANNER_TASK_VIEW (data);

	planner_task_tree_unindent_task (PLANNER_TASK_TREE (view->priv->tree));
}

static void
task_view_reset_constraint_cb (GtkAction *action,
			       gpointer   data)
{
	PlannerTaskView *view;

	view = PLANNER_TASK_VIEW (data);

	planner_task_tree_reset_constraint (PLANNER_TASK_TREE (view->priv->tree));
}

static void
task_view_edit_custom_props_cb (GtkAction *action,
				gpointer   data)
{
	PlannerTaskView *view;
	GtkWidget       *dialog;
	MrpProject      *project;

	view = PLANNER_TASK_VIEW (data);

	project = planner_window_get_project (PLANNER_VIEW (view)->main_window);

	dialog = planner_property_dialog_new (PLANNER_VIEW (view)->main_window,
					      project,
					      MRP_TYPE_TASK,
					      _("Edit custom task properties"));

	gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 300);
	gtk_widget_show (dialog);
}

static void
task_view_highlight_critical_cb (GtkAction *action,
				 gpointer   data)
{
	PlannerTaskViewPriv *priv;
	gboolean             state;

	priv = PLANNER_TASK_VIEW (data)->priv;

	state = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

	planner_task_tree_set_highlight_critical (
		PLANNER_TASK_TREE (priv->tree),
		state);

	planner_conf_set_bool (CRITICAL_PATH_KEY, state, "task");
}

static void
task_view_nonstandard_days_cb (GtkAction *action,
				 gpointer   data)
{
	PlannerTaskViewPriv *priv;
	gboolean             state;

	priv = PLANNER_TASK_VIEW (data)->priv;

	state = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));

	planner_task_tree_set_nonstandard_days (
		PLANNER_TASK_TREE (priv->tree),
		state);


	planner_conf_set_bool (NOSTDDAYS_PATH_KEY, state, "task");
}

static void
task_view_edit_columns_cb (GtkAction *action,
			   gpointer   data)
{
	PlannerTaskView     *view;
	PlannerTaskViewPriv *priv;

	view = PLANNER_TASK_VIEW (data);
	priv = view->priv;

	planner_column_dialog_show (PLANNER_VIEW (view)->main_window,
				    _("Edit Task Columns"),
				    GTK_TREE_VIEW (priv->tree));
}

static void
task_view_selection_changed_cb (PlannerTaskTree *tree, PlannerView *view)
{
	task_view_update_ui (view);
}

static void
task_view_relations_changed_cb (PlannerTaskTree  *tree,
				MrpTask     *task,
				MrpRelation *relation,
				PlannerView      *view)
{
	task_view_update_ui (view);
}


static void
task_view_print_init (PlannerView     *view,
		      PlannerPrintJob *job)
{
	PlannerTaskViewPriv *priv;

	priv = PLANNER_TASK_VIEW (view)->priv;

	priv->print_sheet = planner_table_print_sheet_new (PLANNER_VIEW (view), job,
							   GTK_TREE_VIEW (priv->tree));
}

static void
task_view_print (PlannerView *view,
		 gint         page_nr)
{
	PlannerTaskViewPriv *priv;

	priv = PLANNER_TASK_VIEW (view)->priv;

	planner_table_print_sheet_output (priv->print_sheet, page_nr);
}

static gint
task_view_print_get_n_pages (PlannerView *view)
{
	PlannerTaskViewPriv *priv;

	priv = PLANNER_TASK_VIEW (view)->priv;

	return planner_table_print_sheet_get_n_pages (priv->print_sheet);
}

static void
task_view_print_cleanup (PlannerView *view)
{
	PlannerTaskViewPriv *priv;

	priv = PLANNER_TASK_VIEW (view)->priv;

	planner_table_print_sheet_free (priv->print_sheet);
	priv->print_sheet = NULL;
}

static void
task_view_update_ui (PlannerView *view)
{
	PlannerTaskViewPriv *priv;
	GList           *list, *l;
	gboolean         value;
	gboolean         rel_value  = FALSE;
	gboolean         link_value = FALSE;
	gint	         count = 0;

	if (!view->activated) {
		return;
	}

	priv = PLANNER_TASK_VIEW (view)->priv;

	list = planner_task_tree_get_selected_tasks (PLANNER_TASK_TREE (priv->tree));

	for (l = list; l; l = l->next) {
		if (mrp_task_has_relation (MRP_TASK (l->data))) {
			rel_value = TRUE;
			break;
		}
	}

	for (l = list; l; l = l->next) {
		count++;
	}

	value = (list != NULL);
	link_value = (count >= 2);

	g_object_set (gtk_action_group_get_action (priv->actions, "EditTask"),
		      "sensitive", value,
		      NULL);
	g_object_set (gtk_action_group_get_action (priv->actions, "RemoveTask"),
		      "sensitive", value,
		      NULL);
	g_object_set (gtk_action_group_get_action (priv->actions, "UnlinkTask"),
		      "sensitive", rel_value,
		      NULL);
	g_object_set (gtk_action_group_get_action (priv->actions, "LinkTasks"),
		      "sensitive", link_value,
		      NULL);
	g_object_set (gtk_action_group_get_action (priv->actions, "IndentTask"),
		      "sensitive", value,
		      NULL);
	g_object_set (gtk_action_group_get_action (priv->actions, "UnindentTask"),
		      "sensitive", value,
		      NULL);
	g_object_set (gtk_action_group_get_action (priv->actions, "MoveTaskUp"),
		      "sensitive", value,
		      NULL);
	g_object_set (gtk_action_group_get_action (priv->actions, "MoveTaskDown"),
		      "sensitive", value,
		      NULL);
	g_object_set (gtk_action_group_get_action (priv->actions, "ResetConstraint"),
		      "sensitive", value,
		      NULL);

	g_list_free (list);
}

static void
task_view_save_columns (PlannerView *view)
{
	PlannerTaskViewPriv *priv;

	priv = PLANNER_TASK_VIEW (view)->priv;

	planner_view_column_save_helper (view, GTK_TREE_VIEW (priv->tree),
					 "task");
}

static void
task_view_load_columns (PlannerView *view)
{
	PlannerTaskViewPriv *priv;

	priv = PLANNER_TASK_VIEW (view)->priv;

	/* Load the columns. */
	planner_view_column_load_helper (view, GTK_TREE_VIEW (priv->tree),
					 "task");
}

PlannerView *
planner_task_view_new (void)
{
	PlannerView *view;

	view = g_object_new (PLANNER_TYPE_TASK_VIEW, NULL);

	return view;
}