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

support V2/GET_CLIENT_ICON in socketapi, add icon to dolphin right click menu #8638

Merged
merged 7 commits into from
May 26, 2021

Conversation

gabi18
Copy link
Contributor

@gabi18 gabi18 commented May 18, 2021

Solves #8464

@CLAassistant
Copy link

CLAassistant commented May 18, 2021

CLA assistant check
All committers have signed the CLA.

QByteArray line_end("\n");
QJsonObject args { { "size", size } };
QJsonObject obj { { QStringLiteral("id"), "1" }, { QStringLiteral("arguments"), args } };
std::string command = "V2/GET_CLIENT_ICON:" + QJsonDocument(obj).toJson(QJsonDocument::Compact).toStdString();
Copy link
Member

Choose a reason for hiding this comment

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

QByteArrayLiteral("V2/GET_CLIENT_ICON:")

shell_integration/dolphin/ownclouddolphinpluginhelper.cpp Outdated Show resolved Hide resolved
void OwncloudDolphinPluginHelper::slotConnected()
{
sendCommand("VERSION:\n");
sendCommand("GET_STRINGS:\n");
sendCommand("V2/GET_CLIENT_ICON:\n");
Copy link
Member

Choose a reason for hiding this comment

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

Probably not needed.

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 are right - it isn't needed

void OwncloudDolphinPluginHelper::sendGetClientIconCommand(int size)
{
QByteArray line_end("\n");
QJsonObject args { { "size", size } };
Copy link
Member

Choose a reason for hiding this comment

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

QStringLietral()

@@ -112,7 +124,26 @@ void OwncloudDolphinPluginHelper::slotReadyRead()
_socket.disconnectFromServer();
return;
}
} else if (line.startsWith("V2/GET_CLIENT_ICON_RESULT:")) {
line.remove(0, QString("V2/GET_CLIENT_ICON_RESULT:").size());
Copy link
Member

Choose a reason for hiding this comment

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

QStringLiteral

line.remove(0, QString("V2/GET_CLIENT_ICON_RESULT:").size());
QJsonParseError error;
auto json = QJsonDocument::fromJson(line, &error).object();
if (error.error != QJsonParseError::NoError)
Copy link
Member

Choose a reason for hiding this comment

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

{
}

if (jsonArgs.isEmpty())
continue;

QByteArray pngBase64 = jsonArgs.value("png").toString().toLatin1();
Copy link
Member

Choose a reason for hiding this comment

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

const QByteArray pngBase64
toUtf8

src/gui/socketapi/socketapi.cpp Outdated Show resolved Hide resolved
src/gui/socketapi/socketapi.cpp Outdated Show resolved Hide resolved
src/gui/socketapi/socketapi.cpp Outdated Show resolved Hide resolved
QJsonObject obj { { QStringLiteral("id"), "1" }, { QStringLiteral("arguments"), args } };
std::string command = "V2/GET_CLIENT_ICON:" + QJsonDocument(obj).toJson(QJsonDocument::Compact).toStdString();
sendCommand(QByteArray(command.c_str() + line_end));
int msgId = 1;
Copy link
Member

Choose a reason for hiding this comment

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

Here I meant a member that counts upwards.
the v2 response will have the same id, so when you (in theory) start multiple requests you can map them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I see

sendCommand(QByteArray(command.c_str() + line_end));
int msgId = 1;
QJsonObject args { { QStringLiteral("size"), size } };
QJsonObject obj { { QStringLiteral("id"), QString(msgId) }, { QStringLiteral("arguments"), args } };
Copy link
Member

Choose a reason for hiding this comment

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

QString::number
and please const for the objects.

@@ -125,17 +124,19 @@ void OwncloudDolphinPluginHelper::slotReadyRead()
return;
}
} else if (line.startsWith("V2/GET_CLIENT_ICON_RESULT:")) {
line.remove(0, QString("V2/GET_CLIENT_ICON_RESULT:").size());
line.remove(0, QStringLiteral("V2/GET_CLIENT_ICON_RESULT:").size());
Copy link
Member

Choose a reason for hiding this comment

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

Hm maybe we could split at the : before the else if and only compare the command (command:argumen)
https://github.com/owncloud/client/blob/master/src/gui/socketapi/socketapi.cpp#L354

QJsonObject args { { QStringLiteral("size"), size } };
QJsonObject obj { { QStringLiteral("id"), QString(msgId) }, { QStringLiteral("arguments"), args } };
auto json = QJsonDocument(obj).toJson(QJsonDocument::Compact);
sendCommand(QByteArray("V2/GET_CLIENT_ICON:" + json + "\n"));
Copy link
Member

Choose a reason for hiding this comment

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

For all the mess with the strings, we build our core library with a stricter string handling, so for example QString("a") would not compile there. That's why I'm a bit pedantic here :)

QByteArray("V2/GET_CLIENT_ICON:" + json + "\n")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

improved - hopefully correct now

// get the command (at begin of line, before first ':')
const QByteArray command = line.left(firstColon);
// rest of line contains the information
QByteArray info = line.right(line.size() - firstColon - 1);
Copy link
Member

Choose a reason for hiding this comment

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

Might be me but I find line.mid(firstColon + 1) more intuitive.
Also const.
If you use midRef it event removes the need to create a copy of the string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, line.mid() IS more intuitive

QByteArray line;
qSwap(line, _line);
line.chop(1);
if (line.isEmpty())
continue;
int firstColon = line.indexOf(':');
Copy link
Member

Choose a reason for hiding this comment

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

const

@sonarcloud
Copy link

sonarcloud bot commented May 26, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@gabi18 gabi18 merged commit 066ed56 into master May 26, 2021
@delete-merged-branch delete-merged-branch bot deleted the work/dolphin_icon branch May 26, 2021 13:03
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.

3 participants