Exemple #1
0
int WebSocketImpl::attachSocket(TcpSocketImpl&& tcp, HttpParserImpl&& parser)
{
    is_server_ = true;
    ws_handler_.setDataCallback([this] (uint8_t* data, uint32_t len) { onWsData(data, len); });
    ws_handler_.setHandshakeCallback([this] (int err) { onWsHandshake(err); });
    tcp_socket_.setReadCallback([this] (int err) { onReceive(err); });
    tcp_socket_.setWriteCallback([this] (int err) { onSend(err); });
    tcp_socket_.setErrorCallback([this] (int err) { onClose(err); });
    setState(STATE_HANDSHAKE);

#ifdef KUMA_HAS_OPENSSL
    SOCKET_FD fd;
    SSL* ssl = nullptr;
    uint32_t flags = tcp.getFlags();
    int ret = tcp.detachFd(fd, ssl);
    ret = tcp_socket_.attachFd(fd, ssl, flags);
#else
    SOCKET_FD fd;
    uint32_t flags = tcp.getFlags();
    int ret = tcp.detachFd(fd);
    ret = tcp_socket_.attachFd(fd, flags);
#endif
    
    ws_handler_.setHttpParser(std::move(parser));
    return ret;
}
Exemple #2
0
void PhotoCropBox::init(const QImage &img, PeerData *peer) {
	if (peerIsChat(_peerId) || (peer && peer->isMegagroup())) {
		_title = lang(lng_create_group_crop);
	} else if (peerIsChannel(_peerId)) {
		_title = lang(lng_create_channel_crop);
	} else {
		_title = lang(lng_settings_crop_profile);
	}

	connect(&_done, SIGNAL(clicked()), this, SLOT(onSend()));
	connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
	if (peerToBareInt(_peerId)) {
		connect(this, SIGNAL(ready(const QImage&)), this, SLOT(onReady(const QImage&)));
	}

	int32 s = st::boxWideWidth - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
	_thumb = QPixmap::fromImage(img.scaled(s, s, Qt::KeepAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly);
	_thumbw = _thumb.width();
	_thumbh = _thumb.height();
	if (_thumbw > _thumbh) {
		_cropw = _thumbh - 20;
	} else {
		_cropw = _thumbw - 20;
	}
	_cropx = (_thumbw - _cropw) / 2;
	_cropy = (_thumbh - _cropw) / 2;

	_thumbx = (st::boxWideWidth - _thumbw) / 2;
	_thumby = st::boxPhotoPadding.top();
	setMouseTracking(true);

	resizeMaxHeight(st::boxWideWidth, st::boxPhotoPadding.top() + _thumbh + st::boxPhotoPadding.bottom() + st::boxTextFont->height + st::cropSkip + st::boxButtonPadding.top() + _done.height() + st::boxButtonPadding.bottom());
}
Exemple #3
0
void AddContactBox::initBox() {
	_width = st::addContactWidth;
	if (_peer) {
		if (_peer->chat) {
			_boxTitle = lang(lng_edit_group_title);
			_height = st::addContactTitleHeight + st::addContactPadding.top() + 1 * _firstInput.height() + st::addContactPadding.bottom() + _addButton.height();
		} else {
			_boxTitle = lang(_peer == App::self() ? lng_edit_self_title : lng_edit_contact_title);
			_height = st::addContactTitleHeight + st::addContactPadding.top() + 2 * _firstInput.height() + 1 * st::addContactDelta + st::addContactPadding.bottom() + _addButton.height();
		}
	} else {
		bool readyToAdd = !_phoneInput.text().isEmpty() && (!_firstInput.text().isEmpty() || !_lastInput.text().isEmpty());
		_boxTitle = lang(readyToAdd ? lng_confirm_contact_data : lng_enter_contact_data);
		_height = st::addContactTitleHeight + st::addContactPadding.top() + 3 * _firstInput.height() + 2 * st::addContactDelta + st::addContactPadding.bottom() + _addButton.height();
	}
	_firstInput.setGeometry(st::addContactPadding.left(), st::addContactTitleHeight + st::addContactPadding.top(), _width - st::addContactPadding.left() - st::addContactPadding.right(), _firstInput.height());
	_lastInput.setGeometry(st::addContactPadding.left(), _firstInput.y() + _firstInput.height() + st::addContactDelta, _firstInput.width(), _firstInput.height());
	_phoneInput.setGeometry(st::addContactPadding.left(), _lastInput.y() + _lastInput.height() + st::addContactDelta, _lastInput.width(), _lastInput.height());

	int32 buttonTop = (_peer ? (_peer->chat ? _firstInput : _lastInput) : _phoneInput).y() + _phoneInput.height() + st::addContactPadding.bottom();
	_cancelButton.move(0, buttonTop);
	_addButton.move(_width - _addButton.width(), buttonTop);
	_retryButton.move(_width - _retryButton.width(), buttonTop);
	_retryButton.hide();

	connect(&_addButton, SIGNAL(clicked()), this, SLOT(onSend()));
	connect(&_retryButton, SIGNAL(clicked()), this, SLOT(onRetry()));
	connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));

	resize(_width, _height);

	showAll();
	_cache = myGrab(this, rect());
	hideAll();
}
Exemple #4
0
void PhotoCropBox::keyPressEvent(QKeyEvent *e) {
	if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
		onSend();
	} else {
		AbstractBox::keyPressEvent(e);
	}
}
Exemple #5
0
void PhotoSendBox::keyPressEvent(QKeyEvent *e) {
	if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
		onSend((e->modifiers().testFlag(Qt::ControlModifier) || e->modifiers().testFlag(Qt::MetaModifier)) && e->modifiers().testFlag(Qt::ShiftModifier));
	} else {
		AbstractBox::keyPressEvent(e);
	}
}
Exemple #6
0
void PhotoSendBox::keyPressEvent(QKeyEvent *e) {
	if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
		onSend();
	} else if (e->key() == Qt::Key_Escape) {
		onCancel();
	}
}
Exemple #7
0
bool EReader::processNonBlockingSelect() {
	fd_set readSet, writeSet, errorSet;
	struct timeval tval;

	tval.tv_usec = 100 * 1000; //100 ms
	tval.tv_sec = 0;

	if( m_pClientSocket->fd() >= 0 ) {

		FD_ZERO( &readSet);
		errorSet = writeSet = readSet;

		FD_SET( m_pClientSocket->fd(), &readSet);

		if (m_needsWriteSelect)
			FD_SET( m_pClientSocket->fd(), &writeSet);

		FD_SET( m_pClientSocket->fd(), &errorSet);

		int ret = select( m_pClientSocket->fd() + 1, &readSet, &writeSet, &errorSet, &tval);

		if( ret == 0) { // timeout
			return false;
		}

		if( ret < 0) {	// error
			m_pClientSocket->eDisconnect();
			return false;
		}

		if( m_pClientSocket->fd() < 0)
			return false;

		if( FD_ISSET( m_pClientSocket->fd(), &errorSet)) {
			// error on socket
			m_pClientSocket->onError();
		}

		if( m_pClientSocket->fd() < 0)
			return false;

		if( FD_ISSET( m_pClientSocket->fd(), &writeSet)) {
			// socket is ready for writing
			onSend();
		}

		if( m_pClientSocket->fd() < 0)
			return false;

		if( FD_ISSET( m_pClientSocket->fd(), &readSet)) {
			// socket is ready for reading
			onReceive();
		}

		return true;
	}

	return false;
}
Exemple #8
0
void HttpClient::startRequest(std::string& url)
{
    http_request_.setDataCallback([this] (uint8_t* data, uint32_t len) { onData(data, len); });
    http_request_.setWriteCallback([this] (int err) { onSend(err); });
    http_request_.setErrorCallback([this] (int err) { onClose(err); });
    http_request_.setHeaderCompleteCallback([this] { onHeaderComplete(); });
    http_request_.setResponseCompleteCallback([this] { onRequestComplete(); });
    http_request_.sendRequest("GET", url.c_str(), "HTTP/1.1");
}
Exemple #9
0
void AddContactBox::keyPressEvent(QKeyEvent *e) {
	if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
		if (_firstInput.hasFocus()) {
			if (_peer && _peer->chat) {
				if (_firstInput.text().trimmed().isEmpty()) {
					_firstInput.setFocus();
					_firstInput.notaBene();
				} else {
					onSend();
				}
			} else {
				_lastInput.setFocus();
			}
		} else if (_lastInput.hasFocus()) {
			if (_peer) {
				if (_firstInput.text().trimmed().isEmpty()) {
					_firstInput.setFocus();
					_firstInput.notaBene();
				} else if (_lastInput.text().trimmed().isEmpty()) {
					_lastInput.setFocus();
					_lastInput.notaBene();
				} else {
					onSend();
				}
			} else if (_phoneInput.isEnabled()) {
				_phoneInput.setFocus();
			} else {
				onSend();
			}
		} else if (_phoneInput.hasFocus()) {
			if (_firstInput.text().trimmed().isEmpty()) {
				_firstInput.setFocus();
				_firstInput.notaBene();
			} else if (_lastInput.text().trimmed().isEmpty()) {
				_lastInput.setFocus();
				_lastInput.notaBene();
			} else {
				onSend();
			}
		}
	} else {
		AbstractBox::keyPressEvent(e);
	}
}
Exemple #10
0
int HttpTest::attachSocket(TcpSocket&& tcp, HttpParser&& parser)
{
    http_.setWriteCallback([this] (int err) { onSend(err); });
    http_.setErrorCallback([this] (int err) { onClose(err); });
    
    http_.setDataCallback([this] (uint8_t* data, uint32_t len) { onHttpData(data, len); });
    http_.setHeaderCompleteCallback([this] () { onHeaderComplete(); });
    http_.setRequestCompleteCallback([this] () { onRequestComplete(); });
    http_.setResponseCompleteCallback([this] () { onResponseComplete(); });
    
    return http_.attachSocket(std::move(tcp), std::move(parser));
}
Exemple #11
0
int HttpTest::attachFd(SOCKET_FD fd, uint32_t ssl_flags)
{
    http_.setWriteCallback([this] (int err) { onSend(err); });
    http_.setErrorCallback([this] (int err) { onClose(err); });
    
    http_.setDataCallback([this] (uint8_t* data, uint32_t len) { onHttpData(data, len); });
    http_.setHeaderCompleteCallback([this] () { onHeaderComplete(); });
    http_.setRequestCompleteCallback([this] () { onRequestComplete(); });
    http_.setResponseCompleteCallback([this] () { onResponseComplete(); });
    http_.setSslFlags(ssl_flags);
    return http_.attachFd(fd);
}
void UdpWriteModule::pingRemote(TokenT udpToken)
{
	dbglog << "UdpWriteModule #" << mPeerId
	       << " pinging remote " << *mRemoteEndpoint
	       << " aka #" << mPeerId
	       << " with token: " << udpToken;
	
	CharArray512T ca512;
	std::copy(udpToken.begin(), udpToken.end(), ca512.begin());
	DataPayload payload(ID::NE_PING_UDP, 0, 0, udpToken.size(), ca512);
	onSend(payload);
}
void ToyCmdGrid::onSendAllTimeout()
{
	if(m_SendAllIndex < m_List.size())
	{
		ToyCmdWidget *w = static_cast<ToyCmdWidget*>( m_List[m_SendAllIndex] );
		onSend(w);
		m_SendAllIndex++;
	}
	
	if(m_SendAllIndex >= m_List.size())
		m_SendAllTimer->stop();
	
	UpdateSendAllButton();
}
Exemple #14
0
int WebSocketImpl::attachFd(SOCKET_FD fd, uint32_t flags, const uint8_t* init_data, uint32_t init_len)
{
    is_server_ = true;
    if(init_data && init_len > 0) {
        init_data = new uint8_t(init_len);
        memcpy(init_data_, init_data, init_len);
        init_len_ = init_len;
    }
    ws_handler_.setDataCallback([this] (uint8_t* data, uint32_t len) { onWsData(data, len); });
    ws_handler_.setHandshakeCallback([this] (int err) { onWsHandshake(err); });
    tcp_socket_.setReadCallback([this] (int err) { onReceive(err); });
    tcp_socket_.setWriteCallback([this] (int err) { onSend(err); });
    tcp_socket_.setErrorCallback([this] (int err) { onClose(err); });
    setState(STATE_HANDSHAKE);
    return tcp_socket_.attachFd(fd, flags);
}
void ToyCmdGrid::SendAll()
{
	if(Toy::GetCmdSendAllDelayMS() == 0)
	{
		m_SendAllTimer->stop();
		for(WIDGET_LIST::const_iterator i=m_List.begin(); i!=m_List.end(); i++)
			onSend( static_cast<ToyCmdWidget*>(*i) );
	}
	else
	{
		m_SendAllIndex = 0;
		m_SendAllTimer->start( Toy::GetCmdSendAllDelayMS() );
	}
	
	UpdateSendAllButton();
}
Exemple #16
0
PhotoCropBox::PhotoCropBox(const QImage &img, const PeerId &peer, bool upload) : AbstractBox()
, _downState(0)
, _done(this, lang(lng_settings_save), st::defaultBoxButton)
, _cancel(this, lang(lng_cancel), st::cancelBoxButton)
, _img(img)
, _peerId(peer) {
	if (peerIsChannel(_peerId)) {
		_title = lang(lng_create_channel_crop);
	} else if (peerIsChat(_peerId)) {
		_title = lang(lng_create_group_crop);
	} else {
		_title = lang(lng_settings_crop_profile);
	}

	connect(&_done, SIGNAL(clicked()), this, SLOT(onSend()));
	connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
	if (_peerId && upload) {
		connect(this, SIGNAL(ready(const QImage&)), this, SLOT(onReady(const QImage&)));
	}
Exemple #17
0
PhotoSendBox::PhotoSendBox(const QString &phone, const QString &fname, const QString &lname, MsgId replyTo) : _img(0),
_thumbx(0), _thumby(0), _thumbw(0), _thumbh(0), _namew(0), _textw(0),
_compressed(this, lang(lng_send_image_compressed), true),
_sendButton(this, lang(lng_send_button), st::btnSelectDone),
_cancelButton(this, lang(lng_cancel), st::btnSelectCancel),
_phone(phone), _fname(fname), _lname(lname), _replyTo(replyTo) {
	connect(&_sendButton, SIGNAL(clicked()), this, SLOT(onSend()));
	connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(onClose()));

	_compressed.hide();

	_name = lng_full_name(lt_first_name, _fname, lt_last_name, _lname);
	_namew = st::mediaFont->width(_name);
	_size = _phone;
	_textw = qMax(_namew, st::mediaFont->width(_size));

	resizeMaxHeight(st::boxWideWidth, st::boxPadding.top() + st::boxFont->height + st::boxPadding.bottom() + st::mediaPadding.top() + st::mediaThumbSize + st::mediaPadding.bottom() + st::boxPadding.bottom() + _sendButton.height());
	prepare();
}
void TcpNet::send(const Networking::Address* from, const Networking::Address* to,
			std::unique_ptr<Networking::Buffer> buffer)
throw ()
{
	assert(from);
	assert(to);
	assert(to->getOrigin()==Networking::Origin::TCP);
	assert(buffer.get());

	std::unique_ptr<Utils::Command> cmd (new TcpNetCommandSend(*this,
		[this] (std::unique_ptr<Networking::Address> a, std::unique_ptr<Networking::Address> b,
				std::unique_ptr<Networking::Buffer> c) {
				onSend(std::move(a), std::move(b), std::move(c));
		},
		from,
		to,
		std::move(buffer)
	));
	mCtx->processor.process(std::move(cmd));
}
Exemple #19
0
PhotoSendBox::PhotoSendBox(const QString &phone, const QString &fname, const QString &lname) : _img(0),
_thumbx(0), _thumby(0), _thumbw(0), _thumbh(0), _namew(0), _textw(0),
_compressed(this, lang(lng_send_image_compressed), true),
_sendButton(this, lang(lng_send_button), st::btnSelectDone),
_cancelButton(this, lang(lng_cancel), st::btnSelectCancel),
_phone(phone), _fname(fname), _lname(lname),
a_opacity(0, 1) {
	connect(&_sendButton, SIGNAL(clicked()), this, SLOT(onSend()));
	connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));

	_width = st::confirmWidth;
	_compressed.hide();
	_height = st::boxPadding.top() + st::boxFont->height + st::boxPadding.bottom() + st::mediaPadding.top() + st::mediaThumbSize + st::mediaPadding.bottom() + st::boxPadding.bottom() + _sendButton.height();

	_name = _fname + QChar(' ') + _lname;
	_namew = st::mediaFont->m.width(_name);
	_size = _phone;
	_textw = qMax(_namew, st::mediaFont->m.width(_size));

	resize(_width, _height);
}
Exemple #20
0
int WebSocketImpl::connect_i(const std::string& ws_url)
{
    if(!uri_.parse(ws_url)) {
        return false;
    }
    tcp_socket_.setReadCallback([this] (int err) { onReceive(err); });
    tcp_socket_.setWriteCallback([this] (int err) { onSend(err); });
    tcp_socket_.setErrorCallback([this] (int err) { onClose(err); });
    setState(STATE_CONNECTING);
    std::string str_port = uri_.getPort();
    uint16_t port = 80;
    uint32_t flag = 0;
    if(is_equal("wss", uri_.getScheme())) {
        port = 443;
        flag = FLAG_HAS_SSL;
    }
    if(!str_port.empty()) {
        port = atoi(str_port.c_str());
    }
    return tcp_socket_.connect(uri_.getHost().c_str(), port, [this] (int err) { onConnect(err); }, flag);
}
Exemple #21
0
PhotoSendBox::PhotoSendBox(const ReadyLocalMedia &img) : _img(img),
	_sendButton(this, lang(lng_send_button), st::btnSelectDone),
	_cancelButton(this, lang(lng_cancel), st::btnSelectCancel),
	a_opacity(0, 1) {

	connect(&_sendButton, SIGNAL(clicked()), this, SLOT(onSend()));
	connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));

	int32 maxW = 0, maxH = 0;
	for (PreparedPhotoThumbs::const_iterator i = img.photoThumbs.cbegin(), e = img.photoThumbs.cend(); i != e; ++i) {
		if (i->width() >= maxW && i->height() >= maxH) {
			_thumb = *i;
			maxW = _thumb.width();
			maxH = _thumb.height();
		}
	}
	int32 tw = _thumb.width(), th = _thumb.height();
	if (!tw || !th) {
		tw = th = 1;
	}
	_width = st::confirmWidth;
	_thumbw = _width - st::boxPadding.left() - st::boxPadding.right();
	if (_thumb.width() < _thumbw) {
		_thumbw = (_thumb.width() > 20) ? _thumb.width() : 20;
	}
	int32 maxthumbh = qRound(1.5 * _thumbw);
	_thumbh = qRound(th * float64(_thumbw) / tw);
	if (_thumbh > maxthumbh) {
		_thumbw = qRound(_thumbw * float64(maxthumbh) / _thumbh);
		_thumbh = maxthumbh;
		if (_thumbw < 10) {
			_thumbw = 10;
		}
	}
	_height = _thumbh + st::boxPadding.top() + st::boxFont->height + st::boxPadding.bottom() + st::boxPadding.bottom() + _sendButton.height();

	_thumb = QPixmap::fromImage(_thumb.toImage().scaled(_thumbw, _thumbh, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));

	resize(_width, _height);
}
Exemple #22
0
void AddContactBox::initBox() {
	if (_peer) {
		if (_peer->chat) {
			_boxTitle = lang(lng_edit_group_title);
			setMaxHeight(st::boxTitleHeight + st::addContactPadding.top() + 1 * _firstInput.height() + st::addContactPadding.bottom() + _addButton.height());
		} else {
			_boxTitle = lang(_peer == App::self() ? lng_edit_self_title : lng_edit_contact_title);
			setMaxHeight(st::boxTitleHeight + st::addContactPadding.top() + 2 * _firstInput.height() + 1 * st::addContactDelta + st::addContactPadding.bottom() + _addButton.height());
		}
	} else {
		bool readyToAdd = !_phoneInput.text().isEmpty() && (!_firstInput.text().isEmpty() || !_lastInput.text().isEmpty());
		_boxTitle = lang(readyToAdd ? lng_confirm_contact_data : lng_enter_contact_data);
		setMaxHeight(st::boxTitleHeight + st::addContactPadding.top() + 3 * _firstInput.height() + 2 * st::addContactDelta + st::addContactPadding.bottom() + _addButton.height());
	}
	_retryButton.hide();

	connect(&_addButton, SIGNAL(clicked()), this, SLOT(onSend()));
	connect(&_retryButton, SIGNAL(clicked()), this, SLOT(onRetry()));
	connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(onClose()));

	prepare();
}
Exemple #23
0
PidDlg::PidDlg(QString partname, int jointIndex,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::PidDlg)
{
    ui->setupUi(this);

    this->jointIndex = jointIndex;

    QString title = QString("Pid Control %1 JNT:%2").arg(partname).arg(jointIndex);
    setWindowTitle(title);

    connect(ui->btnRefresh, SIGNAL(clicked()), this, SLOT(onRefresh()));
    connect(ui->btnSend,SIGNAL(clicked()),this,SLOT(onSend()));
    connect(ui->btnCancel,SIGNAL(clicked()),this,SLOT(onCancel()));

    ui->tablePosition->setItemDelegate(new TableDoubleDelegate);
    ui->tableVelocity->setItemDelegate(new TableDoubleDelegate);
    ui->tableTorque->setItemDelegate(new TableDoubleDelegate);
    ui->tableStiffness->setItemDelegate(new TableDoubleDelegate);
    ui->tableOpenloop->setItemDelegate(new TableDoubleDelegate);
    ui->tableCurrent->setItemDelegate(new TableDoubleDelegate);
    ui->tableCurrent->setItemDelegate(new TableGenericDelegate);
}
Exemple #24
0
PhotoSendBox::PhotoSendBox(const ReadyLocalMedia &img) : _img(new ReadyLocalMedia(img)),
	_thumbx(0), _thumby(0), _thumbw(0), _thumbh(0), _namew(0), _textw(0),
	_compressed(this, lang(lng_send_image_compressed), cCompressPastedImage()),
	_sendButton(this, lang(lng_send_button), st::btnSelectDone),
	_cancelButton(this, lang(lng_cancel), st::btnSelectCancel),
	_replyTo(img.replyTo) {
	connect(&_sendButton, SIGNAL(clicked()), this, SLOT(onSend()));
	connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(onClose()));

	if (_img->type == ToPreparePhoto) {
		int32 maxW = 0, maxH = 0;
		for (PreparedPhotoThumbs::const_iterator i = _img->photoThumbs.cbegin(), e = _img->photoThumbs.cend(); i != e; ++i) {
			if (i->width() >= maxW && i->height() >= maxH) {
				_thumb = *i;
				maxW = _thumb.width();
				maxH = _thumb.height();
			}
		}
		int32 tw = _thumb.width(), th = _thumb.height();
		if (!tw || !th) {
			tw = th = 1;
		}
		_thumbw = width() - st::boxPadding.left() - st::boxPadding.right();
		if (_thumb.width() < _thumbw) {
			_thumbw = (_thumb.width() > 20) ? _thumb.width() : 20;
		}
		int32 maxthumbh = qMin(qRound(1.5 * _thumbw), int(st::confirmMaxHeight));
		_thumbh = qRound(th * float64(_thumbw) / tw);
		if (_thumbh > maxthumbh) {
			_thumbw = qRound(_thumbw * float64(maxthumbh) / _thumbh);
			_thumbh = maxthumbh;
			if (_thumbw < 10) {
				_thumbw = 10;
			}
		}
		resizeMaxHeight(st::boxWideWidth, _thumbh + st::boxPadding.top() + st::boxFont->height + st::boxPadding.bottom() + st::boxPadding.bottom() + _compressed.height() + _sendButton.height());

		_thumb = QPixmap::fromImage(_thumb.toImage().scaled(_thumbw * cIntRetinaFactor(), _thumbh * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly);
		_thumb.setDevicePixelRatio(cRetinaFactor());
	} else {
		_compressed.hide();
		if (!_img->photoThumbs.isEmpty()) {
			_thumb = _img->photoThumbs.cbegin().value();
			int32 tw = _thumb.width(), th = _thumb.height();
			if (_thumb.isNull() || !tw || !th) {
				_thumbw = _thumbx = _thumby = 0;
			} else if (tw > th) {
				_thumbw = (tw * st::mediaThumbSize) / th;
				_thumbx = (_thumbw - st::mediaThumbSize) / 2;
				_thumby = 0;
			} else {
				_thumbw = st::mediaThumbSize;
				_thumbx = 0;
				_thumby = ((th * _thumbw) / tw - st::mediaThumbSize) / 2;
			}
		}
		if (_thumbw) {
			_thumb = QPixmap::fromImage(_thumb.toImage().scaledToWidth(_thumbw * cIntRetinaFactor(), Qt::SmoothTransformation), Qt::ColorOnly);
			_thumb.setDevicePixelRatio(cRetinaFactor());
		}
		resizeMaxHeight(st::boxWideWidth, st::boxPadding.top() + st::boxFont->height + st::boxPadding.bottom() + st::mediaPadding.top() + st::mediaThumbSize + st::mediaPadding.bottom() + st::boxPadding.bottom() + _sendButton.height());

		_name = _img->filename;
		_namew = st::mediaFont->width(_name);
		_size = formatSizeText(_img->filesize);
		_textw = qMax(_namew, st::mediaFont->width(_size));
	}
	prepare();
}
Exemple #25
0
LRESULT ChatControl::onSend(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
  onSend();
  return 0;
}
Exemple #26
0
LRESULT ChatControl::onMessageKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled) {
  if (wParam != VK_TAB && !complete.empty()) {
    complete.clear();
  }
  if (wParam == VK_TAB) {
    onTab();
  }
  else if (!processHotKey(wParam)) {
    switch(wParam) 
    {
    case VK_RETURN:
      if ((GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_MENU) & 0x8000)) {
        bHandled = FALSE;
      } 
      else {
        onSend();
      }
      break;
    case VK_UP:
      if ((GetKeyState(VK_MENU) & 0x8000) || (((GetKeyState(VK_CONTROL) & 0x8000) == 0) ^ (BOOLSETTING(USE_CTRL_FOR_LINE_HISTORY) == true))) {
        //scroll up in chat command history
        //currently beyond the last command?
        if (curCommandPosition > 0) {
          //check whether current command needs to be saved
          if (curCommandPosition == prevCommands.size()) {
            AutoArray<TCHAR> messageContents(ctrlMessage.GetWindowTextLength()+2);
            ctrlMessage.GetWindowText(messageContents, ctrlMessage.GetWindowTextLength()+1);
            currentCommand = tstring(messageContents);
          }
          //replace current chat buffer with current command
          ctrlMessage.SetWindowText(prevCommands[--curCommandPosition].c_str());
        }
        // move cursor to end of line
        ctrlMessage.SetSel(ctrlMessage.GetWindowTextLength(), ctrlMessage.GetWindowTextLength());
      } 
      else {
        bHandled = FALSE;
      }
      break;
    case VK_DOWN:
      if ((GetKeyState(VK_MENU) & 0x8000) || (((GetKeyState(VK_CONTROL) & 0x8000) == 0) ^ (BOOLSETTING(USE_CTRL_FOR_LINE_HISTORY) == true))) {
        //scroll down in chat command history
        //currently beyond the last command?
        if (curCommandPosition + 1 < prevCommands.size()) {
          //replace current chat buffer with current command
          ctrlMessage.SetWindowText(prevCommands[++curCommandPosition].c_str());
        } 
        else if (curCommandPosition + 1 == prevCommands.size()) {
          //revert to last saved, unfinished command
          ctrlMessage.SetWindowText(currentCommand.c_str());
          ++curCommandPosition;
        }
        // move cursor to end of line
        ctrlMessage.SetSel(ctrlMessage.GetWindowTextLength(), ctrlMessage.GetWindowTextLength());
      } 
      else {
        bHandled = FALSE;
      }
      break;
    case VK_PRIOR: // page up
      ctrlClient.SendMessage(WM_VSCROLL, SB_PAGEUP);
      break;
    case VK_NEXT: // page down
      ctrlClient.SendMessage(WM_VSCROLL, SB_PAGEDOWN);
      break;
    case VK_HOME:
      if (!prevCommands.empty() && (GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_MENU) & 0x8000)) {
        curCommandPosition = 0;
        AutoArray<TCHAR> messageContents(ctrlMessage.GetWindowTextLength()+2);
        ctrlMessage.GetWindowText(messageContents, ctrlMessage.GetWindowTextLength()+1);
        currentCommand = tstring(messageContents);
        ctrlMessage.SetWindowText(prevCommands[curCommandPosition].c_str());
      } 
      else {
        bHandled = FALSE;
      }
      break;
    case VK_END:
      if ((GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_MENU) & 0x8000)) {
        curCommandPosition = prevCommands.size();
        ctrlMessage.SetWindowText(currentCommand.c_str());
      } 
      else {
        bHandled = FALSE;
      }
      break;
    default:
      bHandled = FALSE;
    }
  }
  return 0;
}
Exemple #27
0
void TcpSocketImpl::ioReady(uint32_t events)
{
    switch(getState())
    {
        case ST_CONNECTING:
        {
            if(events & KUMA_EV_ERROR) {
                KUMA_ERRXTRACE("ioReady, KUMA_EV_ERROR, events="<<events
                              <<", err="<<getLastError()<<", state="<<getState());
                onConnect(KUMA_ERROR_POLLERR);
            } else {
                bool destroyed = false;
                destroy_flag_ptr_ = &destroyed;
                onConnect(KUMA_ERROR_NOERR);
                if(destroyed) {
                    return ;
                }
                destroy_flag_ptr_ = nullptr;
                if((events & KUMA_EV_READ)) {
                    onReceive(0);
                }
            }
            break;
        }
            
        case ST_OPEN:
        {
#ifdef KUMA_HAS_OPENSSL
            if(ssl_handler_ && ssl_handler_->getState() == SslHandler::SslState::SSL_HANDSHAKE) {
                int err = KUMA_ERROR_NOERR;
                if(events & KUMA_EV_ERROR) {
                    err = KUMA_ERROR_POLLERR;
                } else {
                    SslHandler::SslState ssl_state = ssl_handler_->doSslHandshake();
                    if(SslHandler::SslState::SSL_ERROR == ssl_state) {
                        err = KUMA_ERROR_SSL_FAILED;
                    } else if(SslHandler::SslState::SSL_HANDSHAKE == ssl_state) {
                        return;
                    }
                }
                if(cb_connect_) {
                    EventCallback cb_connect = std::move(cb_connect_);
                    cb_connect(err);
                } else if(err != KUMA_ERROR_NOERR) {
                    onClose(err);
                } else {
                    events |= KUMA_EV_WRITE; // notify writable
                }
                if(err != KUMA_ERROR_NOERR) {
                    return;
                }
            }
#endif
            bool destroyed = false;
            destroy_flag_ptr_ = &destroyed;
            if(events & KUMA_EV_READ) {// handle EPOLLIN firstly
                onReceive(0);
            }
            if(destroyed) {
                return;
            }
            destroy_flag_ptr_ = nullptr;
            if((events & KUMA_EV_ERROR) && getState() == ST_OPEN) {
                KUMA_ERRXTRACE("ioReady, KUMA_EV_ERROR, events="<<events
                              <<", err="<<getLastError()<<", state="<<getState());
                onClose(KUMA_ERROR_POLLERR);
                break;
            }
            if((events & KUMA_EV_WRITE) && getState() == ST_OPEN) {
                onSend(0);
            }
            break;
        }
        default:
            //KUMA_WARNXTRACE("ioReady, invalid state="<<getState()
            //	<<", events="<<events);
            break;
    }
}