Skip to content

Commit bbc6007

Browse files
committed
Add folder rename action
Signed-off-by: tokun-mobica <[email protected]>
1 parent d549a16 commit bbc6007

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/gui/accountsettings.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
579579
ac = menu->addAction(folderPaused ? tr("Resume sync") : tr("Pause sync"));
580580
connect(ac, &QAction::triggered, this, &AccountSettings::slotEnableCurrentFolder);
581581

582+
ac = menu->addAction(tr("Rename local folder"));
583+
connect(ac, &QAction::triggered, this, &AccountSettings::slotRenameFolder);
584+
582585
ac = menu->addAction(tr("Remove folder sync connection"));
583586
connect(ac, &QAction::triggered, this, &AccountSettings::slotRemoveCurrentFolder);
584587

@@ -671,6 +674,67 @@ void AccountSettings::slotAddFolder()
671674
folderWizard->open();
672675
}
673676

677+
void AccountSettings::slotRenameFolder()
678+
{
679+
auto dialog = new QDialog(nullptr, Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
680+
dialog->setSizeGripEnabled(true);
681+
dialog->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
682+
dialog->setFixedHeight(100);
683+
dialog->setMaximumWidth(this->width());
684+
dialog->setWindowTitle(tr("Rename local folder"));
685+
dialog->setAttribute(Qt::WA_DeleteOnClose);
686+
687+
auto vbox = new QVBoxLayout;
688+
auto lineEdit = new QLineEdit;
689+
lineEdit->setText(QDir(FolderMan::instance()->folder(selectedFolderAlias())->path()).dirName());
690+
vbox->addWidget(lineEdit);
691+
auto hbox = new QHBoxLayout;
692+
auto pushButtonConfirm = new QPushButton(tr("Rename"));
693+
auto pushButtonCancel = new QPushButton(tr("Cancel"));
694+
hbox->addWidget(pushButtonConfirm);
695+
hbox->addWidget(pushButtonCancel);
696+
vbox->addLayout(hbox);
697+
698+
dialog->setLayout(vbox);
699+
dialog->open();
700+
701+
connect(pushButtonConfirm, &QPushButton::clicked, dialog, &QDialog::accept);
702+
connect(pushButtonCancel, &QPushButton::clicked, dialog, &QDialog::reject);
703+
704+
connect(dialog, &QDialog::finished, this, [this, dialog, lineEdit](const int result) {
705+
if (result == QDialog::Accepted) {
706+
auto folder = FolderMan::instance()->folder(selectedFolderAlias());
707+
QDir currentDirectory(folder->path());
708+
QString folderPath = currentDirectory.path().chopped(currentDirectory.dirName().length());
709+
const auto newFolderPath = folderPath.append(lineEdit->text());
710+
711+
if (currentDirectory.path() != newFolderPath) {
712+
auto folderMan = FolderMan::instance();
713+
folderMan->setSyncEnabled(false); // do not start more syncs.
714+
715+
if (currentDirectory.rename(currentDirectory.path(), newFolderPath)) {
716+
FolderDefinition definition;
717+
definition.localPath = FolderDefinition::prepareLocalPath(newFolderPath);
718+
definition.targetPath = FolderDefinition::prepareTargetPath(folder->remotePath());
719+
definition.ignoreHiddenFiles = folderMan->ignoreHiddenFiles();
720+
721+
Utility::removeFavLink(folder->path());
722+
FolderMan::instance()->removeFolder(folder);
723+
Utility::setupFavLink(definition.localPath);
724+
725+
if (auto f = folderMan->addFolder(_accountState, definition)) {
726+
folderMan->scheduleFolder(f);
727+
emit folderChanged();
728+
}
729+
} else {
730+
QMessageBox::critical(this, tr("Folder rename failed!"),
731+
tr("Folder: %1 \n can't be renamed to: %2 !").arg(currentDirectory.dirName(), lineEdit->text()), QMessageBox::Ok);
732+
}
733+
folderMan->setSyncEnabled(true);
734+
}
735+
}
736+
});
737+
}
674738

675739
void AccountSettings::slotFolderWizardAccepted()
676740
{

src/gui/accountsettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public slots:
7777

7878
protected slots:
7979
void slotAddFolder();
80+
void slotRenameFolder();
8081
void slotEnableCurrentFolder(bool terminate = false);
8182
void slotScheduleCurrentFolder();
8283
void slotScheduleCurrentFolderForceRemoteDiscovery();

0 commit comments

Comments
 (0)