mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Basic infrastructure for profiles is in place, now I gotta hook up the UI
This commit is contained in:
parent
70321756c0
commit
e3da9badac
67
core.cpp
67
core.cpp
|
@ -30,6 +30,7 @@
|
|||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
const QString Core::CONFIG_FILE_NAME = "data";
|
||||
const QString Core::TOX_EXT = ".tox";
|
||||
QList<ToxFile> Core::fileSendQueue;
|
||||
QList<ToxFile> Core::fileRecvQueue;
|
||||
ToxCall Core::calls[TOXAV_MAX_CALLS];
|
||||
|
@ -108,6 +109,7 @@ void Core::start()
|
|||
return;
|
||||
}
|
||||
|
||||
// this will attempt to get the last profile from settings
|
||||
loadConfiguration();
|
||||
|
||||
tox_callback_friend_request(tox, onFriendRequest, this);
|
||||
|
@ -721,34 +723,55 @@ void Core::checkConnection()
|
|||
}
|
||||
}
|
||||
|
||||
void Core::loadConfiguration()
|
||||
QString sanitize(QString name)
|
||||
{
|
||||
QString path = Settings::getSettingsDirPath() + '/' + CONFIG_FILE_NAME;
|
||||
// do things
|
||||
return name;
|
||||
}
|
||||
|
||||
QFile configurationFile(path);
|
||||
void Core::loadConfiguration(QString path)
|
||||
{
|
||||
if (path == "")
|
||||
{
|
||||
// read from settings whose profile?
|
||||
path = Settings::getSettingsDirPath() + '/' + Settings::getInstance().getCurrentProfile() + TOX_EXT;
|
||||
QFile file(path);
|
||||
|
||||
// if the last profile doesn't exist, fall back to old "data"
|
||||
if (!file.exists())
|
||||
{
|
||||
path = Settings::getSettingsDirPath() + '/' + CONFIG_FILE_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
if (!configurationFile.exists()) {
|
||||
QFile conf(path);
|
||||
qDebug() << "Core::loadConfiguration: reading from " << path;
|
||||
|
||||
if (!conf.exists()) {
|
||||
qWarning() << "The Tox configuration file was not found";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!configurationFile.open(QIODevice::ReadOnly)) {
|
||||
if (!conf.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "File " << path << " cannot be opened";
|
||||
return;
|
||||
}
|
||||
|
||||
qint64 fileSize = configurationFile.size();
|
||||
qint64 fileSize = conf.size();
|
||||
if (fileSize > 0) {
|
||||
QByteArray data = configurationFile.readAll();
|
||||
QByteArray data = conf.readAll();
|
||||
tox_load(tox, reinterpret_cast<uint8_t *>(data.data()), data.size());
|
||||
}
|
||||
|
||||
configurationFile.close();
|
||||
conf.close();
|
||||
|
||||
// set GUI with user and statusmsg
|
||||
QString name = getUsername();
|
||||
if (name != "")
|
||||
{
|
||||
emit usernameSet(name);
|
||||
Settings::getInstance().setCurrentProfile(name);
|
||||
}
|
||||
|
||||
QString msg = getStatusMessage();
|
||||
if (msg != "")
|
||||
|
@ -757,7 +780,7 @@ void Core::loadConfiguration()
|
|||
loadFriends();
|
||||
}
|
||||
|
||||
void Core::saveConfiguration()
|
||||
void Core::saveConfiguration(QString path)
|
||||
{
|
||||
if (!tox)
|
||||
{
|
||||
|
@ -765,23 +788,28 @@ void Core::saveConfiguration()
|
|||
return;
|
||||
}
|
||||
|
||||
QString path = Settings::getSettingsDirPath();
|
||||
|
||||
QDir directory(path);
|
||||
|
||||
if (!directory.exists() && !directory.mkpath(directory.absolutePath())) {
|
||||
qCritical() << "Error while creating directory " << path;
|
||||
return;
|
||||
if (path == "")
|
||||
{
|
||||
QString dir = Settings::getSettingsDirPath();
|
||||
QDir directory(dir);
|
||||
if (!directory.exists() && !directory.mkpath(directory.absolutePath())) {
|
||||
qCritical() << "Error while creating directory " << dir;
|
||||
return;
|
||||
}
|
||||
|
||||
path = dir + Settings::getInstance().getCurrentProfile() + TOX_EXT;
|
||||
QFileInfo info(dir);
|
||||
if (!info.exists()) // fall back to old school 'data'
|
||||
path = dir + '/' + CONFIG_FILE_NAME;
|
||||
}
|
||||
|
||||
path += '/' + CONFIG_FILE_NAME;
|
||||
|
||||
QSaveFile configurationFile(path);
|
||||
if (!configurationFile.open(QIODevice::WriteOnly)) {
|
||||
qCritical() << "File " << path << " cannot be opened";
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "Core: writing tox_save";
|
||||
qDebug() << "Core: writing tox_save to " << path;
|
||||
uint32_t fileSize = tox_size(tox);
|
||||
if (fileSize > 0 && fileSize <= INT32_MAX) {
|
||||
uint8_t *data = new uint8_t[fileSize];
|
||||
|
@ -789,6 +817,7 @@ void Core::saveConfiguration()
|
|||
configurationFile.write(reinterpret_cast<char *>(data), fileSize);
|
||||
configurationFile.commit();
|
||||
delete[] data;
|
||||
//configurationFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
7
core.h
7
core.h
|
@ -114,6 +114,8 @@ class Core : public QObject
|
|||
public:
|
||||
explicit Core(Camera* cam, QThread* coreThread);
|
||||
~Core();
|
||||
|
||||
static const QString TOX_EXT;
|
||||
|
||||
int getGroupNumberPeers(int groupId) const;
|
||||
QString getGroupPeerName(int groupId, int peerId) const;
|
||||
|
@ -122,7 +124,9 @@ public:
|
|||
void quitGroupChat(int groupId) const;
|
||||
void dispatchVideoFrame(vpx_image img) const;
|
||||
|
||||
void saveConfiguration();
|
||||
void saveConfiguration(QString path = "");
|
||||
void loadConfiguration(QString path = "");
|
||||
QString sanitize(QString name);
|
||||
|
||||
QString getUsername();
|
||||
QString getStatusMessage();
|
||||
|
@ -273,7 +277,6 @@ private:
|
|||
void checkConnection();
|
||||
void onBootstrapTimer();
|
||||
|
||||
void loadConfiguration();
|
||||
void loadFriends();
|
||||
static void sendAllFileData(Core* core, ToxFile* file);
|
||||
|
||||
|
|
12
settings.cpp
12
settings.cpp
|
@ -81,6 +81,7 @@ void Settings::load()
|
|||
enableIPv6 = s.value("enableIPv6", true).toBool();
|
||||
useTranslations = s.value("useTranslations", true).toBool();
|
||||
makeToxPortable = s.value("makeToxPortable", false).toBool();
|
||||
currentProfile = s.value("currentProfile", ".data").toString();
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("Widgets");
|
||||
|
@ -137,6 +138,7 @@ void Settings::save(QString path)
|
|||
s.setValue("enableIPv6", enableIPv6);
|
||||
s.setValue("useTranslations",useTranslations);
|
||||
s.setValue("makeToxPortable",makeToxPortable);
|
||||
s.setValue("currentProfile", currentProfile);
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("Widgets");
|
||||
|
@ -208,6 +210,16 @@ void Settings::setMakeToxPortable(bool newValue)
|
|||
save(FILENAME); // Commit to the portable file that we don't want to use it
|
||||
}
|
||||
|
||||
QString Settings::getCurrentProfile() const
|
||||
{
|
||||
return currentProfile;
|
||||
}
|
||||
|
||||
void Settings::setCurrentProfile(QString profile)
|
||||
{
|
||||
currentProfile = profile;
|
||||
}
|
||||
|
||||
bool Settings::getUseTranslations() const
|
||||
{
|
||||
return useTranslations;
|
||||
|
|
|
@ -49,6 +49,9 @@ public:
|
|||
bool getMakeToxPortable() const;
|
||||
void setMakeToxPortable(bool newValue);
|
||||
|
||||
QString getCurrentProfile() const;
|
||||
void setCurrentProfile(QString profile);
|
||||
|
||||
bool getUseTranslations() const;
|
||||
void setUseTranslations(bool newValue);
|
||||
|
||||
|
@ -134,6 +137,7 @@ private:
|
|||
bool enableIPv6;
|
||||
bool useTranslations;
|
||||
static bool makeToxPortable;
|
||||
QString currentProfile;
|
||||
|
||||
bool enableLogging;
|
||||
bool encryptLogs;
|
||||
|
|
|
@ -25,14 +25,16 @@ SettingsForm::SettingsForm()
|
|||
: QObject()
|
||||
{
|
||||
main = new QWidget(), head = new QWidget();
|
||||
hboxcont1 = new QWidget(), hboxcont2 = new QWidget();
|
||||
QFont bold, small;
|
||||
bold.setBold(true);
|
||||
small.setPixelSize(13);
|
||||
headLabel.setText(tr("User Settings","\"Headline\" of the window"));
|
||||
headLabel.setFont(bold);
|
||||
|
||||
nameLabel.setText(tr("Name","Username/nick"));
|
||||
statusTextLabel.setText(tr("Status","Status message"));
|
||||
//nameLabel.setText(tr("Name","Username/nick"));
|
||||
//statusTextLabel.setText(tr("Status","Status message"));
|
||||
|
||||
idLabel.setText("Tox ID " + tr("(click here to copy)", "Click on this text to copy TID to clipboard"));
|
||||
id.setFont(small);
|
||||
id.setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||
|
@ -40,6 +42,15 @@ SettingsForm::SettingsForm()
|
|||
id.setFrameStyle(QFrame::NoFrame);
|
||||
id.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
id.setFixedHeight(id.document()->size().height());
|
||||
|
||||
profilesLabel.setText(tr("Available profiles:", "Labels the profile selection box"));
|
||||
populateProfiles();
|
||||
loadConf.setText(tr("Load profile", "button to load selected profile"));
|
||||
exportConf.setText(tr("Export profile", "button to save selected profile elsewhere"));
|
||||
delConf.setText(tr("Delete profile", "button to delete selected profile from disk"));
|
||||
delConf.setToolTip(tr("This is useful to remain safe on public computers", "describes the delete profile button"));
|
||||
//delConf.setWhatsThis(tr("This is useful to remain safe on public computers", "describes the delete profile button"));
|
||||
importConf.setText(tr("Import profile", "button to locate a profile"));
|
||||
|
||||
videoTest.setText(tr("Test video","Text on a button to test the video/webcam"));
|
||||
enableIPv6.setText(tr("Enable IPv6 (recommended)","Text on a checkbox to enable IPv6"));
|
||||
|
@ -50,12 +61,21 @@ SettingsForm::SettingsForm()
|
|||
makeToxPortable.setChecked(Settings::getInstance().getMakeToxPortable());
|
||||
|
||||
main->setLayout(&layout);
|
||||
layout.addWidget(&nameLabel);
|
||||
layout.addWidget(&name);
|
||||
layout.addWidget(&statusTextLabel);
|
||||
layout.addWidget(&statusText);
|
||||
//layout.addWidget(&nameLabel);
|
||||
//layout.addWidget(&name);
|
||||
//layout.addWidget(&statusTextLabel);
|
||||
//layout.addWidget(&statusText);
|
||||
layout.addWidget(&idLabel);
|
||||
layout.addWidget(&id);
|
||||
cbox.addWidget(&profilesLabel);
|
||||
cbox.addWidget(&profiles);
|
||||
hboxcont1->setLayout(&cbox);
|
||||
layout.addWidget(hboxcont1);
|
||||
buttons.addWidget(&loadConf);
|
||||
buttons.addWidget(&exportConf);
|
||||
buttons.addWidget(&delConf);
|
||||
hboxcont2->setLayout(&buttons);
|
||||
layout.addWidget(hboxcont2);
|
||||
layout.addWidget(&videoTest);
|
||||
layout.addWidget(&enableIPv6);
|
||||
layout.addWidget(&useTranslations);
|
||||
|
@ -76,6 +96,16 @@ SettingsForm::~SettingsForm()
|
|||
{
|
||||
}
|
||||
|
||||
void SettingsForm::populateProfiles()
|
||||
{
|
||||
QDir dir(Settings::getSettingsDirPath());
|
||||
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
|
||||
dir.setNameFilters(QStringList("*.tox"));
|
||||
for(QFileInfo file : dir.entryInfoList()) {
|
||||
profiles.addItem(file.completeBaseName());
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsForm::setFriendAddress(const QString& friendAddress)
|
||||
{
|
||||
id.setText(friendAddress);
|
||||
|
@ -83,8 +113,8 @@ void SettingsForm::setFriendAddress(const QString& friendAddress)
|
|||
|
||||
void SettingsForm::show(Ui::Widget &ui)
|
||||
{
|
||||
name.setText(ui.nameLabel->text());
|
||||
statusText.setText(ui.statusLabel->text());
|
||||
//name.setText(ui.nameLabel->text());
|
||||
//statusText.setText(ui.statusLabel->text());
|
||||
ui.mainContent->layout()->addWidget(main);
|
||||
ui.mainHead->layout()->addWidget(head);
|
||||
main->show();
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
#include <QCheckBox>
|
||||
#include <QPushButton>
|
||||
#include <QTextEdit>
|
||||
#include <QComboBox>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include "widget/tool/clickablelabel.h"
|
||||
#include "ui_widget.h"
|
||||
#include "widget/selfcamview.h"
|
||||
|
@ -50,16 +53,20 @@ private slots:
|
|||
void copyIdClicked();
|
||||
|
||||
private:
|
||||
QLabel headLabel, nameLabel, statusTextLabel;
|
||||
QLabel headLabel;/*, nameLabel, statusTextLabel;*/
|
||||
QTextEdit id;
|
||||
ClickableLabel idLabel;
|
||||
QPushButton videoTest;
|
||||
QLabel profilesLabel;
|
||||
QComboBox profiles;
|
||||
QPushButton loadConf, exportConf, delConf, importConf, videoTest;
|
||||
QHBoxLayout cbox, buttons;
|
||||
QCheckBox enableIPv6, useTranslations, makeToxPortable;
|
||||
QVBoxLayout layout, headLayout;
|
||||
QWidget *main, *head;
|
||||
QWidget *main, *head, *hboxcont1, *hboxcont2;
|
||||
void populateProfiles();
|
||||
|
||||
public:
|
||||
QLineEdit name, statusText;
|
||||
//QLineEdit name, statusText;
|
||||
};
|
||||
|
||||
#endif // SETTINGSFORM_H
|
||||
|
|
|
@ -249,8 +249,8 @@ Widget::Widget(QWidget *parent) :
|
|||
connect(setStatusOnline, SIGNAL(triggered()), this, SLOT(setStatusOnline()));
|
||||
connect(setStatusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
|
||||
connect(setStatusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
|
||||
connect(&settingsForm.name, SIGNAL(editingFinished()), this, SLOT(onUsernameChanged()));
|
||||
connect(&settingsForm.statusText, SIGNAL(editingFinished()), this, SLOT(onStatusMessageChanged()));
|
||||
//connect(&settingsForm.name, SIGNAL(editingFinished()), this, SLOT(onUsernameChanged()));
|
||||
//connect(&settingsForm.statusText, SIGNAL(editingFinished()), this, SLOT(onStatusMessageChanged()));
|
||||
connect(&friendForm, SIGNAL(friendRequested(QString,QString)), this, SIGNAL(friendRequested(QString,QString)));
|
||||
|
||||
coreThread->start();
|
||||
|
@ -418,44 +418,56 @@ void Widget::hideMainForms()
|
|||
}
|
||||
}
|
||||
|
||||
void Widget::onUsernameChanged()
|
||||
/*void Widget::onUsernameChanged()
|
||||
{
|
||||
const QString newUsername = settingsForm.name.text();
|
||||
//const QString newUsername = settingsForm.name.text();
|
||||
ui->nameLabel->setText(newUsername);
|
||||
ui->nameLabel->setToolTip(newUsername); // for overlength names
|
||||
settingsForm.name.setText(newUsername);
|
||||
core->setUsername(newUsername);
|
||||
}
|
||||
}*/
|
||||
|
||||
void Widget::onUsernameChanged(const QString& newUsername, const QString& oldUsername)
|
||||
{
|
||||
ui->nameLabel->setText(oldUsername); // restore old username until Core tells us to set it
|
||||
ui->nameLabel->setToolTip(oldUsername); // for overlength names
|
||||
settingsForm.name.setText(oldUsername);
|
||||
//settingsForm.name.setText(oldUsername);
|
||||
core->setUsername(newUsername);
|
||||
|
||||
// move the data file with it
|
||||
QString dir = Settings::getSettingsDirPath();
|
||||
QFile::rename(dir + '/' + oldUsername + core->TOX_EXT, dir + '/' + newUsername + core->TOX_EXT);
|
||||
// and update current profile
|
||||
Settings::getInstance().setCurrentProfile(newUsername);
|
||||
}
|
||||
|
||||
// ugh... Widget::onUsernameChanged() calls Core::setUsername,
|
||||
// which emits Core::usernameSet, which is connect to this function:
|
||||
void Widget::setUsername(const QString& username)
|
||||
{
|
||||
ui->nameLabel->setText(username);
|
||||
ui->nameLabel->setToolTip(username); // for overlength names
|
||||
settingsForm.name.setText(username);
|
||||
//settingsForm.name.setText(username);
|
||||
}
|
||||
// the end result is that the ui gets updated twice -- and actually,
|
||||
// I believe this function is dead code, since the only way to change
|
||||
// username now is via the ui (since I killed the settings version)
|
||||
// the chain of calls before was surely much messier with two ways
|
||||
// to modify the username...
|
||||
|
||||
void Widget::onStatusMessageChanged()
|
||||
/*void Widget::onStatusMessageChanged()
|
||||
{
|
||||
const QString newStatusMessage = settingsForm.statusText.text();
|
||||
ui->statusLabel->setText(newStatusMessage);
|
||||
ui->statusLabel->setToolTip(newStatusMessage); // for overlength messsages
|
||||
settingsForm.statusText.setText(newStatusMessage);
|
||||
core->setStatusMessage(newStatusMessage);
|
||||
}
|
||||
}*/
|
||||
|
||||
void Widget::onStatusMessageChanged(const QString& newStatusMessage, const QString& oldStatusMessage)
|
||||
{
|
||||
ui->statusLabel->setText(oldStatusMessage); // restore old status message until Core tells us to set it
|
||||
ui->statusLabel->setToolTip(oldStatusMessage); // for overlength messsages
|
||||
settingsForm.statusText.setText(oldStatusMessage);
|
||||
//settingsForm.statusText.setText(oldStatusMessage);
|
||||
core->setStatusMessage(newStatusMessage);
|
||||
}
|
||||
|
||||
|
@ -463,7 +475,7 @@ void Widget::setStatusMessage(const QString &statusMessage)
|
|||
{
|
||||
ui->statusLabel->setText(statusMessage);
|
||||
ui->statusLabel->setToolTip(statusMessage); // for overlength messsages
|
||||
settingsForm.statusText.setText(statusMessage);
|
||||
//settingsForm.statusText.setText(statusMessage);
|
||||
}
|
||||
|
||||
void Widget::addFriend(int friendId, const QString &userId)
|
||||
|
|
|
@ -86,8 +86,8 @@ private slots:
|
|||
void onFailedToStartCore();
|
||||
void onUsernameChanged(const QString& newUsername, const QString& oldUsername);
|
||||
void onStatusMessageChanged(const QString& newStatusMessage, const QString& oldStatusMessage);
|
||||
void onUsernameChanged();
|
||||
void onStatusMessageChanged();
|
||||
//void onUsernameChanged();
|
||||
//void onStatusMessageChanged();
|
||||
void setUsername(const QString& username);
|
||||
void setStatusMessage(const QString &statusMessage);
|
||||
void addFriend(int friendId, const QString& userId);
|
||||
|
|
Loading…
Reference in New Issue
Block a user