diff --git a/src/color_convert.cc b/src/color_convert.cc index 244b6c5c40..4af9433fbf 100644 --- a/src/color_convert.cc +++ b/src/color_convert.cc @@ -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 }; @@ -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; @@ -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; diff --git a/src/color_convert.h b/src/color_convert.h index f1d48a5bc0..5b2ef251a1 100644 --- a/src/color_convert.h +++ b/src/color_convert.h @@ -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); }; } diff --git a/src/context.cc b/src/context.cc index f985748fd0..7469716b18 100644 --- a/src/context.cc +++ b/src/context.cc @@ -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 @@ -683,7 +683,7 @@ void Context::updateUI(const UIElements &what) { std::map group_header_id; std::map > 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 = @@ -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, @@ -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]]; @@ -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 @@ -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); @@ -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); @@ -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) { @@ -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; @@ -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( @@ -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); } @@ -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); @@ -5091,7 +5092,7 @@ void Context::uiUpdaterActivity() { updateUI(render); } - running_time = date_duration; + running_time = std::move(date_duration); } } @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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; @@ -6838,7 +6839,7 @@ void Context::collectPushableModels( void on_websocket_message( void *context, - std::string json) { + const std::string json) { poco_check_ptr(context); diff --git a/src/context.h b/src/context.h index 3a07ffcff8..5eb65e2d3d 100644 --- a/src/context.h +++ b/src/context.h @@ -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) {} @@ -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(); @@ -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 diff --git a/src/database/database.cc b/src/database/database.cc index df801f5dd1..fc5546e0f3 100644 --- a/src/database/database.cc +++ b/src/database/database.cc @@ -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", @@ -3501,7 +3501,7 @@ error Database::CurrentAPIToken( poco_check_ptr(session_); Poco::Mutex::ScopedLock lock(session_m_); - *token = ""; + token->clear(); *uid = 0; *session_ << @@ -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) { diff --git a/src/feedback.h b/src/feedback.h index e823c8d771..c025245f48 100644 --- a/src/feedback.h +++ b/src/feedback.h @@ -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; diff --git a/src/get_focused_window_windows.cc b/src/get_focused_window_windows.cc index 9788474056..c1765c0eff 100644 --- a/src/get_focused_window_windows.cc +++ b/src/get_focused_window_windows.cc @@ -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 @@ -76,7 +76,7 @@ int getFocusedWindowInfo( Poco::UnicodeConverter::toUTF8(buf, utf8); #endif - *title = utf8; + *title = std::move(utf8); } return 0; diff --git a/src/gui.cc b/src/gui.cc index b5c6a472ac..8cdb39a137 100644 --- a/src/gui.cc +++ b/src/gui.cc @@ -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); @@ -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(); diff --git a/src/gui.h b/src/gui.h index 62b35d6612..429abd416a 100644 --- a/src/gui.h +++ b/src/gui.h @@ -28,38 +28,38 @@ class TOGGL_INTERNAL_EXPORT TimeEntry { TimeEntry() : ID(0) , DurationInSeconds(0) - , Description("") - , ProjectAndTaskLabel("") - , TaskLabel("") - , ProjectLabel("") - , ClientLabel("") + , Description() + , ProjectAndTaskLabel() + , TaskLabel() + , ProjectLabel() + , ClientLabel() , WID(0) , PID(0) , TID(0) - , Duration("") - , Color("") - , GUID("") + , Duration() + , Color() + , GUID() , Billable(false) - , Tags("") + , Tags() , Started(0) , Ended(0) - , StartTimeString("") - , EndTimeString("") + , StartTimeString() + , EndTimeString() , UpdatedAt(0) , DurOnly(false) - , DateHeader("") - , DateDuration("") + , DateHeader() + , DateDuration() , CanAddProjects(false) , CanSeeBillable(false) , DefaultWID(0) - , WorkspaceName("") + , WorkspaceName() , Unsynced(false) , Error(noError) , Locked(false) , Group(false) , GroupOpen(false) - , GroupName("") - , GroupDuration("") + , GroupName() + , GroupDuration() , GroupItemCount(0) , RoundedStart(0) , RoundedEnd(0) {} @@ -118,22 +118,22 @@ class TOGGL_INTERNAL_EXPORT TimeEntry { class TOGGL_INTERNAL_EXPORT Autocomplete { public: Autocomplete() - : Text("") - , Description("") - , ProjectAndTaskLabel("") - , TaskLabel("") - , ProjectLabel("") - , ClientLabel("") - , ProjectColor("") + : Text() + , Description() + , ProjectAndTaskLabel() + , TaskLabel() + , ProjectLabel() + , ClientLabel() + , ProjectColor() , TaskID(0) , ProjectID(0) , WorkspaceID(0) , Type(0) , Billable(false) - , Tags("") - , WorkspaceName("") + , Tags() + , WorkspaceName() , ClientID(0) - , ProjectGUID("") {} + , ProjectGUID() {} bool IsTimeEntry() const { return kAutocompleteItemTE == Type; @@ -198,9 +198,9 @@ class TOGGL_INTERNAL_EXPORT Generic { Generic() : ID(0) , WID(0) - , GUID("") - , Name("") - , WorkspaceName("") + , GUID() + , Name() + , WorkspaceName() , Premium(false) {} uint64_t ID; @@ -231,8 +231,8 @@ class TOGGL_INTERNAL_EXPORT TimelineEvent { public: TimelineEvent() : ID(0) - , Title("") - , Filename("") + , Title() + , Filename() , StartTime(0) , EndTime(0) , Idle(false) {} @@ -251,11 +251,11 @@ class TOGGL_INTERNAL_EXPORT Country { public: Country() : ID(0) - , Name("") + , Name() , VatApplicable(false) - , VatRegex("") - , VatPercentage("") - , Code("") {} + , VatRegex() + , VatPercentage() + , Code() {} uint64_t ID; std::string Name; @@ -310,7 +310,9 @@ class TOGGL_INTERNAL_EXPORT GUI : public SyncStateMonitor { , on_display_help_articles_(nullptr) , on_display_project_colors_(nullptr) , on_display_countries_(nullptr) + , on_display_onboarding_(nullptr) , on_continue_sign_in(nullptr) + , on_display_login_sso(nullptr) , on_display_timeline_ui(nullptr) , lastSyncState(-1) , lastUnsyncedItemsCount(-1) @@ -319,7 +321,7 @@ class TOGGL_INTERNAL_EXPORT GUI : public SyncStateMonitor { , lastOnlineState(-1) , lastErr(noError) , isFirstLaunch(true) - , time_entry_editor_guid_("") + , time_entry_editor_guid_() , timeline_date_at_(Poco::LocalDateTime()) {} ~GUI() {} @@ -610,7 +612,7 @@ class TOGGL_INTERNAL_EXPORT GUI : public SyncStateMonitor { } void resetTimeEntryGUID() { - time_entry_editor_guid_ = ""; + time_entry_editor_guid_.clear(); } void DisplayOnboarding(const OnboardingType onboarding_type); diff --git a/src/https_client.cc b/src/https_client.cc index bbed8c21c8..afe7a2b810 100644 --- a/src/https_client.cc +++ b/src/https_client.cc @@ -40,7 +40,7 @@ namespace toggl { -void HTTPClient::SetCACertPath(std::string path) { +void HTTPClient::SetCACertPath(const std::string& path) { if (path.compare(Config.CACertPath()) == 0) { return; } @@ -72,7 +72,7 @@ void HTTPClient::resetPocoContext() { verification_mode, 9, true, "ALL"); Poco::Net::SSLManager::instance().initializeClient( nullptr, acceptCertHandler, _context); - context = _context; + context = std::move(_context); } void ServerStatus::startStatusCheck() { @@ -377,10 +377,10 @@ HTTPResponse HTTPClient::makeHttpRequest( } poco_req.set("User-Agent", HTTPClient::Config.UserAgent()); - Poco::Net::HTTPBasicCredentials cred( - req.basic_auth_username, req.basic_auth_password); if (!req.basic_auth_username.empty() && !req.basic_auth_password.empty()) { + Poco::Net::HTTPBasicCredentials cred( + req.basic_auth_username, req.basic_auth_password); cred.authenticate(poco_req); } @@ -462,7 +462,7 @@ HTTPResponse HTTPClient::makeHttpRequest( if (isRedirect(resp.status_code) && response.has("Location")) { std::string decoded_url(""); Poco::URI::decode(response.get("Location"), decoded_url); - resp.body = decoded_url; + resp.body = std::move(decoded_url); // Inflate, if gzip was sent } else if (response.has("Content-Encoding") && @@ -546,7 +546,7 @@ HTTPResponse TogglClient::request( if (err != noError) { logger().error("Will not connect, because of known bad Toggl status: ", err); HTTPResponse resp; - resp.err = err; + resp.err = std::move(err); return resp; } diff --git a/src/https_client.h b/src/https_client.h index 4acba933f5..3d51d16fa0 100644 --- a/src/https_client.h +++ b/src/https_client.h @@ -66,13 +66,13 @@ class TOGGL_INTERNAL_EXPORT ServerStatus { class TOGGL_INTERNAL_EXPORT HTTPClientConfig { public: HTTPClientConfig() - : AppName("") - , AppVersion("") + : AppName() + , AppVersion() , UseProxy(false) , ProxySettings(Proxy()) , AutodetectProxy(true) , ignoreCert(false) - , caCertPath("") {} + , caCertPath() {} ~HTTPClientConfig() {} std::string AppName; @@ -93,7 +93,7 @@ class TOGGL_INTERNAL_EXPORT HTTPClientConfig { std::string CACertPath() { return caCertPath; }; - void SetCACertPath(std::string path) { + void SetCACertPath(const std::string& path) { caCertPath = path; } void SetIgnoreCert(bool ignore) { @@ -108,12 +108,12 @@ class TOGGL_INTERNAL_EXPORT HTTPClientConfig { class TOGGL_INTERNAL_EXPORT HTTPRequest { public: HTTPRequest() - : method("") - , host("") - , relative_url("") - , payload("") - , basic_auth_username("") - , basic_auth_password("") + : method() + , host() + , relative_url() + , payload() + , basic_auth_username() + , basic_auth_password() , form(nullptr) , query(nullptr) , timeout_seconds(kHTTPClientTimeoutSeconds) {} @@ -133,7 +133,7 @@ class TOGGL_INTERNAL_EXPORT HTTPRequest { class TOGGL_INTERNAL_EXPORT HTTPResponse { public: HTTPResponse() - : body("") + : body() , err(noError) , status_code(0) {} virtual ~HTTPResponse() {} @@ -162,7 +162,7 @@ class TOGGL_INTERNAL_EXPORT HTTPClient { static HTTPClientConfig Config; - void SetCACertPath(std::string path); + void SetCACertPath(const std::string& path); void SetIgnoreCert(bool ignore); static error StatusCodeToError(const Poco::Int64 status_code); diff --git a/src/model/alpha_features.cpp b/src/model/alpha_features.cpp index 8ae8462d15..c83dfdfc32 100644 --- a/src/model/alpha_features.cpp +++ b/src/model/alpha_features.cpp @@ -15,7 +15,7 @@ namespace toggl { isTimelineUiEnabled_ = false; } - void AlphaFeatures::ReadAlphaFeatures(Json::Value root) { + void AlphaFeatures::ReadAlphaFeatures(const Json::Value &root) { if (root.isMember("alpha_features")) { for (auto i : root["alpha_features"]) { if (i.isMember("code")) { diff --git a/src/model/alpha_features.h b/src/model/alpha_features.h index 7f8fc0056f..606ea4c05e 100644 --- a/src/model/alpha_features.h +++ b/src/model/alpha_features.h @@ -4,7 +4,7 @@ namespace toggl { { public: AlphaFeatures(); - void ReadAlphaFeatures(Json::Value root); + void ReadAlphaFeatures(const Json::Value &root); bool IsSyncEnabled(); bool IsTimelineUiEnabled(); private: diff --git a/src/model/settings.h b/src/model/settings.h index d4aa6f1c6e..ef82fbb299 100644 --- a/src/model/settings.h +++ b/src/model/settings.h @@ -35,8 +35,8 @@ class TOGGL_INTERNAL_EXPORT Settings : public BaseModel { , remind_fri(true) , remind_sat(true) , remind_sun(true) - , remind_starts("") - , remind_ends("") + , remind_starts() + , remind_ends() , autotrack(false) , open_editor_on_shortcut(false) , has_seen_beta_offering(false) diff --git a/src/model/time_entry.cc b/src/model/time_entry.cc index 996835f308..ad484e3423 100644 --- a/src/model/time_entry.cc +++ b/src/model/time_entry.cc @@ -323,7 +323,7 @@ void TimeEntry::SetStartString(const std::string &value, bool userModified) { } void TimeEntry::SetDurationUserInput(const std::string &value) { - int seconds = Formatter::ParseDurationString(value); + time_t seconds = Formatter::ParseDurationString(value); if (IsTracking()) { time_t now = time(nullptr); time_t start = now - seconds; diff --git a/src/model/user.cc b/src/model/user.cc index f079e68145..535f73b22d 100644 --- a/src/model/user.cc +++ b/src/model/user.cc @@ -1206,7 +1206,7 @@ error User::UserID( error User::LoginToken( const std::string &json_data_string, std::string *result) { - *result = ""; + result->clear(); Json::Value root; Json::Reader reader; bool ok = reader.parse(json_data_string, root); diff --git a/src/onboarding_service.cpp b/src/onboarding_service.cpp index 48ddb3aad6..1a29708079 100644 --- a/src/onboarding_service.cpp +++ b/src/onboarding_service.cpp @@ -216,7 +216,7 @@ bool OnboardingService::hasAtLeastOneTimelineTimeEntryOnCurrentDay() { } // Get current start/end day - int tzd = timeline_date_at_.tzd(); + time_t tzd = timeline_date_at_.tzd(); time_t start_day = timeline_date_at_.timestamp().epochTime() - tzd; // Since we don't store the TimeEntry for each particular day diff --git a/src/proxy.h b/src/proxy.h index 10fe18c9b9..33202e8218 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -14,10 +14,10 @@ namespace toggl { class TOGGL_INTERNAL_EXPORT Proxy { public: Proxy() : - host_(""), + host_(), port_(0), - username_(""), - password_("") {} + username_(), + password_() {} bool IsConfigured() const; bool HasCredentials() const; diff --git a/src/related_data.cc b/src/related_data.cc index 51561d916a..8b3b73386e 100644 --- a/src/related_data.cc +++ b/src/related_data.cc @@ -70,11 +70,11 @@ error RelatedData::DeleteAutotrackerRule(const Poco::Int64 local_id) { error RelatedData::UpdateAutotrackerRule( const Poco::Int64 local_id, - std::string terms, + const std::string terms, const Poco::UInt64 tid, const Poco::UInt64 pid, - std::string start_time, - std::string end_time, + const std::string start_time, + const std::string end_time, const Poco::UInt8 days_of_week) { if (!local_id) { @@ -284,9 +284,9 @@ void RelatedData::timeEntryAutocompleteItems( unique_names->insert(text); view::Autocomplete autocomplete_item; - autocomplete_item.Text = text; - autocomplete_item.Description = description; - autocomplete_item.ProjectAndTaskLabel = project_task_label; + autocomplete_item.Text = std::move(text); + autocomplete_item.Description = std::move(description); + autocomplete_item.ProjectAndTaskLabel = std::move(project_task_label); if (p) { autocomplete_item.ProjectColor = p->ColorCode(); autocomplete_item.ProjectID = p->ID(); @@ -366,7 +366,7 @@ void RelatedData::taskAutocompleteItems( view::Autocomplete autocomplete_item; autocomplete_item.Text = t->Name(); - autocomplete_item.ProjectAndTaskLabel = text; + autocomplete_item.ProjectAndTaskLabel = std::move(text); autocomplete_item.TaskLabel = t->Name(); autocomplete_item.TaskID = t->ID(); @@ -434,7 +434,7 @@ void RelatedData::projectAutocompleteItems( view::Autocomplete autocomplete_item; autocomplete_item.Text = text; - autocomplete_item.ProjectAndTaskLabel = text; + autocomplete_item.ProjectAndTaskLabel = std::move(text); autocomplete_item.ProjectLabel = p->Name(); if (c) { autocomplete_item.ClientLabel = c->Name(); diff --git a/src/related_data.h b/src/related_data.h index cf282f3d3c..c151a60be8 100644 --- a/src/related_data.h +++ b/src/related_data.h @@ -89,11 +89,11 @@ class TOGGL_INTERNAL_EXPORT RelatedData { error DeleteAutotrackerRule(const Poco::Int64 local_id); error UpdateAutotrackerRule( const Poco::Int64 local_id, - std::string terms, + const std::string terms, const Poco::UInt64 tid, const Poco::UInt64 pid, - std::string start_time, - std::string end_time, + const std::string start_time, + const std::string end_time, const Poco::UInt8 days_of_week); void TimeEntryAutocompleteItems(std::vector *) const; diff --git a/src/timeline_notifications.h b/src/timeline_notifications.h index b9f9a40dca..a78d03f650 100644 --- a/src/timeline_notifications.h +++ b/src/timeline_notifications.h @@ -18,8 +18,8 @@ class TOGGL_INTERNAL_EXPORT TimelineBatch { public: TimelineBatch() : user_id_(0) - , api_token_("") - , desktop_id_("") {} + , api_token_() + , desktop_id_() {} ~TimelineBatch() {} diff --git a/src/timeline_uploader.cc b/src/timeline_uploader.cc index 117f348d3e..8fbb43ee8c 100644 --- a/src/timeline_uploader.cc +++ b/src/timeline_uploader.cc @@ -88,7 +88,7 @@ error TimelineUploader::upload(TimelineBatch *batch) { HTTPRequest req; req.host = urls::TimelineUpload(); req.relative_url = "/api/v8/timeline"; - req.payload = json; + req.payload = std::move(json); req.basic_auth_username = batch->APIToken(); req.basic_auth_password = "api_token"; diff --git a/src/toggl_api.cc b/src/toggl_api.cc index c61588b051..7f489d5f41 100644 --- a/src/toggl_api.cc +++ b/src/toggl_api.cc @@ -671,7 +671,7 @@ int64_t toggl_timestamp_from_time_string(const char_t *time) { if (dt.utcTime() > now.utcTime()) { Poco::LocalDateTime new_date = dt - Poco::Timespan(1 * Poco::Timespan::DAYS); - dt = new_date; + dt = std::move(new_date); } return dt.utc().timestamp().epochTime(); @@ -1780,7 +1780,7 @@ void toggl_on_display_login_sso(void *context, } TogglHsvColor toggl_get_adaptive_hsv_color( - TogglRgbColor rgbColor, + const TogglRgbColor &rgbColor, TogglAdaptiveColor type) { return toggl::ColorConverter::GetAdaptiveColor(rgbColor, type); } diff --git a/src/toggl_api.h b/src/toggl_api.h index 5859c294d6..364d68546c 100644 --- a/src/toggl_api.h +++ b/src/toggl_api.h @@ -1366,7 +1366,7 @@ extern "C" { TogglDisplayLoginSSO cb); TOGGL_EXPORT TogglHsvColor toggl_get_adaptive_hsv_color( - TogglRgbColor rgbColor, + const TogglRgbColor &rgbColor, TogglAdaptiveColor type); TOGGL_EXPORT bool_t toggl_get_identity_provider_sso( diff --git a/src/toggl_api_private.cc b/src/toggl_api_private.cc index 7165e54f01..dd5904e0a7 100644 --- a/src/toggl_api_private.cc +++ b/src/toggl_api_private.cc @@ -216,7 +216,7 @@ void country_list_delete_item(TogglCountryView *first) { std::string to_string(const char_t *s) { if (!s) { - return std::string(""); + return std::string(); } #if defined(_WIN32) || defined(WIN32) std::wstring ws(s); diff --git a/src/util/formatter.cc b/src/util/formatter.cc index 36b19af2ac..b94b930708 100644 --- a/src/util/formatter.cc +++ b/src/util/formatter.cc @@ -193,7 +193,7 @@ bool Formatter::ParseTimeInput(const std::string &input, } // Handle formats: HH:mm, H:mm etc - if (value.find(":") != std::string::npos) { + if (value.find(':') != std::string::npos) { Poco::StringTokenizer tokenizer(value, ":"); if (2 != tokenizer.count()) { return false; @@ -348,7 +348,7 @@ int Formatter::ParseDurationString(const std::string &value) { std::string input = Poco::replace(value, " ", ""); input = Poco::replace(input, ",", "."); - if (input.find(":") != std::string::npos) { + if (input.find(':') != std::string::npos) { int parsed_seconds = 0; // Parse duration in seconds HH:MM:SS @@ -374,7 +374,7 @@ int Formatter::ParseDurationString(const std::string &value) { int seconds = parseDurationStringHoursMinutesSeconds(&input); // 15 - if (input.find(".") == std::string::npos) { + if (input.find('.') == std::string::npos) { Poco::Int64 minutes = 0; if (Poco::NumberParser::tryParse64(input, minutes)) { if ((minutes * 60) > kMaxDurationSeconds) { @@ -607,8 +607,8 @@ bool CompareAutotrackerTitles(const std::string &a, const std::string &b) { } bool CompareAutocompleteItems( - view::Autocomplete a, - view::Autocomplete b) { + const view::Autocomplete& a, + const view::Autocomplete& b) { // Time entries first if (a.IsTimeEntry() && !b.IsTimeEntry()) { @@ -638,8 +638,8 @@ bool CompareAutocompleteItems( } bool CompareStructuredAutocompleteItems( - view::Autocomplete a, - view::Autocomplete b) { + const view::Autocomplete& a, + const view::Autocomplete& b) { if (a.WorkspaceName == b.WorkspaceName) { if (a.IsWorkspace() && !b.IsWorkspace()) { diff --git a/src/util/formatter.h b/src/util/formatter.h index a9e1171ef0..62f65a405a 100644 --- a/src/util/formatter.h +++ b/src/util/formatter.h @@ -144,11 +144,11 @@ bool CompareByStart( TimedEvent *a, TimedEvent *b); bool CompareAutocompleteItems( - view::Autocomplete a, - view::Autocomplete b); + const view::Autocomplete& a, + const view::Autocomplete& b); bool CompareStructuredAutocompleteItems( - view::Autocomplete a, - view::Autocomplete b); + const view::Autocomplete& a, + const view::Autocomplete& b); bool CompareWorkspaceByName( Workspace *a, Workspace *b); diff --git a/src/util/property.h b/src/util/property.h index 8bdf549bf8..0806b60514 100644 --- a/src/util/property.h +++ b/src/util/property.h @@ -17,10 +17,8 @@ class Property { public: typedef T value_type; - Property(const T& value) { - current_ = value; - previous_ = value; - } + Property(const T& value) : current_(value), previous_(value) { } + Property(T&& value = T {}) { current_ = std::move(value); previous_ = current_; diff --git a/src/websocket_client.cc b/src/websocket_client.cc index 87f7960695..8b652cade1 100644 --- a/src/websocket_client.cc +++ b/src/websocket_client.cc @@ -197,7 +197,7 @@ error WebSocketClient::receiveWebSocketMessage(std::string *message) { } catch(const std::string & ex) { return error(ex); } - *message = json; + *message = std::move(json); return noError; } diff --git a/src/websocket_client.h b/src/websocket_client.h index 1295a19dd9..5af3e1ad47 100644 --- a/src/websocket_client.h +++ b/src/websocket_client.h @@ -39,7 +39,7 @@ class TOGGL_INTERNAL_EXPORT WebSocketClient { on_websocket_message_(nullptr), ctx_(nullptr), last_connection_at_(0), - api_token_("") {} + api_token_() {} virtual ~WebSocketClient(); virtual void Start( diff --git a/src/window_change_recorder.cc b/src/window_change_recorder.cc index 92a6721e51..019c15e570 100644 --- a/src/window_change_recorder.cc +++ b/src/window_change_recorder.cc @@ -94,7 +94,7 @@ void WindowChangeRecorder::inspectFocusedWindow() { bool idleChanged = hasIdlenessChanged(idle); if (idleChanged) { - last_autotracker_title_ = ""; + last_autotracker_title_.clear(); } bool windowHasChanged = hasWindowChanged(title, filename); @@ -128,8 +128,8 @@ void WindowChangeRecorder::inspectFocusedWindow() { } } - last_title_ = title; - last_filename_ = filename; + last_title_ = std::move(title); + last_filename_ = std::move(filename); last_idle_ = idle; last_event_started_at_ = now; } @@ -152,12 +152,6 @@ void WindowChangeRecorder::recordLoop() { } Poco::Thread::sleep(kWindowRecorderSleepMillis); - - if (recording_.isStopped()) { - break; - } - - Poco::Thread::sleep(kWindowRecorderSleepMillis); } } diff --git a/src/window_change_recorder.h b/src/window_change_recorder.h index 562cf39afa..d09d0ab42c 100644 --- a/src/window_change_recorder.h +++ b/src/window_change_recorder.h @@ -21,13 +21,14 @@ namespace toggl { class TOGGL_INTERNAL_EXPORT WindowChangeRecorder { public: explicit WindowChangeRecorder(TimelineDatasource *datasource) - : last_title_("") - , last_filename_("") + : last_title_() + , last_filename_() , last_event_started_at_(0) + , current_app_started_at_(0) , last_idle_(false) , timeline_datasource_(datasource) , recording_(this, &WindowChangeRecorder::recordLoop) - , last_autotracker_title_("") + , last_autotracker_title_() , shutdown_(false) , isLocked_(false) , isSleeping_(false)