UBLibraryController.h 5.97 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * 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
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * 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
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#ifndef UBLIBRARYCONTROLLER_H_
#define UBLIBRARYCONTROLLER_H_

#include <QtGui>
#include <QtWebKit>

#include "web/UBWebPage.h"

class UBGraphicsScene;
class UBBoardController;
class QGraphicsSvgItem;
class UBLibraryWebView;
class UBWebView;

typedef enum
{
    eUBLibElementType_Category = 0,
    eUBLibElementType_VirtualFolder,
    eUBLibElementType_Folder,
    eUBLibElementType_InteractiveItem,
    eUBLibElementType_Item
}eUBLibElementType;


class UBLibElement
{

public:
    UBLibElement();
    UBLibElement(eUBLibElementType type, const QUrl& path, const QString& name);
45
    UBLibElement(UBLibElement* element);
46
    virtual ~UBLibElement();
Claudio Valerio's avatar
Claudio Valerio committed
47 48 49 50 51 52 53 54

    static UBLibElement* trashElement();

    eUBLibElementType type(){return mType;}
    void setType(eUBLibElementType type) {mType = type;}
    QUrl path(){return mPath;}
    void setPath(QUrl path){mPath = path;}
    QImage* thumbnail(){return &mThumbnail;}
55
    void setThumbnail(QImage pThumb){mThumbnail = pThumb;}
Claudio Valerio's avatar
Claudio Valerio committed
56 57 58 59 60 61
    QString information(){return mInfo;}
    void setInformation(QString info){mInfo = info;}
    QString name(){return mName;}
    void setName(QString name){mName = name;}
    QString extension(){return mExtension;}
    void setExtension(QString &extension){ mExtension = extension;}
62 63
    bool isMoveable(){return mbMoveable;}
    void setMoveable(bool bState){mbMoveable = bState;}
Ivan Ilin's avatar
Ivan Ilin committed
64 65
    bool isDeletable() const {return mbDeletable;}
    void setDeletable(bool mState) {mbDeletable = mState;}
66 67
    void setMetadata(QMap<QString, QString> metadatas){mMetadata = metadatas;}
    QMap<QString, QString> metadatas(){return mMetadata;}
Claudio Valerio's avatar
Claudio Valerio committed
68 69 70 71 72 73 74 75

private:
    eUBLibElementType mType;
    QUrl mPath;
    QImage mThumbnail;
    QString mInfo;
    QString mName;
    QString mExtension;
76
    bool mbMoveable;
Ivan Ilin's avatar
Ivan Ilin committed
77
    bool mbDeletable;
78
    QMap<QString, QString> mMetadata;
Claudio Valerio's avatar
Claudio Valerio committed
79 80 81 82 83 84
};

class UBChainedLibElement
{
public:
    UBChainedLibElement(UBLibElement* pElem, UBChainedLibElement* pNextElem=NULL);
85
    virtual ~UBChainedLibElement();
Claudio Valerio's avatar
Claudio Valerio committed
86 87

    UBChainedLibElement* nextElement(){return mpNextElem;}
88
    UBChainedLibElement* lastElement();
Claudio Valerio's avatar
Claudio Valerio committed
89 90
    void setNextElement(UBChainedLibElement* nextElem);
    UBLibElement* element(){return mpElem;}
91
    QUrl lastItemPath();
Claudio Valerio's avatar
Claudio Valerio committed
92 93 94 95 96 97 98 99 100 101 102

private:
    UBLibElement* mpElem;
    UBChainedLibElement* mpNextElem;
};

class UBLibraryController : public QObject
{
    Q_OBJECT;

    public:
103
        UBLibraryController(QWidget *parentWidget);
Claudio Valerio's avatar
Claudio Valerio committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
        virtual ~UBLibraryController();

        QList<UBLibElement*> getContent(UBLibElement* pElement);
        void moveContent(QList<UBLibElement*> sourceList, UBLibElement *pDestination);
        void trashElements(QList<UBLibElement*> trashList);
        void emptyElementsOnTrash(QList<UBLibElement*> elementsList);

        void addNativeToolToFavorites(const QUrl& url);

        void setItemAsBackground(UBLibElement* image);
        void addItemToPage(UBLibElement* item);

        void addToFavorite(QList<UBLibElement*> elementList);
        void removeFromFavorite(QList<UBLibElement*> elementList);

119 120
        void importItemOnLibrary(QString& pItemString);
        void importImageOnLibrary(QImage &pImage);
Claudio Valerio's avatar
Claudio Valerio committed
121 122 123 124

        QString favoritePath();

        void createNewFolder(QString name, UBLibElement* parentElem);
Claudio Valerio's avatar
Claudio Valerio committed
125
        bool canItemsOnElementBeDeleted(UBLibElement *pElement);
126

127
        void routeItem(QString& pItem, QString pMiddleDirectory = QString());
128
        void routeDataItem(QString& pItem, QByteArray pData);
Claudio Valerio's avatar
Claudio Valerio committed
129 130 131 132

    signals:
        void dialogClosed(int state);
        void setResource(QString &pathResource,QString &mimetype);
133
        void updateItemsList();
Claudio Valerio's avatar
Claudio Valerio committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

    public slots:
        void removeBackground();
        void addImagesToCurrentPage(const QList<QUrl>& images);
        void addVideosToCurrentPage(const QList<QUrl>& videos);
        void addAudiosToCurrentPage(const QList<QUrl>& sounds);
        void addInteractivesToCurrentPage(const QList<QUrl>& interactiveWidgets);

    protected:

        UBGraphicsScene* activeScene();
        QRectF visibleSceneRect();
        QList<UBLibElement*> mFavoriteList;
        void persistFavoriteList();
        void readFavoriteList();
149
        QList<UBLibElement*> mInternalLibElements;
150 151
        QList<UBLibElement*> mElementsList;
        void cleanElementsList();
Claudio Valerio's avatar
Claudio Valerio committed
152 153 154 155 156 157

    private:
        QList<UBLibElement*> rootCategoriesList();
        QList<UBLibElement*> listElementsInPath(const QString& pPath);
        QList<UBLibElement*> listElementsInVirtualForlder(UBLibElement* pElement);
        void userPath(QUrl &pPath);
158 159
        QImage thumbnailForFile(UBLibElement* pPath);
        QImage createThumbnail(UBLibElement* pPath);
160
        QList<UBLibElement*> addVirtualElementsForItemPath(const QString& pPath);
Claudio Valerio's avatar
Claudio Valerio committed
161

162
        void createInternalWidgetItems();
163
        void createDirectory(QUrl& pDirPath);
Claudio Valerio's avatar
Claudio Valerio committed
164

165 166 167 168 169
        QUrl mAudioStandardDirectoryPath;
        QUrl mVideoStandardDirectoryPath;
        QUrl mPicturesStandardDirectoryPath;
        QUrl mInteractiveUserDirectoryPath;
        QUrl mInteractiveCategoryPath;
170
        QUrl mAnimationUserDirectoryPath;
171
        QUrl mSearchCategoryPath;
Claudio Valerio's avatar
Claudio Valerio committed
172 173 174 175 176 177 178 179 180

        QStringList addItemsToCurrentLibrary(const QDir& pSelectedFolder, const QStringList& pExtensions);

        UBLibElement* isOnFavoriteList(UBLibElement * element);

        QWidget *mParentWidget;
        UBBoardController *mBoardController;

        int mLastItemOffsetIndex;
181
        QString getBaseDestinationForItem(QString& pItem);
Claudio Valerio's avatar
Claudio Valerio committed
182 183 184 185

};

#endif /* UBLIBRARYCONTROLLER_H_ */