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

Merge branch 'pr947'

Conflicts:
	src/misc/settings.cpp
This commit is contained in:
Dubslow 2015-02-08 13:29:19 -06:00
commit 4d56a6fdd8
No known key found for this signature in database
GPG Key ID: 3DB8E05315C220AA
11 changed files with 292 additions and 23 deletions

View File

@ -320,4 +320,9 @@ contains(DEFINES, QTOX_PLATFORM_EXT) {
SOURCES += src/platform/timer_osx.cpp \
src/platform/timer_win.cpp \
src/platform/timer_x11.cpp
HEADERS += src/platform/autorun.h
SOURCES += src/platform/autorun_win.cpp \
src/platform/autorun_xdg.cpp \
src/platform/autorun_osx.cpp
}

View File

@ -20,6 +20,9 @@
#include "src/misc/db/plaindb.h"
#include "src/core.h"
#include "src/widget/gui.h"
#ifdef QTOX_PLATFORM_EXT
#include "src/platform/autorun.h"
#endif
#include <QFont>
#include <QApplication>
@ -545,6 +548,22 @@ void Settings::setMakeToxPortable(bool newValue)
save();
}
bool Settings::getAutorun() const
{
#ifdef QTOX_PLATFORM_EXT
return Platform::getAutorun();
#else
return false;
#endif
}
void Settings::setAutorun(bool newValue)
{
#ifdef QTOX_PLATFORM_EXT
Platform::setAutorun(newValue);
#endif
}
bool Settings::getAutostartInTray() const
{
return autostartInTray;

View File

@ -59,6 +59,9 @@ public:
bool getMakeToxPortable() const;
void setMakeToxPortable(bool newValue);
bool getAutorun() const;
void setAutorun(bool newValue);
bool getAutostartInTray() const;
void setAutostartInTray(bool newValue);

31
src/platform/autorun.h Normal file
View File

@ -0,0 +1,31 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#ifdef QTOX_PLATFORM_EXT
#ifndef PLATFORM_AUTORUN_H
#define PLATFORM_AUTORUN_H
namespace Platform
{
bool setAutorun(bool on);
bool getAutorun();
}
#endif // PLATFORM_AUTORUN_H
#endif // QTOX_PLATFORM_EXT

View File

@ -0,0 +1,31 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#if defined(__APPLE__) && defined(__MACH__)
#include "src/platform/autorun.h"
bool Platform::setAutorun(bool on)
{
return false;
}
bool Platform::getAutorun()
{
return false;
}
#endif // defined(__APPLE__) && defined(__MACH__)

View File

@ -0,0 +1,82 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include <QApplication>
#ifdef Q_OS_WIN32
#include "src/platform/autorun.h"
#include "src/misc/settings.h"
#include <Windows.h>
#include <string>
namespace Platform
{
inline std::wstring currentCommandLine()
{
return ("\"" + QApplication::applicationFilePath().replace('/', '\\') + "\" -P \"" +
Settings::getInstance().getCurrentProfile() + "\"").toStdWString();
}
inline std::wstring currentRegistryKeyName()
{
return (QString("qTox - ") + Settings::getInstance().getCurrentProfile()).toStdWString();
}
}
bool Platform::setAutorun(bool on)
{
HKEY key = 0;
if (RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run",
0, KEY_ALL_ACCESS, &key) != ERROR_SUCCESS)
return false;
bool result = false;
std::wstring keyName = currentRegistryKeyName();
if (on)
{
std::wstring path = currentCommandLine();
result = RegSetValueEx(key, keyName.c_str(), 0, REG_SZ, (PBYTE)path.c_str(),
path.length() * sizeof(wchar_t)) == ERROR_SUCCESS;
}
else
result = RegDeleteValue(key, keyName.c_str()) == ERROR_SUCCESS;
RegCloseKey(key);
return result;
}
bool Platform::getAutorun()
{
HKEY key = 0;
if (RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run",
0, KEY_ALL_ACCESS, &key) != ERROR_SUCCESS)
return false;
std::wstring keyName = currentRegistryKeyName();;
wchar_t path[MAX_PATH] = { 0 };
DWORD length = sizeof(path);
DWORD type = REG_SZ;
bool result = false;
if (RegQueryValueEx(key, keyName.c_str(), 0, &type, (PBYTE)path, &length) == ERROR_SUCCESS && type == REG_SZ)
result = true;
RegCloseKey(key);
return result;
}
#endif // Q_OS_WIN32

View File

@ -0,0 +1,69 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include <QApplication>
#if defined(Q_OS_UNIX) && !defined(__APPLE__) && !defined(__MACH__)
#include "src/platform/autorun.h"
#include "src/misc/settings.h"
#include <QProcessEnvironment>
#include <QDir>
namespace Platform
{
QString getAutostartFilePath()
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString config = env.value("XDG_CONFIG_HOME");
if (config.isEmpty())
config = QDir::homePath() + "/" + ".config";
return config + "/" + "autostart/qTox - " +
Settings::getInstance().getCurrentProfile() + ".desktop";
}
inline QString currentCommandLine()
{
return "\"" + QApplication::applicationFilePath() + "\" -P \"" +
Settings::getInstance().getCurrentProfile() + "\"";
}
}
bool Platform::setAutorun(bool on)
{
QFile desktop(getAutostartFilePath());
if (on)
{
if (!desktop.open(QFile::WriteOnly | QFile::Truncate))
return false;
desktop.write("[Desktop Entry]\n");
desktop.write("Type=Application\n");
desktop.write("Name=qTox\n");
desktop.write("Exec=");
desktop.write(currentCommandLine().toUtf8());
desktop.write("\n");
desktop.close();
return true;
}
else
return desktop.remove();
}
bool Platform::getAutorun()
{
return QFile(getAutostartFilePath()).exists();
}
#endif // defined(Q_OS_UNIX) && !defined(__APPLE__) && !defined(__MACH__)

View File

@ -50,6 +50,10 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) :
for (int i = 0; i < langs.size(); i++)
bodyUI->transComboBox->insertItem(i, langs[i]);
bodyUI->transComboBox->setCurrentIndex(locales.indexOf(Settings::getInstance().getTranslation()));
bodyUI->cbAutorun->setChecked(Settings::getInstance().getAutorun());
#if defined(__APPLE__) && defined(__MACH__)
bodyUI->cbAutorun->setEnabled(False);
#endif
bool showSystemTray = Settings::getInstance().getShowSystemTray();
@ -118,6 +122,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) :
//general
connect(bodyUI->checkUpdates, &QCheckBox::stateChanged, this, &GeneralForm::onCheckUpdateChanged);
connect(bodyUI->transComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onTranslationUpdated()));
connect(bodyUI->cbAutorun, &QCheckBox::stateChanged, this, &GeneralForm::onAutorunUpdated);
connect(bodyUI->showSystemTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetShowSystemTray);
connect(bodyUI->startInTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetAutostartInTray);
connect(bodyUI->closeToTray, &QCheckBox::stateChanged, this, &GeneralForm::onSetCloseToTray);
@ -170,6 +175,11 @@ void GeneralForm::onTranslationUpdated()
Widget::getInstance()->setTranslation();
}
void GeneralForm::onAutorunUpdated()
{
Settings::getInstance().setAutorun(bodyUI->cbAutorun->isChecked());
}
void GeneralForm::onSetShowSystemTray()
{
Settings::getInstance().setShowSystemTray(bodyUI->showSystemTray->isChecked());

View File

@ -33,6 +33,7 @@ public:
private slots:
void onEnableIPv6Updated();
void onTranslationUpdated();
void onAutorunUpdated();
void onSetShowSystemTray();
void onSetAutostartInTray();
void onSetCloseToTray();

View File

@ -114,12 +114,12 @@
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="lightTrayIcon">
<property name="text">
<string>Light icon</string>
</property>
<property name="toolTip">
<string comment="toolTip for light icon setting">Enable light tray icon.</string>
</property>
<property name="text">
<string>Light icon</string>
</property>
</widget>
</item>
<item row="2" column="0">
@ -130,12 +130,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Start in tray</string>
</property>
<property name="toolTip">
<string comment="toolTip for Start in tray setting">qTox will start minimized in tray.</string>
</property>
<property name="text">
<string>Start in tray</string>
</property>
</widget>
</item>
<item row="2" column="1">
@ -146,13 +146,13 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Close to tray</string>
</property>
<property name="toolTip">
<string comment="toolTip for close to tray setting">After pressing close (X) qTox will minimize to tray,
instead of closing itself.</string>
</property>
<property name="text">
<string>Close to tray</string>
</property>
</widget>
</item>
<item row="2" column="2">
@ -163,13 +163,13 @@ instead of closing itself.</string>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Minimize to tray</string>
</property>
<property name="toolTip">
<string comment="toolTip for minimize to tray setting">After pressing minimize (_) qTox will minimize itself to tray,
instead of system taskbar.</string>
</property>
<property name="text">
<string>Minimize to tray</string>
</property>
</widget>
</item>
<item row="2" column="3">
@ -189,11 +189,25 @@ instead of system taskbar.</string>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkUpdates">
<property name="text">
<string>Check for updates on startup</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="cbAutorun">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Start qTox on operating system startup (current profile).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Start automatically</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkUpdates">
<property name="text">
<string>Check for updates on startup</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="autoLayout">
@ -202,12 +216,12 @@ instead of system taskbar.</string>
</property>
<item row="1" column="1">
<widget class="QLabel" name="autoSaveFilesDirLabel">
<property name="text">
<string>Save to:</string>
</property>
<property name="toolTip">
<string>Set where files will be saved.</string>
</property>
<property name="text">
<string>Save to:</string>
</property>
</widget>
</item>
<item row="1" column="0">
@ -228,12 +242,12 @@ instead of system taskbar.</string>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>PushButton</string>
</property>
<property name="toolTip">
<string>Set where files will be saved.</string>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item row="0" column="2">

View File

@ -159,7 +159,11 @@ void IdentityForm::onRenameClicked()
QFile::rename(dir.filePath(cur+".ini"), dir.filePath(name+".ini"));
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
break;
}
} while (true);