Favorite functionality partially implemented

preferencesAboutTextFull
Anna Udovichenko 13 years ago
parent 512fd41554
commit fe0c8ab2e4
  1. 102
      src/board/UBFeaturesController.cpp
  2. 9
      src/board/UBFeaturesController.h
  3. 6
      src/gui/UBFeaturesActionBar.cpp
  4. 1
      src/gui/UBFeaturesActionBar.h
  5. 32
      src/gui/UBFeaturesWidget.cpp
  6. 44
      src/gui/UBFeaturesWidget.h

@ -72,6 +72,7 @@ void UBFeaturesController::initDirectoryTree()
interactPath = rootPath + "/Interactivities"; interactPath = rootPath + "/Interactivities";
shapesPath = rootPath + "/Shapes"; shapesPath = rootPath + "/Shapes";
trashPath = rootPath + "/Trash"; trashPath = rootPath + "/Trash";
favoritePath = rootPath + "/Favorites";
featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath ) ); featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/AudiosCategory.svg"), "Audios" , mUserAudioDirectoryPath ) );
featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath ) ); featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/MoviesCategory.svg"), "Movies" , mUserVideoDirectoryPath ) );
@ -82,10 +83,18 @@ void UBFeaturesController::initDirectoryTree()
featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath ) ); featuresList->append( UBFeature( rootPath, QPixmap(":images/libpalette/ShapesCategory.svg"), "Shapes" , mLibShapesDirectoryPath ) );
trashElement = UBFeature( rootPath, QPixmap(":images/libpalette/TrashCategory.svg"), "Trash", trashDirectoryPath, FEATURE_TRASH ); trashElement = UBFeature( rootPath, QPixmap(":images/libpalette/TrashCategory.svg"), "Trash", trashDirectoryPath, FEATURE_TRASH );
featuresList->append( trashElement ); featuresList->append( trashElement );
favoriteElement = UBFeature( rootPath, QPixmap(":images/libpalette/FavoritesCategory.svg"), "Favorites", "favorites" );
featuresList->append( favoriteElement );
loadFavoriteList();
foreach (UBToolsManager::UBToolDescriptor tool, tools) foreach (UBToolsManager::UBToolDescriptor tool, tools)
{ {
featuresList->append( UBFeature( appPath, tool.icon, tool.label, tool.id, FEATURE_INTERNAL ) ); featuresList->append( UBFeature( appPath, tool.icon, tool.label, tool.id, FEATURE_INTERNAL ) );
if ( favoriteSet->find( tool.id ) != favoriteSet->end() )
{
featuresList->append( UBFeature( favoritePath, tool.icon, tool.label, tool.id, FEATURE_INTERNAL ) );
}
} }
fileSystemScan( mUserInteractiveDirectoryPath, appPath ); fileSystemScan( mUserInteractiveDirectoryPath, appPath );
fileSystemScan( mUserAudioDirectoryPath, audiosPath ); fileSystemScan( mUserAudioDirectoryPath, audiosPath );
@ -99,6 +108,8 @@ void UBFeaturesController::initDirectoryTree()
fileSystemScan( mLibInteractiveDirectoryPath, interactPath ); fileSystemScan( mLibInteractiveDirectoryPath, interactPath );
fileSystemScan( trashDirectoryPath, trashPath ); fileSystemScan( trashDirectoryPath, trashPath );
} }
void UBFeaturesController::fileSystemScan(const QString & currentPath, const QString & currVirtualPath) void UBFeaturesController::fileSystemScan(const QString & currentPath, const QString & currVirtualPath)
@ -138,6 +149,10 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt
else icon = createThumbnail( fullFileName );*/ else icon = createThumbnail( fullFileName );*/
} }
featuresList->append( UBFeature( currVirtualPath, icon, fileName, fullFileName, fileType ) ); featuresList->append( UBFeature( currVirtualPath, icon, fileName, fullFileName, fileType ) );
if ( favoriteSet->find( fullFileName ) != favoriteSet->end() )
{
featuresList->append( UBFeature( favoritePath, icon, fileName, fullFileName, fileType ) );
}
if ( fileType == FEATURE_FOLDER ) if ( fileType == FEATURE_FOLDER )
{ {
@ -147,8 +162,95 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt
} }
} }
void UBFeaturesController::loadFavoriteList()
{
favoriteSet = new QSet<QString>();
QFile file( UBSettings::userDataDirectory() + "/favorites.dat" );
if ( file.exists() )
{
file.open(QIODevice::ReadOnly);
QDataStream in(&file);
int elementsNumber;
in >> elementsNumber;
for ( int i = 0; i < elementsNumber; ++i)
{
QString path;
in >> path;
/*QFileInfo fileInfo( path );
QString fileName = fileInfo.fileName();
UBFeature elem( favoritePath, thumbnailForFile( path ), fileName, path, fileTypeFromUrl(path) );
featuresList->append( elem );*/
favoriteSet->insert( path );
}
}
}
void UBFeaturesController::saveFavoriteList()
{
QFile file( UBSettings::userDataDirectory() + "/favorites.dat" );
file.resize(0);
file.open(QIODevice::WriteOnly);
QDataStream out(&file);
out << favoriteSet->size();
for ( QSet<QString>::iterator it = favoriteSet->begin(); it != favoriteSet->end(); ++it )
{
out << (*it);
}
file.close();
}
UBFeature UBFeaturesController::addToFavorite( const QUrl &path )
{
QString filePath = fileNameFromUrl( path );
if ( favoriteSet->find( filePath ) == favoriteSet->end() )
{
QFileInfo fileInfo( filePath );
QString fileName = fileInfo.fileName();
UBFeature elem( favoritePath, thumbnailForFile( filePath ), fileName, filePath, fileTypeFromUrl(filePath) );
favoriteSet->insert( filePath );
saveFavoriteList();
return elem;
}
return UBFeature();
}
QString UBFeaturesController::fileNameFromUrl( const QUrl &url )
{
QString fileName = url.toString();
if ( fileName.contains( "uniboardTool://" ) )
return fileName;
return url.toLocalFile();
}
UBFeatureElementType UBFeaturesController::fileTypeFromUrl( const QString &path )
{
QFileInfo fileInfo( path );
QString fileName = fileInfo.fileName();
UBFeatureElementType fileType = fileInfo.isDir() ? FEATURE_FOLDER : FEATURE_ITEM;
if ( UBFileSystemUtils::mimeTypeFromFileName(fileName).contains("application") )
{
fileType = FEATURE_INTERACTIVE;
}
else if ( path.contains("uniboardTool://") )
{
fileType = FEATURE_INTERNAL;
}
return fileType;
}
QPixmap UBFeaturesController::thumbnailForFile(const QString &path) QPixmap UBFeaturesController::thumbnailForFile(const QString &path)
{ {
if ( path.contains("uniboardTool://") )
{
return QPixmap( UBToolsManager::manager()->iconFromToolId(path) );
}
if ( UBFileSystemUtils::mimeTypeFromFileName(path).contains("application") )
{
return QPixmap( UBAbstractWidget::iconFilePath( QUrl::fromLocalFile(path) ) );
}
QPixmap thumb; QPixmap thumb;
QString thumbnailPath = UBFileSystemUtils::thumbnailPath( path ); QString thumbnailPath = UBFileSystemUtils::thumbnailPath( path );

@ -66,11 +66,16 @@ public:
static void deleteItem( const QUrl &url ); static void deleteItem( const QUrl &url );
bool isTrash( const QUrl &url ); bool isTrash( const QUrl &url );
UBFeature newFolder( const QString &name ); UBFeature newFolder( const QString &name );
UBFeature addToFavorite( const QUrl &path );
private: private:
void initDirectoryTree(); void initDirectoryTree();
void fileSystemScan(const QString &currPath, const QString & currVirtualPath); void fileSystemScan(const QString &currPath, const QString & currVirtualPath);
static QPixmap createThumbnail(const QString &path); static QPixmap createThumbnail(const QString &path);
//void addImageToCurrentPage( const QString &path ); //void addImageToCurrentPage( const QString &path );
void loadFavoriteList();
void saveFavoriteList();
static QString fileNameFromUrl( const QUrl &url );
static UBFeatureElementType fileTypeFromUrl( const QString &path );
QVector <UBFeature> *featuresList; QVector <UBFeature> *featuresList;
UBFeature *rootElement; UBFeature *rootElement;
@ -100,10 +105,14 @@ private:
QString shapesPath; QString shapesPath;
QString interactPath; QString interactPath;
QString trashPath; QString trashPath;
QString favoritePath;
int mLastItemOffsetIndex; int mLastItemOffsetIndex;
UBFeature currentElement; UBFeature currentElement;
UBFeature trashElement; UBFeature trashElement;
UBFeature favoriteElement;
QSet <QString> *favoriteSet;
}; };

@ -180,6 +180,12 @@ void UBFeaturesActionBar::dropEvent( QDropEvent *event )
event->accept(); event->accept();
emit deleteElements( *event->mimeData() ); emit deleteElements( *event->mimeData() );
} }
if ( dest == mpFavoriteBtn )
{
event->setDropAction( Qt::CopyAction );
event->accept();
emit addToFavorite( *event->mimeData() );
}
} }

@ -27,6 +27,7 @@ signals:
void searchElement(const QString &text); void searchElement(const QString &text);
void newFolderToCreate(); void newFolderToCreate();
void deleteElements( const QMimeData &data ); void deleteElements( const QMimeData &data );
void addToFavorite( const QMimeData &data );
private slots: private slots:
void onSearchTextChanged(QString txt); void onSearchTextChanged(QString txt);
void onActionNewFolder(); void onActionNewFolder();

@ -98,6 +98,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
connect( mActionBar, SIGNAL( searchElement(const QString &) ), this, SLOT( const searchStarted(QString &) ) ); connect( mActionBar, SIGNAL( searchElement(const QString &) ), this, SLOT( const searchStarted(QString &) ) );
connect( mActionBar, SIGNAL( newFolderToCreate() ), this, SLOT( createNewFolder() ) ); connect( mActionBar, SIGNAL( newFolderToCreate() ), this, SLOT( createNewFolder() ) );
connect( mActionBar, SIGNAL( deleteElements(const QMimeData &) ), this, SLOT( deleteElements(const QMimeData &) ) ); connect( mActionBar, SIGNAL( deleteElements(const QMimeData &) ), this, SLOT( deleteElements(const QMimeData &) ) );
connect( mActionBar, SIGNAL( addToFavorite(const QMimeData &) ), this, SLOT( addToFavorite(const QMimeData &) ) );
connect( pathListView, SIGNAL(clicked( const QModelIndex & ) ), connect( pathListView, SIGNAL(clicked( const QModelIndex & ) ),
this, SLOT( currentPathChanged( const QModelIndex & ) ) ); this, SLOT( currentPathChanged( const QModelIndex & ) ) );
} }
@ -211,6 +212,22 @@ void UBFeaturesWidget::deleteElements( const QMimeData & mimeData )
model->invalidate(); model->invalidate();
} }
void UBFeaturesWidget::addToFavorite( const QMimeData & mimeData )
{
if ( !mimeData.hasUrls() )
return;
QList<QUrl> urls = mimeData.urls();
foreach ( QUrl url, urls )
{
UBFeature elem = controller->addToFavorite( url );
if ( !elem.getUrl().isEmpty() && !elem.getUrl().isNull() )
featuresModel->addItem( elem );
}
QSortFilterProxyModel *model = dynamic_cast<QSortFilterProxyModel *>( featuresListView->model() );
model->invalidate();
}
void UBFeaturesWidget::switchToListView() void UBFeaturesWidget::switchToListView()
{ {
stackedWidget->setCurrentIndex(ID_LISTVIEW); stackedWidget->setCurrentIndex(ID_LISTVIEW);
@ -500,6 +517,19 @@ void UBFeaturesModel::addItem( const UBFeature &item )
endInsertRows(); endInsertRows();
} }
void UBFeaturesModel::deleteFavoriteItem( const QString &path )
{
for ( int i = 0; i < featuresList->size(); ++i )
{
if ( !QString::compare( featuresList->at(i).getFullPath(), path, Qt::CaseInsensitive ) &&
!QString::compare( featuresList->at(i).getUrl(), "root/favorite", Qt::CaseInsensitive ) )
{
removeRow( i, QModelIndex() );
return;
}
}
}
bool UBFeaturesModel::removeRows( int row, int count, const QModelIndex & parent ) bool UBFeaturesModel::removeRows( int row, int count, const QModelIndex & parent )
{ {
if ( row < 0 ) if ( row < 0 )
@ -590,7 +620,7 @@ bool UBFeaturesPathProxyModel::filterAcceptsRow( int sourceRow, const QModelInde
UBFeature feature = sourceModel()->data(index, Qt::UserRole + 1).value<UBFeature>(); UBFeature feature = sourceModel()->data(index, Qt::UserRole + 1).value<UBFeature>();
bool isFolder = feature.getType() == FEATURE_CATEGORY || bool isFolder = feature.getType() == FEATURE_CATEGORY ||
feature.getType() == FEATURE_FOLDER; feature.getType() == FEATURE_FOLDER || feature.getType() == FEATURE_TRASH;
QString virtualFullPath = feature.getUrl() + "/" + feature.getName(); QString virtualFullPath = feature.getUrl() + "/" + feature.getName();
return isFolder && path.startsWith( virtualFullPath ); return isFolder && path.startsWith( virtualFullPath );

@ -83,6 +83,7 @@ private slots:
void searchStarted( const QString & ); void searchStarted( const QString & );
void createNewFolder(); void createNewFolder();
void deleteElements( const QMimeData & ); void deleteElements( const QMimeData & );
void addToFavorite( const QMimeData & );
}; };
class UBFeaturesListView : public QListView class UBFeaturesListView : public QListView
@ -96,46 +97,6 @@ protected:
virtual void dropEvent( QDropEvent *event ); virtual void dropEvent( QDropEvent *event );
}; };
/*
class UBFeaturesPathViewer : public QGraphicsView
{
Q_OBJECT
public:
UBFeaturesPathViewer(const QPixmap &root, const QString &rootPath, QGraphicsScene *sc, QWidget* parent=0, const char* name="UBFeaturesPathViewer");
virtual ~UBFeaturesPathViewer() {;}
void addPathElement(const QPixmap &p, const QString &s);
void truncatePath(int number);
private:
QGraphicsLinearLayout *layout;
QGraphicsWidget *container;
QPixmap *arrowPixmap;
};
class UBFolderWidget : public QLabel
{
Q_OBJECT
public:
UBFolderWidget( QWidget * parent = 0, Qt::WindowFlags f = 0 ) : QLabel( parent, f ) {;}
virtual ~UBFolderWidget() {;}
virtual QString getPath()const { return path;}
virtual void setPath( const QString &p ) { path = p;}
signals:
void clicked(const QString &);
protected:
virtual void mouseReleaseEvent ( QMouseEvent * ev )
{
Q_UNUSED(ev)
emit clicked(path);
}
virtual void mousePressEvent ( QMouseEvent * ev )
{
ev->accept();
}
private:
QString path;
};
*/
class UBFeatureProperties : public QWidget class UBFeatureProperties : public QWidget
{ {
@ -190,6 +151,8 @@ public:
virtual ~UBFeaturesModel(){;} virtual ~UBFeaturesModel(){;}
void addItem( const UBFeature &item ); void addItem( const UBFeature &item );
void deleteFavoriteItem( const QString &path );
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
QMimeData *mimeData( const QModelIndexList &indexes ) const; QMimeData *mimeData( const QModelIndexList &indexes ) const;
QStringList mimeTypes() const; QStringList mimeTypes() const;
@ -198,6 +161,7 @@ public:
bool dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent); bool dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent);
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
bool removeRow(int row, const QModelIndex &parent = QModelIndex()); bool removeRow(int row, const QModelIndex &parent = QModelIndex());
Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; } Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; }
void setFeaturesList( QVector <UBFeature> *flist ) { featuresList = flist; } void setFeaturesList( QVector <UBFeature> *flist ) { featuresList = flist; }

Loading…
Cancel
Save