~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcontrol/hardware/joystick/joystick.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 ***************************************************************************/
 
21
 
 
22
#include "joystick.h"
 
23
#include "joywidget.h"
 
24
#include "joydevice.h"
 
25
 
 
26
#include <kaboutdata.h>
 
27
#include <kglobal.h>
 
28
#include <klocale.h>
 
29
#include <kdialog.h>
 
30
 
 
31
#include <stdio.h>
 
32
#include <KPluginFactory>
 
33
#include <KPluginLoader>
 
34
 
 
35
#include <QVBoxLayout>
 
36
//---------------------------------------------------------------------------------------------
 
37
 
 
38
K_PLUGIN_FACTORY(JoystickFactory,
 
39
        registerPlugin<Joystick>();
 
40
        )
 
41
K_EXPORT_PLUGIN(JoystickFactory("joystick"))
 
42
 
 
43
extern "C"
 
44
{
 
45
  KDE_EXPORT bool test_joystick()
 
46
  { /* Code stolen from JoyWidget::init() */
 
47
    int i;
 
48
    char dev[30];
 
49
 
 
50
    for (i = 0; i < 5; i++)  // check the first 5 devices
 
51
    {
 
52
      sprintf(dev, "/dev/js%d", i);  // first look in /dev
 
53
      JoyDevice *joy = new JoyDevice(dev);
 
54
 
 
55
      if ( joy->open() != JoyDevice::SUCCESS )
 
56
      {
 
57
        delete joy;
 
58
        sprintf(dev, "/dev/input/js%d", i);  // then look in /dev/input
 
59
        joy = new JoyDevice(dev);
 
60
 
 
61
        if ( joy->open() != JoyDevice::SUCCESS )
 
62
        {
 
63
          delete joy;
 
64
          continue;    // try next number
 
65
        }
 
66
      }
 
67
 
 
68
      return true; /* We have at least one joystick and should hence be shown */
 
69
    }
 
70
    return false;
 
71
  }
 
72
}
 
73
 
 
74
//---------------------------------------------------------------------------------------------
 
75
 
 
76
Joystick::Joystick(QWidget *parent, const QVariantList &)
 
77
  : KCModule(JoystickFactory::componentData(), parent)
 
78
{
 
79
  setButtons(Help);
 
80
  setAboutData(new KAboutData("kcmjoystick", 0, ki18n("KDE Joystick Control Module"), "1.0",
 
81
                               ki18n("KDE System Settings Module to test Joysticks"),
 
82
                               KAboutData::License_GPL, ki18n("(c) 2004, Martin Koller"),
 
83
                               KLocalizedString(), "m.koller@surfeu.at"));
 
84
 
 
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)"
 
102
              ));
 
103
 
 
104
  joyWidget = new JoyWidget(this);
 
105
 
 
106
  QVBoxLayout *top = new QVBoxLayout(this);
 
107
  top->setMargin(0);
 
108
  top->setSpacing(KDialog::spacingHint());
 
109
  top->addWidget(joyWidget);
 
110
}
 
111
 
 
112
//---------------------------------------------------------------------------------------------
 
113
 
 
114
void Joystick::load()
 
115
{
 
116
  joyWidget->init();
 
117
}
 
118
 
 
119
//---------------------------------------------------------------------------------------------
 
120
 
 
121
void Joystick::defaults()
 
122
{
 
123
  joyWidget->resetCalibration();
 
124
 
 
125
  emit changed(true);
 
126
}
 
127
 
 
128
//---------------------------------------------------------------------------------------------
 
129
 
 
130
#include "joystick.moc"