1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "projectwelcomepagewidget.h"
35 #include "projectexplorer.h"
36 #include "ui_projectwelcomepagewidget.h"
38 #include <coreplugin/coreconstants.h>
39 #include <coreplugin/uniqueidmanager.h>
40 #include <coreplugin/modemanager.h>
41 #include <coreplugin/icore.h>
42 #include <coreplugin/dialogs/iwizard.h>
43 #include <coreplugin/filemanager.h>
45 #include <utils/stringutils.h>
47 #include <QtCore/QFileInfo>
48 #include <QtCore/QDir>
49 #include <QtCore/QPair>
50 #include <QtGui/QLabel>
52 #include <QtCore/QDebug>
54 #define MAX_RECENT_PROJECT_ITEMS 6
57 # define MAX_RECENT_SESSION_ITEMS 8
59 # define MAX_RECENT_SESSION_ITEMS 9
62 using namespace ProjectExplorer::Internal;
64 bool ProjectWelcomePageWidget::WelcomePageData::operator==(const WelcomePageData &rhs) const
66 return previousSession == rhs.previousSession
67 && activeSession == rhs.activeSession
68 && sessionList == rhs.sessionList
69 && projectList == rhs.projectList;
72 bool ProjectWelcomePageWidget::WelcomePageData::operator!=(const WelcomePageData &rhs) const
74 return previousSession != rhs.previousSession
75 || activeSession != rhs.activeSession
76 || sessionList != rhs.sessionList
77 || projectList != rhs.projectList;
80 QDebug operator<<(QDebug dgb, const ProjectWelcomePageWidget::WelcomePageData &d)
82 dgb.nospace() << "PreviousSession=" << d.previousSession
83 << " activeSession=" << d.activeSession
84 << " sessionList=" << d.sessionList
85 << " projectList=" << d.projectList;
89 ProjectWelcomePageWidget::ProjectWelcomePageWidget(QWidget *parent) :
91 ui(new Ui::ProjectWelcomePageWidget)
94 updateWelcomePage(WelcomePageData());
96 connect(ui->sessTreeWidget, SIGNAL(activated(QString)), SLOT(slotSessionClicked(QString)));
97 connect(ui->projTreeWidget, SIGNAL(activated(QString)), SLOT(slotProjectClicked(QString)));
98 connect(ui->createNewProjectButton, SIGNAL(clicked()), SLOT(slotCreateNewProject()));
99 connect(ui->openProjectButton, SIGNAL(clicked()),
100 ProjectExplorer::ProjectExplorerPlugin::instance(),
101 SLOT(openOpenProjectDialog()));
102 connect(ui->manageSessionsButton, SIGNAL(clicked()), SIGNAL(manageSessions()));
104 ui->createNewProjectButton->setIcon(
105 QIcon::fromTheme(QLatin1String("document-new"), ui->createNewProjectButton->icon()));
106 ui->openProjectButton->setIcon(
107 QIcon::fromTheme(QLatin1String("document-open"), ui->openProjectButton->icon()));
110 ProjectWelcomePageWidget::~ProjectWelcomePageWidget()
115 void ProjectWelcomePageWidget::updateWelcomePage(const WelcomePageData &welcomePageData)
117 // Update only if data are modified
118 if (welcomePageData == lastData)
120 lastData = welcomePageData;
122 setUpdatesEnabled(false);
123 ui->sessTreeWidget->clear();
124 ui->projTreeWidget->clear();
126 if (welcomePageData.sessionList.count() > 0) {
128 foreach (const QString &s, welcomePageData.sessionList) {
129 if (++items > MAX_RECENT_SESSION_ITEMS)
132 if (welcomePageData.activeSession.isEmpty()) {
133 if (s == welcomePageData.previousSession)
134 str = tr("%1 (last session)").arg(s);
136 if (s == welcomePageData.activeSession)
137 str = tr("%1 (current session)").arg(s);
139 ui->sessTreeWidget->addItem(str, s);
141 ui->sessTreeWidget->updateGeometry();
144 typedef QPair<QString, QString> QStringPair;
145 if (welcomePageData.projectList.count() > 0) {
147 QFontMetrics fm = fontMetrics();
148 foreach (const QStringPair &it, welcomePageData.projectList) {
149 if (++items > MAX_RECENT_PROJECT_ITEMS)
151 const QFileInfo fi(it.first);
152 QString label = "<b>" + it.second +
153 "</b><br><font color=gray>" +
154 fm.elidedText(QDir::toNativeSeparators(Utils::withTildeHomePath(it.first)),
155 Qt::ElideMiddle, 250);
156 ui->projTreeWidget->addItem(label, it.first,
157 QDir::toNativeSeparators(fi.absolutePath()));
159 ui->projTreeWidget->updateGeometry();
161 setUpdatesEnabled(true);
164 void ProjectWelcomePageWidget::activateEditMode()
166 Core::ModeManager *modeManager = Core::ModeManager::instance();
167 if (modeManager->currentMode() == modeManager->mode(Core::Constants::MODE_WELCOME))
168 modeManager->activateMode(Core::Constants::MODE_EDIT);
171 void ProjectWelcomePageWidget::slotSessionClicked(const QString &data)
173 emit requestSession(data);
177 void ProjectWelcomePageWidget::slotProjectClicked(const QString &data)
179 emit requestProject(data);
183 void ProjectWelcomePageWidget::slotCreateNewProject()
185 Core::ICore::instance()->showNewItemDialog(tr("New Project"),
186 Core::IWizard::wizardsOfKind(Core::IWizard::ProjectWizard));