diff --git a/src/cloudsync.cpp b/src/cloudsync.cpp index 9544262..03ad844 100644 --- a/src/cloudsync.cpp +++ b/src/cloudsync.cpp @@ -1,6 +1,8 @@ /* * cloudsync.cpp * + * This contains the implementation of the status notifier (tray icon) class. + * * Copyright (C) 2010 Martin T. Sandsmark */ diff --git a/src/cloudsync.h b/src/cloudsync.h index 8787a85..339214b 100644 --- a/src/cloudsync.h +++ b/src/cloudsync.h @@ -1,6 +1,8 @@ /* * cloudsync.h * + * This contains the declaration of the status notifier (tray icon) class. + * * Copyright (C) 2010 Martin T. Sandsmark */ diff --git a/src/dirsyncer.cpp b/src/dirsyncer.cpp index 5d7df1e..fad5d4a 100644 --- a/src/dirsyncer.cpp +++ b/src/dirsyncer.cpp @@ -1,11 +1,15 @@ /* - * cloudsync.h + * dirsyncer.cpp + * + * This contains the implementation of the class that is responsible for + * synchronising two directories. * * Copyright (C) 2010 Martin T. Sandsmark */ #include "dirsyncer.h" #include "settings.h" + #include #include #include @@ -15,6 +19,40 @@ DirSyncer::DirSyncer(KUrl localPath, KUrl remotePath) : m_localPath(localPath), m_remotePath(remotePath) { + connect(&m_dirWatcher, SIGNAL(dirty(QString)), SLOT(checkDirty(QString))); + + //TODO: Check for remote folder, and add magic so we avoid stating all the time + m_dirWatcher.addDir(localPath.url(), KDirWatch::WatchSubDirs); + m_dirWatcher.addDir(remotePath.url(), KDirWatch::WatchSubDirs); + + // Do initial scan after we return, which also starts continous watch + QMetaObject::invokeMethod(this, SLOT(compareDirs()), Qt::QueuedConnection); +} + +void DirSyncer::checkDirty(QString u) +{ + KUrl url(u); + KUrl parent; + + if (m_localPath.isParentOf(url)) { + parent = m_localPath; + } else { + parent = m_remotePath; + } + + if (url.fileName().isNull()) { + // IT IS LE DIRECTORY! + compareDirs(KUrl::relativeUrl(parent, url)); + } else { + KUrl relative = KUrl::relativeUrl(parent, url); + KDateTime remote = getModificationTime(m_remotePath.url() + relative.url()); + KDateTime local = getModificationTime(m_localPath.url() + relative.url()); + if (local > remote) { + upload(m_localPath.url() + relative.url()); + } else if (local > remote) { + download(m_remotePath.url() + relative.url()); + } + } } void DirSyncer::compareDirs(QString subdir) @@ -80,6 +118,9 @@ void DirSyncer::compareDirs(QString subdir) upload(item.url()); } } + + // Start scanning and watching folders + m_dirWatcher.startScan(); } KDateTime DirSyncer::getModificationTime(KUrl url) @@ -134,8 +175,6 @@ void DirSyncer::cleanJobs(KJob *j) emit finished(job->srcUrls().first().url()); - KIO::setModificationTime(job->destUrl(), getModificationTime(job->srcUrls().first()).dateTime()); // FIXME: isn't kio supposed to do this? - if (m_copyJobs.isEmpty()) emit idle(); } diff --git a/src/dirsyncer.h b/src/dirsyncer.h index 16ab596..18a5252 100644 --- a/src/dirsyncer.h +++ b/src/dirsyncer.h @@ -1,5 +1,8 @@ /* - * cloudsync.h + * dirsyncer.h + * + * This contains the declaration of the class that is responsible for + * synchronising two directories. * * Copyright (C) 2010 Martin T. Sandsmark */ @@ -9,6 +12,7 @@ #include #include #include +#include #include #include @@ -29,6 +33,7 @@ public slots: private slots: void cleanJobs(KJob*); + void checkDirty(QString url); private: void launchTransfer(KUrl from, KUrl to); @@ -36,10 +41,11 @@ private slots: void upload(KUrl file); KDateTime getModificationTime(KUrl url); + KUrl m_localPath; KUrl m_remotePath; - QSet m_copyJobs; + KDirWatch m_dirWatcher; }; #endif//DIRSYNCER_H diff --git a/src/main.cpp b/src/main.cpp index cf6a27d..49fd770 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,7 @@ /* - * cloudsync.h + * main.cpp + * + * Main entry point for the application. * * Copyright (C) 2010 Martin T. Sandsmark */ @@ -21,9 +23,6 @@ int main(int argc, char **argv) KAboutData::License_GPL, ki18n("(C) 2010 Martin T. Sandsmark"), KLocalizedString(), 0, "martin.sandsmark@kde.org"); KCmdLineArgs::init(argc, argv, &about); - KCmdLineOptions options; - options.add("+[URL]", ki18n( "Document to open" )); - KCmdLineArgs::addCmdLineOptions(options); KApplication app; CloudSync *widget = new CloudSync;