add more spacing
[personal-kdebase.git] / workspace / kcontrol / hardware / joystick / joystick.cpp
blobc6837afdc47bf39ee5f94dc650bff42bea935984
1 /***************************************************************************
2 * Copyright (C) 2003 by Martin Koller *
3 * m.koller@surfeu.at *
4 * This file is part of the KDE Control Center Module for Joysticks *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 ***************************************************************************/
22 #include "joystick.h"
23 #include "joywidget.h"
24 #include "joydevice.h"
26 #include <kaboutdata.h>
27 #include <kglobal.h>
28 #include <klocale.h>
29 #include <kdialog.h>
31 #include <stdio.h>
32 #include <KPluginFactory>
33 #include <KPluginLoader>
35 #include <QVBoxLayout>
36 //---------------------------------------------------------------------------------------------
38 K_PLUGIN_FACTORY(JoystickFactory,
39 registerPlugin<Joystick>();
41 K_EXPORT_PLUGIN(JoystickFactory("joystick"))
43 extern "C"
45 KDE_EXPORT bool test_joystick()
46 { /* Code stolen from JoyWidget::init() */
47 int i;
48 char dev[30];
50 for (i = 0; i < 5; i++) // check the first 5 devices
52 sprintf(dev, "/dev/js%d", i); // first look in /dev
53 JoyDevice *joy = new JoyDevice(dev);
55 if ( joy->open() != JoyDevice::SUCCESS )
57 delete joy;
58 sprintf(dev, "/dev/input/js%d", i); // then look in /dev/input
59 joy = new JoyDevice(dev);
61 if ( joy->open() != JoyDevice::SUCCESS )
63 delete joy;
64 continue; // try next number
68 return true; /* We have at least one joystick and should hence be shown */
70 return false;
74 //---------------------------------------------------------------------------------------------
76 Joystick::Joystick(QWidget *parent, const QVariantList &)
77 : KCModule(JoystickFactory::componentData(), parent)
79 setButtons(Help);
80 setAboutData(new KAboutData("kcmjoystick", 0, ki18n("KDE Joystick Control Module"), "1.0",
81 ki18n("KDE Control Center Module to test Joysticks"),
82 KAboutData::License_GPL, ki18n("(c) 2004, Martin Koller"),
83 KLocalizedString(), "m.koller@surfeu.at"));
85 setQuickHelp( i18n("<h1>Joystick</h1>"
86 "This module helps to check if your joystick is working correctly.<br />"
87 "If it delivers wrong values for the axes, you can try to solve this with "
88 "the calibration.<br />"
89 "This module tries to find all available joystick devices "
90 "by checking /dev/js[0-4] and /dev/input/js[0-4]<br />"
91 "If you have another device file, enter it in the combobox.<br />"
92 "The Buttons list shows the state of the buttons on your joystick, the Axes list "
93 "shows the current value for all axes.<br />"
94 "NOTE: the current Linux device driver (Kernel 2.4, 2.6) can only autodetect"
95 "<ul>"
96 "<li>2-axis, 4-button joystick</li>"
97 "<li>3-axis, 4-button joystick</li>"
98 "<li>4-axis, 4-button joystick</li>"
99 "<li>Saitek Cyborg 'digital' joysticks</li>"
100 "</ul>"
101 "(For details you can check your Linux source/Documentation/input/joystick.txt)"
104 joyWidget = new JoyWidget(this);
106 QVBoxLayout *top = new QVBoxLayout(this);
107 top->setMargin(0);
108 top->setSpacing(KDialog::spacingHint());
109 top->addWidget(joyWidget);
112 //---------------------------------------------------------------------------------------------
114 void Joystick::load()
116 joyWidget->init();
119 //---------------------------------------------------------------------------------------------
121 void Joystick::defaults()
123 joyWidget->resetCalibration();
125 emit changed(true);
128 //---------------------------------------------------------------------------------------------
130 #include "joystick.moc"