add more spacing
[personal-kdebase.git] / runtime / soliduiserver / deviceactionsdialog.cpp
blob53abe34baa17c52c08e728284b4a53ccf406c62f
1 /* This file is part of the KDE Project
2 Copyright (c) 2005 Jean-Remy Falleri <jr.falleri@laposte.net>
3 Copyright (c) 2005-2007 Kevin Ottens <ervin@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "deviceactionsdialog.h"
21 #include <QtGui/QLayout>
23 #include <krun.h>
24 #include <klocale.h>
25 #include <kstandarddirs.h>
26 #include <kio/global.h>
27 #include <klistwidget.h>
28 #include <QCheckBox>
31 #include "deviceaction.h"
32 #include "ui_deviceactionsdialogview.h"
34 DeviceActionsDialog::DeviceActionsDialog(QWidget *parent)
35 : KDialog(parent)
37 setModal(false);
38 setButtons(Ok|Cancel);
39 setDefaultButton(Ok);
40 showButtonSeparator(true);
42 QWidget *page = new QWidget(this);
43 m_view.setupUi(page);
44 setMainWidget(page);
45 updateActionsListBox();
47 resize(QSize(400,400).expandedTo(minimumSizeHint()));
49 connect(this, SIGNAL(okClicked()),
50 this, SLOT(slotOk()));
51 connect(m_view.actionsList, SIGNAL(doubleClicked(QListWidgetItem *, const QPoint &)),
52 this, SLOT(slotOk()));
54 connect(this, SIGNAL(finished()),
55 this, SLOT(delayedDestruct()));
58 DeviceActionsDialog::~DeviceActionsDialog()
62 void DeviceActionsDialog::setDevice(const Solid::Device &device)
64 m_device = device;
66 QString label = device.vendor();
67 if (!label.isEmpty()) label+=' ';
68 label+= device.product();
70 setWindowTitle(label);
72 m_view.iconLabel->setPixmap(KIcon(device.icon()).pixmap(64));
73 m_view.descriptionLabel->setText(device.vendor()+' '+device.product());
74 setWindowIcon(KIcon(device.icon()));
77 Solid::Device DeviceActionsDialog::device() const
79 return m_device;
82 void DeviceActionsDialog::setActions(const QList<DeviceAction*> &actions)
84 qDeleteAll(m_actions);
85 m_actions.clear();
87 m_actions = actions;
89 updateActionsListBox();
92 QList<DeviceAction*> DeviceActionsDialog::actions() const
94 return m_actions;
97 void DeviceActionsDialog::updateActionsListBox()
99 m_view.actionsList->clear();
101 foreach (DeviceAction *action, m_actions) {
102 QListWidgetItem *item = new QListWidgetItem(KIcon(action->iconName()),
103 action->label());
104 item->setData(Qt::UserRole, action->id());
105 m_view.actionsList->addItem(item);
108 if (m_view.actionsList->count()>0)
109 m_view.actionsList->item(0)->setSelected(true);
112 void DeviceActionsDialog::slotOk()
114 QListWidgetItem *item = m_view.actionsList->selectedItems().value(0);
116 if (item != 0L) {
117 QString id = item->data(Qt::UserRole).toString();
119 foreach (DeviceAction *action, m_actions) {
120 if (action->id()==id) {
121 launchAction(action);
122 return;
128 void DeviceActionsDialog::launchAction(DeviceAction *action)
130 action->execute(m_device);
131 close();
134 #include "deviceactionsdialog.moc"