1 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
3 // This file is part of CenterIM.
5 // CenterIM is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // CenterIM is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with CenterIM. If not, see <http://www.gnu.org/licenses/>.
28 const char *getStatusIndicator(PurpleStatus
*status
)
30 PurpleStatusType
*status_type
= purple_status_get_type(status
);
31 PurpleStatusPrimitive prim
= purple_status_type_get_primitive(status_type
);
34 case PURPLE_STATUS_UNSET
:
36 case PURPLE_STATUS_OFFLINE
:
38 case PURPLE_STATUS_AVAILABLE
:
40 case PURPLE_STATUS_UNAVAILABLE
:
42 case PURPLE_STATUS_INVISIBLE
:
44 case PURPLE_STATUS_AWAY
:
46 case PURPLE_STATUS_EXTENDED_AWAY
:
48 case PURPLE_STATUS_MOBILE
:
50 case PURPLE_STATUS_TUNE
:
52 case PURPLE_STATUS_MOOD
:
59 char *stripAccelerator(const char *label
)
61 g_assert(label
!= nullptr);
63 // Calculate length of the string without accelerators.
65 for (const char *p
= label
; *p
!= '\0'; ++p
)
69 // Allocate and populate the resulting string.
70 char *res
= g_new(char, len
);
72 for (const char *p
= label
; *p
!= '\0'; ++p
)
80 bool stringToNumber(const char *text
, long min
, long max
, long *out
)
82 g_assert(text
!= nullptr);
83 g_assert(out
!= nullptr);
87 *out
= std::strtol(text
, &endptr
, 10);
88 if (*text
== '\0' || *endptr
!= '\0') {
89 LOG
->warning(_("Value is not a number."));
92 if (errno
== ERANGE
|| *out
< min
|| *out
> max
) {
93 *out
= CLAMP(*out
, min
, max
);
94 LOG
->warning(_("Value is out of range [%ld, %ld]."), min
, max
);
102 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: