Skip to content

Commit e4e0a75

Browse files
refactor: add a new level of abstraction
1 parent 739530f commit e4e0a75

File tree

7 files changed

+87
-31
lines changed

7 files changed

+87
-31
lines changed

cmake/lemon-base.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set(LEMON_BASE_HEADERS
1414
${LEMON_BASEDIR_BASE}/LemonTranslator.hpp
1515
${LEMON_BASEDIR_BASE}/LemonUtils.hpp
1616
${LEMON_BASEDIR_BASE}/LemonBaseApplication.hpp
17+
${LEMON_BASEDIR_BASE}/LemonApplicationInterface.hpp
1718
)
1819

1920
set(LEMON_BASE_SOURCES
@@ -23,6 +24,7 @@ set(LEMON_BASE_SOURCES
2324
${LEMON_BASEDIR_BASE}/LemonTranslator.cpp
2425
${LEMON_BASEDIR_BASE}/LemonUtils.cpp
2526
${LEMON_BASEDIR_BASE}/LemonBaseApplication.cpp
27+
${LEMON_BASEDIR_BASE}/LemonApplicationInterface.cpp
2628
)
2729

2830
add_library(lemon-base STATIC

makespec/BUILDVERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
138
1+
139
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2021 Project LemonLime
3+
*
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*
6+
*/
7+
8+
#include "LemonApplicationInterface.hpp"
9+
//
10+
#include "base/LemonBase.hpp"
11+
#include "base/LemonLog.hpp"
12+
#include "base/LemonTranslator.hpp"
13+
#include "base/settings.h" // TODO: Config Refactor
14+
//
15+
#include <QCoreApplication>
16+
//
17+
#define LEMON_MODULE_NAME "LemonApplicationInterface"
18+
19+
using namespace Lemon;
20+
21+
LemonApplicationInterface::LemonApplicationInterface() {
22+
// ConfigObject = new LemonConfigObject;
23+
LemonCoreApplication = this;
24+
LOG("LemonLime", LEMON_VERSION_STRING, "on", QSysInfo::prettyProductName(),
25+
QSysInfo::currentCpuArchitecture());
26+
DEBUG("LemonLime Start Time: ", QTime::currentTime().msecsSinceStartOfDay());
27+
DEBUG(LEMON_BUILD_INFO);
28+
DEBUG(LEMON_BUILD_EXTRA_INFO);
29+
}
30+
31+
LemonApplicationInterface::~LemonApplicationInterface() {
32+
// delete ConfigObject;
33+
LemonCoreApplication = nullptr;
34+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2021 Project LemonLime
3+
*
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*
6+
*/
7+
8+
#pragma once
9+
//
10+
#include <QString>
11+
#include <QList>
12+
#include <QObject>
13+
14+
namespace Lemon {
15+
struct LemonStartupArguments {
16+
enum Argument {
17+
NORMAL = 0,
18+
EXIT = 1,
19+
LEMON_LINK = 2 // Maybe support URL...
20+
};
21+
QList<Argument> arguments;
22+
QString version;
23+
int buildVersion;
24+
QString data;
25+
QList<QString> links;
26+
QList<QString> fullArgs;
27+
//
28+
bool debugLog;
29+
bool exitLemon;
30+
};
31+
32+
class LemonApplicationInterface {
33+
34+
public:
35+
explicit LemonApplicationInterface();
36+
~LemonApplicationInterface();
37+
38+
Lemon::LemonStartupArguments StartupArguments;
39+
};
40+
41+
inline LemonApplicationInterface *LemonCoreApplication = nullptr;
42+
} // namespace Lemon

src/base/LemonBaseApplication.hpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,22 @@
88
#pragma once
99
//
1010
#include <SingleApplication>
11+
//
12+
#include "base/LemonApplicationInterface.hpp"
1113

1214
namespace Lemon {
13-
struct LemonStartupArguments {
14-
enum Argument {
15-
NORMAL = 0,
16-
EXIT = 1,
17-
LEMON_LINK = 2 // Maybe support URL...
18-
};
19-
QList<Argument> arguments;
20-
QString version;
21-
int buildVersion;
22-
QString data;
23-
QList<QString> links;
24-
QList<QString> fullArgs;
25-
//
26-
bool debugLog;
27-
bool exitLemon;
28-
};
29-
} // namespace Lemon
30-
31-
class LemonBaseApplication : public SingleApplication {
15+
class LemonBaseApplication : public SingleApplication, public LemonApplicationInterface {
3216
Q_OBJECT
3317

3418
public:
3519
LemonBaseApplication(int &argc, char *argv[])
36-
: SingleApplication(argc, argv, true, User | ExcludeAppPath | ExcludeAppVersion){};
20+
: SingleApplication(argc, argv, true, User | ExcludeAppPath | ExcludeAppVersion), LemonApplicationInterface(){};
3721
virtual ~LemonBaseApplication(){};
3822

39-
Lemon::LemonStartupArguments StartupArguments;
40-
4123
virtual bool Initialize() final;
4224

4325
private:
4426
bool parseCommandLine(bool *canContinue, QString *errorMessage);
4527
};
28+
} // namespace Lemon
29+

src/base/LemonLog.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace Lemon::base {
5656
logStream << NEWLINE;
5757
#ifndef QT_DEBUG
5858
// We only process DEBUG log in Release mode
59-
if (t == LEMON_LOG_DEBUG && LemonBaseApplication && !LemonBaseApplication->StartupArguments.debugLog) {
59+
if (t == LEMON_LOG_DEBUG && LemonCoreApplication && !LemonCoreApplication->StartupArguments.debugLog) {
6060
// Discard debug log in non-debug Lemon version with
6161
// no-debugLog mode.
6262
return;

src/main.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ int main(int argc, char *argv[]) {
2525
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
2626
#endif
2727

28-
LemonBaseApplication app(argc, argv);
29-
30-
LOG("LemonLime " LEMON_VERSION_STRING " on " + QSysInfo::prettyProductName() + " " +
31-
QSysInfo::currentCpuArchitecture());
32-
DEBUG("LemonLime Start Time: " + QString::number(QTime::currentTime().msecsSinceStartOfDay()));
33-
DEBUG(LEMON_BUILD_INFO);
34-
DEBUG(LEMON_BUILD_EXTRA_INFO);
28+
Lemon::LemonBaseApplication app(argc, argv);
3529

3630
app.Initialize();
3731

0 commit comments

Comments
 (0)