From cb7bb2eefe664ffd7e8c4da76fb14599428b9497 Mon Sep 17 00:00:00 2001
From: goro <qtc-committer@nokia.com>
Date: Fri, 19 Dec 2008 15:32:21 +0100
Subject: [PATCH] PathChooser migration for Qt version config page

---
 src/libs/utils/pathchooser.cpp                |  6 +-
 src/libs/utils/pathchooser.h                  |  1 +
 .../qt4projectmanager/qtversionmanager.cpp    | 80 +++++++++----------
 .../qt4projectmanager/qtversionmanager.h      |  5 +-
 .../qt4projectmanager/qtversionmanager.ui     | 58 ++++----------
 5 files changed, 61 insertions(+), 89 deletions(-)

diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp
index d3743509709..26fa60294ec 100644
--- a/src/libs/utils/pathchooser.cpp
+++ b/src/libs/utils/pathchooser.cpp
@@ -167,13 +167,15 @@ void PathChooser::slotBrowse()
         ;
     }
 
-    // TODO make cross-platform
-    // Delete trailing slashes unless it is "/", only
+    // Delete trailing slashes unless it is "/"|"\\", only
     if (!newPath.isEmpty()) {
+        newPath = QDir::toNativeSeparators(newPath);
         if (newPath.size() > 1 && newPath.endsWith(QDir::separator()))
             newPath.truncate(newPath.size() - 1);
         setPath(newPath);
     }
+
+    emit browsingFinished();
 }
 
 bool PathChooser::isValid() const
diff --git a/src/libs/utils/pathchooser.h b/src/libs/utils/pathchooser.h
index b3898465531..f22c20120b7 100644
--- a/src/libs/utils/pathchooser.h
+++ b/src/libs/utils/pathchooser.h
@@ -91,6 +91,7 @@ private:
 signals:
     void validChanged();
     void changed();
+    void browsingFinished();
     void returnPressed();
 
 public slots:
diff --git a/src/plugins/qt4projectmanager/qtversionmanager.cpp b/src/plugins/qt4projectmanager/qtversionmanager.cpp
index f1b9b956021..e39240118d1 100644
--- a/src/plugins/qt4projectmanager/qtversionmanager.cpp
+++ b/src/plugins/qt4projectmanager/qtversionmanager.cpp
@@ -368,6 +368,10 @@ QtDirWidget::QtDirWidget(QWidget *parent, QList<QtVersion *> versions, int defau
     , m_specifyPathString(tr("<specify a path>"))
 {
     m_ui.setupUi(this);
+    m_ui.qtPath->setExpectedKind(Core::Utils::PathChooser::Directory);
+    m_ui.qtPath->setPromptDialogTitle(tr("Select QTDIR"));
+    m_ui.mingwPath->setExpectedKind(Core::Utils::PathChooser::Directory);
+    m_ui.qtPath->setPromptDialogTitle(tr("Select MinGW Directory"));
 
     m_ui.addButton->setIcon(QIcon(Core::Constants::ICON_PLUS));
     m_ui.delButton->setIcon(QIcon(Core::Constants::ICON_MINUS));
@@ -385,19 +389,22 @@ QtDirWidget::QtDirWidget(QWidget *parent, QList<QtVersion *> versions, int defau
 
     connect(m_ui.nameEdit, SIGNAL(textEdited(const QString &)),
             this, SLOT(updateCurrentQtName()));
-    connect(m_ui.pathEdit, SIGNAL(textEdited(const QString &)),
+
+
+    connect(m_ui.qtPath, SIGNAL(changed()),
             this, SLOT(updateCurrentQtPath()));
-    connect(m_ui.mingwLineEdit, SIGNAL(textEdited(const QString &)),
+    connect(m_ui.mingwPath, SIGNAL(changed()),
             this, SLOT(updateCurrentMingwDirectory()));
 
     connect(m_ui.addButton, SIGNAL(clicked()),
             this, SLOT(addQtDir()));
     connect(m_ui.delButton, SIGNAL(clicked()),
             this, SLOT(removeQtDir()));
-    connect(m_ui.browseButton, SIGNAL(clicked()),
-            this, SLOT(browse()));
-    connect(m_ui.mingwBrowseButton, SIGNAL(clicked()),
-            this, SLOT(mingwBrowse()));
+
+    connect(m_ui.qtPath, SIGNAL(browsingFinished()),
+            this, SLOT(onQtBrowsed()));
+    connect(m_ui.mingwPath, SIGNAL(browsingFinished()),
+            this, SLOT(onMingwBrowsed()));
 
     connect(m_ui.qtdirList, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
             this, SLOT(versionChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
@@ -421,11 +428,11 @@ void QtDirWidget::addQtDir()
     item->setText(1, newVersion->path());
     item->setData(0, Qt::UserRole, newVersion->uniqueId());
 
-    m_ui.nameEdit->setText(newVersion->name());
-    m_ui.pathEdit->setText(newVersion->path());
+    m_ui.qtdirList->setCurrentItem(item);
 
+    m_ui.nameEdit->setText(newVersion->name());
+    m_ui.qtPath->setPath(newVersion->path());
     m_ui.defaultCombo->addItem(newVersion->name());
-    m_ui.qtdirList->setCurrentItem(item);
     m_ui.nameEdit->setFocus();
     m_ui.nameEdit->selectAll();
 }
@@ -459,10 +466,14 @@ void QtDirWidget::updateState()
         && m_versions.at(m_ui.qtdirList->indexOfTopLevelItem(m_ui.qtdirList->currentItem()))->isSystemVersion());
     m_ui.delButton->setEnabled(enabled && !isSystemVersion);
     m_ui.nameEdit->setEnabled(enabled && !isSystemVersion);
-    m_ui.pathEdit->setEnabled(enabled && !isSystemVersion);
-    m_ui.browseButton->setEnabled(enabled && !isSystemVersion);
-    m_ui.mingwBrowseButton->setEnabled(enabled);
-    m_ui.mingwLineEdit->setEnabled(enabled);
+    m_ui.qtPath->setEnabled(enabled && !isSystemVersion);
+    m_ui.mingwPath->setEnabled(enabled);
+}
+
+void QtDirWidget::makeMingwVisible(bool visible)
+{
+    m_ui.mingwLabel->setVisible(visible);
+    m_ui.mingwPath->setVisible(visible);
 }
 
 void QtDirWidget::showEnvironmentPage(QTreeWidgetItem *item)
@@ -475,16 +486,12 @@ void QtDirWidget::showEnvironmentPage(QTreeWidgetItem *item)
         if (t == QtVersion::MinGW) {
             m_ui.msvcComboBox->setVisible(false);
             m_ui.msvcLabel->setVisible(false);
-            m_ui.mingwLineEdit->setVisible(true);
-            m_ui.mingwLabel->setVisible(true);
-            m_ui.mingwBrowseButton->setVisible(true);
-            m_ui.mingwLineEdit->setText(m_versions.at(index)->mingwDirectory());
+            makeMingwVisible(true);
+            m_ui.mingwPath->setPath(m_versions.at(index)->mingwDirectory());
         } else if (t == QtVersion::MSVC || t == QtVersion::WINCE){
             m_ui.msvcComboBox->setVisible(false);
             m_ui.msvcLabel->setVisible(true);
-            m_ui.mingwLineEdit->setVisible(false);
-            m_ui.mingwLabel->setVisible(false);
-            m_ui.mingwBrowseButton->setVisible(false);
+            makeMingwVisible(false);
             QList<MSVCEnvironment> msvcenvironments = MSVCEnvironment::availableVersions();
             if (msvcenvironments.count() == 0) {
                 m_ui.msvcLabel->setText(tr("No Visual Studio Installation found"));
@@ -506,9 +513,7 @@ void QtDirWidget::showEnvironmentPage(QTreeWidgetItem *item)
         } else if (t == QtVersion::INVALID) {
             m_ui.msvcComboBox->setVisible(false);
             m_ui.msvcLabel->setVisible(false);
-            m_ui.mingwLineEdit->setVisible(false);
-            m_ui.mingwLabel->setVisible(false);
-            m_ui.mingwBrowseButton->setVisible(false);
+            makeMingwVisible(false);
             if (!m_versions.at(index)->isInstalled())
                 m_ui.errorLabel->setText(tr("The Qt Version is not installed. Run make install")
                                            .arg(m_versions.at(index)->path()));
@@ -517,9 +522,7 @@ void QtDirWidget::showEnvironmentPage(QTreeWidgetItem *item)
         } else { //QtVersion::Other
             m_ui.msvcComboBox->setVisible(false);
             m_ui.msvcLabel->setVisible(false);
-            m_ui.mingwLineEdit->setVisible(false);
-            m_ui.mingwLabel->setVisible(false);
-            m_ui.mingwBrowseButton->setVisible(false);
+            makeMingwVisible(false);
             m_ui.errorLabel->setText("Found Qt version "
                                      + m_versions.at(index)->qtVersionString()
                                      + " using mkspec "
@@ -528,9 +531,7 @@ void QtDirWidget::showEnvironmentPage(QTreeWidgetItem *item)
     } else {
         m_ui.msvcComboBox->setVisible(false);
         m_ui.msvcLabel->setVisible(false);
-        m_ui.mingwLineEdit->setVisible(false);
-        m_ui.mingwLabel->setVisible(false);
-        m_ui.mingwBrowseButton->setVisible(false);
+        makeMingwVisible(false);
     }
 }
 
@@ -541,24 +542,21 @@ void QtDirWidget::versionChanged(QTreeWidgetItem *item, QTreeWidgetItem *old)
     }
     if (item) {
         m_ui.nameEdit->setText(item->text(0));
-        m_ui.pathEdit->setText(item->text(1));
+        m_ui.qtPath->setPath(item->text(1));
     } else {
         m_ui.nameEdit->clear();
-        m_ui.pathEdit->clear();
+        m_ui.qtPath->setPath(""); // clear()
     }
     showEnvironmentPage(item);
     updateState();
 }
 
-void QtDirWidget::browse()
+void QtDirWidget::onQtBrowsed()
 {
-    QString dir = QFileDialog::getExistingDirectory(this, tr("Select QTDIR"));
-
+    const QString dir = m_ui.qtPath->path();
     if (dir.isEmpty())
         return;
 
-    dir = QDir::toNativeSeparators(dir);
-    m_ui.pathEdit->setText(dir);
     updateCurrentQtPath();
     if (m_ui.nameEdit->text().isEmpty() || m_ui.nameEdit->text() == m_specifyNameString) {
         QStringList dirSegments = dir.split(QDir::separator(), QString::SkipEmptyParts);
@@ -569,14 +567,12 @@ void QtDirWidget::browse()
     updateState();
 }
 
-void QtDirWidget::mingwBrowse()
+void QtDirWidget::onMingwBrowsed()
 {
-    QString dir = QFileDialog::getExistingDirectory(this, tr("Select MinGW Directory"));
+    const QString dir = m_ui.mingwPath->path();
     if (dir.isEmpty())
         return;
 
-    dir = QDir::toNativeSeparators(dir);
-    m_ui.mingwLineEdit->setText(dir);
     updateCurrentMingwDirectory();
     updateState();
 }
@@ -647,7 +643,7 @@ void QtDirWidget::updateCurrentQtPath()
     QTreeWidgetItem *currentItem = m_ui.qtdirList->currentItem();
     Q_ASSERT(currentItem);
     int currentItemIndex = m_ui.qtdirList->indexOfTopLevelItem(currentItem);
-    m_versions[currentItemIndex]->setPath(m_ui.pathEdit->text());
+    m_versions[currentItemIndex]->setPath(m_ui.qtPath->path());
     currentItem->setText(1, m_versions[currentItemIndex]->path());
 
     showEnvironmentPage(currentItem);
@@ -658,7 +654,7 @@ void QtDirWidget::updateCurrentMingwDirectory()
     QTreeWidgetItem *currentItem = m_ui.qtdirList->currentItem();
     Q_ASSERT(currentItem);
     int currentItemIndex = m_ui.qtdirList->indexOfTopLevelItem(currentItem);
-    m_versions[currentItemIndex]->setMingwDirectory(m_ui.mingwLineEdit->text());
+    m_versions[currentItemIndex]->setMingwDirectory(m_ui.mingwPath->path());
 }
 
 void QtDirWidget::msvcVersionChanged()
diff --git a/src/plugins/qt4projectmanager/qtversionmanager.h b/src/plugins/qt4projectmanager/qtversionmanager.h
index 164e40c6d8e..a76a62ada04 100644
--- a/src/plugins/qt4projectmanager/qtversionmanager.h
+++ b/src/plugins/qt4projectmanager/qtversionmanager.h
@@ -149,8 +149,9 @@ private slots:
     void addQtDir();
     void removeQtDir();
     void updateState();
-    void browse();
-    void mingwBrowse();
+    void makeMingwVisible(bool visible);
+    void onQtBrowsed();
+    void onMingwBrowsed();
     void defaultChanged(int index);
     void updateCurrentQtName();
     void updateCurrentQtPath();
diff --git a/src/plugins/qt4projectmanager/qtversionmanager.ui b/src/plugins/qt4projectmanager/qtversionmanager.ui
index de93505cb09..0d3941d0388 100644
--- a/src/plugins/qt4projectmanager/qtversionmanager.ui
+++ b/src/plugins/qt4projectmanager/qtversionmanager.ui
@@ -109,16 +109,6 @@
         </property>
        </widget>
       </item>
-      <item row="2" column="1">
-       <widget class="QLineEdit" name="pathEdit"/>
-      </item>
-      <item row="2" column="2">
-       <widget class="QToolButton" name="browseButton">
-        <property name="text">
-         <string>...</string>
-        </property>
-       </widget>
-      </item>
       <item row="3" column="0">
        <widget class="QLabel" name="mingwLabel">
         <property name="text">
@@ -126,16 +116,6 @@
         </property>
        </widget>
       </item>
-      <item row="3" column="1">
-       <widget class="QLineEdit" name="mingwLineEdit"/>
-      </item>
-      <item row="3" column="2">
-       <widget class="QToolButton" name="mingwBrowseButton">
-        <property name="text">
-         <string>...</string>
-        </property>
-       </widget>
-      </item>
       <item row="4" column="0" colspan="3">
        <widget class="QLabel" name="msvcLabel">
         <property name="text">
@@ -153,6 +133,12 @@
       <item row="5" column="1" colspan="2">
        <widget class="QComboBox" name="msvcComboBox"/>
       </item>
+      <item row="2" column="1" colspan="2">
+       <widget class="Core::Utils::PathChooser" name="qtPath" native="true"/>
+      </item>
+      <item row="3" column="1" colspan="2">
+       <widget class="Core::Utils::PathChooser" name="mingwPath" native="true"/>
+      </item>
      </layout>
     </widget>
    </item>
@@ -179,34 +165,20 @@
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>Core::Utils::PathChooser</class>
+   <extends>QWidget</extends>
+   <header location="global">utils/pathchooser.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
  <tabstops>
   <tabstop>qtdirList</tabstop>
   <tabstop>delButton</tabstop>
   <tabstop>nameEdit</tabstop>
-  <tabstop>pathEdit</tabstop>
   <tabstop>defaultCombo</tabstop>
-  <tabstop>browseButton</tabstop>
  </tabstops>
- <resources>
-  <include location="../../libs/cplusplus/cplusplus.qrc"/>
-  <include location="../../libs/extensionsystem/pluginview.qrc"/>
-  <include location="../bookmarks/bookmarks.qrc"/>
-  <include location="../coreplugin/core.qrc"/>
-  <include location="../coreplugin/fancyactionbar.qrc"/>
-  <include location="../cppeditor/cppeditor.qrc"/>
-  <include location="../cpptools/cpptools.qrc"/>
-  <include location="../designer/designer.qrc"/>
-  <include location="../find/find.qrc"/>
-  <include location="../gdbdebugger/gdbdebugger.qrc"/>
-  <include location="../help/help.qrc"/>
-  <include location="../perforce/perforce.qrc"/>
-  <include location="../projectexplorer/projectexplorer.qrc"/>
-  <include location="../../../shared/proparser/proparser.qrc"/>
-  <include location="qt4projectmanager.qrc"/>
-  <include location="wizards/wizards.qrc"/>
-  <include location="../quickopen/quickopen.qrc"/>
-  <include location="../resourceeditor/resourceeditor.qrc"/>
-  <include location="../texteditor/texteditor.qrc"/>
- </resources>
+ <resources/>
  <connections/>
 </ui>
-- 
GitLab