mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix change profiles button
This commit is contained in:
parent
67027814e5
commit
db2d9321e4
50
src/core.cpp
50
src/core.cpp
@ -88,15 +88,23 @@ Core::Core(Camera* cam, QThread *CoreThread, QString loadPath) :
|
||||
Audio::openInput(inDevDescr);
|
||||
}
|
||||
|
||||
Core::~Core()
|
||||
void Core::deadifyTox()
|
||||
{
|
||||
if (tox)
|
||||
if (toxav)
|
||||
{
|
||||
toxav_kill(toxav);
|
||||
toxav = nullptr;
|
||||
}
|
||||
if (tox)
|
||||
{
|
||||
tox_kill(tox);
|
||||
tox = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Core::~Core()
|
||||
{
|
||||
deadifyTox();
|
||||
|
||||
if (videobuf)
|
||||
{
|
||||
@ -164,9 +172,6 @@ void Core::make_tox()
|
||||
{
|
||||
if (toxOptions.proxy_enabled)
|
||||
{
|
||||
//QMessageBox::critical(Widget::getInstance(), tr("Proxy failure", "popup title"),
|
||||
//tr("toxcore failed to start with your proxy settings. qTox cannot run; please modify your "
|
||||
//"settings and restart.", "popup text"));
|
||||
qCritical() << "Core: bad proxy! no toxcore!";
|
||||
emit badProxy();
|
||||
}
|
||||
@ -210,14 +215,17 @@ void Core::start()
|
||||
|
||||
if (loadPath != "")
|
||||
{
|
||||
if (!loadConfiguration(loadPath)) // loadPath is meaningless after this
|
||||
{
|
||||
qCritical() << "Core: loadConfiguration failed, exiting now";
|
||||
emit failedToStart();
|
||||
tox_kill(tox);
|
||||
tox = nullptr;
|
||||
return;
|
||||
while (!loadConfiguration(loadPath))
|
||||
{
|
||||
if (loadPath.isEmpty())
|
||||
{
|
||||
qCritical() << "Core: loadConfiguration failed, exiting now";
|
||||
deadifyTox();
|
||||
emit failedToStart();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// loadPath is meaningless after this
|
||||
loadPath = "";
|
||||
}
|
||||
else // new ID
|
||||
@ -1142,6 +1150,7 @@ QString Core::sanitize(QString name)
|
||||
|
||||
bool Core::loadConfiguration(QString path)
|
||||
{
|
||||
loadPath = ""; // if not empty, then user forgot a password
|
||||
// setting the profile is now the responsibility of the caller
|
||||
QFile configurationFile(path);
|
||||
qDebug() << "Core::loadConfiguration: reading from " << path;
|
||||
@ -1169,12 +1178,22 @@ bool Core::loadConfiguration(QString path)
|
||||
if (!loadEncryptedSave(data))
|
||||
{
|
||||
configurationFile.close();
|
||||
|
||||
QString profile;
|
||||
QMetaObject::invokeMethod(Widget::getInstance(), "askProfiles", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QString, profile));
|
||||
|
||||
if (!profile.isEmpty())
|
||||
loadPath = QDir(Settings::getSettingsDirPath()).filePath(profile + TOX_EXT);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
configurationFile.close();
|
||||
|
||||
Settings::getInstance().setCurrentProfile(QFileInfo(path).completeBaseName());
|
||||
// this is necessary for anything that doesn't call switchConfiguration, i.e.
|
||||
// forgetting a password and choosing a different profile
|
||||
|
||||
// set GUI with user and statusmsg
|
||||
QString name = getUsername();
|
||||
if (!name.isEmpty())
|
||||
@ -1237,12 +1256,7 @@ void Core::switchConfiguration(const QString& profile)
|
||||
|
||||
toxTimer->stop();
|
||||
Widget::getInstance()->setEnabledThreadsafe(false);
|
||||
if (tox) {
|
||||
toxav_kill(toxav);
|
||||
toxav = nullptr;
|
||||
tox_kill(tox);
|
||||
tox = nullptr;
|
||||
}
|
||||
deadifyTox();
|
||||
|
||||
emit selfAvatarChanged(QPixmap(":/img/contact_dark.png"));
|
||||
emit blockingClearContacts(); // we need this to block, but signals are required for thread safety
|
||||
|
@ -274,6 +274,8 @@ private:
|
||||
|
||||
void checkLastOnline(int friendId);
|
||||
|
||||
void deadifyTox();
|
||||
|
||||
private slots:
|
||||
void onFileTransferFinished(ToxFile file);
|
||||
|
||||
|
@ -384,7 +384,7 @@ QString Widget::detectProfile()
|
||||
QString path, profile = Settings::getInstance().getCurrentProfile();
|
||||
path = dir.filePath(profile + Core::TOX_EXT);
|
||||
QFile file(path);
|
||||
if (profile == "" || !file.exists())
|
||||
if (profile.isEmpty() || !file.exists())
|
||||
{
|
||||
Settings::getInstance().setCurrentProfile("");
|
||||
#if 1 // deprecation attempt
|
||||
@ -399,10 +399,10 @@ QString Widget::detectProfile()
|
||||
#endif
|
||||
{
|
||||
profile = askProfiles();
|
||||
if (profile != "")
|
||||
return dir.filePath(profile + Core::TOX_EXT);
|
||||
else
|
||||
if (profile.isEmpty())
|
||||
return "";
|
||||
else
|
||||
return dir.filePath(profile + Core::TOX_EXT);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -69,6 +69,7 @@ public:
|
||||
Q_INVOKABLE bool askQuestion(const QString& title, const QString& msg, bool defaultAns = false, bool warning = true);
|
||||
Q_INVOKABLE QString passwordDialog(const QString& cancel, const QString& body);
|
||||
// hooray for threading hacks
|
||||
Q_INVOKABLE QString askProfiles();
|
||||
~Widget();
|
||||
|
||||
virtual void closeEvent(QCloseEvent *event);
|
||||
@ -144,7 +145,6 @@ private:
|
||||
void removeGroup(Group* g, bool fake = false);
|
||||
void saveWindowGeometry();
|
||||
void saveSplitterGeometry();
|
||||
QString askProfiles();
|
||||
QString detectProfile();
|
||||
QSystemTrayIcon *icon;
|
||||
QMenu *trayMenu;
|
||||
|
Loading…
x
Reference in New Issue
Block a user