Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(settings): add notification signals for changed settings values
Browse files Browse the repository at this point in the history
Makes changes to settings application wide transparent. The properties section is optional in theory, but comes in very handy, if we decide to access settings e.g. from within a script context.
  • Loading branch information
antis81 committed Aug 14, 2016
1 parent e4398c7 commit f00b900
Show file tree
Hide file tree
Showing 17 changed files with 740 additions and 229 deletions.
2 changes: 1 addition & 1 deletion src/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ bool Audio::initInput(const QString& deviceName)
return false;
}

d->setInputGain(Settings::getInstance().getAudioInGain());
d->setInputGain(Settings::getInstance().getAudioInGainDecibel());

qDebug() << "Opened audio input" << deviceName;
alcCaptureStart(alInDev);
Expand Down
12 changes: 7 additions & 5 deletions src/chatlog/chatlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class ChatLog : public QGraphicsView
void setTypingNotificationVisible(bool visible);
void scrollToLine(ChatLine::Ptr line);
void selectAll();
void forceRelayout();

QString getSelectedText() const;

Expand All @@ -67,6 +66,13 @@ class ChatLog : public QGraphicsView
signals:
void selectionChanged();

public slots:
void forceRelayout();

private slots:
void onSelectionTimerTimeout();
void onWorkerTimeout();

protected:
QRectF calculateSceneRect() const;
QRect getVisibleRect() const;
Expand Down Expand Up @@ -100,10 +106,6 @@ class ChatLog : public QGraphicsView

ChatLine::Ptr findLineByPosY(qreal yPos) const;

private slots:
void onSelectionTimerTimeout();
void onWorkerTimeout();

private:
void retranslateUi();
bool isActiveFileTransfer(ChatLine::Ptr l);
Expand Down
4 changes: 2 additions & 2 deletions src/chatlog/chatmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QSt
text = detectQuotes(detectAnchors(text), type);

//text styling
if (Settings::getInstance().getStylePreference() != NONE)
if (Settings::getInstance().getStylePreference() != Settings::StyleType::NONE)
text = detectStyle(text);

switch(type)
Expand Down Expand Up @@ -229,7 +229,7 @@ QString ChatMessage::detectStyle(const QString &str)
{
int mul = 0; // Determines how many characters to strip from text
// Set mul depending on styleownPreference
if (Settings::getInstance().getStylePreference() == WITHOUT_CHARS)
if (Settings::getInstance().getStylePreference() == Settings::StyleType::WITHOUT_CHARS)
mul = 2;

// Match captured string to corresponding style format
Expand Down
14 changes: 7 additions & 7 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ void Core::makeTox(QByteArray savedata)
// IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be disabled in options.
bool enableIPv6 = Settings::getInstance().getEnableIPv6();
bool forceTCP = Settings::getInstance().getForceTCP();
ProxyType proxyType = Settings::getInstance().getProxyType();
int proxyPort = Settings::getInstance().getProxyPort();
Settings::ProxyType proxyType = Settings::getInstance().getProxyType();
quint16 proxyPort = Settings::getInstance().getProxyPort();
QString proxyAddr = Settings::getInstance().getProxyAddr();
QByteArray proxyAddrData = proxyAddr.toUtf8();

Expand All @@ -147,7 +147,7 @@ void Core::makeTox(QByteArray savedata)
toxOptions.savedata_data = (uint8_t*)savedata.data();
toxOptions.savedata_length = savedata.size();

if (proxyType != ProxyType::ptNone)
if (proxyType != Settings::ProxyType::ptNone)
{
if (proxyAddr.length() > 255)
{
Expand All @@ -157,9 +157,9 @@ void Core::makeTox(QByteArray savedata)
{
qDebug() << "using proxy" << proxyAddr << ":" << proxyPort;
// protection against changings in TOX_PROXY_TYPE enum
if (proxyType == ProxyType::ptSOCKS5)
if (proxyType == Settings::ProxyType::ptSOCKS5)
toxOptions.proxy_type = TOX_PROXY_TYPE_SOCKS5;
else if (proxyType == ProxyType::ptHTTP)
else if (proxyType == Settings::ProxyType::ptHTTP)
toxOptions.proxy_type = TOX_PROXY_TYPE_HTTP;

toxOptions.proxy_host = proxyAddrData.data();
Expand Down Expand Up @@ -592,7 +592,7 @@ void Core::requestFriendship(const QString& friendAddress, const QString& messag
{
qDebug() << "Requested friendship of "<<friendId;
// Update our friendAddresses
Settings::getInstance().updateFriendAdress(friendAddress);
Settings::getInstance().updateFriendAddress(friendAddress);
QString inviteStr = tr("/me offers friendship.");
if (message.length())
inviteStr = tr("/me offers friendship, \"%1\"").arg(message);
Expand Down Expand Up @@ -1166,7 +1166,7 @@ bool Core::hasFriendWithPublicKey(const QString &pubkey) const
QString Core::getFriendAddress(uint32_t friendNumber) const
{
QString id = getFriendPublicKey(friendNumber);
QString addr = Settings::getInstance().getFriendAdress(id);
QString addr = Settings::getInstance().getFriendAddress(id);
if (addr.size() > id.size())
return addr;

Expand Down
37 changes: 30 additions & 7 deletions src/core/corestructs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,40 @@
#define TOX_HEX_ID_LENGTH 2*TOX_ADDRESS_SIZE

/**
@file corestructs.h
@brief Some headers use Core structs but don't need to include all of core.h
* @file corestructs.h
* @brief Some headers use Core structs but don't need to include all of core.h
*
* They should include this file directly instead to reduce compilation times
*
*
* @var ToxFile::fileKind Data file (default) or avatar
*/

They should include this file directly instead to reduce compilation times
*/
/**
* @brief Compare equal operator
* @param other the compared instance
* @return true, if equal; false otherwise
*/
bool DhtServer::operator==(const DhtServer& other) const
{
return this == &other ||
(port == other.port && address == other.address &&
userId == other.userId && name == other.name);
}

/**
@var uint8_t ToxFile::fileKind
@brief Data file (default) or avatar
*/
* @brief Compare not equal operator
* @param other the compared instance
* @return true, if not equal; false otherwise
*/
bool DhtServer::operator!=(const DhtServer& other) const
{
return !(*this == other);
}

/**
* @brief ToxFile constructor
*/
ToxFile::ToxFile(uint32_t fileNum, uint32_t friendId, QByteArray filename, QString filePath, FileDirection Direction)
: fileKind{TOX_FILE_KIND_DATA}, fileNum(fileNum), friendId(friendId), fileName{filename},
filePath{filePath}, file{new QFile(filePath)}, bytesSent{0}, filesize{0},
Expand Down
3 changes: 3 additions & 0 deletions src/core/corestructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ struct DhtServer
QString userId;
QString address;
quint16 port;

bool operator==(const DhtServer& other) const;
bool operator!=(const DhtServer& other) const;
};

struct ToxFile
Expand Down
2 changes: 1 addition & 1 deletion src/persistence/db/plaindb.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <QSqlDatabase>

namespace Db {
enum class syncType : int {stOff = 0, stNormal = 1, stFull = 2};
enum class syncType {stOff = 0, stNormal = 1, stFull = 2};
}

class PlainDb : public GenericDdInterface
Expand Down
5 changes: 4 additions & 1 deletion src/persistence/historykeeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@

class Profile;
class GenericDdInterface;
namespace Db { enum class syncType; }

namespace Db {
enum class syncType;
}

class HistoryKeeper
{
Expand Down
Loading

0 comments on commit f00b900

Please sign in to comment.