Skip to content

Commit

Permalink
Add folder rename action
Browse files Browse the repository at this point in the history
Signed-off-by: tokun-mobica <tomasz.okun@mobica.com>
  • Loading branch information
tokun-mobica committed Apr 6, 2022
1 parent d549a16 commit 4758fcd
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,9 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
ac = menu->addAction(folderPaused ? tr("Resume sync") : tr("Pause sync"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotEnableCurrentFolder);

ac = menu->addAction(tr("Rename local folder"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotRenameFolder);

ac = menu->addAction(tr("Remove folder sync connection"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotRemoveCurrentFolder);

Expand Down Expand Up @@ -671,6 +674,65 @@ void AccountSettings::slotAddFolder()
folderWizard->open();
}

void AccountSettings::slotRenameFolder()
{
auto dialog = new QDialog(nullptr, Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
dialog->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setSizeGripEnabled(true);
dialog->setMaximumWidth(this->width());
dialog->setFixedHeight(100);
dialog->setWindowTitle(tr("Rename local folder"));

auto vbox = new QVBoxLayout;
auto hbox = new QHBoxLayout;
auto lineEdit = new QLineEdit;
auto pushButtonConfirm = new QPushButton(tr("Rename"));
auto pushButtonCancel = new QPushButton(tr("Cancel"));
lineEdit->setText(QDir(FolderMan::instance()->folder(selectedFolderAlias())->path()).dirName());
hbox->addWidget(pushButtonConfirm);
hbox->addWidget(pushButtonCancel);
vbox->addWidget(lineEdit);
vbox->addLayout(hbox);
dialog->setLayout(vbox);

dialog->open();

connect(pushButtonConfirm, &QPushButton::clicked, dialog, &QDialog::accept);
connect(pushButtonCancel, &QPushButton::clicked, dialog, &QDialog::reject);

connect(dialog, &QDialog::finished, this, [this, lineEdit](const int result) {
if (result == QDialog::Accepted) {
auto folder = FolderMan::instance()->folder(selectedFolderAlias());
QDir currentDirectory(folder->path());
QString folderPath = currentDirectory.path().chopped(currentDirectory.dirName().length());
const auto newFolderPath = folderPath.append(lineEdit->text());

if (currentDirectory.path() != newFolderPath) {
auto folderMan = FolderMan::instance();
folderMan->setSyncEnabled(false); // do not start more syncs.
if (currentDirectory.rename(currentDirectory.path(), newFolderPath)) {
FolderDefinition definition;
definition.localPath = FolderDefinition::prepareLocalPath(newFolderPath);
definition.targetPath = FolderDefinition::prepareTargetPath(folder->remotePath());
definition.ignoreHiddenFiles = folderMan->ignoreHiddenFiles();
Utility::removeFavLink(folder->path());
FolderMan::instance()->removeFolder(folder);
Utility::setupFavLink(definition.localPath);

if (auto f = folderMan->addFolder(_accountState, definition)) {
folderMan->scheduleFolder(f);
emit folderChanged();
}
} else {
QMessageBox::critical(this, tr("Folder rename failed!"),
tr("Folder: %1 \n can't be renamed to: %2 !").arg(currentDirectory.dirName(), lineEdit->text()), QMessageBox::Ok);
}
folderMan->setSyncEnabled(true);
}
}
});
}

void AccountSettings::slotFolderWizardAccepted()
{
Expand Down
1 change: 1 addition & 0 deletions src/gui/accountsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public slots:

protected slots:
void slotAddFolder();
void slotRenameFolder();
void slotEnableCurrentFolder(bool terminate = false);
void slotScheduleCurrentFolder();
void slotScheduleCurrentFolderForceRemoteDiscovery();
Expand Down

0 comments on commit 4758fcd

Please sign in to comment.