bool MtpObjectsModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { qDebug() << "data: " << data << action << row << column; if (action != Qt::CopyAction || !data) return false; QStringList files = extractMimeData(data); qDebug() << "files dropped: " << files; emit onFilesDropped(files); return true; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), _ui(new Ui::MainWindow), _clipboard(QApplication::clipboard()), _proxyModel(new QSortFilterProxyModel), _storageModel(), _objectModel(new MtpObjectsModel()), _uploader(new FileUploader(_objectModel, this)) { _ui->setupUi(this); setWindowIcon(QIcon(":/android-file-transfer.png")); _ui->listView->setModel(_proxyModel); _proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); _proxyModel->sort(0); _proxyModel->setDynamicSortFilter(true); _objectModel->moveToThread(QApplication::instance()->thread()); connect(_ui->listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), SLOT(updateActionsState())); connect(_ui->listView, SIGNAL(doubleClicked(QModelIndex)), SLOT(onActivated(QModelIndex))); connect(_ui->listView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showContextMenu(QPoint))); connect(_ui->actionBack, SIGNAL(triggered()), SLOT(back())); connect(_ui->actionGo_Down, SIGNAL(triggered()), SLOT(down())); connect(_ui->actionCreateDirectory, SIGNAL(triggered()), SLOT(createDirectory())); connect(_ui->actionUploadDirectory, SIGNAL(triggered()), SLOT(uploadDirectories())); connect(_ui->actionUpload_Album, SIGNAL(triggered()), SLOT(uploadAlbum())); connect(_ui->actionUpload, SIGNAL(triggered()), SLOT(uploadFiles())); connect(_ui->actionRename, SIGNAL(triggered()), SLOT(renameFile())); connect(_ui->actionDownload, SIGNAL(triggered()), SLOT(downloadFiles())); connect(_ui->actionDelete, SIGNAL(triggered()), SLOT(deleteFiles())); connect(_ui->storageList, SIGNAL(activated(int)), SLOT(onStorageChanged(int))); connect(_ui->actionRefresh, SIGNAL(triggered()), SLOT(refresh())); connect(_ui->actionPaste, SIGNAL(triggered()), SLOT(pasteFromClipboard())); connect(_objectModel, SIGNAL(onFilesDropped(QStringList)), SLOT(uploadFiles(QStringList))); connect(_objectModel, SIGNAL(existingFileOverwrite(QString)), SLOT(confirmOverwrite(QString)), Qt::BlockingQueuedConnection); connect(_clipboard, SIGNAL(dataChanged()), SLOT(validateClipboard())); validateClipboard(); //fixme: find out how to specify alternative in designer _ui->actionBack->setShortcuts(_ui->actionBack->shortcuts() << QKeySequence("Alt+Up") << QKeySequence("Esc")); _ui->actionGo_Down->setShortcuts(_ui->actionGo_Down->shortcuts() << QKeySequence("Alt+Down") << QKeySequence("Enter")); _ui->actionCreateDirectory->setShortcuts(_ui->actionCreateDirectory->shortcuts() << QKeySequence("F7")); _ui->actionRefresh->setShortcuts(_ui->actionRefresh->shortcuts() << QKeySequence("Ctrl+R")); _ui->listView->setFocus(); }