11from PySide6 .QtWidgets import (QDialog , QVBoxLayout , QHBoxLayout , QLabel ,
22 QLineEdit , QPushButton , QMessageBox , QProgressDialog , QProgressBar )
3- from PySide6 .QtCore import Qt
3+ from PySide6 .QtCore import Qt , QThread , Signal
44from PySide6 .QtGui import QPixmap
55from binaryninja import log_info , log_error , log_warn
66import os
77
8- class ApiKeyWizard (QDialog ):
8+ class ConfigSaveThread (QThread ):
9+ finished = Signal (bool , str )
10+
11+ def __init__ (self , config , api_key , host ):
12+ super ().__init__ ()
13+ self .config = config
14+ self .api_key = api_key
15+ self .host = host
16+
17+ def run (self ):
18+ try :
19+ self .config .api_key = self .api_key
20+ self .config .host = self .host
21+ success = self .config .save_config ()
22+
23+ if not success :
24+ self .finished .emit (False , "API key not valid or host not reachable." )
25+ else :
26+ self .finished .emit (True , "" )
27+
28+ except Exception as e :
29+ self .finished .emit (False , str (e ))
30+
31+ class ConfigDialog (QDialog ):
932 def __init__ (self , config ):
1033 super ().__init__ ()
1134 self .config = config
35+ self .save_thread = None
36+ self .progress = None
1237 self .init_ui ()
1338
1439 def init_ui (self ):
@@ -98,7 +123,7 @@ def save_config(self):
98123 host = self .host_input .text ().strip ()
99124
100125 if not api_key :
101- log_warn ("API Key field is empty" )
126+ log_warn ("RevEng.AI | API Key field is empty" )
102127 QMessageBox .warning (
103128 self ,
104129 "RevEng.AI Configuration" ,
@@ -108,7 +133,7 @@ def save_config(self):
108133 return
109134
110135 if not host :
111- log_warn ("Host URL field is empty" )
136+ log_warn ("RevEng.AI | Host URL field is empty" )
112137 QMessageBox .warning (
113138 self ,
114139 "RevEng.AI Configuration" ,
@@ -117,63 +142,53 @@ def save_config(self):
117142 )
118143 return
119144
120- try :
121- progress = QProgressDialog ("Testing API key..." , None , 0 , 0 , self )
122- progress .setWindowTitle ("RevEng.AI Configuration" )
123- progress .setWindowModality (Qt .WindowModal )
124- progress .setCancelButton (None )
125- progress .setMinimumWidth (400 )
126- progress .setMinimumHeight (100 )
127- progress .findChild (QProgressBar ).setMinimumWidth (250 )
128- progress .findChild (QProgressBar ).setMinimumHeight (20 )
129- progress .setStyleSheet ("""
130- QProgressDialog {
131- background-color: white;
132- color: black;
133- }
134- QProgressBar {
135- border: 1px solid #cccccc;
136- border-radius: 4px;
137- text-align: center;
138- background-color: #f0f0f0;
139- min-width: 250px;
140- min-height: 20px;
141- }
142- QProgressBar::chunk {
143- background-color: #007bff;
144- border-radius: 3px;
145- }
146- QLabel {
147- color: black;
148- font-size: 13px;
149- padding: 10px;
150- }
151- """ )
152- progress .show ()
153-
154- self .config .api_key = api_key
155- self .config .host = host
156- key_try = self .config .save_config ()
157-
158- progress .close ()
159-
160- if not key_try :
161- raise Exception ("API key not valid or host not reachable." )
162-
163- log_info ("RevEng.AI configuration saved successfully!" )
145+ # Create and show progress dialog
146+ self .progress = QProgressDialog ("Testing API key..." , None , 0 , 0 , self )
147+ self .progress .setWindowTitle ("RevEng.AI Configuration" )
148+ self .progress .setWindowModality (Qt .WindowModal )
149+ self .progress .setCancelButton (None )
150+ self .progress .setMinimumWidth (400 )
151+ self .progress .setMinimumHeight (100 )
152+ self .progress .findChild (QProgressBar ).setMinimumWidth (250 )
153+ self .progress .findChild (QProgressBar ).setMinimumHeight (20 )
154+ self .progress .setStyleSheet ("""
155+ QProgressBar {
156+ border: 1px solid #cccccc;
157+ border-radius: 4px;
158+ text-align: center;
159+ background-color: #f0f0f0;
160+ min-width: 250px;
161+ min-height: 20px;
162+ }
163+ QProgressBar::chunk {
164+ background-color: #007bff;
165+ border-radius: 3px;
166+ }
167+ """ )
168+
169+ self .save_thread = ConfigSaveThread (self .config , api_key , host )
170+ self .save_thread .finished .connect (self ._on_save_finished )
171+ self .save_thread .start ()
172+
173+ self .progress .show ()
174+
175+ def _on_save_finished (self , success , error_message ):
176+ self .progress .close ()
177+
178+ if success :
179+ log_info ("RevEng.AI | Configuration saved successfully!" )
164180 QMessageBox .information (
165181 self ,
166182 "RevEng.AI Configuration" ,
167183 "Configuration saved successfully!\n You can now start using RevEng.AI services." ,
168184 QMessageBox .Ok
169185 )
170186 self .accept ()
171-
172- except Exception as e :
173- log_error (f"Failed to save RevEng.AI configuration: { str (e )} " )
187+ else :
188+ log_error (f"RevEng.AI | Failed to save configuration: { error_message } " )
174189 QMessageBox .critical (
175190 self ,
176191 "RevEng.AI Configuration Error" ,
177- f"Failed to save configuration: { str ( e ) } " ,
192+ f"Failed to save configuration: { error_message } " ,
178193 QMessageBox .Ok
179194 )
0 commit comments