|
|
@ -142,67 +142,59 @@ Session *Session::instance() |
|
|
|
return m_instance; |
|
|
|
return m_instance; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Session::addFolder(const QString &path, QString *error) |
|
|
|
nonstd::expected<void, QString> Session::addFolder(const QString &path) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Folder *destFolder = prepareItemDest(path, error); |
|
|
|
const nonstd::expected<Folder *, QString> result = prepareItemDest(path); |
|
|
|
if (!destFolder) |
|
|
|
if (!result) |
|
|
|
return false; |
|
|
|
return result.get_unexpected(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto destFolder = result.value(); |
|
|
|
addItem(new Folder(path), destFolder); |
|
|
|
addItem(new Folder(path), destFolder); |
|
|
|
store(); |
|
|
|
store(); |
|
|
|
return true; |
|
|
|
return {}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Session::addFeed(const QString &url, const QString &path, QString *error) |
|
|
|
nonstd::expected<void, QString> Session::addFeed(const QString &url, const QString &path) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_feedsByURL.contains(url)) |
|
|
|
if (m_feedsByURL.contains(url)) |
|
|
|
{ |
|
|
|
return nonstd::make_unexpected(tr("RSS feed with given URL already exists: %1.").arg(url)); |
|
|
|
if (error) |
|
|
|
|
|
|
|
*error = tr("RSS feed with given URL already exists: %1.").arg(url); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Folder *destFolder = prepareItemDest(path, error); |
|
|
|
const nonstd::expected<Folder *, QString> result = prepareItemDest(path); |
|
|
|
if (!destFolder) |
|
|
|
if (!result) |
|
|
|
return false; |
|
|
|
return result.get_unexpected(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto destFolder = result.value(); |
|
|
|
addItem(new Feed(generateUID(), url, path, this), destFolder); |
|
|
|
addItem(new Feed(generateUID(), url, path, this), destFolder); |
|
|
|
store(); |
|
|
|
store(); |
|
|
|
if (m_processingEnabled) |
|
|
|
if (m_processingEnabled) |
|
|
|
feedByURL(url)->refresh(); |
|
|
|
feedByURL(url)->refresh(); |
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
return {}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Session::moveItem(const QString &itemPath, const QString &destPath, QString *error) |
|
|
|
nonstd::expected<void, QString> Session::moveItem(const QString &itemPath, const QString &destPath) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (itemPath.isEmpty()) |
|
|
|
if (itemPath.isEmpty()) |
|
|
|
{ |
|
|
|
return nonstd::make_unexpected(tr("Cannot move root folder.")); |
|
|
|
if (error) |
|
|
|
|
|
|
|
*error = tr("Cannot move root folder."); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto item = m_itemsByPath.value(itemPath); |
|
|
|
auto item = m_itemsByPath.value(itemPath); |
|
|
|
if (!item) |
|
|
|
if (!item) |
|
|
|
{ |
|
|
|
return nonstd::make_unexpected(tr("Item doesn't exist: %1.").arg(itemPath)); |
|
|
|
if (error) |
|
|
|
|
|
|
|
*error = tr("Item doesn't exist: %1.").arg(itemPath); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return moveItem(item, destPath, error); |
|
|
|
return moveItem(item, destPath); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Session::moveItem(Item *item, const QString &destPath, QString *error) |
|
|
|
nonstd::expected<void, QString> Session::moveItem(Item *item, const QString &destPath) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Q_ASSERT(item); |
|
|
|
Q_ASSERT(item); |
|
|
|
Q_ASSERT(item != rootFolder()); |
|
|
|
Q_ASSERT(item != rootFolder()); |
|
|
|
|
|
|
|
|
|
|
|
Folder *destFolder = prepareItemDest(destPath, error); |
|
|
|
const nonstd::expected<Folder *, QString> result = prepareItemDest(destPath); |
|
|
|
if (!destFolder) |
|
|
|
if (!result) |
|
|
|
return false; |
|
|
|
return result.get_unexpected(); |
|
|
|
|
|
|
|
|
|
|
|
auto srcFolder = static_cast<Folder *>(m_itemsByPath.value(Item::parentPath(item->path()))); |
|
|
|
auto srcFolder = static_cast<Folder *>(m_itemsByPath.value(Item::parentPath(item->path()))); |
|
|
|
|
|
|
|
const auto destFolder = result.value(); |
|
|
|
if (srcFolder != destFolder) |
|
|
|
if (srcFolder != destFolder) |
|
|
|
{ |
|
|
|
{ |
|
|
|
srcFolder->removeItem(item); |
|
|
|
srcFolder->removeItem(item); |
|
|
@ -211,25 +203,17 @@ bool Session::moveItem(Item *item, const QString &destPath, QString *error) |
|
|
|
m_itemsByPath.insert(destPath, m_itemsByPath.take(item->path())); |
|
|
|
m_itemsByPath.insert(destPath, m_itemsByPath.take(item->path())); |
|
|
|
item->setPath(destPath); |
|
|
|
item->setPath(destPath); |
|
|
|
store(); |
|
|
|
store(); |
|
|
|
return true; |
|
|
|
return {}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Session::removeItem(const QString &itemPath, QString *error) |
|
|
|
nonstd::expected<void, QString> Session::removeItem(const QString &itemPath) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (itemPath.isEmpty()) |
|
|
|
if (itemPath.isEmpty()) |
|
|
|
{ |
|
|
|
return nonstd::make_unexpected(tr("Cannot delete root folder.")); |
|
|
|
if (error) |
|
|
|
|
|
|
|
*error = tr("Cannot delete root folder."); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto item = m_itemsByPath.value(itemPath); |
|
|
|
auto *item = m_itemsByPath.value(itemPath); |
|
|
|
if (!item) |
|
|
|
if (!item) |
|
|
|
{ |
|
|
|
return nonstd::make_unexpected(tr("Item doesn't exist: %1.").arg(itemPath)); |
|
|
|
if (error) |
|
|
|
|
|
|
|
*error = tr("Item doesn't exist: %1.").arg(itemPath); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emit itemAboutToBeRemoved(item); |
|
|
|
emit itemAboutToBeRemoved(item); |
|
|
|
item->cleanup(); |
|
|
|
item->cleanup(); |
|
|
@ -238,7 +222,7 @@ bool Session::removeItem(const QString &itemPath, QString *error) |
|
|
|
folder->removeItem(item); |
|
|
|
folder->removeItem(item); |
|
|
|
delete item; |
|
|
|
delete item; |
|
|
|
store(); |
|
|
|
store(); |
|
|
|
return true; |
|
|
|
return {}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QList<Item *> Session::items() const |
|
|
|
QList<Item *> Session::items() const |
|
|
@ -395,30 +379,18 @@ void Session::store() |
|
|
|
m_confFileStorage->store(FeedsFileName, QJsonDocument(rootFolder()->toJsonValue().toObject()).toJson()); |
|
|
|
m_confFileStorage->store(FeedsFileName, QJsonDocument(rootFolder()->toJsonValue().toObject()).toJson()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Folder *Session::prepareItemDest(const QString &path, QString *error) |
|
|
|
nonstd::expected<Folder *, QString> Session::prepareItemDest(const QString &path) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!Item::isValidPath(path)) |
|
|
|
if (!Item::isValidPath(path)) |
|
|
|
{ |
|
|
|
return nonstd::make_unexpected(tr("Incorrect RSS Item path: %1.").arg(path)); |
|
|
|
if (error) |
|
|
|
|
|
|
|
*error = tr("Incorrect RSS Item path: %1.").arg(path); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_itemsByPath.contains(path)) |
|
|
|
if (m_itemsByPath.contains(path)) |
|
|
|
{ |
|
|
|
return nonstd::make_unexpected(tr("RSS item with given path already exists: %1.").arg(path)); |
|
|
|
if (error) |
|
|
|
|
|
|
|
*error = tr("RSS item with given path already exists: %1.").arg(path); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const QString destFolderPath = Item::parentPath(path); |
|
|
|
const QString destFolderPath = Item::parentPath(path); |
|
|
|
auto destFolder = qobject_cast<Folder *>(m_itemsByPath.value(destFolderPath)); |
|
|
|
const auto destFolder = qobject_cast<Folder *>(m_itemsByPath.value(destFolderPath)); |
|
|
|
if (!destFolder) |
|
|
|
if (!destFolder) |
|
|
|
{ |
|
|
|
return nonstd::make_unexpected(tr("Parent folder doesn't exist: %1.").arg(destFolderPath)); |
|
|
|
if (error) |
|
|
|
|
|
|
|
*error = tr("Parent folder doesn't exist: %1.").arg(destFolderPath); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return destFolder; |
|
|
|
return destFolder; |
|
|
|
} |
|
|
|
} |
|
|
|