Placefile "Remove" functionality

This commit is contained in:
Dan Paulat 2023-08-22 23:52:55 -05:00
parent 9955c4ccbe
commit ad5c2b583d
6 changed files with 115 additions and 2 deletions

View file

@ -314,6 +314,33 @@ void PlacefileManager::LoadFile(const std::string& filename)
});
}
void PlacefileManager::RemoveUrl(const std::string& urlString)
{
std::unique_lock lock(p->placefileRecordLock_);
// Determine if the placefile has been loaded previously
auto it = std::find_if(p->placefileRecords_.begin(),
p->placefileRecords_.end(),
[&urlString](auto& record)
{ return record->name_ == urlString; });
if (it == p->placefileRecords_.end())
{
logger_->debug("Placefile doesn't exist: {}", urlString);
return;
}
// Placefile exists, proceed with removing
logger_->info("RemoveUrl: {}", urlString);
// Remove record
p->placefileRecords_.erase(it);
p->placefileRecordMap_.erase(urlString);
lock.unlock();
Q_EMIT PlacefileRemoved(urlString);
}
void PlacefileManager::Impl::PlacefileRecord::Update()
{
logger_->debug("Update: {}", name_);

View file

@ -39,11 +39,13 @@ public:
void AddUrl(const std::string& urlString);
void LoadFile(const std::string& filename);
void RemoveUrl(const std::string& urlString);
static std::shared_ptr<PlacefileManager> Instance();
signals:
void PlacefileEnabled(const std::string& name, bool enabled);
void PlacefileRemoved(const std::string& name);
void PlacefileRenamed(const std::string& oldName,
const std::string& newName);
void PlacefileUpdated(const std::string& name);