1 /*******************************************************************************
3 This file is part of mDictionary.
5 mDictionary is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 mDictionary is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 //Created by Mateusz Półrola
24 #include "MainWidget.h"
27 #include <X11/Xatom.h>
28 #include <QtGui/QX11Info>
29 #include <QtDBus/QDBusMessage>
30 #include <QtDBus/QDBusPendingCall>
35 MainWidget::MainWidget(QWidget *parent):
38 setAttribute(Qt::WA_TranslucentBackground);
41 QCoreApplication::instance()->setApplicationName(
42 "mDictionary desktop widget");
45 Atom winTypeAtom = XInternAtom(
46 QX11Info::display(), "_NET_WM_WINDOW_TYPE", false);
48 Atom homeAppletAto = XInternAtom(
49 QX11Info::display(), "_HILDON_WM_WINDOW_TYPE_HOME_APPLET", false);
51 Atom appletIDAtom = XInternAtom(
52 QX11Info::display(), "_HILDON_APPLET_ID", false);
54 Atom utf8Atom = XInternAtom(
55 QX11Info::display(), "UTF8_STRING", false);
58 // Set correct window type
59 XChangeProperty(QX11Info::display(), winId(), winTypeAtom, XA_ATOM, 32,
60 PropModeReplace, (unsigned char *) &homeAppletAto, 1);
64 // Use application name to fill AppletID
65 QByteArray id (QCoreApplication::instance()->applicationName().remove(' ').toUtf8());
67 XChangeProperty(QX11Info::display(), winId(), appletIDAtom, utf8Atom, 8,
68 PropModeReplace, (unsigned char *)id.constData(),
72 horizontalLayout = new QHBoxLayout;
73 setLayout(horizontalLayout);
75 searchStringLineEdit = new QLineEdit;
76 searchButton = new QPushButton(tr("Search"));
78 searchButton->setMaximumHeight(60);
80 logo = new QToolButton();
81 logo->setIcon(QIcon(":/icons/64x64/mdictionary.png"));
84 horizontalLayout->addWidget(logo);
85 horizontalLayout->addWidget(searchStringLineEdit);
86 horizontalLayout->addWidget(searchButton);
87 horizontalLayout->setContentsMargins(10,10,10,10);
90 connect(searchStringLineEdit, SIGNAL(returnPressed()),
91 this, SLOT(search()));
93 connect(searchButton, SIGNAL(clicked()),
94 this, SLOT(search()));
96 connect(logo, SIGNAL(clicked()),
97 this, SLOT(logoClicked()));
100 setMinimumHeight(100);
101 setMaximumHeight(100);
104 void MainWidget::search() {
105 if(searchStringLineEdit->text().isEmpty()) return;
107 QDBusMessage message =
108 QDBusMessage::createMethodCall("com.comarch.mdictionary",
110 "com.comarch.mdictionary",
113 QList<QVariant> args;
114 args.append(searchStringLineEdit->text());
115 message.setArguments(args);
117 QDBusConnection::sessionBus().send(message);
120 void MainWidget::logoClicked() {
121 QDBusMessage message =
122 QDBusMessage::createMethodCall("com.comarch.mdictionary",
124 "com.comarch.mdictionary",
126 QDBusConnection::sessionBus().send(message);
131 void MainWidget::paintEvent(QPaintEvent *event) {
134 p.setBrush(QColor(0, 0, 0, 255));
138 p.drawRoundedRect(rect(), 25, 25);