Commit 99fb2916 authored by Daniel Molkentin's avatar Daniel Molkentin

welcome screen: populate example combobox

When an example is selected, help and the project are opened
in a split view. We try to read the xml file provided for
QtDemo to extract details about the examples provided. Will
try all available Qts, starting with the default version. Will
fail gracefully (provide a message and disable controls) if
examples or demos cannot be found. Will work if help is not
found, but show an error.
parent 82153bf5
......@@ -126,7 +126,7 @@ WelcomeMode::WelcomeMode() :
m_d->ui.projTitleLabel->setText(titleLabel(tr("Projects")));
m_d->ui.recentSessionsTitleLabel->setText(titleLabel(tr("Sessions")));
m_d->ui.tutorialsTitleLabel->setText(titleLabel(tr("Tutorials")));
m_d->ui.demoTitleLabel->setText(titleLabel(tr("Qt Demos and Examples")));
m_d->ui.demoTitleLabel->setText(titleLabel(tr("Explore Qt Examples")));
m_d->ui.didYouKnowTitleLabel->setText(titleLabel(tr("Did you know?")));
m_d->ui.labsTitleLabel->setText(titleLabel(tr("News from the Qt Labs")));
m_d->ui.sitesTitleLabel->setText(titleLabel(tr("Qt Websites")));
......@@ -155,6 +155,11 @@ WelcomeMode::WelcomeMode() :
connect(m_d->ui.newsTreeWidget, SIGNAL(activated(QString)), SLOT(slotUrlClicked(QString)));
connect(m_d->ui.sitesTreeWidget, SIGNAL(activated(QString)), SLOT(slotUrlClicked(QString)));
connect(m_d->ui.tutorialTreeWidget, SIGNAL(activated(QString)), SIGNAL(openHelpPage(const QString&)));
connect(m_d->ui.openExampleButton, SIGNAL(clicked()), SLOT(slotOpenExample()));
connect(m_d->ui.examplesComboBox, SIGNAL(currentIndexChanged(int)), SLOT(slotEnableExampleButton(int)));
connect(this, SIGNAL(updatedExamples(QString, QString, QString)),
this, SLOT(slotUpdateExamples(QString, QString, QString)));
connect(m_d->rssFetcher, SIGNAL(newsItemReady(QString, QString, QString)),
m_d->ui.newsTreeWidget, SLOT(slotAddNewsItem(QString, QString, QString)));
......@@ -170,10 +175,10 @@ WelcomeMode::WelcomeMode() :
m_d->ui.tutorialTreeWidget->addItem(tr("<b>Qt Creator - A quick tour</b>"),
QString("qthelp://com.nokia.qtcreator.%1%2/doc/index.html").arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR));
m_d->ui.tutorialTreeWidget->addItem(tr("Understanding widgets"),
QLatin1String("qthelp://com.trolltech.qt/qdoc/widgets-tutorial.html"));
m_d->ui.tutorialTreeWidget->addItem(tr("Creating an address book"),
QLatin1String("qthelp://com.trolltech.qt/qdoc/tutorials-addressbook.html"));
m_d->ui.tutorialTreeWidget->addItem(tr("Understanding widgets"),
QLatin1String("qthelp://com.trolltech.qt/qdoc/widgets-tutorial.html"));
m_d->ui.tutorialTreeWidget->addItem(tr("Building with qmake"),
QLatin1String("qthelp://com.trolltech.qmake/qdoc/qmake-tutorial.html"));
m_d->ui.tutorialTreeWidget->addItem(tr("Writing test cases"),
......@@ -302,6 +307,84 @@ void WelcomeMode::slotUrlClicked(const QString &data)
QDesktopServices::openUrl(QUrl(data));
}
void WelcomeMode::slotUpdateExamples(const QString& examplePath, const QString& demosPath, const QString& docPath)
{
QString demoxml = demosPath + "/qtdemo/xml/examples.xml";
if (!QFile::exists(demoxml))
return;
QFile description(demoxml);
if (!description.open(QFile::ReadOnly))
return;
m_d->ui.examplesComboBox->clear();
m_d->ui.examplesComboBox->setEnabled(true);
m_d->ui.examplesComboBox->addItem(tr("Choose an example..."));
QFont f = widget()->font();
f.setItalic(true);
m_d->ui.examplesComboBox->setItemData(0, f, Qt::FontRole);
f.setItalic(false);
bool inExamples = false;
QString dirName;
QXmlStreamReader reader(&description);
while (!reader.atEnd()) {
switch (reader.readNext()) {
case QXmlStreamReader::StartElement:
if (reader.name() == "category") {
QString name = reader.attributes().value(QLatin1String("name")).toString();
if (name.contains("tutorial"))
break;
dirName = reader.attributes().value(QLatin1String("dirname")).toString();
m_d->ui.examplesComboBox->addItem(name);
f.setBold(true);
m_d->ui.examplesComboBox->setItemData(m_d->ui.examplesComboBox->count()-1, f, Qt::FontRole);
f.setBold(false);
inExamples = true;
}
if (inExamples && reader.name() == "example") {
QString name = reader.attributes().value(QLatin1String("name")).toString();
QString fn = reader.attributes().value(QLatin1String("filename")).toString();
QString fileName = examplePath + '/' + dirName + '/' + fn + '/' + fn + ".pro";
QString helpPath = "qthelp://com.trolltech.qt/qdoc/" + dirName.replace("/", "-") + "-" + fn + ".html";
m_d->ui.examplesComboBox->addItem(" " + name, fileName);
m_d->ui.examplesComboBox->setItemData(m_d->ui.examplesComboBox->count()-1, helpPath, Qt::UserRole+1);
}
break;
case QXmlStreamReader::EndElement:
if (reader.name() == "category")
inExamples = false;
break;
default:
break;
}
}
}
void WelcomeMode::slotEnableExampleButton(int index)
{
QString fileName = m_d->ui.examplesComboBox->itemData(index, Qt::UserRole).toString();
m_d->ui.openExampleButton->setEnabled(!fileName.isEmpty());
}
void WelcomeMode::slotOpenExample()
{
QComboBox *box = m_d->ui.examplesComboBox;
QString proFile = box->itemData(box->currentIndex(), Qt::UserRole).toString();
QString helpFile = box->itemData(box->currentIndex(), Qt::UserRole + 1).toString();
QStringList files;
QFileInfo fi(proFile);
QString tryFile = fi.path() + "/main.cpp";
files << proFile;
if(!QFile::exists(tryFile))
tryFile = fi.path() + '/' + fi.baseName() + ".cpp";
if(QFile::exists(tryFile))
files << tryFile;
Core::ICore::instance()->openFiles(files);
emit openContextHelpPage(helpFile);
}
void WelcomeMode::slotFeedback()
{
QDesktopServices::openUrl(QUrl(QLatin1String(
......
......@@ -78,14 +78,19 @@ public:
signals:
void requestProject(const QString &project);
void requestSession(const QString &session);
void openHelpPage(const QString&);
void openHelpPage(const QString& url);
void openContextHelpPage(const QString& url);
void manageSessions();
void updatedExamples(const QString& examplePath, const QString& demosPath, const QString& docPath);
private slots:
void slotFeedback();
void slotSessionClicked(const QString &data);
void slotProjectClicked(const QString &data);
void slotUrlClicked(const QString &data);
void slotUpdateExamples(const QString& examplePath, const QString& demosPath, const QString& docPath);
void slotEnableExampleButton(int);
void slotOpenExample();
void slotCreateNewProject();
void slotNextTip();
void slotPrevTip();
......
......@@ -438,7 +438,7 @@ QToolButton:checked {
</widget>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="comboBox">
<widget class="QComboBox" name="examplesComboBox">
<property name="enabled">
<bool>false</bool>
</property>
......@@ -448,10 +448,15 @@ QToolButton:checked {
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Examples not installed</string>
</property>
</item>
</widget>
</item>
<item row="1" column="1">
<widget class="QToolButton" name="toolButton">
<widget class="QToolButton" name="openExampleButton">
<property name="enabled">
<bool>false</bool>
</property>
......
......@@ -526,6 +526,7 @@ void HelpPlugin::extensionsInitialized()
if (Core::Internal::WelcomeMode *welcomeMode = qobject_cast<Core::Internal::WelcomeMode*>(m_core->modeManager()->mode(Core::Constants::MODE_WELCOME))) {
connect(welcomeMode, SIGNAL(openHelpPage(const QString&)), this, SLOT(openHelpPage(const QString&)));
connect(welcomeMode, SIGNAL(openContextHelpPage(const QString&)), this, SLOT(openContextHelpPage(QString)));
}
}
......@@ -557,6 +558,12 @@ void HelpPlugin::modeChanged(Core::IMode *mode)
}
}
void HelpPlugin::openContextHelpPage(const QString &url)
{
Core::RightPaneWidget::instance()->setShown(true);
m_helpViewerForSideBar->setSource(QUrl(url));
}
void HelpPlugin::activateContext()
{
using namespace Core;
......
......@@ -130,6 +130,7 @@ private slots:
void openHelpPage(const QUrl& url);
void openHelpPage(const QString& url);
void openContextHelpPage(const QString &url);
private:
QToolBar *createToolBar();
......
......@@ -35,7 +35,10 @@
#include <projectexplorer/debugginghelper.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/cesdkhandler.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/welcomemode.h>
#include <extensionsystem/pluginmanager.h>
#include <help/helpplugin.h>
#include <utils/qtcassert.h>
......@@ -98,7 +101,15 @@ QtVersionManager::QtVersionManager()
updateSystemVersion();
writeVersionsIntoSettings();
if (Core::Internal::WelcomeMode *welcomeMode = qobject_cast<Core::Internal::WelcomeMode*>
(Core::ICore::instance()->modeManager()->mode(Core::Constants::MODE_WELCOME))) {
connect(this, SIGNAL(updatedExamples(QString,QString,QString)),
welcomeMode, SIGNAL(updatedExamples(QString,QString, QString)));
}
else
updateDocumentation();
updateExamples();
}
QtVersionManager::~QtVersionManager()
......@@ -129,13 +140,38 @@ void QtVersionManager::updateDocumentation()
QStringList fileEndings = QStringList() << "/qch/qt.qch" << "/qch/qmake.qch" << "/qch/designer.qch";
QStringList files;
foreach (QtVersion *version, m_versions) {
QString docPath = version->versionInfo().value("QT_INSTALL_DOCS");
QString docPath = version->documentationPath();
foreach (const QString &fileEnding, fileEndings)
files << docPath+fileEnding;
}
helpManager->registerDocumentation(files);
}
void QtVersionManager::updateExamples()
{
QList<QtVersion *> versions;
versions.append(currentQtVersion());
versions.append(m_versions);
QString examplesPath;
QString docPath;
QString demosPath;
QtVersion *version = 0;
// try to find a version which has both, examples and docs, starting with default Qt
foreach (version, versions) {
if (version->hasExamples())
examplesPath = version->examplesPath();
if (version->hasDemos())
demosPath = version->demosPath();
if (version->hasDocumentation())
docPath = version->documentationPath();
if (!examplesPath.isEmpty() && !demosPath.isEmpty() && !docPath.isEmpty()) {
emit updatedExamples(examplesPath, demosPath, docPath);
return;
}
}
}
int QtVersionManager::getUniqueId()
{
return m_idcount++;
......@@ -302,8 +338,10 @@ void QtVersionManager::setNewQtVersions(QList<QtVersion *> newVersions, int newD
}
emit qtVersionsChanged();
if (emitDefaultChanged)
if (emitDefaultChanged) {
emit defaultQtVersionChanged();
updateExamples();
}
writeVersionsIntoSettings();
}
......@@ -321,6 +359,9 @@ QtVersion::QtVersion(const QString &name, const QString &path, int id, bool isSy
m_notInstalled(false),
m_defaultConfigIsDebug(true),
m_defaultConfigIsDebugAndRelease(true),
m_hasExamples(false),
m_hasDemos(false),
m_hasDocumentation(false),
m_toolChain(0)
{
if (id == -1)
......@@ -600,6 +641,8 @@ void QtVersion::updateVersionInfo() const
// extract data from qmake executable
m_versionInfo.clear();
m_notInstalled = false;
m_hasExamples = false;
m_hasDocumentation = false;
QFileInfo qmake(qmakeCommand());
if (qmake.exists()) {
static const char * const variables[] = {
......@@ -645,6 +688,21 @@ void QtVersion::updateVersionInfo() const
if (!fi.exists())
m_notInstalled = true;
}
if (m_versionInfo.contains("QT_INSTALL_DOCS")){
QFileInfo fi(m_versionInfo.value("QT_INSTALL_DOCS"));
if (fi.exists())
m_hasDocumentation = true;
}
if (m_versionInfo.contains("QT_INSTALL_EXAMPLES")){
QFileInfo fi(m_versionInfo.value("QT_INSTALL_EXAMPLES"));
if (fi.exists())
m_hasExamples = true;
}
if (m_versionInfo.contains("QT_INSTALL_DEMOS")){
QFileInfo fi(m_versionInfo.value("QT_INSTALL_DEMOS"));
if (fi.exists())
m_hasDemos = true;
}
// Parse qconfigpri
QString baseDir = m_versionInfo.contains("QT_INSTALL_DATA") ?
......@@ -1010,6 +1068,41 @@ QString QtVersion::debuggingHelperLibrary() const
return DebuggingHelperLibrary::debuggingHelperLibrary(qtInstallData, path());
}
bool QtVersion::hasDocumentation() const
{
updateVersionInfo();
return m_hasDocumentation;
}
QString QtVersion::documentationPath() const
{
updateVersionInfo();
return m_versionInfo["QT_INSTALL_DOCS"];
}
bool QtVersion::hasDemos() const
{
updateVersionInfo();
return m_hasDemos;
}
QString QtVersion::demosPath() const
{
updateVersionInfo();
return m_versionInfo["QT_INSTALL_DEMOS"];
}
bool QtVersion::hasExamples() const
{
updateVersionInfo();
return m_hasExamples;
}
QString QtVersion::examplesPath() const
{
updateVersionInfo();
return m_versionInfo["QT_INSTALL_EXAMPLES"];
}
bool QtVersion::isMSVC64Bit() const
{
......
......@@ -86,10 +86,20 @@ public:
bool hasDebuggingHelper() const;
QString debuggingHelperLibrary() const;
// Builds a debugging library
// returns the output of the commands
QString buildDebuggingHelperLibrary();
bool hasExamples() const;
QString examplesPath() const;
bool hasDocumentation() const;
QString documentationPath() const;
bool hasDemos() const;
QString demosPath() const;
int uniqueId() const;
bool isMSVC64Bit() const;
......@@ -130,6 +140,9 @@ private:
mutable bool m_notInstalled;
mutable bool m_defaultConfigIsDebug;
mutable bool m_defaultConfigIsDebugAndRelease;
mutable bool m_hasExamples;
mutable bool m_hasDemos;
mutable bool m_hasDocumentation;
mutable QString m_qmakeCommand;
mutable QString m_qtVersionString;
......@@ -170,6 +183,7 @@ public:
signals:
void defaultQtVersionChanged();
void qtVersionsChanged();
void updatedExamples(const QString& examplesPath, const QString& demosPath, const QString& docPath);
private:
// Used by QtOptionsPage
void setNewQtVersions(QList<QtVersion *> newVersions, int newDefaultVersion);
......@@ -179,6 +193,7 @@ private:
void addNewVersionsFromInstaller();
void updateSystemVersion();
void updateDocumentation();
void updateExamples();
static int indexOfVersionInList(const QtVersion * const version, const QList<QtVersion *> &list);
void updateUniqueIdToIndexMap();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment