2015-06-04 01:29:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#if !defined(CAPACITY__H)
|
|
|
|
|
|
|
|
#define CAPACITY__H
|
|
|
|
#include "../util/libpartitionmanagerexport.h"
|
|
|
|
|
|
|
|
class Partition;
|
|
|
|
class Device;
|
|
|
|
|
|
|
|
#include <qglobal.h>
|
|
|
|
|
|
|
|
/** Represent any kind of capacity.
|
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
Any kind of capacity that can be expressed in units of Byte, KiB, MiB and so on. Also prints
|
|
|
|
capacities in nicely formatted ways.
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
@author Volker Lanz <vl@fidra.de>
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
class LIBKPMCORE_EXPORT Capacity
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
public:
|
|
|
|
/** Units we can deal with */
|
|
|
|
enum Unit { Byte, KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB };
|
|
|
|
/** Type of capacity to print */
|
|
|
|
enum Type { Used, Available, Total };
|
|
|
|
/** Flags for printing */
|
|
|
|
enum Flag { NoFlags = 0, AppendUnit = 1, AppendBytes = 2 };
|
|
|
|
Q_DECLARE_FLAGS(Flags, Flag)
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
public:
|
|
|
|
explicit Capacity(qint64 size);
|
|
|
|
explicit Capacity(const Partition& p, Type t = Total);
|
|
|
|
Capacity(const Device& d);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
public:
|
|
|
|
bool operator==(const Capacity& other) const {
|
|
|
|
return other.m_Size == m_Size;
|
|
|
|
}
|
|
|
|
bool operator!=(const Capacity& other) const {
|
|
|
|
return other.m_Size != m_Size;
|
|
|
|
}
|
|
|
|
bool operator>(const Capacity& other) const {
|
|
|
|
return other.m_Size > m_Size;
|
|
|
|
}
|
|
|
|
bool operator<(const Capacity& other) const {
|
|
|
|
return other.m_Size < m_Size;
|
|
|
|
}
|
|
|
|
bool operator>=(const Capacity& other) const {
|
|
|
|
return other.m_Size >= m_Size;
|
|
|
|
}
|
|
|
|
bool operator<=(const Capacity& other) const {
|
|
|
|
return other.m_Size <= m_Size;
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
qint64 toInt(Unit u) const;
|
|
|
|
double toDouble(Unit u) const;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
bool isValid() const;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
static QString formatByteSize(double size, int precision = 2);
|
|
|
|
static const QString& invalidString() {
|
|
|
|
return m_InvalidString; /**< @return string representing an invalid capacity */
|
|
|
|
}
|
|
|
|
static QString unitName(Unit u, qint64 val = 1);
|
|
|
|
static qint64 unitFactor(Unit from, Unit to);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
private:
|
|
|
|
qint64 m_Size;
|
|
|
|
static const QString m_InvalidString;
|
2015-06-04 01:29:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Capacity::Flags)
|
|
|
|
|
|
|
|
#endif
|