Commit c8d69cda authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢 Committed by Hans-Peter Deifel
Browse files

Add basic dbus-API for synctex support

Katarakt now exposes a dbus-API that allows TeX-editors to synchronize
the positions in source code and pdf via synctex.

TODO: The API allows to specify positions in the PDF as (page,x,y)
triple, but the x,y coordinates are currently ignored or set to 0,
respectively. We need more katarakt-internal API for this to be
implementable.
parent 180f14eb
......@@ -3,7 +3,7 @@ TARGET = katarakt
DEPENDPATH += .
INCLUDEPATH += .
CONFIG += qt
QT += network xml
QT += network xml dbus
DEFINES += "POPPLER_VERSION_MAJOR=`pkg-config --modversion poppler-qt4 | cut -d . -f 1`"
DEFINES += "POPPLER_VERSION_MINOR=`pkg-config --modversion poppler-qt4 | cut -d . -f 2`"
......@@ -13,11 +13,15 @@ QMAKE_CXXFLAGS_DEBUG += -DDEBUG
# Input
HEADERS += src/layout/layout.h src/layout/presentationlayout.h src/layout/gridlayout.h src/layout/presenterlayout.h \
src/viewer.h src/canvas.h src/resourcemanager.h src/grid.h src/search.h src/gotoline.h src/config.h src/download.h src/util.h src/kpage.h src/worker.h src/beamerwindow.h src/toc.h src/splitter.h src/selection.h
src/viewer.h src/canvas.h src/resourcemanager.h src/grid.h src/search.h src/gotoline.h src/config.h \
src/download.h src/util.h src/kpage.h src/worker.h src/beamerwindow.h src/toc.h src/splitter.h src/selection.h \
src/dbus/source_correlate.h src/dbus/dbus.h
SOURCES += src/main.cpp \
src/layout/layout.cpp src/layout/presentationlayout.cpp src/layout/gridlayout.cpp src/layout/presenterlayout.cpp \
src/viewer.cpp src/canvas.cpp src/resourcemanager.cpp src/grid.cpp src/search.cpp src/gotoline.cpp src/config.cpp src/download.cpp src/util.cpp src/kpage.cpp src/worker.cpp src/beamerwindow.cpp src/toc.cpp src/splitter.cpp src/selection.cpp
src/viewer.cpp src/canvas.cpp src/resourcemanager.cpp src/grid.cpp src/search.cpp src/gotoline.cpp src/config.cpp \
src/download.cpp src/util.cpp src/kpage.cpp src/worker.cpp src/beamerwindow.cpp src/toc.cpp src/splitter.cpp \
src/selection.cpp src/dbus/source_correlate.cpp src/dbus/dbus.cpp
unix:LIBS += -lpoppler-qt4
documentation.target = doc/katarakt.1
......
......@@ -193,7 +193,14 @@ void Canvas::mousePressEvent(QMouseEvent *event) {
}
void Canvas::mouseReleaseEvent(QMouseEvent *event) {
if (click_link_button != Qt::NoButton && event->button() == click_link_button) {
if (event->button() == Qt::LeftButton && event->modifiers() == Qt::ControlModifier) {
// emit synctex signal
int page = cur_layout->get_page();
// FIXME Really get the page that was clicked on
// FIXME Get coordinates
emit synchronize_editor(page, 0, 0);
} else if (click_link_button != Qt::NoButton && event->button() == click_link_button) {
if (mx_down == event->x() && my_down == event->y()) {
int page = cur_layout->get_page();
pair<int, QPointF> location = cur_layout->get_location_at(mx_down, my_down);
......
......@@ -43,6 +43,13 @@ protected:
void mouseDoubleClickEvent(QMouseEvent * event);
void resizeEvent(QResizeEvent *event);
signals:
/**
* Emitted when the user requests to see the source code of a
* particular point on a particular page.
*/
void synchronize_editor(int page, int x, int y);
private slots:
void page_rendered(int page);
void goto_page();
......
#include "dbus.h"
#include "source_correlate.h"
#include "../viewer.h"
#include <QDBusConnection>
#include <QApplication>
#include <iostream>
using namespace std;
void dbus_init(Viewer *viewer)
{
/* Add dbus interfaces to the viewer object.
*
* These are automatically destroyed, if the parent object is.
*
* At present, there is only the SourceCorrelate interface.
*/
new SourceCorrelate(viewer);
QString bus_name = QString("katarakt.pid%1")
.arg(QApplication::applicationPid());
if (!QDBusConnection::sessionBus().registerService(bus_name)) {
#ifdef DEBUG
cerr << "Failed to register DBus service" << endl;
#endif
} else {
if (!QDBusConnection::sessionBus().registerObject("/", viewer)) {
#ifdef DEBUG
cerr << "Failed to register viewer object on DBus" << endl;
#endif
}
}
}
#ifndef DBUS_H
#define DBUS_H
class Viewer;
/**
* Connect to the session bus and publish all interfaces.
*
* Fails silently in case of errors.
*/
void dbus_init(Viewer *viewer);
#endif /* DBUS_H */
#include "source_correlate.h"
#include "../viewer.h"
#include "../canvas.h"
#include "../layout/layout.h"
#include "../resourcemanager.h"
#include <QUrl>
#include <QFileInfo>
using namespace std;
SourceCorrelate::SourceCorrelate(Viewer *viewer)
: QDBusAbstractAdaptor(viewer), viewer(viewer)
{
connect(viewer->get_canvas(), SIGNAL(synchronize_editor(int, int, int)),
this, SLOT(emit_edit_signal(int, int, int)));
}
void SourceCorrelate::view(QString filename, int page, int x, int y)
{
if (page < 0)
return;
QFileInfo oldFile = QFileInfo(viewer->get_res()->get_file());
QFileInfo newFile = QFileInfo(filename);
QUrl url(filename);
if ((url.isLocalFile() || url.isRelative())
&& newFile.canonicalFilePath() != oldFile.canonicalFilePath()) {
// only open, if file is different from the already loaded one
viewer->open(filename);
}
// needed to add an entry to the jump list
int current_page = viewer->get_canvas()->get_layout()->get_page();
viewer->get_canvas()->get_layout()->scroll_page(page, false);
// FIXME scroll to offset
viewer->get_res()->store_jump(current_page);
viewer->get_canvas()->repaint();
viewer->repaint();
}
void SourceCorrelate::emit_edit_signal(int page, int x, int y)
{
QString file = viewer->get_res()->get_file();
qDebug("Emitting the edit signal");
emit edit(file, page, x, y);
}
#ifndef SOURCE_CORRELATE_H
#define SOURCE_CORRELATE_H
#include <QDBusAbstractAdaptor>
class Viewer;
class SourceCorrelate : public QDBusAbstractAdaptor {
Q_OBJECT;
Q_CLASSINFO("D-Bus Interface", "katarakt.SourceCorrelate");
public:
SourceCorrelate(Viewer *viewer);
public slots:
/** Jump to a (0 indexed) page in file filename and make the position
* (x,y) in points from the top left corner of page visible.
*
* The document will not be reloaded if the filename is the same as
* the currently loaded file.
*/
void view(QString filename, int page, int x, int y);
signals:
/** Emitted, if the user requests to edit the source code for a
* specific position on a specific page.
*
* The page is 0-indexed.
*/
void edit(QString filename, int page, int x, int y);
private slots:
void emit_edit_signal(int page, int x, int y);
private:
Viewer *viewer;
};
#endif /* SOURCE_CORRELATE_H */
......@@ -7,6 +7,7 @@
#include "resourcemanager.h"
#include "viewer.h"
#include "config.h"
#include "dbus/dbus.h"
using namespace std;
......@@ -94,6 +95,9 @@ int main(int argc, char *argv[]) {
}
katarakt.show();
// initialize dbus interfaces
dbus_init(&katarakt);
return app.exec();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment