forked from blue/squawk
highlight in directory now is optional runtime plugin to KIO, several more file managers to fallback, refactor, 2 new icons
This commit is contained in:
parent
d514db9c4a
commit
ebf0c64ffb
23 changed files with 289 additions and 51 deletions
|
@ -23,6 +23,11 @@
|
|||
Shared::Global* Shared::Global::instance = 0;
|
||||
const std::set<QString> Shared::Global::supportedImagesExts = {"png", "jpg", "webp", "jpeg", "gif", "svg"};
|
||||
|
||||
#ifdef WITH_KIO
|
||||
QLibrary Shared::Global::openFileManagerWindowJob("openFileManagerWindowJob");
|
||||
Shared::Global::HighlightInFileManager Shared::Global::hfm = 0;
|
||||
#endif
|
||||
|
||||
Shared::Global::Global():
|
||||
availability({
|
||||
tr("Online", "Availability"),
|
||||
|
@ -80,7 +85,8 @@ Shared::Global::Global():
|
|||
tr("Your password is going to be stored in KDE wallet storage (KWallet). You're going to be queried for permissions", "AccountPasswordDescription")
|
||||
}),
|
||||
pluginSupport({
|
||||
{"KWallet", false}
|
||||
{"KWallet", false},
|
||||
{"openFileManagerWindowJob", false}
|
||||
}),
|
||||
fileCache()
|
||||
{
|
||||
|
@ -89,6 +95,21 @@ Shared::Global::Global():
|
|||
}
|
||||
|
||||
instance = this;
|
||||
|
||||
#ifdef WITH_KIO
|
||||
openFileManagerWindowJob.load();
|
||||
if (openFileManagerWindowJob.isLoaded()) {
|
||||
hfm = (HighlightInFileManager) openFileManagerWindowJob.resolve("highlightInFileManager");
|
||||
if (hfm) {
|
||||
setSupported("openFileManagerWindowJob", true);
|
||||
qDebug() << "KIO::OpenFileManagerWindow support enabled";
|
||||
} else {
|
||||
qDebug() << "KIO::OpenFileManagerWindow support disabled: couldn't resolve required methods in the library";
|
||||
}
|
||||
} else {
|
||||
qDebug() << "KIO::OpenFileManagerWindow support disabled: couldn't load the library" << openFileManagerWindowJob.errorString();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Shared::Global::FileInfo Shared::Global::getFileInfo(const QString& path)
|
||||
|
@ -181,6 +202,69 @@ QString Shared::Global::getDescription(Shared::AccountPassword ap)
|
|||
return instance->accountPasswordDescription[static_cast<int>(ap)];
|
||||
}
|
||||
|
||||
|
||||
static const QStringList query = {"query", "default", "inode/directory"};
|
||||
static const QRegularExpression dolphinReg("[Dd]olphin");
|
||||
static const QRegularExpression nautilusReg("[Nn]autilus");
|
||||
static const QRegularExpression cajaReg("[Cc]aja");
|
||||
static const QRegularExpression nemoReg("[Nn]emo");
|
||||
static const QRegularExpression konquerorReg("kfmclient");
|
||||
static const QRegularExpression pcmanfmQtReg("pcmanfm-qt");
|
||||
static const QRegularExpression pcmanfmReg("pcmanfm");
|
||||
static const QRegularExpression thunarReg("thunar");
|
||||
|
||||
void Shared::Global::highlightInFileManager(const QString& path)
|
||||
{
|
||||
#ifdef WITH_KIO
|
||||
if (supported("openFileManagerWindowJob")) {
|
||||
hfm(path);
|
||||
return;
|
||||
} else {
|
||||
qDebug() << "requested to highlight in file manager url" << path << "but it's not supported: KIO plugin isn't loaded, trying fallback";
|
||||
}
|
||||
#else
|
||||
qDebug() << "requested to highlight in file manager url" << path << "but it's not supported: squawk wasn't compiled to support it, trying fallback";
|
||||
#endif
|
||||
|
||||
QFileInfo info = path;
|
||||
if (info.exists()) {
|
||||
QProcess proc;
|
||||
proc.start("xdg-mime", query);
|
||||
proc.waitForFinished();
|
||||
QString output = proc.readLine().simplified();
|
||||
|
||||
QString folder;
|
||||
if (info.isDir()) {
|
||||
folder = info.canonicalFilePath();
|
||||
} else {
|
||||
folder = info.canonicalPath();
|
||||
}
|
||||
|
||||
if (output.contains(dolphinReg)) {
|
||||
//there is a bug on current (21.04.0) dolphin, it works correct only if you already have dolphin launched
|
||||
proc.startDetached("dolphin", QStringList() << "--select" << info.canonicalFilePath());
|
||||
//KIO::highlightInFileManager({QUrl(info.canonicalFilePath())});
|
||||
} else if (output.contains(nautilusReg)) {
|
||||
proc.startDetached("nautilus", QStringList() << "--select" << info.canonicalFilePath()); //this worked on nautilus
|
||||
} else if (output.contains(cajaReg)) {
|
||||
proc.startDetached("caja", QStringList() << folder); //caja doesn't seem to support file selection command line, gonna just open directory
|
||||
} else if (output.contains(nemoReg)) {
|
||||
proc.startDetached("nemo", QStringList() << info.canonicalFilePath()); //nemo supports selecting files without keys
|
||||
} else if (output.contains(konquerorReg)) {
|
||||
proc.startDetached("konqueror", QStringList() << "--select" << info.canonicalFilePath()); //this worked on konqueror
|
||||
} else if (output.contains(pcmanfmQtReg)) {
|
||||
proc.startDetached("pcmanfm-qt", QStringList() << folder); //pcmanfm-qt doesn't seem to support open with selection, gonna just open directory
|
||||
} else if (output.contains(pcmanfmReg)) {
|
||||
proc.startDetached("pcmanfm", QStringList() << folder); //pcmanfm also doesn't seem to support open with selection, gonna just open directory
|
||||
} else if (output.contains(thunarReg)) {
|
||||
proc.startDetached("thunar", QStringList() << folder); //thunar doesn't seem to support open with selection, gonna just open directory
|
||||
} else {
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(folder));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define FROM_INT_INPL(Enum) \
|
||||
template<> \
|
||||
Enum Shared::Global::fromInt(int src) \
|
||||
|
|
|
@ -34,6 +34,12 @@
|
|||
#include <QFileInfo>
|
||||
#include <QImage>
|
||||
#include <QSize>
|
||||
#include <QUrl>
|
||||
#include <QLibrary>
|
||||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
#include <QDesktopServices>
|
||||
#include <QRegularExpression>
|
||||
|
||||
namespace Shared {
|
||||
|
||||
|
@ -83,6 +89,7 @@ namespace Shared {
|
|||
static const std::set<QString> supportedImagesExts;
|
||||
|
||||
static FileInfo getFileInfo(const QString& path);
|
||||
static void highlightInFileManager(const QString& path);
|
||||
|
||||
template<typename T>
|
||||
static T fromInt(int src);
|
||||
|
@ -108,6 +115,14 @@ namespace Shared {
|
|||
|
||||
std::map<QString, bool> pluginSupport;
|
||||
std::map<QString, FileInfo> fileCache;
|
||||
|
||||
#ifdef WITH_KIO
|
||||
static QLibrary openFileManagerWindowJob;
|
||||
|
||||
typedef void (*HighlightInFileManager)(const QUrl &);
|
||||
|
||||
static HighlightInFileManager hfm;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -170,6 +170,8 @@ static const std::map<QString, std::pair<QString, QString>> icons = {
|
|||
{"favorite", {"favorite", "favorite"}},
|
||||
{"unfavorite", {"draw-star", "unfavorite"}},
|
||||
{"list-add", {"list-add", "add"}},
|
||||
{"folder", {"folder", "folder"}},
|
||||
{"document-preview", {"document-preview", "document-preview"}}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -46,40 +46,3 @@ QString Shared::processMessageBody(const QString& msg)
|
|||
processed.replace(urlReg, "<a href=\"\\1\">\\1</a>");
|
||||
return "<p style=\"white-space: pre-wrap;\">" + processed + "</p>";
|
||||
}
|
||||
|
||||
static const QStringList query = {"query", "default", "inode/directory"};
|
||||
static const QRegularExpression dolphinReg("[Dd]olphin");
|
||||
static const QRegularExpression nautilusReg("[Nn]autilus");
|
||||
static const QRegularExpression cajaReg("[Cc]aja");
|
||||
static const QRegularExpression nemoReg("[Nn]emo");
|
||||
static const QRegularExpression konquerorReg("kfmclient");
|
||||
|
||||
void Shared::showInDirectory(const QString& path)
|
||||
{
|
||||
QFileInfo info = path;
|
||||
if (info.exists()) {
|
||||
QProcess proc;
|
||||
proc.start("xdg-mime", query);
|
||||
proc.waitForFinished();
|
||||
QString output = proc.readLine().simplified();
|
||||
if (output.contains(dolphinReg)) {
|
||||
proc.startDetached("dolphin", QStringList() << "--select" << info.canonicalFilePath());
|
||||
} else if (output.contains(nautilusReg)) {
|
||||
proc.startDetached("nautilus", QStringList() << "--no-desktop" << info.canonicalFilePath());
|
||||
} else if (output.contains(cajaReg)) {
|
||||
proc.startDetached("caja", QStringList() << "--no-desktop" << info.canonicalFilePath());
|
||||
} else if (output.contains(nemoReg)) {
|
||||
proc.startDetached("nemo", QStringList() << "--no-desktop" << info.canonicalFilePath());
|
||||
} else if (output.contains(konquerorReg)) {
|
||||
proc.startDetached("konqueror", QStringList() << "--select" << info.canonicalFilePath());
|
||||
} else {
|
||||
QString folder;
|
||||
if (info.isDir()) {
|
||||
folder = info.canonicalFilePath();
|
||||
} else {
|
||||
folder = info.canonicalPath();
|
||||
}
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(folder));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,19 +23,16 @@
|
|||
#include <QStringList>
|
||||
#include <QColor>
|
||||
#include <QRegularExpression>
|
||||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
|
||||
//#include "KIO/OpenFileManagerWindowJob"
|
||||
|
||||
#include <uuid/uuid.h>
|
||||
#include <vector>
|
||||
#include <vector>
|
||||
|
||||
namespace Shared {
|
||||
|
||||
QString generateUUID();
|
||||
QString processMessageBody(const QString& msg);
|
||||
void showInDirectory(const QString& path);
|
||||
|
||||
static const std::vector<QColor> colorPalette = {
|
||||
QColor(244, 27, 63),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue