Skip to content

Commit 2c162ce

Browse files
author
pixiuPL
authored
Code refactoring (ariya#15266)
* Refactoring /deploy * Refactoring /src ariya#1 * Refactoring /src ariya#2 * Code refactoring ariya#3 * Code refactoring ariya#4 (repl.*) * Refactoring code ariya#5
1 parent 3dea9d9 commit 2c162ce

File tree

8 files changed

+4
-73
lines changed

8 files changed

+4
-73
lines changed

src/settings.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@
3535
#include <QFileInfo>
3636
#include <QWebFrame>
3737
#include <QWebPage>
38-
3938
#include "settings.h"
40-
4139
#include "consts.h"
4240
#include "qcommandline.h"
4341
#include "terminal.h"
@@ -90,19 +88,16 @@ Settings::Settings(QObject* parent)
9088
// We will handle --help and --version ourselves in phantom.cpp
9189
m_cmdLine->enableHelp(false);
9290
m_cmdLine->enableVersion(false);
93-
9491
resetToDefaults();
9592
}
9693

9794
void Settings::init(const QStringList* const args)
9895
{
9996
resetToDefaults();
100-
10197
QByteArray envSslCertDir = qgetenv("SSL_CERT_DIR");
10298
if (!envSslCertDir.isEmpty()) {
10399
setSslCertificatesPath(envSslCertDir);
104100
}
105-
106101
processArgs(*args);
107102
}
108103

@@ -112,7 +107,6 @@ void Settings::processArgs(const QStringList& args)
112107
connect(m_cmdLine, SIGNAL(optionFound(const QString&, const QVariant&)), this, SLOT(handleOption(const QString&, const QVariant&)));
113108
connect(m_cmdLine, SIGNAL(paramFound(const QString&, const QVariant&)), this, SLOT(handleParam(const QString&, const QVariant&)));
114109
connect(m_cmdLine, SIGNAL(parseError(const QString&)), this, SLOT(handleError(const QString&)));
115-
116110
m_cmdLine->setArguments(args);
117111
m_cmdLine->setConfig(flags);
118112
m_cmdLine->parse();
@@ -162,8 +156,6 @@ void Settings::loadJsonFile(const QString& filePath)
162156
Terminal::instance()->cerr("File with settings MUST be in JSON format!");
163157
return;
164158
}
165-
166-
// TODO: Parse JSON
167159
}
168160

169161
QString Settings::helpText() const
@@ -342,7 +334,6 @@ void Settings::setProxyAuth(const QString& value)
342334
if (proxyUser.lastIndexOf(':') > 0) {
343335
proxyPass = proxyUser.mid(proxyUser.lastIndexOf(':') + 1).trimmed();
344336
proxyUser = proxyUser.left(proxyUser.lastIndexOf(':')).trimmed();
345-
346337
setProxyAuthUser(proxyUser);
347338
setProxyAuthPass(proxyPass);
348339
}
@@ -650,7 +641,6 @@ void Settings::handleSwitch(const QString& sw)
650641
void Settings::handleOption(const QString& option, const QVariant& value)
651642
{
652643
bool boolValue = false;
653-
654644
QStringList booleanFlags;
655645
booleanFlags << "debug";
656646
booleanFlags << "disk-cache";

src/settings.h

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@
2929
*/
3030

3131
#pragma once
32-
3332
#include <QNetworkProxy>
3433
#include <QVariant>
3534

3635
class QCommandLine;
37-
3836
class Settings: public QObject
3937
{
4038
Q_OBJECT
@@ -71,131 +69,91 @@ class Settings: public QObject
7169
public:
7270
Settings(QObject* parent = 0);
7371
virtual ~Settings() = default;
74-
7572
void init(const QStringList* const args);
7673
void processArgs(const QStringList& args);
7774
void loadJsonFile(const QString& filePath);
78-
7975
QString helpText() const;
80-
8176
bool autoLoadImages() const;
8277
void setAutoLoadImages(const bool value);
83-
8478
QString cookiesFile() const;
8579
void setCookiesFile(const QString& cookiesFile);
86-
8780
QString offlineStoragePath() const;
8881
void setOfflineStoragePath(const QString& value);
89-
9082
int offlineStorageDefaultQuota() const;
9183
void setOfflineStorageDefaultQuota(int offlineStorageDefaultQuota);
92-
9384
QString localStoragePath() const;
9485
void setLocalStoragePath(const QString& value);
95-
9686
int localStorageDefaultQuota() const;
9787
void setLocalStorageDefaultQuota(int localStorageDefaultQuota);
98-
9988
bool diskCacheEnabled() const;
10089
void setDiskCacheEnabled(const bool value);
101-
10290
int maxDiskCacheSize() const;
10391
void setMaxDiskCacheSize(int maxDiskCacheSize);
104-
10592
QString diskCachePath() const;
10693
void setDiskCachePath(const QString& value);
107-
10894
bool ignoreSslErrors() const;
10995
void setIgnoreSslErrors(const bool value);
110-
11196
bool localUrlAccessEnabled() const;
11297
void setLocalUrlAccessEnabled(const bool value);
113-
11498
bool localToRemoteUrlAccessEnabled() const;
11599
void setLocalToRemoteUrlAccessEnabled(const bool value);
116-
117100
QString outputEncoding() const;
118101
void setOutputEncoding(const QString& value);
119-
120102
QString proxyType() const;
121103
void setProxyType(const QString& value);
122-
123104
QString proxy() const;
124105
void setProxy(const QString& value);
125106
QString proxyHost() const;
126107
qint16 proxyPort() const;
127-
128108
QString proxyAuth() const;
129109
void setProxyAuth(const QString& value);
130110
QString proxyAuthUser() const;
131111
QString proxyAuthPass() const;
132112
void setProxyAuthUser(const QString& value);
133113
void setProxyAuthPass(const QString& value);
134-
135114
QStringList scriptArgs() const;
136115
void setScriptArgs(const QStringList& value);
137-
138116
QString scriptFile() const;
139117
void setScriptFile(const QString& value);
140-
141118
QString unknownOption() const;
142119
void setUnknownOption(const QString& value);
143-
144120
bool versionFlag() const;
145121
void setVersionFlag(const bool value);
146-
147122
void setDebug(const bool value);
148123
bool debug() const;
149-
150124
void setRemoteDebugPort(const int port);
151125
int remoteDebugPort() const;
152-
153126
void setRemoteDebugAutorun(const bool value);
154127
bool remoteDebugAutorun() const;
155-
156128
bool webSecurityEnabled() const;
157129
void setWebSecurityEnabled(const bool value);
158-
159130
bool helpFlag() const;
160131
void setHelpFlag(const bool value);
161-
162132
void setPrintDebugMessages(const bool value);
163133
bool printDebugMessages() const;
164-
165134
void setJavascriptCanOpenWindows(const bool value);
166135
bool javascriptCanOpenWindows() const;
167-
168136
void setJavascriptCanCloseWindows(const bool value);
169137
bool javascriptCanCloseWindows() const;
170-
171138
void setSslProtocol(const QString& sslProtocolName);
172139
QString sslProtocol() const;
173-
174140
void setSslCiphers(const QString& sslCiphersName);
175141
QString sslCiphers() const;
176-
177142
void setSslCertificatesPath(const QString& sslCertificatesPath);
178143
QString sslCertificatesPath() const;
179-
180144
void setSslClientCertificateFile(const QString& sslClientCertificateFile);
181145
QString sslClientCertificateFile() const;
182-
183146
void setSslClientKeyFile(const QString& sslClientKeyFile);
184147
QString sslClientKeyFile() const;
185-
186148
void setSslClientKeyPassphrase(const QByteArray& sslClientKeyPassphrase);
187149
QByteArray sslClientKeyPassphrase() const;
188-
189150
void setWebdriver(const QString& webdriverConfig);
190151
QString webdriver() const;
191152
bool isWebdriverMode() const;
192-
193153
void setWebdriverLogFile(const QString& webdriverLogFile);
194154
QString webdriverLogFile() const;
195-
196155
void setWebdriverLogLevel(const QString& webdriverLogLevel);
197156
QString webdriverLogLevel() const;
198-
199157
void setWebdriverSeleniumGridHub(const QString& hubUrl);
200158
QString webdriverSeleniumGridHub() const;
201159

@@ -209,7 +167,6 @@ public Q_SLOTS:
209167
void resetToDefaults();
210168
void setProxyHost(const QString& value);
211169
void setProxyPort(const int value);
212-
213170
QCommandLine* m_cmdLine;
214171
bool m_autoLoadImages;
215172
QString m_cookiesFile;
@@ -256,6 +213,5 @@ public Q_SLOTS:
256213
QString m_webdriverLogFile;
257214
QString m_webdriverLogLevel;
258215
QString m_webdriverSeleniumGridHub;
259-
260216
Q_DISABLE_COPY(Settings);
261217
};

src/system.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
#include <QSysInfo>
3333
#include <QVariantMap>
3434
#include <QTextCodec>
35-
3635
#include "env.h"
3736
#include "system.h"
3837
#include "terminal.h"
3938

40-
#if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
39+
if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
4140
#include <sys/utsname.h>
41+
4242
QString getOSRelease()
4343
{
4444
QString release;

src/system.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@
2929
*/
3030

3131
#pragma once
32-
3332
#include <QApplication>
3433
#include <QObject>
3534
#include <QStringList>
3635
#include <QMap>
3736
#include <QVariant>
38-
3937
#include "filesystem.h"
4038

4139
// This class implements the CommonJS System/1.0 spec.

src/terminal.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
*/
3030

3131
#include <iostream>
32-
3332
#include <QCoreApplication>
34-
3533
#include "terminal.h"
3634

3735
static Terminal* terminal_instance = 0;

src/terminal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@
2929
*/
3030

3131
#pragma once
32-
3332
#include <QObject>
3433
#include <QString>
35-
3634
#include "encoding.h"
3735

3836
class Terminal: public QObject

src/utils.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "utils.h"
3232
#include "consts.h"
3333
#include "terminal.h"
34-
3534
#include <QFile>
3635
#include <QDebug>
3736
#include <QDateTime>
@@ -86,9 +85,7 @@ static QString jsFromScriptFile(const QString& scriptPath, const QString& script
8685
namespace Utils
8786
{
8887

89-
bool printDebugMessages = false;
90-
91-
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
88+
bool printDebugMessages(void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
9289
{
9390
Q_UNUSED(context);
9491
QString now = QDateTime::currentDateTime().toString(Qt::ISODate);

src/utils.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,11 @@
3030

3131
#ifndef UTILS_H
3232
#define UTILS_H
33-
3433
#include <QtGlobal>
3534
#include "encoding.h"
3635

3736
class QWebFrame;
3837

39-
/**
40-
* Aggregate common utility functions.
41-
*/
42-
4338
namespace Utils
4439
{
4540

@@ -73,7 +68,6 @@ bool loadJSForDebug(const QString& jsFilePath,
7368
const bool autorun = false);
7469

7570
QString readResourceFileUtf8(const QString& resourceFilePath);
76-
77-
};
71+
;
7872

7973
#endif // UTILS_H

0 commit comments

Comments
 (0)