reformatted to Mozilla code style
This commit is contained in:
committed by
borgmanJeremy
parent
c0e2e48db4
commit
c8d15205be
@@ -17,23 +17,28 @@
|
||||
|
||||
#include "colorutils.h"
|
||||
|
||||
inline qreal getColorLuma(const QColor &c) {
|
||||
return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF();
|
||||
inline qreal
|
||||
getColorLuma(const QColor& c)
|
||||
{
|
||||
return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF();
|
||||
}
|
||||
|
||||
bool ColorUtils::colorIsDark(const QColor &c) {
|
||||
bool isWhite = false;
|
||||
if (getColorLuma(c) <= 0.60) {
|
||||
isWhite = true;
|
||||
}
|
||||
return isWhite;
|
||||
bool
|
||||
ColorUtils::colorIsDark(const QColor& c)
|
||||
{
|
||||
bool isWhite = false;
|
||||
if (getColorLuma(c) <= 0.60) {
|
||||
isWhite = true;
|
||||
}
|
||||
return isWhite;
|
||||
}
|
||||
|
||||
QColor ColorUtils::contrastColor(const QColor &c) {
|
||||
int change = colorIsDark(c) ? 30 : -45;
|
||||
QColor
|
||||
ColorUtils::contrastColor(const QColor& c)
|
||||
{
|
||||
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,8 +21,10 @@
|
||||
|
||||
namespace ColorUtils { // namespace
|
||||
|
||||
bool colorIsDark(const QColor &c);
|
||||
bool
|
||||
colorIsDark(const QColor& c);
|
||||
|
||||
QColor contrastColor(const QColor &c);
|
||||
QColor
|
||||
contrastColor(const QColor& c);
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -16,372 +16,438 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "confighandler.h"
|
||||
#include <algorithm>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <algorithm>
|
||||
|
||||
ConfigHandler::ConfigHandler(){
|
||||
m_settings.setDefaultFormat(QSettings::IniFormat);
|
||||
ConfigHandler::ConfigHandler()
|
||||
{
|
||||
m_settings.setDefaultFormat(QSettings::IniFormat);
|
||||
}
|
||||
|
||||
QVector<CaptureButton::ButtonType> ConfigHandler::getButtons() {
|
||||
QVector<CaptureButton::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 << CaptureButton::TYPE_PENCIL
|
||||
<< CaptureButton::TYPE_DRAWER
|
||||
<< CaptureButton::TYPE_ARROW
|
||||
<< CaptureButton::TYPE_SELECTION
|
||||
<< CaptureButton::TYPE_RECTANGLE
|
||||
<< CaptureButton::TYPE_CIRCLE
|
||||
<< CaptureButton::TYPE_MARKER
|
||||
<< CaptureButton::TYPE_BLUR
|
||||
<< CaptureButton::TYPE_SELECTIONINDICATOR
|
||||
<< CaptureButton::TYPE_MOVESELECTION
|
||||
<< CaptureButton::TYPE_UNDO
|
||||
<< CaptureButton::TYPE_REDO
|
||||
<< CaptureButton::TYPE_COPY
|
||||
<< CaptureButton::TYPE_SAVE
|
||||
<< CaptureButton::TYPE_EXIT
|
||||
<< CaptureButton::TYPE_IMAGEUPLOADER
|
||||
<< CaptureButton::TYPE_OPEN_APP
|
||||
<< CaptureButton::TYPE_PIN
|
||||
<< CaptureButton::TYPE_TEXT
|
||||
<< CaptureButton::TYPE_CIRCLECOUNT;
|
||||
}
|
||||
|
||||
using bt = CaptureButton::ButtonType;
|
||||
std::sort(buttons.begin(), buttons.end(), [](bt a, bt b){
|
||||
return CaptureButton::getPriorityByButton(a) <
|
||||
CaptureButton::getPriorityByButton(b);
|
||||
});
|
||||
return buttons;
|
||||
}
|
||||
|
||||
void ConfigHandler::setButtons(const QVector<CaptureButton::ButtonType> &buttons) {
|
||||
QVector<int> l = fromButtonToInt(buttons);
|
||||
normalizeButtons(l);
|
||||
QVector<CaptureButton::ButtonType>
|
||||
ConfigHandler::getButtons()
|
||||
{
|
||||
QVector<CaptureButton::ButtonType> buttons;
|
||||
if (m_settings.contains(QStringLiteral("buttons"))) {
|
||||
// TODO: remove toList in v1.0
|
||||
m_settings.setValue(QStringLiteral("buttons"), QVariant::fromValue(l.toList()));
|
||||
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 << CaptureButton::TYPE_PENCIL << CaptureButton::TYPE_DRAWER
|
||||
<< CaptureButton::TYPE_ARROW << CaptureButton::TYPE_SELECTION
|
||||
<< CaptureButton::TYPE_RECTANGLE << CaptureButton::TYPE_CIRCLE
|
||||
<< CaptureButton::TYPE_MARKER << CaptureButton::TYPE_BLUR
|
||||
<< CaptureButton::TYPE_SELECTIONINDICATOR
|
||||
<< CaptureButton::TYPE_MOVESELECTION << CaptureButton::TYPE_UNDO
|
||||
<< CaptureButton::TYPE_REDO << CaptureButton::TYPE_COPY
|
||||
<< CaptureButton::TYPE_SAVE << CaptureButton::TYPE_EXIT
|
||||
<< CaptureButton::TYPE_IMAGEUPLOADER << CaptureButton::TYPE_OPEN_APP
|
||||
<< CaptureButton::TYPE_PIN << CaptureButton::TYPE_TEXT
|
||||
<< CaptureButton::TYPE_CIRCLECOUNT;
|
||||
}
|
||||
|
||||
using bt = CaptureButton::ButtonType;
|
||||
std::sort(buttons.begin(), buttons.end(), [](bt a, bt b) {
|
||||
return CaptureButton::getPriorityByButton(a) <
|
||||
CaptureButton::getPriorityByButton(b);
|
||||
});
|
||||
return buttons;
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
void
|
||||
ConfigHandler::setButtons(const QVector<CaptureButton::ButtonType>& buttons)
|
||||
{
|
||||
QVector<int> l = fromButtonToInt(buttons);
|
||||
normalizeButtons(l);
|
||||
// TODO: remove toList in v1.0
|
||||
m_settings.setValue(QStringLiteral("buttons"),
|
||||
QVariant::fromValue(l.toList()));
|
||||
}
|
||||
|
||||
if (m_settings.contains(QStringLiteral("userColors"))) {
|
||||
for (const QString &hex : m_settings.value(QStringLiteral("userColors")).toStringList()) {
|
||||
if (QColor::isValidColor(hex)) {
|
||||
colors.append(QColor(hex));
|
||||
}
|
||||
}
|
||||
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 (colors.isEmpty()) {
|
||||
colors = defaultColors;
|
||||
}
|
||||
} else {
|
||||
colors = defaultColors;
|
||||
if (m_settings.contains(QStringLiteral("userColors"))) {
|
||||
for (const QString& hex :
|
||||
m_settings.value(QStringLiteral("userColors")).toStringList()) {
|
||||
if (QColor::isValidColor(hex)) {
|
||||
colors.append(QColor(hex));
|
||||
}
|
||||
}
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
void ConfigHandler::setUserColors(const QVector<QColor> &l) {
|
||||
QStringList hexColors;
|
||||
|
||||
for (const QColor &color : l) {
|
||||
hexColors.append(color.name());
|
||||
if (colors.isEmpty()) {
|
||||
colors = defaultColors;
|
||||
}
|
||||
} else {
|
||||
colors = defaultColors;
|
||||
}
|
||||
|
||||
m_settings.setValue(QStringLiteral("userColors"), QVariant::fromValue(hexColors));
|
||||
return colors;
|
||||
}
|
||||
|
||||
QString ConfigHandler::savePathValue() {
|
||||
return m_settings.value(QStringLiteral("savePath")).toString();
|
||||
void
|
||||
ConfigHandler::setUserColors(const QVector<QColor>& l)
|
||||
{
|
||||
QStringList hexColors;
|
||||
|
||||
for (const QColor& color : l) {
|
||||
hexColors.append(color.name());
|
||||
}
|
||||
|
||||
m_settings.setValue(QStringLiteral("userColors"),
|
||||
QVariant::fromValue(hexColors));
|
||||
}
|
||||
|
||||
void ConfigHandler::setSavePath(const QString &savePath) {
|
||||
m_settings.setValue(QStringLiteral("savePath"), savePath);
|
||||
QString
|
||||
ConfigHandler::savePathValue()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("savePath")).toString();
|
||||
}
|
||||
|
||||
QColor ConfigHandler::uiMainColorValue() {
|
||||
QColor res = QColor(116, 0, 150);
|
||||
void
|
||||
ConfigHandler::setSavePath(const QString& savePath)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("savePath"), savePath);
|
||||
}
|
||||
|
||||
if (m_settings.contains(QStringLiteral("uiColor"))) {
|
||||
QString hex = m_settings.value(QStringLiteral("uiColor")).toString();
|
||||
QColor
|
||||
ConfigHandler::uiMainColorValue()
|
||||
{
|
||||
QColor res = QColor(116, 0, 150);
|
||||
|
||||
if (QColor::isValidColor(hex)) {
|
||||
res = QColor(hex);
|
||||
}
|
||||
if (m_settings.contains(QStringLiteral("uiColor"))) {
|
||||
QString hex = m_settings.value(QStringLiteral("uiColor")).toString();
|
||||
|
||||
if (QColor::isValidColor(hex)) {
|
||||
res = QColor(hex);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setUIMainColor(const QColor &c) {
|
||||
m_settings.setValue(QStringLiteral("uiColor"), c.name());
|
||||
void
|
||||
ConfigHandler::setUIMainColor(const QColor& c)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("uiColor"), c.name());
|
||||
}
|
||||
|
||||
QColor ConfigHandler::uiContrastColorValue() {
|
||||
QColor res = QColor(86, 0, 120);
|
||||
QColor
|
||||
ConfigHandler::uiContrastColorValue()
|
||||
{
|
||||
QColor res = QColor(86, 0, 120);
|
||||
|
||||
if (m_settings.contains(QStringLiteral("contastUiColor"))) {
|
||||
QString hex = m_settings.value(QStringLiteral("contastUiColor")).toString();
|
||||
if (m_settings.contains(QStringLiteral("contastUiColor"))) {
|
||||
QString hex = m_settings.value(QStringLiteral("contastUiColor")).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) {
|
||||
m_settings.setValue(QStringLiteral("contastUiColor"), c.name());
|
||||
void
|
||||
ConfigHandler::setUIContrastColor(const QColor& c)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("contastUiColor"), c.name());
|
||||
}
|
||||
|
||||
QColor ConfigHandler::drawColorValue() {
|
||||
QColor res(Qt::red);
|
||||
QColor
|
||||
ConfigHandler::drawColorValue()
|
||||
{
|
||||
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) {
|
||||
m_settings.setValue(QStringLiteral("drawColor"), c.name());
|
||||
void
|
||||
ConfigHandler::setDrawColor(const QColor& c)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("drawColor"), c.name());
|
||||
}
|
||||
|
||||
bool ConfigHandler::showHelpValue() {
|
||||
bool res = true;
|
||||
if (m_settings.contains(QStringLiteral("showHelp"))) {
|
||||
res = m_settings.value(QStringLiteral("showHelp")).toBool();
|
||||
}
|
||||
return res;
|
||||
bool
|
||||
ConfigHandler::showHelpValue()
|
||||
{
|
||||
bool res = true;
|
||||
if (m_settings.contains(QStringLiteral("showHelp"))) {
|
||||
res = m_settings.value(QStringLiteral("showHelp")).toBool();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setShowHelp(const bool showHelp) {
|
||||
m_settings.setValue(QStringLiteral("showHelp"), showHelp);
|
||||
void
|
||||
ConfigHandler::setShowHelp(const bool showHelp)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("showHelp"), showHelp);
|
||||
}
|
||||
|
||||
bool ConfigHandler::desktopNotificationValue() {
|
||||
bool res = true;
|
||||
if (m_settings.contains(QStringLiteral("showDesktopNotification"))) {
|
||||
res = m_settings.value(QStringLiteral("showDesktopNotification")).toBool();
|
||||
}
|
||||
return res;
|
||||
bool
|
||||
ConfigHandler::desktopNotificationValue()
|
||||
{
|
||||
bool res = true;
|
||||
if (m_settings.contains(QStringLiteral("showDesktopNotification"))) {
|
||||
res = m_settings.value(QStringLiteral("showDesktopNotification")).toBool();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setDesktopNotification(const bool showDesktopNotification) {
|
||||
m_settings.setValue(QStringLiteral("showDesktopNotification"), showDesktopNotification);
|
||||
void
|
||||
ConfigHandler::setDesktopNotification(const bool showDesktopNotification)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("showDesktopNotification"),
|
||||
showDesktopNotification);
|
||||
}
|
||||
|
||||
QString ConfigHandler::filenamePatternValue() {
|
||||
return m_settings.value(QStringLiteral("filenamePattern")).toString();
|
||||
QString
|
||||
ConfigHandler::filenamePatternValue()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("filenamePattern")).toString();
|
||||
}
|
||||
|
||||
void ConfigHandler::setFilenamePattern(const QString &pattern) {
|
||||
return m_settings.setValue(QStringLiteral("filenamePattern"), pattern);
|
||||
void
|
||||
ConfigHandler::setFilenamePattern(const QString& pattern)
|
||||
{
|
||||
return m_settings.setValue(QStringLiteral("filenamePattern"), pattern);
|
||||
}
|
||||
|
||||
bool ConfigHandler::disabledTrayIconValue() {
|
||||
bool res = false;
|
||||
if (m_settings.contains(QStringLiteral("disabledTrayIcon"))) {
|
||||
res = m_settings.value(QStringLiteral("disabledTrayIcon")).toBool();
|
||||
}
|
||||
return res;
|
||||
bool
|
||||
ConfigHandler::disabledTrayIconValue()
|
||||
{
|
||||
bool res = false;
|
||||
if (m_settings.contains(QStringLiteral("disabledTrayIcon"))) {
|
||||
res = m_settings.value(QStringLiteral("disabledTrayIcon")).toBool();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon) {
|
||||
m_settings.setValue(QStringLiteral("disabledTrayIcon"), disabledTrayIcon);
|
||||
void
|
||||
ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("disabledTrayIcon"), disabledTrayIcon);
|
||||
}
|
||||
|
||||
int ConfigHandler::drawThicknessValue() {
|
||||
int res = 0;
|
||||
if (m_settings.contains(QStringLiteral("drawThickness"))) {
|
||||
res = m_settings.value(QStringLiteral("drawThickness")).toInt();
|
||||
}
|
||||
return res;
|
||||
int
|
||||
ConfigHandler::drawThicknessValue()
|
||||
{
|
||||
int res = 0;
|
||||
if (m_settings.contains(QStringLiteral("drawThickness"))) {
|
||||
res = m_settings.value(QStringLiteral("drawThickness")).toInt();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setdrawThickness(const int thickness) {
|
||||
m_settings.setValue(QStringLiteral("drawThickness"), thickness);
|
||||
void
|
||||
ConfigHandler::setdrawThickness(const int thickness)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("drawThickness"), thickness);
|
||||
}
|
||||
|
||||
bool ConfigHandler::keepOpenAppLauncherValue() {
|
||||
return m_settings.value(QStringLiteral("keepOpenAppLauncher")).toBool();
|
||||
bool
|
||||
ConfigHandler::keepOpenAppLauncherValue()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("keepOpenAppLauncher")).toBool();
|
||||
}
|
||||
|
||||
void ConfigHandler::setKeepOpenAppLauncher(const bool keepOpen) {
|
||||
m_settings.setValue(QStringLiteral("keepOpenAppLauncher"), keepOpen);
|
||||
void
|
||||
ConfigHandler::setKeepOpenAppLauncher(const bool keepOpen)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("keepOpenAppLauncher"), keepOpen);
|
||||
}
|
||||
|
||||
bool ConfigHandler::startupLaunchValue() {
|
||||
bool res = false;
|
||||
bool
|
||||
ConfigHandler::startupLaunchValue()
|
||||
{
|
||||
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 res = false;
|
||||
bool
|
||||
ConfigHandler::verifyLaunchFile()
|
||||
{
|
||||
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(".");
|
||||
}
|
||||
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();
|
||||
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();
|
||||
}
|
||||
#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");
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
void ConfigHandler::setDefaults() {
|
||||
m_settings.clear();
|
||||
}
|
||||
|
||||
void ConfigHandler::setAllTheButtons() {
|
||||
QVector<int> buttons;
|
||||
auto listTypes = CaptureButton::getIterableButtonTypes();
|
||||
for (const CaptureButton::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 = CaptureButton::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<CaptureButton::ButtonType> ConfigHandler::fromIntToButton(
|
||||
const QVector<int> &l)
|
||||
int
|
||||
ConfigHandler::contrastOpacityValue()
|
||||
{
|
||||
QVector<CaptureButton::ButtonType> buttons;
|
||||
for (auto const i: l)
|
||||
buttons << static_cast<CaptureButton::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<CaptureButton::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);
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setDefaults()
|
||||
{
|
||||
m_settings.clear();
|
||||
}
|
||||
|
||||
void
|
||||
ConfigHandler::setAllTheButtons()
|
||||
{
|
||||
QVector<int> buttons;
|
||||
auto listTypes = CaptureButton::getIterableButtonTypes();
|
||||
for (const CaptureButton::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 = CaptureButton::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<CaptureButton::ButtonType>
|
||||
ConfigHandler::fromIntToButton(const QVector<int>& l)
|
||||
{
|
||||
QVector<CaptureButton::ButtonType> buttons;
|
||||
for (auto const i : l)
|
||||
buttons << static_cast<CaptureButton::ButtonType>(i);
|
||||
return buttons;
|
||||
}
|
||||
|
||||
QVector<int>
|
||||
ConfigHandler::fromButtonToInt(const QVector<CaptureButton::ButtonType>& l)
|
||||
{
|
||||
QVector<int> buttons;
|
||||
for (auto const i : l)
|
||||
buttons << static_cast<int>(i);
|
||||
return buttons;
|
||||
}
|
||||
|
||||
@@ -18,73 +18,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/widgets/capture/capturebutton.h"
|
||||
#include <QVector>
|
||||
#include <QSettings>
|
||||
#include <QVector>
|
||||
|
||||
class ConfigHandler {
|
||||
class ConfigHandler
|
||||
{
|
||||
public:
|
||||
explicit ConfigHandler();
|
||||
explicit ConfigHandler();
|
||||
|
||||
QVector<CaptureButton::ButtonType> getButtons();
|
||||
void setButtons(const QVector<CaptureButton::ButtonType> &);
|
||||
QVector<CaptureButton::ButtonType> getButtons();
|
||||
void setButtons(const QVector<CaptureButton::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 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 copyAndCloseAfterUploadEnabled();
|
||||
void setCopyAndCloseAfterUploadEnabled(const bool);
|
||||
|
||||
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<CaptureButton::ButtonType> fromIntToButton(const QVector<int> &l);
|
||||
QVector<int> fromButtonToInt(const QVector<CaptureButton::ButtonType> &l);
|
||||
QVector<CaptureButton::ButtonType> fromIntToButton(const QVector<int>& l);
|
||||
QVector<int> fromButtonToInt(const QVector<CaptureButton::ButtonType>& l);
|
||||
};
|
||||
|
||||
@@ -18,46 +18,59 @@
|
||||
#include "dbusutils.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include <QApplication>
|
||||
#include <QTextStream>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
DBusUtils::DBusUtils(QObject *parent) : QObject(parent) {
|
||||
DBusUtils::DBusUtils(QObject* parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
void
|
||||
DBusUtils::connectPrintCapture(QDBusConnection& session, uint id)
|
||||
{
|
||||
m_id = id;
|
||||
// captureTaken
|
||||
session.connect(QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("captureTaken"),
|
||||
this,
|
||||
SLOT(captureTaken(uint, QByteArray)));
|
||||
// captureFailed
|
||||
session.connect(QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("captureFailed"),
|
||||
this,
|
||||
SLOT(captureFailed(uint)));
|
||||
}
|
||||
|
||||
void DBusUtils::connectPrintCapture(QDBusConnection &session, uint id) {
|
||||
m_id = id;
|
||||
// captureTaken
|
||||
session.connect(QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"), QLatin1String(""), QStringLiteral("captureTaken"),
|
||||
this,
|
||||
SLOT(captureTaken(uint, QByteArray)));
|
||||
// captureFailed
|
||||
session.connect(QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"), QLatin1String(""), QStringLiteral("captureFailed"),
|
||||
this,
|
||||
SLOT(captureFailed(uint)));
|
||||
void
|
||||
DBusUtils::checkDBusConnection(const QDBusConnection& connection)
|
||||
{
|
||||
if (!connection.isConnected()) {
|
||||
SystemNotification().sendMessage(tr("Unable to connect via DBus"));
|
||||
qApp->exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void DBusUtils::checkDBusConnection(const QDBusConnection &connection) {
|
||||
if (!connection.isConnected()) {
|
||||
SystemNotification().sendMessage(tr("Unable to connect via DBus"));
|
||||
qApp->exit(1);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
void DBusUtils::captureFailed(uint id) {
|
||||
if (m_id == id) {
|
||||
QTextStream(stdout) << "screenshot aborted\n";
|
||||
qApp->exit(1);
|
||||
}
|
||||
void
|
||||
DBusUtils::captureFailed(uint id)
|
||||
{
|
||||
if (m_id == id) {
|
||||
QTextStream(stdout) << "screenshot aborted\n";
|
||||
qApp->exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,19 +21,19 @@
|
||||
#include <QDBusConnection>
|
||||
#include <QObject>
|
||||
|
||||
class DBusUtils : public QObject {
|
||||
Q_OBJECT
|
||||
class DBusUtils : public QObject
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -16,137 +16,134 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "desktopfileparse.h"
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QLocale>
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
#include <QLocale>
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
DesktopAppData DesktopFileParser::parseDesktopFile(
|
||||
const QString &fileName, bool &ok) const
|
||||
DesktopFileParser::DesktopFileParser()
|
||||
{
|
||||
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 {
|
||||
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;
|
||||
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"));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
return m_appList.length() - length;
|
||||
}
|
||||
|
||||
QVector<DesktopAppData> DesktopFileParser::getAppsByCategory(const QString &category) {
|
||||
QVector<DesktopAppData> res;
|
||||
for (const DesktopAppData &app : m_appList) {
|
||||
if (app.categories.contains(category)) {
|
||||
res.append(app);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
QMap<QString, QVector<DesktopAppData>> DesktopFileParser::getAppsByCategory(
|
||||
const QStringList &categories)
|
||||
DesktopAppData
|
||||
DesktopFileParser::parseDesktopFile(const QString& fileName, bool& ok) const
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
QVector<DesktopAppData>
|
||||
DesktopFileParser::getAppsByCategory(const QString& category)
|
||||
{
|
||||
QVector<DesktopAppData> res;
|
||||
for (const DesktopAppData& app : m_appList) {
|
||||
if (app.categories.contains(category)) {
|
||||
res.append(app);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -18,55 +18,59 @@
|
||||
#pragma once
|
||||
|
||||
#include <QIcon>
|
||||
#include <QStringList>
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
|
||||
class QDir;
|
||||
class QString;
|
||||
class QTextStream;
|
||||
|
||||
struct DesktopAppData {
|
||||
DesktopAppData() : showInTerminal() {}
|
||||
struct DesktopAppData
|
||||
{
|
||||
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);
|
||||
struct DesktopFileParser
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -18,29 +18,37 @@
|
||||
#include "desktopinfo.h"
|
||||
#include <QProcessEnvironment>
|
||||
|
||||
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"));
|
||||
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"));
|
||||
}
|
||||
|
||||
bool DesktopInfo::waylandDectected() {
|
||||
return XDG_SESSION_TYPE == QLatin1String("wayland") ||
|
||||
WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive);
|
||||
bool
|
||||
DesktopInfo::waylandDectected()
|
||||
{
|
||||
return XDG_SESSION_TYPE == QLatin1String("wayland") ||
|
||||
WAYLAND_DISPLAY.contains(QLatin1String("wayland"),
|
||||
Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -19,25 +19,27 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
class DesktopInfo {
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -17,93 +17,114 @@
|
||||
|
||||
#include "filenamehandler.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
#include <ctime>
|
||||
#include <locale>
|
||||
#include <QStandardPaths>
|
||||
#include <QDir>
|
||||
|
||||
FileNameHandler::FileNameHandler(QObject *parent) : QObject(parent) {
|
||||
std::locale::global(std::locale(""));
|
||||
FileNameHandler::FileNameHandler(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
std::locale::global(std::locale(""));
|
||||
}
|
||||
|
||||
QString FileNameHandler::parsedPattern() {
|
||||
return parseFilename(ConfigHandler().filenamePatternValue());
|
||||
QString
|
||||
FileNameHandler::parsedPattern()
|
||||
{
|
||||
return parseFilename(ConfigHandler().filenamePatternValue());
|
||||
}
|
||||
|
||||
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
|
||||
FileNameHandler::parseFilename(const QString& name)
|
||||
{
|
||||
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 directory = path;
|
||||
QString filename = parsedPattern();
|
||||
fixPath(directory, filename);
|
||||
return directory + filename;
|
||||
QString
|
||||
FileNameHandler::generateAbsolutePath(const QString& path)
|
||||
{
|
||||
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) {
|
||||
ConfigHandler().setFilenamePattern(pattern);
|
||||
void
|
||||
FileNameHandler::setPattern(const QString& pattern)
|
||||
{
|
||||
ConfigHandler().setFilenamePattern(pattern);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,27 +19,27 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class FileNameHandler : public QObject {
|
||||
Q_OBJECT
|
||||
class FileNameHandler : public QObject
|
||||
{
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "globalvalues.h"
|
||||
#include <QFontMetrics>
|
||||
#include <QApplication>
|
||||
#include <QFontMetrics>
|
||||
|
||||
int GlobalValues::buttonBaseSize() {
|
||||
return QApplication::fontMetrics().lineSpacing() * 2.2;
|
||||
int
|
||||
GlobalValues::buttonBaseSize()
|
||||
{
|
||||
return QApplication::fontMetrics().lineSpacing() * 2.2;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
namespace GlobalValues {
|
||||
|
||||
int buttonBaseSize();
|
||||
int
|
||||
buttonBaseSize();
|
||||
|
||||
}
|
||||
|
||||
@@ -17,29 +17,32 @@
|
||||
|
||||
#include "pathinfo.h"
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
const QString PathInfo::whiteIconPath() {
|
||||
return QStringLiteral(":/img/material/white/");
|
||||
const QString
|
||||
PathInfo::whiteIconPath()
|
||||
{
|
||||
return QStringLiteral(":/img/material/white/");
|
||||
}
|
||||
|
||||
const QString PathInfo::blackIconPath() {
|
||||
return QStringLiteral(":/img/material/black/");
|
||||
const QString
|
||||
PathInfo::blackIconPath()
|
||||
{
|
||||
return QStringLiteral(":/img/material/black/");
|
||||
}
|
||||
|
||||
QStringList PathInfo::translationsPaths() {
|
||||
QString binaryPath = QFileInfo(qApp->applicationDirPath())
|
||||
.absoluteFilePath();
|
||||
QString trPath = QDir::toNativeSeparators(binaryPath + "/translations") ;
|
||||
QStringList
|
||||
PathInfo::translationsPaths()
|
||||
{
|
||||
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,10 +21,13 @@
|
||||
|
||||
namespace PathInfo { // namespace
|
||||
|
||||
const QString whiteIconPath();
|
||||
const QString
|
||||
whiteIconPath();
|
||||
|
||||
const QString blackIconPath();
|
||||
const QString
|
||||
blackIconPath();
|
||||
|
||||
QStringList translationsPaths();
|
||||
QStringList
|
||||
translationsPaths();
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
#include "screengrabber.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include <QPixmap>
|
||||
#include <QScreen>
|
||||
#include <QGuiApplication>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QGuiApplication>
|
||||
#include <QPixmap>
|
||||
#include <QScreen>
|
||||
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
#include <QDBusInterface>
|
||||
@@ -30,97 +30,105 @@
|
||||
#include <QDir>
|
||||
#endif
|
||||
|
||||
ScreenGrabber::ScreenGrabber(QObject *parent) : QObject(parent) {
|
||||
ScreenGrabber::ScreenGrabber(QObject* parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
QPixmap ScreenGrabber::grabEntireDesktop(bool &ok) {
|
||||
ok = true;
|
||||
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 (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;
|
||||
}
|
||||
if (!ok) {
|
||||
SystemNotification().sendMessage(tr("Unable to capture screen"));
|
||||
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();
|
||||
}
|
||||
return res;
|
||||
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());
|
||||
}
|
||||
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 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);
|
||||
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);
|
||||
for (QScreen* const screen : QGuiApplication::screens()) {
|
||||
QPoint topLeftScreen = screen->geometry().topLeft();
|
||||
if (topLeft.x() > topLeftScreen.x() ||
|
||||
topLeft.y() > topLeftScreen.y()) {
|
||||
topLeft = topLeftScreen;
|
||||
}
|
||||
} else {
|
||||
p = QApplication::desktop()->screen(screenNumber)->grab();
|
||||
ok = true;
|
||||
}
|
||||
#endif
|
||||
QRect geometry = QApplication::desktop()->screenGeometry(screenNumber);
|
||||
geometry.moveTo(geometry.topLeft() - topLeft);
|
||||
p = p.copy(geometry);
|
||||
}
|
||||
return p;
|
||||
} else {
|
||||
p = QApplication::desktop()->screen(screenNumber)->grab();
|
||||
ok = true;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -20,13 +20,14 @@
|
||||
#include "src/utils/desktopinfo.h"
|
||||
#include <QObject>
|
||||
|
||||
class ScreenGrabber : public QObject {
|
||||
Q_OBJECT
|
||||
class ScreenGrabber : public QObject
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -16,82 +16,84 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "screenshotsaver.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include <QClipboard>
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QClipboard>
|
||||
#include <QFileDialog>
|
||||
#include <QImageWriter>
|
||||
#include <QMessageBox>
|
||||
|
||||
ScreenshotSaver::ScreenshotSaver() {
|
||||
}
|
||||
ScreenshotSaver::ScreenshotSaver() {}
|
||||
|
||||
void ScreenshotSaver::saveToClipboard(const QPixmap &capture) {
|
||||
SystemNotification().sendMessage(
|
||||
QObject::tr("Capture saved to clipboard"));
|
||||
QApplication::clipboard()->setPixmap(capture);
|
||||
}
|
||||
|
||||
bool ScreenshotSaver::saveToFilesystem(const QPixmap &capture,
|
||||
const QString &path)
|
||||
void
|
||||
ScreenshotSaver::saveToClipboard(const QPixmap& capture)
|
||||
{
|
||||
QString completePath = FileNameHandler().generateAbsolutePath(path);
|
||||
completePath += QLatin1String(".png");
|
||||
bool ok = capture.save(completePath);
|
||||
QString saveMessage;
|
||||
QString notificationPath = completePath;
|
||||
SystemNotification().sendMessage(QObject::tr("Capture saved to clipboard"));
|
||||
QApplication::clipboard()->setPixmap(capture);
|
||||
}
|
||||
|
||||
bool
|
||||
ScreenshotSaver::saveToFilesystem(const QPixmap& capture, const QString& path)
|
||||
{
|
||||
QString completePath = FileNameHandler().generateAbsolutePath(path);
|
||||
completePath += QLatin1String(".png");
|
||||
bool ok = capture.save(completePath);
|
||||
QString saveMessage;
|
||||
QString notificationPath = completePath;
|
||||
|
||||
if (ok) {
|
||||
ConfigHandler().setSavePath(path);
|
||||
saveMessage = QObject::tr("Capture saved as ") + completePath;
|
||||
} else {
|
||||
saveMessage = 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);
|
||||
|
||||
if (ok) {
|
||||
ConfigHandler().setSavePath(path);
|
||||
saveMessage = QObject::tr("Capture saved as ") + completePath;
|
||||
QString pathNoFile =
|
||||
savePath.left(savePath.lastIndexOf(QLatin1String("/")));
|
||||
ConfigHandler().setSavePath(pathNoFile);
|
||||
QString msg = QObject::tr("Capture saved as ") + savePath;
|
||||
SystemNotification().sendMessage(msg, savePath);
|
||||
} else {
|
||||
saveMessage = QObject::tr("Error trying to save as ") + completePath;
|
||||
notificationPath = "";
|
||||
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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
class QPixmap;
|
||||
class QString;
|
||||
|
||||
class ScreenshotSaver {
|
||||
class ScreenshotSaver
|
||||
{
|
||||
public:
|
||||
ScreenshotSaver();
|
||||
|
||||
void saveToClipboard(const QPixmap &capture);
|
||||
bool saveToFilesystem(const QPixmap &capture, const QString &path);
|
||||
bool saveToFilesystemGUI(const QPixmap &capture);
|
||||
ScreenshotSaver();
|
||||
|
||||
void saveToClipboard(const QPixmap& capture);
|
||||
bool saveToFilesystem(const QPixmap& capture, const QString& path);
|
||||
bool saveToFilesystemGUI(const QPixmap& capture);
|
||||
};
|
||||
|
||||
@@ -5,59 +5,68 @@
|
||||
|
||||
#ifndef Q_OS_WIN
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusMessage>
|
||||
#else
|
||||
#endif
|
||||
#include "src/core/controller.h"
|
||||
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
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);
|
||||
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);
|
||||
}
|
||||
#else
|
||||
SystemNotification::SystemNotification(QObject *parent) : QObject(parent) {
|
||||
m_interface = nullptr;
|
||||
SystemNotification::SystemNotification(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_interface = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
void SystemNotification::sendMessage(const QString &text, const QString &savePath) {
|
||||
sendMessage(text, tr("Flameshot Info"), savePath);
|
||||
void
|
||||
SystemNotification::sendMessage(const QString& text, const QString& 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
|
||||
}
|
||||
|
||||
@@ -21,19 +21,19 @@
|
||||
|
||||
class QDBusInterface;
|
||||
|
||||
class SystemNotification : public QObject {
|
||||
Q_OBJECT
|
||||
class SystemNotification : public QObject
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
#include "waylandutils.h"
|
||||
|
||||
WaylandUtils::WaylandUtils()
|
||||
{
|
||||
WaylandUtils::WaylandUtils() {}
|
||||
|
||||
}
|
||||
|
||||
bool WaylandUtils::waylandDetected() {
|
||||
|
||||
}
|
||||
bool
|
||||
WaylandUtils::waylandDetected()
|
||||
{}
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
#ifndef WAYLANDUTILS_H
|
||||
#define WAYLANDUTILS_H
|
||||
|
||||
|
||||
class WaylandUtils
|
||||
{
|
||||
public:
|
||||
WaylandUtils();
|
||||
WaylandUtils();
|
||||
|
||||
static bool waylandDetected();
|
||||
static bool waylandDetected();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // WAYLANDUTILS_H
|
||||
|
||||
Reference in New Issue
Block a user