mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Implement profile renaming
This commit is contained in:
parent
21db31c215
commit
7fc087ea95
|
@ -272,3 +272,24 @@ void Profile::remove()
|
||||||
QFile::remove(HistoryKeeper::getHistoryPath(name, 0));
|
QFile::remove(HistoryKeeper::getHistoryPath(name, 0));
|
||||||
QFile::remove(HistoryKeeper::getHistoryPath(name, 1));
|
QFile::remove(HistoryKeeper::getHistoryPath(name, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Profile::rename(QString newName)
|
||||||
|
{
|
||||||
|
QString path = Settings::getSettingsDirPath() + QDir::separator() + name,
|
||||||
|
newPath = Settings::getSettingsDirPath() + QDir::separator() + newName;
|
||||||
|
|
||||||
|
if (!ProfileLocker::lock(newName))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QFile::rename(path+".tox", newPath+".tox");
|
||||||
|
QFile::rename(path+".ini", newPath+".ini");
|
||||||
|
HistoryKeeper::renameHistory(name, newName);
|
||||||
|
bool resetAutorun = Settings::getInstance().getAutorun();
|
||||||
|
Settings::getInstance().setAutorun(false);
|
||||||
|
Settings::getInstance().setCurrentProfile(newName);
|
||||||
|
if (resetAutorun)
|
||||||
|
Settings::getInstance().setAutorun(true); // fixes -p flag in autostart command line
|
||||||
|
|
||||||
|
name = newName;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -35,6 +35,9 @@ public:
|
||||||
/// Updates the profiles vector
|
/// Updates the profiles vector
|
||||||
void remove();
|
void remove();
|
||||||
|
|
||||||
|
/// Tries to rename the profile
|
||||||
|
bool rename(QString newName);
|
||||||
|
|
||||||
/// Scan for profile, automatically importing them if needed
|
/// Scan for profile, automatically importing them if needed
|
||||||
/// NOT thread-safe
|
/// NOT thread-safe
|
||||||
static void scanProfiles();
|
static void scanProfiles();
|
||||||
|
|
|
@ -228,39 +228,26 @@ void ProfileForm::onAvatarClicked()
|
||||||
|
|
||||||
void ProfileForm::onRenameClicked()
|
void ProfileForm::onRenameClicked()
|
||||||
{
|
{
|
||||||
/** TODO: Create a rename (low level) function in Profile, use it
|
Nexus& nexus = Nexus::getInstance();
|
||||||
|
QString cur = nexus.getProfile()->getName();
|
||||||
QString title = tr("Rename \"%1\"", "renaming a profile").arg(cur);
|
QString title = tr("Rename \"%1\"", "renaming a profile").arg(cur);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
QString name = QInputDialog::getText(this, title, title+":");
|
QString name = QInputDialog::getText(this, title, title+":");
|
||||||
if (name.isEmpty()) break;
|
if (name.isEmpty()) break;
|
||||||
name = Core::sanitize(name);
|
name = Core::sanitize(name);
|
||||||
QDir dir(Settings::getSettingsDirPath());
|
|
||||||
QString file = dir.filePath(name+Core::TOX_EXT);
|
|
||||||
if (!QFile::exists(file) || GUI::askQuestion(tr("Profile already exists", "rename confirm title"),
|
|
||||||
tr("A profile named \"%1\" already exists. Do you want to erase it?", "rename confirm text").arg(cur)))
|
|
||||||
{
|
|
||||||
if (!ProfileLocker::lock(name))
|
|
||||||
{
|
|
||||||
GUI::showWarning(tr("Profile already exists", "rename failed title"),
|
|
||||||
tr("A profile named \"%1\" already exists and is in use.").arg(cur));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile::rename(dir.filePath(cur+Core::TOX_EXT), file);
|
if (!Profile::profileExists(name) || GUI::askQuestion(tr("Profile already exists", "rename confirm title"),
|
||||||
QFile::rename(dir.filePath(cur+".ini"), dir.filePath(name+".ini"));
|
tr("A profile named \"%1\" already exists. Do you want to erase it?", "rename confirm text").arg(name)))
|
||||||
bodyUI->profiles->setItemText(bodyUI->profiles->currentIndex(), name);
|
{
|
||||||
HistoryKeeper::renameHistory(cur, name);
|
|
||||||
bool resetAutorun = Settings::getInstance().getAutorun();
|
|
||||||
Settings::getInstance().setAutorun(false);
|
|
||||||
Settings::getInstance().setCurrentProfile(name);
|
|
||||||
if (resetAutorun)
|
|
||||||
Settings::getInstance().setAutorun(true); // fixes -p flag in autostart command line
|
|
||||||
|
|
||||||
|
|
||||||
|
if (!nexus.getProfile()->rename(name))
|
||||||
|
GUI::showError(tr("Failed to rename", "rename failed title"),
|
||||||
|
tr("Couldn't rename the profile to \"%1\"").arg(cur));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileForm::onExportClicked()
|
void ProfileForm::onExportClicked()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user