qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
Public Slots | Signals | Public Member Functions | Static Public Member Functions | Private Slots | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Profile Class Reference

Handles all qTox internal paths. More...

#include <profile.h>

Inheritance diagram for Profile:
Inheritance graph
Collaboration diagram for Profile:
Collaboration graph

Public Slots

void onRequestSent (const ToxPk &friendPk, const QString &message)
 Adds history message about friendship request attempt if history is enabled. More...
 

Signals

void selfAvatarChanged (const QPixmap &pixmap)
 
void friendAvatarChanged (const ToxPk &friendPk, const QPixmap &pixmap)
 
void friendAvatarSet (const ToxPk &friendPk, const QPixmap &pixmap)
 
void friendAvatarRemoved (const ToxPk &friendPk)
 
void failedToStart ()
 
void badProxy ()
 
void coreChanged (Core &core)
 

Public Member Functions

 ~Profile ()
 
CoregetCore () const
 
QString getName () const
 
void startCore ()
 Starts the Core thread. More...
 
bool isEncrypted () const
 Checks, if profile has a password. More...
 
QString setPassword (const QString &newPassword)
 Changes the encryption password and re-saves everything with it. More...
 
const ToxEncryptgetPasskey () const
 
QPixmap loadAvatar ()
 Get our avatar from cache. More...
 
QPixmap loadAvatar (const ToxPk &owner)
 Get a contact's avatar from cache. More...
 
QByteArray loadAvatarData (const ToxPk &owner)
 Get a contact's avatar from cache. More...
 
void setAvatar (QByteArray pic)
 Sets our own avatar. More...
 
void setFriendAvatar (const ToxPk &owner, QByteArray pic)
 Sets a friends avatar. More...
 
QByteArray getAvatarHash (const ToxPk &owner)
 Get the tox hash of a cached avatar. More...
 
void removeSelfAvatar ()
 Removes our own avatar. More...
 
void removeFriendAvatar (const ToxPk &owner)
 Removes friend avatar. More...
 
bool isHistoryEnabled ()
 Checks that the history is enabled in the settings, and loaded successfully for this profile. More...
 
HistorygetHistory ()
 Get chat history. More...
 
QStringList remove ()
 Removes the profile permanently. Updates the profiles vector. More...
 
bool rename (QString newName)
 Tries to rename the profile. More...
 

Static Public Member Functions

static ProfileloadProfile (const QString &name, const QString &password, Settings &settings, const QCommandLineParser *parser)
 Locks and loads an existing profile and creates the associate Core* instance. More...
 
static ProfilecreateProfile (const QString &name, const QString &password, Settings &settings, const QCommandLineParser *parser)
 Creates a new profile and the associated Core* instance. More...
 
static const QStringList getAllProfileNames ()
 Scan for profile, automatically importing them if needed. More...
 
static bool exists (QString name)
 
static bool isEncrypted (QString name)
 Checks if profile is encrypted. More...
 
static QString getDbPath (const QString &profileName)
 Retrieves the path to the database file for a given profile. More...
 

Private Slots

void loadDatabase (QString password)
 
void saveAvatar (const ToxPk &owner, const QByteArray &avatar)
 Save an avatar to cache. More...
 
void removeAvatar (const ToxPk &owner)
 Removes a cached avatar. More...
 
void onSaveToxSave ()
 Saves the profile's .tox save, encrypted if needed. More...
 
void onAvatarOfferReceived (uint32_t friendId, uint32_t fileId, const QByteArray &avatarHash, uint64_t filesize)
 

Private Member Functions

 Profile (const QString &name, std::unique_ptr< ToxEncrypt > passkey, Paths &paths, Settings &settings_)
 
QString avatarPath (const ToxPk &owner, bool forceUnencrypted=false)
 Gets the path of the avatar file cached by this profile and corresponding to this owner ID. More...
 
bool saveToxSave (QByteArray data)
 Write the .tox save, encrypted if needed. More...
 
void initCore (const QByteArray &toxsave, Settings &s, bool isNewProfile)
 

Static Private Member Functions

static QStringList getFilesByExt (QString extension)
 Lists all the files in the config dir with a given extension. More...
 

Private Attributes

std::unique_ptr< AvatarBroadcasteravatarBroadcaster
 
std::unique_ptr< Corecore
 
std::unique_ptr< CoreAVcoreAv
 
QString name
 
std::unique_ptr< ToxEncryptpasskey
 
std::shared_ptr< RawDatabasedatabase
 
std::shared_ptr< Historyhistory
 
bool isRemoved
 True if the profile has been removed by remove(). More...
 
bool encrypted = false
 
std::unique_ptr< BootstrapNodeUpdaterbootstrapNodes
 
Pathspaths
 
Settingssettings
 

Static Private Attributes

static QStringList profiles
 

Detailed Description

Handles all qTox internal paths.

Manages user profiles.

The qTox internal file layout starts at <BASE_PATH>. This directory is platform specific and depends on if qTox runs in portable mode.

Example file layout for non-portable mode:

<BASE_PATH>/themes/
/profiles/avatars/
/...

Example file layout for portable mode:

/qTox.bin
/themes/
/profiles/avatars/
/qtox.ini

All qTox or Tox specific directories should be looked up through this module.

Definition at line 42 of file profile.h.

Constructor & Destructor Documentation

◆ ~Profile()

Profile::~Profile ( )

Definition at line 376 of file profile.cpp.

Here is the call graph for this function:

◆ Profile()

Profile::Profile ( const QString &  name,
std::unique_ptr< ToxEncrypt passkey,
Paths paths,
Settings settings_ 
)
private

Definition at line 296 of file profile.cpp.

Here is the caller graph for this function:

Member Function Documentation

◆ avatarPath()

QString Profile::avatarPath ( const ToxPk owner,
bool  forceUnencrypted = false 
)
private

Gets the path of the avatar file cached by this profile and corresponding to this owner ID.

Parameters
ownerPath to avatar of friend with this PK will returned.
forceUnencryptedIf true, return the path to the plaintext file even if this is an encrypted profile.
Returns
Path to the avatar.

Definition at line 531 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ badProxy

void Profile::badProxy ( )
signal
Here is the caller graph for this function:

◆ coreChanged

void Profile::coreChanged ( Core core)
signal
Here is the caller graph for this function:

◆ createProfile()

Profile * Profile::createProfile ( const QString &  name,
const QString &  password,
Settings settings,
const QCommandLineParser *  parser 
)
static

Creates a new profile and the associated Core* instance.

Parameters
nameUsername.
passwordIf password is not empty, the profile will be encrypted.
Returns
Returns a nullptr on error. Profile pointer otherwise.
Note
If the profile is already in use return nullptr.

Definition at line 355 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exists()

bool Profile::exists ( QString  name)
static

Definition at line 804 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ failedToStart

void Profile::failedToStart ( )
signal
Here is the caller graph for this function:

◆ friendAvatarChanged

void Profile::friendAvatarChanged ( const ToxPk friendPk,
const QPixmap &  pixmap 
)
signal
Here is the caller graph for this function:

◆ friendAvatarRemoved

void Profile::friendAvatarRemoved ( const ToxPk friendPk)
signal
Here is the caller graph for this function:

◆ friendAvatarSet

void Profile::friendAvatarSet ( const ToxPk friendPk,
const QPixmap &  pixmap 
)
signal
Here is the caller graph for this function:

◆ getAllProfileNames()

const QStringList Profile::getAllProfileNames ( )
static

Scan for profile, automatically importing them if needed.

Warning
NOT thread-safe.

Definition at line 414 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAvatarHash()

QByteArray Profile::getAvatarHash ( const ToxPk owner)

Get the tox hash of a cached avatar.

Parameters
ownerFriend PK to get hash.
Returns
Avatar tox hash.

Definition at line 747 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCore()

Core & Profile::getCore ( ) const

Definition at line 428 of file profile.cpp.

Here is the caller graph for this function:

◆ getDbPath()

QString Profile::getDbPath ( const QString &  profileName)
static

Retrieves the path to the database file for a given profile.

Parameters
profileNameProfile name.
Returns
Path to database.

Definition at line 985 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFilesByExt()

QStringList Profile::getFilesByExt ( QString  extension)
staticprivate

Lists all the files in the config dir with a given extension.

Parameters
extensionRaw extension, e.g. "jpeg" not ".jpeg".
Returns
Vector of filenames.

Definition at line 395 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getHistory()

History * Profile::getHistory ( )

Get chat history.

Returns
May return a nullptr if the history failed to load.

Definition at line 785 of file profile.cpp.

Here is the caller graph for this function:

◆ getName()

QString Profile::getName ( ) const

Definition at line 435 of file profile.cpp.

Here is the caller graph for this function:

◆ getPasskey()

const ToxEncrypt * Profile::getPasskey ( ) const

Definition at line 922 of file profile.cpp.

Here is the caller graph for this function:

◆ initCore()

void Profile::initCore ( const QByteArray &  toxsave,
Settings s,
bool  isNewProfile 
)
private

Definition at line 235 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEncrypted() [1/2]

bool Profile::isEncrypted ( ) const

Checks, if profile has a password.

Returns
True if we have a password set (doesn't check the actual file on disk).

Definition at line 814 of file profile.cpp.

Here is the caller graph for this function:

◆ isEncrypted() [2/2]

bool Profile::isEncrypted ( QString  name)
static

Checks if profile is encrypted.

Note
Checks the actual file on disk.
Parameters
nameProfile name.
Returns
True if profile is encrypted, false otherwise.

Definition at line 825 of file profile.cpp.

Here is the call graph for this function:

◆ isHistoryEnabled()

bool Profile::isHistoryEnabled ( )

Checks that the history is enabled in the settings, and loaded successfully for this profile.

Returns
True if enabled, false otherwise.

Definition at line 776 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadAvatar() [1/2]

QPixmap Profile::loadAvatar ( )

Get our avatar from cache.

Returns
Avatar as QPixmap.

Definition at line 556 of file profile.cpp.

Here is the caller graph for this function:

◆ loadAvatar() [2/2]

QPixmap Profile::loadAvatar ( const ToxPk owner)

Get a contact's avatar from cache.

Parameters
ownerFriend PK to load avatar.
Returns
Avatar as QPixmap.

Definition at line 566 of file profile.cpp.

Here is the call graph for this function:

◆ loadAvatarData()

QByteArray Profile::loadAvatarData ( const ToxPk owner)

Get a contact's avatar from cache.

Parameters
ownerFriend PK to load avatar.
Returns
Avatar as QByteArray.

Definition at line 590 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadDatabase

void Profile::loadDatabase ( QString  password)
privateslot

Definition at line 616 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadProfile()

Profile * Profile::loadProfile ( const QString &  name,
const QString &  password,
Settings settings,
const QCommandLineParser *  parser 
)
static

Locks and loads an existing profile and creates the associate Core* instance.

Parameters
nameProfile name.
passwordProfile password.
Returns
Returns a nullptr on error. Profile pointer otherwise.
Note
If the profile is already in use return nullptr.

Definition at line 313 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onAvatarOfferReceived

void Profile::onAvatarOfferReceived ( uint32_t  friendId,
uint32_t  fileId,
const QByteArray &  avatarHash,
uint64_t  filesize 
)
privateslot

Definition at line 474 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onRequestSent

void Profile::onRequestSent ( const ToxPk friendPk,
const QString &  message 
)
slot

Adds history message about friendship request attempt if history is enabled.

Parameters
friendPkPk of a friend which request is destined to
messageFriendship request message

Definition at line 704 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onSaveToxSave

void Profile::onSaveToxSave ( )
privateslot

Saves the profile's .tox save, encrypted if needed.

Warning
Invalid on deleted profiles.

Definition at line 466 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove()

QStringList Profile::remove ( )

Removes the profile permanently. Updates the profiles vector.

Returns
Vector of filenames that could not be removed.
Warning
It is invalid to call loadToxSave or saveToxSave on a deleted profile.

Definition at line 847 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeAvatar

void Profile::removeAvatar ( const ToxPk owner)
privateslot

Removes a cached avatar.

Parameters
ownerFriend PK whose avater to delete.

Definition at line 794 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeFriendAvatar()

void Profile::removeFriendAvatar ( const ToxPk owner)

Removes friend avatar.

Definition at line 766 of file profile.cpp.

Here is the call graph for this function:

◆ removeSelfAvatar()

void Profile::removeSelfAvatar ( )

Removes our own avatar.

Definition at line 758 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rename()

bool Profile::rename ( QString  newName)

Tries to rename the profile.

Parameters
newNameNew name for the profile.
Returns
False on error, true otherwise.

Definition at line 896 of file profile.cpp.

Here is the call graph for this function:

◆ saveAvatar

void Profile::saveAvatar ( const ToxPk owner,
const QByteArray &  avatar 
)
privateslot

Save an avatar to cache.

Parameters
picPicture to save.
ownerPK of avatar owner.

Definition at line 722 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveToxSave()

bool Profile::saveToxSave ( QByteArray  data)
private

Write the .tox save, encrypted if needed.

Parameters
dataByte array of profile save.
Returns
true if successfully saved, false otherwise
Warning
Invalid on deleted profiles.

Definition at line 487 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ selfAvatarChanged

void Profile::selfAvatarChanged ( const QPixmap &  pixmap)
signal
Here is the caller graph for this function:

◆ setAvatar()

void Profile::setAvatar ( QByteArray  pic)

Sets our own avatar.

Parameters
picPicture to use as avatar, if empty an Identicon will be used depending on settings

Definition at line 648 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFriendAvatar()

void Profile::setFriendAvatar ( const ToxPk owner,
QByteArray  pic 
)

Sets a friends avatar.

Parameters
picPicture to use as avatar, if empty an Identicon will be used depending on settings
ownerpk of friend

Definition at line 679 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPassword()

QString Profile::setPassword ( const QString &  newPassword)

Changes the encryption password and re-saves everything with it.

Parameters
newPasswordPassword for encryption, if empty profile will be decrypted.
oldPasswordSupply previous password if already encrypted or empty QString if not yet encrypted.
Returns
Empty QString on success or error message on failure.

Definition at line 934 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startCore()

void Profile::startCore ( )

Starts the Core thread.

Definition at line 443 of file profile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ avatarBroadcaster

std::unique_ptr<AvatarBroadcaster> Profile::avatarBroadcaster
private

Definition at line 114 of file profile.h.

◆ bootstrapNodes

std::unique_ptr<BootstrapNodeUpdater> Profile::bootstrapNodes
private

Definition at line 124 of file profile.h.

◆ core

std::unique_ptr<Core> Profile::core
private

Definition at line 115 of file profile.h.

◆ coreAv

std::unique_ptr<CoreAV> Profile::coreAv
private

Definition at line 116 of file profile.h.

◆ database

std::shared_ptr<RawDatabase> Profile::database
private

Definition at line 119 of file profile.h.

◆ encrypted

bool Profile::encrypted = false
private

Definition at line 122 of file profile.h.

◆ history

std::shared_ptr<History> Profile::history
private

Definition at line 120 of file profile.h.

◆ isRemoved

bool Profile::isRemoved
private

True if the profile has been removed by remove().

Definition at line 121 of file profile.h.

◆ name

QString Profile::name
private

Definition at line 117 of file profile.h.

◆ passkey

std::unique_ptr<ToxEncrypt> Profile::passkey
private

Definition at line 118 of file profile.h.

◆ paths

Paths& Profile::paths
private

Definition at line 125 of file profile.h.

◆ profiles

QStringList Profile::profiles
staticprivate

Definition at line 123 of file profile.h.

◆ settings

Settings& Profile::settings
private

Definition at line 126 of file profile.h.


The documentation for this class was generated from the following files:
Profile::profiles
static QStringList profiles
Definition: profile.h:123