~lubuntu-dev/lxde/liblxqt-mount

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
148
149
150
151
/* BEGIN_COMMON_COPYRIGHT_HEADER
 * (c)LGPL2+
 *
 * LXDE-Qt - a lightweight, Qt based, desktop toolset
 * http://razor-qt.org
 *
 * Copyright: 2012 Razor team
 * Authors:
 *   Alexander Sokoloff <sokoloff.a@gmail.com>
 *
 * This program or library is free software; you can redistribute it
 * and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * END_COMMON_COPYRIGHT_HEADER */

#include "lxqtmount.h"
#include "rzmountproviders.h"
#include <QtCore/QDebug>

namespace LxQt {

MountDevice::MountDevice():
    QObject(0),
    mIsValid(false),
    mIsExternal(false),
    mIsMounted(false),
    mIsEjectable(false)
{
}

QString MountDevice::sizeToString(qulonglong size)
{
    double n;
    n = size / (1024.0 * 1024 * 1024);
    if (n >= 1.0)
        return QObject::tr("%1 GB").arg(n, 0, 'f', 1);

    n = size / (1024.0 * 1024);
    if (n >= 1.0)
        return QObject::tr("%1 MB").arg(n, 0, 'f', 1);

    n = size / (1024.0);
    if (n >= 1.0)
        return QObject::tr("%1 kB").arg(n, 0, 'f', 1);

    return QObject::tr("%1 B").arg(size);
}


MountManager::MountManager(QObject *parent):
    QObject(parent),
    mProvider(0)
{
    mProvider = new UDisks2Provider(this);
    if (!mProvider->isValid())
    {              
        delete mProvider;
        mProvider = 0;

        mProvider = new UDiskProvider(this);
        if (!mProvider->isValid())
        {
            delete mProvider;
            mProvider = 0;
        }
    }

    if (!mProvider)
        return;


    update();

    connect(mProvider, SIGNAL(deviceAdded(LxQt::MountDevice*)),
                 this, SIGNAL(deviceAdded(LxQt::MountDevice*)));

    connect(mProvider, SIGNAL(deviceChanged(LxQt::MountDevice*)),
                 this, SIGNAL(deviceChanged(LxQt::MountDevice*)));

    connect(mProvider, SIGNAL(deviceRemoved(LxQt::MountDevice*)),
                 this, SIGNAL(deviceRemoved(LxQt::MountDevice*)));
}


MountManager::~MountManager()
{
    delete mProvider;
}


void MountManager::update()
{
    if (mProvider)
        mProvider->update();
    else
        qDebug() << "MountDeviceList MountManager::update() no valid provider in use";

}


const MountDeviceList MountManager::devices() const
{
    if (mProvider)
    {
        //qDebug() << "MountManager::devices" << mProvider->devices();
        return mProvider->devices();
    }
    else
    {
        qWarning() << "MountDeviceList MountManager::devices() no valid provider in use";
        return MountDeviceList();
    }
}

} // namespace LxQt

QDebug operator<<(QDebug dbg, const LxQt::MountDevice &device)
{
    dbg << device.devFile();

    switch (device.mediaType())
    {
    case LxQt::MountDevice::MediaTypeUnknown:    dbg<<"Type: MediaTypeUnknown";  break;
    case LxQt::MountDevice::MediaTypeDrive:      dbg<<"Type: MediaTypeDrive";    break;
    case LxQt::MountDevice::MediaTypePartition:  dbg<<"Type: MediaTypePartition";break;
    case LxQt::MountDevice::MediaTypeFdd:        dbg<<"Type: MediaTypeFdd";      break;
    case LxQt::MountDevice::MediaTypeOptical:    dbg<<"Type: MediaTypeOptical";  break;
    default:                                    dbg<<"Type: "<<device.mediaType();break;
    }
    dbg << "Label: " << device.label();
    dbg << "Mount path:" << device.mountPath();
    return dbg.space();
}


QDebug operator<<(QDebug dbg, const LxQt::MountDevice *device)
{
    return operator<<(dbg, *device);
}