File: planner-main.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 (207 lines) | stat: -rw-r--r-- 5,700 bytes parent folder | download
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
/* -*- 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 }
	};

static gchar *
migrate_gconf_settings (const gchar *name)
{
	gboolean   needed = TRUE;
	GError    *error = NULL;
	GKeyFile  *kf;
	gchar    **list;
	gchar     *msg = NULL;
	gsize      i, n;

	kf = g_key_file_new ();

	g_key_file_load_from_data_dirs (kf, "gsettings-data-convert",
					NULL, G_KEY_FILE_NONE, NULL);
	list = g_key_file_get_string_list (kf, "State", "converted", &n, NULL);

	if (list) {
		for (i = 0; i < n; i++)
			if (!g_strcmp0 (list[i], name)) {
				needed = FALSE;
				break;
			}

		g_strfreev (list);
	}

	g_key_file_free (kf);

	if (needed) {
		g_spawn_command_line_sync ("gsettings-data-convert",
					   NULL, NULL, NULL, &error);
		if (error) {
			msg = g_strdup_printf (
				_("Could not migrate old GConf settings: %s\n"
				  "Please make sure that GConf is installed "
				  "and the gsettings-data-convert tool is in "
				  "your PATH.\nAlternatively, ignore this "
				  "message and convert your old settings "
				  "manually."), error->message);
			g_error_free (error);
		} else {
			msg = g_strdup (_("Old GConf settings were "
					  "migrated successfully."));

			/* Allow some time for the GSettings backend
			   to record the changes, otherwise the
			   default values from the new schema might be
			   set.  This timeout is still insufficient to
			   migrate all keys.  */
			sleep (1);
		}
	}

	return msg;
}

static void
show_migration_dialog (GtkWindow *window, gchar *msg)
{
	GtkWidget *dlg;

	dlg = gtk_message_dialog_new (window, GTK_DIALOG_DESTROY_WITH_PARENT,
				      GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
				      "%s", msg);
	g_free (msg);
	gtk_dialog_run (GTK_DIALOG (dlg));
	gtk_widget_destroy (dlg);
}

int
main (int argc, char **argv)
{
        GtkWidget       *main_window;
	GError          *error = NULL;
	gchar           *gconf_migration_msg = 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;
	}

	gconf_migration_msg = migrate_gconf_settings ("planner.convert");

	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 (gconf_migration_msg)
		show_migration_dialog (GTK_WINDOW (main_window),
				       gconf_migration_msg);

	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;
}