diff --git a/flameshot.pro b/flameshot.pro index 34648e53..c4f21c94 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -7,8 +7,11 @@ VERSION = $$system(git --git-dir $$PWD/.git --work-tree $$PWD describe --always --tags) DEFINES += APP_VERSION=\\\"$$VERSION\\\" -QT += core gui -QT += dbus +QT += core gui + +unix:!macx { + QT += dbus +} greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -74,7 +77,6 @@ SOURCES += src/main.cpp \ src/config/buttonlistview.cpp \ src/config/uicoloreditor.cpp \ src/config/geneneralconf.cpp \ - src/core/flameshotdbusadapter.cpp \ src/core/controller.cpp \ src/config/clickablelabel.cpp \ src/config/filenameeditor.cpp \ @@ -112,7 +114,6 @@ SOURCES += src/main.cpp \ src/core/resourceexporter.cpp \ src/capture/widget/notifierbox.cpp \ src/utils/desktopinfo.cpp \ - src/utils/dbusutils.cpp \ src/capture/workers/launcher/applauncherwidget.cpp \ src/capture/tools/applauncher.cpp \ src/utils/desktopfileparse.cpp \ @@ -120,8 +121,7 @@ SOURCES += src/main.cpp \ src/capture/tools/blurtool.cpp \ src/capture/workers/launcher/terminallauncher.cpp -HEADERS += \ - src/capture/widget/buttonhandler.h \ +HEADERS += src/capture/widget/buttonhandler.h \ src/infowindow.h \ src/config/configwindow.h \ src/capture/screenshot.h \ @@ -131,7 +131,6 @@ HEADERS += \ src/config/buttonlistview.h \ src/config/uicoloreditor.h \ src/config/geneneralconf.h \ - src/core/flameshotdbusadapter.h \ src/config/clickablelabel.h \ src/config/filenameeditor.h \ src/utils/filenamehandler.h \ @@ -169,7 +168,6 @@ HEADERS += \ src/core/resourceexporter.h \ src/capture/widget/notifierbox.h \ src/utils/desktopinfo.h \ - src/utils/dbusutils.h \ src/capture/workers/launcher/applauncherwidget.h \ src/capture/tools/applauncher.h \ src/utils/desktopfileparse.h \ @@ -177,11 +175,19 @@ HEADERS += \ src/capture/tools/blurtool.h \ src/capture/workers/launcher/terminallauncher.h +unix:!macx { + SOURCES += src/core/flameshotdbusadapter.cpp \ + src/utils/dbusutils.cpp + + HEADERS += src/core/flameshotdbusadapter.h \ + src/utils/dbusutils.h +} + RESOURCES += \ graphics.qrc # installs -unix: { +unix:!macx { packaging { USRPATH = /usr } else { diff --git a/src/config/geneneralconf.cpp b/src/config/geneneralconf.cpp index b7ac6fb5..2c84cf76 100644 --- a/src/config/geneneralconf.cpp +++ b/src/config/geneneralconf.cpp @@ -42,8 +42,10 @@ GeneneralConf::GeneneralConf(QWidget *parent) : QGroupBox(parent) { void GeneneralConf::updateComponents() { ConfigHandler config; m_helpMessage->setChecked(config.showHelpValue()); - m_showTray->setChecked(!config.disabledTrayIconValue()); m_sysNotifications->setChecked(config.desktopNotificationValue()); +#ifdef Q_OS_LINUX + m_showTray->setChecked(!config.disabledTrayIconValue()); +#endif } void GeneneralConf::showHelpChanged(bool checked) { @@ -127,6 +129,7 @@ void GeneneralConf::initShowDesktopNotification() { } void GeneneralConf::initShowTrayIcon() { +#ifdef Q_OS_LINUX m_showTray = new QCheckBox(tr("Show tray icon"), this); ConfigHandler config; bool checked = !config.disabledTrayIconValue(); @@ -136,6 +139,7 @@ void GeneneralConf::initShowTrayIcon() { connect(m_showTray, &QCheckBox::clicked, this, &GeneneralConf::showTrayIconChanged); +#endif } void GeneneralConf::initConfingButtons() { diff --git a/src/core/controller.cpp b/src/core/controller.cpp index a6d54e22..707ecd77 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -35,9 +35,13 @@ Controller::Controller() : m_captureWindow(nullptr) qApp->setQuitOnLastWindowClosed(false); // init tray icon +#ifdef Q_OS_LINUX if (!ConfigHandler().disabledTrayIconValue()) { enableTrayIcon(); } +#else + enableTrayIcon(); +#endif initDefaults(); @@ -123,10 +127,22 @@ void Controller::enableTrayIcon() { } void Controller::disableTrayIcon() { +#ifdef Q_OS_LINUX if (m_trayIcon) { m_trayIcon->deleteLater(); } ConfigHandler().setDisabledTrayIcon(true); +#endif +} + +void Controller::sendTrayNotification( + const QString &text, + const QString &title, + const int timeout) +{ + if (m_trayIcon) { + m_trayIcon->showMessage(title, text, QSystemTrayIcon::Information, timeout); + } } void Controller::updateConfigComponents() { diff --git a/src/core/controller.h b/src/core/controller.h index 30149ced..473eeaff 100644 --- a/src/core/controller.h +++ b/src/core/controller.h @@ -49,6 +49,9 @@ public slots: void enableTrayIcon(); void disableTrayIcon(); + void sendTrayNotification(const QString &text, + const QString &title = "Flameshot Info", + const int timeout = 5000); void updateConfigComponents(); diff --git a/src/main.cpp b/src/main.cpp index b6b96d04..40910e75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,20 +17,23 @@ #include "src/core/controller.h" #include "singleapplication.h" -#include "src/core/flameshotdbusadapter.h" #include "src/utils/filenamehandler.h" #include "src/utils/confighandler.h" #include "src/cli/commandlineparser.h" #include "src/utils/systemnotification.h" -#include "src/utils/dbusutils.h" #include #include -#include #include #include #include #include +#ifdef Q_OS_LINUX +#include "src/core/flameshotdbusadapter.h" +#include "src/utils/dbusutils.h" +#include +#endif + int main(int argc, char *argv[]) { // required for the button serialization qRegisterMetaTypeStreamOperators >("QList"); @@ -48,6 +51,7 @@ int main(int argc, char *argv[]) { app.setApplicationName("flameshot"); app.setOrganizationName("Dharkael"); +#ifdef Q_OS_LINUX auto c = Controller::getInstance(); new FlameshotDBusAdapter(c); QDBusConnection dbus = QDBusConnection::sessionBus(); @@ -57,9 +61,14 @@ int main(int argc, char *argv[]) { } dbus.registerObject("/", c); dbus.registerService("org.dharkael.Flameshot"); +#else + // Create inicial static instance + Controller::getInstance(); +#endif return app.exec(); } +#ifndef Q_OS_WIN /*--------------| * CLI parsing | * ------------*/ @@ -316,5 +325,7 @@ int main(int argc, char *argv[]) { } } finish: + +#endif return 0; } diff --git a/src/utils/screengrabber.cpp b/src/utils/screengrabber.cpp index 37f12ea3..ceafaac9 100644 --- a/src/utils/screengrabber.cpp +++ b/src/utils/screengrabber.cpp @@ -22,15 +22,19 @@ #include #include #include + +#ifdef Q_OS_LINUX #include #include +#endif ScreenGrabber::ScreenGrabber(QObject *parent) : QObject(parent) { } QPixmap ScreenGrabber::grabEntireDesktop(bool &ok) { - ok = true; // revisit later + ok = true; +#ifdef Q_OS_LINUX if(m_info.waylandDectected()) { QPixmap res; // handle screenshot based on DE @@ -62,6 +66,8 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool &ok) { } return res; } +#endif + QRect geometry; for (QScreen *const screen : QGuiApplication::screens()) { geometry = geometry.united(screen->geometry()); diff --git a/src/utils/systemnotification.cpp b/src/utils/systemnotification.cpp index 6df30d4d..42372db5 100644 --- a/src/utils/systemnotification.cpp +++ b/src/utils/systemnotification.cpp @@ -1,10 +1,16 @@ #include "systemnotification.h" #include "src/utils/confighandler.h" +#include + +#ifndef Q_OS_WIN #include #include #include -#include +#else +#endif +#include "src/core/controller.h" +#ifdef Q_OS_LINUX SystemNotification::SystemNotification(QObject *parent) : QObject(parent) { m_interface = new QDBusInterface(QStringLiteral("org.freedesktop.Notifications"), QStringLiteral("/org/freedesktop/Notifications"), @@ -12,6 +18,11 @@ SystemNotification::SystemNotification(QObject *parent) : QObject(parent) { QDBusConnection::sessionBus(), this); } +#else +SystemNotification::SystemNotification(QObject *parent) : QObject(parent) { + +} +#endif void SystemNotification::sendMessage( const QString &text, @@ -22,6 +33,7 @@ void SystemNotification::sendMessage( return; } +#ifndef Q_OS_WIN QList args; args << (qAppName()) //appname << static_cast(0) //id @@ -32,4 +44,8 @@ void SystemNotification::sendMessage( << QVariantMap() //hints << timeout; //timeout m_interface->callWithArgumentList(QDBus::AutoDetect, "Notify", args); +#else +#endif + auto c = Controller::getInstance(); + c->sendTrayNotification(title, text); }