File: planner-task-input-dialog.c

package info (click to toggle)
planner 0.14.6-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,872 kB
  • ctags: 6,212
  • sloc: ansic: 67,306; sh: 10,242; xml: 3,495; sql: 886; makefile: 762; python: 3
file content (146 lines) | stat: -rw-r--r-- 3,808 bytes parent folder | download | duplicates (5)
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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * 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 <glade/glade.h>
#include <gtk/gtk.h>
#include "libplanner/mrp-paths.h"
#include "planner-marshal.h"
#include "planner-task-input-dialog.h"
#include "planner-task-cmd.h"

typedef struct {
	MrpProject    *project;
	PlannerWindow *main_window;

	GtkWidget     *name_entry;
	GtkWidget     *work_entry;
} DialogData;

static void
task_input_dialog_free (gpointer user_data)
{
	DialogData *data = user_data;

	g_object_unref (data->project);
	g_object_unref (data->main_window);

	g_free (data);
}

static void
task_input_dialog_response_cb (GtkWidget *button,
			       gint       response,
			       GtkWidget *dialog)
{
	DialogData  *data;
	MrpTask     *task;
	const gchar *name;
	const gchar *workstr;
	gint         work;

	switch (response) {
	case GTK_RESPONSE_OK:
		data = g_object_get_data (G_OBJECT (dialog), "data");

		name = gtk_entry_get_text (GTK_ENTRY (data->name_entry));
		workstr = gtk_entry_get_text (GTK_ENTRY (data->work_entry));

		work = 60*60*8 * g_strtod (workstr, NULL);

		task = g_object_new (MRP_TYPE_TASK,
				     "work", work,
				     "name", name,
				     NULL);

		/*mrp_project_insert_task (data->project, NULL, -1, task);*/
		planner_task_cmd_insert (data->main_window,
					 NULL, -1, 0, 0, task);

		gtk_entry_set_text (GTK_ENTRY (data->name_entry), "");
		gtk_entry_set_text (GTK_ENTRY (data->work_entry), "");

		gtk_widget_grab_focus (data->name_entry);
		break;

	case GTK_RESPONSE_DELETE_EVENT:
	case GTK_RESPONSE_CANCEL:
		gtk_widget_destroy (dialog);
		break;

	default:
		g_assert_not_reached ();
		break;
	}
}

static void
task_input_dialog_activate_cb (GtkWidget *widget, GtkDialog *dialog)
{
	gtk_dialog_response (dialog, GTK_RESPONSE_OK);
}

GtkWidget *
planner_task_input_dialog_new (PlannerWindow *main_window)
{
	GtkWidget  *dialog;
	DialogData *data;
	GladeXML   *gui;
	MrpProject *project;
	gchar      *filename;

	data = g_new0 (DialogData, 1);

	project = planner_window_get_project (main_window);

	data->project = g_object_ref (project);
	data->main_window = g_object_ref (main_window);

	filename = mrp_paths_get_glade_dir ("task-input-dialog.glade");
	gui = glade_xml_new (filename, NULL, NULL);
	g_free (filename);

	dialog = glade_xml_get_widget (gui, "task_input_dialog");
	g_signal_connect (dialog,
			  "response",
			  G_CALLBACK (task_input_dialog_response_cb),
			  dialog);

	data->name_entry = glade_xml_get_widget (gui, "name_entry");
	g_signal_connect (data->name_entry,
			  "activate",
			  G_CALLBACK (task_input_dialog_activate_cb),
			  dialog);

	data->work_entry = glade_xml_get_widget (gui, "work_entry");
	g_signal_connect (data->work_entry,
			  "activate",
			  G_CALLBACK (task_input_dialog_activate_cb),
			  dialog);

	g_object_set_data_full (G_OBJECT (dialog),
				"data",
				data,
				task_input_dialog_free);

        return dialog;
}