Changeset View
Changeset View
Standalone View
Standalone View
kcms/cursortheme/kcmcursortheme.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
43 | #include <KNewStuff3/KNS3/DownloadDialog> | 43 | #include <KNewStuff3/KNS3/DownloadDialog> | ||
44 | 44 | | |||
45 | #include <QX11Info> | 45 | #include <QX11Info> | ||
46 | #include <QStandardItemModel> | 46 | #include <QStandardItemModel> | ||
47 | 47 | | |||
48 | #include <X11/Xlib.h> | 48 | #include <X11/Xlib.h> | ||
49 | #include <X11/Xcursor/Xcursor.h> | 49 | #include <X11/Xcursor/Xcursor.h> | ||
50 | 50 | | |||
51 | #include <klauncher_iface.h> | 51 | #include <klauncher_iface.h> | ||
ervin: Shouldn't be in that patch. | |||||
52 | 52 | | |||
53 | #ifdef HAVE_XFIXES | 53 | #ifdef HAVE_XFIXES | ||
54 | # include <X11/extensions/Xfixes.h> | 54 | # include <X11/extensions/Xfixes.h> | ||
55 | #endif | 55 | #endif | ||
56 | 56 | | |||
57 | K_PLUGIN_FACTORY_WITH_JSON(CursorThemeConfigFactory, "kcm_cursortheme.json", registerPlugin<CursorThemeConfig>();) | 57 | K_PLUGIN_FACTORY_WITH_JSON(CursorThemeConfigFactory, "kcm_cursortheme.json", registerPlugin<CursorThemeConfig>();) | ||
58 | 58 | | |||
59 | CursorThemeConfig::CursorThemeConfig(QObject *parent, const QVariantList &args) | 59 | CursorThemeConfig::CursorThemeConfig(QObject *parent, const QVariantList &args) | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | 146 | { | |||
147 | if (m_selectedThemeRow == row) { | 147 | if (m_selectedThemeRow == row) { | ||
148 | return; | 148 | return; | ||
149 | } | 149 | } | ||
150 | 150 | | |||
151 | m_selectedThemeRow = row; | 151 | m_selectedThemeRow = row; | ||
152 | emit selectedThemeRowChanged(); | 152 | emit selectedThemeRowChanged(); | ||
153 | updateSizeComboBox(); | 153 | updateSizeComboBox(); | ||
154 | 154 | | |||
155 | QModelIndex selected = selectedIndex(); | | |||
156 | | ||||
157 | if (selected.isValid()) { | | |||
158 | const CursorTheme *theme = m_proxyModel->theme(selected); | | |||
159 | } | | |||
160 | setNeedsSave(m_originalSelectedThemeRow != m_selectedThemeRow || m_originalPreferredSize != m_preferredSize); | 155 | setNeedsSave(m_originalSelectedThemeRow != m_selectedThemeRow || m_originalPreferredSize != m_preferredSize); | ||
161 | } | 156 | } | ||
162 | 157 | | |||
163 | int CursorThemeConfig::selectedThemeRow() const | 158 | int CursorThemeConfig::selectedThemeRow() const | ||
164 | { | 159 | { | ||
165 | return m_selectedThemeRow; | 160 | return m_selectedThemeRow; | ||
166 | } | 161 | } | ||
167 | 162 | | |||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 242 | foreach (i, sizes) { | |||
251 | } | 246 | } | ||
252 | if (m_pixmap.height() > maxIconHeight) { | 247 | if (m_pixmap.height() > maxIconHeight) { | ||
253 | maxIconHeight = m_pixmap.height(); | 248 | maxIconHeight = m_pixmap.height(); | ||
254 | } | 249 | } | ||
255 | QStandardItem *item = new QStandardItem(QIcon(m_pixmap), QString::number(i)); | 250 | QStandardItem *item = new QStandardItem(QIcon(m_pixmap), QString::number(i)); | ||
256 | item->setData(i); | 251 | item->setData(i); | ||
257 | m_sizesModel->appendRow(item); | 252 | m_sizesModel->appendRow(item); | ||
258 | comboBoxList << i; | 253 | comboBoxList << i; | ||
259 | }; | 254 | } | ||
260 | 255 | | |||
261 | // select an item | 256 | // select an item | ||
262 | int selectItem = comboBoxList.indexOf(m_preferredSize); | 257 | int selectItem = comboBoxList.indexOf(m_preferredSize); | ||
263 | // m_preferredSize not available for this theme | 258 | // m_preferredSize not available for this theme | ||
264 | if (selectItem < 0) { | 259 | if (selectItem < 0) { | ||
265 | /* Search the value next to m_preferredSize. The first entry (0) | 260 | /* Search the value next to m_preferredSize. The first entry (0) | ||
266 | is ignored. (If m_preferredSize would have been 0, then we | 261 | is ignored. (If m_preferredSize would have been 0, then we | ||
267 | would had found it yet. As m_preferredSize is not 0, we won't | 262 | would had found it yet. As m_preferredSize is not 0, we won't | ||
268 | default to "automatic size".)*/ | 263 | default to "automatic size".)*/ | ||
269 | int j; | 264 | int j; | ||
270 | int distance; | 265 | int distance; | ||
271 | int smallestDistance; | 266 | int smallestDistance; | ||
272 | selectItem = 1; | 267 | selectItem = 1; | ||
273 | j = comboBoxList.value(selectItem); | 268 | j = comboBoxList.value(selectItem); | ||
274 | smallestDistance = j < m_preferredSize ? m_preferredSize - j : j - m_preferredSize; | 269 | smallestDistance = j < m_preferredSize ? m_preferredSize - j : j - m_preferredSize; | ||
275 | for (int i = 2; i < comboBoxList.size(); ++i) { | 270 | for (int i = 2; i < comboBoxList.size(); ++i) { | ||
276 | j = comboBoxList.value(i); | 271 | j = comboBoxList.value(i); | ||
277 | distance = j < m_preferredSize ? m_preferredSize - j : j - m_preferredSize; | 272 | distance = j < m_preferredSize ? m_preferredSize - j : j - m_preferredSize; | ||
278 | if (distance < smallestDistance || (distance == smallestDistance && j > m_preferredSize)) { | 273 | if (distance < smallestDistance || (distance == smallestDistance && j > m_preferredSize)) { | ||
279 | smallestDistance = distance; | 274 | smallestDistance = distance; | ||
280 | selectItem = i; | 275 | selectItem = i; | ||
281 | }; | | |||
282 | } | 276 | } | ||
283 | }; | 277 | } | ||
278 | } | ||||
284 | if (selectItem < 0) { | 279 | if (selectItem < 0) { | ||
285 | selectItem = 0; | 280 | selectItem = 0; | ||
286 | } | 281 | } | ||
287 | setSelectedSizeRow(selectItem); | 282 | setSelectedSizeRow(selectItem); | ||
288 | }; | 283 | } | ||
289 | }; | 284 | } | ||
290 | 285 | | |||
291 | // enable or disable the combobox | 286 | // enable or disable the combobox | ||
292 | KConfig c("kcminputrc"); | 287 | KConfig c("kcminputrc"); | ||
293 | KConfigGroup cg(&c, "Mouse"); | 288 | KConfigGroup cg(&c, "Mouse"); | ||
294 | if (cg.isEntryImmutable("cursorSize")) { | 289 | if (cg.isEntryImmutable("cursorSize")) { | ||
295 | setCanResize(false); | 290 | setCanResize(false); | ||
296 | } else { | 291 | } else { | ||
297 | setCanResize(m_sizesModel->rowCount() > 0); | 292 | setCanResize(m_sizesModel->rowCount() > 0); | ||
298 | }; | 293 | } | ||
299 | 294 | | |||
300 | } | 295 | } | ||
301 | 296 | | |||
302 | bool CursorThemeConfig::applyTheme(const CursorTheme *theme, const int size) | 297 | bool CursorThemeConfig::applyTheme(const CursorTheme *theme, const int size) | ||
303 | { | 298 | { | ||
304 | // Require the Xcursor version that shipped with X11R6.9 or greater, since | 299 | // Require the Xcursor version that shipped with X11R6.9 or greater, since | ||
305 | // in previous versions the Xfixes code wasn't enabled due to a bug in the | 300 | // in previous versions the Xfixes code wasn't enabled due to a bug in the | ||
306 | // build system (freedesktop bug #975). | 301 | // build system (freedesktop bug #975). | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | |||||
362 | void CursorThemeConfig::save() | 357 | void CursorThemeConfig::save() | ||
363 | { | 358 | { | ||
364 | const CursorTheme *theme = selectedIndex().isValid() ? m_proxyModel->theme(selectedIndex()) : nullptr; | 359 | const CursorTheme *theme = selectedIndex().isValid() ? m_proxyModel->theme(selectedIndex()) : nullptr; | ||
365 | 360 | | |||
366 | KConfig config("kcminputrc"); | 361 | KConfig config("kcminputrc"); | ||
367 | KConfigGroup c(&config, "Mouse"); | 362 | KConfigGroup c(&config, "Mouse"); | ||
368 | if (theme) { | 363 | if (theme) { | ||
369 | c.writeEntry("cursorTheme", theme->name()); | 364 | c.writeEntry("cursorTheme", theme->name()); | ||
370 | }; | 365 | } | ||
371 | c.writeEntry("cursorSize", m_preferredSize); | 366 | c.writeEntry("cursorSize", m_preferredSize); | ||
372 | c.sync(); | 367 | c.sync(); | ||
373 | 368 | | |||
374 | if (!applyTheme(theme, m_preferredSize)) { | 369 | if (!applyTheme(theme, m_preferredSize)) { | ||
375 | emit showInfoMessage(i18n("You have to restart the Plasma session for these changes to take effect.")); | 370 | emit showInfoMessage(i18n("You have to restart the Plasma session for these changes to take effect.")); | ||
376 | } | 371 | } | ||
377 | 372 | | |||
378 | m_appliedIndex = selectedIndex(); | 373 | m_appliedIndex = selectedIndex(); | ||
Show All 26 Lines | 382 | { | |||
405 | } | 400 | } | ||
406 | 401 | | |||
407 | // Disable the listview and the buttons if we're in kiosk mode | 402 | // Disable the listview and the buttons if we're in kiosk mode | ||
408 | if (cg.isEntryImmutable("cursorTheme")) { | 403 | if (cg.isEntryImmutable("cursorTheme")) { | ||
409 | setCanConfigure(false); | 404 | setCanConfigure(false); | ||
410 | setCanInstall(false); | 405 | setCanInstall(false); | ||
411 | } | 406 | } | ||
412 | 407 | | |||
413 | const CursorTheme *theme = m_proxyModel->theme(m_appliedIndex); | | |||
414 | | ||||
415 | setSelectedThemeRow(m_appliedIndex.row()); | 408 | setSelectedThemeRow(m_appliedIndex.row()); | ||
416 | m_originalSelectedThemeRow = m_selectedThemeRow; | 409 | m_originalSelectedThemeRow = m_selectedThemeRow; | ||
417 | 410 | | |||
418 | // Load cursor size | 411 | // Load cursor size | ||
419 | int size = cg.readEntry("cursorSize", 0); | 412 | int size = cg.readEntry("cursorSize", 0); | ||
420 | if (size <= 0) { | 413 | if (size <= 0) { | ||
421 | m_preferredSize = 0; | 414 | m_preferredSize = 0; | ||
422 | } else { | 415 | } else { | ||
Show All 13 Lines | |||||
436 | { | 429 | { | ||
437 | QModelIndex defaultIndex = m_proxyModel->findIndex("breeze_cursors"); | 430 | QModelIndex defaultIndex = m_proxyModel->findIndex("breeze_cursors"); | ||
438 | setSelectedThemeRow(defaultIndex.row()); | 431 | setSelectedThemeRow(defaultIndex.row()); | ||
439 | m_preferredSize = 0; | 432 | m_preferredSize = 0; | ||
440 | updateSizeComboBox(); | 433 | updateSizeComboBox(); | ||
441 | setNeedsSave(m_originalSelectedThemeRow != m_selectedThemeRow || m_originalPreferredSize != m_preferredSize); | 434 | setNeedsSave(m_originalSelectedThemeRow != m_selectedThemeRow || m_originalPreferredSize != m_preferredSize); | ||
442 | } | 435 | } | ||
443 | 436 | | |||
444 | | ||||
445 | void CursorThemeConfig::selectionChanged() | | |||
446 | { | | |||
447 | updateSizeComboBox(); | | |||
448 | | ||||
449 | setNeedsSave(m_originalSelectedThemeRow != m_selectedThemeRow || m_originalPreferredSize != m_preferredSize); | | |||
450 | //setNeedsSave(m_appliedIndex != selectedIndex()); | | |||
451 | } | | |||
452 | | ||||
453 | QModelIndex CursorThemeConfig::selectedIndex() const | 437 | QModelIndex CursorThemeConfig::selectedIndex() const | ||
454 | { | 438 | { | ||
455 | return m_proxyModel->index(m_selectedThemeRow, 0); | 439 | return m_proxyModel->index(m_selectedThemeRow, 0); | ||
456 | } | 440 | } | ||
457 | 441 | | |||
458 | void CursorThemeConfig::getNewClicked() | 442 | void CursorThemeConfig::getNewClicked() | ||
459 | { | 443 | { | ||
460 | KNS3::DownloadDialog dialog("xcursor.knsrc", nullptr); | 444 | KNS3::DownloadDialog dialog("xcursor.knsrc", nullptr); | ||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Line(s) | 536 | if (themeDirs.isEmpty()) { | |||
554 | return; | 538 | return; | ||
555 | } | 539 | } | ||
556 | 540 | | |||
557 | // The directory we'll install the themes to | 541 | // The directory we'll install the themes to | ||
558 | QString destDir = QDir::homePath() + "/.icons/"; | 542 | QString destDir = QDir::homePath() + "/.icons/"; | ||
559 | if (!QDir().mkpath(destDir)) { | 543 | if (!QDir().mkpath(destDir)) { | ||
560 | emit showErrorMessage(i18n("Failed to create 'icons' folder.")); | 544 | emit showErrorMessage(i18n("Failed to create 'icons' folder.")); | ||
561 | return; | 545 | return; | ||
562 | }; | 546 | } | ||
563 | 547 | | |||
564 | // Process each cursor theme in the archive | 548 | // Process each cursor theme in the archive | ||
565 | foreach (const QString &dirName, themeDirs) { | 549 | foreach (const QString &dirName, themeDirs) { | ||
566 | QDir dest(destDir + dirName); | 550 | QDir dest(destDir + dirName); | ||
567 | if (dest.exists()) { | 551 | if (dest.exists()) { | ||
568 | QString question = i18n("A theme named %1 already exists in your icon " | 552 | QString question = i18n("A theme named %1 already exists in your icon " | ||
569 | "theme folder. Do you want replace it with this one?", dirName); | 553 | "theme folder. Do you want replace it with this one?", dirName); | ||
570 | 554 | | |||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |
Shouldn't be in that patch.