From c653a203ded2b6c26444ea7815a59f599d91736d Mon Sep 17 00:00:00 2001 From: Juan Carlos Cornejo Date: Tue, 13 Dec 2011 19:11:35 -0500 Subject: [PATCH] Implemented a global included list. This list are common temporary and lock files that should be ignored. The user can enable and disable them if they so wish. Additionally, set the ground for a later inclusion of a global list, which the user enters and applies to all accounts. --- owncloud_sync_qt/OwnCloudSync.cpp | 7 +- owncloud_sync_qt/OwnCloudSync.h | 3 +- owncloud_sync_qt/SyncWindow.cpp | 97 ++++++++++- owncloud_sync_qt/SyncWindow.h | 47 ++++++ owncloud_sync_qt/SyncWindow.ui | 265 +++++++++++++++++++++++++++++- 5 files changed, 407 insertions(+), 12 deletions(-) diff --git a/owncloud_sync_qt/OwnCloudSync.cpp b/owncloud_sync_qt/OwnCloudSync.cpp index 51dc58c7a..62eeee2c0 100644 --- a/owncloud_sync_qt/OwnCloudSync.cpp +++ b/owncloud_sync_qt/OwnCloudSync.cpp @@ -39,7 +39,8 @@ #include #endif -OwnCloudSync::OwnCloudSync(QString name, WId id) : mAccountName(name),mWinId(id) +OwnCloudSync::OwnCloudSync(QString name, WId id,QSet *globalFilters) + : mAccountName(name),mWinId(id),mGlobalFilters(globalFilters) { mBusy = false; mIsPaused = false; @@ -1527,9 +1528,11 @@ bool OwnCloudSync::isFileFiltered(QString name) return true; } QList list = mFilters.toList(); + list.append( mGlobalFilters->toList() ); + syncDebug() << "Will check a total of " << list.size() << " filters"; // Else, look through the filters and see if this file is excluded - for( int i = 0; i < mFilters.size(); i++ ) { + for( int i = 0; i < list.size(); i++ ) { QString filter = list[i]; if(filter.contains("*")) { // Must build general expression filter.replace("?","\\\?"); diff --git a/owncloud_sync_qt/OwnCloudSync.h b/owncloud_sync_qt/OwnCloudSync.h index 7497a51cb..aec9a0cb1 100644 --- a/owncloud_sync_qt/OwnCloudSync.h +++ b/owncloud_sync_qt/OwnCloudSync.h @@ -41,7 +41,7 @@ class OwnCloudSync : public QObject Q_OBJECT public: - explicit OwnCloudSync(QString name, WId id); + explicit OwnCloudSync(QString name, WId id, QSet *globalFilters); ~OwnCloudSync(); void initialize(QString host, QString user, QString pass, QString remote, QString local, qint64 time); @@ -107,6 +107,7 @@ private: bool mNotifySyncEmitted; bool mHardStop; QSet mFilters; + QSet *mGlobalFilters; QString mLastSync; QSqlDatabase mDB; QString mDBFileName; diff --git a/owncloud_sync_qt/SyncWindow.cpp b/owncloud_sync_qt/SyncWindow.cpp index 0d9f352ba..dffa768ce 100644 --- a/owncloud_sync_qt/SyncWindow.cpp +++ b/owncloud_sync_qt/SyncWindow.cpp @@ -51,6 +51,8 @@ SyncWindow::SyncWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::SyncWindow) { + mSharedFilters = new QSet(); + mIncludedFilters = g_GetIncludedFilterList(); mQuitAction = false; mBusy = false; ui->setupUi(this); @@ -58,6 +60,7 @@ SyncWindow::SyncWindow(QWidget *parent) : mEditingConfig = -1; mConflictsExist = false; loadApplicationSettings(); + updateSharedFilterList(); // Before anything else, connect to the SyncDebug connect(getSyncDebug(),SIGNAL(debugMessage(const QString)), @@ -87,6 +90,8 @@ SyncWindow::SyncWindow(QWidget *parent) : // Start with the default tab ui->stackedWidget->setCurrentIndex(0); ui->listFilterView->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui->listIncludedFilterView->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui->listGlobalFilterView->setEditTriggers(QAbstractItemView::NoEditTriggers); // Create the Accounts SignalMapper mAccountsSignalMapper = new QSignalMapper(this); @@ -216,7 +221,7 @@ void SyncWindow::systemTrayActivated(QSystemTrayIcon::ActivationReason reason) OwnCloudSync* SyncWindow::addAccount(QString name) { - OwnCloudSync *account = new OwnCloudSync(name,winId()); + OwnCloudSync *account = new OwnCloudSync(name,winId(),mSharedFilters); mAccounts.append(account); mAccountNames.append(name); @@ -621,11 +626,11 @@ void SyncWindow::editConfig(int row) void SyncWindow::listFilters(int row) { if(row<0) { - // Show the filters list + // Show an empty filter list ui->listFilterView->setModel( new QStringListModel()); } else { - // Show the filters list + // Show the filter list ui->listFilterView->setModel( new QStringListModel(mAccounts[row]->getFilterList())); // Create the filterView signals @@ -709,6 +714,15 @@ void SyncWindow::saveApplicationSettings() ui->actionClose_Button_Hides_Window->isChecked()); settings.setValue("display_debug",mDisplayDebug); settings.endGroup(); + settings.beginGroup("DisabledIncludedFilters"); + for(int i = 0; i < mIncludedFilters.size(); i++ ) { + if( !mIncludedFilters[i].enabled ) { + settings.setValue(mIncludedFilters[i].name,true); + } else { + settings.remove(mIncludedFilters[i].name); + } + } + settings.endGroup(); } void SyncWindow::loadApplicationSettings() @@ -722,6 +736,12 @@ void SyncWindow::loadApplicationSettings() mDisplayDebug = settings.value("display_debug").toBool(); ui->actionDisplay_Debug_Messages->setChecked(mDisplayDebug); settings.endGroup(); + settings.beginGroup("DisabledIncludedFilters"); + for(int i = 0; i < mIncludedFilters.size(); i++ ) { + mIncludedFilters[i].enabled = + !settings.value(mIncludedFilters[i].name).toBool(); + } + settings.endGroup(); } void SyncWindow::on_actionEnable_Delete_Account_triggered() @@ -803,3 +823,74 @@ void SyncWindow::on_buttonPause_clicked() ui->buttonResume->setEnabled(true); ui->textBrowser->append(tr("Pausing...")); } + +void SyncWindow::on_actionConfigure_triggered() +{ + ui->stackedWidget->setCurrentIndex(3); + ui->listIncludedFilterView->clear(); + QListWidgetItem *item; + for( int i = 0; i < mIncludedFilters.size(); i++ ) { + item = new QListWidgetItem(mIncludedFilters[i].filter+ + " [" + mIncludedFilters[i].description + "]", + ui->listIncludedFilterView,i); + if( mIncludedFilters[i].canBeDisabled ) { + if ( mIncludedFilters[i].enabled ) { + item->setCheckState(Qt::Checked); + } else { + item->setCheckState(Qt::Unchecked); + } + } else { + item->setFlags(Qt::NoItemFlags); + } + } + connect(ui->listIncludedFilterView,SIGNAL(itemChanged(QListWidgetItem *)), + this,SLOT(includedFilterListItemChanged(QListWidgetItem*))); +} + +void SyncWindow::includedFilterListItemChanged(QListWidgetItem *item) +{ + if(item->checkState() == Qt::Checked ) { + mIncludedFilters[item->type()].enabled = true; + } else { + mIncludedFilters[item->type()].enabled = false; + } + updateSharedFilterList(); +// syncDebug() << "Item changed: " << mIncludedFilters[item->type()].name +// << "State: " << item->checkState() << " Enabled?: " << +// mIncludedFilters[item->type()].enabled; +} + +void SyncWindow::on_buttonEnableAllIncludedFilters_clicked() +{ + for(int i = 0; ilistIncludedFilterView->item(i)->setCheckState(Qt::Checked); + } + } + updateSharedFilterList(); +} + +void SyncWindow::on_buttonDisableAllIncludedFilters_clicked() +{ + for(int i = 0; ilistIncludedFilterView->item(i)->setCheckState(Qt::Unchecked); + } + } + updateSharedFilterList(); +} + +void SyncWindow::updateSharedFilterList() +{ + mSharedFilters->clear(); + for(int i = 0; i < mIncludedFilters.size(); i++ ) { + if(mIncludedFilters[i].enabled) + mSharedFilters->insert(mIncludedFilters[i].filter); + } +} + + +void SyncWindow::on_buttonReturn_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); +} diff --git a/owncloud_sync_qt/SyncWindow.h b/owncloud_sync_qt/SyncWindow.h index 104475ad6..a5a920c6d 100644 --- a/owncloud_sync_qt/SyncWindow.h +++ b/owncloud_sync_qt/SyncWindow.h @@ -33,11 +33,29 @@ class QTimer; class OwnCloudSync; class QSignalMapper; class QMenu; +class QListWidgetItem; namespace Ui { class SyncWindow; } +struct SyncIncludedFilterList { + QString name; // No spaces, must be unique! + QString filter; + QString description; + bool enabled; + bool canBeDisabled; + SyncIncludedFilterList(QString Name, QString Filter, + QString Description, + bool Disable = false) + { + name = Name; + filter = Filter; + description = Description; + canBeDisabled = Disable; + } +}; + class SyncWindow : public QMainWindow { Q_OBJECT @@ -45,9 +63,11 @@ class SyncWindow : public QMainWindow public: explicit SyncWindow(QWidget *parent = 0); ~SyncWindow(); + QSet *mSharedFilters; private: Ui::SyncWindow *ui; + QList mIncludedFilters; QSystemTrayIcon *mSystemTray; QMenu *mSystemTrayMenu; QList mAccounts; @@ -89,6 +109,7 @@ private: void saveApplicationSettings(); void loadApplicationSettings(); void deleteAccount(); + void updateSharedFilterList(); public slots: //void timeToSync(); @@ -101,6 +122,7 @@ public slots: QItemSelection deselected); void slotAccountsSignalMapper(int row); void processDebugMessage(const QString msg); + void includedFilterListItemChanged(QListWidgetItem* item); // GUI related slots void on_buttonSave_clicked(); @@ -133,6 +155,7 @@ public slots: void slotFinishedSync(OwnCloudSync*); void slotToMessage(QString caption, QString body, QSystemTrayIcon::MessageIcon icon); + private slots: void on_action_Quit_triggered(); void on_actionEnable_Delete_Account_triggered(); @@ -143,6 +166,30 @@ private slots: void on_actionDisplay_Debug_Messages_toggled(bool arg1); void on_buttonResume_clicked(); void on_buttonPause_clicked(); + void on_actionConfigure_triggered(); + void on_buttonEnableAllIncludedFilters_clicked(); + void on_buttonDisableAllIncludedFilters_clicked(); + void on_buttonReturn_clicked(); }; +// Now create a global filter list +inline QList g_GetIncludedFilterList() +{ + QList list; + // VIM + list.append(SyncIncludedFilterList("vim_tmp",".*.swp","Vim temporary file",true)); + list.append(SyncIncludedFilterList("vim_tmp2",".*.swo","Vim temporary binary file",true)); + + // LibreOffice/OpenOffice lock files + list.append(SyncIncludedFilterList("libreoffice_lock",".~lock.*#","LibreOffice/OpenOffice lock files",true)); + + // General temporary files that I know of + list.append(SyncIncludedFilterList("tmp1","~*","General Temporary Files",true)); + list.append(SyncIncludedFilterList("android_syncfolders","*.tacit.fs.part","Android Folder Sync temporary file",true)); + + // Internal Files (User cannot disable!!) + list.append(SyncIncludedFilterList("ocs_conflict",".ocs_conflicting.*","Internal Conflict Resolution File",false)); + return list; +} + #endif // SYNCWINDOW_H diff --git a/owncloud_sync_qt/SyncWindow.ui b/owncloud_sync_qt/SyncWindow.ui index aafc1afd9..c10958dc5 100644 --- a/owncloud_sync_qt/SyncWindow.ui +++ b/owncloud_sync_qt/SyncWindow.ui @@ -14,14 +14,14 @@ SyncWindow - - + + 0 - 0 + 3 @@ -619,6 +619,252 @@ p, li { white-space: pre-wrap; } + + + + 0 + + + + + Return to Main Window + + + false + + + false + + + false + + + + + + + false + + + + 16777215 + 16777215 + + + + 0 + + + + false + + + Configure + + + + + + + + + Save database every + + + + + + + seconds. + + + + + + + Save and clear log every + + + + + + + + + + syncs. + + + + + + + + Global Filters + + + + + + Qt::Vertical + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Here you may add any filters that will be applied to <span style=" font-weight:600;">all</span> accounts. Additionally, on the right you may enable or disable the list of included filters. Some may not be disabled, as they are required for the program to function. They will be shown with the checkbox permanently checked. You may also export and import the global list you created. The included filters cannot be exported nor imported. They are built into the program. The only wildcard supported is *. Examples: .*.swp will exclude all temporary VIM files.</p></body></html> + + + + + QFrame::NoFrame + + + QFrame::Raised + + + 0 + + + + 0 + + + + + Qt::Horizontal + + + 5 + + + + false + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + + + + false + + + Insert + + + + + + + false + + + Remove + + + + + + + false + + + Export/Import + + + + + + + + + + + + + Add Filter: + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + 0 + + + + + + + + + Disable All + + + + + + + Enable All + + + + + + + Included Filters: + + + + + + + + + + + + + + + + + @@ -636,7 +882,7 @@ p, li { white-space: pre-wrap; } Program - + @@ -677,9 +923,16 @@ p, li { white-space: pre-wrap; } - + + + + :/images/owncloud.png:/images/owncloud.png + - Global Filters + Configure + + + Configure