mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-28 11:45:40 +08:00
refs #887, copy nested directories in wizard
* added utility function * removed preselectMissingOrOutdated, flag for initCurrentDirectories * support for copying nested directories
This commit is contained in:
committed by
Mathew Sutcliffe
parent
96a2b757e7
commit
80b127bce8
@@ -46,12 +46,12 @@ namespace BlackGui
|
|||||||
if (page == ui->wp_CopyCaches)
|
if (page == ui->wp_CopyCaches)
|
||||||
{
|
{
|
||||||
ui->comp_CopyCaches->setCacheMode();
|
ui->comp_CopyCaches->setCacheMode();
|
||||||
ui->comp_CopyCaches->initAndPreselectDirectories();
|
ui->comp_CopyCaches->initCurrentDirectories(true);
|
||||||
}
|
}
|
||||||
else if (page == ui->wp_CopySettings)
|
else if (page == ui->wp_CopySettings)
|
||||||
{
|
{
|
||||||
ui->comp_CopySettings->setSettingsMode();
|
ui->comp_CopySettings->setSettingsMode();
|
||||||
ui->comp_CopySettings->initAndPreselectDirectories();
|
ui->comp_CopySettings->initCurrentDirectories(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -7,10 +7,11 @@
|
|||||||
* contained in the LICENSE file.
|
* contained in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "ui_copyconfigurationcomponent.h"
|
||||||
#include "copyconfigurationcomponent.h"
|
#include "copyconfigurationcomponent.h"
|
||||||
|
#include "configurationwizard.h"
|
||||||
#include "blackconfig/buildconfig.h"
|
#include "blackconfig/buildconfig.h"
|
||||||
#include "blackmisc/directoryutils.h"
|
#include "blackmisc/directoryutils.h"
|
||||||
#include "ui_copyconfigurationcomponent.h"
|
|
||||||
#include "blackmisc/settingscache.h"
|
#include "blackmisc/settingscache.h"
|
||||||
#include "blackmisc/datacache.h"
|
#include "blackmisc/datacache.h"
|
||||||
|
|
||||||
@@ -34,8 +35,8 @@ namespace BlackGui
|
|||||||
ui->cb_OtherVersions->addItems(CDirectoryUtils::swiftApplicationDataDirectoryList(true, true));
|
ui->cb_OtherVersions->addItems(CDirectoryUtils::swiftApplicationDataDirectoryList(true, true));
|
||||||
m_otherVersionDirs = CDirectoryUtils::swiftApplicationDataDirectoryList(true, false); // not beautified
|
m_otherVersionDirs = CDirectoryUtils::swiftApplicationDataDirectoryList(true, false); // not beautified
|
||||||
|
|
||||||
connect(ui->rb_Cache, &QRadioButton::toggled, this, &CCopyConfigurationComponent::initCurrentDirectories);
|
connect(ui->rb_Cache, &QRadioButton::toggled, [ = ](bool) { this->initCurrentDirectories(true); });
|
||||||
connect(ui->cb_OtherVersions, &QComboBox::currentTextChanged, this, &CCopyConfigurationComponent::initCurrentDirectories);
|
connect(ui->cb_OtherVersions, &QComboBox::currentTextChanged, [ = ] { this->initCurrentDirectories(true); });
|
||||||
connect(ui->pb_SelectAll, &QPushButton::clicked, ui->tv_Source, &QTreeView::selectAll);
|
connect(ui->pb_SelectAll, &QPushButton::clicked, ui->tv_Source, &QTreeView::selectAll);
|
||||||
connect(ui->pb_ClearSelection, &QPushButton::clicked, ui->tv_Source, &QTreeView::clearSelection);
|
connect(ui->pb_ClearSelection, &QPushButton::clicked, ui->tv_Source, &QTreeView::clearSelection);
|
||||||
connect(ui->pb_CopyOver, &QPushButton::clicked, this, &CCopyConfigurationComponent::copySelectedFiles);
|
connect(ui->pb_CopyOver, &QPushButton::clicked, this, &CCopyConfigurationComponent::copySelectedFiles);
|
||||||
@@ -60,22 +61,31 @@ namespace BlackGui
|
|||||||
if (files.isEmpty()) { return 0; }
|
if (files.isEmpty()) { return 0; }
|
||||||
|
|
||||||
const QString destinationDir = this->getThisVersionDirectory();
|
const QString destinationDir = this->getThisVersionDirectory();
|
||||||
|
const QString sourceDir = this->getOtherVersionsSelectedDirectory();
|
||||||
if (destinationDir.isEmpty()) { return 0; }
|
if (destinationDir.isEmpty()) { return 0; }
|
||||||
const QDir d(destinationDir);
|
const QDir source(sourceDir);
|
||||||
if (!d.exists()) { return 0; }
|
const QDir destination(destinationDir);
|
||||||
|
if (!destination.exists()) { return 0; }
|
||||||
|
|
||||||
int c = 0;
|
int c = 0;
|
||||||
for (const QString &file : files)
|
for (const QString &file : files)
|
||||||
{
|
{
|
||||||
const QFileInfo fileInfo(file);
|
const QString relativePath = source.relativeFilePath(file);
|
||||||
const QString target = CFileUtils::appendFilePaths(destinationDir, fileInfo.fileName());
|
const QString target = CFileUtils::appendFilePaths(destinationDir, relativePath);
|
||||||
|
if (relativePath.contains('/'))
|
||||||
|
{
|
||||||
|
const QString targetDir = CFileUtils::stripFileFromPath(target);
|
||||||
|
const bool dirOk = destination.mkpath(targetDir);
|
||||||
|
if (!dirOk) { continue; }
|
||||||
|
}
|
||||||
|
QFile::remove(target); // copy does not overwrite
|
||||||
const bool s = QFile::copy(file, target);
|
const bool s = QFile::copy(file, target);
|
||||||
if (s) { c++; }
|
if (s) { c++; }
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCopyConfigurationComponent::preselectMissingOurOutdated()
|
void CCopyConfigurationComponent::preselectMissingOrOutdated()
|
||||||
{
|
{
|
||||||
const QString dirOther = this->getOtherVersionsSelectedDirectory();
|
const QString dirOther = this->getOtherVersionsSelectedDirectory();
|
||||||
const QString dirCurrent = this->getThisVersionDirectory();
|
const QString dirCurrent = this->getThisVersionDirectory();
|
||||||
@@ -83,7 +93,7 @@ namespace BlackGui
|
|||||||
ui->tv_Source->clearSelection();
|
ui->tv_Source->clearSelection();
|
||||||
ui->tv_Destination->clearSelection();
|
ui->tv_Destination->clearSelection();
|
||||||
|
|
||||||
const CDirectoryUtils::DirComparison comp = CDirectoryUtils::compareTwoDirectories(dirOther, dirCurrent);
|
const CDirectoryUtils::DirComparison comp = CDirectoryUtils::compareTwoDirectories(dirOther, dirCurrent, true);
|
||||||
const QFileSystemModel *sourceModel = qobject_cast<QFileSystemModel *>(ui->tv_Source->model());
|
const QFileSystemModel *sourceModel = qobject_cast<QFileSystemModel *>(ui->tv_Source->model());
|
||||||
if (!sourceModel) { return; }
|
if (!sourceModel) { return; }
|
||||||
|
|
||||||
@@ -97,11 +107,20 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCopyConfigurationComponent::initCurrentDirectories()
|
void CCopyConfigurationComponent::initCurrentDirectories(bool preselectMissingOrOutdated)
|
||||||
{
|
{
|
||||||
ui->le_CurrentVersion->setText(CDirectoryUtils::applicationDirectoryPath());
|
const QString thisVersionDir = this->getThisVersionDirectory(); // cache or settings dir
|
||||||
this->setComboBoxWidth();
|
const QDir thisVersionDirectory(thisVersionDir);
|
||||||
const QString dir = this->getOtherVersionsSelectedDirectory();
|
if (!thisVersionDirectory.exists())
|
||||||
|
{
|
||||||
|
const bool hasDir = thisVersionDirectory.mkpath(thisVersionDir);
|
||||||
|
if (!hasDir)
|
||||||
|
{
|
||||||
|
ui->le_CurrentVersion->setText("No swift target dir");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ui->le_CurrentVersion->setText(thisVersionDir);
|
||||||
|
|
||||||
// source
|
// source
|
||||||
QFileSystemModel *sourceModel = qobject_cast<QFileSystemModel *>(ui->tv_Source->model());
|
QFileSystemModel *sourceModel = qobject_cast<QFileSystemModel *>(ui->tv_Source->model());
|
||||||
@@ -116,13 +135,22 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
Q_UNUSED(path);
|
Q_UNUSED(path);
|
||||||
ui->tv_Source->resizeColumnToContents(0);
|
ui->tv_Source->resizeColumnToContents(0);
|
||||||
|
ui->tv_Source->expandAll();
|
||||||
|
if (preselectMissingOrOutdated)
|
||||||
|
{
|
||||||
|
this->preselectMissingOrOutdated();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->preselectMissingOrOutdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString dir = this->getOtherVersionsSelectedDirectory();
|
||||||
const QModelIndex sourceIndex = sourceModel->setRootPath(dir);
|
const QModelIndex sourceIndex = sourceModel->setRootPath(dir);
|
||||||
ui->tv_Source->setRootIndex(sourceIndex);
|
ui->tv_Source->setRootIndex(sourceIndex);
|
||||||
ui->tv_Source->setSortingEnabled(true); // hide/disable only
|
ui->tv_Source->setSortingEnabled(true); // hide/disable only
|
||||||
ui->tv_Source->resizeColumnToContents(0);
|
|
||||||
|
|
||||||
// destination
|
// destination
|
||||||
QFileSystemModel *destinationModel = qobject_cast<QFileSystemModel *>(ui->tv_Destination->model());
|
QFileSystemModel *destinationModel = qobject_cast<QFileSystemModel *>(ui->tv_Destination->model());
|
||||||
@@ -137,19 +165,13 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
Q_UNUSED(path);
|
Q_UNUSED(path);
|
||||||
ui->tv_Destination->resizeColumnToContents(0);
|
ui->tv_Destination->resizeColumnToContents(0);
|
||||||
|
ui->tv_Destination->expandAll();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const QString destinationDir = this->getThisVersionDirectory();
|
const QString destinationDir = this->getThisVersionDirectory();
|
||||||
const QModelIndex destinationIndex = destinationModel->setRootPath(destinationDir);
|
const QModelIndex destinationIndex = destinationModel->setRootPath(destinationDir);
|
||||||
ui->tv_Destination->setRootIndex(destinationIndex);
|
ui->tv_Destination->setRootIndex(destinationIndex);
|
||||||
ui->tv_Destination->setSortingEnabled(true);
|
ui->tv_Destination->setSortingEnabled(true);
|
||||||
ui->tv_Destination->resizeColumnToContents(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCopyConfigurationComponent::initAndPreselectDirectories()
|
|
||||||
{
|
|
||||||
this->initCurrentDirectories();
|
|
||||||
this->preselectMissingOurOutdated();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCopyConfigurationComponent::hasOtherVersionData() const
|
bool CCopyConfigurationComponent::hasOtherVersionData() const
|
||||||
@@ -173,11 +195,11 @@ namespace BlackGui
|
|||||||
if (ui->cb_OtherVersions->count() < 1) { return ""; }
|
if (ui->cb_OtherVersions->count() < 1) { return ""; }
|
||||||
const QFileInfoList dirs(CDirectoryUtils::swiftApplicationDataDirectories());
|
const QFileInfoList dirs(CDirectoryUtils::swiftApplicationDataDirectories());
|
||||||
if (dirs.isEmpty()) { return ""; }
|
if (dirs.isEmpty()) { return ""; }
|
||||||
const QString s = m_otherVersionDirs.at(ui->cb_OtherVersions->currentIndex());
|
const QString otherVersionDir = m_otherVersionDirs.at(ui->cb_OtherVersions->currentIndex());
|
||||||
QString dir;
|
QString dir;
|
||||||
for (const QFileInfo &info : dirs)
|
for (const QFileInfo &info : dirs)
|
||||||
{
|
{
|
||||||
if (info.absoluteFilePath().contains(s))
|
if (info.absoluteFilePath().contains(otherVersionDir))
|
||||||
{
|
{
|
||||||
dir = info.absoluteFilePath();
|
dir = info.absoluteFilePath();
|
||||||
break;
|
break;
|
||||||
@@ -209,21 +231,19 @@ namespace BlackGui
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCopyConfigurationComponent::setComboBoxWidth()
|
|
||||||
{
|
|
||||||
const int width = this->width() * 0.45;
|
|
||||||
ui->cb_OtherVersions->setFixedWidth(width);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCopyConfigurationWizardPage::initializePage()
|
void CCopyConfigurationWizardPage::initializePage()
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(m_config, Q_FUNC_INFO, "Missing config");
|
Q_ASSERT_X(m_config, Q_FUNC_INFO, "Missing config");
|
||||||
m_config->initCurrentDirectories();
|
m_config->initCurrentDirectories(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCopyConfigurationWizardPage::validatePage()
|
bool CCopyConfigurationWizardPage::validatePage()
|
||||||
{
|
{
|
||||||
|
CConfigurationWizard *wizard = qobject_cast<CConfigurationWizard *>(this->wizard());
|
||||||
Q_ASSERT_X(m_config, Q_FUNC_INFO, "Missing config");
|
Q_ASSERT_X(m_config, Q_FUNC_INFO, "Missing config");
|
||||||
|
Q_ASSERT_X(wizard, Q_FUNC_INFO, "No wizard");
|
||||||
|
|
||||||
|
if (wizard->lastStepSkipped()) { return true; }
|
||||||
m_config->copySelectedFiles();
|
m_config->copySelectedFiles();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,13 +46,10 @@ namespace BlackGui
|
|||||||
int copySelectedFiles();
|
int copySelectedFiles();
|
||||||
|
|
||||||
//! Preselect newer files
|
//! Preselect newer files
|
||||||
void preselectMissingOurOutdated();
|
void preselectMissingOrOutdated();
|
||||||
|
|
||||||
//! Init file content
|
//! Init file content
|
||||||
void initCurrentDirectories();
|
void initCurrentDirectories(bool preselectMissingOrOutdated = false);
|
||||||
|
|
||||||
//! Init and preselect directories
|
|
||||||
void initAndPreselectDirectories();
|
|
||||||
|
|
||||||
//! Are there other versions to copy from
|
//! Are there other versions to copy from
|
||||||
bool hasOtherVersionData() const;
|
bool hasOtherVersionData() const;
|
||||||
@@ -70,9 +67,6 @@ namespace BlackGui
|
|||||||
//! Get the selected files
|
//! Get the selected files
|
||||||
QStringList getSelectedFiles() const;
|
QStringList getSelectedFiles() const;
|
||||||
|
|
||||||
//! Set calculated combobox width
|
|
||||||
void setComboBoxWidth();
|
|
||||||
|
|
||||||
QStringList m_otherVersionDirs;
|
QStringList m_otherVersionDirs;
|
||||||
QScopedPointer<Ui::CCopyConfigurationComponent> ui;
|
QScopedPointer<Ui::CCopyConfigurationComponent> ui;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,12 +20,46 @@
|
|||||||
<enum>QFrame::Raised</enum>
|
<enum>QFrame::Raised</enum>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="3" column="0">
|
<item row="1" column="0" colspan="2">
|
||||||
|
<widget class="QFrame" name="fr_Directories">
|
||||||
|
<layout class="QHBoxLayout" name="hl_Directories">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
<widget class="QGroupBox" name="gb_Source">
|
<widget class="QGroupBox" name="gb_Source">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Source (other versions)</string>
|
<string>Source (other versions)</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="vl_Source">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="cb_OtherVersions">
|
||||||
|
<property name="frame">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeView" name="tv_Source">
|
<widget class="QTreeView" name="tv_Source">
|
||||||
<property name="alternatingRowColors">
|
<property name="alternatingRowColors">
|
||||||
@@ -45,12 +79,31 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item>
|
||||||
<widget class="QGroupBox" name="gb_Destination">
|
<widget class="QGroupBox" name="gb_Destination">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Destination (this version)</string>
|
<string>Destination (this version)</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="vl_Destination">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="le_CurrentVersion">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeView" name="tv_Destination">
|
<widget class="QTreeView" name="tv_Destination">
|
||||||
<property name="alternatingRowColors">
|
<property name="alternatingRowColors">
|
||||||
@@ -70,16 +123,9 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
</layout>
|
||||||
<widget class="QLineEdit" name="le_CurrentVersion">
|
|
||||||
<property name="readOnly">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QComboBox" name="cb_OtherVersions"/>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QWidget" name="wi_Mode" native="true">
|
<widget class="QWidget" name="wi_Mode" native="true">
|
||||||
<layout class="QHBoxLayout" name="hl_RadioButtons">
|
<layout class="QHBoxLayout" name="hl_RadioButtons">
|
||||||
|
|||||||
@@ -101,6 +101,13 @@ namespace BlackMisc
|
|||||||
return QDir::cleanPath(path1 + QChar('/') + path2);
|
return QDir::cleanPath(path1 + QChar('/') + path2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CFileUtils::stripFileFromPath(const QString &path)
|
||||||
|
{
|
||||||
|
if (path.endsWith('/')) { return path; }
|
||||||
|
if (!path.contains('/')) { return path; }
|
||||||
|
return path.left(path.lastIndexOf('/'));
|
||||||
|
}
|
||||||
|
|
||||||
QString CFileUtils::appendFilePaths(const QString &path1, const QString &path2, const QString &path3)
|
QString CFileUtils::appendFilePaths(const QString &path1, const QString &path2, const QString &path3)
|
||||||
{
|
{
|
||||||
return CFileUtils::appendFilePaths(CFileUtils::appendFilePaths(path1, path2), path3);
|
return CFileUtils::appendFilePaths(CFileUtils::appendFilePaths(path1, path2), path3);
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ namespace BlackMisc
|
|||||||
//! \sa CNetworkUtils::buildUrl for URLs
|
//! \sa CNetworkUtils::buildUrl for URLs
|
||||||
static QString appendFilePaths(const QString &path1, const QString &path2);
|
static QString appendFilePaths(const QString &path1, const QString &path2);
|
||||||
|
|
||||||
|
//! Strip file from path a/b/c.json a/b
|
||||||
|
static QString stripFileFromPath(const QString &path);
|
||||||
|
|
||||||
//! Append file paths
|
//! Append file paths
|
||||||
//! \sa CNetworkUtils::buildUrl for URLs
|
//! \sa CNetworkUtils::buildUrl for URLs
|
||||||
static QString appendFilePaths(const QString &path1, const QString &path2, const QString &path3);
|
static QString appendFilePaths(const QString &path1, const QString &path2, const QString &path3);
|
||||||
|
|||||||
Reference in New Issue
Block a user