~lubuntu-dev/lxde/liblxqt-mount

« back to all changes in this revision

Viewing changes to mount.cpp

  • Committer: Luís Pereira
  • Date: 2014-06-12 10:52:04 UTC
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: git-v1:09b968dfd1434bfe6eae98496a1f1e38db8d471d
Changes files names

This change has in mind how to include the header using portable headers
way.

Signed-off-by: Luís Pereira <luis.artur.pereira@gmail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* BEGIN_COMMON_COPYRIGHT_HEADER
 
2
 * (c)LGPL2+
 
3
 *
 
4
 * LXQt - The Lightweight Desktop Environment
 
5
 * http://lxqt.org
 
6
 *
 
7
 * Copyright: 2012 Razor team
 
8
 *            2013-2014 LXQt team
 
9
 * Authors:
 
10
 *   Alexander Sokoloff <sokoloff.a@gmail.com>
 
11
 *
 
12
 * This program or library is free software; you can redistribute it
 
13
 * and/or modify it under the terms of the GNU Lesser General Public
 
14
 * License as published by the Free Software Foundation; either
 
15
 * version 2.1 of the License, or (at your option) any later version.
 
16
 *
 
17
 * This library is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
20
 * Lesser General Public License for more details.
 
21
 
 
22
 * You should have received a copy of the GNU Lesser General
 
23
 * Public License along with this library; if not, write to the
 
24
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
25
 * Boston, MA 02110-1301 USA
 
26
 *
 
27
 * END_COMMON_COPYRIGHT_HEADER */
 
28
 
 
29
#include "mount.h"
 
30
#include "providers.h"
 
31
#include <QtCore/QDebug>
 
32
 
 
33
namespace LxQt {
 
34
 
 
35
MountDevice::MountDevice():
 
36
    QObject(0),
 
37
    mIsValid(false),
 
38
    mIsExternal(false),
 
39
    mIsMounted(false),
 
40
    mIsEjectable(false)
 
41
{
 
42
}
 
43
 
 
44
QString MountDevice::sizeToString(qulonglong size)
 
45
{
 
46
    double n;
 
47
    n = size / (1024.0 * 1024 * 1024);
 
48
    if (n >= 1.0)
 
49
        return QObject::tr("%1 GB").arg(n, 0, 'f', 1);
 
50
 
 
51
    n = size / (1024.0 * 1024);
 
52
    if (n >= 1.0)
 
53
        return QObject::tr("%1 MB").arg(n, 0, 'f', 1);
 
54
 
 
55
    n = size / (1024.0);
 
56
    if (n >= 1.0)
 
57
        return QObject::tr("%1 kB").arg(n, 0, 'f', 1);
 
58
 
 
59
    return QObject::tr("%1 B").arg(size);
 
60
}
 
61
 
 
62
 
 
63
MountManager::MountManager(QObject *parent):
 
64
    QObject(parent),
 
65
    mProvider(0)
 
66
{
 
67
    mProvider = new UDisks2Provider(this);
 
68
    if (!mProvider->isValid())
 
69
    {
 
70
        delete mProvider;
 
71
        mProvider = 0;
 
72
 
 
73
        mProvider = new UDiskProvider(this);
 
74
        if (!mProvider->isValid())
 
75
        {
 
76
            delete mProvider;
 
77
            mProvider = 0;
 
78
        }
 
79
    }
 
80
 
 
81
    if (!mProvider)
 
82
        return;
 
83
 
 
84
 
 
85
    update();
 
86
 
 
87
    connect(mProvider, SIGNAL(deviceAdded(LxQt::MountDevice*)),
 
88
                 this, SIGNAL(deviceAdded(LxQt::MountDevice*)));
 
89
 
 
90
    connect(mProvider, SIGNAL(deviceChanged(LxQt::MountDevice*)),
 
91
                 this, SIGNAL(deviceChanged(LxQt::MountDevice*)));
 
92
 
 
93
    connect(mProvider, SIGNAL(deviceRemoved(LxQt::MountDevice*)),
 
94
                 this, SIGNAL(deviceRemoved(LxQt::MountDevice*)));
 
95
}
 
96
 
 
97
 
 
98
MountManager::~MountManager()
 
99
{
 
100
    delete mProvider;
 
101
}
 
102
 
 
103
 
 
104
void MountManager::update()
 
105
{
 
106
    if (mProvider)
 
107
        mProvider->update();
 
108
    else
 
109
        qDebug() << "MountDeviceList MountManager::update() no valid provider in use";
 
110
 
 
111
}
 
112
 
 
113
 
 
114
const MountDeviceList MountManager::devices() const
 
115
{
 
116
    if (mProvider)
 
117
    {
 
118
        //qDebug() << "MountManager::devices" << mProvider->devices();
 
119
        return mProvider->devices();
 
120
    }
 
121
    else
 
122
    {
 
123
        qWarning() << "MountDeviceList MountManager::devices() no valid provider in use";
 
124
        return MountDeviceList();
 
125
    }
 
126
}
 
127
 
 
128
} // namespace LxQt
 
129
 
 
130
QDebug operator<<(QDebug dbg, const LxQt::MountDevice &device)
 
131
{
 
132
    dbg << device.devFile();
 
133
 
 
134
    switch (device.mediaType())
 
135
    {
 
136
    case LxQt::MountDevice::MediaTypeUnknown:    dbg<<"Type: MediaTypeUnknown";  break;
 
137
    case LxQt::MountDevice::MediaTypeDrive:      dbg<<"Type: MediaTypeDrive";    break;
 
138
    case LxQt::MountDevice::MediaTypePartition:  dbg<<"Type: MediaTypePartition";break;
 
139
    case LxQt::MountDevice::MediaTypeFdd:        dbg<<"Type: MediaTypeFdd";      break;
 
140
    case LxQt::MountDevice::MediaTypeOptical:    dbg<<"Type: MediaTypeOptical";  break;
 
141
    default:                                    dbg<<"Type: "<<device.mediaType();break;
 
142
    }
 
143
    dbg << "Label: " << device.label();
 
144
    dbg << "Mount path:" << device.mountPath();
 
145
    return dbg.space();
 
146
}
 
147
 
 
148
 
 
149
QDebug operator<<(QDebug dbg, const LxQt::MountDevice *device)
 
150
{
 
151
    return operator<<(dbg, *device);
 
152
}