先看代码
void MainWindow::sendNotify(int saveIndex, QString saveFilePath, const bool succeed)
{
// failed notify
if (!succeed)
{
const auto tips = tr("Save failed. Please save it in your home directory.");
m_notifyDBInterface->Notify("Deepin Screenshot", 0, "deepin-screenshot", QString(), tips, QStringList(), QVariantMap(), 0);
exit(0);
}
QDBusInterface remote_dde_notify_obj("com.deepin.dde.Notification", "/com/deepin/dde/Notification",
"com.deepin.dde.Notification");
const bool remote_dde_notify_obj_exist = remote_dde_notify_obj.isValid();
QStringList actions;
QVariantMap hints;
if (remote_dde_notify_obj_exist) {
actions << "_open" << tr("View");
QString fileDir = QUrl::fromLocalFile(QFileInfo(saveFilePath).absoluteDir().absolutePath()).toString();
QString filePath = QUrl::fromLocalFile(saveFilePath).toString();
QString command;
if (QFile("/usr/bin/dde-file-manager").exists()) {
command = QString("/usr/bin/dde-file-manager,%1?selectUrl=%2").arg(fileDir).arg(filePath);
qDebug() << command;
}
else {
command = QString("xdg-open,%1").arg(filePath);
}
hints["x-deepin-action-_open"] = command;
}
qDebug() << "saveFilePath:" << saveFilePath;
QString summary;
if (saveIndex == 3) {
summary = QString(tr("Picture has been saved to clipboard"));
} else {
summary = QString(tr("Picture has been saved to %1")).arg(saveFilePath);
}
if (saveIndex == 3 && !m_noNotify) {
QVariantMap emptyMap;
m_notifyDBInterface->Notify("Deepin Screenshot", 0, "deepin-screenshot", "",
summary, QStringList(), emptyMap, 0);
} else if ( !m_noNotify && !(m_saveIndex == 2 && m_saveFileName.isEmpty())) {
m_notifyDBInterface->Notify("Deepin Screenshot", 0, "deepin-screenshot", "",
summary, actions, hints, 0);
}
QTimer::singleShot(2, [=]{
exitApp();
});
}
核心关注点
/usr/bin/dde-file-manager,file:///home/alda/Desktop?selectUrl=file:///home/pikachu/Desktop/深度截图_选择区域_20190324224011.png
这个回调的时候,会打开深度文件管理器,然后选中那个图片,很神奇
DBus为
发送的参数为
hints就是那个回调的参数,可以打开文管的