mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
(Re)implement profiles UI, using some of the old code.
Avatars aren't handled on switching, and also something about friends disappearing...
This commit is contained in:
parent
eb687b2bfe
commit
0050589cde
10
core.cpp
10
core.cpp
|
@ -633,8 +633,8 @@ void Core::onAvatarInfoCallback(Tox*, int32_t friendnumber, uint8_t format,
|
|||
{
|
||||
qDebug() << "Core: Got null avatar info from" << core->getFriendUsername(friendnumber);
|
||||
emit core->friendAvatarRemoved(friendnumber);
|
||||
QFile::remove(QDir(Settings::getInstance().getSettingsDirPath()).filePath("avatars/"+core->getFriendAddress(friendnumber).left(64)+".png"));
|
||||
QFile::remove(QDir(Settings::getInstance().getSettingsDirPath()).filePath("avatars/"+core->getFriendAddress(friendnumber).left(64)+".hash"));
|
||||
QFile::remove(QDir(Settings::getSettingsDirPath()).filePath("avatars/"+core->getFriendAddress(friendnumber).left(64)+".png"));
|
||||
QFile::remove(QDir(Settings::getSettingsDirPath()).filePath("avatars/"+core->getFriendAddress(friendnumber).left(64)+".hash"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1183,13 +1183,14 @@ void Core::switchConfiguration(QString profile)
|
|||
|
||||
toxTimer->stop();
|
||||
|
||||
Widget::getInstance()->clearContactsList(); // we need this to block, so no signals for us
|
||||
|
||||
if (tox) {
|
||||
toxav_kill(toxav);
|
||||
toxav = nullptr;
|
||||
tox_kill(tox);
|
||||
tox = nullptr;
|
||||
}
|
||||
emit clearFriends();
|
||||
|
||||
make_tox();
|
||||
|
||||
|
@ -1210,6 +1211,7 @@ void Core::switchConfiguration(QString profile)
|
|||
void Core::loadFriends()
|
||||
{
|
||||
const uint32_t friendCount = tox_count_friendlist(tox);
|
||||
qDebug() << "Core: loading" << friendCount << "friends. profile:" << Settings::getInstance().getCurrentProfile();
|
||||
if (friendCount > 0) {
|
||||
// assuming there are not that many friends to fill up the whole stack
|
||||
int32_t *ids = new int32_t[friendCount];
|
||||
|
@ -1218,7 +1220,7 @@ void Core::loadFriends()
|
|||
for (int32_t i = 0; i < static_cast<int32_t>(friendCount); ++i) {
|
||||
if (tox_get_client_id(tox, ids[i], clientId) == 0) {
|
||||
emit friendAdded(ids[i], CUserId::toString(clientId));
|
||||
|
||||
qDebug() << "Core: just added friend" << CUserId::toString(clientId);
|
||||
const int nameSize = tox_get_name_size(tox, ids[i]);
|
||||
if (nameSize > 0) {
|
||||
uint8_t *name = new uint8_t[nameSize];
|
||||
|
|
3
core.h
3
core.h
|
@ -40,6 +40,7 @@ public:
|
|||
|
||||
static const QString TOX_EXT;
|
||||
static const QString CONFIG_FILE_NAME;
|
||||
static QString sanitize(QString name);
|
||||
|
||||
int getGroupNumberPeers(int groupId) const;
|
||||
QString getGroupPeerName(int groupId, int peerId) const;
|
||||
|
@ -109,7 +110,6 @@ signals:
|
|||
void friendMessageReceived(int friendId, const QString& message, bool isAction);
|
||||
|
||||
void friendAdded(int friendId, const QString& userId);
|
||||
void clearFriends();
|
||||
|
||||
void friendStatusChanged(int friendId, Status status);
|
||||
void friendStatusMessageChanged(int friendId, const QString& message);
|
||||
|
@ -218,7 +218,6 @@ private:
|
|||
bool checkConnection();
|
||||
|
||||
bool loadConfiguration(QString path); // Returns false for a critical error, true otherwise
|
||||
static QString sanitize(QString name);
|
||||
void make_tox();
|
||||
void loadFriends();
|
||||
|
||||
|
|
|
@ -18,12 +18,17 @@
|
|||
#include "ui_identitysettings.h"
|
||||
#include "identityform.h"
|
||||
#include "widget/form/settingswidget.h"
|
||||
#include "misc/settings.h"
|
||||
#include "widget/croppinglabel.h"
|
||||
#include "widget/widget.h"
|
||||
#include "core.h"
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QInputDialog>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
IdentityForm::IdentityForm() :
|
||||
GenericForm(tr("Your identity"), QPixmap(":/img/settings/identity.png"))
|
||||
|
@ -50,6 +55,11 @@ IdentityForm::IdentityForm() :
|
|||
connect(toxId, SIGNAL(clicked()), this, SLOT(copyIdClicked()));
|
||||
connect(bodyUI->userName, SIGNAL(editingFinished()), this, SLOT(onUserNameEdited()));
|
||||
connect(bodyUI->statusMessage, SIGNAL(editingFinished()), this, SLOT(onStatusMessageEdited()));
|
||||
connect(bodyUI->loadButton, &QPushButton::clicked, this, &IdentityForm::onLoadClicked);
|
||||
connect(bodyUI->renameButton, &QPushButton::clicked, this, &IdentityForm::onRenameClicked);
|
||||
connect(bodyUI->exportButton, &QPushButton::clicked, this, &IdentityForm::onExportClicked);
|
||||
connect(bodyUI->deleteButton, &QPushButton::clicked, this, &IdentityForm::onDeleteClicked);
|
||||
connect(bodyUI->importButton, &QPushButton::clicked, this, &IdentityForm::onImportClicked);
|
||||
}
|
||||
|
||||
IdentityForm::~IdentityForm()
|
||||
|
@ -77,6 +87,12 @@ void IdentityForm::onStatusMessageEdited()
|
|||
void IdentityForm::updateContent()
|
||||
{
|
||||
toxId->setText(Core::getInstance()->getSelfId().toString());
|
||||
bodyUI->profiles->clear();
|
||||
for (QString profile : Widget::searchProfiles())
|
||||
bodyUI->profiles->addItem(profile);
|
||||
QString current = Settings::getInstance().getCurrentProfile();
|
||||
if (current != "")
|
||||
bodyUI->profiles->setCurrentText(current);
|
||||
}
|
||||
|
||||
void IdentityForm::setUserName(const QString &name)
|
||||
|
@ -88,3 +104,61 @@ void IdentityForm::setStatusMessage(const QString &msg)
|
|||
{
|
||||
bodyUI->statusMessage->setText(msg);
|
||||
}
|
||||
|
||||
void IdentityForm::onLoadClicked()
|
||||
{
|
||||
Core::getInstance()->switchConfiguration(bodyUI->profiles->currentText());
|
||||
}
|
||||
|
||||
void IdentityForm::onRenameClicked()
|
||||
{
|
||||
QString cur = bodyUI->profiles->currentText();
|
||||
QString title = tr("Rename \"%1\"", "renaming a profile").arg(cur);
|
||||
QString name = QInputDialog::getText(this, title, title+":");
|
||||
if (name != "")
|
||||
{
|
||||
name = Core::sanitize(name);
|
||||
QDir dir(Settings::getSettingsDirPath());
|
||||
QFile::copy(dir.filePath(cur+Core::TOX_EXT), dir.filePath(name+Core::TOX_EXT));
|
||||
bodyUI->profiles->setItemText(bodyUI->profiles->currentIndex(), name);
|
||||
}
|
||||
}
|
||||
|
||||
void IdentityForm::onExportClicked()
|
||||
{
|
||||
QString current = bodyUI->profiles->currentText() + Core::TOX_EXT;
|
||||
QString path = QFileDialog::getSaveFileName(this, tr("Export profile", "save dialog title"),
|
||||
QDir::home().filePath(current),
|
||||
tr("Tox save file (*.tox)", "save dialog filter"));
|
||||
QFile::copy(QDir(Settings::getSettingsDirPath()).filePath(current), path);
|
||||
}
|
||||
|
||||
void IdentityForm::onDeleteClicked()
|
||||
{
|
||||
if (Settings::getInstance().getCurrentProfile() == bodyUI->profiles->currentText())
|
||||
{
|
||||
QMessageBox::warning(this, tr("Profile currently loaded","current profile deletion warning title"), tr("This profile is currently in use. Please load a different profile before deleting this one.","current profile deletion warning text"));
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::StandardButton resp = QMessageBox::question(this,
|
||||
tr("Deletion imminent!","deletion confirmation title"), tr("Are you sure you want to delete this profile?","deletion confirmation text"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
|
||||
if (resp == QMessageBox::Yes)
|
||||
{
|
||||
QFile::remove(QDir(Settings::getSettingsDirPath()).filePath(bodyUI->profiles->currentText()+Core::TOX_EXT));
|
||||
bodyUI->profiles->removeItem(bodyUI->profiles->currentIndex());
|
||||
bodyUI->profiles->setCurrentText(Settings::getInstance().getCurrentProfile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IdentityForm::onImportClicked()
|
||||
{
|
||||
QString path = QFileDialog::getOpenFileName(this, tr("Import profile", "import dialog title"), QDir::homePath(), tr("Tox save file (*.tox)", "import dialog filter"));
|
||||
QFileInfo info(path);
|
||||
QString profile = info.completeBaseName();
|
||||
QString profilePath = QDir(Settings::getSettingsDirPath()).filePath(profile + Core::TOX_EXT);
|
||||
QFile::copy(path, profilePath);
|
||||
bodyUI->profiles->addItem(profile);
|
||||
Core::getInstance()->switchConfiguration(profile);
|
||||
}
|
||||
|
|
|
@ -60,6 +60,11 @@ private slots:
|
|||
void copyIdClicked();
|
||||
void onUserNameEdited();
|
||||
void onStatusMessageEdited();
|
||||
void onLoadClicked();
|
||||
void onRenameClicked();
|
||||
void onExportClicked();
|
||||
void onDeleteClicked();
|
||||
void onImportClicked();
|
||||
|
||||
private:
|
||||
Ui::IdentitySettings* bodyUI;
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="profilesComboBox" />
|
||||
<widget class="QComboBox" name="profiles" />
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
|
|
|
@ -66,22 +66,3 @@ void FriendListWidget::moveWidget(QWidget *w, Status s)
|
|||
mainLayout->removeWidget(w);
|
||||
getFriendLayout(s)->addWidget(w);
|
||||
}
|
||||
|
||||
void clearLayout(QLayout *layout)
|
||||
{
|
||||
QLayoutItem *item;
|
||||
while((item = layout->takeAt(0)))
|
||||
{
|
||||
if (item->layout()) {
|
||||
clearLayout(item->layout());
|
||||
delete item->layout();
|
||||
}
|
||||
delete item->widget();
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
void FriendListWidget::clear()
|
||||
{
|
||||
clearLayout(mainLayout);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@ public:
|
|||
signals:
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
|
||||
private:
|
||||
QHash<int, QLayout*> layouts;
|
||||
|
|
|
@ -137,7 +137,6 @@ Widget::Widget(QWidget *parent)
|
|||
connect(core, SIGNAL(fileUploadFinished(const QString&)), &filesForm, SLOT(onFileUploadComplete(const QString&)));
|
||||
connect(core, &Core::friendAdded, this, &Widget::addFriend);
|
||||
connect(core, &Core::failedToAddFriend, this, &Widget::addFriendFailed);
|
||||
connect(core, &Core::clearFriends, contactListWidget, &FriendListWidget::clear);
|
||||
connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged);
|
||||
connect(core, &Core::friendUsernameChanged, this, &Widget::onFriendUsernameChanged);
|
||||
connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged);
|
||||
|
@ -637,6 +636,14 @@ void Widget::removeFriend(int friendId)
|
|||
removeFriend(FriendList::findFriend(friendId));
|
||||
}
|
||||
|
||||
void Widget::clearContactsList()
|
||||
{
|
||||
for (Friend* f : FriendList::friendList)
|
||||
removeFriend(f);
|
||||
for (Group* g : GroupList::groupList)
|
||||
removeGroup(g);
|
||||
}
|
||||
|
||||
void Widget::copyFriendIdToClipboard(int friendId)
|
||||
{
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
|
@ -700,19 +707,23 @@ void Widget::onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t Cha
|
|||
g->updatePeer(peernumber,core->getGroupPeerName(groupnumber, peernumber));
|
||||
}
|
||||
|
||||
void Widget::removeGroup(int groupId)
|
||||
void Widget::removeGroup(Group* g)
|
||||
{
|
||||
Group* g = GroupList::findGroup(groupId);
|
||||
g->widget->setAsInactiveChatroom();
|
||||
if (static_cast<GenericChatroomWidget*>(g->widget) == activeChatroomWidget)
|
||||
activeChatroomWidget = nullptr;
|
||||
GroupList::removeGroup(groupId);
|
||||
core->removeGroup(groupId);
|
||||
GroupList::removeGroup(g->groupId);
|
||||
core->removeGroup(g->groupId);
|
||||
delete g;
|
||||
if (ui->mainHead->layout()->isEmpty())
|
||||
onAddClicked();
|
||||
}
|
||||
|
||||
void Widget::removeGroup(int groupId)
|
||||
{
|
||||
removeGroup(GroupList::findGroup(groupId));
|
||||
}
|
||||
|
||||
Core *Widget::getCore()
|
||||
{
|
||||
return core;
|
||||
|
|
|
@ -57,6 +57,7 @@ public:
|
|||
bool isFriendWidgetCurActiveWidget(Friend* f);
|
||||
bool getIsWindowMinimized();
|
||||
static QList<QString> searchProfiles();
|
||||
void clearContactsList();
|
||||
~Widget();
|
||||
|
||||
virtual void closeEvent(QCloseEvent *event);
|
||||
|
@ -112,6 +113,7 @@ private:
|
|||
virtual bool event(QEvent * e);
|
||||
Group* createGroup(int groupId);
|
||||
void removeFriend(Friend* f);
|
||||
void removeGroup(Group* g);
|
||||
QString askProfiles();
|
||||
QString detectProfile();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user