author | llornkcor <llornkcor> | 2005-08-16 09:55:52 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-08-16 09:55:52 (UTC) |
commit | dd4792fe0ac89205e7d7a7e38f3d4350e19f25d7 (patch) (unidiff) | |
tree | 4a9bcee8e558a66ab9ecd0c1c6337581821c9d95 | |
parent | 8c44cc4fdb67ea6b96cf7e49ec648de4049a9f1c (diff) | |
download | opie-dd4792fe0ac89205e7d7a7e38f3d4350e19f25d7.zip opie-dd4792fe0ac89205e7d7a7e38f3d4350e19f25d7.tar.gz opie-dd4792fe0ac89205e7d7a7e38f3d4350e19f25d7.tar.bz2 |
fix a few things
-rw-r--r-- | noncore/net/opie-smb/qsmb.cpp | 19 | ||||
-rw-r--r-- | noncore/net/opie-smb/qsmb.h | 4 |
2 files changed, 21 insertions, 2 deletions
diff --git a/noncore/net/opie-smb/qsmb.cpp b/noncore/net/opie-smb/qsmb.cpp index 7f3ae89..d35e09a 100644 --- a/noncore/net/opie-smb/qsmb.cpp +++ b/noncore/net/opie-smb/qsmb.cpp | |||
@@ -1,94 +1,95 @@ | |||
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 <qstringlist.h> | 7 | #include <qstringlist.h> |
8 | #include <qdir.h> | 8 | #include <qdir.h> |
9 | #include <qfileinfo.h> | 9 | #include <qfileinfo.h> |
10 | #include <qtabwidget.h> | 10 | #include <qtabwidget.h> |
11 | 11 | ||
12 | #include <qpe/process.h> | 12 | #include <qpe/process.h> |
13 | #include <qlabel.h> | 13 | #include <qlabel.h> |
14 | #include <qlineedit.h> | 14 | #include <qlineedit.h> |
15 | #include <qcombobox.h> | 15 | #include <qcombobox.h> |
16 | #include <qstringlist.h> | 16 | #include <qstringlist.h> |
17 | #include <qcheckbox.h> | 17 | #include <qcheckbox.h> |
18 | #include <qtextview.h> | 18 | #include <qtextview.h> |
19 | #include <qmessagebox.h> | 19 | #include <qmessagebox.h> |
20 | #include <qtextstream.h> | 20 | #include <qtextstream.h> |
21 | 21 | ||
22 | 22 | ||
23 | #include <pthread.h> | 23 | #include <pthread.h> |
24 | #include <signal.h> | 24 | #include <signal.h> |
25 | #include <ctype.h> | 25 | #include <ctype.h> |
26 | 26 | ||
27 | 27 | ||
28 | #include <netinet/in.h> | 28 | #include <netinet/in.h> |
29 | #include <arpa/inet.h> | 29 | #include <arpa/inet.h> |
30 | #include <rpc/clnt.h> | 30 | #include <rpc/clnt.h> |
31 | 31 | ||
32 | #include <sys/vfs.h> | 32 | #include <sys/vfs.h> |
33 | #include <mntent.h> | 33 | #include <mntent.h> |
34 | 34 | ||
35 | // #include <opie2/odebug.h> | 35 | // #include <opie2/odebug.h> |
36 | // using namespace Opie::Core; | 36 | // using namespace Opie::Core; |
37 | 37 | ||
38 | 38 | ||
39 | Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl ) | 39 | Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl ) |
40 | : FormQPESMBBase( parent, name, fl ) | 40 | : FormQPESMBBase( parent, name, fl ) |
41 | { | 41 | { |
42 | connect(CBHost, SIGNAL(activated(int)), this, SLOT(hostSelected(int))); | 42 | connect(CBHost, SIGNAL(activated(int)), this, SLOT(hostSelected(int))); |
43 | connect(DoItBtn, SIGNAL(clicked()), this, SLOT(DoItClicked())); | 43 | connect(DoItBtn, SIGNAL(clicked()), this, SLOT(DoItClicked())); |
44 | connect(UnmountBtn, SIGNAL(clicked()), this, SLOT(umountIt())); | 44 | connect(UnmountBtn, SIGNAL(clicked()), this, SLOT(umountIt())); |
45 | connect(BtnScan, SIGNAL(clicked()), this, SLOT(scanClicked())); | 45 | connect(BtnScan, SIGNAL(clicked()), this, SLOT(scanClicked())); |
46 | connect(BtnClear, SIGNAL(clicked()), this, SLOT(clear())); | 46 | connect(BtnClear, SIGNAL(clicked()), this, SLOT(clear())); |
47 | connect(ListViewScan, SIGNAL(clicked(QListViewItem*)), this, SLOT(TextViewClicked(QListViewItem*))); | ||
47 | 48 | ||
48 | mountpt->setEditable(true); | 49 | mountpt->setEditable(true); |
49 | mountpt->insertItem("/mnt/samba1",-1); | 50 | mountpt->insertItem("/mnt/samba1",-1); |
50 | mountpt->insertItem("/mnt/samba2",-1); | 51 | mountpt->insertItem("/mnt/samba2",-1); |
51 | mountpt->insertItem("/mnt/samba3",-1); | 52 | mountpt->insertItem("/mnt/samba3",-1); |
52 | 53 | ||
53 | setTabOrder(BtnScan, username); | 54 | setTabOrder(BtnScan, username); |
54 | setTabOrder(username, password); | 55 | setTabOrder(username, password); |
55 | setTabOrder(password, CBHost); | 56 | setTabOrder(password, CBHost); |
56 | setTabOrder(CBHost, TextViewOutput); | 57 | setTabOrder(CBHost, TextViewOutput); |
57 | setTabOrder(TextViewOutput, mountpt); | 58 | setTabOrder(TextViewOutput, mountpt); |
58 | setTabOrder(mountpt, DoItBtn); | 59 | setTabOrder(mountpt, DoItBtn); |
59 | setTabOrder(DoItBtn, UnmountBtn); | 60 | setTabOrder(DoItBtn, UnmountBtn); |
60 | 61 | ||
61 | top_element = NULL; | 62 | top_element = NULL; |
62 | scanning = false; | 63 | scanning = false; |
63 | } | 64 | } |
64 | 65 | ||
65 | Qsmb::~Qsmb() | 66 | Qsmb::~Qsmb() |
66 | { | 67 | { |
67 | } | 68 | } |
68 | 69 | ||
69 | void Qsmb::clear() | 70 | void Qsmb::clear() |
70 | { | 71 | { |
71 | if (scanning) return; | 72 | if (scanning) return; |
72 | ListViewScan->clear(); | 73 | ListViewScan->clear(); |
73 | TextViewOutput->setText(""); | 74 | TextViewOutput->setText(""); |
74 | CBHost->clear(); | 75 | CBHost->clear(); |
75 | top_element = NULL; | 76 | top_element = NULL; |
76 | } | 77 | } |
77 | 78 | ||
78 | void Qsmb::scanClicked() | 79 | void Qsmb::scanClicked() |
79 | { | 80 | { |
80 | if (scanning) return; | 81 | if (scanning) return; |
81 | pthread_create(&tpid, NULL, runit, (void *)this); | 82 | pthread_create(&tpid, NULL, runit, (void *)this); |
82 | } | 83 | } |
83 | 84 | ||
84 | void Qsmb::DoItClicked() | 85 | void Qsmb::DoItClicked() |
85 | { | 86 | { |
86 | 87 | ||
87 | if( !ListViewScan->selectedItem()) { | 88 | if( !ListViewScan->selectedItem()) { |
88 | QMessageBox::warning(this, tr("Error"),tr("<p>No share selected!</p>")); | 89 | QMessageBox::warning(this, tr("Error"),tr("<p>No share selected!</p>")); |
89 | return; | 90 | return; |
90 | } | 91 | } |
91 | if (scanning) return; | 92 | if (scanning) return; |
92 | pthread_create(&tpid, NULL, runitm, (void *)this); | 93 | pthread_create(&tpid, NULL, runitm, (void *)this); |
93 | } | 94 | } |
94 | 95 | ||
@@ -308,130 +309,144 @@ void Qsmb::DoIt() | |||
308 | runCommand(ccmd); | 309 | runCommand(ccmd); |
309 | } | 310 | } |
310 | 311 | ||
311 | share = element->text(0); | 312 | share = element->text(0); |
312 | qWarning("selected share is "+share); | 313 | qWarning("selected share is "+share); |
313 | 314 | ||
314 | QString service = CBHost->currentText(); | 315 | QString service = CBHost->currentText(); |
315 | service = service.stripWhiteSpace(); | 316 | service = service.stripWhiteSpace(); |
316 | if(mount.left(1) != "/") | 317 | if(mount.left(1) != "/") |
317 | mount = QDir::currentDirPath()+"/"+mount; | 318 | mount = QDir::currentDirPath()+"/"+mount; |
318 | mount = mount.stripWhiteSpace(); | 319 | mount = mount.stripWhiteSpace(); |
319 | ccmd.clear(); | 320 | ccmd.clear(); |
320 | 321 | ||
321 | ccmd << "/usr/bin/smbmount"; | 322 | ccmd << "/usr/bin/smbmount"; |
322 | ccmd << "//"+ service+"/"+share; | 323 | ccmd << "//"+ service+"/"+share; |
323 | ccmd << mount; | 324 | ccmd << mount; |
324 | ccmd << "-o"; | 325 | ccmd << "-o"; |
325 | ccmd << "username="+username->text()+",password="+password->text()+""; | 326 | ccmd << "username="+username->text()+",password="+password->text()+""; |
326 | 327 | ||
327 | if(onbootBtn->isChecked()) { | 328 | if(onbootBtn->isChecked()) { |
328 | qWarning("Saving Setting permanently..."); | 329 | qWarning("Saving Setting permanently..."); |
329 | QFile sambenv("/opt/QtPalmtop/etc/samba.env"); | 330 | QFile sambenv("/opt/QtPalmtop/etc/samba.env"); |
330 | QTextStream smbv(&sambenv); | 331 | QTextStream smbv(&sambenv); |
331 | sambenv.open(IO_WriteOnly); | 332 | sambenv.open(IO_WriteOnly); |
332 | smbv << ccmd.join(" ") ; | 333 | smbv << ccmd.join(" ") ; |
333 | sambenv.close(); | 334 | sambenv.close(); |
334 | } | 335 | } |
335 | 336 | ||
336 | noerr = runCommand(ccmd); | 337 | noerr = runCommand(ccmd); |
337 | 338 | ||
338 | LScan->setText(""); | 339 | LScan->setText(""); |
339 | 340 | ||
340 | if(noerr && isMounted(mount)) { | 341 | if(noerr && isMounted(mount)) { |
341 | element->setText(2, mount); | 342 | element->setText(2, mount); |
342 | TextViewOutput->append("\n\n================CheckMounts==================\n"); | 343 | TextViewOutput->append("\n\n================CheckMounts==================\n"); |
343 | ccmd = "/bin/mount"; | 344 | ccmd = "/bin/mount"; |
344 | runCommand(ccmd); | 345 | runCommand(ccmd); |
345 | TextViewOutput->append("\n\n============================================\n"); | 346 | TextViewOutput->append("\n\n============================================\n"); |
346 | qApp->processEvents(); | 347 | qApp->processEvents(); |
347 | } else { | 348 | } else { |
348 | //do nothing | 349 | //do nothing |
349 | } | 350 | } |
350 | 351 | ||
351 | scanning = false; | 352 | scanning = false; |
352 | } | 353 | } |
353 | 354 | ||
354 | void Qsmb::umountIt() | 355 | void Qsmb::umountIt() |
355 | { | 356 | { |
357 | QListViewItem *element; | ||
358 | element = ListViewScan->selectedItem(); | ||
359 | if(!element) { | ||
360 | return; | ||
361 | } | ||
362 | |||
356 | QString mount = mountpt->currentText(); | 363 | QString mount = mountpt->currentText(); |
357 | if(!isMounted(mount)) { | 364 | if(!isMounted(mount)) { |
358 | qWarning(mount +" is not mounted"); | 365 | qWarning(mount +" is not mounted"); |
359 | TextViewOutput->append(mount +" is not mounted"); | 366 | TextViewOutput->append(mount +" is not mounted"); |
360 | return; | 367 | return; |
361 | } | 368 | } |
362 | 369 | ||
363 | QStringList ccmd; | 370 | QStringList ccmd; |
364 | QString share; | 371 | QString share; |
365 | QListViewItem *element; | ||
366 | element = ListViewScan->selectedItem(); | ||
367 | share = element->text(0); | 372 | share = element->text(0); |
368 | qWarning("selected share is "+share); | 373 | qWarning("selected share is "+share); |
369 | 374 | ||
370 | if(mount.left(1) != "/") | 375 | if(mount.left(1) != "/") |
371 | mount = QDir::currentDirPath()+"/"+mount; | 376 | mount = QDir::currentDirPath()+"/"+mount; |
372 | mount = mount.stripWhiteSpace(); | 377 | mount = mount.stripWhiteSpace(); |
373 | 378 | ||
374 | ccmd << "/usr/bin/smbumount"; | 379 | ccmd << "/usr/bin/smbumount"; |
375 | ccmd << mount; | 380 | ccmd << mount; |
376 | runCommand(ccmd); | 381 | runCommand(ccmd); |
377 | 382 | ||
378 | element->setText(2, ""); | 383 | element->setText(2, ""); |
379 | 384 | ||
380 | ccmd = "/bin/mount"; | 385 | ccmd = "/bin/mount"; |
381 | runCommand(ccmd); | 386 | runCommand(ccmd); |
382 | } | 387 | } |
383 | 388 | ||
384 | bool Qsmb::runCommand(const QStringList & command) { | 389 | bool Qsmb::runCommand(const QStringList & command) { |
385 | qWarning( "runCommand " + command.join(" ") ); | 390 | qWarning( "runCommand " + command.join(" ") ); |
386 | TextViewOutput->append(command.join(" ")); | 391 | TextViewOutput->append(command.join(" ")); |
387 | out = ""; | 392 | out = ""; |
388 | Process ipkg_status( command); | 393 | Process ipkg_status( command); |
389 | bool r = ipkg_status.exec("",out); | 394 | bool r = ipkg_status.exec("",out); |
390 | 395 | ||
391 | qWarning("result is %d"+ r ); | 396 | qWarning("result is %d"+ r ); |
392 | qWarning("Output " + out ); | 397 | qWarning("Output " + out ); |
393 | TextViewOutput->append(out); | 398 | TextViewOutput->append(out); |
394 | 399 | ||
395 | //very hacky | 400 | //very hacky |
396 | if(out.find("failed") !=-1) { | 401 | if(out.find("failed") !=-1) { |
397 | r = false; | 402 | r = false; |
398 | } | 403 | } |
399 | return r; | 404 | return r; |
400 | } | 405 | } |
401 | 406 | ||
402 | 407 | ||
403 | bool Qsmb::isMounted(const QString &mountPoint) | 408 | bool Qsmb::isMounted(const QString &mountPoint) |
404 | { | 409 | { |
405 | struct mntent *me; | 410 | struct mntent *me; |
406 | bool mounted = false; | 411 | bool mounted = false; |
407 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); | 412 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); |
408 | if ( mntfp ){ | 413 | if ( mntfp ){ |
409 | while ( (me = getmntent( mntfp )) != 0 ) { | 414 | while ( (me = getmntent( mntfp )) != 0 ) { |
410 | QString deviceName = me->mnt_fsname; | 415 | QString deviceName = me->mnt_fsname; |
411 | QString mountDir = me->mnt_dir; | 416 | QString mountDir = me->mnt_dir; |
412 | QString fsType = me->mnt_type; | 417 | QString fsType = me->mnt_type; |
413 | if( fsType == "smbfs" && (mountDir.find(mountPoint) != -1 | deviceName.find(mountPoint) != -1)) | 418 | if( fsType == "smbfs" && (mountDir.find(mountPoint) != -1 | deviceName.find(mountPoint) != -1)) |
414 | mounted = true; | 419 | mounted = true; |
415 | } | 420 | } |
416 | } | 421 | } |
417 | endmntent( mntfp ); | 422 | endmntent( mntfp ); |
418 | return mounted; | 423 | return mounted; |
419 | } | 424 | } |
420 | 425 | ||
421 | QString Qsmb::getMount(const QString &shareName) | 426 | QString Qsmb::getMount(const QString &shareName) |
422 | { | 427 | { |
423 | struct mntent *me; | 428 | struct mntent *me; |
424 | QString mount; | 429 | QString mount; |
425 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); | 430 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); |
426 | if ( mntfp ){ | 431 | if ( mntfp ){ |
427 | while ( (me = getmntent( mntfp )) != 0 ) { | 432 | while ( (me = getmntent( mntfp )) != 0 ) { |
428 | QString deviceName = me->mnt_fsname; | 433 | QString deviceName = me->mnt_fsname; |
429 | QString mountDir = me->mnt_dir; | 434 | QString mountDir = me->mnt_dir; |
430 | QString fsType = me->mnt_type; | 435 | QString fsType = me->mnt_type; |
431 | if( fsType == "smbfs" && deviceName.find(shareName) != -1) | 436 | if( fsType == "smbfs" && deviceName.find(shareName) != -1) |
432 | mount = mountDir; | 437 | mount = mountDir; |
433 | } | 438 | } |
434 | } | 439 | } |
435 | endmntent( mntfp ); | 440 | endmntent( mntfp ); |
436 | return mount; | 441 | return mount; |
437 | } | 442 | } |
443 | |||
444 | void Qsmb::TextViewClicked(QListViewItem* item) | ||
445 | { | ||
446 | if(item == NULL) return; | ||
447 | |||
448 | QString text = item->text(2); | ||
449 | qWarning(text); | ||
450 | if( !text.isEmpty()) | ||
451 | mountpt->insertItem(text,0); | ||
452 | } | ||
diff --git a/noncore/net/opie-smb/qsmb.h b/noncore/net/opie-smb/qsmb.h index abf27da..175b2c3 100644 --- a/noncore/net/opie-smb/qsmb.h +++ b/noncore/net/opie-smb/qsmb.h | |||
@@ -1,45 +1,49 @@ | |||
1 | #ifndef QSMB_H | 1 | #ifndef QSMB_H |
2 | #define QSMB_H | 2 | #define QSMB_H |
3 | 3 | ||
4 | #include "qsmbbase.h" | 4 | #include "qsmbbase.h" |
5 | 5 | ||
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | 9 | ||
10 | #include <qlistview.h> | 10 | #include <qlistview.h> |
11 | #include <pthread.h> | 11 | #include <pthread.h> |
12 | 12 | ||
13 | #include <qlistview.h> | ||
14 | |||
13 | class Qsmb : public FormQPESMBBase | 15 | class Qsmb : public FormQPESMBBase |
14 | { | 16 | { |
15 | Q_OBJECT | 17 | Q_OBJECT |
16 | 18 | ||
17 | public: | 19 | public: |
18 | static QString appName() { return QString::fromLatin1("opie-smb"); } | 20 | static QString appName() { return QString::fromLatin1("opie-smb"); } |
19 | Qsmb( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 21 | Qsmb( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
20 | ~Qsmb(); | 22 | ~Qsmb(); |
21 | void scan(); | 23 | void scan(); |
22 | void DoIt(); | 24 | void DoIt(); |
23 | 25 | ||
24 | private: | 26 | private: |
25 | QListViewItem *top_element; | 27 | QListViewItem *top_element; |
26 | QComboBox *hosts; | 28 | QComboBox *hosts; |
27 | pthread_t tpid; | 29 | pthread_t tpid; |
28 | bool scanning; | 30 | bool scanning; |
29 | bool isMounted(const QString &); | 31 | bool isMounted(const QString &); |
30 | QString getMount(const QString &); | 32 | QString getMount(const QString &); |
31 | 33 | ||
32 | public slots: | 34 | public slots: |
33 | void clear(); | 35 | void clear(); |
34 | void scanClicked(); | 36 | void scanClicked(); |
35 | void hostSelected(int); | 37 | void hostSelected(int); |
36 | void DoItClicked(); | 38 | void DoItClicked(); |
37 | void umountIt(); | 39 | void umountIt(); |
38 | QString out; | 40 | QString out; |
39 | bool runCommand(const QStringList &); | 41 | bool runCommand(const QStringList &); |
40 | 42 | ||
43 | private slots: | ||
44 | void TextViewClicked(QListViewItem*); | ||
41 | }; | 45 | }; |
42 | void* runit(void *arg); | 46 | void* runit(void *arg); |
43 | void* runitm(void *arg); | 47 | void* runitm(void *arg); |
44 | 48 | ||
45 | #endif // QSMB_H | 49 | #endif // QSMB_H |