~zeller-benjamin/qtcreator-plugin-ubuntu/qtc41-beta

« back to all changes in this revision

Viewing changes to ubuntupackagingmode.cpp

  • Committer: Juhapekka Piiroinen
  • Date: 2013-09-04 15:30:00 UTC
  • mto: (23.1.14 binary-plugin)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: juhapekka.piiroinen@canonical.com-20130904153000-r4lhfhrjlwmop277
Added cordova plugin from ubuntu-qtcreator-plugins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2013 Canonical Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Author: Juhapekka Piiroinen <juhapekka.piiroinen@canonical.com>
17
 
 */
18
 
 
19
 
#include "ubuntupackagingmode.h"
20
 
#include "ubuntuconstants.h"
21
 
 
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>
35
 
 
36
 
using namespace Ubuntu::Internal;
37
 
 
38
 
UbuntuPackagingMode::UbuntuPackagingMode(QObject *parent) :
39
 
    Core::IMode(parent)
40
 
{
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));
46
 
 
47
 
    //TODO: enable only when there is a qml project open. Otherwise this tab should remain disabled.
48
 
 
49
 
    m_modeWidget = new QWidget;
50
 
    QVBoxLayout *layout = new QVBoxLayout;
51
 
    layout->setMargin(0);
52
 
    layout->setSpacing(0);
53
 
    m_modeWidget->setLayout(layout);
54
 
 
55
 
 
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);
63
 
 
64
 
    connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)), SLOT(modeChanged(Core::IMode*)));
65
 
 
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*)));
69
 
 
70
 
    setWidget(m_modeWidget);
71
 
    setEnabled(false);
72
 
}
73
 
 
74
 
void UbuntuPackagingMode::initialize() {
75
 
 
76
 
}
77
 
 
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();
82
 
 
83
 
        bool isQmlProject = false;
84
 
        bool isQmakeProject = false;
85
 
        bool isUbuntuProject = false;
86
 
        bool isCordovaProject = false;
87
 
 
88
 
        if (startupProject) {
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));
93
 
        }
94
 
 
95
 
        if (isQmlProject || isUbuntuProject || isCordovaProject) {
96
 
            m_ubuntuPackagingWidget.openManifestForProject();
97
 
            m_ubuntuPackagingWidget.setAvailable(true);
98
 
        } else {
99
 
            m_ubuntuPackagingWidget.setAvailable(false);
100
 
        }
101
 
 
102
 
    } else if (previousMode == id()) {
103
 
        m_ubuntuPackagingWidget.save();
104
 
    }
105
 
 
106
 
    previousMode = currentMode->id();
107
 
}
108
 
 
109
 
 
110
 
void UbuntuPackagingMode::on_projectAdded(ProjectExplorer::Project *project) {
111
 
    ProjectExplorer::SessionManager* sessionManager = ProjectExplorer::ProjectExplorerPlugin::instance()->session();
112
 
    this->setEnabled(sessionManager->projects().count()>0);
113
 
}
114
 
 
115
 
void UbuntuPackagingMode::on_projectRemoved(ProjectExplorer::Project *project) {
116
 
    ProjectExplorer::SessionManager* sessionManager = ProjectExplorer::ProjectExplorerPlugin::instance()->session();
117
 
    this->setEnabled(sessionManager->projects().count()>0);
118
 
}