@@ -80,11 +80,12 @@ TorrentContentLayoutDialog::TorrentContentLayoutDialog(BitTorrent::TorrentConten
8080 setWindowIcon (UIThemeManager::instance ()->getIcon (u" edit-rename" _s));
8181
8282 m_model = new TorrentContentLayoutModel (contentHandler, this );
83- m_ui->treeView ->setModel (m_model);
83+ m_ui->pathListView ->setModel (m_model);
8484 if (m_model->rowCount () > 0 )
8585 {
86- m_ui->treeView ->selectionModel ()->setCurrentIndex (m_model->index (0 , 0 )
86+ m_ui->pathListView ->selectionModel ()->setCurrentIndex (m_model->index (0 , 0 )
8787 , (QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows));
88+ populateCommonPath ();
8889 }
8990
9091 connect (m_model, &QAbstractItemModel::dataChanged, this , [this ]
@@ -105,21 +106,97 @@ TorrentContentLayoutDialog::TorrentContentLayoutDialog(BitTorrent::TorrentConten
105106 RaisedMessageBox::warning (this , tr (" Rename error" ), errorMessage, QMessageBox::Ok);
106107 });
107108
108- m_ui->treeView ->setItemDelegate (new TorrentContentLayoutItemDelegate (this ));
109+ m_ui->pathListView ->setItemDelegate (new TorrentContentLayoutItemDelegate (this ));
110+
111+ connect (m_ui->pathListView ->selectionModel (), &QItemSelectionModel::selectionChanged, this , &TorrentContentLayoutDialog::populateCommonPath);
112+ connect (m_ui->commonPathEdit , &QLineEdit::textEdited, this , &TorrentContentLayoutDialog::onCommonPathEdited);
109113
110114 if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid ())
111115 resize (dialogSize);
112116
113- m_ui->treeView ->header ()->restoreState (m_storeViewState);
117+ m_ui->pathListView ->header ()->restoreState (m_storeViewState);
114118}
115119
116120TorrentContentLayoutDialog::~TorrentContentLayoutDialog ()
117121{
118122 m_storeDialogSize = size ();
119- m_storeViewState = m_ui->treeView ->header ()->saveState ();
123+ m_storeViewState = m_ui->pathListView ->header ()->saveState ();
120124 delete m_ui;
121125}
122126
127+ Path TorrentContentLayoutDialog::currentPath () const
128+ {
129+ const QModelIndex currentIndex = m_ui->pathListView ->selectionModel ()->currentIndex ();
130+ if (!currentIndex.isValid ())
131+ return {};
132+
133+ return Path (currentIndex.siblingAtColumn (TorrentContentLayoutModel::COL_PATH ).data ().toString ());
134+ }
135+
136+ PathList TorrentContentLayoutDialog::selectedPaths () const
137+ {
138+ const QModelIndexList selectedRows = m_ui->pathListView ->selectionModel ()->selectedRows (TorrentContentLayoutModel::COL_PATH );
139+ if (selectedRows.isEmpty ())
140+ return {};
141+
142+ PathList selectedPaths;
143+ selectedPaths.reserve (selectedRows.size ());
144+ for (const QModelIndex &rowIndex : selectedRows)
145+ selectedPaths.append (Path (rowIndex.data ().toString ()));
146+
147+ return selectedPaths;
148+ }
149+
150+ void TorrentContentLayoutDialog::populateCommonPath ()
151+ {
152+ PathList paths = selectedPaths ();
153+ if (paths.isEmpty ())
154+ {
155+ const Path currentPath = this ->currentPath ();
156+ if (currentPath.isValid ())
157+ paths.append (currentPath);
158+ }
159+
160+ if (!paths.isEmpty ())
161+ {
162+ m_commonPath = Path::commonPath (paths);
163+ m_ui->commonPathEdit ->setText (m_commonPath.toString ());
164+ m_ui->commonPathLabel ->setEnabled (true );
165+ m_ui->commonPathEdit ->setEnabled (true );
166+ }
167+ else
168+ {
169+ m_commonPath = {};
170+ m_ui->commonPathEdit ->clear ();
171+ m_ui->commonPathLabel ->setEnabled (false );
172+ m_ui->commonPathEdit ->setEnabled (false );
173+ }
174+ }
175+
176+ void TorrentContentLayoutDialog::onCommonPathEdited (const QString &pathStr)
177+ {
178+ const Path oldCommonPath = m_commonPath;
179+ m_commonPath = Path (pathStr);
180+
181+ QModelIndexList selectedRows = m_ui->pathListView ->selectionModel ()->selectedRows (TorrentContentLayoutModel::COL_PATH );
182+ if (selectedRows.isEmpty ())
183+ {
184+ const QModelIndex currentIndex = m_ui->pathListView ->selectionModel ()->currentIndex ();
185+ if (currentIndex.isValid ())
186+ selectedRows.append (currentIndex.siblingAtColumn (TorrentContentLayoutModel::COL_PATH ));
187+ }
188+
189+ if (selectedRows.isEmpty ())
190+ return ;
191+
192+ for (const QModelIndex &rowIndex : selectedRows)
193+ {
194+ const Path oldPath {rowIndex.data ().toString ()};
195+ const Path newPath = m_commonPath / oldCommonPath.relativePathOf (oldPath);
196+ m_model->setData (rowIndex, newPath.toString ());
197+ }
198+ }
199+
123200void TorrentContentLayoutDialog::apply ()
124201{
125202 m_model->applyChangedFilePaths ();
0 commit comments