author | korovkin <korovkin> | 2006-05-06 18:37:33 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-05-06 18:37:33 (UTC) |
commit | 2d9247d6c2917fd967d0d01d4d9aa6de4fb820f1 (patch) (unidiff) | |
tree | d42ffb6e48f3d0f3b6b53b6c1b628e28e0783ceb | |
parent | 0430a18e64df0cdfc1e468a7f7bbe77efc63d0ca (diff) | |
download | opie-2d9247d6c2917fd967d0d01d4d9aa6de4fb820f1.zip opie-2d9247d6c2917fd967d0d01d4d9aa6de4fb820f1.tar.gz opie-2d9247d6c2917fd967d0d01d4d9aa6de4fb820f1.tar.bz2 |
Browse button forces reconnection.
-rw-r--r-- | noncore/net/opietooth/manager/obexftpdialog.cpp | 29 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/obexftpdialog.h | 4 |
2 files changed, 24 insertions, 9 deletions
diff --git a/noncore/net/opietooth/manager/obexftpdialog.cpp b/noncore/net/opietooth/manager/obexftpdialog.cpp index 2f04ecf..efb3ff2 100644 --- a/noncore/net/opietooth/manager/obexftpdialog.cpp +++ b/noncore/net/opietooth/manager/obexftpdialog.cpp | |||
@@ -1,548 +1,561 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | /* OBEX file browser dialog */ | 2 | /* OBEX file browser dialog */ |
3 | /*************************************************************************** | 3 | /*************************************************************************** |
4 | * * | 4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * | 5 | * This program is free software; you can redistribute it and/or modify * |
6 | * it under the terms of the GNU General Public License as published by * | 6 | * it under the terms of the GNU General Public License as published by * |
7 | * the Free Software Foundation; either version 2 of the License, or * | 7 | * the Free Software Foundation; either version 2 of the License, or * |
8 | * (at your option) any later version. * | 8 | * (at your option) any later version. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | /* | 11 | /* |
12 | * This code uses and is based on ObexFTP project code: http://triq.net/obexftp/ | 12 | * This code uses and is based on ObexFTP project code: http://triq.net/obexftp/ |
13 | */ | 13 | */ |
14 | #include <sys/stat.h> | 14 | #include <sys/stat.h> |
15 | #include <sys/types.h> | 15 | #include <sys/types.h> |
16 | #include <unistd.h> | 16 | #include <unistd.h> |
17 | #include <string.h> | 17 | #include <string.h> |
18 | #include <errno.h> | 18 | #include <errno.h> |
19 | #include <qpushbutton.h> | 19 | #include <qpushbutton.h> |
20 | #include <qmessagebox.h> | 20 | #include <qmessagebox.h> |
21 | #include <qmultilineedit.h> | 21 | #include <qmultilineedit.h> |
22 | #include <qlineedit.h> | 22 | #include <qlineedit.h> |
23 | #include <qspinbox.h> | 23 | #include <qspinbox.h> |
24 | #include <qcombobox.h> | 24 | #include <qcombobox.h> |
25 | #include <qlistview.h> | 25 | #include <qlistview.h> |
26 | #include <qprogressbar.h> | 26 | #include <qprogressbar.h> |
27 | #include <qlabel.h> | 27 | #include <qlabel.h> |
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <errno.h> | 29 | #include <errno.h> |
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qtextstream.h> | 31 | #include <qtextstream.h> |
32 | #include <qstringlist.h> | 32 | #include <qstringlist.h> |
33 | #include "obexftpdialog.h" | 33 | #include "obexftpdialog.h" |
34 | #include "filelistitem.h" | 34 | #include "filelistitem.h" |
35 | 35 | ||
36 | #include <qpe/qpeapplication.h> | 36 | #include <qpe/qpeapplication.h> |
37 | #include <qpe/resource.h> | 37 | #include <qpe/resource.h> |
38 | #include <qpe/config.h> | 38 | #include <qpe/config.h> |
39 | #include <opie2/odebug.h> | 39 | #include <opie2/odebug.h> |
40 | #include <opie2/ofileselector.h> | 40 | #include <opie2/ofileselector.h> |
41 | #include <opie2/ofiledialog.h> | 41 | #include <opie2/ofiledialog.h> |
42 | 42 | ||
43 | using namespace Opie::Core; | 43 | using namespace Opie::Core; |
44 | using namespace Opie::Ui; | 44 | using namespace Opie::Ui; |
45 | 45 | ||
46 | using namespace OpieTooth; | 46 | using namespace OpieTooth; |
47 | 47 | ||
48 | #define MAX_PROGRESS 14 //Maximal progress bar | 48 | #define MAX_PROGRESS 14 //Maximal progress bar |
49 | 49 | ||
50 | static void info_cb(int event, const char *msg, int len, void* data); | 50 | static void info_cb(int event, const char *msg, int len, void* data); |
51 | 51 | ||
52 | /* | 52 | /* |
53 | * Public constructor | 53 | * Public constructor |
54 | * device - bluetooth address of the device | 54 | * device - bluetooth address of the device |
55 | * port - port to connect to | 55 | * port - port to connect to |
56 | */ | 56 | */ |
57 | ObexFtpDialog::ObexFtpDialog(const QString& device, int port, | 57 | ObexFtpDialog::ObexFtpDialog(const QString& device, int port, |
58 | QWidget* parent, const char* name, bool modal, WFlags fl) | 58 | QWidget* parent, const char* name, bool modal, WFlags fl) |
59 | : ObexFtpDialogBase(parent, name, modal, fl), m_device(device), | 59 | : ObexFtpDialogBase(parent, name, modal, fl), m_device(device), |
60 | m_port(port), curdir("") | 60 | m_port(port), curdir("") |
61 | { | 61 | { |
62 | client = NULL; | 62 | client = NULL; |
63 | nRetries = 3; | 63 | nRetries = 3; |
64 | transport = OBEX_TRANS_BLUETOOTH; | 64 | transport = OBEX_TRANS_BLUETOOTH; |
65 | use_conn = TRUE; | 65 | use_conn = TRUE; |
66 | use_path = TRUE; | 66 | use_path = TRUE; |
67 | progressStatus = 0; | 67 | progressStatus = 0; |
68 | localCurdir = "/"; | 68 | localCurdir = "/"; |
69 | browseLog->setEdited(FALSE); | 69 | browseLog->setEdited(FALSE); |
70 | fileList->setSorting(1); | 70 | fileList->setSorting(1); |
71 | fileList->clear(); | 71 | fileList->clear(); |
72 | fileProgress->setTotalSteps(MAX_PROGRESS); | 72 | fileProgress->setTotalSteps(MAX_PROGRESS); |
73 | statusBar->clear(); | 73 | statusBar->clear(); |
74 | localLayout = new QVBoxLayout(localFs); | 74 | localLayout = new QVBoxLayout(localFs); |
75 | localLayout->setSpacing( 0 ); | 75 | localLayout->setSpacing( 0 ); |
76 | localLayout->setMargin( 0 ); | 76 | localLayout->setMargin( 0 ); |
77 | destFile = new OFileSelector(localFs, | 77 | destFile = new OFileSelector(localFs, |
78 | OFileSelector::FileSelector, | 78 | OFileSelector::FileSelector, |
79 | OFileSelector::ExtendedAll, localCurdir, ""); | 79 | OFileSelector::ExtendedAll, localCurdir, ""); |
80 | destFile->setCloseVisible(false); | 80 | destFile->setCloseVisible(false); |
81 | destFile->setNewVisible(false); | 81 | destFile->setNewVisible(false); |
82 | localLayout->addWidget(destFile); | 82 | localLayout->addWidget(destFile); |
83 | nReries->setValue(nRetries); | 83 | nReries->setValue(nRetries); |
84 | connect(browseOK, SIGNAL(clicked()), SLOT(slotBrowse())); | 84 | connect(browseOK, SIGNAL(clicked()), SLOT(slotBrowse())); |
85 | connect(fileList, SIGNAL(clicked(QListViewItem*)), | 85 | connect(fileList, SIGNAL(clicked(QListViewItem*)), |
86 | SLOT(slotCd(QListViewItem*))); | 86 | SLOT(slotCd(QListViewItem*))); |
87 | connect(getButton, | 87 | connect(getButton, |
88 | SIGNAL(clicked()), | 88 | SIGNAL(clicked()), |
89 | SLOT(getFile())); | 89 | SLOT(getFile())); |
90 | connect(putButton, | 90 | connect(putButton, |
91 | SIGNAL(clicked()), | 91 | SIGNAL(clicked()), |
92 | SLOT(putFile())); | 92 | SLOT(putFile())); |
93 | connect(delButton, | 93 | connect(delButton, |
94 | SIGNAL(clicked()), | 94 | SIGNAL(clicked()), |
95 | SLOT(delFile())); | 95 | SLOT(delFile())); |
96 | connect(destFile, | 96 | connect(destFile, |
97 | SIGNAL(dirSelected (const QString&)), | 97 | SIGNAL(dirSelected (const QString&)), |
98 | SLOT(updateDir(const QString&))); | 98 | SLOT(updateDir(const QString&))); |
99 | connect(saveButton, | 99 | connect(saveButton, |
100 | SIGNAL(clicked()), | 100 | SIGNAL(clicked()), |
101 | SLOT(slotSaveLog())); | 101 | SLOT(slotSaveLog())); |
102 | connect(browseButton, | 102 | connect(browseButton, |
103 | SIGNAL(clicked()), | 103 | SIGNAL(clicked()), |
104 | SLOT(slotBrowseLog())); | 104 | SLOT(slotBrowseLog())); |
105 | } | 105 | } |
106 | 106 | ||
107 | ObexFtpDialog::~ObexFtpDialog() | 107 | ObexFtpDialog::~ObexFtpDialog() |
108 | { | 108 | { |
109 | if (client != NULL) { | 109 | if (client != NULL) { |
110 | obexftp_disconnect(client); | 110 | obexftp_disconnect(client); |
111 | obexftp_close(client); | 111 | obexftp_close(client); |
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | void ObexFtpDialog::slotBrowse() | ||
116 | { | ||
117 | doBrowse(TRUE); | ||
118 | } | ||
119 | |||
115 | /* | 120 | /* |
116 | * Do device browsing | 121 | * Do device browsing |
117 | */ | 122 | */ |
118 | void ObexFtpDialog::slotBrowse() | 123 | void ObexFtpDialog::doBrowse(bool reconnect) |
119 | { | 124 | { |
120 | stat_entry_t* ent; //Directory entry | 125 | stat_entry_t* ent; //Directory entry |
121 | void *dir; //Directory to read | 126 | void *dir; //Directory to read |
122 | const uint8_t* use_uuid; //uuid | 127 | const uint8_t* use_uuid; //uuid |
123 | int len; //uuid length | 128 | int len; //uuid length |
124 | FileListItem* root; //root node | 129 | FileListItem* root; //root node |
125 | int fsize; //file size | 130 | int fsize; //file size |
126 | bool numOk; //true if the string is a number | 131 | bool numOk; //true if the string is a number |
127 | int tmp; //just a temp var | 132 | int tmp; //just a temp var |
128 | 133 | ||
129 | status(tr("Connecting to ") + m_device); | 134 | status(tr("Connecting to ") + m_device); |
130 | odebug << "Browse device " << m_device << oendl; | 135 | odebug << "Browse device " << m_device << oendl; |
131 | browseLog->clear(); | 136 | browseLog->clear(); |
132 | fileList->clear(); | 137 | fileList->clear(); |
133 | progressStatus = 0; | 138 | progressStatus = 0; |
134 | fileProgress->setTotalSteps(MAX_PROGRESS); | 139 | fileProgress->setTotalSteps(MAX_PROGRESS); |
135 | fileProgress->reset(); | 140 | fileProgress->reset(); |
136 | 141 | ||
137 | //Get parameters | 142 | //Get parameters |
138 | tmp = nReries->text().toInt(&numOk); | 143 | tmp = nReries->text().toInt(&numOk); |
139 | if (numOk) | 144 | if (numOk) |
140 | nRetries = tmp; | 145 | nRetries = tmp; |
141 | if (uuidType->currentText() == "FBS") { | 146 | if (uuidType->currentText() == "FBS") { |
142 | use_uuid = UUID_FBS; | 147 | use_uuid = UUID_FBS; |
143 | len = sizeof(UUID_FBS); | 148 | len = sizeof(UUID_FBS); |
144 | } else if (uuidType->currentText() == "S45") { | 149 | } else if (uuidType->currentText() == "S45") { |
145 | use_uuid = UUID_S45; | 150 | use_uuid = UUID_S45; |
146 | len = sizeof(UUID_S45); | 151 | len = sizeof(UUID_S45); |
147 | } else { | 152 | } else { |
148 | use_uuid = UUID_FBS; | 153 | use_uuid = UUID_FBS; |
149 | len = sizeof(UUID_FBS); | 154 | len = sizeof(UUID_FBS); |
150 | } | 155 | } |
151 | 156 | ||
152 | if (!cli_connect_uuid(use_uuid, len)) { | 157 | if (!cli_connect_uuid(use_uuid, len, reconnect)) { |
153 | log(tr("Connection failed: ") + tr(strerror(errno))); | 158 | log(tr("Connection failed: ") + tr(strerror(errno))); |
154 | errBox("Connection failed"); | 159 | errBox("Connection failed"); |
155 | status("Connection failed"); | 160 | status("Connection failed"); |
156 | return; | 161 | return; |
157 | } | 162 | } |
158 | else { | 163 | else { |
159 | log(QString("Connected to ") + m_device); | 164 | log(QString("Connected to ") + m_device); |
160 | status(QString("Connected to ") + m_device); | 165 | status(QString("Connected to ") + m_device); |
161 | } | 166 | } |
162 | /* List folder */ | 167 | /* List folder */ |
163 | root = new FileListItem(fileList, NULL); | 168 | root = new FileListItem(fileList, NULL); |
164 | dir = obexftp_opendir(client, curdir); | 169 | dir = obexftp_opendir(client, curdir); |
165 | while ((ent = obexftp_readdir(dir)) != NULL) { | 170 | while ((ent = obexftp_readdir(dir)) != NULL) { |
166 | FileListItem* a; //List view item | 171 | FileListItem* a; //List view item |
167 | if (ent->mode != 16877) { | 172 | if (ent->mode != 16877) { |
168 | fsize = ent->size; | 173 | fsize = ent->size; |
169 | } | 174 | } |
170 | else | 175 | else |
171 | fsize = 0; | 176 | fsize = 0; |
172 | log(QString(ent->name) + QString(" ") + | 177 | log(QString(ent->name) + QString(" ") + |
173 | QString::number(ent->mode)); | 178 | QString::number(ent->mode)); |
174 | 179 | ||
175 | a = new FileListItem(fileList, ent, fsize); | 180 | a = new FileListItem(fileList, ent, fsize); |
176 | } | 181 | } |
177 | obexftp_closedir(dir); | 182 | obexftp_closedir(dir); |
178 | } | 183 | } |
179 | 184 | ||
180 | //Error message box | 185 | //Error message box |
181 | int ObexFtpDialog::errBox(QCString msg) | 186 | int ObexFtpDialog::errBox(QCString msg) |
182 | { | 187 | { |
183 | return QMessageBox::critical(this, tr("ObexFTP error"), msg); | 188 | return QMessageBox::critical(this, tr("ObexFTP error"), msg); |
184 | } | 189 | } |
185 | 190 | ||
186 | int ObexFtpDialog::errBox(QString msg) | 191 | int ObexFtpDialog::errBox(QString msg) |
187 | { | 192 | { |
188 | return QMessageBox::critical(this, tr("ObexFTP error"), msg); | 193 | return QMessageBox::critical(this, tr("ObexFTP error"), msg); |
189 | } | 194 | } |
190 | 195 | ||
191 | int ObexFtpDialog::errBox(const char* msg) | 196 | int ObexFtpDialog::errBox(const char* msg) |
192 | { | 197 | { |
193 | return QMessageBox::critical(this, tr("ObexFTP error"), tr(msg)); | 198 | return QMessageBox::critical(this, tr("ObexFTP error"), tr(msg)); |
194 | } | 199 | } |
195 | 200 | ||
196 | //Text in the status bar | 201 | //Text in the status bar |
197 | void ObexFtpDialog::status(QCString msg) | 202 | void ObexFtpDialog::status(QCString msg) |
198 | { | 203 | { |
199 | statusBar->setText(msg); | 204 | statusBar->setText(msg); |
200 | statusBar->repaint(); | 205 | statusBar->repaint(); |
201 | } | 206 | } |
202 | 207 | ||
203 | void ObexFtpDialog::status(QString msg) | 208 | void ObexFtpDialog::status(QString msg) |
204 | { | 209 | { |
205 | statusBar->setText(msg); | 210 | statusBar->setText(msg); |
206 | statusBar->repaint(); | 211 | statusBar->repaint(); |
207 | } | 212 | } |
208 | 213 | ||
209 | void ObexFtpDialog::status(const char* msg) | 214 | void ObexFtpDialog::status(const char* msg) |
210 | { | 215 | { |
211 | statusBar->setText(msg); | 216 | statusBar->setText(msg); |
212 | statusBar->repaint(); | 217 | statusBar->repaint(); |
213 | } | 218 | } |
214 | 219 | ||
215 | /* | 220 | /* |
216 | * Change directory with item under the cursor | 221 | * Change directory with item under the cursor |
217 | */ | 222 | */ |
218 | void ObexFtpDialog::slotCd(QListViewItem* item) | 223 | void ObexFtpDialog::slotCd(QListViewItem* item) |
219 | { | 224 | { |
220 | FileListItem* file = (FileListItem*)item; | 225 | FileListItem* file = (FileListItem*)item; |
221 | int idx; | 226 | int idx; |
222 | if (file == NULL) | 227 | if (file == NULL) |
223 | return; | 228 | return; |
224 | odebug << "Item " << file->text(0) << " clicked" << oendl; | 229 | odebug << "Item " << file->text(0) << " clicked" << oendl; |
225 | if (file->gettype() == IS_DIR) { | 230 | if (file->gettype() == IS_DIR) { |
226 | if (file->text(0) == "../") { | 231 | if (file->text(0) == "../") { |
227 | if (curdir.right(1) == "/") | 232 | if (curdir.right(1) == "/") |
228 | curdir.remove(curdir.length() - 1, 1); | 233 | curdir.remove(curdir.length() - 1, 1); |
229 | idx = curdir.findRev('/'); | 234 | idx = curdir.findRev('/'); |
230 | if (idx >= 0) | 235 | if (idx >= 0) |
231 | curdir.remove(idx, curdir.length() - idx); | 236 | curdir.remove(idx, curdir.length() - idx); |
232 | else | 237 | else |
233 | curdir = ""; | 238 | curdir = ""; |
234 | } | 239 | } |
235 | else { | 240 | else { |
236 | if (curdir != "" && curdir.right(1) != "/") | 241 | if (curdir != "" && curdir.right(1) != "/") |
237 | curdir += "/"; | 242 | curdir += "/"; |
238 | curdir += file->text(0); | 243 | curdir += file->text(0); |
239 | } | 244 | } |
240 | odebug << "Browse " << curdir << oendl; | 245 | odebug << "Browse " << curdir << oendl; |
241 | if (obexftp_setpath(client, curdir, 0) < 0) | 246 | if (obexftp_setpath(client, curdir, 0) < 0) |
242 | log(tr("CD failed: ") + tr(strerror(errno))); | 247 | log(tr("CD failed: ") + tr(strerror(errno))); |
243 | slotBrowse(); | 248 | doBrowse(); |
244 | } | 249 | } |
245 | } | 250 | } |
246 | 251 | ||
247 | /* | 252 | /* |
248 | * Copy file from a remote device to the local device | 253 | * Copy file from a remote device to the local device |
249 | */ | 254 | */ |
250 | void ObexFtpDialog::getFile() | 255 | void ObexFtpDialog::getFile() |
251 | { | 256 | { |
252 | FileListItem* file = (FileListItem*)fileList->selectedItem(); | 257 | FileListItem* file = (FileListItem*)fileList->selectedItem(); |
253 | int result; | 258 | int result; |
254 | if (file == NULL) | 259 | if (file == NULL) |
255 | return; | 260 | return; |
256 | file2get = "/"; | 261 | file2get = "/"; |
257 | local = localCurdir; | 262 | local = localCurdir; |
258 | if (local == "") { | 263 | if (local == "") { |
259 | errBox("Select a destination first"); | 264 | errBox("Select a destination first"); |
260 | return; | 265 | return; |
261 | } | 266 | } |
262 | if (local.right(1) != "/") | 267 | if (local.right(1) != "/") |
263 | local += "/"; | 268 | local += "/"; |
264 | if (file->gettype() == IS_FILE) { | 269 | if (file->gettype() == IS_FILE) { |
265 | if (client == NULL) { | 270 | if (client == NULL) { |
266 | errBox("No connection established"); | 271 | errBox("No connection established"); |
267 | return; | 272 | return; |
268 | } | 273 | } |
269 | file2get += curdir; | 274 | file2get += curdir; |
270 | if (curdir != "" && curdir.right(1) != "/") | 275 | if (curdir != "" && curdir.right(1) != "/") |
271 | file2get += "/"; | 276 | file2get += "/"; |
272 | file2get += file->text(0); | 277 | file2get += file->text(0); |
273 | local += file->text(0); | 278 | local += file->text(0); |
274 | odebug << "Copy " << file2get << " to " << local << oendl; | 279 | odebug << "Copy " << file2get << " to " << local << oendl; |
275 | progressStatus = 0; | 280 | progressStatus = 0; |
276 | fileProgress->setTotalSteps(file->getsize() / 1024); | 281 | fileProgress->setTotalSteps(file->getsize() / 1024); |
277 | fileProgress->reset(); | 282 | fileProgress->reset(); |
278 | status(tr("Receiving file ") + file2get); | 283 | status(tr("Receiving file ") + file2get); |
279 | result = obexftp_get(client, local, file2get); | 284 | result = obexftp_get(client, local, file2get); |
280 | if (result < 0) { | 285 | if (result < 0) { |
281 | log(file2get + QString(" receive ERROR:\n") + tr(strerror(errno))); | 286 | log(file2get + QString(" receive ERROR:\n") + tr(strerror(errno))); |
282 | errBox(file2get + QString(" receive ERROR")); | 287 | errBox(file2get + QString(" receive ERROR")); |
283 | status(file2get + QString(" receive ERROR")); | 288 | status(file2get + QString(" receive ERROR")); |
284 | } | 289 | } |
285 | else { | 290 | else { |
286 | log(file2get + QString(" received")); | 291 | log(file2get + QString(" received")); |
287 | status(file2get + QString(" received")); | 292 | status(file2get + QString(" received")); |
288 | destFile->reread(); | 293 | destFile->reread(); |
289 | } | 294 | } |
290 | } | 295 | } |
291 | } | 296 | } |
292 | 297 | ||
293 | /* | 298 | /* |
294 | * Copy file from the local device to a remote device | 299 | * Copy file from the local device to a remote device |
295 | */ | 300 | */ |
296 | void ObexFtpDialog::putFile() | 301 | void ObexFtpDialog::putFile() |
297 | { | 302 | { |
298 | int result; //OPeration result | 303 | int result; //OPeration result |
299 | int idx; //Index of a symbol in the string | 304 | int idx; //Index of a symbol in the string |
300 | struct stat localFStat; //Local file information | 305 | struct stat localFStat; //Local file information |
301 | 306 | ||
302 | if (client == NULL) { | 307 | if (client == NULL) { |
303 | errBox("No connection established"); | 308 | errBox("No connection established"); |
304 | return; | 309 | return; |
305 | } | 310 | } |
306 | local = destFile->selectedName(); | 311 | local = destFile->selectedName(); |
307 | if (local == "") { | 312 | if (local == "") { |
308 | errBox("No file slected"); | 313 | errBox("No file slected"); |
309 | return; | 314 | return; |
310 | } | 315 | } |
311 | result = stat(local, &localFStat); | 316 | result = stat(local, &localFStat); |
312 | if (result < 0) { | 317 | if (result < 0) { |
313 | errBox(tr("Wrong file selected ") + local + tr(" ") + | 318 | errBox(tr("Wrong file selected ") + local + tr(" ") + |
314 | tr(strerror(errno))); | 319 | tr(strerror(errno))); |
315 | return; | 320 | return; |
316 | } | 321 | } |
317 | idx = local.findRev('/'); | 322 | idx = local.findRev('/'); |
318 | if (idx > 0) { | 323 | if (idx > 0) { |
319 | file2get = local.right(local.length() - idx - 1); | 324 | file2get = local.right(local.length() - idx - 1); |
320 | } | 325 | } |
321 | else | 326 | else |
322 | file2get = local; | 327 | file2get = local; |
323 | 328 | ||
324 | odebug << "Copy " << local << " to " << file2get << oendl; | 329 | odebug << "Copy " << local << " to " << file2get << oendl; |
325 | progressStatus = 0; | 330 | progressStatus = 0; |
326 | fileProgress->setTotalSteps(localFStat.st_size / 1024); | 331 | fileProgress->setTotalSteps(localFStat.st_size / 1024); |
327 | fileProgress->reset(); | 332 | fileProgress->reset(); |
328 | status(tr("Sending file ") + local); | 333 | status(tr("Sending file ") + local); |
329 | result = obexftp_put_file(client, local, file2get); | 334 | result = obexftp_put_file(client, local, file2get); |
330 | if (result < 0) { | 335 | if (result < 0) { |
331 | log(local + QString(" send ERROR:\n") + tr(strerror(errno))); | 336 | log(local + QString(" send ERROR:\n") + tr(strerror(errno))); |
332 | errBox(local + QString(" send ERROR")); | 337 | errBox(local + QString(" send ERROR")); |
333 | status(local + QString(" send ERROR")); | 338 | status(local + QString(" send ERROR")); |
334 | } | 339 | } |
335 | else { | 340 | else { |
336 | slotBrowse(); | 341 | doBrowse(); |
337 | log(local + QString(" sent")); | 342 | log(local + QString(" sent")); |
338 | status(local + QString(" sent")); | 343 | status(local + QString(" sent")); |
339 | } | 344 | } |
340 | } | 345 | } |
341 | 346 | ||
342 | /* | 347 | /* |
343 | * Delete file on a remote device | 348 | * Delete file on a remote device |
344 | */ | 349 | */ |
345 | void ObexFtpDialog::delFile() | 350 | void ObexFtpDialog::delFile() |
346 | { | 351 | { |
347 | FileListItem* file = (FileListItem*)fileList->selectedItem(); | 352 | FileListItem* file = (FileListItem*)fileList->selectedItem(); |
348 | int result; | 353 | int result; |
349 | if (file == NULL) | 354 | if (file == NULL) |
350 | return; | 355 | return; |
351 | file2get = "/"; | 356 | file2get = "/"; |
352 | if (file->gettype() == IS_FILE) { | 357 | if (file->gettype() == IS_FILE) { |
353 | if (client == NULL) { | 358 | if (client == NULL) { |
354 | errBox("No connection established"); | 359 | errBox("No connection established"); |
355 | return; | 360 | return; |
356 | } | 361 | } |
357 | file2get += curdir; | 362 | file2get += curdir; |
358 | if (curdir != "" && curdir.right(1) != "/") | 363 | if (curdir != "" && curdir.right(1) != "/") |
359 | file2get += "/"; | 364 | file2get += "/"; |
360 | file2get += file->text(0); | 365 | file2get += file->text(0); |
361 | } | 366 | } |
362 | result = QMessageBox::warning(this, tr("Remove File"), | 367 | result = QMessageBox::warning(this, tr("Remove File"), |
363 | tr("Do you want to remove\n") + file2get, "Yes", "No"); | 368 | tr("Do you want to remove\n") + file2get, "Yes", "No"); |
364 | if (result != 0) | 369 | if (result != 0) |
365 | return; | 370 | return; |
366 | odebug << "Remove " << file2get << oendl; | 371 | odebug << "Remove " << file2get << oendl; |
367 | result = obexftp_del(client, file2get); | 372 | result = obexftp_del(client, file2get); |
368 | if (result < 0) { | 373 | if (result < 0) { |
369 | log(file2get + QString(" remove ERROR\n") + tr(strerror(errno))); | 374 | log(file2get + QString(" remove ERROR\n") + tr(strerror(errno))); |
370 | errBox(file2get + QString(" remove ERROR")); | 375 | errBox(file2get + QString(" remove ERROR")); |
371 | status(file2get + QString(" remove ERROR")); | 376 | status(file2get + QString(" remove ERROR")); |
372 | } | 377 | } |
373 | else { | 378 | else { |
374 | slotBrowse(); | 379 | doBrowse(); |
375 | log(file2get + QString(" removed")); | 380 | log(file2get + QString(" removed")); |
376 | status(file2get + QString(" removed")); | 381 | status(file2get + QString(" removed")); |
377 | } | 382 | } |
378 | } | 383 | } |
379 | 384 | ||
380 | /* connect with given uuid. re-connect every time */ | 385 | /* connect with given uuid. re-connect every time */ |
381 | int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len) | 386 | int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len, |
387 | bool reconnect) | ||
382 | { | 388 | { |
383 | int retry; | 389 | int retry; |
384 | if (client != NULL) | 390 | if (client != NULL) { |
385 | return TRUE; | 391 | if (reconnect) { |
392 | obexftp_disconnect(client); | ||
393 | obexftp_close(client); | ||
394 | sleep(3); | ||
395 | } | ||
396 | else | ||
397 | return TRUE; | ||
398 | } | ||
386 | /* Open */ | 399 | /* Open */ |
387 | client = obexftp_open (transport, NULL, info_cb, this); | 400 | client = obexftp_open (transport, NULL, info_cb, this); |
388 | if(client == NULL) { | 401 | if(client == NULL) { |
389 | errBox("Error opening obexftp-client"); | 402 | errBox("Error opening obexftp-client"); |
390 | return FALSE; | 403 | return FALSE; |
391 | } | 404 | } |
392 | if (!use_conn) | 405 | if (!use_conn) |
393 | client->quirks &= ~OBEXFTP_CONN_HEADER; | 406 | client->quirks &= ~OBEXFTP_CONN_HEADER; |
394 | if (!use_path) | 407 | if (!use_path) |
395 | client->quirks &= ~OBEXFTP_SPLIT_SETPATH; | 408 | client->quirks &= ~OBEXFTP_SPLIT_SETPATH; |
396 | for (retry = 0; retry < nRetries; retry++) { | 409 | for (retry = 0; retry < nRetries; retry++) { |
397 | /* Connect */ | 410 | /* Connect */ |
398 | switch (transport) { | 411 | switch (transport) { |
399 | case OBEX_TRANS_IRDA: | 412 | case OBEX_TRANS_IRDA: |
400 | if (obexftp_connect_uuid(client, NULL, 0, uuid, uuid_len) >= 0) | 413 | if (obexftp_connect_uuid(client, NULL, 0, uuid, uuid_len) >= 0) |
401 | return TRUE; | 414 | return TRUE; |
402 | break; | 415 | break; |
403 | case OBEX_TRANS_BLUETOOTH: | 416 | case OBEX_TRANS_BLUETOOTH: |
404 | if (obexftp_connect_uuid(client, m_device, m_port, | 417 | if (obexftp_connect_uuid(client, m_device, m_port, |
405 | uuid, uuid_len) >= 0) | 418 | uuid, uuid_len) >= 0) |
406 | return TRUE; | 419 | return TRUE; |
407 | break; | 420 | break; |
408 | default: | 421 | default: |
409 | errBox("Transport type unknown"); | 422 | errBox("Transport type unknown"); |
410 | return FALSE; | 423 | return FALSE; |
411 | } | 424 | } |
412 | log(tr("Still trying to connect")); | 425 | log(tr("Still trying to connect")); |
413 | } | 426 | } |
414 | client = NULL; | 427 | client = NULL; |
415 | 428 | ||
416 | return FALSE; | 429 | return FALSE; |
417 | } | 430 | } |
418 | 431 | ||
419 | /* | 432 | /* |
420 | * Put a message to the log window | 433 | * Put a message to the log window |
421 | */ | 434 | */ |
422 | void ObexFtpDialog::log(QString str) | 435 | void ObexFtpDialog::log(QString str) |
423 | { | 436 | { |
424 | browseLog->append(str); | 437 | browseLog->append(str); |
425 | } | 438 | } |
426 | 439 | ||
427 | void ObexFtpDialog::log(QCString str) | 440 | void ObexFtpDialog::log(QCString str) |
428 | { | 441 | { |
429 | browseLog->append(str); | 442 | browseLog->append(str); |
430 | } | 443 | } |
431 | 444 | ||
432 | void ObexFtpDialog::log(QString& str) | 445 | void ObexFtpDialog::log(QString& str) |
433 | { | 446 | { |
434 | browseLog->append(str); | 447 | browseLog->append(str); |
435 | } | 448 | } |
436 | 449 | ||
437 | void ObexFtpDialog::log(const char* str) | 450 | void ObexFtpDialog::log(const char* str) |
438 | { | 451 | { |
439 | browseLog->append(str); | 452 | browseLog->append(str); |
440 | } | 453 | } |
441 | 454 | ||
442 | void ObexFtpDialog::incProgress() | 455 | void ObexFtpDialog::incProgress() |
443 | { | 456 | { |
444 | if (progressStatus < fileProgress->totalSteps()) | 457 | if (progressStatus < fileProgress->totalSteps()) |
445 | fileProgress->setProgress(progressStatus++); | 458 | fileProgress->setProgress(progressStatus++); |
446 | } | 459 | } |
447 | 460 | ||
448 | void ObexFtpDialog::doneProgress() | 461 | void ObexFtpDialog::doneProgress() |
449 | { | 462 | { |
450 | progressStatus = 0; | 463 | progressStatus = 0; |
451 | fileProgress->reset(); | 464 | fileProgress->reset(); |
452 | } | 465 | } |
453 | 466 | ||
454 | void ObexFtpDialog::updateDir(const QString& newdir) | 467 | void ObexFtpDialog::updateDir(const QString& newdir) |
455 | { | 468 | { |
456 | localCurdir = newdir; | 469 | localCurdir = newdir; |
457 | } | 470 | } |
458 | 471 | ||
459 | /** | 472 | /** |
460 | * Save Log to the specified file | 473 | * Save Log to the specified file |
461 | */ | 474 | */ |
462 | void ObexFtpDialog::slotSaveLog() | 475 | void ObexFtpDialog::slotSaveLog() |
463 | { | 476 | { |
464 | QFile logFile(saveLogEdit->text()); | 477 | QFile logFile(saveLogEdit->text()); |
465 | if (!logFile.open(IO_WriteOnly)) { | 478 | if (!logFile.open(IO_WriteOnly)) { |
466 | errBox(tr("Unable to open file ") + saveLogEdit->text() + tr(" ") + | 479 | errBox(tr("Unable to open file ") + saveLogEdit->text() + tr(" ") + |
467 | tr(strerror(errno))); | 480 | tr(strerror(errno))); |
468 | return; | 481 | return; |
469 | } | 482 | } |
470 | QTextStream stream(&logFile); | 483 | QTextStream stream(&logFile); |
471 | stream << browseLog->text() << endl; | 484 | stream << browseLog->text() << endl; |
472 | QMessageBox::information(this, tr("Saving"), | 485 | QMessageBox::information(this, tr("Saving"), |
473 | tr("Log file saved to ") + saveLogEdit->text()); | 486 | tr("Log file saved to ") + saveLogEdit->text()); |
474 | } | 487 | } |
475 | 488 | ||
476 | void ObexFtpDialog::slotBrowseLog() | 489 | void ObexFtpDialog::slotBrowseLog() |
477 | { | 490 | { |
478 | MimeTypes types; | 491 | MimeTypes types; |
479 | QStringList all; | 492 | QStringList all; |
480 | all << "*/*"; | 493 | all << "*/*"; |
481 | types.insert("All Files", all ); | 494 | types.insert("All Files", all ); |
482 | 495 | ||
483 | QString str = OFileDialog::getOpenFileName( 1,"/","", types, 0 ); | 496 | QString str = OFileDialog::getOpenFileName( 1,"/","", types, 0 ); |
484 | saveLogEdit->setText(str); | 497 | saveLogEdit->setText(str); |
485 | } | 498 | } |
486 | 499 | ||
487 | /* | 500 | /* |
488 | * Event callback function | 501 | * Event callback function |
489 | */ | 502 | */ |
490 | static void info_cb(int event, const char *msg, int len, void* data) | 503 | static void info_cb(int event, const char *msg, int len, void* data) |
491 | { | 504 | { |
492 | ObexFtpDialog* dlg = (ObexFtpDialog*)data; | 505 | ObexFtpDialog* dlg = (ObexFtpDialog*)data; |
493 | QCString cmsg(msg, len); //Message to display | 506 | QCString cmsg(msg, len); //Message to display |
494 | 507 | ||
495 | switch (event) { | 508 | switch (event) { |
496 | 509 | ||
497 | case OBEXFTP_EV_ERRMSG: | 510 | case OBEXFTP_EV_ERRMSG: |
498 | dlg->log(QCString("Error: ") + cmsg); | 511 | dlg->log(QCString("Error: ") + cmsg); |
499 | break; | 512 | break; |
500 | 513 | ||
501 | case OBEXFTP_EV_ERR: | 514 | case OBEXFTP_EV_ERR: |
502 | dlg->log(QCString("failed: ") + cmsg); | 515 | dlg->log(QCString("failed: ") + cmsg); |
503 | dlg->doneProgress(); | 516 | dlg->doneProgress(); |
504 | break; | 517 | break; |
505 | case OBEXFTP_EV_OK: | 518 | case OBEXFTP_EV_OK: |
506 | dlg->log(QCString("done")); | 519 | dlg->log(QCString("done")); |
507 | dlg->doneProgress(); | 520 | dlg->doneProgress(); |
508 | break; | 521 | break; |
509 | 522 | ||
510 | case OBEXFTP_EV_CONNECTING: | 523 | case OBEXFTP_EV_CONNECTING: |
511 | dlg->log(QCString("Connecting...")); | 524 | dlg->log(QCString("Connecting...")); |
512 | break; | 525 | break; |
513 | case OBEXFTP_EV_DISCONNECTING: | 526 | case OBEXFTP_EV_DISCONNECTING: |
514 | dlg->log(QCString("Disconnecting...")); | 527 | dlg->log(QCString("Disconnecting...")); |
515 | break; | 528 | break; |
516 | case OBEXFTP_EV_SENDING: | 529 | case OBEXFTP_EV_SENDING: |
517 | dlg->log(QCString("Sending ") + msg); | 530 | dlg->log(QCString("Sending ") + msg); |
518 | break; | 531 | break; |
519 | case OBEXFTP_EV_RECEIVING: | 532 | case OBEXFTP_EV_RECEIVING: |
520 | dlg->log(QCString("Receiving ") + msg); | 533 | dlg->log(QCString("Receiving ") + msg); |
521 | break; | 534 | break; |
522 | 535 | ||
523 | case OBEXFTP_EV_LISTENING: | 536 | case OBEXFTP_EV_LISTENING: |
524 | dlg->log(QCString("Waiting for incoming connection")); | 537 | dlg->log(QCString("Waiting for incoming connection")); |
525 | break; | 538 | break; |
526 | 539 | ||
527 | case OBEXFTP_EV_CONNECTIND: | 540 | case OBEXFTP_EV_CONNECTIND: |
528 | dlg->log(QCString("Incoming connection")); | 541 | dlg->log(QCString("Incoming connection")); |
529 | break; | 542 | break; |
530 | case OBEXFTP_EV_DISCONNECTIND: | 543 | case OBEXFTP_EV_DISCONNECTIND: |
531 | dlg->log(QCString("Disconnecting")); | 544 | dlg->log(QCString("Disconnecting")); |
532 | break; | 545 | break; |
533 | 546 | ||
534 | case OBEXFTP_EV_INFO: | 547 | case OBEXFTP_EV_INFO: |
535 | // 64 bit problems ? | 548 | // 64 bit problems ? |
536 | dlg->log(QString("Got info ") + QString::number((int)msg)); | 549 | dlg->log(QString("Got info ") + QString::number((int)msg)); |
537 | break; | 550 | break; |
538 | 551 | ||
539 | case OBEXFTP_EV_BODY: | 552 | case OBEXFTP_EV_BODY: |
540 | break; | 553 | break; |
541 | 554 | ||
542 | case OBEXFTP_EV_PROGRESS: | 555 | case OBEXFTP_EV_PROGRESS: |
543 | dlg->incProgress(); | 556 | dlg->incProgress(); |
544 | break; | 557 | break; |
545 | } | 558 | } |
546 | } | 559 | } |
547 | 560 | ||
548 | //eof | 561 | //eof |
diff --git a/noncore/net/opietooth/manager/obexftpdialog.h b/noncore/net/opietooth/manager/obexftpdialog.h index 75ee95b..45699d2 100644 --- a/noncore/net/opietooth/manager/obexftpdialog.h +++ b/noncore/net/opietooth/manager/obexftpdialog.h | |||
@@ -1,71 +1,73 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | /* OBEX file browser dialog */ | 2 | /* OBEX file browser dialog */ |
3 | /*************************************************************************** | 3 | /*************************************************************************** |
4 | * * | 4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * | 5 | * This program is free software; you can redistribute it and/or modify * |
6 | * it under the terms of the GNU General Public License as published by * | 6 | * it under the terms of the GNU General Public License as published by * |
7 | * the Free Software Foundation; either version 2 of the License, or * | 7 | * the Free Software Foundation; either version 2 of the License, or * |
8 | * (at your option) any later version. * | 8 | * (at your option) any later version. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | /* | 11 | /* |
12 | * This code uses and is based on ObexFTP project code: http://triq.net/obexftp/ | 12 | * This code uses and is based on ObexFTP project code: http://triq.net/obexftp/ |
13 | */ | 13 | */ |
14 | #ifndef _OBEXFTPDIALOG_H_ | 14 | #ifndef _OBEXFTPDIALOG_H_ |
15 | #define _OBEXFTPDIALOG_H_ | 15 | #define _OBEXFTPDIALOG_H_ |
16 | #include "obexftpdialogbase.h" | 16 | #include "obexftpdialogbase.h" |
17 | #include <qstring.h> | 17 | #include <qstring.h> |
18 | #include <obexftp.h> | 18 | #include <obexftp.h> |
19 | #include <uuid.h> | 19 | #include <uuid.h> |
20 | #include <client.h> | 20 | #include <client.h> |
21 | #include <opie2/ofileselector.h> | 21 | #include <opie2/ofileselector.h> |
22 | #include <qlayout.h> | 22 | #include <qlayout.h> |
23 | namespace OpieTooth { | 23 | namespace OpieTooth { |
24 | class ObexFtpDialog : public ObexFtpDialogBase { | 24 | class ObexFtpDialog : public ObexFtpDialogBase { |
25 | Q_OBJECT | 25 | Q_OBJECT |
26 | public: | 26 | public: |
27 | ObexFtpDialog(const QString& device = 0, int port = 0, | 27 | ObexFtpDialog(const QString& device = 0, int port = 0, |
28 | QWidget* parent = 0, const char* name = 0, bool modal = TRUE, | 28 | QWidget* parent = 0, const char* name = 0, bool modal = TRUE, |
29 | WFlags fl = 0); | 29 | WFlags fl = 0); |
30 | ~ObexFtpDialog(); | 30 | ~ObexFtpDialog(); |
31 | void log(QString str); | 31 | void log(QString str); |
32 | void log(QCString str); | 32 | void log(QCString str); |
33 | void log(const char* str); | 33 | void log(const char* str); |
34 | void log(QString& str); | 34 | void log(QString& str); |
35 | void incProgress(); | 35 | void incProgress(); |
36 | void doneProgress(); | 36 | void doneProgress(); |
37 | protected: | 37 | protected: |
38 | int cli_connect_uuid(const uint8_t *uuid, int uuid_len); | 38 | int cli_connect_uuid(const uint8_t *uuid, int uuid_len, |
39 | bool reconnect = FALSE); | ||
39 | int errBox(QCString msg); //Error message box | 40 | int errBox(QCString msg); //Error message box |
40 | int errBox(QString msg); //Error message box | 41 | int errBox(QString msg); //Error message box |
41 | int errBox(const char* msg); //Error message box | 42 | int errBox(const char* msg); //Error message box |
42 | void status(QCString msg); //Text in the status bar | 43 | void status(QCString msg); //Text in the status bar |
43 | void status(QString msg); //Text in the status bar | 44 | void status(QString msg); //Text in the status bar |
44 | void status(const char* msg); //Text in the status bar | 45 | void status(const char* msg); //Text in the status bar |
46 | void doBrowse(bool reconnect = FALSE); //Browse device | ||
45 | protected: | 47 | protected: |
46 | QString m_device; //device MAC address | 48 | QString m_device; //device MAC address |
47 | int m_port; //port | 49 | int m_port; //port |
48 | int transport; //transport type | 50 | int transport; //transport type |
49 | bool use_conn; | 51 | bool use_conn; |
50 | bool use_path; | 52 | bool use_path; |
51 | obexftp_client_t* client; //Obex ftp client handler | 53 | obexftp_client_t* client; //Obex ftp client handler |
52 | QString curdir; //Current directory on device | 54 | QString curdir; //Current directory on device |
53 | QString localCurdir; //Local current directory | 55 | QString localCurdir; //Local current directory |
54 | QString file2get; //Remote file name | 56 | QString file2get; //Remote file name |
55 | QString local; //Local file name | 57 | QString local; //Local file name |
56 | int progressStatus; //Progress status | 58 | int progressStatus; //Progress status |
57 | Opie::Ui::OFileSelector* destFile; //Destination file or directory | 59 | Opie::Ui::OFileSelector* destFile; //Destination file or directory |
58 | QVBoxLayout* localLayout; //Window layout | 60 | QVBoxLayout* localLayout; //Window layout |
59 | int nRetries; //Number of retries (on connection) | 61 | int nRetries; //Number of retries (on connection) |
60 | private slots: | 62 | private slots: |
61 | void slotBrowse(); | 63 | void slotBrowse(); |
62 | void slotCd(QListViewItem* item); | 64 | void slotCd(QListViewItem* item); |
63 | void getFile(); | 65 | void getFile(); |
64 | void putFile(); | 66 | void putFile(); |
65 | void delFile(); | 67 | void delFile(); |
66 | void updateDir(const QString& newdir); | 68 | void updateDir(const QString& newdir); |
67 | void slotSaveLog(); | 69 | void slotSaveLog(); |
68 | void slotBrowseLog(); | 70 | void slotBrowseLog(); |
69 | }; | 71 | }; |
70 | }; | 72 | }; |
71 | #endif | 73 | #endif |