Add initial DBus support

This commit is contained in:
lupoDharkael
2017-06-06 12:39:25 +02:00
parent 11b0e2db4b
commit 6fb14b91bb
9 changed files with 152 additions and 7 deletions

View 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>

View File

@@ -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

View File

@@ -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,

View File

@@ -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();

View 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();
}

View 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

View File

@@ -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();
}

View 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

View 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();
}