From 1b9cf76600297afde6fc708551cf98e1ce33670f Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Date: Tue, 24 Jul 2012 16:41:15 +0200
Subject: [PATCH] ProfileChooser: Introduce flags specifying which profiles to
 list.

Introduce flags to filter profiles that have a debugger
configured, restrict to host abi and include invalid profiles
(which is not relevant if only debugging is desired).
Introduce convenience flags for debugging.

Introduce populate() function for cleanliness.

Change-Id: I476c40cc9a59e4dd5b1bc7c49597e9169c053754
Reviewed-by: hjk <qthjk@ovi.com>
---
 src/plugins/analyzerbase/startremotedialog.cpp   |  2 +-
 src/plugins/debugger/debuggerdialogs.cpp         | 10 +++++-----
 src/plugins/debugger/loadremotecoredialog.cpp    |  2 +-
 src/plugins/projectexplorer/profilechooser.cpp   | 15 +++++++++++----
 src/plugins/projectexplorer/profilechooser.h     | 11 ++++++++++-
 src/plugins/remotelinux/startgdbserverdialog.cpp |  2 +-
 6 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/src/plugins/analyzerbase/startremotedialog.cpp b/src/plugins/analyzerbase/startremotedialog.cpp
index 7696314413d..5d1e3856c1e 100644
--- a/src/plugins/analyzerbase/startremotedialog.cpp
+++ b/src/plugins/analyzerbase/startremotedialog.cpp
@@ -69,7 +69,7 @@ StartRemoteDialog::StartRemoteDialog(QWidget *parent)
     setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
     setWindowTitle(tr("Start Remote Analysis"));
 
-    d->profileChooser = new ProfileChooser(this, true);
+    d->profileChooser = new ProfileChooser(this, ProfileChooser::RemoteDebugging);
     d->executable = new QLineEdit(this);
     d->arguments = new QLineEdit(this);
     d->workingDirectory = new QLineEdit(this);
diff --git a/src/plugins/debugger/debuggerdialogs.cpp b/src/plugins/debugger/debuggerdialogs.cpp
index 0ad5feddc91..ed5fe952e00 100644
--- a/src/plugins/debugger/debuggerdialogs.cpp
+++ b/src/plugins/debugger/debuggerdialogs.cpp
@@ -215,7 +215,7 @@ AttachCoreDialog::AttachCoreDialog(QWidget *parent)
     d->overrideStartScriptFileName->setExpectedKind(PathChooser::File);
     d->overrideStartScriptFileName->setPromptDialogTitle(tr("Select Startup Script"));
 
-    d->profileComboBox = new ProfileChooser(this, false);
+    d->profileComboBox = new ProfileChooser(this, ProfileChooser::RemoteDebugging);
 
     QFrame *line = new QFrame(this);
     line->setFrameShape(QFrame::HLine);
@@ -346,7 +346,7 @@ AttachExternalDialog::AttachExternalDialog(QWidget *parent)
     d->filterWidget = new FilterLineEdit(this);
     d->filterWidget->setFocus(Qt::TabFocusReason);
 
-    d->profileComboBox = new ProfileChooser(this, true);
+    d->profileComboBox = new ProfileChooser(this, ProfileChooser::LocalDebugging);
 
     d->procView = new QTreeView(this);
     d->procView->setAlternatingRowColors(true);
@@ -628,7 +628,7 @@ StartExternalDialog::StartExternalDialog(QWidget *parent)
 
     d->runInTerminalCheckBox = new QCheckBox(this);
 
-    d->profileChooser = new ProfileChooser(this, true);
+    d->profileChooser = new ProfileChooser(this, ProfileChooser::LocalDebugging);
 
     d->breakAtMainCheckBox = new QCheckBox(this);
     d->breakAtMainCheckBox->setText(QString());
@@ -939,7 +939,7 @@ StartRemoteDialog::StartRemoteDialog(QWidget *parent, bool enableStartScript)
     setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
     setWindowTitle(tr("Start Debugger"));
 
-    d->profileChooser = new ProfileChooser(this);
+    d->profileChooser = new ProfileChooser(this, ProfileChooser::RemoteDebugging);
 
     d->executablePathChooser = new PathChooser(this);
     d->executablePathChooser->setExpectedKind(PathChooser::File);
@@ -1149,7 +1149,7 @@ AttachToQmlPortDialog::AttachToQmlPortDialog(QWidget *parent)
     setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
     setWindowTitle(tr("Start Debugger"));
 
-    d->profileChooser = new ProfileChooser(this);
+    d->profileChooser = new ProfileChooser(this, ProfileChooser::RemoteDebugging);
 
     d->hostLineEdit = new QLineEdit(this);
     d->hostLineEdit->setText(QString::fromUtf8("localhost"));
diff --git a/src/plugins/debugger/loadremotecoredialog.cpp b/src/plugins/debugger/loadremotecoredialog.cpp
index 65d567690cb..f3fc5aafadc 100644
--- a/src/plugins/debugger/loadremotecoredialog.cpp
+++ b/src/plugins/debugger/loadremotecoredialog.cpp
@@ -114,7 +114,7 @@ LoadRemoteCoreFileDialog::LoadRemoteCoreFileDialog(QWidget *parent)
 
     d->deviceComboBox = new QComboBox(this);
 
-    d->profileChooser = new ProfileChooser(this);
+    d->profileChooser = new ProfileChooser(this, ProfileChooser::RemoteDebugging);
     d->fileSystemModel = new SftpFileSystemModel(this);
 
     //executablePathChooser = new PathChooser(q);
diff --git a/src/plugins/projectexplorer/profilechooser.cpp b/src/plugins/projectexplorer/profilechooser.cpp
index 15b0180a2e3..24b7f5057a3 100644
--- a/src/plugins/projectexplorer/profilechooser.cpp
+++ b/src/plugins/projectexplorer/profilechooser.cpp
@@ -43,21 +43,28 @@
 
 namespace ProjectExplorer {
 
-ProfileChooser::ProfileChooser(QWidget *parent, bool hostAbiOnly) :
+ProfileChooser::ProfileChooser(QWidget *parent, unsigned flags) :
     QComboBox(parent)
 {
+    populate(flags);
+}
+
+void ProfileChooser::populate(unsigned flags)
+{
+    clear();
     const Abi hostAbi = Abi::hostAbi();
     foreach (const Profile *profile, ProfileManager::instance()->profiles()) {
-        if (!profile->isValid())
+        if (!profile->isValid() && !(flags & IncludeInvalidProfiles))
             continue;
         ToolChain *tc = ToolChainProfileInformation::toolChain(profile);
         if (!tc)
             continue;
         const Abi abi = tc->targetAbi();
-        if (hostAbiOnly && hostAbi.os() != abi.os())
+        if ((flags & HostAbiOnly) && hostAbi.os() != abi.os())
             continue;
-
         const QString debuggerCommand = profile->value(Core::Id("Debugger.Information")).toString();
+        if ((flags & HasDebugger) && debuggerCommand.isEmpty())
+            continue;
         const QString completeBase = QFileInfo(debuggerCommand).completeBaseName();
         const QString name = tr("%1 (%2)").arg(profile->displayName(), completeBase);
         addItem(name, qVariantFromValue(profile->id()));
diff --git a/src/plugins/projectexplorer/profilechooser.h b/src/plugins/projectexplorer/profilechooser.h
index 79011ca04ee..2f9cf2dd498 100644
--- a/src/plugins/projectexplorer/profilechooser.h
+++ b/src/plugins/projectexplorer/profilechooser.h
@@ -47,7 +47,15 @@ class PROJECTEXPLORER_EXPORT ProfileChooser : public QComboBox
     Q_OBJECT
 
 public:
-    explicit ProfileChooser(QWidget *parent, bool hostAbiOnly = false);
+    enum Flags {
+        HostAbiOnly = 0x1,
+        IncludeInvalidProfiles = 0x2,
+        HasDebugger = 0x4,
+        RemoteDebugging = IncludeInvalidProfiles | HasDebugger,
+        LocalDebugging = RemoteDebugging | HostAbiOnly
+    };
+
+    explicit ProfileChooser(QWidget *parent, unsigned flags = 0);
 
     void setCurrentProfileId(Core::Id id);
     Core::Id currentProfileId() const;
@@ -55,6 +63,7 @@ public:
     Profile *currentProfile() const;
 
 private:
+    void populate(unsigned flags);
     Profile *profileAt(int index) const;
 };
 
diff --git a/src/plugins/remotelinux/startgdbserverdialog.cpp b/src/plugins/remotelinux/startgdbserverdialog.cpp
index 7f98f445ed0..196a9e3cf3b 100644
--- a/src/plugins/remotelinux/startgdbserverdialog.cpp
+++ b/src/plugins/remotelinux/startgdbserverdialog.cpp
@@ -119,7 +119,7 @@ StartGdbServerDialogPrivate::StartGdbServerDialogPrivate(StartGdbServerDialog *q
 
     deviceComboBox = new QComboBox(q);
 
-    profileChooser = new ProfileChooser(q);
+    profileChooser = new ProfileChooser(q, ProfileChooser::RemoteDebugging);
 //    sysrootPathChooser = new PathChooser(q);
 //    sysrootPathChooser->setExpectedKind(PathChooser::Directory);
 //    sysrootPathChooser->setPromptDialogTitle(StartGdbServerDialog::tr("Select Sysroot"));
-- 
GitLab