1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Remove username and status message from settings, instead use Core

This commit is contained in:
Bill Winslow 2014-07-11 16:38:39 -04:00
parent 34e596641a
commit e0b6fd1e13
5 changed files with 38 additions and 38 deletions

View File

@ -563,6 +563,17 @@ void Core::removeGroup(int groupId)
tox_del_groupchat(tox, groupId);
}
QString Core::getUsername()
{
int size = tox_get_self_name_size(tox);
uint8_t* name = new uint8_t[size];
if (tox_get_self_name(tox, name) == size)
return QString(CString::toString(name, size));
else
return QString();
delete[] name;
}
void Core::setUsername(const QString& username)
{
CString cUsername(username);
@ -575,6 +586,17 @@ void Core::setUsername(const QString& username)
}
}
QString Core::getStatusMessage()
{
int size = tox_get_self_status_message_size(tox);
uint8_t* name = new uint8_t[size];
if (tox_get_self_status_message(tox, name, size) == size)
return QString(CString::toString(name, size));
else
return QString();
delete[] name;
}
void Core::setStatusMessage(const QString& message)
{
CString cMessage(message);
@ -697,6 +719,15 @@ void Core::loadConfiguration()
configurationFile.close();
// set GUI with user and statusmsg
QString name = getUsername();
if (name != "")
emit usernameSet(name);
QString msg = getStatusMessage();
if (msg != "")
emit statusMessageSet(msg);
loadFriends();
}

3
core.h
View File

@ -120,6 +120,9 @@ public:
void dispatchVideoFrame(vpx_image img) const;
void saveConfiguration();
QString getUsername();
QString getStatusMessage();
public slots:
void start();

View File

@ -73,8 +73,6 @@ void Settings::load()
s.endGroup();
s.beginGroup("General");
username = s.value("username", "My name").toString();
statusMessage = s.value("statusMessage", "My status").toString();
enableIPv6 = s.value("enableIPv6", true).toBool();
useTranslations = s.value("useTranslations", true).toBool();
s.endGroup();
@ -126,8 +124,6 @@ void Settings::save()
s.endGroup();
s.beginGroup("General");
s.setValue("username", username);
s.setValue("statusMessage", statusMessage);
s.setValue("enableIPv6", enableIPv6);
s.setValue("useTranslations",useTranslations);
s.endGroup();
@ -177,26 +173,6 @@ void Settings::setDhtServerList(const QList<DhtServer>& newDhtServerList)
emit dhtServerListChanged();
}
QString Settings::getUsername() const
{
return username;
}
void Settings::setUsername(const QString& newUsername)
{
username = newUsername;
}
QString Settings::getStatusMessage() const
{
return statusMessage;
}
void Settings::setStatusMessage(const QString& newMessage)
{
statusMessage = newMessage;
}
bool Settings::getEnableIPv6() const
{
return enableIPv6;

View File

@ -43,12 +43,6 @@ public:
const QList<DhtServer>& getDhtServerList() const;
void setDhtServerList(const QList<DhtServer>& newDhtServerList);
QString getUsername() const;
void setUsername(const QString& newUsername);
QString getStatusMessage() const;
void setStatusMessage(const QString& newMessage);
bool getEnableIPv6() const;
void setEnableIPv6(bool newValue);
@ -133,9 +127,6 @@ private:
int dhtServerId;
bool dontShowDhtDialog;
QString username;
QString statusMessage;
bool enableIPv6;
bool useTranslations;

View File

@ -152,9 +152,10 @@ Widget::Widget(QWidget *parent) :
friendListWidget->setLayoutDirection(Qt::LeftToRight);
ui->friendList->setWidget(friendListWidget);
ui->nameLabel->setText(Settings::getInstance().getUsername());
// delay setting username and message until Core inits
//ui->nameLabel->setText(core->getUsername());
ui->nameLabel->label->setStyleSheet("QLabel { color : white; font-size: 11pt; font-weight:bold;}");
ui->statusLabel->setText(Settings::getInstance().getStatusMessage());
//ui->statusLabel->setText(core->getStatusMessage());
ui->statusLabel->label->setStyleSheet("QLabel { color : white; font-size: 8pt;}");
ui->friendList->widget()->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
@ -434,7 +435,6 @@ void Widget::setUsername(const QString& username)
{
ui->nameLabel->setText(username);
settingsForm.name.setText(username);
Settings::getInstance().setUsername(username);
}
void Widget::onStatusMessageChanged()
@ -456,7 +456,6 @@ void Widget::setStatusMessage(const QString &statusMessage)
{
ui->statusLabel->setText(statusMessage);
settingsForm.statusText.setText(statusMessage);
Settings::getInstance().setStatusMessage(statusMessage);
}
void Widget::addFriend(int friendId, const QString &userId)
@ -668,7 +667,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int friendgroupnumber, cons
if ((isGroupWidgetActive != 1 || (g->groupId != activeGroupWidget->groupId)) || isWindowMinimized)
{
if (message.contains(Settings::getInstance().getUsername(), Qt::CaseInsensitive))
if (message.contains(core->getUsername(), Qt::CaseInsensitive))
{
newMessageAlert();
g->hasNewMessages = 1;