Add base code for custom filenames
This commit is contained in:
63
src/utils/filenamehandler.cpp
Normal file
63
src/utils/filenamehandler.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright 2017 Alejandro Sirgo Rica
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "filenamehandler.h"
|
||||
#include <ctime>
|
||||
#include <locale>
|
||||
#include <QSettings>
|
||||
|
||||
FileNameHandler::FileNameHandler(QObject *parent) : QObject(parent) {
|
||||
std::locale::global(std::locale(std::locale("").name()));
|
||||
}
|
||||
|
||||
QString FileNameHandler::getActualPattern() {
|
||||
return QSettings().value("filenamePattern").toString();
|
||||
}
|
||||
|
||||
QString FileNameHandler::getParsedPattern() {
|
||||
return parseFilename(getActualPattern());
|
||||
}
|
||||
|
||||
QString FileNameHandler::parseFilename(const QString &name) {
|
||||
QString res;
|
||||
if (name.isEmpty()) {
|
||||
res = tr("screenshot");
|
||||
} else {
|
||||
std::time_t t = std::time(NULL);
|
||||
|
||||
char *tempData = QStringTocharArr(name);
|
||||
char data[MAX_CHARACTERS] = {0};
|
||||
std::strftime(data, sizeof(data),
|
||||
tempData, std::localtime(&t));
|
||||
res = QString::fromLocal8Bit(data, strlen(data));
|
||||
free(tempData);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void FileNameHandler::savePattern(const QString &pattern) {
|
||||
QSettings().setValue("filenamePattern", pattern);
|
||||
}
|
||||
|
||||
QString FileNameHandler::charArrToQString(const char *c) {
|
||||
return QString::fromLocal8Bit(c, MAX_CHARACTERS);
|
||||
}
|
||||
|
||||
char * FileNameHandler::QStringTocharArr(const QString &s) {
|
||||
QByteArray ba = s.toLocal8Bit();
|
||||
return const_cast<char *>(strdup(ba.constData()));
|
||||
}
|
||||
Reference in New Issue
Block a user