Added dbus communication with desktop widget
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 31 Aug 2010 10:24:10 +0000 (12:24 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 31 Aug 2010 10:24:10 +0000 (12:24 +0200)
data/other/com.comarch.mdictionary.service [new file with mode: 0644]
data/other/mdictionary.desktop
trunk/src/base/base.pro
trunk/src/base/gui/DBusAdapter.cpp [new file with mode: 0644]
trunk/src/base/gui/DBusAdapter.h [new file with mode: 0644]
trunk/src/base/gui/main.cpp
trunk/src/desktopWidget/MainWidget.cpp
trunk/src/desktopWidget/MainWidget.h
trunk/src/desktopWidget/desktopWidget.pro
trunk/src/desktopWidget/main.cpp

diff --git a/data/other/com.comarch.mdictionary.service b/data/other/com.comarch.mdictionary.service
new file mode 100644 (file)
index 0000000..718ea09
--- /dev/null
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=com.comarch.mdictionary
+Exec=/usr/bin/mdictionary
index b1e23ed..f3819c7 100644 (file)
@@ -7,3 +7,4 @@ Name=mDictionary
 Icon=mdictionary
 Exec=/usr/bin/mdictionary
 X-Maemo-Category=Main
+X-Osso-Service=com.comarch.mdictionary
index aec27f2..f1086ab 100644 (file)
@@ -5,7 +5,8 @@ QT += core \
     gui \
     sql \
     xml \
-    xmlpatterns
+    xmlpatterns \
+    dbus
 
 maemo5:QT += maemo5
 TARGET = mdictionary
@@ -32,7 +33,8 @@ SOURCES += gui/main.cpp \
     gui/BookmarksWidget.cpp \
     gui/WelcomeScreenWidget.cpp \
     gui/AboutWidget.cpp \
-    gui/TranslationTextEdit.cpp
+    gui/TranslationTextEdit.cpp \
+    gui/DBusAdapter.cpp
 HEADERS += gui/MainWindow.h \
     backbone/ConfigGenerator.h \
     gui/AboutWidget.h \
@@ -60,7 +62,8 @@ HEADERS += gui/MainWindow.h \
     ../includes/Notify.h \
     gui/TranslationTextEdit.h \
     ../includes/AccentsNormalizer.h \
-    ../includes/DictDialog.h
+    ../includes/DictDialog.h \
+    gui/DBusAdapter.h
 RESOURCES += ../../../data/icons/gui.qrc
 unix { 
     # VARIABLES
@@ -73,7 +76,9 @@ unix {
     # MAKE INSTALL
     INSTALLS += target \
         desktop \
-        icon64
+        icon64 \
+        service
+
     target.path = $$BINDIR
     maemo5 { 
         desktop.path = $$DATADIR/applications/hildon
@@ -85,5 +90,8 @@ unix {
     }
     desktop.files += ../../../data/other/$${TARGET}.desktop
     icon64.files += ../../../data/icons/64x64/$${TARGET}.png
+
+    service.path = $$DATADIR/dbus-1/services
+    service.files += ../../../data/other/com.comarch.mdictionary.service
 }
 RESOURCES += xslt2.qrc
diff --git a/trunk/src/base/gui/DBusAdapter.cpp b/trunk/src/base/gui/DBusAdapter.cpp
new file mode 100644 (file)
index 0000000..45e41bd
--- /dev/null
@@ -0,0 +1,42 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary 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.
+
+    mDictionary 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 mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "DBusAdapter.h"
+#include <QDebug>
+
+DBusAdapter::DBusAdapter(MainWindow *w):
+    QDBusAbstractAdaptor(w)
+{
+    mainWindow = w;
+}
+
+void DBusAdapter::search(QString word) {
+    mainWindow->searchExact(word);
+    if(!mainWindow->isVisible())
+        mainWindow->show();
+}
+
+int DBusAdapter::top_application() {
+    qDebug()<<"top";
+    return 0;
+}
diff --git a/trunk/src/base/gui/DBusAdapter.h b/trunk/src/base/gui/DBusAdapter.h
new file mode 100644 (file)
index 0000000..1a7f49d
--- /dev/null
@@ -0,0 +1,46 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary 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.
+
+    mDictionary 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 mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef DBUSADAPTER_H
+#define DBUSADAPTER_H
+
+#include <QDBusAbstractAdaptor>
+#include "MainWindow.h"
+
+class DBusAdapter : public QDBusAbstractAdaptor
+{
+    Q_OBJECT
+    Q_CLASSINFO("D-Bus Interface", "com.comarch.mdictionary")
+public:
+    explicit DBusAdapter(MainWindow* w);
+
+public slots:
+    void search(QString);
+    Q_SCRIPTABLE int top_application();
+
+private:
+    MainWindow* mainWindow;
+
+};
+
+#endif // DBUSADAPTER_H
index f047889..8d154c2 100644 (file)
 #include "../backbone/backbone.h"
 #include "../../includes/translation.h"
 #include "../../includes/Notify.h"
+#include "DBusAdapter.h"
 #include <QDebug>
+#include <QDBusConnection>
+
 
 
 QStringList parseParameters(int argc, char *argv[]) {
@@ -65,8 +68,17 @@ int main(int argc, char *argv[]) {
     qRegisterMetaType<Notify::NotifyType>("Notify::NotifyType");
     Backbone backbone;
     MainWindow w(&backbone);
+
+    DBusAdapter* adapter = new DBusAdapter(&w);
+
+    QDBusConnection::sessionBus().registerObject("/mainWindow",
+                                                 &w);
+    QDBusConnection::sessionBus().registerService("com.comarch.mdictionary");
+
+
     w.show();
 
+
     if(search.count() > 0) {
         w.setExactSearch(true);
         w.searchExact(search[0]);
index 42a5766..061298d 100644 (file)
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
 #include <QtGui/QX11Info>
+#include <QtDBus/QDBusMessage>
+#include <QtDBus/QDBusPendingCall>
+#include <QList>
+#include <QDebug>
 
-MainWidget::MainWidget(QWidget *parent) :
+MainWidget::MainWidget(QWidget *parent):
     QWidget(parent)
 {
     QCoreApplication::instance()->setApplicationName(
@@ -46,9 +50,6 @@ MainWidget::MainWidget(QWidget *parent) :
     Atom utf8Atom = XInternAtom(
             QX11Info::display(), "UTF8_STRING", false);
 
-    Atom appletSettingAtom = XInternAtom(
-            QX11Info::display(), "_HILDON_APPLET_SETTINGS", false);
-
 
     // Set correct window type
     XChangeProperty(QX11Info::display(), winId(), winTypeAtom, XA_ATOM, 32,
@@ -67,9 +68,33 @@ MainWidget::MainWidget(QWidget *parent) :
     layout = new QVBoxLayout;
     setLayout(layout);
 
+    title = new QLabel("mDictionary");
+    layout->addWidget(title,0, Qt::AlignHCenter);
+
+
     searchStringLineEdit = new QLineEdit;
     searchButton = new QPushButton(tr("Search"));
 
-    layout->addWidget(searchStringLineEdit);
-    layout->addWidget(searchButton);
+    horizontalLayout = new QHBoxLayout;
+    horizontalLayout->addWidget(searchStringLineEdit);
+    horizontalLayout->addWidget(searchButton);
+
+    layout->addLayout(horizontalLayout);
+
+    connect(searchButton, SIGNAL(clicked()),
+            this, SLOT(search()));
+}
+
+void MainWidget::search() {
+    QDBusMessage message =
+            QDBusMessage::createMethodCall("com.comarch.mdictionary",
+                                           "/mainWindow",
+                                           "com.comarch.mdictionary",
+                                           "search");
+
+    QList<QVariant> args;
+    args.append(searchStringLineEdit->text());
+    message.setArguments(args);
+
+    QDBusConnection::sessionBus().send(message);
 }
index c6fa486..2ee6fdd 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <QWidget>
 #include <QtGui>
+#include <QtDBus/QDBusConnection>
 
 class MainWidget : public QWidget
 {
@@ -33,10 +34,15 @@ class MainWidget : public QWidget
 public:
     explicit MainWidget(QWidget *parent = 0);
 
+private slots:
+    void search();
+
 private:
     QLineEdit* searchStringLineEdit;
     QPushButton* searchButton;
+    QLabel* title;
     QVBoxLayout* layout;
+    QHBoxLayout* horizontalLayout;
 };
 
 #endif // MAINWIDGET_H
index c8fccfa..8344634 100644 (file)
@@ -1,8 +1,7 @@
 # -------------------------------------------------
 # Project created by QtCreator 2010-08-03T08:54:27
 # -------------------------------------------------
-QT += core \
-      gui \
+QT += core gui dbus
 
 TARGET = mdictionarywidget
 
index b6e1148..bc4d769 100644 (file)
@@ -24,6 +24,7 @@
 #include <QtGui/QApplication>
 #include "MainWidget.h"
 #include <X11/extensions/Xrender.h>
+#include <QtDBus/QDBusConnection>
 
 int main(int argc, char *argv[]) {
 
@@ -33,7 +34,6 @@ int main(int argc, char *argv[]) {
         exit(1);
     }
 
-
     QApplication a(dpy, argc, argv);
     QApplication::setOrganizationName("Comarch S.A.");
     QApplication::setOrganizationDomain("comarch.com");