Added clearing sources of any UBGraphicsWidget.

Added new system util method: deleteFile.
preferencesAboutTextFull
Aleksei Kanash 13 years ago
parent 93e08950bc
commit 70e3b539ec
  1. 1
      src/board/UBBoardController.cpp
  2. 8
      src/domain/UBGraphicsMediaItem.cpp
  3. 8
      src/domain/UBGraphicsWidgetItem.cpp
  4. 6
      src/domain/UBGraphicsWidgetItem.h
  5. 4
      src/frameworks/UBCoreGraphicsScene.cpp
  6. 7
      src/frameworks/UBFileSystemUtils.cpp
  7. 1
      src/frameworks/UBFileSystemUtils.h

@ -1802,6 +1802,7 @@ UBGraphicsWidgetItem *UBBoardController::addW3cWidget(const QUrl &pUrl, const QP
QString struuid = UBStringUtils::toCanonicalUuid(uuid); QString struuid = UBStringUtils::toCanonicalUuid(uuid);
QString snapshotPath = mActiveDocument->persistencePath() + "/" + UBPersistenceManager::widgetDirectory + "/" + struuid + ".png"; QString snapshotPath = mActiveDocument->persistencePath() + "/" + UBPersistenceManager::widgetDirectory + "/" + struuid + ".png";
w3cWidgetItem->setSnapshotPath(QUrl::fromLocalFile(snapshotPath));
UBGraphicsWidgetItem *tmpItem = dynamic_cast<UBGraphicsWidgetItem*>(w3cWidgetItem); UBGraphicsWidgetItem *tmpItem = dynamic_cast<UBGraphicsWidgetItem*>(w3cWidgetItem);
if (tmpItem) if (tmpItem)
tmpItem->widgetWebView()->takeSnapshot().save(snapshotPath, "PNG"); tmpItem->widgetWebView()->takeSnapshot().save(snapshotPath, "PNG");

@ -25,6 +25,8 @@
#include "core/memcheck.h" #include "core/memcheck.h"
#include "frameworks/UBFileSystemUtils.h"
bool UBGraphicsMediaItem::sIsMutedByDefault = false; bool UBGraphicsMediaItem::sIsMutedByDefault = false;
UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent) UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent)
@ -85,15 +87,11 @@ QVariant UBGraphicsMediaItem::itemChange(GraphicsItemChange change, const QVaria
void UBGraphicsMediaItem::clearSource() void UBGraphicsMediaItem::clearSource()
{ {
QString path = mediaFileUrl().path(); QString path = mediaFileUrl().path();
//if path is absolute clean duplicated path string //if path is absolute clean duplicated path string
if (!path.contains(UBApplication::boardController->activeDocument()->persistencePath())) if (!path.contains(UBApplication::boardController->activeDocument()->persistencePath()))
path = UBApplication::boardController->activeDocument()->persistencePath() + "/" + path; path = UBApplication::boardController->activeDocument()->persistencePath() + "/" + path;
QFile f(path); UBFileSystemUtils::deleteFile(path);
f.setPermissions(path, QFile::ReadOwner | QFile::WriteOwner);
f.remove();
} }
void UBGraphicsMediaItem::toggleMute() void UBGraphicsMediaItem::toggleMute()

@ -25,6 +25,7 @@
#include "UBW3CWidget.h" #include "UBW3CWidget.h"
#include "UBGraphicsScene.h" #include "UBGraphicsScene.h"
#include "UBAppleWidget.h" #include "UBAppleWidget.h"
#include "frameworks/UBFileSystemUtils.h"
#include "core/memcheck.h" #include "core/memcheck.h"
@ -246,6 +247,13 @@ void UBGraphicsWidgetItem::removeScript()
mWebKitWidget->page()->mainFrame()->evaluateJavaScript("if(widget && widget.onremove) { widget.onremove();}"); mWebKitWidget->page()->mainFrame()->evaluateJavaScript("if(widget && widget.onremove) { widget.onremove();}");
} }
} }
void UBGraphicsWidgetItem::clearSource()
{
UBFileSystemUtils::deleteDir(getOwnFolder().toLocalFile());
UBFileSystemUtils::deleteFile(getSnapshotPath().toLocalFile());
}
QString UBGraphicsWidgetItem::downloadUrl(const QString &fileUrl, const QString &extention) QString UBGraphicsWidgetItem::downloadUrl(const QString &fileUrl, const QString &extention)
{ {
return mUniboardAPI->downloadUrl(fileUrl, extention); return mUniboardAPI->downloadUrl(fileUrl, extention);

@ -70,9 +70,10 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget
virtual void setOwnFolder(const QUrl &newFolder) {ownFolder = newFolder;} virtual void setOwnFolder(const QUrl &newFolder) {ownFolder = newFolder;}
virtual QUrl getOwnFolder() const {return ownFolder;} virtual QUrl getOwnFolder() const {return ownFolder;}
virtual void setSnapshotPath(const QUrl &newFilePath){SnapshotFile = newFilePath;}
virtual QUrl getSnapshotPath(){return SnapshotFile;}
virtual void clearSource();
virtual void clearSource(){;}
protected: protected:
@ -95,6 +96,7 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget
bool mShouldMoveWidget; bool mShouldMoveWidget;
UBWidgetUniboardAPI* mUniboardAPI; UBWidgetUniboardAPI* mUniboardAPI;
QUrl ownFolder; QUrl ownFolder;
QUrl SnapshotFile;
}; };
class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem

@ -19,6 +19,7 @@
#include "domain/UBGraphicsAudioItem.h" #include "domain/UBGraphicsAudioItem.h"
#include "domain/UBGraphicsVideoItem.h" #include "domain/UBGraphicsVideoItem.h"
#include "domain/UBGraphicsMediaItem.h" #include "domain/UBGraphicsMediaItem.h"
#include "domain/UBGraphicsWidgetItem.h"
UBCoreGraphicsScene::UBCoreGraphicsScene(QObject * parent) UBCoreGraphicsScene::UBCoreGraphicsScene(QObject * parent)
: QGraphicsScene ( parent ) : QGraphicsScene ( parent )
@ -70,6 +71,9 @@ bool UBCoreGraphicsScene::deleteItem(QGraphicsItem* item)
case UBGraphicsVideoItem::Type: case UBGraphicsVideoItem::Type:
item_casted = dynamic_cast<UBGraphicsVideoItem*>(item); item_casted = dynamic_cast<UBGraphicsVideoItem*>(item);
break; break;
case UBGraphicsW3CWidgetItem::Type:
item_casted = dynamic_cast<UBGraphicsWidgetItem*>(item);
break;
} }
if (0 != item_casted) if (0 != item_casted)

@ -79,6 +79,13 @@ bool UBFileSystemUtils::copyFile(const QString &source, const QString &Destinati
return QFile::copy(source, normalizedDestination); return QFile::copy(source, normalizedDestination);
} }
bool UBFileSystemUtils::deleteFile(const QString &path)
{
QFile f(path);
f.setPermissions(path, QFile::ReadOwner | QFile::WriteOwner);
return f.remove();
}
QString UBFileSystemUtils::defaultTempDirPath() QString UBFileSystemUtils::defaultTempDirPath()
{ {
return QDesktopServices::storageLocation(QDesktopServices::TempLocation) + "/" + defaultTempDirName(); return QDesktopServices::storageLocation(QDesktopServices::TempLocation) + "/" + defaultTempDirName();

@ -67,6 +67,7 @@ class UBFileSystemUtils
static bool copyFile(const QString &source, const QString &Destination, bool overwrite = false); static bool copyFile(const QString &source, const QString &Destination, bool overwrite = false);
static bool deleteFile(const QString &path);
/** /**
* Compress a source directory in a zip file. * Compress a source directory in a zip file.
* @arg pDir the directory to add in zip * @arg pDir the directory to add in zip

Loading…
Cancel
Save