mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Scan profiles for login screen
This commit is contained in:
parent
68f6a5d032
commit
7d6167d90c
6
qtox.pro
6
qtox.pro
|
@ -470,7 +470,8 @@ SOURCES += \
|
|||
src/video/cameradevice.cpp \
|
||||
src/video/camerasource.cpp \
|
||||
src/video/corevideosource.cpp \
|
||||
src/core/toxid.cpp
|
||||
src/core/toxid.cpp \
|
||||
src/profile.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/audio.h \
|
||||
|
@ -503,4 +504,5 @@ HEADERS += \
|
|||
src/video/camerasource.h \
|
||||
src/video/corevideosource.h \
|
||||
src/video/videomode.h \
|
||||
src/core/toxid.h
|
||||
src/core/toxid.h \
|
||||
src/profile.h
|
||||
|
|
|
@ -1246,7 +1246,6 @@ bool Settings::getCompactLayout() const
|
|||
void Settings::setCompactLayout(bool value)
|
||||
{
|
||||
compactLayout = value;
|
||||
emit compactLayoutChanged();
|
||||
}
|
||||
|
||||
bool Settings::getGroupchatPosition() const
|
||||
|
@ -1268,3 +1267,24 @@ void Settings::setThemeColor(const int &value)
|
|||
{
|
||||
themeColor = value;
|
||||
}
|
||||
|
||||
void Settings::createPersonal(QString basename)
|
||||
{
|
||||
QString path = getSettingsDirPath() + QDir::separator() + basename + ".ini";
|
||||
qDebug() << "Creating new profile settings in " << path;
|
||||
|
||||
QSettings ps(path, QSettings::IniFormat);
|
||||
ps.beginGroup("Friends");
|
||||
ps.beginWriteArray("Friend", 0);
|
||||
ps.endArray();
|
||||
ps.endGroup();
|
||||
|
||||
ps.beginGroup("Privacy");
|
||||
ps.endGroup();
|
||||
}
|
||||
|
||||
bool Settings::profileExists(QString basename)
|
||||
{
|
||||
QString path = getSettingsDirPath() + QDir::separator() + basename;
|
||||
return QFile::exists(path+".tox") && QFile::exists(path+".ini");
|
||||
}
|
||||
|
|
|
@ -30,12 +30,15 @@ class Settings : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
~Settings() = default;
|
||||
static Settings& getInstance();
|
||||
void switchProfile(const QString& profile);
|
||||
QString detectProfile();
|
||||
QList<QString> searchProfiles();
|
||||
QString askProfiles();
|
||||
~Settings() = default;
|
||||
|
||||
void createPersonal(QString basename); ///< Write a default personnal settings file for a profile
|
||||
bool profileExists(QString basename); ///< Return true if the given profile (tox AND ini) exists
|
||||
|
||||
void executeSettingsDialog(QWidget* parent);
|
||||
|
||||
|
@ -365,12 +368,9 @@ private:
|
|||
int themeColor;
|
||||
|
||||
signals:
|
||||
//void dataChanged();
|
||||
void dhtServerListChanged();
|
||||
void logStorageOptsChanged();
|
||||
void smileyPackChanged();
|
||||
void emojiFontChanged();
|
||||
void compactLayoutChanged();
|
||||
};
|
||||
|
||||
#endif // SETTINGS_HPP
|
||||
|
|
54
src/profile.cpp
Normal file
54
src/profile.cpp
Normal file
|
@ -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;
|
||||
}
|
31
src/profile.h
Normal file
31
src/profile.h
Normal file
|
@ -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
|
|
@ -1,5 +1,6 @@
|
|||
#include "loginscreen.h"
|
||||
#include "ui_loginscreen.h"
|
||||
#include "src/profile.h"
|
||||
|
||||
LoginScreen::LoginScreen(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
|
@ -11,6 +12,15 @@ LoginScreen::LoginScreen(QWidget *parent) :
|
|||
connect(ui->loginPgbtn, &QPushButton::clicked, this, &LoginScreen::onLoginPageClicked);
|
||||
connect(ui->createAccountButton, &QPushButton::clicked, this, &LoginScreen::onCreateNewProfile);
|
||||
connect(ui->loginButton, &QPushButton::clicked, this, &LoginScreen::onLogin);
|
||||
|
||||
QVector<QString> profiles = Profile::getProfiles();
|
||||
for (QString profile : profiles)
|
||||
ui->loginUsernames->addItem(profile);
|
||||
|
||||
if (profiles.isEmpty())
|
||||
ui->stackedWidget->setCurrentIndex(0);
|
||||
else
|
||||
ui->stackedWidget->setCurrentIndex(1);
|
||||
}
|
||||
|
||||
LoginScreen::~LoginScreen()
|
||||
|
|
|
@ -357,7 +357,7 @@ margin-bottom:45px;</string>
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit">
|
||||
<widget class="QLineEdit" name="newUsername">
|
||||
<property name="maxLength">
|
||||
<number>64</number>
|
||||
</property>
|
||||
|
@ -374,7 +374,7 @@ margin-bottom:45px;</string>
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_2">
|
||||
<widget class="QLineEdit" name="newPass">
|
||||
<property name="maxLength">
|
||||
<number>64</number>
|
||||
</property>
|
||||
|
@ -394,7 +394,7 @@ margin-bottom:45px;</string>
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_5"/>
|
||||
<widget class="QLineEdit" name="newPassConfirm"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
|
@ -706,7 +706,7 @@ margin-bottom:5px;</string>
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox"/>
|
||||
<widget class="QComboBox" name="loginUsernames"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
|
@ -719,7 +719,7 @@ margin-bottom:5px;</string>
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_4">
|
||||
<widget class="QLineEdit" name="loginPassword">
|
||||
<property name="maxLength">
|
||||
<number>64</number>
|
||||
</property>
|
||||
|
|
Loading…
Reference in New Issue
Block a user