Changeset View
Changeset View
Standalone View
Standalone View
dataengines/kimpanel/kimpanelagent.cpp
Show All 25 Lines | |||||
26 | #include <QList> | 26 | #include <QList> | ||
27 | #include <QMap> | 27 | #include <QMap> | ||
28 | #include <QString> | 28 | #include <QString> | ||
29 | #include <QStringList> | 29 | #include <QStringList> | ||
30 | #include <QVariant> | 30 | #include <QVariant> | ||
31 | #include <QDBusServiceWatcher> | 31 | #include <QDBusServiceWatcher> | ||
32 | #include <QDBusConnection> | 32 | #include <QDBusConnection> | ||
33 | 33 | | |||
34 | #include "input_sources.h" | ||||
35 | #include "layout_list_models.h" | ||||
36 | | ||||
37 | #include <KConfigGroup> | ||||
38 | #include <KSharedConfig> | ||||
39 | | ||||
40 | #include "input_sources.h" | ||||
41 | #include "layout_list_models.h" | ||||
42 | | ||||
43 | #include <KConfigGroup> | ||||
44 | #include <KSharedConfig> | ||||
45 | | ||||
34 | PanelAgent::PanelAgent(QObject *parent) | 46 | PanelAgent::PanelAgent(QObject *parent) | ||
35 | : QObject(parent) | 47 | : QObject(parent) | ||
36 | ,adaptor(new ImpanelAdaptor(this)) | 48 | ,adaptor(new ImpanelAdaptor(this)) | ||
37 | ,adaptor2(new Impanel2Adaptor(this)) | 49 | ,adaptor2(new Impanel2Adaptor(this)) | ||
38 | ,watcher(new QDBusServiceWatcher(this)) | 50 | ,watcher(new QDBusServiceWatcher(this)) | ||
51 | ,m_kdedIface(new QDBusInterface("org.kde.keyboard", "/Layouts", "org.kde.KeyboardLayouts")) | ||||
52 | ,m_models(new LayoutListModels(this)) | ||||
39 | { | 53 | { | ||
40 | watcher->setConnection(QDBusConnection::sessionBus()); | 54 | watcher->setConnection(QDBusConnection::sessionBus()); | ||
41 | watcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration); | 55 | watcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration); | ||
42 | QDBusConnection::connectToBus(QDBusConnection::SessionBus, QStringLiteral("kimpanel_bus")).registerObject(QStringLiteral("/org/kde/impanel"), this); | 56 | QDBusConnection::connectToBus(QDBusConnection::SessionBus, QStringLiteral("kimpanel_bus")).registerObject(QStringLiteral("/org/kde/impanel"), this); | ||
43 | QDBusConnection::connectToBus(QDBusConnection::SessionBus, QStringLiteral("kimpanel_bus")).registerService(QStringLiteral("org.kde.impanel")); | 57 | QDBusConnection::connectToBus(QDBusConnection::SessionBus, QStringLiteral("kimpanel_bus")).registerService(QStringLiteral("org.kde.impanel")); | ||
44 | 58 | | |||
45 | // directly connect to corresponding signal | 59 | // directly connect to corresponding signal | ||
46 | QDBusConnection(QStringLiteral("kimpanel_bus")).connect(QString(), QString(), QStringLiteral("org.kde.kimpanel.inputmethod"), | 60 | QDBusConnection(QStringLiteral("kimpanel_bus")).connect(QString(), QString(), QStringLiteral("org.kde.kimpanel.inputmethod"), | ||
Show All 26 Lines | |||||
73 | QDBusConnection(QStringLiteral("kimpanel_bus")).connect(QString(), QString(), QStringLiteral("org.kde.kimpanel.inputmethod"), | 87 | QDBusConnection(QStringLiteral("kimpanel_bus")).connect(QString(), QString(), QStringLiteral("org.kde.kimpanel.inputmethod"), | ||
74 | QStringLiteral("RegisterProperties"), this, SLOT(RegisterProperties(QStringList))); | 88 | QStringLiteral("RegisterProperties"), this, SLOT(RegisterProperties(QStringList))); | ||
75 | QDBusConnection(QStringLiteral("kimpanel_bus")).connect(QString(), QString(), QStringLiteral("org.kde.kimpanel.inputmethod"), | 89 | QDBusConnection(QStringLiteral("kimpanel_bus")).connect(QString(), QString(), QStringLiteral("org.kde.kimpanel.inputmethod"), | ||
76 | QStringLiteral("ExecDialog"), this, SLOT(ExecDialog(QString))); | 90 | QStringLiteral("ExecDialog"), this, SLOT(ExecDialog(QString))); | ||
77 | QDBusConnection(QStringLiteral("kimpanel_bus")).connect(QString(), QString(), QStringLiteral("org.kde.kimpanel.inputmethod"), | 91 | QDBusConnection(QStringLiteral("kimpanel_bus")).connect(QString(), QString(), QStringLiteral("org.kde.kimpanel.inputmethod"), | ||
78 | QStringLiteral("ExecMenu"), this, SLOT(ExecMenu(QStringList))); | 92 | QStringLiteral("ExecMenu"), this, SLOT(ExecMenu(QStringList))); | ||
79 | 93 | | |||
80 | connect(watcher, SIGNAL(serviceUnregistered(QString)), this, SLOT(serviceUnregistered(QString))); | 94 | connect(watcher, SIGNAL(serviceUnregistered(QString)), this, SLOT(serviceUnregistered(QString))); | ||
95 | connect(InputSources::self(), &InputSources::currentSourceChanged, this, &PanelAgent::updateShowStatus); | ||||
96 | connect(m_kdedIface, SIGNAL(configChanged()), this, SLOT(updateConfig())); | ||||
97 | connect(m_models, &LayoutListModels::currentLayoutIndexChanged, | ||||
98 | this, &PanelAgent::updateCurrentLayoutIndex); | ||||
99 | | ||||
100 | updateConfig(); | ||||
81 | } | 101 | } | ||
82 | 102 | | |||
83 | PanelAgent::~PanelAgent() | 103 | PanelAgent::~PanelAgent() | ||
84 | { | 104 | { | ||
85 | // destructor | 105 | // destructor | ||
86 | QDBusConnection::disconnectFromBus(QStringLiteral("kimpanel_bus")); | 106 | QDBusConnection::disconnectFromBus(QStringLiteral("kimpanel_bus")); | ||
87 | } | 107 | } | ||
88 | 108 | | |||
89 | void PanelAgent::serviceUnregistered(const QString& service) | 109 | void PanelAgent::serviceUnregistered(const QString& service) | ||
90 | { | 110 | { | ||
91 | if (service == m_currentService) { | 111 | if (service == m_currentService) { | ||
92 | watcher->setWatchedServices(QStringList()); | 112 | watcher->setWatchedServices(QStringList()); | ||
93 | cached_props.clear(); | 113 | cached_props.clear(); | ||
94 | m_currentService = QString(); | 114 | m_currentService = QString(); | ||
95 | emit showAux(false); | 115 | emit showAux(false); | ||
96 | emit showPreedit(false); | 116 | emit showPreedit(false); | ||
97 | emit showLookupTable(false); | 117 | emit showLookupTable(false); | ||
98 | emit registerProperties(QList<KimpanelProperty>()); | 118 | emit registerProperties(QList<KimpanelProperty>()); | ||
99 | } | 119 | } | ||
100 | } | 120 | } | ||
101 | 121 | | |||
122 | void PanelAgent::updateShowStatus() | ||||
123 | { | ||||
124 | bool show = false; | ||||
125 | | ||||
126 | if (InputSources::self()->currentSource() == InputSources::Sources::XkbSource) { | ||||
127 | if (m_show_layout_indicator) { | ||||
128 | if (m_models->configuredLayoutListModel()->rowCount() > 1 || m_show_single) { | ||||
129 | show = true; | ||||
130 | } | ||||
131 | } | ||||
132 | } | ||||
133 | else { | ||||
134 | show = true; | ||||
135 | } | ||||
136 | | ||||
137 | emit showPlasmoid(show); | ||||
138 | } | ||||
139 | | ||||
140 | void PanelAgent::updateConfig() | ||||
141 | { | ||||
142 | m_models->loadConfig(); | ||||
143 | | ||||
144 | KConfigGroup config( | ||||
145 | KSharedConfig::openConfig(QStringLiteral("kxkbrc"), KConfig::NoGlobals), | ||||
146 | QStringLiteral("Layout")); | ||||
147 | | ||||
148 | m_show_layout_indicator = config.readEntry<bool>("ShowLayoutIndicator", true); | ||||
149 | m_show_single = config.readEntry<bool>("ShowSingle", false); | ||||
150 | | ||||
151 | updateShowStatus(); | ||||
152 | } | ||||
153 | | ||||
154 | void PanelAgent::updateCurrentLayoutIndex() | ||||
155 | { | ||||
156 | int new_idx = m_models->currentLayoutIndex(); | ||||
157 | | ||||
158 | // TODO: make a "short name" role and use that | ||||
159 | QString name = m_models->currentLayoutListModel()->data( | ||||
160 | m_models->currentLayoutListModel()->index(new_idx, 0), | ||||
161 | LayoutListModelBase::Roles::ShortNameRole).toString(); | ||||
162 | | ||||
163 | QString iconName = m_models->currentIconName(); | ||||
164 | | ||||
165 | emit currentLayoutChanged(name, iconName); | ||||
166 | } | ||||
167 | | ||||
168 | LayoutListModels *PanelAgent::models() const | ||||
169 | { | ||||
170 | return m_models; | ||||
171 | } | ||||
172 | | ||||
102 | void PanelAgent::configure() | 173 | void PanelAgent::configure() | ||
103 | { | 174 | { | ||
104 | emit Configure(); | 175 | emit Configure(); | ||
105 | } | 176 | } | ||
106 | 177 | | |||
107 | void PanelAgent::lookupTablePageDown() | 178 | void PanelAgent::lookupTablePageDown() | ||
108 | { | 179 | { | ||
109 | emit LookupTablePageDown(); | 180 | emit LookupTablePageDown(); | ||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Line(s) | 258 | { | |||
202 | 273 | | |||
203 | result.has_prev = has_prev; | 274 | result.has_prev = has_prev; | ||
204 | result.has_next = has_next; | 275 | result.has_next = has_next; | ||
205 | return result; | 276 | return result; | ||
206 | } | 277 | } | ||
207 | 278 | | |||
208 | void PanelAgent::created() | 279 | void PanelAgent::created() | ||
209 | { | 280 | { | ||
281 | updateShowStatus(); | ||||
282 | updateCurrentLayoutIndex(); | ||||
210 | emit PanelCreated(); | 283 | emit PanelCreated(); | ||
211 | emit PanelCreated2(); | 284 | emit PanelCreated2(); | ||
212 | } | 285 | } | ||
213 | 286 | | |||
214 | void PanelAgent::exit() | 287 | void PanelAgent::exit() | ||
215 | { | 288 | { | ||
216 | emit Exit(); | 289 | emit Exit(); | ||
217 | } | 290 | } | ||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |