KDirWatchTest_GUI::KDirWatchTest_GUI() : QWidget() { QPushButton *e,*f; QVBoxLayout *lay = new QVBoxLayout(this); lay->setMargin( 0 ); lay->addWidget(l1 = new QLineEdit( "Test 1", this)); lay->addWidget(l2 = new QLineEdit( "Test 2", this)); lay->addWidget(l3 = new QLineEdit( "Test 3", this)); lay->addWidget(m_eventBrowser = new QTextBrowser(this)); lay->addWidget(d = new QLineEdit( "Status", this)); lay->addWidget(e = new QPushButton("new file", this)); lay->addWidget(f = new QPushButton("delete file", this)); dir = QDir::currentPath(); file = dir + "/testfile_kdirwatchtest_gui"; w1 = new KDirWatch(); w1->setObjectName("w1"); w2 = new KDirWatch(); w2->setObjectName("w2"); w3 = new KDirWatch(); w3->setObjectName("w3"); connect(w1, SIGNAL(dirty(QString)), this, SLOT(slotDir1(QString))); connect(w2, SIGNAL(dirty(QString)), this, SLOT(slotDir2(QString))); connect(w3, SIGNAL(dirty(QString)), this, SLOT(slotDir3(QString))); w1->addDir(dir); w2->addDir(dir); w3->addDir(dir); KDirWatch* w4 = new KDirWatch(this); w4->setObjectName("w4"); w4->addDir(dir, KDirWatch::WatchFiles|KDirWatch::WatchSubDirs); connect(w1, SIGNAL(dirty(QString)), this, SLOT(slotDirty(QString))); connect(w1, SIGNAL(created(QString)), this, SLOT(slotCreated(QString))); connect(w1, SIGNAL(deleted(QString)), this, SLOT(slotDeleted(QString))); KDirWatch* w5 = new KDirWatch(this); w5->setObjectName("w5"); w5->addFile(file); connect(w5, SIGNAL(dirty(QString)), this, SLOT(slotDirty(QString))); connect(w5, SIGNAL(created(QString)), this, SLOT(slotCreated(QString))); connect(w5, SIGNAL(deleted(QString)), this, SLOT(slotDeleted(QString))); lay->addWidget(new QLabel("Directory = " + dir, this)); lay->addWidget(new QLabel("File = " + file, this)); connect(e, SIGNAL(clicked()), this, SLOT(slotNewClicked())); connect(f, SIGNAL(clicked()), this, SLOT(slotDeleteClicked())); setMinimumWidth(800); setMinimumHeight(400); }
void DlgPrefController::removeOutputMappings() { if (m_pOutputProxyModel) { QItemSelection selection = m_pOutputProxyModel->mapSelectionToSource( m_ui.m_pOutputMappingTableView->selectionModel()->selection()); QModelIndexList selectedIndices = selection.indexes(); if (selectedIndices.size() > 0 && m_pOutputTableModel) { m_pOutputTableModel->removeMappings(selectedIndices); slotDirty(); } } }
void DlgPrefController::clearAllOutputMappings() { if (QMessageBox::warning( this, tr("Clear Output Mappings"), tr("Are you sure you want to clear all output mappings?"), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel) != QMessageBox::Ok) { return; } if (m_pOutputTableModel) { m_pOutputTableModel->clear(); slotDirty(); } }
void DlgPrefController::addOutputMapping() { if (m_pOutputTableModel) { m_pOutputTableModel->addEmptyMapping(); // Ensure the added row is visible. QModelIndex left = m_pOutputProxyModel->mapFromSource( m_pOutputTableModel->index(m_pOutputTableModel->rowCount() - 1, 0)); QModelIndex right = m_pOutputProxyModel->mapFromSource( m_pOutputTableModel->index(m_pOutputTableModel->rowCount() - 1, m_pOutputTableModel->columnCount() - 1)); m_ui.m_pOutputMappingTableView->selectionModel()->select( QItemSelection(left, right), QItemSelectionModel::Clear | QItemSelectionModel::Select); m_ui.m_pOutputMappingTableView->scrollTo(left); slotDirty(); } }
void DlgPrefController::showLearningWizard() { // If the user has checked the "Enabled" checkbox but they haven't hit OK to // apply it yet, prompt them to apply the settings before we open the // learning dialog. If we don't apply the settings first and open the // device, the dialog won't react to controller messages. if (m_ui.chkEnabledDevice->isChecked() && !m_pController->isOpen()) { QMessageBox::StandardButton result = QMessageBox::question( this, tr("Apply device settings?"), tr("Your settings must be applied before starting the learning wizard.\n" "Apply settings and continue?"), QMessageBox::Ok | QMessageBox::Cancel, // Buttons to be displayed QMessageBox::Ok); // Default button // Stop if the user has not pressed the Ok button, // which could be the Cancel or the Close Button. if (result != QMessageBox::Ok) { return; } } slotApply(); // After this point we consider the mapping wizard as dirtying the preset. slotDirty(); // Note that DlgControllerLearning is set to delete itself on close using // the Qt::WA_DeleteOnClose attribute (so this "new" doesn't leak memory) m_pDlgControllerLearning = new DlgControllerLearning(this, m_pController); m_pDlgControllerLearning->show(); ControllerLearningEventFilter* pControllerLearning = m_pControllerManager->getControllerLearningEventFilter(); pControllerLearning->startListening(); connect(pControllerLearning, SIGNAL(controlClicked(ControlObject*)), m_pDlgControllerLearning, SLOT(controlClicked(ControlObject*))); connect(m_pDlgControllerLearning, SIGNAL(listenForClicks()), pControllerLearning, SLOT(startListening())); connect(m_pDlgControllerLearning, SIGNAL(stopListeningForClicks()), pControllerLearning, SLOT(stopListening())); connect(m_pDlgControllerLearning, SIGNAL(stopLearning()), this, SLOT(show())); connect(m_pDlgControllerLearning, SIGNAL(inputMappingsLearned(MidiInputMappings)), this, SLOT(midiInputMappingsLearned(MidiInputMappings))); emit(mappingStarted()); connect(m_pDlgControllerLearning, SIGNAL(stopLearning()), this, SIGNAL(mappingEnded())); }
void DlgPrefController::slotLoadPreset(int chosenIndex) { if (chosenIndex == 0) { // User picked ... return; } const QString presetPath = m_ui.comboBoxPreset->itemData(chosenIndex).toString(); // When loading the preset, we only want to load from the same dir as the // preset itself, otherwise when loading from the system-wide dir we'll // start the search in the user's dir find the existing script, // and do nothing. const QFileInfo presetFileInfo(presetPath); QList<QString> presetDirs; presetDirs.append(presetFileInfo.canonicalPath()); ControllerPresetPointer pPreset = ControllerPresetFileHandler::loadPreset( presetPath, ControllerManager::getPresetPaths(m_pConfig)); // Import the preset scripts to the user scripts folder. for (QList<ControllerPreset::ScriptFileInfo>::iterator it = pPreset->scripts.begin(); it != pPreset->scripts.end(); ++it) { // No need to import builtin scripts. if (it->builtin) { continue; } QString scriptPath = ControllerManager::getAbsolutePath( it->name, presetDirs); QString importedScriptFileName; // If a conflict exists then importScript will provide a new filename to // use. If importing fails then load the preset anyway without the // import. if (m_pControllerManager->importScript(scriptPath, &importedScriptFileName)) { it->name = importedScriptFileName; } } // TODO(rryan): We really should not load the preset here. We should load it // into the preferences GUI and then load it to the actual controller once // the user hits apply. emit(loadPreset(m_pController, pPreset)); slotDirty(); }
void DlgPrefController::addScript() { QString scriptFile = QFileDialog::getOpenFileName( this, tr("Add Script"), QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation), tr("Controller Script Files (*.js)")); if (scriptFile.isNull()) { return; } QString importedScriptFileName; if (!m_pControllerManager->importScript(scriptFile, &importedScriptFileName)) { QMessageBox::warning(this, tr("Add Script"), tr("Could not add script file: '%s'")); return; } // Don't allow duplicate entries in the table. This could happen if the file // is missing (and the user added it to try and fix this) or if the file is // already in the presets directory with an identical checksum. for (int i = 0; i < m_ui.m_pScriptsTableWidget->rowCount(); ++i) { if (m_ui.m_pScriptsTableWidget->item(i, 0)->text() == importedScriptFileName) { return; } } int newRow = m_ui.m_pScriptsTableWidget->rowCount(); m_ui.m_pScriptsTableWidget->setRowCount(newRow + 1); QTableWidgetItem* pScriptName = new QTableWidgetItem(importedScriptFileName); m_ui.m_pScriptsTableWidget->setItem(newRow, 0, pScriptName); pScriptName->setFlags(pScriptName->flags() & ~Qt::ItemIsEditable); QTableWidgetItem* pScriptPrefix = new QTableWidgetItem(""); m_ui.m_pScriptsTableWidget->setItem(newRow, 1, pScriptPrefix); QTableWidgetItem* pScriptBuiltin = new QTableWidgetItem(); pScriptBuiltin->setCheckState(Qt::Unchecked); pScriptBuiltin->setFlags(pScriptBuiltin->flags() & ~(Qt::ItemIsEditable | Qt::ItemIsUserCheckable)); m_ui.m_pScriptsTableWidget->setItem(newRow, 2, pScriptBuiltin); slotDirty(); }
void DlgPrefController::slotEnableDevice(bool enable) { slotDirty(); // Set tree item text to normal/bold. emit(controllerEnabled(this, enable)); }
void DlgPrefController::slotPresetLoaded(ControllerPresetPointer preset) { m_ui.labelLoadedPreset->setText(presetName(preset)); m_ui.labelLoadedPresetDescription->setText(presetDescription(preset)); m_ui.labelLoadedPresetAuthor->setText(presetAuthor(preset)); QStringList supportLinks; QString forumLink = presetForumLink(preset); if (forumLink.length() > 0) { supportLinks << forumLink; } QString wikiLink = presetWikiLink(preset); if (wikiLink.length() > 0) { supportLinks << wikiLink; } // There is always at least one support link. // TODO(rryan): This is a horrible general support link for MIDI! QString troubleShooting = QString( "<a href=\"http://mixxx.org/wiki/doku.php/midi_scripting\">%1</a>") .arg(tr("Troubleshooting")); supportLinks << troubleShooting; QString support = supportLinks.join(" "); m_ui.labelLoadedPresetSupportLinks->setText(support); // We mutate this preset so keep a reference to it while we are using it. // TODO(rryan): Clone it? Technically a waste since nothing else uses this // copy but if someone did they might not expect it to change. m_pPreset = preset; ControllerInputMappingTableModel* pInputModel = new ControllerInputMappingTableModel(this); // If the model reports changes, mark ourselves as dirty. connect(pInputModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(slotDirty())); connect(pInputModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(slotDirty())); connect(pInputModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(slotDirty())); pInputModel->setPreset(preset); QSortFilterProxyModel* pInputProxyModel = new QSortFilterProxyModel(this); pInputProxyModel->setSortRole(Qt::UserRole); pInputProxyModel->setSourceModel(pInputModel); m_ui.m_pInputMappingTableView->setModel(pInputProxyModel); for (int i = 0; i < pInputModel->columnCount(); ++i) { QAbstractItemDelegate* pDelegate = pInputModel->delegateForColumn( i, m_ui.m_pInputMappingTableView); if (pDelegate != NULL) { qDebug() << "Setting input delegate for column" << i << pDelegate; m_ui.m_pInputMappingTableView->setItemDelegateForColumn(i, pDelegate); } } // Now that we have set the new model our old model can be deleted. delete m_pInputProxyModel; m_pInputProxyModel = pInputProxyModel; delete m_pInputTableModel; m_pInputTableModel = pInputModel; ControllerOutputMappingTableModel* pOutputModel = new ControllerOutputMappingTableModel(this); pOutputModel->setPreset(preset); QSortFilterProxyModel* pOutputProxyModel = new QSortFilterProxyModel(this); pOutputProxyModel->setSortRole(Qt::UserRole); pOutputProxyModel->setSourceModel(pOutputModel); m_ui.m_pOutputMappingTableView->setModel(pOutputProxyModel); for (int i = 0; i < pOutputModel->columnCount(); ++i) { QAbstractItemDelegate* pDelegate = pOutputModel->delegateForColumn( i, m_ui.m_pOutputMappingTableView); if (pDelegate != NULL) { qDebug() << "Setting output delegate for column" << i << pDelegate; m_ui.m_pOutputMappingTableView->setItemDelegateForColumn(i, pDelegate); } } // Now that we have set the new model our old model can be deleted. delete m_pOutputProxyModel; m_pOutputProxyModel = pOutputProxyModel; delete m_pOutputTableModel; m_pOutputTableModel = pOutputModel; // Populate the script tab with the scripts this preset uses. m_ui.m_pScriptsTableWidget->setRowCount(preset->scripts.length()); m_ui.m_pScriptsTableWidget->setColumnCount(3); m_ui.m_pScriptsTableWidget->setHorizontalHeaderItem( 0, new QTableWidgetItem(tr("Filename"))); m_ui.m_pScriptsTableWidget->setHorizontalHeaderItem( 1, new QTableWidgetItem(tr("Function Prefix"))); m_ui.m_pScriptsTableWidget->setHorizontalHeaderItem( 2, new QTableWidgetItem(tr("Built-in"))); m_ui.m_pScriptsTableWidget->horizontalHeader() ->setResizeMode(QHeaderView::Stretch); for (int i = 0; i < preset->scripts.length(); ++i) { const ControllerPreset::ScriptFileInfo& script = preset->scripts.at(i); QTableWidgetItem* pScriptName = new QTableWidgetItem(script.name); m_ui.m_pScriptsTableWidget->setItem(i, 0, pScriptName); pScriptName->setFlags(pScriptName->flags() & ~Qt::ItemIsEditable); QTableWidgetItem* pScriptPrefix = new QTableWidgetItem( script.functionPrefix); m_ui.m_pScriptsTableWidget->setItem(i, 1, pScriptPrefix); // If the script is built-in don't allow editing of the prefix. if (script.builtin) { pScriptPrefix->setFlags(pScriptPrefix->flags() & ~Qt::ItemIsEditable); } QTableWidgetItem* pScriptBuiltin = new QTableWidgetItem(); pScriptBuiltin->setCheckState(script.builtin ? Qt::Checked : Qt::Unchecked); pScriptBuiltin->setFlags(pScriptBuiltin->flags() & ~(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsUserCheckable)); m_ui.m_pScriptsTableWidget->setItem(i, 2, pScriptBuiltin); } }