2
* util.c -- Misc utilities
4
* Copyright (C) 2007-2008 Johannes H. Jensen <joh@pseudoberries.com>
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
* Johannes H. Jensen <joh@pseudoberries.com>
27
#include <glib-object.h>
31
* Calculates the alarm timestamp given hour, min and secs.
34
get_alarm_timestamp (guint hour, guint minute, guint second)
40
tm = localtime (&now);
42
// Check if the alarm is for tomorrow
43
if (hour < tm->tm_hour ||
44
(hour == tm->tm_hour && minute < tm->tm_min) ||
45
(hour == tm->tm_hour && minute == tm->tm_min && second < tm->tm_sec)) {
47
g_debug("Alarm is for tomorrow.");
57
strftime (tmp, sizeof (tmp), "%c", tm);
58
g_debug ("Alarm will trigger at %s", tmp);
64
* Construct a Uppercased name of filename without the extension.
67
to_basename (const gchar *filename)
72
len = strlen (filename);
74
for (i = len-1; i > 0; i--) {
75
if (filename[i] == '.') {
81
// Extension not found
84
result = g_strndup (filename, i);
86
// Make first character Uppercase
87
result[0] = g_utf8_strup (result, 1)[0];
96
command_run (const gchar *command) {
99
if (!g_spawn_command_line_async (command, &err)) {
100
g_critical ("Could not launch `%s': %s", command, err->message);
110
is_executable_valid (gchar *executable)
114
path = g_find_program_in_path (executable);