Skip to content

Commit bb07bb8

Browse files
tokun-mobicamgallien
authored andcommitted
Add folder rename action
Signed-off-by: tokun-mobica <[email protected]>
1 parent 57a8a93 commit bb07bb8

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
@@ -698,6 +698,9 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
698698
ac = menu->addAction(folderPaused ? tr("Resume sync") : tr("Pause sync"));
699699
connect(ac, &QAction::triggered, this, &AccountSettings::slotEnableCurrentFolder);
700700

701+
ac = menu->addAction(tr("Rename local folder"));
702+
connect(ac, &QAction::triggered, this, &AccountSettings::slotRenameFolder);
703+
701704
ac = menu->addAction(tr("Remove folder sync connection"));
702705
connect(ac, &QAction::triggered, this, &AccountSettings::slotRemoveCurrentFolder);
703706

@@ -791,6 +794,65 @@ void AccountSettings::slotAddFolder()
791794
folderWizard->open();
792795
}
793796

797+
void AccountSettings::slotRenameFolder()
798+
{
799+
auto dialog = new QDialog(nullptr, Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
800+
dialog->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
801+
dialog->setAttribute(Qt::WA_DeleteOnClose);
802+
dialog->setSizeGripEnabled(true);
803+
dialog->setMaximumWidth(this->width());
804+
dialog->setFixedHeight(100);
805+
dialog->setWindowTitle(tr("Rename local folder"));
806+
807+
auto vbox = new QVBoxLayout;
808+
auto hbox = new QHBoxLayout;
809+
auto lineEdit = new QLineEdit;
810+
auto pushButtonConfirm = new QPushButton(tr("Rename"));
811+
auto pushButtonCancel = new QPushButton(tr("Cancel"));
812+
lineEdit->setText(QDir(FolderMan::instance()->folder(selectedFolderAlias())->path()).dirName());
813+
hbox->addWidget(pushButtonConfirm);
814+
hbox->addWidget(pushButtonCancel);
815+
vbox->addWidget(lineEdit);
816+
vbox->addLayout(hbox);
817+
dialog->setLayout(vbox);
818+
819+
dialog->open();
820+
821+
connect(pushButtonConfirm, &QPushButton::clicked, dialog, &QDialog::accept);
822+
connect(pushButtonCancel, &QPushButton::clicked, dialog, &QDialog::reject);
823+
824+
connect(dialog, &QDialog::finished, this, [this, lineEdit](const int result) {
825+
if (result == QDialog::Accepted) {
826+
auto folder = FolderMan::instance()->folder(selectedFolderAlias());
827+
QDir currentDirectory(folder->path());
828+
QString folderPath = currentDirectory.path().chopped(currentDirectory.dirName().length());
829+
const auto newFolderPath = folderPath.append(lineEdit->text());
830+
831+
if (currentDirectory.path() != newFolderPath) {
832+
auto folderMan = FolderMan::instance();
833+
folderMan->setSyncEnabled(false); // do not start more syncs.
834+
if (currentDirectory.rename(currentDirectory.path(), newFolderPath)) {
835+
FolderDefinition definition;
836+
definition.localPath = FolderDefinition::prepareLocalPath(newFolderPath);
837+
definition.targetPath = FolderDefinition::prepareTargetPath(folder->remotePath());
838+
definition.ignoreHiddenFiles = folderMan->ignoreHiddenFiles();
839+
Utility::removeFavLink(folder->path());
840+
FolderMan::instance()->removeFolder(folder);
841+
Utility::setupFavLink(definition.localPath);
842+
843+
if (auto f = folderMan->addFolder(_accountState, definition)) {
844+
folderMan->scheduleFolder(f);
845+
emit folderChanged();
846+
}
847+
} else {
848+
QMessageBox::critical(this, tr("Folder rename failed!"),
849+
tr("Folder: %1 \n can't be renamed to: %2 !").arg(currentDirectory.dirName(), lineEdit->text()), QMessageBox::Ok);
850+
}
851+
folderMan->setSyncEnabled(true);
852+
}
853+
}
854+
});
855+
}
794856

795857
void AccountSettings::slotFolderWizardAccepted()
796858
{

src/gui/accountsettings.h

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

7474
protected slots:
7575
void slotAddFolder();
76+
void slotRenameFolder();
7677
void slotEnableCurrentFolder(bool terminate = false);
7778
void slotScheduleCurrentFolder();
7879
void slotScheduleCurrentFolderForceRemoteDiscovery();

0 commit comments

Comments
 (0)