File: test-system-timezone.c

package info (click to toggle)
cinnamon-settings-daemon 6.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,896 kB
  • sloc: ansic: 31,182; xml: 205; python: 61; sh: 50; makefile: 20
file content (92 lines) | stat: -rw-r--r-- 2,347 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
/* Test for system timezone handling
 *
 * Copyright (C) 2008-2010 Novell, Inc.
 *
 * Authors: Vincent Untz <vuntz@gnome.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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
 */

#include <glib.h>
#include "system-timezone.h"

static void
timezone_print (void)
{
	SystemTimezone *systz;

	systz = system_timezone_new ();
        g_print ("Current timezone: %s\n", system_timezone_get (systz));
	g_object_unref (systz);
}

static int
timezone_set (const char *new_tz)
{
        GError *error;

        error = NULL;
        if (!system_timezone_set (new_tz, &error)) {
                g_printerr ("%s\n", error->message);
                g_error_free (error);
                return 1;
        }

	return 0;
}

int
main (int    argc,
      char **argv)
{
	int      retval;

	gboolean  get = FALSE;
	char     *tz_set = NULL;

	GError         *error;
	GOptionContext *context;
        GOptionEntry options[] = {
                { "get", 'g', 0, G_OPTION_ARG_NONE, &get, "Get the current timezone", NULL },
                { "set", 's', 0, G_OPTION_ARG_STRING, &tz_set, "Set the timezone to TIMEZONE", "TIMEZONE" },
                { NULL, 0, 0, 0, NULL, NULL, NULL }
        };

	retval = 0;


	context = g_option_context_new ("");
	g_option_context_add_main_entries (context, options, NULL);

	error = NULL;
	if (!g_option_context_parse (context, &argc, &argv, &error)) {
		g_printerr ("%s\n", error->message);
		g_error_free (error);
		g_option_context_free (context);

		return 1;
	}

	g_option_context_free (context);

	if (get || (!tz_set))
		timezone_print ();
	else if (tz_set)
		retval = timezone_set (tz_set);
	else
		g_assert_not_reached ();

        return retval;
}