Commit 2ac542b729b58bf44bbefdec31abcc45ef67e8b5

  • avatar
  • swiesner <swiesner @283d02a7-25f6-0310…ecb5cbfe19da.>
  • Mon Mar 15 13:44:47 CET 2010
Read default settings from the touchpad driver

git-svn-id: svn+ssh://svn.kde.org/home/kde/trunk/playground/utils/synaptiks@1103586 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
  
130130 "found.</warning>"));
131131 }
132132 } else {
133 // setup global action
134 d->globalActions = new KActionCollection(this, d->applicationData);
135 KAction *touchpadOn = new KToggleAction(
136 i18nc("@action:button hidden action", "Touchpad on"),
137 d->globalActions);
138 d->globalActions->addAction("touchpadOn", touchpadOn);
139 touchpadOn->setGlobalShortcut(
140 KShortcut(i18nc("touchpadOn shortcut", "Ctrl+Alt+T")));
141 this->connect(touchpadOn, SIGNAL(triggered(bool)),
142 SLOT(touchpadOnTriggered(bool)));
143
133 // create the touchpad manager
144134 d->touchpadManager = new TouchpadManager(touchpad, monitor, this);
145135 this->connect(d->touchpadManager,
146136 SIGNAL(touchpadSwitched(bool, const QString&,
141141 SIGNAL(touchpadError(const QString&)),
142142 SLOT(notifyError(const QString&)));
143143
144
145 // dump settings from touchpad driver to configuration and write the
146 // settings to a file to make them available to the kcmodule
147 this->dumpTouchpadToConfiguration();
148 d->config->setSharedConfig(KSharedConfig::openConfig(
149 "synaptiksrc-defaults"));
150 d->config->writeConfig();
151 // update all defaults in the configuration scheme ...
152 foreach (KConfigSkeletonItem *item, d->config->items()) {
153 item->swapDefault();
154 }
155 // ... and finally read the actual configuration
156 d->config->setSharedConfig(
157 KSharedConfig::openConfig("synaptiksrc"));
158 d->config->readConfig();
159
160 // action to switch the touchpad with global shortcut
161 d->globalActions = new KActionCollection(this, d->applicationData);
162 KAction *touchpadOn = new KToggleAction(
163 i18nc("@action:button hidden action", "Touchpad on"),
164 d->globalActions);
165 d->globalActions->addAction("touchpadOn", touchpadOn);
166 touchpadOn->setGlobalShortcut(
167 KShortcut(i18nc("touchpadOn shortcut", "Ctrl+Alt+T")));
168 this->connect(touchpadOn, SIGNAL(triggered(bool)),
169 SLOT(touchpadOnTriggered(bool)));
170
144171 // initial touchpad state
145172 int state = d->config->touchpadStateAtStartup();
146173 if (state != SynaptiksConfiguration::UnchangedState) {
176176 // and the rest of the configuration
177177 this->reparseConfiguration();
178178
179 // register on session bus
179180 QDBusConnection::sessionBus().registerObject("/Touchpad", touchpad);
180
181181 QDBusConnection::sessionBus().registerObject(
182182 "/TouchpadManager", d->touchpadManager,
183183 QDBusConnection::ExportScriptableContents);
263263 << "HorizontalTwoFingerScrolling" << "VerticalTwoFingerScrolling"
264264 << "HorizontalEdgeScrolling" << "VerticalEdgeScrolling"
265265 << "HorizontalScrollingDistance" << "VerticalScrollingDistance"
266 << "CornerCoasting"
266267 // tapping configuration
267268 << "FastTaps" << "TapAndDragGesture" << "LockedDrags";
268269 foreach (const QString &name, names) {
277277 // ... and finally the more complicated stuff
278278 if (d->config->coasting()) {
279279 this->setTouchpadProperty(
280 "cornerCoasting", d->config->cornerCoasting());
281 this->setTouchpadProperty(
282280 "coastingSpeed", d->config->coastingSpeed());
283281 } else {
284282 // 0.0 for coasting speed disables coasting
301301 this->setTouchpadProperty("fingerButtons", buttons);
302302}
303303
304void SynaptiksDaemon::dumpTouchpadToConfiguration() {
305 Q_D(SynaptiksDaemon);
306 // First all items, that directly map to touchpad properties ...
307 QList<QString> names;
308 names
309 // general configuration
310 << "CircularTouchpad"
311 // motion configuration
312 << "MinimumSpeed" << "MaximumSpeed" << "AccelerationFactor"
313 << "EdgeMotionAlways"
314 // scrolling configuration
315 << "CircularScrolling" << "CircularScrollingTrigger"
316 << "HorizontalTwoFingerScrolling" << "VerticalTwoFingerScrolling"
317 << "HorizontalEdgeScrolling" << "VerticalEdgeScrolling"
318 << "HorizontalScrollingDistance" << "VerticalScrollingDistance"
319 << "CornerCoasting" << "CoastingSpeed"
320 // tapping configuration
321 << "FastTaps" << "TapAndDragGesture" << "LockedDrags";
322 foreach (const QString &name, names) {
323 KConfigSkeletonItem *item = d->config->findItem(name);
324 Q_ASSERT(item);
325 QString property = name;
326 property[0] = property.at(0).toLower();
327 QVariant value = this->touchpadProperty(property.toAscii());
328 if (value.userType() == QMetaType::Float) {
329 value = round(value.toFloat()*100)/100.0;
330 kDebug() << "rounding" << name << "to" << value;
331 }
332 kDebug() << "setting" << name << "to" << value;
333 item->setProperty(value);
334 }
335
336 // ... and the more complicated stuff
337 float coastingSpeed = this->touchpadProperty("coastingSpeed").toFloat();
338 d->config->setCoasting(coastingSpeed != 0.0);
339 // convert to degrees
340 float circScrollDistance =
341 this->touchpadProperty("circularScrollingDistance").toFloat();
342 d->config->setCircularScrollingDistance(
343 round(circScrollDistance*180/M_PI));
344 // lockedDragsTimeout scaled to seconds
345 int lockedDragsTimeout =
346 this->touchpadProperty("lockedDragsTimeout").toInt();
347 d->config->setLockedDragsTimeout(lockedDragsTimeout / 1000.0);
348 // corner and finger buttons
349 QByteArray buttons;
350 buttons = this->touchpadProperty("cornerButtons").toByteArray();
351 for (int i=0; i < 4; i++) {
352 d->config->setCornerButton(i, buttons.at(i));
353 }
354 buttons = this->touchpadProperty("fingerButtons").toByteArray();
355 for (int i=0; i < 3; i++) {
356 d->config->setFingerButton(i, buttons.at(i));
357 }
358}
359
304360bool SynaptiksDaemon::isTouchpadAvailable() const {
305361 Q_D(const SynaptiksDaemon);
306362 // if touchpad manager is a null pointer, no touchpad is available.
392392 d->touchpadManager->touchpad()->setProperty(name, value);
393393 } catch (const QXDeviceError &error) {
394394 this->notifyError(error.toString());
395 }
396}
397
398QVariant SynaptiksDaemon::touchpadProperty(const char *name) const {
399 Q_D(const SynaptiksDaemon);
400 try {
401 return d->touchpadManager->touchpad()->property(name);
402 } catch (const QXDeviceError &error) {
403 return QVariant();
395404 }
396405}
397406
  
149149 Q_DECLARE_PRIVATE(SynaptiksDaemon)
150150
151151 /**
152 * @brief Dump the touchpad state to the configuration object.
153 *
154 * This function reads all configurable properties from the
155 * touchpad, and writes them to the configuration.
156 *
157 * This is used to initialize the configuration with defaults from
158 * the touchpad driver.
159 */
160 void dumpTouchpadToConfiguration();
161
162 /**
152163 * @brief Set the given touchpad @p property to the given @p value.
153164 *
154165 * This function does not propagate any exceptions from
171171 */
172172 void setTouchpadProperty(const char *property,
173173 const QVariant &value);
174
175 /**
176 * @brief Get the given touchpad @p property.
177 *
178 * This function does not propagate any exceptions from
179 * synaptiks::Touchpad, but catches and silently ignores them. In
180 * this case, an invalid QVariant is returned.
181 *
182 * Do @e always use this function, if you access touchpad properties
183 * from slots or DBus calls!
184 *
185 * @return the property value, or an invalid QVariant in case of
186 * exception
187 */
188 QVariant touchpadProperty(const char *property) const;
174189
175190 SynaptiksDaemonPrivate *const d_ptr;
176191 };
  
9494 // daemon is running and has a touchpad, so load configuration and
9595 // setup user interface
9696 this->config = new SynaptiksConfiguration();
97 // read the defaults provided by the daemon ...
98 this->config->setSharedConfig(
99 KSharedConfig::openConfig("synaptiksrc-defaults"));
100 this->config->readConfig();
101 // ... update all defaults in the configuration scheme ...
102 foreach (KConfigSkeletonItem *item, this->config->items()) {
103 item->swapDefault();
104 }
105 // ... and finally read the actual configuration
106 this->config->setSharedConfig(
107 KSharedConfig::openConfig("synaptiksrc"));
108 this->config->readConfig();
97109 this->setupUi();
98110 }
99111}
  
55ClassName=SynaptiksConfiguration
66# generate mutator functions
77Mutators=true
8# use the enum as return and argument type (instead of int)
9UseEnumTypes=true