summaryrefslogtreecommitdiffstats
path: root/k9devices/k9haldevice.cpp
blob: 0129efe7b1e2b31c8dd3316f79044fb07b0f1ca3 (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
//
// C++ Implementation: k9haldevice
//
// Description:
//
//
// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "k9haldevice.h"
#ifdef HAVE_HAL
#include "k9halconnection.h"
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus.h>
#include <hal/libhal.h>
#include <hal/libhal-storage.h>

k9HalDevice::k9HalDevice(TQObject *parent, const char *udi)
        : TQObject(parent, udi) {

    m_connection=(k9HalConnection*)parent;
    getDriveProperties();
}

k9HalDevice::~k9HalDevice() {}

TQString k9HalDevice::volumeName() {
    TQString sVol("");
    LibHalDrive *drive= libhal_drive_from_udi ((LibHalContext *)m_connection->m_context, name());
    int num_volumes;
    if (drive !=NULL) {
        char** volumes = libhal_drive_find_all_volumes ((LibHalContext *)m_connection->m_context, drive, &num_volumes);
        if (volumes != NULL) {
            for (int i = 0; i < num_volumes; i++) {
                char *volume_udi;
                LibHalVolume *volume;
                volume_udi = volumes[i];
                TQString s(volume_udi);
                m_volumeUdi=s;
                volume = libhal_volume_from_udi ((LibHalContext *)m_connection->m_context, volume_udi);
                if (volume != NULL) {
                    sVol=TQString(libhal_volume_get_label (volume));
                    libhal_volume_free (volume);
                }
            }
            if (num_volumes >0)
            	libhal_free_string_array (volumes);
	}        
        libhal_drive_free(drive);
    }
    return sVol;
}

TQString k9HalDevice::mountPoint() {
    TQString sMountPoint("");
    LibHalDrive *drive= libhal_drive_from_udi ((LibHalContext *)m_connection->m_context, name());
    if (drive !=NULL) {
        int num_volumes;
        char** volumes = libhal_drive_find_all_volumes ((LibHalContext *)m_connection->m_context, drive, &num_volumes);
        if (volumes != NULL) {
            for (int i = 0; i < num_volumes; i++) {
                char *volume_udi;
                LibHalVolume *volume;
                volume_udi = volumes[i];
                volume = libhal_volume_from_udi ((LibHalContext *)m_connection->m_context, volume_udi);
                if (volume != NULL) {
                    sMountPoint=TQString(libhal_volume_get_mount_point (volume));
                    libhal_volume_free (volume);
                }
            }
            if (num_volumes >0)
            	libhal_free_string_array (volumes);
        }
        libhal_drive_free(drive);
    }
    return sMountPoint;
}


void k9HalDevice::updateVolumeName() {
    m_volumeName=volumeName();
    emit volumeChanged(this->getDeviceName(),m_volumeName);
}

void k9HalDevice::getDriveProperties() {
    LibHalContext *context=(LibHalContext *)m_connection->m_context;
    LibHalDrive *drive= libhal_drive_from_udi (context, name());
    LibHalDriveCdromCaps caps;
    caps= libhal_drive_get_cdrom_caps (drive);
    m_canReadCd=m_canReadDvd=m_canBurnCd=m_canBurnDvd=false;
    m_canReadCd= (caps & LIBHAL_DRIVE_CDROM_CAPS_CDROM)==LIBHAL_DRIVE_CDROM_CAPS_CDROM;
    m_canBurnCd= (caps & LIBHAL_DRIVE_CDROM_CAPS_CDR)==LIBHAL_DRIVE_CDROM_CAPS_CDR;
    m_canReadDvd=(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDROM)==LIBHAL_DRIVE_CDROM_CAPS_DVDROM;
    m_canBurnDvd=(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDR)==LIBHAL_DRIVE_CDROM_CAPS_DVDR;
    m_model=TQString(libhal_drive_get_model(drive));
    //    tqDebug("%s", (TQString("canReadDvd:%1 canBurnDvd:%2 model:%3").arg(m_canReadDvd).arg(m_canBurnDvd).arg(m_model)).ascii());


    libhal_drive_free(drive);
    if (libhal_device_property_exists( (LibHalContext*) m_connection->m_context, name(), "storage.cdrom.write_speed", 0 )) {
        m_maxWriteSpeed= libhal_device_get_property_int( (LibHalContext*)m_connection->m_context, name(), "storage.cdrom.write_speed", 0 );
    }
    char* dev = libhal_device_get_property_string( (LibHalContext*) m_connection->m_context, name(), "block.device", 0 );
    m_deviceName=TQString ( dev );
    libhal_free_string( dev );

    m_volumeName=volumeName();
}
#include "k9haldevice.moc"
#endif