Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions libimageviewer/unionimage/imageutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,6 @@ bool imageSupportSave(const QString &path)
#endif
}

//bool imageSupportWrite(const QString &path)
//{
// /*lmh0724使用USE_UNIONIMAGE*/
//#ifdef USE_UNIONIMAGE
// return UnionImage_NameSpace::canSave(path);
//#else
// return freeimage::isSupportsWriting(path);
//#endif
//}

bool rotate(const QString &path, int degree)
{
/*lmh0724使用USE_UNIONIMAGE*/
Expand Down Expand Up @@ -787,25 +777,17 @@ bool imageSupportWallPaper(const QString &path)
&& !mt.name().endsWith("x-portable-anymap");
}

//bool suffixisImage(const QString &path)
//{
//#ifdef USE_UNIONIMAGE
// return UnionImage_NameSpace::suffixisImage(path);
//#else
// bool iRet = false;
// QFileInfo info(path);
// QMimeDatabase db;
// QMimeType mt = db.mimeTypeForFile(path, QMimeDatabase::MatchContent);
// QMimeType mt1 = db.mimeTypeForFile(path, QMimeDatabase::MatchExtension);
// QString str = info.suffix();
// // if (!m_nosupportformat.contains(str, Qt::CaseSensitive)) {
// if (mt.name().startsWith("image/") || mt.name().startsWith("video/x-mng") ||
// mt1.name().startsWith("image/") || mt1.name().startsWith("video/x-mng")) {
// iRet = true;
// }
// return iRet;
//#endif
//}
/**
@return 返回文件类型是否可以直接设置锁屏壁纸
壁纸支持 jpeg jpg png bmp tif gif
锁屏支持 jpeg jpg png
*/
bool imageSupportGreeterDirect(const QString &path)
{
QMimeDatabase db;
QMimeType mt = db.mimeTypeForFile(path, QMimeDatabase::MatchDefault);
return "image/jpeg" == mt.name() || "image/png" == mt.name();
}

QString makeVaultLocalPath(const QString &path, const QString &base)
{
Expand Down
6 changes: 1 addition & 5 deletions libimageviewer/unionimage/imageutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,10 @@ const QImage getRotatedImage(const QString &path);
const QImage loadTga(QString filePath, bool &success);
#endif

/*
* lmh0901,根据后缀是否是图片
**/
//bool suffixisImage(const QString &path);
bool imageSupportRead(const QString &path);
bool imageSupportSave(const QString &path);
//bool imageSupportWrite(const QString &path);
bool imageSupportWallPaper(const QString &path);
bool imageSupportGreeterDirect(const QString &path);
bool rotate(const QString &path, int degree);
const QImage scaleImage(const QString &path,
const QSize &size = QSize(384, 383));
Expand Down
170 changes: 69 additions & 101 deletions libimageviewer/viewpanel/viewpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,61 +827,75 @@ void LibViewPanel::setContextMenuItemVisible(imageViewerSpace::NormalMenuItemId
updateMenuContent();
}

/**
@brief 通过DBus接口设置图片 \a path 为壁纸
task 32367: 同时设置为锁屏壁纸
*/
static void setWallpaperWithDBus(const QString &path)
{
//202011/12 bug54279 设置壁纸代码改变,采用DBus
qDebug() << "SettingWallpaper: " << "flatpak" << path;
QDBusInterface interface("com.deepin.daemon.Appearance",
"/com/deepin/daemon/Appearance",
"com.deepin.daemon.Appearance");

if (interface.isValid()) {
QString screenname;

//判断环境是否是wayland
auto e = QProcessEnvironment::systemEnvironment();
QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
QString WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));

bool isWayland = false;
if (XDG_SESSION_TYPE != QLatin1String("wayland") && !WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive)) {
isWayland = false;
} else {
isWayland = true;
}

// wayland下设置壁纸使用,2020/09/21
if (isWayland) {
QDBusInterface interfaceWayland("com.deepin.daemon.Display", "/com/deepin/daemon/Display", "com.deepin.daemon.Display");
screenname = qvariant_cast< QString >(interfaceWayland.property("Primary"));
} else {
screenname = QGuiApplication::primaryScreen()->name();
}
QDBusMessage reply = interface.call(QStringLiteral("SetMonitorBackground"), screenname, path);
QString error = reply.errorMessage();
if (!error.isEmpty()) {
qWarning() << "SettingWallpaper: replay" << reply.errorMessage();
}

// 新增需求32367:同时设置锁屏壁纸
reply = interface.call(QStringLiteral("Set"), QStringLiteral("greeterbackground"), path);
error = reply.errorMessage();
if (!error.isEmpty()) {
qWarning() << "Set greeterbackground: replay" << reply.errorMessage();
}

// 通知触发设置壁纸动作(属于拷贝动作)
PermissionConfig::instance()->triggerAction(PermissionConfig::TidCopy, path);
} else {
qWarning() << "SettingWallpaper failed" << interface.lastError();
}
}

void LibViewPanel::setWallpaper(const QImage &img)
{
QThread *th1 = QThread::create([ = ]() {
if (!img.isNull()) {
QString path = "/tmp/DIVIMG.png";
img.save("/tmp/DIVIMG.png", "png");
//202011/12 bug54279
{
//设置壁纸代码改变,采用DBus,原方法保留
if (/*!qEnvironmentVariableIsEmpty("FLATPAK_APPID")*/1) {
// gdbus call -e -d com.deepin.daemon.Appearance -o /com/deepin/daemon/Appearance -m com.deepin.daemon.Appearance.Set background /home/test/test.png
qDebug() << "SettingWallpaper: " << "flatpak" << path;
QDBusInterface interface("com.deepin.daemon.Appearance",
"/com/deepin/daemon/Appearance",
"com.deepin.daemon.Appearance");
// if (interface.isValid()) {
// //获取鼠标在的位置的桌面
// QString screenname = QGuiApplication::screenAt(QCursor::pos())->name();
// QDBusMessage reply = interface.call(QStringLiteral("SetMonitorBackground"), screenname, path);
// qDebug() << "SettingWallpaper: replay" << reply.errorMessage();
// }
if (interface.isValid()) {
QString screenname;

//判断环境是否是wayland
auto e = QProcessEnvironment::systemEnvironment();
QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
QString WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));

bool isWayland = false;
if (XDG_SESSION_TYPE != QLatin1String("wayland") && !WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive)) {
isWayland = false;
} else {
isWayland = true;
}
//wayland下设置壁纸使用,2020/09/21
if (isWayland) {
QDBusInterface interfaceWayland("com.deepin.daemon.Display", "/com/deepin/daemon/Display", "com.deepin.daemon.Display");
screenname = qvariant_cast< QString >(interfaceWayland.property("Primary"));
} else {
screenname = QGuiApplication::primaryScreen()->name();
}
QDBusMessage reply = interface.call(QStringLiteral("SetMonitorBackground"), screenname, path);
qDebug() << "SettingWallpaper: replay" << reply.errorMessage();
} else {
qWarning() << "SettingWallpaper failed" << interface.lastError();
}
}
// // Remove the tmp file
// QTimer::singleShot(1000,this, [ = ] {
// QFile(path).remove();
// });


// 设置锁屏壁纸不能使用相同名称,且临时文件不能立即删除(调用DBus接口拷贝需要时间),保留至缓存目录,程序退出自动清理
QTemporaryFile tmpImage;
tmpImage.setAutoRemove(false);
tmpImage.setFileTemplate(Libutils::image::getCacheImagePath() + QDir::separator() + "XXXXXX_Wallpaper.png");
if (!tmpImage.open() || !img.save(tmpImage.fileName(), "PNG")) {
qWarning() << QString("Copy image set wallpaper failed! path: %1").arg(tmpImage.fileName());
return;
}
qInfo() << QString("Copy image set wallpaper, path: %1").arg(tmpImage.fileName());

setWallpaperWithDBus(tmpImage.fileName());
}
});
connect(th1, &QThread::finished, th1, &QObject::deleteLater);
Expand All @@ -892,53 +906,7 @@ void LibViewPanel::setWallpaper(const QString &imgPath)
{
QThread *th1 = QThread::create([ = ]() {
if (!imgPath.isNull()) {
QString path = imgPath;
//202011/12 bug54279
{
//设置壁纸代码改变,采用DBus,原方法保留
if (/*!qEnvironmentVariableIsEmpty("FLATPAK_APPID")*/1) {
// gdbus call -e -d com.deepin.daemon.Appearance -o /com/deepin/daemon/Appearance -m com.deepin.daemon.Appearance.Set background /home/test/test.png
qDebug() << "SettingWallpaper: " << "flatpak" << path;
QDBusInterface interface("com.deepin.daemon.Appearance",
"/com/deepin/daemon/Appearance",
"com.deepin.daemon.Appearance");
// if (interface.isValid()) {
// //获取鼠标在的位置的桌面
// QString screenname = QGuiApplication::screenAt(QCursor::pos())->name();
// QDBusMessage reply = interface.call(QStringLiteral("SetMonitorBackground"), screenname, path);
// qDebug() << "SettingWallpaper: replay" << reply.errorMessage();
// }
if (interface.isValid()) {
QString screenname;

//判断环境是否是wayland
auto e = QProcessEnvironment::systemEnvironment();
QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
QString WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));

bool isWayland = false;
if (XDG_SESSION_TYPE != QLatin1String("wayland") && !WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive)) {
isWayland = false;
} else {
isWayland = true;
}
//wayland下设置壁纸使用,2020/09/21
if (isWayland) {
QDBusInterface interfaceWayland("com.deepin.daemon.Display", "/com/deepin/daemon/Display", "com.deepin.daemon.Display");
screenname = qvariant_cast< QString >(interfaceWayland.property("Primary"));
} else {
screenname = QGuiApplication::primaryScreen()->name();
}
QDBusMessage reply = interface.call(QStringLiteral("SetMonitorBackground"), screenname, path);
qDebug() << "SettingWallpaper: replay" << reply.errorMessage();

// 通知触发设置壁纸动作(属于拷贝动作)
PermissionConfig::instance()->triggerAction(PermissionConfig::TidCopy, path);
} else {
qWarning() << "SettingWallpaper failed" << interface.lastError();
}
}
}
setWallpaperWithDBus(imgPath);
}
});
connect(th1, &QThread::finished, th1, &QObject::deleteLater);
Expand Down Expand Up @@ -1885,12 +1853,12 @@ void LibViewPanel::onMenuItemClicked(QAction *action)
if (m_view) {
m_view->slotRotatePixCurrent();
}
//todo设置壁纸
qDebug() << m_currentPath;
// setWallpaper(m_view->image());
if (!m_currentPath.isNull() && m_view->getcurrentImgCount() <= 1) {

// 仅 jpeg 和 png 图片类型使用文件路径直接设置
if (Libutils::image::imageSupportGreeterDirect(m_currentPath)) {
setWallpaper(m_currentPath);
} else {
// 保存文件存在时延 bug 106135
setWallpaper(m_view->image());
}
break;
Expand Down