GCC Code Coverage Report


Directory: ./
File: panels/color/cc-color-common.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 51 0.0%
Functions: 0 3 0.0%
Branches: 0 34 0.0%

Line Branch Exec Source
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2 *
3 * Copyright (C) 2012 Richard Hughes <richard@hughsie.com>
4 *
5 * Licensed under the GNU General Public License Version 2
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #include "config.h"
23
24 #include <glib/gi18n.h>
25
26 #include "cc-color-common.h"
27
28 gchar *
29 cc_color_device_get_title (CdDevice *device)
30 {
31 const gchar *tmp;
32 GString *string;
33
34 string = g_string_new ("");
35
36 /* is laptop panel */
37 if (cd_device_get_kind (device) == CD_DEVICE_KIND_DISPLAY &&
38 cd_device_get_embedded (device))
39 {
40 /* TRANSLATORS: This refers to the TFT display on a laptop */
41 g_string_append (string, _("Laptop Screen"));
42 goto out;
43 }
44
45 /* is internal webcam */
46 if (cd_device_get_kind (device) == CD_DEVICE_KIND_WEBCAM &&
47 cd_device_get_embedded (device))
48 {
49 /* TRANSLATORS: This refers to the embedded webcam on a laptop */
50 g_string_append (string, _("Built-in Webcam"));
51 goto out;
52 }
53
54 /* get the display model, falling back to something sane */
55 tmp = cd_device_get_model (device);
56 if (tmp == NULL)
57 tmp = cd_device_get_vendor (device);
58 if (tmp == NULL)
59 tmp = cd_device_get_id (device);
60
61 switch (cd_device_get_kind (device)) {
62 case CD_DEVICE_KIND_DISPLAY:
63 /* TRANSLATORS: an externally connected display, where %s is either the
64 * model, vendor or ID, e.g. 'LP2480zx Monitor' */
65 g_string_append_printf (string, _("%s Monitor"), tmp);
66 break;
67 case CD_DEVICE_KIND_SCANNER:
68 /* TRANSLATORS: a flatbed scanner device, e.g. 'Epson Scanner' */
69 g_string_append_printf (string, _("%s Scanner"), tmp);
70 break;
71 case CD_DEVICE_KIND_CAMERA:
72 /* TRANSLATORS: a camera device, e.g. 'Nikon D60 Camera' */
73 g_string_append_printf (string, _("%s Camera"), tmp);
74 break;
75 case CD_DEVICE_KIND_PRINTER:
76 /* TRANSLATORS: a printer device, e.g. 'Epson Photosmart Printer' */
77 g_string_append_printf (string, _("%s Printer"), tmp);
78 break;
79 case CD_DEVICE_KIND_WEBCAM:
80 /* TRANSLATORS: a webcam device, e.g. 'Philips HiDef Camera' */
81 g_string_append_printf (string, _("%s Webcam"), tmp);
82 break;
83 default:
84 g_string_append (string, tmp);
85 break;
86 }
87 out:
88 return g_string_free (string, FALSE);
89 }
90
91 static const gchar *
92 cc_color_device_kind_to_sort (CdDevice *device)
93 {
94 CdDeviceKind kind = cd_device_get_kind (device);
95 if (kind == CD_DEVICE_KIND_DISPLAY)
96 return "4";
97 if (kind == CD_DEVICE_KIND_SCANNER)
98 return "3";
99 if (kind == CD_DEVICE_KIND_CAMERA)
100 return "2";
101 if (kind == CD_DEVICE_KIND_WEBCAM)
102 return "1";
103 if (kind == CD_DEVICE_KIND_PRINTER)
104 return "0";
105 return "9";
106 }
107
108 gchar *
109 cc_color_device_get_sortable_base (CdDevice *device)
110 {
111 g_autofree gchar *title = cc_color_device_get_title (device);
112 return g_strdup_printf ("%s-%s-%s",
113 cc_color_device_kind_to_sort (device),
114 cd_device_get_id (device),
115 title);
116 }
117