planner-window.c 56.5 KB
Newer Older
Richard Hult's avatar
Richard Hult committed
1 2
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
Richard Hult's avatar
Richard Hult committed
3
 * Copyright (C) 2003-2005 Imendio AB
Richard Hult's avatar
Richard Hult committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * Copyright (C) 2002-2003 CodeFactory AB
 * Copyright (C) 2002-2003 Richard Hult <richard@imendio.com>
 * Copyright (C) 2002-2003 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
Josué Abarca's avatar
Josué Abarca committed
20 21
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
Richard Hult's avatar
Richard Hult committed
22 23 24 25 26
 */

#include <config.h>
#include <string.h>
#include <math.h>
27
#include <glib/gi18n.h>
Richard Hult's avatar
Richard Hult committed
28
#include <gdk-pixbuf/gdk-pixbuf.h>
29
#include <gtk/gtk.h>
Richard Hult's avatar
Richard Hult committed
30 31 32
#include <glade/glade.h>
#include <libplanner/mrp-error.h>
#include <libplanner/mrp-project.h>
33
#include <libplanner/mrp-paths.h>
Richard Hult's avatar
Richard Hult committed
34
#include "planner-marshal.h"
35
#include "planner-conf.h"
Richard Hult's avatar
Richard Hult committed
36
#include "planner-sidebar.h"
Richard Hult's avatar
Richard Hult committed
37
#include "planner-window.h"
Richard Hult's avatar
Richard Hult committed
38 39 40 41 42 43 44
#include "planner-plugin-loader.h"
#include "planner-project-properties.h"
#include "planner-phase-dialog.h"
#include "planner-calendar-dialog.h"
#include "planner-day-type-dialog.h"
#include "planner-print-dialog.h"
#include "planner-view.h"
45 46 47 48
#include "planner-gantt-view.h"
#include "planner-task-view.h"
#include "planner-resource-view.h"
#include "planner-usage-view.h"
Francisco Moraes's avatar
Francisco Moraes committed
49
#include "planner-util.h"
Richard Hult's avatar
Richard Hult committed
50 51 52

#define d(x)

Richard Hult's avatar
Richard Hult committed
53 54
struct _PlannerWindowPriv {
	PlannerApplication  *application;
Richard Hult's avatar
Richard Hult committed
55

56 57 58
	GtkUIManager        *ui_manager;
	GtkActionGroup      *actions;
	GtkActionGroup      *view_actions;
Richard Hult's avatar
Richard Hult committed
59

Richard Hult's avatar
Richard Hult committed
60 61
	PlannerCmdManager   *cmd_manager;

Richard Hult's avatar
Richard Hult committed
62 63
	MrpProject          *project;

Richard Hult's avatar
Richard Hult committed
64 65
	GtkWidget           *statusbar;
	GtkWidget           *ui_box;
Richard Hult's avatar
Richard Hult committed
66 67 68 69 70 71 72 73
	GtkWidget           *sidebar;
	GtkWidget           *notebook;

	GtkWidget           *properties_dialog;
	GtkWidget           *calendar_dialog;
	GtkWidget           *day_type_dialog;
	GtkWidget           *phase_dialog;

Richard Hult's avatar
Richard Hult committed
74
	PlannerView         *current_view;
Richard Hult's avatar
Richard Hult committed
75 76 77 78 79
	GList               *views;
	GList               *plugins;
	GTimer              *last_saved;
};

80 81 82 83 84 85 86 87 88 89 90 91
/* Drop targets. */
enum {
	TARGET_STRING,
	TARGET_URI_LIST
};

static const GtkTargetEntry drop_target_types[] = {
	{ "STRING",     0, TARGET_STRING },
	{ "text/plain", 0, TARGET_STRING },
	{ "text/uri-list", 0, TARGET_URI_LIST },
};

Richard Hult's avatar
Richard Hult committed
92 93 94 95 96 97 98 99
/* Signals */
enum {
	CLOSED,
	NEW_WINDOW,
	EXIT,
	LAST_SIGNAL
};

100 101 102 103 104 105
/* Links type */
enum {
	LINK_TYPE_EMAIL,
	LINK_TYPE_URL
};

Richard Hult's avatar
Richard Hult committed
106 107 108 109 110 111 112
static void       window_class_init                      (PlannerWindowClass           *klass);
static void       window_init                            (PlannerWindow                *window);
static void       window_finalize                        (GObject                      *object);
static void       window_populate                        (PlannerWindow                *window);
static void       window_view_selected                   (PlannerSidebar               *sidebar,
							  gint                          index,
							  PlannerWindow                *window);
113 114 115 116 117 118 119 120 121 122 123
static void       window_view_cb                         (GtkAction                    *action,
							  GtkRadioAction               *current,
							  gpointer                      data);
static void       window_new_cb                          (GtkAction                    *action,
							  gpointer                      data);
static void       window_open_cb                         (GtkAction                    *action,
							  gpointer                      data);
static void       window_save_as_cb                      (GtkAction                    *action,
							  gpointer                      data);
static void       window_save_cb                         (GtkAction                    *action,
							  gpointer                      data);
124
static void       window_page_setup_cb                   (GtkAction                    *action,
125
							  gpointer                      data);
126
static void       window_print_cb                        (GtkAction                    *action,
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
							  gpointer                      data);
static void       window_close_cb                        (GtkAction                    *action,
							  gpointer                      data);
static void       window_exit_cb                         (GtkAction                    *action,
							  gpointer                      data);
static void       window_undo_cb                         (GtkAction                    *action,
							  gpointer                      data);
static void       window_redo_cb                         (GtkAction                    *action,
							  gpointer                      data);
static void       window_project_props_cb                (GtkAction                    *action,
							  gpointer                      data);
static void       window_manage_calendars_cb             (GtkAction                    *action,
							  gpointer                      data);
static void       window_edit_day_types_cb               (GtkAction                    *action,
							  gpointer                      data);
static void       window_edit_phases_cb                  (GtkAction                    *action,
							  gpointer                      data);
static void       window_help_cb                         (GtkAction                    *action,
							  gpointer                      data);
static void       window_about_cb                        (GtkAction                    *action,
							  gpointer                      data);
Richard Hult's avatar
Richard Hult committed
148 149 150 151
static gboolean   window_delete_event_cb                 (PlannerWindow                *window,
							  gpointer                      user_data);
static void       window_undo_state_changed_cb           (PlannerCmdManager            *manager,
							  gboolean                      state,
152
							  const gchar                  *label,
Richard Hult's avatar
Richard Hult committed
153 154 155
							  PlannerWindow                *window);
static void       window_redo_state_changed_cb           (PlannerCmdManager            *manager,
							  gboolean                      state,
156
							  const gchar                  *label,
Richard Hult's avatar
Richard Hult committed
157
							  PlannerWindow                *window);
158 159 160 161 162 163 164 165
static void       window_drag_data_received_cb           (GtkWidget                    *widget,
							  GdkDragContext               *context,
							  int                           x,
							  int                           y,
							  GtkSelectionData             *data,
							  guint                         info,
							  guint                         time,
							  PlannerWindow                *window);
Richard Hult's avatar
Richard Hult committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179
static void       window_project_needs_saving_changed_cb (MrpProject                   *project,
							  gboolean                      needs_saving,
							  PlannerWindow                *window);
static void       window_project_notify_name_cb          (MrpProject                   *project,
							  GParamSpec                   *pspec,
							  PlannerWindow                *window);
static gboolean   window_confirm_exit_run                (PlannerWindow                *window);
static gboolean   window_do_save                         (PlannerWindow                *window,
							  gboolean                      force);
static gboolean   window_do_save_as                      (PlannerWindow                *window);
static gchar *    window_get_name                        (PlannerWindow                *window);
static void       window_update_title                    (PlannerWindow                *window);
static GtkWidget *window_create_dialog_button            (const gchar                  *icon_name,
							  const gchar                  *text);
180 181
static void       window_recent_add_item                 (PlannerWindow                *window,
							  const gchar                  *uri);
182 183
static void       window_save_state                      (PlannerWindow *window);
static void       window_restore_state                   (PlannerWindow *window);
Richard Hult's avatar
Richard Hult committed
184

Richard Hult's avatar
Richard Hult committed
185 186 187 188 189 190 191 192 193 194
static void window_disconnect_proxy_cb (GtkUIManager  *manager,
					GtkAction     *action,
					GtkWidget     *proxy,
					PlannerWindow *window);

static void window_connect_proxy_cb (GtkUIManager  *manager,
				     GtkAction     *action,
				     GtkWidget     *proxy,
				     PlannerWindow *window);

195 196 197 198 199 200
#define CONF_WINDOW_DIR       "/ui"
#define CONF_WINDOW_MAXIMIZED "/ui/main_window_maximized"
#define CONF_WINDOW_WIDTH     "/ui/main_window_width"
#define CONF_WINDOW_HEIGHT    "/ui/main_window_height"
#define CONF_WINDOW_POS_X     "/ui/main_window_position_x"
#define CONF_WINDOW_POS_Y     "/ui/main_window_position_y"
Richard Hult's avatar
Richard Hult committed
201
#define CONF_ACTIVE_VIEW           "/ui/active_view"
202
#define CONF_LAST_DIR         "/general/last_dir"
Richard Hult's avatar
Richard Hult committed
203

204 205 206
#define DEFAULT_WINDOW_WIDTH  800
#define DEFAULT_WINDOW_HEIGHT 550

Richard Hult's avatar
Richard Hult committed
207 208
#define VIEW_PATH "/menu/View/Views placeholder"
#define VIEW_GROUP "view group"
209

210
static GtkWindowClass *parent_class = NULL;
Richard Hult's avatar
Richard Hult committed
211 212 213
static guint signals[LAST_SIGNAL];


214
static GtkActionEntry entries[] = {
215
	{ "File",
216
	  NULL, N_("_File"), NULL, NULL,
217 218 219 220 221 222 223 224 225
	  NULL
	},
	{ "FileNew",
	  GTK_STOCK_NEW,           N_("_New Project"),             "<Control>n",        N_("Create a new project"),
	  G_CALLBACK (window_new_cb)
	},
	{ "FileOpen",
	  GTK_STOCK_OPEN,          N_("_Open..."),                 "F3",                N_("Open a project"),
	  G_CALLBACK (window_open_cb) },
226 227 228
	{ "FileOpenRecent",
	  NULL,                    N_("Open _Recent"),             NULL,                NULL,
	  NULL },
229 230 231
	{ "Import",
	  NULL,                    N_("_Import"),                  NULL,                NULL,
	  NULL },
232

233 234 235 236 237 238 239 240 241
	{ "FileSave",
	  GTK_STOCK_SAVE,          N_("_Save"),                    "<Control>s",        N_("Save the current project"),
	  G_CALLBACK (window_save_cb) },
	{ "Export",
	  NULL,                    N_("_Export"),                  NULL,                NULL,
	  NULL },
	{ "FileSaveAs",
	  GTK_STOCK_SAVE_AS,       N_("Save _As..."),              "<Shift><Control>s", N_("Save the current project with a different name"),
	  G_CALLBACK (window_save_as_cb) },
242 243 244
	{ "FilePageSetup",
	  NULL,                    N_("Page Set_up..."),           NULL,                N_("Setup the page settings for your current printer"),
	  G_CALLBACK (window_page_setup_cb) },
245 246 247 248 249
	{ "FilePrint",
	  GTK_STOCK_PRINT,         N_("_Print..."),                "<Control>p",        N_("Print the current project"),
	  G_CALLBACK (window_print_cb) },
	{ "FilePrintPreview",
	  GTK_STOCK_PRINT_PREVIEW, N_("Print Pre_view"),           "<Shift><Control>p", N_("Print preview of the current project"),
250
	  G_CALLBACK (window_print_cb) },
251 252 253 254 255 256
	{ "FileClose",
	  GTK_STOCK_CLOSE,         N_("_Close"),                   "<Control>w",        N_("Close the current file"),
	  G_CALLBACK (window_close_cb) },
	{ "FileExit",
	  GTK_STOCK_QUIT,          N_("_Quit"),                    "<Control>q",        N_("Exit the program"),
	  G_CALLBACK (window_exit_cb) },
257

258 259 260 261 262 263 264 265 266
	{ "Edit",
	  NULL,                    N_("_Edit"),                    NULL,                NULL,
	  NULL },
	{ "EditUndo",
	  GTK_STOCK_UNDO,          N_("_Undo"),                    "<Control>z",        N_("Undo the last action"),
	  G_CALLBACK (window_undo_cb) },
	{ "EditRedo",
	  GTK_STOCK_REDO,          N_("_Redo"),                    "<Control>r",        N_("Redo the undone action"),
	  G_CALLBACK (window_redo_cb) },
267

268 269 270
	{ "View",
	  NULL,                    N_("_View"),                    NULL,                NULL,
	  NULL },
271

272 273 274
	{ "Actions",
	  NULL,                    N_("_Actions"),                 NULL,                NULL,
	  NULL },
275

276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
	{ "Project",
	  NULL,                    N_("_Project"),                 NULL,                NULL,
	  NULL },
	{ "ManageCalendars",
	  NULL,                    N_("_Manage Calendars"),        NULL,                NULL,
	  G_CALLBACK (window_manage_calendars_cb) },
	{ "EditDayTypes",
	  NULL,                    N_("Edit Day _Types"),          NULL,                NULL,
	  G_CALLBACK (window_edit_day_types_cb) },
	{ "EditPhases",
	  NULL,                    N_("Edit Project _Phases"),     NULL,                NULL,
	  G_CALLBACK (window_edit_phases_cb) },
	{ "EditProjectProps",
	  GTK_STOCK_PROPERTIES,    N_("_Edit Project Properties"), NULL,                N_("Edit the project properties"),
	  G_CALLBACK (window_project_props_cb) },
291

292 293 294
/*	{ "PreferencesEditPreferences",
	NULL,                    NULL,                           NULL,                NULL,
	G_CALLBACK (window_preferences_cb) },*/
295

296 297 298 299 300 301 302
	{ "Help",
	  NULL,                    N_("_Help"),                    NULL,                NULL,
	  NULL },
	{ "HelpHelp",
	  GTK_STOCK_HELP,          N_("_User Guide"),              "F1",                N_("Show the Planner User Guide"),
	  G_CALLBACK (window_help_cb) },
	{ "HelpAbout",
303
	  GTK_STOCK_ABOUT,         N_("_About"),                   NULL,                N_("About this application"),
304
	  G_CALLBACK (window_about_cb) },
305
};
Richard Hult's avatar
Richard Hult committed
306

307
static guint n_entries = G_N_ELEMENTS(entries);
Richard Hult's avatar
Richard Hult committed
308 309 310


GType
Richard Hult's avatar
Richard Hult committed
311
planner_window_get_type (void)
Richard Hult's avatar
Richard Hult committed
312
{
313
	static GType type = 0;
Richard Hult's avatar
Richard Hult committed
314 315 316

	if (!type) {
		static const GTypeInfo info = {
Richard Hult's avatar
Richard Hult committed
317
			sizeof (PlannerWindowClass),
Richard Hult's avatar
Richard Hult committed
318 319
			NULL,		/* base_init */
			NULL,		/* base_finalize */
Richard Hult's avatar
Richard Hult committed
320
			(GClassInitFunc) window_class_init,
Richard Hult's avatar
Richard Hult committed
321 322
			NULL,		/* class_finalize */
			NULL,		/* class_data */
Richard Hult's avatar
Richard Hult committed
323
			sizeof (PlannerWindow),
Richard Hult's avatar
Richard Hult committed
324
			0,              /* n_preallocs */
Richard Hult's avatar
Richard Hult committed
325
			(GInstanceInitFunc) window_init
Richard Hult's avatar
Richard Hult committed
326 327
		};

328
		type = g_type_register_static (GTK_TYPE_WINDOW,
Richard Hult's avatar
Richard Hult committed
329
					       "PlannerWindow", &info, 0);
Richard Hult's avatar
Richard Hult committed
330
	}
331

Richard Hult's avatar
Richard Hult committed
332 333 334 335
	return type;
}

static void
Richard Hult's avatar
Richard Hult committed
336
window_class_init (PlannerWindowClass *klass)
Richard Hult's avatar
Richard Hult committed
337 338
{
	GObjectClass *o_class;
339

Richard Hult's avatar
Richard Hult committed
340 341 342 343 344
	parent_class = g_type_class_peek_parent (klass);

	o_class = (GObjectClass *) klass;

	/* GObject functions */
Richard Hult's avatar
Richard Hult committed
345
	o_class->finalize = window_finalize;
Richard Hult's avatar
Richard Hult committed
346 347

	/* Signals */
348 349 350 351 352 353 354
	signals[CLOSED] = g_signal_new ("closed",
					G_TYPE_FROM_CLASS (klass),
					G_SIGNAL_RUN_LAST,
					0, /*G_STRUCT_OFFSET (PlannerWindowClass, method), */
					NULL, NULL,
					planner_marshal_VOID__VOID,
					G_TYPE_NONE, 0);
Richard Hult's avatar
Richard Hult committed
355 356 357
}

static void
Richard Hult's avatar
Richard Hult committed
358
window_init (PlannerWindow *window)
Richard Hult's avatar
Richard Hult committed
359
{
Richard Hult's avatar
Richard Hult committed
360
	PlannerWindowPriv *priv;
Richard Hult's avatar
Richard Hult committed
361

Richard Hult's avatar
Richard Hult committed
362
	priv = g_new0 (PlannerWindowPriv, 1);
Richard Hult's avatar
Richard Hult committed
363 364
	window->priv = priv;

365 366
	priv->views = NULL;

367 368 369 370 371 372 373 374 375 376 377
	/* Setup drag-n-drop. */
	gtk_drag_dest_set (GTK_WIDGET (window),
			   GTK_DEST_DEFAULT_ALL,
			   drop_target_types,
			   G_N_ELEMENTS (drop_target_types),
			   GDK_ACTION_COPY);

	g_signal_connect (window,
			  "drag_data_received",
			  G_CALLBACK (window_drag_data_received_cb),
			  window);
378

Richard Hult's avatar
Richard Hult committed
379 380 381 382 383 384 385 386 387 388 389
	priv->cmd_manager = planner_cmd_manager_new ();

	g_signal_connect (priv->cmd_manager,
			  "undo_state_changed",
			  G_CALLBACK (window_undo_state_changed_cb),
			  window);

	g_signal_connect (priv->cmd_manager,
			  "redo_state_changed",
			  G_CALLBACK (window_redo_state_changed_cb),
			  window);
Richard Hult's avatar
Richard Hult committed
390 391 392
}

static void
Richard Hult's avatar
Richard Hult committed
393
window_finalize (GObject *object)
Richard Hult's avatar
Richard Hult committed
394
{
Richard Hult's avatar
Richard Hult committed
395 396
	PlannerWindow     *window = PLANNER_WINDOW (object);
	PlannerWindowPriv *priv = window->priv;
Richard Hult's avatar
Richard Hult committed
397

398 399 400
	if (priv->last_saved) {
		g_timer_destroy (priv->last_saved);
	}
401
	if (priv->plugins) {
402
		planner_plugin_loader_unload (priv->plugins);
403 404
		g_list_free (priv->plugins);
	}
405 406 407 408
	if (priv->views) {
		g_list_foreach (priv->views, (GFunc) g_object_unref, NULL);
		g_list_free (priv->views);
	}
409
	/* FIXME: check if project should be unreffed */
Richard Hult's avatar
Richard Hult committed
410 411 412
	if (priv->cmd_manager) {
		g_object_unref (priv->cmd_manager);
	}
413

414 415 416 417 418 419
	if (priv->view_actions) {
		g_object_unref (priv->view_actions);
	}
	if (priv->actions) {
		g_object_unref (priv->actions);
	}
420 421 422 423
	if (priv->ui_manager) {
		g_object_unref (priv->ui_manager);
	}

424 425 426 427
	if (priv->application) {
		g_object_unref (priv->application);
	}

Richard Hult's avatar
Richard Hult committed
428 429 430 431 432 433 434 435
	g_free (window->priv);

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

static void
436
recent_chooser_item_activated (GtkRecentChooser *chooser, gpointer user_data)
Richard Hult's avatar
Richard Hult committed
437
{
438 439
	gchar *uri;
	PlannerWindow *window;
Richard Hult's avatar
Richard Hult committed
440

441
	g_return_if_fail (PLANNER_IS_WINDOW (user_data));
Richard Hult's avatar
Richard Hult committed
442

443 444 445 446 447 448 449
	window = PLANNER_WINDOW (user_data);

	uri = gtk_recent_chooser_get_current_uri (chooser);
	if (uri != NULL) {
		planner_window_open_in_existing_or_new (window, uri, FALSE);
		g_free (uri);
	}
Richard Hult's avatar
Richard Hult committed
450 451 452
}

static void
453 454
window_add_widget (GtkUIManager  *merge,
		   GtkWidget     *widget,
Richard Hult's avatar
Richard Hult committed
455
		   PlannerWindow *window)
Richard Hult's avatar
Richard Hult committed
456
{
Richard Hult's avatar
Richard Hult committed
457 458 459
	PlannerWindowPriv *priv;

	priv = window->priv;
Richard Hult's avatar
Richard Hult committed
460

Richard Hult's avatar
Richard Hult committed
461 462
	gtk_box_pack_start (GTK_BOX (priv->ui_box), widget, FALSE, FALSE, 0);
}
Richard Hult's avatar
Richard Hult committed
463

464 465 466 467 468 469 470 471
static void
window_add_stock_icon (GtkIconFactory *icon_factory,
		       const gchar    *stock_id,
		       const gchar    *filename)
{
	gchar      *path;
	GdkPixbuf  *pixbuf;
	GtkIconSet *icon_set;
472

473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
	path = mrp_paths_get_image_dir (filename);
	pixbuf = gdk_pixbuf_new_from_file (path, NULL);
	icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
	g_object_unref (pixbuf);
	gtk_icon_factory_add (icon_factory, stock_id, icon_set);
	g_free (path);
}

static void
window_add_stock_icons (void)
{
	static GtkIconFactory *icon_factory = NULL;

	if (icon_factory) {
		return;
	}
489

490 491 492 493
	icon_factory = gtk_icon_factory_new ();
	gtk_icon_factory_add_default (icon_factory);

	/* Task/Gantt icons. */
494
	window_add_stock_icon (icon_factory,
495 496
			       "planner-stock-insert-task",
			       "24_insert_task.png");
497 498

	window_add_stock_icon (icon_factory,
499 500
			       "planner-stock-remove-task",
			       "24_remove_task.png");
501 502

	window_add_stock_icon (icon_factory,
503 504
			       "planner-stock-unlink-task",
			       "24_unlink_task.png");
505 506

	window_add_stock_icon (icon_factory,
507 508
			       "planner-stock-link-task",
			       "24_link_task.png");
509 510

	window_add_stock_icon (icon_factory,
511 512
			       "planner-stock-indent-task",
			       "24_indent_task.png");
513 514

	window_add_stock_icon (icon_factory,
515 516
			       "planner-stock-unindent-task",
			       "24_unindent_task.png");
517 518

	window_add_stock_icon (icon_factory,
519 520
			       "planner-stock-move-task-up",
			       "24_task_up.png");
521 522

	window_add_stock_icon (icon_factory,
523 524 525 526 527 528 529
			       "planner-stock-move-task-down",
			       "24_task_down.png");

	/* Resource icons. */
	window_add_stock_icon (icon_factory,
			       "planner-stock-insert-resource",
			       "/24_insert_resource.png");
530

531 532 533 534 535 536 537
	window_add_stock_icon (icon_factory,
			       "planner-stock-remove-resource",
			       "24_remove_resource.png");

	window_add_stock_icon (icon_factory,
			       "planner-stock-edit-resource",
			       "24_edit_resource.png");
538

539 540 541 542 543
	window_add_stock_icon (icon_factory,
			       "planner-stock-edit-groups",
			       "24_groups.png");
}

544 545 546 547
static void
window_populate (PlannerWindow *window)
{
	PlannerWindowPriv    *priv;
Richard Hult's avatar
Richard Hult committed
548
	GtkWidget            *hbox;
549 550
	GList                *l;
	GtkWidget            *view_widget;
551 552 553
	GtkWidget            *recent_view;
	GtkRecentFilter      *filter;
	GtkWidget            *open_recent;
554 555 556 557
	PlannerView          *view;
	gint                  view_num;
	GtkRadioActionEntry  *r_entries;
	gchar                *xml_string_tmp, *xml_string;
Richard Hult's avatar
Richard Hult committed
558
	gchar                *str;
559
	gchar                *filename;
560
	const gchar          *xml_string_full =
561 562 563 564 565 566 567 568 569
		"<ui>"
		"<menubar name='MenuBar'>"
		"<menu action='View'>"
		"<placeholder name='Views placeholder'>"
		"%s"
		"</placeholder>"
		"</menu>"
		"</menubar>"
		"</ui>";
Richard Hult's avatar
Richard Hult committed
570

571
	priv = window->priv;
572

573
	window_add_stock_icons ();
574

Richard Hult's avatar
Richard Hult committed
575 576
	priv->ui_box = gtk_vbox_new (FALSE, 0);
	gtk_container_add (GTK_CONTAINER (window), priv->ui_box);
577

578
	priv->actions = gtk_action_group_new ("Planner");
579

580
	gtk_action_group_set_translation_domain (priv->actions, GETTEXT_PACKAGE);
581 582 583 584
	gtk_action_group_add_actions (priv->actions, entries, n_entries, window);

	priv->ui_manager = gtk_ui_manager_new ();

Richard Hult's avatar
Richard Hult committed
585 586 587 588 589 590 591 592 593 594 595 596
	g_signal_connect (priv->ui_manager,
			  "add_widget",
			  G_CALLBACK (window_add_widget),
			  window);
	g_signal_connect (priv->ui_manager,
			  "connect_proxy",
			  G_CALLBACK (window_connect_proxy_cb),
			  window);
	g_signal_connect (priv->ui_manager,
			  "disconnect_proxy",
			  G_CALLBACK (window_disconnect_proxy_cb),
			  window);
597

598 599 600 601
	gtk_ui_manager_insert_action_group (priv->ui_manager, priv->actions, 0);
	gtk_window_add_accel_group (GTK_WINDOW (window),
				    gtk_ui_manager_get_accel_group (priv->ui_manager));

602
	filename = mrp_paths_get_ui_dir ("main-window.ui");
603
	gtk_ui_manager_add_ui_from_file (priv->ui_manager,
604
					 filename ,
605
					 NULL);
606
	g_free (filename);
607 608

	g_object_set (gtk_action_group_get_action (priv->actions, "EditUndo"),
609
		      "sensitive", FALSE,
610 611
		      NULL);
	g_object_set (gtk_action_group_get_action (priv->actions, "EditRedo"),
612
		      "sensitive", FALSE,
613 614
		      NULL);
	g_object_set (gtk_action_group_get_action (priv->actions, "FileSave"),
615
		      "sensitive", FALSE,
616
		      NULL);
Richard Hult's avatar
Richard Hult committed
617

618 619
	/* Make the Actions menu always visible even when empty. */
	g_object_set (gtk_action_group_get_action (priv->actions, "Actions"),
620
		      "hide-if-empty", FALSE,
621 622
		      NULL);

623
	/* Handle recent file stuff. */
624
	recent_view = gtk_recent_chooser_menu_new_for_manager (
625 626 627 628 629 630
		planner_application_get_recent_model (priv->application));

	filter = gtk_recent_filter_new ();
	gtk_recent_filter_add_mime_type (filter, "application/x-planner");
	gtk_recent_filter_add_mime_type (filter, "application/x-mrproject");
	gtk_recent_filter_add_group (filter, "planner");
631
	gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (recent_view), filter);
632

633
	g_signal_connect (recent_view,
634 635 636 637
			  "item_activated",
			  G_CALLBACK (recent_chooser_item_activated),
			  window);

638 639 640 641
	gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recent_view), GTK_RECENT_SORT_MRU);
	gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (recent_view), TRUE);
	gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (recent_view), 5);
	gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (recent_view), TRUE);
642 643

	open_recent = gtk_ui_manager_get_widget (priv->ui_manager, "/MenuBar/File/FileOpenRecent");
644
	gtk_menu_item_set_submenu (GTK_MENU_ITEM (open_recent), recent_view);
645

Richard Hult's avatar
Richard Hult committed
646 647 648
	hbox = gtk_hbox_new (FALSE, 0);

	priv->sidebar = planner_sidebar_new ();
649 650
	gtk_box_pack_start (GTK_BOX (hbox), priv->sidebar, FALSE, TRUE, 0);
	g_signal_connect (priv->sidebar,
Richard Hult's avatar
Richard Hult committed
651
			  "icon-selected",
Richard Hult's avatar
Richard Hult committed
652
			  G_CALLBACK (window_view_selected),
Richard Hult's avatar
Richard Hult committed
653 654 655 656
			  window);

	priv->notebook = gtk_notebook_new ();
	gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
657
	gtk_box_pack_start (GTK_BOX (hbox), priv->notebook, TRUE, TRUE, 0);
Richard Hult's avatar
Richard Hult committed
658

Richard Hult's avatar
Richard Hult committed
659 660 661 662 663
	priv->statusbar = gtk_statusbar_new ();
	gtk_box_pack_end (GTK_BOX (priv->ui_box), priv->statusbar, FALSE, TRUE, 0);
	gtk_widget_show (priv->statusbar);

	gtk_box_pack_end (GTK_BOX (priv->ui_box), hbox, TRUE, TRUE, 0);
Richard Hult's avatar
Richard Hult committed
664

665
	/* Create views. */
666 667
	priv->view_actions = gtk_action_group_new ("View Actions");
	gtk_ui_manager_insert_action_group (priv->ui_manager, priv->view_actions, 0);
Richard Hult's avatar
Richard Hult committed
668

669 670 671 672
	priv->views = g_list_append (priv->views, planner_gantt_view_new ());
	priv->views = g_list_append (priv->views, planner_task_view_new ());
	priv->views = g_list_append (priv->views, planner_resource_view_new ());
	priv->views = g_list_append (priv->views, planner_usage_view_new ());
673

Richard Hult's avatar
Richard Hult committed
674
	view_num = 0;
Richard Hult's avatar
Richard Hult committed
675 676
	xml_string = g_strdup ("");
	r_entries  = g_new0 (GtkRadioActionEntry, g_list_length (priv->views));
677
	for (l = priv->views; l; l = l->next, view_num++ ) {
Richard Hult's avatar
Richard Hult committed
678
		view = l->data;
679 680

		planner_view_setup (view, window);
681

Richard Hult's avatar
Richard Hult committed
682 683
		view_widget = planner_view_get_widget (view);
		gtk_widget_show (view_widget);
Richard Hult's avatar
Richard Hult committed
684

Richard Hult's avatar
Richard Hult committed
685 686 687
		planner_sidebar_append (PLANNER_SIDEBAR (priv->sidebar),
					planner_view_get_icon (view),
					planner_view_get_label (view));
Richard Hult's avatar
Richard Hult committed
688

689 690 691
		r_entries[view_num].name  = planner_view_get_name (view);
		r_entries[view_num].label = planner_view_get_menu_label (view);
		r_entries[view_num].value = view_num;
692 693 694
		r_entries[view_num].tooltip = g_strdup_printf (_("Switch to the view \"%s\""),
							       planner_view_get_label (view));

695
		xml_string_tmp = xml_string;
Richard Hult's avatar
Richard Hult committed
696 697 698
		xml_string = g_strdup_printf ("%s<menuitem action='%s'/>",
					      xml_string, r_entries[view_num].name);
		g_free (xml_string_tmp);
699

Richard Hult's avatar
Richard Hult committed
700 701 702 703 704 705
		gtk_notebook_append_page (
			GTK_NOTEBOOK (priv->notebook),
			view_widget,
			gtk_label_new (planner_view_get_label (view)));
	}

Richard Hult's avatar
Richard Hult committed
706 707
	gtk_action_group_add_radio_actions (priv->view_actions,
					    r_entries,
Richard Hult's avatar
Richard Hult committed
708
					    g_list_length (priv->views), 0,
Richard Hult's avatar
Richard Hult committed
709 710
					    G_CALLBACK (window_view_cb),
					    window);
711

712 713 714 715 716 717 718 719
	view_num = 0;
	for (l = priv->views; l; l = l->next, view_num++ ) {
		/* Cast off const so we can free the string we allocated */
		gchar *tooltip = (gchar *)(r_entries[view_num].tooltip);
		g_free (tooltip);
	}
	g_free (r_entries);

Richard Hult's avatar
Richard Hult committed
720
	xml_string_tmp = g_strdup_printf (xml_string_full, xml_string);
721 722 723
	gtk_ui_manager_add_ui_from_string (priv->ui_manager, xml_string_tmp, -1, NULL);
	g_free (xml_string);
	g_free (xml_string_tmp);
724

Richard Hult's avatar
Richard Hult committed
725
	gtk_ui_manager_ensure_update (priv->ui_manager);
726

Richard Hult's avatar
Richard Hult committed
727 728 729
	/* Load plugins. */
	priv->plugins = planner_plugin_loader_load (window);

Richard Hult's avatar
Richard Hult committed
730 731 732 733 734 735 736 737
	str = planner_conf_get_string (CONF_ACTIVE_VIEW, NULL);
	if (str) {
		gboolean found;

		found = FALSE;
		view_num = 0;
		for (l = priv->views; l; l = l->next, view_num++ ) {
			view = l->data;
738

Richard Hult's avatar
Richard Hult committed
739 740 741
			if (strcmp (str, planner_view_get_name (view)) == 0) {
				found = TRUE;
				break;
742
			}
Richard Hult's avatar
Richard Hult committed
743 744 745 746 747
		}

		if (!found) {
			view_num = 0;
		}
748

Richard Hult's avatar
Richard Hult committed
749 750
		window_view_selected (PLANNER_SIDEBAR (priv->sidebar), view_num, window);
		g_free (str);
751
	} else {
Richard Hult's avatar
Richard Hult committed
752 753
		window_view_selected (PLANNER_SIDEBAR (priv->sidebar), 0, window);
	}
Richard Hult's avatar
Richard Hult committed
754 755 756
}

static void
Richard Hult's avatar
Richard Hult committed
757 758 759
window_view_selected (PlannerSidebar *sidebar,
		      gint            index,
		      PlannerWindow  *window)
Richard Hult's avatar
Richard Hult committed
760
{
Richard Hult's avatar
Richard Hult committed
761
	PlannerWindowPriv *priv;
762 763 764 765
	GList             *list;
	PlannerView       *view;
	GtkAction         *action;

Richard Hult's avatar
Richard Hult committed
766
	priv = window->priv;
767

Richard Hult's avatar
Richard Hult committed
768 769 770 771 772 773 774 775 776 777
	list = g_list_nth (priv->views, index);
	if (list != NULL) {
		view = list->data;
	} else {
		view = NULL;
	}

	if (view == priv->current_view) {
		return;
	}
778

Richard Hult's avatar
Richard Hult committed
779 780 781 782 783 784 785 786 787 788
	if (priv->current_view != NULL) {
		planner_view_deactivate (priv->current_view);
	}

	if (view != NULL) {
		planner_view_activate (view);
	}

	gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), index);

Richard Hult's avatar
Richard Hult committed
789 790 791
	g_signal_handlers_block_by_func (sidebar, window_view_selected, window);
	planner_sidebar_set_active (PLANNER_SIDEBAR (sidebar), index);
	g_signal_handlers_unblock_by_func (sidebar, window_view_selected, window);
792

793 794
	action = gtk_action_group_get_action (priv->view_actions,
					      planner_view_get_name (view));
Richard Hult's avatar
Richard Hult committed
795
	if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) ) {
796 797
		gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
	}
798

Richard Hult's avatar
Richard Hult committed
799
	priv->current_view = view;
Richard Hult's avatar
Richard Hult committed
800 801

	planner_conf_set_string (CONF_ACTIVE_VIEW, planner_view_get_name (view), NULL);
802 803 804 805 806 807 808 809 810 811
}

static void
window_view_cb (GtkAction      *action,
		GtkRadioAction *current,
		gpointer        data)
{
	PlannerWindow     *window;
	GtkWidget         *sidebar;
	guint              index;
Richard Hult's avatar
Richard Hult committed
812

813 814
	window  = PLANNER_WINDOW (data);
	sidebar = window->priv->sidebar;
Richard Hult's avatar
Richard Hult committed
815

816
	index = gtk_radio_action_get_current_value(current);
Richard Hult's avatar
Richard Hult committed
817

818
	planner_sidebar_set_active (PLANNER_SIDEBAR (sidebar), index);
Richard Hult's avatar
Richard Hult committed
819 820 821
}

static void
822 823
window_new_cb (GtkAction *action,
	       gpointer   data)
Richard Hult's avatar
Richard Hult committed
824
{
Richard Hult's avatar
Richard Hult committed
825 826
	PlannerWindow     *window;
	PlannerWindowPriv *priv;
827
	GtkWidget         *new_window;
828

Richard Hult's avatar
Richard Hult committed
829
	window = PLANNER_WINDOW (data);
Richard Hult's avatar
Richard Hult committed
830 831 832 833 834 835
	priv   = window->priv;

	new_window = planner_application_new_window (priv->application);
	gtk_widget_show_all (new_window);
}

Richard Hult's avatar
Richard Hult committed
836
static gchar *
Richard Hult's avatar
Richard Hult committed
837
get_last_dir (PlannerWindow *window)
Richard Hult's avatar
Richard Hult committed
838
{
839
	gchar             *last_dir;
840

841
	last_dir = planner_conf_get_string (CONF_LAST_DIR, NULL);
842

Richard Hult's avatar
Richard Hult committed
843
	if (last_dir == NULL) {
844
		last_dir = g_strdup (g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS));
Richard Hult's avatar
Richard Hult committed
845
	}
846

Richard Hult's avatar
Richard Hult committed
847 848 849
	return last_dir;
}

Richard Hult's avatar
Richard Hult committed
850
static void
851 852
window_open_cb (GtkAction *action,
		gpointer   data)
Richard Hult's avatar
Richard Hult committed
853
{
Richard Hult's avatar
Richard Hult committed
854
	PlannerWindow     *window;
Anders Carlsson's avatar
Anders Carlsson committed
855
	GtkWidget         *file_chooser;
856
	GtkFileFilter     *filter;
857 858
	gint               response;
	gchar             *last_dir;
Richard Hult's avatar
Richard Hult committed
859

Richard Hult's avatar
Richard Hult committed
860
	window = PLANNER_WINDOW (data);
Richard Hult's avatar
Richard Hult committed
861

862
	file_chooser = gtk_file_chooser_dialog_new (_("Open a File"),
Anders Carlsson's avatar
Anders Carlsson committed
863 864 865 866 867
						    GTK_WINDOW (window),
						    GTK_FILE_CHOOSER_ACTION_OPEN,
						    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
						    GTK_STOCK_OPEN, GTK_RESPONSE_OK,
						    NULL);
868

869
	gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (file_chooser), TRUE);
870

871 872 873 874 875 876 877 878 879 880 881
	filter = gtk_file_filter_new ();
	gtk_file_filter_set_name (filter, _("Planner Files"));
	gtk_file_filter_add_pattern (filter, "*.planner");
	gtk_file_filter_add_pattern (filter, "*.mrproject");
	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (file_chooser), filter);

	filter = gtk_file_filter_new ();
	gtk_file_filter_set_name (filter, _("All Files"));
	gtk_file_filter_add_pattern (filter, "*");
	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (file_chooser), filter);

Richard Hult's avatar
Richard Hult committed
882
	last_dir = get_last_dir (window);
Anders Carlsson's avatar
Anders Carlsson committed
883
	gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (file_chooser), last_dir);
Richard Hult's avatar
Richard Hult committed
884 885
	g_free (last_dir);

Anders Carlsson's avatar
Anders Carlsson committed
886
	gtk_window_set_modal (GTK_WINDOW (file_chooser), TRUE);
Richard Hult's avatar
Richard Hult committed
887

Anders Carlsson's avatar
Anders Carlsson committed
888
	gtk_widget_show (file_chooser);
Richard Hult's avatar
Richard Hult committed
889

Anders Carlsson's avatar
Anders Carlsson committed
890
	response = gtk_dialog_run (GTK_DIALOG (file_chooser));
891
	gtk_widget_hide (file_chooser);
Richard Hult's avatar
Richard Hult committed
892 893

	if (response == GTK_RESPONSE_OK) {
894
		GSList *uris, *l;
Richard Hult's avatar
Richard Hult committed
895

896 897 898 899 900 901 902 903 904
		uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (file_chooser));

		if (uris) {
			gchar *filename;

			filename = g_filename_from_uri (uris->data, NULL, NULL);
			if (filename) {
				last_dir = g_path_get_dirname (filename);
				g_free (filename);
905
				planner_conf_set_string (CONF_LAST_DIR, last_dir, NULL);
906
				g_free (last_dir);
Richard Hult's avatar
Richard Hult committed
907 908
			}
		}
909

910
		for (l = uris; l; l = l->next) {
911
			planner_window_open_in_existing_or_new (window, l->data, FALSE);
912
		}
913

914 915
		g_slist_foreach (uris, (GFunc) g_free, NULL);
		g_slist_free (uris);
Richard Hult's avatar
Richard Hult committed
916
	}
917

918
	gtk_widget_destroy (file_chooser);
Richard Hult's avatar
Richard Hult committed
919 920 921
}

static void
922 923
window_save_as_cb (GtkAction *action,
		   gpointer   data)
Richard Hult's avatar
Richard Hult committed
924
{
Richard Hult's avatar
Richard Hult committed
925
	PlannerWindow *window;
Richard Hult's avatar
Richard Hult committed
926

Richard Hult's avatar
Richard Hult committed
927
	window = PLANNER_WINDOW (data);
Richard Hult's avatar
Richard Hult committed
928

Richard Hult's avatar
Richard Hult committed
929
        window_do_save_as (window);
Richard Hult's avatar
Richard Hult committed
930 931 932
}

static void
933 934
window_save_cb (GtkAction *action,
		gpointer   data)
Richard Hult's avatar
Richard Hult committed
935
{
Richard Hult's avatar
Richard Hult committed
936
	PlannerWindow     *window;
Richard Hult's avatar
Richard Hult committed
937

Richard Hult's avatar
Richard Hult committed
938
	window = PLANNER_WINDOW (data);
Richard Hult's avatar
Richard Hult committed
939

Richard Hult's avatar
Richard Hult committed
940
	window_do_save (window, FALSE);
Richard Hult's avatar
Richard Hult committed
941 942 943
}

static void
944 945
window_page_setup_cb (GtkAction *action,
		      gpointer   data)
Richard Hult's avatar
Richard Hult committed
946
{
Richard Hult's avatar
Richard Hult committed
947
	PlannerWindow     *window;
948 949
	GtkPageSetup      *old_page_setup, *new_page_setup;
	GtkPrintSettings  *settings;
950

Richard Hult's avatar
Richard Hult committed
951
	window = PLANNER_WINDOW (data);
Richard Hult's avatar
Richard Hult committed
952

953 954
	settings = planner_print_dialog_load_print_settings ();
	old_page_setup = planner_print_dialog_load_page_setup ();
955

956
	new_page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (window), old_page_setup, settings);
957

958
	g_object_unref (old_page_setup);
Richard Hult's avatar
Richard Hult committed
959

960 961
	planner_print_dialog_save_page_setup (new_page_setup);
	planner_print_dialog_save_print_settings (settings);
Richard Hult's avatar
Richard Hult committed
962

963 964
	g_object_unref (new_page_setup);
	g_object_unref (settings);
Richard Hult's avatar
Richard Hult committed
965 966 967
}

static void
968 969
window_print_cb (GtkAction *action,
		 gpointer   data)
Richard Hult's avatar
Richard Hult committed
970
{
971 972 973 974 975 976 977 978 979 980
	PlannerWindow           *window;
	PlannerWindowPriv       *priv;
	GtkPrintOperation       *print;
	GtkPrintSettings        *settings;
	GtkPageSetup            *page_setup;
	PlannerPrintJob         *job;
	GError                  *error = NULL;
	GtkPrintOperationResult  res;
	GtkPrintOperationAction  print_action;

Richard Hult's avatar
Richard Hult committed
981
	window = PLANNER_WINDOW (data);
Richard Hult's avatar
Richard Hult committed
982 983
	priv = window->priv;

984
	/* Load printer settings */
985
	print = gtk_print_operation_new ();
Richard Hult's avatar
Richard Hult committed
986

987 988 989 990
	settings = planner_print_dialog_load_print_settings ();
	gtk_print_operation_set_print_settings (print, settings);
	g_object_unref (settings);
	settings = NULL;
991

992 993 994 995
	page_setup = planner_print_dialog_load_page_setup ();
	gtk_print_operation_set_default_page_setup (print, page_setup);
	g_object_unref (page_setup);
	page_setup = NULL;
996

997
	job = planner_print_job_new (print, priv->views);
998

999 1000 1001 1002
	if (!strcmp (gtk_action_get_name (action), "FilePrint")) {
		print_action = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG;
	} else {
		print_action = GTK_PRINT_OPERATION_ACTION_PREVIEW;
1003 1004
	}

1005
	res = gtk_print_operation_run (print, print_action, GTK_WINDOW (window), &error);
1006

1007 1008
	if (res == GTK_PRINT_OPERATION_RESULT_ERROR) {
		GtkWidget *dialog;
1009

1010 1011 1012 1013 1014 1015
		dialog = gtk_message_dialog_new (GTK_WINDOW (window),
						 GTK_DIALOG_DESTROY_WITH_PARENT,
						 GTK_MESSAGE_ERROR,
						 GTK_BUTTONS_CLOSE,
						 "%s", error->message);
		g_error_free (error);
1016

1017 1018
		g_signal_connect (dialog, "response",
				  G_CALLBACK (gtk_widget_destroy), NULL);
1019 1020

		gtk_widget_show (dialog);
Richard Hult's avatar
Richard Hult committed
1021
	}
1022 1023 1024
	else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
		settings = gtk_print_operation_get_print_settings (print);
		planner_print_dialog_save_print_settings (settings);
Richard Hult's avatar
Richard Hult committed
1025
	}
1026
	g_object_unref (print);
Richard Hult's avatar
Richard Hult committed
1027 1028 1029 1030
	g_object_unref (job);
}

static void
1031 1032
window_close_cb (GtkAction *action,
		 gpointer   data)
Richard Hult's avatar
Richard Hult committed
1033
{
Richard Hult's avatar
Richard Hult committed
1034
	planner_window_close (PLANNER_WINDOW (data));
Richard Hult's avatar
Richard Hult committed
1035 1036 1037
}

static void
1038
window_exit_cb (GtkAction *action,
1039
		gpointer   data)
Richard Hult's avatar
Richard Hult committed
1040
{
Richard Hult's avatar
Richard Hult committed
1041 1042
	PlannerWindow     *window;
	PlannerWindowPriv *priv;
1043

Richard Hult's avatar
Richard Hult committed
1044
	window = PLANNER_WINDOW (data);
Richard Hult's avatar
Richard Hult committed
1045
	priv   = window->priv;
1046

Richard Hult's avatar
Richard Hult committed
1047 1048 1049 1050
	planner_application_exit (priv->application);
}

static void
1051 1052
window_redo_cb (GtkAction *action,
		gpointer           data)
Richard Hult's avatar
Richard Hult committed
1053
{
Richard Hult's avatar
Richard Hult committed
1054 1055 1056 1057 1058 1059
	PlannerWindow     *window;
	PlannerWindowPriv *priv;

	window = PLANNER_WINDOW (data);

	priv = window->priv;
1060

Richard Hult's avatar
Richard Hult committed
1061
	planner_cmd_manager_redo (priv->cmd_manager);
Richard Hult's avatar
Richard Hult committed
1062 1063 1064
}

static void
1065 1066
window_undo_cb (GtkAction *action,
		gpointer           data)
Richard Hult's avatar
Richard Hult committed
1067
{
Richard Hult's avatar
Richard Hult committed
1068 1069 1070 1071 1072 1073 1074 1075
	PlannerWindow     *window;
	PlannerWindowPriv *priv;

	window = PLANNER_WINDOW (data);

	priv = window->priv;

	planner_cmd_manager_undo (priv->cmd_manager);
Richard Hult's avatar
Richard Hult committed
1076 1077 1078
}

static void
1079 1080
window_project_props_cb (GtkAction *action,
			 gpointer           data)
Richard Hult's avatar
Richard Hult committed
1081
{
Richard Hult's avatar
Richard Hult committed
1082 1083
	PlannerWindow     *window;
	PlannerWindowPriv *priv;
1084

Richard Hult's avatar
Richard Hult committed
1085
	window = PLANNER_WINDOW (data);
Richard Hult's avatar
Richard Hult committed
1086
	priv = window->priv;
1087

Richard Hult's avatar
Richard Hult committed
1088 1089 1090 1091 1092 1093
	if (priv->properties_dialog) {
		gtk_window_present (GTK_WINDOW (priv->properties_dialog));
	} else {
		priv->properties_dialog = planner_project_properties_new (window);

		g_object_add_weak_pointer (G_OBJECT (priv->properties_dialog),
1094
					   (gpointer) &priv->properties_dialog);
Richard Hult's avatar
Richard Hult committed
1095 1096 1097 1098 1099 1100

		gtk_widget_show (priv->properties_dialog);
	}
}

static void
1101 1102
window_manage_calendars_cb (GtkAction *action,
			    gpointer           data)
Richard Hult's avatar
Richard Hult committed
1103
{
Richard Hult's avatar
Richard Hult committed
1104
	PlannerWindow *window;
1105

Richard Hult's avatar
Richard Hult committed
1106
	window = PLANNER_WINDOW (data);
Richard Hult's avatar
Richard Hult committed
1107

Richard Hult's avatar
Richard Hult committed
1108
	planner_window_show_calendar_dialog (window);
Richard Hult's avatar
Richard Hult committed
1109 1110 1111
}

static void
1112 1113
window_edit_day_types_cb (GtkAction *action,
			  gpointer           data)
Richard Hult's avatar
Richard Hult committed
1114
{
Richard Hult's avatar
Richard Hult committed
1115
	PlannerWindow *window;
1116

Richard Hult's avatar
Richard Hult committed
1117
	window = PLANNER_WINDOW (data);
Richard Hult's avatar
Richard Hult committed
1118

Richard Hult's avatar
Richard Hult committed
1119
	planner_window_show_day_type_dialog (window);
Richard Hult's avatar
Richard Hult committed
1120 1121 1122
}

static void
1123 1124
window_edit_phases_cb (GtkAction *action,
		       gpointer           data)
Richard Hult's avatar
Richard Hult committed
1125
{
Richard Hult's avatar
Richard Hult committed
1126 1127
	PlannerWindow     *window;
	PlannerWindowPriv *priv;
1128

Richard Hult's avatar
Richard Hult committed
1129
	window = PLANNER_WINDOW (data);
Richard Hult's avatar
Richard Hult committed
1130
	priv = window->priv;
1131

Richard Hult's avatar
Richard Hult committed
1132 1133 1134 1135
	if (priv->phase_dialog) {
		gtk_window_present (GTK_WINDOW (priv->phase_dialog));
	} else {
		priv->phase_dialog = planner_phase_dialog_new (window);
1136

Richard Hult's avatar
Richard Hult committed
1137
		g_object_add_weak_pointer (G_OBJECT (priv->phase_dialog),
1138
					   (gpointer) &priv->phase_dialog);
1139

Richard Hult's avatar
Richard Hult committed
1140 1141 1142 1143 1144
		gtk_widget_show (priv->phase_dialog);
	}
}

static void
1145
window_help_cb (GtkAction *action,
1146
		gpointer   data)
Richard Hult's avatar
Richard Hult committed
1147
{
1148
	planner_util_show_help (NULL);
Richard Hult's avatar
Richard Hult committed
1149 1150 1151
}

static void
1152
window_about_cb (GtkAction *action,
1153
		 gpointer   data)
Richard Hult's avatar
Richard Hult committed
1154
{
1155
	PlannerWindow *window;
1156
	gchar         *filename;
1157 1158
	GdkPixbuf     *pixbuf;
	const gchar   *authors[] = {
1159
		"Kurt Maute <kurt@maute.us>",
Richard Hult's avatar
Richard Hult committed
1160 1161 1162 1163 1164
		"Richard Hult <richard@imendio.com>",
		"Mikael Hallendal <micke@imendio.com>",
		"Alvaro del Castillo <acs@barrapunto.com>",
		NULL
	};
1165
	const gchar   *documenters[] = {
1166
		"Kurt Maute <kurt@maute.us>",
Richard Hult's avatar
Richard Hult committed
1167 1168 1169 1170
		"Alvaro del Castillo <acs@barrapunto.com>",
		"Pedro Soria-Rodriguez <sorrodp@alum.wpi.edu>",
		NULL
	};
1171

1172
	window = PLANNER_WINDOW (data);
1173

1174 1175 1176
	filename = mrp_paths_get_image_dir ("gnome-planner.png");
	pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
	g_free (filename);
1177

1178
	gtk_show_about_dialog (GTK_WINDOW (window),
1179 1180 1181 1182
			       "version", VERSION,
			       "comments", _("A Project Management application for the GNOME desktop"),
			       "authors", authors,
			       "documenters", documenters,
1183
			       "translator-credits", _("translator-credits"),
1184
			       "website", "http://live.gnome.org/Planner",
1185 1186 1187
			       "website-label", _("The Planner Homepage"),
			       "logo", pixbuf,
			       NULL);
1188

1189
	if (pixbuf != NULL) {
1190
		g_object_unref (pixbuf);
1191
	}
Richard Hult's avatar
Richard Hult committed
1192 1193 1194
}

static gboolean
Richard Hult's avatar
Richard Hult committed
1195
window_delete_event_cb (PlannerWindow *window,
Richard Hult's avatar
Richard Hult committed
1196
			gpointer       user_data)
Richard Hult's avatar
Richard Hult committed
1197
{
Richard Hult's avatar
Richard Hult committed
1198
	planner_window_close (window);
Richard Hult's avatar
Richard Hult committed
1199 1200 1201
	return TRUE;
}

1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
static void
window_drag_data_received_cb (GtkWidget        *widget,
			      GdkDragContext   *context,
			      int               x,
			      int               y,
			      GtkSelectionData *data,
			      guint             info,
			      guint             time,
			      PlannerWindow    *window)
{
	gchar             **uris;
	gint                i;
1214

1215 1216 1217 1218 1219
	if (data->length < 0 || data->format != 8) {
		g_message ("Don't know how to handle format %d", data->format);
		gtk_drag_finish (context, FALSE, FALSE, time);
		return;
	}
1220

Francisco Moraes's avatar
Francisco Moraes committed
1221
	uris = g_uri_list_extract_uris (data->data);
1222 1223 1224

	i = 0;
	while (uris[i]) {
1225
		planner_window_open_in_existing_or_new (window, uris[i], FALSE);
1226 1227
		i++;
	}
1228

1229 1230 1231 1232 1233
	g_strfreev (uris);

	gtk_drag_finish (context, TRUE, FALSE, time);
}

Richard Hult's avatar
Richard Hult committed
1234
static void
Richard Hult's avatar
Richard Hult committed
1235 1236
window_undo_state_changed_cb (PlannerCmdManager *manager,
			      gboolean           state,
1237
			      const gchar       *str,
Richard Hult's avatar
Richard Hult committed
1238 1239 1240
			      PlannerWindow     *window)
{
	PlannerWindowPriv *priv;
1241 1242
	GtkWidget         *widget;
	GtkWidget         *label;
Richard Hult's avatar
Richard Hult committed
1243 1244 1245

	priv = window->priv;

1246 1247 1248 1249
	g_object_set (gtk_action_group_get_action (priv->actions, "EditUndo"),
		      "sensitive", state,
		      NULL);
	g_object_set (gtk_action_group_get_action (priv->actions, "EditUndo"),
1250
		      "tooltip", str,
1251
		      NULL);
1252 1253 1254 1255 1256

	widget = gtk_ui_manager_get_widget (priv->ui_manager,
					    "/MenuBar/Edit/EditUndo");
	label = gtk_bin_get_child (GTK_BIN (widget));
	gtk_label_set_text (GTK_LABEL (label), str);
Richard Hult's avatar
Richard Hult committed
1257 1258 1259 1260 1261
}

static void
window_redo_state_changed_cb (PlannerCmdManager *manager,
			      gboolean           state,
1262
			      const gchar       *str,
Richard Hult's avatar
Richard Hult committed
1263 1264 1265
			      PlannerWindow     *window)
{
	PlannerWindowPriv *priv;
1266 1267
	GtkWidget         *widget;
	GtkWidget         *label;
1268

Richard Hult's avatar
Richard Hult committed
1269
	priv = window->priv;
1270

1271 1272 1273 1274
	g_object_set (gtk_action_group_get_action (priv->actions, "EditRedo"),
		      "sensitive", state,
		      NULL);
	g_object_set (gtk_action_group_get_action (priv->actions, "EditRedo"),
1275
		      "tooltip", str,
1276