remarkable_tool/notebook_tree.hpp

78 lines
1.9 KiB
C++

/* Copyright 2021, Michele Santullo
* This file is part of remarkable_tool.
*
* remarkable_tool 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.
*
* Remarkable_tool 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 remarkable_tool. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vector>
#include <cstdint>
#include <string>
#include <string_view>
#include <memory>
namespace duck {
struct NotebookInfo {
std::string visible_name;
std::string parent;
std::string type;
std::vector<std::string> files;
std::uint64_t version = 0;
std::uintmax_t total_size = 0;
bool deleted = false;
bool isolated = true;
};
struct Node {
Node() :
info(nullptr),
parent(nullptr)
{ }
Node (const Node&) = delete;
Node (Node&& other) = default;
Node& operator= (const Node&) = delete;
Node& operator= (Node&&) = default;
Node (std::string_view name, const NotebookInfo* payload, Node* parent) :
name(name),
info(payload),
parent(parent)
{ }
std::vector<Node> children;
std::string_view name;
const NotebookInfo* info;
const Node* parent;
};
class Notebooks {
public:
Notebooks (std::string_view base_path);
~Notebooks() noexcept;
std::vector<Node> build_tree() const;
private:
struct LocalData;
std::unique_ptr<LocalData> m_local;
};
std::vector<const NotebookInfo*> make_list_of_deleted (const std::vector<Node>& roots);
std::vector<const NotebookInfo*> make_list_of_deleted (const Node* root);
} //namespace duck