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

more incremental commits, compiles and sort of works now

This commit is contained in:
Bill Winslow 2014-07-27 03:27:15 -05:00
parent b4a42cb34a
commit 08ab94bf5a
4 changed files with 44 additions and 38 deletions

View File

@ -109,8 +109,22 @@ void Core::start()
return; return;
} }
// this will attempt to get the last profile from settings // where do we find the data file?
loadConfiguration(); QString path;
{ // read data from whose profile?
path = Settings::getSettingsDirPath() + '/' + Settings::getInstance().getCurrentProfile() + TOX_EXT;
#if 1 // deprecation attempt
// if the last profile doesn't exist, fall back to old "data"
//! or maybe, should we give an option to choose other existing profiles?
QFile file(path);
if (!file.exists())
{
path = Settings::getSettingsDirPath() + '/' + CONFIG_FILE_NAME;
}
#endif
}
loadConfiguration(path);
tox_callback_friend_request(tox, onFriendRequest, this); tox_callback_friend_request(tox, onFriendRequest, this);
tox_callback_friend_message(tox, onFriendMessage, this); tox_callback_friend_message(tox, onFriendMessage, this);
@ -591,6 +605,15 @@ void Core::removeGroup(int groupId)
tox_del_groupchat(tox, groupId); tox_del_groupchat(tox, groupId);
} }
QString Core::getIDString()
{
uint8_t friendAddress[TOX_FRIEND_ADDRESS_SIZE];
tox_get_address(tox, friendAddress);
return CFriendAddress::toString(friendAddress).left(12);
// 12 is the smallest multiple of four such that
// 16^n > 10^10 (which is roughly the planet's population)
}
QString Core::getUsername() QString Core::getUsername()
{ {
int size = tox_get_self_name_size(tox); int size = tox_get_self_name_size(tox);
@ -609,8 +632,8 @@ void Core::setUsername(const QString& username)
if (tox_set_name(tox, cUsername.data(), cUsername.size()) == -1) { if (tox_set_name(tox, cUsername.data(), cUsername.size()) == -1) {
emit failedToSetUsername(username); emit failedToSetUsername(username);
} else { } else {
saveConfiguration();
emit usernameSet(username); emit usernameSet(username);
saveConfiguration();
} }
} }
@ -730,28 +753,8 @@ QString Core::sanitize(QString 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 { // also loadFriends/clearFriends is borked as fuck
// but for now it's bedtime // setting the profile is now the responsibility of the caller
// also loadFriends/clearFriends is borked as fuck
if (path == "")
{
// read from settings whose profile?
QString profile = Settings::getInstance().getCurrentProfile();
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;
}
}
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;
@ -795,16 +798,24 @@ void Core::saveConfiguration()
} }
QString profile = Settings::getInstance().getCurrentProfile(); QString profile = Settings::getInstance().getCurrentProfile();
//qDebug() << "saveConf read profile: " << profile;
if (profile == "") if (profile == "")
{ // no profile active; this should only happen on startup, if at all { // no profile active; this should only happen on startup, if at all
profile = sanitize(getUsername()); profile = sanitize(getUsername());
if (profile == "") // happens on creation of a new Tox ID
profile = getIDString();
//qDebug() << "saveConf: read sanitized user as " << profile;
Settings::getInstance().setCurrentProfile(profile); Settings::getInstance().setCurrentProfile(profile);
} }
QString path = dir + profile + TOX_EXT; QString path = dir + profile + TOX_EXT;
QFileInfo info(path); QFileInfo info(path);
if (!info.exists()) // fall back to old school 'data' if (!info.exists()) // fall back to old school 'data'
path = dir + '/' + CONFIG_FILE_NAME; { //path = dir + '/' + CONFIG_FILE_NAME;
qDebug() << path << " does not exist";
}
saveConfiguration(path);
} }
void Core::saveConfiguration(const QString& path) void Core::saveConfiguration(const QString& path)

2
core.h
View File

@ -130,6 +130,8 @@ public:
static QString sanitize(QString name); static QString sanitize(QString name);
QString getIDString();
QString getUsername(); QString getUsername();
QString getStatusMessage(); QString getStatusMessage();

View File

@ -32,9 +32,6 @@ SettingsForm::SettingsForm()
headLabel.setText(tr("User Settings","\"Headline\" of the window")); headLabel.setText(tr("User Settings","\"Headline\" of the window"));
headLabel.setFont(bold); headLabel.setFont(bold);
//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")); idLabel.setText("Tox ID " + tr("(click here to copy)", "Click on this text to copy TID to clipboard"));
id.setFont(small); id.setFont(small);
id.setTextInteractionFlags(Qt::TextSelectableByMouse); id.setTextInteractionFlags(Qt::TextSelectableByMouse);
@ -44,7 +41,6 @@ SettingsForm::SettingsForm()
id.setFixedHeight(id.document()->size().height()); id.setFixedHeight(id.document()->size().height());
profilesLabel.setText(tr("Available profiles:", "Labels the profile selection box")); profilesLabel.setText(tr("Available profiles:", "Labels the profile selection box"));
populateProfiles();
loadConf.setText(tr("Load profile", "button to load selected profile")); loadConf.setText(tr("Load profile", "button to load selected profile"));
exportConf.setText(tr("Export profile", "button to save selected profile elsewhere")); exportConf.setText(tr("Export profile", "button to save selected profile elsewhere"));
delConf.setText(tr("Delete profile", "button to delete selected profile from disk")); delConf.setText(tr("Delete profile", "button to delete selected profile from disk"));
@ -61,10 +57,6 @@ SettingsForm::SettingsForm()
makeToxPortable.setChecked(Settings::getInstance().getMakeToxPortable()); makeToxPortable.setChecked(Settings::getInstance().getMakeToxPortable());
main->setLayout(&layout); main->setLayout(&layout);
//layout.addWidget(&nameLabel);
//layout.addWidget(&name);
//layout.addWidget(&statusTextLabel);
//layout.addWidget(&statusText);
layout.addWidget(&idLabel); layout.addWidget(&idLabel);
layout.addWidget(&id); layout.addWidget(&id);
cbox.addWidget(&profilesLabel); cbox.addWidget(&profilesLabel);
@ -123,8 +115,7 @@ void SettingsForm::setFriendAddress(const QString& friendAddress)
void SettingsForm::show(Ui::Widget &ui) void SettingsForm::show(Ui::Widget &ui)
{ {
//name.setText(ui.nameLabel->text()); populateProfiles();
//statusText.setText(ui.statusLabel->text());
ui.mainContent->layout()->addWidget(main); ui.mainContent->layout()->addWidget(main);
ui.mainHead->layout()->addWidget(head); ui.mainHead->layout()->addWidget(head);
main->show(); main->show();
@ -134,8 +125,8 @@ void SettingsForm::show(Ui::Widget &ui)
void SettingsForm::onLoadClicked() void SettingsForm::onLoadClicked()
{ {
Widget::getInstance()->getCore()->saveConfiguration(); Widget::getInstance()->getCore()->saveConfiguration();
Settings::getInstance().setCurrentProfile(profiles.currentText());
Widget::getInstance()->getCore()->loadConfiguration(getSelectedSavePath()); Widget::getInstance()->getCore()->loadConfiguration(getSelectedSavePath());
// loadConf also setsCurrentProfile
} }
void SettingsForm::onExportClicked() void SettingsForm::onExportClicked()
@ -169,6 +160,7 @@ void SettingsForm::onImportClicked()
QFileInfo info(path); QFileInfo info(path);
QString profile = info.completeBaseName(); QString profile = info.completeBaseName();
QString profilePath = Settings::getSettingsDirPath() + profile + Widget::getInstance()->getCore()->TOX_EXT; QString profilePath = Settings::getSettingsDirPath() + profile + Widget::getInstance()->getCore()->TOX_EXT;
Settings::getInstance().setCurrentProfile(profile);
QFile::copy(path, profilePath); QFile::copy(path, profilePath);
Widget::getInstance()->getCore()->loadConfiguration(profilePath); Widget::getInstance()->getCore()->loadConfiguration(profilePath);
profiles.addItem(profile); profiles.addItem(profile);

View File

@ -208,8 +208,9 @@ Widget::Widget(QWidget *parent) :
qRegisterMetaType<ToxFile>("ToxFile"); qRegisterMetaType<ToxFile>("ToxFile");
qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection"); qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection");
// QString path = detectProfiles();
coreThread = new QThread(this); coreThread = new QThread(this);
core = new Core(camera, coreThread); core = new Core(camera, coreThread/*, profile*/);
core->moveToThread(coreThread); core->moveToThread(coreThread);
connect(coreThread, &QThread::started, core, &Core::start); connect(coreThread, &QThread::started, core, &Core::start);