File: sat-pref-debug.c

package info (click to toggle)
gpredict 1.1-7
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 8,280 kB
  • ctags: 2,873
  • sloc: ansic: 34,903; sh: 10,151; makefile: 417
file content (270 lines) | stat: -rw-r--r-- 7,653 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
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
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
    Gpredict: Real-time satellite tracking and orbit prediction program

    Copyright (C)  2001-2009  Alexandru Csete, OZ9AEC.

    Authors: Alexandru Csete <oz9aec@gmail.com>

    Comments, questions and bugreports should be submitted via
    http://sourceforge.net/projects/gpredict/
    More details can be found at the project home page:

            http://gpredict.oz9aec.net/
 
    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, visit http://www.fsf.org/
*/
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#ifdef HAVE_CONFIG_H
#  include <build-config.h>
#endif
#include "sat-cfg.h"
#include "gpredict-utils.h"
#include "sat-pref-debug.h"
#include "compat.h"


#define SEC_PER_DAY 86400
#define SEC_PER_WEEK 604800
#define SEC_PER_MONTH 18144000


static GtkWidget *level;
static GtkWidget *age;

static gboolean dirty = FALSE;
static gboolean reset = FALSE;

static void state_change_cb (GtkWidget *widget, gpointer data);
static void select_age      (void);
static void reset_cb        (GtkWidget *button, gpointer data);



/** \brief Create and initialise widgets for the debug messages tab.
 *
 *
 */
GtkWidget *sat_pref_debug_create ()
{
	GtkWidget   *vbox;    /* vbox containing the list part and the details part */
	GtkWidget   *hbox;
	GtkWidget   *rbut;
	GtkTooltips *tips;
	GtkWidget   *label;
	GtkWidget   *butbox;
	gchar       *msg;
    gchar       *confdir;


	vbox = gtk_vbox_new (FALSE, 10);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 20);
	gtk_box_set_spacing (GTK_BOX (vbox), 10);


	/* debug level */
	hbox = gtk_hbox_new (FALSE, 10);

	label = gtk_label_new (_("Debug level:"));
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);

	level = gtk_combo_box_new_text ();
	gtk_combo_box_append_text (GTK_COMBO_BOX (level), _("Level 0: None"));
	gtk_combo_box_append_text (GTK_COMBO_BOX (level), _("Level 1: Bug"));
	gtk_combo_box_append_text (GTK_COMBO_BOX (level), _("Level 2: Error"));
	gtk_combo_box_append_text (GTK_COMBO_BOX (level), _("Level 3: Warning"));
	gtk_combo_box_append_text (GTK_COMBO_BOX (level), _("Level 4: Info"));
	gtk_combo_box_append_text (GTK_COMBO_BOX (level), _("Level 5: Trace"));
	gtk_combo_box_set_active (GTK_COMBO_BOX (level),
							  sat_cfg_get_int (SAT_CFG_INT_LOG_LEVEL));
	g_signal_connect (G_OBJECT (level), "realize",
					  G_CALLBACK (gpredict_set_combo_tooltips),
					  _("Select the debug level. The higher the level, the more "
						"messages will be logged (so be careful with eLevel 5)."));
	g_signal_connect (G_OBJECT (level), "changed",
					  G_CALLBACK (state_change_cb), NULL);

	gtk_box_pack_start (GTK_BOX (hbox), level, FALSE, FALSE, 10);
	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);

	/* clean frequency */
	hbox = gtk_hbox_new (FALSE, 10);

	label = gtk_label_new (_("Delete log files older than:"));
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);

	age = gtk_combo_box_new_text ();
	gtk_combo_box_append_text (GTK_COMBO_BOX (age), _("Always delete"));
	gtk_combo_box_append_text (GTK_COMBO_BOX (age), _("1 day"));
	gtk_combo_box_append_text (GTK_COMBO_BOX (age), _("1 week"));
	gtk_combo_box_append_text (GTK_COMBO_BOX (age), _("1 month"));
	select_age ();
	g_signal_connect (G_OBJECT (age), "realize",
					  G_CALLBACK (gpredict_set_combo_tooltips),
					  _("Select how often gpredict should delete old log files."));
	g_signal_connect (G_OBJECT (age), "changed",
					  G_CALLBACK (state_change_cb), NULL);
	gtk_box_pack_start (GTK_BOX (hbox), age, FALSE, FALSE, 10);
	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);

	/* separator */
	gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, 0);

	/* info label */
    confdir = get_user_conf_dir ();
	msg = g_strdup_printf (_("Gpredict stores all run-time messages "
                             "in the %s%slogs%s folder. The "
							 "current log file is called gpredict.log and the "
							 "file is always kept until the next execution so "
							 "that you can examine it in case of a failure. "
							 "If old log files are kept, they are called "
							 "gpredict-XYZ.log where XYZ is a uniques timestamp."),
                           confdir, G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S);
	label = gtk_label_new (msg);
	gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
	gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
	g_free (msg);

	/* reset button */
	rbut = gtk_button_new_with_label (_("Reset"));
	tips = gtk_tooltips_new ();
	gtk_tooltips_set_tip (tips, rbut,
						  _("Reset settings to the default values."),
						  NULL);
	g_signal_connect (G_OBJECT (rbut), "clicked",
					  G_CALLBACK (reset_cb), NULL);
	butbox = gtk_hbutton_box_new ();
	gtk_button_box_set_layout (GTK_BUTTON_BOX (butbox), GTK_BUTTONBOX_END);
	gtk_box_pack_end (GTK_BOX (butbox), rbut, FALSE, TRUE, 10);

	gtk_box_pack_end (GTK_BOX (vbox), butbox, FALSE, TRUE, 0);

	return vbox;
}


/** \brief Select proper log file age in combo box. */
static void 
select_age (void)
{
	gint num = sat_cfg_get_int (SAT_CFG_INT_LOG_CLEAN_AGE);

	switch (num) {

	case SEC_PER_DAY:
		gtk_combo_box_set_active (GTK_COMBO_BOX (age), 1);
		break;

	case SEC_PER_WEEK:
		gtk_combo_box_set_active (GTK_COMBO_BOX (age), 2);
		break;

	case SEC_PER_MONTH:
		gtk_combo_box_set_active (GTK_COMBO_BOX (age), 3);
		break;

	default:
		gtk_combo_box_set_active (GTK_COMBO_BOX (age), 0);
	}

}

/** \brief User pressed cancel. Any changes to config must be cancelled.
 */
void
sat_pref_debug_cancel ()
{
}


/** \brief User pressed OK. Any changes should be stored in config.
 */
void
sat_pref_debug_ok     ()
{
	gint num = gtk_combo_box_get_active (GTK_COMBO_BOX (age));

	if (dirty) {
		/* store new values */
		sat_cfg_set_int (SAT_CFG_INT_LOG_LEVEL,
						 gtk_combo_box_get_active (GTK_COMBO_BOX (level)));

		switch (num) {

		case 1:
			sat_cfg_set_int (SAT_CFG_INT_LOG_CLEAN_AGE, SEC_PER_DAY);
			break;

		case 2:
			sat_cfg_set_int (SAT_CFG_INT_LOG_CLEAN_AGE, SEC_PER_WEEK);
			break;

		case 3:
			sat_cfg_set_int (SAT_CFG_INT_LOG_CLEAN_AGE, SEC_PER_MONTH);
			break;

		default:
			sat_cfg_set_int (SAT_CFG_INT_LOG_CLEAN_AGE, 0);
		}
	}

	else if (reset) {
		/* reset values */
		sat_cfg_reset_int (SAT_CFG_INT_LOG_LEVEL);
		sat_cfg_reset_int (SAT_CFG_INT_LOG_CLEAN_AGE);
	}

	dirty = FALSE;
	reset = FALSE;
}


static void
state_change_cb (GtkWidget *widget, gpointer data)
{
	dirty = TRUE;
}



static void
reset_cb               (GtkWidget *button, gpointer data)
{
	gint num = sat_cfg_get_int_def (SAT_CFG_INT_LOG_CLEAN_AGE);

	switch (num) {

	case SEC_PER_DAY:
		gtk_combo_box_set_active (GTK_COMBO_BOX (age), 1);
		break;

	case SEC_PER_WEEK:
		gtk_combo_box_set_active (GTK_COMBO_BOX (age), 2);
		break;

	case SEC_PER_MONTH:
		gtk_combo_box_set_active (GTK_COMBO_BOX (age), 3);
		break;

	default:
		gtk_combo_box_set_active (GTK_COMBO_BOX (age), 0);
	}

	gtk_combo_box_set_active (GTK_COMBO_BOX (level),
							  sat_cfg_get_int_def (SAT_CFG_INT_LOG_LEVEL));

	reset = TRUE;
	dirty = FALSE;
}