SshClient.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. GNU General Public License version 3 notice
  3. Copyright (C) 2012 Mihawk <luiz@netdome.biz>. All rights reserved.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see < http://www.gnu.org/licenses/ >.
  14. */
  15. /* SSH client for connecting to QWNET central */
  16. #ifndef SSHCLIENT_H
  17. #define SSHCLIENT_H
  18. #include <QObject>
  19. class QProcess;
  20. class QDateTime;
  21. class QStringList;
  22. class App;
  23. class SshClient : public QObject
  24. {
  25. Q_OBJECT
  26. public:
  27. enum Error { NoError, ConnectionTimedOutError };
  28. explicit SshClient(App* app, QObject *parent = 0);
  29. ~SshClient();
  30. bool connectToHost(const QString& user, const QString &host);
  31. bool isConnected() const;
  32. void disconnectFromHost();
  33. void write(const QString& data);
  34. signals:
  35. void error(Error errorCode);
  36. void connected();
  37. protected:
  38. void timerEvent(QTimerEvent *e);
  39. private slots:
  40. void read();
  41. void exited(int exitCode);
  42. private:
  43. App* myApp;
  44. QProcess* myProcess;
  45. QRegExp* myCommandRegex;
  46. bool myConnectedFlag;
  47. int myConnectionTimerID;
  48. int myPingTimerID;
  49. int myPongTimerID;
  50. QStringList* myClients;
  51. void parse(const QDateTime& time, const QString& command, const QString& commandData);
  52. void ping();
  53. void pong();
  54. };
  55. #endif // SSHCLIENT_H