Skip to content

Commit

Permalink
update copyright stuff, add kdirwatch for continous monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sandsmark committed Apr 23, 2010
1 parent 405becf commit ac1aa60
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
2 changes: 2 additions & 0 deletions 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 <martin.sandsmark@kde.org>
*/

Expand Down
2 changes: 2 additions & 0 deletions 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 <martin.sandsmark@kde.org>
*/

Expand Down
45 changes: 42 additions & 3 deletions 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 <martin.sandsmark@kde.org>
*/

#include "dirsyncer.h"
#include "settings.h"

#include <KApplication>
#include <KDebug>
#include <KIO/StatJob>
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
10 changes: 8 additions & 2 deletions 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 <martin.sandsmark@kde.org>
*/
Expand All @@ -9,6 +12,7 @@
#include <QDir>
#include <KUrl>
#include <KDirLister>
#include <KDirWatch>
#include <KFileItem>
#include <KDateTime>

Expand All @@ -29,17 +33,19 @@ public slots:

private slots:
void cleanJobs(KJob*);
void checkDirty(QString url);

private:
void launchTransfer(KUrl from, KUrl to);
void download(KUrl file); // Fires off async calls
void upload(KUrl file);

KDateTime getModificationTime(KUrl url);

KUrl m_localPath;
KUrl m_remotePath;

QSet<KJob*> m_copyJobs;
KDirWatch m_dirWatcher;
};

#endif//DIRSYNCER_H
7 changes: 3 additions & 4 deletions src/main.cpp
@@ -1,5 +1,7 @@
/*
* cloudsync.h
* main.cpp
*
* Main entry point for the application.
*
* Copyright (C) 2010 Martin T. Sandsmark <martin.sandsmark@kde.org>
*/
Expand All @@ -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;
Expand Down

0 comments on commit ac1aa60

Please sign in to comment.