aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/misc.c
blob: acae5d8e1ee52b2b373e44075309b5274ae12a0a (plain) (blame)
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
/*
 * Evolution calendar - Miscellaneous utility functions
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>  
 *
 *
 * Authors:
 *      Federico Mena-Quintero <federico@ximian.com>
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <ctype.h>
#include <time.h>
#include <libedataserver/e-url.h>
#include <glib/gi18n.h>

#include "misc.h"



/**
 * string_is_empty:
 * @value: A string.
 *
 * Returns whether a string is NULL, the empty string, or completely made up of
 * whitespace characters.
 *
 * Return value: TRUE if the string is empty, FALSE otherwise.
 **/
gboolean
string_is_empty (const char *value)
{
    const char *p;
    gboolean empty;

    empty = TRUE;

    if (value) {
        p = value;
        while (*p) {
            if (!isspace ((unsigned char) *p)) {
                empty = FALSE;
                break;
            }
            p++;
        }
    }
    return empty;

}

/**
 * get_uri_without_password
 */
char *
get_uri_without_password (const char *full_uri)
{
    EUri *uri;
    char *uristr;

    uri = e_uri_new (full_uri);
    if (!uri)
        return NULL;

    uristr = e_uri_to_string (uri, FALSE);
    e_uri_free (uri);

    return uristr;
 }

gint
get_position_in_array (GPtrArray *objects, gpointer item)
{
    gint i;

    for (i = 0; i < objects->len; i++) {
        if (g_ptr_array_index (objects, i) == item)
            return i;
    }

    return -1;
}

char *
calculate_time (time_t start, time_t end)
{
    time_t difference = end - start;
    char *str;
    int   hours, minutes;
    char *times[4];
    char *joined;
    int   i;

        i = 0;
    if (difference >= 3600) {
        hours = difference / 3600;
        difference %= 3600;

        times[i++] = g_strdup_printf (ngettext("%d hour", "%d hours", hours), hours);
    }
    if (difference >= 60) {
        minutes = difference / 60;
        difference %= 60;

        times[i++] = g_strdup_printf (ngettext("%d minute", "%d minutes", minutes), minutes);
    }
    if (i == 0 || difference != 0) {
        /* TRANSLATORS: here, "second" is the time division (like "minute"), not the ordinal number (like "third") */
        times[i++] = g_strdup_printf (ngettext("%d second", "%d seconds", difference), (int)difference);
    }

    times[i] = NULL;
    joined = g_strjoinv (" ", times);
    str = g_strconcat ("(", joined, ")", NULL);
    while (i > 0)
        g_free (times[--i]);
    g_free (joined);

    return str;
}
>2-7/+6 * - Update to 1.9.72sunpoet2015-03-182-3/+3 * print/rubygem-rbpdf: Add port.xmj2015-03-154-0/+26 * - Simplify MASTER_SITESamdmi32015-03-152-2/+5 * - Update to 1.0.67sunpoet2015-03-132-3/+3 * Update KDE SC to 4.14.3alonso2015-03-121-2/+2 * Add CPE informationjohans2015-03-101-1/+2 * - add CPE stringdinoex2015-03-081-1/+2 * Update to upstream version 20150228riggs2015-03-072-4/+4 * print/cups-filters: update 1.0.65 -> 1.0.66robak2015-03-062-3/+3 * The FreeBSD Xfce team proudly presents Xfce 4.12.olivierd2015-03-061-28/+9 * Remove Author from pkg-descr and white space fixesbapt2015-03-035-8/+3 * Deprecate ports broken for more than 6 monthsantoine2015-02-281-0/+2 * - Update to 1.0.4jhale2015-02-262-3/+3 * Update to 1.0.65arved2015-02-252-6/+5 * 1: add LICENSE/LICENSE_FILE.vanilla2015-02-241-1/+4 * Update to 2.1.3.rakuco2015-02-203-3/+14 * - Remove deprecated USE_KDE4=kdehiermakc2015-02-201-1/+1 * - Fix installation when DOCS option is offnivit2015-02-191-0/+2 * Fix libpng issue.hrs2015-02-194-19/+181 * - Release maintainership (it was not intended in previous commit)sunpoet2015-02-191-1/+1 * - Update to 20140814.2sunpoet2015-02-194-18/+27 * Fix with perl 5.20+.mat2015-02-182-1/+12 * - Update to 20150214danilo2015-02-173-5/+50 * Upgrade to 20140814.1.vanilla2015-02-164-32/+45 * Add a patch, that removes the reference to bash frommi2015-02-151-0/+44 * print/foomatic-db-engine: Update version 4.0.11=>4.0.12bofh2015-02-152-7/+6 * - Add security/linux-c6-nss to dependenciesnivit2015-02-131-2/+2 * Update system-config-printer to 1.4.7.kwm2015-02-104-19/+22 * print/hplip:makc2015-02-107-16/+64 * print/ft2demos: Update version 2.5.2=>2.5.5bofh2015-02-072-4/+3 * Cleanup plistbapt2015-02-053-17/+1 * Update poppler to 0.30.0 [1].kwm2015-02-037-6/+7 * Fix build with GCC 4.2.jkim2015-02-031-0/+11 * print/scribus: welcome 1.4.5 releasebsam2015-02-014-17/+45 * - Add pTeX support to xdvik. This improvement is imported fromhrs2015-01-3174-23/+12707 * Use bin/perl instead of bin/perlN.NN.N in the shebang line.hrs2015-01-291-3/+3 * Update to 0.1.2.jkim2015-01-293-4/+4 * - Update to 1.0.62amdmi32015-01-273-7/+7 * - Update to upstream version 20141230 (same as v2.1.0)jbeich2015-01-252-8/+7 * Unbreak build on 8.xjbeich2015-01-251-0/+15 * Fix LIB_DEPENDSantoine2015-01-251-2/+2 * Fix some _DEPENDSantoine2015-01-251-1/+2 * Update texi2dvi to latest releasejohans2015-01-252-10/+9 * Switch ports depending on docbook* through a directory name to a package name,antoine2015-01-241-1/+1 * - Add linux-*-dbus-libs to run dependencies [1]nivit2015-01-221-4/+5 * Drop redundant stuff from pkg-plist.mandree2015-01-201-2/+0 * Fix build on headantoine2015-01-171-1/+1 * Drop maintainership as I no longer use these software nor have time andrafan2015-01-171-1/+1 * Update graphics/giflib to 5.0.5antoine2015-01-151-0/+1 * - Update to 1.9.70sunpoet2015-01-142-3/+3 * Update freetype2 to 2.5.5.kwm2015-01-083-6/+4 * - Update to 0.09sunpoet2015-01-053-6/+7 * - Update to upstream version 20141126riggs2015-01-0413-911/+296 * print/cups-client via print/cups-base: treat avahi/dnssd explicitelybsam2015-01-041-16/+23 * security/libgcrypt: 1.6.1 -> 1.6.2, bump dependspi2015-01-031-3/+3 * Update to 1.8.8 release.ale2014-12-302-11/+11 * Update to 0.2.2bapt2014-12-302-3/+4 * Update to 0.2.1bapt2014-12-302-3/+3 * - Update graphics/libspiro to 0.2.20131203wen2014-12-281-1/+1 * Mark as broken after png updatebapt2014-12-261-2/+3 * Bump portrevision after png updatebapt2014-12-2618-15/+18 * Change libpng15.so to libpng.so in LIB_DEPENDS to prepare the upgradeantoine2014-12-2616-16/+16 * Properly support png 1.5antoine2014-12-253-4/+3 * Properly support png 1.5bapt2014-12-254-22/+197 * Change my non-FreeBSD MAINTAINER mail to bofh@bofh2014-12-245-5/+5 * Unbreakantoine2014-12-231-3/+3 * Use DIST_SUBDIR for rolling distfilesjohans2014-12-232-8/+10 * Update texinfo.tex and texi2dvi to latest releasejohans2014-12-222-5/+5 * cleanup plistbapt2014-12-2111-19/+2 * - Revive print/lgrind, now distributed as one filepawel2014-12-1910-0/+134 * - Move kpse* scripts from texlive-base to tex-kpathsea.hrs2014-12-153-15/+40 * Chase update of freetype2 to 2.5.4.riggs2014-12-142-5/+5 * - Reset maintainership of my portsgahr2014-12-112-2/+2 * print/pdflib: Make DragonFly respect Perl's LDDFLAGS toomarino2014-12-111-2/+3 * Replace USES=libtool:oldver with USES=libtool or USES=libtool:keepla intijl2014-12-092-2/+2 * Update "BSD" license in print categoryfeld2014-12-072-2/+2 * Update freetype2 to 2.5.4.kwm2014-12-073-5/+4 * Respect Perl's LDDLFLAGS.mat2014-12-051-3/+11 * Add etex symlink.hrs2014-12-041-0/+1 * Update to 0.9.36.kwm2014-12-033-8/+8 * print/cups-base: Fix build when PAM option is enabledmarino2014-11-282-47/+46 * print/muttprint: provide option to build it without X11 supportmarino2014-11-281-3/+11 * Remove print/pdfjam, it's included in texlive-baseantoine2014-11-284-51/+0 * Properly strip libraries in cups-base, cups-client and cups-image portsamdmi32014-11-281-4/+3 * Remove print/latexmk, it's included in texlive-baseantoine2014-11-285-67/+0 * Mark a few ports BROKEN after GNOME 2 removalantoine2014-11-281-0/+2 * Turn on the LCD_FILTERING option by default for sub-pixel rendering. [1]kwm2014-11-272-3/+3 * Change the way Perl modules are installed, update the default Perl to 5.18.mat2014-11-2629-89/+37 * Bump PORTREVISION after graphics/poppler update to 0.26.3makc2014-11-257-5/+7 * - Strip binaries properly.hrs2014-11-234-34/+39 * - Strip binaries properly.hrs2014-11-234-21/+29 * Update to 9.15. Changes include:hrs2014-11-2321-142/+133 * Resurrect print/ghostscript7{,-commfont,-jpnfont,-korfont,-nox11}.hrs2014-11-23129-0/+9024 * - Fix an incorrect usage of stagedir. The program was looking for its files indanilo2014-11-182-53/+120 * Reset miwi's maintainership per his demandbapt2014-11-182-2/+2 * Cleanup plistantoine2014-11-13119-11088/+155 * Upgrade CentOS to 6.6xmj2014-11-112-5/+6 * - Let the rc script require the mdnsd or avahi_daemon rc scripts [1]tijl2014-11-073-2/+25 * print/foomatic-db-engine: Not jobs safemarino2014-11-071-1/+3 * - Remove a few remaining $Id$ from pkg-plistsak2014-11-071-1/+0 * - Chase GNU Emacs updatesashish2014-11-052-1/+2 * Update Qt5 ports to 5.3.2.rakuco2014-11-052-1/+4 * Fix build with old make.hrs2014-11-041-7/+8 * Update to 11.88.hrs2014-11-034-36/+147 * Fix a warning message when \usepackage[magyar]{babel} and utf8 inputenchrs2014-11-031-1/+2 * print/hp2xx: multiple fixesrobak2014-11-023-21/+27 * Allow building with bison 3antoine2014-11-021-0/+37