5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef PROCESS_SYNC_H
22 #define PROCESS_SYNC_H
28 #include <QDirIterator>
29 #include <QReadWriteLock>
33 class SyncProcess
: public QObject
46 enum SyncCompareType
{
47 OVERWR_NEWER_IF_DIFF
= 0,
52 Q_ENUM(SyncCompareType
)
57 OPT_SKIP_EMPTY_DIR
= 0x02,
59 OPT_SKIP_DIR_LINKS
= 0x08
61 Q_DECLARE_FLAGS(SyncOptionFlags
, SyncOptionFlag
)
62 Q_FLAG(SyncOptionFlags
)
64 // TODO: perhaps move this to AppData/saved settings once that refactoring is merged.
66 explicit SyncOptions() { reset(); }
70 QString excludeFilter
; // CSV list of glob pattern(s)
71 QString includeFilter
; // CSV list of glob pattern(s)
72 qint64 maxFileSize
; // Bytes
73 int direction
; // SyncDirection
74 int compareType
; // SyncCompareType
75 int flags
; // SyncOptionFlags
76 int dirFilterFlags
; // QDir::Filters
77 int logLevel
; // QtMsgType (see ProgressWidget::addMessage())
81 excludeFilter
= QStringLiteral(".*,System Volume*");
82 includeFilter
.clear();
83 direction
= SYNC_A2B_B2A
;
84 compareType
= OVERWR_NEWER_IF_DIFF
;
85 maxFileSize
= 2 * 1024 * 1024;
86 logLevel
= QtWarningMsg
;
87 flags
= OPT_RECURSIVE
;
88 dirFilterFlags
= QDir::Dirs
| QDir::Files
| QDir::NoDotAndDotDot
| QDir::Readable
;
91 friend inline QDebug
operator<<(QDebug debug
, const SyncOptions
&o
) {
92 return debug
<< "Incl:" << o
.includeFilter
<< "Excl:" << o
.excludeFilter
<< SyncDirection(o
.direction
) << SyncCompareType(o
.compareType
) << SyncOptionFlags(o
.flags
) << QDir::Filters(o
.dirFilterFlags
);
103 void clear() { memset(this, 0, sizeof(SyncStatus
)); }
106 explicit SyncProcess(const SyncOptions
& options
);
116 void fileCountChanged(int count
);
117 void statusUpdate(const SyncProcess::SyncStatus
& status
);
118 void statusMessage(const QString
& text
, const int & type
= QtInfoMsg
);
119 void progressMessage(const QString
& text
, const int & type
= QtInfoMsg
, bool richText
= false);
122 enum FileFilterResult
{ FILE_ALLOW
, FILE_OVERSIZE
, FILE_EXCLUDE
, FILE_LINK_IGNORE
};
124 bool isStopRequsted();
126 FileFilterResult
fileFilter(const QFileInfo
& fileInfo
);
127 QFileInfoList
dirInfoList(const QString
& directory
);
128 int getFilesCount(const QString
& directory
);
129 void updateDir(const QString
& source
, const QString
& destination
);
130 void pushDirEntries(const QFileInfo
& fi
, QMutableListIterator
<QFileInfo
> &it
);
131 bool updateEntry(const QString
& entry
, const QDir
& source
, const QDir
& destination
);
133 void emitProgressMessage(const QString
&text
, int type
);
135 SyncOptions m_options
;
137 QReadWriteLock stopReqMutex
;
139 QVector
<QRegExp
> m_excludeFilters
;
140 QStringList m_dirIteratorFilters
;
141 QDir::Filters m_dirFilters
;
142 QDateTime m_startTime
;
143 unsigned long m_pauseTime
;
147 Q_DECLARE_METATYPE(SyncProcess::SyncOptions
)
148 Q_DECLARE_TYPEINFO(SyncProcess::SyncOptions
, Q_MOVABLE_TYPE
);
149 Q_DECLARE_METATYPE(SyncProcess::SyncStatus
)
150 Q_DECLARE_TYPEINFO(SyncProcess::SyncStatus
, Q_PRIMITIVE_TYPE
);
152 #endif // PROCESS_SYNC_H