diff --git a/kcms/componentchooser/componentchooser.cpp b/kcms/componentchooser/componentchooser.cpp index 388a560f9..bf94bcc4e 100644 --- a/kcms/componentchooser/componentchooser.cpp +++ b/kcms/componentchooser/componentchooser.cpp @@ -1,257 +1,256 @@ /*************************************************************************** componentchooser.cpp - description ------------------- copyright : (C) 2002 by Joseph Wenninger email : jowenn@kde.org ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License verstion 2 as * * published by the Free Software Foundation * * * ***************************************************************************/ #include "componentchooser.h" #include "componentchooserbrowser.h" #include "componentchooseremail.h" #include "componentchooserfilemanager.h" #ifdef Q_OS_UNIX #include "componentchooserterminal.h" #endif #include -#include #include #include #include #include #include #include #include #include #include #include #include //BEGIN General kpart based Component selection CfgComponent::CfgComponent(QWidget *parent) : QWidget(parent), Ui::ComponentConfig_UI(), CfgPlugin() { setupUi( this ); connect(ComponentSelector,SIGNAL(activated(const QString&)),this,SLOT(slotComponentChanged(const QString&))); } CfgComponent::~CfgComponent() { } void CfgComponent::slotComponentChanged(const QString&) { emit changed(true); } void CfgComponent::save(KConfig *cfg) { // yes, this can happen if there are NO KTrader offers for this component if (!m_lookupDict.contains(ComponentSelector->currentText())) return; KConfigGroup mainGroup = cfg->group(QByteArray()); QString serviceTypeToConfigure=mainGroup.readEntry("ServiceTypeToConfigure"); KConfig store(mainGroup.readPathEntry("storeInFile", QStringLiteral("null"))); KConfigGroup cg(&store, mainGroup.readEntry("valueSection")); cg.writePathEntry(mainGroup.readEntry("valueName", "kcm_componenchooser_null"), m_lookupDict.value(ComponentSelector->currentText())); store.sync(); emit changed(false); } void CfgComponent::load(KConfig *cfg) { ComponentSelector->clear(); m_lookupDict.clear(); m_revLookupDict.clear(); const KConfigGroup mainGroup = cfg->group(QByteArray()); const QString serviceTypeToConfigure = mainGroup.readEntry("ServiceTypeToConfigure"); const KService::List offers = KServiceTypeTrader::self()->query(serviceTypeToConfigure); for (KService::List::const_iterator tit = offers.begin(); tit != offers.end(); ++tit) { ComponentSelector->addItem((*tit)->name()); m_lookupDict.insert((*tit)->name(), (*tit)->desktopEntryName()); m_revLookupDict.insert((*tit)->desktopEntryName(), (*tit)->name()); } KConfig store(mainGroup.readPathEntry("storeInFile",QStringLiteral("null"))); const KConfigGroup group(&store, mainGroup.readEntry("valueSection")); QString setting = group.readEntry(mainGroup.readEntry("valueName","kcm_componenchooser_null"), QString()); if (setting.isEmpty()) setting = mainGroup.readEntry("defaultImplementation", QString()); QString tmp = m_revLookupDict.value(setting); if (!tmp.isEmpty()) { for (int i=0;icount();i++) if (tmp==ComponentSelector->itemText(i)) { ComponentSelector->setCurrentIndex(i); break; } } emit changed(false); } void CfgComponent::defaults() { //todo } //END General kpart based Component selection ComponentChooser::ComponentChooser(QWidget *parent): QWidget(parent), Ui::ComponentChooser_UI(), somethingChanged(false), configWidget(nullptr) { setupUi(this); static_cast(layout())->setRowStretch(1, 1); const QStringList services=KGlobal::dirs()->findAllResources( "data",QStringLiteral("kcm_componentchooser/*.desktop"), KStandardDirs::NoDuplicates); for (QStringList::const_iterator it=services.constBegin(); it!=services.constEnd(); ++it) { KConfig cfg(*it, KConfig::SimpleConfig); KConfigGroup cg = cfg.group(QByteArray()); QListWidgetItem *item = new QListWidgetItem( QIcon::fromTheme(cg.readEntry("Icon",QStringLiteral("preferences-desktop-default-applications"))), cg.readEntry("Name",i18n("Unknown"))); item->setData(Qt::UserRole, (*it)); ServiceChooser->addItem(item); loadConfigWidget((*it), cfg.group(QByteArray()).readEntry("configurationType"), item->text()); } ServiceChooser->setFixedWidth(ServiceChooser->sizeHintForColumn(0) + 20); ServiceChooser->sortItems(); connect(ServiceChooser,&QListWidget::currentItemChanged,this,&ComponentChooser::slotServiceSelected); ServiceChooser->setCurrentRow(0); } void ComponentChooser::loadConfigWidget(const QString &service, const QString &cfgType, const QString &name) { QWidget *loadedConfigWidget = nullptr; if (cfgType.isEmpty() || (cfgType == QLatin1String("component"))) { loadedConfigWidget = new CfgComponent(configContainer); static_cast(loadedConfigWidget)->ChooserDocu->setText(i18n("Choose from the list below which component should be used by default for the %1 service.", name)); } else if (cfgType==QLatin1String("internal_email")) { loadedConfigWidget = new CfgEmailClient(configContainer); } #ifdef Q_OS_UNIX else if (cfgType==QLatin1String("internal_terminal")) { loadedConfigWidget = new CfgTerminalEmulator(configContainer); } #endif else if (cfgType==QLatin1String("internal_filemanager")) { loadedConfigWidget = new CfgFileManager(configContainer); } else if (cfgType==QLatin1String("internal_browser")) { loadedConfigWidget = new CfgBrowser(configContainer); } if (loadedConfigWidget) { configWidgetMap.insert(service, loadedConfigWidget); configContainer->addWidget(loadedConfigWidget); connect(loadedConfigWidget, SIGNAL(changed(bool)), this, SLOT(emitChanged(bool))); } } void ComponentChooser::slotServiceSelected(QListWidgetItem* it) { if (!it) return; if (somethingChanged) { if (KMessageBox::questionYesNo(this,i18n("You changed the default component of your choice, do want to save that change now ?"),QString(),KStandardGuiItem::save(),KStandardGuiItem::discard())==KMessageBox::Yes) save(); } const QString &service = it->data(Qt::UserRole).toString(); KConfig cfg(service, KConfig::SimpleConfig); ComponentDescription->setText(cfg.group(QByteArray()).readEntry("Comment",i18n("No description available"))); ComponentDescription->setMinimumSize(ComponentDescription->sizeHint()); configWidget = configWidgetMap.value(service); if (configWidget) { configContainer->setCurrentWidget(configWidget); dynamic_cast(configWidget)->load(&cfg); } emitChanged(false); latestEditedService = service; } void ComponentChooser::emitChanged(bool val) { somethingChanged=val; emit changed(val); } ComponentChooser::~ComponentChooser() { for (QWidget *configWidget : configWidgetMap) { delete configWidget; } } void ComponentChooser::load() { if( configWidget ) { CfgPlugin * plugin = dynamic_cast( configWidget ); if( plugin ) { KConfig cfg(latestEditedService, KConfig::SimpleConfig); plugin->load( &cfg ); } } } void ComponentChooser::save() { if( configWidget ) { CfgPlugin* plugin = dynamic_cast( configWidget ); if( plugin ) { KConfig cfg(latestEditedService, KConfig::SimpleConfig); plugin->save( &cfg ); } } } void ComponentChooser::restoreDefault() { if (configWidget) { dynamic_cast(configWidget)->defaults(); emitChanged(true); } /* txtEMailClient->setText("kmail"); chkRunTerminal->setChecked(false); // Check if -e is needed, I do not think so terminalLE->setText("xterm"); //No need for i18n terminalCB->setChecked(true); emitChanged(false); */ } // vim: sw=4 ts=4 noet diff --git a/kcms/componentchooser/componentchooserterminal.cpp b/kcms/componentchooser/componentchooserterminal.cpp index 12582e943..aa715086b 100644 --- a/kcms/componentchooser/componentchooserterminal.cpp +++ b/kcms/componentchooser/componentchooserterminal.cpp @@ -1,115 +1,114 @@ /*************************************************************************** componentchooser.cpp - description ------------------- copyright : (C) 2002 by Joseph Wenninger email : jowenn@kde.org ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License verstion 2 as * * published by the Free Software Foundation * * * ***************************************************************************/ #include "componentchooserterminal.h" #include #include #include #include #include -#include #include #include #include #include #include #include #include #include #include #include "../migrationlib/kdelibs4config.h" CfgTerminalEmulator::CfgTerminalEmulator(QWidget *parent) : QWidget(parent), Ui::TerminalEmulatorConfig_UI(), CfgPlugin() { setupUi(this); connect(terminalLE, &QLineEdit::textChanged, this, &CfgTerminalEmulator::configChanged); connect(terminalCB, &QRadioButton::toggled, this, &CfgTerminalEmulator::configChanged); connect(otherCB, &QRadioButton::toggled, this, &CfgTerminalEmulator::configChanged); connect(btnSelectTerminal, &QToolButton::clicked, this, &CfgTerminalEmulator::selectTerminalApp); } CfgTerminalEmulator::~CfgTerminalEmulator() { } void CfgTerminalEmulator::configChanged() { emit changed(true); } void CfgTerminalEmulator::defaults() { load(nullptr); } void CfgTerminalEmulator::load(KConfig *) { KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "General"); QString terminal = config.readPathEntry("TerminalApplication",QStringLiteral("konsole")); if (terminal == QLatin1String("konsole")) { terminalLE->setText(QStringLiteral("xterm")); terminalCB->setChecked(true); } else { terminalLE->setText(terminal); otherCB->setChecked(true); } emit changed(false); } void CfgTerminalEmulator::save(KConfig *) { KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); KConfigGroup config(profile, QStringLiteral("General")); const QString terminal = terminalCB->isChecked() ? QStringLiteral("konsole") : terminalLE->text(); config.writePathEntry("TerminalApplication", terminal); // KConfig::Normal|KConfig::Global); config.sync(); Kdelibs4SharedConfig::syncConfigGroup(QLatin1String("General"), "kdeglobals"); KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged); QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.klauncher5"), QStringLiteral("/KLauncher"), QStringLiteral("org.kde.KLauncher"), QStringLiteral("reparseConfiguration")); QDBusConnection::sessionBus().send(message); emit changed(false); } void CfgTerminalEmulator::selectTerminalApp() { QList urlList; KOpenWithDialog dlg(urlList, i18n("Select preferred terminal application:"), QString(), this); // hide "Run in &terminal" here, we don't need it for a Terminal Application dlg.hideRunInTerminal(); if (dlg.exec() != QDialog::Accepted) return; QString client = dlg.text(); if (!client.isEmpty()) { terminalLE->setText(client); } } // vim: sw=4 ts=4 noet diff --git a/kcms/dateandtime/dtime.cpp b/kcms/dateandtime/dtime.cpp index 5833caec9..c0543aa45 100644 --- a/kcms/dateandtime/dtime.cpp +++ b/kcms/dateandtime/dtime.cpp @@ -1,490 +1,489 @@ /* * dtime.cpp * * Copyright (C) 1998 Luca Montecchiani * * Plasma analog-clock drawing code: * * Copyright 2007 by Aaron Seigo * Copyright 2007 by Riccardo Iaconelli * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #include "dtime.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#include #include #include #include #include #include #include #include #include #include #include #include "timedated_interface.h" #include "helper.h" Dtime::Dtime(QWidget * parent, bool haveTimeDated): QWidget(parent), m_haveTimedated(haveTimeDated) { setupUi(this); connect(setDateTimeAuto, &QCheckBox::toggled, this, &Dtime::serverTimeCheck); connect(setDateTimeAuto, &QCheckBox::toggled, this, &Dtime::configChanged); timeServerList->setEditable(false); connect(timeServerList, static_cast(&QComboBox::activated), this, &Dtime::configChanged); connect(timeServerList, &QComboBox::editTextChanged, this, &Dtime::configChanged); connect(setDateTimeAuto, &QCheckBox::toggled, timeServerList, &QComboBox::setEnabled); timeServerList->setEnabled(false); timeServerList->setEditable(true); if (!haveTimeDated) { findNTPutility(); if (ntpUtility.isEmpty()) { QString toolTip = i18n("No NTP utility has been found. " "Install 'ntpdate' or 'rdate' command to enable automatic " "updating of date and time."); setDateTimeAuto->setEnabled(false); setDateTimeAuto->setToolTip(toolTip); timeServerList->setToolTip(toolTip); } } QVBoxLayout *v2 = new QVBoxLayout( timeBox ); v2->setMargin( 0 ); kclock = new Kclock( timeBox ); kclock->setObjectName(QStringLiteral("Kclock")); kclock->setMinimumSize(150,150); v2->addWidget( kclock ); v2->addSpacing( KDialog::spacingHint() ); QHBoxLayout *v3 = new QHBoxLayout( ); v2->addLayout( v3 ); v3->addStretch(); timeEdit = new QTimeEdit( timeBox ); timeEdit->setWrapping(true); timeEdit->setDisplayFormat(KLocale::global()->use12Clock() ? "hh:mm:ss ap" : "HH:mm:ss"); v3->addWidget(timeEdit); v3->addStretch(); QString wtstr = i18n("Here you can change the system time. Click into the" " hours, minutes or seconds field to change the relevant value, either" " using the up and down buttons to the right or by entering a new value."); timeEdit->setWhatsThis( wtstr ); connect(timeEdit, &QTimeEdit::timeChanged, this, &Dtime::set_time); connect(cal, &KDatePicker::dateChanged, this, &Dtime::changeDate); connect(&internalTimer, &QTimer::timeout, this, &Dtime::timeout); kclock->setEnabled(false); //Timezone connect(tzonelist, &K4TimeZoneWidget::itemSelectionChanged, this, &Dtime::configChanged); tzonesearch->setTreeWidget(tzonelist); } void Dtime::currentZone() { KTimeZone localZone = KSystemTimeZones::local(); if (localZone.abbreviations().isEmpty()) { m_local->setText(i18nc("%1 is name of time zone", "Current local time zone: %1", K4TimeZoneWidget::displayName(localZone))); } else { m_local->setText(i18nc("%1 is name of time zone, %2 is its abbreviation", "Current local time zone: %1 (%2)", K4TimeZoneWidget::displayName(localZone), QString::fromUtf8(localZone.abbreviations().first()))); } } void Dtime::serverTimeCheck() { // Enable time and date if the ntp utility is missing bool enabled = ntpUtility.isEmpty() || !setDateTimeAuto->isChecked(); cal->setEnabled(enabled); timeEdit->setEnabled(enabled); //kclock->setEnabled(enabled); } void Dtime::findNTPutility(){ QByteArray envpath = qgetenv("PATH"); if (!envpath.isEmpty() && envpath.startsWith(':')) { envpath.remove(0, 1); } QString path = QStringLiteral("/sbin:/usr/sbin:"); if (!envpath.isEmpty()) { path += QFile::decodeName(envpath); } else { path += QLatin1String("/bin:/usr/bin"); } foreach(const QString &possible_ntputility, QStringList() << "ntpdate" << "rdate" ) { if( !((ntpUtility = KStandardDirs::findExe(possible_ntputility, path)).isEmpty()) ) { qDebug() << "ntpUtility = " << ntpUtility; return; } } qDebug() << "ntpUtility not found!"; } void Dtime::set_time() { if( ontimeout ) return; internalTimer.stop(); time = timeEdit->time(); kclock->setTime( time ); emit timeChanged( true ); } void Dtime::changeDate(const QDate &d) { date = d; emit timeChanged( true ); } void Dtime::configChanged(){ emit timeChanged( true ); } void Dtime::load() { QString currentTimeZone; if (m_haveTimedated) { OrgFreedesktopTimedate1Interface timeDatedIface(QStringLiteral("org.freedesktop.timedate1"), QStringLiteral("/org/freedesktop/timedate1"), QDBusConnection::systemBus()); //the server list is not relevant for timesyncd, it fetches it from the network timeServerList->setVisible(false); timeServerLabel->setVisible(false); setDateTimeAuto->setEnabled(timeDatedIface.canNTP()); setDateTimeAuto->setChecked(timeDatedIface.nTP()); currentTimeZone = timeDatedIface.timezone(); } else { // The config is actually written to the system config, but the user does not have any local config, // since there is nothing writing it. KConfig _config( QStringLiteral("kcmclockrc"), KConfig::NoGlobals ); KConfigGroup config(&_config, "NTP"); timeServerList->clear(); timeServerList->addItems(config.readEntry("servers", i18n("Public Time Server (pool.ntp.org),\ asia.pool.ntp.org,\ europe.pool.ntp.org,\ north-america.pool.ntp.org,\ oceania.pool.ntp.org")).split(',', QString::SkipEmptyParts)); setDateTimeAuto->setChecked(config.readEntry("enabled", false)); if (ntpUtility.isEmpty()) { timeServerList->setEnabled(false); } currentTimeZone = KSystemTimeZones::local().name(); } // Reset to the current date and time time = QTime::currentTime(); date = QDate::currentDate(); cal->setDate(date); // start internal timer internalTimer.start( 1000 ); timeout(); //Timezone currentZone(); tzonelist->setSelected(currentTimeZone, true); emit timeChanged(false); } QString Dtime::selectedTimeZone() const { QStringList selectedZones(tzonelist->selection()); if (!selectedZones.isEmpty()) { return selectedZones.first(); } return QString(); } QStringList Dtime::ntpServers() const { // Save the order, but don't duplicate! QStringList list; if( timeServerList->count() != 0) list.append(timeServerList->currentText()); for ( int i=0; icount();i++ ) { QString text = timeServerList->itemText(i); if( !list.contains(text) ) list.append(text); // Limit so errors can go away and not stored forever if( list.count() == 10) break; } return list; } bool Dtime::ntpEnabled() const { return setDateTimeAuto->isChecked(); } QDateTime Dtime::userTime() const { return QDateTime(date, QTime(timeEdit->time())); } void Dtime::processHelperErrors( int code ) { if( code & ClockHelper::NTPError ) { KMessageBox::error( this, i18n("Unable to contact time server: %1.", timeServer) ); setDateTimeAuto->setChecked( false ); } if( code & ClockHelper::DateError ) { KMessageBox::error( this, i18n("Can not set date.")); } if( code & ClockHelper::TimezoneError) KMessageBox::error( this, i18n("Error setting new time zone."), i18n("Time zone Error")); } void Dtime::timeout() { // get current time time = QTime::currentTime(); ontimeout = true; timeEdit->setTime(time); ontimeout = false; kclock->setTime( time ); } QString Dtime::quickHelp() const { return i18n("

Date & Time

This system settings module can be used to set the system date and" " time. As these settings do not only affect you as a user, but rather the whole system, you" " can only change these settings when you start the System Settings as root. If you do not have" " the root password, but feel the system time should be corrected, please contact your system" " administrator."); } Kclock::Kclock(QWidget *parent) : QWidget(parent) { m_theme = new Plasma::Svg(this); m_theme->setImagePath(QStringLiteral("widgets/clock")); m_theme->setContainsMultipleImages(true); } Kclock::~Kclock() { delete m_theme; } void Kclock::showEvent( QShowEvent *event ) { setClockSize( size() ); QWidget::showEvent( event ); } void Kclock::resizeEvent( QResizeEvent * ) { setClockSize( size() ); } void Kclock::setClockSize(const QSize &size) { int dim = qMin(size.width(), size.height()); QSize newSize = QSize(dim, dim) * devicePixelRatioF(); if (newSize != m_faceCache.size()) { m_faceCache = QPixmap(newSize); m_handsCache = QPixmap(newSize); m_glassCache = QPixmap(newSize); m_faceCache.setDevicePixelRatio(devicePixelRatioF()); m_handsCache.setDevicePixelRatio(devicePixelRatioF()); m_glassCache.setDevicePixelRatio(devicePixelRatioF()); m_theme->resize(QSize(dim, dim)); m_repaintCache = RepaintAll; } } void Kclock::setTime(const QTime &time) { if (time.minute() != this->time.minute() || time.hour() != this->time.hour()) { if (m_repaintCache == RepaintNone) { m_repaintCache = RepaintHands; } } this->time = time; update(); } void Kclock::drawHand(QPainter *p, const QRect &rect, const qreal verticalTranslation, const qreal rotation, const QString &handName) { // this code assumes the following conventions in the svg file: // - the _vertical_ position of the hands should be set with respect to the center of the face // - the _horizontal_ position of the hands does not matter // - the _shadow_ elements should have the same vertical position as their _hand_ element counterpart QRectF elementRect; QString name = handName + "HandShadow"; if (m_theme->hasElement(name)) { p->save(); elementRect = m_theme->elementRect(name); if( rect.height() < 64 ) elementRect.setWidth( elementRect.width() * 2.5 ); static const QPoint offset = QPoint(2, 3); p->translate(rect.x() + (rect.width() / 2) + offset.x(), rect.y() + (rect.height() / 2) + offset.y()); p->rotate(rotation); p->translate(-elementRect.width()/2, elementRect.y()-verticalTranslation); m_theme->paint(p, QRectF(QPointF(0, 0), elementRect.size()), name); p->restore(); } p->save(); name = handName + "Hand"; elementRect = m_theme->elementRect(name); if (rect.height() < 64) { elementRect.setWidth(elementRect.width() * 2.5); } p->translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2); p->rotate(rotation); p->translate(-elementRect.width()/2, elementRect.y()-verticalTranslation); m_theme->paint(p, QRectF(QPointF(0, 0), elementRect.size()), name); p->restore(); } void Kclock::paintInterface(QPainter *p, const QRect &rect) { const bool m_showSecondHand = true; // compute hand angles const qreal minutes = 6.0 * time.minute() - 180; const qreal hours = 30.0 * time.hour() - 180 + ((time.minute() / 59.0) * 30.0); qreal seconds = 0; if (m_showSecondHand) { static const double anglePerSec = 6; seconds = anglePerSec * time.second() - 180; } // paint face and glass cache QRect faceRect = m_faceCache.rect(); QRect targetRect = QRect(QPoint(0, 0), QSize(m_faceCache.width() / devicePixelRatioF(), m_faceCache.height() / devicePixelRatioF())); if (m_repaintCache == RepaintAll) { m_faceCache.fill(Qt::transparent); m_glassCache.fill(Qt::transparent); QPainter facePainter(&m_faceCache); QPainter glassPainter(&m_glassCache); facePainter.setRenderHint(QPainter::SmoothPixmapTransform); glassPainter.setRenderHint(QPainter::SmoothPixmapTransform); m_theme->paint(&facePainter, targetRect, QStringLiteral("ClockFace")); glassPainter.save(); QRectF elementRect = QRectF(QPointF(0, 0), m_theme->elementSize(QStringLiteral("HandCenterScrew"))); glassPainter.translate(faceRect.width() / (2 * devicePixelRatioF()) - elementRect.width() / 2, faceRect.height() / (2 * devicePixelRatioF()) - elementRect.height() / 2); m_theme->paint(&glassPainter, elementRect, QStringLiteral("HandCenterScrew")); glassPainter.restore(); m_theme->paint(&glassPainter, targetRect, QStringLiteral("Glass")); // get vertical translation, see drawHand() for more details m_verticalTranslation = m_theme->elementRect(QStringLiteral("ClockFace")).center().y(); } // paint hour and minute hands cache if (m_repaintCache == RepaintHands || m_repaintCache == RepaintAll) { m_handsCache.fill(Qt::transparent); QPainter handsPainter(&m_handsCache); handsPainter.drawPixmap(targetRect, m_faceCache, faceRect); handsPainter.setRenderHint(QPainter::SmoothPixmapTransform); drawHand(&handsPainter, targetRect, m_verticalTranslation, hours, QStringLiteral("Hour")); drawHand(&handsPainter, targetRect, m_verticalTranslation, minutes, QStringLiteral("Minute")); } // reset repaint cache flag m_repaintCache = RepaintNone; // paint caches and second hand if (targetRect.width() < rect.width()) { targetRect.moveLeft((rect.width() - targetRect.width()) / 2); } p->drawPixmap(targetRect, m_handsCache, faceRect); if (m_showSecondHand) { p->setRenderHint(QPainter::SmoothPixmapTransform); drawHand(p, targetRect, m_verticalTranslation, seconds, QStringLiteral("Second")); } p->drawPixmap(targetRect, m_glassCache, faceRect); } void Kclock::paintEvent( QPaintEvent * ) { QPainter paint(this); paint.setRenderHint(QPainter::Antialiasing); paintInterface(&paint, rect()); } diff --git a/kcms/hardware/joystick/joydevice.cpp b/kcms/hardware/joystick/joydevice.cpp index a60ca74fa..16196e3fd 100644 --- a/kcms/hardware/joystick/joydevice.cpp +++ b/kcms/hardware/joystick/joydevice.cpp @@ -1,407 +1,406 @@ /*************************************************************************** * Copyright (C) 2003 by Martin Koller * * kollix@aon.at * * This file is part of the KDE Control Center Module for Joysticks * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "joydevice.h" -#include #include #include #include #include #include #include #include #include #include #include #include //-------------------------------------------------------------- JoyDevice::JoyDevice(const QString &devicefile) : devName(devicefile), joyFd(-1), buttons(0), axes(0), amin(nullptr), amax(nullptr), corr(nullptr), origCorr(nullptr) { } //-------------------------------------------------------------- QString JoyDevice::errText(ErrorCode code) const { switch ( code ) { case SUCCESS: return QLatin1String(""); case OPEN_FAILED: { return i18n("The given device %1 could not be opened: %2", devName, strerror(errno)); } case NO_JOYSTICK: { return i18n("The given device %1 is not a joystick.", devName); } case ERR_GET_VERSION: { return i18n("Could not get kernel driver version for joystick device %1: %2", devName, strerror(errno)); } case WRONG_VERSION: { int version = 0; int fd = ::open(devName.toLatin1(), O_RDONLY); if ( fd != -1 ) { ::ioctl(fd, JSIOCGVERSION, &version); ::close(fd); } KLocalizedString loc = ki18n("The current running kernel driver version (%1.%2.%3) is not the one this module was compiled for (%4.%5.%6)."); loc = loc.subs(version >> 16); loc = loc.subs((version >> 8) & 0xFF); loc = loc.subs(version & 0xFF); loc = loc.subs(JS_VERSION >> 16); loc = loc.subs((JS_VERSION >> 8) & 0xFF); loc = loc.subs(JS_VERSION & 0xFF); return loc.toString(); } case ERR_GET_BUTTONS: { return i18n("Could not get number of buttons for joystick device %1: %2", devName, strerror(errno)); } case ERR_GET_AXES: { return i18n("Could not get number of axes for joystick device %1: %2", devName, strerror(errno)); } case ERR_GET_CORR: { return i18n("Could not get calibration values for joystick device %1: %2", devName, strerror(errno)); } case ERR_RESTORE_CORR: { return i18n("Could not restore calibration values for joystick device %1: %2", devName, strerror(errno)); } case ERR_INIT_CAL: { return i18n("Could not initialize calibration values for joystick device %1: %2", devName, strerror(errno)); } case ERR_APPLY_CAL: { return i18n("Could not apply calibration values for joystick device %1: %2", devName, strerror(errno)); } default: return i18n("internal error - code %1 unknown", int(code)); } } //-------------------------------------------------------------- JoyDevice::ErrorCode JoyDevice::open() { if ( joyFd != -1 ) return JoyDevice::SUCCESS; // already open int fd = ::open(devName.toLatin1(), O_RDONLY); if ( fd == -1 ) return JoyDevice::OPEN_FAILED; // we could open the devicefile, now check if a joystick is attached char name[128]; if ( ::ioctl(fd, JSIOCGNAME(sizeof(name)), &name) == -1 ) { ::close(fd); return JoyDevice::NO_JOYSTICK; } // check the kernel driver version int version; if ( ::ioctl(fd, JSIOCGVERSION, &version) == -1 ) { ::close(fd); return JoyDevice::ERR_GET_VERSION; } if ( version != JS_VERSION ) { ::close(fd); return JoyDevice::WRONG_VERSION; } char bt = 0, ax = 0; if ( ::ioctl(fd, JSIOCGBUTTONS, &bt) == -1 ) { ::close(fd); return JoyDevice::ERR_GET_BUTTONS; } if ( ::ioctl(fd, JSIOCGAXES, &ax) == -1 ) { ::close(fd); return JoyDevice::ERR_GET_AXES; } struct js_corr *oldCorr = new struct js_corr[ax]; if ( ::ioctl(fd, JSIOCGCORR, oldCorr) == -1 ) { ::close(fd); delete [] oldCorr; return JoyDevice::ERR_GET_CORR; } if (bt < 0) { return JoyDevice::ERR_GET_BUTTONS; } descr = name; joyFd = fd; axes = ax; buttons = bt; origCorr = oldCorr; corr = new struct js_corr[axes]; amin = new int[axes]; amax = new int[axes]; int i; for (i = 0; i < axes; i++) resetMinMax(i); return JoyDevice::SUCCESS; } //-------------------------------------------------------------- void JoyDevice::close() { if ( joyFd == -1 ) return; ::close(joyFd); joyFd = -1; descr = QLatin1String(""); delete [] amin; delete [] amax; amin = nullptr; amax = nullptr; delete [] corr; corr = nullptr; delete [] origCorr; origCorr = nullptr; } //-------------------------------------------------------------- int JoyDevice::axisMin(int axis) const { if ( (axis < 0) || (axis >= axes) ) return 0; return amin[axis]; } //-------------------------------------------------------------- int JoyDevice::axisMax(int axis) const { if ( (axis < 0) || (axis >= axes) ) return 0; return amax[axis]; } //-------------------------------------------------------------- JoyDevice::ErrorCode JoyDevice::initCalibration() { if ( joyFd == -1 ) return JoyDevice::ERR_INIT_CAL; int i; // Reset all current correction values for (i = 0; i < axes; i++) { corr[i].type = JS_CORR_NONE; corr[i].prec = 0; } if ( ::ioctl(joyFd, JSIOCSCORR, corr) == -1 ) return JoyDevice::ERR_INIT_CAL; for (i = 0; i < axes; i++) corr[i].type = JS_CORR_BROKEN; return JoyDevice::SUCCESS; } //-------------------------------------------------------------- JoyDevice::ErrorCode JoyDevice::applyCalibration() { if ( joyFd == -1 ) return JoyDevice::ERR_APPLY_CAL; if ( ::ioctl(joyFd, JSIOCSCORR, corr) == -1 ) return JoyDevice::ERR_APPLY_CAL; return JoyDevice::SUCCESS; } //-------------------------------------------------------------- void JoyDevice::resetMinMax(int axis, int value) { amin[axis] = value; amax[axis] = value; } //-------------------------------------------------------------- void JoyDevice::calcPrecision() { if ( !corr ) return; int i; for (i = 0; i < axes; i++) { corr[i].prec = amax[i] - amin[i]; qDebug() << "Precision for axis: " << i << ": " << corr[i].prec; } } //-------------------------------------------------------------- JoyDevice::ErrorCode JoyDevice::restoreCorr() { if ( joyFd == -1 ) return JoyDevice::SUCCESS; if ( ::ioctl(joyFd, JSIOCSCORR, origCorr) == -1 ) return JoyDevice::ERR_RESTORE_CORR; else return JoyDevice::SUCCESS; } //-------------------------------------------------------------- JoyDevice::~JoyDevice() { close(); } //-------------------------------------------------------------- bool JoyDevice::getEvent(JoyDevice::EventType &type, int &number, int &value) { number = value = 0; int ret; fd_set readSet; FD_ZERO(&readSet); FD_SET(joyFd, &readSet); struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = 10000; ret = ::select(joyFd + 1, &readSet, nullptr, nullptr, &timeout); if ( ret == 1 ) // got an event from the joystick { struct js_event e; if ( ::read(joyFd, &e, sizeof(struct js_event)) == sizeof(struct js_event) ) { if ( e.type & JS_EVENT_BUTTON ) { type = JoyDevice::BUTTON; value = e.value; number = e.number; return true; } if ( e.type & JS_EVENT_AXIS ) { type = JoyDevice::AXIS; value = e.value; number = e.number; // store min, max values if ( e.value < amin[number] ) amin[number] = e.value; if ( e.value > amax[number] ) amax[number] = e.value; return true; } } } return false; // no event } //-------------------------------------------------------------- void JoyDevice::calcCorrection(int axis, int *min, int *center, int *max) { const int MIN = 0; const int MAX = 1; double a, b, c, d; a = center[MIN]; // inputs.cmin[1]; b = center[MAX]; // inputs.cmax[1]; c = 32767.0 / (center[MIN] - min[MAX]); // (inputs.cmin[1] - inputs.cmax[0]); d = 32767.0 / (max[MIN] - center[MAX]); // (inputs.cmin[2] - inputs.cmax[1]); corr[axis].coef[0] = (int)rint(a); corr[axis].coef[1] = (int)rint(b); corr[axis].coef[2] = (int)rint(c*16384.0); corr[axis].coef[3] = (int)rint(d*16384.0); qDebug() << "min min: " << min[0] << " max: " << min[1] ; qDebug() << "max min: " << max[0] << " max: " << max[1] ; qDebug() << "Correction values for axis: " << axis << ": " << corr[axis].coef[0] << ", " << corr[axis].coef[1] << ", " << corr[axis].coef[2] << ", " << corr[axis].coef[3] << endl; } //--------------------------------------------------------------