File indexing completed on 2025-01-05 03:53:17
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2019-04-02 0007 * Description : plugin to export image as wallpaper - macOS version. 0008 * 0009 * SPDX-FileCopyrightText: 2019 by Igor Antropov <antropovi at yahoo dot com> 0010 * SPDX-FileCopyrightText: 2019-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "wallpaperplugin.h" 0017 0018 // Qt includes 0019 0020 #include <QStringList> 0021 #include <QMessageBox> 0022 #include <QProcess> 0023 0024 // KDE includes 0025 0026 #include <klocalizedstring.h> 0027 0028 // Local includes 0029 0030 #include "digikam_debug.h" 0031 0032 namespace DigikamGenericWallpaperPlugin 0033 { 0034 0035 bool WallpaperPlugin::setWallpaper(const QString& path, int layout) const 0036 { 0037 /** 0038 * NOTE: sound like macOS < BigSur do not provide a way to customize the wallpaper layout. 0039 * Find a way to pass layout setting to osascript. 0040 * Possible values are in this order from macOS control panel: Adjusted, AdjustedAspectRatio, AdjustedCropped, Centered, Mosaic. 0041 */ 0042 Q_UNUSED(layout); 0043 0044 QStringList args; 0045 args << QLatin1String("-e"); 0046 args << QLatin1String("tell application \"System Events\""); 0047 args << QLatin1String("-e"); 0048 args << QLatin1String("tell current desktop"); 0049 args << QLatin1String("-e"); 0050 args << QString::fromUtf8("set picture to POSIX file \"%1\"").arg(path); 0051 args << QLatin1String("-e"); 0052 args << QLatin1String("end tell"); 0053 args << QLatin1String("-e"); 0054 args << QLatin1String("end tell"); 0055 args << QLatin1String("-e"); 0056 args << QLatin1String("return"); 0057 0058 int ret = QProcess::execute(QLatin1String("/usr/bin/osascript"), args); 0059 0060 if ((ret == -1) || (ret == 2)) 0061 { 0062 QMessageBox::warning(nullptr, 0063 i18nc("@title:window", 0064 "Error While to Set Image as Wallpaper"), 0065 i18nc("@info", "Cannot change wallpaper image from current desktop with\n%1", 0066 path)); 0067 0068 return false; 0069 } 0070 0071 return true; 0072 } 0073 0074 } // namespace DigikamGenericWallpaperPlugin