#include <hws.h> #include <QDebug> #include <QObject> #include <QCoreApplication> #include <QHash> #include <QTextStream> #include <QUrl> #include <QThread> #include <unistd.h> // The majority of our logic comes out of remote calls, so you'll need to // use signals to handle almost all real methods of the SDK. class HandleRequests : public QObject { Q_OBJECT public: HandleRequests(QObject *parent) : QObject(parent), mClient(NULL) { } void setClient(hws::Client * client) { mClient = client; connect(mClient, &hws::Client::logInDone, this, &HandleRequests::logInDone); connect(mClient, &hws::Client::validateSessionDone, this, &HandleRequests::validateSessionDone); connect(mClient, &hws::Client::executeMethodDone, this, &HandleRequests::executeMethodDone); } // We begin here by logging in with some test data. void start() { hws::Session session; // session.setUrl(QUrl("http://localhost:9000")); session.setUrl(QUrl("https://helix_ws.das.perforce.com")); session.setUser("super"); session.setP4Ticket("81E326680B04C811F86E705D97B0C8AD"); // session.setP4Ticket("INVALID"); mClient->setSession(session); mClient->validateSession(); // mClient->logIn("super", "superuser1A!"); // mClient->logIn("jdoe", "johndoe1A!"); } signals: void finished(); public slots: void logInDone(hws::RequestErrorPtr error, hws::SessionPtr session) { // If there's any errors, you're going to get those set via the // RequestError class. if (error) { qDebug() << "Error: " << error->messageText(); throw error; } // Now that we've logged in, we know there's a session, so prepare // the request to list some projects. QSharedPointer<hws::Client::QStringHash> params(new hws::Client::QStringHash); (*params)["details"] = "true"; mClient->executeMethod("GET", "/projects/v1", params); } void validateSessionDone(hws::RequestErrorPtr error) { // If there's any errors, you're going to get those set via the // RequestError class. if (error) { qDebug() << "Error: " << error->messageText(); throw error; } QSharedPointer<hws::Client::QStringHash> params(new hws::Client::QStringHash); (*params)["details"] = "true"; mClient->executeMethod("GET", "/projects/v1", params); } void executeMethodDone(hws::RequestErrorPtr error, const QString &method, const QString &path, const QSharedPointer<hws::Client::QVariantMapList> data) { // Just print out the names of projects we have here. There's no // error checking just because this is a simple example app. QTextStream ts(stdout); ts << "Projects:\n"; foreach(QVariantMap result, *data) { ts << result["name"].toString() << '\n'; } ts.flush(); // Let the application code know we're done waiting. emit finished(); } public: hws::Client * mClient; }; int main(int argc, char** argv) { QCoreApplication app(argc, argv); hws::Client client(&app); // The server configuration here points to HWS running in a development mode. client.setUrl(QUrl("https://helix_ws.das.perforce.com")); client.ignoreSslErrors(true); // client.setHWSPrefixPath("/hws"); // client.setUrl(QUrl("http://localhost:9000")); // client.setHWSPrefixPath(""); // This is a special setting for project listing against a single // Helix Versioning Engine instance. client.addRequestConfig("HVE-PROJECTS-PATH", "//depot/projects"); client.addRequestConfig("P4PORT", "helix_ws.das.perforce.com:1666"); HandleRequests handleRequests(&app); handleRequests.setClient(&client); handleRequests.start(); QObject::connect(&handleRequests, SIGNAL(finished()), &app, SLOT(quit())); app.exec(); } #include "Example.moc"
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 15688 | Doug Scheirer |
Populate -o //guest/perforce_software/helix-web-services/... //guest/doug_scheirer/helix-web-services/.... |
||
//guest/perforce_software/helix-web-services/main/build/helix_web_services_client_qt/Example.cpp | |||||
#3 | 15601 | tjuricek | validateSessionFinished should not emit a signal if an error occurred on the request | ||
#2 | 15521 | tjuricek | Call client.ignoreSslErrors(true) to bypass self-signed cert problems. | ||
#1 | 15448 | tjuricek |
Qt SDK revision: remove higher-level objects from the SDK. It's likely we could add higher-level objects that adapt the executeMethodDone and convert the variant maps to something, well, typed and easier to use. That's not in my current scope of work, however. |