Skip to content

Commit

Permalink
Merge pull request #7 from kapitainsky/kptsky_tasks
Browse files Browse the repository at this point in the history
Kptsky tasks
  • Loading branch information
kapitainsky committed Sep 22, 2019
2 parents 9c3ce5a + 8cac09c commit 03c5729
Show file tree
Hide file tree
Showing 14 changed files with 1,211 additions and 255 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ debian/files
debian/debhelper-build-stamp
debian/rclone-browser*

/bs0.cmd
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ set(MOC
stream_widget.h
preferences_dialog.h
icon_cache.h
list_of_job_options.h
item_model.h
)

set(OTHER
pch.h
utils.h
job_options.h
)

set(SOURCE
Expand All @@ -72,6 +74,8 @@ set(SOURCE
icon_cache.cpp
item_model.cpp
utils.cpp
job_options.cpp
list_of_job_options.cpp
)

if(WIN32)
Expand Down
189 changes: 189 additions & 0 deletions src/job_options.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#include "job_options.h"
#include <qexception.h>
#include <qdebug.h>
#include <qlogging.h>
#ifdef _WIN32
#pragma warning(disable:4505)
#endif
JobOptions::JobOptions(bool isDownload) : JobOptions()
{
setJobType(isDownload);
uniqueId = QUuid::createUuid();
}

JobOptions::JobOptions():
jobType(UnknownJobType), operation(UnknownOp), dryRun(false), sync(false),
syncTiming(UnknownTiming), skipNewer(false), skipExisting(false),
compare(false), compareOption(), verbose(false), sameFilesystem(false),
dontUpdateModified(false), maxDepth(0), deleteExcluded(false), isFolder(false)
{
}

const qint32 JobOptions::classVersion = 3;


JobOptions::~JobOptions()
{
}

/*
* Turn the options held here into a string list for
* use in the rclone command.
*
* This logic was originally in transfer_dialog.cpp.
*
* This needs to change whenever e.g. new options are
* added to the dialog.
*/
QStringList JobOptions::getOptions() const
{
QStringList list;

if (operation == Copy)
{
list << "copy";
}
else if (operation == Move)
{
list << "move";
}
else if (operation == Sync)
{
list << "sync";
}

if (dryRun)
{
list << "--dry-run";
}

if (sync)
{
switch (syncTiming)
{
case During:
list << "--delete-during";
break;
case After:
list << "--delete-after";
break;
case Before:
list << "--delete-before";
break;
default:
break;;
}
}

if (skipNewer)
{
list << "--update";
}
if (skipExisting)
{
list << "--ignore-existing";
}

if (compare)
{
switch (compareOption)
{
case Checksum:
list << "--checksum";
break;
case IgnoreSize:
list << "--ignore-size";
break;
case SizeOnly:
list << "--size-only";
break;
case ChecksumIgnoreSize:
list << "--checksum" << "--ignore-size";
break;
default:
break;
}
}

//always verbose
list << "--verbose";
if (sameFilesystem)
{
list << "--one-file-system";
}
if (dontUpdateModified)
{
list << "--no-update-modtime";
}

list << "--transfers" << transfers;
list << "--checkers" << checkers;

if (!bandwidth.isEmpty())
{
list << "--bwlimit" << bandwidth;
}
if (!minSize.isEmpty())
{
list << "--min-size" << minSize;
}
if (!minAge.isEmpty())
{
list << "--min-age" << minAge;
}
if (!maxAge.isEmpty())
{
list << "--max-age" << maxAge;
}

if (maxDepth != 0)
{
list << "--max-depth" << QString::number(maxDepth);
}

list << "--contimeout" << (connectTimeout + "s");
list << "--timeout" << (idleTimeout + "s");
list << "--retries" << retries;
list << "--low-level-retries" << lowLevelRetries;

if (deleteExcluded)
{
list << "--delete-excluded";
}

if (!excluded.isEmpty())
{
for (auto line : excluded.split('\n'))
{
list << "--exclude" << line;
}
}

if (!extra.isEmpty())
{
for (auto arg : extra.split(' '))
{
list << arg;
}
}


if (DriveSharedWithMe)
{
list << "--drive-shared-with-me";
}

list << "--stats" << "1s";

list << source;
list << dest;

return list;
}

SerializationException::SerializationException(QString msg) : QException(), Message(msg)
{
}



107 changes: 107 additions & 0 deletions src/job_options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#pragma once
#include <qexception.h>
#include <QListWidget>
#include <quuid.h>

class JobOptions
{
public:
explicit JobOptions(bool isDownload);
JobOptions();

~JobOptions();

enum Operation { UnknownOp, Copy, Move, Sync };
enum JobType {UnknownJobType, Upload, Download};

/*
* The following enums have their int values synchronized with the
* list indexes on the gui. Changes needed to be synchronized.
*/
enum SyncTiming { During, After, Before, UnknownTiming};
enum CompareOption {SizeAndModTime, Checksum, IgnoreSize, SizeOnly, ChecksumIgnoreSize};

QString description;

JobType jobType;
Operation operation;
bool dryRun; // not persisted
bool sync;
SyncTiming syncTiming;
bool skipNewer;
bool skipExisting;
bool compare;
CompareOption compareOption;
bool verbose;
bool sameFilesystem;
bool dontUpdateModified;
QString transfers;
QString checkers;
QString bandwidth;
QString minSize;
QString minAge;
QString maxAge;
int maxDepth;
QString connectTimeout;
QString idleTimeout;
QString retries;
QString lowLevelRetries;
bool deleteExcluded;
QString excluded;
QString extra;
QString source;
QString dest;
bool isFolder;
QUuid uniqueId;
bool DriveSharedWithMe;

void setJobType (bool isDownload)
{
jobType = (isDownload) ? Download : Upload;
}

QString myName() const
{
return "JobOptions"; //this->staticQtMetaObject.myName();
}
QStringList getOptions() const;


bool operator==(const JobOptions &other) const
{
return uniqueId == other.uniqueId;
}


/*
* This allows the de-serialization method to accomodate changes
* to the class structure, especially (most easily) added members.
*
* Increment the value each time a change is made, emit the new field(s)
* in the operator<< function, and in operator>> add conditional logic
* based on the version for reading in the new field(s)
*/
static const qint32 classVersion;

};

class JobOptionsListWidgetItem : public QListWidgetItem
{
public:

JobOptionsListWidgetItem(JobOptions *jo, const QIcon &icon, const QString &text) : QListWidgetItem(icon, text), mJobData(jo) {}

void SetData(JobOptions *jo) { mJobData = jo; }
JobOptions *GetData() { return mJobData; }

private:
JobOptions *mJobData;
};

class SerializationException : public QException
{
public:
QString Message;
explicit SerializationException(QString msg);
};

Loading

0 comments on commit 03c5729

Please sign in to comment.