diff --git a/resources/etc/OpenBoard.config b/resources/etc/OpenBoard.config index 7a261d40..6e85db95 100644 --- a/resources/etc/OpenBoard.config +++ b/resources/etc/OpenBoard.config @@ -93,6 +93,8 @@ SortOrder=0 SplitterLeftSize=200 SplitterRightSize=800 ShowDateColumnOnAlphabeticalSort=false +emptyTrashForOlderDocuments=true +emptyTrashDaysValue=30 [IntranetPodcast] Author= diff --git a/resources/forms/preferences.ui b/resources/forms/preferences.ui index 602f7ead..6fdf3936 100644 --- a/resources/forms/preferences.ui +++ b/resources/forms/preferences.ui @@ -7,7 +7,7 @@ 0 0 825 - 748 + 767 @@ -552,7 +552,7 @@ Documents Mode - + @@ -567,24 +567,54 @@ - - - - Qt::Horizontal - - - QSizePolicy::Fixed + + + + Empty trash for documents older than - - - 40 - 20 - + + + + + + + + + days - + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp index 194ea6e4..60d8f26f 100644 --- a/src/core/UBApplication.cpp +++ b/src/core/UBApplication.cpp @@ -451,6 +451,12 @@ void UBApplication::closeEvent(QCloseEvent *event) void UBApplication::closing() { + if (UBSettings::settings()->emptyTrashForOlderDocuments->get().toBool()) + { + UBDocumentTreeModel *docModel = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel; + documentController->deleteDocumentsInFolderOlderThan(docModel->trashIndex(), UBSettings::settings()->emptyTrashDaysValue->get().toInt()); + documentController->deleteEmptyFolders(docModel->trashIndex()); + } if (boardController) boardController->closing(); diff --git a/src/core/UBPreferencesController.cpp b/src/core/UBPreferencesController.cpp index b536ea1e..9ecceeec 100644 --- a/src/core/UBPreferencesController.cpp +++ b/src/core/UBPreferencesController.cpp @@ -138,8 +138,12 @@ void UBPreferencesController::wire() connect(mPreferencesUI->useSystemOSKCheckBox, SIGNAL(clicked(bool)), settings->useSystemOnScreenKeyboard, SLOT(setBool(bool))); connect(mPreferencesUI->useSystemOSKCheckBox, SIGNAL(clicked(bool)), this, SLOT(systemOSKCheckBoxToggled(bool))); + // Documents Mode preferences connect(mPreferencesUI->showDateColumnOnAlphabeticalSort, SIGNAL(clicked(bool)), settings->showDateColumnOnAlphabeticalSort, SLOT(setBool(bool))); connect(mPreferencesUI->showDateColumnOnAlphabeticalSort, SIGNAL(clicked(bool)), UBApplication::documentController, SLOT(refreshDateColumns())); + connect(mPreferencesUI->emptyTrashForOlderDocuments, SIGNAL(clicked(bool)), settings->emptyTrashForOlderDocuments, SLOT(setBool(bool))); + connect(mPreferencesUI->emptyTrashDaysValue, SIGNAL(valueChanged(int)), settings->emptyTrashDaysValue, SLOT(setInt(int))); + connect(mPreferencesUI->keyboardPaletteKeyButtonSize, SIGNAL(currentIndexChanged(const QString &)), settings->boardKeyboardPaletteKeyBtnSize, SLOT(setString(const QString &))); connect(mPreferencesUI->startModeComboBox, SIGNAL(currentIndexChanged(int)), settings->appStartMode, SLOT(setInt(int))); @@ -279,6 +283,8 @@ void UBPreferencesController::init() this->systemOSKCheckBoxToggled(mPreferencesUI->useSystemOSKCheckBox->isChecked()); mPreferencesUI->showDateColumnOnAlphabeticalSort->setChecked(settings->showDateColumnOnAlphabeticalSort->get().toBool()); + mPreferencesUI->emptyTrashForOlderDocuments->setChecked(settings->emptyTrashForOlderDocuments->get().toBool()); + mPreferencesUI->emptyTrashDaysValue->setValue(settings->emptyTrashDaysValue->get().toInt()); mPreferencesUI->startModeComboBox->setCurrentIndex(settings->appStartMode->get().toInt()); @@ -344,8 +350,13 @@ void UBPreferencesController::defaultSettings() mPreferencesUI->startModeComboBox->setCurrentIndex(0); mPreferencesUI->useSystemOSKCheckBox->setChecked(settings->useSystemOnScreenKeyboard->reset().toBool()); + mPreferencesUI->showDateColumnOnAlphabeticalSort->setChecked(settings->showDateColumnOnAlphabeticalSort->reset().toBool()); UBApplication::documentController->refreshDateColumns(); + + mPreferencesUI->emptyTrashForOlderDocuments->setChecked(settings->emptyTrashForOlderDocuments->reset().toBool()); + mPreferencesUI->emptyTrashDaysValue->setValue(settings->emptyTrashDaysValue->reset().toInt()); + } else if (mPreferencesUI->mainTabWidget->currentWidget() == mPreferencesUI->penTab) { diff --git a/src/core/UBSettings.cpp b/src/core/UBSettings.cpp index 557b3c65..5d5cb705 100644 --- a/src/core/UBSettings.cpp +++ b/src/core/UBSettings.cpp @@ -459,6 +459,8 @@ void UBSettings::init() useSystemOnScreenKeyboard = new UBSetting(this, "App", "UseSystemOnScreenKeyboard", true); showDateColumnOnAlphabeticalSort = new UBSetting(this, "Document", "ShowDateColumnOnAlphabeticalSort", false); + emptyTrashForOlderDocuments = new UBSetting(this, "Document", "emptyTrashForOlderDocuments", true); + emptyTrashDaysValue = new UBSetting(this, "Document", "emptyTrashDaysValue", 30); cleanNonPersistentSettings(); checkNewSettings(); diff --git a/src/core/UBSettings.h b/src/core/UBSettings.h index 5ba97c93..a5e6d109 100644 --- a/src/core/UBSettings.h +++ b/src/core/UBSettings.h @@ -415,6 +415,9 @@ class UBSettings : public QObject UBSetting* showDateColumnOnAlphabeticalSort; + UBSetting* emptyTrashForOlderDocuments; + UBSetting* emptyTrashDaysValue; + UBSetting* magnifierDrawingMode; UBSetting* autoSaveInterval; diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 1bf2ebc9..bfef2848 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -762,6 +762,31 @@ bool UBDocumentTreeModel::removeRows(int row, int count, const QModelIndex &pare return true; } +bool UBDocumentTreeModel::containsDocuments(const QModelIndex &index) +{ + for (int i = 0; i < rowCount(index); i++) + { + QModelIndex child = this->index(i, 0, index); + if (isCatalog(child)) + { + if (containsDocuments(child)) + { + return true; + } + } + else if (isDocument(child)) + { + return true; + } + else + { + qDebug() << "Who the hell are you ?"; + } + } + + return false; +} + QModelIndex UBDocumentTreeModel::indexForNode(UBDocumentTreeNode *pNode) const { if (pNode == 0) { @@ -2054,7 +2079,6 @@ void UBDocumentController::setupViews() } } -//N/C - NNE - 20140403 void UBDocumentController::refreshDateColumns() { if (UBSettings::settings()->documentSortKind->get().toInt() == UBDocumentController::Alphabetical) @@ -2602,6 +2626,69 @@ void UBDocumentController::moveToTrash(QModelIndex &index, UBDocumentTreeModel* } //issue 1629 - NNE - 20131212 : END +void UBDocumentController::deleteDocumentsInFolderOlderThan(const QModelIndex &index, const int days) +{ + UBDocumentTreeModel *docModel = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel; + + QModelIndexList list; + for (int i = 0; i < docModel->rowCount(index); i++) + { + list << docModel->index(i, 0, index); + } + + foreach (QModelIndex child, list) + { + UBDocumentProxy *documentProxy= docModel->proxyForIndex(child); + + if (documentProxy) + { + if (documentProxy->lastUpdate() < QDateTime::currentDateTime().addDays(-days)) + { + deleteIndexAndAssociatedData(child); + } + } + else + { + if (docModel->isCatalog(child)) + { + deleteDocumentsInFolderOlderThan(child, days); + } + } + } +} + +void UBDocumentController::deleteEmptyFolders(const QModelIndex &index) +{ + UBDocumentTreeModel *docModel = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel; + + QModelIndexList list; + for (int i = 0; i < docModel->rowCount(index); i++) + { + list << docModel->index(i, 0, index); + } + + if (list.length() > 0) + { + foreach (QModelIndex child, list) + { + if (docModel->isCatalog(child)) + { + if (!docModel->containsDocuments(child)) + { + deleteIndexAndAssociatedData(child); + } + } + } + } + else + { + if (docModel->isCatalog(index)) + { + deleteIndexAndAssociatedData(index); + } + } +} + void UBDocumentController::emptyFolder(const QModelIndex &index, DeletionType pDeletionType) { // Issue NC - CFA - 20131029 : ajout d'une popup de confirmation pour la suppression definitive diff --git a/src/document/UBDocumentController.h b/src/document/UBDocumentController.h index c2afaa84..88ed74b2 100644 --- a/src/document/UBDocumentController.h +++ b/src/document/UBDocumentController.h @@ -187,6 +187,8 @@ public: bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); bool removeRows(int row, int count, const QModelIndex &parent); + bool containsDocuments(const QModelIndex& index); + QModelIndex indexForNode(UBDocumentTreeNode *pNode) const; QPersistentModelIndex persistentIndexForNode(UBDocumentTreeNode *pNode); // bool insertRow(int row, const QModelIndex &parent); @@ -414,6 +416,9 @@ class UBDocumentController : public UBDocumentContainer */ void moveToTrash(QModelIndex &index, UBDocumentTreeModel* docModel); + void deleteDocumentsInFolderOlderThan(const QModelIndex &index, const int days); + void deleteEmptyFolders(const QModelIndex &index); + QModelIndex mapIndexToSource(const QModelIndex &index); QModelIndexList mapIndexesToSource(const QModelIndexList &indexes);