comparison src/gui/widgets/drop_list_widget.cc @ 317:b1f4d1867ab1

services: VERY initial Kitsu support it only supports user authentication for now, but it's definitely a start.
author Paper <paper@paper.us.eu.org>
date Wed, 12 Jun 2024 04:07:10 -0400
parents
children
comparison
equal deleted inserted replaced
316:180714442770 317:b1f4d1867ab1
1 #include "gui/widgets/drop_list_widget.h"
2
3 #include <QDragMoveEvent>
4 #include <QDropEvent>
5 #include <QMimeData>
6 #include <QFileInfo>
7
8 /* currently this only sends local paths that are folders */
9
10 DroppableListWidget::DroppableListWidget(QWidget* parent) : QListWidget(parent) {
11 setAcceptDrops(true);
12 }
13
14 void DroppableListWidget::dragMoveEvent(QDragMoveEvent* event) {
15 if (event->mimeData()->hasUrls())
16 event->acceptProposedAction();
17 }
18
19 void DroppableListWidget::dragEnterEvent(QDragEnterEvent* event) {
20 if (event->mimeData()->hasUrls())
21 event->acceptProposedAction();
22 }
23
24 void DroppableListWidget::dropEvent(QDropEvent* event) {
25 const QMimeData* mime_data = event->mimeData();
26
27 if (!mime_data->hasUrls())
28 return;
29
30 QStringList path_list;
31 QList<QUrl> url_list = mime_data->urls();
32
33 for (const auto& url : url_list) {
34 if (!url.isLocalFile())
35 continue;
36
37 const QString file = url.toLocalFile();
38 const QFileInfo fileinfo(file);
39 if (fileinfo.exists() && fileinfo.isDir())
40 path_list.append(file);
41 }
42
43 if (!path_list.isEmpty())
44 emit FilesDropped(path_list);
45
46 event->acceptProposedAction();
47 }