Beispiel #1
0
HistoryKeeper *HistoryKeeper::getInstance()
{
    historyMutex.lock();
    if (historyInstance == nullptr)
    {
        QList<QString> initLst;
        initLst.push_back(QString("CREATE TABLE IF NOT EXISTS history (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER NOT NULL, ") +
                          QString("chat_id INTEGER NOT NULL, sender INTEGER NOT NULL, message TEXT NOT NULL, alias TEXT);"));
        initLst.push_back(QString("CREATE TABLE IF NOT EXISTS aliases (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id TEXT UNIQUE NOT NULL);"));
        initLst.push_back(QString("CREATE TABLE IF NOT EXISTS chats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE NOT NULL, ctype INTEGER NOT NULL);"));
        initLst.push_back(QString("CREATE TABLE IF NOT EXISTS sent_status (id INTEGER PRIMARY KEY AUTOINCREMENT, status INTEGER NOT NULL DEFAULT 0);"));

        QString path(":memory:");
        GenericDdInterface *dbIntf;

        if (Nexus::getProfile()->isEncrypted())
        {
            path = getHistoryPath();
            dbIntf = new EncryptedDb(path, initLst);

            historyInstance = new HistoryKeeper(dbIntf);
            return historyInstance;
        }
        else
        {
            path = getHistoryPath();
        }

        dbIntf = new PlainDb(path, initLst);
        historyInstance = new HistoryKeeper(dbIntf);
    }
    historyMutex.unlock();

    return historyInstance;
}
Beispiel #2
0
bool HistoryKeeper::isFileExist(bool encrypted)
{
    QString path = getHistoryPath({}, encrypted ? 1 : 0);
    QFile file(path);

    return file.exists();
}
Beispiel #3
0
bool HistoryKeeper::checkPassword(const TOX_PASS_KEY &passkey, int encrypted)
{
    if (!Settings::getInstance().getEnableLogging() && (encrypted == -1))
        return true;

    if ((encrypted == 1) || (encrypted == -1))
        return EncryptedDb::check(passkey, getHistoryPath(Nexus::getProfile()->getName(), encrypted));

    return true;
}
Beispiel #4
0
bool HistoryKeeper::checkPassword(int encrypted)
{
    if (!Settings::getInstance().getEnableLogging() && (encrypted == -1))
        return true;

    if ((encrypted == 1) || (encrypted == -1 && Settings::getInstance().getEncryptLogs()))
        return EncryptedDb::check(getHistoryPath(Settings::getInstance().getCurrentProfile(), encrypted));

    return true;
}
Beispiel #5
0
bool HistoryKeeper::checkPassword()
{
    if (Settings::getInstance().getEnableLogging())
    {
        if (Settings::getInstance().getEncryptLogs())
        {
            QString dbpath = getHistoryPath();
            return EncryptedDb::check(dbpath);
        } else {
            return true;
        }
    } else {
        return true;
    }
}
Beispiel #6
0
HistoryKeeper *HistoryKeeper::getInstance()
{
    if (historyInstance == nullptr)
    {
        QList<QString> initLst;
        initLst.push_back(QString("CREATE TABLE IF NOT EXISTS history (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER NOT NULL, ") +
                          QString("chat_id INTEGER NOT NULL, sender INTEGER NOT NULL, message TEXT NOT NULL);"));
        initLst.push_back(QString("CREATE TABLE IF NOT EXISTS aliases (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id TEXT UNIQUE NOT NULL);"));
        initLst.push_back(QString("CREATE TABLE IF NOT EXISTS chats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE NOT NULL, ctype INTEGER NOT NULL);"));
        initLst.push_back(QString("CREATE TABLE IF NOT EXISTS sent_status (id INTEGER PRIMARY KEY AUTOINCREMENT, status INTEGER NOT NULL DEFAULT 0);"));

        QString path(":memory:");
        GenericDdInterface *dbIntf;

        if (Settings::getInstance().getEnableLogging())
        {
            bool encrypted = Settings::getInstance().getEncryptLogs();

            if (encrypted)
            {
                path = getHistoryPath();
                dbIntf = new EncryptedDb(path, initLst);

                historyInstance = new HistoryKeeper(dbIntf);
                return historyInstance;
            } else {
                path = getHistoryPath();
            }
        }

        dbIntf = new PlainDb(path, initLst);
        historyInstance = new HistoryKeeper(dbIntf);
    }

    return historyInstance;
}
Beispiel #7
0
void HistoryKeeper::removeHistory()
{
    resetInstance();
    QFile::remove(getHistoryPath({}, 0));
    QFile::remove(getHistoryPath({}, 1));
}