nextcloud-desktop/OwnCloudSync.h
Juan Carlos Cornejo 18d32bda91 Major bugfixes.
1) Fixed a bug that prevented directories on the server to be properly
deleted.

2) Fixed a bug that would cause files and directories to be deleted
often, and then re-uploaded. This was due to a missing comparison.

3) Serialized the directory creation, making sure that it was successful
before trying to create the next one, which may have been a
subdirectory.

4) Fixed the issue with the GUI freezing when it was waiting for a sync
to happen if the user tried to quit.

5) Fixed an issue that if a directory existed with the same Remote or
Local directory name, weird stuff would happen! This was due to an
incorrect comparison.

6) Fixed the issue where the system tray icon would not change when a
conflict occurred. (Apparently I had accidentally removed this when I
made the change to multiple accounts).

7) Added two new buttons to clear the log and clear & save the log.
Useful when debugging :) But useful in general, I suppose.

Possibly some other fixes, but now I forget them exactly. Probably just
some lost pointers and the like that I found :)
2012-02-15 08:55:13 +01:00

215 lines
6.5 KiB
C++

/******************************************************************************
* Copyright 2011 Juan Carlos Cornejo jc2@paintblack.com
*
* This file is part of owncloud_sync.
*
* owncloud_sync is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* owncloud_sync is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with owncloud_sync. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#ifndef OWNCLOUDSYNC_H
#define OWNCLOUDSYNC_H
#include <QMainWindow>
#include "QWebDAV.h"
#include <QSqlDatabase>
#include <QQueue>
#include <QSystemTrayIcon>
#include <QIcon>
#include <QSet>
#include <QSqlQuery>
class QTimer;
class QFileSystemWatcher;
#ifdef Q_OS_LINUX
#include <kde4/kwallet.h>
#endif
class OwnCloudSync : public QObject
{
Q_OBJECT
public:
explicit OwnCloudSync(QString name, WId id);
~OwnCloudSync();
void initialize(QString host, QString user, QString pass, QString remote,
QString local, qint64 time);
struct FileInfo {
QString name;
qint64 size;
FileInfo(QString fileName, qint64 fileSize) {
name = fileName;
size = fileSize;
}
};
enum SyncPosition {
SYNCFINISHED,
CHECKSETTINGS,
LISTREMOTEDIR,
LISTLOCALDIR,
TRANSFER
};
QSqlQuery getConflicts() {
QSqlQuery query(QSqlDatabase::database(mAccountName));
query.exec("SELECT * from conflicts;");
return query;
};
QString getName() { return mAccountName; }
QString getHost() { return mHost; }
QString getUserName() { return mUsername; }
QString getPassword() { return mPassword; }
QString getRemoteDirectory() { return mRemoteDirectory; }
QString getLocalDirectory() { return mLocalDirectory; }
qint64 getUpdateTime() { return mUpdateTime; }
bool isEnabled() { return mIsEnabled; }
void setEnabled(bool enabled);
void saveConfigToDB();
void processFileConflict(QString name, QString wins);
bool needsSync();
void deleteWatcher();
void stop();
QString getLastSync();
QStringList getFilterList();
void addFilter(QString filter);
void removeFilter(QString filter);
void hardStop();
void deleteAccount();
private:
WId mWinId;
QWebDAV *mWebdav;
bool mIsEnabled;
bool mAllowedToSync;
bool mNeedsSync;
bool mNotifySyncEmitted;
bool mHardStop;
QSet<QString> mFilters;
QString mLastSync;
QSqlDatabase mDB;
QString mDBFileName;
QQueue<QString> mDirectoryQueue;
QString mHomeDirectory;
QString mRemoteDirectory;
QString mLocalDirectory;
QString mConfigDirectory;
QString mHost;
QString mPassword;
QString mUsername;
QTimer *mSyncTimer;
QTimer *mSaveDBTimer;
QTimer *mRequestTimer;
QQueue<QString> mMakeServerDirs;
QQueue<FileInfo> mUploadingFiles;
QQueue<FileInfo> mDownloadingFiles;
QQueue<FileInfo> mDownloadConflict;
QQueue<FileInfo> mUploadingConflictFiles;
qint64 mTotalToDownload;
qint64 mTotalToUpload;
qint64 mTotalToTransfer;
qint64 mTotalTransfered;
qint64 mTotalDownloaded;
qint64 mTotalUploaded;
qint64 mCurrentFileSize;
QString mCurrentFile;
QString mTransferState;
bool mBusy;
bool mDBOpen;
qint64 mUpdateTime;
QFileSystemWatcher *mFileWatcher;
bool mIsFirstRun;
bool mDownloadingConflictingFile;
QSet<QString> mScanDirectoriesSet;
QQueue<QString> mScanDirectories;
QSet<QString> mUploadingConflictFilesSet;
bool mFileAccessBusy;
bool mConflictsExist;
bool mSettingsCheck;
QString mAccountName;
SyncPosition mLastSyncAborted;
SyncPosition mSyncPosition;
#ifdef Q_OS_LINUX
KWallet::Wallet *mWallet;
void saveWalletPassword();
void requestPassword();
#endif
bool mReadPassword;
void updateDBLocalFile(QString name,qint64 size,qint64 last,QString type);
void scanLocalDirectory(QString dirPath);
QSqlQuery queryDBFileInfo(QString fileName, QString table);
QSqlQuery queryDBAllFiles(QString table);
void syncFiles();
void upload(FileInfo fileName);
void download(FileInfo fileName);
void updateDBDownload(QString fileName);
void processNextStep();
void createDataBase();
void initialize();
void readConfigFromDB();
void scanLocalDirectoryForNewFiles(QString name);
void processLocalFile(QString name);
void deleteRemovedFiles();
void deleteFromLocal(QString name, bool isDir);
void deleteFromServer(QString name);
void dropFromDB(QString table, QString column, QString condition );
void setFileConflict(QString name, qint64 size, QString server_last,
QString local_last);
void clearFileConflict(QString name);
QString getConflictName(QString name);
void settingsAreFine();
void start();
bool isFileFiltered(QString name);
void restartRequestTimer();
void stopRequestTimer();
// String manipulation functions
QString stringRemoveBasePath(QString path, QString base);
signals:
void toLog(QString text);
void toStatus(QString text);
void toMessage(QString caption, QString body,
QSystemTrayIcon::MessageIcon icon);
void conflictExists(OwnCloudSync*);
void conflictResolved(OwnCloudSync*);
void progressFile(qint64 value);
void progressTotal(qint64 value);
void readyToSync(OwnCloudSync*);
void finishedSync(OwnCloudSync*);
public slots:
void directoryListingError(QString url);
void processDirectoryListing(QList<QWebDAV::FileInfo> fileInfo);
void processFileReady(QByteArray data,QString fileName);
void updateDBUpload(QString fileName);
void timeToSync();
void sync();
void updateStatus();
void transferProgress(qint64 current,qint64 total);
void localFileChanged(QString name);
void localDirectoryChanged(QString name);
void saveDBToFile();
void loadDBFromFile();
void requestTimedout();
void serverDirectoryCreated(QString name);
//#ifdef Q_OS_LINUX
void walletOpened(bool);
//#endif
};
#endif // OWNCLOUDSYNC_H