File: qhimdmacdetection.cpp

package info (click to toggle)
linux-minidisc 0.9.16-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,640 kB
  • sloc: ansic: 6,389; cpp: 2,731; python: 2,537; perl: 866; sh: 207; makefile: 10
file content (64 lines) | stat: -rw-r--r-- 1,405 bytes parent folder | download | duplicates (4)
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
#include "qhimddetection.h"

#include <QList>
#include <QDir>
#include <QFile>

class QHiMDMacDetection : public QHiMDDetection {
public:
    QHiMDMacDetection(QObject * parent = NULL);
    ~QHiMDMacDetection();

    void scan_for_himd_devices();

private:
    void add_himddevice(QString path, QString name);
};


QHiMDDetection * createDetection(QObject * parent)
{
    return new QHiMDMacDetection(parent);
}

QHiMDMacDetection::QHiMDMacDetection(QObject * parent)
    : QHiMDDetection(parent)
{
}

QHiMDMacDetection::~QHiMDMacDetection()
{
}

void QHiMDMacDetection::scan_for_himd_devices()
{
    const QString BASE_DIR = "/Volumes/";

    QString path;
    foreach (path, QDir(BASE_DIR).entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
        QString fullPath = BASE_DIR + path;
        if (QFile(fullPath + "/HI-MD.IND").exists()) {
            add_himddevice(fullPath, path);
        }
    }
}

void QHiMDMacDetection::add_himddevice(QString path, QString name)
{
    QMDDevice *device;
    foreach (device, dlist) {
        if (device->path() == path) {
            // Device is already added -- skip duplicate
            return;
        }
    }

    QHiMDDevice * new_device = new QHiMDDevice();
    new_device->setMdInserted(true);
    new_device->setName(name);
    new_device->setPath(path);
    new_device->setBusy(false);

    dlist.append(new_device);
    emit deviceListChanged(dlist);
}