void KeyboardLayoutWidget::setKeyboardLayout(const QString& layout, const QString& variant)
{
    XkbRF_VarDefsRec rdefs;
    XkbComponentNamesRec rnames;
    QString rulesPath = "./rules/evdev";
    char c[] = "C";
    XkbRF_RulesPtr rules = XkbRF_Load (rulesPath.toLocal8Bit().data(), c, True, True);
    if (rules == NULL) {
        rulesPath = FcitxXkbFindXkbRulesFile();
        if (rulesPath.endsWith(".xml")) {
            rulesPath.chop(4);
        }
        rules = XkbRF_Load (rulesPath.toLocal8Bit().data(), c, True, True);
    }
    if (rules == NULL) {
        return;
    }
    memset (&rdefs, 0, sizeof (XkbRF_VarDefsRec));
    memset (&rnames, 0, sizeof (XkbComponentNamesRec));
    QString model, option;
    if (!FcitxXkbInitDefaultOption(model, option))
        return;

    rdefs.model = !model.isNull() ? strdup(model.toUtf8().constData()) : NULL;
    rdefs.layout =  !layout.isNull() ? strdup(layout.toUtf8().constData()) : NULL;
    rdefs.variant =  !variant.isNull() ? strdup(variant.toUtf8().constData()) : NULL;
    rdefs.options =  !option.isNull() ? strdup(option.toUtf8().constData()) : NULL;
    XkbRF_GetComponents (rules, &rdefs, &rnames);
    free (rdefs.model);
    free (rdefs.layout);
    free (rdefs.variant);
    free (rdefs.options);

    setKeyboard(&rnames);
}
Beispiel #2
0
void TKeyboard::attach(QFrame *frame, const QStringList &keyboards)
{
	if(_frame != NULL) {
		qDebug() << "Error, attach a keyboard without detach";
		detach();
	}

	_frame = frame;
	_keyboards = keyboards;

	_currentKeyboard = 0;
	setKeyboard(_keyboards[0]);
}
void SwitchLayout::reAlignCurrentIndex()
{
    if (m_CurrentIndexOfKeyBoard == m_KeyboardList.length() - 1) {
        m_CurrentIndexOfKeyBoard = 0;

        // make sure the listwidgetitem is positioned as initial after one-cycle selection
        if (m_KeyboardList.length() > 5) {
            for (int i = 0, length = m_KeyboardList.length(); i < length; i++) {
                QWidget *w = m_ListWidget->itemWidget(m_ListWidget->item(i));
                w->move(0, KEYBOARD_ITEM_HEIGHT * (i + 5 - length));
            }
        }
    } else {
        m_CurrentIndexOfKeyBoard++;
    }

    // apply changes
    setKeyboard();
}
Beispiel #4
0
void setAllKeyboards(LedState changes[])
{
    IOHIDManagerRef manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
    if (!manager) {
        fprintf(stderr, "Failed to create IOHID manager.\n");
        return;
    }
    
    CFDictionaryRef keyboard = getKeyboardDictionary();
    if (!keyboard) {
        fprintf(stderr, "Failed to get dictionary usage page for kHIDUsage_GD_Keyboard.\n");
        return;
    }
    
    IOHIDManagerOpen(manager, kIOHIDOptionsTypeNone);
    IOHIDManagerSetDeviceMatching(manager, keyboard);
    
    CFSetRef devices = IOHIDManagerCopyDevices(manager);
    if (devices) {
        CFIndex deviceCount = CFSetGetCount(devices);
        if (deviceCount == 0) {
            fprintf(stderr, "Could not find any keyboard devices.\n");
        }
        else {
            // Loop through all keyboards attempting to get or display led state
            IOHIDDeviceRef *deviceRefs = malloc(sizeof(IOHIDDeviceRef) * deviceCount);
            if (deviceRefs) {
                CFSetGetValues(devices, (const void **) deviceRefs);
                for (CFIndex deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++)
                    if (isKeyboardDevice(deviceRefs[deviceIndex]))
                        setKeyboard(deviceRefs[deviceIndex], keyboard, changes);
                
                free(deviceRefs);
            }
        }
        
        CFRelease(devices);
    }
    
    CFRelease(keyboard);
}
Beispiel #5
0
void TKeyboard::slotClicked(bool /*checked*/)
{
	if(_pressed != NULL) {
		if(_pressed->text() == QString("ALT")) {
			_currentKeyboard ++;
			if(_currentKeyboard >= _keyboards.size()) {
				_currentKeyboard = 0;		
			}
			setKeyboard(_keyboards[_currentKeyboard]);
		} else if(_pressed->text() == QString("CAPS")) {
			setUpcase(!_upcase);
		} else if(_pressed->text() == QString("SPACE")) {
			emit signalKey(" ");
		} else {
			emit signalKey(_pressed->text());
		}

		_pressed = NULL;
	} else {
		qDebug("Error, button clicked without having been pressed!");
	}
}
Beispiel #6
0
void menu(struct menuInfo* theSelectedInfo, int *theConfHasBeenUpdated)
{
  ENTER("menu");
  enum MENU_State aMenuState=MENU_Volume;
  struct menuInfo aOldInfo;
  
  if (!theSelectedInfo || !theConfHasBeenUpdated)
    {
      return;
    }

  memcpy( &aOldInfo, theSelectedInfo, sizeof(struct menuInfo));

  if (mustSetPreferences())
    {
      *theConfHasBeenUpdated=1;
    }
  else
    {
      setTextToSpeech( &(theSelectedInfo->myTextToSpeech), 
		       theSelectedInfo->myMenuLanguage,
		       theSelectedInfo->myDesktop,
		       0);
      aMenuState=MENU_End;
      *theConfHasBeenUpdated=0;
    }

  serialPortInit();

  while(aMenuState != MENU_End)
    {
      switch(aMenuState)
	{
	case MENU_Volume:
	  setVolume();
	  aMenuState = (GNC_UpArrowKey == getLastKeyPressed()) ? MENU_QuitExpected : MENU_Language;
	  break;

	case MENU_Language:
	  if (setMenuLanguage( &theSelectedInfo->myMenuLanguage))
	    {
	      theSelectedInfo->myUserConfIsKnown=1;
	      if (!aOldInfo.myUserConfIsKnown)
		{ /* The default keyboard must match the selected language */
		  theSelectedInfo->myKeyboard = getProbableKeyboard(theSelectedInfo->myMenuLanguage);
		  loadkeys( theSelectedInfo->myKeyboard);
		}

	      buildI18n( theSelectedInfo->myMenuLanguage, 
			 theSelectedInfo->myTextToSpeech, 
			 theSelectedInfo->myKeyboard,
			 theSelectedInfo->myKeyboardFeatures,
			 theSelectedInfo->myDesktop,
			 theSelectedInfo->myUserConfIsKnown);
	    }
	  aMenuState = (GNC_UpArrowKey == getLastKeyPressed()) ? MENU_Volume : MENU_Keyboard;
	  break;

	case MENU_Keyboard:
	  {
	    if(setKeyboard(&theSelectedInfo->myKeyboard, 
			   theSelectedInfo->myMenuLanguage))
	      {
		theSelectedInfo->myUserConfIsKnown=1;

		// The keyboard is available as soon as it is selected.
		loadkeys( theSelectedInfo->myKeyboard);

		buildI18n( theSelectedInfo->myMenuLanguage, 
			   theSelectedInfo->myTextToSpeech, 
			   theSelectedInfo->myKeyboard,
			   theSelectedInfo->myKeyboardFeatures,
			   theSelectedInfo->myDesktop,
			   theSelectedInfo->myUserConfIsKnown);
	      }
	    aMenuState = (GNC_UpArrowKey == getLastKeyPressed()) ? MENU_Language : MENU_KeyboardFeatures;	  
	  }
	  break;

	case MENU_KeyboardFeatures:
	  if (setKeyboardFeatures(& theSelectedInfo->myKeyboardFeatures))
	    {
	      theSelectedInfo->myUserConfIsKnown=1;
	      buildI18n( theSelectedInfo->myMenuLanguage, 
			 theSelectedInfo->myTextToSpeech, 
			 theSelectedInfo->myKeyboard,
			 theSelectedInfo->myKeyboardFeatures,
			 theSelectedInfo->myDesktop,
			 theSelectedInfo->myUserConfIsKnown);
	    }
	  aMenuState = (GNC_UpArrowKey == getLastKeyPressed()) ? MENU_Keyboard : MENU_Braille;	  
	  break;

	case MENU_Braille:
	  {
	    // The braille driver is installed as soon as it is selected.
	    struct brailleInfo aBrailleInfo;
	    getDefaultConf( theSelectedInfo->myKeyboard, & aBrailleInfo );
	    setBraille( &aBrailleInfo);
	    
	    aMenuState = (GNC_UpArrowKey == getLastKeyPressed()) ? MENU_KeyboardFeatures : MENU_Desktop;
	  }
	  break;

	case MENU_Desktop:
	  if (setDesktop( &(theSelectedInfo->myDesktop)))
	    {
	      theSelectedInfo->myUserConfIsKnown=1;	      
	      buildI18n( theSelectedInfo->myMenuLanguage, 
			 theSelectedInfo->myTextToSpeech, 
			 theSelectedInfo->myKeyboard,
			 theSelectedInfo->myKeyboardFeatures,
			 theSelectedInfo->myDesktop,
			 theSelectedInfo->myUserConfIsKnown);
	    }
	  aMenuState = (GNC_UpArrowKey == getLastKeyPressed()) ? MENU_Braille : MENU_TTS;
	  break;

	case MENU_TTS:
	  if (setTextToSpeech( &(theSelectedInfo->myTextToSpeech),
			       theSelectedInfo->myMenuLanguage,
			       theSelectedInfo->myDesktop,
			       1))
	    {
	      theSelectedInfo->myUserConfIsKnown=1;	      
	      buildI18n( theSelectedInfo->myMenuLanguage, 
			 theSelectedInfo->myTextToSpeech, 
			 theSelectedInfo->myKeyboard,
			 theSelectedInfo->myKeyboardFeatures,
			 theSelectedInfo->myDesktop,
			 theSelectedInfo->myUserConfIsKnown);
	    }
	  aMenuState = (GNC_UpArrowKey == getLastKeyPressed()) ? MENU_Desktop : MENU_Internet;
	  break;

	case MENU_Internet:
	  {
	    setInternet( theSelectedInfo);
	    aMenuState = (GNC_UpArrowKey == getLastKeyPressed()) ? MENU_TTS : MENU_PersistentStorage;
	  }
	  break;

	case MENU_PersistentStorage:
	  {
	    setPersistentStorage( theSelectedInfo);
	    aMenuState = (GNC_UpArrowKey == getLastKeyPressed()) ? MENU_Internet : MENU_QuitExpected;
	  }
	  break;

	case MENU_QuitExpected:
	  {
	    if (setQuitExpected())
	      {
		aMenuState = MENU_End;
	      }
	    else
	      {
		aMenuState = (GNC_UpArrowKey == getLastKeyPressed()) ? MENU_PersistentStorage : MENU_Volume;
	      }
	  }
	  break;

	default:
	  aMenuState = MENU_End; // Security
	  break;
	}
    }
  clearStoredSentences();

  if (!*theConfHasBeenUpdated)
    {
      *theConfHasBeenUpdated=(0!=memcmp( &aOldInfo, theSelectedInfo, sizeof(struct menuInfo)));

/* 	((aOldInfo.myMenuLanguage != theSelectedInfo->myMenuLanguage) */
/* 	 || (aOldInfo.myKeyboard != theSelectedInfo->myKeyboard) */
/* 	 || (aOldInfo.myKeyboardFeatures.myStickyKeysAreAvailable != theSelectedInfo->myKeyboardFeatures.myStickyKeysAreAvailable) */
/* 	 || (aOldInfo.myKeyboardFeatures.myRepeatKeysAreAvailable != theSelectedInfo->myKeyboardFeatures.myRepeatKeysAreAvailable) */
/* 	 || (aOldInfo.myTextToSpeech.myIdentifier != theSelectedInfo->myTextToSpeech.myIdentifier) */
/* 	 || (aOldInfo.myTextToSpeech.myLanguage != theSelectedInfo->myTextToSpeech.myLanguage) */
/* 	 || (aOldInfo.myTextToSpeech.myPort != theSelectedInfo->myTextToSpeech.myPort) */
/* 	 || (aOldInfo.myDesktop != theSelectedInfo->myDesktop)); */
    }
}
Beispiel #7
0
MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
{
    _currentKeyboard = 0;

    _mainLayout = new QVBoxLayout;
    _mainLayout->setSpacing(0);
    _mainLayout->setMargin(0);
    _mainLayout->setContentsMargins(10,10,10,0);

    QWidget *centralWidget = new QWidget;
    centralWidget->setLayout(_mainLayout);
    this->setCentralWidget(centralWidget);

    // create labels
    Label * label = new Label(2);
    label->setObjectName("2");
    _labels[label->objectName()] = label;
    connect(label, SIGNAL(selected()), this, SLOT(labelSelected()));
    _mainLayout->addWidget(label);

    // second row: UInt16 Hex
    QWidget *row = new QWidget;
    QLayout *rowLayout = new QHBoxLayout;
    rowLayout->setSpacing(0);
    rowLayout->setMargin(0);
    row->setLayout(rowLayout);
    _mainLayout->addWidget(row);

    label = new Label(10);
    label->setObjectName("10");
    _labels[label->objectName()] = label;
    connect(label, SIGNAL(selected()), this, SLOT(labelSelected()));
    row->layout()->addWidget(label);

    label = new Label(16);
    label->setObjectName("16");
    _labels[label->objectName()] = label;
    connect(label, SIGNAL(selected()), this, SLOT(labelSelected()));
    row->layout()->addWidget(label);

    // third row: Octal Char
    row = new QWidget;
    rowLayout = new QHBoxLayout;
    rowLayout->setSpacing(0);
    rowLayout->setMargin(0);
    row->setLayout(rowLayout);
    _mainLayout->addWidget(row);

    label = new Label(8);
    label->setObjectName("8");
    _labels[label->objectName()] = label;
    connect(label, SIGNAL(selected()), this, SLOT(labelSelected()));
    row->layout()->addWidget(label);

    label = new CharLabel();
    _labels["Char"] = label;
    connect(label, SIGNAL(selected()), this, SLOT(labelSelected()));
    row->layout()->addWidget(label);

    // keyboard box widget
    _keyboardBoxWidget = new QWidget;
    QLayout * keyboardBoxLayout = new QGridLayout;
    keyboardBoxLayout->setSpacing(0);
    keyboardBoxLayout->setMargin(0);
    keyboardBoxLayout->setContentsMargins(0,0,0,0);
    _keyboardBoxWidget->setLayout(keyboardBoxLayout);
    _keyboardBoxWidget->setFixedHeight(200);
    _mainLayout->addWidget(_keyboardBoxWidget);

    // keyboards
    Keyboard *keyboard = new Keyboard(16, 3);
    keyboard->setObjectName("16");
    connect(keyboard, SIGNAL(pressedButton(QString)), this, SLOT(pressedButton(QString)));
    _keyboards[keyboard->objectName()] = keyboard;

    keyboard = new Keyboard(8, 3);
    keyboard->setObjectName("8");
    connect(keyboard, SIGNAL(pressedButton(QString)), this, SLOT(pressedButton(QString)));
    _keyboards[keyboard->objectName()] = keyboard;

    keyboard = new Keyboard(10, 3);
    keyboard->setObjectName("10");
    connect(keyboard, SIGNAL(pressedButton(QString)), this, SLOT(pressedButton(QString)));
    _keyboards[keyboard->objectName()] = keyboard;

    keyboard = new Keyboard(2, 2);
    keyboard->setObjectName("2");
    connect(keyboard, SIGNAL(pressedButton(QString)), this, SLOT(pressedButton(QString)));
    _keyboards[keyboard->objectName()] = keyboard;

    setKeyboard(tr("10"));
    updateLabels();
}
Beispiel #8
0
void MainWindow::labelSelected() {
    Label * label = (Label *)sender();
    setKeyboard(label->objectName());
}
Beispiel #9
0
void TKeyboard::setUpcase(bool upcase)
{
	_upcase = upcase;

	setKeyboard(_keyboards[_currentKeyboard]);
}