@@ -66,9 +66,21 @@ MainWindow::MainWindow(CUploadEngineList* engineList, LogWindow* logWindow, QWid
6666 ui->treeView ->setColumnWidth (1 , 150 ); // Status column
6767 ui->treeView ->setColumnWidth (2 , 150 ); // Progress column
6868 ui->treeView ->setSelectionBehavior (QAbstractItemView::SelectRows);
69+
6970 connect (ui->treeView , &QTreeView::doubleClicked, this , &MainWindow::itemDoubleClicked);
7071 connect (ui->treeView , &QTreeView::customContextMenuRequested, this , &MainWindow::onCustomContextMenu);
7172
73+ copyDirectLinkAction_ = new QAction (tr (" Copy direct link" ), this );
74+ copyDirectLinkAction_->setShortcut (QKeySequence::Copy);
75+ connect (copyDirectLinkAction_, &QAction::triggered, this , &MainWindow::onCopyDirectLinkTriggered);
76+
77+ copyFilePathAction_ = new QAction (tr (" Copy file path to clipboard" ), this );
78+ copyFilePathAction_->setShortcut (QKeySequence (Qt::CTRL + Qt::SHIFT + Qt::Key_C));
79+ connect (copyFilePathAction_, &QAction::triggered, this , &MainWindow::onCopyFilePathTriggered);
80+
81+ ui->treeView ->addAction (copyDirectLinkAction_);
82+ ui->treeView ->addAction (copyFilePathAction_);
83+
7284 const ServerProfile imageProfile = settings->imageServer .getByIndex (0 );
7385
7486 imageServerWidget_ = new ServerSelectorWidget (uploadEngineManager_.get (), false , this );
@@ -98,12 +110,12 @@ MainWindow::MainWindow(CUploadEngineList* engineList, LogWindow* logWindow, QWid
98110
99111 iconsLoadingThread_->start ();
100112
101- QMenu* contextMenu = new QMenu (this );
102- QAction* exitAction = contextMenu ->addAction (tr (" Exit" ));
113+ QMenu* trayContextMenu = new QMenu (this );
114+ QAction* exitAction = trayContextMenu ->addAction (tr (" Exit" ));
103115 connect (exitAction, &QAction::triggered, this , &MainWindow::quitApp);
104116 systemTrayIcon_ = new QSystemTrayIcon (this );
105117 systemTrayIcon_->setIcon (QIcon (" :/res/icon_main.ico" ));
106- systemTrayIcon_->setContextMenu (contextMenu );
118+ systemTrayIcon_->setContextMenu (trayContextMenu );
107119 connect (systemTrayIcon_, &QSystemTrayIcon::activated, [&](QSystemTrayIcon::ActivationReason reason) {
108120 if (reason == QSystemTrayIcon::Trigger || reason == QSystemTrayIcon::DoubleClick){
109121 setWindowState (windowState () & ~Qt::WindowMinimized | Qt::WindowActive);
@@ -299,7 +311,7 @@ void MainWindow::onCustomContextMenu(const QPoint& point) {
299311 if (index.isValid ()) {
300312 UploadTreeModel::InternalItem* internalItem = uploadTreeModel_->getInternalItem (index);
301313 QMenu* contextMenu = new QMenu (ui->treeView );
302- // ui->treeView->setContextMenuPolicy(Qt::ActionsContextMenu);
314+
303315 QAction* viewCodeAction = new QAction (tr (" View HTML/BBCode" ), contextMenu);
304316
305317 contextMenu->addAction (viewCodeAction);
@@ -315,19 +327,13 @@ void MainWindow::onCustomContextMenu(const QPoint& point) {
315327 QString viewUrl = QString::fromStdString (uploadResult->getDownloadUrl ());
316328
317329 if (!directUrl.isEmpty ()) {
318- QAction* copyDirectLinkAction = new QAction (tr (" Copy direct link" ), contextMenu);
319- copyDirectLinkAction->setShortcut (QKeySequence (Qt::CTRL + Qt::Key_C));
320- connect (copyDirectLinkAction, &QAction::triggered, [directUrl](bool checked) {
321- QClipboard* clipboard = QApplication::clipboard ();
322- clipboard->setText (directUrl);
323- });
324- contextMenu->addAction (copyDirectLinkAction);
330+ contextMenu->addAction (copyDirectLinkAction_);
325331 }
326332
327333 if (!viewUrl.isEmpty ()) {
328334 QAction* copyViewLinkAction = new QAction (tr (" Copy view link" ), contextMenu);
329335 if (directUrl.isEmpty ()) {
330- copyViewLinkAction->setShortcut (QKeySequence (Qt::CTRL + Qt::Key_C) );
336+ copyViewLinkAction->setShortcut (QKeySequence::Copy );
331337 }
332338 connect (copyViewLinkAction, &QAction::triggered, [viewUrl](bool checked) {
333339 QClipboard* clipboard = QApplication::clipboard ();
@@ -355,14 +361,7 @@ void MainWindow::onCustomContextMenu(const QPoint& point) {
355361 QDesktopServices::openUrl (" file:///" + fileName);
356362 });
357363 contextMenu->addAction (openInProgram);
358-
359- QAction* copyPathAction = new QAction (tr (" Copy file path to clipboard" ), contextMenu);
360- connect (copyPathAction, &QAction::triggered, [fileName](bool checked)
361- {
362- QClipboard* clipboard = QApplication::clipboard ();
363- clipboard->setText (fileName);
364- });
365- contextMenu->addAction (copyPathAction);
364+ contextMenu->addAction (copyFilePathAction_);
366365 }
367366
368367 }
@@ -381,6 +380,39 @@ void MainWindow::fillServerIcons() {
381380 fileServerWidget_->fillServerIcons ();
382381}
383382
383+ void MainWindow::onCopyDirectLinkTriggered (bool checked) {
384+ QModelIndex index = getUploadTreeViewSelectedIndex ();
385+
386+ if (!index.isValid ()) {
387+ return ;
388+ }
389+
390+ QString url = ui->treeView ->model ()->data (index, Qt::UserRole).toString ();
391+ QClipboard* clipboard = QApplication::clipboard ();
392+ clipboard->setText (url);
393+ }
394+
395+ void MainWindow::onCopyFilePathTriggered (bool checked) {
396+ QModelIndex index = getUploadTreeViewSelectedIndex ();
397+
398+ if (!index.isValid ()) {
399+ return ;
400+ }
401+
402+ UploadTreeModel::InternalItem* internalItem = uploadTreeModel_->getInternalItem (index);
403+
404+ if (!internalItem || !internalItem->task ) {
405+ return ;
406+
407+ }
408+ auto fileTask = std::dynamic_pointer_cast<FileUploadTask>(internalItem->task );
409+
410+ if (fileTask) {
411+ QString fileName = U2Q (fileTask->getFileName ());
412+ QApplication::clipboard ()->setText (fileName);
413+ }
414+ }
415+
384416void MainWindow::on_actionAboutProgram_triggered () {
385417 AboutDialog dlg (this );
386418 dlg.setModal (true );
@@ -415,3 +447,15 @@ void MainWindow::closeEvent(QCloseEvent *event) {
415447 saveOptions ();
416448}
417449
450+ QModelIndex MainWindow::getUploadTreeViewSelectedIndex () {
451+ QItemSelectionModel * selection = ui->treeView ->selectionModel ();
452+ QModelIndexList indexes = selection->selectedIndexes ();
453+
454+ if (indexes.size () < 1 ) {
455+ return {};
456+ }
457+ std::sort (indexes.begin (), indexes.end ());
458+ QModelIndex index = indexes.first ();
459+ return index;
460+ }
461+
0 commit comments