Changed clang format to new agreement
This commit is contained in:
committed by
borgmanJeremy
parent
2cbccc3d0a
commit
0d5386edd4
@@ -17,28 +17,25 @@
|
||||
|
||||
#include "colorutils.h"
|
||||
|
||||
inline qreal
|
||||
getColorLuma(const QColor& c)
|
||||
inline qreal getColorLuma(const QColor& c)
|
||||
{
|
||||
return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF();
|
||||
return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF();
|
||||
}
|
||||
|
||||
bool
|
||||
ColorUtils::colorIsDark(const QColor& c)
|
||||
bool ColorUtils::colorIsDark(const QColor& c)
|
||||
{
|
||||
bool isWhite = false;
|
||||
if (getColorLuma(c) <= 0.60) {
|
||||
isWhite = true;
|
||||
}
|
||||
return isWhite;
|
||||
bool isWhite = false;
|
||||
if (getColorLuma(c) <= 0.60) {
|
||||
isWhite = true;
|
||||
}
|
||||
return isWhite;
|
||||
}
|
||||
|
||||
QColor
|
||||
ColorUtils::contrastColor(const QColor& c)
|
||||
QColor ColorUtils::contrastColor(const QColor& c)
|
||||
{
|
||||
int change = colorIsDark(c) ? 30 : -45;
|
||||
int change = colorIsDark(c) ? 30 : -45;
|
||||
|
||||
return QColor(qBound(0, c.red() + change, 255),
|
||||
qBound(0, c.green() + change, 255),
|
||||
qBound(0, c.blue() + change, 255));
|
||||
return QColor(qBound(0, c.red() + change, 255),
|
||||
qBound(0, c.green() + change, 255),
|
||||
qBound(0, c.blue() + change, 255));
|
||||
}
|
||||
|
||||
@@ -21,10 +21,8 @@
|
||||
|
||||
namespace ColorUtils { // namespace
|
||||
|
||||
bool
|
||||
colorIsDark(const QColor& c);
|
||||
bool colorIsDark(const QColor& c);
|
||||
|
||||
QColor
|
||||
contrastColor(const QColor& c);
|
||||
QColor contrastColor(const QColor& c);
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -23,472 +23,434 @@
|
||||
|
||||
ConfigHandler::ConfigHandler()
|
||||
{
|
||||
m_settings.setDefaultFormat(QSettings::IniFormat);
|
||||
m_settings.setDefaultFormat(QSettings::IniFormat);
|
||||
}
|
||||
|
||||
QVector<CaptureToolButton::ButtonType>
|
||||
ConfigHandler::getButtons()
|
||||
QVector<CaptureToolButton::ButtonType> ConfigHandler::getButtons()
|
||||
{
|
||||
QVector<CaptureToolButton::ButtonType> buttons;
|
||||
if (m_settings.contains(QStringLiteral("buttons"))) {
|
||||
QVector<CaptureToolButton::ButtonType> buttons;
|
||||
if (m_settings.contains(QStringLiteral("buttons"))) {
|
||||
// TODO: remove toList in v1.0
|
||||
QVector<int> buttonsInt = m_settings.value(QStringLiteral("buttons"))
|
||||
.value<QList<int>>()
|
||||
.toVector();
|
||||
bool modified = normalizeButtons(buttonsInt);
|
||||
if (modified) {
|
||||
m_settings.setValue(QStringLiteral("buttons"),
|
||||
QVariant::fromValue(buttonsInt.toList()));
|
||||
}
|
||||
buttons = fromIntToButton(buttonsInt);
|
||||
} else {
|
||||
// Default tools
|
||||
buttons << CaptureToolButton::TYPE_PENCIL
|
||||
<< CaptureToolButton::TYPE_DRAWER
|
||||
<< CaptureToolButton::TYPE_ARROW
|
||||
<< CaptureToolButton::TYPE_SELECTION
|
||||
<< CaptureToolButton::TYPE_RECTANGLE
|
||||
<< CaptureToolButton::TYPE_CIRCLE
|
||||
<< CaptureToolButton::TYPE_MARKER
|
||||
<< CaptureToolButton::TYPE_PIXELATE
|
||||
<< CaptureToolButton::TYPE_SELECTIONINDICATOR
|
||||
<< CaptureToolButton::TYPE_MOVESELECTION
|
||||
<< CaptureToolButton::TYPE_UNDO << CaptureToolButton::TYPE_REDO
|
||||
<< CaptureToolButton::TYPE_COPY << CaptureToolButton::TYPE_SAVE
|
||||
<< CaptureToolButton::TYPE_EXIT
|
||||
<< CaptureToolButton::TYPE_IMAGEUPLOADER
|
||||
<< CaptureToolButton::TYPE_OPEN_APP
|
||||
<< CaptureToolButton::TYPE_PIN << CaptureToolButton::TYPE_TEXT
|
||||
<< CaptureToolButton::TYPE_CIRCLECOUNT;
|
||||
}
|
||||
|
||||
using bt = CaptureToolButton::ButtonType;
|
||||
std::sort(buttons.begin(), buttons.end(), [](bt a, bt b) {
|
||||
return CaptureToolButton::getPriorityByButton(a) <
|
||||
CaptureToolButton::getPriorityByButton(b);
|
||||
});
|
||||
return buttons;
|
||||
}
|
||||
|
||||
void ConfigHandler::setButtons(
|
||||
const QVector<CaptureToolButton::ButtonType>& buttons)
|
||||
{
|
||||
QVector<int> l = fromButtonToInt(buttons);
|
||||
normalizeButtons(l);
|
||||
// TODO: remove toList in v1.0
|
||||
QVector<int> buttonsInt = m_settings.value(QStringLiteral("buttons"))
|
||||
.value<QList<int>>()
|
||||
.toVector();
|
||||
bool modified = normalizeButtons(buttonsInt);
|
||||
if (modified) {
|
||||
m_settings.setValue(QStringLiteral("buttons"),
|
||||
QVariant::fromValue(buttonsInt.toList()));
|
||||
}
|
||||
buttons = fromIntToButton(buttonsInt);
|
||||
} else {
|
||||
// Default tools
|
||||
buttons << CaptureToolButton::TYPE_PENCIL << CaptureToolButton::TYPE_DRAWER
|
||||
<< CaptureToolButton::TYPE_ARROW
|
||||
<< CaptureToolButton::TYPE_SELECTION
|
||||
<< CaptureToolButton::TYPE_RECTANGLE
|
||||
<< CaptureToolButton::TYPE_CIRCLE << CaptureToolButton::TYPE_MARKER
|
||||
<< CaptureToolButton::TYPE_PIXELATE
|
||||
<< CaptureToolButton::TYPE_SELECTIONINDICATOR
|
||||
<< CaptureToolButton::TYPE_MOVESELECTION
|
||||
<< CaptureToolButton::TYPE_UNDO << CaptureToolButton::TYPE_REDO
|
||||
<< CaptureToolButton::TYPE_COPY << CaptureToolButton::TYPE_SAVE
|
||||
<< CaptureToolButton::TYPE_EXIT
|
||||
<< CaptureToolButton::TYPE_IMAGEUPLOADER
|
||||
<< CaptureToolButton::TYPE_OPEN_APP << CaptureToolButton::TYPE_PIN
|
||||
<< CaptureToolButton::TYPE_TEXT
|
||||
<< CaptureToolButton::TYPE_CIRCLECOUNT;
|
||||
}
|
||||
|
||||
using bt = CaptureToolButton::ButtonType;
|
||||
std::sort(buttons.begin(), buttons.end(), [](bt a, bt b) {
|
||||
return CaptureToolButton::getPriorityByButton(a) <
|
||||
CaptureToolButton::getPriorityByButton(b);
|
||||
});
|
||||
return buttons;
|
||||
m_settings.setValue(QStringLiteral("buttons"),
|
||||
QVariant::fromValue(l.toList()));
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setButtons(const QVector<CaptureToolButton::ButtonType>& buttons)
|
||||
QVector<QColor> ConfigHandler::getUserColors()
|
||||
{
|
||||
QVector<int> l = fromButtonToInt(buttons);
|
||||
normalizeButtons(l);
|
||||
// TODO: remove toList in v1.0
|
||||
m_settings.setValue(QStringLiteral("buttons"),
|
||||
QVariant::fromValue(l.toList()));
|
||||
}
|
||||
QVector<QColor> colors;
|
||||
const QVector<QColor>& defaultColors = {
|
||||
Qt::darkRed, Qt::red, Qt::yellow, Qt::green, Qt::darkGreen,
|
||||
Qt::cyan, Qt::blue, Qt::magenta, Qt::darkMagenta
|
||||
};
|
||||
|
||||
QVector<QColor>
|
||||
ConfigHandler::getUserColors()
|
||||
{
|
||||
QVector<QColor> colors;
|
||||
const QVector<QColor>& defaultColors = {
|
||||
Qt::darkRed, Qt::red, Qt::yellow, Qt::green, Qt::darkGreen,
|
||||
Qt::cyan, Qt::blue, Qt::magenta, Qt::darkMagenta
|
||||
};
|
||||
if (m_settings.contains(QStringLiteral("userColors"))) {
|
||||
for (const QString& hex :
|
||||
m_settings.value(QStringLiteral("userColors")).toStringList()) {
|
||||
if (QColor::isValidColor(hex)) {
|
||||
colors.append(QColor(hex));
|
||||
}
|
||||
}
|
||||
|
||||
if (m_settings.contains(QStringLiteral("userColors"))) {
|
||||
for (const QString& hex :
|
||||
m_settings.value(QStringLiteral("userColors")).toStringList()) {
|
||||
if (QColor::isValidColor(hex)) {
|
||||
colors.append(QColor(hex));
|
||||
}
|
||||
if (colors.isEmpty()) {
|
||||
colors = defaultColors;
|
||||
}
|
||||
} else {
|
||||
colors = defaultColors;
|
||||
}
|
||||
|
||||
if (colors.isEmpty()) {
|
||||
colors = defaultColors;
|
||||
return colors;
|
||||
}
|
||||
|
||||
void ConfigHandler::setUserColors(const QVector<QColor>& l)
|
||||
{
|
||||
QStringList hexColors;
|
||||
|
||||
for (const QColor& color : l) {
|
||||
hexColors.append(color.name());
|
||||
}
|
||||
} else {
|
||||
colors = defaultColors;
|
||||
}
|
||||
|
||||
return colors;
|
||||
m_settings.setValue(QStringLiteral("userColors"),
|
||||
QVariant::fromValue(hexColors));
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setUserColors(const QVector<QColor>& l)
|
||||
QString ConfigHandler::savePathValue()
|
||||
{
|
||||
QStringList hexColors;
|
||||
|
||||
for (const QColor& color : l) {
|
||||
hexColors.append(color.name());
|
||||
}
|
||||
|
||||
m_settings.setValue(QStringLiteral("userColors"),
|
||||
QVariant::fromValue(hexColors));
|
||||
return m_settings.value(QStringLiteral("savePath")).toString();
|
||||
}
|
||||
|
||||
QString
|
||||
ConfigHandler::savePathValue()
|
||||
void ConfigHandler::setSavePath(const QString& savePath)
|
||||
{
|
||||
return m_settings.value(QStringLiteral("savePath")).toString();
|
||||
m_settings.setValue(QStringLiteral("savePath"), savePath);
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setSavePath(const QString& savePath)
|
||||
QColor ConfigHandler::uiMainColorValue()
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("savePath"), savePath);
|
||||
}
|
||||
QColor res = QColor(116, 0, 150);
|
||||
|
||||
QColor
|
||||
ConfigHandler::uiMainColorValue()
|
||||
{
|
||||
QColor res = QColor(116, 0, 150);
|
||||
if (m_settings.contains(QStringLiteral("uiColor"))) {
|
||||
QString hex = m_settings.value(QStringLiteral("uiColor")).toString();
|
||||
|
||||
if (m_settings.contains(QStringLiteral("uiColor"))) {
|
||||
QString hex = m_settings.value(QStringLiteral("uiColor")).toString();
|
||||
|
||||
if (QColor::isValidColor(hex)) {
|
||||
res = QColor(hex);
|
||||
if (QColor::isValidColor(hex)) {
|
||||
res = QColor(hex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setUIMainColor(const QColor& c)
|
||||
void ConfigHandler::setUIMainColor(const QColor& c)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("uiColor"), c.name());
|
||||
m_settings.setValue(QStringLiteral("uiColor"), c.name());
|
||||
}
|
||||
|
||||
QColor
|
||||
ConfigHandler::uiContrastColorValue()
|
||||
QColor ConfigHandler::uiContrastColorValue()
|
||||
{
|
||||
QColor res = QColor(86, 0, 120);
|
||||
QColor res = QColor(86, 0, 120);
|
||||
|
||||
if (m_settings.contains(QStringLiteral("contrastUiColor"))) {
|
||||
QString hex =
|
||||
m_settings.value(QStringLiteral("contrastUiColor")).toString();
|
||||
if (m_settings.contains(QStringLiteral("contrastUiColor"))) {
|
||||
QString hex =
|
||||
m_settings.value(QStringLiteral("contrastUiColor")).toString();
|
||||
|
||||
if (QColor::isValidColor(hex)) {
|
||||
res = QColor(hex);
|
||||
if (QColor::isValidColor(hex)) {
|
||||
res = QColor(hex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setUIContrastColor(const QColor& c)
|
||||
void ConfigHandler::setUIContrastColor(const QColor& c)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("contrastUiColor"), c.name());
|
||||
m_settings.setValue(QStringLiteral("contrastUiColor"), c.name());
|
||||
}
|
||||
|
||||
QColor
|
||||
ConfigHandler::drawColorValue()
|
||||
QColor ConfigHandler::drawColorValue()
|
||||
{
|
||||
QColor res(Qt::red);
|
||||
QColor res(Qt::red);
|
||||
|
||||
if (m_settings.contains(QStringLiteral("drawColor"))) {
|
||||
QString hex = m_settings.value(QStringLiteral("drawColor")).toString();
|
||||
if (m_settings.contains(QStringLiteral("drawColor"))) {
|
||||
QString hex = m_settings.value(QStringLiteral("drawColor")).toString();
|
||||
|
||||
if (QColor::isValidColor(hex)) {
|
||||
res = QColor(hex);
|
||||
if (QColor::isValidColor(hex)) {
|
||||
res = QColor(hex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setDrawColor(const QColor& c)
|
||||
void ConfigHandler::setDrawColor(const QColor& c)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("drawColor"), c.name());
|
||||
m_settings.setValue(QStringLiteral("drawColor"), c.name());
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigHandler::showHelpValue()
|
||||
bool ConfigHandler::showHelpValue()
|
||||
{
|
||||
bool res = true;
|
||||
if (m_settings.contains(QStringLiteral("showHelp"))) {
|
||||
res = m_settings.value(QStringLiteral("showHelp")).toBool();
|
||||
}
|
||||
return res;
|
||||
bool res = true;
|
||||
if (m_settings.contains(QStringLiteral("showHelp"))) {
|
||||
res = m_settings.value(QStringLiteral("showHelp")).toBool();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setShowHelp(const bool showHelp)
|
||||
void ConfigHandler::setShowHelp(const bool showHelp)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("showHelp"), showHelp);
|
||||
m_settings.setValue(QStringLiteral("showHelp"), showHelp);
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigHandler::showSidePanelButtonValue()
|
||||
bool ConfigHandler::showSidePanelButtonValue()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("showSidePanelButton"), true).toBool();
|
||||
return m_settings.value(QStringLiteral("showSidePanelButton"), true)
|
||||
.toBool();
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setShowSidePanelButton(const bool showSidePanelButton)
|
||||
void ConfigHandler::setShowSidePanelButton(const bool showSidePanelButton)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("showSidePanelButton"),
|
||||
showSidePanelButton);
|
||||
m_settings.setValue(QStringLiteral("showSidePanelButton"),
|
||||
showSidePanelButton);
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigHandler::desktopNotificationValue()
|
||||
bool ConfigHandler::desktopNotificationValue()
|
||||
{
|
||||
bool res = true;
|
||||
if (m_settings.contains(QStringLiteral("showDesktopNotification"))) {
|
||||
res = m_settings.value(QStringLiteral("showDesktopNotification")).toBool();
|
||||
}
|
||||
return res;
|
||||
bool res = true;
|
||||
if (m_settings.contains(QStringLiteral("showDesktopNotification"))) {
|
||||
res =
|
||||
m_settings.value(QStringLiteral("showDesktopNotification")).toBool();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setDesktopNotification(const bool showDesktopNotification)
|
||||
void ConfigHandler::setDesktopNotification(const bool showDesktopNotification)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("showDesktopNotification"),
|
||||
showDesktopNotification);
|
||||
m_settings.setValue(QStringLiteral("showDesktopNotification"),
|
||||
showDesktopNotification);
|
||||
}
|
||||
|
||||
QString
|
||||
ConfigHandler::filenamePatternValue()
|
||||
QString ConfigHandler::filenamePatternValue()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("filenamePattern")).toString();
|
||||
return m_settings.value(QStringLiteral("filenamePattern")).toString();
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setFilenamePattern(const QString& pattern)
|
||||
void ConfigHandler::setFilenamePattern(const QString& pattern)
|
||||
{
|
||||
return m_settings.setValue(QStringLiteral("filenamePattern"), pattern);
|
||||
return m_settings.setValue(QStringLiteral("filenamePattern"), pattern);
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigHandler::disabledTrayIconValue()
|
||||
bool ConfigHandler::disabledTrayIconValue()
|
||||
{
|
||||
bool res = false;
|
||||
if (m_settings.contains(QStringLiteral("disabledTrayIcon"))) {
|
||||
res = m_settings.value(QStringLiteral("disabledTrayIcon")).toBool();
|
||||
}
|
||||
return res;
|
||||
bool res = false;
|
||||
if (m_settings.contains(QStringLiteral("disabledTrayIcon"))) {
|
||||
res = m_settings.value(QStringLiteral("disabledTrayIcon")).toBool();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon)
|
||||
void ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("disabledTrayIcon"), disabledTrayIcon);
|
||||
m_settings.setValue(QStringLiteral("disabledTrayIcon"), disabledTrayIcon);
|
||||
}
|
||||
|
||||
int
|
||||
ConfigHandler::drawThicknessValue()
|
||||
int ConfigHandler::drawThicknessValue()
|
||||
{
|
||||
int res = 0;
|
||||
if (m_settings.contains(QStringLiteral("drawThickness"))) {
|
||||
res = m_settings.value(QStringLiteral("drawThickness")).toInt();
|
||||
}
|
||||
return res;
|
||||
int res = 0;
|
||||
if (m_settings.contains(QStringLiteral("drawThickness"))) {
|
||||
res = m_settings.value(QStringLiteral("drawThickness")).toInt();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setdrawThickness(const int thickness)
|
||||
void ConfigHandler::setdrawThickness(const int thickness)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("drawThickness"), thickness);
|
||||
m_settings.setValue(QStringLiteral("drawThickness"), thickness);
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigHandler::keepOpenAppLauncherValue()
|
||||
bool ConfigHandler::keepOpenAppLauncherValue()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("keepOpenAppLauncher")).toBool();
|
||||
return m_settings.value(QStringLiteral("keepOpenAppLauncher")).toBool();
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setKeepOpenAppLauncher(const bool keepOpen)
|
||||
void ConfigHandler::setKeepOpenAppLauncher(const bool keepOpen)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("keepOpenAppLauncher"), keepOpen);
|
||||
m_settings.setValue(QStringLiteral("keepOpenAppLauncher"), keepOpen);
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigHandler::startupLaunchValue()
|
||||
bool ConfigHandler::startupLaunchValue()
|
||||
{
|
||||
bool res = false;
|
||||
bool res = false;
|
||||
|
||||
if (m_settings.contains(QStringLiteral("startupLaunch"))) {
|
||||
res = m_settings.value(QStringLiteral("startupLaunch")).toBool();
|
||||
}
|
||||
if (m_settings.contains(QStringLiteral("startupLaunch"))) {
|
||||
res = m_settings.value(QStringLiteral("startupLaunch")).toBool();
|
||||
}
|
||||
|
||||
if (res != verifyLaunchFile()) {
|
||||
setStartupLaunch(res);
|
||||
}
|
||||
if (res != verifyLaunchFile()) {
|
||||
setStartupLaunch(res);
|
||||
}
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigHandler::verifyLaunchFile()
|
||||
bool ConfigHandler::verifyLaunchFile()
|
||||
{
|
||||
bool res = false;
|
||||
bool res = false;
|
||||
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
QString path = QDir::homePath() + "/.config/autostart/Flameshot.desktop";
|
||||
res = QFile(path).exists();
|
||||
QString path = QDir::homePath() + "/.config/autostart/Flameshot.desktop";
|
||||
res = QFile(path).exists();
|
||||
#elif defined(Q_OS_WIN)
|
||||
QSettings bootUpSettings(
|
||||
"HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
||||
QSettings::NativeFormat);
|
||||
res = bootUpSettings.value("Flameshot").toString() ==
|
||||
QDir::toNativeSeparators(QCoreApplication::applicationFilePath());
|
||||
QSettings bootUpSettings(
|
||||
"HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
||||
QSettings::NativeFormat);
|
||||
res = bootUpSettings.value("Flameshot").toString() ==
|
||||
QDir::toNativeSeparators(QCoreApplication::applicationFilePath());
|
||||
#endif
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setStartupLaunch(const bool start)
|
||||
void ConfigHandler::setStartupLaunch(const bool start)
|
||||
{
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
QString path = QDir::homePath() + "/.config/autostart/";
|
||||
QDir autostartDir(path);
|
||||
if (!autostartDir.exists()) {
|
||||
autostartDir.mkpath(".");
|
||||
}
|
||||
|
||||
QFile file(path + "Flameshot.desktop");
|
||||
if (start) {
|
||||
if (file.open(QIODevice::WriteOnly)) {
|
||||
QByteArray data("[Desktop Entry]\nName=flameshot\nIcon=flameshot"
|
||||
"\nExec=flameshot\nTerminal=false\nType=Application"
|
||||
"\nX-GNOME-Autostart-enabled=true\n");
|
||||
file.write(data);
|
||||
QString path = QDir::homePath() + "/.config/autostart/";
|
||||
QDir autostartDir(path);
|
||||
if (!autostartDir.exists()) {
|
||||
autostartDir.mkpath(".");
|
||||
}
|
||||
|
||||
QFile file(path + "Flameshot.desktop");
|
||||
if (start) {
|
||||
if (file.open(QIODevice::WriteOnly)) {
|
||||
QByteArray data("[Desktop Entry]\nName=flameshot\nIcon=flameshot"
|
||||
"\nExec=flameshot\nTerminal=false\nType=Application"
|
||||
"\nX-GNOME-Autostart-enabled=true\n");
|
||||
file.write(data);
|
||||
}
|
||||
} else {
|
||||
file.remove();
|
||||
}
|
||||
} else {
|
||||
file.remove();
|
||||
}
|
||||
#elif defined(Q_OS_WIN)
|
||||
QSettings bootUpSettings(
|
||||
"HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
||||
QSettings::NativeFormat);
|
||||
if (start) {
|
||||
QString app_path =
|
||||
QDir::toNativeSeparators(QCoreApplication::applicationFilePath());
|
||||
bootUpSettings.setValue("Flameshot", app_path);
|
||||
} else {
|
||||
bootUpSettings.remove("Flameshot");
|
||||
}
|
||||
#endif
|
||||
m_settings.setValue(QStringLiteral("startupLaunch"), start);
|
||||
}
|
||||
|
||||
int
|
||||
ConfigHandler::contrastOpacityValue()
|
||||
{
|
||||
int opacity = 190;
|
||||
if (m_settings.contains(QStringLiteral("contrastOpacity"))) {
|
||||
opacity = m_settings.value(QStringLiteral("contrastOpacity")).toInt();
|
||||
opacity = qBound(0, opacity, 255);
|
||||
}
|
||||
return opacity;
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setContrastOpacity(const int transparency)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("contrastOpacity"), transparency);
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigHandler::closeAfterScreenshotValue()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("closeAfterScreenshot")).toBool();
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setCloseAfterScreenshot(const bool close)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("closeAfterScreenshot"), close);
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigHandler::copyAndCloseAfterUploadEnabled()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("copyAndCloseAfterUpload")).toBool();
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setCopyAndCloseAfterUploadEnabled(const bool value)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("copyAndCloseAfterUpload"), value);
|
||||
}
|
||||
bool
|
||||
ConfigHandler::saveAfterCopyValue()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("saveAfterCopy")).toBool();
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setSaveAfterCopy(const bool save)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("saveAfterCopy"), save);
|
||||
}
|
||||
|
||||
QString
|
||||
ConfigHandler::saveAfterCopyPathValue()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("saveAfterCopyPath")).toString();
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setSaveAfterCopyPath(const QString& path)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("saveAfterCopyPath"), path);
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setDefaults()
|
||||
{
|
||||
m_settings.clear();
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setAllTheButtons()
|
||||
{
|
||||
QVector<int> buttons;
|
||||
auto listTypes = CaptureToolButton::getIterableButtonTypes();
|
||||
for (const CaptureToolButton::ButtonType t : listTypes) {
|
||||
buttons << static_cast<int>(t);
|
||||
}
|
||||
// TODO: remove toList in v1.0
|
||||
m_settings.setValue(QStringLiteral("buttons"),
|
||||
QVariant::fromValue(buttons.toList()));
|
||||
}
|
||||
|
||||
QString
|
||||
ConfigHandler::configFilePath() const
|
||||
{
|
||||
return m_settings.fileName();
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigHandler::normalizeButtons(QVector<int>& buttons)
|
||||
{
|
||||
auto listTypes = CaptureToolButton::getIterableButtonTypes();
|
||||
QVector<int> listTypesInt;
|
||||
for (auto i : listTypes)
|
||||
listTypesInt << static_cast<int>(i);
|
||||
|
||||
bool hasChanged = false;
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
if (!listTypesInt.contains(buttons.at(i))) {
|
||||
buttons.remove(i);
|
||||
hasChanged = true;
|
||||
QSettings bootUpSettings(
|
||||
"HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
||||
QSettings::NativeFormat);
|
||||
if (start) {
|
||||
QString app_path =
|
||||
QDir::toNativeSeparators(QCoreApplication::applicationFilePath());
|
||||
bootUpSettings.setValue("Flameshot", app_path);
|
||||
} else {
|
||||
bootUpSettings.remove("Flameshot");
|
||||
}
|
||||
}
|
||||
return hasChanged;
|
||||
#endif
|
||||
m_settings.setValue(QStringLiteral("startupLaunch"), start);
|
||||
}
|
||||
|
||||
QVector<CaptureToolButton::ButtonType>
|
||||
ConfigHandler::fromIntToButton(const QVector<int>& l)
|
||||
int ConfigHandler::contrastOpacityValue()
|
||||
{
|
||||
QVector<CaptureToolButton::ButtonType> buttons;
|
||||
for (auto const i : l)
|
||||
buttons << static_cast<CaptureToolButton::ButtonType>(i);
|
||||
return buttons;
|
||||
int opacity = 190;
|
||||
if (m_settings.contains(QStringLiteral("contrastOpacity"))) {
|
||||
opacity = m_settings.value(QStringLiteral("contrastOpacity")).toInt();
|
||||
opacity = qBound(0, opacity, 255);
|
||||
}
|
||||
return opacity;
|
||||
}
|
||||
|
||||
QVector<int>
|
||||
ConfigHandler::fromButtonToInt(const QVector<CaptureToolButton::ButtonType>& l)
|
||||
void ConfigHandler::setContrastOpacity(const int transparency)
|
||||
{
|
||||
QVector<int> buttons;
|
||||
for (auto const i : l)
|
||||
buttons << static_cast<int>(i);
|
||||
return buttons;
|
||||
m_settings.setValue(QStringLiteral("contrastOpacity"), transparency);
|
||||
}
|
||||
|
||||
bool ConfigHandler::closeAfterScreenshotValue()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("closeAfterScreenshot")).toBool();
|
||||
}
|
||||
|
||||
void ConfigHandler::setCloseAfterScreenshot(const bool close)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("closeAfterScreenshot"), close);
|
||||
}
|
||||
|
||||
bool ConfigHandler::copyAndCloseAfterUploadEnabled()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("copyAndCloseAfterUpload")).toBool();
|
||||
}
|
||||
|
||||
void ConfigHandler::setCopyAndCloseAfterUploadEnabled(const bool value)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("copyAndCloseAfterUpload"), value);
|
||||
}
|
||||
bool ConfigHandler::saveAfterCopyValue()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("saveAfterCopy")).toBool();
|
||||
}
|
||||
|
||||
void ConfigHandler::setSaveAfterCopy(const bool save)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("saveAfterCopy"), save);
|
||||
}
|
||||
|
||||
QString ConfigHandler::saveAfterCopyPathValue()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("saveAfterCopyPath")).toString();
|
||||
}
|
||||
|
||||
void ConfigHandler::setSaveAfterCopyPath(const QString& path)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("saveAfterCopyPath"), path);
|
||||
}
|
||||
|
||||
void ConfigHandler::setDefaults()
|
||||
{
|
||||
m_settings.clear();
|
||||
}
|
||||
|
||||
void ConfigHandler::setAllTheButtons()
|
||||
{
|
||||
QVector<int> buttons;
|
||||
auto listTypes = CaptureToolButton::getIterableButtonTypes();
|
||||
for (const CaptureToolButton::ButtonType t : listTypes) {
|
||||
buttons << static_cast<int>(t);
|
||||
}
|
||||
// TODO: remove toList in v1.0
|
||||
m_settings.setValue(QStringLiteral("buttons"),
|
||||
QVariant::fromValue(buttons.toList()));
|
||||
}
|
||||
|
||||
QString ConfigHandler::configFilePath() const
|
||||
{
|
||||
return m_settings.fileName();
|
||||
}
|
||||
|
||||
bool ConfigHandler::normalizeButtons(QVector<int>& buttons)
|
||||
{
|
||||
auto listTypes = CaptureToolButton::getIterableButtonTypes();
|
||||
QVector<int> listTypesInt;
|
||||
for (auto i : listTypes)
|
||||
listTypesInt << static_cast<int>(i);
|
||||
|
||||
bool hasChanged = false;
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
if (!listTypesInt.contains(buttons.at(i))) {
|
||||
buttons.remove(i);
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
return hasChanged;
|
||||
}
|
||||
|
||||
QVector<CaptureToolButton::ButtonType> ConfigHandler::fromIntToButton(
|
||||
const QVector<int>& l)
|
||||
{
|
||||
QVector<CaptureToolButton::ButtonType> buttons;
|
||||
for (auto const i : l)
|
||||
buttons << static_cast<CaptureToolButton::ButtonType>(i);
|
||||
return buttons;
|
||||
}
|
||||
|
||||
QVector<int> ConfigHandler::fromButtonToInt(
|
||||
const QVector<CaptureToolButton::ButtonType>& l)
|
||||
{
|
||||
QVector<int> buttons;
|
||||
for (auto const i : l)
|
||||
buttons << static_cast<int>(i);
|
||||
return buttons;
|
||||
}
|
||||
|
||||
@@ -24,75 +24,77 @@
|
||||
class ConfigHandler
|
||||
{
|
||||
public:
|
||||
explicit ConfigHandler();
|
||||
explicit ConfigHandler();
|
||||
|
||||
QVector<CaptureToolButton::ButtonType> getButtons();
|
||||
void setButtons(const QVector<CaptureToolButton::ButtonType>&);
|
||||
QVector<CaptureToolButton::ButtonType> getButtons();
|
||||
void setButtons(const QVector<CaptureToolButton::ButtonType>&);
|
||||
|
||||
QVector<QColor> getUserColors();
|
||||
void setUserColors(const QVector<QColor>&);
|
||||
QVector<QColor> getUserColors();
|
||||
void setUserColors(const QVector<QColor>&);
|
||||
|
||||
QString savePathValue();
|
||||
void setSavePath(const QString&);
|
||||
QString savePathValue();
|
||||
void setSavePath(const QString&);
|
||||
|
||||
QColor uiMainColorValue();
|
||||
void setUIMainColor(const QColor&);
|
||||
QColor uiMainColorValue();
|
||||
void setUIMainColor(const QColor&);
|
||||
|
||||
QColor uiContrastColorValue();
|
||||
void setUIContrastColor(const QColor&);
|
||||
QColor uiContrastColorValue();
|
||||
void setUIContrastColor(const QColor&);
|
||||
|
||||
QColor drawColorValue();
|
||||
void setDrawColor(const QColor&);
|
||||
QColor drawColorValue();
|
||||
void setDrawColor(const QColor&);
|
||||
|
||||
bool showHelpValue();
|
||||
void setShowHelp(const bool);
|
||||
bool showHelpValue();
|
||||
void setShowHelp(const bool);
|
||||
|
||||
bool showSidePanelButtonValue();
|
||||
void setShowSidePanelButton(const bool);
|
||||
bool showSidePanelButtonValue();
|
||||
void setShowSidePanelButton(const bool);
|
||||
|
||||
bool desktopNotificationValue();
|
||||
void setDesktopNotification(const bool);
|
||||
bool desktopNotificationValue();
|
||||
void setDesktopNotification(const bool);
|
||||
|
||||
QString filenamePatternValue();
|
||||
void setFilenamePattern(const QString&);
|
||||
QString filenamePatternValue();
|
||||
void setFilenamePattern(const QString&);
|
||||
|
||||
bool disabledTrayIconValue();
|
||||
void setDisabledTrayIcon(const bool);
|
||||
bool disabledTrayIconValue();
|
||||
void setDisabledTrayIcon(const bool);
|
||||
|
||||
int drawThicknessValue();
|
||||
void setdrawThickness(const int);
|
||||
int drawThicknessValue();
|
||||
void setdrawThickness(const int);
|
||||
|
||||
bool keepOpenAppLauncherValue();
|
||||
void setKeepOpenAppLauncher(const bool);
|
||||
bool keepOpenAppLauncherValue();
|
||||
void setKeepOpenAppLauncher(const bool);
|
||||
|
||||
bool verifyLaunchFile();
|
||||
bool startupLaunchValue();
|
||||
void setStartupLaunch(const bool);
|
||||
bool verifyLaunchFile();
|
||||
bool startupLaunchValue();
|
||||
void setStartupLaunch(const bool);
|
||||
|
||||
int contrastOpacityValue();
|
||||
void setContrastOpacity(const int);
|
||||
int contrastOpacityValue();
|
||||
void setContrastOpacity(const int);
|
||||
|
||||
bool closeAfterScreenshotValue();
|
||||
void setCloseAfterScreenshot(const bool);
|
||||
bool closeAfterScreenshotValue();
|
||||
void setCloseAfterScreenshot(const bool);
|
||||
|
||||
bool copyAndCloseAfterUploadEnabled();
|
||||
void setCopyAndCloseAfterUploadEnabled(const bool);
|
||||
bool saveAfterCopyValue();
|
||||
void setSaveAfterCopy(const bool);
|
||||
bool copyAndCloseAfterUploadEnabled();
|
||||
void setCopyAndCloseAfterUploadEnabled(const bool);
|
||||
bool saveAfterCopyValue();
|
||||
void setSaveAfterCopy(const bool);
|
||||
|
||||
QString saveAfterCopyPathValue();
|
||||
void setSaveAfterCopyPath(const QString&);
|
||||
QString saveAfterCopyPathValue();
|
||||
void setSaveAfterCopyPath(const QString&);
|
||||
|
||||
void setDefaults();
|
||||
void setAllTheButtons();
|
||||
void setDefaults();
|
||||
void setAllTheButtons();
|
||||
|
||||
QString configFilePath() const;
|
||||
QString configFilePath() const;
|
||||
|
||||
private:
|
||||
QSettings m_settings;
|
||||
QSettings m_settings;
|
||||
|
||||
bool normalizeButtons(QVector<int>&);
|
||||
bool normalizeButtons(QVector<int>&);
|
||||
|
||||
QVector<CaptureToolButton::ButtonType> fromIntToButton(const QVector<int>& l);
|
||||
QVector<int> fromButtonToInt(const QVector<CaptureToolButton::ButtonType>& l);
|
||||
QVector<CaptureToolButton::ButtonType> fromIntToButton(
|
||||
const QVector<int>& l);
|
||||
QVector<int> fromButtonToInt(
|
||||
const QVector<CaptureToolButton::ButtonType>& l);
|
||||
};
|
||||
|
||||
@@ -25,52 +25,48 @@ DBusUtils::DBusUtils(QObject* parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
void
|
||||
DBusUtils::connectPrintCapture(QDBusConnection& session, uint id)
|
||||
void DBusUtils::connectPrintCapture(QDBusConnection& session, uint id)
|
||||
{
|
||||
m_id = id;
|
||||
// captureTaken
|
||||
session.connect(QStringLiteral("org.flameshot.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("captureTaken"),
|
||||
this,
|
||||
SLOT(captureTaken(uint, QByteArray)));
|
||||
// captureFailed
|
||||
session.connect(QStringLiteral("org.flameshot.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("captureFailed"),
|
||||
this,
|
||||
SLOT(captureFailed(uint)));
|
||||
m_id = id;
|
||||
// captureTaken
|
||||
session.connect(QStringLiteral("org.flameshot.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("captureTaken"),
|
||||
this,
|
||||
SLOT(captureTaken(uint, QByteArray)));
|
||||
// captureFailed
|
||||
session.connect(QStringLiteral("org.flameshot.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("captureFailed"),
|
||||
this,
|
||||
SLOT(captureFailed(uint)));
|
||||
}
|
||||
|
||||
void
|
||||
DBusUtils::checkDBusConnection(const QDBusConnection& connection)
|
||||
void DBusUtils::checkDBusConnection(const QDBusConnection& connection)
|
||||
{
|
||||
if (!connection.isConnected()) {
|
||||
SystemNotification().sendMessage(tr("Unable to connect via DBus"));
|
||||
qApp->exit(1);
|
||||
}
|
||||
if (!connection.isConnected()) {
|
||||
SystemNotification().sendMessage(tr("Unable to connect via DBus"));
|
||||
qApp->exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DBusUtils::captureTaken(uint id, QByteArray rawImage)
|
||||
void DBusUtils::captureTaken(uint id, QByteArray rawImage)
|
||||
{
|
||||
if (m_id == id) {
|
||||
QFile file;
|
||||
file.open(stdout, QIODevice::WriteOnly);
|
||||
file.write(rawImage);
|
||||
file.close();
|
||||
qApp->exit();
|
||||
}
|
||||
if (m_id == id) {
|
||||
QFile file;
|
||||
file.open(stdout, QIODevice::WriteOnly);
|
||||
file.write(rawImage);
|
||||
file.close();
|
||||
qApp->exit();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DBusUtils::captureFailed(uint id)
|
||||
void DBusUtils::captureFailed(uint id)
|
||||
{
|
||||
if (m_id == id) {
|
||||
QTextStream(stdout) << "screenshot aborted\n";
|
||||
qApp->exit(1);
|
||||
}
|
||||
if (m_id == id) {
|
||||
QTextStream(stdout) << "screenshot aborted\n";
|
||||
qApp->exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,17 +23,17 @@
|
||||
|
||||
class DBusUtils : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DBusUtils(QObject* parent = nullptr);
|
||||
explicit DBusUtils(QObject* parent = nullptr);
|
||||
|
||||
void connectPrintCapture(QDBusConnection& session, uint id);
|
||||
void checkDBusConnection(const QDBusConnection& connection);
|
||||
void connectPrintCapture(QDBusConnection& session, uint id);
|
||||
void checkDBusConnection(const QDBusConnection& connection);
|
||||
|
||||
public slots:
|
||||
void captureTaken(uint id, QByteArray rawImage);
|
||||
void captureFailed(uint id);
|
||||
void captureTaken(uint id, QByteArray rawImage);
|
||||
void captureFailed(uint id);
|
||||
|
||||
private:
|
||||
uint m_id;
|
||||
uint m_id;
|
||||
};
|
||||
|
||||
@@ -24,126 +24,130 @@
|
||||
|
||||
DesktopFileParser::DesktopFileParser()
|
||||
{
|
||||
QString locale = QLocale().name();
|
||||
QString localeShort = QLocale().name().left(2);
|
||||
m_localeName = QStringLiteral("Name[%1]").arg(locale);
|
||||
m_localeDescription = QStringLiteral("Comment[%1]").arg(locale);
|
||||
m_localeNameShort = QStringLiteral("Name[%1]").arg(localeShort);
|
||||
m_localeDescriptionShort = QStringLiteral("Comment[%1]").arg(localeShort);
|
||||
m_defaultIcon = QIcon::fromTheme(QStringLiteral("application-x-executable"));
|
||||
QString locale = QLocale().name();
|
||||
QString localeShort = QLocale().name().left(2);
|
||||
m_localeName = QStringLiteral("Name[%1]").arg(locale);
|
||||
m_localeDescription = QStringLiteral("Comment[%1]").arg(locale);
|
||||
m_localeNameShort = QStringLiteral("Name[%1]").arg(localeShort);
|
||||
m_localeDescriptionShort = QStringLiteral("Comment[%1]").arg(localeShort);
|
||||
m_defaultIcon =
|
||||
QIcon::fromTheme(QStringLiteral("application-x-executable"));
|
||||
}
|
||||
|
||||
DesktopAppData
|
||||
DesktopFileParser::parseDesktopFile(const QString& fileName, bool& ok) const
|
||||
DesktopAppData DesktopFileParser::parseDesktopFile(const QString& fileName,
|
||||
bool& ok) const
|
||||
{
|
||||
DesktopAppData res;
|
||||
ok = true;
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
ok = false;
|
||||
return res;
|
||||
}
|
||||
bool nameLocaleSet = false;
|
||||
bool descriptionLocaleSet = false;
|
||||
bool isApplication = false;
|
||||
QTextStream in(&file);
|
||||
// enter the desktop entry definition
|
||||
while (!in.atEnd() && in.readLine() != QLatin1String("[Desktop Entry]")) {
|
||||
}
|
||||
// start parsing
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
if (line.startsWith(QLatin1String("Icon"))) {
|
||||
res.icon = QIcon::fromTheme(
|
||||
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed(),
|
||||
m_defaultIcon);
|
||||
} else if (!nameLocaleSet && line.startsWith(QLatin1String("Name"))) {
|
||||
if (line.startsWith(m_localeName) || line.startsWith(m_localeNameShort)) {
|
||||
res.name = line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
|
||||
nameLocaleSet = true;
|
||||
} else if (line.startsWith(QLatin1String("Name="))) {
|
||||
res.name = line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
|
||||
}
|
||||
} else if (!descriptionLocaleSet &&
|
||||
line.startsWith(QLatin1String("Comment"))) {
|
||||
if (line.startsWith(m_localeDescription) ||
|
||||
line.startsWith(m_localeDescriptionShort)) {
|
||||
res.description =
|
||||
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
|
||||
descriptionLocaleSet = true;
|
||||
} else if (line.startsWith(QLatin1String("Comment="))) {
|
||||
res.description =
|
||||
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
|
||||
}
|
||||
} else if (line.startsWith(QLatin1String("Exec"))) {
|
||||
if (line.contains(QLatin1String("%"))) {
|
||||
res.exec = line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
|
||||
} else {
|
||||
DesktopAppData res;
|
||||
ok = true;
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
} else if (line.startsWith(QLatin1String("Type"))) {
|
||||
if (line.contains(QLatin1String("Application"))) {
|
||||
isApplication = true;
|
||||
}
|
||||
} else if (line.startsWith(QLatin1String("Categories"))) {
|
||||
res.categories = line.mid(line.indexOf(QLatin1String("=")) + 1)
|
||||
.split(QStringLiteral(";"));
|
||||
} else if (line == QLatin1String("NoDisplay=true")) {
|
||||
ok = false;
|
||||
break;
|
||||
} else if (line == QLatin1String("Terminal=true")) {
|
||||
res.showInTerminal = true;
|
||||
return res;
|
||||
}
|
||||
// ignore the other entries
|
||||
else if (line.startsWith(QLatin1String("["))) {
|
||||
break;
|
||||
bool nameLocaleSet = false;
|
||||
bool descriptionLocaleSet = false;
|
||||
bool isApplication = false;
|
||||
QTextStream in(&file);
|
||||
// enter the desktop entry definition
|
||||
while (!in.atEnd() && in.readLine() != QLatin1String("[Desktop Entry]")) {
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
if (res.exec.isEmpty() || res.name.isEmpty() || !isApplication) {
|
||||
ok = false;
|
||||
}
|
||||
return res;
|
||||
// start parsing
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
if (line.startsWith(QLatin1String("Icon"))) {
|
||||
res.icon = QIcon::fromTheme(
|
||||
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed(),
|
||||
m_defaultIcon);
|
||||
} else if (!nameLocaleSet && line.startsWith(QLatin1String("Name"))) {
|
||||
if (line.startsWith(m_localeName) ||
|
||||
line.startsWith(m_localeNameShort)) {
|
||||
res.name =
|
||||
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
|
||||
nameLocaleSet = true;
|
||||
} else if (line.startsWith(QLatin1String("Name="))) {
|
||||
res.name =
|
||||
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
|
||||
}
|
||||
} else if (!descriptionLocaleSet &&
|
||||
line.startsWith(QLatin1String("Comment"))) {
|
||||
if (line.startsWith(m_localeDescription) ||
|
||||
line.startsWith(m_localeDescriptionShort)) {
|
||||
res.description =
|
||||
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
|
||||
descriptionLocaleSet = true;
|
||||
} else if (line.startsWith(QLatin1String("Comment="))) {
|
||||
res.description =
|
||||
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
|
||||
}
|
||||
} else if (line.startsWith(QLatin1String("Exec"))) {
|
||||
if (line.contains(QLatin1String("%"))) {
|
||||
res.exec =
|
||||
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
|
||||
} else {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
} else if (line.startsWith(QLatin1String("Type"))) {
|
||||
if (line.contains(QLatin1String("Application"))) {
|
||||
isApplication = true;
|
||||
}
|
||||
} else if (line.startsWith(QLatin1String("Categories"))) {
|
||||
res.categories = line.mid(line.indexOf(QLatin1String("=")) + 1)
|
||||
.split(QStringLiteral(";"));
|
||||
} else if (line == QLatin1String("NoDisplay=true")) {
|
||||
ok = false;
|
||||
break;
|
||||
} else if (line == QLatin1String("Terminal=true")) {
|
||||
res.showInTerminal = true;
|
||||
}
|
||||
// ignore the other entries
|
||||
else if (line.startsWith(QLatin1String("["))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
if (res.exec.isEmpty() || res.name.isEmpty() || !isApplication) {
|
||||
ok = false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int
|
||||
DesktopFileParser::processDirectory(const QDir& dir)
|
||||
int DesktopFileParser::processDirectory(const QDir& dir)
|
||||
{
|
||||
QStringList entries = dir.entryList(QDir::NoDotAndDotDot | QDir::Files);
|
||||
bool ok;
|
||||
int length = m_appList.length();
|
||||
for (QString file : entries) {
|
||||
DesktopAppData app = parseDesktopFile(dir.absoluteFilePath(file), ok);
|
||||
if (ok) {
|
||||
m_appList.append(app);
|
||||
QStringList entries = dir.entryList(QDir::NoDotAndDotDot | QDir::Files);
|
||||
bool ok;
|
||||
int length = m_appList.length();
|
||||
for (QString file : entries) {
|
||||
DesktopAppData app = parseDesktopFile(dir.absoluteFilePath(file), ok);
|
||||
if (ok) {
|
||||
m_appList.append(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
return m_appList.length() - length;
|
||||
return m_appList.length() - length;
|
||||
}
|
||||
|
||||
QVector<DesktopAppData>
|
||||
DesktopFileParser::getAppsByCategory(const QString& category)
|
||||
QVector<DesktopAppData> DesktopFileParser::getAppsByCategory(
|
||||
const QString& category)
|
||||
{
|
||||
QVector<DesktopAppData> res;
|
||||
for (const DesktopAppData& app : m_appList) {
|
||||
if (app.categories.contains(category)) {
|
||||
res.append(app);
|
||||
QVector<DesktopAppData> res;
|
||||
for (const DesktopAppData& app : m_appList) {
|
||||
if (app.categories.contains(category)) {
|
||||
res.append(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
QMap<QString, QVector<DesktopAppData>>
|
||||
DesktopFileParser::getAppsByCategory(const QStringList& categories)
|
||||
QMap<QString, QVector<DesktopAppData>> DesktopFileParser::getAppsByCategory(
|
||||
const QStringList& categories)
|
||||
{
|
||||
QMap<QString, QVector<DesktopAppData>> res;
|
||||
for (const DesktopAppData& app : m_appList) {
|
||||
for (const QString& category : categories) {
|
||||
if (app.categories.contains(category)) {
|
||||
res[category].append(app);
|
||||
}
|
||||
QMap<QString, QVector<DesktopAppData>> res;
|
||||
for (const DesktopAppData& app : m_appList) {
|
||||
for (const QString& category : categories) {
|
||||
if (app.categories.contains(category)) {
|
||||
res[category].append(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -27,50 +27,50 @@ class QTextStream;
|
||||
|
||||
struct DesktopAppData
|
||||
{
|
||||
DesktopAppData()
|
||||
: showInTerminal()
|
||||
{}
|
||||
DesktopAppData()
|
||||
: showInTerminal()
|
||||
{}
|
||||
|
||||
DesktopAppData(const QString& name,
|
||||
const QString& description,
|
||||
const QString& exec,
|
||||
QIcon icon)
|
||||
: name(name)
|
||||
, description(description)
|
||||
, exec(exec)
|
||||
, icon(icon)
|
||||
, showInTerminal(false)
|
||||
{}
|
||||
DesktopAppData(const QString& name,
|
||||
const QString& description,
|
||||
const QString& exec,
|
||||
QIcon icon)
|
||||
: name(name)
|
||||
, description(description)
|
||||
, exec(exec)
|
||||
, icon(icon)
|
||||
, showInTerminal(false)
|
||||
{}
|
||||
|
||||
bool operator==(const DesktopAppData& other) const
|
||||
{
|
||||
return name == other.name;
|
||||
}
|
||||
bool operator==(const DesktopAppData& other) const
|
||||
{
|
||||
return name == other.name;
|
||||
}
|
||||
|
||||
QString name;
|
||||
QString description;
|
||||
QString exec;
|
||||
QStringList categories;
|
||||
QIcon icon;
|
||||
bool showInTerminal;
|
||||
QString name;
|
||||
QString description;
|
||||
QString exec;
|
||||
QStringList categories;
|
||||
QIcon icon;
|
||||
bool showInTerminal;
|
||||
};
|
||||
|
||||
struct DesktopFileParser
|
||||
{
|
||||
DesktopFileParser();
|
||||
DesktopAppData parseDesktopFile(const QString& fileName, bool& ok) const;
|
||||
int processDirectory(const QDir& dir);
|
||||
DesktopFileParser();
|
||||
DesktopAppData parseDesktopFile(const QString& fileName, bool& ok) const;
|
||||
int processDirectory(const QDir& dir);
|
||||
|
||||
QVector<DesktopAppData> getAppsByCategory(const QString& category);
|
||||
QMap<QString, QVector<DesktopAppData>> getAppsByCategory(
|
||||
const QStringList& categories);
|
||||
QVector<DesktopAppData> getAppsByCategory(const QString& category);
|
||||
QMap<QString, QVector<DesktopAppData>> getAppsByCategory(
|
||||
const QStringList& categories);
|
||||
|
||||
private:
|
||||
QString m_localeName;
|
||||
QString m_localeDescription;
|
||||
QString m_localeNameShort;
|
||||
QString m_localeDescriptionShort;
|
||||
QString m_localeName;
|
||||
QString m_localeDescription;
|
||||
QString m_localeNameShort;
|
||||
QString m_localeDescriptionShort;
|
||||
|
||||
QIcon m_defaultIcon;
|
||||
QVector<DesktopAppData> m_appList;
|
||||
QIcon m_defaultIcon;
|
||||
QVector<DesktopAppData> m_appList;
|
||||
};
|
||||
|
||||
@@ -20,35 +20,33 @@
|
||||
|
||||
DesktopInfo::DesktopInfo()
|
||||
{
|
||||
auto e = QProcessEnvironment::systemEnvironment();
|
||||
XDG_CURRENT_DESKTOP = e.value(QStringLiteral("XDG_CURRENT_DESKTOP"));
|
||||
XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
|
||||
WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));
|
||||
KDE_FULL_SESSION = e.value(QStringLiteral("KDE_FULL_SESSION"));
|
||||
GNOME_DESKTOP_SESSION_ID =
|
||||
e.value(QStringLiteral("GNOME_DESKTOP_SESSION_ID"));
|
||||
DESKTOP_SESSION = e.value(QStringLiteral("DESKTOP_SESSION"));
|
||||
auto e = QProcessEnvironment::systemEnvironment();
|
||||
XDG_CURRENT_DESKTOP = e.value(QStringLiteral("XDG_CURRENT_DESKTOP"));
|
||||
XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
|
||||
WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));
|
||||
KDE_FULL_SESSION = e.value(QStringLiteral("KDE_FULL_SESSION"));
|
||||
GNOME_DESKTOP_SESSION_ID =
|
||||
e.value(QStringLiteral("GNOME_DESKTOP_SESSION_ID"));
|
||||
DESKTOP_SESSION = e.value(QStringLiteral("DESKTOP_SESSION"));
|
||||
}
|
||||
|
||||
bool
|
||||
DesktopInfo::waylandDectected()
|
||||
bool DesktopInfo::waylandDectected()
|
||||
{
|
||||
return XDG_SESSION_TYPE == QLatin1String("wayland") ||
|
||||
WAYLAND_DISPLAY.contains(QLatin1String("wayland"),
|
||||
Qt::CaseInsensitive);
|
||||
return XDG_SESSION_TYPE == QLatin1String("wayland") ||
|
||||
WAYLAND_DISPLAY.contains(QLatin1String("wayland"),
|
||||
Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
DesktopInfo::WM
|
||||
DesktopInfo::windowManager()
|
||||
DesktopInfo::WM DesktopInfo::windowManager()
|
||||
{
|
||||
DesktopInfo::WM res = DesktopInfo::OTHER;
|
||||
if (XDG_CURRENT_DESKTOP.contains(QLatin1String("GNOME"),
|
||||
Qt::CaseInsensitive) ||
|
||||
!GNOME_DESKTOP_SESSION_ID.isEmpty()) {
|
||||
res = DesktopInfo::GNOME;
|
||||
} else if (!KDE_FULL_SESSION.isEmpty() ||
|
||||
DESKTOP_SESSION == QLatin1String("kde-plasma")) {
|
||||
res = DesktopInfo::KDE;
|
||||
}
|
||||
return res;
|
||||
DesktopInfo::WM res = DesktopInfo::OTHER;
|
||||
if (XDG_CURRENT_DESKTOP.contains(QLatin1String("GNOME"),
|
||||
Qt::CaseInsensitive) ||
|
||||
!GNOME_DESKTOP_SESSION_ID.isEmpty()) {
|
||||
res = DesktopInfo::GNOME;
|
||||
} else if (!KDE_FULL_SESSION.isEmpty() ||
|
||||
DESKTOP_SESSION == QLatin1String("kde-plasma")) {
|
||||
res = DesktopInfo::KDE;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -22,24 +22,24 @@
|
||||
class DesktopInfo
|
||||
{
|
||||
public:
|
||||
DesktopInfo();
|
||||
DesktopInfo();
|
||||
|
||||
enum WM
|
||||
{
|
||||
GNOME,
|
||||
KDE,
|
||||
OTHER
|
||||
};
|
||||
enum WM
|
||||
{
|
||||
GNOME,
|
||||
KDE,
|
||||
OTHER
|
||||
};
|
||||
|
||||
bool waylandDectected();
|
||||
WM windowManager();
|
||||
bool waylandDectected();
|
||||
WM windowManager();
|
||||
|
||||
private:
|
||||
QString XDG_CURRENT_DESKTOP;
|
||||
QString XDG_SESSION_TYPE;
|
||||
QString WAYLAND_DISPLAY;
|
||||
QString KDE_FULL_SESSION;
|
||||
QString GNOME_DESKTOP_SESSION_ID;
|
||||
QString GDMSESSION;
|
||||
QString DESKTOP_SESSION;
|
||||
QString XDG_CURRENT_DESKTOP;
|
||||
QString XDG_SESSION_TYPE;
|
||||
QString WAYLAND_DISPLAY;
|
||||
QString KDE_FULL_SESSION;
|
||||
QString GNOME_DESKTOP_SESSION_ID;
|
||||
QString GDMSESSION;
|
||||
QString DESKTOP_SESSION;
|
||||
};
|
||||
|
||||
@@ -25,106 +25,98 @@
|
||||
FileNameHandler::FileNameHandler(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
std::locale::global(std::locale(""));
|
||||
std::locale::global(std::locale(""));
|
||||
}
|
||||
|
||||
QString
|
||||
FileNameHandler::parsedPattern()
|
||||
QString FileNameHandler::parsedPattern()
|
||||
{
|
||||
return parseFilename(ConfigHandler().filenamePatternValue());
|
||||
return parseFilename(ConfigHandler().filenamePatternValue());
|
||||
}
|
||||
|
||||
QString
|
||||
FileNameHandler::parseFilename(const QString& name)
|
||||
QString FileNameHandler::parseFilename(const QString& name)
|
||||
{
|
||||
QString res = name;
|
||||
if (name.isEmpty()) {
|
||||
res = QLatin1String("%F_%H-%M");
|
||||
}
|
||||
std::time_t t = std::time(NULL);
|
||||
QString res = name;
|
||||
if (name.isEmpty()) {
|
||||
res = QLatin1String("%F_%H-%M");
|
||||
}
|
||||
std::time_t t = std::time(NULL);
|
||||
|
||||
char* tempData = QStringTocharArr(res);
|
||||
char data[MAX_CHARACTERS] = { 0 };
|
||||
std::strftime(data, sizeof(data), tempData, std::localtime(&t));
|
||||
res = QString::fromLocal8Bit(data, (int)strlen(data));
|
||||
free(tempData);
|
||||
char* tempData = QStringTocharArr(res);
|
||||
char data[MAX_CHARACTERS] = { 0 };
|
||||
std::strftime(data, sizeof(data), tempData, std::localtime(&t));
|
||||
res = QString::fromLocal8Bit(data, (int)strlen(data));
|
||||
free(tempData);
|
||||
|
||||
// add the parsed pattern in a correct format for the filesystem
|
||||
res = res.replace(QLatin1String("/"), QStringLiteral("⁄"))
|
||||
.replace(QLatin1String(":"), QLatin1String("-"));
|
||||
return res;
|
||||
// add the parsed pattern in a correct format for the filesystem
|
||||
res = res.replace(QLatin1String("/"), QStringLiteral("⁄"))
|
||||
.replace(QLatin1String(":"), QLatin1String("-"));
|
||||
return res;
|
||||
}
|
||||
|
||||
QString
|
||||
FileNameHandler::generateAbsolutePath(const QString& path)
|
||||
QString FileNameHandler::generateAbsolutePath(const QString& path)
|
||||
{
|
||||
QString directory = path;
|
||||
QString filename = parsedPattern();
|
||||
fixPath(directory, filename);
|
||||
return directory + filename;
|
||||
QString directory = path;
|
||||
QString filename = parsedPattern();
|
||||
fixPath(directory, filename);
|
||||
return directory + filename;
|
||||
}
|
||||
// path a images si no existe, add numeration
|
||||
void
|
||||
FileNameHandler::setPattern(const QString& pattern)
|
||||
void FileNameHandler::setPattern(const QString& pattern)
|
||||
{
|
||||
ConfigHandler().setFilenamePattern(pattern);
|
||||
ConfigHandler().setFilenamePattern(pattern);
|
||||
}
|
||||
|
||||
QString
|
||||
FileNameHandler::absoluteSavePath(QString& directory, QString& filename)
|
||||
QString FileNameHandler::absoluteSavePath(QString& directory, QString& filename)
|
||||
{
|
||||
ConfigHandler config;
|
||||
directory = config.savePathValue();
|
||||
if (directory.isEmpty() || !QDir(directory).exists() ||
|
||||
!QFileInfo(directory).isWritable()) {
|
||||
directory =
|
||||
QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
|
||||
}
|
||||
filename = parsedPattern();
|
||||
fixPath(directory, filename);
|
||||
return directory + filename;
|
||||
}
|
||||
|
||||
QString
|
||||
FileNameHandler::absoluteSavePath()
|
||||
{
|
||||
QString dir, file;
|
||||
return absoluteSavePath(dir, file);
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
void
|
||||
FileNameHandler::fixPath(QString& directory, QString& filename)
|
||||
{
|
||||
// add '/' at the end of the directory
|
||||
if (!directory.endsWith(QLatin1String("/"))) {
|
||||
directory += QLatin1String("/");
|
||||
}
|
||||
// add numeration in case of repeated filename in the directory
|
||||
// find unused name adding _n where n is a number
|
||||
QFileInfo checkFile(directory + filename + ".png");
|
||||
if (checkFile.exists()) {
|
||||
filename += QLatin1String("_");
|
||||
int i = 1;
|
||||
while (true) {
|
||||
checkFile.setFile(directory + filename + QString::number(i) + ".png");
|
||||
if (!checkFile.exists()) {
|
||||
filename += QString::number(i);
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
ConfigHandler config;
|
||||
directory = config.savePathValue();
|
||||
if (directory.isEmpty() || !QDir(directory).exists() ||
|
||||
!QFileInfo(directory).isWritable()) {
|
||||
directory =
|
||||
QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
|
||||
}
|
||||
filename = parsedPattern();
|
||||
fixPath(directory, filename);
|
||||
return directory + filename;
|
||||
}
|
||||
|
||||
QString FileNameHandler::absoluteSavePath()
|
||||
{
|
||||
QString dir, file;
|
||||
return absoluteSavePath(dir, file);
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
void FileNameHandler::fixPath(QString& directory, QString& filename)
|
||||
{
|
||||
// add '/' at the end of the directory
|
||||
if (!directory.endsWith(QLatin1String("/"))) {
|
||||
directory += QLatin1String("/");
|
||||
}
|
||||
// add numeration in case of repeated filename in the directory
|
||||
// find unused name adding _n where n is a number
|
||||
QFileInfo checkFile(directory + filename + ".png");
|
||||
if (checkFile.exists()) {
|
||||
filename += QLatin1String("_");
|
||||
int i = 1;
|
||||
while (true) {
|
||||
checkFile.setFile(directory + filename + QString::number(i) +
|
||||
".png");
|
||||
if (!checkFile.exists()) {
|
||||
filename += QString::number(i);
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,25 +21,25 @@
|
||||
|
||||
class FileNameHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FileNameHandler(QObject* parent = nullptr);
|
||||
explicit FileNameHandler(QObject* parent = nullptr);
|
||||
|
||||
QString parsedPattern();
|
||||
QString parseFilename(const QString& name);
|
||||
QString generateAbsolutePath(const QString& path);
|
||||
QString absoluteSavePath(QString& directory, QString& filename);
|
||||
QString absoluteSavePath();
|
||||
QString parsedPattern();
|
||||
QString parseFilename(const QString& name);
|
||||
QString generateAbsolutePath(const QString& path);
|
||||
QString absoluteSavePath(QString& directory, QString& filename);
|
||||
QString absoluteSavePath();
|
||||
|
||||
static const int MAX_CHARACTERS = 70;
|
||||
static const int MAX_CHARACTERS = 70;
|
||||
|
||||
public slots:
|
||||
void setPattern(const QString& pattern);
|
||||
void setPattern(const QString& pattern);
|
||||
|
||||
private:
|
||||
// using charArr = char[MAX_CHARACTERS];
|
||||
QString charArrToQString(const char* c);
|
||||
char* QStringTocharArr(const QString& s);
|
||||
// using charArr = char[MAX_CHARACTERS];
|
||||
QString charArrToQString(const char* c);
|
||||
char* QStringTocharArr(const QString& s);
|
||||
|
||||
void fixPath(QString& directory, QString& filename);
|
||||
void fixPath(QString& directory, QString& filename);
|
||||
};
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
#include <QApplication>
|
||||
#include <QFontMetrics>
|
||||
|
||||
int
|
||||
GlobalValues::buttonBaseSize()
|
||||
int GlobalValues::buttonBaseSize()
|
||||
{
|
||||
return QApplication::fontMetrics().lineSpacing() * 2.2;
|
||||
return QApplication::fontMetrics().lineSpacing() * 2.2;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
namespace GlobalValues {
|
||||
|
||||
int
|
||||
buttonBaseSize();
|
||||
int buttonBaseSize();
|
||||
|
||||
}
|
||||
|
||||
@@ -20,29 +20,27 @@
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
const QString
|
||||
PathInfo::whiteIconPath()
|
||||
const QString PathInfo::whiteIconPath()
|
||||
{
|
||||
return QStringLiteral(":/img/material/white/");
|
||||
return QStringLiteral(":/img/material/white/");
|
||||
}
|
||||
|
||||
const QString
|
||||
PathInfo::blackIconPath()
|
||||
const QString PathInfo::blackIconPath()
|
||||
{
|
||||
return QStringLiteral(":/img/material/black/");
|
||||
return QStringLiteral(":/img/material/black/");
|
||||
}
|
||||
|
||||
QStringList
|
||||
PathInfo::translationsPaths()
|
||||
QStringList PathInfo::translationsPaths()
|
||||
{
|
||||
QString binaryPath = QFileInfo(qApp->applicationDirPath()).absoluteFilePath();
|
||||
QString trPath = QDir::toNativeSeparators(binaryPath + "/translations");
|
||||
QString binaryPath =
|
||||
QFileInfo(qApp->applicationDirPath()).absoluteFilePath();
|
||||
QString trPath = QDir::toNativeSeparators(binaryPath + "/translations");
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
return QStringList()
|
||||
<< QStringLiteral(APP_PREFIX) + "/share/flameshot/translations"
|
||||
<< trPath << QStringLiteral("/usr/share/flameshot/translations")
|
||||
<< QStringLiteral("/usr/local/share/flameshot/translations");
|
||||
return QStringList()
|
||||
<< QStringLiteral(APP_PREFIX) + "/share/flameshot/translations"
|
||||
<< trPath << QStringLiteral("/usr/share/flameshot/translations")
|
||||
<< QStringLiteral("/usr/local/share/flameshot/translations");
|
||||
#elif defined(Q_OS_WIN)
|
||||
return QStringList() << trPath;
|
||||
return QStringList() << trPath;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -21,13 +21,10 @@
|
||||
|
||||
namespace PathInfo { // namespace
|
||||
|
||||
const QString
|
||||
whiteIconPath();
|
||||
const QString whiteIconPath();
|
||||
|
||||
const QString
|
||||
blackIconPath();
|
||||
const QString blackIconPath();
|
||||
|
||||
QStringList
|
||||
translationsPaths();
|
||||
QStringList translationsPaths();
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -34,101 +34,102 @@ ScreenGrabber::ScreenGrabber(QObject* parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
QPixmap
|
||||
ScreenGrabber::grabEntireDesktop(bool& ok)
|
||||
QPixmap ScreenGrabber::grabEntireDesktop(bool& ok)
|
||||
{
|
||||
ok = true;
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
if (m_info.waylandDectected()) {
|
||||
QPixmap res;
|
||||
// handle screenshot based on DE
|
||||
switch (m_info.windowManager()) {
|
||||
case DesktopInfo::GNOME: {
|
||||
// https://github.com/GNOME/gnome-shell/blob/695bfb96160033be55cfb5ac41c121998f98c328/data/org.gnome.Shell.Screenshot.xml
|
||||
QString path =
|
||||
FileNameHandler().generateAbsolutePath(QDir::tempPath()) + ".png";
|
||||
QDBusInterface gnomeInterface(
|
||||
QStringLiteral("org.gnome.Shell"),
|
||||
QStringLiteral("/org/gnome/Shell/Screenshot"),
|
||||
QStringLiteral("org.gnome.Shell.Screenshot"));
|
||||
QDBusReply<bool> reply =
|
||||
gnomeInterface.call(QStringLiteral("Screenshot"), false, false, path);
|
||||
if (reply.value()) {
|
||||
res = QPixmap(path);
|
||||
QFile dbusResult(path);
|
||||
dbusResult.remove();
|
||||
} else {
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DesktopInfo::KDE: {
|
||||
// https://github.com/KDE/spectacle/blob/517a7baf46a4ca0a45f32fd3f2b1b7210b180134/src/PlatformBackends/KWinWaylandImageGrabber.cpp#L145
|
||||
QDBusInterface kwinInterface(QStringLiteral("org.kde.KWin"),
|
||||
QStringLiteral("/Screenshot"),
|
||||
QStringLiteral("org.kde.kwin.Screenshot"));
|
||||
QDBusReply<QString> reply =
|
||||
kwinInterface.call(QStringLiteral("screenshotFullscreen"));
|
||||
res = QPixmap(reply.value());
|
||||
if (!res.isNull()) {
|
||||
QFile dbusResult(reply.value());
|
||||
dbusResult.remove();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
if (!ok) {
|
||||
SystemNotification().sendMessage(tr("Unable to capture screen"));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
QRect geometry;
|
||||
for (QScreen* const screen : QGuiApplication::screens()) {
|
||||
geometry = geometry.united(screen->geometry());
|
||||
}
|
||||
|
||||
QPixmap p(
|
||||
QApplication::primaryScreen()->grabWindow(QApplication::desktop()->winId(),
|
||||
geometry.x(),
|
||||
geometry.y(),
|
||||
geometry.width(),
|
||||
geometry.height()));
|
||||
auto screenNumber = QApplication::desktop()->screenNumber();
|
||||
QScreen* screen = QApplication::screens()[screenNumber];
|
||||
p.setDevicePixelRatio(screen->devicePixelRatio());
|
||||
return p;
|
||||
}
|
||||
|
||||
QPixmap
|
||||
ScreenGrabber::grabScreen(int screenNumber, bool& ok)
|
||||
{
|
||||
QPixmap p;
|
||||
bool isVirtual = QApplication::desktop()->isVirtualDesktop();
|
||||
if (isVirtual || m_info.waylandDectected()) {
|
||||
p = grabEntireDesktop(ok);
|
||||
if (ok) {
|
||||
QPoint topLeft(0, 0);
|
||||
#ifdef Q_OS_WIN
|
||||
for (QScreen* const screen : QGuiApplication::screens()) {
|
||||
QPoint topLeftScreen = screen->geometry().topLeft();
|
||||
if (topLeft.x() > topLeftScreen.x() ||
|
||||
topLeft.y() > topLeftScreen.y()) {
|
||||
topLeft = topLeftScreen;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
QRect geometry = QApplication::desktop()->screenGeometry(screenNumber);
|
||||
geometry.moveTo(geometry.topLeft() - topLeft);
|
||||
p = p.copy(geometry);
|
||||
}
|
||||
} else {
|
||||
p = QApplication::desktop()->screen(screenNumber)->grab();
|
||||
ok = true;
|
||||
}
|
||||
return p;
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
if (m_info.waylandDectected()) {
|
||||
QPixmap res;
|
||||
// handle screenshot based on DE
|
||||
switch (m_info.windowManager()) {
|
||||
case DesktopInfo::GNOME: {
|
||||
// https://github.com/GNOME/gnome-shell/blob/695bfb96160033be55cfb5ac41c121998f98c328/data/org.gnome.Shell.Screenshot.xml
|
||||
QString path =
|
||||
FileNameHandler().generateAbsolutePath(QDir::tempPath()) +
|
||||
".png";
|
||||
QDBusInterface gnomeInterface(
|
||||
QStringLiteral("org.gnome.Shell"),
|
||||
QStringLiteral("/org/gnome/Shell/Screenshot"),
|
||||
QStringLiteral("org.gnome.Shell.Screenshot"));
|
||||
QDBusReply<bool> reply = gnomeInterface.call(
|
||||
QStringLiteral("Screenshot"), false, false, path);
|
||||
if (reply.value()) {
|
||||
res = QPixmap(path);
|
||||
QFile dbusResult(path);
|
||||
dbusResult.remove();
|
||||
} else {
|
||||
ok = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DesktopInfo::KDE: {
|
||||
// https://github.com/KDE/spectacle/blob/517a7baf46a4ca0a45f32fd3f2b1b7210b180134/src/PlatformBackends/KWinWaylandImageGrabber.cpp#L145
|
||||
QDBusInterface kwinInterface(
|
||||
QStringLiteral("org.kde.KWin"),
|
||||
QStringLiteral("/Screenshot"),
|
||||
QStringLiteral("org.kde.kwin.Screenshot"));
|
||||
QDBusReply<QString> reply =
|
||||
kwinInterface.call(QStringLiteral("screenshotFullscreen"));
|
||||
res = QPixmap(reply.value());
|
||||
if (!res.isNull()) {
|
||||
QFile dbusResult(reply.value());
|
||||
dbusResult.remove();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
if (!ok) {
|
||||
SystemNotification().sendMessage(tr("Unable to capture screen"));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
QRect geometry;
|
||||
for (QScreen* const screen : QGuiApplication::screens()) {
|
||||
geometry = geometry.united(screen->geometry());
|
||||
}
|
||||
|
||||
QPixmap p(QApplication::primaryScreen()->grabWindow(
|
||||
QApplication::desktop()->winId(),
|
||||
geometry.x(),
|
||||
geometry.y(),
|
||||
geometry.width(),
|
||||
geometry.height()));
|
||||
auto screenNumber = QApplication::desktop()->screenNumber();
|
||||
QScreen* screen = QApplication::screens()[screenNumber];
|
||||
p.setDevicePixelRatio(screen->devicePixelRatio());
|
||||
return p;
|
||||
}
|
||||
|
||||
QPixmap ScreenGrabber::grabScreen(int screenNumber, bool& ok)
|
||||
{
|
||||
QPixmap p;
|
||||
bool isVirtual = QApplication::desktop()->isVirtualDesktop();
|
||||
if (isVirtual || m_info.waylandDectected()) {
|
||||
p = grabEntireDesktop(ok);
|
||||
if (ok) {
|
||||
QPoint topLeft(0, 0);
|
||||
#ifdef Q_OS_WIN
|
||||
for (QScreen* const screen : QGuiApplication::screens()) {
|
||||
QPoint topLeftScreen = screen->geometry().topLeft();
|
||||
if (topLeft.x() > topLeftScreen.x() ||
|
||||
topLeft.y() > topLeftScreen.y()) {
|
||||
topLeft = topLeftScreen;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
QRect geometry =
|
||||
QApplication::desktop()->screenGeometry(screenNumber);
|
||||
geometry.moveTo(geometry.topLeft() - topLeft);
|
||||
p = p.copy(geometry);
|
||||
}
|
||||
} else {
|
||||
p = QApplication::desktop()->screen(screenNumber)->grab();
|
||||
ok = true;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
|
||||
class ScreenGrabber : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScreenGrabber(QObject* parent = nullptr);
|
||||
QPixmap grabEntireDesktop(bool& ok);
|
||||
QPixmap grabScreen(int screenNumber, bool& ok);
|
||||
explicit ScreenGrabber(QObject* parent = nullptr);
|
||||
QPixmap grabEntireDesktop(bool& ok);
|
||||
QPixmap grabScreen(int screenNumber, bool& ok);
|
||||
|
||||
private:
|
||||
DesktopInfo m_info;
|
||||
DesktopInfo m_info;
|
||||
};
|
||||
|
||||
@@ -29,90 +29,88 @@ ScreenshotSaver::ScreenshotSaver() {}
|
||||
|
||||
// TODO: If data is saved to the clipboard before the notification is sent via
|
||||
// dbus, the application freezes.
|
||||
void
|
||||
ScreenshotSaver::saveToClipboard(const QPixmap& capture)
|
||||
void ScreenshotSaver::saveToClipboard(const QPixmap& capture)
|
||||
{
|
||||
|
||||
// If we are able to properly save the file, save the file and copy to
|
||||
// clipboard.
|
||||
if ((ConfigHandler().saveAfterCopyValue()) &&
|
||||
(!ConfigHandler().saveAfterCopyPathValue().isEmpty())) {
|
||||
saveToFilesystem(capture,
|
||||
ConfigHandler().saveAfterCopyPathValue(),
|
||||
QObject::tr("Capture saved to clipboard."));
|
||||
QApplication::clipboard()->setPixmap(capture);
|
||||
}
|
||||
// Otherwise only save to clipboard
|
||||
else {
|
||||
SystemNotification().sendMessage(QObject::tr("Capture saved to clipboard"));
|
||||
QApplication::clipboard()->setPixmap(capture);
|
||||
}
|
||||
// If we are able to properly save the file, save the file and copy to
|
||||
// clipboard.
|
||||
if ((ConfigHandler().saveAfterCopyValue()) &&
|
||||
(!ConfigHandler().saveAfterCopyPathValue().isEmpty())) {
|
||||
saveToFilesystem(capture,
|
||||
ConfigHandler().saveAfterCopyPathValue(),
|
||||
QObject::tr("Capture saved to clipboard."));
|
||||
QApplication::clipboard()->setPixmap(capture);
|
||||
}
|
||||
// Otherwise only save to clipboard
|
||||
else {
|
||||
SystemNotification().sendMessage(
|
||||
QObject::tr("Capture saved to clipboard"));
|
||||
QApplication::clipboard()->setPixmap(capture);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ScreenshotSaver::saveToFilesystem(const QPixmap& capture,
|
||||
const QString& path,
|
||||
const QString& messagePrefix)
|
||||
bool ScreenshotSaver::saveToFilesystem(const QPixmap& capture,
|
||||
const QString& path,
|
||||
const QString& messagePrefix)
|
||||
{
|
||||
QString completePath = FileNameHandler().generateAbsolutePath(path);
|
||||
completePath += QLatin1String(".png");
|
||||
bool ok = capture.save(completePath);
|
||||
QString saveMessage;
|
||||
QString notificationPath = completePath;
|
||||
|
||||
if (ok) {
|
||||
ConfigHandler().setSavePath(path);
|
||||
saveMessage =
|
||||
messagePrefix + QObject::tr("Capture saved as ") + completePath;
|
||||
} else {
|
||||
saveMessage =
|
||||
messagePrefix + QObject::tr("Error trying to save as ") + completePath;
|
||||
notificationPath = "";
|
||||
}
|
||||
|
||||
SystemNotification().sendMessage(saveMessage, notificationPath);
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool
|
||||
ScreenshotSaver::saveToFilesystemGUI(const QPixmap& capture)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
while (!ok) {
|
||||
QString savePath = QFileDialog::getSaveFileName(
|
||||
nullptr,
|
||||
QString(),
|
||||
FileNameHandler().absoluteSavePath() + ".png",
|
||||
QLatin1String("Portable Network Graphic file (PNG) (*.png);;BMP file "
|
||||
"(*.bmp);;JPEG file (*.jpg)"));
|
||||
|
||||
if (savePath.isNull()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!savePath.endsWith(QLatin1String(".png"), Qt::CaseInsensitive) &&
|
||||
!savePath.endsWith(QLatin1String(".bmp"), Qt::CaseInsensitive) &&
|
||||
!savePath.endsWith(QLatin1String(".jpg"), Qt::CaseInsensitive)) {
|
||||
|
||||
savePath += QLatin1String(".png");
|
||||
}
|
||||
|
||||
ok = capture.save(savePath);
|
||||
QString completePath = FileNameHandler().generateAbsolutePath(path);
|
||||
completePath += QLatin1String(".png");
|
||||
bool ok = capture.save(completePath);
|
||||
QString saveMessage;
|
||||
QString notificationPath = completePath;
|
||||
|
||||
if (ok) {
|
||||
QString pathNoFile =
|
||||
savePath.left(savePath.lastIndexOf(QLatin1String("/")));
|
||||
ConfigHandler().setSavePath(pathNoFile);
|
||||
QString msg = QObject::tr("Capture saved as ") + savePath;
|
||||
SystemNotification().sendMessage(msg, savePath);
|
||||
ConfigHandler().setSavePath(path);
|
||||
saveMessage =
|
||||
messagePrefix + QObject::tr("Capture saved as ") + completePath;
|
||||
} else {
|
||||
QString msg = QObject::tr("Error trying to save as ") + savePath;
|
||||
QMessageBox saveErrBox(
|
||||
QMessageBox::Warning, QObject::tr("Save Error"), msg);
|
||||
saveErrBox.setWindowIcon(QIcon(":img/app/flameshot.svg"));
|
||||
saveErrBox.exec();
|
||||
saveMessage = messagePrefix + QObject::tr("Error trying to save as ") +
|
||||
completePath;
|
||||
notificationPath = "";
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
|
||||
SystemNotification().sendMessage(saveMessage, notificationPath);
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap& capture)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
while (!ok) {
|
||||
QString savePath = QFileDialog::getSaveFileName(
|
||||
nullptr,
|
||||
QString(),
|
||||
FileNameHandler().absoluteSavePath() + ".png",
|
||||
QLatin1String("Portable Network Graphic file (PNG) (*.png);;BMP file "
|
||||
"(*.bmp);;JPEG file (*.jpg)"));
|
||||
|
||||
if (savePath.isNull()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!savePath.endsWith(QLatin1String(".png"), Qt::CaseInsensitive) &&
|
||||
!savePath.endsWith(QLatin1String(".bmp"), Qt::CaseInsensitive) &&
|
||||
!savePath.endsWith(QLatin1String(".jpg"), Qt::CaseInsensitive)) {
|
||||
|
||||
savePath += QLatin1String(".png");
|
||||
}
|
||||
|
||||
ok = capture.save(savePath);
|
||||
|
||||
if (ok) {
|
||||
QString pathNoFile =
|
||||
savePath.left(savePath.lastIndexOf(QLatin1String("/")));
|
||||
ConfigHandler().setSavePath(pathNoFile);
|
||||
QString msg = QObject::tr("Capture saved as ") + savePath;
|
||||
SystemNotification().sendMessage(msg, savePath);
|
||||
} else {
|
||||
QString msg = QObject::tr("Error trying to save as ") + savePath;
|
||||
QMessageBox saveErrBox(
|
||||
QMessageBox::Warning, QObject::tr("Save Error"), msg);
|
||||
saveErrBox.setWindowIcon(QIcon(":img/app/flameshot.svg"));
|
||||
saveErrBox.exec();
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ class QString;
|
||||
class ScreenshotSaver
|
||||
{
|
||||
public:
|
||||
ScreenshotSaver();
|
||||
ScreenshotSaver();
|
||||
|
||||
void saveToClipboard(const QPixmap& capture);
|
||||
bool saveToFilesystem(const QPixmap& capture,
|
||||
const QString& path,
|
||||
const QString& messagePrefix);
|
||||
bool saveToFilesystemGUI(const QPixmap& capture);
|
||||
void saveToClipboard(const QPixmap& capture);
|
||||
bool saveToFilesystem(const QPixmap& capture,
|
||||
const QString& path,
|
||||
const QString& messagePrefix);
|
||||
bool saveToFilesystemGUI(const QPixmap& capture);
|
||||
};
|
||||
|
||||
@@ -15,58 +15,57 @@
|
||||
SystemNotification::SystemNotification(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_interface =
|
||||
new QDBusInterface(QStringLiteral("org.freedesktop.Notifications"),
|
||||
QStringLiteral("/org/freedesktop/Notifications"),
|
||||
QStringLiteral("org.freedesktop.Notifications"),
|
||||
QDBusConnection::sessionBus(),
|
||||
this);
|
||||
m_interface =
|
||||
new QDBusInterface(QStringLiteral("org.freedesktop.Notifications"),
|
||||
QStringLiteral("/org/freedesktop/Notifications"),
|
||||
QStringLiteral("org.freedesktop.Notifications"),
|
||||
QDBusConnection::sessionBus(),
|
||||
this);
|
||||
}
|
||||
#else
|
||||
SystemNotification::SystemNotification(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_interface = nullptr;
|
||||
m_interface = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
SystemNotification::sendMessage(const QString& text, const QString& savePath)
|
||||
void SystemNotification::sendMessage(const QString& text,
|
||||
const QString& savePath)
|
||||
{
|
||||
sendMessage(text, tr("Flameshot Info"), savePath);
|
||||
sendMessage(text, tr("Flameshot Info"), savePath);
|
||||
}
|
||||
|
||||
void
|
||||
SystemNotification::sendMessage(const QString& text,
|
||||
const QString& title,
|
||||
const QString& savePath,
|
||||
const int timeout)
|
||||
void SystemNotification::sendMessage(const QString& text,
|
||||
const QString& title,
|
||||
const QString& savePath,
|
||||
const int timeout)
|
||||
{
|
||||
if (!ConfigHandler().desktopNotificationValue()) {
|
||||
return;
|
||||
}
|
||||
if (!ConfigHandler().desktopNotificationValue()) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef Q_OS_WIN
|
||||
QList<QVariant> args;
|
||||
QVariantMap hintsMap;
|
||||
if (!savePath.isEmpty()) {
|
||||
QUrl fullPath = QUrl::fromLocalFile(savePath);
|
||||
// allows the notification to be dragged and dropped
|
||||
hintsMap[QStringLiteral("x-kde-urls")] =
|
||||
QStringList({ fullPath.toString() });
|
||||
}
|
||||
args << (qAppName()) // appname
|
||||
<< static_cast<unsigned int>(0) // id
|
||||
<< "flameshot" // icon
|
||||
<< title // summary
|
||||
<< text // body
|
||||
<< QStringList() // actions
|
||||
<< hintsMap // hints
|
||||
<< timeout; // timeout
|
||||
m_interface->callWithArgumentList(
|
||||
QDBus::AutoDetect, QStringLiteral("Notify"), args);
|
||||
QList<QVariant> args;
|
||||
QVariantMap hintsMap;
|
||||
if (!savePath.isEmpty()) {
|
||||
QUrl fullPath = QUrl::fromLocalFile(savePath);
|
||||
// allows the notification to be dragged and dropped
|
||||
hintsMap[QStringLiteral("x-kde-urls")] =
|
||||
QStringList({ fullPath.toString() });
|
||||
}
|
||||
args << (qAppName()) // appname
|
||||
<< static_cast<unsigned int>(0) // id
|
||||
<< "flameshot" // icon
|
||||
<< title // summary
|
||||
<< text // body
|
||||
<< QStringList() // actions
|
||||
<< hintsMap // hints
|
||||
<< timeout; // timeout
|
||||
m_interface->callWithArgumentList(
|
||||
QDBus::AutoDetect, QStringLiteral("Notify"), args);
|
||||
#else
|
||||
auto c = Controller::getInstance();
|
||||
c->sendTrayNotification(text, title, timeout);
|
||||
auto c = Controller::getInstance();
|
||||
c->sendTrayNotification(text, title, timeout);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -23,17 +23,17 @@ class QDBusInterface;
|
||||
|
||||
class SystemNotification : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SystemNotification(QObject* parent = nullptr);
|
||||
explicit SystemNotification(QObject* parent = nullptr);
|
||||
|
||||
void sendMessage(const QString& text, const QString& savePath = {});
|
||||
void sendMessage(const QString& text, const QString& savePath = {});
|
||||
|
||||
void sendMessage(const QString& text,
|
||||
const QString& title,
|
||||
const QString& savePath,
|
||||
const int timeout = 5000);
|
||||
void sendMessage(const QString& text,
|
||||
const QString& title,
|
||||
const QString& savePath,
|
||||
const int timeout = 5000);
|
||||
|
||||
private:
|
||||
QDBusInterface* m_interface;
|
||||
QDBusInterface* m_interface;
|
||||
};
|
||||
|
||||
@@ -2,6 +2,4 @@
|
||||
|
||||
WaylandUtils::WaylandUtils() {}
|
||||
|
||||
bool
|
||||
WaylandUtils::waylandDetected()
|
||||
{}
|
||||
bool WaylandUtils::waylandDetected() {}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
class WaylandUtils
|
||||
{
|
||||
public:
|
||||
WaylandUtils();
|
||||
WaylandUtils();
|
||||
|
||||
static bool waylandDetected();
|
||||
static bool waylandDetected();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user