void Connection::close() {

        if (this->isOpened) {
            this->isOpened = false;
            performClose();
        }

        this->reader->join();
        this->reader.reset();
    }
Esempio n. 2
0
_choicedialog::_choicedialog(QWidget* _parent, QString _sAllowed) : QDialog(_parent)
{
  setAttribute(Qt::WA_DeleteOnClose);
  setWindowFlags(windowFlags() | Qt::Tool);

  QVBoxLayout *j = new QVBoxLayout();
  setLayout(j);

  QWidget *g = new QWidget();

  QVBoxLayout *jj = new QVBoxLayout();
  g->setLayout(jj);
  QScrollArea *a = new QScrollArea(this);
  a->setWidget(g);
  a->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
  a->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); 
  a->setWidgetResizable(true);

  QStringList l;
  if (_sAllowed.contains(";")) l = _sAllowed.split(";");
  else if (_sAllowed.contains(",")) l = _sAllowed.split(",");
  
  for (int i = 0; i < l.size(); i++){   
    
    pref[l.at(i)] = new QCheckBox(l.at(i), g); 
    QCheckBox *c = pref[l.at(i)];
    jj->addWidget(c);
    c->setChecked(sSet.contains(l.at(i)));
  }

  j->addWidget(a);

  setWindowTitle(tr("Selectable Properties"));
  setModal(true);
  
  QWidget *f = new QWidget();
  QHBoxLayout *fj = new QHBoxLayout();
  f->setLayout(fj);
  j->addWidget(f);
 
  QPushButton *p;

  p = new QPushButton(tr("&Ok"), f); fj->addWidget(p);
  connect(p, SIGNAL( clicked() ), this, SLOT(performClose()) );
 
  move(QApplication::desktop()->width() / 2 - sizeHint().width() / 2, QApplication::desktop()->height() / 2 - sizeHint().height() / 2);
  
  qApp->setActiveWindow(this);

  exec();
  
}
    void Connection::readerThread() {

        char buffer[BUFFER_SIZE];

        int readStatus = 0;
        memset(buffer, 0, sizeof (buffer));
        while (this->isOpened && (readStatus = recv(this->socketDescriptor, buffer, sizeof (buffer), 0) > 0)) {

            addToBuffer(buffer);
            memset(buffer, 0, sizeof (buffer));
        }

        if (this->isOpened) {
            performClose();
            this->isOpened = false;
        }
    }