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

« back to all changes in this revision

Viewing changes to src/ubuntu/ubuntuwelcomemode.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 "ubuntuwelcomemode.h"
 
20
#include "ubuntuconstants.h"
 
21
 
 
22
#include <coreplugin/modemanager.h>
 
23
#include <QDeclarativeEngine>
 
24
#include <QDeclarativeContext>
 
25
#include <coreplugin/editormanager/editormanager.h>
 
26
#include <coreplugin/dialogs/iwizard.h>
 
27
#include <coreplugin/coreconstants.h>
 
28
#include <projectexplorer/projectexplorer.h>
 
29
#include <extensionsystem/pluginmanager.h>
 
30
#include <coreplugin/icore.h>
 
31
#include <coreplugin/imode.h>
 
32
#include <utils/styledbar.h>
 
33
#include <utils/iwelcomepage.h>
 
34
#include <extensionsystem/pluginmanager.h>
 
35
#include <coreplugin/dialogs/iwizard.h>
 
36
 
 
37
#include <QVBoxLayout>
 
38
#include <QScrollArea>
 
39
#include <QDir>
 
40
#include <QDebug>
 
41
#include <QList>
 
42
#include <QCoreApplication>
 
43
 
 
44
using namespace Ubuntu;
 
45
using namespace Ubuntu::Internal;
 
46
 
 
47
 
 
48
UbuntuWelcomeMode::UbuntuWelcomeMode(QObject *parent) : Core::IMode(parent),
 
49
                                                        m_declarativeView(new QDeclarativeView) {
 
50
    setDisplayName(tr(Ubuntu::Constants::UBUNTU_MODE_WELCOME_DISPLAYNAME));
 
51
    setIcon(QIcon(QLatin1String(Ubuntu::Constants::UBUNTU_MODE_WELCOME_ICON)));
 
52
    setPriority(Core::Constants::P_MODE_WELCOME);
 
53
    setId(Ubuntu::Constants::UBUNTU_MODE_WELCOME);
 
54
    setObjectName(QLatin1String(Ubuntu::Constants::UBUNTU_MODE_WELCOME));
 
55
 
 
56
    QDeclarativeContext *context = m_declarativeView->rootContext();
 
57
    context->setContextProperty(QLatin1String("welcomeMode"), this);
 
58
 
 
59
    m_declarativeView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
 
60
    m_declarativeView->setMinimumWidth(860);
 
61
    m_declarativeView->setMinimumHeight(548);
 
62
 
 
63
    m_modeWidget = new QWidget;
 
64
    QVBoxLayout *layout = new QVBoxLayout;
 
65
    layout->setMargin(0);
 
66
    layout->setSpacing(0);
 
67
    m_modeWidget->setLayout(layout);
 
68
 
 
69
    Utils::StyledBar* styledBar = new Utils::StyledBar(m_modeWidget);
 
70
    layout->addWidget(styledBar);
 
71
    QScrollArea *scrollArea = new QScrollArea(m_modeWidget);
 
72
    scrollArea->setFrameShape(QFrame::NoFrame);
 
73
    layout->addWidget(scrollArea);
 
74
    scrollArea->setWidget(m_declarativeView);
 
75
    scrollArea->setWidgetResizable(true);
 
76
    m_declarativeView->setMinimumWidth(860);
 
77
    m_declarativeView->setMinimumHeight(548);
 
78
    connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)), SLOT(modeChanged(Core::IMode*)));
 
79
    ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance();
 
80
    connect(pluginManager, SIGNAL(objectAdded(QObject*)), SLOT(objectAdded(QObject*)));
 
81
 
 
82
    setWidget(m_modeWidget);
 
83
    //qDebug() << __PRETTY_FUNCTION__;
 
84
}
 
85
 
 
86
void UbuntuWelcomeMode::modeChanged(Core::IMode *mode) {
 
87
    Q_UNUSED(mode);
 
88
}
 
89
 
 
90
void UbuntuWelcomeMode::initialize() {
 
91
 
 
92
    //qDebug() << __PRETTY_FUNCTION__;
 
93
    QDeclarativeContext *context = m_declarativeView->rootContext();
 
94
    context->setContextProperty(QLatin1String("pagesModel"), QVariant::fromValue(m_welcomeTabPluginList));
 
95
 
 
96
    m_declarativeView->setSource(QUrl::fromLocalFile(Constants::UBUNTU_WELCOMESCREEN_QML));
 
97
    m_declarativeView->show();
 
98
    // Load existing welcome screen plugins - start
 
99
 /*   QList<Utils::IWelcomePage*> loadedWelcomeScreenPlugins = ExtensionSystem::PluginManager::getObjects<Utils::IWelcomePage>();
 
100
 
 
101
    QDeclarativeEngine *engine = m_declarativeView->engine();
 
102
    
 
103
 
 
104
    QStringList importPathList = engine->importPathList();
 
105
    importPathList << Core::ICore::resourcePath() + QLatin1String("/welcomescreen")
 
106
                   << QDir::cleanPath(QCoreApplication::applicationDirPath() + QLatin1String("/../" IDE_LIBRARY_BASENAME "/qtcreator"));                   
 
107
    engine->setImportPathList(importPathList);
 
108
    qDebug() << engine->importPathList();
 
109
    qDebug() << "Checking for loaded plugins";
 
110
    foreach (Utils::IWelcomePage *plugin, loadedWelcomeScreenPlugins) {
 
111
        qDebug() << "Load welcomepage plugin: " << plugin->title();
 
112
        plugin->facilitateQml(engine);
 
113
        m_welcomeTabPluginList.append(plugin);
 
114
    }
 
115
    context->setContextProperty(QLatin1String("pagesModel"), QVariant::fromValue(m_welcomeTabPluginList));
 
116
    qDebug() << "check complete";*/
 
117
    // end
 
118
 
 
119
}
 
120
 
 
121
void UbuntuWelcomeMode::objectAdded(QObject* obj) {
 
122
    Q_UNUSED(obj);
 
123
    //qDebug() << __PRETTY_FUNCTION__;
 
124
}
 
125
 
 
126
 
 
127
void UbuntuWelcomeMode::newProject() {
 
128
    Core::ICore::showNewItemDialog(tr("New Project"), Core::IWizard::wizardsOfKind(Core::IWizard::ProjectWizard));
 
129
}
 
130
 
 
131
void UbuntuWelcomeMode::openProject() {
 
132
    ProjectExplorer::ProjectExplorerPlugin::instance()->openOpenProjectDialog();
 
133
}