void KUrlRequesterDialogPrivate::initDialog(const QString &text, const QUrl &urlName) { QVBoxLayout *topLayout = new QVBoxLayout; q->setLayout(topLayout); QLabel *label = new QLabel(text, q); topLayout->addWidget(label); urlRequester = new KUrlRequester(urlName, q); urlRequester->setMinimumWidth(urlRequester->sizeHint().width() * 3); topLayout->addWidget(urlRequester); urlRequester->setFocus(); QObject::connect(urlRequester->lineEdit(), SIGNAL(textChanged(QString)), q, SLOT(_k_slotTextChanged(QString))); /* KFile::Mode mode = static_cast<KFile::Mode>( KFile::File | KFile::ExistingOnly ); urlRequester_->setMode( mode ); */ buttonBox = new QDialogButtonBox(q); buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(accept())); QObject::connect(buttonBox, SIGNAL(rejected()), q, SLOT(reject())); topLayout->addWidget(buttonBox); _k_slotTextChanged(urlName.toString()); }
int main( int argc, char **argv ) { KCmdLineArgs::init(argc, argv, "kurlrequestertest", 0, ki18n("kurlrequestertest"), "0", ki18n("test app")); KApplication app; app.setQuitOnLastWindowClosed(false); KUrl url = KUrlRequesterDialog::getUrl( "ftp://ftp.kde.org" ); qDebug( "Selected url: %s", url.url().toLatin1().constData()); KUrlRequester *req = new KUrlRequester(); #ifndef KDE_NO_DEPRECATED KEditListBox *el = new KEditListBox( QLatin1String("Test"), req->customEditor() ); #else KEditListWidget *el = new KEditListWidget( req->customEditor() ); el->setWindowTitle( QLatin1String("Test") ); #endif el->show(); KUrlRequester *req1 = new KUrlRequester(); req1->fileDialog(); req1->setWindowTitle("AAAAAAAAAAAA"); req1->show(); return app.exec(); }
RhythmboxConfigWidget::RhythmboxConfigWidget( const QVariantMap &config, QWidget *parent, Qt::WindowFlags f ) : SimpleImporterConfigWidget( "Rhythmbox", config, parent, f ) { const QString defaultPath = QDir::toNativeSeparators( QDir::homePath() + "/.local/share/rhythmbox/rhythmdb.xml" ); KUrlRequester *dbField = new KUrlRequester( defaultPath ); dbField->setFilter( "rhythmdb.xml" ); addField( "dbPath", i18n( "Database location" ), dbField, "text" ); }
MatchChecksumDlg::MatchChecksumDlg(const QStringList& files, bool containFolders, const QString& path, const QString& checksumFile) : QDialog(krApp) { setWindowTitle(i18n("Verify Checksum")); setWindowModality(Qt::WindowModal); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); QList<CS_Tool *> tools = getTools(containFolders); if (tools.count() == 0) { // nothing was suggested?! QString error = i18n("<qt>Cannot verify 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-decrypt-verify", KIconLoader::Desktop, 32)); hlayout->addWidget(p); QLabel *l1 = new QLabel(widget); if (containFolders) l1->setText(i18n("About to verify checksum for the following files and folders:")); else l1->setText(i18n("About to verify 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 file QHBoxLayout *hlayout2 = new QHBoxLayout; QLabel *l2 = new QLabel(i18n("Checksum file:"), widget); hlayout2->addWidget(l2); KUrlRequester *checksumFileReq = new KUrlRequester(widget); checksumFileReq->setUrl(QUrl::fromLocalFile(path)); if (!checksumFile.isEmpty()) checksumFileReq->setUrl(QUrl::fromLocalFile(checksumFile)); checksumFileReq->setFocus(); hlayout2->addWidget(checksumFileReq); layout->addLayout(hlayout2, row, 0, 1, 2, Qt::AlignLeft); 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; QString file = checksumFileReq->url().toDisplayString(QUrl::PreferLocalFile); QString extension; if (!verifyChecksumFile(file, extension)) { KMessageBox::error(0, i18n("<qt>Error reading checksum file <i>%1</i>.<br />Please specify a valid checksum file.</qt>", file)); return; } // do we have a tool for that extension? int i; CS_Tool *mytool = 0; for (i = 0; i < tools.count(); ++i) if (cs_typeToText[tools.at(i)->type] == extension.toLower()) { mytool = tools.at(i); break; } if (!mytool) { KMessageBox::error(0, i18n("<qt>Krusader cannot find a checksum tool that handles %1 on your system. Please check the <b>Dependencies</b> page in Krusader's settings.</qt>", extension)); 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; mytool->verify(proc, mytool, files, file, containFolders, extension); 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("Verifying 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; } }; if (proc.exitStatus() != QProcess::NormalExit) { KMessageBox::error(0, i18n("<qt>There was an error while running <b>%1</b>.</qt>", mytool->binary)); return; } QApplication::restoreOverrideCursor(); krApp->stopWait(); // 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; } VerifyResultDlg dlg(mytool->failed(stdOut, stdErr)); }
void KUrlRequesterTest::testGetSet() { KUrlRequester req; req.setUrl(QUrl(QStringLiteral("file:///etc"))); QCOMPARE(req.url().toString(), QString("file:///etc")); }