Skip to content

Commit 4758fcd

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

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/gui/accountsettings.cpp

Lines changed: 62 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,65 @@ 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->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
681+
dialog->setAttribute(Qt::WA_DeleteOnClose);
682+
dialog->setSizeGripEnabled(true);
683+
dialog->setMaximumWidth(this->width());
684+
dialog->setFixedHeight(100);
685+
dialog->setWindowTitle(tr("Rename local folder"));
686+
687+
auto vbox = new QVBoxLayout;
688+
auto hbox = new QHBoxLayout;
689+
auto lineEdit = new QLineEdit;
690+
auto pushButtonConfirm = new QPushButton(tr("Rename"));
691+
auto pushButtonCancel = new QPushButton(tr("Cancel"));
692+
lineEdit->setText(QDir(FolderMan::instance()->folder(selectedFolderAlias())->path()).dirName());
693+
hbox->addWidget(pushButtonConfirm);
694+
hbox->addWidget(pushButtonCancel);
695+
vbox->addWidget(lineEdit);
696+
vbox->addLayout(hbox);
697+
dialog->setLayout(vbox);
698+
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, 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+
if (currentDirectory.rename(currentDirectory.path(), newFolderPath)) {
715+
FolderDefinition definition;
716+
definition.localPath = FolderDefinition::prepareLocalPath(newFolderPath);
717+
definition.targetPath = FolderDefinition::prepareTargetPath(folder->remotePath());
718+
definition.ignoreHiddenFiles = folderMan->ignoreHiddenFiles();
719+
Utility::removeFavLink(folder->path());
720+
FolderMan::instance()->removeFolder(folder);
721+
Utility::setupFavLink(definition.localPath);
722+
723+
if (auto f = folderMan->addFolder(_accountState, definition)) {
724+
folderMan->scheduleFolder(f);
725+
emit folderChanged();
726+
}
727+
} else {
728+
QMessageBox::critical(this, tr("Folder rename failed!"),
729+
tr("Folder: %1 \n can't be renamed to: %2 !").arg(currentDirectory.dirName(), lineEdit->text()), QMessageBox::Ok);
730+
}
731+
folderMan->setSyncEnabled(true);
732+
}
733+
}
734+
});
735+
}
674736

675737
void AccountSettings::slotFolderWizardAccepted()
676738
{

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)