コード例 #1
0
/**
 * Gets a raw key press from user and converts it to a string.
 *
 * @param  self         Pointer to self.
 *         args         The arguments passed from python program, must
 *                      be parsed by python's parse tuple function.
 * @return              PyObject version of string.
 */
static PyObject * getkeypress(PyObject * self, PyObject *args) {
   char * returnString = "";

   rootCheck();

   Config config;
   getDeviceFile(&config);

   int kbd_fd = openKeyboardDeviceFile(config.deviceFile);
   assert(kbd_fd > 0);

   // Daemonize process. Don't change working directory but redirect standard
   // inputs and outputs to /dev/null
//   if (daemon(1, 0) == -1) {
//      LOG_ERROR("%s", strerror(errno));
//      exit(-1);
//   }

   uint8_t shift_pressed = 0;
   input_event event;
   while (read(kbd_fd, &event, sizeof(input_event)) > 0) {
      if (event.type == EV_KEY) {
         if (event.value == KEY_PRESS) {
            char *name = getKeyText(event.code, shift_pressed);
            if (isShift(event.code)) {
               shift_pressed++;
            }
            else if (strcmp(name, UNKNOWN_KEY) != 0) {
               //LOG("%s", name);
               returnString = strdup(name);
               break;

            }
         } else if (event.value == KEY_RELEASE) {
            if (isShift(event.code)) {
               shift_pressed--;
            }
         }
      }
      assert(shift_pressed >= 0 && shift_pressed <= 2);
   }

   Config_cleanup(&config);
   close(kbd_fd);
   return Py_BuildValue("s", returnString);
}
コード例 #2
0
bool Prefs_KeyboardShortcuts::exportKeySet(QString filename)
{
	QFileInfo fi = QFileInfo(filename);
	QString exportFileName;
	if (filename.endsWith(".xml"))
		exportFileName = filename;
	else
		exportFileName = filename+".xml";
	if (overwrite(this, exportFileName))
	{
		bool ok;
		QString setName = QInputDialog::getText(this, tr("Export Keyboard Shortcuts to File"), tr("Enter the name of the shortcut set:"), QLineEdit::Normal, QString::null, &ok);
		if (!( ok && !setName.isEmpty()) )
			return false;

		QDomDocument doc( "keymapentries" );
		QString keyset=QString("<shortcutset name=\"%1\"></shortcutset>").arg(setName);
		doc.setContent(keyset);
		QDomElement keySetElement=doc.documentElement();
		QMap<QString,Keys>::Iterator itEnd=keyMap.end();
		for (QMap<QString,Keys>::Iterator it=keyMap.begin(); it!=itEnd; ++it)
		{
			if (it.value().keySequence.isEmpty() && it.key().isEmpty())
				continue;
			QDomElement function_shortcut = doc.createElement("function");
			function_shortcut.setAttribute("name", it.key());
			function_shortcut.setAttribute("shortcut", getKeyText(it.value().keySequence));
			keySetElement.appendChild(function_shortcut);
		}
		QFile f(filename);
		if(!f.open(QIODevice::WriteOnly))
			return false;
		QDataStream s(&f);
		QByteArray xmltag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
		s.writeRawData(xmltag.data(), xmltag.length());
		QByteArray xmldoc = doc.toByteArray(4);
		s.writeRawData(xmldoc, xmldoc.length());
		f.close();
	}
	return true;
}
コード例 #3
0
ファイル: mythvirtualkeyboard.cpp プロジェクト: Olti/mythtv
void MythUIVirtualKeyboard::charClicked(void)
{
    if (!GetFocusWidget())
        return;

    KeyDefinition key = m_keyMap.value(GetFocusWidget()->objectName());
    QString c = getKeyText(key);

    if (m_composing)
    {
        if (m_composeStr.isEmpty())
            m_composeStr = c;
        else
        {
            // Produce the composed key.
            for (int i = 0; i < numcomps; i++)
            {
                if ((m_composeStr == comps[i][0]) && (c == comps[i][1]))
                {
                    c = comps[i][2];

                    emit keyPressed(c);

                    if (m_parentEdit)
                    {
                        QKeyEvent *event = new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier, c);
                        m_parentEdit->keyPressEvent(event);
                    }

                    break;
                }
            }

            m_composeStr.clear();
            m_composing = false;
            if (m_compButton)
                m_compButton->SetLocked(false);
        }
    }
    else
    {
        emit keyPressed(c);

        if (m_parentEdit)
        {
            QKeyEvent *event = new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier, c);
            m_parentEdit->keyPressEvent(event);
        }

        if (m_shift && !m_lock)
        {
            m_shift = false;
            if (m_shiftLButton)
                m_shiftLButton->SetLocked(false);
            if (m_shiftRButton)
                m_shiftRButton->SetLocked(false);

            updateKeys();
        }
    }
}
コード例 #4
0
ファイル: mythvirtualkeyboard.cpp プロジェクト: Olti/mythtv
void MythUIVirtualKeyboard::updateKeys(bool connectSignals)
{
    QList<MythUIType *> *children = GetAllChildren();
    for (int i = 0; i < children->size(); ++i)
    {
        MythUIButton *button = dynamic_cast<MythUIButton *>(children->at(i));
        if (button)
        {
            if (m_keyMap.contains(button->objectName()))
            {
                KeyDefinition key = m_keyMap.value(button->objectName());
                button->SetText(getKeyText(key));

                if (connectSignals)
                {
                    if (key.type == "shift")
                    {
                        if (!m_shiftLButton)
                            m_shiftLButton = button;
                        else if (!m_shiftRButton)
                            m_shiftRButton = button;

                        button->SetLockable(true);
                        connect(button, SIGNAL(Clicked()), SLOT(shiftClicked()));
                    }
                    else if (key.type == "char")
                        connect(button, SIGNAL(Clicked()), SLOT(charClicked()));
                    else if (key.type == "done")
                        connect(button, SIGNAL(Clicked()), SLOT(returnClicked()));
                    else if (key.type == "del")
                        connect(button, SIGNAL(Clicked()), SLOT(delClicked()));
                    else if (key.type == "lock")
                    {
                        m_lockButton = button;
                        m_lockButton->SetLockable(true);
                        connect(m_lockButton, SIGNAL(Clicked()), SLOT(lockClicked()));
                    }
                    else if (key.type == "alt")
                    {
                        m_altButton = button;
                        m_altButton->SetLockable(true);
                        connect(m_altButton, SIGNAL(Clicked()), SLOT(altClicked()));
                    }
                    else if (key.type == "comp")
                    {
                        m_compButton = button;
                        m_compButton->SetLockable(true);
                        connect(m_compButton, SIGNAL(Clicked()), SLOT(compClicked()));
                    }
                    else if (key.type == "moveleft")
                        connect(button, SIGNAL(Clicked()), SLOT(moveleftClicked()));
                    else if (key.type == "moveright")
                        connect(button, SIGNAL(Clicked()), SLOT(moverightClicked()));
                    else if (key.type == "back")
                        connect(button, SIGNAL(Clicked()), SLOT(backClicked()));
                }
            }
            else
                LOG(VB_GENERAL, LOG_WARNING,
                    QString("WARNING - Key '%1' not found in map")
                        .arg(button->objectName()));
        }
    }
}
コード例 #5
0
ファイル: browsethread.cpp プロジェクト: Drakeo/mixxx
void BrowseThread::populateModel() {
    m_path_mutex.lock();
    MDir thisPath = m_path;
    BrowseTableModel* thisModelObserver = m_model_observer;
    m_path_mutex.unlock();

    // Refresh the name filters in case we loaded new SoundSource plugins.
    QStringList nameFilters(SoundSourceProxy::getSupportedFileNamePatterns());

    QDirIterator fileIt(thisPath.dir().absolutePath(), nameFilters,
                        QDir::Files | QDir::NoDotAndDotDot);

    // remove all rows
    // This is a blocking operation
    // see signal/slot connection in BrowseTableModel
    emit(clearModel(thisModelObserver));

    QList< QList<QStandardItem*> > rows;

    int row = 0;
    // Iterate over the files
    while (fileIt.hasNext()) {
        // If a user quickly jumps through the folders
        // the current task becomes "dirty"
        m_path_mutex.lock();
        MDir newPath = m_path;
        m_path_mutex.unlock();

        if (thisPath.dir() != newPath.dir()) {
            qDebug() << "Abort populateModel()";
            return populateModel();
        }

        QString filepath = fileIt.next();
        auto pTrack = Track::newTemporary(filepath, thisPath.token());
        SoundSourceProxy(pTrack).updateTrackFromSource();

        QList<QStandardItem*> row_data;

        QStandardItem* item = new QStandardItem("0");
        item->setData("0", Qt::UserRole);
        row_data.insert(COLUMN_PREVIEW, item);

        item = new QStandardItem(pTrack->getFileName());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_FILENAME, item);

        item = new QStandardItem(pTrack->getArtist());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_ARTIST, item);

        item = new QStandardItem(pTrack->getTitle());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_TITLE, item);

        item = new QStandardItem(pTrack->getAlbum());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_ALBUM, item);

        item = new QStandardItem(pTrack->getAlbumArtist());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_ALBUMARTIST, item);

        item = new QStandardItem(pTrack->getTrackNumber());
        item->setToolTip(item->text());
        item->setData(item->text().toInt(), Qt::UserRole);
        row_data.insert(COLUMN_TRACK_NUMBER, item);

        const QString year(pTrack->getYear());
        item = new YearItem(year);
        item->setToolTip(year);
        // The year column is sorted according to the numeric calendar year
        item->setData(mixxx::TrackMetadata::parseCalendarYear(year), Qt::UserRole);
        row_data.insert(COLUMN_YEAR, item);

        item = new QStandardItem(pTrack->getGenre());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_GENRE, item);

        item = new QStandardItem(pTrack->getComposer());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_COMPOSER, item);

        item = new QStandardItem(pTrack->getGrouping());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_GROUPING, item);

        item = new QStandardItem(pTrack->getComment());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_COMMENT, item);

        QString duration = pTrack->getDurationText(mixxx::Duration::Precision::SECONDS);
        item = new QStandardItem(duration);
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_DURATION, item);

        item = new QStandardItem(pTrack->getBpmText());
        item->setToolTip(item->text());
        item->setData(pTrack->getBpm(), Qt::UserRole);
        row_data.insert(COLUMN_BPM, item);

        item = new QStandardItem(pTrack->getKeyText());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_KEY, item);

        item = new QStandardItem(pTrack->getType());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_TYPE, item);

        item = new QStandardItem(pTrack->getBitrateText());
        item->setToolTip(item->text());
        item->setData(pTrack->getBitrate(), Qt::UserRole);
        row_data.insert(COLUMN_BITRATE, item);

        QString location = pTrack->getLocation();
        QString nativeLocation = QDir::toNativeSeparators(location);
        item = new QStandardItem(nativeLocation);
        item->setToolTip(nativeLocation);
        item->setData(location, Qt::UserRole);
        row_data.insert(COLUMN_NATIVELOCATION, item);

        QDateTime modifiedTime = pTrack->getFileModifiedTime().toLocalTime();
        item = new QStandardItem(modifiedTime.toString(Qt::DefaultLocaleShortDate));
        item->setToolTip(item->text());
        item->setData(modifiedTime, Qt::UserRole);
        row_data.insert(COLUMN_FILE_MODIFIED_TIME, item);

        QDateTime creationTime = pTrack->getFileCreationTime().toLocalTime();
        item = new QStandardItem(creationTime.toString(Qt::DefaultLocaleShortDate));
        item->setToolTip(item->text());
        item->setData(creationTime, Qt::UserRole);
        row_data.insert(COLUMN_FILE_CREATION_TIME, item);

        const mixxx::ReplayGain replayGain(pTrack->getReplayGain());
        item = new QStandardItem(
                mixxx::ReplayGain::ratioToString(replayGain.getRatio()));
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_REPLAYGAIN, item);

        rows.append(row_data);
        ++row;
        // If 10 tracks have been analyzed, send it to GUI
        // Will limit GUI freezing
        if (row % 10 == 0) {
            // this is a blocking operation
            emit(rowsAppended(rows, thisModelObserver));
            qDebug() << "Append " << rows.count() << " from " << filepath;
            rows.clear();
        }
        // Sleep additionally for 10ms which prevents us from GUI freezes
        msleep(20);
    }
    emit(rowsAppended(rows, thisModelObserver));
    qDebug() << "Append last " << rows.count();
}