Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kdesktop 968 applied c++20 style and new features #174

Draft
wants to merge 60 commits into
base: develop
Choose a base branch
from

Conversation

herve-er
Copy link
Contributor

This PR aims to do a first pass of refactoring to applied c++20 recommended style to our code base.

@herve-er herve-er marked this pull request as ready for review June 17, 2024 11:58
@herve-er herve-er requested a review from a team as a code owner June 17, 2024 11:58
@herve-er herve-er marked this pull request as draft June 17, 2024 11:58
{ProxyType::ProxyTypeHTTP, {0, QString(tr("HTTP(S) Proxy"))}}
//, { ProxyType::ProxyTypeSocks5, { 0, QString(tr("SOCKS5 Proxy")) } }
{ProxyType::HTTP, {0, QString(tr("HTTP(S) Proxy"))}}
//, { ProxyType::Socks5, { 0, QString(tr("SOCKS5 Proxy")) } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the commented line still useful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think. @ChristopheLarchier could you please confirm?

@@ -239,17 +239,17 @@ void StatusBarWidget::createStatusActionMenu(MenuWidget *&menu, bool &resetButto
QWidgetAction *syncAction;
for (auto const &syncInfoMapElt : syncOfCurrentDrive) {
if (pauseClicked &&
(syncInfoMapElt.second.status() == SyncStatusStoped || syncInfoMapElt.second.status() == SyncStatusPaused)) {
(syncInfoMapElt.second.status() == SyncStatus::Stoped || syncInfoMapElt.second.status() == SyncStatus::Paused)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could take the opportunity to rename Stoped with Stopped?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, done in commit: dba898f

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And commit: 1810e5a

@@ -21,7 +21,7 @@
namespace KDC {

ProxyConfigInfo::ProxyConfigInfo()
: _type(ProxyTypeNone), _hostName(QString()), _port(0), _needsAuth(false), _user(QString()), _pwd(QString()) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SonarCloud will be grateful to you if you could initialize _type. _port and _needsAuth in the header and remove the default-constructed data members from this initialization list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit: c18bc48

src/libcommon/info/syncinfo.cpp Outdated Show resolved Hide resolved
@@ -21,7 +21,7 @@
namespace KDC {

ProxyConfig::ProxyConfig()
: _type(ProxyTypeNone), _hostName(std::string()), _port(0), _needsAuth(false), _user(std::string()), _token(std::string()) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind applying the usual recommandation for initialization list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I used VS2022 to find and replace with regular expressions, I only checked that the applied modifications were correct but didn't check if the modified code needed to be refactored to adapt to our "new" guidelines. Sorry about that and thanks for noticing it 👍🏾.

Done in commit: 3c50feb and 3ee0add

if (_linkType == LinkTypeSymlink) {
return _targetType == NodeTypeFile ? mimeTypeSymlink : mimeTypeSymlinkFolder;
} else if (_linkType == LinkTypeHardlink) {
if (_linkType == LinkType::Symlink) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have: refactor with a switch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here: a56cf19

valid = CommonUtility::dirNameIsValid(name);
}

if (!valid) {
LOGW_SYNCPAL_DEBUG(_logger, L"The file/directory name contains a character not yet supported by the filesystem "
<< SyncName2WStr(name).c_str() << L". Item is ignored.");

Error err(_syncPal->syncDbId(), "", nodeId, type, name, ConflictTypeNone, InconsistencyTypeNotYetSupportedChar);
Error err(_syncPal->syncDbId(), "", nodeId, type, name, ConflictType::None, InconsistencyTypeNotYetSupportedChar);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about InconsistencyType::NotYetSupportedChar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These classes can't be easily converted to enum classes due to the numerous bitwise operations involved. I will take a deeper look to see if I can find an efficient way to convert them to enum classes without making the code unreadable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check these 3 commits 5470bb5, c6f3ed3, 78afc22.

NodeType::Directory, {}, (side == ReplicaSide::Local ? dbNode.nodeIdLocal() : dbNode.nodeIdRemote()),
(side == ReplicaSide::Local ? dbNode.created() : dbNode.created()),
(side == ReplicaSide::Local ? dbNode.lastModifiedLocal() : dbNode.lastModifiedRemote()),
0, //(side == ReplicaSide::Local ? dbNode.lastModifiedLocal() : dbNode.lastModifiedRemote()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the commented part still relevant?

@@ -491,8 +491,8 @@ void AppServer::onRequestReceived(int id, RequestNum num, const QByteArray &para
sendUserUpdated(userInfo);
}

resultStream << exitCode;
if (exitCode == ExitCodeOk) {
resultStream << enumClassToInt(exitCode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to check: the result is then translated back to an enum?

Copy link
Contributor Author

@herve-er herve-er Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, here is the client code:

    QDataStream resultStream(&results, QIODevice::ReadOnly);
    resultStream >> exitCode;

where >> operator reinterpret_cast to exitCode:

template <typename T>
typename std::enable_if_t<std::is_enum<T>::value, QDataStream &>
operator>>(QDataStream &s, T &t)
{ return s >> reinterpret_cast<typename std::underlying_type<T>::type &>(t); }

@@ -654,11 +654,11 @@ bool VfsWin::status(const QString &filePath, bool &isPlaceholder, bool &isHydrat

bool VfsWin::fileStatusChanged(const QString &path, SyncFileStatus status) {
LOGW_DEBUG(logger(), L"fileStatusChanged: " << Utility::formatSyncPath(QStr2Path(path)).c_str() << L" status = "
<< Utility::s2ws(Utility::syncFileStatus2Str(status)).c_str());
<< Utility::s2ws(Utility::SyncFileInstruction2Str(status)).c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using the upper case S in the function name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I made the correction in commit: 24387cd

herve-er and others added 27 commits June 18, 2024 12:01
Copy link

sonarcloud bot commented Jun 19, 2024

@herve-er herve-er marked this pull request as draft June 19, 2024 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants