Code refactoring - change code style to the new clang-format rules
This commit is contained in:
@@ -17,60 +17,72 @@
|
||||
|
||||
#include "capturerequest.h"
|
||||
#include "src/utils/screenshotsaver.h"
|
||||
#include <QVector>
|
||||
#include <QDateTime>
|
||||
#include <QVector>
|
||||
|
||||
CaptureRequest::CaptureRequest(CaptureRequest::CaptureMode mode,
|
||||
const uint delay, const QString &path,
|
||||
const QVariant &data,
|
||||
CaptureRequest::ExportTask tasks) :
|
||||
m_mode(mode), m_delay(delay), m_path(path), m_tasks(tasks),
|
||||
m_data(data), m_forcedID(false), m_id(0)
|
||||
const uint delay,
|
||||
const QString& path,
|
||||
const QVariant& data,
|
||||
CaptureRequest::ExportTask tasks)
|
||||
: m_mode(mode)
|
||||
, m_delay(delay)
|
||||
, m_path(path)
|
||||
, m_tasks(tasks)
|
||||
, m_data(data)
|
||||
, m_forcedID(false)
|
||||
, m_id(0)
|
||||
{}
|
||||
|
||||
void CaptureRequest::setStaticID(uint id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CaptureRequest::setStaticID(uint id) {
|
||||
m_forcedID = true;
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
uint CaptureRequest::id() const {
|
||||
uint CaptureRequest::id() const
|
||||
{
|
||||
if (m_forcedID) {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
uint id = 0;
|
||||
QVector<uint>v;
|
||||
QVector<uint> v;
|
||||
v << qHash(m_mode) << qHash(m_delay * QDateTime::currentMSecsSinceEpoch())
|
||||
<< qHash(m_path) << qHash(m_tasks) << m_data.toInt();
|
||||
for(uint i : v) {
|
||||
for (uint i : v) {
|
||||
id ^= i + 0x9e3779b9 + (id << 6) + (id >> 2);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
CaptureRequest::CaptureMode CaptureRequest::captureMode() const {
|
||||
CaptureRequest::CaptureMode CaptureRequest::captureMode() const
|
||||
{
|
||||
return m_mode;
|
||||
}
|
||||
|
||||
uint CaptureRequest::delay() const {
|
||||
uint CaptureRequest::delay() const
|
||||
{
|
||||
return m_delay;
|
||||
}
|
||||
|
||||
QString CaptureRequest::path() const {
|
||||
QString CaptureRequest::path() const
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
QVariant CaptureRequest::data() const {
|
||||
QVariant CaptureRequest::data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
void CaptureRequest::addTask(CaptureRequest::ExportTask task) {
|
||||
void CaptureRequest::addTask(CaptureRequest::ExportTask task)
|
||||
{
|
||||
m_tasks |= task;
|
||||
}
|
||||
|
||||
void CaptureRequest::exportCapture(const QPixmap &p) {
|
||||
void CaptureRequest::exportCapture(const QPixmap& p)
|
||||
{
|
||||
if ((m_tasks & ExportTask::FILESYSTEM_SAVE_TASK) != ExportTask::NO_TASK) {
|
||||
if (m_path.isEmpty()) {
|
||||
ScreenshotSaver().saveToFilesystemGUI(p);
|
||||
@@ -82,5 +94,4 @@ void CaptureRequest::exportCapture(const QPixmap &p) {
|
||||
if ((m_tasks & ExportTask::CLIPBOARD_SAVE_TASK) != ExportTask::NO_TASK) {
|
||||
ScreenshotSaver().saveToClipboard(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,19 +17,22 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
class CaptureRequest {
|
||||
class CaptureRequest
|
||||
{
|
||||
public:
|
||||
enum CaptureMode {
|
||||
enum CaptureMode
|
||||
{
|
||||
FULLSCREEN_MODE,
|
||||
GRAPHICAL_MODE,
|
||||
SCREEN_MODE,
|
||||
};
|
||||
|
||||
enum ExportTask {
|
||||
enum ExportTask
|
||||
{
|
||||
NO_TASK = 0,
|
||||
CLIPBOARD_SAVE_TASK = 1,
|
||||
FILESYSTEM_SAVE_TASK = 2,
|
||||
@@ -37,8 +40,8 @@ public:
|
||||
|
||||
CaptureRequest(CaptureMode mode,
|
||||
const uint delay = 0,
|
||||
const QString &path = QLatin1String(""),
|
||||
const QVariant &data = QVariant(),
|
||||
const QString& path = QLatin1String(""),
|
||||
const QVariant& data = QVariant(),
|
||||
ExportTask tasks = NO_TASK);
|
||||
|
||||
void setStaticID(uint id);
|
||||
@@ -50,7 +53,7 @@ public:
|
||||
CaptureMode captureMode() const;
|
||||
|
||||
void addTask(ExportTask task);
|
||||
void exportCapture(const QPixmap &p);
|
||||
void exportCapture(const QPixmap& p);
|
||||
|
||||
private:
|
||||
CaptureMode m_mode;
|
||||
@@ -65,16 +68,18 @@ private:
|
||||
|
||||
using eTask = CaptureRequest::ExportTask;
|
||||
|
||||
inline eTask operator|(const eTask &a, const eTask &b) {
|
||||
inline eTask operator|(const eTask& a, const eTask& b)
|
||||
{
|
||||
return static_cast<eTask>(static_cast<int>(a) | static_cast<int>(b));
|
||||
}
|
||||
|
||||
inline eTask operator&(const eTask &a, const eTask &b) {
|
||||
inline eTask operator&(const eTask& a, const eTask& b)
|
||||
{
|
||||
return static_cast<eTask>(static_cast<int>(a) & static_cast<int>(b));
|
||||
}
|
||||
|
||||
inline eTask& operator|=(eTask &a, const eTask &b) {
|
||||
inline eTask& operator|=(eTask& a, const eTask& b)
|
||||
{
|
||||
a = static_cast<eTask>(static_cast<int>(a) | static_cast<int>(b));
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,25 +16,25 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "controller.h"
|
||||
#include "src/widgets/capture/capturewidget.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/widgets/infowindow.h"
|
||||
#include "src/config/configwindow.h"
|
||||
#include "src/widgets/capture/capturebutton.h"
|
||||
#include "src/widgets/capturelauncher.h"
|
||||
#include "src/widgets/notificationwidget.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include "src/utils/screengrabber.h"
|
||||
#include "src/utils/history.h"
|
||||
#include "src/utils/configenterprise.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/history.h"
|
||||
#include "src/utils/screengrabber.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include "src/widgets/capture/capturebutton.h"
|
||||
#include "src/widgets/capture/capturewidget.h"
|
||||
#include "src/widgets/capturelauncher.h"
|
||||
#include "src/widgets/historywidget.h"
|
||||
#include <QFile>
|
||||
#include <QApplication>
|
||||
#include <QSystemTrayIcon>
|
||||
#include "src/widgets/infowindow.h"
|
||||
#include "src/widgets/notificationwidget.h"
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QDesktopWidget>
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDesktopWidget>
|
||||
#include <QFile>
|
||||
#include <QMenu>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "src/core/globalshortcutfilter.h"
|
||||
@@ -43,7 +43,9 @@
|
||||
// Controller is the core component of Flameshot, creates the trayIcon and
|
||||
// launches the capture widget
|
||||
|
||||
Controller::Controller() : m_captureWindow(nullptr) {
|
||||
Controller::Controller()
|
||||
: m_captureWindow(nullptr)
|
||||
{
|
||||
qApp->setQuitOnLastWindowClosed(false);
|
||||
|
||||
// set default shortcusts if not set yet
|
||||
@@ -57,10 +59,9 @@ Controller::Controller() : m_captureWindow(nullptr) {
|
||||
#elif defined(Q_OS_WIN)
|
||||
enableTrayIcon();
|
||||
|
||||
GlobalShortcutFilter *nativeFilter = new GlobalShortcutFilter(this);
|
||||
GlobalShortcutFilter* nativeFilter = new GlobalShortcutFilter(this);
|
||||
qApp->installNativeEventFilter(nativeFilter);
|
||||
connect(nativeFilter, &GlobalShortcutFilter::printPressed,
|
||||
this, [this](){
|
||||
connect(nativeFilter, &GlobalShortcutFilter::printPressed, this, [this]() {
|
||||
this->requestCapture(CaptureRequest(CaptureRequest::GRAPHICAL_MODE));
|
||||
});
|
||||
#endif
|
||||
@@ -69,50 +70,57 @@ Controller::Controller() : m_captureWindow(nullptr) {
|
||||
qApp->setStyleSheet(StyleSheet);
|
||||
}
|
||||
|
||||
Controller *Controller::getInstance() {
|
||||
Controller* Controller::getInstance()
|
||||
{
|
||||
static Controller c;
|
||||
return &c;
|
||||
}
|
||||
|
||||
void Controller::enableExports() {
|
||||
connect(this, &Controller::captureTaken,
|
||||
this, &Controller::handleCaptureTaken);
|
||||
connect(this, &Controller::captureFailed,
|
||||
this, &Controller::handleCaptureFailed);
|
||||
void Controller::enableExports()
|
||||
{
|
||||
connect(
|
||||
this, &Controller::captureTaken, this, &Controller::handleCaptureTaken);
|
||||
connect(
|
||||
this, &Controller::captureFailed, this, &Controller::handleCaptureFailed);
|
||||
}
|
||||
|
||||
void Controller::requestCapture(const CaptureRequest &request) {
|
||||
void Controller::requestCapture(const CaptureRequest& request)
|
||||
{
|
||||
uint id = request.id();
|
||||
m_requestMap.insert(id, request);
|
||||
|
||||
switch (request.captureMode()) {
|
||||
case CaptureRequest::FULLSCREEN_MODE:
|
||||
doLater(request.delay(), this, [this, id](){
|
||||
this->startFullscreenCapture(id);
|
||||
});
|
||||
break;
|
||||
case CaptureRequest::SCREEN_MODE: {
|
||||
int &&number = request.data().toInt();
|
||||
doLater(request.delay(), this, [this, id, number](){
|
||||
this->startScreenGrab(id, number);
|
||||
});
|
||||
break;
|
||||
} case CaptureRequest::GRAPHICAL_MODE: {
|
||||
QString &&path = request.path();
|
||||
doLater(request.delay(), this, [this, id, path](){
|
||||
this->startVisualCapture(id, path);
|
||||
});
|
||||
break;
|
||||
} default:
|
||||
emit captureFailed(id);
|
||||
break;
|
||||
case CaptureRequest::FULLSCREEN_MODE:
|
||||
doLater(request.delay(), this, [this, id]() {
|
||||
this->startFullscreenCapture(id);
|
||||
});
|
||||
break;
|
||||
case CaptureRequest::SCREEN_MODE: {
|
||||
int&& number = request.data().toInt();
|
||||
doLater(request.delay(), this, [this, id, number]() {
|
||||
this->startScreenGrab(id, number);
|
||||
});
|
||||
break;
|
||||
}
|
||||
case CaptureRequest::GRAPHICAL_MODE: {
|
||||
QString&& path = request.path();
|
||||
doLater(request.delay(), this, [this, id, path]() {
|
||||
this->startVisualCapture(id, path);
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
emit captureFailed(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// creation of a new capture in GUI mode
|
||||
void Controller::startVisualCapture(const uint id, const QString &forcedSavePath) {
|
||||
void Controller::startVisualCapture(const uint id,
|
||||
const QString& forcedSavePath)
|
||||
{
|
||||
if (!m_captureWindow) {
|
||||
QWidget *modalWidget = nullptr;
|
||||
QWidget* modalWidget = nullptr;
|
||||
do {
|
||||
modalWidget = qApp->activeModalWidget();
|
||||
if (modalWidget) {
|
||||
@@ -122,24 +130,30 @@ void Controller::startVisualCapture(const uint id, const QString &forcedSavePath
|
||||
} while (modalWidget);
|
||||
|
||||
m_captureWindow = new CaptureWidget(id, forcedSavePath);
|
||||
//m_captureWindow = new CaptureWidget(id, forcedSavePath, false); // debug
|
||||
connect(m_captureWindow, &CaptureWidget::captureFailed,
|
||||
this, &Controller::captureFailed);
|
||||
connect(m_captureWindow, &CaptureWidget::captureTaken,
|
||||
this, &Controller::captureTaken);
|
||||
// m_captureWindow = new CaptureWidget(id, forcedSavePath, false); //
|
||||
// debug
|
||||
connect(m_captureWindow,
|
||||
&CaptureWidget::captureFailed,
|
||||
this,
|
||||
&Controller::captureFailed);
|
||||
connect(m_captureWindow,
|
||||
&CaptureWidget::captureTaken,
|
||||
this,
|
||||
&Controller::captureTaken);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
m_captureWindow->show();
|
||||
#else
|
||||
m_captureWindow->showFullScreen();
|
||||
//m_captureWindow->show(); // Debug
|
||||
// m_captureWindow->show(); // Debug
|
||||
#endif
|
||||
} else {
|
||||
emit captureFailed(id);
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::startScreenGrab(const uint id, const int screenNumber) {
|
||||
void Controller::startScreenGrab(const uint id, const int screenNumber)
|
||||
{
|
||||
bool ok = true;
|
||||
int n = screenNumber;
|
||||
|
||||
@@ -156,7 +170,8 @@ void Controller::startScreenGrab(const uint id, const int screenNumber) {
|
||||
}
|
||||
|
||||
// creation of the configuration window
|
||||
void Controller::openConfigWindow() {
|
||||
void Controller::openConfigWindow()
|
||||
{
|
||||
if (!m_configWindow) {
|
||||
m_configWindow = new ConfigWindow();
|
||||
m_configWindow->show();
|
||||
@@ -164,46 +179,50 @@ void Controller::openConfigWindow() {
|
||||
}
|
||||
|
||||
// creation of the window of information
|
||||
void Controller::openInfoWindow() {
|
||||
void Controller::openInfoWindow()
|
||||
{
|
||||
if (!m_infoWindow) {
|
||||
m_infoWindow = new InfoWindow();
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::openLauncherWindow() {
|
||||
CaptureLauncher *w = new CaptureLauncher();
|
||||
void Controller::openLauncherWindow()
|
||||
{
|
||||
CaptureLauncher* w = new CaptureLauncher();
|
||||
w->show();
|
||||
}
|
||||
|
||||
void Controller::enableTrayIcon() {
|
||||
void Controller::enableTrayIcon()
|
||||
{
|
||||
if (m_trayIcon) {
|
||||
return;
|
||||
}
|
||||
QMenu *trayIconMenu = new QMenu();
|
||||
QMenu* trayIconMenu = new QMenu();
|
||||
|
||||
ConfigHandler().setDisabledTrayIcon(false);
|
||||
QAction *captureAction = new QAction(tr("&Take Screenshot"), this);
|
||||
connect(captureAction, &QAction::triggered, this, [this](){
|
||||
QAction* captureAction = new QAction(tr("&Take Screenshot"), this);
|
||||
connect(captureAction, &QAction::triggered, this, [this]() {
|
||||
// Wait 400 ms to hide the QMenu
|
||||
doLater(400, this, [this](){ this->startVisualCapture(); });
|
||||
doLater(400, this, [this]() { this->startVisualCapture(); });
|
||||
});
|
||||
QAction *launcherAction = new QAction(tr("&Open Launcher"), this);
|
||||
connect(launcherAction, &QAction::triggered, this,
|
||||
QAction* launcherAction = new QAction(tr("&Open Launcher"), this);
|
||||
connect(launcherAction,
|
||||
&QAction::triggered,
|
||||
this,
|
||||
&Controller::openLauncherWindow);
|
||||
|
||||
QAction *configAction = new QAction(tr("&Configuration"), this);
|
||||
connect(configAction, &QAction::triggered, this,
|
||||
&Controller::openConfigWindow);
|
||||
QAction *infoAction = new QAction(tr("&Information"), this);
|
||||
connect(infoAction, &QAction::triggered, this,
|
||||
&Controller::openInfoWindow);
|
||||
QAction *quitAction = new QAction(tr("&Quit"), this);
|
||||
connect(quitAction, &QAction::triggered, qApp,
|
||||
&QCoreApplication::quit);
|
||||
QAction* configAction = new QAction(tr("&Configuration"), this);
|
||||
connect(
|
||||
configAction, &QAction::triggered, this, &Controller::openConfigWindow);
|
||||
QAction* infoAction = new QAction(tr("&Information"), this);
|
||||
connect(infoAction, &QAction::triggered, this, &Controller::openInfoWindow);
|
||||
QAction* quitAction = new QAction(tr("&Quit"), this);
|
||||
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
|
||||
|
||||
// recent screenshots
|
||||
QAction *recentAction = new QAction(tr("&Latest Uploads"), this);
|
||||
connect(recentAction, SIGNAL(triggered()), this, SLOT(showRecentScreenshots()));
|
||||
QAction* recentAction = new QAction(tr("&Latest Uploads"), this);
|
||||
connect(
|
||||
recentAction, SIGNAL(triggered()), this, SLOT(showRecentScreenshots()));
|
||||
|
||||
// generate menu
|
||||
trayIconMenu->addAction(captureAction);
|
||||
@@ -219,10 +238,11 @@ void Controller::enableTrayIcon() {
|
||||
m_trayIcon = new QSystemTrayIcon();
|
||||
m_trayIcon->setToolTip(QStringLiteral("Flameshot"));
|
||||
m_trayIcon->setContextMenu(trayIconMenu);
|
||||
QIcon trayicon = QIcon::fromTheme("flameshot-tray", QIcon(":img/app/flameshot.png"));
|
||||
QIcon trayicon =
|
||||
QIcon::fromTheme("flameshot-tray", QIcon(":img/app/flameshot.png"));
|
||||
m_trayIcon->setIcon(trayicon);
|
||||
|
||||
auto trayIconActivated = [this](QSystemTrayIcon::ActivationReason r){
|
||||
auto trayIconActivated = [this](QSystemTrayIcon::ActivationReason r) {
|
||||
if (r == QSystemTrayIcon::Trigger) {
|
||||
startVisualCapture();
|
||||
}
|
||||
@@ -230,14 +250,18 @@ void Controller::enableTrayIcon() {
|
||||
connect(m_trayIcon, &QSystemTrayIcon::activated, this, trayIconActivated);
|
||||
m_trayIcon->show();
|
||||
if (ConfigHandler().showStartupLaunchMessage()) {
|
||||
m_trayIcon->showMessage("Flameshot",
|
||||
QObject::tr("Hello, I'm here! Click icon in the tray to take a screenshot or click with a right button to see more options."),
|
||||
QSystemTrayIcon::Information,
|
||||
3000);
|
||||
m_trayIcon->showMessage(
|
||||
"Flameshot",
|
||||
QObject::tr(
|
||||
"Hello, I'm here! Click icon in the tray to take a screenshot or "
|
||||
"click with a right button to see more options."),
|
||||
QSystemTrayIcon::Information,
|
||||
3000);
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::disableTrayIcon() {
|
||||
void Controller::disableTrayIcon()
|
||||
{
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
if (m_trayIcon) {
|
||||
m_trayIcon->deleteLater();
|
||||
@@ -246,28 +270,31 @@ void Controller::disableTrayIcon() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Controller::sendTrayNotification(
|
||||
const QString &text,
|
||||
const QString &title,
|
||||
const int timeout)
|
||||
void Controller::sendTrayNotification(const QString& text,
|
||||
const QString& title,
|
||||
const int timeout)
|
||||
{
|
||||
if (m_trayIcon) {
|
||||
m_trayIcon->showMessage(title, text, QSystemTrayIcon::Information, timeout);
|
||||
m_trayIcon->showMessage(
|
||||
title, text, QSystemTrayIcon::Information, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::updateConfigComponents() {
|
||||
void Controller::updateConfigComponents()
|
||||
{
|
||||
if (m_configWindow) {
|
||||
m_configWindow->updateChildren();
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::showRecentScreenshots() {
|
||||
HistoryWidget *pHistory = new HistoryWidget();
|
||||
void Controller::showRecentScreenshots()
|
||||
{
|
||||
HistoryWidget* pHistory = new HistoryWidget();
|
||||
pHistory->exec();
|
||||
}
|
||||
|
||||
void Controller::startFullscreenCapture(const uint id) {
|
||||
void Controller::startFullscreenCapture(const uint id)
|
||||
{
|
||||
bool ok = true;
|
||||
QPixmap p(ScreenGrabber().grabEntireDesktop(ok));
|
||||
if (ok) {
|
||||
@@ -277,7 +304,8 @@ void Controller::startFullscreenCapture(const uint id) {
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::handleCaptureTaken(uint id, QPixmap p) {
|
||||
void Controller::handleCaptureTaken(uint id, QPixmap p)
|
||||
{
|
||||
auto it = m_requestMap.find(id);
|
||||
if (it != m_requestMap.end()) {
|
||||
it.value().exportCapture(p);
|
||||
@@ -288,7 +316,8 @@ void Controller::handleCaptureTaken(uint id, QPixmap p) {
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::handleCaptureFailed(uint id) {
|
||||
void Controller::handleCaptureFailed(uint id)
|
||||
{
|
||||
m_requestMap.remove(id);
|
||||
|
||||
if (ConfigHandler().closeAfterScreenshotValue()) {
|
||||
@@ -296,10 +325,13 @@ void Controller::handleCaptureFailed(uint id) {
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::doLater(int msec, QObject *receiver, lambda func) {
|
||||
QTimer *timer = new QTimer(receiver);
|
||||
QObject::connect(timer, &QTimer::timeout, receiver,
|
||||
[timer, func](){ func(); timer->deleteLater(); });
|
||||
void Controller::doLater(int msec, QObject* receiver, lambda func)
|
||||
{
|
||||
QTimer* timer = new QTimer(receiver);
|
||||
QObject::connect(timer, &QTimer::timeout, receiver, [timer, func]() {
|
||||
func();
|
||||
timer->deleteLater();
|
||||
});
|
||||
timer->setInterval(msec);
|
||||
timer->start();
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/core/capturerequest.h"
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QPixmap>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QPixmap>
|
||||
#include <QPointer>
|
||||
#include <QTimer>
|
||||
#include <functional>
|
||||
|
||||
@@ -32,14 +32,15 @@ class QSystemTrayIcon;
|
||||
|
||||
using lambda = std::function<void(void)>;
|
||||
|
||||
class Controller : public QObject {
|
||||
class Controller : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static Controller* getInstance();
|
||||
|
||||
Controller(const Controller&) = delete;
|
||||
void operator =(const Controller&) = delete;
|
||||
void operator=(const Controller&) = delete;
|
||||
|
||||
void enableExports();
|
||||
|
||||
@@ -48,16 +49,17 @@ signals:
|
||||
void captureFailed(uint id);
|
||||
|
||||
public slots:
|
||||
void requestCapture(const CaptureRequest &request);
|
||||
void requestCapture(const CaptureRequest& request);
|
||||
|
||||
void openConfigWindow();
|
||||
void openInfoWindow();
|
||||
void openLauncherWindow();
|
||||
void enableTrayIcon();
|
||||
void disableTrayIcon();
|
||||
void sendTrayNotification(const QString &text,
|
||||
const QString &title = QStringLiteral("Flameshot Info"),
|
||||
const int timeout = 5000);
|
||||
void sendTrayNotification(
|
||||
const QString& text,
|
||||
const QString& title = QStringLiteral("Flameshot Info"),
|
||||
const int timeout = 5000);
|
||||
|
||||
void updateConfigComponents();
|
||||
|
||||
@@ -66,7 +68,7 @@ public slots:
|
||||
private slots:
|
||||
void startFullscreenCapture(const uint id = 0);
|
||||
void startVisualCapture(const uint id = 0,
|
||||
const QString &forcedSavePath = QString());
|
||||
const QString& forcedSavePath = QString());
|
||||
void startScreenGrab(const uint id = 0, const int screenNumber = -1);
|
||||
|
||||
void handleCaptureTaken(uint id, QPixmap p);
|
||||
@@ -77,7 +79,7 @@ private:
|
||||
|
||||
// replace QTimer::singleShot introduced in Qt 5.4
|
||||
// the actual target Qt version is 5.3
|
||||
void doLater(int msec, QObject *receiver, lambda func);
|
||||
void doLater(int msec, QObject* receiver, lambda func);
|
||||
|
||||
QMap<uint, CaptureRequest> m_requestMap;
|
||||
QPointer<CaptureWidget> m_captureWindow;
|
||||
|
||||
@@ -16,37 +16,42 @@
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "flameshotdbusadapter.h"
|
||||
#include "src/core/controller.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/screengrabber.h"
|
||||
#include "src/core/controller.h"
|
||||
#include "src/utils/screenshotsaver.h"
|
||||
#include "src/utils/systemnotification.h"
|
||||
#include <QBuffer>
|
||||
FlameshotDBusAdapter::FlameshotDBusAdapter(QObject *parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
FlameshotDBusAdapter::FlameshotDBusAdapter(QObject* parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
{
|
||||
auto controller = Controller::getInstance();
|
||||
connect(controller, &Controller::captureFailed,
|
||||
this, &FlameshotDBusAdapter::captureFailed);
|
||||
connect(controller, &Controller::captureTaken,
|
||||
this, &FlameshotDBusAdapter::handleCaptureTaken);
|
||||
auto controller = Controller::getInstance();
|
||||
connect(controller,
|
||||
&Controller::captureFailed,
|
||||
this,
|
||||
&FlameshotDBusAdapter::captureFailed);
|
||||
connect(controller,
|
||||
&Controller::captureTaken,
|
||||
this,
|
||||
&FlameshotDBusAdapter::handleCaptureTaken);
|
||||
}
|
||||
|
||||
FlameshotDBusAdapter::~FlameshotDBusAdapter() {
|
||||
FlameshotDBusAdapter::~FlameshotDBusAdapter() {}
|
||||
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::graphicCapture(QString path, int delay, uint id) {
|
||||
void FlameshotDBusAdapter::graphicCapture(QString path, int delay, uint id)
|
||||
{
|
||||
CaptureRequest req(CaptureRequest::GRAPHICAL_MODE, delay, path);
|
||||
// if (toClipboard) {
|
||||
// req.addTask(CaptureRequest::CLIPBOARD_SAVE_TASK);
|
||||
// }
|
||||
// if (toClipboard) {
|
||||
// req.addTask(CaptureRequest::CLIPBOARD_SAVE_TASK);
|
||||
// }
|
||||
req.setStaticID(id);
|
||||
Controller::getInstance()->requestCapture(req);
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::fullScreen(
|
||||
QString path, bool toClipboard, int delay, uint id)
|
||||
void FlameshotDBusAdapter::fullScreen(QString path,
|
||||
bool toClipboard,
|
||||
int delay,
|
||||
uint id)
|
||||
{
|
||||
CaptureRequest req(CaptureRequest::FULLSCREEN_MODE, delay, path);
|
||||
if (toClipboard) {
|
||||
@@ -59,12 +64,16 @@ void FlameshotDBusAdapter::fullScreen(
|
||||
Controller::getInstance()->requestCapture(req);
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::openLauncher() {
|
||||
void FlameshotDBusAdapter::openLauncher()
|
||||
{
|
||||
Controller::getInstance()->openLauncherWindow();
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::captureScreen(int number, QString path,
|
||||
bool toClipboard, int delay, uint id)
|
||||
void FlameshotDBusAdapter::captureScreen(int number,
|
||||
QString path,
|
||||
bool toClipboard,
|
||||
int delay,
|
||||
uint id)
|
||||
{
|
||||
CaptureRequest req(CaptureRequest::SCREEN_MODE, delay, path, number);
|
||||
if (toClipboard) {
|
||||
@@ -77,12 +86,14 @@ void FlameshotDBusAdapter::captureScreen(int number, QString path,
|
||||
Controller::getInstance()->requestCapture(req);
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::openConfig() {
|
||||
void FlameshotDBusAdapter::openConfig()
|
||||
{
|
||||
Controller::getInstance()->openConfigWindow();
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::trayIconEnabled(bool enabled) {
|
||||
auto controller = Controller::getInstance();
|
||||
void FlameshotDBusAdapter::trayIconEnabled(bool enabled)
|
||||
{
|
||||
auto controller = Controller::getInstance();
|
||||
if (enabled) {
|
||||
controller->enableTrayIcon();
|
||||
} else {
|
||||
@@ -90,14 +101,16 @@ void FlameshotDBusAdapter::trayIconEnabled(bool enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::autostartEnabled(bool enabled) {
|
||||
void FlameshotDBusAdapter::autostartEnabled(bool enabled)
|
||||
{
|
||||
ConfigHandler().setStartupLaunch(enabled);
|
||||
auto controller = Controller::getInstance();
|
||||
auto controller = Controller::getInstance();
|
||||
// Autostart is not saved in a .ini file, requires manual update
|
||||
controller->updateConfigComponents();
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::handleCaptureTaken(uint id, const QPixmap &p) {
|
||||
void FlameshotDBusAdapter::handleCaptureTaken(uint id, const QPixmap& p)
|
||||
{
|
||||
QByteArray byteArray;
|
||||
QBuffer buffer(&byteArray);
|
||||
p.save(&buffer, "PNG");
|
||||
|
||||
@@ -17,15 +17,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtDBus/QDBusAbstractAdaptor>
|
||||
#include "src/core/controller.h"
|
||||
#include <QtDBus/QDBusAbstractAdaptor>
|
||||
|
||||
class FlameshotDBusAdapter : public QDBusAbstractAdaptor {
|
||||
class FlameshotDBusAdapter : public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.dharkael.Flameshot")
|
||||
|
||||
public:
|
||||
explicit FlameshotDBusAdapter(QObject *parent = nullptr);
|
||||
explicit FlameshotDBusAdapter(QObject* parent = nullptr);
|
||||
virtual ~FlameshotDBusAdapter();
|
||||
|
||||
signals:
|
||||
@@ -34,13 +35,20 @@ signals:
|
||||
|
||||
public slots:
|
||||
Q_NOREPLY void graphicCapture(QString path, int delay, uint id);
|
||||
Q_NOREPLY void fullScreen(QString path, bool toClipboard, int delay, uint id);
|
||||
Q_NOREPLY void captureScreen(int number, QString path, bool toClipboard, int delay, uint id);
|
||||
Q_NOREPLY void fullScreen(QString path,
|
||||
bool toClipboard,
|
||||
int delay,
|
||||
uint id);
|
||||
Q_NOREPLY void captureScreen(int number,
|
||||
QString path,
|
||||
bool toClipboard,
|
||||
int delay,
|
||||
uint id);
|
||||
Q_NOREPLY void openLauncher();
|
||||
Q_NOREPLY void openConfig();
|
||||
Q_NOREPLY void trayIconEnabled(bool enabled);
|
||||
Q_NOREPLY void autostartEnabled(bool enabled);
|
||||
|
||||
private slots:
|
||||
void handleCaptureTaken(uint id, const QPixmap &p);
|
||||
void handleCaptureTaken(uint id, const QPixmap& p);
|
||||
};
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#include "src/widgets/historywidget.h"
|
||||
#include <qt_windows.h>
|
||||
|
||||
GlobalShortcutFilter::GlobalShortcutFilter(QObject *parent) :
|
||||
QObject(parent)
|
||||
GlobalShortcutFilter::GlobalShortcutFilter(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
// Forced Print Screen
|
||||
if (RegisterHotKey(NULL, 1, 0, VK_SNAPSHOT)) {
|
||||
@@ -33,10 +33,9 @@ GlobalShortcutFilter::GlobalShortcutFilter(QObject *parent) :
|
||||
}
|
||||
}
|
||||
|
||||
bool GlobalShortcutFilter::nativeEventFilter(
|
||||
const QByteArray &eventType,
|
||||
void *message,
|
||||
long *result)
|
||||
bool GlobalShortcutFilter::nativeEventFilter(const QByteArray& eventType,
|
||||
void* message,
|
||||
long* result)
|
||||
{
|
||||
Q_UNUSED(eventType);
|
||||
Q_UNUSED(result);
|
||||
@@ -49,15 +48,15 @@ bool GlobalShortcutFilter::nativeEventFilter(
|
||||
const quint32 modifiers = LOWORD(msg->lParam);
|
||||
|
||||
// Show screenshots history
|
||||
if(VK_SNAPSHOT == keycode && MOD_SHIFT == modifiers) {
|
||||
HistoryWidget *pHistory = new HistoryWidget();
|
||||
if (VK_SNAPSHOT == keycode && MOD_SHIFT == modifiers) {
|
||||
HistoryWidget* pHistory = new HistoryWidget();
|
||||
pHistory->show();
|
||||
}
|
||||
|
||||
// Capture screen
|
||||
if(VK_SNAPSHOT == keycode && 0 == modifiers) {
|
||||
if (VK_SNAPSHOT == keycode && 0 == modifiers) {
|
||||
Controller::getInstance()->requestCapture(
|
||||
CaptureRequest(CaptureRequest::GRAPHICAL_MODE));
|
||||
CaptureRequest(CaptureRequest::GRAPHICAL_MODE));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -17,15 +17,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QAbstractNativeEventFilter>
|
||||
#include <QObject>
|
||||
|
||||
class GlobalShortcutFilter : public QObject, public QAbstractNativeEventFilter {
|
||||
class GlobalShortcutFilter
|
||||
: public QObject
|
||||
, public QAbstractNativeEventFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GlobalShortcutFilter(QObject *parent = nullptr);
|
||||
explicit GlobalShortcutFilter(QObject* parent = nullptr);
|
||||
|
||||
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
|
||||
bool nativeEventFilter(const QByteArray& eventType,
|
||||
void* message,
|
||||
long* result);
|
||||
|
||||
signals:
|
||||
void printPressed();
|
||||
|
||||
Reference in New Issue
Block a user