author | llornkcor <llornkcor> | 2005-08-15 11:09:26 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-08-15 11:09:26 (UTC) |
commit | 0771d689056f233fe772d85de4040f59f3ba1e6b (patch) (unidiff) | |
tree | cd746f64ca8b36852d6232f62ee7b803e6a5a3c4 | |
parent | e7c0016a970ab1bdf5870a648a7bf07b857fbb11 (diff) | |
download | opie-0771d689056f233fe772d85de4040f59f3ba1e6b.zip opie-0771d689056f233fe772d85de4040f59f3ba1e6b.tar.gz opie-0771d689056f233fe772d85de4040f59f3ba1e6b.tar.bz2 |
better way to get shares
-rw-r--r-- | noncore/net/opie-smb/qsmb.cpp | 151 | ||||
-rw-r--r-- | noncore/net/opie-smb/qsmbbase.ui | 20 |
2 files changed, 93 insertions, 78 deletions
diff --git a/noncore/net/opie-smb/qsmb.cpp b/noncore/net/opie-smb/qsmb.cpp index c1ee9a9..fbe1c5c 100644 --- a/noncore/net/opie-smb/qsmb.cpp +++ b/noncore/net/opie-smb/qsmb.cpp | |||
@@ -92,13 +92,13 @@ void* runitm(void* arg) | |||
92 | caller->DoIt(); | 92 | caller->DoIt(); |
93 | return(0); | 93 | return(0); |
94 | } | 94 | } |
95 | 95 | ||
96 | void Qsmb::scan() | 96 | void Qsmb::scan() |
97 | { | 97 | { |
98 | int i; | 98 | // int i; |
99 | 99 | ||
100 | if (scanning) return; | 100 | if (scanning) return; |
101 | scanning = true; | 101 | scanning = true; |
102 | 102 | ||
103 | QString match; | 103 | QString match; |
104 | QString cmd; | 104 | QString cmd; |
@@ -120,13 +120,12 @@ void Qsmb::scan() | |||
120 | QTextStream lms(&lmhosts); | 120 | QTextStream lms(&lmhosts); |
121 | lmhosts.open(IO_WriteOnly); | 121 | lmhosts.open(IO_WriteOnly); |
122 | lms << "127.0.0.1 localhost\n"; | 122 | lms << "127.0.0.1 localhost\n"; |
123 | 123 | ||
124 | /* parse output and display in ListViewScan */ | 124 | /* parse output and display in ListViewScan */ |
125 | ccmd = "smbfind"; | 125 | ccmd = "smbfind"; |
126 | owarn <<"cmd: " << ccmd << oendl; | ||
127 | runCommand(ccmd); | 126 | runCommand(ccmd); |
128 | 127 | ||
129 | QTextStream s(&out, IO_ReadOnly); | 128 | QTextStream s(&out, IO_ReadOnly); |
130 | 129 | ||
131 | while ( !s.atEnd() ) { | 130 | while ( !s.atEnd() ) { |
132 | QString ip_addr, host, output; | 131 | QString ip_addr, host, output; |
@@ -148,94 +147,105 @@ void Qsmb::scan() | |||
148 | scanning = false; | 147 | scanning = false; |
149 | } | 148 | } |
150 | 149 | ||
151 | void Qsmb::hostSelected(int index) | 150 | void Qsmb::hostSelected(int index) |
152 | { | 151 | { |
153 | owarn << "hostSelected" << oendl; | 152 | owarn << "hostSelected" << oendl; |
154 | int i; | ||
155 | |||
156 | QListViewItem *element; | 153 | QListViewItem *element; |
157 | QListViewItem *parent; | 154 | QListViewItem *parent; |
158 | 155 | ||
159 | QString text = CBHost->currentText(); | 156 | QString text = CBHost->currentText(); |
160 | 157 | ||
161 | if (scanning) return; | 158 | if (scanning) return; |
162 | scanning = true; | 159 | scanning = true; |
163 | 160 | ||
164 | QString cmd; | 161 | QString cmd; |
165 | char result[256]; | 162 | QStringList ccmd; |
166 | |||
167 | FILE *pipe; | ||
168 | 163 | ||
169 | LScan->setText("Scanning..."); | 164 | LScan->setText("Scanning..."); |
170 | 165 | ||
171 | if(username->text().isEmpty()) | 166 | ccmd << "/usr/bin/smbclient"; |
172 | cmd = "/usr/bin/smbclient -L //"+CBHost->currentText()+" -N 2>&1 |grep Disk"; | 167 | ccmd << "-L"; |
173 | else | 168 | ccmd << CBHost->currentText(); |
174 | cmd = "/usr/bin/smbclient -L //"+CBHost->currentText()+" -N -U "+username->text()+"\%"+password->text()+" 2>&1 |grep Disk"; | 169 | ccmd << "-N"; |
170 | |||
171 | if(username->text().isEmpty()) { | ||
172 | } else { | ||
173 | ccmd << "-U"; | ||
174 | ccmd << username->text()+"\%"+ password->text(); | ||
175 | } | ||
176 | runCommand(ccmd); | ||
177 | QTextStream s(&out, IO_ReadOnly); | ||
175 | 178 | ||
176 | // for(i = 0; i < 512; i++) { | 179 | while ( !s.atEnd() ) { |
177 | // if(cmd[i]==':') { | 180 | QString share; |
178 | // cmd[i]='%'; | 181 | QString comment; |
179 | // break; | 182 | QString tmp = s.readLine(); |
180 | // } | 183 | |
181 | // if(cmd[i]=='\0') | 184 | if( tmp.find("$") == -1 && tmp.find("Disk") != -1) { |
182 | // break; | 185 | QStringList token = QStringList::split(' ', tmp ); |
183 | // } | 186 | share = token[0]; |
187 | comment = token[2]; | ||
188 | element = new QListViewItem(ListViewScan,share, comment); | ||
189 | element->setOpen(true); | ||
190 | // top_element = element; | ||
191 | // parent = element; | ||
192 | } | ||
184 | 193 | ||
185 | owarn << "i="<< index << "cmd:" << cmd << oendl; | 194 | } |
195 | // owarn << "i="<< index << "cmd:" << cmd << oendl; | ||
186 | 196 | ||
187 | TextViewOutput->append(cmd); | 197 | TextViewOutput->append(cmd); |
188 | 198 | ||
189 | /* run smbclient & read output */ | 199 | /* run smbclient & read output */ |
190 | if ((pipe = popen(cmd.latin1(), "r")) == NULL) { | 200 | // if ((pipe = popen(cmd.latin1(), "r")) == NULL) { |
191 | snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); | 201 | // snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); |
192 | // cmd = "Error: Can't run "+cmd; | 202 | // // cmd = "Error: Can't run "+cmd; |
193 | TextViewOutput->append(result); | 203 | // TextViewOutput->append(result); |
194 | return; | 204 | // return; |
195 | } | 205 | // } |
196 | 206 | ||
197 | /* parse output and display in ListViewScan */ | 207 | /* parse output and display in ListViewScan */ |
198 | while(fgets(result, 256, pipe) != NULL) { | 208 | // while(fgets(result, 256, pipe) != NULL) { |
199 | /* put result into TextViewOutput */ | 209 | // /* put result into TextViewOutput */ |
200 | TextViewOutput->append(result); | 210 | // TextViewOutput->append(result); |
201 | 211 | ||
202 | if( strchr(result, '$') == NULL ) { | 212 | // if( strchr(result, '$') == NULL ) { |
203 | char share[256], *ptr1; | 213 | // char share[256], *ptr1; |
204 | 214 | ||
205 | strcpy(share,result); | 215 | // strcpy(share,result); |
206 | ptr1 = strchr(share,' '); | 216 | // ptr1 = strchr(share,' '); |
207 | share[ptr1 - share]='\0'; | 217 | // share[ptr1 - share]='\0'; |
208 | 218 | ||
209 | owarn<< "add share: " << share << oendl; | 219 | // owarn<< "add share: " << share << oendl; |
210 | 220 | ||
211 | if(top_element != NULL) { | 221 | // if(top_element != NULL) { |
212 | bool found = false; | 222 | // bool found = false; |
213 | element = top_element; | 223 | // element = top_element; |
214 | 224 | ||
215 | while(element != NULL && !found) { | 225 | // while(element != NULL && !found) { |
216 | if(strcmp( element->text(0).ascii(), share)==0) { | 226 | // if(strcmp( element->text(0).ascii(), share)==0) { |
217 | parent = element; | 227 | // parent = element; |
218 | found = true; | 228 | // found = true; |
219 | } | 229 | // } |
220 | element = element->nextSibling(); | 230 | // element = element->nextSibling(); |
221 | } | 231 | // } |
222 | 232 | ||
223 | if(!found) { | 233 | // if(!found) { |
224 | element = new QListViewItem(ListViewScan,share); | 234 | // element = new QListViewItem(ListViewScan,share); |
225 | element->setOpen(true); | 235 | // element->setOpen(true); |
226 | parent=element; | 236 | // parent=element; |
227 | } | 237 | // } |
228 | } else { | 238 | // } else { |
229 | element = new QListViewItem(ListViewScan,share); | 239 | // element = new QListViewItem(ListViewScan,share); |
230 | element->setOpen(true); | 240 | // element->setOpen(true); |
231 | top_element = element; | 241 | // top_element = element; |
232 | parent = element; | 242 | // parent = element; |
233 | } | 243 | // } |
234 | } | 244 | // } |
235 | } | 245 | // } |
236 | 246 | ||
237 | TextViewOutput->append("\n\n============================================\n"); | 247 | TextViewOutput->append("\n\n============================================\n"); |
238 | LScan->setText(""); | 248 | LScan->setText(""); |
239 | scanning = false; | 249 | scanning = false; |
240 | } | 250 | } |
241 | 251 | ||
@@ -265,25 +275,12 @@ void Qsmb::DoIt() | |||
265 | 275 | ||
266 | LScan->setText("Mounting..."); | 276 | LScan->setText("Mounting..."); |
267 | qApp->processEvents(); | 277 | qApp->processEvents(); |
268 | 278 | ||
269 | 279 | ||
270 | if(! QFileInfo(text).exists()) { | 280 | if(! QFileInfo(text).exists()) { |
271 | // /* make sure mount exists! */ | ||
272 | |||
273 | // cmd = "mkdir -p "+ text; | ||
274 | // owarn<<"cmd: "<< cmd << oendl; | ||
275 | // if ((pipe2 = popen(cmd.latin1(), "r")) == NULL) { | ||
276 | // snprintf(result, 256, "Error: Can't run %s", cmd.latin1()); | ||
277 | // TextViewOutput->append(result); | ||
278 | // return; | ||
279 | // } | ||
280 | // while(fgets(result, 256, pipe2) != NULL) { | ||
281 | // /* put result into TextViewOutput */ | ||
282 | // TextViewOutput->append(result); | ||
283 | // } | ||
284 | QStringList ccmd; | 281 | QStringList ccmd; |
285 | ccmd << "mkdir"; | 282 | ccmd << "mkdir"; |
286 | ccmd << "-p"; | 283 | ccmd << "-p"; |
287 | ccmd << text; | 284 | ccmd << text; |
288 | 285 | ||
289 | owarn<<"cmd: "<< ccmd << oendl; | 286 | owarn<<"cmd: "<< ccmd << oendl; |
diff --git a/noncore/net/opie-smb/qsmbbase.ui b/noncore/net/opie-smb/qsmbbase.ui index 35a1aec..3107929 100644 --- a/noncore/net/opie-smb/qsmbbase.ui +++ b/noncore/net/opie-smb/qsmbbase.ui | |||
@@ -8,13 +8,13 @@ | |||
8 | </property> | 8 | </property> |
9 | <property stdset="1"> | 9 | <property stdset="1"> |
10 | <name>geometry</name> | 10 | <name>geometry</name> |
11 | <rect> | 11 | <rect> |
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>254</width> | 14 | <width>250</width> |
15 | <height>352</height> | 15 | <height>352</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
19 | <name>font</name> | 19 | <name>font</name> |
20 | <font> | 20 | <font> |
@@ -119,16 +119,34 @@ | |||
119 | </property> | 119 | </property> |
120 | <property> | 120 | <property> |
121 | <name>resizeable</name> | 121 | <name>resizeable</name> |
122 | <bool>true</bool> | 122 | <bool>true</bool> |
123 | </property> | 123 | </property> |
124 | </column> | 124 | </column> |
125 | <column> | ||
126 | <property> | ||
127 | <name>text</name> | ||
128 | <string>Comment</string> | ||
129 | </property> | ||
130 | <property> | ||
131 | <name>clickable</name> | ||
132 | <bool>true</bool> | ||
133 | </property> | ||
134 | <property> | ||
135 | <name>resizeable</name> | ||
136 | <bool>true</bool> | ||
137 | </property> | ||
138 | </column> | ||
125 | <property stdset="1"> | 139 | <property stdset="1"> |
126 | <name>name</name> | 140 | <name>name</name> |
127 | <cstring>ListViewScan</cstring> | 141 | <cstring>ListViewScan</cstring> |
128 | </property> | 142 | </property> |
143 | <property stdset="1"> | ||
144 | <name>allColumnsShowFocus</name> | ||
145 | <bool>true</bool> | ||
146 | </property> | ||
129 | </widget> | 147 | </widget> |
130 | <widget row="0" column="0" rowspan="1" colspan="2" > | 148 | <widget row="0" column="0" rowspan="1" colspan="2" > |
131 | <class>QPushButton</class> | 149 | <class>QPushButton</class> |
132 | <property stdset="1"> | 150 | <property stdset="1"> |
133 | <name>name</name> | 151 | <name>name</name> |
134 | <cstring>BtnScan</cstring> | 152 | <cstring>BtnScan</cstring> |