2 * Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "krunnerdialog.h"
22 #include <QSvgRenderer>
23 #include <QResizeEvent>
24 #include <QMouseEvent>
31 #include <KWindowSystem>
32 #include <KPluginInfo>
34 #include <NETRootInfo>
37 #include "kworkspace/kdisplaymanager.h"
39 #include <Plasma/AbstractRunner>
40 #include <Plasma/FrameSvg>
41 #include <Plasma/RunnerManager>
42 #include <Plasma/Theme>
44 #include "configdialog.h"
45 #include "krunnerapp.h"
51 KRunnerDialog::KRunnerDialog(Plasma::RunnerManager
*runnerManager
, QWidget
*parent
, Qt::WindowFlags f
)
53 m_runnerManager(runnerManager
),
57 setWindowTitle( i18n("Run Command") );
58 setWindowIcon(KIcon("system-run"));
60 QPalette pal
= palette();
61 pal
.setColor(backgroundRole(), Qt::transparent
);
64 m_background
= new Plasma::FrameSvg(this);
65 m_iconSvg
= new Plasma::Svg(this);
68 // lock because setImagePath uses KSycoca
69 QMutexLocker
lock(Plasma::AbstractRunner::bigLock());
70 m_iconSvg
->setImagePath("widgets/configuration-icons");
71 m_background
->setImagePath("dialogs/krunner");
74 m_background
->setEnabledBorders(Plasma::FrameSvg::AllBorders
);
75 m_iconSvg
->setContainsMultipleImages(true);
76 m_iconSvg
->resize(KIconLoader::SizeSmall
, KIconLoader::SizeSmall
);
78 connect(m_background
, SIGNAL(repaintNeeded()), this, SLOT(update()));
80 connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(themeUpdated()));
84 KRunnerDialog::~KRunnerDialog()
88 void KRunnerDialog::setStaticQueryMode(bool staticQuery
)
93 void KRunnerDialog::switchUser()
95 KService::Ptr service
= KService::serviceByStorageId("plasma-runner-sessions.desktop");
96 KPluginInfo
info(service
);
101 dm
.localSessions(sessions
);
103 if (sessions
.isEmpty()) {
104 // no sessions to switch between, let's just start up another session directly
105 Plasma::AbstractRunner
*sessionRunner
= m_runnerManager
->runner(info
.pluginName());
107 Plasma::QueryMatch
switcher(sessionRunner
);
108 sessionRunner
->run(*m_runnerManager
->searchContext(), switcher
);
112 //TODO: create a "single runner" mode
113 //m_header->setText(i18n("Switch users"));
114 //m_header->setPixmap("system-switch-user");
116 //TODO: ugh, magic strings. See sessions/sessionrunner.cpp
117 setStaticQueryMode(true);
118 m_runnerManager
->launchQuery("SESSIONS", info
.pluginName());
123 void KRunnerDialog::showConfigDialog()
125 if (!m_configDialog
) {
126 m_configDialog
= new KRunnerConfigDialog(m_runnerManager
);
127 connect(m_configDialog
, SIGNAL(finished()), this, SLOT(configCompleted()));
130 KWindowSystem::setOnDesktop(m_configDialog
->winId(), KWindowSystem::currentDesktop());
131 KWindowSystem::activateWindow(m_configDialog
->winId());
132 m_configDialog
->show();
135 void KRunnerDialog::configCompleted()
137 m_configDialog
->deleteLater();
141 void KRunnerDialog::themeUpdated()
143 int margin
= marginHint();
144 const int topHeight
= qMax(0, int(m_background
->marginSize(Plasma::TopMargin
)) - margin
);
145 const int leftWidth
= qMax(0, int(m_background
->marginSize(Plasma::LeftMargin
)) - margin
);
146 const int rightWidth
= qMax(0, int(m_background
->marginSize(Plasma::RightMargin
)) - margin
);
147 const int bottomHeight
= qMax(0, int(m_background
->marginSize(Plasma::BottomMargin
)) - margin
);
149 setContentsMargins(leftWidth
, topHeight
, rightWidth
, bottomHeight
);
152 void KRunnerDialog::paintEvent(QPaintEvent
*e
)
155 p
.setRenderHint(QPainter::Antialiasing
);
156 p
.setClipRect(e
->rect());
157 //kDebug() << "clip rect set to: " << e->rect();
159 m_background
->paintFrame(&p
);
162 bool KRunnerDialog::event(QEvent
*event
)
164 if (event
->type() == QEvent::Paint
) {
166 p
.setCompositionMode(QPainter::CompositionMode_Source
);
167 p
.fillRect(rect(), Qt::transparent
);
170 return KDialog::event(event
);
173 void KRunnerDialog::resizeEvent(QResizeEvent
*e
)
175 m_background
->resizeFrame(e
->size());
177 /*FIXME for 4.3: now the clip mask always has to be on for disabling the KWin shadow,
178 in the future something better has to be done, and enable the mask only when compositing is active
179 if (!QX11Info::isCompositingManagerRunning()) {
180 setMask(m_background->mask());
183 setMask(m_background
->mask());
185 setMask(m_background
->mask());
187 KDialog::resizeEvent(e
);
190 void KRunnerDialog::mousePressEvent(QMouseEvent
*e
)
193 // We have to release the mouse grab before initiating the move operation.
194 // Ideally we would call releaseMouse() to do this, but when we only have an
195 // implicit passive grab, Qt is unaware of it, and will refuse to release it.
196 XUngrabPointer(x11Info().display(), CurrentTime
);
198 // Ask the window manager to start an interactive move operation.
199 NETRootInfo
rootInfo(x11Info().display(), NET::WMMoveResize
);
200 rootInfo
.moveResizeRequest(winId(), e
->globalX(), e
->globalY(), NET::Move
);
206 #include "krunnerdialog.moc"