Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Many edits with strings, vars, constructors and code refactor #4823

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/color_convert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TogglRgbColor ColorConverter::GetRgbAdaptiveColor(const std::string &hexColor, T
return hsvToRgb(hsv);
}

TogglHsvColor ColorConverter::adjustColor(TogglHsvColor hsvColor, TogglAdaptiveColor type) {
TogglHsvColor ColorConverter::adjustColor(const TogglHsvColor &hsvColor, TogglAdaptiveColor type) {
switch (type) {
case AdaptiveColorShapeOnLightBackground:
return { hsvColor.h, hsvColor.s, hsvColor.v };
Expand All @@ -49,7 +49,7 @@ TogglHsvColor ColorConverter::adjustColor(TogglHsvColor hsvColor, TogglAdaptiveC
return hsvColor;
}

TogglHsvColor ColorConverter::rgbToHsv(TogglRgbColor rgbColor)
TogglHsvColor ColorConverter::rgbToHsv(const TogglRgbColor &rgbColor)
{
double r = rgbColor.r;
double g = rgbColor.g;
Expand Down Expand Up @@ -104,7 +104,7 @@ TogglRgbColor ColorConverter::hexToRgb(std::string hex)
return { r, g, b };
}

TogglRgbColor ColorConverter::hsvToRgb(TogglHsvColor hsvColor) {
TogglRgbColor ColorConverter::hsvToRgb(const TogglHsvColor &hsvColor) {
double h = hsvColor.h;
double s = hsvColor.s;
double v = hsvColor.v;
Expand Down
7 changes: 3 additions & 4 deletions src/color_convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ class TOGGL_INTERNAL_EXPORT ColorConverter {
static TogglRgbColor GetRgbAdaptiveColor(const std::string &hexColor, TogglAdaptiveColor type);

private:
static TogglHsvColor adjustColor(TogglHsvColor hsvColor, TogglAdaptiveColor type);
static TogglHsvColor rgbToHsv(TogglRgbColor rgbColor);
static TogglHsvColor adjustColor(const TogglHsvColor &hsvColor, TogglAdaptiveColor type);
static TogglHsvColor rgbToHsv(const TogglRgbColor &rgbColor);
static TogglRgbColor hexToRgb(std::string hex);
static std::string rgbToHex(TogglRgbColor rbg);
static TogglRgbColor hsvToRgb(TogglHsvColor hsvColor);
static TogglRgbColor hsvToRgb(const TogglHsvColor &hsvColor);
};

}
Expand Down
61 changes: 31 additions & 30 deletions src/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ void Context::updateUI(const UIElements &what) {

if (what.display_time_entries && user_) {
if (what.open_time_entry_list) {
time_entry_editor_guid_ = "";
time_entry_editor_guid_.clear();
}

// Get a sorted list of time entries
Expand All @@ -683,7 +683,7 @@ void Context::updateUI(const UIElements &what) {
std::map<std::string, Poco::UInt64> group_header_id;
std::map<std::string, std::vector<Poco::UInt64> > group_items;

for (unsigned int i = 0; i < time_entries.size(); i++) {
for (size_t i = 0; i < time_entries.size(); i++) {
TimeEntry *te = time_entries[i];

std::string date_header =
Expand Down Expand Up @@ -715,7 +715,7 @@ void Context::updateUI(const UIElements &what) {
}

// Assign the date durations we calculated previously
for (unsigned int i = 0; i < time_entries.size(); i++) {
for (size_t i = 0; i < time_entries.size(); i++) {
TimeEntry *te = time_entries[i];

// Dont render running entry in list,
Expand All @@ -734,7 +734,7 @@ void Context::updateUI(const UIElements &what) {
if (group_header_id[view.GroupName] == i) {
// If Group open add all entries in group
if (entry_groups[view.GroupName]) {
for (unsigned int j = 0; j < group_items[view.GroupName].size(); j++) {
for (size_t j = 0; j < group_items[view.GroupName].size(); j++) {
TimeEntry *group_entry =
time_entries[group_items[view.GroupName][j]];

Expand Down Expand Up @@ -872,18 +872,19 @@ void Context::updateUI(const UIElements &what) {
std::sort(time_entries.begin(), time_entries.end(),
CompareByStart);

Poco::LocalDateTime tl = UI()->TimelineDateAt();
Poco::LocalDateTime datetime(
UI()->TimelineDateAt().year(),
UI()->TimelineDateAt().month(),
UI()->TimelineDateAt().day());
int tzd = datetime.tzd();
tl.year(),
tl.month(),
tl.day());
time_t tzd = datetime.tzd();

// Get all entires in this day (no chunk, no overlap)
time_t start_day = datetime.timestamp().epochTime() - tzd;
time_t end_day = start_day + 86400; // one day

// Collect the time entries into a list
for (unsigned int i = 0; i < time_entries.size(); i++) {
for (size_t i = 0; i < time_entries.size(); i++) {
TimeEntry *te = time_entries[i];
if (te->Duration() < 0) {
// Don't account running entries
Expand Down Expand Up @@ -1836,8 +1837,8 @@ void Context::onTimelineUpdateServerSettings(Poco::Util::TimerTask&) { // NOLIN
HTTPRequest req;
req.host = urls::TimelineUpload();
req.relative_url = "/api/v8/timeline_settings";
req.payload = json;
req.basic_auth_username = apitoken;
req.payload = std::move(json);
req.basic_auth_username = std::move(apitoken);
req.basic_auth_password = "api_token";

HTTPResponse resp = TogglClient::GetInstance().Post(req);
Expand Down Expand Up @@ -1941,8 +1942,8 @@ void Context::onSendFeedback(Poco::Util::TimerTask&) { // NOLINT
HTTPRequest req;
req.host = urls::API();
req.relative_url ="/api/v8/feedback/web";
req.basic_auth_username = api_token_value;
req.basic_auth_password = api_token_name;
req.basic_auth_username = std::move(api_token_value);
req.basic_auth_password = std::move(api_token_name);
req.form = &form;

HTTPResponse resp = TogglClient::GetInstance().Post(req);
Expand Down Expand Up @@ -2495,7 +2496,7 @@ void Context::SetNeedEnableSSO(const std::string &code) {

void Context::ResetEnableSSO() {
need_enable_SSO = false;
sso_confirmation_code = "";
sso_confirmation_code.clear();
}

void Context::LoginSSO(const std::string &api_token) {
Expand Down Expand Up @@ -3129,8 +3130,8 @@ void Context::OpenTimeEntryEditor(
if (time_entry_editor_guid_ == te->GUID()) {
render.open_time_entry_editor = false;
render.display_time_entry_editor = false;
render.time_entry_editor_guid = "";
render.time_entry_editor_field = "";
render.time_entry_editor_guid.clear();
render.time_entry_editor_field.clear();

render.open_time_entry_list = true;
render.display_time_entries = true;
Expand Down Expand Up @@ -3588,7 +3589,7 @@ error Context::SetTimeEntryStart(
if (dt.utcTime() > now.utcTime()) {
Poco::LocalDateTime new_date =
dt - Poco::Timespan(1 * Poco::Timespan::DAYS);
dt = new_date;
dt = std::move(new_date);
}

std::string s = Poco::DateTimeFormatter::format(
Expand Down Expand Up @@ -3900,7 +3901,7 @@ error Context::DiscardTimeAt(
render.open_time_entry_editor = true;
render.display_time_entry_editor = true;
render.time_entry_editor_guid = split->GUID();
render.time_entry_editor_field = "";
render.time_entry_editor_field.clear();
updateUI(render);
}

Expand Down Expand Up @@ -4553,7 +4554,7 @@ error Context::OpenReportsInBrowser() {
req.host = urls::API();
req.relative_url = "/api/v8/desktop_login_tokens";
req.payload = "{}";
req.basic_auth_username = apitoken;
req.basic_auth_username = std::move(apitoken);
req.basic_auth_password = "api_token";

HTTPResponse resp = TogglClient::GetInstance().Post(req);
Expand Down Expand Up @@ -5091,7 +5092,7 @@ void Context::uiUpdaterActivity() {
updateUI(render);
}

running_time = date_duration;
running_time = std::move(date_duration);
}
}

Expand Down Expand Up @@ -5305,7 +5306,7 @@ void Context::onLoadMore(Poco::Util::TimerTask&) {
HTTPRequest req;
req.host = urls::API();
req.relative_url = ss.str();
req.basic_auth_username = api_token;
req.basic_auth_username = std::move(api_token);
req.basic_auth_password = "api_token";

HTTPResponse resp = TogglClient::GetInstance().Get(req);
Expand Down Expand Up @@ -5604,10 +5605,10 @@ error Context::pushBatchedChanges(
lastRequestUUID_ = Poco::UUIDGenerator().createOne().toString();

HTTPRequest req;
req.payload = payload;
req.payload = std::move(payload);
req.host = urls::SyncAPI();
req.relative_url = "/push/" + lastRequestUUID_;
req.basic_auth_username = api_token;
req.basic_auth_username = std::move(api_token);
req.basic_auth_password = "api_token";

auto response = TogglClient::GetInstance().Post(req);
Expand Down Expand Up @@ -5956,7 +5957,7 @@ error Context::pushEntries(
HTTPResponse resp;

if ((*it)->NeedsDELETE()) {
req.payload = "";
req.payload.clear();
resp = TogglClient::GetInstance().Delete(req);
} else if ((*it)->ID()) {
resp = TogglClient::GetInstance().Put(req);
Expand Down Expand Up @@ -6180,7 +6181,7 @@ error Context::pullWorkspaces() {
HTTPRequest req;
req.host = urls::API();
req.relative_url = "/api/v9/me/workspaces";
req.basic_auth_username = api_token;
req.basic_auth_username = std::move(api_token);
req.basic_auth_password = "api_token";

HTTPResponse resp = TogglClient::GetInstance().Get(req);
Expand Down Expand Up @@ -6267,7 +6268,7 @@ error Context::pullWorkspacePreferences(
HTTPRequest req;
req.host = urls::API();
req.relative_url = ss.str();
req.basic_auth_username = api_token;
req.basic_auth_username = std::move(api_token);
req.basic_auth_password = "api_token";

HTTPResponse resp = TogglClient::GetInstance().Get(req);
Expand Down Expand Up @@ -6302,7 +6303,7 @@ error Context::pullUserPreferences() {
HTTPRequest req;
req.host = urls::API();
req.relative_url = "/api/v9/me/preferences/desktop";
req.basic_auth_username = api_token;
req.basic_auth_username = std::move(api_token);
req.basic_auth_password = "api_token";

HTTPResponse resp = TogglClient::GetInstance().Get(req);
Expand Down Expand Up @@ -6737,7 +6738,7 @@ error Context::ToSAccept() {
HTTPRequest req;
req.host = urls::API();
req.relative_url = "/api/v9/me/accept_tos";
req.basic_auth_username = api_token;
req.basic_auth_username = std::move(api_token);
req.basic_auth_password = "api_token";

HTTPResponse resp = TogglClient::GetInstance().Post(req);
Expand All @@ -6759,7 +6760,7 @@ error Context::ToSAccept() {
return noError;
}

error Context::ToggleEntriesGroup(std::string name) {
error Context::ToggleEntriesGroup(const std::string& name) {
entry_groups[name] = !entry_groups[name];
OpenTimeEntryList();
return noError;
Expand Down Expand Up @@ -6838,7 +6839,7 @@ void Context::collectPushableModels(

void on_websocket_message(
void *context,
std::string json) {
const std::string json) {

poco_check_ptr(context);

Expand Down
8 changes: 4 additions & 4 deletions src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class TOGGL_INTERNAL_EXPORT UIElements {
, open_time_entry_editor(false)
, display_autotracker_rules(false)
, display_settings(false)
, time_entry_editor_guid("")
, time_entry_editor_field("")
, time_entry_editor_guid()
, time_entry_editor_field()
, display_unsynced_items(false)
, display_timeline(false)
, open_timeline(false) {}
Expand Down Expand Up @@ -568,7 +568,7 @@ class TOGGL_INTERNAL_EXPORT Context : public TimelineDatasource {
const int64_t promotion_response);

error ToggleEntriesGroup(
std::string name);
const std::string& name);

error AsyncPullCountries();
error PullCountries();
Expand Down Expand Up @@ -903,7 +903,7 @@ class TOGGL_INTERNAL_EXPORT Context : public TimelineDatasource {
};
void on_websocket_message(
void *context,
std::string json);
const std::string json);

} // namespace toggl

Expand Down
6 changes: 3 additions & 3 deletions src/database/database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ error Database::Trim(const std::string &text, std::string *result) {
poco_check_ptr(session_);
poco_check_ptr(result);

*result = "";
result->clear();

*session_ <<
"select trim(:text) limit 1",
Expand Down Expand Up @@ -3501,7 +3501,7 @@ error Database::CurrentAPIToken(
poco_check_ptr(session_);
Poco::Mutex::ScopedLock lock(session_m_);

*token = "";
token->clear();
*uid = 0;

*session_ <<
Expand Down Expand Up @@ -3816,7 +3816,7 @@ error Database::String(
*session_ << sql,
into(value),
now;
*result = value;
*result = std::move(value);
} catch(const Poco::Exception& exc) {
return exc.displayText();
} catch(const std::exception& ex) {
Expand Down
6 changes: 3 additions & 3 deletions src/feedback.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace toggl {
class TOGGL_INTERNAL_EXPORT Feedback {
public:
Feedback()
: subject_("")
, details_("")
, attachment_path_("") {}
: subject_()
, details_()
, attachment_path_() {}
~Feedback() {}

toggl::error Validate() const;
Expand Down
6 changes: 3 additions & 3 deletions src/get_focused_window_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ int getFocusedWindowInfo(
std::string *title,
std::string *filename,
bool *idle) {
*title = "";
*filename = "";
title->clear();
filename->clear();
*idle = false;

// get window handle
Expand Down Expand Up @@ -76,7 +76,7 @@ int getFocusedWindowInfo(
Poco::UnicodeConverter::toUTF8(buf, utf8);
#endif

*title = utf8;
*title = std::move(utf8);
}

return 0;
Expand Down
6 changes: 3 additions & 3 deletions src/gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void GUI::DisplayTimeEntryList(const bool open,

// Get render list from last 9 days at the first launch
time_t last9Days = time(nullptr) - 9 * 86400;
for (auto it = list.begin(); it != list.end(); it++) {
for (auto it = list.begin(); it != list.end(); ++it) {
auto timeEntry = *it;
if (timeEntry.Started >= last9Days) {
renderList.push_back(timeEntry);
Expand Down Expand Up @@ -461,13 +461,13 @@ void GUI::DisplayTimeline(const bool open,
TimelineDateAt().year(),
TimelineDateAt().month(),
TimelineDateAt().day());
int tzd = datetime.tzd();
time_t tzd = datetime.tzd();

// Get all entires in this day (no chunk, no overlap)
TogglTimeEntryView *first_entry = nullptr;
time_t start_day = datetime.timestamp().epochTime() - tzd;
time_t end_day = start_day + 86400; // one day
for (unsigned int i = 0; i < entries_list.size(); i++) {
for (size_t i = 0; i < entries_list.size(); i++) {
view::TimeEntry te = entries_list.at(i);
TogglTimeEntryView *item = time_entry_view_item_init(te);
time_t start_time_entry = Poco::Timestamp::fromEpochTime(item->Started).epochTime();
Expand Down
Loading