2009-07-27 13:55:30 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2009-07-27 13:55:30 +02:00
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2009-07-27 13:55:30 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
2009-07-27 13:55:30 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2009-07-27 13:55:30 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "gettingstartedwelcomepagewidget.h"
|
|
|
|
|
#include "ui_gettingstartedwelcomepagewidget.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
2010-06-11 13:11:37 +02:00
|
|
|
#include <coreplugin/helpmanager.h>
|
2009-07-27 13:55:30 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2010-10-19 13:07:19 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2010-09-24 17:30:10 +02:00
|
|
|
#include <coreplugin/rssfetcher.h>
|
2010-11-02 16:53:56 +01:00
|
|
|
#include <coreplugin/dialogs/iwizard.h>
|
2010-06-28 14:34:30 +02:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2009-07-27 13:55:30 +02:00
|
|
|
|
2009-10-22 17:59:17 +02:00
|
|
|
#include <utils/pathchooser.h>
|
2010-09-27 14:55:51 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2009-10-22 17:59:17 +02:00
|
|
|
|
2009-07-27 13:55:30 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QDateTime>
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
#include <QtCore/QDebug>
|
2010-03-11 10:43:37 +01:00
|
|
|
#include <QtCore/QStringBuilder>
|
2009-07-27 13:55:30 +02:00
|
|
|
#include <QtCore/QUrl>
|
2010-05-25 19:18:22 +02:00
|
|
|
#include <QtCore/QTimer>
|
2009-10-22 17:59:17 +02:00
|
|
|
#include <QtCore/QSettings>
|
2009-07-27 13:55:30 +02:00
|
|
|
#include <QtCore/QXmlStreamReader>
|
2010-10-21 12:36:19 +02:00
|
|
|
#include <QtCore/QScopedPointer>
|
2009-10-22 17:59:17 +02:00
|
|
|
#include <QtGui/QDialogButtonBox>
|
2009-07-27 13:55:30 +02:00
|
|
|
#include <QtGui/QFont>
|
2009-10-22 17:59:17 +02:00
|
|
|
#include <QtGui/QMessageBox>
|
|
|
|
|
#include <QtGui/QPushButton>
|
2010-04-07 18:02:26 +02:00
|
|
|
#include <QtGui/QMenu>
|
2010-09-24 17:30:10 +02:00
|
|
|
#include <QtGui/QDesktopServices>
|
|
|
|
|
|
2009-07-27 13:55:30 +02:00
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-04-07 18:02:26 +02:00
|
|
|
const char ExamplePathPropertyName[] = "__qt_ExamplePath";
|
|
|
|
|
const char HelpPathPropertyName[] = "__qt_HelpPath";
|
2010-11-16 19:10:13 +01:00
|
|
|
const char QmlMainFileName[] = "__qt_QmlMainFileName";
|
2010-04-07 18:02:26 +02:00
|
|
|
|
2010-09-24 17:30:10 +02:00
|
|
|
void PixmapDownloader::populatePixmap(QNetworkReply *reply) {
|
|
|
|
|
QImage image;
|
|
|
|
|
image.loadFromData(reply->readAll());
|
|
|
|
|
m_label->setScaledContents(false);
|
|
|
|
|
m_label->setPixmap(QPixmap::fromImage(image));
|
|
|
|
|
deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-27 13:55:30 +02:00
|
|
|
GettingStartedWelcomePageWidget::GettingStartedWelcomePageWidget(QWidget *parent) :
|
2010-09-27 14:55:51 +02:00
|
|
|
QWidget(parent), ui(new Ui::GettingStartedWelcomePageWidget),
|
|
|
|
|
m_currentFeature(0), m_rssFetcher(0)
|
2009-07-27 13:55:30 +02:00
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2010-06-01 12:51:18 +02:00
|
|
|
|
2009-07-27 13:55:30 +02:00
|
|
|
ui->didYouKnowTextBrowser->viewport()->setAutoFillBackground(false);
|
2010-09-24 17:30:10 +02:00
|
|
|
ui->detailsLabel->hide();
|
2009-07-27 13:55:30 +02:00
|
|
|
|
|
|
|
|
connect(ui->tutorialTreeWidget, SIGNAL(activated(QString)), SLOT(slotOpenHelpPage(const QString&)));
|
|
|
|
|
|
2010-11-05 13:40:46 +01:00
|
|
|
QFontMetrics fm = fontMetrics();
|
|
|
|
|
const int margins = 30;
|
|
|
|
|
int width = ui->tutorialTreeWidget->minimumWidth() - margins;
|
|
|
|
|
|
|
|
|
|
QString itemText = tr("The Qt Creator User Interface");
|
|
|
|
|
QString url = QLatin1String("qthelp://com.nokia.qtcreator/doc/creator-quick-tour.html");
|
|
|
|
|
ui->tutorialTreeWidget->addItem(fm.elidedText(itemText, Qt::ElideRight, width), url, itemText);
|
|
|
|
|
|
|
|
|
|
itemText = tr("Building and Running an Example");
|
|
|
|
|
url = QLatin1String("qthelp://com.nokia.qtcreator/doc/creator-build-example-application.html?view=split");
|
|
|
|
|
ui->tutorialTreeWidget->addItem(fm.elidedText(itemText, Qt::ElideRight, width), url, itemText);
|
|
|
|
|
|
|
|
|
|
itemText = tr("Creating a Qt C++ Application");
|
|
|
|
|
url = QLatin1String("qthelp://com.nokia.qtcreator/doc/creator-writing-program.html?view=split");
|
|
|
|
|
ui->tutorialTreeWidget->addItem(fm.elidedText(itemText, Qt::ElideRight, width), url, itemText);
|
|
|
|
|
|
|
|
|
|
itemText = tr("Creating a Mobile Application");
|
|
|
|
|
url = QLatin1String("qthelp://com.nokia.qtcreator/doc/creator-mobile-example.html?view=split");
|
|
|
|
|
ui->tutorialTreeWidget->addItem(fm.elidedText(itemText, Qt::ElideRight, width), url, itemText);
|
|
|
|
|
|
|
|
|
|
itemText = tr("Creating a Qt Quick Application");
|
|
|
|
|
url = QLatin1String("qthelp://com.nokia.qtcreator/doc/creator-qml-application.html?view=split");
|
|
|
|
|
ui->tutorialTreeWidget->addItem(fm.elidedText(itemText, Qt::ElideRight, width), url, itemText);
|
2009-07-27 13:55:30 +02:00
|
|
|
|
|
|
|
|
srand(QDateTime::currentDateTime().toTime_t());
|
|
|
|
|
QStringList tips = tipsOfTheDay();
|
|
|
|
|
m_currentTip = rand()%tips.count();
|
|
|
|
|
|
|
|
|
|
QTextDocument *doc = ui->didYouKnowTextBrowser->document();
|
2010-10-05 17:27:36 +02:00
|
|
|
doc->setDefaultStyleSheet("* {color:black;};");
|
2009-07-27 13:55:30 +02:00
|
|
|
ui->didYouKnowTextBrowser->setDocument(doc);
|
|
|
|
|
ui->didYouKnowTextBrowser->setText(tips.at(m_currentTip));
|
|
|
|
|
|
|
|
|
|
connect(ui->nextTipBtn, SIGNAL(clicked()), this, SLOT(slotNextTip()));
|
|
|
|
|
connect(ui->prevTipBtn, SIGNAL(clicked()), this, SLOT(slotPrevTip()));
|
2010-06-28 14:34:30 +02:00
|
|
|
connect(ui->openProjectButton, SIGNAL(clicked()),
|
|
|
|
|
ProjectExplorer::ProjectExplorerPlugin::instance(),
|
|
|
|
|
SLOT(openOpenProjectDialog()));
|
2010-04-09 17:41:46 +02:00
|
|
|
connect(ui->createNewProjectButton, SIGNAL(clicked()), this, SLOT(slotCreateNewProject()));
|
2010-04-29 14:52:57 +02:00
|
|
|
|
|
|
|
|
ui->createNewProjectButton->setIcon(
|
2010-07-30 22:16:59 +02:00
|
|
|
QIcon::fromTheme(QLatin1String("document-new"), ui->createNewProjectButton->icon()));
|
2010-04-29 19:07:13 +02:00
|
|
|
ui->openProjectButton->setIcon(
|
2010-07-30 22:16:59 +02:00
|
|
|
QIcon::fromTheme(QLatin1String("document-open"), ui->openProjectButton->icon()));
|
2010-09-24 17:30:10 +02:00
|
|
|
|
2010-11-01 16:29:45 +01:00
|
|
|
m_rssFetcher = new Core::RssFetcher;
|
|
|
|
|
connect (m_rssFetcher, SIGNAL(rssItemReady(Core::RssItem)), SLOT(addToFeatures(Core::RssItem)));
|
2010-09-24 17:30:10 +02:00
|
|
|
connect (m_rssFetcher, SIGNAL(finished(bool)), SLOT(showFeature()), Qt::QueuedConnection);
|
|
|
|
|
connect(this, SIGNAL(startRssFetching(QUrl)), m_rssFetcher, SLOT(fetch(QUrl)), Qt::QueuedConnection);
|
|
|
|
|
m_rssFetcher->start(QThread::LowestPriority);
|
|
|
|
|
const QString featureRssFile = Core::ICore::instance()->resourcePath()+QLatin1String("/rss/featured.rss");
|
|
|
|
|
emit startRssFetching(QUrl::fromLocalFile(featureRssFile));
|
|
|
|
|
|
2010-11-30 13:26:14 +01:00
|
|
|
ui->nextFeatureBtn->hide();
|
|
|
|
|
ui->prevFeatureBtn->hide();
|
2010-09-24 17:30:10 +02:00
|
|
|
connect(ui->nextFeatureBtn, SIGNAL(clicked()), this, SLOT(slotNextFeature()));
|
|
|
|
|
connect(ui->prevFeatureBtn, SIGNAL(clicked()), this, SLOT(slotPrevFeature()));
|
2009-07-27 13:55:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GettingStartedWelcomePageWidget::~GettingStartedWelcomePageWidget()
|
|
|
|
|
{
|
2010-09-24 17:30:10 +02:00
|
|
|
m_rssFetcher->exit();
|
|
|
|
|
m_rssFetcher->wait();
|
|
|
|
|
delete m_rssFetcher;
|
2009-07-27 13:55:30 +02:00
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-21 19:15:55 +02:00
|
|
|
void GettingStartedWelcomePageWidget::parseXmlFile(QFile *file, QMenuHash &cppSubMenuHash, QMenuHash &qmlSubMenuHash,
|
|
|
|
|
const QString &examplePath, const QString &sourcePath)
|
2009-07-27 13:55:30 +02:00
|
|
|
{
|
2010-10-21 19:15:55 +02:00
|
|
|
QMenu *cppSubMenu = 0;
|
|
|
|
|
QMenu *qmlSubMenu = 0;
|
2009-07-27 13:55:30 +02:00
|
|
|
bool inExamples = false;
|
|
|
|
|
QString dirName;
|
2010-10-21 19:15:55 +02:00
|
|
|
|
|
|
|
|
QXmlStreamReader reader(file);
|
2010-04-07 18:02:26 +02:00
|
|
|
|
2009-07-27 13:55:30 +02:00
|
|
|
while (!reader.atEnd()) {
|
|
|
|
|
switch (reader.readNext()) {
|
2010-10-14 18:59:07 +02:00
|
|
|
case QXmlStreamReader::StartElement:
|
2010-05-07 12:34:10 +02:00
|
|
|
if (reader.name() == QLatin1String("category")) {
|
2009-07-27 13:55:30 +02:00
|
|
|
QString name = reader.attributes().value(QLatin1String("name")).toString();
|
2010-10-21 19:15:55 +02:00
|
|
|
if (name.contains(QLatin1String("Tutorial")))
|
2009-07-27 13:55:30 +02:00
|
|
|
break;
|
|
|
|
|
dirName = reader.attributes().value(QLatin1String("dirname")).toString();
|
2010-10-21 19:15:55 +02:00
|
|
|
if (!cppSubMenuHash.contains(dirName)) {
|
|
|
|
|
cppSubMenu = new QMenu(name, this);
|
|
|
|
|
cppSubMenu->setObjectName(dirName);
|
|
|
|
|
cppSubMenuHash.insert(dirName, cppSubMenu);
|
|
|
|
|
} else {
|
|
|
|
|
cppSubMenu = cppSubMenuHash.value(dirName);
|
|
|
|
|
}
|
|
|
|
|
if (!qmlSubMenuHash.contains(dirName)) {
|
|
|
|
|
qmlSubMenu = new QMenu(name, this);
|
|
|
|
|
qmlSubMenu->setObjectName(dirName);
|
|
|
|
|
qmlSubMenuHash.insert(dirName, qmlSubMenu);
|
|
|
|
|
} else {
|
|
|
|
|
qmlSubMenu = qmlSubMenuHash.value(dirName);
|
|
|
|
|
}
|
2009-07-27 13:55:30 +02:00
|
|
|
inExamples = true;
|
|
|
|
|
}
|
2010-05-07 12:34:10 +02:00
|
|
|
if (inExamples && reader.name() == QLatin1String("example")) {
|
2010-02-01 12:43:56 +01:00
|
|
|
const QChar slash = QLatin1Char('/');
|
|
|
|
|
const QString name = reader.attributes().value(QLatin1String("name")).toString();
|
2010-10-14 18:59:07 +02:00
|
|
|
const bool isQml = reader.attributes().value(QLatin1String("qml")).toString() == "true";
|
2010-10-21 19:15:55 +02:00
|
|
|
const QString localDir = reader.attributes().value(QLatin1String("filename")).toString();
|
2010-11-16 19:10:13 +01:00
|
|
|
const QString fileName = localDir.section('/', -1);
|
|
|
|
|
QString replacedFileName = fileName;
|
|
|
|
|
replacedFileName.replace(QLatin1Char('-'), QString());
|
|
|
|
|
QString relativeProPath = slash + dirName + slash + localDir + slash + replacedFileName;
|
2010-10-14 18:59:07 +02:00
|
|
|
|
2010-11-16 19:10:13 +01:00
|
|
|
QString finalFileName = examplePath + relativeProPath + QLatin1String(".pro");
|
2010-10-21 19:15:55 +02:00
|
|
|
|
2010-11-16 19:10:13 +01:00
|
|
|
if (!QFile::exists(finalFileName))
|
|
|
|
|
finalFileName = sourcePath + QLatin1String("/examples") + relativeProPath + QLatin1String(".pro");
|
|
|
|
|
|
|
|
|
|
if (isQml && !QFile::exists(finalFileName)) {
|
|
|
|
|
// maybe it's an old-style QML project?
|
|
|
|
|
relativeProPath = slash + dirName + slash + localDir + slash + fileName;
|
|
|
|
|
finalFileName = examplePath + relativeProPath + QLatin1String(".qmlproject");
|
|
|
|
|
|
|
|
|
|
if (!QFile::exists(finalFileName))
|
|
|
|
|
finalFileName = sourcePath + QLatin1String("/examples") + relativeProPath + QLatin1String(".qmlproject");;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!QFile::exists(finalFileName))
|
2010-10-21 19:15:55 +02:00
|
|
|
break;
|
2010-10-14 18:59:07 +02:00
|
|
|
|
2010-11-16 19:10:13 +01:00
|
|
|
QString dirNameforHelp = dirName;
|
|
|
|
|
dirNameforHelp.replace(slash, QLatin1Char('-'));
|
2010-02-01 12:43:56 +01:00
|
|
|
QString helpPath = QLatin1String("qthelp://com.trolltech.qt/qdoc/") +
|
2010-11-16 19:10:13 +01:00
|
|
|
dirNameforHelp +
|
2010-10-21 19:15:55 +02:00
|
|
|
QLatin1Char('-') + fileName + QLatin1String(".html");
|
|
|
|
|
|
|
|
|
|
QAction *exampleAction = 0;
|
|
|
|
|
QAction *beforeAction = 0;
|
|
|
|
|
bool duplicate = false;
|
|
|
|
|
QMenu *subMenu;
|
|
|
|
|
subMenu = isQml ? qmlSubMenu : cppSubMenu;
|
|
|
|
|
|
|
|
|
|
foreach (beforeAction, subMenu->actions()) {
|
|
|
|
|
int res = beforeAction->text().compare(name, Qt::CaseInsensitive);
|
|
|
|
|
if (res==0) {
|
|
|
|
|
duplicate = true;
|
|
|
|
|
break;
|
|
|
|
|
} else if (res<0)
|
|
|
|
|
beforeAction = 0;
|
|
|
|
|
else if (res>0) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!duplicate) {
|
|
|
|
|
exampleAction = new QAction(name, subMenu);
|
|
|
|
|
subMenu->insertAction(beforeAction, exampleAction);
|
|
|
|
|
connect(exampleAction, SIGNAL(triggered()), SLOT(slotOpenExample()));
|
2010-11-16 19:10:13 +01:00
|
|
|
exampleAction->setProperty(ExamplePathPropertyName, finalFileName);
|
2010-10-21 19:15:55 +02:00
|
|
|
exampleAction->setProperty(HelpPathPropertyName, helpPath);
|
2010-11-16 19:10:13 +01:00
|
|
|
if (isQml)
|
|
|
|
|
exampleAction->setProperty(QmlMainFileName, fileName);
|
2010-10-21 19:15:55 +02:00
|
|
|
}
|
2009-07-27 13:55:30 +02:00
|
|
|
}
|
|
|
|
|
break;
|
2010-10-14 18:59:07 +02:00
|
|
|
case QXmlStreamReader::EndElement:
|
2010-10-21 19:15:55 +02:00
|
|
|
if (inExamples && reader.name() == QLatin1String("category")) {
|
|
|
|
|
if (cppSubMenu->actions().isEmpty())
|
|
|
|
|
delete cppSubMenuHash.take(dirName);
|
|
|
|
|
|
|
|
|
|
if (qmlSubMenu->actions().isEmpty())
|
|
|
|
|
delete qmlSubMenuHash.take(dirName);
|
2010-10-14 18:59:07 +02:00
|
|
|
|
2009-07-27 13:55:30 +02:00
|
|
|
inExamples = false;
|
2010-10-14 18:59:07 +02:00
|
|
|
}
|
2009-07-27 13:55:30 +02:00
|
|
|
break;
|
2010-10-14 18:59:07 +02:00
|
|
|
default:
|
2009-07-27 13:55:30 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-21 19:15:55 +02:00
|
|
|
bool menuEntryCompare(QMenu* first, QMenu* second)
|
|
|
|
|
{
|
|
|
|
|
return (QString::localeAwareCompare(first->title(), second->title()) < 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GettingStartedWelcomePageWidget::updateExamples(const QString &examplePath,
|
|
|
|
|
const QString &demosPath,
|
|
|
|
|
const QString &sourcePath)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
QString demoXml = demosPath + "/qtdemo/xml/examples.xml";
|
|
|
|
|
if (!QFile::exists(demoXml)) {
|
|
|
|
|
demoXml = sourcePath + "/demos/qtdemo/xml/examples.xml";
|
|
|
|
|
if (!QFile::exists(demoXml))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMenuHash cppSubMenuHash;
|
|
|
|
|
QMenuHash qmlSubMenuHash;
|
|
|
|
|
|
|
|
|
|
const QString dropDownLabel = tr("Choose an Example...");
|
|
|
|
|
QMenu *cppMenu = new QMenu(ui->cppExamplesButton);
|
|
|
|
|
ui->cppExamplesButton->setMenu(cppMenu);
|
|
|
|
|
QMenu *qmlMenu = new QMenu(ui->qmlExamplesButton);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// let Creator's files take precedence
|
|
|
|
|
QString localQmlExamplesXml =
|
|
|
|
|
Core::ICore::instance()->resourcePath()+QLatin1String("/examplebrowser/qmlexamples.xml");
|
|
|
|
|
|
|
|
|
|
QFile localDescriptions(localQmlExamplesXml);
|
|
|
|
|
if (localDescriptions.open(QFile::ReadOnly)) {
|
|
|
|
|
parseXmlFile(&localDescriptions, cppSubMenuHash, qmlSubMenuHash, examplePath, sourcePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFile descriptions(demoXml);
|
|
|
|
|
if (!descriptions.open(QFile::ReadOnly))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ui->cppExamplesButton->setEnabled(true);
|
|
|
|
|
ui->cppExamplesButton->setText(dropDownLabel);
|
|
|
|
|
|
|
|
|
|
parseXmlFile(&descriptions, cppSubMenuHash, qmlSubMenuHash, examplePath, sourcePath);
|
|
|
|
|
|
|
|
|
|
QList<QMenu*> cppSubMenus = cppSubMenuHash.values();
|
|
|
|
|
qSort(cppSubMenus.begin(), cppSubMenus.end(), menuEntryCompare);
|
|
|
|
|
QList<QMenu*> qmlSubMenus = qmlSubMenuHash.values();
|
|
|
|
|
qSort(qmlSubMenus.begin(), qmlSubMenus.end(), menuEntryCompare);
|
|
|
|
|
|
|
|
|
|
foreach (QMenu *menu, cppSubMenus)
|
|
|
|
|
cppMenu->addMenu(menu);
|
|
|
|
|
foreach (QMenu *menu, qmlSubMenus)
|
|
|
|
|
qmlMenu->addMenu(menu);
|
|
|
|
|
|
|
|
|
|
if (!qmlMenu->isEmpty()) {
|
|
|
|
|
ui->qmlExamplesButton->setMenu(qmlMenu);
|
|
|
|
|
ui->qmlExamplesButton->setEnabled(true);
|
|
|
|
|
ui->qmlExamplesButton->setText(dropDownLabel);
|
|
|
|
|
}
|
2009-07-27 13:55:30 +02:00
|
|
|
}
|
|
|
|
|
|
2009-10-22 17:59:17 +02:00
|
|
|
namespace {
|
|
|
|
|
void copyRecursive(const QDir& from, const QDir& to, const QString& dir)
|
|
|
|
|
{
|
|
|
|
|
QDir dest(to);
|
|
|
|
|
dest.mkdir(dir);
|
|
|
|
|
dest.cd(dir);
|
|
|
|
|
QDir src(from);
|
|
|
|
|
src.cd(dir);
|
|
|
|
|
foreach(const QFileInfo& roFile, src.entryInfoList(QDir::Files)) {
|
|
|
|
|
QFile::copy(roFile.absoluteFilePath(), dest.absolutePath() + '/' + roFile.fileName());
|
|
|
|
|
}
|
|
|
|
|
foreach(const QString& roDir, src.entryList(QDir::NoDotAndDotDot|QDir::Dirs)) {
|
|
|
|
|
copyRecursive(src, dest, QDir(roDir).dirName());
|
2010-01-29 21:33:57 +01:00
|
|
|
}
|
2009-10-22 17:59:17 +02:00
|
|
|
}
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2009-07-27 13:55:30 +02:00
|
|
|
void GettingStartedWelcomePageWidget::slotOpenExample()
|
|
|
|
|
{
|
2010-04-07 18:02:26 +02:00
|
|
|
QAction *action = qobject_cast<QAction*>(sender());
|
|
|
|
|
if (!action)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QString helpFile = action->property(HelpPathPropertyName).toString();
|
|
|
|
|
QString proFile = action->property(ExamplePathPropertyName).toString();
|
2010-11-16 19:10:13 +01:00
|
|
|
QString qmlMainFileName;
|
|
|
|
|
bool isQmlProject = false;
|
|
|
|
|
if (action->dynamicPropertyNames().contains(QmlMainFileName)) {
|
|
|
|
|
qmlMainFileName = action->property(QmlMainFileName).toString();
|
|
|
|
|
isQmlProject = true;
|
|
|
|
|
}
|
2009-07-27 13:55:30 +02:00
|
|
|
QStringList files;
|
2010-04-07 18:02:26 +02:00
|
|
|
|
2009-10-22 17:59:17 +02:00
|
|
|
QFileInfo proFileInfo(proFile);
|
|
|
|
|
// If the Qt is a distro Qt on Linux, it will not be writable, hence compilation will fail
|
|
|
|
|
if (!proFileInfo.isWritable())
|
|
|
|
|
{
|
|
|
|
|
QDialog d;
|
|
|
|
|
QGridLayout *lay = new QGridLayout(&d);
|
|
|
|
|
QLabel *descrLbl = new QLabel;
|
|
|
|
|
d.setWindowTitle(tr("Copy Project to writable Location?"));
|
|
|
|
|
descrLbl->setTextFormat(Qt::RichText);
|
|
|
|
|
descrLbl->setWordWrap(true);
|
|
|
|
|
descrLbl->setText(tr("<p>The project you are about to open is located in the "
|
|
|
|
|
"write-protected location:</p><blockquote>%1</blockquote>"
|
|
|
|
|
"<p>Please select a writable location below and click \"Copy Project and Open\" "
|
|
|
|
|
"to open a modifiable copy of the project or click \"Keep Project and Open\" "
|
|
|
|
|
"to open the project in location.</p><p><b>Note:</b> You will not "
|
|
|
|
|
"be able to alter or compile your project in the current location.</p>")
|
|
|
|
|
.arg(QDir::toNativeSeparators(proFileInfo.dir().absolutePath())));
|
|
|
|
|
lay->addWidget(descrLbl, 0, 0, 1, 2);
|
|
|
|
|
QLabel *txt = new QLabel(tr("&Location:"));
|
|
|
|
|
Utils::PathChooser *chooser = new Utils::PathChooser;
|
|
|
|
|
txt->setBuddy(chooser);
|
2011-02-21 12:42:20 +01:00
|
|
|
chooser->setExpectedKind(Utils::PathChooser::ExistingDirectory);
|
2009-10-22 17:59:17 +02:00
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
chooser->setPath(settings->value(
|
|
|
|
|
QString::fromLatin1("General/ProjectsFallbackRoot"), QDir::homePath()).toString());
|
|
|
|
|
lay->addWidget(txt, 1, 0);
|
|
|
|
|
lay->addWidget(chooser, 1, 1);
|
|
|
|
|
QDialogButtonBox *bb = new QDialogButtonBox;
|
|
|
|
|
connect(bb, SIGNAL(accepted()), &d, SLOT(accept()));
|
|
|
|
|
connect(bb, SIGNAL(rejected()), &d, SLOT(reject()));
|
|
|
|
|
QPushButton *copyBtn = bb->addButton(tr("&Copy Project and Open"), QDialogButtonBox::AcceptRole);
|
|
|
|
|
copyBtn->setDefault(true);
|
|
|
|
|
bb->addButton(tr("&Keep Project and Open"), QDialogButtonBox::RejectRole);
|
|
|
|
|
lay->addWidget(bb, 2, 0, 1, 2);
|
|
|
|
|
connect(chooser, SIGNAL(validChanged(bool)), copyBtn, SLOT(setEnabled(bool)));
|
|
|
|
|
if (d.exec() == QDialog::Accepted) {
|
|
|
|
|
QString exampleDirName = proFileInfo.dir().dirName();
|
|
|
|
|
QString toDir = chooser->path();
|
|
|
|
|
settings->setValue(QString::fromLatin1("General/ProjectsFallbackRoot"), toDir);
|
|
|
|
|
QDir toDirWithExamplesDir(toDir);
|
|
|
|
|
if (toDirWithExamplesDir.cd(exampleDirName)) {
|
|
|
|
|
toDirWithExamplesDir.cdUp(); // step out, just to not be in the way
|
|
|
|
|
QMessageBox::warning(topLevelWidget(), tr("Warning"),
|
|
|
|
|
tr("The specified location already exists. "
|
|
|
|
|
"Please specify a valid location."),
|
|
|
|
|
QMessageBox::Ok, QMessageBox::NoButton);
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
QDir from = proFileInfo.dir();
|
|
|
|
|
from.cdUp();
|
|
|
|
|
copyRecursive(from, toDir, exampleDirName);
|
|
|
|
|
// set vars to new location
|
|
|
|
|
proFileInfo = QFileInfo(toDir + '/'+ exampleDirName + '/' + proFileInfo.fileName());
|
|
|
|
|
proFile = proFileInfo.absoluteFilePath();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-16 19:10:13 +01:00
|
|
|
QString tryFile;
|
2009-07-27 13:55:30 +02:00
|
|
|
files << proFile;
|
2010-11-16 19:10:13 +01:00
|
|
|
if (isQmlProject) {
|
2010-04-29 14:08:09 +02:00
|
|
|
tryFile = proFileInfo.path() + '/' + "/main.qml";
|
2010-11-16 19:10:13 +01:00
|
|
|
if(!QFile::exists(tryFile))
|
|
|
|
|
tryFile = proFileInfo.path() + "/qml/" + qmlMainFileName + ".qml";
|
|
|
|
|
// legacy qmlproject case
|
|
|
|
|
if(!QFile::exists(tryFile))
|
|
|
|
|
tryFile = proFileInfo.path() + '/' + qmlMainFileName + ".qml";
|
|
|
|
|
if(QFile::exists(tryFile))
|
|
|
|
|
files << tryFile;
|
|
|
|
|
} else {
|
|
|
|
|
tryFile = proFileInfo.path() + "/main.cpp";
|
|
|
|
|
if(!QFile::exists(tryFile))
|
|
|
|
|
tryFile = proFileInfo.path() + '/' + proFileInfo.baseName() + ".cpp";
|
|
|
|
|
}
|
2010-10-19 13:07:19 +02:00
|
|
|
Core::ICore::instance()->openFiles(files, static_cast<Core::ICore::OpenFilesFlags>(Core::ICore::SwitchMode | Core::ICore::StopOnLoadFail));
|
|
|
|
|
if (!tryFile.isEmpty() && Core::EditorManager::instance()->hasEditor(tryFile) && !helpFile.isEmpty())
|
2010-04-29 14:08:09 +02:00
|
|
|
slotOpenContextHelpPage(helpFile);
|
2009-07-27 13:55:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GettingStartedWelcomePageWidget::slotOpenHelpPage(const QString& url)
|
|
|
|
|
{
|
2010-06-11 13:11:37 +02:00
|
|
|
Core::HelpManager *helpManager = Core::HelpManager::instance();
|
2009-07-27 13:55:30 +02:00
|
|
|
Q_ASSERT(helpManager);
|
2010-03-10 18:24:13 +01:00
|
|
|
helpManager->handleHelpRequest(url);
|
2009-07-27 13:55:30 +02:00
|
|
|
}
|
|
|
|
|
void GettingStartedWelcomePageWidget::slotOpenContextHelpPage(const QString& url)
|
|
|
|
|
{
|
2010-06-11 13:11:37 +02:00
|
|
|
Core::HelpManager *helpManager = Core::HelpManager::instance();
|
2009-07-27 13:55:30 +02:00
|
|
|
Q_ASSERT(helpManager);
|
2010-03-10 18:39:46 +01:00
|
|
|
helpManager->handleHelpRequest(url % QLatin1String("?view=split"));
|
2009-07-27 13:55:30 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-09 17:41:46 +02:00
|
|
|
void GettingStartedWelcomePageWidget::slotCreateNewProject()
|
|
|
|
|
{
|
2010-04-19 15:31:59 +02:00
|
|
|
Core::ICore::instance()->showNewItemDialog(tr("New Project"),
|
2010-04-09 17:41:46 +02:00
|
|
|
Core::IWizard::wizardsOfKind(Core::IWizard::ProjectWizard));
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-27 13:55:30 +02:00
|
|
|
void GettingStartedWelcomePageWidget::slotNextTip()
|
|
|
|
|
{
|
|
|
|
|
QStringList tips = tipsOfTheDay();
|
|
|
|
|
m_currentTip = ((m_currentTip+1)%tips.count());
|
|
|
|
|
ui->didYouKnowTextBrowser->setText(tips.at(m_currentTip));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GettingStartedWelcomePageWidget::slotPrevTip()
|
|
|
|
|
{
|
|
|
|
|
QStringList tips = tipsOfTheDay();
|
|
|
|
|
m_currentTip = ((m_currentTip-1)+tips.count())%tips.count();
|
|
|
|
|
ui->didYouKnowTextBrowser->setText(tips.at(m_currentTip));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList GettingStartedWelcomePageWidget::tipsOfTheDay()
|
|
|
|
|
{
|
|
|
|
|
static QStringList tips;
|
|
|
|
|
if (tips.isEmpty()) {
|
|
|
|
|
QString altShortcut =
|
|
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
|
tr("Cmd", "Shortcut key");
|
|
|
|
|
#else
|
|
|
|
|
tr("Alt", "Shortcut key");
|
|
|
|
|
#endif
|
2009-10-07 12:17:59 +02:00
|
|
|
|
|
|
|
|
QString ctrlShortcut =
|
|
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
|
tr("Cmd", "Shortcut key");
|
|
|
|
|
#else
|
|
|
|
|
tr("Ctrl", "Shortcut key");
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-07-27 13:55:30 +02:00
|
|
|
//:%1 gets replaced by Alt (Win/Unix) or Cmd (Mac)
|
|
|
|
|
tips.append(tr("You can show and hide the side bar using <tt>%1+0<tt>.").arg(altShortcut));
|
|
|
|
|
tips.append(tr("You can fine tune the <tt>Find</tt> function by selecting "Whole Words" "
|
|
|
|
|
"or "Case Sensitive". Simply click on the icons on the right end of the line edit."));
|
2010-05-31 11:22:24 +02:00
|
|
|
tips.append(tr("If you add external libraries to your project, Qt Creator will automatically offer syntax highlighting "
|
2009-07-27 13:55:30 +02:00
|
|
|
"and code completion."));
|
|
|
|
|
tips.append(tr("The code completion is CamelCase-aware. For example, to complete <tt>namespaceUri</tt> "
|
|
|
|
|
"you can just type <tt>nU</tt> and hit <tt>Ctrl+Space</tt>."));
|
|
|
|
|
tips.append(tr("You can force code completion at any time using <tt>Ctrl+Space</tt>."));
|
|
|
|
|
tips.append(tr("You can start Qt Creator with a session by calling <tt>qtcreator <sessionname></tt>."));
|
|
|
|
|
tips.append(tr("You can return to edit mode from any other mode at any time by hitting <tt>Escape</tt>."));
|
|
|
|
|
//:%1 gets replaced by Alt (Win/Unix) or Cmd (Mac)
|
|
|
|
|
tips.append(tr("You can switch between the output pane by hitting <tt>%1+n</tt> where n is the number denoted "
|
2010-10-05 17:35:21 +02:00
|
|
|
"on the buttons at the window bottom: <br /><br />"
|
|
|
|
|
"1: Build Issues, 2: Search Results, 3: Application Output, "
|
|
|
|
|
"4: Compile Output").arg(altShortcut));
|
2009-07-27 13:55:30 +02:00
|
|
|
tips.append(tr("You can quickly search methods, classes, help and more using the "
|
2010-08-24 21:36:35 +02:00
|
|
|
"<a href=\"qthelp://com.nokia.qtcreator/doc/creator-editor-locator.html\">Locator bar</a> (<tt>%1+K</tt>).").arg(ctrlShortcut));
|
2009-07-27 13:55:30 +02:00
|
|
|
tips.append(tr("You can add custom build steps in the "
|
2010-05-31 11:22:24 +02:00
|
|
|
"<a href=\"qthelp://com.nokia.qtcreator/doc/creator-build-settings.html\">build settings</a>."));
|
2009-07-27 13:55:30 +02:00
|
|
|
tips.append(tr("Within a session, you can add "
|
2010-05-31 11:22:24 +02:00
|
|
|
"<a href=\"qthelp://com.nokia.qtcreator/doc/creator-build-dependencies.html\">dependencies</a> between projects."));
|
2009-07-27 13:55:30 +02:00
|
|
|
tips.append(tr("You can set the preferred editor encoding for every project in <tt>Projects -> Editor Settings -> Default Encoding</tt>."));
|
|
|
|
|
tips.append(tr("You can use Qt Creator with a number of <a href=\"qthelp://com.nokia.qtcreator/doc/creator-version-control.html\">"
|
2009-07-31 16:41:12 +02:00
|
|
|
"revision control systems</a> such as Subversion, Perforce, CVS and Git."));
|
2009-10-29 16:43:30 +01:00
|
|
|
tips.append(tr("In the editor, <tt>F2</tt> follows symbol definition, <tt>Shift+F2</tt> toggles declaration and definition "
|
|
|
|
|
"while <tt>F4</tt> toggles header file and source file."));
|
2009-07-27 13:55:30 +02:00
|
|
|
}
|
|
|
|
|
return tips;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-01 16:29:45 +01:00
|
|
|
void GettingStartedWelcomePageWidget::addToFeatures(const Core::RssItem &feature)
|
2010-09-24 17:30:10 +02:00
|
|
|
{
|
|
|
|
|
m_featuredItems.append(feature);
|
2010-11-30 13:26:14 +01:00
|
|
|
if (m_featuredItems.count() > 1) {
|
|
|
|
|
ui->nextFeatureBtn->show();
|
|
|
|
|
ui->prevFeatureBtn->show();
|
|
|
|
|
}
|
2010-09-24 17:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GettingStartedWelcomePageWidget::showFeature(int feature)
|
|
|
|
|
{
|
2010-09-27 14:55:51 +02:00
|
|
|
if (m_featuredItems.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2010-09-24 17:30:10 +02:00
|
|
|
if (feature == -1) {
|
|
|
|
|
srand(QDateTime::currentDateTime().toTime_t());
|
2010-09-25 08:52:28 +02:00
|
|
|
m_currentFeature = rand()%m_featuredItems.count();
|
2010-09-24 17:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-01 16:29:45 +01:00
|
|
|
const Core::RssItem &item = m_featuredItems.at(m_currentFeature);
|
2010-09-24 17:30:10 +02:00
|
|
|
ui->featuredTextLabel->setTextFormat(Qt::RichText);
|
|
|
|
|
QString text = QString::fromLatin1("<b style='color: rgb(85, 85, 85);'>%1</b><br><b>%2</b><br/><br/>%3").arg(item.category).arg(item.title).arg(item.description);
|
|
|
|
|
ui->featuredTextLabel->setText(text);
|
|
|
|
|
QString imagePath = item.imagePath;
|
|
|
|
|
if (!imagePath.startsWith("http")) {
|
|
|
|
|
imagePath = Core::ICore::instance()->resourcePath() + "/rss/" + item.imagePath;
|
|
|
|
|
ui->featuredImage->setPixmap(QPixmap(imagePath));
|
|
|
|
|
} else {
|
|
|
|
|
new PixmapDownloader(QUrl(imagePath), ui->featuredImage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.category == QLatin1String("Event")) {
|
2010-10-05 09:53:34 +02:00
|
|
|
ui->detailsLabel->setText(tr("<a href='%1'>Details...</a>").arg(item.url));
|
2010-09-24 17:30:10 +02:00
|
|
|
ui->detailsLabel->show();
|
|
|
|
|
ui->detailsLabel->setOpenExternalLinks(true);
|
|
|
|
|
}
|
|
|
|
|
else if (item.category == QLatin1String("Tutorial")) {
|
2010-10-05 09:53:34 +02:00
|
|
|
ui->detailsLabel->setText(tr("<a href='%1'>Take Tutorial</a>").arg(item.url+"?view=split"));
|
2010-09-24 17:30:10 +02:00
|
|
|
ui->detailsLabel->show();
|
|
|
|
|
ui->detailsLabel->setOpenExternalLinks(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GettingStartedWelcomePageWidget::slotNextFeature()
|
|
|
|
|
{
|
2010-09-27 14:55:51 +02:00
|
|
|
QTC_ASSERT(!m_featuredItems.isEmpty(), return);
|
|
|
|
|
m_currentFeature = (m_currentFeature+1) % m_featuredItems.count();
|
2010-09-24 17:30:10 +02:00
|
|
|
showFeature(m_currentFeature);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GettingStartedWelcomePageWidget::slotPrevFeature()
|
|
|
|
|
{
|
2010-09-27 14:55:51 +02:00
|
|
|
QTC_ASSERT(!m_featuredItems.isEmpty(), return);
|
|
|
|
|
m_currentFeature = ((m_currentFeature-1)+m_featuredItems.count()) % m_featuredItems.count();
|
2010-09-24 17:30:10 +02:00
|
|
|
showFeature(m_currentFeature);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-27 13:55:30 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Qt4ProjectManager
|