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

Commit

Permalink
Code refactoring (#15266)
Browse files Browse the repository at this point in the history
* Refactoring /deploy
* Refactoring /src #1
* Refactoring /src #2
* Code refactoring #3
* Code refactoring #4 (repl.*)
* Refactoring code #5
  • Loading branch information
pixiuPL authored Jan 15, 2018
1 parent 3dea9d9 commit 2c162ce
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 73 deletions.
10 changes: 0 additions & 10 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
#include <QFileInfo>
#include <QWebFrame>
#include <QWebPage>

#include "settings.h"

#include "consts.h"
#include "qcommandline.h"
#include "terminal.h"
Expand Down Expand Up @@ -90,19 +88,16 @@ Settings::Settings(QObject* parent)
// We will handle --help and --version ourselves in phantom.cpp
m_cmdLine->enableHelp(false);
m_cmdLine->enableVersion(false);

resetToDefaults();
}

void Settings::init(const QStringList* const args)
{
resetToDefaults();

QByteArray envSslCertDir = qgetenv("SSL_CERT_DIR");
if (!envSslCertDir.isEmpty()) {
setSslCertificatesPath(envSslCertDir);
}

processArgs(*args);
}

Expand All @@ -112,7 +107,6 @@ void Settings::processArgs(const QStringList& args)
connect(m_cmdLine, SIGNAL(optionFound(const QString&, const QVariant&)), this, SLOT(handleOption(const QString&, const QVariant&)));
connect(m_cmdLine, SIGNAL(paramFound(const QString&, const QVariant&)), this, SLOT(handleParam(const QString&, const QVariant&)));
connect(m_cmdLine, SIGNAL(parseError(const QString&)), this, SLOT(handleError(const QString&)));

m_cmdLine->setArguments(args);
m_cmdLine->setConfig(flags);
m_cmdLine->parse();
Expand Down Expand Up @@ -162,8 +156,6 @@ void Settings::loadJsonFile(const QString& filePath)
Terminal::instance()->cerr("File with settings MUST be in JSON format!");
return;
}

// TODO: Parse JSON
}

QString Settings::helpText() const
Expand Down Expand Up @@ -342,7 +334,6 @@ void Settings::setProxyAuth(const QString& value)
if (proxyUser.lastIndexOf(':') > 0) {
proxyPass = proxyUser.mid(proxyUser.lastIndexOf(':') + 1).trimmed();
proxyUser = proxyUser.left(proxyUser.lastIndexOf(':')).trimmed();

setProxyAuthUser(proxyUser);
setProxyAuthPass(proxyPass);
}
Expand Down Expand Up @@ -650,7 +641,6 @@ void Settings::handleSwitch(const QString& sw)
void Settings::handleOption(const QString& option, const QVariant& value)
{
bool boolValue = false;

QStringList booleanFlags;
booleanFlags << "debug";
booleanFlags << "disk-cache";
Expand Down
44 changes: 0 additions & 44 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
*/

#pragma once

#include <QNetworkProxy>
#include <QVariant>

class QCommandLine;

class Settings: public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -71,131 +69,91 @@ class Settings: public QObject
public:
Settings(QObject* parent = 0);
virtual ~Settings() = default;

void init(const QStringList* const args);
void processArgs(const QStringList& args);
void loadJsonFile(const QString& filePath);

QString helpText() const;

bool autoLoadImages() const;
void setAutoLoadImages(const bool value);

QString cookiesFile() const;
void setCookiesFile(const QString& cookiesFile);

QString offlineStoragePath() const;
void setOfflineStoragePath(const QString& value);

int offlineStorageDefaultQuota() const;
void setOfflineStorageDefaultQuota(int offlineStorageDefaultQuota);

QString localStoragePath() const;
void setLocalStoragePath(const QString& value);

int localStorageDefaultQuota() const;
void setLocalStorageDefaultQuota(int localStorageDefaultQuota);

bool diskCacheEnabled() const;
void setDiskCacheEnabled(const bool value);

int maxDiskCacheSize() const;
void setMaxDiskCacheSize(int maxDiskCacheSize);

QString diskCachePath() const;
void setDiskCachePath(const QString& value);

bool ignoreSslErrors() const;
void setIgnoreSslErrors(const bool value);

bool localUrlAccessEnabled() const;
void setLocalUrlAccessEnabled(const bool value);

bool localToRemoteUrlAccessEnabled() const;
void setLocalToRemoteUrlAccessEnabled(const bool value);

QString outputEncoding() const;
void setOutputEncoding(const QString& value);

QString proxyType() const;
void setProxyType(const QString& value);

QString proxy() const;
void setProxy(const QString& value);
QString proxyHost() const;
qint16 proxyPort() const;

QString proxyAuth() const;
void setProxyAuth(const QString& value);
QString proxyAuthUser() const;
QString proxyAuthPass() const;
void setProxyAuthUser(const QString& value);
void setProxyAuthPass(const QString& value);

QStringList scriptArgs() const;
void setScriptArgs(const QStringList& value);

QString scriptFile() const;
void setScriptFile(const QString& value);

QString unknownOption() const;
void setUnknownOption(const QString& value);

bool versionFlag() const;
void setVersionFlag(const bool value);

void setDebug(const bool value);
bool debug() const;

void setRemoteDebugPort(const int port);
int remoteDebugPort() const;

void setRemoteDebugAutorun(const bool value);
bool remoteDebugAutorun() const;

bool webSecurityEnabled() const;
void setWebSecurityEnabled(const bool value);

bool helpFlag() const;
void setHelpFlag(const bool value);

void setPrintDebugMessages(const bool value);
bool printDebugMessages() const;

void setJavascriptCanOpenWindows(const bool value);
bool javascriptCanOpenWindows() const;

void setJavascriptCanCloseWindows(const bool value);
bool javascriptCanCloseWindows() const;

void setSslProtocol(const QString& sslProtocolName);
QString sslProtocol() const;

void setSslCiphers(const QString& sslCiphersName);
QString sslCiphers() const;

void setSslCertificatesPath(const QString& sslCertificatesPath);
QString sslCertificatesPath() const;

void setSslClientCertificateFile(const QString& sslClientCertificateFile);
QString sslClientCertificateFile() const;

void setSslClientKeyFile(const QString& sslClientKeyFile);
QString sslClientKeyFile() const;

void setSslClientKeyPassphrase(const QByteArray& sslClientKeyPassphrase);
QByteArray sslClientKeyPassphrase() const;

void setWebdriver(const QString& webdriverConfig);
QString webdriver() const;
bool isWebdriverMode() const;

void setWebdriverLogFile(const QString& webdriverLogFile);
QString webdriverLogFile() const;

void setWebdriverLogLevel(const QString& webdriverLogLevel);
QString webdriverLogLevel() const;

void setWebdriverSeleniumGridHub(const QString& hubUrl);
QString webdriverSeleniumGridHub() const;

Expand All @@ -209,7 +167,6 @@ public Q_SLOTS:
void resetToDefaults();
void setProxyHost(const QString& value);
void setProxyPort(const int value);

QCommandLine* m_cmdLine;
bool m_autoLoadImages;
QString m_cookiesFile;
Expand Down Expand Up @@ -256,6 +213,5 @@ public Q_SLOTS:
QString m_webdriverLogFile;
QString m_webdriverLogLevel;
QString m_webdriverSeleniumGridHub;

Q_DISABLE_COPY(Settings);
};
4 changes: 2 additions & 2 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
#include <QSysInfo>
#include <QVariantMap>
#include <QTextCodec>

#include "env.h"
#include "system.h"
#include "terminal.h"

#if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
#include <sys/utsname.h>

QString getOSRelease()
{
QString release;
Expand Down
2 changes: 0 additions & 2 deletions src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@
*/

#pragma once

#include <QApplication>
#include <QObject>
#include <QStringList>
#include <QMap>
#include <QVariant>

#include "filesystem.h"

// This class implements the CommonJS System/1.0 spec.
Expand Down
2 changes: 0 additions & 2 deletions src/terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
*/

#include <iostream>

#include <QCoreApplication>

#include "terminal.h"

static Terminal* terminal_instance = 0;
Expand Down
2 changes: 0 additions & 2 deletions src/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
*/

#pragma once

#include <QObject>
#include <QString>

#include "encoding.h"

class Terminal: public QObject
Expand Down
5 changes: 1 addition & 4 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "utils.h"
#include "consts.h"
#include "terminal.h"

#include <QFile>
#include <QDebug>
#include <QDateTime>
Expand Down Expand Up @@ -86,9 +85,7 @@ static QString jsFromScriptFile(const QString& scriptPath, const QString& script
namespace Utils
{

bool printDebugMessages = false;

void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
bool printDebugMessages(void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
Q_UNUSED(context);
QString now = QDateTime::currentDateTime().toString(Qt::ISODate);
Expand Down
8 changes: 1 addition & 7 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,11 @@

#ifndef UTILS_H
#define UTILS_H

#include <QtGlobal>
#include "encoding.h"

class QWebFrame;

/**
* Aggregate common utility functions.
*/

namespace Utils
{

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

QString readResourceFileUtf8(const QString& resourceFilePath);

};
;

#endif // UTILS_H

0 comments on commit 2c162ce

Please sign in to comment.