@@ -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
675737void AccountSettings::slotFolderWizardAccepted ()
676738{
0 commit comments