Accept file drops inside the Group files window
This commit is contained in:
1 parent
04e8a18c9a
commit
7d6b45ba5d
3 files changed
+116
-5
No files matched your search
@@ -18,9 +18,11 @@
|
||||
#include <QMimeData>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDropEvent>
|
||||
#include <QLineEdit>
|
||||
extern "C" {
|
||||
#include "member_files/member_files.h"
|
||||
#include "mem.h"
|
||||
#include "debug_config.h"
|
||||
}
|
||||
static mf_gui_request captured;
|
||||
static mf_gui_request quotaCaptured;
|
||||
@@ -68,8 +70,66 @@ static QPushButton* cancelButton(MemberFileBrowser& browser) {
|
||||
class BrowserTest : public QObject {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void initTestCase() {
|
||||
debug_config_init(); debug_set_level(DEBUG_LEVEL_WARN);
|
||||
debug_set_category_level(DEBUG_CATEGORY_DEBUG, DEBUG_LEVEL_DEBUG);
|
||||
debug_set_category_level(DEBUG_CATEGORY_MEDIA, DEBUG_LEVEL_INFO);
|
||||
}
|
||||
void init() { transfers.clear(); cancelled.clear(); ready = true; }
|
||||
|
||||
void browserDropsIntoCurrentDirectory() {
|
||||
sqlite3* sql = nullptr; QCOMPARE(sqlite3_open(":memory:", &sql), SQLITE_OK);
|
||||
QCOMPARE(sqlite3_exec(sql, "CREATE TABLE accounts(node_id INTEGER,display_name TEXT);"
|
||||
"INSERT INTO accounts VALUES(11,'Other'),(22,'Me'),(33,'Server');"
|
||||
"CREATE TABLE peers_42(node_id INTEGER,adm_tags TEXT,adm_tags_sig BLOB,deleted INTEGER,source INTEGER);"
|
||||
"INSERT INTO peers_42 VALUES(11,'{}',NULL,0,0),(22,'{}',NULL,0,0),"
|
||||
"(33,'{\"storage\":\"yes\"}',zeroblob(64),0,0);", nullptr, nullptr, nullptr), SQLITE_OK);
|
||||
DbManager db; db.setDb(sql); db.setMyNodeId(22);
|
||||
QTemporaryDir dir; QVERIFY(dir.isValid()); QString path = dir.filePath("dropped.txt");
|
||||
{ QFile file(path); QVERIFY(file.open(QIODevice::WriteOnly)); QCOMPARE(file.write("test"), 4LL); }
|
||||
QMimeData mime; mime.setUrls({QUrl::fromLocalFile(path)});
|
||||
{
|
||||
MemberFileBrowser browser(&db); browser.show();
|
||||
auto* tree = browser.findChild<QTreeWidget*>(); auto* location = browser.findChild<QLineEdit*>(); QVERIFY(location);
|
||||
auto* cancel = cancelButton(browser); QVERIFY(cancel);
|
||||
QList<QWidget*> targets{&browser, tree->viewport(), location};
|
||||
for (auto* button : browser.findChildren<QPushButton*>()) if (button->text().startsWith("Upload")) targets.append(button);
|
||||
for (auto* target : targets) {
|
||||
browser.setChannel("42", 22); location->setText("documents"); location->returnPressed();
|
||||
QDragEnterEvent enter(QPoint(3, 3), Qt::CopyAction | Qt::MoveAction, &mime, Qt::LeftButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(target, &enter);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEDIA, "test browser drop: target=%s acceptDrops=%d accepted=%d",
|
||||
target->metaObject()->className(), target->acceptDrops(), enter.isAccepted());
|
||||
QVERIFY(enter.isAccepted()); QCOMPARE(enter.dropAction(), Qt::CopyAction);
|
||||
QVERIFY(browser.findChild<QLabel*>("memberFilesDropHint")->isVisible());
|
||||
QDropEvent drop(QPointF(3, 3), Qt::CopyAction | Qt::MoveAction, &mime, Qt::LeftButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(target, &drop); QVERIFY(drop.isAccepted()); QCOMPARE(drop.dropAction(), Qt::CopyAction);
|
||||
QVERIFY(!browser.findChild<QLabel*>("memberFilesDropHint")->isVisible());
|
||||
browser.setChannel("43", 11); // Назначение уже зафиксировано до отложенного запуска очереди.
|
||||
QTRY_COMPARE(captured.message.command, uint8_t(MF_STAT));
|
||||
QCOMPARE(captured.group, 42ULL); QCOMPARE(captured.server, 33ULL); QCOMPARE(captured.message.owner, 22ULL);
|
||||
QCOMPARE(QString::fromUtf8(captured.message.path), QString("documents/dropped.txt"));
|
||||
int count = transfers.size(); respond(browser, captured, MF_NOT_FOUND); QCOMPARE(transfers.size(), count + 1);
|
||||
QCOMPARE(QString::fromUtf8(transfers.last().remote), QString("documents/dropped.txt"));
|
||||
complete(browser, transfers.last());
|
||||
}
|
||||
browser.setChannel("42", 11);
|
||||
QDragEnterEvent other(QPoint(3, 3), Qt::CopyAction, &mime, Qt::LeftButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(tree->viewport(), &other); QVERIFY(!other.isAccepted());
|
||||
browser.setChannel("42", 22);
|
||||
QDragEnterEvent enter(QPoint(3, 3), Qt::CopyAction, &mime, Qt::LeftButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(tree->viewport(), &enter); QVERIFY(enter.isAccepted());
|
||||
QDropEvent drop(QPointF(3, 3), Qt::CopyAction, &mime, Qt::LeftButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(tree->viewport(), &drop); QVERIFY(drop.isAccepted());
|
||||
quint64 previous = captured.message.request_id; cancel->click(); QCoreApplication::processEvents();
|
||||
QCOMPARE(captured.message.request_id, previous); QVERIFY(!cancel->isEnabled());
|
||||
ready = false;
|
||||
QDragEnterEvent stopped(QPoint(3, 3), Qt::CopyAction, &mime, Qt::LeftButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(tree->viewport(), &stopped); QVERIFY(!stopped.isAccepted()); ready = true;
|
||||
}
|
||||
db.setDb(nullptr); QCOMPARE(sqlite3_close(sql), SQLITE_OK);
|
||||
}
|
||||
|
||||
void footerDropsCopyAndCaptureGroup() {
|
||||
DbManager db; db.setMyNodeId(22); ChannelList list(&db); list.resize(350, 400); list.show();
|
||||
auto* view = list.findChild<QListView*>(); auto* model = qobject_cast<QStandardItemModel*>(view->model()); QVERIFY(model);
|
||||
|
||||
Reference in new issue
Block a user