@@ -56,29 +56,46 @@ def __init__(self):
5656 self .pb_add .clicked .connect (self .button_add )
5757 self .pb_clear .clicked .connect (self .button_clear )
5858 self .pb_download .clicked .connect (self .button_download )
59- self .tw .itemClicked .connect (self .remove_item )
59+
60+ self .tw .setContextMenuPolicy (QtCore .Qt .CustomContextMenu )
61+ self .tw .customContextMenuRequested .connect (self .open_menu )
62+
63+ def open_menu (self , position ):
64+ menu = QtWidgets .QMenu ()
65+
66+ delete_action = menu .addAction (qta .icon ("mdi6.trash-can" ), "Delete" )
67+ copy_url_action = menu .addAction (qta .icon ("mdi6.content-copy" ), "Copy URL" )
68+ open_folder_action = menu .addAction (qta .icon ("mdi6.folder-open" ), "Open Folder" )
69+
70+ item = self .tw .itemAt (position )
71+
72+ if item :
73+ item_path = item .data (0 , ItemRoles .PathRole )
74+ item_link = item .data (0 , ItemRoles .LinkRole )
75+ action = menu .exec (self .tw .viewport ().mapToGlobal (position ))
76+
77+ if action == delete_action :
78+ self .remove_item (item , 0 )
79+ elif action == copy_url_action :
80+ QtWidgets .QApplication .clipboard ().setText (item_link )
81+ logger .info (f"Copied URL to clipboard: { item_link } " )
82+ elif action == open_folder_action :
83+ QtGui .QDesktopServices .openUrl (QtCore .QUrl .fromLocalFile (item_path ))
84+ logger .info (f"Opened folder: { item_path } " )
6085
6186 def remove_item (self , item , column ):
6287 item_id = item .data (0 , ItemRoles .IdRole )
6388 item_text = item .text (0 )
6489
65- ret = QtWidgets .QMessageBox .question (
66- self ,
67- "Application Message" ,
68- f"Would you like to remove { item_text } ?" ,
69- QtWidgets .QMessageBox .Yes | QtWidgets .QMessageBox .No ,
70- QtWidgets .QMessageBox .No ,
71- )
72- if ret == QtWidgets .QMessageBox .Yes :
73- if self .to_dl .get (item_id ):
74- logger .debug (f"Removing queued download ({ item_id } ): { item_text } " )
75- self .to_dl .pop (item_id )
76- elif worker := self .worker .get (item_id ):
77- logger .info (f"Stopping and removing download ({ item_id } ): { item_text } " )
78- worker .stop ()
79- self .tw .takeTopLevelItem (
80- self .tw .indexOfTopLevelItem (item )
81- ) # remove and return a top-level item
90+ logger .debug (f"Removing download ({ item_id } ): { item_text } " )
91+
92+ if worker := self .worker .get (item_id ):
93+ worker .stop ()
94+
95+ self .to_dl .pop (item_id , None )
96+ self .tw .takeTopLevelItem (
97+ self .tw .indexOfTopLevelItem (item )
98+ ) # remove and return a top-level item
8299
83100 def button_path (self ):
84101 path = QtWidgets .QFileDialog .getExistingDirectory (
@@ -107,11 +124,7 @@ def button_add(self):
107124 return QtWidgets .QMessageBox .information (
108125 self ,
109126 "Application Message" ,
110- (
111- f"Required fields ({ missing_fields } ) are missing."
112- if len (missing ) > 1
113- else f"Required field ({ missing_fields } ) is missing."
114- ),
127+ f"Required field{ 's' if len (missing ) > 1 else '' } ({ missing_fields } ) missing." ,
115128 )
116129
117130 self .te_link .clear ()
@@ -142,7 +155,7 @@ def button_clear(self):
142155 self ,
143156 "Application Message" ,
144157 "Unable to clear list because there are active downloads in progress.\n "
145- "Remove a download by clicking on it." ,
158+ "Remove a download by right clicking on it and selecting delete ." ,
146159 )
147160
148161 self .worker = {}
0 commit comments