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 HomeWidget::HomeWidget(QWidget *parent):
38 //setting application name, it will use it later to set home applet id
39 QCoreApplication::instance()->setApplicationName(
40 "mDictionary desktop widget");
42 //setting this attribute to get transparent backgorund
43 setAttribute(Qt::WA_TranslucentBackground);
51 void HomeWidget::initializeUI() {
54 horizontalLayout = new QHBoxLayout;
55 setLayout(horizontalLayout);
58 searchStringLineEdit = new QLineEdit;
60 searchButton = new QPushButton(tr("Search"));
61 searchButton->setMaximumHeight(60);
63 logo = new QToolButton();
64 logo->setIcon(QIcon(":/icons/64x64/mdictionary.png"));
66 horizontalLayout->addWidget(logo);
67 horizontalLayout->addWidget(searchStringLineEdit);
68 horizontalLayout->addWidget(searchButton);
69 horizontalLayout->setContentsMargins(10,10,10,10);
71 connect(searchStringLineEdit, SIGNAL(returnPressed()),
72 this, SLOT(search()));
74 connect(searchButton, SIGNAL(clicked()),
75 this, SLOT(search()));
77 connect(logo, SIGNAL(clicked()),
78 this, SLOT(logoClicked()));
81 setMinimumHeight(100);
82 setMaximumHeight(100);
85 void HomeWidget::initializeX11() {
87 Atom winTypeAtom = XInternAtom(QX11Info::display(),
88 "_NET_WM_WINDOW_TYPE",
91 Atom homeAppletAtom = XInternAtom(QX11Info::display(),
92 "_HILDON_WM_WINDOW_TYPE_HOME_APPLET",
95 Atom appletIDAtom = XInternAtom(QX11Info::display(),
99 Atom utf8Atom = XInternAtom(QX11Info::display(),
104 // Set window type to home applet
105 XChangeProperty(QX11Info::display(), winId(), winTypeAtom,
106 XA_ATOM, 32, PropModeReplace,
107 (unsigned char *) &homeAppletAtom, 1);
109 // Applet id will be the same as application name
111 QCoreApplication::instance()->applicationName().remove(' ').toUtf8());
114 XChangeProperty(QX11Info::display(), winId(), appletIDAtom, utf8Atom, 8,
115 PropModeReplace, (unsigned char *)id.constData(),
119 void HomeWidget::search() {
120 if(searchStringLineEdit->text().isEmpty()) return;
122 QDBusMessage message =
123 QDBusMessage::createMethodCall("com.comarch.mdictionary",
125 "com.comarch.mdictionary",
128 QList<QVariant> args;
129 args.append(searchStringLineEdit->text());
130 message.setArguments(args);
132 QDBusConnection::sessionBus().send(message);
134 searchStringLineEdit->clear();
137 void HomeWidget::logoClicked() {
138 QDBusMessage message =
139 QDBusMessage::createMethodCall("com.comarch.mdictionary",
141 "com.comarch.mdictionary",
143 QDBusConnection::sessionBus().send(message);
148 void HomeWidget::paintEvent(QPaintEvent *event) {
149 //custom painting of rounded corners
152 p.setBrush(palette().background());
156 p.drawRoundedRect(rect(), 25, 25);
160 QWidget::paintEvent(event);