mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Cleanup main() a bit
This commit is contained in:
parent
6bf0317e3e
commit
192d9a5e29
8
qtox.pro
8
qtox.pro
|
@ -440,6 +440,14 @@ unix:!macx {
|
||||||
src/platform/camera/v4l2.cpp
|
src/platform/camera/v4l2.cpp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macx {
|
||||||
|
SOURCES += \
|
||||||
|
src/platform/install_osx.cpp
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
src/platform/install_osx.h
|
||||||
|
}
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
src/audio.cpp \
|
src/audio.cpp \
|
||||||
src/historykeeper.cpp \
|
src/historykeeper.cpp \
|
||||||
|
|
68
src/main.cpp
68
src/main.cpp
|
@ -12,7 +12,6 @@
|
||||||
See the COPYING file for more details.
|
See the COPYING file for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "toxme.h"
|
|
||||||
#include "widget/widget.h"
|
#include "widget/widget.h"
|
||||||
#include "misc/settings.h"
|
#include "misc/settings.h"
|
||||||
#include "src/nexus.h"
|
#include "src/nexus.h"
|
||||||
|
@ -28,17 +27,15 @@
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QProcess>
|
|
||||||
|
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#define EXIT_UPDATE_MACX 218 //We track our state using unique exit codes when debugging
|
#if defined(Q_OS_MACX) && defined(QT_RELEASE)
|
||||||
#define EXIT_UPDATE_MACX_FAIL 216
|
#include "platform/install_osx.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef LOG_TO_FILE
|
#ifdef LOG_TO_FILE
|
||||||
static QTextStream* logFile {nullptr};
|
static QTextStream* logFile {nullptr};
|
||||||
|
@ -118,7 +115,7 @@ int main(int argc, char *argv[])
|
||||||
if (parser.isSet("p"))
|
if (parser.isSet("p"))
|
||||||
{
|
{
|
||||||
QString profileName = parser.value("p");
|
QString profileName = parser.value("p");
|
||||||
if (QDir(Settings::getSettingsDirPath()).exists(profileName + ".tox"))
|
if (Profile::exists(profileName))
|
||||||
{
|
{
|
||||||
qDebug() << "Setting profile to" << profileName;
|
qDebug() << "Setting profile to" << profileName;
|
||||||
if (Profile::isEncrypted(profileName))
|
if (Profile::isEncrypted(profileName))
|
||||||
|
@ -147,7 +144,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
#ifdef LOG_TO_FILE
|
#ifdef LOG_TO_FILE
|
||||||
logFile = new QTextStream;
|
logFile = new QTextStream;
|
||||||
QFile logfile(QDir(Settings::getSettingsDirPath()).filePath("qtox.log"));
|
QFile logfile(Settings::getSettingsDirPath()+"qtox.log");
|
||||||
if (logfile.open(QIODevice::Append))
|
if (logfile.open(QIODevice::Append))
|
||||||
{
|
{
|
||||||
logFile->setDevice(&logfile);
|
logFile->setDevice(&logfile);
|
||||||
|
@ -169,60 +166,7 @@ int main(int argc, char *argv[])
|
||||||
qDebug() << "commit: " << GIT_VERSION << "\n";
|
qDebug() << "commit: " << GIT_VERSION << "\n";
|
||||||
|
|
||||||
#if defined(Q_OS_MACX) && defined(QT_RELEASE)
|
#if defined(Q_OS_MACX) && defined(QT_RELEASE)
|
||||||
if (qApp->applicationDirPath() != "/Applications/qtox.app/Contents/MacOS") {
|
osx::moveToAppFolder();
|
||||||
qDebug() << "OS X: Not in Applications folder";
|
|
||||||
|
|
||||||
QMessageBox AskInstall;
|
|
||||||
AskInstall.setIcon(QMessageBox::Question);
|
|
||||||
AskInstall.setWindowModality(Qt::ApplicationModal);
|
|
||||||
AskInstall.setText("Move to Applications folder?");
|
|
||||||
AskInstall.setInformativeText("I can move myself to the Applications folder, keeping your downloads folder less cluttered.\r\n");
|
|
||||||
AskInstall.setStandardButtons(QMessageBox::Yes|QMessageBox::No);
|
|
||||||
AskInstall.setDefaultButton(QMessageBox::Yes);
|
|
||||||
|
|
||||||
int AskInstallAttempt = AskInstall.exec(); //Actually ask the user
|
|
||||||
|
|
||||||
if (AskInstallAttempt == QMessageBox::Yes) {
|
|
||||||
QProcess *sudoprocess = new QProcess;
|
|
||||||
QProcess *qtoxprocess = new QProcess;
|
|
||||||
|
|
||||||
QString bindir = qApp->applicationDirPath();
|
|
||||||
QString appdir = bindir;
|
|
||||||
appdir.chop(15);
|
|
||||||
QString sudo = bindir + "/qtox_sudo rsync -avzhpltK " + appdir + " /Applications";
|
|
||||||
QString qtox = "open /Applications/qtox.app";
|
|
||||||
|
|
||||||
QString appdir_noqtox = appdir;
|
|
||||||
appdir_noqtox.chop(8);
|
|
||||||
|
|
||||||
if ((appdir_noqtox + "qtox.app") != appdir) //quick safety check
|
|
||||||
{
|
|
||||||
qDebug() << "OS X: Attmepted to delete non qTox directory!";
|
|
||||||
return EXIT_UPDATE_MACX_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDir old_app(appdir);
|
|
||||||
|
|
||||||
sudoprocess->start(sudo); //Where the magic actually happens, safety checks ^
|
|
||||||
sudoprocess->waitForFinished();
|
|
||||||
|
|
||||||
if (old_app.removeRecursively()) //We've just deleted the running program
|
|
||||||
{
|
|
||||||
qDebug() << "OS X: Cleaned up old directory";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug() << "OS X: This should never happen, the directory failed to delete";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fork() != 0) //Forking is required otherwise it won't actually cleanly launch
|
|
||||||
return EXIT_UPDATE_MACX;
|
|
||||||
|
|
||||||
qtoxprocess->start(qtox);
|
|
||||||
|
|
||||||
return 0; //Actually kills it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Install Unicode 6.1 supporting font
|
// Install Unicode 6.1 supporting font
|
||||||
|
|
|
@ -407,14 +407,15 @@ uint32_t Settings::makeProfileId(const QString& profile)
|
||||||
QString Settings::getSettingsDirPath()
|
QString Settings::getSettingsDirPath()
|
||||||
{
|
{
|
||||||
if (makeToxPortable)
|
if (makeToxPortable)
|
||||||
return ".";
|
return QString(".")+QDir::separator();
|
||||||
|
|
||||||
// workaround for https://bugreports.qt-project.org/browse/QTBUG-38845
|
// workaround for https://bugreports.qt-project.org/browse/QTBUG-38845
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
|
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + QDir::separator()
|
||||||
+ QDir::separator() + "AppData" + QDir::separator() + "Roaming" + QDir::separator() + "tox");
|
+ "AppData" + QDir::separator() + "Roaming" + QDir::separator() + "tox" + QDir::separator());
|
||||||
#else
|
#else
|
||||||
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QDir::separator() + "tox");
|
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)
|
||||||
|
+ QDir::separator() + "tox" + QDir::separator());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
|
|
||||||
void createPersonal(QString basename); ///< Write a default personnal settings file for a profile
|
void createPersonal(QString basename); ///< Write a default personnal settings file for a profile
|
||||||
|
|
||||||
static QString getSettingsDirPath();
|
static QString getSettingsDirPath(); ///< The returned path ends with a directory separator
|
||||||
|
|
||||||
struct DhtServer
|
struct DhtServer
|
||||||
{
|
{
|
||||||
|
|
64
src/platform/install_osx.cpp
Normal file
64
src/platform/install_osx.cpp
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
#include "install_osx.h"
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void osx::moveToAppFolder()
|
||||||
|
{
|
||||||
|
if (qApp->applicationDirPath() != "/Applications/qtox.app/Contents/MacOS")
|
||||||
|
{
|
||||||
|
qDebug() << "OS X: Not in Applications folder";
|
||||||
|
|
||||||
|
QMessageBox AskInstall;
|
||||||
|
AskInstall.setIcon(QMessageBox::Question);
|
||||||
|
AskInstall.setWindowModality(Qt::ApplicationModal);
|
||||||
|
AskInstall.setText("Move to Applications folder?");
|
||||||
|
AskInstall.setInformativeText("I can move myself to the Applications folder, keeping your downloads folder less cluttered.\r\n");
|
||||||
|
AskInstall.setStandardButtons(QMessageBox::Yes|QMessageBox::No);
|
||||||
|
AskInstall.setDefaultButton(QMessageBox::Yes);
|
||||||
|
|
||||||
|
int AskInstallAttempt = AskInstall.exec(); //Actually ask the user
|
||||||
|
|
||||||
|
if (AskInstallAttempt == QMessageBox::Yes)
|
||||||
|
{
|
||||||
|
QProcess *sudoprocess = new QProcess;
|
||||||
|
QProcess *qtoxprocess = new QProcess;
|
||||||
|
|
||||||
|
QString bindir = qApp->applicationDirPath();
|
||||||
|
QString appdir = bindir;
|
||||||
|
appdir.chop(15);
|
||||||
|
QString sudo = bindir + "/qtox_sudo rsync -avzhpltK " + appdir + " /Applications";
|
||||||
|
QString qtox = "open /Applications/qtox.app";
|
||||||
|
|
||||||
|
QString appdir_noqtox = appdir;
|
||||||
|
appdir_noqtox.chop(8);
|
||||||
|
|
||||||
|
if ((appdir_noqtox + "qtox.app") != appdir) //quick safety check
|
||||||
|
{
|
||||||
|
qDebug() << "OS X: Attmepted to delete non qTox directory!";
|
||||||
|
exit(EXIT_UPDATE_MACX_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir old_app(appdir);
|
||||||
|
|
||||||
|
sudoprocess->start(sudo); //Where the magic actually happens, safety checks ^
|
||||||
|
sudoprocess->waitForFinished();
|
||||||
|
|
||||||
|
if (old_app.removeRecursively()) //We've just deleted the running program
|
||||||
|
qDebug() << "OS X: Cleaned up old directory";
|
||||||
|
else
|
||||||
|
qDebug() << "OS X: This should never happen, the directory failed to delete";
|
||||||
|
|
||||||
|
if (fork() != 0) //Forking is required otherwise it won't actually cleanly launch
|
||||||
|
exit(EXIT_UPDATE_MACX);
|
||||||
|
|
||||||
|
qtoxprocess->start(qtox);
|
||||||
|
|
||||||
|
exit(0); //Actually kills it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
src/platform/install_osx.h
Normal file
16
src/platform/install_osx.h
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef INSTALLOSX_H
|
||||||
|
#define INSTALLOSX_H
|
||||||
|
|
||||||
|
#ifndef Q_OS_MACX
|
||||||
|
#error "This file is only meant to be compiled for Mac OSX targets"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace osx
|
||||||
|
{
|
||||||
|
static constexpr int EXIT_UPDATE_MACX = 218; // We track our state using unique exit codes when debugging
|
||||||
|
static constexpr int EXIT_UPDATE_MACX_FAIL = 216;
|
||||||
|
|
||||||
|
void moveToAppFolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // INSTALLOSX_H
|
|
@ -54,7 +54,7 @@ Profile* Profile::createProfile(QString name, QString password)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profileExists(name))
|
if (exists(name))
|
||||||
{
|
{
|
||||||
qCritical() << "Tried to create profile "<<name<<", but it already exists!";
|
qCritical() << "Tried to create profile "<<name<<", but it already exists!";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -108,7 +108,7 @@ void Profile::scanProfiles()
|
||||||
|
|
||||||
void Profile::importProfile(QString name)
|
void Profile::importProfile(QString name)
|
||||||
{
|
{
|
||||||
assert(!profileExists(name));
|
assert(!exists(name));
|
||||||
Settings::getInstance().createPersonal(name);
|
Settings::getInstance().createPersonal(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ void Profile::saveToxSave(QByteArray data)
|
||||||
newProfile = false;
|
newProfile = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Profile::profileExists(QString name)
|
bool Profile::exists(QString name)
|
||||||
{
|
{
|
||||||
QString path = Settings::getSettingsDirPath() + QDir::separator() + name;
|
QString path = Settings::getSettingsDirPath() + QDir::separator() + name;
|
||||||
return QFile::exists(path+".tox") && QFile::exists(path+".ini");
|
return QFile::exists(path+".tox") && QFile::exists(path+".ini");
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
static void scanProfiles();
|
static void scanProfiles();
|
||||||
static QVector<QString> getProfiles();
|
static QVector<QString> getProfiles();
|
||||||
|
|
||||||
static bool profileExists(QString name);
|
static bool exists(QString name);
|
||||||
static bool isEncrypted(QString name); ///< Returns false on error. Checks the actual file on disk.
|
static bool isEncrypted(QString name); ///< Returns false on error. Checks the actual file on disk.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -240,7 +240,7 @@ void ProfileForm::onRenameClicked()
|
||||||
if (name.isEmpty()) break;
|
if (name.isEmpty()) break;
|
||||||
name = Core::sanitize(name);
|
name = Core::sanitize(name);
|
||||||
|
|
||||||
if (Profile::profileExists(name))
|
if (Profile::exists(name))
|
||||||
GUI::showError(tr("Profile already exists", "rename failure title"),
|
GUI::showError(tr("Profile already exists", "rename failure title"),
|
||||||
tr("A profile named \"%1\" already exists.", "rename confirm text").arg(name));
|
tr("A profile named \"%1\" already exists.", "rename confirm text").arg(name));
|
||||||
else if (!nexus.getProfile()->rename(name))
|
else if (!nexus.getProfile()->rename(name))
|
||||||
|
|
|
@ -92,7 +92,7 @@ void LoginScreen::onCreateNewProfile()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Profile::profileExists(name))
|
if (Profile::exists(name))
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, tr("Couldn't create a new profile"), tr("This profile already exists."));
|
QMessageBox::critical(this, tr("Couldn't create a new profile"), tr("This profile already exists."));
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user