File: planner-main.c

package info (click to toggle)
planner 0.14.6-9
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 14,988 kB
  • sloc: ansic: 67,169; sh: 10,242; xml: 3,928; sql: 886; makefile: 694; python: 33
file content (131 lines) | stat: -rw-r--r-- 3,810 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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2003 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 <gtk/gtk.h>
#include <glib/gi18n.h>
#include "libplanner/mrp-paths.h"
#include "planner-application.h"
#include "planner-window.h"

static PlannerApplication *application;

/* Command line options */
static gchar *geometry = NULL;

static GOptionEntry options[] = {
		{ "geometry", 'g', 0, G_OPTION_ARG_STRING, &geometry, N_("Create the initial window with the given geometry."), N_("GEOMETRY")},
		{ NULL }
	};

int
main (int argc, char **argv)
{
        GtkWidget       *main_window;
	GError          *error = NULL;
	gchar           *filename;
	gchar           *locale_dir;
	gint             i;

	locale_dir = mrp_paths_get_locale_dir ();
	bindtextdomain (GETTEXT_PACKAGE, locale_dir);
	g_free(locale_dir);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	g_set_application_name ("Planner");

	 /* Initialize GTK+ program */
	if (!gtk_init_with_args (&argc, &argv,
	                         _("- Planner project management"),
	                         options,
	                         GETTEXT_PACKAGE,
	                         &error)) {
		g_printerr (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
		            error->message, argv[0]);
		g_error_free (error);
		return 1;
	}

	filename = mrp_paths_get_image_dir ("gnome-planner.png");
	gtk_window_set_default_icon_from_file (filename, NULL);
	g_free (filename);

#ifdef WIN32
	gchar *module_dir;
	module_dir = g_win32_get_package_installation_directory_of_module (NULL);
	filename = g_build_filename (module_dir, "share/icons");
	g_free (module_dir);
	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default(),
					   filename);
	g_free (filename);
#endif

	application = planner_application_new ();
	main_window = planner_application_new_window (application);

	if ((geometry) && !gtk_window_parse_geometry (GTK_WINDOW (main_window), geometry))
		g_warning(_("Invalid geometry string \"%s\"\n"), geometry);

	gtk_widget_show_all (main_window);

	if (argc > 1) {
		i = 1;
		while (argv[i]) {
			if (g_str_has_prefix (argv[i], "file:")) {
				planner_window_open_in_existing_or_new (
					PLANNER_WINDOW (main_window), argv[i], FALSE);
			} else {
				gchar *uri;

				if (!g_path_is_absolute (argv[i])) {
					/* Relative path. */
					gchar *cwd, *tmp;

					cwd = g_get_current_dir ();
					tmp = g_build_filename (cwd, argv[i], NULL);
					uri = g_filename_to_uri (tmp, NULL, NULL);
					g_free (tmp);
					g_free (cwd);
				} else {
					uri = g_filename_to_uri (argv[i], NULL, NULL);
				}

				if (uri) {
					planner_window_open_in_existing_or_new (
						PLANNER_WINDOW (main_window), uri, FALSE);
					g_free (uri);
				}
			}

			i++;
		}
	}

        gtk_main ();

	g_object_unref (application);

        return 0;
}