Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

Commit

Permalink
Added IPv6 option with IPv4 fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
nurupo committed Oct 17, 2014
1 parent 102a776 commit 101e51e
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 14 deletions.
8 changes: 6 additions & 2 deletions projectfiles/QtCreator/TOX-Qt-GUI.pro
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ SOURCES += \
../../src/Settings/dhtserverdialog.cpp \
../../src/Settings/customhintlistwidget.cpp \
../../src/Settings/loggingsettingspage.cpp \
../../src/Settings/networksettingspage.cpp \
../../src/aboutdialog.cpp \
../../src/emoticonmenu.cpp \
../../src/opacitywidget.cpp \
Expand Down Expand Up @@ -106,7 +107,8 @@ SOURCES += \
../../src/messages/messagefilter.cpp \
../../src/messages/chatviewsearchwidget.cpp \
../../src/Settings/privacysettingspage.cpp \
../../src/messages/typingitem.cpp
../../src/messages/typingitem.cpp \
../../src/Settings/informationiconlabel.cpp

HEADERS += \
../../src/mainwindow.hpp \
Expand Down Expand Up @@ -135,6 +137,7 @@ HEADERS += \
../../src/Settings/dhtserverdialog.hpp \
../../src/Settings/customhintlistwidget.hpp \
../../src/Settings/loggingsettingspage.hpp \
../../src/Settings/networksettingspage.hpp \
../../src/aboutdialog.hpp \
../../src/appinfo.hpp \
../../src/emoticonmenu.hpp \
Expand Down Expand Up @@ -164,7 +167,8 @@ HEADERS += \
../../src/messages/messagefilter.hpp \
../../src/messages/chatviewsearchwidget.hpp \
../../src/Settings/privacysettingspage.hpp \
../../src/messages/typingitem.hpp
../../src/messages/typingitem.hpp \
../../src/Settings/informationiconlabel.hpp

RESOURCES += \
../../resources/resources.qrc
Expand Down
Binary file added resources/icons/globe_network.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@
<file>icons/find.png</file>
<file>icons/text_uppercase.png</file>
<file>icons/eye.png</file>
<file>icons/globe_network.png</file>
</qresource>
</RCC>
35 changes: 35 additions & 0 deletions src/Settings/informationiconlabel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright (C) 2014 by Maxim Biro <nurupo.contributions@gmail.com>
This file is part of Tox Qt GUI.
This program is free 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 "informationiconlabel.hpp"

#include <QPainter>

InformationIconLabel::InformationIconLabel(QWidget *parent) :
QLabel(parent)
{
QImage image(":/icons/information.png");

// set alpha to 175
QPainter p;
p.begin(&image);
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
p.fillRect(image.rect(), QColor(0, 0, 0, 175));
p.end();

setPixmap(QPixmap::fromImage(image));
setFixedSize(16, 16);
}
30 changes: 30 additions & 0 deletions src/Settings/informationiconlabel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright (C) 2014 by Maxim Biro <nurupo.contributions@gmail.com>
This file is part of Tox Qt GUI.
This program is free 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 INFORMATIONICONLABEL_HPP
#define INFORMATIONICONLABEL_HPP

#include <QLabel>

class InformationIconLabel : public QLabel
{
Q_OBJECT
public:
explicit InformationIconLabel(QWidget *parent = 0);

};

#endif // INFORMATIONICONLABEL_HPP
8 changes: 4 additions & 4 deletions src/Settings/loggingsettingspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
See the COPYING file for more details.
*/

#include "settings.hpp"
#include "loggingsettingspage.hpp"

#include "informationiconlabel.hpp"
#include "settings.hpp"

#include <QLabel>
#include <QVBoxLayout>

Expand All @@ -43,9 +45,7 @@ QGroupBox* LoggingSettingsPage::buildLoggingGroup()

encryptLogsCheckBox = new QCheckBox("Encrypt logs", group);

QLabel* encryptLogsInfoLabel = new QLabel(group);
encryptLogsInfoLabel->setPixmap(QPixmap(":/icons/information.png"));
encryptLogsInfoLabel->setFixedSize(16, 16);
InformationIconLabel* encryptLogsInfoLabel = new InformationIconLabel(group);
encryptLogsInfoLabel->setToolTip(QString("%1\n%2").arg("It is highly recommended that you encrypt logs as a countermeasure to logs being stolen.", "Don't disable this option unless you have really good reasons for doing so."));

QHBoxLayout* encryptLogsLayout = new QHBoxLayout();
Expand Down
3 changes: 1 addition & 2 deletions src/Settings/loggingsettingspage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
#define LOGGINGSETTINGSPAGE_HPP

#include "abstractsettingspage.hpp"
#include "settings.hpp"

#include <QGroupBox>
#include <QCheckBox>
#include <QGroupBox>

class LoggingSettingsPage : public AbstractSettingsPage
{
Expand Down
85 changes: 85 additions & 0 deletions src/Settings/networksettingspage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright (C) 2014 by Maxim Biro <nurupo.contributions@gmail.com>
This file is part of Tox Qt GUI.
This program is free 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 "networksettingspage.hpp"

#include "informationiconlabel.hpp"
#include "settings.hpp"

#include <QCheckBox>
#include <QGroupBox>
#include <QVBoxLayout>

NetworkSettingsPage::NetworkSettingsPage(QWidget *parent) :
AbstractSettingsPage(parent)
{
}

void NetworkSettingsPage::buildGui()
{
QVBoxLayout *layout = new QVBoxLayout(this);

QGroupBox *networkGroup = buildNetworkGroup();

layout->addWidget(networkGroup);
layout->addStretch(0);
}

QGroupBox* NetworkSettingsPage::buildNetworkGroup()
{
QGroupBox *group = new QGroupBox("Network", this);
QVBoxLayout *layout = new QVBoxLayout(group);

enableIPv6CheckBox = new QCheckBox("Use IPv6", group);

InformationIconLabel *IPv6InfoIcon = new InformationIconLabel(group);
IPv6InfoIcon->setToolTip("Change requires client restart in order to take place");

enableIPv4FallbackCheckBox = new QCheckBox("Fallback to IPv4", group);

connect(enableIPv6CheckBox, &QCheckBox::stateChanged, this, &NetworkSettingsPage::IPv6CheckBoxStateChanged);

QHBoxLayout *IPv6Layout = new QHBoxLayout();
IPv6Layout->setSpacing(0);

IPv6Layout->addWidget(enableIPv6CheckBox);
IPv6Layout->addWidget(IPv6InfoIcon, 999, Qt::AlignHCenter | Qt::AlignLeft);

layout->addLayout(IPv6Layout);
layout->addWidget(enableIPv4FallbackCheckBox);

return group;
}

void NetworkSettingsPage::setGui()
{
const Settings& settings = Settings::getInstance();
enableIPv6CheckBox->setChecked(settings.isIPv6Enabled());
enableIPv4FallbackCheckBox->setChecked(settings.isIPv4FallbackEnabled());
IPv6CheckBoxStateChanged(enableIPv6CheckBox->isChecked() ? Qt::Checked : Qt::Unchecked);
}

void NetworkSettingsPage::applyChanges()
{
Settings& settings = Settings::getInstance();
settings.setIPv6Enabled(enableIPv6CheckBox->isChecked());
settings.setIPv4FallbackEnabled(enableIPv4FallbackCheckBox->isChecked());
}

void NetworkSettingsPage::IPv6CheckBoxStateChanged(int state) {
enableIPv4FallbackCheckBox->setEnabled(state == Qt::Checked);
}

44 changes: 44 additions & 0 deletions src/Settings/networksettingspage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright (C) 2014 by Maxim Biro <nurupo.contributions@gmail.com>
This file is part of Tox Qt GUI.
This program is free 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 NETWORKSETTINGSPAGE_HPP
#define NETWORKSETTINGSPAGE_HPP

#include "abstractsettingspage.hpp"

class QGroupBox;
class QCheckBox;

class NetworkSettingsPage : public AbstractSettingsPage
{
public:
NetworkSettingsPage(QWidget *parent);

void applyChanges();
void buildGui();
void setGui();

private:
QGroupBox *buildNetworkGroup();

QCheckBox *enableIPv6CheckBox;
QCheckBox *enableIPv4FallbackCheckBox;

private slots:
void IPv6CheckBoxStateChanged(int state);
};

#endif // NETWORKSETTINGSPAGE_HPP
30 changes: 30 additions & 0 deletions src/Settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ void Settings::load()
typingNotification = s.value("typingNotification", false).toBool();
s.endGroup();

s.beginGroup("Network");
enableIPv6 = s.value("enableIPv6", true).toBool();
enableIPv4Fallback = s.value("enableIPv4Fallback", true).toBool();
s.endGroup();

loaded = true;
}

Expand Down Expand Up @@ -166,6 +171,11 @@ void Settings::save()
s.beginGroup("Privacy");
s.setValue("typingNotification", typingNotification);
s.endGroup();

s.beginGroup("Network");
s.setValue("enableIPv6", enableIPv6);
s.setValue("enableIPv4Fallback", enableIPv4Fallback);
s.endGroup();
}

QString Settings::getSettingsDirPath()
Expand Down Expand Up @@ -351,3 +361,23 @@ void Settings::setTypingNotification(bool enabled)
{
typingNotification = enabled;
}

bool Settings::isIPv6Enabled() const
{
return enableIPv6;
}

void Settings::setIPv6Enabled(bool enabled)
{
enableIPv6 = enabled;
}

bool Settings::isIPv4FallbackEnabled() const
{
return enableIPv4Fallback;
}

void Settings::setIPv4FallbackEnabled(bool enabled)
{
enableIPv4Fallback = enabled;
}
11 changes: 11 additions & 0 deletions src/Settings/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ class Settings : public QObject
bool isTypingNotificationEnabled() const;
void setTypingNotification(bool enabled);

// Network
bool isIPv6Enabled() const;
void setIPv6Enabled(bool enabled);

bool isIPv4FallbackEnabled() const;
void setIPv4FallbackEnabled(bool enabled);

private:
Settings();
Settings(Settings &settings) = delete;
Expand Down Expand Up @@ -151,6 +158,10 @@ class Settings : public QObject
// Privacy
bool typingNotification;

// Network
bool enableIPv6;
bool enableIPv4Fallback;

signals:
//void dataChanged();
void dhtServerListChanged();
Expand Down
8 changes: 6 additions & 2 deletions src/Settings/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
See the COPYING file for more details.
*/

#include "dhtbootstrapsettingspage.hpp"
#include "loggingsettingspage.hpp"
#include "settingsdialog.hpp"

#include "dhtbootstrapsettingspage.hpp"
#include "guisettingspage.hpp"
#include "loggingsettingspage.hpp"
#include "networksettingspage.hpp"
#include "privacysettingspage.hpp"

SettingsDialog::SettingsDialog(QWidget* parent) :
Expand All @@ -30,12 +32,14 @@ SettingsDialog::SettingsDialog(QWidget* parent) :
//addPage(":/icons/database.png", "Logging", new LoggingSettingsPage(this));
addPage(":/icons/application_side_list.png", tr("GUI"), new GuiSettingsPage(this));
addPage(":/icons/eye.png", tr("Privacy"), new PrivacySettingsPage(this));
addPage(":/icons/globe_network.png", tr("Network"), new NetworkSettingsPage(this));

listWidget->setCurrentRow(0);
listWidget->setMinimumWidth(130);
setMinimumSize(450, 325);
}

// we should have only a single settings dialog at a time
int SettingsDialog::showDialog(QWidget* parent)
{
static SettingsDialog* dialog = nullptr;
Expand Down
Loading

0 comments on commit 101e51e

Please sign in to comment.