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