mirror of https://github.com/qTox/qTox.git
7 changed files with 129 additions and 12 deletions
@ -0,0 +1,54 @@
@@ -0,0 +1,54 @@
|
||||
#include "profile.h" |
||||
#include "src/misc/settings.h" |
||||
#include <cassert> |
||||
#include <QDir> |
||||
#include <QFileInfo> |
||||
|
||||
QVector<QString> Profile::profiles; |
||||
|
||||
Profile::Profile() |
||||
{ |
||||
|
||||
} |
||||
|
||||
Profile::~Profile() |
||||
{ |
||||
|
||||
} |
||||
|
||||
QVector<QString> Profile::getFilesByExt(QString extension) |
||||
{ |
||||
QDir dir(Settings::getInstance().getSettingsDirPath()); |
||||
QVector<QString> out; |
||||
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot); |
||||
dir.setNameFilters(QStringList("*."+extension)); |
||||
QFileInfoList list = dir.entryInfoList(); |
||||
out.reserve(list.size()); |
||||
for (QFileInfo file : list) |
||||
out += file.completeBaseName(); |
||||
return out; |
||||
} |
||||
|
||||
void Profile::scanProfiles() |
||||
{ |
||||
profiles.clear(); |
||||
QVector<QString> toxfiles = getFilesByExt("tox"), inifiles = getFilesByExt("ini"); |
||||
for (QString toxfile : toxfiles) |
||||
{ |
||||
if (!inifiles.contains(toxfile)) |
||||
importProfile(toxfile); |
||||
profiles.append(toxfile); |
||||
} |
||||
} |
||||
|
||||
void Profile::importProfile(QString name) |
||||
{ |
||||
Settings& s = Settings::getInstance(); |
||||
assert(!s.profileExists(name)); |
||||
s.createPersonal(name); |
||||
} |
||||
|
||||
QVector<QString> Profile::getProfiles() |
||||
{ |
||||
return profiles; |
||||
} |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
#ifndef PROFILE_H |
||||
#define PROFILE_H |
||||
|
||||
#include <QVector> |
||||
#include <QString> |
||||
|
||||
/// Manages user profiles
|
||||
class Profile |
||||
{ |
||||
public: |
||||
Profile(); |
||||
~Profile(); |
||||
|
||||
/// Scan for profile, automatically importing them if needed
|
||||
/// NOT thread-safe
|
||||
static void scanProfiles(); |
||||
static QVector<QString> getProfiles(); |
||||
|
||||
private: |
||||
/// 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: |
||||
static QVector<QString> profiles; |
||||
}; |
||||
|
||||
#endif // PROFILE_H
|
Loading…
Reference in new issue