-
Notifications
You must be signed in to change notification settings - Fork 665
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
Conversation
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(); |
There was a problem hiding this comment.
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:")
void OwncloudDolphinPluginHelper::slotConnected() | ||
{ | ||
sendCommand("VERSION:\n"); | ||
sendCommand("GET_STRINGS:\n"); | ||
sendCommand("V2/GET_CLIENT_ICON:\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not needed.
There was a problem hiding this comment.
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 } }; |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const QByteArray pngBase64
toUtf8
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 } }; |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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")); |
There was a problem hiding this comment.
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")
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(':'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
Kudos, SonarCloud Quality Gate passed! |
Solves #8464