summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/base
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/base')
-rw-r--r--rbutil/rbutilqt/base/autodetection.cpp18
-rw-r--r--rbutil/rbutilqt/base/playerbuildinfo.cpp49
-rw-r--r--rbutil/rbutilqt/base/playerbuildinfo.h6
-rw-r--r--rbutil/rbutilqt/base/systeminfo.cpp90
-rw-r--r--rbutil/rbutilqt/base/systeminfo.h51
5 files changed, 60 insertions, 154 deletions
diff --git a/rbutil/rbutilqt/base/autodetection.cpp b/rbutil/rbutilqt/base/autodetection.cpp
index 58e844b4c3..63ed9ad9ff 100644
--- a/rbutil/rbutilqt/base/autodetection.cpp
+++ b/rbutil/rbutilqt/base/autodetection.cpp
@@ -19,7 +19,6 @@
19#include <QtCore> 19#include <QtCore>
20#include "autodetection.h" 20#include "autodetection.h"
21#include "rbsettings.h" 21#include "rbsettings.h"
22#include "systeminfo.h"
23#include "playerbuildinfo.h" 22#include "playerbuildinfo.h"
24 23
25#include "../ipodpatcher/ipodpatcher.h" 24#include "../ipodpatcher/ipodpatcher.h"
@@ -82,30 +81,25 @@ bool Autodetection::detect(void)
82 */ 81 */
83void Autodetection::detectUsb() 82void Autodetection::detectUsb()
84{ 83{
85 // usbids holds the mapping in the form
86 // ((VID<<16)|(PID)), targetname
87 // the ini file needs to hold the IDs as hex values.
88 QMap<int, QStringList> usbids = SystemInfo::usbIdMap(SystemInfo::MapDevice);
89 QMap<int, QStringList> usberror = SystemInfo::usbIdMap(SystemInfo::MapError);
90
91 // usb pid detection 84 // usb pid detection
92 QList<uint32_t> attached; 85 QList<uint32_t> attached;
93 attached = System::listUsbIds(); 86 attached = System::listUsbIds();
94 87
95 int i = attached.size(); 88 int i = attached.size();
96 while(i--) { 89 while(i--) {
97 if(usbids.contains(attached.at(i))) { 90 QStringList a = PlayerBuildInfo::instance()->value(PlayerBuildInfo::UsbIdTargetList, attached.at(i)).toStringList();
98 // we found a USB device that might be ambiguous. 91 if(a.size() > 0) {
99 struct Detected d; 92 struct Detected d;
100 d.status = PlayerOk; 93 d.status = PlayerOk;
101 d.usbdevices = usbids.value(attached.at(i)); 94 d.usbdevices = a;
102 m_detected.append(d); 95 m_detected.append(d);
103 LOG_INFO() << "[USB] detected supported player" << d.usbdevices; 96 LOG_INFO() << "[USB] detected supported player" << d.usbdevices;
104 } 97 }
105 if(usberror.contains(attached.at(i))) { 98 QStringList b = PlayerBuildInfo::instance()->value(PlayerBuildInfo::UsbIdErrorList, attached.at(i)).toStringList();
99 if(b.size() > 0) {
106 struct Detected d; 100 struct Detected d;
107 d.status = PlayerMtpMode; 101 d.status = PlayerMtpMode;
108 d.device = usberror.value(attached.at(i)).at(0); 102 d.usbdevices = b;
109 m_detected.append(d); 103 m_detected.append(d);
110 LOG_WARNING() << "[USB] detected problem with player" << d.device; 104 LOG_WARNING() << "[USB] detected problem with player" << d.device;
111 } 105 }
diff --git a/rbutil/rbutilqt/base/playerbuildinfo.cpp b/rbutil/rbutilqt/base/playerbuildinfo.cpp
index 4310991f40..f118a9fd7a 100644
--- a/rbutil/rbutilqt/base/playerbuildinfo.cpp
+++ b/rbutil/rbutilqt/base/playerbuildinfo.cpp
@@ -70,6 +70,8 @@ const static struct {
70 { PlayerBuildInfo::TargetNamesEnabled, "_targets/enabled" }, 70 { PlayerBuildInfo::TargetNamesEnabled, "_targets/enabled" },
71 { PlayerBuildInfo::LanguageInfo, "languages/:target:" }, 71 { PlayerBuildInfo::LanguageInfo, "languages/:target:" },
72 { PlayerBuildInfo::LanguageList, "_languages/list" }, 72 { PlayerBuildInfo::LanguageList, "_languages/list" },
73 { PlayerBuildInfo::UsbIdErrorList, "_usb/error" },
74 { PlayerBuildInfo::UsbIdTargetList, "_usb/target" },
73}; 75};
74 76
75const static struct { 77const static struct {
@@ -257,6 +259,52 @@ QVariant PlayerBuildInfo::value(DeviceInfo item, QString target)
257 return result; 259 return result;
258} 260}
259 261
262QVariant PlayerBuildInfo::value(DeviceInfo item, unsigned int match)
263{
264 QStringList result;
265 int i = 0;
266 while(PlayerInfoList[i].item != item)
267 i++;
268 QString s = PlayerInfoList[i].name;
269
270 switch(item) {
271 case UsbIdErrorList:
272 {
273 // go through all targets and find the one indicated by the usb id "target".
274 // return list of matching players (since it could be more than one)
275 QStringList targets = targetNames(true);
276 for(int i = 0; i < targets.size(); i++) {
277 QStringList usbids = playerInfo.value(targets.at(i) + "/usberror").toStringList();
278 for(int j = 0; j < usbids.size(); j++) {
279 if(usbids.at(j).toUInt(nullptr, 0) == match) {
280 result << targets.at(i);
281 }
282 }
283 }
284 break;
285 }
286
287 case UsbIdTargetList:
288 {
289 QStringList targets = targetNames(true);
290 for(int i = 0; i < targets.size(); i++) {
291 QStringList usbids = playerInfo.value(targets.at(i) + "/usbid").toStringList();
292 for(int j = 0; j < usbids.size(); j++) {
293 if(usbids.at(j).toUInt(nullptr, 0) == match) {
294 result << targets.at(i);
295 }
296 }
297 }
298 break;
299 }
300
301 default:
302 break;
303 }
304 LOG_INFO() << "T:" << s << result;
305 return result;
306}
307
260QVariant PlayerBuildInfo::value(SystemUrl item) 308QVariant PlayerBuildInfo::value(SystemUrl item)
261{ 309{
262 // locate setting item in server info file 310 // locate setting item in server info file
@@ -309,7 +357,6 @@ QStringList PlayerBuildInfo::targetNames(bool all)
309 result.append(target); 357 result.append(target);
310 } 358 }
311 } 359 }
312 result.removeDuplicates();
313 return result; 360 return result;
314} 361}
315 362
diff --git a/rbutil/rbutilqt/base/playerbuildinfo.h b/rbutil/rbutilqt/base/playerbuildinfo.h
index 52654312a0..85fc2ac6dc 100644
--- a/rbutil/rbutilqt/base/playerbuildinfo.h
+++ b/rbutil/rbutilqt/base/playerbuildinfo.h
@@ -71,6 +71,8 @@ public:
71 TargetNamesEnabled, 71 TargetNamesEnabled,
72 LanguageInfo, 72 LanguageInfo,
73 LanguageList, 73 LanguageList,
74 UsbIdErrorList,
75 UsbIdTargetList,
74 }; 76 };
75 77
76 enum SystemUrl { 78 enum SystemUrl {
@@ -90,6 +92,10 @@ public:
90 // Get information about a device. This data does not depend on the build type. 92 // Get information about a device. This data does not depend on the build type.
91 QVariant value(DeviceInfo item, QString target = ""); 93 QVariant value(DeviceInfo item, QString target = "");
92 94
95 // Get information about a device. Make a numeric match
96 // (only sensible implementation for USB IDs)
97 QVariant value(DeviceInfo item, unsigned int match);
98
93 // Get build information for currently selected player. 99 // Get build information for currently selected player.
94 QVariant value(BuildInfo item, BuildType type); 100 QVariant value(BuildInfo item, BuildType type);
95 101
diff --git a/rbutil/rbutilqt/base/systeminfo.cpp b/rbutil/rbutilqt/base/systeminfo.cpp
deleted file mode 100644
index 2b39300930..0000000000
--- a/rbutil/rbutilqt/base/systeminfo.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2010 by Dominik Wenger
10 *
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
13 *
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
16 *
17 ****************************************************************************/
18
19#include "systeminfo.h"
20#include "rbsettings.h"
21
22#include <QSettings>
23#include "Logger.h"
24
25// device settings
26
27//! pointer to setting object to nullptr
28QSettings* SystemInfo::systemInfos = nullptr;
29
30void SystemInfo::ensureSystemInfoExists()
31{
32 //check and create settings object
33 if(systemInfos == nullptr)
34 {
35 // only use built-in rbutil.ini
36 systemInfos = new QSettings(":/ini/rbutil.ini", QSettings::IniFormat);
37 }
38}
39
40
41QMap<int, QStringList> SystemInfo::usbIdMap(enum MapType type)
42{
43 ensureSystemInfoExists();
44
45 QMap<int, QStringList> map;
46 // get a list of ID -> target name
47 QStringList platforms;
48 systemInfos->beginGroup("platforms");
49 platforms = systemInfos->childKeys();
50 systemInfos->endGroup();
51
52 QString t;
53 switch(type) {
54 case MapDevice:
55 t = "usbid";
56 break;
57 case MapError:
58 t = "usberror";
59 break;
60 case MapIncompatible:
61 t = "usbincompat";
62 break;
63 }
64
65 for(int i = 0; i < platforms.size(); i++)
66 {
67 systemInfos->beginGroup("platforms");
68 QString target = systemInfos->value(platforms.at(i)).toString();
69 systemInfos->endGroup();
70 systemInfos->beginGroup(target);
71 QStringList ids = systemInfos->value(t).toStringList();
72 int j = ids.size();
73 while(j--) {
74 QStringList l;
75 int id = ids.at(j).toInt(nullptr, 16);
76 if(id == 0) {
77 continue;
78 }
79 if(map.contains(id)) {
80 l = map.take(id);
81 }
82 l.append(target);
83 map.insert(id, l);
84 }
85 systemInfos->endGroup();
86 }
87 return map;
88}
89
90
diff --git a/rbutil/rbutilqt/base/systeminfo.h b/rbutil/rbutilqt/base/systeminfo.h
deleted file mode 100644
index 5ca5b35885..0000000000
--- a/rbutil/rbutilqt/base/systeminfo.h
+++ /dev/null
@@ -1,51 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2010 by Dominik Wenger
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21#ifndef SYSTEMINFO_H
22#define SYSTEMINFO_H
23
24#include <QtCore>
25
26class SystemInfo : public QObject
27{
28 Q_OBJECT
29 public:
30 //! Type of requested usb-id map
31 enum MapType {
32 MapDevice,
33 MapError,
34 MapIncompatible,
35 };
36
37 //! returns a map of usb-ids and their targets
38 static QMap<int, QStringList> usbIdMap(enum MapType type);
39 //! get a value from system settings
40
41 private:
42 //! you shouldnt call this, its a fully static calls
43 SystemInfo() {}
44 //! create the setting objects if neccessary
45 static void ensureSystemInfoExists();
46 //! pointers to our setting objects
47 static QSettings *systemInfos;
48};
49
50#endif
51