comparison src/multichoicedialog.cpp @ 483:a582c6417004

Some textual updates; include final URL path element in default for local file on clone
author Chris Cannam
date Wed, 17 Aug 2011 15:53:17 +0100
parents b9c153e00e84
children 9c8147c9f245
comparison
equal deleted inserted replaced
482:c6ea3eb00635 483:a582c6417004
169 MultiChoiceDialog::getDefaultPath() const 169 MultiChoiceDialog::getDefaultPath() const
170 { 170 {
171 QDir home(QDir::home()); 171 QDir home(QDir::home());
172 QDir dflt; 172 QDir dflt;
173 173
174 dflt = QDir(home.filePath(tr("Documents")));
175 DEBUG << "testing " << dflt << endl;
176 if (dflt.exists()) return dflt.canonicalPath();
177
174 dflt = QDir(home.filePath(tr("My Documents"))); 178 dflt = QDir(home.filePath(tr("My Documents")));
175 DEBUG << "testing " << dflt << endl; 179 DEBUG << "testing " << dflt << endl;
176 if (dflt.exists()) return dflt.canonicalPath(); 180 if (dflt.exists()) return dflt.canonicalPath();
177 181
178 dflt = QDir(home.filePath(tr("Documents"))); 182 dflt = QDir(home.filePath(tr("Desktop")));
179 DEBUG << "testing " << dflt << endl; 183 DEBUG << "testing " << dflt << endl;
180 if (dflt.exists()) return dflt.canonicalPath(); 184 if (dflt.exists()) return dflt.canonicalPath();
181 185
182 DEBUG << "all failed, returning " << home << endl; 186 DEBUG << "all failed, returning " << home << endl;
183 return home.canonicalPath(); 187 return home.canonicalPath();
216 220
217 void 221 void
218 MultiChoiceDialog::urlChanged(const QString &s) 222 MultiChoiceDialog::urlChanged(const QString &s)
219 { 223 {
220 updateOkButton(); 224 updateOkButton();
225 updateFileComboFromURL();
221 } 226 }
222 227
223 void 228 void
224 MultiChoiceDialog::fileChanged(const QString &s) 229 MultiChoiceDialog::fileChanged(const QString &s)
225 { 230 {
226 updateOkButton(); 231 updateOkButton();
227 } 232 }
228 233
229 void 234 void
230 MultiChoiceDialog::updateOkButton() 235 MultiChoiceDialog::updateFileComboFromURL()
231 { 236 {
232 /* This doesn't work well
233 if (m_argTypes[m_currentChoice] != UrlToDirectoryArg) { 237 if (m_argTypes[m_currentChoice] != UrlToDirectoryArg) {
234 return; 238 return;
235 }
236 QDir dirPath(m_fileCombo->currentText());
237 if (!dirPath.exists()) {
238 if (!dirPath.cdUp()) return;
239 } 239 }
240 QString url = m_urlCombo->currentText(); 240 QString url = m_urlCombo->currentText();
241 if (QRegExp("^\\w+://").indexIn(url) < 0) { 241 if (QRegExp("^\\w+://").indexIn(url) < 0) {
242 return; 242 return;
243 } 243 }
244 QString urlDirName = url; 244 QString urlDirName = url;
245 urlDirName.replace(QRegExp("^.*\\//.*\\/"), ""); 245 urlDirName.replace(QRegExp("^.*\\//.*\\/"), "");
246 if (urlDirName == "" || urlDirName == url) { 246 if (urlDirName == "" || urlDirName == url) {
247 return; 247 return;
248 } 248 }
249 m_fileCombo->lineEdit()->setText(dirPath.filePath(urlDirName)); 249 QString dirPath = m_fileCombo->currentText();
250 */ 250 QString defaultPath = getDefaultPath();
251 if (dirPath == defaultPath) {
252 dirPath += QDir::separator() + urlDirName;
253 } else if (dirPath == defaultPath + QDir::separator()) {
254 dirPath += urlDirName;
255 } else {
256 QDir d(dirPath);
257 d.cdUp();
258 dirPath = d.filePath(urlDirName);
259 }
260 m_fileCombo->lineEdit()->setText(dirPath);
261 }
262
263 void
264 MultiChoiceDialog::updateOkButton()
265 {
251 if (m_argTypes[m_currentChoice] == UrlToDirectoryArg) { 266 if (m_argTypes[m_currentChoice] == UrlToDirectoryArg) {
252 m_okButton->setEnabled(getArgument() != "" && 267 m_okButton->setEnabled(getArgument() != "" &&
253 getAdditionalArgument() != ""); 268 getAdditionalArgument() != "");
254 } else { 269 } else {
255 m_okButton->setEnabled(getArgument() != ""); 270 m_okButton->setEnabled(getArgument() != "");
287 } 302 }
288 } 303 }
289 304
290 m_descriptionLabel->setText(m_descriptions[id]); 305 m_descriptionLabel->setText(m_descriptions[id]);
291 306
307 m_browseButton->hide();
308
309 m_urlLabel->hide();
310 m_urlCombo->clear();
311 m_urlCombo->hide();
312
292 m_fileLabel->hide(); 313 m_fileLabel->hide();
314 m_fileCombo->clear();
293 m_fileCombo->hide(); 315 m_fileCombo->hide();
294 m_browseButton->hide();
295 m_urlLabel->hide();
296 m_urlCombo->hide();
297 316
298 QSharedPointer<RecentFiles> rf = m_recentFiles[id]; 317 QSharedPointer<RecentFiles> rf = m_recentFiles[id];
299 m_fileCombo->clear();
300 m_urlCombo->clear();
301 318
302 switch (m_argTypes[id]) { 319 switch (m_argTypes[id]) {
303 320
304 case NoArg: 321 case NoArg:
305 break; 322 break;
332 m_urlCombo->addItems(rf->getRecent()); 349 m_urlCombo->addItems(rf->getRecent());
333 m_fileLabel->setText(tr("&Folder:")); 350 m_fileLabel->setText(tr("&Folder:"));
334 m_fileLabel->show(); 351 m_fileLabel->show();
335 m_fileCombo->show(); 352 m_fileCombo->show();
336 m_fileCombo->lineEdit()->setText(getDefaultPath()); 353 m_fileCombo->lineEdit()->setText(getDefaultPath());
354 updateFileComboFromURL();
337 m_browseButton->show(); 355 m_browseButton->show();
338 break; 356 break;
339 } 357 }
340 358
341 updateOkButton(); 359 updateOkButton();