Add base code for custom filenames
This commit is contained in:
@@ -30,3 +30,7 @@
|
||||
- value: "showDesktopNotification"
|
||||
- type: bool
|
||||
- description: show every desktop notification.
|
||||
- filename pattern
|
||||
- value: "filenamePattern"
|
||||
- type: QString
|
||||
- description: pattern for the saved files.
|
||||
|
||||
@@ -49,7 +49,10 @@ SOURCES += src/main.cpp\
|
||||
src/config/uicoloreditor.cpp \
|
||||
src/config/geneneralconf.cpp \
|
||||
src/flameshotdbusadapter.cpp \
|
||||
src/config/clickablelabel.cpp
|
||||
src/config/clickablelabel.cpp \
|
||||
src/config/filenameeditor.cpp \
|
||||
src/utils/filenamehandler.cpp \
|
||||
src/config/strftimechooserwidget.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/controller.h \
|
||||
@@ -65,7 +68,10 @@ HEADERS += \
|
||||
src/config/uicoloreditor.h \
|
||||
src/config/geneneralconf.h \
|
||||
src/flameshotdbusadapter.h \
|
||||
src/config/clickablelabel.h
|
||||
src/config/clickablelabel.h \
|
||||
src/config/filenameeditor.h \
|
||||
src/utils/filenamehandler.h \
|
||||
src/config/strftimechooserwidget.h
|
||||
|
||||
RESOURCES += \
|
||||
graphics.qrc
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
#include "screenshot.h"
|
||||
#include "button.h"
|
||||
#include "capturemodification.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include <QStandardPaths>
|
||||
#include <QIcon>
|
||||
#include <QSettings>
|
||||
#include <QDateTime>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QMessageBox>
|
||||
@@ -72,8 +72,9 @@ QString Screenshot::graphicalSave(const QRect &selection, QWidget *parent) const
|
||||
savePath = QDir::currentPath();
|
||||
}
|
||||
}
|
||||
|
||||
QString tempName = "/"+ FileNameHandler().getParsedPattern();
|
||||
// find unused name adding _n where n is a number
|
||||
QString tempName = QObject::tr("/screenshot");
|
||||
QFileInfo checkFile(savePath + tempName + "." + format);
|
||||
if (checkFile.exists()) {
|
||||
tempName += "_";
|
||||
@@ -291,8 +292,7 @@ void Screenshot::uploadToImgur(QNetworkAccessManager *accessManager,
|
||||
const QRect &selection)
|
||||
{
|
||||
QString title ="flameshot_screenshot";
|
||||
QString datetime = QDateTime().toString();
|
||||
QString description = "flameshot " + datetime;
|
||||
QString description = FileNameHandler().getParsedPattern();
|
||||
QPixmap pixToSave;
|
||||
if (selection.isEmpty()) {
|
||||
pixToSave = m_modifiedScreenshot;
|
||||
|
||||
@@ -20,18 +20,18 @@
|
||||
#include "src/config/buttonlistview.h"
|
||||
#include "src/config/uicoloreditor.h"
|
||||
#include "src/config/geneneralconf.h"
|
||||
#include "src/config/filenameeditor.h"
|
||||
#include <QIcon>
|
||||
#include <QVBoxLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QKeyEvent>
|
||||
#include <QFrame>
|
||||
|
||||
// ConfigWindow contains the menus where you can configure the application
|
||||
|
||||
ConfigWindow::ConfigWindow(QWidget *parent) : QWidget(parent) {
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setFixedSize(400, 450);
|
||||
setFixedSize(410, 540);
|
||||
setWindowIcon(QIcon(":img/flameshot.png"));
|
||||
setWindowTitle(tr("Configuration"));
|
||||
|
||||
@@ -57,6 +57,13 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QWidget(parent) {
|
||||
m_buttonListView->setFlow(QListWidget::TopToBottom);
|
||||
m_layout->addWidget(m_buttonListView);
|
||||
|
||||
// name editor
|
||||
QLabel *nameEditLabel = new QLabel(tr("Filename editor"), this);
|
||||
m_layout->addWidget(nameEditLabel);
|
||||
|
||||
FileNameEditor *nameEditor = new FileNameEditor(this);
|
||||
m_layout->addWidget(nameEditor);
|
||||
|
||||
show();
|
||||
}
|
||||
|
||||
|
||||
64
src/config/filenameeditor.cpp
Normal file
64
src/config/filenameeditor.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
// 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 "filenameeditor.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include <QGridLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
|
||||
FileNameEditor::FileNameEditor(QWidget *parent) : QFrame(parent) {
|
||||
setFrameStyle(QFrame::StyledPanel);
|
||||
initWidgets();
|
||||
initLayout();
|
||||
}
|
||||
|
||||
void FileNameEditor::initLayout() {
|
||||
m_layout = new QGridLayout(this);
|
||||
m_layout->addWidget(m_nameEditor, 0,1);
|
||||
m_layout->addWidget(m_saveButton, 0, 0);
|
||||
m_layout->addWidget(new QLabel("Preview: ", this), 1, 0);
|
||||
m_layout->addWidget(m_outputLabel, 1, 1);
|
||||
}
|
||||
|
||||
void FileNameEditor::initWidgets() {
|
||||
m_nameHandler = new FileNameHandler(this);
|
||||
|
||||
m_nameEditor = new QLineEdit(this);
|
||||
m_nameEditor->setMaxLength(FileNameHandler::MAX_CHARACTERS);
|
||||
|
||||
m_outputLabel = new QLabel(this);
|
||||
m_saveButton = new QPushButton(tr("Save"), this);
|
||||
|
||||
connect(m_nameEditor, &QLineEdit::textChanged, this,
|
||||
&FileNameEditor::showParsedPattern);
|
||||
m_nameEditor->setText(m_nameHandler->getActualPattern());
|
||||
m_outputLabel->setText(m_nameHandler->getParsedPattern());
|
||||
|
||||
connect(m_saveButton, &QPushButton::clicked, this, &FileNameEditor::savePattern);
|
||||
}
|
||||
|
||||
void FileNameEditor::savePattern() {
|
||||
QString pattern = m_nameEditor->text();
|
||||
m_nameHandler->savePattern(pattern);
|
||||
}
|
||||
|
||||
void FileNameEditor::showParsedPattern(const QString &p) {
|
||||
QString output = m_nameHandler->parseFilename(p);
|
||||
m_outputLabel->setText(output);
|
||||
}
|
||||
50
src/config/filenameeditor.h
Normal file
50
src/config/filenameeditor.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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/>.
|
||||
|
||||
#ifndef FILENAMEEDITOR_H
|
||||
#define FILENAMEEDITOR_H
|
||||
|
||||
#include <QFrame>
|
||||
|
||||
class QGridLayout;
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class FileNameHandler;
|
||||
class QPushButton;
|
||||
|
||||
class FileNameEditor : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FileNameEditor(QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QGridLayout *m_layout;
|
||||
QLabel *m_outputLabel;
|
||||
QLineEdit *m_nameEditor;
|
||||
QPushButton *m_saveButton;
|
||||
FileNameHandler *m_nameHandler;
|
||||
|
||||
void initLayout();
|
||||
void initWidgets();
|
||||
|
||||
private slots:
|
||||
void savePattern();
|
||||
void showParsedPattern(const QString &);
|
||||
};
|
||||
|
||||
#endif // FILENAMEEDITOR_H
|
||||
93
src/config/strftimechooserwidget.cpp
Normal file
93
src/config/strftimechooserwidget.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "strftimechooserwidget.h"
|
||||
|
||||
StrftimeChooserWidget::StrftimeChooserWidget(QWidget *parent) : QWidget(parent) {
|
||||
|
||||
}
|
||||
|
||||
//QStringList StrftimeChooserWidget::m_valuesStr = QList<QString>()
|
||||
// << "%a"
|
||||
// << "%A"
|
||||
// << "%b"
|
||||
// << "%B"
|
||||
// << "%C"
|
||||
// << "%d"
|
||||
// << "%D"
|
||||
// << "%e"
|
||||
// << "%E"
|
||||
// << "%F"
|
||||
// << "%G"
|
||||
// << "%g"
|
||||
// << "%h"
|
||||
// << "%H"
|
||||
// << "%I"
|
||||
// << "%j"
|
||||
// << "%k"
|
||||
// << "%l"
|
||||
// << "%m"
|
||||
// << "%M"
|
||||
// << "%n"
|
||||
// << "%O"
|
||||
// << "%p"
|
||||
// << "%P"
|
||||
// << "%r"
|
||||
// << "%R"
|
||||
// << "%s"
|
||||
// << "%S"
|
||||
// << "%t"
|
||||
// << "%T"
|
||||
// << "%u"
|
||||
// << "%U"
|
||||
// << "%V"
|
||||
// << "%w"
|
||||
// << "%W"
|
||||
// << "%x"
|
||||
// << "%X"
|
||||
// << "%y"
|
||||
// << "%Y"
|
||||
// << "%z"
|
||||
// << "%Z"
|
||||
// << "%%";
|
||||
|
||||
//QStringList StrftimeChooserWidget::m_buttonLabel = QList<QString>()
|
||||
// << "Day (Mon)" //"%a"
|
||||
// << "Day (Monday)" //"%A"
|
||||
// << "Month (Jan)" //"%b"
|
||||
// << "Month (1...12)" //"%B"
|
||||
// << "Century (21)" //"%C"
|
||||
// << "Day (01...31)" //"%d"
|
||||
// << "Full Date (%m/%d/%y)" //"%D"
|
||||
// << " ()" //"%e"
|
||||
// << " ()" //"%E"
|
||||
// << " ()" //"%F"
|
||||
// << " ()" //"%G"
|
||||
// << " ()" //"%g"
|
||||
// << " ()" //"%h"
|
||||
// << " ()" //"%H"
|
||||
// << " ()" //"%I"
|
||||
// << " ()" //"%j"
|
||||
// << " ()" //"%k"
|
||||
// << " ()" //"%l"
|
||||
// << " ()" //"%m"
|
||||
// << " ()" //"%M"
|
||||
// << " ()" //"%n"
|
||||
// << " ()" //"%O"
|
||||
// << " ()" //"%p"
|
||||
// << " ()" //"%P"
|
||||
// << " ()" //"%r"
|
||||
// << " ()" //"%R"
|
||||
// << " ()" //"%s"
|
||||
// << " ()" //"%S"
|
||||
// << " ()" //"%t"
|
||||
// << " ()" //"%T"
|
||||
// << " ()" //"%u"
|
||||
// << " ()" //"%U"
|
||||
// << " ()" //"%V"
|
||||
// << " ()" //"%w"
|
||||
// << " ()" //"%W"
|
||||
// << " ()" //"%x"
|
||||
// << " ()" //"%X"
|
||||
// << " ()" //"%y"
|
||||
// << " ()" //"%Y"
|
||||
// << " ()" //"%z"
|
||||
// << " ()" //"%Z"
|
||||
// << "%"; //"%%";
|
||||
20
src/config/strftimechooserwidget.h
Normal file
20
src/config/strftimechooserwidget.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef STRFTIMECHOOSERWIDGET_H
|
||||
#define STRFTIMECHOOSERWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class StrftimeChooserWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit StrftimeChooserWidget(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void variableEmitted(const QString &);
|
||||
|
||||
private:
|
||||
static QStringList m_valuesStr;
|
||||
static QStringList m_buttonLabel;
|
||||
};
|
||||
|
||||
#endif // STRFTIMECHOOSERWIDGET_H
|
||||
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()));
|
||||
}
|
||||
45
src/utils/filenamehandler.h
Normal file
45
src/utils/filenamehandler.h
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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/>.
|
||||
|
||||
#ifndef FILENAMEHANDLER_H
|
||||
#define FILENAMEHANDLER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class FileNameHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FileNameHandler(QObject *parent = nullptr);
|
||||
|
||||
QString getActualPattern();
|
||||
QString getParsedPattern();
|
||||
QString parseFilename(const QString &name);
|
||||
|
||||
static const int MAX_CHARACTERS = 70;
|
||||
|
||||
public slots:
|
||||
void savePattern(const QString &pattern);
|
||||
|
||||
private:
|
||||
//using charArr = char[MAX_CHARACTERS];
|
||||
inline QString charArrToQString(const char *c);
|
||||
inline char * QStringTocharArr(const QString &s);
|
||||
};
|
||||
|
||||
#endif // FILENAMEHANDLER_H
|
||||
Reference in New Issue
Block a user