Skip to content

Commit

Permalink
Start 3.0 dev with libQtShadowsocks 2.0 dev
Browse files Browse the repository at this point in the history
  • Loading branch information
librehat committed Sep 22, 2017
1 parent ba961cd commit eace99f
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 107 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.1)

project(Shadowsocks-Qt5
VERSION 2.10.0
VERSION 3.0.0
LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
Expand All @@ -21,7 +21,7 @@ if(UNIX AND NOT APPLE)
endif()
find_package(PkgConfig)

pkg_check_modules(QSS REQUIRED QtShadowsocks>=1.10.0)
pkg_check_modules(QSS REQUIRED QtShadowsocks>=2.0.0)
find_library(QSS_LIBRARY_VAR
NAMES ${QSS_LIBRARIES}
HINTS ${QSS_LIBRARY_DIRS} ${QSS_LIBDIR})
Expand Down
7 changes: 0 additions & 7 deletions src/confighelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,6 @@ void ConfigHelper::read(ConnectionTableModel *model)
QVariant value = settings->value("SQProfile");
SQProfile profile = value.value<SQProfile>();
checkProfileDataUsageReset(profile);
if (configVer < 2.5) {
profile.httpMode = false;
}
if (configVer < 2.6) {
qCritical() << "configVer" << configVer << " < 2.6";
profile.onetimeAuth = false;
}
Connection *con = new Connection(profile, this);
model->appendConnection(con);
}
Expand Down
29 changes: 6 additions & 23 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@ const QString& Connection::getName() const
return profile.name;
}

const QString& Connection::getLog() const
{
return log;
}

QByteArray Connection::getURI() const
{
return profile.toProfile().toURI();
std::string uri = profile.toProfile().toUriSip002();
return QByteArray(uri.data(), uri.length());
}

bool Connection::isValid() const
Expand Down Expand Up @@ -84,20 +80,15 @@ void Connection::start()
if (controller) {
controller->deleteLater();
}
controller = new QSS::Controller(true, false, this);
controller = new QSS::Controller(qssprofile, true, false, this);
connect(controller, &QSS::Controller::runningStateChanged, [&](bool run){
running = run;
emit stateChanged(run);
});
connect(controller, &QSS::Controller::tcpLatencyAvailable, this, &Connection::onLatencyAvailable);
connect(controller, &QSS::Controller::newBytesReceived, this, &Connection::onNewBytesTransmitted);
connect(controller, &QSS::Controller::newBytesSent, this, &Connection::onNewBytesTransmitted);
connect(controller, &QSS::Controller::info, this, &Connection::onNewLog);
if (profile.debug) {
connect(controller, &QSS::Controller::debug, this, &Connection::onNewLog);
}

controller->setup(qssprofile);
if (!controller->start()) {
emit startFailed();
}
Expand All @@ -117,7 +108,8 @@ void Connection::testAddressLatency(const QHostAddress &addr)
QSS::AddressTester *addrTester = new QSS::AddressTester(addr, profile.serverPort, this);
connect(addrTester, &QSS::AddressTester::connectivityTestFinished, this, &Connection::onConnectivityTestFinished, Qt::QueuedConnection);
connect(addrTester, &QSS::AddressTester::lagTestFinished, this, &Connection::onLatencyAvailable, Qt::QueuedConnection);
addrTester->startConnectivityTest(profile.method, profile.password, profile.onetimeAuth);
QSS::Profile qProfile = profile.toProfile();
addrTester->startConnectivityTest(qProfile.method(), qProfile.password());
}

void Connection::onNewBytesTransmitted(const quint64 &b)
Expand All @@ -127,15 +119,6 @@ void Connection::onNewBytesTransmitted(const quint64 &b)
emit dataUsageChanged(profile.currentUsage, profile.totalUsage);
}

void Connection::onNewLog(const QString &str)
{
if(!log.endsWith('\n') && !log.isEmpty()) {
log.append('\n');
}
log.append(str);
emit newLogAvailable(str);
}

void Connection::onServerAddressLookedUp(const QHostInfo &host)
{
if (host.error() == QHostInfo::NoError) {
Expand All @@ -157,7 +140,7 @@ void Connection::onConnectivityTestFinished(bool con)
if (!con) {
disconnect(tester, &QSS::AddressTester::lagTestFinished, this, &Connection::onLatencyAvailable);
this->onLatencyAvailable(SQProfile::LATENCY_ERROR);
onNewLog(QStringLiteral("Internet connectivity test failed. Please check the connection's profile and your firewall settings."));
qWarning("Internet connectivity test failed. Please check the connection's profile and your firewall settings.");
}
tester->deleteLater();
}
4 changes: 0 additions & 4 deletions src/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class Connection : public QObject

const SQProfile &getProfile() const;
const QString &getName() const;
const QString &getLog() const;
QByteArray getURI() const;
bool isValid() const;
const bool &isRunning() const;
Expand All @@ -55,19 +54,16 @@ public slots:
QSS::Controller *controller;
SQProfile profile;
bool running;
QString log;

void testAddressLatency(const QHostAddress &addr);

friend class EditDialog;
friend class ConfigHelper;
friend class StatusDialog;
friend class LogDialog;
friend class ConnectionItem;

private slots:
void onNewBytesTransmitted(const quint64 &);
void onNewLog(const QString &);
void onServerAddressLookedUp(const QHostInfo &host);
void onLatencyAvailable(const int);
void onConnectivityTestFinished(bool);
Expand Down
2 changes: 0 additions & 2 deletions src/editdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ EditDialog::EditDialog(Connection *_connection, QWidget *parent) :
ui->httpRadioButton->setChecked(connection->profile.httpMode);
ui->pwdEdit->setText(connection->profile.password);
ui->encryptComboBox->setCurrentText(connection->profile.method.toUpper());
ui->otaCheckBox->setChecked(connection->profile.onetimeAuth);
ui->timeoutSpinBox->setValue(connection->profile.timeout);
ui->resetDateEdit->setDate(connection->profile.nextResetDate);
ui->resetDateEdit->setMinimumDate(QDate::currentDate());
Expand Down Expand Up @@ -61,7 +60,6 @@ void EditDialog::save()
connection->profile.nextResetDate = ui->resetDateEdit->date();
connection->profile.autoStart = ui->autoStartCheckBox->isChecked();
connection->profile.debug = ui->debugCheckBox->isChecked();
connection->profile.onetimeAuth = ui->otaCheckBox->isChecked();

this->accept();
}
27 changes: 8 additions & 19 deletions src/editdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@
</property>
</widget>
</item>
<item row="9" column="0">
<item row="8" column="0">
<widget class="QLabel" name="timeoutLabel">
<property name="text">
<string>Timeout</string>
</property>
</widget>
</item>
<item row="9" column="1">
<item row="8" column="1">
<widget class="QSpinBox" name="timeoutSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
Expand All @@ -181,14 +181,14 @@
</property>
</widget>
</item>
<item row="10" column="0">
<item row="9" column="0">
<widget class="QLabel" name="resetDateLabel">
<property name="text">
<string>Reset Data Usage after</string>
</property>
</widget>
</item>
<item row="10" column="1">
<item row="9" column="1">
<widget class="QDateEdit" name="resetDateEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
Expand All @@ -201,14 +201,14 @@
</property>
</widget>
</item>
<item row="11" column="0">
<item row="10" column="0">
<widget class="QLabel" name="autoStartLabel">
<property name="text">
<string>Automation</string>
</property>
</widget>
</item>
<item row="11" column="1">
<item row="10" column="1">
<widget class="QCheckBox" name="autoStartCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
Expand All @@ -221,14 +221,14 @@
</property>
</widget>
</item>
<item row="12" column="0">
<item row="11" column="0">
<widget class="QLabel" name="logLevelLabel">
<property name="text">
<string>Log Level</string>
</property>
</widget>
</item>
<item row="12" column="1">
<item row="11" column="1">
<widget class="QCheckBox" name="debugCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
Expand All @@ -241,16 +241,6 @@
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="otaCheckBox">
<property name="toolTip">
<string>[Deprecated] Turn on one-time authentication and header verification (need server support)</string>
</property>
<property name="text">
<string>One-time authentication</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -289,7 +279,6 @@
<tabstop>socks5RadioButton</tabstop>
<tabstop>httpRadioButton</tabstop>
<tabstop>encryptComboBox</tabstop>
<tabstop>otaCheckBox</tabstop>
<tabstop>timeoutSpinBox</tabstop>
<tabstop>resetDateEdit</tabstop>
<tabstop>autoStartCheckBox</tabstop>
Expand Down
14 changes: 2 additions & 12 deletions src/logdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
#include "ui_logdialog.h"
#include <QFileDialog>

LogDialog::LogDialog(Connection *c, QWidget *parent) :
LogDialog::LogDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::LogDialog),
con(c)
ui(new Ui::LogDialog)
{
ui->setupUi(this);
ui->logBrowser->setText(con->log);
ui->logBrowser->moveCursor(QTextCursor::End);

connect(con, &Connection::newLogAvailable, this, &LogDialog::append);
connect(ui->clearButton, &QPushButton::clicked, this, &LogDialog::onClearClicked);
connect(ui->saveAsButton, &QPushButton::clicked, this, &LogDialog::onSaveClicked);

Expand All @@ -23,12 +20,6 @@ LogDialog::~LogDialog()
delete ui;
}

void LogDialog::append(const QString &str)
{
ui->logBrowser->append(str);
ui->logBrowser->moveCursor(QTextCursor::End);
}

void LogDialog::onSaveClicked()
{
QString file = QFileDialog::getSaveFileName(this, tr("Save Log As"));
Expand All @@ -44,5 +35,4 @@ void LogDialog::onSaveClicked()
void LogDialog::onClearClicked()
{
ui->logBrowser->clear();
con->log.clear();
}
4 changes: 1 addition & 3 deletions src/logdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ class LogDialog : public QDialog
Q_OBJECT

public:
explicit LogDialog(Connection *c, QWidget *parent = 0);
explicit LogDialog(QWidget *parent = 0);
~LogDialog();

private:
Ui::LogDialog *ui;
Connection *con;

private slots:
void append(const QString &);
void onSaveClicked();
void onClearClicked();
};
Expand Down
7 changes: 2 additions & 5 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,7 @@ void MainWindow::onLatencyTest()

void MainWindow::onViewLog()
{
Connection *con = model->getItem(
proxyModel->mapToSource(ui->connectionView->currentIndex()).
row())->getConnection();
LogDialog *logDlg = new LogDialog(con, this);
LogDialog *logDlg = new LogDialog(this);
connect(logDlg, &LogDialog::finished, logDlg, &LogDialog::deleteLater);
logDlg->exec();
}
Expand Down Expand Up @@ -456,7 +453,7 @@ void MainWindow::onAbout()
"<a href='https://github.com/shadowsocks/shadowsocks-qt5'>"
"GitHub</a></p>")
.arg(QStringLiteral(APP_VERSION))
.arg(QSS::Common::version().data());
.arg(QSS::Common::version());
QMessageBox::about(this, tr("About"), text);
}

Expand Down
Loading

0 comments on commit eace99f

Please sign in to comment.