-
Notifications
You must be signed in to change notification settings - Fork 63
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
Xmlconsole #52
base: master
Are you sure you want to change the base?
Xmlconsole #52
Conversation
Test-Information: Built on LinuxMint 18 with Qt 5.5.1 successfully. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-information: Tested on LinuxMint 18, Qt 5.5.1
I think an input field in the original dialog would be preferred over opening an addition window to input the XML. Other than that it look great. |
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.
Left some code style comments. Thanks for working on this.
Swift/QtUI/QtXMLConsoleWidget.cpp
Outdated
setWindowTitle(tr("Debug Console")); | ||
emit titleUpdated(); | ||
} | ||
|
||
QtXMLConsoleWidget::~QtXMLConsoleWidget() { | ||
} | ||
|
||
void QtXMLConsoleWidget::showWindow() { | ||
QtXMLSenderWidget* XMLWindow = new QtXMLSenderWidget(); |
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 can use auto
here on the left-hand side.
Swift/QtUI/QtXMLSenderWidget.cpp
Outdated
* Copyright (c) 2010-2016 Isode Limited. | ||
* All rights reserved. | ||
* See the COPYING file for more information. | ||
*/ |
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 this file is completely new and written by yourself, it should have a copyright header with your name on it. See for example how another student has done it in their PR https://github.com/swift/swift/pull/46/files .
Swift/QtUI/QtXMLSenderWidget.cpp
Outdated
#include <Swift/QtUI/QtXMLSenderWidget.h> | ||
|
||
#include <string> | ||
#include <QString> |
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.
We tend to group our includes, so ideally the QString should be grouped with other Qt includes. There is also a script doing this for you, see the python script https://github.com/swift/swift/blob/master/BuildTools/FixIncludes.py .
Changed to input field in original dialog, and changed copyright. I'm having trouble figuring out how to send the outgoing XML, any tips on what code I should be looking at? |
The MainController should have a Swift::Client instance. It has sendMessage() and sendPresence) method. For sending IQs you can also get the IQRouter from that Swift::Client instance. They are all defined in Swift::CoreClient https://github.com/swift/swift/blob/master/Swiften/Client/CoreClient.h . |
Swift/QtUI/QtXMLConsoleWidget.cpp
Outdated
void QtXMLConsoleWidget::showWindow() { | ||
QtXMLSenderWidget* XMLWindow = new QtXMLSenderWidget(); | ||
XMLWindow->show(); | ||
void QtXMLConsoleWidget::showWindow(bool showXMLSender) { |
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.
While this way is totally fine, you can also use C++11 lambdas as Qt slots. This has the widget definition and the handler for the widget close to each other in the code and doesn't require an additional method to be added to the class. See https://github.com/swift/swift/blob/master/Swift/QtUI/QtBlockListEditorWindow.cpp#L113 for an example.
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.
Also made this change :)
Swift/QtUI/QtXMLConsoleWidget.cpp
Outdated
else | ||
{ | ||
XMLWindow->hide(); | ||
} |
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.
Instead of this if you could also pass a boolean flag to QWidget::setVisible
method, see http://doc.qt.io/qt-5/qwidget.html#visible-prop .
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.
Made change. Will push when I get back to college tomorrow :)
Swift/QtUI/QtXMLConsoleWidget.h
Outdated
@@ -42,5 +42,7 @@ namespace Swift { | |||
private: | |||
QTextEdit* textEdit; | |||
QCheckBox* enabled; | |||
QCheckBox* debugenabled; |
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.
Ideally all pointers are initialised with nullptr
if you don't directly assign a correct value to them at declaration time.
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.
I'm not entirely sure what you mean, could I have a bit more detail?
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.
The value of these members is undefined until you assign a value to them.
You can write QCheckBox* debugEnabled = nullptr
in the class definition in the header file to do so. Furthermore it should be debugEnabled
and not debugenabled
, as we camelCase for member variables. See the Naming section in https://github.com/swift/swift/wiki/Coding-Style .
|
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.
Left some inline feedback. The general direction is good. Please run the FixIncludes.py
tool over the touched files or sort/group the includes manually.
@@ -7,6 +7,7 @@ | |||
#pragma once | |||
|
|||
#include <Swiften/Base/SafeByteArray.h> | |||
#include <boost/signals2.hpp> |
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.
In Swift we aim to keep our includes sorted. There's a handy script for this which aims to do the job for most cases, https://github.com/swift/swift/blob/master/BuildTools/FixIncludes.py . Simply run it like ./BuildTools/FixIncludes.py -i path_to_cpp_or_h_file.cpp
.
} | ||
} |
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.
There is a newline missing at the end of the file. While it's not required for C++11, currently all files in Swift have newlines at the end of the source files and our CI enforces this.
this->client_ = client_; | ||
} | ||
void XMLConsoleController::sendXML(std::string data){ | ||
client_->sendData(data); |
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.
This should probably check if client_
is actually set, not? If the developer forgets to call setClient(…)
pressing the send XML button would cause a crash I think.
@@ -12,13 +12,15 @@ | |||
#include <boost/signals2.hpp> | |||
|
|||
#include <Swiften/Base/SafeByteArray.h> | |||
#include <Swiften/Client/Client.h> |
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 the predeclaration below is sufficient, then there's no need to include Client.h
here, right? If not, the predeclaration is not needed anymore.
Swift/QtUI/QtXMLConsoleWidget.h
Outdated
@@ -42,5 +42,7 @@ namespace Swift { | |||
private: | |||
QTextEdit* textEdit; | |||
QCheckBox* enabled; | |||
QCheckBox* debugenabled; |
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.
The value of these members is undefined until you assign a value to them.
You can write QCheckBox* debugEnabled = nullptr
in the class definition in the header file to do so. Furthermore it should be debugEnabled
and not debugenabled
, as we camelCase for member variables. See the Naming section in https://github.com/swift/swift/wiki/Coding-Style .
Swift/QtUI/QtXMLSenderWidget.cpp
Outdated
* Copyright (c) 2017 Barun Parruck. | ||
* All rights reserved. | ||
* See the COPYING file for more information. | ||
*/ |
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.
Your copyright header should match the license you aim to submit the patch under. See for example cc873b3#diff-0856e1d938fb0b1106ce0267bbb319b0R1 .
Swift/QtUI/QtXMLSenderWidget.h
Outdated
@@ -0,0 +1,28 @@ | |||
/* |
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.
Is an additional widget really needed in this case, or wouldn't it be more straightforward to just put QTextEdit in the existing QtXMLConsoleWidget class. I think that would make the code a bit cleaner.
I've made the necessary changes :) Anything else? |
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.
Okay. I've build the app and ran it locally. Ideally I'd put
the checkbox and the send XML button at the bottom, next to the "Trace input/output" checkbox. Leaving space between all these and the clear button.
Furthermore I'd live the log at the top and the input below, ideally with a label above, maybe put it in a QGroupBox.
If i send some basic XML like "" I don't see it appear in the XML log. Is this code already hooked up?
Some smaller comments inline.
@@ -41,5 +43,13 @@ void XMLConsoleController::handleDataWritten(const SafeByteArray& data) { | |||
xmlConsoleWidget->handleDataWritten(data); | |||
} | |||
} | |||
|
|||
void XMLConsoleController::setClient(std::shared_ptr<Client> client_) |
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.
Parameter should not have the _ suffix. This way you won't need to use this in the next line too.
@@ -41,5 +43,13 @@ void XMLConsoleController::handleDataWritten(const SafeByteArray& data) { | |||
xmlConsoleWidget->handleDataWritten(data); | |||
} | |||
} | |||
|
|||
void XMLConsoleController::setClient(std::shared_ptr<Client> client_) | |||
{ |
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.
This { belongs at the end of the previous line.
{ | ||
this->client_ = client_; | ||
} | ||
void XMLConsoleController::sendXML(std::string data){ |
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.
Please add a newline between method definitions.
|
||
private: | ||
void handleUIEvent(std::shared_ptr<UIEvent> event); | ||
|
||
void sendXML(std::string data); |
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.
The parameter should have the type const std::string&
to avoid a copy.
Hi there, I've not looked at this yet, is it possible to get a screenshot of how the current input dialog looks, and what the button in the XML window looks like, please? |
Great, thanks. Some comments on that: It looks like at the moment it's only letting you put in a block of XML on its own, and doesn't have any mechanisms for choosing what stanza type you want to be sending, what the values of to/from/type/id should be? |
(That is what manually enter XML does, I'll change the name). No mechanisms for now, just the raw stuff. |
Thanks. It's probably not worth us spending much time reviewing the patch until the functionality is there, is it? |
Well, you can still send raw XML (or even non-XML), just not specific types yet. I'm more than happy to also hold off on reviewing until I add more functionality (though I'm really grateful to Tobias for reviewing, it's helped me fix a number of issues I wouldn't have been aware of). |
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.
Code stylistic the latest version is much better. Ideally we want to send Presence/IQ/Message stanzas (the C++ classes with the same names) with a RawXMLPayload ( https://github.com/swift/swift/blob/master/Swiften/Elements/RawXMLPayload.h ) as a child. That way we can call the correct method on the Client object (sendMessage(), sendPresence() and getIQRouter()->sendIQ(). This way it won't break XEP-0198 support.
The input form for the stanza could look like https://www.dropbox.com/s/wrbsb1ushi9zotp/Screenshot%202017-04-12%2012.15.06.png?dl=0 . This way the user can select a stanza type, specify the IQ/Presence/Message type, to, from and id. Plus the free form RawXMLPayload inside of it.
Let me know if you have further questions.
In Progress: Teaser Task for Gsoc - Sending raw xml via a "Send XML" button.
Steps:
Done
Not Done
4. On Button press, send XML in QtXMLSenderWidget.
5. Check for validity of XML before sending (optional)
Screenshots of work so far attached (only User Interface).