Made changes after review of merge

This commit is contained in:
Jeremy Borgman
2021-01-15 17:51:23 -06:00
parent 73fe772b70
commit 92b9379d69
14 changed files with 93 additions and 138 deletions

View File

@@ -4,9 +4,9 @@ cmake_minimum_required(VERSION 3.13)
set(FLAMESHOT_VERSION 0.8.5.6)
# Flameshot-org
#set(GIT_API_URL "https://api.github.com/repos/flameshot-org/flameshot/releases/latest")
set(GIT_API_URL "https://api.github.com/repos/flameshot-org/flameshot/releases/latest")
# Namecheap
set(GIT_API_URL "https://api.github.com/repos/namecheap/flameshot/releases/latest")
# set(GIT_API_URL "https://api.github.com/repos/namecheap/flameshot/releases/latest")
# TODO - fix it for all linux distros
# find_package (Git)

View File

@@ -149,20 +149,7 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/widgets/capture>
$<INSTALL_INTERFACE:include/mylib>)
if (APPLE)
target_link_libraries(
flameshot
project_warnings
project_options
qhotkey
Qt5::Svg
Qt5::DBus
Qt5::Network
Qt5::Widgets
SingleApplication::SingleApplication
spdlog::spdlog)
else ()
target_link_libraries(
target_link_libraries(
flameshot
project_warnings
project_options
@@ -172,6 +159,12 @@ else ()
Qt5::Widgets
SingleApplication::SingleApplication
spdlog::spdlog
)
if (APPLE)
target_link_libraries(
flameshot
qhotkey
)
endif ()

View File

@@ -17,7 +17,7 @@
#include "controller.h"
#include "src/config/configwindow.h"
#include "src/core/QHotkey/QHotkey"
#include "external/QHotkey/QHotkey"
#include "src/utils/confighandler.h"
#include "src/utils/history.h"
#include "src/utils/screengrabber.h"
@@ -55,15 +55,12 @@
// launches the capture widget
Controller::Controller()
: m_captureWindow(nullptr)
, m_history(nullptr)
, m_trayIconMenu(nullptr)
, m_networkCheckUpdates(nullptr)
, m_showCheckAppUpdateStatus(false)
: m_captureWindow(nullptr), m_history(nullptr), m_trayIconMenu(nullptr), m_networkCheckUpdates(nullptr),
m_showCheckAppUpdateStatus(false)
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
defined(Q_OS_MACX))
, m_HotkeyScreenshotCapture(nullptr)
, m_HotkeyScreenshotHistory(nullptr)
, m_HotkeyScreenshotCapture(nullptr)
, m_HotkeyScreenshotHistory(nullptr)
#endif
{
m_appLatestVersion = QStringLiteral(APP_VERSION).replace("v", "");
@@ -115,28 +112,24 @@ Controller::Controller()
getLatestAvailableVersion();
}
Controller::~Controller()
{
Controller::~Controller() {
delete m_history;
delete m_trayIconMenu;
}
Controller* Controller::getInstance()
{
Controller *Controller::getInstance() {
static Controller c;
return &c;
}
void Controller::enableExports()
{
void Controller::enableExports() {
connect(
this, &Controller::captureTaken, this, &Controller::handleCaptureTaken);
connect(
this, &Controller::captureFailed, this, &Controller::handleCaptureFailed);
}
void Controller::getLatestAvailableVersion()
{
void Controller::getLatestAvailableVersion() {
// This features is required for MacOS and Windows user and for Linux users
// who installed Flameshot not from the repository.
m_networkCheckUpdates = new QNetworkAccessManager(this);
@@ -153,8 +146,7 @@ void Controller::getLatestAvailableVersion()
});
}
void Controller::handleReplyCheckUpdates(QNetworkReply* reply)
{
void Controller::handleReplyCheckUpdates(QNetworkReply *reply) {
if (reply->error() == QNetworkReply::NoError) {
QJsonDocument response = QJsonDocument::fromJson(reply->readAll());
QJsonObject json = response.object();
@@ -186,8 +178,7 @@ void Controller::handleReplyCheckUpdates(QNetworkReply* reply)
m_showCheckAppUpdateStatus = false;
}
void Controller::appUpdates()
{
void Controller::appUpdates() {
if (m_appLatestUrl.isEmpty()) {
m_showCheckAppUpdateStatus = true;
getLatestAvailableVersion();
@@ -196,8 +187,7 @@ void Controller::appUpdates()
}
}
void Controller::requestCapture(const CaptureRequest& request)
{
void Controller::requestCapture(const CaptureRequest &request) {
uint id = request.id();
m_requestMap.insert(id, request);
@@ -210,14 +200,14 @@ void Controller::requestCapture(const CaptureRequest& request)
// TODO: Figure out the code path that gets here so the deprated warning
// can be fixed
case CaptureRequest::SCREEN_MODE: {
int&& number = request.data().toInt();
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();
QString &&path = request.path();
doLater(request.delay(), this, [this, id, path]() {
this->startVisualCapture(id, path);
});
@@ -231,10 +221,9 @@ void Controller::requestCapture(const CaptureRequest& request)
// creation of a new capture in GUI mode
void Controller::startVisualCapture(const uint id,
const QString& forcedSavePath)
{
const QString &forcedSavePath) {
if (!m_captureWindow) {
QWidget* modalWidget = nullptr;
QWidget *modalWidget = nullptr;
do {
modalWidget = qApp->activeModalWidget();
if (modalWidget) {
@@ -265,6 +254,7 @@ void Controller::startVisualCapture(const uint id,
m_captureWindow->raise();
#else
m_captureWindow->showFullScreen();
//m_captureWindow->show(); //Debug
#endif
if (!m_appLatestUrl.isEmpty() &&
ConfigHandler().ignoreUpdateToVersion().compare(
@@ -277,8 +267,7 @@ void Controller::startVisualCapture(const uint 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;
@@ -296,8 +285,7 @@ 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();
@@ -310,8 +298,7 @@ void Controller::openConfigWindow()
}
// creation of the window of information
void Controller::openInfoWindow()
{
void Controller::openInfoWindow() {
if (!m_infoWindow) {
m_infoWindow = new InfoWindow();
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
@@ -322,8 +309,7 @@ void Controller::openInfoWindow()
}
}
void Controller::openLauncherWindow()
{
void Controller::openLauncherWindow() {
if (!m_launcherWindow) {
m_launcherWindow = new CaptureLauncher();
}
@@ -335,38 +321,37 @@ void Controller::openLauncherWindow()
#endif
}
void Controller::enableTrayIcon()
{
void Controller::enableTrayIcon() {
if (m_trayIcon) {
return;
}
m_trayIconMenu = new QMenu();
ConfigHandler().setDisabledTrayIcon(false);
QAction* captureAction = new QAction(tr("&Take Screenshot"), 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(); });
});
QAction* launcherAction = new QAction(tr("&Open Launcher"), this);
QAction *launcherAction = new QAction(tr("&Open Launcher"), this);
connect(launcherAction,
&QAction::triggered,
this,
&Controller::openLauncherWindow);
QAction* configAction = new QAction(tr("&Configuration"), this);
QAction *configAction = new QAction(tr("&Configuration"), this);
connect(
configAction, &QAction::triggered, this, &Controller::openConfigWindow);
QAction* infoAction = new QAction(tr("&About"), this);
QAction *infoAction = new QAction(tr("&About"), this);
connect(infoAction, &QAction::triggered, this, &Controller::openInfoWindow);
m_appUpdates = new QAction(tr("Check for updates"), this);
connect(m_appUpdates, &QAction::triggered, this, &Controller::appUpdates);
QAction* quitAction = new QAction(tr("&Quit"), this);
QAction *quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
// recent screenshots
QAction* recentAction = new QAction(tr("&Latest Uploads"), this);
QAction *recentAction = new QAction(tr("&Latest Uploads"), this);
connect(
recentAction, SIGNAL(triggered()), this, SLOT(showRecentScreenshots()));
@@ -435,8 +420,7 @@ void Controller::enableTrayIcon()
m_trayIcon->show();
}
void Controller::disableTrayIcon()
{
void Controller::disableTrayIcon() {
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
if (m_trayIcon) {
m_trayIcon->deleteLater();
@@ -445,25 +429,22 @@ 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, QIcon(":img/app/flameshot.svg"), timeout);
}
}
void Controller::updateConfigComponents()
{
void Controller::updateConfigComponents() {
if (m_configWindow) {
m_configWindow->updateChildren();
}
}
void Controller::updateRecentScreenshots()
{
void Controller::updateRecentScreenshots() {
if (nullptr != m_history) {
if (m_history->isVisible()) {
m_history->loadHistory();
@@ -471,8 +452,7 @@ void Controller::updateRecentScreenshots()
}
}
void Controller::showRecentScreenshots()
{
void Controller::showRecentScreenshots() {
if (nullptr == m_history) {
m_history = new HistoryWidget();
}
@@ -485,8 +465,7 @@ void Controller::showRecentScreenshots()
#endif
}
void Controller::startFullscreenCapture(const uint id)
{
void Controller::startFullscreenCapture(const uint id) {
bool ok = true;
QPixmap p(ScreenGrabber().grabEntireDesktop(ok));
if (ok) {
@@ -497,8 +476,7 @@ void Controller::startFullscreenCapture(const uint id)
}
}
void Controller::handleCaptureTaken(uint id, QPixmap p, QRect selection)
{
void Controller::handleCaptureTaken(uint id, QPixmap p, QRect selection) {
auto it = m_requestMap.find(id);
if (it != m_requestMap.end()) {
it.value().exportCapture(p);
@@ -506,14 +484,12 @@ void Controller::handleCaptureTaken(uint id, QPixmap p, QRect selection)
}
}
void Controller::handleCaptureFailed(uint id)
{
void Controller::handleCaptureFailed(uint id) {
m_requestMap.remove(id);
}
void Controller::doLater(int msec, QObject* receiver, lambda func)
{
QTimer* timer = new QTimer(receiver);
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();

View File

@@ -23,9 +23,8 @@
#include <QVBoxLayout>
#include <QWheelEvent>
UtilityPanel::UtilityPanel(QWidget* parent)
: QWidget(parent)
{
UtilityPanel::UtilityPanel(QWidget *parent)
: QWidget(parent) {
initInternalPanel();
setAttribute(Qt::WA_TransparentForMouseEvents);
setCursor(Qt::ArrowCursor);
@@ -49,13 +48,11 @@ UtilityPanel::UtilityPanel(QWidget* parent)
#endif
}
QWidget* UtilityPanel::toolWidget() const
{
QWidget *UtilityPanel::toolWidget() const {
return m_toolWidget;
}
void UtilityPanel::addToolWidget(QWidget* w)
{
void UtilityPanel::addToolWidget(QWidget *w) {
if (m_toolWidget) {
m_toolWidget->deleteLater();
}
@@ -67,20 +64,17 @@ void UtilityPanel::addToolWidget(QWidget* w)
}
}
void UtilityPanel::clearToolWidget()
{
void UtilityPanel::clearToolWidget() {
if (m_toolWidget) {
m_toolWidget->deleteLater();
}
}
void UtilityPanel::pushWidget(QWidget* w)
{
void UtilityPanel::pushWidget(QWidget *w) {
m_layout->insertWidget(m_layout->count() - 1, w);
}
void UtilityPanel::show()
{
void UtilityPanel::show() {
setAttribute(Qt::WA_TransparentForMouseEvents, false);
m_showAnimation->setStartValue(QRect(-width(), 0, 0, height()));
m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
@@ -93,8 +87,7 @@ void UtilityPanel::show()
QWidget::show();
}
void UtilityPanel::hide()
{
void UtilityPanel::hide() {
setAttribute(Qt::WA_TransparentForMouseEvents);
m_hideAnimation->setStartValue(QRect(0, 0, width(), height()));
m_hideAnimation->setEndValue(QRect(-width(), 0, 0, height()));
@@ -103,8 +96,7 @@ void UtilityPanel::hide()
QWidget::hide();
}
void UtilityPanel::toggle()
{
void UtilityPanel::toggle() {
if (m_internalPanel->isHidden()) {
show();
} else {
@@ -112,11 +104,10 @@ void UtilityPanel::toggle()
}
}
void UtilityPanel::initInternalPanel()
{
void UtilityPanel::initInternalPanel() {
m_internalPanel = new QScrollArea(this);
m_internalPanel->setAttribute(Qt::WA_NoMousePropagation);
QWidget* widget = new QWidget();
QWidget *widget = new QWidget();
m_internalPanel->setWidget(widget);
m_internalPanel->setWidgetResizable(true);
@@ -127,7 +118,7 @@ void UtilityPanel::initInternalPanel()
m_layout->addLayout(m_bottomLayout);
widget->setLayout(m_layout);
QPushButton* closeButton = new QPushButton(this);
QPushButton *closeButton = new QPushButton(this);
closeButton->setText(tr("Close"));
connect(closeButton, &QPushButton::clicked, this, &UtilityPanel::toggle);
m_bottomLayout->addWidget(closeButton);
@@ -136,10 +127,5 @@ void UtilityPanel::initInternalPanel()
bgColor.setAlphaF(0.0);
m_internalPanel->setStyleSheet(
QStringLiteral("QScrollArea {background-color: %1}").arg(bgColor.name()));
m_hide = new QPushButton();
m_hide->setText(tr("Hide"));
m_upLayout->addWidget(m_hide);
connect(m_hide, SIGNAL(clicked()), this, SLOT(slotHidePanel()));
m_internalPanel->hide();
}