void USBLinkTreeWidget::deleteEntry() { if(!context_menu_item) return; usblink_queue_delete(usblink_path_item(context_menu_item).toStdString(), context_menu_item->data(0, Qt::UserRole).toBool(), usblink_delete_callback, context_menu_item); }
void USBLinkTreeWidget::newFolder() { auto *line_edit= qobject_cast<QLineEdit*>(QObject::sender()); // FIXME: Don't use usblink_upload_callback here, it may change behavior. usblink_queue_new_dir((usblink_path_item(context_menu_item) + QStringLiteral("/") + line_edit->text()).toStdString(), usblink_upload_callback, this); }
QString USBLinkTreeWidget::usblink_path_item(QTreeWidgetItem *w) { if(!w) return QString(); return usblink_path_item(w->parent()) + QStringLiteral("/") + w->text(0); // This crashes on 32-bit linux somehow //return QString("%0/%1").arg(path_parent).arg(path_this); }
static QString usblink_path_item(QTreeWidgetItem *w) { if(!w) return ""; return usblink_path_item(w->parent()) + "/" + w->text(0); // This crashes on 32-bit linux somehow //return QString("%0/%1").arg(path_parent).arg(path_this); }
void USBLinkTreeWidget::downloadEntry() { if(!context_menu_item || context_menu_item->data(0, Qt::UserRole).toBool()) // Is a directory return; QString dest = QFileDialog::getSaveFileName(this, tr("Chose save location"), QString(), tr("TNS file (*.tns)")); if(!dest.isEmpty()) usblink_queue_download(usblink_path_item(context_menu_item).toStdString(), dest.toStdString(), usblink_download_callback, this); }
bool USBLinkTreeWidget::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) { if(data->urls().size() != 1) return false; (void) index; (void) action; std::string file = QDir::toNativeSeparators(data->urls()[0].toLocalFile()).toStdString(); usblink_queue_put_file(file, usblink_path_item(parent).toStdString(), usblink_upload_callback, this); return true; }
void USBLinkTreeWidget::dataChangedHandler(QTreeWidgetItem *item, int column) { // Only the name can be changed if(column != 0) return; std::string filepath = usblink_path_item(item->parent()).toStdString(); std::string old_name = item->data(2, Qt::UserRole).toString().toStdString(), new_name = item->data(0, Qt::DisplayRole).toString().toStdString(); usblink_queue_move(filepath + "/" + old_name, filepath + "/" + new_name, usblink_move_progress, item); }
static bool usblink_dirlist_nested(QTreeWidgetItem *w) { if(w->data(0, Qt::UserRole).value<bool>() == false) //Not a directory return false; if(w->data(1, Qt::UserRole).value<bool>() == false) //Not filled yet { QByteArray path_utf8 = usblink_path_item(w).toUtf8(); usblink_queue_dirlist(path_utf8.data(), MainWindow::usblink_dirlist_callback_nested, w); return true; } else { for(int i = 0; i < w->childCount(); ++i) if(usblink_dirlist_nested(w->child(i))) return true; } return false; }
bool USBLinkTreeWidget::usblink_dirlist_nested(QTreeWidgetItem *w) { // Find a directory (w or its children) to fill if(w->data(0, Qt::UserRole).value<bool>() == false) //Not a directory return false; if(w->data(1, Qt::UserRole).value<bool>() == false) //Not filled yet { std::string path_utf8 = usblink_path_item(w).toStdString(); usblink_queue_dirlist(path_utf8, USBLinkTreeWidget::usblink_dirlist_callback_nested, w); return true; } else { for(int i = 0; i < w->childCount(); ++i) if(usblink_dirlist_nested(w->child(i))) return true; } return false; }