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

Merge branch 'pr750'

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-11-14 18:32:03 +01:00
commit c4f9baf04b
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
10 changed files with 285 additions and 5 deletions

View File

@ -33,7 +33,8 @@ FORMS += \
src/widget/form/settings/privacysettings.ui \
src/widget/form/loadhistorydialog.ui \
src/widget/form/inputpassworddialog.ui \
src/widget/form/setpassworddialog.ui
src/widget/form/setpassworddialog.ui \
src/widget/form/settings/advancedsettings.ui
CONFIG += c++11
@ -152,7 +153,8 @@ HEADERS += src/widget/form/addfriendform.h \
src/toxdns.h \
src/widget/toxsave.h \
src/autoupdate.h \
src/misc/serialize.h
src/misc/serialize.h \
src/widget/form/settings/advancedform.h
SOURCES += \
src/widget/form/addfriendform.cpp \
@ -217,4 +219,5 @@ SOURCES += \
src/ipc.cpp \
src/widget/toxsave.cpp \
src/autoupdate.cpp \
src/misc/serialize.cpp
src/misc/serialize.cpp \
src/widget/form/settings/advancedform.cpp

View File

@ -130,6 +130,8 @@ HistoryKeeper::HistoryKeeper(GenericDdInterface *db_) :
updateChatsID();
updateAliases();
setSyncType(Settings::getInstance().getDbSyncType());
QSqlQuery sqlAnswer = db->exec("select seq from sqlite_sequence where name=\"history\";");
sqlAnswer.first();
messageID = sqlAnswer.value(0).toInt();
@ -145,10 +147,12 @@ int HistoryKeeper::addChatEntry(const QString& chat, const QString& message, con
int chat_id = getChatID(chat, ctSingle).first;
int sender_id = getAliasID(sender);
db->exec("BEGIN TRANSACTION");
db->exec(QString("INSERT INTO history (timestamp, chat_id, sender, message)") +
QString("VALUES (%1, %2, %3, '%4');")
.arg(dt.toMSecsSinceEpoch()).arg(chat_id).arg(sender_id).arg(wrapMessage(message)));
db->exec(QString("INSERT INTO sent_status (status) VALUES (%1)").arg(isSent));
db->exec("COMMIT TRANSACTION");
messageID++;
return messageID;
@ -315,3 +319,25 @@ void HistoryKeeper::markAsSent(int m_id)
{
db->exec(QString("UPDATE sent_status SET status = 1 WHERE id = %1;").arg(m_id));
}
void HistoryKeeper::setSyncType(Db::syncType sType)
{
QString syncCmd;
switch (sType) {
case Db::syncType::stFull:
syncCmd = "FULL";
break;
case Db::syncType::stNormal:
syncCmd = "NORMAL";
break;
case Db::syncType::stOff:
syncCmd = "OFF";
break;
default:
syncCmd = "FULL";
break;
}
db->exec(QString("PRAGMA synchronous=%1;").arg(syncCmd));
}

View File

@ -22,6 +22,7 @@
#include <QDateTime>
class GenericDdInterface;
namespace Db { enum class syncType; }
class HistoryKeeper
{
@ -51,6 +52,8 @@ public:
QList<HistMessage> getChatHistory(ChatType ct, const QString &chat, const QDateTime &time_from, const QDateTime &time_to);
void markAsSent(int m_id);
void setSyncType(Db::syncType sType);
private:
HistoryKeeper(GenericDdInterface *db_);
HistoryKeeper(HistoryKeeper &hk) = delete;

View File

@ -21,6 +21,10 @@
#include <QSqlDatabase>
namespace Db {
enum class syncType : int {stOff = 0, stNormal = 1, stFull = 2};
}
class PlainDb : public GenericDdInterface
{
public:

View File

@ -17,6 +17,7 @@
#include "settings.h"
#include "smileypack.h"
#include "src/corestructs.h"
#include "src/misc/db/plaindb.h"
#include <QFont>
#include <QApplication>
@ -121,12 +122,17 @@ void Settings::load()
proxyAddr = s.value("proxyAddr", "").toString();
proxyPort = s.value("proxyPort", 0).toInt();
currentProfile = s.value("currentProfile", "").toString();
autoAwayTime = s.value("autoAwayTime", 10).toInt();
autoAwayTime = s.value("autoAwayTime", 10).toInt();
checkUpdates = s.value("checkUpdates", false).toBool();
showInFront = s.value("showInFront", false).toBool();
fauxOfflineMessaging = s.value("fauxOfflineMessaging", true).toBool();
s.endGroup();
s.beginGroup("Advanced");
int sType = s.value("dbSyncType", static_cast<int>(Db::syncType::stFull)).toInt();
setDbSyncType(sType);
s.endGroup();
s.beginGroup("Widgets");
QList<QString> objectNames = s.childKeys();
for (const QString& name : objectNames) {
@ -267,6 +273,10 @@ void Settings::save(QString path)
s.setValue("fauxOfflineMessaging", fauxOfflineMessaging);
s.endGroup();
s.beginGroup("Advanced");
s.setValue("dbSyncType", static_cast<int>(dbSyncType));
s.endGroup();
s.beginGroup("Widgets");
const QList<QString> widgetNames = widgetSettings.keys();
for (const QString& name : widgetNames) {
@ -597,6 +607,19 @@ void Settings::setEncryptTox(bool newValue)
encryptTox = newValue;
}
Db::syncType Settings::getDbSyncType() const
{
return dbSyncType;
}
void Settings::setDbSyncType(int newValue)
{
if (newValue >= 0 && newValue <= 2)
dbSyncType = static_cast<Db::syncType>(newValue);
else
dbSyncType = Db::syncType::stFull;
}
int Settings::getAutoAwayTime() const
{
return autoAwayTime;

View File

@ -22,6 +22,7 @@
#include <QPixmap>
struct ToxID;
namespace Db { enum class syncType; }
class Settings : public QObject
{
@ -99,6 +100,9 @@ public:
bool getEncryptTox() const;
void setEncryptTox(bool newValue);
Db::syncType getDbSyncType() const;
void setDbSyncType(int newValue);
int getAutoAwayTime() const;
void setAutoAwayTime(int newValue);
@ -278,6 +282,7 @@ private:
// Privacy
bool typingNotification;
Db::syncType dbSyncType;
// Audio
QString inDev;

View File

@ -0,0 +1,62 @@
/*
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 "ui_advancedsettings.h"
#include "advancedform.h"
#include "src/historykeeper.h"
#include "src/misc/settings.h"
#include "src/misc/db/plaindb.h"
AdvancedForm::AdvancedForm() :
GenericForm(tr("Advanced"), QPixmap(":/img/settings/general.png"))
{
bodyUI = new Ui::AdvancedSettings;
bodyUI->setupUi(this);
bodyUI->dbLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
bodyUI->dbLabel->setOpenExternalLinks(true);
bodyUI->syncTypeComboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
bodyUI->syncTypeComboBox->addItems({"FULL - very safe, slowest (recommended)",
"NORMAL - almost as safe as FULL, about 20% faster than FULL",
"OFF - disables all safety, when something goes wrong your history may be lost, fastest (not recommended)"
});
int index = 2 - static_cast<int>(Settings::getInstance().getDbSyncType());
bodyUI->syncTypeComboBox->setCurrentIndex(index);
connect(bodyUI->syncTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onDbSyncTypeUpdated()));
connect(bodyUI->resetButton, SIGNAL(clicked()), this, SLOT(resetToDefault()));
}
AdvancedForm::~AdvancedForm()
{
delete bodyUI;
}
void AdvancedForm::onDbSyncTypeUpdated()
{
int index = 2 - bodyUI->syncTypeComboBox->currentIndex();
Settings::getInstance().setDbSyncType(index);
HistoryKeeper::getInstance()->setSyncType(Settings::getInstance().getDbSyncType());
}
void AdvancedForm::resetToDefault()
{
int index = 2 - static_cast<int>(Db::syncType::stFull);
bodyUI->syncTypeComboBox->setCurrentIndex(index);
onDbSyncTypeUpdated();
}

View File

@ -0,0 +1,43 @@
/*
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.
*/
#ifndef ADVANCEDFORM_H
#define ADVANCEDFORM_H
#include "genericsettings.h"
class Core;
namespace Ui {
class AdvancedSettings;
}
class AdvancedForm : public GenericForm
{
Q_OBJECT
public:
AdvancedForm();
virtual ~AdvancedForm();
private slots:
void onDbSyncTypeUpdated();
void resetToDefault();
private:
Ui::AdvancedSettings* bodyUI;
};
#endif // ADVANCEDFORM_H

View File

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AdvancedSettings</class>
<widget class="QWidget" name="AdvancedSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>380</width>
<height>280</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="warningLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; color:#ff0000;&quot;&gt;IMPORTANT NOTE&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; color:#ff0000;&quot;&gt;Unless you &lt;/span&gt;&lt;span style=&quot; font-weight:600; color:#ff0000;&quot;&gt;really&lt;/span&gt;&lt;span style=&quot; color:#ff0000;&quot;&gt; know what you are doing, please do &lt;/span&gt;&lt;span style=&quot; font-weight:600; color:#ff0000;&quot;&gt;not&lt;/span&gt;&lt;span style=&quot; color:#ff0000;&quot;&gt; change anything here. Changes made here may lead to problems with qTox, and even to loss of your data, e.g. history.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item alignment="Qt::AlignTop">
<widget class="QPushButton" name="resetButton">
<property name="text">
<string>Reset to default settings</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignTop">
<widget class="QGroupBox" name="historyGroup">
<property name="title">
<string>History</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="dbLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;http://www.sqlite.org/pragma.html#pragma_synchronous&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;Synchronous writing to DB&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="syncTypeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -22,6 +22,7 @@
#include "src/widget/form/settings/identityform.h"
#include "src/widget/form/settings/privacyform.h"
#include "src/widget/form/settings/avform.h"
#include "src/widget/form/settings/advancedform.h"
#include <QTabWidget>
SettingsWidget::SettingsWidget(QWidget* parent)
@ -54,8 +55,9 @@ SettingsWidget::SettingsWidget(QWidget* parent)
IdentityForm* ifrm = new IdentityForm;
PrivacyForm* pfrm = new PrivacyForm;
AVForm* avfrm = new AVForm;
AdvancedForm *expfrm = new AdvancedForm;
GenericForm* cfgForms[] = { gfrm, ifrm, pfrm, avfrm };
GenericForm* cfgForms[] = { gfrm, ifrm, pfrm, avfrm, expfrm };
for (GenericForm* cfgForm : cfgForms)
settingsWidgets->addTab(cfgForm, cfgForm->getFormIcon(), cfgForm->getFormName());