1
0
forked from blue/squawk
squawk/core/components/urlstorage.h

98 lines
3.5 KiB
C
Raw Normal View History

2021-04-13 13:27:31 +00:00
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CORE_URLSTORAGE_H
#define CORE_URLSTORAGE_H
#include <QString>
#include <QDataStream>
2021-04-13 13:27:31 +00:00
#include <list>
#include <storage.h>
#include <shared/messageinfo.h>
2021-04-13 13:27:31 +00:00
namespace Core {
class UrlStorage {
public:
2021-04-13 13:27:31 +00:00
class UrlInfo;
2021-04-13 13:27:31 +00:00
public:
UrlStorage(const QString& name);
~UrlStorage();
void open();
void close();
void addFile(const QString& url);
void addFile(const QString& url, const QString& path);
void addFile(const QString& url, const QString& account, const QString& jid, const QString& id);
void addFile(const QString& url, const QString& path, const QString& account, const QString& jid, const QString& id);
void addFile(const std::list<Shared::MessageInfo>& msgs, const QString& url, const QString& path); //this one overwrites all that was
std::list<Shared::MessageInfo> removeFile(const QString& url); //removes entry like it never was in the database, returns affected message infos
std::list<Shared::MessageInfo> deletedFile(const QString& path); //empties the localPath of the entry, returns affected message infos
std::list<Shared::MessageInfo> setPath(const QString& url, const QString& path);
QString getUrl(const QString& path);
2021-04-13 13:27:31 +00:00
QString addMessageAndCheckForPath(const QString& url, const QString& account, const QString& jid, const QString& id);
std::pair<QString, std::list<Shared::MessageInfo>> getPath(const QString& url);
2021-04-13 13:27:31 +00:00
private:
LMDBAL::Base base;
LMDBAL::Storage<QString, UrlInfo>* urlToInfo;
LMDBAL::Storage<QString, QString>* pathToUrl;
2021-04-13 13:27:31 +00:00
private:
void writeInfo(const QString& key, const UrlInfo& info, bool overwrite = false);
void writeInfo(const QString& key, const UrlInfo& info, MDB_txn* txn, bool overwrite = false);
UrlInfo addToInfo(const QString& url, const QString& account, const QString& jid, const QString& id, const QString& path = "-s");
2021-04-13 13:27:31 +00:00
public:
2021-04-13 13:27:31 +00:00
class UrlInfo {
public:
UrlInfo(const QString& path);
UrlInfo(const QString& path, const std::list<Shared::MessageInfo>& msgs);
2021-04-13 13:27:31 +00:00
UrlInfo();
~UrlInfo();
void serialize(QDataStream& data) const;
void deserialize(QDataStream& data);
QString getPath() const;
bool hasPath() const;
void setPath(const QString& path);
bool addMessage(const QString& acc, const QString& jid, const QString& id);
void getMessages(std::list<Shared::MessageInfo>& container) const;
2021-04-13 13:27:31 +00:00
private:
QString localPath;
std::list<Shared::MessageInfo> messages;
2021-04-13 13:27:31 +00:00
};
};
}
QDataStream& operator >> (QDataStream &in, Core::UrlStorage::UrlInfo& info);
QDataStream& operator << (QDataStream &out, const Core::UrlStorage::UrlInfo& info);
2021-04-13 13:27:31 +00:00
#endif // CORE_URLSTORAGE_H