UBW3CWidgetAPI.cpp 4.54 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1
/*
2
 * Copyright (C) 2015-2018 Département de l'Instruction Publique (DIP-SEM)
Craig Watson's avatar
Craig Watson committed
3
 *
Claudio Valerio's avatar
Claudio Valerio committed
4
 * Copyright (C) 2013 Open Education Foundation
Claudio Valerio's avatar
Claudio Valerio committed
5
 *
Claudio Valerio's avatar
Claudio Valerio committed
6 7
 * Copyright (C) 2010-2013 Groupement d'Intérêt Public pour
 * l'Education Numérique en Afrique (GIP ENA)
8
 *
Claudio Valerio's avatar
Claudio Valerio committed
9 10 11
 * This file is part of OpenBoard.
 *
 * OpenBoard is free software: you can redistribute it and/or modify
Claudio Valerio's avatar
Claudio Valerio committed
12 13
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License,
14 15 16 17
 * with a specific linking exception for the OpenSSL project's
 * "OpenSSL" library (or with modified versions of it that use the
 * same license as the "OpenSSL" library).
 *
Claudio Valerio's avatar
Claudio Valerio committed
18
 * OpenBoard is distributed in the hope that it will be useful,
Claudio Valerio's avatar
Claudio Valerio committed
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Claudio Valerio's avatar
Claudio Valerio committed
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Claudio Valerio's avatar
Claudio Valerio committed
21
 * GNU General Public License for more details.
Claudio Valerio's avatar
Claudio Valerio committed
22
 *
Claudio Valerio's avatar
Claudio Valerio committed
23
 * You should have received a copy of the GNU General Public License
Claudio Valerio's avatar
Claudio Valerio committed
24
 * along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
Claudio Valerio's avatar
Claudio Valerio committed
25 26
 */

27

Claudio Valerio's avatar
Claudio Valerio committed
28

Claudio Valerio's avatar
Claudio Valerio committed
29

Claudio Valerio's avatar
Claudio Valerio committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include "UBW3CWidgetAPI.h"

#include <QtGui>
#include <QtWebKit>

#include "core/UBApplication.h"
#include "core/UBApplicationController.h"

#include "web/UBWebController.h"

#include "domain/UBGraphicsWidgetItem.h"
#include "domain/UBGraphicsProxyWidget.h"

#include "UBWidgetMessageAPI.h"

45
#include "core/memcheck.h"
Claudio Valerio's avatar
Claudio Valerio committed
46

47 48
UBW3CWidgetAPI::UBW3CWidgetAPI(UBGraphicsW3CWidgetItem *graphicsWidget, QObject *parent)
    : QObject(parent)
Claudio Valerio's avatar
Claudio Valerio committed
49 50
    , mGraphicsW3CWidget(graphicsWidget)
{
51
    mPreferencesAPI = new UBW3CWidgetPreferenceAPI(graphicsWidget, parent);
Claudio Valerio's avatar
Claudio Valerio committed
52 53 54 55 56 57 58 59 60 61 62 63

}

UBW3CWidgetAPI::~UBW3CWidgetAPI()
{
    // NOOP
}


QString UBW3CWidgetAPI::uuid()
{
    if (mGraphicsW3CWidget)
64
        return mGraphicsW3CWidget->uuid().toString();
Claudio Valerio's avatar
Claudio Valerio committed
65 66 67 68 69 70 71
    else
        return "";
}


int UBW3CWidgetAPI::width()
{
72
    return mGraphicsW3CWidget->nominalSize().width();
Claudio Valerio's avatar
Claudio Valerio committed
73 74 75 76 77
}


int UBW3CWidgetAPI::height()
{
78
    return mGraphicsW3CWidget->nominalSize().height();
Claudio Valerio's avatar
Claudio Valerio committed
79 80 81 82 83
}


QString UBW3CWidgetAPI::id()
{
84
    return mGraphicsW3CWidget->metadatas().id;
Claudio Valerio's avatar
Claudio Valerio committed
85 86 87 88 89
}


QString UBW3CWidgetAPI::name()
{
90
    return mGraphicsW3CWidget->metadatas().name;
Claudio Valerio's avatar
Claudio Valerio committed
91 92 93 94 95
}


QString UBW3CWidgetAPI::description()
{
96
    return mGraphicsW3CWidget->metadatas().description;
Claudio Valerio's avatar
Claudio Valerio committed
97 98 99 100 101
}


QString UBW3CWidgetAPI::author()
{
102
    return mGraphicsW3CWidget->metadatas().author;
Claudio Valerio's avatar
Claudio Valerio committed
103 104 105 106 107
}


QString UBW3CWidgetAPI::authorEmail()
{
108
    return mGraphicsW3CWidget->metadatas().authorEmail;
Claudio Valerio's avatar
Claudio Valerio committed
109 110 111 112 113
}


QString UBW3CWidgetAPI::authorHref()
{
114
    return mGraphicsW3CWidget->metadatas().authorHref;
Claudio Valerio's avatar
Claudio Valerio committed
115 116 117 118 119
}


QString UBW3CWidgetAPI::version()
{
120
    return mGraphicsW3CWidget->metadatas().version;
Claudio Valerio's avatar
Claudio Valerio committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134
}

QObject* UBW3CWidgetAPI::preferences()
{
    return mPreferencesAPI;
}


void UBW3CWidgetAPI::openURL(const QString& url)
{
    UBApplication::webController->loadUrl(QUrl(url));
}


Guillaume Burel's avatar
Guillaume Burel committed
135
UBW3CWidgetPreferenceAPI::UBW3CWidgetPreferenceAPI(UBGraphicsW3CWidgetItem *graphicsWidget, QObject *parent)
136
    : UBW3CWebStorage(parent)
Claudio Valerio's avatar
Claudio Valerio committed
137 138 139 140 141 142 143 144 145 146 147 148 149
    , mGraphicsW3CWidget(graphicsWidget)
{
    // NOOP
}

UBW3CWidgetPreferenceAPI::~UBW3CWidgetPreferenceAPI()
{
    // NOOP
}


QString UBW3CWidgetPreferenceAPI::key(int index)
{
Guillaume Burel's avatar
Guillaume Burel committed
150
  QMap<QString, UBGraphicsW3CWidgetItem::PreferenceValue> w3CPrefs = mGraphicsW3CWidget->preferences();
Claudio Valerio's avatar
Claudio Valerio committed
151

152 153 154 155
  if (index < w3CPrefs.size())
    return w3CPrefs.keys().at(index);
  else
    return "";
Claudio Valerio's avatar
Claudio Valerio committed
156 157 158 159
}

QString UBW3CWidgetPreferenceAPI::getItem(const QString& key)
{
160
  if (mGraphicsW3CWidget) {
Guillaume Burel's avatar
Guillaume Burel committed
161 162 163
    QMap<QString, QString> docPref = mGraphicsW3CWidget->UBGraphicsWidgetItem::preferences();
    if (docPref.contains(key))
      return docPref.value(key);
164
  
Guillaume Burel's avatar
Guillaume Burel committed
165

166
    QMap<QString, UBGraphicsW3CWidgetItem::PreferenceValue> w3cPrefs = mGraphicsW3CWidget->preferences();
Claudio Valerio's avatar
Claudio Valerio committed
167

168 169 170 171
    if (w3cPrefs.contains(key)) {
      UBGraphicsW3CWidgetItem::PreferenceValue pref = w3cPrefs.value(key);
      return pref.value;
    }
172
  }
173
  return QString();
Guillaume Burel's avatar
Guillaume Burel committed
174
}
Claudio Valerio's avatar
Claudio Valerio committed
175 176 177

int UBW3CWidgetPreferenceAPI::length()
{
Guillaume Burel's avatar
Guillaume Burel committed
178
   QMap<QString, UBGraphicsW3CWidgetItem::PreferenceValue> w3cPrefs = mGraphicsW3CWidget->preferences();
Claudio Valerio's avatar
Claudio Valerio committed
179 180 181 182 183 184 185

   return w3cPrefs.size();
}


void UBW3CWidgetPreferenceAPI::setItem(const QString& key, const QString& value)
{
186
  if (mGraphicsW3CWidget) {
Guillaume Burel's avatar
Guillaume Burel committed
187
    QMap<QString, UBGraphicsW3CWidgetItem::PreferenceValue> w3cPrefs = mGraphicsW3CWidget->preferences();
Claudio Valerio's avatar
Claudio Valerio committed
188

189 190 191
    if (w3cPrefs.contains(key) && !w3cPrefs.value(key).readonly)
      mGraphicsW3CWidget->setPreference(key, value);
  }
Claudio Valerio's avatar
Claudio Valerio committed
192 193 194
}


Guillaume Burel's avatar
Guillaume Burel committed
195 196


Claudio Valerio's avatar
Claudio Valerio committed
197 198
void UBW3CWidgetPreferenceAPI::removeItem(const QString& key)
{
199 200
  if (mGraphicsW3CWidget)
    mGraphicsW3CWidget->removePreference(key);
Claudio Valerio's avatar
Claudio Valerio committed
201 202 203 204 205
}


void UBW3CWidgetPreferenceAPI::clear()
{
206 207
  if (mGraphicsW3CWidget)
    mGraphicsW3CWidget->removeAllPreferences();
Claudio Valerio's avatar
Claudio Valerio committed
208 209 210 211 212
}