summaryrefslogtreecommitdiffstats
path: root/src/libtdebluez/devicemimeconverter.cpp
blob: b14669e25776816c521e2322878d32c3c172a216 (plain)
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
138
139
140
141
142
143
144
145
146
147
/*
 *
 *  Device Mime Converter for libtdebluez
 *
 *  Copyright (C) 2003 by Fred Schaettgen
 *  Copyright (C) 2018  Emanoil Kotsev <[email protected]>
 *
 *
 *  This file is part of libtdebluez.
 *
 *  libtdebluez is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  libtdebluez 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with kbluetooth; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include <kmimetype.h>

#include "devicemimeconverter.h"

namespace TDEBluetooth
{

DeviceMimeConverter::DeviceMimeConverter()
{
    getIconName("bluetooth/unknown-device-class");
    getIconName("bluetooth/misc-device-class");
    getIconName("bluetooth/computer-device-class");
    getIconName("bluetooth/phone-device-class");
    getIconName("bluetooth/lan-device-class");
    getIconName("bluetooth/av-device-class");
    getIconName("bluetooth/peripheral-device-class");
    getIconName("bluetooth/mouse-device-class");
    getIconName("bluetooth/keyboard-device-class");
    getIconName("bluetooth/imaging-device-class");
}

void DeviceMimeConverter::getIconName(TQString mime)
{
    TQString iconName = KMimeType::mimeType(mime)->icon(TQString::null, false);
    mimeTypeToIconMap[mime] = iconName;
}

DeviceMimeConverter* DeviceMimeConverter::getInstance()
{
    static DeviceMimeConverter instance;
    return &instance;
}

TQString DeviceMimeConverter::classToIconName(int n)
{
    return DeviceMimeConverter::mimeTypeToIcon(DeviceMimeConverter::classToMimeType(n));
}

/*
 * device classes
 *
    AUDIO_VIDEO (Value: 0x00000400)
    COMPUTER (Value: 0x00000100)
    HEALTH (Value: 0x00000900)
    IMAGING (Value: 0x00000600)
    MISC (Value: 0x00000000)
    NETWORKING (Value: 0x00000300)
    PERIPHERAL (Value: 0x00000500)
    PHONE (Value: 0x00000200)
    TOY (Value: 0x00000800)
    UNCATEGORIZED (Value: 0x00001f00)
    WEARABLE (Value: 0x00000700)
*/

TQString DeviceMimeConverter::classToMimeType(int n)
{
    TQString mimeType;
    int major = ((n & 0x001F00) >> 8);
    int minor = ((n >> 2) & 0x30);
    switch (major)
    {
    case 0x00:
        mimeType = "bluetooth/misc-device-class";
        break;
    case 0x01:
        mimeType = "bluetooth/computer-device-class";
        break;
    case 0x02:
        mimeType = "bluetooth/phone-device-class";
        break;
    case 0x03:
        mimeType = "bluetooth/lan-device-class";
        break;
    case 0x04:
        mimeType = "bluetooth/av-device-class";
        break;
    case 0x05:
        switch (minor)
        {
        case 0x10:
            mimeType = "bluetooth/keyboard-device-class";
            break;
        case 0x20:
            mimeType = "bluetooth/mouse-device-class";
            break;
        default:
            mimeType = "bluetooth/peripheral-device-class";
        }
        break;
    case 0x06:
        mimeType = "bluetooth/imaging-device-class";
        break;
    case 0x07:
        mimeType = "bluetooth/wearable-device-class";
        break;
    case 0x08:
        mimeType = "bluetooth/toy-device-class";
        break;
    case 0x09:
        mimeType = "bluetooth/health-device-class";
        break;
    default:
        mimeType = "bluetooth/unknown-device-class";
    }
    return mimeType;
}

TQString DeviceMimeConverter::mimeTypeToIcon(TQString mime)
{
    DeviceMimeConverter* c = DeviceMimeConverter::getInstance();
    if (c->mimeTypeToIconMap.find(mime) != c->mimeTypeToIconMap.end())
    {
        return c->mimeTypeToIconMap[mime];
    }
    else
    {
        return c->mimeTypeToIconMap["bluetooth/unknown-device-class"];
    }
}

} // TDEBluetooth