1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
qTox/src/profile.h

60 lines
2.0 KiB
C
Raw Normal View History

2015-06-04 05:20:47 +08:00
#ifndef PROFILE_H
#define PROFILE_H
#include <QVector>
#include <QString>
#include <QByteArray>
class Core;
class QThread;
2015-06-04 05:20:47 +08:00
/// Manages user profiles
class Profile
{
public:
/// Locks and loads an existing profile and create the associate Core* instance
/// Returns a nullptr on error, for example if the profile is already in use
static Profile* loadProfile(QString name, QString password);
/// Creates a new profile and the associated Core* instance
/// If password is not empty, the profile will be encrypted
/// Returns a nullptr on error, for example if the profile already exists
static Profile* createProfile(QString name, QString password);
2015-06-04 05:20:47 +08:00
~Profile();
Core* getCore();
2015-06-04 08:43:07 +08:00
QString getName();
void startCore(); ///< Starts the Core thread
2015-06-04 08:43:07 +08:00
bool isNewProfile();
QByteArray loadToxSave(); ///< Loads the profile's .tox save from file, unencrypted
2015-06-04 05:20:47 +08:00
/// Scan for profile, automatically importing them if needed
/// NOT thread-safe
static void scanProfiles();
static QVector<QString> getProfiles();
static bool profileExists(QString name);
static bool isProfileEncrypted(QString name); ///< Returns false on error.
2015-06-04 05:20:47 +08:00
private:
2015-06-04 08:43:07 +08:00
Profile(QString name, QString password, bool newProfile);
2015-06-04 05:20:47 +08:00
/// Lists all the files in the config dir with a given extension
/// Pass the raw extension, e.g. "jpeg" not ".jpeg".
static QVector<QString> getFilesByExt(QString extension);
/// Creates a .ini file for the given .tox profile
/// Only pass the basename, without extension
static void importProfile(QString name);
private:
Core* core;
QThread* coreThread;
QString name, password;
2015-06-04 05:20:47 +08:00
static QVector<QString> profiles;
2015-06-04 08:43:07 +08:00
bool newProfile; ///< True if this is a newly created profile, with no .tox save file yet.
/// How much data we need to read to check if the file is encrypted
/// Must be >= TOX_ENC_SAVE_MAGIC_LENGTH (8), which isn't publicly defined
static constexpr int encryptHeaderSize = 8;
2015-06-04 05:20:47 +08:00
};
#endif // PROFILE_H