diff 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
line wrap: on
line diff
--- a/src/multichoicedialog.cpp	Tue Aug 16 17:13:35 2011 +0100
+++ b/src/multichoicedialog.cpp	Wed Aug 17 15:53:17 2011 +0100
@@ -171,11 +171,15 @@
     QDir home(QDir::home());
     QDir dflt;
 
+    dflt = QDir(home.filePath(tr("Documents")));
+    DEBUG << "testing " << dflt << endl;
+    if (dflt.exists()) return dflt.canonicalPath();
+
     dflt = QDir(home.filePath(tr("My Documents")));
     DEBUG << "testing " << dflt << endl;
     if (dflt.exists()) return dflt.canonicalPath();
 
-    dflt = QDir(home.filePath(tr("Documents")));
+    dflt = QDir(home.filePath(tr("Desktop")));
     DEBUG << "testing " << dflt << endl;
     if (dflt.exists()) return dflt.canonicalPath();
 
@@ -218,6 +222,7 @@
 MultiChoiceDialog::urlChanged(const QString &s)
 {
     updateOkButton();
+    updateFileComboFromURL();
 }
 
 void
@@ -227,16 +232,11 @@
 }
 
 void
-MultiChoiceDialog::updateOkButton()
+MultiChoiceDialog::updateFileComboFromURL()
 {
-/* This doesn't work well
     if (m_argTypes[m_currentChoice] != UrlToDirectoryArg) {
         return;
     }
-    QDir dirPath(m_fileCombo->currentText());
-    if (!dirPath.exists()) {
-        if (!dirPath.cdUp()) return;
-    }
     QString url = m_urlCombo->currentText();
     if (QRegExp("^\\w+://").indexIn(url) < 0) {
         return;
@@ -246,8 +246,23 @@
     if (urlDirName == "" || urlDirName == url) {
         return;
     }
-    m_fileCombo->lineEdit()->setText(dirPath.filePath(urlDirName));
-*/
+    QString dirPath = m_fileCombo->currentText();
+    QString defaultPath = getDefaultPath();
+    if (dirPath == defaultPath) {
+        dirPath += QDir::separator() + urlDirName;
+    } else if (dirPath == defaultPath + QDir::separator()) {
+        dirPath += urlDirName;
+    } else {
+        QDir d(dirPath);
+        d.cdUp();
+        dirPath = d.filePath(urlDirName);
+    }
+    m_fileCombo->lineEdit()->setText(dirPath);
+}
+
+void
+MultiChoiceDialog::updateOkButton()
+{
     if (m_argTypes[m_currentChoice] == UrlToDirectoryArg) {
         m_okButton->setEnabled(getArgument() != "" &&
                                getAdditionalArgument() != "");
@@ -289,15 +304,17 @@
 
     m_descriptionLabel->setText(m_descriptions[id]);
 
-    m_fileLabel->hide();
-    m_fileCombo->hide();
     m_browseButton->hide();
+
     m_urlLabel->hide();
+    m_urlCombo->clear();
     m_urlCombo->hide();
 
+    m_fileLabel->hide();
+    m_fileCombo->clear();
+    m_fileCombo->hide();
+
     QSharedPointer<RecentFiles> rf = m_recentFiles[id];
-    m_fileCombo->clear();
-    m_urlCombo->clear();
 
     switch (m_argTypes[id]) {
         
@@ -334,6 +351,7 @@
         m_fileLabel->show();
         m_fileCombo->show();
         m_fileCombo->lineEdit()->setText(getDefaultPath());
+        updateFileComboFromURL();
         m_browseButton->show();
         break;
     }