2015-06-04 05:20:47 +08:00
|
|
|
#ifndef PROFILE_H
|
|
|
|
#define PROFILE_H
|
|
|
|
|
|
|
|
#include <QVector>
|
|
|
|
#include <QString>
|
2015-06-04 07:30:17 +08:00
|
|
|
#include <QByteArray>
|
|
|
|
|
|
|
|
class Core;
|
|
|
|
class QThread;
|
2015-06-04 05:20:47 +08:00
|
|
|
|
|
|
|
/// Manages user profiles
|
|
|
|
class Profile
|
|
|
|
{
|
|
|
|
public:
|
2015-06-04 07:30:17 +08:00
|
|
|
/// 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
|
2015-06-04 08:10:06 +08:00
|
|
|
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();
|
|
|
|
|
2015-06-04 07:30:17 +08:00
|
|
|
Core* getCore();
|
2015-06-04 08:43:07 +08:00
|
|
|
QString getName();
|
|
|
|
|
2015-06-04 07:30:17 +08:00
|
|
|
void startCore(); ///< Starts the Core thread
|
2015-06-04 08:43:07 +08:00
|
|
|
bool isNewProfile();
|
2015-06-04 07:30:17 +08:00
|
|
|
QByteArray loadToxSave(); ///< Loads the profile's .tox save from file, unencrypted
|
2015-06-04 17:37:54 +08:00
|
|
|
void saveToxSave(); ///< Saves the profile's .tox save, encrypted if needed
|
|
|
|
void saveToxSave(QByteArray data); ///< Saves the profile's .tox save with this data, encrypted if needed
|
2015-06-04 07:30:17 +08:00
|
|
|
|
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();
|
|
|
|
|
2015-06-04 08:10:06 +08:00
|
|
|
static bool profileExists(QString name);
|
|
|
|
static bool isProfileEncrypted(QString name); ///< Returns false on error.
|
2015-06-04 07:30:17 +08:00
|
|
|
|
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:
|
2015-06-04 07:30:17 +08:00
|
|
|
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.
|
2015-06-04 07:30:17 +08:00
|
|
|
/// 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
|