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,437 +1,452 @@ | |||
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 | ||
95 | void* runit(void* arg) | 96 | void* runit(void* arg) |
96 | { | 97 | { |
97 | Qsmb* caller = (Qsmb*)arg; | 98 | Qsmb* caller = (Qsmb*)arg; |
98 | caller->scan(); | 99 | caller->scan(); |
99 | return(0); | 100 | return(0); |
100 | } | 101 | } |
101 | 102 | ||
102 | void* runitm(void* arg) | 103 | void* runitm(void* arg) |
103 | { | 104 | { |
104 | Qsmb* caller = (Qsmb*)arg; | 105 | Qsmb* caller = (Qsmb*)arg; |
105 | caller->DoIt(); | 106 | caller->DoIt(); |
106 | return(0); | 107 | return(0); |
107 | } | 108 | } |
108 | 109 | ||
109 | void Qsmb::scan() | 110 | void Qsmb::scan() |
110 | { | 111 | { |
111 | clear(); | 112 | clear(); |
112 | // if (scanning) return; | 113 | // if (scanning) return; |
113 | scanning = true; | 114 | scanning = true; |
114 | 115 | ||
115 | QString match; | 116 | QString match; |
116 | QString cmd; | 117 | QString cmd; |
117 | LScan->setText("Scanning..."); | 118 | LScan->setText("Scanning..."); |
118 | qApp->processEvents(); | 119 | qApp->processEvents(); |
119 | 120 | ||
120 | sockaddr_in my_addr; | 121 | sockaddr_in my_addr; |
121 | get_myaddress( &my_addr); | 122 | get_myaddress( &my_addr); |
122 | 123 | ||
123 | QString ip = inet_ntoa( my_addr.sin_addr); | 124 | QString ip = inet_ntoa( my_addr.sin_addr); |
124 | qWarning("IP Address : "+ip); | 125 | qWarning("IP Address : "+ip); |
125 | 126 | ||
126 | match = ip.left(5); | 127 | match = ip.left(5); |
127 | 128 | ||
128 | QStringList ccmd; | 129 | QStringList ccmd; |
129 | TextViewOutput->append("smbfind"); | 130 | TextViewOutput->append("smbfind"); |
130 | 131 | ||
131 | QFile lmhosts("/etc/samba/lmhosts"); | 132 | QFile lmhosts("/etc/samba/lmhosts"); |
132 | QTextStream lms(&lmhosts); | 133 | QTextStream lms(&lmhosts); |
133 | lmhosts.open(IO_WriteOnly); | 134 | lmhosts.open(IO_WriteOnly); |
134 | lms << "127.0.0.1 localhost\n"; | 135 | lms << "127.0.0.1 localhost\n"; |
135 | 136 | ||
136 | /* parse output and display in ListViewScan */ | 137 | /* parse output and display in ListViewScan */ |
137 | ccmd = "smbfind"; | 138 | ccmd = "smbfind"; |
138 | runCommand(ccmd); | 139 | runCommand(ccmd); |
139 | 140 | ||
140 | QTextStream s(&out, IO_ReadOnly); | 141 | QTextStream s(&out, IO_ReadOnly); |
141 | 142 | ||
142 | while ( !s.atEnd() ) { | 143 | while ( !s.atEnd() ) { |
143 | QString ip_addr, host, output; | 144 | QString ip_addr, host, output; |
144 | QString tmp = s.readLine(); | 145 | QString tmp = s.readLine(); |
145 | bool ok; | 146 | bool ok; |
146 | tmp.left(1).toInt( &ok, 10 ); | 147 | tmp.left(1).toInt( &ok, 10 ); |
147 | if(ok) { | 148 | if(ok) { |
148 | QStringList token = QStringList::split(' ', tmp ); | 149 | QStringList token = QStringList::split(' ', tmp ); |
149 | ip_addr = token[0]; | 150 | ip_addr = token[0]; |
150 | host = token[1]; | 151 | host = token[1]; |
151 | CBHost->insertItem( host, -1); | 152 | CBHost->insertItem( host, -1); |
152 | lms << ip_addr+" "+host+"\n"; | 153 | lms << ip_addr+" "+host+"\n"; |
153 | } | 154 | } |
154 | } | 155 | } |
155 | lmhosts.close(); | 156 | lmhosts.close(); |
156 | 157 | ||
157 | TextViewOutput->append("\n\n============================================\n"); | 158 | TextViewOutput->append("\n\n============================================\n"); |
158 | LScan->setText(""); | 159 | LScan->setText(""); |
159 | scanning = false; | 160 | scanning = false; |
160 | } | 161 | } |
161 | 162 | ||
162 | void Qsmb::hostSelected(int /*index*/ ) | 163 | void Qsmb::hostSelected(int /*index*/ ) |
163 | { | 164 | { |
164 | QListViewItem *element; | 165 | QListViewItem *element; |
165 | // QListViewItem *parent; | 166 | // QListViewItem *parent; |
166 | 167 | ||
167 | QString text = CBHost->currentText(); | 168 | QString text = CBHost->currentText(); |
168 | ListViewScan->clear(); | 169 | ListViewScan->clear(); |
169 | 170 | ||
170 | if (scanning) return; | 171 | if (scanning) return; |
171 | scanning = true; | 172 | scanning = true; |
172 | 173 | ||
173 | QString cmd; | 174 | QString cmd; |
174 | QStringList ccmd; | 175 | QStringList ccmd; |
175 | 176 | ||
176 | LScan->setText("Scanning..."); | 177 | LScan->setText("Scanning..."); |
177 | 178 | ||
178 | ccmd << "/usr/bin/smbclient"; | 179 | ccmd << "/usr/bin/smbclient"; |
179 | ccmd << "-L"; | 180 | ccmd << "-L"; |
180 | ccmd << CBHost->currentText(); | 181 | ccmd << CBHost->currentText(); |
181 | ccmd << "-N"; | 182 | ccmd << "-N"; |
182 | 183 | ||
183 | if(username->text().isEmpty()) { | 184 | if(username->text().isEmpty()) { |
184 | //do nothing | 185 | //do nothing |
185 | } else { | 186 | } else { |
186 | ccmd << "-U"; | 187 | ccmd << "-U"; |
187 | ccmd << username->text()+"\%"+ password->text(); | 188 | ccmd << username->text()+"\%"+ password->text(); |
188 | } | 189 | } |
189 | runCommand(ccmd); | 190 | runCommand(ccmd); |
190 | QTextStream s(&out, IO_ReadOnly); | 191 | QTextStream s(&out, IO_ReadOnly); |
191 | 192 | ||
192 | while ( !s.atEnd() ) { | 193 | while ( !s.atEnd() ) { |
193 | QString share; | 194 | QString share; |
194 | QString comment; | 195 | QString comment; |
195 | QString mount; | 196 | QString mount; |
196 | QString tmp = s.readLine(); | 197 | QString tmp = s.readLine(); |
197 | 198 | ||
198 | if( tmp.find("$") == -1 && tmp.find("Disk") != -1) { | 199 | if( tmp.find("$") == -1 && tmp.find("Disk") != -1) { |
199 | QStringList token = QStringList::split(' ', tmp ); | 200 | QStringList token = QStringList::split(' ', tmp ); |
200 | share = token[0]; | 201 | share = token[0]; |
201 | comment = token[2]; | 202 | comment = token[2]; |
202 | share = share.stripWhiteSpace(); | 203 | share = share.stripWhiteSpace(); |
203 | comment = comment.stripWhiteSpace(); | 204 | comment = comment.stripWhiteSpace(); |
204 | // if(isMounted(share)) | 205 | // if(isMounted(share)) |
205 | 206 | ||
206 | mount = getMount(share); | 207 | mount = getMount(share); |
207 | element = new QListViewItem(ListViewScan, share, comment, mount); | 208 | element = new QListViewItem(ListViewScan, share, comment, mount); |
208 | element->setOpen(true); | 209 | element->setOpen(true); |
209 | // top_element = element; | 210 | // top_element = element; |
210 | // parent = element; | 211 | // parent = element; |
211 | } | 212 | } |
212 | 213 | ||
213 | } | 214 | } |
214 | // owarn << "i="<< index << "cmd:" << cmd << oendl; | 215 | // owarn << "i="<< index << "cmd:" << cmd << oendl; |
215 | 216 | ||
216 | TextViewOutput->append(cmd); | 217 | TextViewOutput->append(cmd); |
217 | 218 | ||
218 | /* run smbclient & read output */ | 219 | /* run smbclient & read output */ |
219 | // if ((pipe = popen(cmd.latin1(), "r")) == NULL) { | 220 | // if ((pipe = popen(cmd.latin1(), "r")) == NULL) { |
220 | // snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); | 221 | // snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); |
221 | // // cmd = "Error: Can't run "+cmd; | 222 | // // cmd = "Error: Can't run "+cmd; |
222 | // TextViewOutput->append(result); | 223 | // TextViewOutput->append(result); |
223 | // return; | 224 | // return; |
224 | // } | 225 | // } |
225 | 226 | ||
226 | /* parse output and display in ListViewScan */ | 227 | /* parse output and display in ListViewScan */ |
227 | // while(fgets(result, 256, pipe) != NULL) { | 228 | // while(fgets(result, 256, pipe) != NULL) { |
228 | // /* put result into TextViewOutput */ | 229 | // /* put result into TextViewOutput */ |
229 | // TextViewOutput->append(result); | 230 | // TextViewOutput->append(result); |
230 | 231 | ||
231 | // if( strchr(result, '$') == NULL ) { | 232 | // if( strchr(result, '$') == NULL ) { |
232 | // char share[256], *ptr1; | 233 | // char share[256], *ptr1; |
233 | 234 | ||
234 | // strcpy(share,result); | 235 | // strcpy(share,result); |
235 | // ptr1 = strchr(share,' '); | 236 | // ptr1 = strchr(share,' '); |
236 | // share[ptr1 - share]='\0'; | 237 | // share[ptr1 - share]='\0'; |
237 | 238 | ||
238 | // owarn<< "add share: " << share << oendl; | 239 | // owarn<< "add share: " << share << oendl; |
239 | 240 | ||
240 | // if(top_element != NULL) { | 241 | // if(top_element != NULL) { |
241 | // bool found = false; | 242 | // bool found = false; |
242 | // element = top_element; | 243 | // element = top_element; |
243 | 244 | ||
244 | // while(element != NULL && !found) { | 245 | // while(element != NULL && !found) { |
245 | // if(strcmp( element->text(0).ascii(), share)==0) { | 246 | // if(strcmp( element->text(0).ascii(), share)==0) { |
246 | // parent = element; | 247 | // parent = element; |
247 | // found = true; | 248 | // found = true; |
248 | // } | 249 | // } |
249 | // element = element->nextSibling(); | 250 | // element = element->nextSibling(); |
250 | // } | 251 | // } |
251 | 252 | ||
252 | // if(!found) { | 253 | // if(!found) { |
253 | // element = new QListViewItem(ListViewScan,share); | 254 | // element = new QListViewItem(ListViewScan,share); |
254 | // element->setOpen(true); | 255 | // element->setOpen(true); |
255 | // parent=element; | 256 | // parent=element; |
256 | // } | 257 | // } |
257 | // } else { | 258 | // } else { |
258 | // element = new QListViewItem(ListViewScan,share); | 259 | // element = new QListViewItem(ListViewScan,share); |
259 | // element->setOpen(true); | 260 | // element->setOpen(true); |
260 | // top_element = element; | 261 | // top_element = element; |
261 | // parent = element; | 262 | // parent = element; |
262 | // } | 263 | // } |
263 | // } | 264 | // } |
264 | // } | 265 | // } |
265 | 266 | ||
266 | TextViewOutput->append("\n\n============================================\n"); | 267 | TextViewOutput->append("\n\n============================================\n"); |
267 | LScan->setText(""); | 268 | LScan->setText(""); |
268 | scanning = false; | 269 | scanning = false; |
269 | } | 270 | } |
270 | 271 | ||
271 | 272 | ||
272 | void Qsmb::DoIt() | 273 | void Qsmb::DoIt() |
273 | { | 274 | { |
274 | 275 | ||
275 | QListViewItem *element; | 276 | QListViewItem *element; |
276 | element = ListViewScan->selectedItem(); | 277 | element = ListViewScan->selectedItem(); |
277 | if(!element) { | 278 | if(!element) { |
278 | return; | 279 | return; |
279 | } | 280 | } |
280 | 281 | ||
281 | if (scanning) return; | 282 | if (scanning) return; |
282 | scanning = true; | 283 | scanning = true; |
283 | 284 | ||
284 | QString mount = mountpt->currentText(); | 285 | QString mount = mountpt->currentText(); |
285 | if(isMounted(mount)) { | 286 | if(isMounted(mount)) { |
286 | qWarning(mount +" is already mounted"); | 287 | qWarning(mount +" is already mounted"); |
287 | TextViewOutput->append(mount +" is already mounted"); | 288 | TextViewOutput->append(mount +" is already mounted"); |
288 | return; | 289 | return; |
289 | } | 290 | } |
290 | 291 | ||
291 | bool noerr = false; | 292 | bool noerr = false; |
292 | 293 | ||
293 | QString share; | 294 | QString share; |
294 | QString cmd; | 295 | QString cmd; |
295 | QString cmd2; | 296 | QString cmd2; |
296 | QString text = mountpt->currentText(); | 297 | QString text = mountpt->currentText(); |
297 | QStringList ccmd; | 298 | QStringList ccmd; |
298 | 299 | ||
299 | LScan->setText("Mounting..."); | 300 | LScan->setText("Mounting..."); |
300 | qApp->processEvents(); | 301 | qApp->processEvents(); |
301 | 302 | ||
302 | if( !QFileInfo(text).exists()) { | 303 | if( !QFileInfo(text).exists()) { |
303 | ccmd << "mkdir"; | 304 | ccmd << "mkdir"; |
304 | ccmd << "-p"; | 305 | ccmd << "-p"; |
305 | ccmd << text; | 306 | ccmd << text; |
306 | 307 | ||
307 | qWarning( "cmd: "+ ccmd.join(" ")); | 308 | qWarning( "cmd: "+ ccmd.join(" ")); |
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 |