/*************************************************************************** ** ** This file is part of Qt Creator ** ** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). ** ** Contact: Qt Software Information (qt-info@nokia.com) ** ** ** Non-Open Source Usage ** ** Licensees may use this file in accordance with the Qt Beta Version ** License Agreement, Agreement version 2.2 provided with the Software or, ** alternatively, in accordance with the terms contained in a written ** agreement between you and Nokia. ** ** GNU General Public License Usage ** ** Alternatively, this file may be used under the terms of the GNU General ** Public License versions 2.0 or 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the packaging ** of this file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and ** http://www.gnu.org/copyleft/gpl.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt GPL Exception ** version 1.3, included in the file GPL_EXCEPTION.txt in this package. ** ***************************************************************************/ #include "welcomemode.h" #include "coreconstants.h" #include "uniqueidmanager.h" #include "coreimpl.h" #include "modemanager.h" #if !defined(QT_NO_WEBKIT) #include #include #include #else #include #endif #include #include #include #include #include #include namespace Core { namespace Internal { static QString readFile(const QString &name) { QFile f(name); if (!f.open(QIODevice::ReadOnly)) { qWarning("Unable to open %s: %s", name.toUtf8().constData(), f.errorString().toUtf8().constData()); return QString(); } QTextStream ts(&f); return ts.readAll(); } struct WelcomeModePrivate { WelcomeModePrivate(); QWidget *m_widget; #if !defined(QT_NO_WEBKIT) QWebView *m_webview; #else QLabel *m_label; #endif WelcomeMode::WelcomePageData lastData; const QString m_htmlTemplate; const QString m_sessionHtmlTemplate; const QString m_projectHtmlTemplate; const QUrl m_baseUrl; }; WelcomeModePrivate::WelcomeModePrivate() : m_widget(new QWidget), #if !defined(QT_NO_WEBKIT) m_webview(new QWebView), #else m_label(new QLabel), #endif m_htmlTemplate(readFile(QLatin1String(":/core/html/welcome.html"))), m_sessionHtmlTemplate(readFile(QLatin1String(":/core/html/recent_sessions.html"))), m_projectHtmlTemplate(readFile(QLatin1String(":/core/html/recent_projects.html"))), m_baseUrl(QUrl(QLatin1String("qrc:/core/html/welcome.html"))) { } #if defined(QT_NO_WEBKIT) const char *LABEL = "
" "



Welcome

Qt Creator is an intuitive, modern cross platform IDE that enables " "developers to create graphically appealing applications for desktop, " "embedded, and mobile devices. " "

(This startup page lacks features due to disabled webkit support)" "

"; #endif // --- WelcomePageData bool WelcomeMode::WelcomePageData::operator==(const WelcomePageData &rhs) const { return previousSession == rhs.previousSession && activeSession == rhs.activeSession && sessionList == rhs.sessionList && projectList == rhs.projectList; } bool WelcomeMode::WelcomePageData::operator!=(const WelcomePageData &rhs) const { return previousSession != rhs.previousSession || activeSession != rhs.activeSession || sessionList != rhs.sessionList || projectList != rhs.projectList; } QDebug operator<<(QDebug dgb, const WelcomeMode::WelcomePageData &d) { dgb.nospace() << "PreviousSession=" << d.previousSession << " activeSession=" << d.activeSession << " sessionList=" << d.sessionList << " projectList=" << d.projectList; return dgb; } // --- WelcomeMode WelcomeMode::WelcomeMode() : m_d(new WelcomeModePrivate) { QVBoxLayout *l = new QVBoxLayout(m_d->m_widget); l->setMargin(0); l->setSpacing(0); l->addWidget(new QToolBar(m_d->m_widget)); #if !defined(QT_NO_WEBKIT) connect(m_d->m_webview, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClicked(QUrl))); WelcomePageData welcomePageData; updateWelcomePage(welcomePageData); l->addWidget(m_d->m_webview); #else m_d->m_label->setWordWrap(true); m_d->m_label->setAlignment(Qt::AlignCenter); m_d->m_label->setText(LABEL); l->addWidget(m_d->m_label); #endif } WelcomeMode::~WelcomeMode() { delete m_d; } QString WelcomeMode::name() const { return QLatin1String("Welcome"); } QIcon WelcomeMode::icon() const { return QIcon(QLatin1String(":/core/images/qtcreator_logo_32.png")); } int WelcomeMode::priority() const { return Constants::P_MODE_WELCOME; } QWidget* WelcomeMode::widget() { return m_d->m_widget; } const char* WelcomeMode::uniqueModeName() const { return Constants::MODE_WELCOME; } QList WelcomeMode::context() const { static QList contexts = QList() << CoreImpl::instance()->uniqueIDManager()->uniqueIdentifier(Constants::C_WELCOME_MODE); return contexts; } void WelcomeMode::updateWelcomePage(const WelcomePageData &welcomePageData) { // should really only modify the DOM tree #if defined(QT_NO_WEBKIT) Q_UNUSED(welcomePageData); #else // Update only if data are modified if (welcomePageData == m_d->lastData) return; m_d->lastData = welcomePageData; QString html = m_d->m_htmlTemplate; if (!welcomePageData.previousSession.isEmpty() || !welcomePageData.projectList.isEmpty()) { QString sessionHtml = m_d->m_sessionHtmlTemplate; sessionHtml.replace(QLatin1String("LAST_SESSION"), welcomePageData.previousSession); if (welcomePageData.sessionList.count() > 1) { QString sessions; foreach (QString s, welcomePageData.sessionList) { QString last; if (s == welcomePageData.previousSession) last = tr(" (last session)"); sessions += QString::fromLatin1("
  • %2%3

  • ").arg(s, s, last); } sessionHtml.replace(QLatin1String(""), sessions); } html.replace(QLatin1String(""), sessionHtml); QString projectHtml = m_d->m_projectHtmlTemplate; { QString projects; QTextStream str(&projects); foreach (const QString &s, welcomePageData.projectList) { const QFileInfo fi(s); str << "
  • " << fi.fileName() << "

  • \n"; } projectHtml.replace(QLatin1String(""), projects); } html.replace(QLatin1String(""), projectHtml); } m_d->m_webview->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); m_d->m_webview->setHtml(html, m_d->m_baseUrl); #endif } void WelcomeMode::linkClicked(const QUrl &url) { QString scheme = url.scheme(); Core::ModeManager *modeManager = CoreImpl::instance()->modeManager(); if (scheme.startsWith(QLatin1String("gh"))) { QString s = url.toString(QUrl::RemoveScheme); if (scheme == QLatin1String("gh")) { emit requestHelp(s); } else if (scheme == QLatin1String("gh-project")) { emit requestProject(s); if (modeManager->currentMode() == this) modeManager->activateMode(Core::Constants::MODE_EDIT); } else if (scheme == QLatin1String("gh-session")) { emit requestSession(s); if (modeManager->currentMode() == this) modeManager->activateMode(Core::Constants::MODE_EDIT); } } else { QDesktopServices::openUrl(url); } } } // namespace Internal } // namespace Core