// Mode methods void Window::setMode() { if (_isFullScreen) { setFullscreenMode(); } else { setNormalMode(); } }
bool FalconCommLibFTDI::open(uint8_t device_index) { if(!m_isInitialized) { m_errorCode = FALCON_COMM_NOT_INITIALIZED; return false; } unsigned int count, i, status; struct ftdi_device_list *dev_list, *current; if(m_isCommOpen) close(); count = ftdi_usb_find_all((m_falconDevice), &dev_list, FALCON_VENDOR_ID, FALCON_PRODUCT_ID); if(count <= 0 || device_index > count) { ftdi_list_free(&dev_list); if(count == 0) { m_errorCode = FALCON_COMM_DEVICE_NOT_FOUND_ERROR; return false; } else if(device_index > count) { m_errorCode = FALCON_COMM_DEVICE_INDEX_OUT_OF_RANGE_ERROR; return false; } } for(i = 0, current = dev_list; current != NULL && i < device_index; current = current->next, ++i); if(current==NULL || (m_deviceErrorCode = ftdi_usb_open_dev((m_falconDevice), current->dev)) < 0) { m_errorCode = FALCON_COMM_DEVICE_ERROR; ftdi_list_free(&dev_list); return false; } setNormalMode(); ftdi_list_free(&dev_list); m_isCommOpen = true; if((m_deviceErrorCode = ftdi_usb_purge_buffers((m_falconDevice))) < 0) return false; setNormalMode(); return true; }
//Intercept keystrokes--- partially copied from Rekonq source code //TODO: Make replacements conditional so textboxes work normally void MiniWeb::keyPressEvent(QKeyEvent* e) { if (e->modifiers() == Qt::NoModifier) { if (isNormalMode()) { switch (e->key()) { case Qt::Key_J: e = new QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier); break; case Qt::Key_K: e = new QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier); break; case Qt::Key_L: e = new QKeyEvent(QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier); break; case Qt::Key_H: e = new QKeyEvent(QEvent::KeyPress, Qt::Key_Left, Qt::NoModifier); break; case Qt::Key_I: setInsertMode(); e = new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier); break; default: break; } } else { if (e->key() == Qt::Key_Escape) setNormalMode(); } } KWebView::keyPressEvent(e); }
/* * Constructs a QG_CommandWidget as a child of 'parent', with the * name 'name' and widget flags set to 'f'. */ QG_CommandWidget::QG_CommandWidget(QWidget* parent, const char* name, Qt::WindowFlags fl) : QWidget(parent, fl) , actionHandler(nullptr) { setObjectName(name); setupUi(this); connect(leCommand, SIGNAL(command(QString)), this, SLOT(handleCommand(QString))); connect(leCommand, SIGNAL(escape()), this, SLOT(escape())); connect(leCommand, SIGNAL(focusOut()), this, SLOT(setNormalMode())); connect(leCommand, SIGNAL(focusIn()), this, SLOT(setCommandMode())); connect(leCommand, SIGNAL(tabPressed()), this, SLOT(tabPressed())); connect(leCommand, SIGNAL(clearCommandsHistory()), teHistory, SLOT(clear())); connect(leCommand, SIGNAL(message(QString)), this, SLOT(appendHistory(QString))); connect(leCommand, &QG_CommandEdit::keycode, this, &QG_CommandWidget::handleKeycode); auto a1 = new QAction(QObject::tr("Keycode Mode"), this); a1->setObjectName("keycode_action"); a1->setCheckable(true); connect(a1, &QAction::toggled, this, &QG_CommandWidget::setKeycodeMode); options_button->addAction(a1); QSettings settings; if (settings.value("Widgets/KeycodeMode", false).toBool()) { leCommand->keycode_mode = true; a1->setChecked(true); } auto a2 = new QAction(QObject::tr("Load Command File"), this); connect(a2, &QAction::triggered, this, &QG_CommandWidget::chooseCommandFile); options_button->addAction(a2); auto a3 = new QAction(QObject::tr("Paste Multiple Commands"), this); connect(a3, &QAction::triggered, leCommand, &QG_CommandEdit::modifiedPaste); options_button->addAction(a3); options_button->setStyleSheet("QToolButton::menu-indicator { image: none; }"); }
//Ripped out of libusb_open_device_with_vid_pid bool FalconCommLibUSB::open(unsigned int index) { LOG_INFO("Opening device"); struct libusb_device **devs; struct libusb_device *found = NULL; struct libusb_device *dev; size_t i = 0; int count = 0; if ((m_deviceErrorCode = libusb_get_device_list(m_usbContext, &devs)) < 0) { LOG_ERROR("Device list not retrievable - Device error code " << m_deviceErrorCode); m_errorCode = FALCON_COMM_DEVICE_ERROR; return false; } while ((dev = devs[i++]) != NULL) { struct libusb_device_descriptor desc; m_deviceErrorCode = libusb_get_device_descriptor(dev, &desc); if (m_deviceErrorCode < 0) { LOG_ERROR("Device descriptor not retrievable - Device error code " << m_deviceErrorCode); m_errorCode = FALCON_COMM_DEVICE_ERROR; libusb_free_device_list(devs, 1); return false; } if (desc.idVendor == FALCON_VENDOR_ID && desc.idProduct == FALCON_PRODUCT_ID) { if(count == index) { found = dev; break; } ++count; } } if (found) { m_deviceErrorCode = libusb_open(found, &m_falconDevice); if (m_deviceErrorCode < 0) { LOG_ERROR("Cannot open device - Device error code " << m_deviceErrorCode); m_falconDevice = NULL; m_errorCode = FALCON_COMM_DEVICE_ERROR; libusb_free_device_list(devs, 1); return false; } } else { LOG_ERROR("Device index " << index << " out of range"); m_errorCode = FALCON_COMM_DEVICE_INDEX_OUT_OF_RANGE_ERROR; return false; } if ((m_deviceErrorCode = libusb_claim_interface(m_falconDevice, 0)) < 0) { LOG_ERROR("Cannot claim device interface - Device error code " << m_deviceErrorCode); m_errorCode = FALCON_COMM_DEVICE_ERROR; return false; } if ((m_deviceErrorCode = libusb_control_transfer(m_falconDevice, SIO_RESET_REQUEST_TYPE, SIO_RESET_REQUEST, SIO_RESET_PURGE_RX, INTERFACE_ANY, NULL, 0, 1000)) != 0) { m_errorCode = FALCON_COMM_DEVICE_ERROR; LOG_ERROR("Cannot rx purge - Device error code " << m_deviceErrorCode); return false; } if ((m_deviceErrorCode = libusb_control_transfer(m_falconDevice, SIO_RESET_REQUEST_TYPE, SIO_RESET_REQUEST, SIO_RESET_PURGE_TX, INTERFACE_ANY, NULL, 0, 1000)) != 0) { m_errorCode = FALCON_COMM_DEVICE_ERROR; LOG_ERROR("Cannot tx purge - Device error code " << m_deviceErrorCode); return false; } reset(); m_isCommOpen = true; setNormalMode(); return true; }