author | llornkcor <llornkcor> | 2005-08-16 08:48:50 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-08-16 08:48:50 (UTC) |
commit | e49f60f79b86a6feb3cae4bc33c19123deec4eb3 (patch) (unidiff) | |
tree | 0dbfa09072fcdd70f19a06ac93ad8f3f97b2978c /noncore/net | |
parent | 373b2f0bdc2be62c6e275c74488a8921d03fc299 (diff) | |
download | opie-e49f60f79b86a6feb3cae4bc33c19123deec4eb3.zip opie-e49f60f79b86a6feb3cae4bc33c19123deec4eb3.tar.gz opie-e49f60f79b86a6feb3cae4bc33c19123deec4eb3.tar.bz2 |
remove last popen. add umount.
-rw-r--r-- | noncore/net/opie-smb/qsmb.cpp | 198 | ||||
-rw-r--r-- | noncore/net/opie-smb/qsmb.h | 22 | ||||
-rw-r--r-- | noncore/net/opie-smb/qsmbbase.ui | 59 |
3 files changed, 170 insertions, 109 deletions
diff --git a/noncore/net/opie-smb/qsmb.cpp b/noncore/net/opie-smb/qsmb.cpp index 422b9f3..b978b46 100644 --- a/noncore/net/opie-smb/qsmb.cpp +++ b/noncore/net/opie-smb/qsmb.cpp | |||
@@ -9,2 +9,3 @@ | |||
9 | #include <qfileinfo.h> | 9 | #include <qfileinfo.h> |
10 | #include <qtabwidget.h> | ||
10 | 11 | ||
@@ -28,8 +29,9 @@ | |||
28 | #include <arpa/inet.h> | 29 | #include <arpa/inet.h> |
29 | |||
30 | #include <rpc/clnt.h> | 30 | #include <rpc/clnt.h> |
31 | 31 | ||
32 | #include <sys/vfs.h> | ||
33 | #include <mntent.h> | ||
32 | 34 | ||
33 | #include <opie2/odebug.h> | 35 | // #include <opie2/odebug.h> |
34 | using namespace Opie::Core; | 36 | // using namespace Opie::Core; |
35 | 37 | ||
@@ -41,2 +43,3 @@ Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl ) | |||
41 | connect(DoItBtn, SIGNAL(clicked()), this, SLOT(DoItClicked())); | 43 | connect(DoItBtn, SIGNAL(clicked()), this, SLOT(DoItClicked())); |
44 | connect(UnmountBtn, SIGNAL(clicked()), this, SLOT(umountIt())); | ||
42 | connect(BtnScan, SIGNAL(clicked()), this, SLOT(scanClicked())); | 45 | connect(BtnScan, SIGNAL(clicked()), this, SLOT(scanClicked())); |
@@ -44,2 +47,3 @@ Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl ) | |||
44 | 47 | ||
48 | mountpt->setEditable(true); | ||
45 | mountpt->insertItem("/mnt/samba1",-1); | 49 | mountpt->insertItem("/mnt/samba1",-1); |
@@ -47,3 +51,5 @@ Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl ) | |||
47 | mountpt->insertItem("/mnt/samba3",-1); | 51 | mountpt->insertItem("/mnt/samba3",-1); |
48 | 52 | ||
53 | // TextViewOutput | ||
54 | |||
49 | top_element = NULL; | 55 | top_element = NULL; |
@@ -73,3 +79,3 @@ void Qsmb::DoItClicked() | |||
73 | 79 | ||
74 | if(! ListViewScan->selectedItem()) { | 80 | if( !ListViewScan->selectedItem()) { |
75 | QMessageBox::warning(this, tr("Error"),tr("<p>No share selected!</p>")); | 81 | QMessageBox::warning(this, tr("Error"),tr("<p>No share selected!</p>")); |
@@ -97,4 +103,2 @@ void Qsmb::scan() | |||
97 | { | 103 | { |
98 | // int i; | ||
99 | |||
100 | if (scanning) return; | 104 | if (scanning) return; |
@@ -111,3 +115,3 @@ void Qsmb::scan() | |||
111 | QString ip = inet_ntoa( my_addr.sin_addr); | 115 | QString ip = inet_ntoa( my_addr.sin_addr); |
112 | owarn << "IP Address : " << ip<< oendl; | 116 | qWarning("IP Address : "+ip); |
113 | 117 | ||
@@ -149,9 +153,9 @@ void Qsmb::scan() | |||
149 | 153 | ||
150 | void Qsmb::hostSelected(int index) | 154 | void Qsmb::hostSelected(int /*index*/ ) |
151 | { | 155 | { |
152 | owarn << "hostSelected" << oendl; | ||
153 | QListViewItem *element; | 156 | QListViewItem *element; |
154 | QListViewItem *parent; | 157 | // QListViewItem *parent; |
155 | 158 | ||
156 | QString text = CBHost->currentText(); | 159 | QString text = CBHost->currentText(); |
160 | ListViewScan->clear(); | ||
157 | 161 | ||
@@ -188,3 +192,5 @@ void Qsmb::hostSelected(int index) | |||
188 | comment = token[2]; | 192 | comment = token[2]; |
189 | element = new QListViewItem(ListViewScan,share, comment); | 193 | share = share.stripWhiteSpace(); |
194 | comment = comment.stripWhiteSpace(); | ||
195 | element = new QListViewItem(ListViewScan, share, comment); | ||
190 | element->setOpen(true); | 196 | element->setOpen(true); |
@@ -252,4 +258,6 @@ void Qsmb::hostSelected(int index) | |||
252 | 258 | ||
259 | |||
253 | void Qsmb::DoIt() | 260 | void Qsmb::DoIt() |
254 | { | 261 | { |
262 | |||
255 | QListViewItem *element; | 263 | QListViewItem *element; |
@@ -257,3 +265,2 @@ void Qsmb::DoIt() | |||
257 | if(!element) { | 265 | if(!element) { |
258 | QMessageBox::warning(this, tr("Error!!"),tr("<p><b>No</b> share selected!!</p>")); | ||
259 | return; | 266 | return; |
@@ -264,13 +271,16 @@ void Qsmb::DoIt() | |||
264 | 271 | ||
265 | int i; | 272 | QString mount = mountpt->currentText(); |
266 | bool err = false; | 273 | if(isMounted(mount)) { |
274 | qWarning(mount +" is already mounted"); | ||
275 | TextViewOutput->append(mount +" is already mounted"); | ||
276 | return; | ||
277 | } | ||
278 | |||
279 | bool noerr = false; | ||
267 | 280 | ||
268 | char share[512]; | 281 | QString share; |
269 | QString cmd; | 282 | QString cmd; |
270 | QString cmd2; | 283 | QString cmd2; |
271 | char result[256]; | ||
272 | // QString result; | ||
273 | QString text = mountpt->currentText(); | 284 | QString text = mountpt->currentText(); |
274 | 285 | QStringList ccmd; | |
275 | FILE *pipe,*pipe2; | ||
276 | 286 | ||
@@ -279,5 +289,3 @@ void Qsmb::DoIt() | |||
279 | 289 | ||
280 | 290 | if( !QFileInfo(text).exists()) { | |
281 | if(! QFileInfo(text).exists()) { | ||
282 | QStringList ccmd; | ||
283 | ccmd << "mkdir"; | 291 | ccmd << "mkdir"; |
@@ -286,3 +294,3 @@ void Qsmb::DoIt() | |||
286 | 294 | ||
287 | owarn<<"cmd: "<< ccmd << oendl; | 295 | qWarning( "cmd: "+ ccmd.join(" ")); |
288 | runCommand(ccmd); | 296 | runCommand(ccmd); |
@@ -290,68 +298,75 @@ void Qsmb::DoIt() | |||
290 | 298 | ||
299 | share = element->text(0); | ||
300 | qWarning("selected share is "+share); | ||
291 | 301 | ||
292 | strcpy(share,(const char *)element->text(0)); | 302 | QString service = CBHost->currentText(); |
293 | 303 | service = service.stripWhiteSpace(); | |
294 | for(i = 0; i < 256; i++) { | 304 | if(mount.left(1) != "/") |
295 | if(isalpha( share[i])) { | 305 | mount = QDir::currentDirPath()+"/"+mount; |
296 | strcpy( share, share + i); | 306 | mount = mount.stripWhiteSpace(); |
297 | break; | 307 | ccmd.clear(); |
298 | } | 308 | |
299 | } | 309 | ccmd << "/usr/bin/smbmount"; |
300 | 310 | ccmd << "//"+ service+"/"+share; | |
301 | cmd = "/usr/bin/smbmount //"+CBHost->currentText()+"/"+share+" "+mountpt->currentText()+" -o username="+username->text()+",password="+password->text(); | 311 | ccmd << mount; |
302 | 312 | ccmd << "-o"; | |
303 | owarn << "cmd: " << cmd << oendl; | 313 | ccmd << "username="+username->text()+",password="+password->text()+""; |
304 | TextViewOutput->append(cmd.latin1()); | ||
305 | 314 | ||
315 | TextViewOutput->append(ccmd.join(" ").latin1()); | ||
306 | 316 | ||
307 | if(onbootBtn->isChecked()) { | 317 | if(onbootBtn->isChecked()) { |
308 | owarn << "Saving Setting permanently..." << oendl; | 318 | qWarning("Saving Setting permanently..."); |
309 | cmd2 = "echo '" + cmd + "'>/opt/QtPalmtop/etc/samba.env"; | 319 | QFile sambenv("/opt/QtPalmtop/etc/samba.env"); |
310 | /* run command & read output */ | 320 | QTextStream smbv(&sambenv); |
311 | if ((pipe = popen(cmd2.latin1(), "r")) == NULL) { | 321 | sambenv.open(IO_WriteOnly); |
312 | snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); | 322 | smbv << ccmd.join(" ") ; |
313 | return; | 323 | sambenv.close(); |
314 | } | ||
315 | /* parse output and display in ListViewScan */ | ||
316 | while(fgets(result, 256, pipe) != NULL) { | ||
317 | } | ||
318 | } | ||
319 | |||
320 | |||
321 | /* run command & read output */ | ||
322 | if ((pipe = popen(cmd.latin1(), "r")) == NULL) { | ||
323 | snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); | ||
324 | TextViewOutput->append(result); | ||
325 | return; | ||
326 | } | ||
327 | |||
328 | /* parse output and display in ListViewScan */ | ||
329 | while(fgets(result, 256, pipe) != NULL) { | ||
330 | /* put result into TextViewOutput */ | ||
331 | TextViewOutput->append(result); | ||
332 | } | 324 | } |
333 | 325 | ||
326 | noerr = runCommand(ccmd); | ||
334 | 327 | ||
335 | TextViewOutput->append("\n\n================CheckMounts==================\n"); | ||
336 | LScan->setText(""); | 328 | LScan->setText(""); |
337 | 329 | ||
338 | cmd = "/bin/mount 2>&1"; | 330 | if(noerr) { |
339 | owarn << "cmd: " << cmd << oendl; | 331 | element->setText(2, mount); |
340 | 332 | TextViewOutput->append("\n\n================CheckMounts==================\n"); | |
341 | if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) { | 333 | ccmd = "/bin/mount"; |
334 | runCommand(ccmd); | ||
335 | TextViewOutput->append("\n\n============================================\n"); | ||
336 | qApp->processEvents(); | ||
337 | } else { | ||
338 | //do nothing | ||
339 | } | ||
342 | 340 | ||
343 | snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); | 341 | scanning = false; |
344 | // result = "Error: Can't run "+ cmd; | 342 | } |
345 | 343 | ||
346 | TextViewOutput->append(result); | 344 | void Qsmb::umountIt() |
345 | { | ||
346 | QString mount = mountpt->currentText(); | ||
347 | if(!isMounted(mount)) { | ||
348 | qWarning(mount +" is not mounted"); | ||
349 | TextViewOutput->append(mount +" is not mounted"); | ||
347 | return; | 350 | return; |
348 | } | 351 | } |
349 | /* parse output and display in ListViewScan */ | ||
350 | while(fgets(result, 256, pipe2) != NULL) { | ||
351 | /* put result into TextViewOutput */ | ||
352 | TextViewOutput->append(result); | ||
353 | } | ||
354 | 352 | ||
355 | TextViewOutput->append("\n\n============================================\n"); | 353 | QStringList ccmd; |
356 | scanning = false; | 354 | QString share; |
355 | QListViewItem *element; | ||
356 | element = ListViewScan->selectedItem(); | ||
357 | share = element->text(0); | ||
358 | qWarning("selected share is "+share); | ||
359 | |||
360 | if(mount.left(1) != "/") | ||
361 | mount = QDir::currentDirPath()+"/"+mount; | ||
362 | mount = mount.stripWhiteSpace(); | ||
363 | |||
364 | ccmd << "/usr/bin/smbumount"; | ||
365 | ccmd << mount; | ||
366 | runCommand(ccmd); | ||
367 | |||
368 | element->setText(2, ""); | ||
369 | |||
370 | ccmd = "/bin/mount"; | ||
371 | runCommand(ccmd); | ||
357 | } | 372 | } |
@@ -359,3 +374,4 @@ void Qsmb::DoIt() | |||
359 | bool Qsmb::runCommand(const QStringList & command) { | 374 | bool Qsmb::runCommand(const QStringList & command) { |
360 | owarn << "runCommand " << command.join(" ") << oendl; | 375 | qWarning( "runCommand " + command.join(" ") ); |
376 | TextViewOutput->append(command.join(" ")); | ||
361 | out = ""; | 377 | out = ""; |
@@ -364,8 +380,10 @@ bool Qsmb::runCommand(const QStringList & command) { | |||
364 | 380 | ||
365 | if(!r) { | 381 | qWarning("result is %d"+ r ); |
366 | QMessageBox::warning(this, tr("Error!!"),tr("<p>"+out+"</p>")); | 382 | qWarning("Output " + out ); |
367 | } | 383 | TextViewOutput->append(out); |
368 | 384 | ||
369 | owarn << "Output " << out << oendl; | 385 | //very hacky |
370 | TextViewOutput->append(out.latin1()); | 386 | if(out.find("failed") !=-1) { |
387 | r = false; | ||
388 | } | ||
371 | return r; | 389 | return r; |
@@ -374 +392,17 @@ bool Qsmb::runCommand(const QStringList & command) { | |||
374 | 392 | ||
393 | bool Qsmb::isMounted(const QString &mountPoint) { | ||
394 | struct mntent *me; | ||
395 | bool mounted = false; | ||
396 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); | ||
397 | if ( mntfp ){ | ||
398 | while ( (me = getmntent( mntfp )) != 0 ) { | ||
399 | QString deviceName = me->mnt_fsname; | ||
400 | QString mountDir = me->mnt_dir; | ||
401 | QString fsType = me->mnt_type; | ||
402 | if( fsType == "smbfs" && mountDir.find(mountPoint) !=-1) | ||
403 | mounted = true; | ||
404 | } | ||
405 | } | ||
406 | endmntent( mntfp ); | ||
407 | return mounted; | ||
408 | } | ||
diff --git a/noncore/net/opie-smb/qsmb.h b/noncore/net/opie-smb/qsmb.h index b406a1e..fba94d0 100644 --- a/noncore/net/opie-smb/qsmb.h +++ b/noncore/net/opie-smb/qsmb.h | |||
@@ -14,16 +14,17 @@ class Qsmb : public FormQPESMBBase | |||
14 | { | 14 | { |
15 | Q_OBJECT | 15 | Q_OBJECT |
16 | 16 | ||
17 | public: | 17 | public: |
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 | ||
24 | private: | 24 | private: |
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 | 30 | ||
@@ -34,2 +35,3 @@ public slots: | |||
34 | void DoItClicked(); | 35 | void DoItClicked(); |
36 | void umountIt(); | ||
35 | QString out; | 37 | QString out; |
diff --git a/noncore/net/opie-smb/qsmbbase.ui b/noncore/net/opie-smb/qsmbbase.ui index 297eb2a..4692282 100644 --- a/noncore/net/opie-smb/qsmbbase.ui +++ b/noncore/net/opie-smb/qsmbbase.ui | |||
@@ -13,4 +13,4 @@ | |||
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>250</width> | 14 | <width>259</width> |
15 | <height>352</height> | 15 | <height>395</height> |
16 | </rect> | 16 | </rect> |
@@ -70,3 +70,3 @@ | |||
70 | <name>spacing</name> | 70 | <name>spacing</name> |
71 | <number>0</number> | 71 | <number>2</number> |
72 | </property> | 72 | </property> |
@@ -138,2 +138,16 @@ | |||
138 | </column> | 138 | </column> |
139 | <column> | ||
140 | <property> | ||
141 | <name>text</name> | ||
142 | <string>Mount</string> | ||
143 | </property> | ||
144 | <property> | ||
145 | <name>clickable</name> | ||
146 | <bool>true</bool> | ||
147 | </property> | ||
148 | <property> | ||
149 | <name>resizeable</name> | ||
150 | <bool>true</bool> | ||
151 | </property> | ||
152 | </column> | ||
139 | <property stdset="1"> | 153 | <property stdset="1"> |
@@ -180,14 +194,3 @@ | |||
180 | </widget> | 194 | </widget> |
181 | <widget row="5" column="0" rowspan="1" colspan="2" > | 195 | <widget row="5" column="2" rowspan="2" colspan="2" > |
182 | <class>QPushButton</class> | ||
183 | <property stdset="1"> | ||
184 | <name>name</name> | ||
185 | <cstring>DoItBtn</cstring> | ||
186 | </property> | ||
187 | <property stdset="1"> | ||
188 | <name>text</name> | ||
189 | <string>&Mount</string> | ||
190 | </property> | ||
191 | </widget> | ||
192 | <widget row="5" column="2" rowspan="1" colspan="2" > | ||
193 | <class>QLayoutWidget</class> | 196 | <class>QLayoutWidget</class> |
@@ -278,2 +281,24 @@ | |||
278 | </widget> | 281 | </widget> |
282 | <widget row="6" column="0" rowspan="1" colspan="2" > | ||
283 | <class>QPushButton</class> | ||
284 | <property stdset="1"> | ||
285 | <name>name</name> | ||
286 | <cstring>UnmountBtn</cstring> | ||
287 | </property> | ||
288 | <property stdset="1"> | ||
289 | <name>text</name> | ||
290 | <string>&Umount</string> | ||
291 | </property> | ||
292 | </widget> | ||
293 | <widget row="5" column="0" rowspan="1" colspan="2" > | ||
294 | <class>QPushButton</class> | ||
295 | <property stdset="1"> | ||
296 | <name>name</name> | ||
297 | <cstring>DoItBtn</cstring> | ||
298 | </property> | ||
299 | <property stdset="1"> | ||
300 | <name>text</name> | ||
301 | <string>&Mount</string> | ||
302 | </property> | ||
303 | </widget> | ||
279 | </grid> | 304 | </grid> |
@@ -293,3 +318,3 @@ | |||
293 | <name>margin</name> | 318 | <name>margin</name> |
294 | <number>11</number> | 319 | <number>2</number> |
295 | </property> | 320 | </property> |
@@ -297,3 +322,3 @@ | |||
297 | <name>spacing</name> | 322 | <name>spacing</name> |
298 | <number>6</number> | 323 | <number>2</number> |
299 | </property> | 324 | </property> |