1/* This file is part of the KDE Project
2 Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library 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 GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#include "solidautoeject.h"
20
21#include <kpluginfactory.h>
22
23#include <solid/device.h>
24#include <solid/devicenotifier.h>
25#include <solid/opticaldrive.h>
26
27K_PLUGIN_FACTORY(SolidAutoEjectFactory, registerPlugin<SolidAutoEject>();)
28K_EXPORT_PLUGIN(SolidAutoEjectFactory("solidautoeject"))
29
30SolidAutoEject::SolidAutoEject(QObject* parent, const QList<QVariant>&)
31 : KDEDModule(parent)
32{
33 QList<Solid::Device> drives = Solid::Device::listFromQuery("IS OpticalDrive");
34 foreach (const Solid::Device &drive, drives) {
35 connectDevice(drive);
36 }
37
38 connect(Solid::DeviceNotifier::instance(), SIGNAL(deviceAdded(QString)),
39 this, SLOT(onDeviceAdded(QString)));
40}
41
42SolidAutoEject::~SolidAutoEject()
43{
44}
45
46void SolidAutoEject::onDeviceAdded(const QString &udi)
47{
48 connectDevice(Solid::Device(udi));
49}
50
51void SolidAutoEject::onEjectPressed(const QString &udi)
52{
53 Solid::Device dev(udi);
54 dev.as<Solid::OpticalDrive>()->eject();
55}
56
57void SolidAutoEject::connectDevice(const Solid::Device &device)
58{
59 if ( device.as<Solid::OpticalDrive>() ) {
60 connect(device.as<Solid::OpticalDrive>(), SIGNAL(ejectPressed(QString)),
61 this, SLOT(onEjectPressed(QString)));
62 }
63}
64
65#include "solidautoeject.moc"
66