Changeset View
Changeset View
Standalone View
Standalone View
wallpapers/image/image.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
48 | #include <krun.h> | 48 | #include <krun.h> | ||
49 | #include <KNewStuff3/KNS3/DownloadDialog> | 49 | #include <KNewStuff3/KNS3/DownloadDialog> | ||
50 | #include <klocalizedstring.h> | 50 | #include <klocalizedstring.h> | ||
51 | 51 | | |||
52 | #include <Plasma/Theme> | 52 | #include <Plasma/Theme> | ||
53 | #include <Plasma/PluginLoader> | 53 | #include <Plasma/PluginLoader> | ||
54 | #include <qstandardpaths.h> | 54 | #include <qstandardpaths.h> | ||
55 | #include "backgroundlistmodel.h" | 55 | #include "backgroundlistmodel.h" | ||
56 | #include "slidemodel.h" | ||||
56 | 57 | | |||
57 | #include <KPackage/PackageLoader> | 58 | #include <KPackage/PackageLoader> | ||
58 | 59 | | |||
59 | Image::Image(QObject *parent) | 60 | Image::Image(QObject *parent) | ||
60 | : QObject(parent), | 61 | : QObject(parent), | ||
61 | m_ready(false), | 62 | m_ready(false), | ||
62 | m_delay(10), | 63 | m_delay(10), | ||
63 | m_dirWatch(new KDirWatch(this)), | 64 | m_dirWatch(new KDirWatch(this)), | ||
64 | m_mode(SingleImage), | 65 | m_mode(SingleImage), | ||
65 | m_currentSlide(-1), | 66 | m_currentSlide(-1), | ||
66 | m_model(nullptr), | 67 | m_model(nullptr), | ||
68 | m_slideshowModel(nullptr), | ||||
67 | m_dialog(nullptr) | 69 | m_dialog(nullptr) | ||
68 | { | 70 | { | ||
69 | m_wallpaperPackage = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Wallpaper/Images")); | 71 | m_wallpaperPackage = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Wallpaper/Images")); | ||
70 | 72 | | |||
71 | connect(&m_timer, &QTimer::timeout, this, &Image::nextSlide); | 73 | connect(&m_timer, &QTimer::timeout, this, &Image::nextSlide); | ||
72 | 74 | | |||
73 | connect(m_dirWatch, &KDirWatch::created, this, &Image::pathCreated); | 75 | connect(m_dirWatch, &KDirWatch::created, this, &Image::pathCreated); | ||
74 | connect(m_dirWatch, &KDirWatch::dirty, this, &Image::pathDirty); | 76 | connect(m_dirWatch, &KDirWatch::dirty, this, &Image::pathDirty); | ||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Line(s) | 268 | if (!m_model) { | |||
270 | 272 | | |||
271 | m_model = new BackgroundListModel(this, this); | 273 | m_model = new BackgroundListModel(this, this); | ||
272 | m_model->reload(m_usersWallpapers); | 274 | m_model->reload(m_usersWallpapers); | ||
273 | } | 275 | } | ||
274 | 276 | | |||
275 | return m_model; | 277 | return m_model; | ||
276 | } | 278 | } | ||
277 | 279 | | |||
280 | QAbstractItemModel* Image::slideshowModel() | ||||
281 | { | ||||
282 | if (!m_slideshowModel) { | ||||
283 | m_slideshowModel = new SlideModel(this, this); | ||||
284 | m_slideshowModel->reload(m_slidePaths); | ||||
285 | } | ||||
286 | return m_slideshowModel; | ||||
287 | } | ||||
288 | | ||||
278 | int Image::slideTimer() const | 289 | int Image::slideTimer() const | ||
279 | { | 290 | { | ||
280 | return m_delay; | 291 | return m_delay; | ||
281 | } | 292 | } | ||
282 | 293 | | |||
283 | void Image::setSlideTimer(int time) | 294 | void Image::setSlideTimer(int time) | ||
284 | { | 295 | { | ||
285 | if (time == m_delay) { | 296 | if (time == m_delay) { | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 334 | { | |||
331 | if (m_slidePaths.isEmpty()) { | 342 | if (m_slidePaths.isEmpty()) { | ||
332 | m_slidePaths << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("share/wallpapers"), QStandardPaths::LocateDirectory); | 343 | m_slidePaths << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("share/wallpapers"), QStandardPaths::LocateDirectory); | ||
333 | } | 344 | } | ||
334 | 345 | | |||
335 | if (m_mode == SlideShow) { | 346 | if (m_mode == SlideShow) { | ||
336 | updateDirWatch(m_slidePaths); | 347 | updateDirWatch(m_slidePaths); | ||
337 | startSlideshow(); | 348 | startSlideshow(); | ||
338 | } | 349 | } | ||
339 | 350 | if (m_slideshowModel) { | |||
351 | m_slideshowModel->reload(m_slidePaths); | ||||
352 | } | ||||
340 | emit slidePathsChanged(); | 353 | emit slidePathsChanged(); | ||
341 | } | 354 | } | ||
342 | 355 | | |||
343 | void Image::showAddSlidePathsDialog() | 356 | void Image::showAddSlidePathsDialog() | ||
344 | { | 357 | { | ||
345 | QFileDialog *dialog = new QFileDialog(nullptr, i18n("Directory with the wallpaper to show slides from"), QString()); | 358 | QFileDialog *dialog = new QFileDialog(nullptr, i18n("Directory with the wallpaper to show slides from"), QString()); | ||
346 | dialog->setAttribute(Qt::WA_DeleteOnClose, true ); | 359 | dialog->setAttribute(Qt::WA_DeleteOnClose, true ); | ||
347 | dialog->setOptions(QFileDialog::ShowDirsOnly); | 360 | dialog->setOptions(QFileDialog::ShowDirsOnly); | ||
348 | dialog->setAcceptMode(QFileDialog::AcceptOpen); | 361 | dialog->setAcceptMode(QFileDialog::AcceptOpen); | ||
349 | connect(dialog, &QDialog::accepted, this, &Image::addDirFromSelectionDialog); | 362 | connect(dialog, &QDialog::accepted, this, &Image::addDirFromSelectionDialog); | ||
350 | dialog->show(); | 363 | dialog->show(); | ||
351 | } | 364 | } | ||
352 | 365 | | |||
353 | void Image::addSlidePath(const QString &path) | 366 | void Image::addSlidePath(const QString &path) | ||
354 | { | 367 | { | ||
355 | if (!path.isEmpty() && !m_slidePaths.contains(path)) { | 368 | if (!path.isEmpty() && !m_slidePaths.contains(path)) { | ||
356 | m_slidePaths.append(path); | 369 | m_slidePaths.append(path); | ||
357 | if (m_mode == SlideShow) { | 370 | if (m_mode == SlideShow) { | ||
358 | updateDirWatch(m_slidePaths); | 371 | updateDirWatch(m_slidePaths); | ||
359 | } | 372 | } | ||
360 | 373 | if (m_slideshowModel) { | |||
374 | m_slideshowModel->reload(m_slidePaths); | ||||
375 | } | ||||
361 | emit slidePathsChanged(); | 376 | emit slidePathsChanged(); | ||
362 | startSlideshow(); | 377 | startSlideshow(); | ||
363 | } | 378 | } | ||
364 | } | 379 | } | ||
365 | 380 | | |||
366 | void Image::removeSlidePath(const QString &path) | 381 | void Image::removeSlidePath(const QString &path) | ||
367 | { | 382 | { | ||
368 | if (m_slidePaths.contains(path)) { | 383 | if (m_slidePaths.contains(path)) { | ||
369 | m_slidePaths.removeAll(path); | 384 | m_slidePaths.removeAll(path); | ||
370 | if (m_mode == SlideShow) { | 385 | if (m_mode == SlideShow) { | ||
371 | updateDirWatch(m_slidePaths); | 386 | updateDirWatch(m_slidePaths); | ||
372 | } | 387 | } | ||
373 | 388 | if (m_slideshowModel) { | |||
389 | m_slideshowModel->removeDir(path); | ||||
390 | } | ||||
374 | emit slidePathsChanged(); | 391 | emit slidePathsChanged(); | ||
375 | startSlideshow(); | 392 | startSlideshow(); | ||
376 | } | 393 | } | ||
377 | } | 394 | } | ||
378 | 395 | | |||
379 | void Image::pathDirty(const QString& path) | 396 | void Image::pathDirty(const QString& path) | ||
380 | { | 397 | { | ||
381 | updateDirWatch(QStringList(path)); | 398 | updateDirWatch(QStringList(path)); | ||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Line(s) | 590 | { | |||
577 | 594 | | |||
578 | m_findToken.clear(); | 595 | m_findToken.clear(); | ||
579 | 596 | | |||
580 | if(m_scanDirty) { | 597 | if(m_scanDirty) { | ||
581 | m_scanDirty = false; | 598 | m_scanDirty = false; | ||
582 | startSlideshow(); | 599 | startSlideshow(); | ||
583 | return; | 600 | return; | ||
584 | } | 601 | } | ||
585 | | ||||
586 | m_slideshowBackgrounds = paths; | 602 | m_slideshowBackgrounds = paths; | ||
587 | m_unseenSlideshowBackgrounds.clear(); | 603 | m_unseenSlideshowBackgrounds.clear(); | ||
588 | // start slideshow | 604 | // start slideshow | ||
589 | if (m_slideshowBackgrounds.isEmpty()) { | 605 | if (m_slideshowBackgrounds.isEmpty()) { | ||
590 | // no image has been found, which is quite weird... try again later (this is useful for events which | 606 | // no image has been found, which is quite weird... try again later (this is useful for events which | ||
591 | // are not detected by KDirWatch, like a NFS directory being mounted) | 607 | // are not detected by KDirWatch, like a NFS directory being mounted) | ||
592 | QTimer::singleShot(1000, this, &Image::startSlideshow); | 608 | QTimer::singleShot(1000, this, &Image::startSlideshow); | ||
593 | } else { | 609 | } else { | ||
▲ Show 20 Lines • Show All 255 Lines • ▼ Show 20 Line(s) | 863 | { | |||
849 | //we can't be sure the model exists | 865 | //we can't be sure the model exists | ||
850 | if (!m_model) { | 866 | if (!m_model) { | ||
851 | return; | 867 | return; | ||
852 | } | 868 | } | ||
853 | 869 | | |||
854 | for (const QString &wallpaperCandidate : m_model->wallpapersAwaitingDeletion()) { | 870 | for (const QString &wallpaperCandidate : m_model->wallpapersAwaitingDeletion()) { | ||
855 | removeWallpaper(wallpaperCandidate); | 871 | removeWallpaper(wallpaperCandidate); | ||
856 | } | 872 | } | ||
857 | } | 873 | } | ||
davidedmundson: You update m_uncheckedSlides but you're not updating m_slideshowBackgrounds so it does nothing… | |||||
davidre: Thanks for spotting this, will try testing this. | |||||
This generates a warning (variable krun is unused). I would suggest using KIO::highlightInFileManager() instead. For example: https://cgit.kde.org/spectacle.git/tree/src/Gui/KSMainWindow.cpp#n327 ngraham: This generates a warning (variable `krun` is unused). I would suggest using `KIO… | |||||
Yes I also saw this method since the backgroundlist uses it but the Header said to use KRun if you want to open a folder instead of it. davidre: Yes I also saw this method since the backgroundlist uses it but the Header said to use KRun if… | |||||
Well it just depends on what you want to do. If you want to open the folder, then yeah KRun is better. But if you want to highlight it in a file manager window, then highlightInFileManager() is the way to go. ngraham: Well it just depends on what you want to do. If you want to open the folder, then yeah KRun is… | |||||
858 | |
You update m_uncheckedSlides but you're not updating m_slideshowBackgrounds so it does nothing till you restart