diff --git a/kaccess/CMakeLists.txt b/kaccess/CMakeLists.txt --- a/kaccess/CMakeLists.txt +++ b/kaccess/CMakeLists.txt @@ -7,21 +7,21 @@ set(kaccess_KDEINIT_SRCS kaccess.cpp main.cpp ) -kf5_add_kdeinit_executable( kaccess ${kaccess_KDEINIT_SRCS}) +kf5_add_kdeinit_executable(kaccess ${kaccess_KDEINIT_SRCS}) target_link_libraries(kdeinit_kaccess Qt5::Widgets Qt5::X11Extras KF5::ConfigCore KF5::Completion KF5::GlobalAccel KF5::I18n - KF5::IconThemes KF5::Notifications KF5::WidgetsAddons KF5::WindowSystem + KF5::DBusAddons + KF5::Service Phonon::phonon4qt5 - KF5::KDELibs4Support ${X11_LIBRARIES} ) diff --git a/kaccess/kaccess.h b/kaccess/kaccess.h --- a/kaccess/kaccess.h +++ b/kaccess/kaccess.h @@ -29,9 +29,6 @@ #include #include - -#include - #include #include @@ -45,15 +42,15 @@ class KDialog; class KComboBox; -class KAccessApp : public KUniqueApplication, QAbstractNativeEventFilter +class KAccessApp : public QObject, public QAbstractNativeEventFilter { Q_OBJECT public: - explicit KAccessApp(bool allowStyles = true, bool GUIenabled = true); - int newInstance() Q_DECL_OVERRIDE; + explicit KAccessApp(); + void newInstance(); void setXkbOpcode(int opcode); - bool nativeEventFilter(const QByteArray& eventType, void* message, long int* result) Q_DECL_OVERRIDE; + bool nativeEventFilter(const QByteArray& eventType, void* message, long int* result) override; bool isFailed() const { return m_error; @@ -101,7 +98,7 @@ WId _activeWindow; - KDialog *dialog; + QDialog *dialog; QLabel *featuresLabel; KComboBox *showModeCombobox; diff --git a/kaccess/kaccess.cpp b/kaccess/kaccess.cpp --- a/kaccess/kaccess.cpp +++ b/kaccess/kaccess.cpp @@ -32,30 +32,30 @@ #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 #define XK_MISCELLANY #define XK_XKB_KEYS #include #include -#include #include @@ -144,9 +144,8 @@ /********************************************************************/ -KAccessApp::KAccessApp(bool allowStyles, bool GUIenabled) - : KUniqueApplication(allowStyles, GUIenabled), - overlay(0), _player(0), toggleScreenReaderAction(new QAction(this)) +KAccessApp::KAccessApp() + : overlay(0), _player(0), toggleScreenReaderAction(new QAction(this)) { m_error = false; _activeWindow = KWindowSystem::activeWindow(); @@ -168,14 +167,16 @@ unsigned char locked = XkbModLocks(&state_return); state = ((int)locked) << 8 | latched; - qApp->installNativeEventFilter(this); + auto service = new KDBusService(KDBusService::Unique, this); + connect(service, &KDBusService::activateRequested, this, &KAccessApp::newInstance); + + QTimer::singleShot(0, this, &KAccessApp::readSettings); } -int KAccessApp::newInstance() +void KAccessApp::newInstance() { KSharedConfig::openConfig()->reparseConfiguration(); readSettings(); - return 0; } void KAccessApp::readSettings() @@ -372,19 +373,15 @@ void KAccessApp::setScreenReaderEnabled(bool enabled) { if (enabled) { - QStringList args; - args << "set" << "org.gnome.desktop.a11y.applications" << "screen-reader-enabled" << "true"; + QStringList args = { "set", "org.gnome.desktop.a11y.applications", "screen-reader-enabled", "true"}; int ret = QProcess::execute("gsettings", args); if (ret == 0) { - QStringList args = {"--replace"}; qint64 pid = 0; - QProcess::startDetached("orca", args, QString(), &pid); + QProcess::startDetached("orca", {"--replace"}, QString(), &pid); qCDebug(logKAccess) << "Launching Orca, pid:" << pid; } } else { - QStringList args; - args << "set" << "org.gnome.desktop.a11y.applications" << "screen-reader-enabled" << "false"; - QProcess::execute("gsettings", args); + QProcess::startDetached("gsettings", { "set", "org.gnome.desktop.a11y.applications", "screen-reader-enabled", "false"}); } } @@ -521,7 +518,7 @@ WId id = _activeWindow; NETRect frame, window; - NETWinInfo net(QX11Info::connection(), id, desktop()->winId(), 0); + NETWinInfo net(QX11Info::connection(), id, qApp->desktop()->winId(), 0); net.kdeGeometry(frame, window); @@ -553,7 +550,7 @@ // flash the overlay widget overlay->raise(); overlay->show(); - flush(); + qApp->flush(); } // ask Phonon to ring a nice bell @@ -662,35 +659,24 @@ void KAccessApp::createDialogContents() { if (dialog == 0) { - dialog = new KDialog(0); - dialog->setCaption(i18n("Warning")); - dialog->setButtons(KDialog::Yes | KDialog::No); - dialog->setButtonGuiItem(KDialog::Yes, KStandardGuiItem::yes()); - dialog->setButtonGuiItem(KDialog::No, KStandardGuiItem::no()); - dialog->setDefaultButton(KDialog::No); - dialog->setEscapeButton(KDialog::Close); + dialog = new QDialog(nullptr); + dialog->setWindowTitle(i18n("Warning")); dialog->setObjectName("AccessXWarning"); dialog->setModal(true); - KVBox *topcontents = new KVBox(dialog); - topcontents->setSpacing(KDialog::spacingHint() * 2); -#ifdef __GNUC__ -#warning "kde4 fixme" -#endif - //topcontents->setMargin(KDialog::marginHint()); + QWidget *topcontents = new QWidget(dialog); + topcontents->setLayout(new QVBoxLayout(topcontents)); QWidget *contents = new QWidget(topcontents); QHBoxLayout * lay = new QHBoxLayout(contents); - lay->setSpacing(KDialog::spacingHint()); QLabel *label1 = new QLabel(contents); - QPixmap pixmap = KIconLoader::global()->loadIcon("dialog-warning", KIconLoader::NoGroup, KIconLoader::SizeMedium, KIconLoader::DefaultState, QStringList(), 0, true); - if (pixmap.isNull()) - pixmap = QMessageBox::standardIcon(QMessageBox::Warning); - label1->setPixmap(pixmap); + QIcon icon = QIcon::fromTheme("dialog-warning"); + if (icon.isNull()) + icon = QMessageBox::standardIcon(QMessageBox::Warning); + label1->setPixmap(icon.pixmap(64, 64)); lay->addWidget(label1, 0, Qt::AlignCenter); - lay->addSpacing(KDialog::spacingHint()); QVBoxLayout * vlay = new QVBoxLayout(); lay->addItem(vlay); @@ -715,11 +701,13 @@ showModeCombobox->insertItem(2, i18n("Deactivate All AccessX Features & Gestures")); showModeCombobox->setCurrentIndex(1); - dialog->setMainWidget(topcontents); + auto buttons = new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::No, dialog); + lay->addWidget(buttons); - connect(dialog, &KDialog::yesClicked, this, &KAccessApp::yesClicked); - connect(dialog, &KDialog::noClicked, this, &KAccessApp::noClicked); - connect(dialog, &KDialog::closeClicked, this, &KAccessApp::dialogClosed); + connect(buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept); + connect(buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject); + connect(dialog, &QDialog::accepted, this, &KAccessApp::yesClicked); + connect(dialog, &QDialog::rejected, this, &KAccessApp::noClicked); } } @@ -865,7 +853,7 @@ + " " + i18n("These AccessX settings are needed for some users with motion impairments and can be configured in the KDE System Settings. You can also turn them on and off with standardized keyboard gestures.\n\nIf you do not need them, you can select \"Deactivate all AccessX features and gestures\".")); KWindowSystem::setState(dialog->winId(), NET::KeepAbove); - kapp->updateUserTimestamp(); + KUserTimestamp::updateUserTimestamp(0); dialog->show(); } } @@ -935,9 +923,9 @@ void KAccessApp::yesClicked() { - if (dialog != 0) + if (dialog) dialog->deleteLater(); - dialog = 0; + dialog = nullptr; KConfigGroup config(KSharedConfig::openConfig(), "Keyboard"); switch (showModeCombobox->currentIndex()) { @@ -965,9 +953,9 @@ void KAccessApp::noClicked() { - if (dialog != 0) + if (dialog) dialog->deleteLater(); - dialog = 0; + dialog = nullptr; requestedFeatures = features; KConfigGroup config(KSharedConfig::openConfig(), "Keyboard"); diff --git a/kaccess/main.cpp b/kaccess/main.cpp --- a/kaccess/main.cpp +++ b/kaccess/main.cpp @@ -20,49 +20,47 @@ */ #include "kaccess.h" -#include -#include -#include -#include +#include +#include +#include #include +#include +#include +#include #include -#include extern "C" Q_DECL_EXPORT int kdemain(int argc, char * argv[]) { + // we need an application object for QX11Info + QApplication app(argc, argv); + KAccessApp acc; + Kdelibs4ConfigMigrator migrate(QStringLiteral("kaccess")); migrate.setConfigFiles(QStringList() << QStringLiteral("kaccessrc")); migrate.migrate(); QGuiApplication::setFallbackSessionManagementEnabled(false); - K4AboutData about(I18N_NOOP("kaccess"), 0, ki18n("KDE Accessibility Tool"), - 0, KLocalizedString(), K4AboutData::License_GPL, - ki18n("(c) 2000, Matthias Hoelzer-Kluepfel")); + KAboutData about("kaccess", QString(), i18n("KDE Accessibility Tool"), + {}, KAboutLicense::GPL_V2, + i18n("(c) 2000, Matthias Hoelzer-Kluepfel")); - about.addAuthor(ki18n("Matthias Hoelzer-Kluepfel"), ki18n("Author") , "hoelzer@kde.org"); - - KCmdLineArgs::init(argc, argv, &about); + about.addAuthor(i18n("Matthias Hoelzer-Kluepfel"), i18n("Author") , QStringLiteral("hoelzer@kde.org")); //this application is currently only relevant on X, force to run under X //note if someone does port this we still need to run kaccess under X for xwayland apps - setenv("QT_QPA_PLATFORM", "xcb", true); - - if (!KAccessApp::start()) - return 0; + qputenv("QT_QPA_PLATFORM", "xcb"); // verify the Xlib has matching XKB extension int major = XkbMajorVersion; int minor = XkbMinorVersion; if (!XkbLibraryVersion(&major, &minor)) { - kError() << "Xlib XKB extension does not match" << endl; + qWarning() << "Xlib XKB extension does not match"; return 1; } - kDebug() << "Xlib XKB extension major=" << major << " minor=" << minor; + qDebug() << "Xlib XKB extension major=" << major << " minor=" << minor; - // we need an application object for QX11Info - KAccessApp app; - if (app.isFailed()) { + if (acc.isFailed()) { return 1; } @@ -73,23 +71,23 @@ QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement); QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); - // verify the X server has matching XKB extension // if yes, the XKB extension is initialized int opcode_rtrn; int error_rtrn; int xkb_opcode; if (!XkbQueryExtension(QX11Info::display(), &opcode_rtrn, &xkb_opcode, &error_rtrn, &major, &minor)) { - kError() << "X server has not matching XKB extension" << endl; + qWarning() << "X server has not matching XKB extension" << endl; return 1; } - kDebug() << "X server XKB extension major=" << major << " minor=" << minor; + qDebug() << "X server XKB extension major=" << major << " minor=" << minor; + + app.installNativeEventFilter(&acc); //Without that, the application dies when the dialog is closed only once. app.setQuitOnLastWindowClosed(false); - app.setXkbOpcode(xkb_opcode); - app.disableSessionManagement(); + acc.setXkbOpcode(xkb_opcode); return app.exec(); }