Commit 14adaa3b authored by Boudewijn Rempt's avatar Boudewijn Rempt

Use QFileInfo::completeBaseName instead of baseName

This makes it possible for users to use dots in their filenames.
Not that that is a good idea, everything after the first dot is
technically an extensions, as in bla.tar.gz, but Krita doesn't
handle any file formats where that actually happens, so we can
be a bit less technically correct when handling filenames and
only check the extension after the last dot.

BUG:409765
parent f440685c
......@@ -93,7 +93,7 @@ bool KisPngBrush::loadFromDevice(QIODevice *dev)
}
else {
QFileInfo info(filename());
setName(info.baseName());
setName(info.completeBaseName());
}
QImage image = reader.read();
......
......@@ -97,7 +97,7 @@ bool KisSvgBrush::loadFromDevice(QIODevice *dev)
setHeight(brushTipImage().height());
QFileInfo fi(filename());
setName(fi.baseName());
setName(fi.completeBaseName());
return !brushTipImage().isNull() && valid();
}
......
......@@ -172,7 +172,7 @@ QString SvgSavingContext::createFileName(const QString &extension)
QFileInfo fi(file->fileName());
QString path = fi.absolutePath();
QString dstBaseFilename = fi.baseName();
QString dstBaseFilename = fi.completeBaseName();
// create a filename for the image file at the destination directory
QString fname = dstBaseFilename + '_' + createUID("file");
......
......@@ -853,7 +853,7 @@ bool KoColorSet::Private::loadGpl()
bool KoColorSet::Private::loadAct()
{
QFileInfo info(colorSet->filename());
colorSet->setName(info.baseName());
colorSet->setName(info.completeBaseName());
KisSwatch e;
for (int i = 0; i < data.size(); i += 3) {
quint8 r = data[i];
......@@ -869,7 +869,7 @@ bool KoColorSet::Private::loadRiff()
{
// http://worms2d.info/Palette_file
QFileInfo info(colorSet->filename());
colorSet->setName(info.baseName());
colorSet->setName(info.completeBaseName());
KisSwatch e;
RiffHeader header;
......@@ -892,7 +892,7 @@ bool KoColorSet::Private::loadRiff()
bool KoColorSet::Private::loadPsp()
{
QFileInfo info(colorSet->filename());
colorSet->setName(info.baseName());
colorSet->setName(info.completeBaseName());
KisSwatch e;
qint32 r, g, b;
......@@ -1010,7 +1010,7 @@ bool KoColorSet::Private::loadKpl()
bool KoColorSet::Private::loadAco()
{
QFileInfo info(colorSet->filename());
colorSet->setName(info.baseName());
colorSet->setName(info.completeBaseName());
QBuffer buf(&data);
buf.open(QBuffer::ReadOnly);
......
......@@ -1097,7 +1097,7 @@ bool KisMainWindow::saveDocument(KisDocument *document, bool saveas, bool isExpo
// dialog and then tries to just plain Save ---
// suggest a different filename extension (yes, we fortunately don't all live in a world of magic :))
QString suggestedFilename = QFileInfo(suggestedURL.toLocalFile()).baseName();
QString suggestedFilename = QFileInfo(suggestedURL.toLocalFile()).completeBaseName();
if (!suggestedFilename.isEmpty()) { // ".kra" looks strange for a name
suggestedFilename = suggestedFilename + "." + KisMimeDatabase::suffixesForMimeType(KIS_MIME_TYPE).first();
......@@ -1126,7 +1126,7 @@ bool KisMainWindow::saveDocument(KisDocument *document, bool saveas, bool isExpo
// Use the location where we last exported to, if it's set, as the opening location for the file dialog
QString proposedPath = QFileInfo(d->lastExportLocation).absolutePath();
// If the document doesn't have a filename yet, use the title
QString proposedFileName = suggestedURL.isEmpty() ? document->documentInfo()->aboutInfo("title") : QFileInfo(suggestedURL.toLocalFile()).baseName();
QString proposedFileName = suggestedURL.isEmpty() ? document->documentInfo()->aboutInfo("title") : QFileInfo(suggestedURL.toLocalFile()).completeBaseName();
// Use the last mimetype we exported to by default
QString proposedMimeType = d->lastExportedFormat.isEmpty() ? "" : d->lastExportedFormat;
QString proposedExtension = KisMimeDatabase::suffixesForMimeType(proposedMimeType).first().remove("*,");
......@@ -1173,7 +1173,7 @@ bool KisMainWindow::saveDocument(KisDocument *document, bool saveas, bool isExpo
if (document->documentInfo()->aboutInfo("title") == i18n("Unnamed")) {
QString fn = newURL.toLocalFile();
QFileInfo info(fn);
document->documentInfo()->setAboutInfo("title", info.baseName());
document->documentInfo()->setAboutInfo("title", info.completeBaseName());
}
QByteArray outputFormat = nativeFormat;
......@@ -1187,9 +1187,9 @@ bool KisMainWindow::saveDocument(KisDocument *document, bool saveas, bool isExpo
}
else {
QString path = QFileInfo(d->lastExportLocation).absolutePath();
QString filename = QFileInfo(document->url().toLocalFile()).baseName();
QString filename = QFileInfo(document->url().toLocalFile()).completeBaseName();
justChangingFilterOptions = (QFileInfo(newURL.toLocalFile()).absolutePath() == path)
&& (QFileInfo(newURL.toLocalFile()).baseName() == filename)
&& (QFileInfo(newURL.toLocalFile()).completeBaseName() == filename)
&& (outputFormat == d->lastExportedFormat);
}
......@@ -2462,7 +2462,7 @@ void KisMainWindow::applyDefaultSettings(QPrinter &printer) {
QString title = d->activeView->document()->documentInfo()->aboutInfo("title");
if (title.isEmpty()) {
QFileInfo info(d->activeView->document()->url().fileName());
title = info.baseName();
title = info.completeBaseName();
}
if (title.isEmpty()) {
......
......@@ -51,7 +51,7 @@ KisResourceBundle::KisResourceBundle(QString const& fileName)
: KoResource(fileName),
m_bundleVersion("1")
{
setName(QFileInfo(fileName).baseName());
setName(QFileInfo(fileName).completeBaseName());
m_metadata["generator"] = "Krita (" + KritaVersionWrapper::versionString(true) + ")";
}
......
......@@ -238,7 +238,7 @@ void KisTemplateTree::readTemplates()
// Found a PNG file - the template must be here in the same dir.
icon = filePath;
QFileInfo fi(filePath);
text = fi.baseName();
text = fi.completeBaseName();
templatePath = filePath; // Note that we store the .png file as the template !
// That's the way it's always been done. Then the app replaces the extension...
}
......
......@@ -319,7 +319,7 @@ void KisDlgLayerStyle::slotSaveStyle()
new KisPSDLayerStyleCollectionResource(filename));
KisPSDLayerStyleSP newStyle = style()->clone();
newStyle->setName(QFileInfo(filename).baseName());
newStyle->setName(QFileInfo(filename).completeBaseName());
KisPSDLayerStyleCollectionResource::StylesVector vector = collection->layerStyles();
vector << newStyle;
......
......@@ -496,8 +496,8 @@ void KisLayerManager::convertLayerToFileLayer(KisNodeSP source)
urlRequester->setMimeTypeFilters(listMimeFilter);
urlRequester->setFileName(m_view->document()->url().toLocalFile());
if (m_view->document()->url().isLocalFile()) {
QFileInfo location = QFileInfo(m_view->document()->url().toLocalFile()).baseName();
location.setFile(location.dir(), location.baseName() + "_" + source->name() + ".png");
QFileInfo location = QFileInfo(m_view->document()->url().toLocalFile()).completeBaseName();
location.setFile(location.dir(), location.completeBaseName() + "_" + source->name() + ".png");
urlRequester->setFileName(location.absoluteFilePath());
}
else {
......@@ -914,7 +914,7 @@ void KisLayerManager::saveGroupLayers()
mimeType = "image/png";
}
QString extension = KisMimeDatabase::suffixesForMimeType(mimeType).first();
QString basename = f.baseName();
QString basename = f.completeBaseName();
KisImageSP image = m_view->image();
if (!image) return;
......
......@@ -235,7 +235,7 @@ void ThemeManager::populateThemeMenu()
KSharedConfigPtr config = KSharedConfig::openConfig(filename);
QIcon icon = createSchemePreviewIcon(config);
KConfigGroup group(config, "General");
const QString name = group.readEntry("Name", info.baseName());
const QString name = group.readEntry("Name", info.completeBaseName());
action = new QAction(name, d->themeMenuActionGroup);
action->setIcon(icon);
action->setCheckable(true);
......@@ -302,7 +302,7 @@ void ThemeManager::populateThemeMap()
const QFileInfo info(filename);
KSharedConfigPtr config = KSharedConfig::openConfig(filename);
KConfigGroup group(config, "General");
const QString name = group.readEntry("Name", info.baseName());
const QString name = group.readEntry("Name", info.completeBaseName());
d->themeMap.insert(name, filename);
}
......
......@@ -255,7 +255,7 @@ public:
}
if (fileInfo.exists()) {
QString filename = fileInfo.path() + "/" + fileInfo.baseName() + "XXXXXX" + "." + fileInfo.suffix();
QString filename = fileInfo.path() + "/" + fileInfo.completeBaseName() + "XXXXXX" + "." + fileInfo.suffix();
debugWidgets << "fileName is " << filename;
QTemporaryFile file(filename);
if (file.open()) {
......@@ -384,12 +384,12 @@ public:
Q_ASSERT(!resource->defaultFileExtension().isEmpty());
Q_ASSERT(!saveLocation().isEmpty());
QString newFilename = saveLocation() + fi.baseName() + resource->defaultFileExtension();
QString newFilename = saveLocation() + fi.completeBaseName() + resource->defaultFileExtension();
QFileInfo fileInfo(newFilename);
int i = 1;
while (fileInfo.exists()) {
fileInfo.setFile(saveLocation() + fi.baseName() + QString("%1").arg(i) + resource->defaultFileExtension());
fileInfo.setFile(saveLocation() + fi.completeBaseName() + QString("%1").arg(i) + resource->defaultFileExtension());
i++;
}
resource->setFilename(fileInfo.filePath());
......
......@@ -122,7 +122,7 @@ void KoFileDialog::setMimeTypeFilters(const QStringList &mimeTypeList, QString d
QString suffix = KisMimeDatabase::suffixesForMimeType(defaultMimeType).first();
if (!d->proposedFileName.isEmpty()) {
d->proposedFileName = QFileInfo(d->proposedFileName).baseName() + "." + suffix;
d->proposedFileName = QFileInfo(d->proposedFileName).completeBaseName() + "." + suffix;
}
QStringList defaultFilters = getFilterStringListFromMime(QStringList() << defaultMimeType, false);
......
......@@ -89,7 +89,7 @@ void KColorSchemeModel::init()
Q_FOREACH (const QString &schemeFile, schemeFiles) {
KSharedConfigPtr config = KSharedConfig::openConfig(schemeFile);
KConfigGroup group(config, QStringLiteral("General"));
const QString name = group.readEntry("Name", QFileInfo(schemeFile).baseName());
const QString name = group.readEntry("Name", QFileInfo(schemeFile).completeBaseName());
const KColorSchemeModelData data = {name, schemeFile, createPreview(schemeFile)};
m_data.append(data);
}
......
......@@ -205,7 +205,7 @@ void CompositionDockerDock::exportClicked()
QString filename = m_canvas->viewManager()->document()->localFilePath();
if (!filename.isEmpty()) {
QFileInfo info(filename);
path += info.baseName() + '_';
path += info.completeBaseName() + '_';
}
Q_FOREACH (KisLayerCompositionSP composition, m_canvas->viewManager()->image()->compositions()) {
......
......@@ -287,12 +287,12 @@ void ResourceManager::slotImportBundles()
}
QFileInfo fi(res);
QString newFilename = KisResourceBundleServerProvider::instance()->resourceBundleServer()->saveLocation() + fi.baseName() + bundle->defaultFileExtension();
QString newFilename = KisResourceBundleServerProvider::instance()->resourceBundleServer()->saveLocation() + fi.completeBaseName() + bundle->defaultFileExtension();
QFileInfo fileInfo(newFilename);
int i = 1;
while (fileInfo.exists()) {
fileInfo.setFile(KisResourceBundleServerProvider::instance()->resourceBundleServer()->saveLocation() + fi.baseName() + QString("%1").arg(i) + bundle->defaultFileExtension());
fileInfo.setFile(KisResourceBundleServerProvider::instance()->resourceBundleServer()->saveLocation() + fi.completeBaseName() + QString("%1").arg(i) + bundle->defaultFileExtension());
i++;
}
bundle->setFilename(fileInfo.filePath());
......
......@@ -231,7 +231,7 @@ KisConfigWidget *KisBrushExport::createConfigurationWidget(QWidget *parent, cons
// preload gih name with chosen filename
QFileInfo fileLocation(filename());
wdg->nameLineEdit->setText(fileLocation.baseName());
wdg->nameLineEdit->setText(fileLocation.completeBaseName());
return wdg;
}
......
......@@ -47,7 +47,7 @@ KisImportExportErrorCode QMLConverter::buildFile(const QString &filename, const
QFileInfo info(filename);
QFileInfo infoRealFile(realFilename);
KisNodeSP node = image->rootLayer()->firstChild();
QString imageDir = infoRealFile.baseName() + "_images";
QString imageDir = infoRealFile.completeBaseName() + "_images";
QString imagePath = infoRealFile.absolutePath() + '/' + imageDir;
if (node) {
QDir dir;
......
......@@ -607,7 +607,7 @@ KisImportExportErrorCode KisSpriterExport::convert(KisDocument *document, QIODev
// Generate scml
QDomDocument scml;
fillScml(scml, fi.baseName());
fillScml(scml, fi.completeBaseName());
bool openedHere = false;
if (!io->isOpen()) {
......
......@@ -40,7 +40,7 @@ struct KisEmbeddedPatternManager::Private {
if (name.isEmpty() || name != QFileInfo(name).fileName()) {
QFileInfo info(filename);
name = info.baseName();
name = info.completeBaseName();
}
if (!img.isNull()) {
......
......@@ -147,7 +147,7 @@ void KisEmbeddedPatternManagerTest::checkOneConfig(NameStatus nameStatus, bool h
QVERIFY(pattern->name().startsWith(expectedName));
QFileInfo info(pattern->filename());
QVERIFY(info.baseName().startsWith(expectedName));
QVERIFY(info.completeBaseName().startsWith(expectedName));
QCOMPARE(info.dir().path(), QDir(KoResourceServerProvider::instance()->patternServer()->saveLocation()).path());
// We can only find things on the server by name or by md5; the file path as an identifier does not work.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment