sistemata la gestione dei devices
[avrdudequi:avrdudequi.git] / sysdevices.cpp
1 /***************************************************************************
2  *   Copyright (C) 2011 by Maurilio                                        *
3  *   mau_ri_tec@yahoo.it                                                   *
4  *                                                                         *
5  *   This program 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.                                   *
9  *                                                                         *
10  *   This program 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.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21
22 #include "sysdevices.h"
23 #include <QDebug>
24
25 #define SUBSYSTEM 0
26
27 SysDevice *SysDevice::m_instance = 0;
28
29 SysDevice::~SysDevice()
30 {
31
32 }
33
34 SysDevice::SysDevice() :
35     QObject(0)
36 {
37     udevClient = new UdevQt::Client(this);
38     udevClient->setWatchedSubsystems(QSet<QString>());
39     connect(udevClient, SIGNAL(deviceRemoved(UdevQt::Device)), this, SIGNAL(deviceRemoved(UdevQt::Device)));
40 }
41
42 UdevQt::DeviceList SysDevice::getMatchListFromUDI(const QString & udi)
43 {
44     UdevQt::DeviceList devMatchList;
45     if (udi.isEmpty())
46         return devMatchList;
47
48     UdevQt::Device dev;
49     QString doUdi;
50     QStringList udiSplit = udi.split("/");
51     UdevQt::DeviceList devList = udevClient->devicesBySubsystem(udiSplit[SUBSYSTEM]);
52     while (!devList.isEmpty()) {
53         dev = devList.takeFirst();
54         if (udiSplit[SUBSYSTEM] == "usb") {
55             doUdi = dev.subsystem() + "/"
56                     + dev.devType() + "/"
57                     + dev.deviceProperty("ID_VENDOR_ID") + "/"
58                     + dev.deviceProperty("ID_MODEL_ID");
59         }
60         else
61         if (udiSplit[SUBSYSTEM] == "tty") {
62             doUdi = dev.subsystem() + "/"
63                     + dev.deviceProperty("ID_TYPE") + "/"
64                     + dev.deviceProperty("ID_VENDOR_ID") + "/"
65                     + dev.deviceProperty("ID_MODEL_ID") + "/"
66                     + dev.deviceProperty("ID_USB_DRIVER");
67         }
68
69         if (udi == doUdi) { // match device
70             devMatchList << dev;
71
72         }
73     }
74
75     return devMatchList;
76 }
77
78