Skip to content

Commit 13b9e39

Browse files
committed
Format C++ files using clang-format
1 parent 075e78a commit 13b9e39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1902
-1267
lines changed

.clang-format

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: Google
4+
5+
AccessModifierOffset: -2
6+
AllowAllParametersOfDeclarationOnNextLine: false
7+
AllowShortIfStatementsOnASingleLine: false
8+
BinPackArguments: false
9+
BinPackParameters: false
10+
BreakConstructorInitializers: AfterColon
11+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
12+
FixNamespaceComments: false
13+
SpaceAfterTemplateKeyword: false
14+
Standard: Cpp11
15+
...

CONTRIBUTING.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ LOOT's JavaScript uses a slightly tweaked version of the Airbnb style, and can b
7676

7777
### C++ Code Style
7878

79-
The [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html) is used as the base, with deviations as listed below.
79+
The [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html) is used as the base, with deviations as listed below. Formatting style is codified in the repository's `.clang-format` file, but is not enforced.
8080

8181
#### C++ Features
8282

@@ -91,8 +91,3 @@ The [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html)
9191

9292
* Constant, enumerator and variable names should use `camelCase` or `underscore_separators`, but they should be consistent within the same scope.
9393
* Function names should use `PascalCase` or `camelCase`, but they should be consistent within the same scope.
94-
95-
#### Formatting
96-
97-
* Line length doesn't matter.
98-
* `public`, `protected` and `private` keywords should not be indented within a class declaration.

src/gui/cef/loot_app.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424

2525
#include "gui/cef/loot_app.h"
2626

27-
#include <boost/locale.hpp>
28-
#include <boost/log/trivial.hpp>
2927
#include <include/views/cef_browser_view.h>
3028
#include <include/views/cef_window.h>
29+
#include <boost/locale.hpp>
30+
#include <boost/log/trivial.hpp>
3131

32-
#include "gui/state/loot_paths.h"
3332
#include "gui/cef/loot_handler.h"
3433
#include "gui/cef/loot_scheme_handler_factory.h"
3534
#include "gui/cef/window_delegate.h"
35+
#include "gui/state/loot_paths.h"
3636

3737
namespace loot {
3838
void LootApp::Initialise(const std::string& defaultGame,
@@ -44,12 +44,13 @@ void LootApp::Initialise(const std::string& defaultGame,
4444
url_ = url;
4545
}
4646

47-
void LootApp::OnBeforeCommandLineProcessing(const CefString& process_type,
48-
CefRefPtr<CefCommandLine> command_line) {
47+
void LootApp::OnBeforeCommandLineProcessing(
48+
const CefString& process_type,
49+
CefRefPtr<CefCommandLine> command_line) {
4950
if (process_type.empty()) {
50-
// Browser process, OK to modify the command line.
51+
// Browser process, OK to modify the command line.
5152

52-
// Disable spell checking.
53+
// Disable spell checking.
5354
command_line->AppendSwitch("--disable-spell-checking");
5455
command_line->AppendSwitch("--disable-extensions");
5556
}
@@ -64,14 +65,15 @@ CefRefPtr<CefRenderProcessHandler> LootApp::GetRenderProcessHandler() {
6465
}
6566

6667
void LootApp::OnContextInitialized() {
67-
//Make sure this is running in the UI thread.
68+
// Make sure this is running in the UI thread.
6869
assert(CefCurrentlyOn(TID_UI));
6970

7071
// Set the handler for browser-level callbacks.
7172
CefRefPtr<LootHandler> handler(new LootHandler(lootState_));
7273

7374
// Register the custom "loot" domain handler.
74-
CefRegisterSchemeHandlerFactory("http", "loot", new LootSchemeHandlerFactory());
75+
CefRegisterSchemeHandlerFactory(
76+
"http", "loot", new LootSchemeHandlerFactory());
7577

7678
// Specify CEF browser settings here.
7779
CefBrowserSettings browser_settings;
@@ -84,35 +86,37 @@ void LootApp::OnContextInitialized() {
8486
gen.add_messages_path(LootPaths::getL10nPath().string());
8587
gen.add_messages_domain("loot");
8688

87-
BOOST_LOG_TRIVIAL(debug) << "Selected language: " << lootState_.getLanguage();
89+
BOOST_LOG_TRIVIAL(debug)
90+
<< "Selected language: " << lootState_.getLanguage();
8891
std::locale::global(gen(lootState_.getLanguage() + ".UTF-8"));
8992
loot::InitialiseLocale(lootState_.getLanguage() + ".UTF-8");
9093
boost::filesystem::path::imbue(std::locale());
9194
}
9295

93-
CefRefPtr<CefBrowserView> browser_view = CefBrowserView::CreateBrowserView(handler, url_, browser_settings, NULL, NULL);
96+
CefRefPtr<CefBrowserView> browser_view = CefBrowserView::CreateBrowserView(
97+
handler, url_, browser_settings, NULL, NULL);
9498

9599
CefWindow::CreateTopLevelWindow(new WindowDelegate(browser_view, lootState_));
96100
}
97101

98102
void LootApp::OnWebKitInitialized() {
99-
// Create the renderer-side router for query handling.
103+
// Create the renderer-side router for query handling.
100104
CefMessageRouterConfig config;
101105
message_router_ = CefMessageRouterRendererSide::Create(config);
102106
}
103107

104-
bool LootApp::OnProcessMessageReceived(
105-
CefRefPtr<CefBrowser> browser,
106-
CefProcessId source_process,
107-
CefRefPtr<CefProcessMessage> message) {
108+
bool LootApp::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
109+
CefProcessId source_process,
110+
CefRefPtr<CefProcessMessage> message) {
108111
// Handle IPC messages from the browser process...
109-
return message_router_->OnProcessMessageReceived(browser, source_process, message);
112+
return message_router_->OnProcessMessageReceived(
113+
browser, source_process, message);
110114
}
111115

112116
void LootApp::OnContextCreated(CefRefPtr<CefBrowser> browser,
113117
CefRefPtr<CefFrame> frame,
114118
CefRefPtr<CefV8Context> context) {
115-
// Register javascript functions.
119+
// Register javascript functions.
116120
message_router_->OnContextCreated(browser, frame, context);
117121
}
118122
}

src/gui/cef/loot_app.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,39 @@
2525
#ifndef LOOT_GUI_LOOT_APP
2626
#define LOOT_GUI_LOOT_APP
2727

28-
#include <include/cef_app.h>
2928
#include <include/base/cef_lock.h>
29+
#include <include/cef_app.h>
3030
#include <include/wrapper/cef_message_router.h>
3131

3232
#include "gui/state/loot_state.h"
3333

3434
namespace loot {
3535
class LootApp : public CefApp,
36-
public CefBrowserProcessHandler,
37-
public CefRenderProcessHandler {
36+
public CefBrowserProcessHandler,
37+
public CefRenderProcessHandler {
3838
public:
3939
void Initialise(const std::string& defaultGame,
4040
const std::string& gameAppDataPath,
4141
const std::string& lootDataPath,
4242
const std::string& url);
4343

4444
// Override CefApp methods.
45-
virtual void OnBeforeCommandLineProcessing(const CefString& process_type,
46-
CefRefPtr<CefCommandLine> command_line);
47-
virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() OVERRIDE;
45+
virtual void OnBeforeCommandLineProcessing(
46+
const CefString& process_type,
47+
CefRefPtr<CefCommandLine> command_line);
48+
virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler()
49+
OVERRIDE;
4850
virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() OVERRIDE;
4951

5052
// Override CefBrowserProcessHandler methods.
5153
virtual void OnContextInitialized() OVERRIDE;
5254
virtual void OnWebKitInitialized() OVERRIDE;
5355

5456
// Override CefRenderProcessHandler methods.
55-
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
56-
CefProcessId source_process,
57-
CefRefPtr<CefProcessMessage> message) OVERRIDE;
57+
virtual bool OnProcessMessageReceived(
58+
CefRefPtr<CefBrowser> browser,
59+
CefProcessId source_process,
60+
CefRefPtr<CefProcessMessage> message) OVERRIDE;
5861

5962
private:
6063
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,

src/gui/cef/loot_handler.cpp

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,36 @@
2828
#include <sstream>
2929
#include <string>
3030

31-
#include <boost/algorithm/string.hpp>
32-
#include <boost/filesystem.hpp>
33-
#include <boost/log/trivial.hpp>
3431
#include <include/cef_app.h>
3532
#include <include/views/cef_browser_view.h>
3633
#include <include/views/cef_window.h>
34+
#include <boost/algorithm/string.hpp>
35+
#include <boost/filesystem.hpp>
36+
#include <boost/log/trivial.hpp>
3737

38-
#include "gui/state/loot_paths.h"
39-
#include "gui/helpers.h"
4038
#include "gui/cef/loot_scheme_handler_factory.h"
4139
#include "gui/cef/query/query_handler.h"
40+
#include "gui/helpers.h"
41+
#include "gui/state/loot_paths.h"
4242

4343
namespace loot {
4444
LootHandler::LootHandler(LootState& lootState) : lootState_(lootState) {}
4545

4646
// CefClient methods
4747
//------------------
4848

49-
CefRefPtr<CefDisplayHandler> LootHandler::GetDisplayHandler() {
50-
return this;
51-
}
49+
CefRefPtr<CefDisplayHandler> LootHandler::GetDisplayHandler() { return this; }
5250

53-
CefRefPtr<CefLifeSpanHandler> LootHandler::GetLifeSpanHandler() {
54-
return this;
55-
}
51+
CefRefPtr<CefLifeSpanHandler> LootHandler::GetLifeSpanHandler() { return this; }
5652

57-
CefRefPtr<CefLoadHandler> LootHandler::GetLoadHandler() {
58-
return this;
59-
}
53+
CefRefPtr<CefLoadHandler> LootHandler::GetLoadHandler() { return this; }
6054

61-
bool LootHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
62-
CefProcessId source_process,
63-
CefRefPtr<CefProcessMessage> message) {
64-
return browser_side_router_->OnProcessMessageReceived(browser, source_process, message);
55+
bool LootHandler::OnProcessMessageReceived(
56+
CefRefPtr<CefBrowser> browser,
57+
CefProcessId source_process,
58+
CefRefPtr<CefProcessMessage> message) {
59+
return browser_side_router_->OnProcessMessageReceived(
60+
browser, source_process, message);
6561
}
6662

6763
// CefLifeSpanHandler methods
@@ -85,26 +81,30 @@ bool LootHandler::DoClose(CefRefPtr<CefBrowser> browser) {
8581

8682
// Check if unapplied changes exist.
8783
if (lootState_.hasUnappliedChanges()) {
88-
browser->GetMainFrame()->ExecuteJavaScript("onQuit();", browser->GetMainFrame()->GetURL(), 0);
84+
browser->GetMainFrame()->ExecuteJavaScript(
85+
"onQuit();", browser->GetMainFrame()->GetURL(), 0);
8986
return true;
9087
}
9188

9289
auto browserView = CefBrowserView::GetForBrowser(browser);
9390
if (browserView == nullptr) {
94-
BOOST_LOG_TRIVIAL(error) << "Failed to save LOOT's settings, browser view is null";
91+
BOOST_LOG_TRIVIAL(error)
92+
<< "Failed to save LOOT's settings, browser view is null";
9593
return false;
9694
}
9795

9896
auto window = browserView->GetWindow();
9997
if (window == nullptr) {
100-
BOOST_LOG_TRIVIAL(error) << "Failed to save LOOT's settings, window is null";
98+
BOOST_LOG_TRIVIAL(error)
99+
<< "Failed to save LOOT's settings, window is null";
101100
return false;
102101
}
103102

104103
LootSettings::WindowPosition position;
105104
position.maximised = window->IsMaximized();
106105

107-
// Un-maximise the window so that the non-maximised size and position are recorded.
106+
// Un-maximise the window so that the non-maximised size and position are
107+
// recorded.
108108
window->Restore();
109109

110110
CefRect windowBounds = window->GetBoundsInScreen();
@@ -116,9 +116,9 @@ bool LootHandler::DoClose(CefRefPtr<CefBrowser> browser) {
116116

117117
try {
118118
lootState_.save(LootPaths::getSettingsPath());
119-
}
120-
catch (std::exception &e) {
121-
BOOST_LOG_TRIVIAL(error) << "Failed to save LOOT's settings. Error: " << e.what();
119+
} catch (std::exception& e) {
120+
BOOST_LOG_TRIVIAL(error)
121+
<< "Failed to save LOOT's settings. Error: " << e.what();
122122
}
123123

124124
// Allow the close. For windowed browsers this will result in the OS close
@@ -133,15 +133,17 @@ void LootHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
133133
browser_side_router_->OnBeforeClose(browser);
134134

135135
// Remove from the list of existing browsers.
136-
for (BrowserList::iterator bit = browser_list_.begin(); bit != browser_list_.end(); ++bit) {
136+
for (BrowserList::iterator bit = browser_list_.begin();
137+
bit != browser_list_.end();
138+
++bit) {
137139
if ((*bit)->IsSame(browser)) {
138140
browser_list_.erase(bit);
139141
break;
140142
}
141143
}
142144

143145
if (browser_list_.empty()) {
144-
// All browser windows have closed. Quit the application message loop.
146+
// All browser windows have closed. Quit the application message loop.
145147
CefQuitMessageLoop();
146148
}
147149
}
@@ -160,50 +162,55 @@ void LootHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
160162
if (errorCode == ERR_ABORTED)
161163
return;
162164

163-
// Display a load error message.
165+
// Display a load error message.
164166
std::stringstream ss;
165167
ss << "<html><body bgcolor=\"white\">"
166-
<< "<h2>Failed to load URL " << std::string(failedUrl)
167-
<< " with error " << std::string(errorText) << " (" << errorCode
168-
<< ").</h2></body></html>";
168+
<< "<h2>Failed to load URL " << std::string(failedUrl) << " with error "
169+
<< std::string(errorText) << " (" << errorCode << ").</h2></body></html>";
169170

170171
frame->LoadString(ss.str(), failedUrl);
171172
}
172173

173174
// CefRequestHandler methods
174175
//--------------------------
175176

176-
CefRefPtr<CefRequestHandler> LootHandler::GetRequestHandler() {
177-
return this;
178-
}
177+
CefRefPtr<CefRequestHandler> LootHandler::GetRequestHandler() { return this; }
179178

180-
bool LootHandler::OnBeforeBrowse(CefRefPtr< CefBrowser > browser,
181-
CefRefPtr< CefFrame > frame,
182-
CefRefPtr< CefRequest > request,
179+
bool LootHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
180+
CefRefPtr<CefFrame> frame,
181+
CefRefPtr<CefRequest> request,
183182
bool is_redirect) {
184-
BOOST_LOG_TRIVIAL(trace) << "Attempting to open link: " << request->GetURL().ToString();
183+
BOOST_LOG_TRIVIAL(trace) << "Attempting to open link: "
184+
<< request->GetURL().ToString();
185185

186186
const std::string url = request->GetURL().ToString();
187187
if (boost::starts_with(url, "http://loot/")) {
188-
BOOST_LOG_TRIVIAL(trace) << "Link is to LOOT page, allowing CEF's default handling.";
188+
BOOST_LOG_TRIVIAL(trace)
189+
<< "Link is to LOOT page, allowing CEF's default handling.";
189190
return false;
190191
} else if (boost::starts_with(url, "http://localhost:")) {
191-
BOOST_LOG_TRIVIAL(warning) << "Link is to a page on localhost, if this isn't happening while running tests, something has gone wrong";
192+
BOOST_LOG_TRIVIAL(warning) << "Link is to a page on localhost, if this "
193+
"isn't happening while running tests, "
194+
"something has gone wrong";
192195
return false;
193196
}
194197

195198
BOOST_LOG_TRIVIAL(info) << "Opening link in Windows' default handler.";
196-
OpenInDefaultApplication(boost::filesystem::path(request->GetURL().ToString()));
199+
OpenInDefaultApplication(
200+
boost::filesystem::path(request->GetURL().ToString()));
197201

198202
return true;
199203
}
200204

201-
CefRequestHandler::ReturnValue LootHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
202-
CefRefPtr<CefFrame> frame,
203-
CefRefPtr<CefRequest> request,
204-
CefRefPtr<CefRequestCallback> callback) {
205-
if (boost::starts_with(request->GetURL().ToString(), "https://fonts.googleapis.com")) {
206-
BOOST_LOG_TRIVIAL(warning) << "Blocking load of resource at " << request->GetURL().ToString();
205+
CefRequestHandler::ReturnValue LootHandler::OnBeforeResourceLoad(
206+
CefRefPtr<CefBrowser> browser,
207+
CefRefPtr<CefFrame> frame,
208+
CefRefPtr<CefRequest> request,
209+
CefRefPtr<CefRequestCallback> callback) {
210+
if (boost::starts_with(request->GetURL().ToString(),
211+
"https://fonts.googleapis.com")) {
212+
BOOST_LOG_TRIVIAL(warning)
213+
<< "Blocking load of resource at " << request->GetURL().ToString();
207214
return RV_CANCEL;
208215
}
209216

0 commit comments

Comments
 (0)