Add initial DBus support
This commit is contained in:
7
dbus/org.dharkael.Flameshot.xml
Normal file
7
dbus/org.dharkael.Flameshot.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="org.kde.Flameshot">
|
||||
<method name="createCapture">
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
QT += core gui
|
||||
QT += x11extras
|
||||
QT += dbus
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
@@ -47,7 +48,8 @@ SOURCES += src/main.cpp\
|
||||
src/capture/colorpicker.cpp \
|
||||
src/config/buttonlistview.cpp \
|
||||
src/config/uicoloreditor.cpp \
|
||||
src/config/geneneralconf.cpp
|
||||
src/config/geneneralconf.cpp \
|
||||
src/flameshotdbusadapter.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/nativeeventfilter.h \
|
||||
@@ -62,7 +64,8 @@ HEADERS += \
|
||||
src/capture/colorpicker.h \
|
||||
src/config/buttonlistview.h \
|
||||
src/config/uicoloreditor.h \
|
||||
src/config/geneneralconf.h
|
||||
src/config/geneneralconf.h \
|
||||
src/flameshotdbusadapter.h
|
||||
|
||||
RESOURCES += \
|
||||
graphics.qrc
|
||||
|
||||
@@ -44,7 +44,7 @@ Controller::Controller(QObject *parent) : QObject(parent),
|
||||
|
||||
m_nativeEventFilter = new NativeEventFilter(this);
|
||||
qApp->installNativeEventFilter(m_nativeEventFilter);
|
||||
connect(m_nativeEventFilter, &NativeEventFilter::activated, this, &Controller::slotPrintHotkey);
|
||||
connect(m_nativeEventFilter, &NativeEventFilter::activated, this, &Controller::createCapture);
|
||||
|
||||
QString StyleSheet = Button::getStyle();
|
||||
qApp->setStyleSheet(StyleSheet);
|
||||
@@ -114,7 +114,7 @@ void Controller::initDefaults() {
|
||||
}
|
||||
|
||||
// creation of a new capture
|
||||
void Controller::slotPrintHotkey() {
|
||||
void Controller::createCapture() {
|
||||
if (!m_captureWindow) {
|
||||
m_captureWindow = new CaptureWidget();
|
||||
connect(m_captureWindow, &CaptureWidget::newMessage,
|
||||
|
||||
@@ -34,10 +34,12 @@ class Controller : public QObject {
|
||||
public:
|
||||
explicit Controller(QObject *parent = 0);
|
||||
|
||||
private slots:
|
||||
void slotPrintHotkey();
|
||||
public slots:
|
||||
void createCapture();
|
||||
void openConfigWindow();
|
||||
void openInfoWindow();
|
||||
|
||||
private slots:
|
||||
void showMessage(QString);
|
||||
void initDefaults();
|
||||
|
||||
|
||||
36
src/flameshotdbusadapter.cpp
Normal file
36
src/flameshotdbusadapter.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright 2017 Alejandro Sirgo Rica
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "flameshotdbusadapter.h"
|
||||
|
||||
FlameshotDBusAdapter::FlameshotDBusAdapter(Controller *parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FlameshotDBusAdapter::~FlameshotDBusAdapter() {
|
||||
|
||||
}
|
||||
|
||||
Controller *FlameshotDBusAdapter::parent() const {
|
||||
return static_cast<Controller *>(QObject::parent());
|
||||
}
|
||||
|
||||
void FlameshotDBusAdapter::createCapture() {
|
||||
parent()->createCapture();
|
||||
}
|
||||
44
src/flameshotdbusadapter.h
Normal file
44
src/flameshotdbusadapter.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2017 Alejandro Sirgo Rica
|
||||
//
|
||||
// This file is part of Flameshot.
|
||||
//
|
||||
// Flameshot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Flameshot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef FLAMESHOTDBUSADAPTER_H
|
||||
#define FLAMESHOTDBUSADAPTER_H
|
||||
|
||||
#include <QtDBus/QDBusAbstractAdaptor>
|
||||
#include "src/controller.h"
|
||||
|
||||
class FlameshotDBusAdapter : public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.dharkael.Flameshot")
|
||||
Q_CLASSINFO("D-Bus Introspection", ""
|
||||
"<interface name=\"org.kde.Flameshot\">\n"
|
||||
" <method name=\"createCapture\">\n"
|
||||
" </method>\n"
|
||||
"</interface>\n"
|
||||
""
|
||||
)
|
||||
public:
|
||||
FlameshotDBusAdapter(Controller *parent = 0);
|
||||
virtual ~FlameshotDBusAdapter();
|
||||
inline Controller *parent() const;
|
||||
|
||||
public slots:
|
||||
Q_NOREPLY void createCapture();
|
||||
};
|
||||
|
||||
#endif // FLAMESHOTDBUSADAPTER_H
|
||||
@@ -17,8 +17,10 @@
|
||||
|
||||
#include "controller.h"
|
||||
#include "singleapplication.h"
|
||||
#include "src/flameshotdbusadapter.h"
|
||||
#include <QApplication>
|
||||
#include <QTranslator>
|
||||
#include <QDBusConnection>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QTranslator translator;
|
||||
@@ -27,11 +29,16 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
SingleApplication app(argc, argv);
|
||||
app.installTranslator(&translator);
|
||||
app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
|
||||
|
||||
app.setApplicationName("flameshot");
|
||||
app.setOrganizationName("Dharkael");
|
||||
|
||||
Controller w;
|
||||
Controller c;
|
||||
new FlameshotDBusAdapter(&c);
|
||||
QDBusConnection dbus = QDBusConnection::sessionBus();
|
||||
dbus.registerObject("/", &c);
|
||||
dbus.registerService("org.dharkael.Flameshot");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
24
tools/flameshot-cli/flameshot-cli.pro
Normal file
24
tools/flameshot-cli/flameshot-cli.pro
Normal file
@@ -0,0 +1,24 @@
|
||||
QT += core
|
||||
QT += dbus
|
||||
QT -= gui
|
||||
|
||||
CONFIG += c++11
|
||||
|
||||
TARGET = flameshot-cli
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
SOURCES += main.cpp
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which as been marked deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
22
tools/flameshot-cli/main.cpp
Normal file
22
tools/flameshot-cli/main.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
//#include <QCommandLineParser>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Q_UNUSED(argc);
|
||||
Q_UNUSED(argv);
|
||||
//QCoreApplication a(argc, argv);
|
||||
//QCommandLineParser parser;
|
||||
QDBusMessage m = QDBusMessage::createMethodCall("org.dharkael.Flameshot",
|
||||
"/",
|
||||
"",
|
||||
"createCapture"
|
||||
);
|
||||
|
||||
QDBusConnection::sessionBus().call(m);
|
||||
|
||||
|
||||
//return a.exec();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user