mirror of
https://github.com/fergalmoran/flameshot.git
synced 2026-02-13 14:03:58 +00:00
Code refactoring - change code style to the new clang-format rules
This commit is contained in:
@@ -17,11 +17,13 @@
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
bool ColorUtils::colorIsDark(const QColor &c) {
|
||||
bool ColorUtils::colorIsDark(const QColor& c)
|
||||
{
|
||||
bool isWhite = false;
|
||||
if (getColorLuma(c) <= 0.60) {
|
||||
isWhite = true;
|
||||
@@ -29,11 +31,11 @@ bool ColorUtils::colorIsDark(const QColor &c) {
|
||||
return isWhite;
|
||||
}
|
||||
|
||||
QColor ColorUtils::contrastColor(const QColor &c) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +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
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
#include "configenterprise.h"
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
#include <QFileInfo>
|
||||
#include <QString>
|
||||
#include <QSettings>
|
||||
|
||||
#include <QString>
|
||||
|
||||
ConfigEnterprise::ConfigEnterprise()
|
||||
{
|
||||
// get enterprise settings
|
||||
m_settings = nullptr;
|
||||
QString configIniPath = QDir(QDir::currentPath()).filePath("config.ini");
|
||||
if(!(QFileInfo::exists(configIniPath) && QFileInfo(configIniPath).isFile())) {
|
||||
if (!(QFileInfo::exists(configIniPath) &&
|
||||
QFileInfo(configIniPath).isFile())) {
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
configIniPath = "/etc/flameshot/config.ini";
|
||||
#elif defined(Q_OS_WIN)
|
||||
// calculate workdir for flameshot on startup if is not set yet
|
||||
QSettings bootUpSettings(
|
||||
"HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
||||
QSettings::NativeFormat);
|
||||
"HKEY_CURRENT_"
|
||||
"USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
||||
QSettings::NativeFormat);
|
||||
QFileInfo fi(bootUpSettings.value("Flameshot").toString());
|
||||
configIniPath = QDir(fi.absolutePath()).filePath("config.ini");
|
||||
#endif
|
||||
@@ -26,6 +26,7 @@ ConfigEnterprise::ConfigEnterprise()
|
||||
m_settings = new QSettings(configIniPath, QSettings::IniFormat);
|
||||
}
|
||||
|
||||
QSettings *ConfigEnterprise::settings() {
|
||||
QSettings* ConfigEnterprise::settings()
|
||||
{
|
||||
return m_settings;
|
||||
}
|
||||
|
||||
@@ -3,16 +3,15 @@
|
||||
|
||||
class QSettings;
|
||||
|
||||
|
||||
class ConfigEnterprise
|
||||
{
|
||||
public:
|
||||
ConfigEnterprise();
|
||||
|
||||
QSettings *settings();
|
||||
QSettings* settings();
|
||||
|
||||
private:
|
||||
QSettings *m_settings;
|
||||
QSettings* m_settings;
|
||||
};
|
||||
|
||||
#endif // CONFIGENTERPRISE_H
|
||||
|
||||
@@ -2,112 +2,133 @@
|
||||
#include "src/tools/capturetool.h"
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
ConfigShortcuts::ConfigShortcuts()
|
||||
{
|
||||
|
||||
}
|
||||
ConfigShortcuts::ConfigShortcuts() {}
|
||||
|
||||
// QVector<CaptureButton::ButtonType> getButtons()
|
||||
|
||||
const QVector<QStringList>& ConfigShortcuts::captureShortcutsDefault(const QVector<CaptureButton::ButtonType> &buttons) {
|
||||
const QVector<QStringList>& ConfigShortcuts::captureShortcutsDefault(
|
||||
const QVector<CaptureButton::ButtonType>& buttons)
|
||||
{
|
||||
// get shortcuts names from tools
|
||||
for (const CaptureButton::ButtonType &t: buttons) {
|
||||
CaptureButton *b = new CaptureButton(t, nullptr);
|
||||
for (const CaptureButton::ButtonType& t : buttons) {
|
||||
CaptureButton* b = new CaptureButton(t, nullptr);
|
||||
QString shortcutName = QVariant::fromValue(t).toString();
|
||||
QKeySequence ks = captureShortcutDefault(t);
|
||||
m_shortcuts << (QStringList() << shortcutName << b->tool()->description() << ks.toString());
|
||||
m_shortcuts << (QStringList()
|
||||
<< shortcutName << b->tool()->description()
|
||||
<< ks.toString());
|
||||
b->close();
|
||||
}
|
||||
|
||||
m_shortcuts << (QStringList() << "TYPE_TOGGLE_PANEL" << QObject::tr("Toggle side panel")
|
||||
m_shortcuts << (QStringList()
|
||||
<< "TYPE_TOGGLE_PANEL" << QObject::tr("Toggle side panel")
|
||||
<< QKeySequence(Qt::Key_Space).toString());
|
||||
|
||||
m_shortcuts << (QStringList() << "TYPE_RESIZE_LEFT" << QObject::tr("Resize selection left 1px")
|
||||
m_shortcuts << (QStringList()
|
||||
<< "TYPE_RESIZE_LEFT"
|
||||
<< QObject::tr("Resize selection left 1px")
|
||||
<< QKeySequence(Qt::SHIFT + Qt::Key_Left).toString());
|
||||
m_shortcuts << (QStringList() << "TYPE_RESIZE_RIGHT" << QObject::tr("Resize selection right 1px")
|
||||
m_shortcuts << (QStringList()
|
||||
<< "TYPE_RESIZE_RIGHT"
|
||||
<< QObject::tr("Resize selection right 1px")
|
||||
<< QKeySequence(Qt::SHIFT + Qt::Key_Right).toString());
|
||||
m_shortcuts << (QStringList() << "TYPE_RESIZE_UP" << QObject::tr("Resize selection up 1px")
|
||||
m_shortcuts << (QStringList()
|
||||
<< "TYPE_RESIZE_UP"
|
||||
<< QObject::tr("Resize selection up 1px")
|
||||
<< QKeySequence(Qt::SHIFT + Qt::Key_Up).toString());
|
||||
m_shortcuts << (QStringList() << "TYPE_RESIZE_DOWN" << QObject::tr("Resize selection down 1px")
|
||||
m_shortcuts << (QStringList()
|
||||
<< "TYPE_RESIZE_DOWN"
|
||||
<< QObject::tr("Resize selection down 1px")
|
||||
<< QKeySequence(Qt::SHIFT + Qt::Key_Down).toString());
|
||||
|
||||
m_shortcuts << (QStringList() << "TYPE_MOVE_LEFT" << QObject::tr("Move selection left 1px")
|
||||
<< QKeySequence(Qt::Key_Left).toString());
|
||||
m_shortcuts << (QStringList() << "TYPE_MOVE_RIGHT" << QObject::tr("Move selection right 1px")
|
||||
<< QKeySequence(Qt::Key_Right).toString());
|
||||
m_shortcuts << (QStringList() << "TYPE_MOVE_UP" << QObject::tr("Move selection up 1px")
|
||||
m_shortcuts << (QStringList() << "TYPE_MOVE_LEFT"
|
||||
<< QObject::tr("Move selection left 1px")
|
||||
<< QKeySequence(Qt::Key_Left).toString());
|
||||
m_shortcuts << (QStringList() << "TYPE_MOVE_RIGHT"
|
||||
<< QObject::tr("Move selection right 1px")
|
||||
<< QKeySequence(Qt::Key_Right).toString());
|
||||
m_shortcuts << (QStringList()
|
||||
<< "TYPE_MOVE_UP" << QObject::tr("Move selection up 1px")
|
||||
<< QKeySequence(Qt::Key_Up).toString());
|
||||
m_shortcuts << (QStringList() << "TYPE_MOVE_DOWN" << QObject::tr("Move selection down 1px")
|
||||
<< QKeySequence(Qt::Key_Down).toString());
|
||||
m_shortcuts << (QStringList() << "TYPE_MOVE_DOWN"
|
||||
<< QObject::tr("Move selection down 1px")
|
||||
<< QKeySequence(Qt::Key_Down).toString());
|
||||
|
||||
m_shortcuts << (QStringList() << "" << QObject::tr("Quit capture") << QKeySequence(Qt::Key_Escape).toString());
|
||||
m_shortcuts << (QStringList() << "" << QObject::tr("Screenshot history") << "Shift+Print Screen");
|
||||
m_shortcuts << (QStringList() << "" << QObject::tr("Capture screen") << "Print Screen");
|
||||
m_shortcuts << (QStringList() << "" << QObject::tr("Show color picker") << "Right Click");
|
||||
m_shortcuts << (QStringList() << "" << QObject::tr("Change the tool's thickness") << "Mouse Wheel");
|
||||
m_shortcuts << (QStringList() << "" << QObject::tr("Quit capture")
|
||||
<< QKeySequence(Qt::Key_Escape).toString());
|
||||
m_shortcuts << (QStringList() << "" << QObject::tr("Screenshot history")
|
||||
<< "Shift+Print Screen");
|
||||
m_shortcuts << (QStringList()
|
||||
<< "" << QObject::tr("Capture screen") << "Print Screen");
|
||||
m_shortcuts << (QStringList()
|
||||
<< "" << QObject::tr("Show color picker") << "Right Click");
|
||||
m_shortcuts << (QStringList()
|
||||
<< "" << QObject::tr("Change the tool's thickness")
|
||||
<< "Mouse Wheel");
|
||||
|
||||
return m_shortcuts;
|
||||
}
|
||||
|
||||
const QKeySequence &ConfigShortcuts::captureShortcutDefault(const CaptureButton::ButtonType &buttonType) {
|
||||
const QKeySequence& ConfigShortcuts::captureShortcutDefault(
|
||||
const CaptureButton::ButtonType& buttonType)
|
||||
{
|
||||
m_ks = QKeySequence();
|
||||
switch (buttonType) {
|
||||
case CaptureButton::ButtonType::TYPE_PENCIL:
|
||||
m_ks = QKeySequence(Qt::Key_P);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_DRAWER:
|
||||
m_ks = QKeySequence(Qt::Key_D);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_ARROW:
|
||||
m_ks = QKeySequence(Qt::Key_A);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_SELECTION:
|
||||
m_ks = QKeySequence(Qt::Key_S);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_RECTANGLE:
|
||||
m_ks = QKeySequence(Qt::Key_R);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_CIRCLE:
|
||||
m_ks = QKeySequence(Qt::Key_C);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_MARKER:
|
||||
m_ks = QKeySequence(Qt::Key_M);
|
||||
break;
|
||||
// case CaptureButton::ButtonType::TYPE_SELECTIONINDICATOR:
|
||||
case CaptureButton::ButtonType::TYPE_MOVESELECTION:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::Key_M);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_UNDO:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::Key_Z);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_COPY:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::Key_C);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_SAVE:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::Key_S);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_EXIT:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::Key_Q);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_IMAGEUPLOADER:
|
||||
m_ks = QKeySequence(Qt::Key_Return);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_OPEN_APP:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::Key_O);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_BLUR:
|
||||
m_ks = QKeySequence(Qt::Key_B);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_REDO:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z);
|
||||
break;
|
||||
// case CaptureButton::ButtonType::TYPE_PIN:
|
||||
case CaptureButton::ButtonType::TYPE_TEXT:
|
||||
m_ks = QKeySequence(Qt::Key_T);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_PENCIL:
|
||||
m_ks = QKeySequence(Qt::Key_P);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_DRAWER:
|
||||
m_ks = QKeySequence(Qt::Key_D);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_ARROW:
|
||||
m_ks = QKeySequence(Qt::Key_A);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_SELECTION:
|
||||
m_ks = QKeySequence(Qt::Key_S);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_RECTANGLE:
|
||||
m_ks = QKeySequence(Qt::Key_R);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_CIRCLE:
|
||||
m_ks = QKeySequence(Qt::Key_C);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_MARKER:
|
||||
m_ks = QKeySequence(Qt::Key_M);
|
||||
break;
|
||||
// case CaptureButton::ButtonType::TYPE_SELECTIONINDICATOR:
|
||||
case CaptureButton::ButtonType::TYPE_MOVESELECTION:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::Key_M);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_UNDO:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::Key_Z);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_COPY:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::Key_C);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_SAVE:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::Key_S);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_EXIT:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::Key_Q);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_IMAGEUPLOADER:
|
||||
m_ks = QKeySequence(Qt::Key_Return);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_OPEN_APP:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::Key_O);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_BLUR:
|
||||
m_ks = QKeySequence(Qt::Key_B);
|
||||
break;
|
||||
case CaptureButton::ButtonType::TYPE_REDO:
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z);
|
||||
break;
|
||||
// case CaptureButton::ButtonType::TYPE_PIN:
|
||||
case CaptureButton::ButtonType::TYPE_TEXT:
|
||||
m_ks = QKeySequence(Qt::Key_T);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return m_ks;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
#ifndef CONFIGSHORTCUTS_H
|
||||
#define CONFIGSHORTCUTS_H
|
||||
|
||||
#include <QVector>
|
||||
#include "src/widgets/capture/capturebutton.h"
|
||||
#include <QKeySequence>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QKeySequence>
|
||||
#include "src/widgets/capture/capturebutton.h"
|
||||
#include <QVector>
|
||||
|
||||
class ConfigShortcuts
|
||||
{
|
||||
public:
|
||||
ConfigShortcuts();
|
||||
|
||||
const QVector<QStringList>& captureShortcutsDefault(const QVector<CaptureButton::ButtonType> &buttons);
|
||||
const QKeySequence& captureShortcutDefault(const CaptureButton::ButtonType &buttonType);
|
||||
const QVector<QStringList>& captureShortcutsDefault(
|
||||
const QVector<CaptureButton::ButtonType>& buttons);
|
||||
const QKeySequence& captureShortcutDefault(
|
||||
const CaptureButton::ButtonType& buttonType);
|
||||
|
||||
private:
|
||||
QVector<QStringList> m_shortcuts;
|
||||
|
||||
@@ -18,34 +18,42 @@
|
||||
#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) {
|
||||
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)));
|
||||
QStringLiteral("/"),
|
||||
QLatin1String(""),
|
||||
QStringLiteral("captureTaken"),
|
||||
this,
|
||||
SLOT(captureTaken(uint, QByteArray)));
|
||||
// captureFailed
|
||||
session.connect(QStringLiteral("org.dharkael.Flameshot"),
|
||||
QStringLiteral("/"), QLatin1String(""), QStringLiteral("captureFailed"),
|
||||
this,
|
||||
SLOT(captureFailed(uint)));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -55,7 +63,8 @@ void DBusUtils::captureTaken(uint id, QByteArray rawImage) {
|
||||
}
|
||||
}
|
||||
|
||||
void DBusUtils::captureFailed(uint id) {
|
||||
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 {
|
||||
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);
|
||||
|
||||
private:
|
||||
|
||||
uint m_id;
|
||||
};
|
||||
|
||||
@@ -16,25 +16,26 @@
|
||||
// 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() {
|
||||
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"));
|
||||
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;
|
||||
@@ -55,51 +56,48 @@ DesktopAppData DesktopFileParser::parseDesktopFile(
|
||||
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"))) {
|
||||
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();
|
||||
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();
|
||||
res.name =
|
||||
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
|
||||
}
|
||||
}
|
||||
else if (!descriptionLocaleSet && line.startsWith(QLatin1String("Comment"))) {
|
||||
} 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();
|
||||
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();
|
||||
res.description =
|
||||
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
|
||||
}
|
||||
}
|
||||
else if (line.startsWith(QLatin1String("Exec"))) {
|
||||
} else if (line.startsWith(QLatin1String("Exec"))) {
|
||||
if (line.contains(QLatin1String("%"))) {
|
||||
res.exec = line.mid(line.indexOf(QLatin1String("="))+1)
|
||||
.trimmed();
|
||||
res.exec =
|
||||
line.mid(line.indexOf(QLatin1String("=")) + 1).trimmed();
|
||||
} else {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (line.startsWith(QLatin1String("Type"))) {
|
||||
} 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")) {
|
||||
} 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")) {
|
||||
} else if (line == QLatin1String("Terminal=true")) {
|
||||
res.showInTerminal = true;
|
||||
}
|
||||
// ignore the other entries
|
||||
@@ -114,11 +112,12 @@ DesktopAppData DesktopFileParser::parseDesktopFile(
|
||||
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){
|
||||
for (QString file : entries) {
|
||||
DesktopAppData app = parseDesktopFile(dir.absoluteFilePath(file), ok);
|
||||
if (ok) {
|
||||
m_appList.append(app);
|
||||
@@ -127,9 +126,11 @@ int DesktopFileParser::processDirectory(const QDir &dir) {
|
||||
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) {
|
||||
for (const DesktopAppData& app : m_appList) {
|
||||
if (app.categories.contains(category)) {
|
||||
res.append(app);
|
||||
}
|
||||
@@ -138,11 +139,11 @@ QVector<DesktopAppData> DesktopFileParser::getAppsByCategory(const QString &cate
|
||||
}
|
||||
|
||||
QMap<QString, QVector<DesktopAppData>> DesktopFileParser::getAppsByCategory(
|
||||
const QStringList &categories)
|
||||
const QStringList& categories)
|
||||
{
|
||||
QMap<QString, QVector<DesktopAppData>> res;
|
||||
for (const DesktopAppData &app : m_appList) {
|
||||
for (const QString &category: categories) {
|
||||
for (const DesktopAppData& app : m_appList) {
|
||||
for (const QString& category : categories) {
|
||||
if (app.categories.contains(category)) {
|
||||
res[category].append(app);
|
||||
}
|
||||
|
||||
@@ -18,29 +18,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <QIcon>
|
||||
#include <QStringList>
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
|
||||
class QDir;
|
||||
class QString;
|
||||
class QTextStream;
|
||||
|
||||
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)
|
||||
struct DesktopAppData
|
||||
{
|
||||
DesktopAppData()
|
||||
: showInTerminal()
|
||||
{}
|
||||
|
||||
bool operator==(const DesktopAppData &other) const {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -52,14 +55,15 @@ struct DesktopAppData {
|
||||
bool showInTerminal;
|
||||
};
|
||||
|
||||
struct DesktopFileParser {
|
||||
struct DesktopFileParser
|
||||
{
|
||||
DesktopFileParser();
|
||||
DesktopAppData parseDesktopFile(const QString &fileName, bool &ok) const;
|
||||
int processDirectory(const QDir &dir);
|
||||
DesktopAppData parseDesktopFile(const QString& fileName, bool& ok) const;
|
||||
int processDirectory(const QDir& dir);
|
||||
|
||||
QVector<DesktopAppData> getAppsByCategory(const QString &category);
|
||||
QVector<DesktopAppData> getAppsByCategory(const QString& category);
|
||||
QMap<QString, QVector<DesktopAppData>> getAppsByCategory(
|
||||
const QStringList &categories);
|
||||
const QStringList& categories);
|
||||
|
||||
private:
|
||||
QString m_localeName;
|
||||
|
||||
@@ -18,28 +18,34 @@
|
||||
#include "desktopinfo.h"
|
||||
#include <QProcessEnvironment>
|
||||
|
||||
DesktopInfo::DesktopInfo() {
|
||||
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"));
|
||||
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);
|
||||
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())
|
||||
{
|
||||
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")) {
|
||||
} else if (!KDE_FULL_SESSION.isEmpty() ||
|
||||
DESKTOP_SESSION == QLatin1String("kde-plasma")) {
|
||||
res = DesktopInfo::KDE;
|
||||
}
|
||||
return res;
|
||||
|
||||
@@ -19,11 +19,13 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
class DesktopInfo {
|
||||
class DesktopInfo
|
||||
{
|
||||
public:
|
||||
DesktopInfo();
|
||||
|
||||
enum WM {
|
||||
enum WM
|
||||
{
|
||||
GNOME,
|
||||
KDE,
|
||||
OTHER
|
||||
|
||||
@@ -17,79 +17,92 @@
|
||||
|
||||
#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) {
|
||||
FileNameHandler::FileNameHandler(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
std::locale::global(std::locale(""));
|
||||
}
|
||||
|
||||
QString FileNameHandler::parsedPattern() {
|
||||
QString FileNameHandler::parsedPattern()
|
||||
{
|
||||
return parseFilename(ConfigHandler().filenamePatternValue());
|
||||
}
|
||||
|
||||
QString FileNameHandler::parseFilename(const QString &name) {
|
||||
QString FileNameHandler::parseFilename(const QString& name)
|
||||
{
|
||||
QString res = name;
|
||||
// remove trailing characters '%' in the pattern
|
||||
if (name.isEmpty()) {
|
||||
res = QLatin1String("%F_%H-%M");
|
||||
}
|
||||
while(res.endsWith('%')) {
|
||||
while (res.endsWith('%')) {
|
||||
res.chop(1);
|
||||
}
|
||||
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));
|
||||
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("-"));
|
||||
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;
|
||||
}
|
||||
// path a images si no existe, add numeration
|
||||
void FileNameHandler::setPattern(const QString &pattern) {
|
||||
void FileNameHandler::setPattern(const QString& 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);
|
||||
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 FileNameHandler::absoluteSavePath()
|
||||
{
|
||||
QString dir, file;
|
||||
return absoluteSavePath(dir, file);
|
||||
}
|
||||
|
||||
QString FileNameHandler::charArrToQString(const char *c) {
|
||||
QString FileNameHandler::charArrToQString(const char* c)
|
||||
{
|
||||
return QString::fromLocal8Bit(c, MAX_CHARACTERS);
|
||||
}
|
||||
|
||||
char * FileNameHandler::QStringTocharArr(const QString &s) {
|
||||
char* FileNameHandler::QStringTocharArr(const QString& s)
|
||||
{
|
||||
QByteArray ba = s.toLocal8Bit();
|
||||
return const_cast<char *>(strdup(ba.constData()));
|
||||
return const_cast<char*>(strdup(ba.constData()));
|
||||
}
|
||||
|
||||
void FileNameHandler::fixPath(QString &directory, QString &filename) {
|
||||
void FileNameHandler::fixPath(QString& directory, QString& filename)
|
||||
{
|
||||
// add '/' at the end of the directory
|
||||
if (!directory.endsWith(QLatin1String("/"))) {
|
||||
directory += QLatin1String("/");
|
||||
@@ -101,8 +114,8 @@ void FileNameHandler::fixPath(QString &directory, QString &filename) {
|
||||
filename += QLatin1String("_");
|
||||
int i = 1;
|
||||
while (true) {
|
||||
checkFile.setFile(
|
||||
directory + filename + QString::number(i) + ".png");
|
||||
checkFile.setFile(directory + filename + QString::number(i) +
|
||||
".png");
|
||||
if (!checkFile.exists()) {
|
||||
filename += QString::number(i);
|
||||
break;
|
||||
|
||||
@@ -19,27 +19,27 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class FileNameHandler : public QObject {
|
||||
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 parseFilename(const QString& name);
|
||||
QString generateAbsolutePath(const QString& path);
|
||||
QString absoluteSavePath(QString& directory, QString& filename);
|
||||
QString absoluteSavePath();
|
||||
|
||||
|
||||
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,10 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "globalvalues.h"
|
||||
#include <QFontMetrics>
|
||||
#include <QApplication>
|
||||
#include <QFontMetrics>
|
||||
|
||||
int GlobalValues::buttonBaseSize() {
|
||||
int GlobalValues::buttonBaseSize()
|
||||
{
|
||||
return QApplication::fontMetrics().lineSpacing() * 2.2;
|
||||
}
|
||||
|
||||
@@ -17,29 +17,30 @@
|
||||
|
||||
#include "pathinfo.h"
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
const QString PathInfo::whiteIconPath() {
|
||||
const QString PathInfo::whiteIconPath()
|
||||
{
|
||||
return QStringLiteral(":/img/material/white/");
|
||||
}
|
||||
|
||||
const QString PathInfo::blackIconPath() {
|
||||
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");
|
||||
<< 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
|
||||
}
|
||||
|
||||
@@ -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,47 +30,56 @@
|
||||
#include <QDir>
|
||||
#endif
|
||||
|
||||
ScreenGrabber::ScreenGrabber(QObject *parent) : QObject(parent) {
|
||||
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()) {
|
||||
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 {
|
||||
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;
|
||||
} 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;
|
||||
break;
|
||||
}
|
||||
if (!ok) {
|
||||
SystemNotification().sendMessage(tr("Unable to capture screen"));
|
||||
@@ -80,24 +89,24 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool &ok) {
|
||||
#endif
|
||||
|
||||
QRect geometry;
|
||||
for (QScreen *const screen : QGuiApplication::screens()) {
|
||||
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())
|
||||
);
|
||||
QApplication::desktop()->winId(),
|
||||
geometry.x(),
|
||||
geometry.y(),
|
||||
geometry.width(),
|
||||
geometry.height()));
|
||||
auto screenNumber = QApplication::desktop()->screenNumber();
|
||||
QScreen *screen = QApplication::screens()[screenNumber];
|
||||
QScreen* screen = QApplication::screens()[screenNumber];
|
||||
p.setDevicePixelRatio(screen->devicePixelRatio());
|
||||
return p;
|
||||
}
|
||||
|
||||
QPixmap ScreenGrabber::grabScreen(int screenNumber, bool &ok) {
|
||||
QPixmap ScreenGrabber::grabScreen(int screenNumber, bool& ok)
|
||||
{
|
||||
QPixmap p;
|
||||
bool isVirtual = QApplication::desktop()->isVirtualDesktop();
|
||||
if (isVirtual || m_info.waylandDectected()) {
|
||||
@@ -105,16 +114,16 @@ QPixmap ScreenGrabber::grabScreen(int screenNumber, bool &ok) {
|
||||
if (ok) {
|
||||
QPoint topLeft(0, 0);
|
||||
#ifdef Q_OS_WIN
|
||||
for (QScreen *const screen : QGuiApplication::screens()) {
|
||||
for (QScreen* const screen : QGuiApplication::screens()) {
|
||||
QPoint topLeftScreen = screen->geometry().topLeft();
|
||||
if (topLeft.x() > topLeftScreen.x() ||
|
||||
topLeft.y() > topLeftScreen.y()) {
|
||||
topLeft.y() > topLeftScreen.y()) {
|
||||
topLeft = topLeftScreen;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
QRect geometry = QApplication::desktop()->
|
||||
screenGeometry(screenNumber);
|
||||
QRect geometry =
|
||||
QApplication::desktop()->screenGeometry(screenNumber);
|
||||
geometry.moveTo(geometry.topLeft() - topLeft);
|
||||
p = p.copy(geometry);
|
||||
}
|
||||
|
||||
@@ -20,12 +20,13 @@
|
||||
#include "src/utils/desktopinfo.h"
|
||||
#include <QObject>
|
||||
|
||||
class ScreenGrabber : public QObject {
|
||||
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;
|
||||
|
||||
@@ -17,26 +17,24 @@
|
||||
|
||||
#include "screenshotsaver.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include "src/utils/filenamehandler.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include <QClipboard>
|
||||
#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"));
|
||||
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)
|
||||
bool ScreenshotSaver::saveToFilesystem(const QPixmap& capture,
|
||||
const QString& path)
|
||||
{
|
||||
QString completePath = FileNameHandler().generateAbsolutePath(path);
|
||||
completePath += QLatin1String(".png");
|
||||
@@ -56,17 +54,19 @@ bool ScreenshotSaver::saveToFilesystem(const QPixmap &capture,
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap &capture) {
|
||||
bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap& capture)
|
||||
{
|
||||
bool ok = false;
|
||||
while (!ok) {
|
||||
ConfigHandler config;
|
||||
QString savePath = FileNameHandler().absoluteSavePath();
|
||||
if(config.savePathFixed().size() == 0) {
|
||||
if (config.savePathFixed().size() == 0) {
|
||||
savePath = QFileDialog::getSaveFileName(
|
||||
nullptr,
|
||||
QObject::tr("Save screenshot"),
|
||||
FileNameHandler().absoluteSavePath(),
|
||||
QLatin1String("Portable Network Graphic file (PNG) (*.png);;BMP file (*.bmp);;JPEG file (*.jpg)"));
|
||||
nullptr,
|
||||
QObject::tr("Save screenshot"),
|
||||
FileNameHandler().absoluteSavePath(),
|
||||
QLatin1String("Portable Network Graphic file (PNG) (*.png);;BMP "
|
||||
"file (*.bmp);;JPEG file (*.jpg)"));
|
||||
}
|
||||
|
||||
if (savePath.isNull()) {
|
||||
@@ -84,20 +84,21 @@ bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap &capture) {
|
||||
|
||||
if (ok) {
|
||||
ConfigHandler config;
|
||||
QString pathNoFile = savePath.left(savePath.lastIndexOf(QLatin1String("/")));
|
||||
QString pathNoFile =
|
||||
savePath.left(savePath.lastIndexOf(QLatin1String("/")));
|
||||
config.setSavePath(pathNoFile);
|
||||
QString msg = QObject::tr("Capture saved as ") + savePath;
|
||||
if(config.copyPathAfterSaveEnabled()) {
|
||||
if (config.copyPathAfterSaveEnabled()) {
|
||||
QApplication::clipboard()->setText(savePath);
|
||||
msg = QObject::tr("Capture saved and copied to the clipboard as ") + savePath;
|
||||
msg =
|
||||
QObject::tr("Capture saved and copied to the clipboard 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);
|
||||
QMessageBox::Warning, QObject::tr("Save Error"), msg);
|
||||
saveErrBox.setWindowIcon(QIcon(":img/app/flameshot.svg"));
|
||||
saveErrBox.exec();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
void saveToClipboard(const QPixmap& capture);
|
||||
bool saveToFilesystem(const QPixmap& capture, const QString& path);
|
||||
bool saveToFilesystemGUI(const QPixmap& capture);
|
||||
};
|
||||
|
||||
@@ -5,37 +5,43 @@
|
||||
|
||||
#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) {
|
||||
SystemNotification::SystemNotification(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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()) {
|
||||
if (!ConfigHandler().desktopNotificationValue()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,17 +51,19 @@ void SystemNotification::sendMessage(
|
||||
if (!savePath.isEmpty()) {
|
||||
QUrl fullPath = QUrl::fromLocalFile(savePath);
|
||||
// allows the notification to be dragged and dropped
|
||||
hintsMap[QStringLiteral("x-kde-urls")] = QStringList({fullPath.toString()});
|
||||
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);
|
||||
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);
|
||||
|
||||
@@ -21,19 +21,19 @@
|
||||
|
||||
class QDBusInterface;
|
||||
|
||||
class SystemNotification : public QObject {
|
||||
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,
|
||||
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,5 @@
|
||||
#include "waylandutils.h"
|
||||
|
||||
WaylandUtils::WaylandUtils()
|
||||
{
|
||||
WaylandUtils::WaylandUtils() {}
|
||||
|
||||
}
|
||||
|
||||
bool WaylandUtils::waylandDetected() {
|
||||
|
||||
}
|
||||
bool WaylandUtils::waylandDetected() {}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef WAYLANDUTILS_H
|
||||
#define WAYLANDUTILS_H
|
||||
|
||||
|
||||
class WaylandUtils
|
||||
{
|
||||
public:
|
||||
@@ -10,7 +9,6 @@ public:
|
||||
static bool waylandDetected();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // WAYLANDUTILS_H
|
||||
|
||||
Reference in New Issue
Block a user