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;
}
// this will attempt to get the last profile from settings
loadConfiguration();
// where do we find the data file?
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_message(tox, onFriendMessage, this);
@ -591,6 +605,15 @@ void Core::removeGroup(int 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()
{
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) {
emit failedToSetUsername(username);
} else {
saveConfiguration();
emit usernameSet(username);
saveConfiguration();
}
}
@ -730,28 +753,8 @@ QString Core::sanitize(QString 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
// 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);
}
{ // also loadFriends/clearFriends is borked as fuck
// setting the profile is now the responsibility of the caller
QFile conf(path);
qDebug() << "Core::loadConfiguration: reading from " << path;
@ -795,16 +798,24 @@ void Core::saveConfiguration()
}
QString profile = Settings::getInstance().getCurrentProfile();
//qDebug() << "saveConf read profile: " << profile;
if (profile == "")
{ // no profile active; this should only happen on startup, if at all
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);
}
QString path = dir + profile + TOX_EXT;
QFileInfo info(path);
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)

2
core.h
View File

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

View File

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

View File

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