/* common/KMFileEnumerator.h
 *
 * Copyright (C) 2023 OpenKylin, Inc
 */

#ifndef __KMFILEENUMERATOR_H__
#define __KMFILEENUMERATOR_H__

#include <gio/gio.h>
#include <string>
#include <memory>

#include "KMFileInfo.h"

/**
 * @brief : 对GFileEnumerator的简单封装
 * @note  : g_file_enumerate_开头的函数都可以迁移进来
 */
class KMFileEnumerator
{
public:
    KMFileEnumerator();
    KMFileEnumerator(const KMFileEnumerator &other);
    KMFileEnumerator(KMFileEnumerator &&other);
    KMFileEnumerator(GFileEnumerator *enumerator);
    ~KMFileEnumerator();

    KMFileEnumerator &operator=(const KMFileEnumerator &other);
    KMFileEnumerator &operator=(KMFileEnumerator &&other);
    KMFileEnumerator &operator=(GFileEnumerator *enumerator);

    operator bool() const
    {
        return d.operator bool();
    }

    GFileEnumerator *get();

    KMFileInfo nextFile();

    // 获取最后一次错误信息
    std::string errorMessage() const;
    int errorCode() const;

private:
    class Private;
    std::shared_ptr<Private> d = nullptr;
};

#endif // !__KMFILEENUMERATOR_H__
