From ffc9b5c346f63a4a8551df1c701d7dc7499b4900 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Thu, 3 May 2012 18:14:20 +0300 Subject: [PATCH 1/3] Web search partially implemented --- resources/style.qss | 7 ++ src/board/UBFeaturesController.cpp | 16 +++-- src/board/UBFeaturesController.h | 5 +- src/gui/UBFeaturesWidget.cpp | 105 +++++++++++++++++++++++++++++ src/gui/UBFeaturesWidget.h | 24 +++++++ 5 files changed, 152 insertions(+), 5 deletions(-) diff --git a/resources/style.qss b/resources/style.qss index 31f1e671..29505cea 100644 --- a/resources/style.qss +++ b/resources/style.qss @@ -26,6 +26,13 @@ QWidget#UBLibWebView border: 2px solid #999999; } +QWidget#UBFeaturesWebView +{ + background: #EEEEEE; + border-radius : 10px; + border: 2px solid #999999; +} + QListView { background: #EEEEEE; diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index 5ab469a4..e25893d8 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -65,6 +65,7 @@ void UBFeaturesController::initDirectoryTree() mLibInteractiveDirectoryPath = UBSettings::settings()->applicationInteractivesDirectory(); mLibApplicationsDirectoryPath = UBSettings::settings()->applicationApplicationsLibraryDirectory(); mLibShapesDirectoryPath = UBSettings::settings()->applicationShapeLibraryDirectory() ; + mLibSearchDirectoryPath = UBSettings::settings()->userSearchDirectory(); trashDirectoryPath = UBSettings::userTrashDirPath(); featuresList = new QList (); @@ -100,7 +101,8 @@ void UBFeaturesController::initDirectoryTree() featuresList->append( trashElement ); favoriteElement = UBFeature( rootPath, QPixmap(":images/libpalette/FavoritesCategory.svg"), "Favorites", "favorites", FEATURE_FAVORITE ); featuresList->append( favoriteElement ); - + searchElement = UBFeature( rootPath, QPixmap(":images/libpalette/WebSearchCategory.svg"), "Web search", mLibSearchDirectoryPath ); + featuresList->append( searchElement ); loadFavoriteList(); foreach (UBToolsManager::UBToolDescriptor tool, tools) @@ -122,7 +124,7 @@ void UBFeaturesController::initDirectoryTree() fileSystemScan( mLibShapesDirectoryPath, shapesPath ); fileSystemScan( mLibInteractiveDirectoryPath, interactPath ); fileSystemScan( trashDirectoryPath, trashPath ); - + fileSystemScan( mLibSearchDirectoryPath, rootPath + "/" + "Web search" ); } @@ -137,8 +139,14 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt UBFeatureElementType fileType = fileInfo->isDir() ? FEATURE_FOLDER : FEATURE_ITEM; QString fileName = fileInfo->fileName(); - if ( UBFileSystemUtils::mimeTypeFromFileName(fileName).contains("application") ) { - fileType = FEATURE_INTERACTIVE; + if ( UBFileSystemUtils::mimeTypeFromFileName(fileName).contains("application") ) + { + if ( UBFileSystemUtils::mimeTypeFromFileName(fileName).contains("application/search") ) + { + fileType = FEATURE_SEARCH; + } + else + fileType = FEATURE_INTERACTIVE; } QString itemName = (fileType != FEATURE_ITEM) ? fileName : fileInfo->completeBaseName(); QPixmap icon = QPixmap(":images/libpalette/soundIcon.svg"); diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index 914b6a7d..08e59453 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -19,7 +19,8 @@ enum UBFeatureElementType FEATURE_INTERNAL, FEATURE_ITEM, FEATURE_TRASH, - FEATURE_FAVORITE + FEATURE_FAVORITE, + FEATURE_SEARCH }; class UBFeature @@ -105,6 +106,7 @@ private: QString mLibApplicationsDirectoryPath; QString mLibShapesDirectoryPath; QString trashDirectoryPath; + QString mLibSearchDirectoryPath; QString rootPath; QString audiosPath; @@ -127,6 +129,7 @@ private: UBFeature interactElement; UBFeature flashElement; UBFeature shapesElement; + UBFeature searchElement; QSet *favoriteSet; }; diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 58a691ae..af4c74e7 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -1,3 +1,5 @@ +#include + #include "UBFeaturesWidget.h" #include "domain/UBAbstractWidget.h" #include "gui/UBThumbnailWidget.h" @@ -6,6 +8,7 @@ #include "core/UBApplication.h" #include "core/UBDownloadManager.h" #include "globals/UBGlobals.h" +#include "board/UBBoardController.h" UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent) { @@ -82,6 +85,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale pathScene = new QGraphicsScene(this); //pathViewer = new UBFeaturesPathViewer( QPixmap(":images/libpalette/home.png"), controller->getRootPath(), pathScene, this ); featureProperties = new UBFeatureProperties(this); + webView = new UBFeaturesWebView(this); //layout->addWidget( pathViewer ); //pathViewer->show(); @@ -91,6 +95,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale stackedWidget->addWidget( featuresListView ); stackedWidget->addWidget( featureProperties ); + stackedWidget->addWidget( webView ); stackedWidget->setCurrentIndex(ID_LISTVIEW); currentStackedWidget = ID_LISTVIEW; @@ -183,6 +188,11 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) mActionBar->setCurrentState( IN_FOLDER ); } } + else if ( feature.getType() == FEATURE_SEARCH ) + { + webView->showElement( feature ); + switchToWebView(); + } else { featureProperties->showElement( feature ); @@ -307,6 +317,11 @@ void UBFeaturesWidget::switchToProperties() currentStackedWidget = ID_PROPERTIES; } +void UBFeaturesWidget::switchToWebView() +{ + stackedWidget->setCurrentIndex(ID_WEBVIEW); + currentStackedWidget = ID_WEBVIEW; +} /* @@ -375,6 +390,96 @@ void UBFeaturesListView::dropEvent( QDropEvent *event ) } +UBFeaturesWebView::UBFeaturesWebView(QWidget* parent, const char* name):QWidget(parent) + , mpView(NULL) + , mpWebSettings(NULL) + , mpLayout(NULL) + , mpSankoreAPI(NULL) +{ + setObjectName(name); + + SET_STYLE_SHEET(); + + mpLayout = new QVBoxLayout(); + setLayout(mpLayout); + + mpView = new QWebView(this); + mpView->setObjectName("SearchEngineView"); + mpSankoreAPI = new UBWidgetUniboardAPI(UBApplication::boardController->activeScene()); + mpView->page()->mainFrame()->addToJavaScriptWindowObject("sankore", mpSankoreAPI); + + mpWebSettings = QWebSettings::globalSettings(); + mpWebSettings->setAttribute(QWebSettings::JavaEnabled, true); + mpWebSettings->setAttribute(QWebSettings::PluginsEnabled, true); + mpWebSettings->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true); + mpWebSettings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true); + mpWebSettings->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); + mpWebSettings->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true); + mpWebSettings->setAttribute(QWebSettings::DnsPrefetchEnabled, true); + + mpLayout->addWidget(mpView); + + connect(mpView, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); +} + +UBFeaturesWebView::~UBFeaturesWebView() +{ + if(NULL != mpSankoreAPI){ + delete mpSankoreAPI; + mpSankoreAPI = NULL; + } + if(NULL != mpView){ + delete mpView; + mpView = NULL; + } + if(NULL != mpLayout){ + delete mpLayout; + mpLayout = NULL; + } +} + +void UBFeaturesWebView::showElement(const UBFeature &elem) +{ + QString qsWidgetName; + QString path = elem.getFullPath(); + + QString qsConfigPath = QString("%0/config.xml").arg(path); + + if(QFile::exists(qsConfigPath)) + { + QFile f(qsConfigPath); + if(f.open(QIODevice::ReadOnly)) + { + QDomDocument domDoc; + domDoc.setContent(QString(f.readAll())); + QDomElement root = domDoc.documentElement(); + + QDomNode node = root.firstChild(); + while(!node.isNull()) + { + if(node.toElement().tagName() == "content") + { + QDomAttr srcAttr = node.toElement().attributeNode("src"); + qsWidgetName = srcAttr.value(); + break; + } + node = node.nextSibling(); + } + f.close(); + } + } + + mpView->load(QUrl::fromLocalFile(QString("%0/%1").arg(path).arg(qsWidgetName))); +} + +void UBFeaturesWebView::onLoadFinished(bool ok) +{ + if(ok && NULL != mpSankoreAPI){ + mpView->page()->mainFrame()->addToJavaScriptWindowObject("sankore", mpSankoreAPI); + } +} + + UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) : QWidget(parent) , mpLayout(NULL) , mpButtonLayout(NULL) diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 5c9762c6..ff66c14e 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -18,6 +18,7 @@ #include "UBDockPaletteWidget.h" //#include "UBLibActionBar.h" #include "board/UBFeaturesController.h" +#include "api/UBWidgetUniboardAPI.h" #include "UBFeaturesActionBar.h" #include "UBRubberBand.h" @@ -25,6 +26,7 @@ #define THUMBNAIL_WIDTH 400 #define ID_LISTVIEW 0 #define ID_PROPERTIES 1 +#define ID_WEBVIEW 2 class UBListModel; @@ -38,6 +40,7 @@ class UBFeaturesPathViewer; class UBFeatureProperties; class UBFeatureItemButton; class UBFeaturesListView; +class UBFeaturesWebView; class UBFeaturesWidget : public UBDockPaletteWidget { @@ -59,6 +62,7 @@ public: private: void switchToListView(); void switchToProperties(); + void switchToWebView(); UBFeaturesController *controller; @@ -79,7 +83,9 @@ private: QGraphicsScene *pathScene; UBFeaturesActionBar *mActionBar; UBFeatureProperties *featureProperties; + UBFeaturesWebView *webView; QStackedWidget *stackedWidget; + int currentStackedWidget; QModelIndex trashIndex; @@ -114,6 +120,24 @@ private: //QPoint rubberOrigin; }; +class UBFeaturesWebView : public QWidget +{ + Q_OBJECT +public: + UBFeaturesWebView(QWidget* parent = 0, const char* name = "UBFeaturesWebView"); + ~UBFeaturesWebView(); + + void showElement(const UBFeature &elem); + +private slots: + void onLoadFinished(bool ok); + +private: + QWebView* mpView; + QWebSettings* mpWebSettings; + QVBoxLayout* mpLayout; + UBWidgetUniboardAPI* mpSankoreAPI; +}; class UBFeatureProperties : public QWidget { From 812c3cafce538d542da618ec09926ef03f180a85 Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Thu, 3 May 2012 19:42:51 +0300 Subject: [PATCH 2/3] fixed not worked features widget --- src/board/UBFeaturesController.h | 6 +++--- src/gui/UBFeaturesWidget.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index 5b56d8c4..92008227 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -59,7 +59,7 @@ public: UBFeaturesController(QWidget *parentWidget); virtual ~UBFeaturesController(); - const QList & getFeatures()const { return featuresList; } + QList * getFeatures()const { return featuresList; } const QString& getRootPath()const { return rootPath; } @@ -89,7 +89,7 @@ private: static UBFeatureElementType fileTypeFromUrl( const QString &path ); - QList featuresList; + QList *featuresList; UBFeature *rootElement; QString mUserAudioDirectoryPath; @@ -132,7 +132,7 @@ private: UBFeature shapesElement; UBFeature searchElement; - QSet favoriteSet; + QSet *favoriteSet; }; diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 614c0335..faaea0c4 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -205,9 +205,9 @@ public: Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; } - void setFeaturesList(const QList &flist ) { featuresList = flist; } + void setFeaturesList(QList *flist ) { featuresList = flist; } private: - QList featuresList; + QList *featuresList; }; class UBFeaturesProxyModel : public QSortFilterProxyModel From 51e90964492390785257da44e37fdc56da411d7a Mon Sep 17 00:00:00 2001 From: Anna Udovichenko Date: Thu, 3 May 2012 19:46:38 +0300 Subject: [PATCH 3/3] Fixed memory leak --- src/gui/UBFeaturesWidget.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index af4c74e7..f40f9e16 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -605,6 +605,16 @@ void UBFeatureProperties::onAddToPage() UBFeatureProperties::~UBFeatureProperties() { + if ( mpOrigPixmap ) + { + delete mpOrigPixmap; + mpOrigPixmap = NULL; + } + if ( mpElement ) + { + delete mpElement; + mpElement = NULL; + } } UBFeatureItemButton::UBFeatureItemButton(QWidget *parent, const char *name):QPushButton(parent)