UBW3CWidgetAPI.cpp 4.14 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1
/*
Claudio Valerio's avatar
Claudio Valerio committed
2 3
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
Claudio Valerio's avatar
Claudio Valerio committed
4
 * the Free Software Foundation, either version 2 of the License, or
Claudio Valerio's avatar
Claudio Valerio committed
5
 * (at your option) any later version.
Claudio Valerio's avatar
Claudio Valerio committed
6
 *
Claudio Valerio's avatar
Claudio Valerio committed
7 8 9 10 11 12 13
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Claudio Valerio's avatar
Claudio Valerio committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 */

#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"

31
#include "core/memcheck.h"
Claudio Valerio's avatar
Claudio Valerio committed
32

33 34
UBW3CWidgetAPI::UBW3CWidgetAPI(UBGraphicsW3CWidgetItem *graphicsWidget, QObject *parent)
    : QObject(parent)
Claudio Valerio's avatar
Claudio Valerio committed
35 36
    , mGraphicsW3CWidget(graphicsWidget)
{
37
    mPreferencesAPI = new UBW3CWidgetPreferenceAPI(graphicsWidget, parent);
Claudio Valerio's avatar
Claudio Valerio committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

}

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


QString UBW3CWidgetAPI::uuid()
{
    if (mGraphicsW3CWidget)
        return mGraphicsW3CWidget->uuid();
    else
        return "";
}


int UBW3CWidgetAPI::width()
{
58
    return mGraphicsW3CWidget->nominalSize().width();
Claudio Valerio's avatar
Claudio Valerio committed
59 60 61 62 63
}


int UBW3CWidgetAPI::height()
{
64
    return mGraphicsW3CWidget->nominalSize().height();
Claudio Valerio's avatar
Claudio Valerio committed
65 66 67 68 69
}


QString UBW3CWidgetAPI::id()
{
70
    return mGraphicsW3CWidget->metadatas().id;
Claudio Valerio's avatar
Claudio Valerio committed
71 72 73 74 75
}


QString UBW3CWidgetAPI::name()
{
76
    return mGraphicsW3CWidget->metadatas().name;
Claudio Valerio's avatar
Claudio Valerio committed
77 78 79 80 81
}


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


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


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


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


QString UBW3CWidgetAPI::version()
{
106
    return mGraphicsW3CWidget->metadatas().version;
Claudio Valerio's avatar
Claudio Valerio committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120
}

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


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


Guillaume Burel's avatar
Guillaume Burel committed
121
UBW3CWidgetPreferenceAPI::UBW3CWidgetPreferenceAPI(UBGraphicsW3CWidgetItem *graphicsWidget, QObject *parent)
122
    : UBW3CWebStorage(parent)
Claudio Valerio's avatar
Claudio Valerio committed
123 124 125 126 127 128 129 130 131 132 133 134 135
    , mGraphicsW3CWidget(graphicsWidget)
{
    // NOOP
}

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


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

138 139 140 141
  if (index < w3CPrefs.size())
    return w3CPrefs.keys().at(index);
  else
    return "";
Claudio Valerio's avatar
Claudio Valerio committed
142 143 144 145
}

QString UBW3CWidgetPreferenceAPI::getItem(const QString& key)
{
146
  if (mGraphicsW3CWidget) {
Guillaume Burel's avatar
Guillaume Burel committed
147 148 149
    QMap<QString, QString> docPref = mGraphicsW3CWidget->UBGraphicsWidgetItem::preferences();
    if (docPref.contains(key))
      return docPref.value(key);
150
  
Guillaume Burel's avatar
Guillaume Burel committed
151

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

154 155 156 157
    if (w3cPrefs.contains(key)) {
      UBGraphicsW3CWidgetItem::PreferenceValue pref = w3cPrefs.value(key);
      return pref.value;
    }
158
  }
159
  return QString();
Guillaume Burel's avatar
Guillaume Burel committed
160
}
Claudio Valerio's avatar
Claudio Valerio committed
161 162 163

int UBW3CWidgetPreferenceAPI::length()
{
Guillaume Burel's avatar
Guillaume Burel committed
164
   QMap<QString, UBGraphicsW3CWidgetItem::PreferenceValue> w3cPrefs = mGraphicsW3CWidget->preferences();
Claudio Valerio's avatar
Claudio Valerio committed
165 166 167 168 169 170 171

   return w3cPrefs.size();
}


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

175 176 177
    if (w3cPrefs.contains(key) && !w3cPrefs.value(key).readonly)
      mGraphicsW3CWidget->setPreference(key, value);
  }
Claudio Valerio's avatar
Claudio Valerio committed
178 179 180
}


Guillaume Burel's avatar
Guillaume Burel committed
181 182


Claudio Valerio's avatar
Claudio Valerio committed
183 184
void UBW3CWidgetPreferenceAPI::removeItem(const QString& key)
{
185 186
  if (mGraphicsW3CWidget)
    mGraphicsW3CWidget->removePreference(key);
Claudio Valerio's avatar
Claudio Valerio committed
187 188 189 190 191
}


void UBW3CWidgetPreferenceAPI::clear()
{
192 193
  if (mGraphicsW3CWidget)
    mGraphicsW3CWidget->removeAllPreferences();
Claudio Valerio's avatar
Claudio Valerio committed
194 195 196 197 198
}