void KOTodoPriorityDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const { KComboBox *combo = static_cast<KComboBox *>( editor ); model->setData( index, combo->currentIndex() ); }
void RuleDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { KLineEdit *ruleLineEdit = static_cast<KLineEdit*>(editor->layout()->itemAt(0)->widget()); KComboBox *matchComboBox = static_cast<KComboBox*>(editor->layout()->itemAt(1)->widget()); QCheckBox *requiredCheckBox = static_cast<QCheckBox*>(editor->layout()->itemAt(2)->widget()); model->setData(index, ((matchComboBox->currentIndex() > 0)?(QString("%1+%2+%3").arg(requiredCheckBox->isChecked()?'1':'0').arg(matchComboBox->currentIndex()).arg(ruleLineEdit->text())):QString()), Qt::EditRole); }
void CharactersViewDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { switch (index.column()) { case 0: case 1: { KLineEdit* lineEdit = static_cast<KLineEdit*>(editor); model->setData(index, lineEdit->text()); break; } case 2: { KComboBox* comboBox = static_cast<KComboBox*>(editor); model->setData(index, comboBox->currentIndex()); break; } default: QStyledItemDelegate::setModelData(editor, model, index); } }
CreateChecksumDlg::CreateChecksumDlg(const QStringList& files, bool containFolders, const QString& path) : QDialog(krApp) { setWindowModality(Qt::WindowModal); setWindowTitle(i18n("Create Checksum")); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); QList<CS_Tool *> tools = getTools(containFolders); if (tools.count() == 0) { // nothing was suggested?! QString error = i18n("<qt>Cannot calculate checksum since no supported tool was found. " "Please check the <b>Dependencies</b> page in Krusader's settings.</qt>"); if (containFolders) error += i18n("<qt><b>Note</b>: you have selected folders, and probably have no recursive checksum tool installed." " Krusader currently supports <i>md5deep, sha1deep, sha256deep, tigerdeep and cfv</i></qt>"); KMessageBox::error(0, error); return; } QWidget * widget = new QWidget(this); QGridLayout *layout = new QGridLayout(widget); int row = 0; // title (icon+text) QHBoxLayout *hlayout = new QHBoxLayout; QLabel *p = new QLabel(widget); p->setPixmap(krLoader->loadIcon("document-edit-sign", KIconLoader::Desktop, 32)); hlayout->addWidget(p); QLabel *l1 = new QLabel(widget); if (containFolders) l1->setText(i18n("About to calculate checksum for the following files and folders:")); else l1->setText(i18n("About to calculate checksum for the following files:")); hlayout->addWidget(l1); layout->addLayout(hlayout, row, 0, 1, 2, Qt::AlignLeft); ++row; // file list KrListWidget *lb = new KrListWidget(widget); lb->addItems(files); layout->addWidget(lb, row, 0, 1, 2); ++row; // checksum method QHBoxLayout *hlayout2 = new QHBoxLayout; QLabel *l2 = new QLabel(i18n("Select the checksum method:"), widget); hlayout2->addWidget(l2); KComboBox *method = new KComboBox(widget); // -- fill the combo with available methods int i; for (i = 0; i < tools.count(); ++i) method->addItem(cs_typeToText[tools.at(i)->type], i); method->setFocus(); hlayout2->addWidget(method); layout->addLayout(hlayout2, row, 0, 1, 2, Qt::AlignLeft); ++row; mainLayout->addWidget(widget); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); mainLayout->addWidget(buttonBox); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); if (exec() != Accepted) return; // else implied: run the process QTemporaryFile tmpOut(QDir::tempPath() + QLatin1String("/krusader_XXXXXX.stdout")); tmpOut.open(); // necessary to create the filename QTemporaryFile tmpErr(QDir::tempPath() + QLatin1String("/krusader_XXXXXX.stderr")); tmpErr.open(); // necessary to create the filename KProcess proc; CS_Tool *mytool = tools.at(method->currentIndex()); mytool->create(proc, mytool, files, QString(), containFolders, method->currentText()); proc.setOutputChannelMode(KProcess::SeparateChannels); // without this the next 2 lines have no effect! proc.setStandardOutputFile(tmpOut.fileName()); proc.setStandardErrorFile(tmpErr.fileName()); proc.setWorkingDirectory(path); krApp->startWaiting(i18n("Calculating checksums..."), 0, true); QApplication::setOverrideCursor(Qt::WaitCursor); proc.start(); // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking // it would be better to connect to started(), error() and finished() if (proc.waitForStarted()) while (proc.state() == QProcess::Running) { usleep(500); qApp->processEvents(); if (krApp->wasWaitingCancelled()) { // user cancelled proc.kill(); QApplication::restoreOverrideCursor(); return; } }; krApp->stopWait(); QApplication::restoreOverrideCursor(); if (proc.exitStatus() != QProcess::NormalExit) { KMessageBox::error(0, i18n("<qt>There was an error while running <b>%1</b>.</qt>", mytool->binary)); return; } // suggest a filename QString suggestedFilename = path + '/'; if (files.count() > 1) suggestedFilename += ("checksum." + cs_typeToText[mytool->type]); else suggestedFilename += (files[0] + '.' + cs_typeToText[mytool->type]); // send both stdout and stderr QStringList stdOut, stdErr; if (!KrServices::fileToStringList(&tmpOut, stdOut) || !KrServices::fileToStringList(&tmpErr, stdErr)) { KMessageBox::error(krApp, i18n("Error reading stdout or stderr")); return; } ChecksumResultsDlg dlg(stdOut, stdErr, suggestedFilename, mytool->standardFormat); }