Browse Source

incremental improvements to profiles, more work required

pull/260/head
Bill Winslow 11 years ago
parent
commit
f9a3192f30
  1. 15
      core.cpp
  2. 3
      core.h
  3. 38
      widget/form/settingsform.cpp
  4. 4
      widget/form/settingsform.h
  5. 31
      widget/widget.cpp
  6. 4
      widget/widget.h

15
core.cpp

@ -723,17 +723,19 @@ void Core::checkConnection()
} }
} }
QString sanitize(QString name) QString Core::sanitize(QString name)
{ {
// do things // do things
return name; return name;
} }
void Core::loadConfiguration(QString path) 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 == "") if (path == "")
{ {
// read from settings whose profile? // read from settings whose profile?
QString profile = Settings::getInstance().getCurrentProfile();
path = Settings::getSettingsDirPath() + '/' + Settings::getInstance().getCurrentProfile() + TOX_EXT; path = Settings::getSettingsDirPath() + '/' + Settings::getInstance().getCurrentProfile() + TOX_EXT;
QFile file(path); QFile file(path);
@ -743,6 +745,11 @@ void Core::loadConfiguration(QString path)
path = Settings::getSettingsDirPath() + '/' + CONFIG_FILE_NAME; path = Settings::getSettingsDirPath() + '/' + CONFIG_FILE_NAME;
} }
} }
else
{
QString profile = QFileInfo(path).completeBaseName();
Settings::getInstance().setCurrentProfile(profile);
}
QFile conf(path); QFile conf(path);
qDebug() << "Core::loadConfiguration: reading from " << path; qDebug() << "Core::loadConfiguration: reading from " << path;
@ -768,10 +775,7 @@ void Core::loadConfiguration(QString path)
// set GUI with user and statusmsg // set GUI with user and statusmsg
QString name = getUsername(); QString name = getUsername();
if (name != "") if (name != "")
{
emit usernameSet(name); emit usernameSet(name);
Settings::getInstance().setCurrentProfile(name);
}
QString msg = getStatusMessage(); QString msg = getStatusMessage();
if (msg != "") if (msg != "")
@ -825,6 +829,7 @@ void Core::loadFriends()
{ {
const uint32_t friendCount = tox_count_friendlist(tox); const uint32_t friendCount = tox_count_friendlist(tox);
if (friendCount > 0) { if (friendCount > 0) {
emit clearFriends();
// assuming there are not that many friends to fill up the whole stack // assuming there are not that many friends to fill up the whole stack
int32_t *ids = new int32_t[friendCount]; int32_t *ids = new int32_t[friendCount];
tox_get_friendlist(tox, ids, friendCount); tox_get_friendlist(tox, ids, friendCount);

3
core.h

@ -126,7 +126,7 @@ public:
void saveConfiguration(QString path = ""); void saveConfiguration(QString path = "");
void loadConfiguration(QString path = ""); void loadConfiguration(QString path = "");
QString sanitize(QString name); static QString sanitize(QString name);
QString getUsername(); QString getUsername();
QString getStatusMessage(); QString getStatusMessage();
@ -177,6 +177,7 @@ signals:
void friendMessageReceived(int friendId, const QString& message); void friendMessageReceived(int friendId, const QString& message);
void friendAdded(int friendId, const QString& userId); void friendAdded(int friendId, const QString& userId);
void clearFriends();
void friendStatusChanged(int friendId, Status status); void friendStatusChanged(int friendId, Status status);
void friendStatusMessageChanged(int friendId, const QString& message); void friendStatusMessageChanged(int friendId, const QString& message);

38
widget/form/settingsform.cpp

@ -21,8 +21,8 @@
#include <QClipboard> #include <QClipboard>
#include <QApplication> #include <QApplication>
SettingsForm::SettingsForm(Core* core) SettingsForm::SettingsForm()
: QObject(), core(core) : QObject()
{ {
main = new QWidget(), head = new QWidget(); main = new QWidget(), head = new QWidget();
hboxcont1 = new QWidget(), hboxcont2 = new QWidget(); hboxcont1 = new QWidget(), hboxcont2 = new QWidget();
@ -81,7 +81,7 @@ SettingsForm::SettingsForm(Core* core)
layout.addWidget(&enableIPv6); layout.addWidget(&enableIPv6);
layout.addWidget(&useTranslations); layout.addWidget(&useTranslations);
layout.addWidget(&makeToxPortable); layout.addWidget(&makeToxPortable);
layout.addStretch(); //layout.addStretch();
head->setLayout(&headLayout); head->setLayout(&headLayout);
headLayout.addWidget(&headLabel); headLayout.addWidget(&headLabel);
@ -113,7 +113,7 @@ void SettingsForm::populateProfiles()
QString SettingsForm::getSelectedSavePath() 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) void SettingsForm::setFriendAddress(const QString& friendAddress)
@ -133,33 +133,45 @@ void SettingsForm::show(Ui::Widget &ui)
void SettingsForm::onLoadClicked() void SettingsForm::onLoadClicked()
{ {
core->saveConfiguration(); Widget::getInstance()->getCore()->saveConfiguration();
core->loadConfiguration(getSelectedSavePath()); Widget::getInstance()->getCore()->loadConfiguration(getSelectedSavePath());
// loadConf also setsCurrentProfile // loadConf also setsCurrentProfile
} }
void SettingsForm::onExportClicked() void SettingsForm::onExportClicked()
{ {
QString current = getSelectedSavePath(); 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")); 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"));
// dunno if that "~" works
QFile::copy(getSelectedSavePath(), path); QFile::copy(getSelectedSavePath(), path);
} }
void SettingsForm::onDeleteClicked() 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() void SettingsForm::onImportClicked()
{ {
QString path = QFileDialog::getOpenFileName(0, tr("Import profile", "import dialog title"), QDir::homePath(), tr("Tox save file (*.tox)", "import dialog filter")); 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); QFileInfo info(path);
QString profile = info.completeBaseName(); 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); QFile::copy(path, profilePath);
core->loadConfiguration(profilePath); Widget::getInstance()->getCore()->loadConfiguration(profilePath);
profiles.addItem(profile);
} }
void SettingsForm::onTestVideoClicked() void SettingsForm::onTestVideoClicked()

4
widget/form/settingsform.h

@ -30,6 +30,7 @@
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox>
#include "widget/tool/clickablelabel.h" #include "widget/tool/clickablelabel.h"
#include "ui_widget.h" #include "ui_widget.h"
#include "widget/selfcamview.h" #include "widget/selfcamview.h"
@ -39,7 +40,7 @@ class SettingsForm : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
SettingsForm(Core* core); SettingsForm();
~SettingsForm(); ~SettingsForm();
void show(Ui::Widget& ui); void show(Ui::Widget& ui);
@ -71,7 +72,6 @@ private:
QWidget *main, *head, *hboxcont1, *hboxcont2; QWidget *main, *head, *hboxcont1, *hboxcont2;
void populateProfiles(); void populateProfiles();
QString getSelectedSavePath(); QString getSelectedSavePath();
Core* core;
public: public:
//QLineEdit name, statusText; //QLineEdit name, statusText;

31
widget/widget.cpp

@ -141,8 +141,6 @@ Widget::Widget(QWidget *parent) :
isWindowMinimized = 0; isWindowMinimized = 0;
settingsForm = new SettingsForm(core);
ui->mainContent->setLayout(new QVBoxLayout()); ui->mainContent->setLayout(new QVBoxLayout());
ui->mainHead->setLayout(new QVBoxLayout()); ui->mainHead->setLayout(new QVBoxLayout());
ui->mainHead->layout()->setMargin(0); ui->mainHead->layout()->setMargin(0);
@ -221,11 +219,12 @@ Widget::Widget(QWidget *parent) :
connect(core, &Core::statusSet, this, &Widget::onStatusSet); connect(core, &Core::statusSet, this, &Widget::onStatusSet);
connect(core, &Core::usernameSet, this, &Widget::setUsername); connect(core, &Core::usernameSet, this, &Widget::setUsername);
connect(core, &Core::statusMessageSet, this, &Widget::setStatusMessage); 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(fileDownloadFinished(const QString&)), &filesForm, SLOT(onFileDownloadComplete(const QString&)));
connect(core, SIGNAL(fileUploadFinished(const QString&)), &filesForm, SLOT(onFileUploadComplete(const QString&))); connect(core, SIGNAL(fileUploadFinished(const QString&)), &filesForm, SLOT(onFileUploadComplete(const QString&)));
connect(core, &Core::friendAdded, this, &Widget::addFriend); connect(core, &Core::friendAdded, this, &Widget::addFriend);
connect(core, &Core::failedToAddFriend, this, &Widget::addFriendFailed); connect(core, &Core::failedToAddFriend, this, &Widget::addFriendFailed);
connect(core, &Core::clearFriends, this, &Widget::clearFriends);
connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged); connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged);
connect(core, &Core::friendUsernameChanged, this, &Widget::onFriendUsernameChanged); connect(core, &Core::friendUsernameChanged, this, &Widget::onFriendUsernameChanged);
connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged); connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged);
@ -285,7 +284,6 @@ Widget::~Widget()
settings.setValue("geometry", geometry()); settings.setValue("geometry", geometry());
settings.setValue("maximized", isMaximized()); settings.setValue("maximized", isMaximized());
settings.setValue("useNativeTheme", useNativeTheme); settings.setValue("useNativeTheme", useNativeTheme);
delete settingsForm;
delete ui; delete ui;
} }
@ -396,7 +394,7 @@ void Widget::onTransferClicked()
void Widget::onSettingsClicked() void Widget::onSettingsClicked()
{ {
hideMainForms(); hideMainForms();
settingsForm->show(*ui); settingsForm.show(*ui);
isFriendWidgetActive = 0; isFriendWidgetActive = 0;
isGroupWidgetActive = 0; isGroupWidgetActive = 0;
} }
@ -439,11 +437,12 @@ void Widget::onUsernameChanged(const QString& newUsername, const QString& oldUse
//settingsForm.name.setText(oldUsername); //settingsForm.name.setText(oldUsername);
core->setUsername(newUsername); core->setUsername(newUsername);
// move the data file with it /*// move the data file with it
QString dir = Settings::getSettingsDirPath(); 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 // and update current profile
Settings::getInstance().setCurrentProfile(newUsername); Settings::getInstance().setCurrentProfile(newUsername);
*/
} }
// ugh... Widget::onUsernameChanged() calls Core::setUsername, // ugh... Widget::onUsernameChanged() calls Core::setUsername,
// which emits Core::usernameSet, which is connect to this function: // 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); emit friendRequestAccepted(userId);
} }
void Widget::removeFriend(int friendId) void Widget::removeFriend(Friend* f)
{ {
Friend* f = FriendList::findFriend(friendId);
f->widget->setAsInactiveChatroom(); f->widget->setAsInactiveChatroom();
if (f->widget == activeFriendWidget) if (f->widget == activeFriendWidget)
activeFriendWidget = nullptr; activeFriendWidget = nullptr;
FriendList::removeFriend(friendId); FriendList::removeFriend(f->friendId);
core->removeFriend(friendId); core->removeFriend(f->friendId);
delete f; delete f;
if (ui->mainHead->layout()->isEmpty()) if (ui->mainHead->layout()->isEmpty())
onAddClicked(); 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) void Widget::copyFriendIdToClipboard(int friendId)
{ {
Friend* f = FriendList::findFriend(friendId); Friend* f = FriendList::findFriend(friendId);

4
widget/widget.h

@ -106,6 +106,7 @@ private slots:
void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change); void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
void onGroupWidgetClicked(GroupWidget* widget); void onGroupWidgetClicked(GroupWidget* widget);
void removeFriend(int friendId); void removeFriend(int friendId);
void clearFriends();
void copyFriendIdToClipboard(int friendId); void copyFriendIdToClipboard(int friendId);
void removeGroup(int groupId); void removeGroup(int groupId);
void splitterMoved(int pos, int index); void splitterMoved(int pos, int index);
@ -119,6 +120,7 @@ protected slots:
private: private:
void hideMainForms(); void hideMainForms();
Group* createGroup(int groupId); Group* createGroup(int groupId);
void removeFriend(Friend* f);
private: private:
Ui::Widget *ui; Ui::Widget *ui;
@ -142,7 +144,7 @@ private:
Core* core; Core* core;
QThread* coreThread; QThread* coreThread;
AddFriendForm friendForm; AddFriendForm friendForm;
SettingsForm* settingsForm; SettingsForm settingsForm;
FilesForm filesForm; FilesForm filesForm;
static Widget* instance; static Widget* instance;
FriendWidget* activeFriendWidget; FriendWidget* activeFriendWidget;

Loading…
Cancel
Save