summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opie-smb/qsmb.cpp33
-rw-r--r--noncore/net/opie-smb/qsmb.h1
2 files changed, 28 insertions, 6 deletions
diff --git a/noncore/net/opie-smb/qsmb.cpp b/noncore/net/opie-smb/qsmb.cpp
index e2ddc7f..7f3ae89 100644
--- a/noncore/net/opie-smb/qsmb.cpp
+++ b/noncore/net/opie-smb/qsmb.cpp
@@ -179,41 +179,45 @@ void Qsmb::hostSelected(int /*index*/ )
179 ccmd << "-L"; 179 ccmd << "-L";
180 ccmd << CBHost->currentText(); 180 ccmd << CBHost->currentText();
181 ccmd << "-N"; 181 ccmd << "-N";
182 182
183 if(username->text().isEmpty()) { 183 if(username->text().isEmpty()) {
184 //do nothing 184 //do nothing
185 } else { 185 } else {
186 ccmd << "-U"; 186 ccmd << "-U";
187 ccmd << username->text()+"\%"+ password->text(); 187 ccmd << username->text()+"\%"+ password->text();
188 } 188 }
189 runCommand(ccmd); 189 runCommand(ccmd);
190 QTextStream s(&out, IO_ReadOnly); 190 QTextStream s(&out, IO_ReadOnly);
191 191
192 while ( !s.atEnd() ) { 192 while ( !s.atEnd() ) {
193 QString share; 193 QString share;
194 QString comment; 194 QString comment;
195 QString mount;
195 QString tmp = s.readLine(); 196 QString tmp = s.readLine();
196 197
197 if( tmp.find("$") == -1 && tmp.find("Disk") != -1) { 198 if( tmp.find("$") == -1 && tmp.find("Disk") != -1) {
198 QStringList token = QStringList::split(' ', tmp ); 199 QStringList token = QStringList::split(' ', tmp );
199 share = token[0]; 200 share = token[0];
200 comment = token[2]; 201 comment = token[2];
201 share = share.stripWhiteSpace(); 202 share = share.stripWhiteSpace();
202 comment = comment.stripWhiteSpace(); 203 comment = comment.stripWhiteSpace();
203 element = new QListViewItem(ListViewScan, share, comment); 204// if(isMounted(share))
205
206 mount = getMount(share);
207 element = new QListViewItem(ListViewScan, share, comment, mount);
204 element->setOpen(true); 208 element->setOpen(true);
205// top_element = element; 209// top_element = element;
206// parent = element; 210// parent = element;
207 } 211 }
208 212
209 } 213 }
210// owarn << "i="<< index << "cmd:" << cmd << oendl; 214// owarn << "i="<< index << "cmd:" << cmd << oendl;
211 215
212 TextViewOutput->append(cmd); 216 TextViewOutput->append(cmd);
213 217
214 /* run smbclient & read output */ 218 /* run smbclient & read output */
215// if ((pipe = popen(cmd.latin1(), "r")) == NULL) { 219// if ((pipe = popen(cmd.latin1(), "r")) == NULL) {
216// snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); 220// snprintf(result, 256, "Error: Can't run %s", cmd.latin1());
217// // cmd = "Error: Can't run "+cmd; 221// // cmd = "Error: Can't run "+cmd;
218// TextViewOutput->append(result); 222// TextViewOutput->append(result);
219// return; 223// return;
@@ -307,48 +311,46 @@ void Qsmb::DoIt()
307 share = element->text(0); 311 share = element->text(0);
308 qWarning("selected share is "+share); 312 qWarning("selected share is "+share);
309 313
310 QString service = CBHost->currentText(); 314 QString service = CBHost->currentText();
311 service = service.stripWhiteSpace(); 315 service = service.stripWhiteSpace();
312 if(mount.left(1) != "/") 316 if(mount.left(1) != "/")
313 mount = QDir::currentDirPath()+"/"+mount; 317 mount = QDir::currentDirPath()+"/"+mount;
314 mount = mount.stripWhiteSpace(); 318 mount = mount.stripWhiteSpace();
315 ccmd.clear(); 319 ccmd.clear();
316 320
317 ccmd << "/usr/bin/smbmount"; 321 ccmd << "/usr/bin/smbmount";
318 ccmd << "//"+ service+"/"+share; 322 ccmd << "//"+ service+"/"+share;
319 ccmd << mount; 323 ccmd << mount;
320 ccmd << "-o"; 324 ccmd << "-o";
321 ccmd << "username="+username->text()+",password="+password->text()+""; 325 ccmd << "username="+username->text()+",password="+password->text()+"";
322 326
323 TextViewOutput->append(ccmd.join(" ").latin1());
324
325 if(onbootBtn->isChecked()) { 327 if(onbootBtn->isChecked()) {
326 qWarning("Saving Setting permanently..."); 328 qWarning("Saving Setting permanently...");
327 QFile sambenv("/opt/QtPalmtop/etc/samba.env"); 329 QFile sambenv("/opt/QtPalmtop/etc/samba.env");
328 QTextStream smbv(&sambenv); 330 QTextStream smbv(&sambenv);
329 sambenv.open(IO_WriteOnly); 331 sambenv.open(IO_WriteOnly);
330 smbv << ccmd.join(" ") ; 332 smbv << ccmd.join(" ") ;
331 sambenv.close(); 333 sambenv.close();
332 } 334 }
333 335
334 noerr = runCommand(ccmd); 336 noerr = runCommand(ccmd);
335 337
336 LScan->setText(""); 338 LScan->setText("");
337 339
338 if(noerr) { 340 if(noerr && isMounted(mount)) {
339 element->setText(2, mount); 341 element->setText(2, mount);
340 TextViewOutput->append("\n\n================CheckMounts==================\n"); 342 TextViewOutput->append("\n\n================CheckMounts==================\n");
341 ccmd = "/bin/mount"; 343 ccmd = "/bin/mount";
342 runCommand(ccmd); 344 runCommand(ccmd);
343 TextViewOutput->append("\n\n============================================\n"); 345 TextViewOutput->append("\n\n============================================\n");
344 qApp->processEvents(); 346 qApp->processEvents();
345 } else { 347 } else {
346 //do nothing 348 //do nothing
347 } 349 }
348 350
349 scanning = false; 351 scanning = false;
350} 352}
351 353
352void Qsmb::umountIt() 354void Qsmb::umountIt()
353{ 355{
354 QString mount = mountpt->currentText(); 356 QString mount = mountpt->currentText();
@@ -385,32 +387,51 @@ bool Qsmb::runCommand(const QStringList & command) {
385 out = ""; 387 out = "";
386 Process ipkg_status( command); 388 Process ipkg_status( command);
387 bool r = ipkg_status.exec("",out); 389 bool r = ipkg_status.exec("",out);
388 390
389 qWarning("result is %d"+ r ); 391 qWarning("result is %d"+ r );
390 qWarning("Output " + out ); 392 qWarning("Output " + out );
391 TextViewOutput->append(out); 393 TextViewOutput->append(out);
392 394
393//very hacky 395//very hacky
394 if(out.find("failed") !=-1) { 396 if(out.find("failed") !=-1) {
395 r = false; 397 r = false;
396 } 398 }
397 return r; 399 return r;
398} 400}
399 401
400 402
401bool Qsmb::isMounted(const QString &mountPoint) { 403bool Qsmb::isMounted(const QString &mountPoint)
404{
402 struct mntent *me; 405 struct mntent *me;
403 bool mounted = false; 406 bool mounted = false;
404 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 407 FILE *mntfp = setmntent( "/etc/mtab", "r" );
405 if ( mntfp ){ 408 if ( mntfp ){
406 while ( (me = getmntent( mntfp )) != 0 ) { 409 while ( (me = getmntent( mntfp )) != 0 ) {
407 QString deviceName = me->mnt_fsname; 410 QString deviceName = me->mnt_fsname;
408 QString mountDir = me->mnt_dir; 411 QString mountDir = me->mnt_dir;
409 QString fsType = me->mnt_type; 412 QString fsType = me->mnt_type;
410 if( fsType == "smbfs" && mountDir.find(mountPoint) !=-1) 413 if( fsType == "smbfs" && (mountDir.find(mountPoint) != -1 | deviceName.find(mountPoint) != -1))
411 mounted = true; 414 mounted = true;
412 } 415 }
413 } 416 }
414 endmntent( mntfp ); 417 endmntent( mntfp );
415 return mounted; 418 return mounted;
416} 419}
420
421QString Qsmb::getMount(const QString &shareName)
422{
423 struct mntent *me;
424 QString mount;
425 FILE *mntfp = setmntent( "/etc/mtab", "r" );
426 if ( mntfp ){
427 while ( (me = getmntent( mntfp )) != 0 ) {
428 QString deviceName = me->mnt_fsname;
429 QString mountDir = me->mnt_dir;
430 QString fsType = me->mnt_type;
431 if( fsType == "smbfs" && deviceName.find(shareName) != -1)
432 mount = mountDir;
433 }
434 }
435 endmntent( mntfp );
436 return mount;
437}
diff --git a/noncore/net/opie-smb/qsmb.h b/noncore/net/opie-smb/qsmb.h
index fba94d0..abf27da 100644
--- a/noncore/net/opie-smb/qsmb.h
+++ b/noncore/net/opie-smb/qsmb.h
@@ -14,31 +14,32 @@ class Qsmb : public FormQPESMBBase
14{ 14{
15 Q_OBJECT 15 Q_OBJECT
16 16
17public: 17public:
18 static QString appName() { return QString::fromLatin1("opie-smb"); } 18 static QString appName() { return QString::fromLatin1("opie-smb"); }
19 Qsmb( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 19 Qsmb( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
20 ~Qsmb(); 20 ~Qsmb();
21 void scan(); 21 void scan();
22 void DoIt(); 22 void DoIt();
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 bool isMounted(const QString &); 29 bool isMounted(const QString &);
30 QString getMount(const QString &);
30 31
31public slots: 32public slots:
32 void clear(); 33 void clear();
33 void scanClicked(); 34 void scanClicked();
34 void hostSelected(int); 35 void hostSelected(int);
35 void DoItClicked(); 36 void DoItClicked();
36 void umountIt(); 37 void umountIt();
37 QString out; 38 QString out;
38 bool runCommand(const QStringList &); 39 bool runCommand(const QStringList &);
39 40
40}; 41};
41void* runit(void *arg); 42void* runit(void *arg);
42void* runitm(void *arg); 43void* runitm(void *arg);
43 44
44#endif // QSMB_H 45#endif // QSMB_H