File: menus.c

package info (click to toggle)
gnotime 2.3.1~snapshot20091119-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 5,348 kB
  • ctags: 1,515
  • sloc: ansic: 15,043; sh: 3,857; xml: 1,367; makefile: 237; lisp: 138
file content (403 lines) | stat: -rw-r--r-- 10,934 bytes parent folder | download | duplicates (4)
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
/*   Application menubar menu layout for GTimeTracker
 *   Copyright (C) 1997,98 Eckehard Berns
 *   Copyright (C) 2002, 2003 Linas Vepstas <linas@linas.org>
 *
 *   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 <gnome.h>
#include <string.h>

#include "app.h"
#include "export.h"
#include "gtt.h"
#include "journal.h"
#include "menucmd.h"
#include "menus.h"
#include "plug-in.h"
#include "timer.h"


static GnomeUIInfo menu_main_file[] = {
	{GNOME_APP_UI_ITEM, N_("_Export Tasks"), NULL,
		export_file_picker,  TAB_DELIM_EXPORT, NULL,
		GNOME_APP_PIXMAP_STOCK, GTK_STOCK_SAVE,
		'E', GDK_CONTROL_MASK, NULL},
	{GNOME_APP_UI_ITEM, N_("Export _Projects"), NULL,
		export_file_picker, TODO_EXPORT, NULL,
		GNOME_APP_PIXMAP_STOCK, GTK_STOCK_SAVE,
		'P', GDK_CONTROL_MASK, NULL},
	GNOMEUIINFO_SEPARATOR,
	GNOMEUIINFO_MENU_EXIT_ITEM(app_quit,NULL),
	GNOMEUIINFO_END
};

/* Insert an item with a stock icon and a user data pointer */
#define GNOMEUIINFO_ITEM_STOCK_DATA(label, tooltip, callback, user_data, stock_id) \
   { GNOME_APP_UI_ITEM, label, tooltip, (gpointer)callback, user_data, NULL, \
     GNOME_APP_PIXMAP_STOCK, stock_id, 0, (GdkModifierType) 0, NULL }

static GnomeUIInfo menu_main_projects[] = {
  GNOMEUIINFO_MENU_NEW_ITEM(N_("_New ..."), NULL,
				  new_project, NULL),
	GNOMEUIINFO_SEPARATOR,
#define MENU_PROJECTS_CUT_POS 2
  {
    GNOME_APP_UI_ITEM,
    N_("Cu_t"),
    N_("Delete the selected project"),
    cut_project,
    NULL,
    NULL,
    GNOME_APP_PIXMAP_STOCK,
    GNOME_STOCK_PIXMAP_CUT,
    'D',
    GDK_CONTROL_MASK,
    NULL
  },
#define MENU_PROJECTS_COPY_POS 3
  {
    GNOME_APP_UI_ITEM,
    N_("_Copy"),
    N_("Copy the selected project"),
    copy_project,
    NULL,
    NULL,
    GNOME_APP_PIXMAP_STOCK,
    GNOME_STOCK_PIXMAP_COPY,
    'F',
    GDK_CONTROL_MASK,
    NULL
  },
#define MENU_PROJECTS_PASTE_POS 4
  {
    GNOME_APP_UI_ITEM,
    N_("_Paste"),
    N_("Paste the previously copied project"),
    paste_project,
    NULL,
    NULL,
    GNOME_APP_PIXMAP_STOCK,
    GNOME_STOCK_PIXMAP_PASTE,
    'G',
    GDK_CONTROL_MASK,
    NULL
  },
	GNOMEUIINFO_SEPARATOR,
	GNOMEUIINFO_ITEM_STOCK(N_("Edit _Times"),
		N_("Edit the time interval associated with this project"),
			       menu_howto_edit_times,
			       GNOME_STOCK_BLANK),
#define MENU_PROJECTS_PROP_POS 7
	GNOMEUIINFO_MENU_PROPERTIES_ITEM(menu_properties,NULL),
	GNOMEUIINFO_END
};

static GnomeUIInfo menu_main_settings[] = {
	GNOMEUIINFO_MENU_PREFERENCES_ITEM(menu_options,NULL),
	GNOMEUIINFO_END
};


static GnomeUIInfo menu_main_reports[] = {
	GNOMEUIINFO_ITEM_STOCK_DATA(N_("_Journal..."),
		N_("Show the journal for this project"),
			       show_report, JOURNAL_REPORT,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_ITEM_STOCK_DATA(N_("_Activity..."),
		N_("Show the journal together with the timestamps for this project"),
			       show_report, ACTIVITY_REPORT,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_ITEM_STOCK_DATA(N_("_Daily..."),
		N_("Show the total time spent on a project, day by day"),
			       show_report, DAILY_REPORT,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_ITEM_STOCK_DATA(N_("_Status..."),
		N_("Show the project descriptions and notes."),
			       show_report, STATUS_REPORT,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_ITEM_STOCK_DATA(N_("_To Do..."),
		N_("Show a sample to-do list"),
			       show_report, TODO_REPORT,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_ITEM_STOCK_DATA(N_("_Invoice..."),
		N_("Show a sample invoice for this project"),
			       show_report, INVOICE_REPORT,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_ITEM_STOCK_DATA(N_("_Query..."),
		N_("Run a sample Query Generator"),
			       show_report, QUERY_REPORT,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_ITEM_STOCK_DATA(N_("_Primer..."),
		N_("Show a sample introductory primer for designing custom reports"),
			       show_report, PRIMER_REPORT,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_ITEM_STOCK(N_("_New Report..."),
		N_("Define a path to a new GnoTime ghtml report file"),
			       new_report,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_ITEM_STOCK(N_("_Edit Reports..."),
		N_("Edit the entries in the Reports pulldown menu (this menu)"),
			       report_menu_edit,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_SEPARATOR,
	GNOMEUIINFO_END
};



static GnomeUIInfo menu_main_timer[] = {
#define MENU_TIMER_START_POS 0
	{
    GNOME_APP_UI_ITEM,
    N_("St_art"),
    N_("Start the timer running"),
    menu_start_timer,
    NULL,
    NULL,
    GNOME_APP_PIXMAP_STOCK,
    GNOME_STOCK_TIMER,
    'S',
    GDK_CONTROL_MASK,
    NULL
  },
#define MENU_TIMER_STOP_POS 1
  {
    GNOME_APP_UI_ITEM,
    N_("Sto_p"),
    N_("Stop the timer"),
    menu_stop_timer,
    NULL,
    NULL,
    GNOME_APP_PIXMAP_STOCK,
    GNOME_STOCK_TIMER_STOP,
    'W',
    GDK_CONTROL_MASK,
    NULL
  },
#define MENU_TIMER_TOGGLE_POS 2
  {
    GNOME_APP_UI_TOGGLEITEM,
    N_("_Timer Running"),
    NULL,
    menu_toggle_timer,
    NULL,
    NULL,
    GNOME_APP_PIXMAP_NONE,
    NULL,
    'T',
    GDK_CONTROL_MASK,
    NULL
  },
  GNOMEUIINFO_END
};


static GnomeUIInfo menu_main_help[] = {
	GNOMEUIINFO_HELP("gnotime"),
	GNOMEUIINFO_MENU_ABOUT_ITEM(about_box,NULL),
	GNOMEUIINFO_END
};


static GnomeUIInfo menu_main[] = {
	GNOMEUIINFO_MENU_FILE_TREE(menu_main_file),
	GNOMEUIINFO_SUBTREE(N_("_Projects"), menu_main_projects),
	GNOMEUIINFO_MENU_SETTINGS_TREE(menu_main_settings),
	GNOMEUIINFO_SUBTREE(N_("_Reports"), menu_main_reports),
	GNOMEUIINFO_SUBTREE(N_("_Timer"), menu_main_timer),
	GNOMEUIINFO_MENU_HELP_TREE(menu_main_help),
	GNOMEUIINFO_END
};



static GnomeUIInfo menu_popup[] = {
#define MENU_POPUP_JNL_POS 0
	GNOMEUIINFO_ITEM_STOCK_DATA(N_("_Activity..."),
		N_("Show the timesheet journal for this project"),
			       show_report, ACTIVITY_REPORT,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_ITEM_STOCK(N_("Edit _Times"),
		N_("Edit the time interval associated with this project"),
			       menu_howto_edit_times,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_ITEM_STOCK(N_("_New Diary Entry"),
		N_("Change the current task for this project"),
			       new_task_ui,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_ITEM_STOCK(N_("_Edit Diary Entry"),
		N_("Edit task header for this project"),
			       edit_task_ui,
			       GNOME_STOCK_BLANK),
	GNOMEUIINFO_SEPARATOR,
#define MENU_POPUP_CUT_POS 5
	GNOMEUIINFO_MENU_CUT_ITEM(cut_project,NULL),
#define MENU_POPUP_COPY_POS 6
	GNOMEUIINFO_MENU_COPY_ITEM(copy_project,NULL),
#define MENU_POPUP_PASTE_POS 7
	GNOMEUIINFO_MENU_PASTE_ITEM(paste_project,NULL),
	GNOMEUIINFO_SEPARATOR,
#define MENU_POPUP_PROP_POS 9
	GNOMEUIINFO_MENU_PROPERTIES_ITEM(menu_properties,NULL),
	GNOMEUIINFO_END
};




GtkMenuShell *
menus_get_popup(void)
{
	static GtkMenuShell *menu = NULL;

	if (menu) return menu;

	menu = (GtkMenuShell *)gtk_menu_new();
	gnome_app_fill_menu(menu, menu_popup, NULL, TRUE, 0);
	return menu;
}



void
menus_create(GnomeApp *app)
{
	menus_get_popup(); /* initialize it */
	gnome_app_create_menus(app, menu_main);

}

/* Global: the user-defined reports pull-down menu */
static GnomeUIInfo *reports_menu = NULL;

GnomeUIInfo *
gtt_get_reports_menu (void)
{
	return (reports_menu);
}

void
gtt_set_reports_menu (GnomeApp *app, GnomeUIInfo *new_menus)
{
	int i;
	char * path;

	/* Build the i18n menu path ... */
	/* (is this right ??? or is this pre-i18n ???) */
	path = g_strdup_printf ("%s/<Separator>", _("Reports"));

	/* If there are old menu items, remove them and free them. */
	if (reports_menu)
	{
		int nreports;
		for (i=0; GNOME_APP_UI_ENDOFINFO != reports_menu[i].type; i++) {}
		nreports = i;
		gnome_app_remove_menu_range (app, path, 1, nreports);

		if (new_menus != reports_menu)
		{
			for (i=0; i<nreports; i++)
			{
				// XXX can't free this, since 'append' recycles old pointers !!
				// there's probably a minor memory leak here ...
				// gtt_plugin_free(reports_menu[i].user_data);
			}
			g_free (reports_menu);
		}
	}

	/* Now install the new menu items. */
	reports_menu = new_menus;
	if (!reports_menu)
	{
		reports_menu = g_new0 (GnomeUIInfo, 1);
		reports_menu[0].type = GNOME_APP_UI_ENDOFINFO;
	}

	/* fixup */
	for (i=0; GNOME_APP_UI_ENDOFINFO != reports_menu[i].type; i++)
	{
		reports_menu[i].moreinfo = invoke_report;
	}
	gnome_app_insert_menus (app, path, reports_menu);
}

/* ============================================================ */
/* Slide a new menu entry into first place */

void
gtt_reports_menu_prepend_entry (GnomeApp *app, GnomeUIInfo *new_entry)
{
	int i, nitems;
	GnomeUIInfo * current_sysmenu, *new_sysmenu;

	current_sysmenu = gtt_get_reports_menu ();
	for (i=0; GNOME_APP_UI_ENDOFINFO != current_sysmenu[i].type; i++) {}
	nitems = i+1;

	new_sysmenu = g_new0 (GnomeUIInfo, nitems+1);
	new_sysmenu[0] = *new_entry;

	memcpy (&new_sysmenu[1], current_sysmenu, nitems*sizeof(GnomeUIInfo));
	gtt_set_reports_menu (app, new_sysmenu);
}

/* ============================================================ */

void
menus_add_plugins (GnomeApp *app)
{
	gtt_set_reports_menu (app, reports_menu);
}


void
menu_set_states(void)
{
	GtkCheckMenuItem *mi;

	if (!menu_main_timer[MENU_TIMER_START_POS].widget) return;
	gtk_widget_set_sensitive(menu_main_timer[MENU_TIMER_TOGGLE_POS].widget,
				 1);
	mi = GTK_CHECK_MENU_ITEM(menu_main_timer[MENU_TIMER_TOGGLE_POS].widget);
	/* Can't call the 'set_active' directly, as that issues an
	 * event which puts us in an infinite loop.  Instead,
	 * just set the value.
	 * gtk_check_menu_item_set_active (mi, timer_is_running());
	 */
	mi->active = timer_is_running();

	/* XXX would be nice to change this menu entry to say
	 * 'timer stopped' when the timer is stopped.  But don't
	 * know how to change the menu label in gtk */

	gtk_widget_set_sensitive(menu_main_timer[MENU_TIMER_START_POS].widget,
				 (FALSE == timer_is_running()) );
	gtk_widget_set_sensitive(menu_main_timer[MENU_TIMER_STOP_POS].widget,
				 (timer_is_running()) );
	gtk_widget_set_sensitive(menu_main_projects[MENU_PROJECTS_PASTE_POS].widget,
				 (have_cutted_project()) );

	if (menu_popup[MENU_POPUP_CUT_POS].widget)
	{
		gtk_widget_set_sensitive(menu_popup[MENU_POPUP_PASTE_POS].widget,
				 (have_cutted_project()) );
	}
}

/* ======================= END OF FILE ===================== */