4 Комити 703ad7cccd ... fde3eb8a63

Аутор SHA1 Порука Датум
  Ivan Baidakou fde3eb8a63 fltk, add local_entry пре 2 недеља
  Ivan Baidakou 054c5ee69b fltk, refactor entry пре 2 недеља
  Ivan Baidakou 2d61f360d4 fltk, refactor entry пре 2 недеља
  Ivan Baidakou 3646290117 fltk, refactor entry пре 2 недеља

+ 2 - 2
src/ui-fltk/CMakeLists.txt

@@ -33,13 +33,14 @@ add_executable(syncspirit-fltk WIN32
     table_widget/label.cpp
     table_widget/path.cpp
     tree_item/devices.cpp
+    tree_item/entry.cpp
     tree_item/folder.cpp
     tree_item/folders.cpp
     tree_item/ignored_device.cpp
     tree_item/ignored_devices.cpp
+    tree_item/local_entry.cpp
     tree_item/peer_device.cpp
     tree_item/peer_entry.cpp
-    tree_item/peer_entry_base.cpp
     tree_item/peer_folder.cpp
     tree_item/peer_folders.cpp
     tree_item/pending_device.cpp
@@ -48,7 +49,6 @@ add_executable(syncspirit-fltk WIN32
     tree_item/pending_folders.cpp
     tree_item/self_device.cpp
     tree_item/settings.cpp
-
 )
 
 target_link_libraries(syncspirit-fltk

+ 7 - 9
src/ui-fltk/app_supervisor.cpp

@@ -5,10 +5,10 @@
 #include "tree_item/ignored_devices.h"
 #include "tree_item/peer_device.h"
 #include "tree_item/peer_folder.h"
+#include "tree_item/entry.h"
 #include "tree_item/pending_devices.h"
 #include "tree_item/pending_folders.h"
 #include "tree_item/peer_folders.h"
-#include "tree_item/virtual_entry.h"
 #include "net/names.h"
 #include "config/utils.h"
 #include "model/diff/load/load_cluster.h"
@@ -413,14 +413,12 @@ void app_supervisor_t::set_show_deleted(bool value) {
     auto &self = cluster->get_device();
     for (auto &it_f : cluster->get_folders()) {
         for (auto &it : it_f.item->get_folder_infos()) {
-            if (it.item->get_device() != self.get()) {
-                auto generic_augmnetation = it.item->get_augmentation();
-                if (generic_augmnetation) {
-                    auto augmentation = static_cast<augmentation_t *>(generic_augmnetation.get());
-                    auto virtual_entry = static_cast<tree_item::virtual_entry_t *>(augmentation->get_owner());
-                    if (virtual_entry) {
-                        virtual_entry->show_deleted(value);
-                    }
+            auto generic_augmnetation = it.item->get_augmentation();
+            if (generic_augmnetation) {
+                auto augmentation = static_cast<augmentation_base_t *>(generic_augmnetation.get());
+                auto entry = static_cast<tree_item::entry_t *>(augmentation->get_owner());
+                if (entry) {
+                    entry->show_deleted(value);
                 }
             }
         }

+ 3 - 3
src/ui-fltk/content/remote_file_table.cpp

@@ -1,5 +1,5 @@
 #include "remote_file_table.h"
-#include "../tree_item/virtual_entry.h"
+#include "../tree_item/entry.h"
 #include "../table_widget/checkbox.h"
 
 using namespace syncspirit::fltk;
@@ -30,7 +30,7 @@ auto make_checkbox(Fl_Widget &container, bool value) -> widgetable_ptr_t { retur
 
 remote_file_table_t::remote_file_table_t(tree_item_t &container_, int x, int y, int w, int h)
     : parent_t(x, y, w, h), container{container_}, top_modifitcation{-1} {
-    auto host = static_cast<tree_item::virtual_entry_t *>(&container);
+    auto host = static_cast<tree_item::entry_t *>(&container);
     auto &entry = *host->get_entry();
     auto data = table_rows_t();
 
@@ -83,7 +83,7 @@ void remote_file_table_t::refresh() {
         }
     };
 
-    auto host = static_cast<tree_item::virtual_entry_t *>(&container);
+    auto host = static_cast<tree_item::entry_t *>(&container);
     auto &entry = *host->get_entry();
     auto &devices = container.supervisor.get_cluster()->get_devices();
     auto data = table_rows_t();

+ 35 - 15
src/ui-fltk/tree_item/peer_entry_base.cpp

@@ -1,20 +1,20 @@
-#include "peer_entry_base.h"
+#include "entry.h"
 #include "../utils.hpp"
 
 using namespace syncspirit::fltk::tree_item;
 
-peer_entry_base_t::peer_entry_base_t(app_supervisor_t &supervisor, Fl_Tree *tree, bool has_augmentation)
+entry_t::entry_t(app_supervisor_t &supervisor, Fl_Tree *tree, bool has_augmentation)
     : parent_t(supervisor, tree, has_augmentation), dirs_count{0} {}
 
-peer_entry_base_t::~peer_entry_base_t() {
+entry_t::~entry_t() {
     for (auto item : orphaned_items) {
         delete item;
     }
     orphaned_items.clear();
 }
 
-auto peer_entry_base_t::locate_dir(const bfs::path &parent) -> virtual_entry_t * {
-    auto current = (virtual_entry_t *)(this);
+auto entry_t::locate_dir(const bfs::path &parent) -> entry_t * {
+    auto current = this;
     for (auto &piece : parent) {
         auto name = piece.string();
         current = current->locate_own_dir(name);
@@ -22,24 +22,24 @@ auto peer_entry_base_t::locate_dir(const bfs::path &parent) -> virtual_entry_t *
     return current;
 }
 
-virtual_entry_t *peer_entry_base_t::locate_own_dir(std::string_view name) {
+entry_t *entry_t::locate_own_dir(std::string_view name) {
     if (name.empty()) {
         return this;
     }
 
     auto it = dirs_map.find(name);
     assert(it != dirs_map.end());
-    return static_cast<virtual_entry_t *>(it->second);
+    return it->second;
 }
 
-void peer_entry_base_t::add_entry(model::file_info_t &file) {
+void entry_t::add_entry(model::file_info_t &file) {
     bool deleted = file.is_deleted();
     bool show_deleted = supervisor.get_app_config().fltk_config.display_deleted;
     auto name_provider = [this](int index) { return std::string_view(child(index)->label()); };
     auto start_index = int{0};
     auto end_index = int{0};
     auto t = tree();
-    auto node = within_tree([&]() -> peer_entry_base_t * { return make_entry(file); });
+    auto node = within_tree([&]() -> entry_t * { return make_entry(file); });
     node->update_label();
     auto name = std::string(node->label());
 
@@ -57,9 +57,9 @@ void peer_entry_base_t::add_entry(model::file_info_t &file) {
     }
 }
 
-void peer_entry_base_t::remove_child(tree_item_t *child) { remove_node(static_cast<peer_entry_base_t *>(child)); }
+void entry_t::remove_child(tree_item_t *child) { remove_node(static_cast<entry_t *>(child)); }
 
-void peer_entry_base_t::remove_node(peer_entry_base_t *child) {
+void entry_t::remove_node(entry_t *child) {
     auto &entry = *child->get_entry();
     if (entry.is_dir()) {
         --dirs_count;
@@ -85,7 +85,7 @@ void peer_entry_base_t::remove_node(peer_entry_base_t *child) {
     }
 }
 
-void peer_entry_base_t::insert_node(peer_entry_base_t *node) {
+void entry_t::insert_node(entry_t *node) {
     auto name_provider = [this](int index) { return std::string_view(child(index)->label()); };
     auto start_index = int{0};
     auto end_index = int{0};
@@ -108,7 +108,7 @@ void peer_entry_base_t::insert_node(peer_entry_base_t *node) {
     }
 }
 
-void peer_entry_base_t::show_deleted(bool value) {
+void entry_t::show_deleted(bool value) {
     for (auto &it : dirs_map) {
         it.second->show_deleted(value);
     }
@@ -128,14 +128,14 @@ void peer_entry_base_t::show_deleted(bool value) {
     tree()->redraw();
 }
 
-void peer_entry_base_t::apply(const entry_visitor_t &visitor, void *data) {
+void entry_t::apply(const entry_visitor_t &visitor, void *data) {
     auto entry = get_entry();
     if (entry) {
         visitor.visit(*entry, data);
     }
     bool show_deleted = supervisor.get_app_config().fltk_config.display_deleted;
     for (int i = 0; i < children(); ++i) {
-        auto &child_entry = static_cast<peer_entry_base_t &>(*child(i));
+        auto &child_entry = static_cast<entry_t &>(*child(i));
         child_entry.apply(visitor, data);
     }
 
@@ -145,3 +145,23 @@ void peer_entry_base_t::apply(const entry_visitor_t &visitor, void *data) {
         }
     }
 }
+
+void entry_t::make_hierarchy(model::file_infos_map_t &files_map) {
+    using files_t = std::vector<model::file_info_ptr_t>;
+    auto files = files_t();
+    files.reserve(files_map.size());
+    for (auto &it : files_map) {
+        files.push_back(it.item);
+    }
+    auto sorter = [](const model::file_info_ptr_t &l, const model::file_info_ptr_t &r) {
+        return l->get_name() < r->get_name();
+    };
+    std::sort(files.begin(), files.end(), sorter);
+
+    for (auto &file : files) {
+        auto path = bfs::path(file->get_name());
+        auto dir = locate_dir(path.parent_path());
+        dir->add_entry(*file);
+    }
+    tree()->redraw();
+}

+ 46 - 0
src/ui-fltk/tree_item/entry.h

@@ -0,0 +1,46 @@
+#pragma once
+
+#include "../tree_item.h"
+#include "utils/string_comparator.hpp"
+#include <set>
+#include <map>
+
+namespace syncspirit::fltk::tree_item {
+
+struct entry_visitor_t {
+    virtual ~entry_visitor_t() = default;
+    virtual void visit(const model::file_info_t &file, void *) const = 0;
+};
+
+struct entry_t : tree_item_t {
+    using parent_t = tree_item_t;
+    using items_t = std::set<entry_t *>;
+    using dirs_map_t = std::map<std::string, entry_t *, utils::string_comparator_t>;
+
+    entry_t(app_supervisor_t &supervisor, Fl_Tree *tree, bool has_augmentation);
+    ~entry_t();
+
+    virtual model::file_info_t *get_entry() = 0;
+
+    virtual entry_t *locate_own_dir(std::string_view name);
+    virtual entry_t *locate_dir(const bfs::path &parent);
+    virtual void add_entry(model::file_info_t &file);
+    virtual void show_deleted(bool value);
+    virtual void apply(const entry_visitor_t &visitor, void *data);
+
+    void remove_child(tree_item_t *child) override;
+
+    void remove_node(entry_t *child);
+    void insert_node(entry_t *node);
+
+    void make_hierarchy(model::file_infos_map_t &files);
+
+    virtual entry_t *make_entry(model::file_info_t &file) = 0;
+
+    int dirs_count;
+    dirs_map_t dirs_map;
+    items_t orphaned_items;
+    items_t deleted_items;
+};
+
+} // namespace syncspirit::fltk::tree_item

+ 12 - 2
src/ui-fltk/tree_item/folder.cpp

@@ -1,10 +1,10 @@
 #include "folder.h"
 
+#include "local_entry.h"
 #include "../table_widget/checkbox.h"
 #include "../table_widget/choice.h"
 #include "../table_widget/input.h"
 #include "../table_widget/label.h"
-
 #include "../content/folder_table.h"
 #include "../symbols.h"
 #include <boost/smart_ptr/local_shared_ptr.hpp>
@@ -195,7 +195,13 @@ folder_t::folder_t(model::folder_t &folder_, app_supervisor_t &supervisor, Fl_Tr
 
     auto cluster = supervisor.get_cluster();
     auto &fi = *folder.get_folder_infos().by_device(*cluster->get_device());
-    fi.set_augmentation(new augmentation_proxy_t(get_proxy()));
+    auto augmentation = augmentation_ptr_t(new augmentation_proxy_t(get_proxy()));
+    fi.set_augmentation(augmentation);
+
+    tree->close(this, 0);
+
+    auto &files_map = fi.get_file_infos();
+    make_hierarchy(files_map);
 }
 
 void folder_t::update_label() {
@@ -226,3 +232,7 @@ bool folder_t::on_select() {
     });
     return true;
 }
+
+auto folder_t::get_entry() -> model::file_info_t * { return nullptr; }
+
+auto folder_t::make_entry(model::file_info_t &file) -> entry_t * { return new local_entry_t(supervisor, tree(), file); }

+ 6 - 4
src/ui-fltk/tree_item/folder.h

@@ -1,18 +1,20 @@
 #pragma once
 
-#include "../tree_item.h"
-#include "../static_table.h"
+#include "entry.h"
 
 namespace syncspirit::fltk::tree_item {
 
-struct folder_t : tree_item_t {
-    using parent_t = tree_item_t;
+struct folder_t final : entry_t {
+    using parent_t = entry_t;
 
     folder_t(model::folder_t &folder, app_supervisor_t &supervisor, Fl_Tree *tree);
 
     bool on_select() override;
     void update_label() override;
 
+    model::file_info_t *get_entry() override;
+    entry_t *make_entry(model::file_info_t &file) override;
+
     model::folder_t &folder;
 };
 

+ 53 - 0
src/ui-fltk/tree_item/local_entry.cpp

@@ -0,0 +1,53 @@
+#include "local_entry.h"
+#include "../content/remote_file_table.h"
+
+using namespace syncspirit::fltk;
+using namespace syncspirit::fltk::tree_item;
+
+local_entry_t::local_entry_t(app_supervisor_t &supervisor, Fl_Tree *tree, model::file_info_t &entry_)
+    : parent_t(supervisor, tree, true), entry{entry_} {
+    entry.set_augmentation(get_proxy());
+}
+
+void local_entry_t::update_label() {
+    auto &entry = *get_entry();
+    auto name = get_entry()->get_path().filename().string();
+    label(name.c_str());
+    if (entry.is_deleted()) {
+        labelfgcolor(FL_DARK1);
+    } else if (entry.is_global()) {
+        labelfgcolor(FL_GREEN);
+    } else {
+        labelfgcolor(FL_BLACK);
+    }
+    tree()->redraw();
+}
+
+bool local_entry_t::on_select() {
+    content = supervisor.replace_content([&](content_t *content) -> content_t * {
+        auto prev = content->get_widget();
+        int x = prev->x(), y = prev->y(), w = prev->w(), h = prev->h();
+        return new content::remote_file_table_t(*this, x, y, w, h);
+    });
+    return true;
+}
+
+void local_entry_t::on_update() {
+    parent_t::on_update();
+    auto &entry = *get_entry();
+    if (entry.is_deleted()) {
+        auto host = static_cast<entry_t *>(parent());
+        bool show_deleted = supervisor.get_app_config().fltk_config.display_deleted;
+        if (!show_deleted) {
+            host->remove_child(this);
+        } else {
+            host->deleted_items.emplace(this);
+        }
+    }
+}
+
+auto local_entry_t::get_entry() -> model::file_info_t * { return &entry; }
+
+auto local_entry_t::make_entry(model::file_info_t &file) -> entry_t * {
+    return new local_entry_t(supervisor, tree(), file);
+}

+ 21 - 0
src/ui-fltk/tree_item/local_entry.h

@@ -0,0 +1,21 @@
+#pragma once
+
+#include "entry.h"
+
+namespace syncspirit::fltk::tree_item {
+
+struct local_entry_t final : entry_t {
+    using parent_t = entry_t;
+    local_entry_t(app_supervisor_t &supervisor, Fl_Tree *tree, model::file_info_t &entry);
+
+    bool on_select() override;
+    void update_label() override;
+    void on_update() override;
+
+    model::file_info_t *get_entry() override;
+    entry_t *make_entry(model::file_info_t &file) override;
+
+    model::file_info_t &entry;
+};
+
+}; // namespace syncspirit::fltk::tree_item

+ 0 - 0
src/ui-fltk/tree_item/peer_entry.cpp


Неке датотеке нису приказане због велике количине промена