feat: implement file and text drop handling for chat and add shrunk sidebar override for window view
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
#include <QHash>
|
||||
|
||||
#include <QList>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QObject>
|
||||
#include <QQmlEngine>
|
||||
#include <QStringList>
|
||||
#include <QTemporaryDir>
|
||||
#include <QUrl>
|
||||
|
||||
namespace ZShell::Services {
|
||||
|
||||
class DropImporter : public QObject {
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
QML_SINGLETON
|
||||
|
||||
public:
|
||||
enum Decision { Ignore, InsertText, Attach };
|
||||
Q_ENUM(Decision)
|
||||
|
||||
explicit DropImporter(QObject* parent = nullptr);
|
||||
|
||||
Q_INVOKABLE Decision decide(
|
||||
const QList<QUrl>& urls,
|
||||
const QString& text,
|
||||
const QString& html,
|
||||
bool hasRawImage) const;
|
||||
|
||||
Q_INVOKABLE int importAttachments(
|
||||
const QList<QUrl>& urls,
|
||||
const QString& html,
|
||||
const QByteArray& rawImage);
|
||||
|
||||
signals:
|
||||
void importFinished(
|
||||
int id, const QStringList& paths, const QStringList& errors);
|
||||
|
||||
private:
|
||||
struct Request {
|
||||
int pending = 0;
|
||||
QStringList files;
|
||||
QStringList errors;
|
||||
};
|
||||
|
||||
void addLocal(int id, const QUrl& url);
|
||||
void download(int id, const QUrl& url);
|
||||
void saveBytes(int id, const QByteArray& bytes);
|
||||
void succeed(int id, const QString& path);
|
||||
void failWith(int id, const QString& message);
|
||||
void finishUnit(int id);
|
||||
QString newSubdir();
|
||||
|
||||
QNetworkAccessManager m_nam;
|
||||
QTemporaryDir m_tempDir;
|
||||
QHash<int, Request> m_requests;
|
||||
int m_nextId = 0;
|
||||
int m_counter = 0;
|
||||
};
|
||||
|
||||
} // namespace ZShell::Services
|
||||
Reference in New Issue
Block a user