New upstream version 2.0.9.8
authorBoyuan Yang <byang@debian.org>
Tue, 13 Nov 2018 00:56:16 +0000 (19:56 -0500)
committerBoyuan Yang <byang@debian.org>
Tue, 13 Nov 2018 00:56:16 +0000 (19:56 -0500)
18 files changed:
CHANGELOG.md
src/dsysinfo.cpp
src/filesystem/dpathbuf.cpp
src/filesystem/dpathbuf.h
src/filesystem/dstandardpaths.cpp
src/settings/backend/gsettingsbackend.cpp
src/settings/backend/gsettingsbackend.h
src/settings/backend/qsettingbackend.cpp
src/settings/dsettings.cpp
src/settings/dsettingsbackend.h
src/settings/dsettingsgroup.cpp
src/settings/dsettingsgroup.h
src/settings/dsettingsoption.cpp
src/settings/dsettingsoption.h
src/util/dabstractunitformatter.cpp
src/util/ddisksizeformatter.cpp
src/util/dtimeunitformatter.cpp
tests/dutiltester.cpp

index 5fdaa58018ecdb3db73d049a6724eb615832bbc2..422ab19f10454ca6734c6107ec54a7bcb72bea94 100644 (file)
@@ -1,3 +1,13 @@
+<a name="2.0.9.8"></a>
+## 2.0.9.8 (2018-11-09)
+
+
+#### Bug Fixes
+
+*   can't get correct disk size in some case ([20a12b62](https://github.com/linuxdeepin/dtkcore/commit/20a12b622ea7b01f0616c15a8af85e31fc2d36cb))
+
+
+
 <a name="2.0.9.5"></a>
 ## 2.0.9.5 (2018-10-26)
 
index 658af353a3dc981b80625db44560644b3f8c64c0..1fbdb7d621f138a739ae6589e9d4a8652507c7c2 100644 (file)
@@ -25,6 +25,8 @@
 #include <QStorageInfo>
 #include <QProcess>
 #include <QDebug>
+#include <QJsonDocument>
+#include <QJsonArray>
 
 #ifdef Q_OS_LINUX
 #include <sys/sysinfo.h>
@@ -315,27 +317,35 @@ void DSysInfoPrivate::ensureComputerInfo()
 
     memoryTotalSize = get_phys_pages() * sysconf(_SC_PAGESIZE);
 
-    const QString &root_part = QStorageInfo::root().device();
-
-    if (root_part.isEmpty())
-        return;
-
+    // Getting Disk Size
+    const QString &deviceName = QStorageInfo::root().device();
     QProcess lsblk;
 
-    lsblk.start("lsblk", {"-prno", "pkname", root_part}, QIODevice::ReadOnly);
-
-    if (!lsblk.waitForFinished())
-        return;
-
-    const QString &root_disk = QString::fromLatin1(lsblk.readAllStandardOutput().trimmed());
+    lsblk.start("lsblk", {"-Jlpb", "-oNAME,KNAME,PKNAME,SIZE"}, QIODevice::ReadOnly);
 
-    lsblk.start("lsblk", {"-prnbdo", "size", root_disk}, QIODevice::ReadOnly);
-
-    if (!lsblk.waitForFinished())
+    if (!lsblk.waitForFinished()) {
         return;
+    }
 
-    const QByteArray &disk_size = lsblk.readAllStandardOutput().trimmed();
-    diskSize = disk_size.toLongLong();
+    const QByteArray &diskStatusJson = lsblk.readAllStandardOutput();
+    QJsonDocument diskStatus = QJsonDocument::fromJson(diskStatusJson);
+    QJsonValue diskStatusJsonValue = diskStatus["blockdevices"];
+    QMap<QString, QPair<QString, qulonglong>> deviceParentAndSizeMap;
+
+    if (!diskStatusJsonValue.isUndefined()) {
+        QJsonArray diskStatusArray = diskStatusJsonValue.toArray();
+        QString keyName;
+        for (const QJsonValue &oneValue : diskStatusArray) {
+            if (keyName.isNull() && deviceName == oneValue["name"].toString()) {
+                keyName = oneValue["kname"].toString();
+            }
+            deviceParentAndSizeMap[oneValue["kname"].toString()] = QPair<QString, qulonglong>(oneValue["pkname"].toString(), oneValue["size"].toString().toULongLong());
+        }
+        while (!deviceParentAndSizeMap[keyName].first.isNull()) {
+            keyName = deviceParentAndSizeMap[keyName].first;
+        }
+        diskSize = deviceParentAndSizeMap[keyName].second;
+    }
 #endif
 }
 
index 9fe11b232f759ad55dde961f94afd771194bd15a..cd5aa62b12862ef3d94e9ce04c98754724631334 100644 (file)
@@ -1,6 +1,30 @@
 #include "dpathbuf.h"
 
-Dtk::Core::DPathBuf::DPathBuf(const QString &path)
+/*!
+ * \~english \class Dtk::Core::DPathBuf
+ * \brief Dtk::Core::DPathBuf cat path friendly and supoort multiplatform.
+ */
+
+/*!
+ * \~chinese \class Dtk::Core::DPathBuf
+ * \brief Dtk::Core::DPathBuf是一个用于跨平台拼接路径的辅助类。
+ * 它能够方便的写出链式结构的路径拼接代码。
+```
+DPathBuf logPath(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first());
+logPath = logPath / ".cache" / "deepin" / "deepin-test-dtk" / "deepin-test-dtk.log";
+```
+ */
+
+
+DCORE_BEGIN_NAMESPACE
+
+/*!
+ * \brief Create Dtk::Core::DPathBuf from string.
+ * \param path
+ */
+DPathBuf::DPathBuf(const QString &path)
 {
     m_path = QDir(path).absolutePath();
 }
+
+DCORE_END_NAMESPACE
index 3aa7609ac50a4403a289a28d5b4f9feea0a8375d..aa5c997fcd98645834a19e218ebe05261846a2e9 100644 (file)
@@ -28,26 +28,53 @@ class LIBDTKCORESHARED_EXPORT DPathBuf
 public:
     DPathBuf(const QString &path);
 
+    /*!
+     * \brief join path with operator /
+     * \param p is subpath
+     * \return a new DPathBuf with subpath p
+     */
     DPathBuf operator/(const QString &p) const
     {
         return DPathBuf(m_path + "/" + p);
     }
 
+    /*!
+     * \brief join path to self with operator /=
+     * \param p is subpath to join
+     * \return self object
+     */
     DPathBuf &operator/=(const QString &p)
     {
         return join(p);
     }
 
+    /*!
+     * \brief join path with operator /
+     * \param p is subpath
+     * \return a new DPathBuf with subpath p
+     * \sa Dtk::Core::DPathBuf::operator/(const QString &p) const
+     */
     DPathBuf operator/(const char *p) const
     {
         return operator /(QString(p));
     }
 
+    /*!
+     * \brief join path to self with operator /=
+     * \param p is subpath to join
+     * \return self object
+     * \sa Dtk::Core::DPathBuf::operator/=(const QString &p)
+     */
     DPathBuf &operator/=(const char *p)
     {
         return operator /=(QString(p));
     }
 
+    /*!
+     * \brief join add subpath p to self
+     * \param p is subpath to join
+     * \return slef object with subpath joined
+     */
     DPathBuf &join(const QString &p)
     {
         m_path += "/" + p;
@@ -55,6 +82,10 @@ public:
         return *this;
     }
 
+    /*!
+     * \brief toString export native separators format string.
+     * \return string with native separators
+     */
     QString toString() const
     {
         return QDir::toNativeSeparators(m_path);
index bad435d7d2e181484473ab934b815a752f3f1d37..bf4080ed9b447e3f42717f09c30d69d9a4edf9f4 100644 (file)
@@ -21,8 +21,7 @@
 
 DCORE_BEGIN_NAMESPACE
 
-
-class DSnapStandardPaths
+class DSnapStandardPathsPrivate
 {
 public:
     inline  static QString writableLocation(QStandardPaths::StandardLocation /*type*/)
@@ -49,12 +48,28 @@ public:
     }
 
 private:
-    DSnapStandardPaths();
-    ~DSnapStandardPaths();
-    Q_DISABLE_COPY(DSnapStandardPaths)
+    DSnapStandardPathsPrivate();
+    ~DSnapStandardPathsPrivate();
+    Q_DISABLE_COPY(DSnapStandardPathsPrivate)
 };
 
 
+/*!
+ * \~chinese \class Dtk::Core::DStandardPaths
+ * \brief DStandardPaths提供兼容Snap/Dtk标准的路径模式。DStandardPaths实现了Qt的QStandardPaths主要接口。
+ * \sa QStandardPaths
+ *
+ * \enum DStandardPaths::Mode
+ * \brief DStandardPaths支持的路径产生模式。
+ * \var DStandardPaths::Mode DStandardPaths::Auto
+ * \brief 和Qt标准的行为表现一致。
+ * \var DStandardPaths::Mode DStandardPaths::Snap
+ * \brief 读取SNAP相关的环境变量,支持将配置存储在SNAP对应目录。
+ * \var DStandardPaths::Mode DStandardPaths::Test
+ * \brief 和Qt标准的行为表现一致,但是会开启测试模式,参考QStandardPaths::setTestModeEnabled。
+ */
+
+
 static DStandardPaths::Mode s_mode = DStandardPaths::Auto;
 
 QString DStandardPaths::writableLocation(QStandardPaths::StandardLocation type)
@@ -64,7 +79,7 @@ QString DStandardPaths::writableLocation(QStandardPaths::StandardLocation type)
     case Test:
         return  QStandardPaths::writableLocation(type);
     case Snap:
-        return DSnapStandardPaths::writableLocation(type);
+        return DSnapStandardPathsPrivate::writableLocation(type);
     }
     return QStandardPaths::writableLocation(type);
 }
@@ -76,7 +91,7 @@ QStringList DStandardPaths::standardLocations(QStandardPaths::StandardLocation t
     case Test:
         return  QStandardPaths::standardLocations(type);
     case Snap:
-        return DSnapStandardPaths::standardLocations(type);
+        return DSnapStandardPathsPrivate::standardLocations(type);
     }
     return  QStandardPaths::standardLocations(type);
 }
index 526c5c0f7947361c6e1e5710dafcc23b2c2a1fc1..0b076bc5233a5491335ee377eb9a23894894e1ed 100644 (file)
@@ -11,7 +11,6 @@
 
 DCORE_BEGIN_NAMESPACE
 
-
 QString unqtifyName(const QString &name)
 {
     QString ret;
@@ -45,6 +44,15 @@ public:
     Q_DECLARE_PUBLIC(GSettingsBackend)
 };
 
+/*!
+ * \class GSettingsBackend
+ * \brief Storage backend of DSettings use gsettings.
+ *
+ * You should generate gsetting schema with /usr/lib/dtk2/dtk-settings.
+ *
+ * You can find this tool from libdtkcore-bin. use /usr/lib/dtk2/dtk-settings -h for help.
+ */
+
 GSettingsBackend::GSettingsBackend(DSettings *settings, QObject *parent) :
     DSettingsBackend(parent), d_ptr(new GSettingsBackendPrivate(this))
 {
@@ -75,18 +83,30 @@ GSettingsBackend::~GSettingsBackend()
 
 }
 
+/*!
+ * \brief List all gsettings keys.
+ * \return
+ */
 QStringList GSettingsBackend::keys() const
 {
     Q_D(const GSettingsBackend);
     return d->gsettings->keys();
 }
 
+/*!
+ * \brief Get value of key.
+ * \return
+ */
 QVariant GSettingsBackend::getOption(const QString &key) const
 {
     Q_D(const GSettingsBackend);
     return d->gsettings->get(qtifyName(key));
 }
 
+/*!
+ * \brief Set value to gsettings
+ * \return
+ */
 void GSettingsBackend::doSetOption(const QString &key, const QVariant &value)
 {
     Q_D(GSettingsBackend);
@@ -96,6 +116,9 @@ void GSettingsBackend::doSetOption(const QString &key, const QVariant &value)
     }
 }
 
+/*!
+ * \brief Trigger DSettings to sync option to storage.
+ */
 void GSettingsBackend::doSync()
 {
     Q_EMIT sync();
index 94abdc0ec58363d2e20c9f93444ca3cf7b2574c3..8b02ebba913ced0d6efd043caa84ed4b70211244 100644 (file)
@@ -12,7 +12,7 @@ class LIBDTKCORESHARED_EXPORT GSettingsBackend: public DSettingsBackend
 {
     Q_OBJECT
 public:
-    explicit GSettingsBackend(DSettings *settings, QObject *parent = 0);
+    explicit GSettingsBackend(DSettings *settings, QObject *parent = nullptr);
     ~GSettingsBackend();
 
     virtual QStringList keys() const Q_DECL_OVERRIDE;
index ae15b4fc329e81d3290d4721275ef3832c4dd2cc..ec30198d4073830311f1e3d3a10645e0e4fcf6e1 100644 (file)
@@ -35,6 +35,16 @@ public:
     Q_DECLARE_PUBLIC(QSettingBackend)
 };
 
+/*!
+ * \class QSettingBackend
+ * \brief Storage DSetttings to an QSettings
+ */
+
+/*!
+ * \brief Save data to filepath with QSettings::NativeFormat format.
+ * \param filepath is path to storage data.
+ * \param parent
+ */
 QSettingBackend::QSettingBackend(const QString &filepath, QObject *parent) :
     DSettingsBackend(parent), d_ptr(new QSettingBackendPrivate(this))
 {
@@ -49,12 +59,21 @@ QSettingBackend::~QSettingBackend()
 
 }
 
+/*!
+ * \brief List all keys of QSettings
+ * \return
+ */
 QStringList QSettingBackend::keys() const
 {
     Q_D(const QSettingBackend);
     return d->settings->childGroups();
 }
 
+/*!
+ * \brief Get value of key from QSettings
+ * \param key
+ * \return
+ */
 QVariant QSettingBackend::getOption(const QString &key) const
 {
     Q_D(const QSettingBackend);
@@ -64,6 +83,11 @@ QVariant QSettingBackend::getOption(const QString &key) const
     return value;
 }
 
+/*!
+ * \brief Set value of key to QSettings
+ * \param key
+ * \param value
+ */
 void QSettingBackend::doSetOption(const QString &key, const QVariant &value)
 {
     Q_D(QSettingBackend);
@@ -78,6 +102,9 @@ void QSettingBackend::doSetOption(const QString &key, const QVariant &value)
     d->writeLock.unlock();
 }
 
+/*!
+ * \brief Trigger DSettings to save option value to QSettings
+ */
 void QSettingBackend::doSync()
 {
     Q_D(QSettingBackend);
index d5a66367f8302739b20e76a2f9a719c79a794a1f..ae13a6da0dbea743bbc6343beba8fbeb576fe8ae 100644 (file)
@@ -48,6 +48,222 @@ public:
 };
 
 
+/*!
+ * \~english \class DSettingsBackend
+ * \brief DSettingsBackend is interface of DSettings storage class.
+ *
+ * Simaple example:
+
+```json
+{
+    "groups": [{
+        "key": "base",
+        "name": "Basic settings",
+        "groups": [{
+                "key": "open_action",
+                "name": "Open Action",
+                "options": [{
+                        "key": "alway_open_on_new",
+                        "type": "checkbox",
+                        "text": "Always Open On New Windows",
+                        "default": true
+                    },
+                    {
+                        "key": "open_file_action",
+                        "name": "Open File:",
+                        "type": "combobox",
+                        "default": ""
+                    }
+                ]
+            },
+            {
+                "key": "new_tab_windows",
+                "name": "New Tab & Window",
+                "options": [{
+                        "key": "new_window_path",
+                        "name": "New Window Open:",
+                        "type": "combobox",
+                        "default": ""
+                    },
+                    {
+                        "key": "new_tab_path",
+                        "name": "New Tab Open:",
+                        "type": "combobox",
+                        "default": ""
+                    }
+                ]
+            }
+        ]
+    }]
+}
+```
+
+ * How to read/write key and value:
+
+```c++
+    // init a storage backend
+    QTemporaryFile tmpFile;
+    tmpFile.open();
+    auto backend = new Dtk::Core::QSettingBackend(tmpFile.fileName());
+
+    // read settings from json
+    auto settings = Dtk::Core::DSettings::fromJsonFile(":/resources/data/dfm-settings.json");
+    settings->setBackend(backend);
+
+    // read value
+    auto opt = settings->option("base.new_tab_windows.new_window_path");
+    qDebug() << opt->value();
+
+    // modify value
+    opt->setValue("Test")
+    qDebug() << opt->value();
+```
+ * \sa Dtk::Core::DSettingsOption
+ * \sa Dtk::Core::DSettingsGroup
+ * \sa Dtk::Core::DSettingsBackend
+ * \sa Dtk::Widget::DSettingsWidgetFactory
+ * \sa Dtk::Widget::DSettingsDialog
+ */
+
+
+/*!
+ * \~english \class DSettings
+ * \brief DSettings support base config storage and ui create tool for dtk applications.
+ * \sa Dtk::Core::DSettings
+ * \sa Dtk::Core::DSettingsBackend
+ *
+ * \fn virtual QStringList DSettingsBackend::keys() const = 0;
+ * \brief return all key of storage.
+ *
+ * \fn virtual QVariant DSettingsBackend::getOption(const QString &key) const = 0;
+ * \brief get value by key.
+ *
+ * \fn virtual void DSettingsBackend::doSync() = 0;
+ * \brief do the real sync action.
+ *
+ * \fn virtual void DSettingsBackend::doSetOption(const QString &key, const QVariant &value) = 0;
+ * \brief write key/value to storage.
+ *
+ * \fn void DSettingsBackend::optionChanged(const QString &key, const QVariant &value);
+ * \brief emited when option value changed.
+ *
+ * \fn void DSettingsBackend::sync();
+ * \brief private signal, please do not use it.
+ *
+ * \fn void DSettingsBackend::setOption(const QString &key, const QVariant &value);
+ * \brief private signal, please do not use it.
+ */
+
+/*!
+ * \~chinese \class DSettingsBackend
+ * \brief DSettingsBackend是一个纯虚类, 用来描述DSettings的存储接口。
+ * \sa Dtk::Core::DSettings
+ * \sa Dtk::Core::DSettingsBackend
+ *
+ * \fn virtual QStringList DSettingsBackend::keys() const = 0;
+ * \brief 返回全部键值。
+ *
+ * \fn virtual QVariant DSettingsBackend::getOption(const QString &key) const = 0;
+ * \brief 获取key对应的值。
+ *
+ * \fn virtual void DSettingsBackend::doSync() = 0;
+ * \brief 开始进行同步。
+ *
+ * \fn virtual void DSettingsBackend::doSetOption(const QString &key, const QVariant &value) = 0;
+ * \brief 设置key对应的值,并使用存储后端进行存储。
+ *
+ * \fn void DSettingsBackend::optionChanged(const QString &key, const QVariant &value);
+ * \brief DSettingsOption的值发生变化时发出的信号。
+ *
+ * \fn void DSettingsBackend::sync();
+ * \brief 私有信号,请勿使用。
+ *
+ * \fn void DSettingsBackend::setOption(const QString &key, const QVariant &value);
+ * \brief 私有信号,请勿使用。
+ */
+
+
+/*!
+ * \~chinese \class DSettings
+ * \brief DSettings是设计上为Dtk的应用程序提供统一的配置存储以及界面生成工具的基础库。
+ * DSetting使用json作为应用配置程序的描述文件。简单来说,应用查询的配置分为组/键值二个基础层级,
+ * 对于一个标准的Dtk配置控件,一般只包含组/子组/键值三个层级,对于超过三个层级的键值,可以通过
+ * DSettings的API接口进行读取和写入,但是不能在标准的DSettingsDialogs上显示出来。
+ *
+ * 一个简单的配置文件如下:
+```json
+{
+    "groups": [{
+        "key": "base",
+        "name": "Basic settings",
+        "groups": [{
+                "key": "open_action",
+                "name": "Open Action",
+                "options": [{
+                        "key": "alway_open_on_new",
+                        "type": "checkbox",
+                        "text": "Always Open On New Windows",
+                        "default": true
+                    },
+                    {
+                        "key": "open_file_action",
+                        "name": "Open File:",
+                        "type": "combobox",
+                        "default": ""
+                    }
+                ]
+            },
+            {
+                "key": "new_tab_windows",
+                "name": "New Tab & Window",
+                "options": [{
+                        "key": "new_window_path",
+                        "name": "New Window Open:",
+                        "type": "combobox",
+                        "default": ""
+                    },
+                    {
+                        "key": "new_tab_path",
+                        "name": "New Tab Open:",
+                        "type": "combobox",
+                        "default": ""
+                    }
+                ]
+            }
+        ]
+    }]
+}
+```
+
+ * 改组中包含一个base的root组,两个子组: open_action/new_tab_windows,每个子组有包含若干选项。
+ * 对于"New Window Open:"这个配置,其完整的访问id为base.new_tab_windows.new_window_path。
+ * 读取/设置其值的示例如下:
+
+```c++
+    // 初始化一个存储后端
+    QTemporaryFile tmpFile;
+    tmpFile.open();
+    auto backend = new Dtk::Core::QSettingBackend(tmpFile.fileName());
+
+    // 从json中初始化配置
+    auto settings = Dtk::Core::DSettings::fromJsonFile(":/resources/data/dfm-settings.json");
+    settings->setBackend(backend);
+
+    // 读取配置
+    auto opt = settings->option("base.new_tab_windows.new_window_path");
+    qDebug() << opt->value();
+
+    // 修改配置
+    opt->setValue("Test")
+    qDebug() << opt->value();
+```
+ * \sa Dtk::Core::DSettingsOption
+ * \sa Dtk::Core::DSettingsGroup
+ * \sa Dtk::Core::DSettingsBackend
+ * \sa Dtk::Widget::DSettingsWidgetFactory
+ * \sa Dtk::Widget::DSettingsDialog
+ */
+
 DSettings::DSettings(QObject *parent) :
     QObject(parent), dd_ptr(new DSettingsPrivate(this))
 {
index d4e78891fddcaf18ac3ee237791f13956baf1f86..45e49aef429e5dbe7ee9ba12460bc03c9d22d89c 100644 (file)
@@ -29,7 +29,7 @@ class LIBDTKCORESHARED_EXPORT DSettingsBackend : public QObject
 {
     Q_OBJECT
 public:
-    explicit DSettingsBackend(QObject *parent = 0): QObject(parent)
+    explicit DSettingsBackend(QObject *parent = Q_NULLPTR): QObject(parent)
     {
         connect(this, &DSettingsBackend::sync, this, &DSettingsBackend::doSync, Qt::QueuedConnection);
         connect(this, &DSettingsBackend::setOption, this, &DSettingsBackend::doSetOption, Qt::QueuedConnection);
index 28109a24909e1e5807f6be1fc2b5a27c12a42c97..1b49d88e5d2338c3af23a2278a9d430948827bde 100644 (file)
@@ -47,6 +47,12 @@ public:
     Q_DECLARE_PUBLIC(DSettingsGroup)
 };
 
+/*!
+ * \class DSettingsGroup
+ * \brief A group of DSettingsOption and DSettingsGroup.
+ * DSettingsGroup can contain a lost option and subgroup.
+ */
+
 DSettingsGroup::DSettingsGroup(QObject *parent) :
     QObject(parent), dd_ptr(new DSettingsGroupPrivate(this))
 {
@@ -57,49 +63,82 @@ DSettingsGroup::~DSettingsGroup()
 {
 
 }
-
+/*!
+ * \brief Get direct parent group of this group.
+ * \return
+ */
 QPointer<DSettingsGroup> DSettingsGroup::parentGroup() const
 {
     Q_D(const DSettingsGroup);
     return d->parent;
 }
 
+/*!
+ * \brief Change the direct parent group of this group.
+ * \param parentGroup
+ */
 void DSettingsGroup::setParentGroup(QPointer<DSettingsGroup> parentGroup)
 {
     Q_D(DSettingsGroup);
     d->parent = parentGroup;
 }
 
+/*!
+ * \brief Return the full key of this group, include all parent.
+ * \return
+ */
 QString DSettingsGroup::key() const
 {
     Q_D(const DSettingsGroup);
     return d->key;
 }
 
+/*!
+ * \brief Get display name of this group, it may be translated.
+ * \return
+ */
 QString DSettingsGroup::name() const
 {
     Q_D(const DSettingsGroup);
     return d->name;
 }
 
+/*!
+ * \brief Check this group will show on DSettings dialog.
+ * \return true if group not bind to ui element.
+ */
 bool DSettingsGroup::isHidden() const
 {
     Q_D(const DSettingsGroup);
     return d->hide;
 }
 
+/*!
+ * \brief Get the child group of groupKey
+ * \param groupKey is child group key
+ * \return
+ */
 QPointer<DSettingsGroup> DSettingsGroup::childGroup(const QString &groupKey) const
 {
     Q_D(const DSettingsGroup);
     return d->childGroups.value(groupKey);
 }
 
+/*!
+ * \brief Get the child option of key
+ * \param key is child option key
+ * \return
+ */
 QPointer<DSettingsOption> DSettingsGroup::option(const QString &key) const
 {
     Q_D(const DSettingsGroup);
     return d->childOptions.value(key);
 }
 
+/*!
+ * \brief Enum all direct child group of this group
+ * \return
+ */
 QList<QPointer<DSettingsGroup> > DSettingsGroup::childGroups() const
 {
     Q_D(const DSettingsGroup);
@@ -110,6 +149,10 @@ QList<QPointer<DSettingsGroup> > DSettingsGroup::childGroups() const
     return grouplist;
 }
 
+/*!
+ * \brief Enum all direct child option with the raw order in json description file.
+ * \return
+ */
 QList<QPointer<DSettingsOption> > DSettingsGroup::childOptions() const
 {
     Q_D(const DSettingsGroup);
@@ -120,12 +163,22 @@ QList<QPointer<DSettingsOption> > DSettingsGroup::childOptions() const
     return optionlist;
 }
 
+/*!
+ * \brief Enum all direct child option of this group.
+ * \return
+ */
 QList<QPointer<DSettingsOption> > DSettingsGroup::options() const
 {
     Q_D(const DSettingsGroup);
     return d->options.values();
 }
 
+/*!
+ * \brief Convert QJsonObject to DSettingsGroup.
+ * \param prefixKey instead parse prefix key from parent.
+ * \param json is an QJsonObejct instance.
+ * \sa QPointer<DSettingsOption> Dtk::Core::DSettingsGroup::parseJson(const QString &prefixKey, const QJsonObject &json)
+ */
 QPointer<DSettingsGroup> DSettingsGroup::fromJson(const QString &prefixKey, const QJsonObject &group)
 {
     auto groupPtr = QPointer<DSettingsGroup>(new DSettingsGroup);
@@ -133,6 +186,12 @@ QPointer<DSettingsGroup> DSettingsGroup::fromJson(const QString &prefixKey, cons
     return groupPtr;
 }
 
+/*!
+ * \brief Parse QJsonObject to DSettingsGroup.
+ * \param prefixKey instead parse prefix key from parent.
+ * \param json is an QJsonObejct instance.
+ * \sa QPointer<DSettingsOption> Dtk::Core::DSettingsGroup::fromJson(const QString &prefixKey, const QJsonObject &json)
+ */
 void DSettingsGroup::parseJson(const QString &prefixKey, const QJsonObject &group)
 {
     Q_D(DSettingsGroup);
index b11a9422451c7e5b91f3b2332f3d2024e14d1d75..ab09a81cc956a9f2c8b1c913e3bc177e68e73d4a 100644 (file)
@@ -49,9 +49,6 @@ public:
     QList<QPointer<DSettingsOption> > options() const;
 
     static QPointer<DSettingsGroup> fromJson(const QString &prefixKey, const QJsonObject &group);
-Q_SIGNALS:
-
-public Q_SLOTS:
 
 private:
     void parseJson(const QString &prefixKey, const QJsonObject &group);
index fb2644ca12fa52b9c1c8e6f6f6164bab58dc4ded..82419f9cc77eed0dd44a004b27a43f37d5401d44 100644 (file)
@@ -45,6 +45,22 @@ public:
     Q_DECLARE_PUBLIC(DSettingsOption)
 };
 
+/*!
+ * \class DSettingsOption
+ * \brief DSettingsOption is the base key/value item of DSettings.
+ *
+ * \fn void DSettingsOption::valueChanged(QVariant value);
+ * \brief Emit when option value change.
+ *
+ * \fn void DSettingsOption::dataChanged(const QString &dataType, QVariant value);
+ * \brief Emit when option data change.
+ *
+ *
+
+ * \property DSettingsOption::value
+ * \brief Current value of this option.
+ */
+
 DSettingsOption::DSettingsOption(QObject *parent) :
     QObject(parent), dd_ptr(new DSettingsOptionPrivate(this))
 {
@@ -55,73 +71,128 @@ DSettingsOption::~DSettingsOption()
 
 }
 
+/*!
+ * \brief Get direct parent group of this option.
+ * \return
+ */
 QPointer<DSettingsGroup> DSettingsOption::parentGroup() const
 {
     Q_D(const DSettingsOption);
     return d->parent;
 }
 
+/*!
+ * \brief Change the direct parent group of this option.
+ * \param parentGroup
+ */
 void DSettingsOption::setParentGroup(QPointer<DSettingsGroup> parentGroup)
 {
     Q_D(DSettingsOption);
     d->parent = parentGroup;
 }
 
+/*!
+ * \brief Return the full key of this option, include all parent.
+ * \return
+ */
 QString DSettingsOption::key() const
 {
     Q_D(const DSettingsOption);
     return d->key;
 }
 
+/*!
+ * \brief Get display name of the option, it may be translated.
+ * \return
+ */
 QString DSettingsOption::name() const
 {
     Q_D(const DSettingsOption);
     return d->name;
 }
 
+/*!
+ * \brief Check this option can be reset to default value. if false, reset action will not take effect.
+ * \return true if can be reset.
+ * \sa Dtk::Core::DSettings::reset
+ */
 bool DSettingsOption::canReset() const
 {
     Q_D(const DSettingsOption);
     return d->canReset;
 }
 
+/*!
+ * \brief Default value of this option, must config in this json desciption file.
+ * \return
+ */
 QVariant DSettingsOption::defaultValue() const
 {
     Q_D(const DSettingsOption);
     return d->defalutValue;
 }
 
+/*!
+ * \brief Get current value of option.
+ * \return
+ */
 QVariant DSettingsOption::value() const
 {
     Q_D(const DSettingsOption);
     return (!d->value.isValid() || d->value.isNull()) ? d->defalutValue : d->value;
 }
 
+/*!
+ * \brief Custom data of option, like QObject::property.
+ * \param dataType
+ * \return
+ * \sa QObject::property
+ * \sa Dtk::Core::DSettingsOption::setData
+ */
 QVariant DSettingsOption::data(const QString &dataType) const
 {
     Q_D(const DSettingsOption);
     return d->datas.value(dataType);
 }
 
+/*!
+ * \brief UI widget type of this option
+ * \return
+ * \sa Dtk::Widget::DSettingsWidgetFactory
+ */
 QString DSettingsOption::viewType() const
 {
     Q_D(const DSettingsOption);
     return d->viewType;
 }
 
+/*!
+ * \brief Check this option will show on DSettings dialog.
+ * \return true if option not bind to ui element.
+ */
 bool DSettingsOption::isHidden() const
 {
     Q_D(const DSettingsOption);
     return d->hidden;
 }
 
-QPointer<DSettingsOption> DSettingsOption::fromJson(const QString &prefixKey, const QJsonObject &group)
+/*!
+ * \brief Convert QJsonObject to DSettingsOption.
+ * \param prefixKey instead parse prefix key from parent.
+ * \param json is an QJsonObejct instance.
+ * \return
+ */
+QPointer<DSettingsOption> DSettingsOption::fromJson(const QString &prefixKey, const QJsonObject &json)
 {
     auto optionPtr = QPointer<DSettingsOption>(new DSettingsOption);
-    optionPtr->parseJson(prefixKey, group);
+    optionPtr->parseJson(prefixKey, json);
     return optionPtr;
 }
 
+/*!
+ * \brief Set current value of option
+ * \param value
+ */
 void DSettingsOption::setValue(QVariant value)
 {
     Q_D(DSettingsOption);
@@ -134,16 +205,22 @@ void DSettingsOption::setValue(QVariant value)
     Q_EMIT valueChanged(value);
 }
 
-//!
-//! \brief DSettingsOption::setDefault will override default value of json
-//! \param value
-//!
-// void DSettingsOption::setDefault(QVariant value)
-// {
-//     Q_D(DSettingsOption);
-//     d->defalutValue = value;
-// }
-
+///*!
+// * \brief Override default value of json
+// * \param value
+// */
+//void DSettingsOption::setDefault(QVariant value)
+//{
+//    Q_D(DSettingsOption);
+//    d->defalutValue = value;
+//}
+
+/*!
+ * \brief Set custom data
+ * \param dataType is data id, just a unique string.
+ * \param value of the data id.
+ * \sa Dtk::Core::DSettingsOption::data
+ */
 void DSettingsOption::setData(const QString &dataType, QVariant value)
 {
     Q_D(DSettingsOption);
@@ -157,6 +234,12 @@ void DSettingsOption::setData(const QString &dataType, QVariant value)
     Q_EMIT dataChanged(dataType, value);
 }
 
+/*!
+ * \brief Parse QJsonObject to DSettingsOption.
+ * \param prefixKey instead parse prefix key from parent.
+ * \param json is an QJsonObejct instance.
+ * \sa QPointer<DSettingsOption> Dtk::Core::DSettingsOption::fromJson(const QString &prefixKey, const QJsonObject &json)
+ */
 void DSettingsOption::parseJson(const QString &prefixKey, const QJsonObject &option)
 {
     Q_D(DSettingsOption);
index 0087c0d8380e1acc3d4262f65bb1ad00f8e5a69a..72448dfd6b0951bdb7c040d11f2ee928fe15afdf 100644 (file)
@@ -49,7 +49,7 @@ public:
     QString viewType() const;
     bool isHidden() const;
 
-    static QPointer<DSettingsOption> fromJson(const QString &prefixKey, const QJsonObject &group);
+    static QPointer<DSettingsOption> fromJson(const QString &prefixKey, const QJsonObject &json);
 Q_SIGNALS:
     void valueChanged(QVariant value);
     void dataChanged(const QString &dataType, QVariant value);
index 418ed316eda9c10498a48906d7cd61e5749c1b29..6522d8d125a1635ca7e059d3250448c6163022e5 100644 (file)
 
 DCORE_BEGIN_NAMESPACE
 
+/*!
+ * \~chinese \class DAbstractUnitFormatter
+ * \~chinese \brief DAbstractUnitFormatter 类是对拥有相同类型数据管理的接口类
+ * 接口定义了最大值、最小值、转换单位和单位对应的字符串。
+ *
+ * \~chinese \fn DAbstractUnitFormatter::unitMax
+ * \~chinese \brief 返回列表中最大的单位
+ *
+ * \~chinese \fn DAbstractUnitFormatter::unitMin
+ * \~chinese \brief 返回列表中最小的单位
+ *
+ * \~chinese \fn DAbstractUnitFormatter::unitConvertRate
+ * \~chinese \brief 返回当前设置的转换单位
+ *
+ * \~chinese \fn DAbstractUnitFormatter::unitValueMax
+ * \~chinese \brief 返回列表中根据当前设置的转换单位的最大值
+ *
+ * \~chinese \fn DAbstractUnitFormatter::unitValueMin
+ * \~chinese \brief 返回列表中根据当前设置的转换单位的最小值
+ *
+ * \~chinese \fn DAbstractUnitFormatter::unitStr
+ * \~chinese \brief 传入id,返回列表中对应的字符串
+ */
+
+/*!
+ * \~chinese \brief DAbstractUnitFormatter 的构造函数
+ *
+ */
 DAbstractUnitFormatter::DAbstractUnitFormatter()
 {
 
 }
 
+/*!
+ * \~chinese \brief DAbstractUnitFormatter 的析构函数
+ *
+ */
 DAbstractUnitFormatter::~DAbstractUnitFormatter()
 {
 
 }
 
+/*!
+ * \~chinese \brief 将传入的值从当前转换单位转换到目标单位上,返回转换过的值
+ * 如果当前转换单位小于目标单位,值会被缩小,反之会放大,当前转换单位也会被缩小和放大,直至当前转换单位等于目标单位。
+ *
+ * @param value 原始数值
+ * @param currentUnit 当前的转换比率
+ * @param targetUnit 目标的转换比率
+ * @return qreal 返回转换过的值
+ */
 qreal DAbstractUnitFormatter::formatAs(qreal value, int currentUnit, const int targetUnit) const
 {
     while (currentUnit < targetUnit)
@@ -39,6 +80,15 @@ qreal DAbstractUnitFormatter::formatAs(qreal value, int currentUnit, const int t
     return value;
 }
 
+/*!
+ * \~chinese \brief 将值转换到最合适的单位上
+ *
+ * 如果值大于 unitMin() 或者小于 unitMax() ,会尽量保证值被转换到接近最小值的合适单位上。
+ *
+ * @param value 原始数值
+ * @param unit 当前的转换单位
+ * @return QPair<qreal, int> 转换过的数值和转化单位
+ */
 QPair<qreal, int> DAbstractUnitFormatter::format(const qreal value, const int unit) const
 {
     // can convert to smaller unit
@@ -52,6 +102,13 @@ QPair<qreal, int> DAbstractUnitFormatter::format(const qreal value, const int un
     return QPair<qreal, int>(value, unit);
 }
 
+/*!
+ * \~chinese \brief 是 format() ,但是包含了完整的转换数据
+ *
+ * @param value
+ * @param unit
+ * @return QList<QPair<qreal, int> >
+ */
 QList<QPair<qreal, int> > DAbstractUnitFormatter::formatAsUnitList(const qreal value, int unit) const
 {
     if (qFuzzyIsNull(value))
index fbd98061d1ad103c6ae31eeac275821c5224a245..f5c408fa866d17e2a6f6cc8afc4baf5a3a360e83 100644 (file)
 
 DCORE_BEGIN_NAMESPACE
 
+/*!
+ * \~chinese \class DDiskSizeFormatter
+ *
+ * \~chinese \brief DDiskSizeFormatter 是用来获取磁盘容量单位的类, 通过枚举值
+ * 获取不同类型磁盘容量的单位
+ *
+ * \~chinese \enum DDiskSizeFormatter::DiskUnits 磁盘容量单位的枚举
+ * \~chinese \var DDiskSizeFormatter::DiskUnits DDiskSizeFormatter::B
+ * \~chinese \brief 字节
+ * \~chinese \var DDiskSizeFormatter::DiskUnits DDiskSizeFormatter::K
+ * \~chinese \brief 千字节
+ * \~chinese \var DDiskSizeFormatter::DiskUnits DDiskSizeFormatter::M
+ * \~chinese \brief 兆字节
+ * \~chinese \var DDiskSizeFormatter::DiskUnits DDiskSizeFormatter::G
+ * \~chinese \brief 吉字节
+ * \~chinese \var DDiskSizeFormatter::DiskUnits DDiskSizeFormatter::T
+ * \~chinese \brief 太字节
+ *
+ * \~chinese \fn DDiskSizeFormatter::unitMax
+ * \~chinese \brief 返回最大磁盘容量单位的枚举
+ *
+ * \~chinese \fn DDiskSizeFormatter::unitMin
+ * \~chinese \brief 返回最小磁盘容量单位的枚举
+ *
+ * \~chinese \fn DDiskSizeFormatter::unitConvertRate
+ * \~chinese \brief 返回当前的单位转换比率
+ */
+
+/*!
+ * \~chinese \brief DDiskSizeFormatter的构造函数
+ *
+ */
 DDiskSizeFormatter::DDiskSizeFormatter()
     : DAbstractUnitFormatter()
 {
 
 }
 
+/*!
+ * \~chinese \brief 根据枚举返回对应单位的字符串
+ *
+ * @param unitId DDiskSizeFormatter::DiskUnits 的枚举值
+ * @return QString 对应单位的字符串
+ */
 QString DDiskSizeFormatter::unitStr(int unitId) const
 {
     switch (unitId)
@@ -41,6 +79,12 @@ QString DDiskSizeFormatter::unitStr(int unitId) const
     return QString();
 }
 
+/*!
+ * \~chinese \brief 设置当前的单位转换比率
+ *
+ * @param rate 转换比率
+ * @return DDiskSizeFormatter 返回 DDiskSizeFormatter 对象
+ */
 DDiskSizeFormatter DDiskSizeFormatter::rate(int rate)
 {
     m_rate = rate;
index 79cc8315e4aaeb955e4380fc84857978be65f955..508e6db4e3cf05d274a8810ff3b71e485cbf82fc 100644 (file)
 
 DCORE_BEGIN_NAMESPACE
 
+/*!
+ * \~chinese \class DTimeUnitFormatter
+ *
+ * \~chinese \brief DTimeUnitFormatter是用来获取时间单位的类, 通过枚举值
+ * 获取不同类型时间单位的进制
+ *
+ * \~chinese \enum DTimeUnitFormatter::TimeUnits 时间单位的枚举
+ * \~chinese \var DTimeUnitFormatter::TimeUnits DTimeUnitFormatter::Seconds
+ * \~chinese \brief 返回分钟单位的进制
+ * \~chinese \var DTimeUnitFormatter::TimeUnits DTimeUnitFormatter::Minute
+ * \~chinese \brief 返回秒单位的进制
+ * \~chinese \var DTimeUnitFormatter::TimeUnits DTimeUnitFormatter::Hour
+ * \~chinese \brief 返回小时单位的进制
+ * \~chinese \var DTimeUnitFormatter::TimeUnits DTimeUnitFormatter::Day
+ * \~chinese \brief 返回天单位的进制
+ *
+ * \~chinese \fn DTimeUnitFormatter::unitMax
+ * \~chinese \brief 返回最大时间单位的枚举
+ *
+ * \~chinese \fn DTimeUnitFormatter::unitMin
+ * \~chinese \brief 返回最小时间单位的枚举
+ */
+
+/*!
+ * \~chinese \brief DTimeUnitFormatter的构造函数
+ *
+ */
 DTimeUnitFormatter::DTimeUnitFormatter()
     : DAbstractUnitFormatter()
 {
 
 }
 
+/*!
+ * \~chinese \brief 根据枚举返回对应的单位进制
+ *
+ * @param unitId DTimeUnitFormatter::TimeUnits 的枚举值
+ * @return uint 对应的单位进制
+ */
 uint DTimeUnitFormatter::unitConvertRate(int unitId) const
 {
     switch (unitId)
@@ -40,6 +73,12 @@ uint DTimeUnitFormatter::unitConvertRate(int unitId) const
     return 0;
 }
 
+/*!
+ * \~chinese \brief 根据枚举返回对应单位的缩写
+ *
+ * @param unitId DTimeUnitFormatter::TimeUnits 的枚举值
+ * @return QString 对应单位的缩写
+ */
 QString DTimeUnitFormatter::unitStr(int unitId) const
 {
     switch (unitId)
index 69edb3f6da8fe3de155ee05e51a89e44ad8c0ac0..9ccd9927329b1248acf2f2ace5db3d32f4270a5e 100644 (file)
@@ -42,7 +42,7 @@ void TestDUtil::testLogPath()
     qApp->setApplicationName("deepin-test-dtk");
 
     DPathBuf logPath(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first());
-    logPath = logPath / ".cache/deepin/deepin-test-dtk/deepin-test-dtk.log";
+    logPath = logPath / ".cache" / "deepin" / "deepin-test-dtk" / "deepin-test-dtk.log";
 
     QCOMPARE(DLogManager::getlogFilePath(), logPath.toString());
 }
@@ -160,40 +160,41 @@ void TestDUtil::testDBusSender()
 {
     // basic method call
     DDBusSender()
-        .service("com.deepin.dde.ControlCenter")
-        .interface("com.deepin.dde.ControlCenter")
-        .path("/com/deepin/dde/ControlCenter")
-        .method("ShowPage")
-        .arg(QString("update"))
-        .arg(QString("available-updates"))
-        .call();
+    .service("com.deepin.dde.ControlCenter")
+    .interface("com.deepin.dde.ControlCenter")
+    .path("/com/deepin/dde/ControlCenter")
+    .method("ShowPage")
+    .arg(QString("update"))
+    .arg(QString("available-updates"))
+    .call();
 
     // property set
     QDBusPendingReply<> r1 = DDBusSender()
-        .service("com.deepin.dde.daemon.Dock")
-        .interface("com.deepin.dde.daemon.Dock")
-        .path("/com/deepin/dde/daemon/Dock")
-        .property("DisplayMode")
-        .set(1); // set to efficient mode
+                             .service("com.deepin.dde.daemon.Dock")
+                             .interface("com.deepin.dde.daemon.Dock")
+                             .path("/com/deepin/dde/daemon/Dock")
+                             .property("DisplayMode")
+                             .set(1); // set to efficient mode
 
     // property get
     QDBusPendingReply<QVariant> r2 = DDBusSender()
-        .service("com.deepin.dde.daemon.Dock")
-        .interface("com.deepin.dde.daemon.Dock")
-        .path("/com/deepin/dde/daemon/Dock")
-        .property("DisplayMode")
-        .get(); // read mode
+                                     .service("com.deepin.dde.daemon.Dock")
+                                     .interface("com.deepin.dde.daemon.Dock")
+                                     .path("/com/deepin/dde/daemon/Dock")
+                                     .property("DisplayMode")
+                                     .get(); // read mode
 
-    if (!r2.isError() && !r1.isError())
+    if (!r2.isError() && !r1.isError()) {
         Q_ASSERT(r2.value().toInt() == 1);
+    }
 
     // complex type property get
     QDBusPendingReply<QVariant> r3 = DDBusSender()
-        .service("com.deepin.dde.ControlCenter")
-        .interface("com.deepin.dde.ControlCenter")
-        .path("/com/deepin/dde/ControlCenter")
-        .property("Rect")
-        .get();
+                                     .service("com.deepin.dde.ControlCenter")
+                                     .interface("com.deepin.dde.ControlCenter")
+                                     .path("/com/deepin/dde/ControlCenter")
+                                     .property("Rect")
+                                     .get();
 
     QVariant variant = r3.value();
     const QDBusArgument v = variant.value<QDBusArgument>();