Connection.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Connection.h
  3. * nirc
  4. *
  5. * Created by Niklas Bölter on 02.02.10.
  6. * Copyright 2010 Frubar Corporation.
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. *
  15. *
  16. */
  17. #ifndef NIRC_CONNECTION_H
  18. #define NIRC_CONNECTION_H
  19. #include <QObject>
  20. #include <QSslSocket>
  21. #include <QSslError>
  22. #include <QString>
  23. #include <QStringList>
  24. #include <QQueue>
  25. #include <QHostInfo>
  26. #include <QTimer>
  27. #include <QDebug>
  28. struct ConnectionSettings {
  29. int id;
  30. QString host;
  31. quint16 port;
  32. QString name;
  33. bool isSSL;
  34. bool ignoreSSLErrors;
  35. };
  36. class Connection : public QObject
  37. {
  38. Q_OBJECT
  39. public:
  40. Connection(int cid);
  41. int getID();
  42. void open(ConnectionSettings settings);
  43. void splitLines();
  44. bool hasLines();
  45. void sendLine(QString line);
  46. QString nextLine();
  47. private:
  48. int id;
  49. bool ssl;
  50. bool ignoreSSLErrors;
  51. QSslSocket *socket;
  52. QString readBuffer;
  53. QByteArray writeBuffer;
  54. QQueue<QString> lines;
  55. private slots:
  56. void sendBuffer();
  57. void readyRead();
  58. void encrypted();
  59. void connected();
  60. void disconnected();
  61. void socketError();
  62. void sslErrors(QList<QSslError> error);
  63. signals:
  64. void dataReady(int cid);
  65. void connected(int cid);
  66. void disconnected(int cid);
  67. void message(int cid, QString msg);
  68. };
  69. #endif