Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • util
fileformat.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17
18#include "fileformat.h"
19#include <QDir>
20#include <QFileInfo>
21#include <QMap>
22
23bool removePFFTmpDirectory(const QString& dirName)
24{
25 if (dirName.isEmpty())
26 {
27 return false;
28 }
29
30 QDir dir(dirName);
31
32 if (!dir.exists())
33 {
34 Q_ASSERT(false);
35 return false;
36 }
37
38 bool result = dir.removeRecursively();
39 return result;
40}
41
42QString retrieveProjectNameFromTempPath(const QString& path)
43{
44 QFileInfo info(path);
45 QString fileName = info.completeBaseName();
46
47 QStringList tokens = fileName.split("_");
48 //qDebug() << tokens;
49 return tokens[0];
50}
51
52QString detectFormatByFileNameExtension(const QString& fileName)
53{
54 QMap<QString, QString> extensionMapping
55 {
56 { "png", "PNG" },
57 { "jpg" , "JPG" },
58 { "jpeg", "JPG" },
59 { "tif", "TIF" },
60 { "tiff", "TIF" },
61 { "bmp", "BMP" },
62 { "webp", "WEBP" },
63 { "mp4", "MP4" },
64 { "avi", "AVI" },
65 { "gif", "GIF" },
66 { "webm", "WEBM" },
67 { "apng", "APNG" },
68 };
69
70 QString extension = fileName.mid(fileName.lastIndexOf(".") + 1).toLower();
71 if (!fileName.contains(".") || !extensionMapping.contains(extension))
72 {
73 return QString();
74 }
75 return extensionMapping[extension];
76}
77
78bool isMovieFormat(const QString& format)
79{
80 QMap<QString, bool> formatMapping
81 {
82 { "PNG", false },
83 { "JPG", false },
84 { "TIF", false },
85 { "BMP", false },
86 { "MP4", true },
87 { "AVI", true },
88 { "GIF", true },
89 { "WEBM", true },
90 { "APNG", true },
91 };
92
93 Q_ASSERT(formatMapping.contains(format));
94 return formatMapping[format];
95}
QDir
QFileInfo
QMap
QString::split
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString::isEmpty
bool isEmpty() const const
QString::lastIndexOf
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
QString::mid
QString mid(int position, int n) const const
QString::toLower
QString toLower() const const
QStringList
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39