Skip to content

Commit

Permalink
Extract folder now big activity generation into separate method
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Aug 3, 2023
1 parent 5e3488d commit b0d4307
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
69 changes: 38 additions & 31 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,37 +1289,7 @@ void Folder::slotExistingFolderNowBig(const QString &folderPath)
}

postExistingFolderNowBigNotification(folderPath);

auto whitelistActivityLink = ActivityLink();
whitelistActivityLink._label = tr("Keep syncing");
whitelistActivityLink._primary = false;
whitelistActivityLink._verb = ActivityLink::WhitelistFolderVerb;

QVector<ActivityLink> activityLinks = {whitelistActivityLink};

if (!stopSyncing) {
auto blacklistActivityLink = ActivityLink();
blacklistActivityLink._label = tr("Stop syncing");
blacklistActivityLink._primary = true;
blacklistActivityLink._verb = ActivityLink::BlacklistFolderVerb;

activityLinks.append(blacklistActivityLink);
}

auto existingFolderNowBigActivity = Activity();
existingFolderNowBigActivity._type = Activity::NotificationType;
existingFolderNowBigActivity._dateTime = QDateTime::fromString(QDateTime::currentDateTime().toString(), Qt::ISODate);
existingFolderNowBigActivity._subject =
tr("The folder %1 has surpassed the set folder size limit of %2MB.").arg(folderPath, ConfigFile().newBigFolderSizeLimit().second);
existingFolderNowBigActivity._message = tr("Would you like to stop syncing this folder?");
existingFolderNowBigActivity._accName = _accountState->account()->displayName();
existingFolderNowBigActivity._folder = alias();
existingFolderNowBigActivity._file = cleanPath() + '/' + trailSlashFolderPath;
existingFolderNowBigActivity._links = activityLinks;
existingFolderNowBigActivity._id = qHash(existingFolderNowBigActivity._file);

const auto user = UserModel::instance()->findUserForAccount(_accountState.data());
user->slotAddNotification(this, existingFolderNowBigActivity);
postExistingFolderNowBigActivity(folderPath);
}
}

Expand All @@ -1333,6 +1303,43 @@ void Folder::postExistingFolderNowBigNotification(const QString &folderPath)
Logger::instance()->postGuiLog(Theme::instance()->appNameGUI(), message);
}

void Folder::postExistingFolderNowBigActivity(const QString &folderPath) const
{
const auto stopSyncing = ConfigFile().stopSyncingExistingFoldersOverLimit();
const auto trailSlashFolderPath = Utility::trailingSlashPath(folderPath);

auto whitelistActivityLink = ActivityLink();
whitelistActivityLink._label = tr("Keep syncing");
whitelistActivityLink._primary = false;
whitelistActivityLink._verb = ActivityLink::WhitelistFolderVerb;

QVector<ActivityLink> activityLinks = {whitelistActivityLink};

if (!stopSyncing) {
auto blacklistActivityLink = ActivityLink();
blacklistActivityLink._label = tr("Stop syncing");
blacklistActivityLink._primary = true;
blacklistActivityLink._verb = ActivityLink::BlacklistFolderVerb;

activityLinks.append(blacklistActivityLink);
}

auto existingFolderNowBigActivity = Activity();
existingFolderNowBigActivity._type = Activity::NotificationType;
existingFolderNowBigActivity._dateTime = QDateTime::fromString(QDateTime::currentDateTime().toString(), Qt::ISODate);
existingFolderNowBigActivity._subject =
tr("The folder %1 has surpassed the set folder size limit of %2MB.").arg(folderPath, QString::number(ConfigFile().newBigFolderSizeLimit().second));
existingFolderNowBigActivity._message = tr("Would you like to stop syncing this folder?");
existingFolderNowBigActivity._accName = _accountState->account()->displayName();
existingFolderNowBigActivity._folder = alias();
existingFolderNowBigActivity._file = cleanPath() + '/' + trailSlashFolderPath;
existingFolderNowBigActivity._links = activityLinks;
existingFolderNowBigActivity._id = qHash(existingFolderNowBigActivity._file);

const auto user = UserModel::instance()->findUserForAccount(_accountState.data());
user->slotAddNotification(this, existingFolderNowBigActivity);
}

void Folder::slotLogPropagationStart()
{
_fileLog->logLap("Propagation starts");
Expand Down
1 change: 1 addition & 0 deletions src/gui/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ private slots:
void removePathFromSelectiveSyncList(const QString &path, const SyncJournalDb::SelectiveSyncListType listType);

static void postExistingFolderNowBigNotification(const QString &folderPath);
void postExistingFolderNowBigActivity(const QString &folderPath) const;

AccountStatePtr _accountState;
FolderDefinition _definition;
Expand Down

0 comments on commit b0d4307

Please sign in to comment.