static KURL getNewFileName(const KURL &u, const QString &text) { bool ok; QString dialogText(text); if(dialogText.isEmpty()) dialogText = i18n("Filename for clipboard content:"); QString file = KInputDialog::getText(QString::null, dialogText, QString::null, &ok); if(!ok) return KURL(); KURL myurl(u); myurl.addPath(file); if(KIO::NetAccess::exists(myurl, false, 0)) { kdDebug(7007) << "Paste will overwrite file. Prompting..." << endl; KIO::RenameDlg_Result res = KIO::R_OVERWRITE; QString newPath; // Ask confirmation about resuming previous transfer res = Observer::self()->open_RenameDlg(0L, i18n("File Already Exists"), u.pathOrURL(), myurl.pathOrURL(), (KIO::RenameDlg_Mode)(KIO::M_OVERWRITE | KIO::M_SINGLE), newPath); if(res == KIO::R_RENAME) { myurl = newPath; } else if(res == KIO::R_CANCEL) { return KURL(); } } return myurl; }
static QByteArray chooseFormatAndUrl(const QUrl &u, const QMimeData *mimeData, const QStringList &formats, const QString &text, const QString &suggestedFileName, QWidget *widget, bool clipboard, QUrl *newUrl) { QMimeDatabase db; QStringList formatLabels; for (int i = 0; i < formats.size(); ++i) { const QString &fmt = formats[i]; QMimeType mime = db.mimeTypeForName(fmt); if (mime.isValid()) { formatLabels.append(i18n("%1 (%2)", mime.comment(), fmt)); } else { formatLabels.append(fmt); } } QString dialogText(text); if (dialogText.isEmpty()) { dialogText = i18n("Filename for clipboard content:"); } //using QString() instead of QString::null didn't compile (with gcc 3.2.3), because the ctor was mistaken as a function declaration, Alex //krazy:exclude=nullstrassign KIO::PasteDialog dlg(QString::null, dialogText, suggestedFileName, formatLabels, widget, clipboard); //krazy:exclude=nullstrassign if (dlg.exec() != QDialog::Accepted) { return QByteArray(); } if (clipboard && dlg.clipboardChanged()) { KMessageBox::sorry(widget, i18n("The clipboard has changed since you used 'paste': " "the chosen data format is no longer applicable. " "Please copy again what you wanted to paste.")); return QByteArray(); } const QString result = dlg.lineEditText(); const QString chosenFormat = formats[ dlg.comboItem() ]; //qDebug() << " result=" << result << " chosenFormat=" << chosenFormat; *newUrl = u; newUrl->setPath(newUrl->path() + '/' + result); // In Qt3, the result of clipboard()->mimeData() only existed until the next // event loop run (see dlg.exec() above), so we re-fetched it. // TODO: This should not be necessary with Qt5; remove this conditional // and test that it still works. if (clipboard) { mimeData = QApplication::clipboard()->mimeData(); } const QByteArray ba = mimeData->data(chosenFormat); return ba; }
static KIO::CopyJob *chooseAndPaste(const KURL &u, QMimeSource *data, const QValueVector< QCString > &formats, const QString &text, QWidget *widget, bool clipboard) { QStringList formatLabels; for(uint i = 0; i < formats.size(); ++i) { const QCString &fmt = formats[i]; KMimeType::Ptr mime = KMimeType::mimeType(fmt); if(mime != KMimeType::defaultMimeTypePtr()) formatLabels.append(i18n("%1 (%2)").arg(mime->comment()).arg(fmt)); else formatLabels.append(fmt); } QString dialogText(text); if(dialogText.isEmpty()) dialogText = i18n("Filename for clipboard content:"); KIO::PasteDialog dlg(QString::null, dialogText, QString::null, formatLabels, widget, clipboard); if(dlg.exec() != KDialogBase::Accepted) return 0; if(clipboard && dlg.clipboardChanged()) { KMessageBox::sorry(widget, i18n("The clipboard has changed since you used 'paste': " "the chosen data format is no longer applicable. " "Please copy again what you wanted to paste.")); return 0; } const QString result = dlg.lineEditText(); const QCString chosenFormat = formats[dlg.comboItem()]; kdDebug() << " result=" << result << " chosenFormat=" << chosenFormat << endl; KURL new_url(u); new_url.addPath(result); // if "data" came from QClipboard, then it was deleted already - by a nice 0-seconds timer // In that case, get it again. Let's hope the user didn't copy something else meanwhile :/ if(clipboard) { data = QApplication::clipboard()->data(); } const QByteArray ba = data->encodedData(chosenFormat); return pasteDataAsyncTo(new_url, ba); }
static QUrl getNewFileName(const QUrl &u, const QString &text, const QString &suggestedFileName, QWidget *widget) { bool ok; QString dialogText(text); if (dialogText.isEmpty()) { dialogText = i18n("Filename for clipboard content:"); } QString file = QInputDialog::getText(widget, QString(), dialogText, QLineEdit::Normal, suggestedFileName, &ok); if (!ok) { return QUrl(); } QUrl myurl(u); myurl.setPath(myurl.path() + '/' + file); KIO::StatJob *job = KIO::stat(myurl, myurl.isLocalFile() ? KIO::HideProgressInfo : KIO::DefaultFlags); job->setDetails(0); job->setSide(KIO::StatJob::DestinationSide); KJobWidgets::setWindow(job, widget); // Check for existing destination file. // When we were using CopyJob, we couldn't let it do that (would expose // an ugly tempfile name as the source URL) // And now we're using a put job anyway, no destination checking included. if (job->exec()) { //qDebug() << "Paste will overwrite file. Prompting..."; KIO::RenameDialog dlg(widget, i18n("File Already Exists"), u, myurl, KIO::RenameDialog_Overwrite); KIO::RenameDialog_Result res = static_cast<KIO::RenameDialog_Result>(dlg.exec()); if (res == KIO::Result_Rename) { myurl = dlg.newDestUrl(); } else if (res == KIO::Result_Cancel) { return QUrl(); } else if (res == KIO::Result_Overwrite) { // OK, proceed } } return myurl; }