dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
welcomemode.cpp
Go to the documentation of this file.
1 
14 /*
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  * for more details.
24  *
25  * You should have received a copy of the GNU General Public License along
26  * with this program; if not, see <http://www.gnu.org/licenses/>
27  */
28 
29 #include "welcomemode.h"
31 
32 #include <coreplugin/icore.h>
35 #include <coreplugin/modemanager.h>
36 
37 #include <utils/styledbar.h>
38 #include <utils/pathutils.h>
39 
40 #include <QDesktopServices>
41 
42 #include <QtCore/QSettings>
43 #include <QtCore/QUrl>
44 #include <QtCore/QDebug>
45 
46 #include <QtQuick>
47 #include <QQuickView>
48 #include <QQmlEngine>
49 #include <QQmlContext>
50 
51 #include <cstdlib>
52 
53 using namespace ExtensionSystem;
54 using namespace Utils;
55 
56 namespace Welcome {
57 
59 {
61 
62  QQuickView *quickView;
63 };
64 
65 WelcomeModePrivate::WelcomeModePrivate()
66 {
67 }
68 
69 // --- WelcomeMode
70 // instUUID is used to hash-- to determine if we're in the fraction of users
71 // that should get a staggered announcement. It may be bogus on first run,
72 // but no big deal.
73 WelcomeMode::WelcomeMode(QString instUUID)
74  : m_d(new WelcomeModePrivate)
75  , m_priority(Core::Constants::P_MODE_WELCOME)
76 {
77  m_d->quickView = new QQuickView;
78  m_d->quickView->setResizeMode(QQuickView::SizeRootObjectToView);
79 
80  m_d->quickView->engine()->rootContext()->setContextProperty("welcomePlugin", this);
81  m_d->quickView->engine()->rootContext()->setContextProperty("instHash",
82  QVariant(qHash(instUUID)));
83  m_d->quickView->engine()->rootContext()->setContextProperty(
84  "gitHash", QVariant(Core::Constants::GCS_REVISION_SHORT_STR));
85 
86  QString fn = Utils::PathUtils().InsertDataPath(QString("%%DATAPATH%%/welcome/main.qml"));
87  m_d->quickView->setSource(QUrl::fromLocalFile(fn));
88  m_container = NULL;
89 
91  &WelcomeMode::modesChanged);
92  modesChanged();
93 }
94 
96 {
97  delete m_d->quickView;
98  delete m_d;
99 }
100 
101 QString WelcomeMode::name() const
102 {
103  return tr("Welcome");
104 }
105 
106 QIcon WelcomeMode::icon() const
107 {
108  return QIcon(QLatin1String(":/core/gcs_logo_64"));
109 }
110 
112 {
113  return m_priority;
114 }
115 
117 {
118  if (!m_container) {
119  m_container = QWidget::createWindowContainer(m_d->quickView);
120  m_container->setMinimumSize(64, 64);
121  m_container->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
122  }
123  return m_container;
124 }
125 
126 const char *WelcomeMode::uniqueModeName() const
127 {
129 }
130 
132 {
133  static QList<int> contexts = QList<int>()
135  return contexts;
136 }
137 
138 void WelcomeMode::openPage(const QString &page)
139 {
141 }
142 
143 void WelcomeMode::triggerAction(const QString &actionId)
144 {
146 }
147 
148 void WelcomeMode::modesChanged()
149 {
150  QVector<IMode *> modes = Core::ModeManager::instance()->modes();
151  QStringList modeNames;
152 
153  foreach (IMode *mode, modes)
154  modeNames.append(mode->name());
155 
156  auto buttons = m_d->quickView->rootObject()->findChild<QObject *>("modeButtons");
157  if (buttons)
158  buttons->setProperty("modeNames", modeNames);
159  else
160  qWarning() << "[WelcomeMode::modesChanged] Can't find mode buttons";
161 }
162 
163 } // namespace Welcome
static UniqueIDManager * instance()
int uniqueIdentifier(const QString &id)
IMode(QObject *parent=nullptr)
Definition: imode.h:45
static ModeManager * instance()
Definition: modemanager.h:62
void triggerAction(const QString &actionId)
int priority() const
const char *const C_WELCOME_MODE
Definition: coreconstants.h:91
QVector< IMode * > modes() const
Definition: modemanager.h:70
const char *const GCS_REVISION_SHORT_STR
Definition: coreconstants.h:58
QString name() const
const char *const MODE_WELCOME
Definition: coreconstants.h:68
void activateModeByWorkspaceName(const QString &id)
const char * uniqueModeName() const
QList< int > context() const
quint64 qHash(Point const &point)
Definition: point.cpp:45
QIcon icon() const
void openPage(const QString &page)
const int P_MODE_WELCOME
Definition: coreconstants.h:70
void triggerAction(const QString &actionId)
static QString InsertDataPath(QString path)
Definition: pathutils.cpp:84