summaryrefslogtreecommitdiff
path: root/noncore
authorllornkcor <llornkcor>2005-08-15 06:45:15 (UTC)
committer llornkcor <llornkcor>2005-08-15 06:45:15 (UTC)
commitfb0e4444f79ad253998f1a2e5c706e3fcf29ad08 (patch) (unidiff)
treefba795d9d82f0e7002b7711a72ed1bac5d2522a4 /noncore
parent1dc2675c1bf557ba0032781535faf033809bae48 (diff)
downloadopie-fb0e4444f79ad253998f1a2e5c706e3fcf29ad08.zip
opie-fb0e4444f79ad253998f1a2e5c706e3fcf29ad08.tar.gz
opie-fb0e4444f79ad253998f1a2e5c706e3fcf29ad08.tar.bz2
cleanup. fix
Diffstat (limited to 'noncore') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opie-smb/qsmb.cpp61
-rw-r--r--noncore/net/opie-smb/qsmb.h3
2 files changed, 35 insertions, 29 deletions
diff --git a/noncore/net/opie-smb/qsmb.cpp b/noncore/net/opie-smb/qsmb.cpp
index 880573b..8aa4987 100644
--- a/noncore/net/opie-smb/qsmb.cpp
+++ b/noncore/net/opie-smb/qsmb.cpp
@@ -1,21 +1,22 @@
1#include "qsmb.h" 1#include "qsmb.h"
2#include <qpushbutton.h> 2#include <qpushbutton.h>
3#include <qpe/qpeapplication.h> 3#include <qpe/qpeapplication.h>
4 4
5#include <string.h> 5#include <string.h>
6#include <qstring.h> 6#include <qstring.h>
7#include <qdir.h> 7#include <qdir.h>
8#include <qfileinfo.h> 8#include <qfileinfo.h>
9 9
10#include <qpe/process.h>
10#include <qlabel.h> 11#include <qlabel.h>
11#include <qlineedit.h> 12#include <qlineedit.h>
12#include <qcombobox.h> 13#include <qcombobox.h>
13#include <qstringlist.h> 14#include <qstringlist.h>
14#include <qcheckbox.h> 15#include <qcheckbox.h>
15#include <qtextview.h> 16#include <qtextview.h>
16#include <qmessagebox.h> 17#include <qmessagebox.h>
17 18
18 19
19#include <pthread.h> 20#include <pthread.h>
20#include <signal.h> 21#include <signal.h>
21#include <ctype.h> 22#include <ctype.h>
@@ -24,29 +25,24 @@
24#include <opie2/odebug.h> 25#include <opie2/odebug.h>
25using namespace Opie::Core; 26using namespace Opie::Core;
26 27
27 28
28Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl ) 29Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl )
29 : FormQPESMBBase( parent, name, fl ) 30 : FormQPESMBBase( parent, name, fl )
30{ 31{
31 connect(CBHost, SIGNAL(activated(int)), this, SLOT(hostSelected(int))); 32 connect(CBHost, SIGNAL(activated(int)), this, SLOT(hostSelected(int)));
32 connect(DoItBtn, SIGNAL(clicked()), this, SLOT(DoItClicked())); 33 connect(DoItBtn, SIGNAL(clicked()), this, SLOT(DoItClicked()));
33 connect(BtnScan, SIGNAL(clicked()), this, SLOT(scanClicked())); 34 connect(BtnScan, SIGNAL(clicked()), this, SLOT(scanClicked()));
34 connect(BtnClear, SIGNAL(clicked()), this, SLOT(clear())); 35 connect(BtnClear, SIGNAL(clicked()), this, SLOT(clear()));
35 36
36//TODO configurable mount points
37 if(!QFileInfo("/mnt/samba1").exists()) system("mkdir /mnt/samba1");
38 if(!QFileInfo("/mnt/samba2").exists()) system("mkdir /mnt/samba2");
39 if(!QFileInfo("/mnt/samba2").exists()) system("mkdir /mnt/samba3");
40
41 mountpt->insertItem("/mnt/samba1",-1); 37 mountpt->insertItem("/mnt/samba1",-1);
42 mountpt->insertItem("/mnt/samba2",-1); 38 mountpt->insertItem("/mnt/samba2",-1);
43 mountpt->insertItem("/mnt/samba3",-1); 39 mountpt->insertItem("/mnt/samba3",-1);
44 40
45 top_element = NULL; 41 top_element = NULL;
46 scanning = false; 42 scanning = false;
47} 43}
48 44
49Qsmb::~Qsmb() 45Qsmb::~Qsmb()
50{ 46{
51} 47}
52 48
@@ -194,37 +190,37 @@ void Qsmb::hostSelected(int index)
194 QString text = CBHost->currentText(); 190 QString text = CBHost->currentText();
195 191
196 if (scanning) return; 192 if (scanning) return;
197 scanning = true; 193 scanning = true;
198 194
199 QString cmd; 195 QString cmd;
200 char result[256]; 196 char result[256];
201 197
202 FILE *pipe; 198 FILE *pipe;
203 199
204 LScan->setText("Scanning..."); 200 LScan->setText("Scanning...");
205 201
206 if((const char *)username->text() == '\0') 202 if(username->text().isEmpty())
207 cmd = "/usr/bin/smbclient -L //"+CBHost->currentText()+" -N 2>&1 |grep Disk"; 203 cmd = "/usr/bin/smbclient -L //"+CBHost->currentText()+" -N 2>&1 |grep Disk";
208 else 204 else
209 cmd = "/usr/bin/smbclient -L //"+CBHost->currentText()+" -N -U"+username->text()+":"+password->text()+" 2>&1 |grep Disk"; 205 cmd = "/usr/bin/smbclient -L //"+CBHost->currentText()+" -N -U "+username->text()+"\%"+password->text()+" 2>&1 |grep Disk";
210 206
211 for(i = 0; i < 512; i++) { 207// for(i = 0; i < 512; i++) {
212 if(cmd[i]==':') { 208// if(cmd[i]==':') {
213 cmd[i]='%'; 209// cmd[i]='%';
214 break; 210// break;
215 } 211// }
216 if(cmd[i]=='\0') 212// if(cmd[i]=='\0')
217 break; 213// break;
218 } 214// }
219 215
220 owarn << "i="<< index << "cmd:" << cmd << oendl; 216 owarn << "i="<< index << "cmd:" << cmd << oendl;
221 217
222 TextViewOutput->append(cmd); 218 TextViewOutput->append(cmd);
223 219
224 /* run smbclient & read output */ 220 /* run smbclient & read output */
225 if ((pipe = popen(cmd.latin1(), "r")) == NULL) { 221 if ((pipe = popen(cmd.latin1(), "r")) == NULL) {
226 snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 222 snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
227// cmd = "Error: Can't run "+cmd; 223// cmd = "Error: Can't run "+cmd;
228 TextViewOutput->append(result); 224 TextViewOutput->append(result);
229 return; 225 return;
230 } 226 }
@@ -291,62 +287,52 @@ void Qsmb::DoIt()
291 char share[512]; 287 char share[512];
292 QString cmd; 288 QString cmd;
293 QString cmd2; 289 QString cmd2;
294 char result[256]; 290 char result[256];
295// QString result; 291// QString result;
296 QString text = mountpt->currentText(); 292 QString text = mountpt->currentText();
297 293
298 FILE *pipe,*pipe2; 294 FILE *pipe,*pipe2;
299 295
300 LScan->setText("Mounting..."); 296 LScan->setText("Mounting...");
301 qApp->processEvents(); 297 qApp->processEvents();
302 298
303 cmd = "mkdir -p "+ text;
304 299
300 if(! QFileInfo(text).exists()) {
301 cmd = "mkdir -p "+ text;
305 owarn<<"cmd: "<< cmd << oendl; 302 owarn<<"cmd: "<< cmd << oendl;
306
307 /* make sure mount exists! */ 303 /* make sure mount exists! */
308 if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) { 304 if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) {
309
310 snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 305 snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
311 // result = "Error: Can't run " + cmd; 306 // result = "Error: Can't run " + cmd;
312 TextViewOutput->append(result); 307 TextViewOutput->append(result);
313 return; 308 return;
314 } 309 }
315
316 while(fgets(result, 256, pipe2) != NULL) { 310 while(fgets(result, 256, pipe2) != NULL) {
317 /* put result into TextViewOutput */ 311 /* put result into TextViewOutput */
318 TextViewOutput->append(result); 312 TextViewOutput->append(result);
319 } 313 }
314 }
320 315
321 316
322 strcpy(share,(const char *)element->text(0)); 317 strcpy(share,(const char *)element->text(0));
323 318
324 for(i = 0; i < 256; i++) { 319 for(i = 0; i < 256; i++) {
325 if(isalpha( share[i])) { 320 if(isalpha( share[i])) {
326 strcpy( share, share + i); 321 strcpy( share, share + i);
327 break; 322 break;
328 } 323 }
329 } 324 }
330 325
331 cmd = "/usr/bin/smbmount //"+CBHost->currentText()+"/"+share+" "+mountpt->currentText()+" -U"+username->text()+":"+password->text(); 326 cmd = "/usr/bin/smbmount //"+CBHost->currentText()+"/"+share+" "+mountpt->currentText()+" -o username="+username->text()+",password="+password->text();
332
333 for(i = 0; i < 512; i++) {
334 if(cmd[i]==':') {
335 cmd[i]='%';
336 break;
337 }
338 if(cmd[i]=='\0')
339 break;
340 }
341 327
342 owarn << "cmd: " << cmd << oendl; 328 owarn << "cmd: " << cmd << oendl;
343 TextViewOutput->append(cmd.latin1()); 329 TextViewOutput->append(cmd.latin1());
344 330
345 331
346 if(onbootBtn->isChecked()) { 332 if(onbootBtn->isChecked()) {
347 owarn << "Saving Setting permanently..." << oendl; 333 owarn << "Saving Setting permanently..." << oendl;
348 cmd2 = "echo '" + cmd + "'>/opt/QtPalmtop/etc/samba.env"; 334 cmd2 = "echo '" + cmd + "'>/opt/QtPalmtop/etc/samba.env";
349 335
350 /* run command & read output */ 336 /* run command & read output */
351 if ((pipe = popen(cmd2.latin1(), "r")) == NULL) { 337 if ((pipe = popen(cmd2.latin1(), "r")) == NULL) {
352 338
@@ -391,12 +377,29 @@ void Qsmb::DoIt()
391 TextViewOutput->append(result); 377 TextViewOutput->append(result);
392 return; 378 return;
393 } 379 }
394 /* parse output and display in ListViewScan */ 380 /* parse output and display in ListViewScan */
395 while(fgets(result, 256, pipe2) != NULL) { 381 while(fgets(result, 256, pipe2) != NULL) {
396 /* put result into TextViewOutput */ 382 /* put result into TextViewOutput */
397 TextViewOutput->append(result); 383 TextViewOutput->append(result);
398 } 384 }
399 385
400 TextViewOutput->append("\n\n============================================\n"); 386 TextViewOutput->append("\n\n============================================\n");
401 scanning = false; 387 scanning = false;
402} 388}
389
390bool Qsmb::runCommand(const QStringList & command) {
391 owarn << "runCommand " << command.join(" ") << oendl;
392 out = "";
393 Process ipkg_status( command);
394 bool r = ipkg_status.exec("",out);
395
396 if(!r) {
397 QMessageBox::warning(this, tr("Error!!"),tr("<p>"+out+"</p>"));
398 }
399
400 owarn << "Output " << out << oendl;
401 TextViewOutput->append(out.latin1());
402 return r;
403}
404
405
diff --git a/noncore/net/opie-smb/qsmb.h b/noncore/net/opie-smb/qsmb.h
index 8fefe91..b406a1e 100644
--- a/noncore/net/opie-smb/qsmb.h
+++ b/noncore/net/opie-smb/qsmb.h
@@ -23,17 +23,20 @@ public:
23 23
24private: 24private:
25 QListViewItem *top_element; 25 QListViewItem *top_element;
26 QComboBox *hosts; 26 QComboBox *hosts;
27 pthread_t tpid; 27 pthread_t tpid;
28 bool scanning; 28 bool scanning;
29 29
30public slots: 30public slots:
31 void clear(); 31 void clear();
32 void scanClicked(); 32 void scanClicked();
33 void hostSelected(int); 33 void hostSelected(int);
34 void DoItClicked(); 34 void DoItClicked();
35 QString out;
36 bool runCommand(const QStringList &);
37
35}; 38};
36void* runit(void *arg); 39void* runit(void *arg);
37void* runitm(void *arg); 40void* runitm(void *arg);
38 41
39#endif // QSMB_H 42#endif // QSMB_H