implemented downloading pictures to library

preferencesAboutTextFull
Anna Udovichenko 13 years ago
parent bfd74d2247
commit 922efd33a7
  1. 2
      src/board/UBBoardPaletteManager.h
  2. 21
      src/board/UBFeaturesController.cpp
  3. 4
      src/board/UBFeaturesController.h
  4. 59
      src/gui/UBFeaturesWidget.cpp
  5. 8
      src/gui/UBFeaturesWidget.h

@ -44,7 +44,7 @@ class UBApplicationController;
class UBDockTeacherGuideWidget;
// Uncomment this to use old-styles lib paletter
#define USE_WEB_WIDGET
// #define USE_WEB_WIDGET
class UBBoardPaletteManager : public QObject

@ -369,7 +369,7 @@ void UBFeaturesController::addItemAsBackground(const UBFeature &item)
UBFeature UBFeaturesController::getDestinationForItem( const QUrl &url )
{
QString mimetype = UBFileSystemUtils::mimeTypeFromFileName( fileNameFromUrl(url) );
QString mimetype = UBFileSystemUtils::mimeTypeFromFileName( url.toString() );
if ( mimetype.contains("audio") )
return audiosElement;
@ -387,6 +387,25 @@ UBFeature UBFeaturesController::getDestinationForItem( const QUrl &url )
return UBFeature();
}
UBFeature UBFeaturesController::addDownloadedFile( const QUrl &sourceUrl, const QByteArray &pData )
{
UBFeature dest = getDestinationForItem( sourceUrl );
if ( dest == UBFeature() )
return UBFeature();
QString fileName = QFileInfo( sourceUrl.toString() ).fileName();
QString filePath = dest.getFullPath().toLocalFile() + "/" + fileName;
QFile file( filePath );
if( file.open(QIODevice::WriteOnly ))
{
file.write(pData);
file.close();
return UBFeature( dest.getFullVirtualPath(), thumbnailForFile( filePath ),
fileName, QUrl::fromLocalFile(filePath), FEATURE_ITEM );
}
return UBFeature();
}
UBFeature UBFeaturesController::moveItemToFolder( const QUrl &url, const UBFeature &destination )
{
UBFeature newElement = copyItemToFolder( url, destination );

@ -10,6 +10,7 @@
#include <QPixmap>
#include <QMap>
#include <QUrl>
#include <QByteArray>
//#include "UBDockPaletteWidget.h"
@ -75,6 +76,9 @@ public:
const UBFeature& getCurrentElement()const { return currentElement; }
void setCurrentElement( const UBFeature &elem ) { currentElement = elem; }
const UBFeature & getTrashElement () const { return trashElement; }
UBFeature addDownloadedFile( const QUrl &sourceUrl, const QByteArray &pData );
UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination );
UBFeature copyItemToFolder( const QUrl &url, const UBFeature &destination );
void deleteItem( const QUrl &url );

@ -126,6 +126,8 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
connect( thumbSlider, SIGNAL( sliderMoved(int) ), this, SLOT(thumbnailSizeChanged( int ) ) );
connect( UBApplication::boardController, SIGNAL( displayMetadata( QMap<QString,QString> ) ),
this, SLOT( onDisplayMetadata( QMap<QString,QString> ) ) );
connect( UBDownloadManager::downloadManager(), SIGNAL( addDownloadedFileToLibrary( bool, QUrl, QString, QByteArray ) ),
this, SLOT( onAddDownloadedFileToLibrary( bool, QUrl, QString,QByteArray ) ) );
}
bool UBFeaturesWidget::eventFilter( QObject *target, QEvent *event )
@ -317,6 +319,20 @@ void UBFeaturesWidget::onDisplayMetadata( QMap<QString,QString> metadata )
mActionBar->setCurrentState( IN_PROPERTIES );
}
void UBFeaturesWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentHeader, QByteArray pData)
{
if ( pSuccess )
{
UBFeature newFeature = controller->addDownloadedFile( sourceUrl, pData );
if ( newFeature != UBFeature() )
{
featuresModel->addItem( newFeature );
QSortFilterProxyModel *model = dynamic_cast<QSortFilterProxyModel *>( featuresListView->model() );
model->invalidate();
}
}
}
void UBFeaturesWidget::switchToListView()
{
stackedWidget->setCurrentIndex(ID_LISTVIEW);
@ -557,7 +573,34 @@ UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) :
connect( mpAddPageButton, SIGNAL(clicked()), this, SLOT(onAddToPage()) );
connect( mpSetAsBackgroundButton, SIGNAL( clicked() ), this, SLOT( onSetAsBackground() ) );
connect( mpAddToLibButton, SIGNAL( clicked() ), this, SLOT(onAddToLib() ) );
}
void UBFeatureProperties::resizeEvent( QResizeEvent *event )
{
Q_UNUSED(event);
adaptSize();
}
void UBFeatureProperties::showEvent (QShowEvent *event )
{
Q_UNUSED(event);
adaptSize();
}
void UBFeatureProperties::adaptSize()
{
if( NULL != mpOrigPixmap )
{
if( width() < THUMBNAIL_WIDTH + 40 )
{
mpThumbnail->setPixmap( mpOrigPixmap->scaledToWidth( width() - 40 ) );
}
else
{
mpThumbnail->setPixmap( mpOrigPixmap->scaledToWidth( THUMBNAIL_WIDTH ) );
}
}
}
void UBFeatureProperties::showElement( const UBFeature &elem )
@ -629,6 +672,22 @@ void UBFeatureProperties::onAddToPage()
featuresWidget->getFeaturesController()->addItemToPage( *mpElement );
}
void UBFeatureProperties::onAddToLib()
{
if ( UBApplication::isFromWeb( mpElement->getFullPath().toString() ) )
{
sDownloadFileDesc desc;
desc.isBackground = false;
desc.modal = false;
desc.name = QFileInfo( mpElement->getFullPath().toString()).fileName();
qDebug() << desc.name;
desc.url = mpElement->getFullPath().toString();
qDebug() << desc.url;
UBDownloadManager::downloadManager()->addFileToDownload(desc);
}
}
void UBFeatureProperties::onSetAsBackground()
{
QWidget *w = parentWidget()->parentWidget();

@ -100,6 +100,7 @@ private slots:
void removeFromFavorite( const QMimeData & );
void thumbnailSizeChanged( int );
void onDisplayMetadata( QMap<QString,QString> );
void onAddDownloadedFileToLibrary(bool, QUrl, QString, QByteArray);
protected:
bool eventFilter(QObject *target, QEvent *event);
};
@ -151,17 +152,18 @@ public:
protected:
//void resizeEvent(QResizeEvent *event);
//void showEvent(QShowEvent *event);
void resizeEvent(QResizeEvent *event);
void showEvent(QShowEvent *event);
private slots:
void onAddToPage();
//void onAddToLib();
void onAddToLib();
void onSetAsBackground();
//void onBack();
private:
void populateMetadata();
void adaptSize();
QVBoxLayout* mpLayout;
QHBoxLayout* mpButtonLayout;

Loading…
Cancel
Save