bool Editor::saveFile(const QUrl &targetUrl) { QUrl url(targetUrl); bool result = false; if (url.isEmpty() && currentUrl().isEmpty()) { result = saveFileAs(); } else { if (url.isEmpty()) url = currentUrl(); QTemporaryFile tmp; // only used for network export tmp.setAutoRemove(false); tmp.open(); QString filename = url.isLocalFile() ? url.toLocalFile() : tmp.fileName(); QSaveFile *savefile = new QSaveFile(filename); if (savefile->open(QIODevice::WriteOnly)) { QTextStream outputStream(savefile); // store commands in their generic @(...) notation format, to be translatable when reopened // this allows sharing of scripts written in different languages Tokenizer tokenizer; tokenizer.initialize(editor->document()->toPlainText()); const QStringList localizedLooks(Translator::instance()->allLocalizedLooks()); QString unstranslated; Token* t; bool pendingEOL = false; // to avoid writing a final EOL token while ((t = tokenizer.getToken())->type() != Token::EndOfInput) { if (pendingEOL) { unstranslated.append('\n'); pendingEOL = false; } if (localizedLooks.contains(t->look())) { QString defaultLook(Translator::instance()->defaultLook(t->look())); unstranslated.append(QString("@(%1)").arg(defaultLook)); } else { if (t->type() == Token::EndOfLine) pendingEOL = true; else unstranslated.append(t->look()); } } outputStream << KTURTLE_MAGIC_1_0 << '\n'; outputStream << unstranslated; outputStream.flush(); savefile->commit(); // check for error here? } delete savefile; if (!url.isLocalFile()) { KIO::StoredTransferJob *job = KIO::storedPut(savefile, url, -1, 0); if(job->exec()){ setCurrentUrl(url); editor->document()->setModified(false); // MainWindow will add us to the recent file list emit fileSaved(url); result = true; // fix GUI for saveAs and saveExamples. TODO: check 5 lines above } } } return result; }
bool OwncloudSetupPage::urlHasChanged() { bool change = false; const QChar slash('/'); QUrl currentUrl( url() ); QUrl initialUrl( _oCUrl ); QString currentPath = currentUrl.path(); QString initialPath = initialUrl.path(); // add a trailing slash. if( ! currentPath.endsWith( slash )) currentPath += slash; if( ! initialPath.endsWith( slash )) initialPath += slash; if( currentUrl.host() != initialUrl.host() || currentPath != initialPath ) { change = true; } if( !change) { // no change yet, check the user. QString user = _ui.leUsername->text().simplified(); if( user != _ocUser ) change = true; } return change; }
void ChatTextEdit::mouseMoveEvent(QMouseEvent *e) { QPlainTextEdit::mouseMoveEvent(e); if(currentUrl(e).size()) viewport()->setCursor(QCursor(Qt::PointingHandCursor)); else viewport()->setCursor(QCursor(Qt::IBeamCursor)); }
QString GPSBookmarkOwner::currentTitle() const { if (d->lastTitle.isEmpty()) { return currentUrl().toString(); } return d->lastTitle; }
void KWQTableView::doVocabSound() { QUrl currentUrl(model()->data(currentIndex(), KWQTableModel::SoundRole).toString()); QUrl soundUrl = QFileDialog::getOpenFileUrl(this, i18n("Select Sound"), currentUrl, i18n("*|All Files")); if (!soundUrl.isEmpty()) { KWQCommandSound *kwqc = new KWQCommandSound(this, soundUrl); m_undoStack->push(kwqc); } }
void KWQTableView::doVocabImage() { QUrl currentUrl(model()->data(currentIndex(), KWQTableModel::ImageRole).toString()); QUrl imageUrl = KFileDialog::getImageOpenUrl(currentUrl, this, i18n("Select Image")); if (!imageUrl.isEmpty()) { KWQCommandImage *kwqc = new KWQCommandImage(this, imageUrl); m_undoStack->push(kwqc); } }
void ChatTextEdit::mouseReleaseEvent(QMouseEvent *e) { QPlainTextEdit::mouseReleaseEvent(e); if(e->button() == Qt::RightButton) return; QString url = currentUrl(e); if(url.size()) QDesktopServices::openUrl(QUrl(url)); }
bool OwncloudSetupPage::urlHasChanged() { bool change = false; const QChar slash('/'); QUrl currentUrl( url() ); QUrl initialUrl( _oCUrl ); QString currentPath = currentUrl.path(); QString initialPath = initialUrl.path(); // add a trailing slash. if( ! currentPath.endsWith( slash )) currentPath += slash; if( ! initialPath.endsWith( slash )) initialPath += slash; if( currentUrl.host() != initialUrl.host() || currentUrl.port() != initialUrl.port() || currentPath != initialPath ) { change = true; } return change; }
QString KateBookmarkHandler::currentTitle() const { return currentUrl(); }
void DirSelectWidget::slotFolderSelected(Q3ListViewItem*) { emit folderItemSelected(currentUrl()); }