summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2005-08-16 08:48:50 (UTC)
committer llornkcor <llornkcor>2005-08-16 08:48:50 (UTC)
commite49f60f79b86a6feb3cae4bc33c19123deec4eb3 (patch) (unidiff)
tree0dbfa09072fcdd70f19a06ac93ad8f3f97b2978c
parent373b2f0bdc2be62c6e275c74488a8921d03fc299 (diff)
downloadopie-e49f60f79b86a6feb3cae4bc33c19123deec4eb3.zip
opie-e49f60f79b86a6feb3cae4bc33c19123deec4eb3.tar.gz
opie-e49f60f79b86a6feb3cae4bc33c19123deec4eb3.tar.bz2
remove last popen. add umount.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opie-smb/qsmb.cpp198
-rw-r--r--noncore/net/opie-smb/qsmb.h22
-rw-r--r--noncore/net/opie-smb/qsmbbase.ui59
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
@@ -7,6 +7,7 @@
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 11
11#include <qpe/process.h> 12#include <qpe/process.h>
12#include <qlabel.h> 13#include <qlabel.h>
@@ -26,12 +27,13 @@
26 27
27#include <netinet/in.h> 28#include <netinet/in.h>
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>
34using namespace Opie::Core; 36// using namespace Opie::Core;
35 37
36 38
37Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl ) 39Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl )
@@ -39,13 +41,17 @@ Qsmb::Qsmb( QWidget* parent, const char* name, WFlags fl )
39{ 41{
40 connect(CBHost, SIGNAL(activated(int)), this, SLOT(hostSelected(int))); 42 connect(CBHost, SIGNAL(activated(int)), this, SLOT(hostSelected(int)));
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()));
43 connect(BtnClear, SIGNAL(clicked()), this, SLOT(clear())); 46 connect(BtnClear, SIGNAL(clicked()), this, SLOT(clear()));
44 47
48 mountpt->setEditable(true);
45 mountpt->insertItem("/mnt/samba1",-1); 49 mountpt->insertItem("/mnt/samba1",-1);
46 mountpt->insertItem("/mnt/samba2",-1); 50 mountpt->insertItem("/mnt/samba2",-1);
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;
50 scanning = false; 56 scanning = false;
51} 57}
@@ -71,7 +77,7 @@ void Qsmb::scanClicked()
71void Qsmb::DoItClicked() 77void Qsmb::DoItClicked()
72{ 78{
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>"));
76 return; 82 return;
77 } 83 }
@@ -95,8 +101,6 @@ void* runitm(void* arg)
95 101
96void Qsmb::scan() 102void Qsmb::scan()
97{ 103{
98// int i;
99
100 if (scanning) return; 104 if (scanning) return;
101 scanning = true; 105 scanning = true;
102 106
@@ -109,7 +113,7 @@ void Qsmb::scan()
109 get_myaddress( &my_addr); 113 get_myaddress( &my_addr);
110 114
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
114 match = ip.left(5); 118 match = ip.left(5);
115 119
@@ -147,13 +151,13 @@ void Qsmb::scan()
147 scanning = false; 151 scanning = false;
148} 152}
149 153
150void Qsmb::hostSelected(int index) 154void 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
158 if (scanning) return; 162 if (scanning) return;
159 scanning = true; 163 scanning = true;
@@ -186,7 +190,9 @@ void Qsmb::hostSelected(int index)
186 QStringList token = QStringList::split(' ', tmp ); 190 QStringList token = QStringList::split(' ', tmp );
187 share = token[0]; 191 share = token[0];
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);
191// top_element = element; 197// top_element = element;
192// parent = element; 198// parent = element;
@@ -250,125 +256,153 @@ void Qsmb::hostSelected(int index)
250 scanning = false; 256 scanning = false;
251} 257}
252 258
259
253void Qsmb::DoIt() 260void Qsmb::DoIt()
254{ 261{
262
255 QListViewItem *element; 263 QListViewItem *element;
256 element = ListViewScan->selectedItem(); 264 element = ListViewScan->selectedItem();
257 if(!element) { 265 if(!element) {
258 QMessageBox::warning(this, tr("Error!!"),tr("<p><b>No</b> share selected!!</p>"));
259 return; 266 return;
260 } 267 }
261 268
262 if (scanning) return; 269 if (scanning) return;
263 scanning = true; 270 scanning = true;
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
277 LScan->setText("Mounting..."); 287 LScan->setText("Mounting...");
278 qApp->processEvents(); 288 qApp->processEvents();
279 289
280 290 if( !QFileInfo(text).exists()) {
281 if(! QFileInfo(text).exists()) {
282 QStringList ccmd;
283 ccmd << "mkdir"; 291 ccmd << "mkdir";
284 ccmd << "-p"; 292 ccmd << "-p";
285 ccmd << text; 293 ccmd << text;
286 294
287 owarn<<"cmd: "<< ccmd << oendl; 295 qWarning( "cmd: "+ ccmd.join(" "));
288 runCommand(ccmd); 296 runCommand(ccmd);
289 } 297 }
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); 344void 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}
358 373
359bool Qsmb::runCommand(const QStringList & command) { 374bool 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 = "";
362 Process ipkg_status( command); 378 Process ipkg_status( command);
363 bool r = ipkg_status.exec("",out); 379 bool r = ipkg_status.exec("",out);
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;
372} 390}
373 391
374 392
393bool 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
@@ -12,26 +12,28 @@
12 12
13class Qsmb : public FormQPESMBBase 13class 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 30
30public slots: 31public slots:
31 void clear(); 32 void clear();
32 void scanClicked(); 33 void scanClicked();
33 void hostSelected(int); 34 void hostSelected(int);
34 void DoItClicked(); 35 void DoItClicked();
36 void umountIt();
35 QString out; 37 QString out;
36 bool runCommand(const QStringList &); 38 bool runCommand(const QStringList &);
37 39
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
@@ -11,8 +11,8 @@
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
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>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
@@ -68,7 +68,7 @@
68 </property> 68 </property>
69 <property stdset="1"> 69 <property stdset="1">
70 <name>spacing</name> 70 <name>spacing</name>
71 <number>0</number> 71 <number>2</number>
72 </property> 72 </property>
73 <widget row="1" column="0" rowspan="1" colspan="4" > 73 <widget row="1" column="0" rowspan="1" colspan="4" >
74 <class>QComboBox</class> 74 <class>QComboBox</class>
@@ -136,6 +136,20 @@
136 <bool>true</bool> 136 <bool>true</bool>
137 </property> 137 </property>
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">
140 <name>name</name> 154 <name>name</name>
141 <cstring>ListViewScan</cstring> 155 <cstring>ListViewScan</cstring>
@@ -178,18 +192,7 @@
178 <string>Reconnect on boot</string> 192 <string>Reconnect on boot</string>
179 </property> 193 </property>
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>&amp;Mount</string>
190 </property>
191 </widget>
192 <widget row="5" column="2" rowspan="1" colspan="2" >
193 <class>QLayoutWidget</class> 196 <class>QLayoutWidget</class>
194 <property stdset="1"> 197 <property stdset="1">
195 <name>name</name> 198 <name>name</name>
@@ -276,6 +279,28 @@
276 </widget> 279 </widget>
277 </grid> 280 </grid>
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>&amp;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>&amp;Mount</string>
302 </property>
303 </widget>
279 </grid> 304 </grid>
280 </widget> 305 </widget>
281 <widget> 306 <widget>
@@ -291,11 +316,11 @@
291 <grid> 316 <grid>
292 <property stdset="1"> 317 <property stdset="1">
293 <name>margin</name> 318 <name>margin</name>
294 <number>11</number> 319 <number>2</number>
295 </property> 320 </property>
296 <property stdset="1"> 321 <property stdset="1">
297 <name>spacing</name> 322 <name>spacing</name>
298 <number>6</number> 323 <number>2</number>
299 </property> 324 </property>
300 <widget row="0" column="0" > 325 <widget row="0" column="0" >
301 <class>QTextView</class> 326 <class>QTextView</class>