Changeset View
Standalone View
kcms/fonts/fonts.cpp
Show All 28 Lines | |||||
29 | #include <QQuickItem> | 29 | #include <QQuickItem> | ||
30 | #include <QWindow> | 30 | #include <QWindow> | ||
31 | #include <QQmlEngine> | 31 | #include <QQmlEngine> | ||
32 | #include <QQuickView> | 32 | #include <QQuickView> | ||
33 | #include <QDebug> | 33 | #include <QDebug> | ||
34 | #include <QFontDialog> | 34 | #include <QFontDialog> | ||
35 | #include <QApplication> | 35 | #include <QApplication> | ||
36 | #include <QFontDatabase> | 36 | #include <QFontDatabase> | ||
37 | #include <QDBusInterface> | ||||
37 | 38 | | |||
38 | #include <KAcceleratorManager> | 39 | #include <KAcceleratorManager> | ||
39 | #include <KGlobalSettings> | 40 | #include <KGlobalSettings> | ||
40 | #include <KConfigGroup> | 41 | #include <KConfigGroup> | ||
41 | #include <KConfig> | 42 | #include <KConfig> | ||
42 | #include <KAboutData> | 43 | #include <KAboutData> | ||
43 | #include <KLocalizedString> | 44 | #include <KLocalizedString> | ||
44 | #include <KPluginFactory> | 45 | #include <KPluginFactory> | ||
▲ Show 20 Lines • Show All 511 Lines • ▼ Show 20 Line(s) | 551 | { | |||
556 | cg.writeEntry("smallestReadableFont", m_smallFont.toString()); | 557 | cg.writeEntry("smallestReadableFont", m_smallFont.toString()); | ||
557 | cg.writeEntry("toolBarFont", m_toolbarFont.toString()); | 558 | cg.writeEntry("toolBarFont", m_toolbarFont.toString()); | ||
558 | cg.writeEntry("menuFont", m_menuFont.toString()); | 559 | cg.writeEntry("menuFont", m_menuFont.toString()); | ||
559 | cg.sync(); | 560 | cg.sync(); | ||
560 | cg = KConfigGroup(config, "WM"); | 561 | cg = KConfigGroup(config, "WM"); | ||
561 | cg.writeEntry("activeFont", m_windowTitleFont.toString()); | 562 | cg.writeEntry("activeFont", m_windowTitleFont.toString()); | ||
562 | cg.sync(); | 563 | cg.sync(); | ||
563 | 564 | | |||
565 | saveFontToGtkSettings(); | ||||
566 | | ||||
564 | m_defaultFontOriginal = m_defaultFont; | 567 | m_defaultFontOriginal = m_defaultFont; | ||
565 | m_generalFontOriginal = m_generalFont; | 568 | m_generalFontOriginal = m_generalFont; | ||
566 | m_fixedWidthFontOriginal = m_fixedWidthFont; | 569 | m_fixedWidthFontOriginal = m_fixedWidthFont; | ||
567 | m_smallFontOriginal = m_smallFont; | 570 | m_smallFontOriginal = m_smallFont; | ||
568 | m_toolbarFontOriginal = m_toolbarFont; | 571 | m_toolbarFontOriginal = m_toolbarFont; | ||
569 | m_menuFontOriginal = m_menuFont; | 572 | m_menuFontOriginal = m_menuFont; | ||
570 | m_windowTitleFontOriginal = m_windowTitleFont; | 573 | m_windowTitleFontOriginal = m_windowTitleFont; | ||
571 | 574 | | |||
Show All 17 Lines | |||||
589 | KGlobalSettings::self()->emitChange(KGlobalSettings::FontChanged); | 592 | KGlobalSettings::self()->emitChange(KGlobalSettings::FontChanged); | ||
590 | 593 | | |||
591 | runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); | 594 | runRdb(KRdbExportXftSettings | KRdbExportGtkTheme); | ||
592 | 595 | | |||
593 | emit fontsHaveChanged(); | 596 | emit fontsHaveChanged(); | ||
594 | setNeedsSave(false); | 597 | setNeedsSave(false); | ||
595 | } | 598 | } | ||
596 | 599 | | |||
600 | void KFonts::saveFontToGtkSettings() | ||||
601 | { | ||||
602 | QDBusInterface kdedInterface { | ||||
603 | QStringLiteral("org.kde.kded5"), | ||||
nicolasfella: QStringLiteral() around strings | |||||
604 | QStringLiteral("/modules/gtkconfig"), | ||||
605 | QStringLiteral("org.kde.gtkconfig") | ||||
606 | }; | ||||
607 | kdedInterface.call("setFont", m_generalFont.toString()); | ||||
Given this is a kded module and as such a regular qt application, you should be able to get all of this automatically. broulik: Given this is a kded module and as such a regular qt application, you should be able to get all… | |||||
There are two designs which are both sensible:
Both have an advantage, and a disadvantage. This is both running all the time *and* is being explicitly called, which is the worst of both worlds. davidedmundson: There are two designs which are both sensible:
1) we have a daemon that runs all the time so… | |||||
@davidedmundson So, what are advantages and disadvantages of each of those options and what way do you recommend me go? gikari: @davidedmundson So, what are advantages and disadvantages of each of those options and what way… | |||||
@broulik I do not understand. KDEDModule (which is a parent of GtkConfig) is QObject, not a QGuiApplication. Maybe I am missing something? You want me to create a connection with that signal within a module, so I don't have to ask from KCM to change a font via DBus? gikari: @broulik I do not understand. `KDEDModule` (which is a parent of `GtkConfig`) is `QObject`, not… | |||||
kded (the application you're running in) is a QApplication, so from the constructor of your kdedmodule you could do #include <QApplication> connect(qApp, &QGuiApplication::fontChanged, this, [this](this QFont &font) { // now check if you have the new fonts }); I can't guarantee this will work (accessing font from there will actually deadlock :D but I am curious whether that signal is emitted properly, so you dont have to listen to or ask the font kcm to tell you. broulik: kded (the application you're running in) is a `QApplication`, so from the constructor of your… | |||||
So, I wrote this: GtkConfig::GtkConfig(QObject *parent, const QVariantList&) : KDEDModule(parent), configEditor {new ConfigEditor()} { qDebug() << "Parent: " << parent; QGuiApplication *qapp = static_cast<QGuiApplication *>(parent); qDebug() << "Qapp: " << qapp; connect(qapp, &QGuiApplication::fontChanged, this, [this](const QFont &font) { qDebug() << "Font recieved"; qDebug() << font; }); qDebug() << "GTK configuration module loaded"; } And when I save fonts via KCM nothing (Except the "parent", "qapp" and "GTK ..." lines) was printed in konsole, where I run Kded5. So, it means signal was not send? gikari: So, I wrote this:
```
GtkConfig::GtkConfig(QObject *parent, const QVariantList&)… | |||||
Are you sure parent is a QGuiApplication? I don't think so. Perhaps you want to connect to QGuiApplication::instance() instead. broulik: Are you sure `parent` is a `QGuiApplication`? I don't think so. Perhaps you want to connect to… | |||||
Just tested. It works. So the plan is to remove explicit call from the font kcm and replace it with that signal binding? For fonts it sure will work, but what about other settings, that will be in the future, like color schemes, icons etc? Whose signals we will receive? gikari: Just tested. It works. So the plan is to remove explicit call from the font kcm and replace it… | |||||
608 | } | ||||
nicolasfella: I think the specific string should be determined by the gtkconfig daemon | |||||
609 | | ||||
597 | void KFonts::updateNeedsSave() | 610 | void KFonts::updateNeedsSave() | ||
598 | { | 611 | { | ||
We know it will be about GTK, so changeFont should be enough. Also, setFont would be more consistent with other API naming nicolasfella: We know it will be about GTK, so changeFont should be enough.
Also, setFont would be more… | |||||
599 | setNeedsSave(m_defaultFontOriginal != m_defaultFont || | 612 | setNeedsSave(m_defaultFontOriginal != m_defaultFont || | ||
600 | m_generalFontOriginal != m_generalFont || | 613 | m_generalFontOriginal != m_generalFont || | ||
601 | m_fixedWidthFontOriginal != m_fixedWidthFont || | 614 | m_fixedWidthFontOriginal != m_fixedWidthFont || | ||
602 | m_smallFontOriginal != m_smallFont || | 615 | m_smallFontOriginal != m_smallFont || | ||
603 | m_toolbarFontOriginal != m_toolbarFont || | 616 | m_toolbarFontOriginal != m_toolbarFont || | ||
604 | m_menuFontOriginal != m_menuFont || | 617 | m_menuFontOriginal != m_menuFont || | ||
605 | m_windowTitleFontOriginal != m_windowTitleFont || | 618 | m_windowTitleFontOriginal != m_windowTitleFont || | ||
606 | m_fontAASettings->needsSave()); | 619 | m_fontAASettings->needsSave()); | ||
▲ Show 20 Lines • Show All 165 Lines • Show Last 20 Lines |
QStringLiteral() around strings