file handler fix, deleting snapmatic pictures added
This commit is contained in:
		
							parent
							
								
									517f446d12
								
							
						
					
					
						commit
						2c6a0fa2a5
					
				
					 7 changed files with 82 additions and 6 deletions
				
			
		|  | @ -223,13 +223,13 @@ fileDialogPreSave: | |||
| 
 | ||||
|             if (!isSaved) | ||||
|             { | ||||
|                 QMessageBox::warning(this, tr("Snapmatic Picture Exporter"), tr("Failed to save the picture")); | ||||
|                 QMessageBox::warning(this, tr("Export picture"), tr("Failed to save the picture")); | ||||
|                 goto fileDialogPreSave; | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             QMessageBox::warning(this, tr("Snapmatic Picture Exporter"), tr("No valid file is selected")); | ||||
|             QMessageBox::warning(this, tr("Export picture"), tr("No valid file is selected")); | ||||
|             goto fileDialogPreSave; | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -55,11 +55,13 @@ ProfileInterface::~ProfileInterface() | |||
|     } | ||||
|     foreach(SnapmaticPicture *picture, pictures) | ||||
|     { | ||||
|         pictures.removeAll(picture); | ||||
|         picture->deleteLater(); | ||||
|         delete picture; | ||||
|     } | ||||
|     foreach(QWidget *widget, widgets) | ||||
|     { | ||||
|         widgets.removeAll(widget); | ||||
|         widget->deleteLater(); | ||||
|         delete widget; | ||||
|     } | ||||
|  | @ -101,6 +103,7 @@ void ProfileInterface::on_pictureLoaded(SnapmaticPicture *picture, QString pictu | |||
|     ui->vlSnapmatic->addWidget(picWidget); | ||||
|     widgets.append(picWidget); | ||||
|     pictures.append(picture); | ||||
|     QObject::connect(picWidget, SIGNAL(pictureDeleted()), this, SLOT(on_pictureDeleted())); | ||||
| } | ||||
| 
 | ||||
| void ProfileInterface::on_loadingProgress(int value, int maximum) | ||||
|  | @ -118,6 +121,14 @@ void ProfileInterface::on_profileLoaded() | |||
|     ui->cmdCloseProfile->setEnabled(true); | ||||
| } | ||||
| 
 | ||||
| void ProfileInterface::on_pictureDeleted() | ||||
| { | ||||
|     SnapmaticWidget *picWidget = (SnapmaticWidget*)sender(); | ||||
|     widgets.removeAll(picWidget); | ||||
|     picWidget->deleteLater(); | ||||
|     delete picWidget; | ||||
| } | ||||
| 
 | ||||
| void ProfileInterface::on_cmdCloseProfile_clicked() | ||||
| { | ||||
|     emit profileClosed(); | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ | |||
| #define PROFILEINTERFACE_H | ||||
| 
 | ||||
| #include "SnapmaticPicture.h" | ||||
| #include "SnapmaticWidget.h" | ||||
| #include "ProfileDatabase.h" | ||||
| #include "DatabaseThread.h" | ||||
| #include "ProfileLoader.h" | ||||
|  | @ -46,6 +47,7 @@ private slots: | |||
|     void on_pictureLoaded(SnapmaticPicture *picture, QString picturePath); | ||||
|     void on_savegameLoaded(SavegameData *savegame, QString savegamePath); | ||||
|     void on_loadingProgress(int value, int maximum); | ||||
|     void on_pictureDeleted(); | ||||
|     void on_profileLoaded(); | ||||
| 
 | ||||
| private: | ||||
|  |  | |||
|  | @ -39,6 +39,8 @@ bool SavegameData::readingSavegame() | |||
|     if (!saveFile->open(QFile::ReadOnly)) | ||||
|     { | ||||
|         lastStep = "1;/1,OpenFile," + convertDrawStringForLog(savegameFileName); | ||||
|         saveFile->deleteLater(); | ||||
|         delete saveFile; | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|  | @ -46,6 +48,9 @@ bool SavegameData::readingSavegame() | |||
|     if (!saveFile->isReadable()) | ||||
|     { | ||||
|         lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(savegameFileName) + ",1,NOHEADER"; | ||||
|         saveFile->close(); | ||||
|         saveFile->deleteLater(); | ||||
|         delete saveFile; | ||||
|         return false; | ||||
|     } | ||||
|     QByteArray savegameHeaderLine = saveFile->read(savegameHeaderLength); | ||||
|  | @ -58,6 +63,9 @@ bool SavegameData::readingSavegame() | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     saveFile->close(); | ||||
|     saveFile->deleteLater(); | ||||
|     delete saveFile; | ||||
|     return savegameOk; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -60,6 +60,8 @@ bool SnapmaticPicture::readingPicture() | |||
|     if (!picFile->open(QFile::ReadOnly)) | ||||
|     { | ||||
|         lastStep = "1;/1,OpenFile," + convertDrawStringForLog(picFileName); | ||||
|         picFile->deleteLater(); | ||||
|         delete picFile; | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|  | @ -67,6 +69,9 @@ bool SnapmaticPicture::readingPicture() | |||
|     if (!picFile->isReadable()) | ||||
|     { | ||||
|         lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",1,NOHEADER"; | ||||
|         picFile->close(); | ||||
|         picFile->deleteLater(); | ||||
|         delete picFile; | ||||
|         return false; | ||||
|     } | ||||
|     QByteArray snapmaticHeaderLine = picFile->read(snapmaticHeaderLength); | ||||
|  | @ -76,6 +81,9 @@ bool SnapmaticPicture::readingPicture() | |||
|     if (!picFile->isReadable()) | ||||
|     { | ||||
|         lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",2,NOHEADER"; | ||||
|         picFile->close(); | ||||
|         picFile->deleteLater(); | ||||
|         delete picFile; | ||||
|         return false; | ||||
|     } | ||||
|     QByteArray jpegHeaderLine = picFile->read(jpegPreHeaderLength); | ||||
|  | @ -85,6 +93,9 @@ bool SnapmaticPicture::readingPicture() | |||
|     if (jpegHeaderLine.left(4) != "JPEG") | ||||
|     { | ||||
|         lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",2,NOJPEG"; | ||||
|         picFile->close(); | ||||
|         picFile->deleteLater(); | ||||
|         delete picFile; | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|  | @ -92,6 +103,9 @@ bool SnapmaticPicture::readingPicture() | |||
|     if (!picFile->isReadable()) | ||||
|     { | ||||
|         lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",3,NOPIC"; | ||||
|         picFile->close(); | ||||
|         picFile->deleteLater(); | ||||
|         delete picFile; | ||||
|         return false; | ||||
|     } | ||||
|     QByteArray jpegRawContent = picFile->read(jpegPicStreamLength); | ||||
|  | @ -101,17 +115,26 @@ bool SnapmaticPicture::readingPicture() | |||
|     if (!picFile->isReadable()) | ||||
|     { | ||||
|         lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",3,NOJSON"; | ||||
|         picFile->close(); | ||||
|         picFile->deleteLater(); | ||||
|         delete picFile; | ||||
|         return picOk; | ||||
|     } | ||||
|     else if (picFile->read(4) != "JSON") | ||||
|     { | ||||
|         lastStep = "2;/3,ReadingFile," + convertDrawStringForLog(picFileName) + ",3,CTJSON"; | ||||
|         picFile->close(); | ||||
|         picFile->deleteLater(); | ||||
|         delete picFile; | ||||
|         return picOk; | ||||
|     } | ||||
|     QByteArray jsonRawContent = picFile->read(jsonStreamLength); | ||||
|     jsonStr = getSnapmaticJSONString(jsonRawContent); | ||||
|     parseJsonContent(); // JSON parsing is own function
 | ||||
| 
 | ||||
|     picFile->close(); | ||||
|     picFile->deleteLater(); | ||||
|     delete picFile; | ||||
|     return picOk; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -21,7 +21,10 @@ | |||
| #include "SnapmaticPicture.h" | ||||
| #include "DatabaseThread.h" | ||||
| #include "PictureDialog.h" | ||||
| #include <QMessageBox> | ||||
| #include <QPixmap> | ||||
| #include <QDebug> | ||||
| #include <QFile> | ||||
| 
 | ||||
| SnapmaticWidget::SnapmaticWidget(ProfileDatabase *profileDB, DatabaseThread *threadDB, QWidget *parent) : | ||||
|     QWidget(parent), profileDB(profileDB), threadDB(threadDB), | ||||
|  | @ -29,6 +32,7 @@ SnapmaticWidget::SnapmaticWidget(ProfileDatabase *profileDB, DatabaseThread *thr | |||
| { | ||||
|     ui->setupUi(this); | ||||
|     picPath = ""; | ||||
|     picStr = ""; | ||||
|     smpic = 0; | ||||
| } | ||||
| 
 | ||||
|  | @ -39,12 +43,14 @@ SnapmaticWidget::~SnapmaticWidget() | |||
| 
 | ||||
| void SnapmaticWidget::setSnapmaticPicture(SnapmaticPicture *picture, QString picturePath) | ||||
| { | ||||
|     QPixmap SnapmaticPixmap = QPixmap::fromImage(picture->getPicture(), Qt::AutoColor); | ||||
|     SnapmaticPixmap.scaled(ui->labPicture->width(), ui->labPicture->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); | ||||
|     ui->labPicStr->setText(picture->getPictureStr()); | ||||
|     ui->labPicture->setPixmap(SnapmaticPixmap); | ||||
|     smpic = picture; | ||||
|     picPath = picturePath; | ||||
|     picStr = picture->getPictureStr(); | ||||
| 
 | ||||
|     QPixmap SnapmaticPixmap = QPixmap::fromImage(picture->getPicture(), Qt::AutoColor); | ||||
|     SnapmaticPixmap.scaled(ui->labPicture->width(), ui->labPicture->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); | ||||
|     ui->labPicStr->setText(picStr); | ||||
|     ui->labPicture->setPixmap(SnapmaticPixmap); | ||||
| } | ||||
| 
 | ||||
| void SnapmaticWidget::on_cmdView_clicked() | ||||
|  | @ -63,3 +69,24 @@ void SnapmaticWidget::on_cmdView_clicked() | |||
|     picDialog->deleteLater(); | ||||
|     delete picDialog; | ||||
| } | ||||
| 
 | ||||
| void SnapmaticWidget::on_cmdDelete_clicked() | ||||
| { | ||||
|     int uchoice = QMessageBox::question(this, tr("Delete picture"), tr("You're sure to delete %1 from your Snapmatic pictures?").arg(picStr), QMessageBox::No | QMessageBox::Yes, QMessageBox::No); | ||||
|     if (uchoice == QMessageBox::Yes) | ||||
|     { | ||||
|         QFile pictureFile(picPath); | ||||
|         if (!pictureFile.exists()) | ||||
|         { | ||||
|             emit pictureDeleted(); | ||||
|         } | ||||
|         else if(QFile::remove(picPath)) | ||||
|         { | ||||
|             emit pictureDeleted(); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             QMessageBox::warning(this, tr("Delete picture"), tr("Failed at deleting %1 from your Snapmatic pictures").arg(picStr)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -39,6 +39,7 @@ public: | |||
| 
 | ||||
| private slots: | ||||
|     void on_cmdView_clicked(); | ||||
|     void on_cmdDelete_clicked(); | ||||
| 
 | ||||
| private: | ||||
|     ProfileDatabase *profileDB; | ||||
|  | @ -46,6 +47,10 @@ private: | |||
|     Ui::SnapmaticWidget *ui; | ||||
|     SnapmaticPicture *smpic; | ||||
|     QString picPath; | ||||
|     QString picStr; | ||||
| 
 | ||||
| signals: | ||||
|     void pictureDeleted(); | ||||
| }; | ||||
| 
 | ||||
| #endif // SNAPMATICWIDGET_H
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue