-rw-r--r-- | noncore/settings/sshkeys/sshkeys.cpp | 58 | ||||
-rw-r--r-- | noncore/settings/sshkeys/sshkeys.h | 5 |
2 files changed, 54 insertions, 9 deletions
diff --git a/noncore/settings/sshkeys/sshkeys.cpp b/noncore/settings/sshkeys/sshkeys.cpp index c5e1170..43e02af 100644 --- a/noncore/settings/sshkeys/sshkeys.cpp +++ b/noncore/settings/sshkeys/sshkeys.cpp | |||
@@ -46,13 +46,13 @@ SSHKeysApp::SSHKeysApp( QWidget* parent, const char* name, WFlags fl ) | |||
46 | connect(RefreshListButton, SIGNAL(clicked()), this, SLOT(doRefreshListButton())); | 46 | connect(RefreshListButton, SIGNAL(clicked()), this, SLOT(doRefreshListButton())); |
47 | connect(RemoveAllButton, SIGNAL(clicked()), this, SLOT(doRemoveAllButton())); | 47 | connect(RemoveAllButton, SIGNAL(clicked()), this, SLOT(doRemoveAllButton())); |
48 | 48 | ||
49 | connect(&addprocess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 49 | connect(&addprocess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
50 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 50 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); |
51 | connect(&addprocess, SIGNAL(receivedStderr(OProcess*,char*,int)), | 51 | connect(&addprocess, SIGNAL(receivedStderr(OProcess*,char*,int)), |
52 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 52 | this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); |
53 | connect(&addprocess, SIGNAL(processExited(OProcess*)), | 53 | connect(&addprocess, SIGNAL(processExited(OProcess*)), |
54 | this, SLOT(ssh_add_exited(OProcess*))); | 54 | this, SLOT(ssh_add_exited(OProcess*))); |
55 | 55 | ||
56 | connect(KeyFileName, SIGNAL(textChanged(const QString&)), | 56 | connect(KeyFileName, SIGNAL(textChanged(const QString&)), |
57 | this, SLOT(add_text_changed(const QString&))); | 57 | this, SLOT(add_text_changed(const QString&))); |
58 | 58 | ||
@@ -87,13 +87,13 @@ void SSHKeysApp::doRefreshListButton() | |||
87 | t = next; | 87 | t = next; |
88 | } | 88 | } |
89 | 89 | ||
90 | connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)), | 90 | connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)), |
91 | this, SLOT(get_list_keys_output(OProcess*,char*,int))); | 91 | this, SLOT(get_list_keys_output(OProcess*,char*,int))); |
92 | connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), | 92 | connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), |
93 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 93 | this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); |
94 | 94 | ||
95 | keystate = KeySize; | 95 | keystate = KeySize; |
96 | incoming_keyname=""; | 96 | incoming_keyname=""; |
97 | incoming_keysize=""; | 97 | incoming_keysize=""; |
98 | incoming_keyfingerprint=""; | 98 | incoming_keyfingerprint=""; |
99 | 99 | ||
@@ -101,12 +101,13 @@ void SSHKeysApp::doRefreshListButton() | |||
101 | sshadd_process << "ssh-add" << "-l"; | 101 | sshadd_process << "ssh-add" << "-l"; |
102 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); | 102 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); |
103 | if (!ret) { | 103 | if (!ret) { |
104 | log_text(tr("Error running ssh-add")); | 104 | log_text(tr("Error running ssh-add")); |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | flush_sshadd_output(); | ||
107 | if (sshadd_process.exitStatus() == 2) { | 108 | if (sshadd_process.exitStatus() == 2) { |
108 | setEnabled(FALSE); | 109 | setEnabled(FALSE); |
109 | } | 110 | } |
110 | } | 111 | } |
111 | 112 | ||
112 | void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen) | 113 | void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen) |
@@ -174,18 +175,55 @@ void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen) | |||
174 | } | 175 | } |
175 | break; | 176 | break; |
176 | } | 177 | } |
177 | } | 178 | } |
178 | } | 179 | } |
179 | 180 | ||
181 | void SSHKeysApp::flush_sshadd_output(void) | ||
182 | { | ||
183 | if (pending_stdout.length()) { | ||
184 | log_text(pending_stdout.ascii()); | ||
185 | } | ||
186 | pending_stdout = ""; | ||
187 | |||
188 | if (pending_stderr.length()) { | ||
189 | log_text(pending_stderr.ascii()); | ||
190 | } | ||
191 | pending_stderr = ""; | ||
192 | } | ||
193 | |||
180 | void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen) | 194 | void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen) |
181 | { | 195 | { |
182 | (void)proc; | 196 | (void) proc; |
183 | (void)buflen; | ||
184 | 197 | ||
185 | log_text(buffer); | 198 | while (buflen) { |
199 | if (*buffer == '\n') { | ||
200 | log_text(pending_stdout); | ||
201 | pending_stdout = ""; | ||
202 | } else { | ||
203 | pending_stdout += *buffer; | ||
204 | } | ||
205 | buffer++; | ||
206 | buflen--; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | void SSHKeysApp::log_sshadd_stderr(OProcess *proc, char *buffer, int buflen) | ||
211 | { | ||
212 | (void) proc; | ||
213 | |||
214 | while (buflen) { | ||
215 | if (*buffer == '\n') { | ||
216 | log_text(pending_stderr); | ||
217 | pending_stderr = ""; | ||
218 | } else { | ||
219 | pending_stderr += *buffer; | ||
220 | } | ||
221 | buffer++; | ||
222 | buflen--; | ||
223 | } | ||
186 | } | 224 | } |
187 | 225 | ||
188 | void SSHKeysApp::ssh_add_exited(OProcess *proc) | 226 | void SSHKeysApp::ssh_add_exited(OProcess *proc) |
189 | { | 227 | { |
190 | (void)proc; | 228 | (void)proc; |
191 | 229 | ||
@@ -213,23 +251,24 @@ void SSHKeysApp::doAddButton() | |||
213 | addprocess.clearArguments(); | 251 | addprocess.clearArguments(); |
214 | 252 | ||
215 | setEnabled(FALSE); | 253 | setEnabled(FALSE); |
216 | 254 | ||
217 | if (KeyFileName->currentText().length()) { | 255 | if (KeyFileName->currentText().length()) { |
218 | addprocess << "ssh-add" << "--" << KeyFileName->currentText(); | 256 | addprocess << "ssh-add" << "--" << KeyFileName->currentText(); |
219 | log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText()); | 257 | // log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText()); |
220 | } else { | 258 | } else { |
221 | addprocess << "ssh-add"; | 259 | addprocess << "ssh-add"; |
222 | log_text(tr("Running ssh-add")); | 260 | // log_text(tr("Running ssh-add")); |
223 | } | 261 | } |
224 | bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput); | 262 | bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput); |
225 | if (!ret) { | 263 | if (!ret) { |
226 | log_text(tr("Error running ssh-add")); | 264 | log_text(tr("Error running ssh-add")); |
227 | doRefreshListButton(); | 265 | doRefreshListButton(); |
228 | setEnabled(TRUE); | 266 | setEnabled(TRUE); |
229 | } | 267 | } |
268 | flush_sshadd_output(); | ||
230 | } | 269 | } |
231 | 270 | ||
232 | void SSHKeysApp::log_text(const char *text) | 271 | void SSHKeysApp::log_text(const char *text) |
233 | { | 272 | { |
234 | TextOutput->append(text); | 273 | TextOutput->append(text); |
235 | TextOutput->setCursorPosition(TextOutput->numLines()+1, 0, FALSE); | 274 | TextOutput->setCursorPosition(TextOutput->numLines()+1, 0, FALSE); |
@@ -239,16 +278,17 @@ void SSHKeysApp::doRemoveAllButton() | |||
239 | { | 278 | { |
240 | OProcess sshadd_process; | 279 | OProcess sshadd_process; |
241 | 280 | ||
242 | connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)), | 281 | connect(&sshadd_process, SIGNAL(receivedStdout(OProcess*,char*,int)), |
243 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 282 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); |
244 | connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), | 283 | connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), |
245 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 284 | this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); |
246 | 285 | ||
247 | log_text(tr("Running ssh-add -D")); | 286 | //log_text(tr("Running ssh-add -D")); |
248 | sshadd_process << "ssh-add" << "-D"; | 287 | sshadd_process << "ssh-add" << "-D"; |
249 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); | 288 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); |
250 | if (!ret) { | 289 | if (!ret) { |
251 | log_text(tr("Error running ssh-add")); | 290 | log_text(tr("Error running ssh-add")); |
252 | } | 291 | } |
292 | flush_sshadd_output(); | ||
253 | doRefreshListButton(); | 293 | doRefreshListButton(); |
254 | } | 294 | } |
diff --git a/noncore/settings/sshkeys/sshkeys.h b/noncore/settings/sshkeys/sshkeys.h index 5e306d1..bbc6993 100644 --- a/noncore/settings/sshkeys/sshkeys.h +++ b/noncore/settings/sshkeys/sshkeys.h | |||
@@ -32,24 +32,29 @@ class SSHKeysApp : public SSHKeysBase | |||
32 | public: | 32 | public: |
33 | SSHKeysApp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 33 | SSHKeysApp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
34 | ~SSHKeysApp(); | 34 | ~SSHKeysApp(); |
35 | 35 | ||
36 | private: | 36 | private: |
37 | void log_text(const char *text); | 37 | void log_text(const char *text); |
38 | void flush_sshadd_output(void); | ||
39 | |||
38 | enum { Noise, KeyName, KeySize, KeyFingerprint } keystate; | 40 | enum { Noise, KeyName, KeySize, KeyFingerprint } keystate; |
39 | QString incoming_keyname; | 41 | QString incoming_keyname; |
40 | QString incoming_keysize; | 42 | QString incoming_keysize; |
41 | QString incoming_keyfingerprint; | 43 | QString incoming_keyfingerprint; |
42 | QString incoming_noise; | 44 | QString incoming_noise; |
43 | OProcess addprocess; | 45 | OProcess addprocess; |
46 | QString pending_stdout; | ||
47 | QString pending_stderr; | ||
44 | 48 | ||
45 | private slots: | 49 | private slots: |
46 | void doAddButton(); | 50 | void doAddButton(); |
47 | void doRefreshListButton(); | 51 | void doRefreshListButton(); |
48 | void doRemoveAllButton(); | 52 | void doRemoveAllButton(); |
49 | void get_list_keys_output(OProcess *proc, char *buffer, int buflen); | 53 | void get_list_keys_output(OProcess *proc, char *buffer, int buflen); |
50 | void log_sshadd_output(OProcess *proc, char *buffer, int buflen); | 54 | void log_sshadd_output(OProcess *proc, char *buffer, int buflen); |
55 | void log_sshadd_stderr(OProcess *proc, char *buffer, int buflen); | ||
51 | void ssh_add_exited(OProcess *proc); | 56 | void ssh_add_exited(OProcess *proc); |
52 | void add_text_changed(const QString &text); | 57 | void add_text_changed(const QString &text); |
53 | }; | 58 | }; |
54 | #endif | 59 | #endif |
55 | 60 | ||