mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
incremental improvements to profiles, more work required
This commit is contained in:
parent
1c33fccadd
commit
f9a3192f30
15
core.cpp
15
core.cpp
|
@ -723,17 +723,19 @@ void Core::checkConnection()
|
|||
}
|
||||
}
|
||||
|
||||
QString sanitize(QString name)
|
||||
QString Core::sanitize(QString name)
|
||||
{
|
||||
// do things
|
||||
return name;
|
||||
}
|
||||
|
||||
void Core::loadConfiguration(QString path)
|
||||
{
|
||||
{ // note to self: this really needs refactoring into the GUI, making the path mandatory here
|
||||
// but for now it's bedtime
|
||||
if (path == "")
|
||||
{
|
||||
// read from settings whose profile?
|
||||
QString profile = Settings::getInstance().getCurrentProfile();
|
||||
path = Settings::getSettingsDirPath() + '/' + Settings::getInstance().getCurrentProfile() + TOX_EXT;
|
||||
QFile file(path);
|
||||
|
||||
|
@ -743,6 +745,11 @@ void Core::loadConfiguration(QString path)
|
|||
path = Settings::getSettingsDirPath() + '/' + CONFIG_FILE_NAME;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QString profile = QFileInfo(path).completeBaseName();
|
||||
Settings::getInstance().setCurrentProfile(profile);
|
||||
}
|
||||
|
||||
QFile conf(path);
|
||||
qDebug() << "Core::loadConfiguration: reading from " << path;
|
||||
|
@ -768,10 +775,7 @@ void Core::loadConfiguration(QString path)
|
|||
// set GUI with user and statusmsg
|
||||
QString name = getUsername();
|
||||
if (name != "")
|
||||
{
|
||||
emit usernameSet(name);
|
||||
Settings::getInstance().setCurrentProfile(name);
|
||||
}
|
||||
|
||||
QString msg = getStatusMessage();
|
||||
if (msg != "")
|
||||
|
@ -825,6 +829,7 @@ void Core::loadFriends()
|
|||
{
|
||||
const uint32_t friendCount = tox_count_friendlist(tox);
|
||||
if (friendCount > 0) {
|
||||
emit clearFriends();
|
||||
// assuming there are not that many friends to fill up the whole stack
|
||||
int32_t *ids = new int32_t[friendCount];
|
||||
tox_get_friendlist(tox, ids, friendCount);
|
||||
|
|
3
core.h
3
core.h
|
@ -126,7 +126,7 @@ public:
|
|||
|
||||
void saveConfiguration(QString path = "");
|
||||
void loadConfiguration(QString path = "");
|
||||
QString sanitize(QString name);
|
||||
static QString sanitize(QString name);
|
||||
|
||||
QString getUsername();
|
||||
QString getStatusMessage();
|
||||
|
@ -177,6 +177,7 @@ signals:
|
|||
void friendMessageReceived(int friendId, const QString& message);
|
||||
|
||||
void friendAdded(int friendId, const QString& userId);
|
||||
void clearFriends();
|
||||
|
||||
void friendStatusChanged(int friendId, Status status);
|
||||
void friendStatusMessageChanged(int friendId, const QString& message);
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#include <QClipboard>
|
||||
#include <QApplication>
|
||||
|
||||
SettingsForm::SettingsForm(Core* core)
|
||||
: QObject(), core(core)
|
||||
SettingsForm::SettingsForm()
|
||||
: QObject()
|
||||
{
|
||||
main = new QWidget(), head = new QWidget();
|
||||
hboxcont1 = new QWidget(), hboxcont2 = new QWidget();
|
||||
|
@ -81,7 +81,7 @@ SettingsForm::SettingsForm(Core* core)
|
|||
layout.addWidget(&enableIPv6);
|
||||
layout.addWidget(&useTranslations);
|
||||
layout.addWidget(&makeToxPortable);
|
||||
layout.addStretch();
|
||||
//layout.addStretch();
|
||||
|
||||
head->setLayout(&headLayout);
|
||||
headLayout.addWidget(&headLabel);
|
||||
|
@ -113,7 +113,7 @@ void SettingsForm::populateProfiles()
|
|||
|
||||
QString SettingsForm::getSelectedSavePath()
|
||||
{
|
||||
return Settings::getSettingsDirPath() + profiles.currentText() + core->TOX_EXT;
|
||||
return Settings::getSettingsDirPath() + profiles.currentText() + Widget::getInstance()->getCore()->TOX_EXT;
|
||||
}
|
||||
|
||||
void SettingsForm::setFriendAddress(const QString& friendAddress)
|
||||
|
@ -133,33 +133,45 @@ void SettingsForm::show(Ui::Widget &ui)
|
|||
|
||||
void SettingsForm::onLoadClicked()
|
||||
{
|
||||
core->saveConfiguration();
|
||||
core->loadConfiguration(getSelectedSavePath());
|
||||
Widget::getInstance()->getCore()->saveConfiguration();
|
||||
Widget::getInstance()->getCore()->loadConfiguration(getSelectedSavePath());
|
||||
// loadConf also setsCurrentProfile
|
||||
}
|
||||
|
||||
void SettingsForm::onExportClicked()
|
||||
{
|
||||
QString current = getSelectedSavePath();
|
||||
QString path = QFileDialog::getSaveFileName(0, tr("Export profile", "save dialog title"), QDir::homePath() + '/' + profiles.currentText() + core->TOX_EXT, tr("Tox save file (*.tox)", "save dialog filter"));
|
||||
// dunno if that "~" works
|
||||
QString path = QFileDialog::getSaveFileName(0, tr("Export profile", "save dialog title"), QDir::homePath() + '/' + profiles.currentText() + Widget::getInstance()->getCore()->TOX_EXT, tr("Tox save file (*.tox)", "save dialog filter"));
|
||||
QFile::copy(getSelectedSavePath(), path);
|
||||
}
|
||||
|
||||
void SettingsForm::onDeleteClicked()
|
||||
{ // this should really be guarded by a pop up
|
||||
QFile::remove(getSelectedSavePath());
|
||||
{
|
||||
if (Settings::getInstance().getCurrentProfile() == profiles.currentText())
|
||||
{
|
||||
QMessageBox::warning(main, 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(main,
|
||||
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(getSelectedSavePath());
|
||||
profiles.removeItem(profiles.currentIndex());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsForm::onImportClicked()
|
||||
{
|
||||
QString path = QFileDialog::getOpenFileName(0, tr("Import profile", "import dialog title"), QDir::homePath(), tr("Tox save file (*.tox)", "import dialog filter"));
|
||||
// again, the "~"...
|
||||
QFileInfo info(path);
|
||||
QString profile = info.completeBaseName();
|
||||
QString profilePath = Settings::getSettingsDirPath() + profile + core->TOX_EXT;
|
||||
QString profilePath = Settings::getSettingsDirPath() + profile + Widget::getInstance()->getCore()->TOX_EXT;
|
||||
QFile::copy(path, profilePath);
|
||||
core->loadConfiguration(profilePath);
|
||||
Widget::getInstance()->getCore()->loadConfiguration(profilePath);
|
||||
profiles.addItem(profile);
|
||||
}
|
||||
|
||||
void SettingsForm::onTestVideoClicked()
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include "widget/tool/clickablelabel.h"
|
||||
#include "ui_widget.h"
|
||||
#include "widget/selfcamview.h"
|
||||
|
@ -39,7 +40,7 @@ class SettingsForm : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SettingsForm(Core* core);
|
||||
SettingsForm();
|
||||
~SettingsForm();
|
||||
|
||||
void show(Ui::Widget& ui);
|
||||
|
@ -71,7 +72,6 @@ private:
|
|||
QWidget *main, *head, *hboxcont1, *hboxcont2;
|
||||
void populateProfiles();
|
||||
QString getSelectedSavePath();
|
||||
Core* core;
|
||||
|
||||
public:
|
||||
//QLineEdit name, statusText;
|
||||
|
|
|
@ -141,8 +141,6 @@ Widget::Widget(QWidget *parent) :
|
|||
|
||||
isWindowMinimized = 0;
|
||||
|
||||
settingsForm = new SettingsForm(core);
|
||||
|
||||
ui->mainContent->setLayout(new QVBoxLayout());
|
||||
ui->mainHead->setLayout(new QVBoxLayout());
|
||||
ui->mainHead->layout()->setMargin(0);
|
||||
|
@ -221,11 +219,12 @@ Widget::Widget(QWidget *parent) :
|
|||
connect(core, &Core::statusSet, this, &Widget::onStatusSet);
|
||||
connect(core, &Core::usernameSet, this, &Widget::setUsername);
|
||||
connect(core, &Core::statusMessageSet, this, &Widget::setStatusMessage);
|
||||
connect(core, &Core::friendAddressGenerated, settingsForm, &SettingsForm::setFriendAddress);
|
||||
connect(core, &Core::friendAddressGenerated, &settingsForm, &SettingsForm::setFriendAddress);
|
||||
connect(core, SIGNAL(fileDownloadFinished(const QString&)), &filesForm, SLOT(onFileDownloadComplete(const QString&)));
|
||||
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, this, &Widget::clearFriends);
|
||||
connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged);
|
||||
connect(core, &Core::friendUsernameChanged, this, &Widget::onFriendUsernameChanged);
|
||||
connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged);
|
||||
|
@ -285,7 +284,6 @@ Widget::~Widget()
|
|||
settings.setValue("geometry", geometry());
|
||||
settings.setValue("maximized", isMaximized());
|
||||
settings.setValue("useNativeTheme", useNativeTheme);
|
||||
delete settingsForm;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
@ -396,7 +394,7 @@ void Widget::onTransferClicked()
|
|||
void Widget::onSettingsClicked()
|
||||
{
|
||||
hideMainForms();
|
||||
settingsForm->show(*ui);
|
||||
settingsForm.show(*ui);
|
||||
isFriendWidgetActive = 0;
|
||||
isGroupWidgetActive = 0;
|
||||
}
|
||||
|
@ -439,11 +437,12 @@ void Widget::onUsernameChanged(const QString& newUsername, const QString& oldUse
|
|||
//settingsForm.name.setText(oldUsername);
|
||||
core->setUsername(newUsername);
|
||||
|
||||
// move the data file with it
|
||||
/*// move the data file with it
|
||||
QString dir = Settings::getSettingsDirPath();
|
||||
QFile::rename(dir + '/' + oldUsername + core->TOX_EXT, dir + '/' + newUsername + core->TOX_EXT);
|
||||
QFile::rename(dir + '/' + core->sanitize(oldUsername) + core->TOX_EXT, dir + '/' + core->sanitize(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:
|
||||
|
@ -649,19 +648,29 @@ void Widget::onFriendRequestReceived(const QString& userId, const QString& messa
|
|||
emit friendRequestAccepted(userId);
|
||||
}
|
||||
|
||||
void Widget::removeFriend(int friendId)
|
||||
void Widget::removeFriend(Friend* f)
|
||||
{
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
f->widget->setAsInactiveChatroom();
|
||||
if (f->widget == activeFriendWidget)
|
||||
activeFriendWidget = nullptr;
|
||||
FriendList::removeFriend(friendId);
|
||||
core->removeFriend(friendId);
|
||||
FriendList::removeFriend(f->friendId);
|
||||
core->removeFriend(f->friendId);
|
||||
delete f;
|
||||
if (ui->mainHead->layout()->isEmpty())
|
||||
onAddClicked();
|
||||
}
|
||||
|
||||
void Widget::removeFriend(int friendId)
|
||||
{
|
||||
removeFriend(FriendList::findFriend(friendId));
|
||||
}
|
||||
|
||||
void Widget::clearFriends()
|
||||
{ // used for dynamic profile loading
|
||||
for (Friend* f : FriendList::friendList)
|
||||
removeFriend(f);
|
||||
}
|
||||
|
||||
void Widget::copyFriendIdToClipboard(int friendId)
|
||||
{
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
|
|
|
@ -106,6 +106,7 @@ private slots:
|
|||
void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
|
||||
void onGroupWidgetClicked(GroupWidget* widget);
|
||||
void removeFriend(int friendId);
|
||||
void clearFriends();
|
||||
void copyFriendIdToClipboard(int friendId);
|
||||
void removeGroup(int groupId);
|
||||
void splitterMoved(int pos, int index);
|
||||
|
@ -119,6 +120,7 @@ protected slots:
|
|||
private:
|
||||
void hideMainForms();
|
||||
Group* createGroup(int groupId);
|
||||
void removeFriend(Friend* f);
|
||||
|
||||
private:
|
||||
Ui::Widget *ui;
|
||||
|
@ -142,7 +144,7 @@ private:
|
|||
Core* core;
|
||||
QThread* coreThread;
|
||||
AddFriendForm friendForm;
|
||||
SettingsForm* settingsForm;
|
||||
SettingsForm settingsForm;
|
||||
FilesForm filesForm;
|
||||
static Widget* instance;
|
||||
FriendWidget* activeFriendWidget;
|
||||
|
|
Loading…
Reference in New Issue
Block a user