tdebluez
devicemimeconverter.cpp
Go to the documentation of this file.
1
/*
2
*
3
* Device Mime Converter for libtdebluez
4
*
5
* Copyright (C) 2003 by Fred Schaettgen
6
* Copyright (C) 2018 Emanoil Kotsev <deloptes@gmail.com>
7
*
8
*
9
* This file is part of libtdebluez.
10
*
11
* libtdebluez is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; either version 2 of the License, or
14
* (at your option) any later version.
15
*
16
* libtdebluez is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
20
*
21
* You should have received a copy of the GNU General Public License
22
* along with kbluetooth; if not, write to the Free Software
23
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
*
25
*/
26
27
#include <kmimetype.h>
28
29
#include "
devicemimeconverter.h
"
30
31
namespace
TDEBluetooth
32
{
33
34
DeviceMimeConverter::DeviceMimeConverter
()
35
{
36
getIconName
(
"bluetooth/unknown-device-class"
);
37
getIconName
(
"bluetooth/misc-device-class"
);
38
getIconName
(
"bluetooth/computer-device-class"
);
39
getIconName
(
"bluetooth/phone-device-class"
);
40
getIconName
(
"bluetooth/lan-device-class"
);
41
getIconName
(
"bluetooth/av-device-class"
);
42
getIconName
(
"bluetooth/peripheral-device-class"
);
43
getIconName
(
"bluetooth/mouse-device-class"
);
44
getIconName
(
"bluetooth/keyboard-device-class"
);
45
getIconName
(
"bluetooth/imaging-device-class"
);
46
}
47
48
void
DeviceMimeConverter::getIconName
(
TQString
mime
)
49
{
50
TQString
iconName
= KMimeType::mimeType(
mime
)->icon(TQString::null,
false
);
51
mimeTypeToIconMap
[
mime
] =
iconName
;
52
}
53
54
DeviceMimeConverter
*
DeviceMimeConverter::getInstance
()
55
{
56
static
DeviceMimeConverter
instance
;
57
return
&
instance
;
58
}
59
60
TQString
DeviceMimeConverter::classToIconName
(
int
n
)
61
{
62
return
DeviceMimeConverter::mimeTypeToIcon
(
DeviceMimeConverter::classToMimeType
(
n
));
63
}
64
65
/*
66
* device classes
67
*
68
AUDIO_VIDEO (Value: 0x00000400)
69
COMPUTER (Value: 0x00000100)
70
HEALTH (Value: 0x00000900)
71
IMAGING (Value: 0x00000600)
72
MISC (Value: 0x00000000)
73
NETWORKING (Value: 0x00000300)
74
PERIPHERAL (Value: 0x00000500)
75
PHONE (Value: 0x00000200)
76
TOY (Value: 0x00000800)
77
UNCATEGORIZED (Value: 0x00001f00)
78
WEARABLE (Value: 0x00000700)
79
*/
80
81
TQString
DeviceMimeConverter::classToMimeType
(
int
n
)
82
{
83
TQString
mimeType
;
84
int
major
= ((
n
& 0x001F00) >> 8);
85
int
minor
= ((
n
>> 2) & 0x30);
86
switch
(
major
)
87
{
88
case
0x00:
89
mimeType
=
"bluetooth/misc-device-class"
;
90
break
;
91
case
0x01:
92
mimeType
=
"bluetooth/computer-device-class"
;
93
break
;
94
case
0x02:
95
mimeType
=
"bluetooth/phone-device-class"
;
96
break
;
97
case
0x03:
98
mimeType
=
"bluetooth/lan-device-class"
;
99
break
;
100
case
0x04:
101
mimeType
=
"bluetooth/av-device-class"
;
102
break
;
103
case
0x05:
104
switch
(
minor
)
105
{
106
case
0x10:
107
mimeType
=
"bluetooth/keyboard-device-class"
;
108
break
;
109
case
0x20:
110
mimeType
=
"bluetooth/mouse-device-class"
;
111
break
;
112
default
:
113
mimeType
=
"bluetooth/peripheral-device-class"
;
114
}
115
break
;
116
case
0x06:
117
mimeType
=
"bluetooth/imaging-device-class"
;
118
break
;
119
case
0x07:
120
mimeType
=
"bluetooth/wearable-device-class"
;
121
break
;
122
case
0x08:
123
mimeType
=
"bluetooth/toy-device-class"
;
124
break
;
125
case
0x09:
126
mimeType
=
"bluetooth/health-device-class"
;
127
break
;
128
default
:
129
mimeType
=
"bluetooth/unknown-device-class"
;
130
}
131
return
mimeType
;
132
}
133
134
TQString
DeviceMimeConverter::mimeTypeToIcon
(
TQString
mime
)
135
{
136
DeviceMimeConverter
*
c
=
DeviceMimeConverter::getInstance
();
137
if
(
c
->mimeTypeToIconMap.find(
mime
) !=
c
->mimeTypeToIconMap.end())
138
{
139
return
c
->mimeTypeToIconMap[
mime
];
140
}
141
else
142
{
143
return
c
->mimeTypeToIconMap[
"bluetooth/unknown-device-class"
];
144
}
145
}
146
147
}
// TDEBluetooth
TDEBluetooth::DeviceMimeConverter
Definition
devicemimeconverter.h:38
TDEBluetooth::DeviceMimeConverter::mimeTypeToIcon
static TQString mimeTypeToIcon(TQString mimeType)
Definition
devicemimeconverter.cpp:134
TDEBluetooth::DeviceMimeConverter::DeviceMimeConverter
DeviceMimeConverter()
Definition
devicemimeconverter.cpp:34
TDEBluetooth::DeviceMimeConverter::classToMimeType
static TQString classToMimeType(int deviceClass)
Definition
devicemimeconverter.cpp:81
TDEBluetooth::DeviceMimeConverter::getInstance
static DeviceMimeConverter * getInstance()
Definition
devicemimeconverter.cpp:54
TDEBluetooth::DeviceMimeConverter::classToIconName
static TQString classToIconName(int deviceClass)
Definition
devicemimeconverter.cpp:60
TDEBluetooth::DeviceMimeConverter::getIconName
void getIconName(TQString mimetype)
Definition
devicemimeconverter.cpp:48
TDEBluetooth::DeviceMimeConverter::mimeTypeToIconMap
std::map< TQString, TQString > mimeTypeToIconMap
Definition
devicemimeconverter.h:47
TQMap
Definition
adapter1Interface.h:17
devicemimeconverter.h
TDEBluetooth
Definition
adapterImpl.cpp:40
src
libtdebluez
devicemimeconverter.cpp
Generated by
1.9.8