All Classes Namespaces Functions Variables Enumerations Properties Pages
fileformat.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #include "fileformat.h"
19 #include <QDir>
20 #include <QFileInfo>
21 #include <QMap>
22 
23 bool 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 
42 QString 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 
52 QString 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  { "mp4", "MP4" },
63  { "avi", "AVI" },
64  { "gif", "GIF" },
65  { "webm", "WEBM" },
66  { "apng", "APNG" },
67  };
68 
69  QString extension = fileName.mid(fileName.lastIndexOf(".") + 1).toLower();
70  if (!fileName.contains(".") || !extensionMapping.contains(extension))
71  {
72  return QString();
73  }
74  return extensionMapping[extension];
75 }
76 
77 bool isMovieFormat(const QString& format)
78 {
79  QMap<QString, bool> formatMapping
80  {
81  { "PNG", false },
82  { "JPG", false },
83  { "TIF", false },
84  { "BMP", false },
85  { "MP4", true },
86  { "AVI", true },
87  { "GIF", true },
88  { "WEBM", true },
89  { "APNG", true },
90  };
91 
92  Q_ASSERT(formatMapping.contains(format));
93  return formatMapping[format];
94 }
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString mid(int position, int n) const const