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 /*! \file MainWidget.cpp
23 \brief Implements widget for maemo that allows user to search quickly right from home screen using mdictionary.
25 \author Mateusz Półrola <mateusz.polrola@comarch.pl>
28 #include "MainWidget.h"
31 #include <X11/Xatom.h>
32 #include <QtGui/QX11Info>
33 #include <QtDBus/QDBusMessage>
34 #include <QtDBus/QDBusPendingCall>
39 HomeWidget::HomeWidget(QWidget *parent):
42 //setting application name, it will use it later to set home applet id
43 QCoreApplication::instance()->setApplicationName(
44 "mDictionary desktop widget");
46 //setting this attribute to get transparent backgorund
47 setAttribute(Qt::WA_TranslucentBackground);
55 void HomeWidget::initializeUI() {
58 horizontalLayout = new QHBoxLayout;
59 setLayout(horizontalLayout);
62 searchStringLineEdit = new QLineEdit;
64 searchButton = new QPushButton(tr("Search"));
65 searchButton->setMaximumHeight(60);
67 logo = new QToolButton();
68 logo->setIcon(QIcon(":/icons/64x64/mdictionary.png"));
70 horizontalLayout->addWidget(logo);
71 horizontalLayout->addWidget(searchStringLineEdit);
72 horizontalLayout->addWidget(searchButton);
73 horizontalLayout->setContentsMargins(10,10,10,10);
75 connect(searchStringLineEdit, SIGNAL(returnPressed()),
76 this, SLOT(search()));
78 connect(searchButton, SIGNAL(clicked()),
79 this, SLOT(search()));
81 connect(logo, SIGNAL(clicked()),
82 this, SLOT(logoClicked()));
85 setMinimumHeight(100);
86 setMaximumHeight(100);
89 void HomeWidget::initializeX11() {
91 Atom winTypeAtom = XInternAtom(QX11Info::display(),
92 "_NET_WM_WINDOW_TYPE",
95 Atom homeAppletAtom = XInternAtom(QX11Info::display(),
96 "_HILDON_WM_WINDOW_TYPE_HOME_APPLET",
99 Atom appletIDAtom = XInternAtom(QX11Info::display(),
103 Atom utf8Atom = XInternAtom(QX11Info::display(),
108 // Set window type to home applet
109 XChangeProperty(QX11Info::display(), winId(), winTypeAtom,
110 XA_ATOM, 32, PropModeReplace,
111 (unsigned char *) &homeAppletAtom, 1);
113 // Applet id will be the same as application name
115 QCoreApplication::instance()->applicationName().remove(' ').toUtf8());
118 XChangeProperty(QX11Info::display(), winId(), appletIDAtom, utf8Atom, 8,
119 PropModeReplace, (unsigned char *)id.constData(),
123 void HomeWidget::search() {
124 if(searchStringLineEdit->text().isEmpty()) return;
126 QDBusMessage message =
127 QDBusMessage::createMethodCall("com.comarch.mdictionary",
129 "com.comarch.mdictionary",
132 QList<QVariant> args;
133 args.append(searchStringLineEdit->text());
134 message.setArguments(args);
136 QDBusConnection::sessionBus().send(message);
138 searchStringLineEdit->clear();
141 void HomeWidget::logoClicked() {
142 QDBusMessage message =
143 QDBusMessage::createMethodCall("com.comarch.mdictionary",
145 "com.comarch.mdictionary",
147 QDBusConnection::sessionBus().send(message);
152 void HomeWidget::paintEvent(QPaintEvent *event) {
153 //custom painting of rounded corners
156 p.setBrush(palette().background());
160 p.drawRoundedRect(rect(), 25, 25);
164 QWidget::paintEvent(event);