2
* Copyright 2013 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 2.1.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Author: Juhapekka Piiroinen <juhapekka.piiroinen@canonical.com>
19
#include "ubuntupackagingmode.h"
20
#include "ubuntuconstants.h"
22
#include <coreplugin/modemanager.h>
23
#include <coreplugin/editormanager/editormanager.h>
24
#include <coreplugin/dialogs/iwizard.h>
25
#include <coreplugin/coreconstants.h>
26
#include <projectexplorer/projectexplorer.h>
27
#include <projectexplorer/iprojectmanager.h>
28
#include <projectexplorer/session.h>
29
#include <projectexplorer/project.h>
30
#include <coreplugin/icore.h>
31
#include <coreplugin/imode.h>
32
#include <utils/styledbar.h>
33
#include <QVBoxLayout>
34
#include <QScrollArea>
36
using namespace Ubuntu::Internal;
38
UbuntuPackagingMode::UbuntuPackagingMode(QObject *parent) :
41
setDisplayName(tr(Ubuntu::Constants::UBUNTU_MODE_PACKAGING_DISPLAYNAME));
42
setIcon(QIcon(QLatin1String(Ubuntu::Constants::UBUNTU_MODE_PACKAGING_ICON)));
43
setPriority(Ubuntu::Constants::UBUNTU_MODE_PACKAGING_PRIORITY);
44
setId(Ubuntu::Constants::UBUNTU_MODE_PACKAGING);
45
setObjectName(QLatin1String(Ubuntu::Constants::UBUNTU_MODE_PACKAGING));
47
//TODO: enable only when there is a qml project open. Otherwise this tab should remain disabled.
49
m_modeWidget = new QWidget;
50
QVBoxLayout *layout = new QVBoxLayout;
52
layout->setSpacing(0);
53
m_modeWidget->setLayout(layout);
56
Utils::StyledBar* styledBar = new Utils::StyledBar(m_modeWidget);
57
layout->addWidget(styledBar);
58
QScrollArea *scrollArea = new QScrollArea(m_modeWidget);
59
scrollArea->setFrameShape(QFrame::NoFrame);
60
layout->addWidget(scrollArea);
61
scrollArea->setWidget(&m_ubuntuPackagingWidget);
62
scrollArea->setWidgetResizable(true);
64
connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)), SLOT(modeChanged(Core::IMode*)));
66
ProjectExplorer::SessionManager* sessionManager = ProjectExplorer::ProjectExplorerPlugin::instance()->session();
67
connect(sessionManager,SIGNAL(projectAdded(ProjectExplorer::Project*)),SLOT(on_projectAdded(ProjectExplorer::Project*)));
68
connect(sessionManager,SIGNAL(projectRemoved(ProjectExplorer::Project*)),SLOT(on_projectRemoved(ProjectExplorer::Project*)));
70
setWidget(m_modeWidget);
74
void UbuntuPackagingMode::initialize() {
78
void UbuntuPackagingMode::modeChanged(Core::IMode* currentMode) {
79
if (currentMode->id() == id()) {
80
ProjectExplorer::ProjectExplorerPlugin* projectExplorerInstance = ProjectExplorer::ProjectExplorerPlugin::instance();
81
ProjectExplorer::Project* startupProject = projectExplorerInstance->startupProject();
83
bool isQmlProject = false;
84
bool isQmakeProject = false;
85
bool isUbuntuProject = false;
86
bool isCordovaProject = false;
89
isQmlProject = (startupProject->projectManager()->mimeType() == QLatin1String("application/x-qmlproject"));
90
isQmakeProject = (startupProject->projectManager()->mimeType() == QLatin1String("application/vnd.nokia.qt.qmakeprofile"));
91
isCordovaProject = (startupProject->projectManager()->mimeType() == QLatin1String("application/x-cordovaproject"));
92
isUbuntuProject = (startupProject->projectManager()->mimeType() == QLatin1String(Constants::UBUNTUPROJECT_MIMETYPE));
95
if (isQmlProject || isUbuntuProject || isCordovaProject) {
96
m_ubuntuPackagingWidget.openManifestForProject();
97
m_ubuntuPackagingWidget.setAvailable(true);
99
m_ubuntuPackagingWidget.setAvailable(false);
102
} else if (previousMode == id()) {
103
m_ubuntuPackagingWidget.save();
106
previousMode = currentMode->id();
110
void UbuntuPackagingMode::on_projectAdded(ProjectExplorer::Project *project) {
111
ProjectExplorer::SessionManager* sessionManager = ProjectExplorer::ProjectExplorerPlugin::instance()->session();
112
this->setEnabled(sessionManager->projects().count()>0);
115
void UbuntuPackagingMode::on_projectRemoved(ProjectExplorer::Project *project) {
116
ProjectExplorer::SessionManager* sessionManager = ProjectExplorer::ProjectExplorerPlugin::instance()->session();
117
this->setEnabled(sessionManager->projects().count()>0);