Changeset View
Changeset View
Standalone View
Standalone View
wallpapers/image/image.cpp
Show All 40 Lines | |||||
41 | #include <QQuickItem> | 41 | #include <QQuickItem> | ||
42 | #include <QQuickWindow> | 42 | #include <QQuickWindow> | ||
43 | 43 | | |||
44 | #include <QDebug> | 44 | #include <QDebug> | ||
45 | #include <KDirWatch> | 45 | #include <KDirWatch> | ||
46 | #include <QFileDialog> | 46 | #include <QFileDialog> | ||
47 | #include <KRandom> | 47 | #include <KRandom> | ||
48 | #include <KIO/Job> | 48 | #include <KIO/Job> | ||
49 | #include <KIO/CopyJob> | ||||
49 | #include <krun.h> | 50 | #include <krun.h> | ||
50 | #include <klocalizedstring.h> | 51 | #include <klocalizedstring.h> | ||
51 | 52 | | |||
52 | #include <Plasma/Theme> | 53 | #include <Plasma/Theme> | ||
53 | #include <Plasma/PluginLoader> | 54 | #include <Plasma/PluginLoader> | ||
54 | #include <qstandardpaths.h> | 55 | #include <qstandardpaths.h> | ||
55 | #include "backgroundlistmodel.h" | 56 | #include "backgroundlistmodel.h" | ||
56 | #include "slidemodel.h" | 57 | #include "slidemodel.h" | ||
▲ Show 20 Lines • Show All 489 Lines • ▼ Show 20 Line(s) | 546 | path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, | |||
546 | QLatin1String("wallpapers/") + url.path(), | 547 | QLatin1String("wallpapers/") + url.path(), | ||
547 | QStandardPaths::LocateDirectory); | 548 | QStandardPaths::LocateDirectory); | ||
548 | } | 549 | } | ||
549 | 550 | | |||
550 | if (path.isEmpty()) { | 551 | if (path.isEmpty()) { | ||
551 | return; | 552 | return; | ||
552 | } | 553 | } | ||
553 | } else { | 554 | } else { | ||
554 | QString wallpaperPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("wallpapers/") + url.path(); | 555 | QDir wallpaperDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/wallpapers/"); | ||
556 | const QString wallpaperPath = wallpaperDir.absoluteFilePath(url.fileName()); | ||||
557 | | ||||
558 | if (wallpaperDir.mkpath(wallpaperDir.absolutePath()) && !url.fileName().isEmpty()) { | ||||
mart: this is for first run when ~/.local/share/wallpapers isn't there yet? | |||||
This is to check if the directory is available before copying, otherwise FileCopyJob would fail. trmdi: This is to check if the directory is available before copying, otherwise FileCopyJob would fail. | |||||
559 | KIO::CopyJob *job = KIO::copy(url, QUrl::fromLocalFile(wallpaperPath), KIO::HideProgressInfo); | ||||
mart: I would prefer it to ask before owerwriting | |||||
trmdi: Do I need to modify this or just land it now? | |||||
555 | 560 | | |||
556 | if (!wallpaperPath.isEmpty()) { | | |||
557 | KIO::FileCopyJob *job = KIO::file_copy(url, QUrl(wallpaperPath), -1, KIO::HideProgressInfo); | | |||
558 | if (setAsCurrent) { | 561 | if (setAsCurrent) { | ||
559 | connect(job, &KJob::result, this, &Image::setWallpaperRetrieved); | 562 | connect(job, &KJob::result, this, &Image::setWallpaperRetrieved); | ||
560 | } else { | 563 | } else { | ||
561 | connect(job, &KJob::result, this, &Image::addWallpaperRetrieved); | 564 | connect(job, &KJob::result, this, &Image::addWallpaperRetrieved); | ||
562 | } | 565 | } | ||
563 | } | 566 | } | ||
564 | 567 | | |||
565 | return; | 568 | return; | ||
566 | } | 569 | } | ||
567 | 570 | | |||
568 | if (setAsCurrent) { | 571 | if (setAsCurrent) { | ||
569 | setWallpaper(path); | 572 | setWallpaper(path); | ||
570 | } else { | 573 | } else { | ||
571 | if (m_mode != SingleImage) { | 574 | if (m_mode != SingleImage) { | ||
572 | // it's a slide show, add it to the slide show | 575 | // it's a slide show, add it to the slide show | ||
573 | m_slideshowModel->addBackground(path); | 576 | m_slideshowModel->addBackground(path); | ||
574 | } | 577 | } | ||
575 | // always add it to the user papers, though | 578 | // always add it to the user papers, though | ||
576 | addUsersWallpaper(path); | 579 | addUsersWallpaper(path); | ||
577 | } | 580 | } | ||
578 | } | 581 | } | ||
579 | 582 | | |||
580 | void Image::setWallpaperRetrieved(KJob *job) | 583 | void Image::setWallpaperRetrieved(KJob *job) | ||
581 | { | 584 | { | ||
582 | KIO::FileCopyJob *copyJob = qobject_cast<KIO::FileCopyJob *>(job); | 585 | KIO::CopyJob *copyJob = qobject_cast<KIO::CopyJob *>(job); | ||
583 | if (copyJob && !copyJob->error()) { | 586 | if (copyJob && !copyJob->error()) { | ||
584 | setWallpaper(copyJob->destUrl().toLocalFile()); | 587 | setWallpaper(copyJob->destUrl().toLocalFile()); | ||
585 | } | 588 | } | ||
586 | } | 589 | } | ||
587 | 590 | | |||
588 | void Image::addWallpaperRetrieved(KJob *job) | 591 | void Image::addWallpaperRetrieved(KJob *job) | ||
589 | { | 592 | { | ||
590 | KIO::FileCopyJob *copyJob = qobject_cast<KIO::FileCopyJob *>(job); | 593 | KIO::CopyJob *copyJob = qobject_cast<KIO::CopyJob *>(job); | ||
591 | if (copyJob && !copyJob->error()) { | 594 | if (copyJob && !copyJob->error()) { | ||
592 | addUrl(copyJob->destUrl(), false); | 595 | addUrl(copyJob->destUrl(), false); | ||
593 | } | 596 | } | ||
594 | } | 597 | } | ||
595 | 598 | | |||
596 | void Image::setWallpaper(const QString &path) | 599 | void Image::setWallpaper(const QString &path) | ||
597 | { | 600 | { | ||
598 | if (m_mode == SingleImage) { | 601 | if (m_mode == SingleImage) { | ||
▲ Show 20 Lines • Show All 301 Lines • Show Last 20 Lines |
this is for first run when ~/.local/share/wallpapers isn't there yet?