mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 02:45:33 +08:00
refs #887, UI for settings / cache copying
* newer / missing files preselected * copied files will be copied
This commit is contained in:
@@ -8,7 +8,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "copyconfigurationcomponent.h"
|
#include "copyconfigurationcomponent.h"
|
||||||
|
#include "blackconfig/buildconfig.h"
|
||||||
|
#include "blackmisc/directoryutils.h"
|
||||||
#include "ui_copyconfigurationcomponent.h"
|
#include "ui_copyconfigurationcomponent.h"
|
||||||
|
#include "blackmisc/settingscache.h"
|
||||||
|
#include "blackmisc/datacache.h"
|
||||||
|
|
||||||
|
#include <QDirIterator>
|
||||||
|
#include <QFileInfoList>
|
||||||
|
#include <QFileSystemModel>
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
|
using namespace BlackConfig;
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
@@ -19,9 +30,156 @@ namespace BlackGui
|
|||||||
ui(new Ui::CCopyConfigurationComponent)
|
ui(new Ui::CCopyConfigurationComponent)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
ui->cb_OtherVersions->clear();
|
||||||
|
ui->cb_OtherVersions->addItems(CDirectoryUtils::swiftApplicationDataDirectoryList(true, true));
|
||||||
|
m_versionDirs = CDirectoryUtils::swiftApplicationDataDirectoryList(true, false); // not beautified
|
||||||
|
|
||||||
|
this->initCurrentDirectories();
|
||||||
|
this->preselectMissingOurOutdated();
|
||||||
|
|
||||||
|
connect(ui->rb_Cache, &QRadioButton::toggled, this, &CCopyConfigurationComponent::initCurrentDirectories);
|
||||||
|
connect(ui->cb_OtherVersions, &QComboBox::currentTextChanged, this, &CCopyConfigurationComponent::initCurrentDirectories);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCopyConfigurationComponent::~CCopyConfigurationComponent()
|
CCopyConfigurationComponent::~CCopyConfigurationComponent()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
void CCopyConfigurationComponent::setCacheMode()
|
||||||
|
{
|
||||||
|
ui->rb_Cache->setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCopyConfigurationComponent::setSettingsMode()
|
||||||
|
{
|
||||||
|
ui->rb_Settings->setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCopyConfigurationComponent::copySelectedFiles()
|
||||||
|
{
|
||||||
|
const QStringList files = this->getSelectedFiles();
|
||||||
|
if (files.isEmpty()) { return; }
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCopyConfigurationComponent::preselectMissingOurOutdated()
|
||||||
|
{
|
||||||
|
const QString dirOther = this->getOtherVersionsSelectedDirectory();
|
||||||
|
const QString dirCurrent = this->getThisVersionDirectory();
|
||||||
|
|
||||||
|
ui->tv_Destination->clearSelection();
|
||||||
|
const CDirectoryUtils::DirComparison comp = CDirectoryUtils::compareTwoDirectories(dirOther, dirCurrent);
|
||||||
|
const QFileSystemModel *model = qobject_cast<QFileSystemModel *>(ui->tv_Destination->model());
|
||||||
|
|
||||||
|
QStringList select = comp.missingInTarget.toList();
|
||||||
|
select.append(comp.newerInSource.toList());
|
||||||
|
for (const QString &file : as_const(comp.missingInTarget))
|
||||||
|
{
|
||||||
|
ui->tv_Destination->setCurrentIndex(model->index(file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCopyConfigurationComponent::initCurrentDirectories()
|
||||||
|
{
|
||||||
|
ui->le_CurrentVersion->setText(CDirectoryUtils::applicationDirectoryPath());
|
||||||
|
this->setComboBoxWidth();
|
||||||
|
const QString dir = this->getOtherVersionsSelectedDirectory();
|
||||||
|
if (dir.isEmpty()) { return; }
|
||||||
|
|
||||||
|
// source
|
||||||
|
QFileSystemModel *sourceModel = qobject_cast<QFileSystemModel *>(ui->tv_Source->model());
|
||||||
|
if (!sourceModel)
|
||||||
|
{
|
||||||
|
sourceModel = new QFileSystemModel(this);
|
||||||
|
sourceModel->setFilter(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs);
|
||||||
|
sourceModel->setNameFilterDisables(false);
|
||||||
|
sourceModel->setNameFilters(QStringList("*.json"));
|
||||||
|
ui->tv_Source->setModel(sourceModel);
|
||||||
|
connect(sourceModel, &QFileSystemModel::directoryLoaded, this, [ = ](const QString & path)
|
||||||
|
{
|
||||||
|
Q_UNUSED(path);
|
||||||
|
ui->tv_Source->resizeColumnToContents(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const QModelIndex sourceIndex = sourceModel->setRootPath(dir);
|
||||||
|
ui->tv_Source->setRootIndex(sourceIndex);
|
||||||
|
ui->tv_Source->setSortingEnabled(true);
|
||||||
|
|
||||||
|
// destination
|
||||||
|
QFileSystemModel *destinationModel = qobject_cast<QFileSystemModel *>(ui->tv_Destination->model());
|
||||||
|
if (!destinationModel)
|
||||||
|
{
|
||||||
|
destinationModel = new QFileSystemModel(this);
|
||||||
|
destinationModel->setFilter(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs);
|
||||||
|
destinationModel->setNameFilterDisables(false);
|
||||||
|
destinationModel->setNameFilters(QStringList("*.json"));
|
||||||
|
ui->tv_Destination->setModel(destinationModel);
|
||||||
|
connect(destinationModel, &QFileSystemModel::directoryLoaded, this, [ = ](const QString & path)
|
||||||
|
{
|
||||||
|
Q_UNUSED(path);
|
||||||
|
ui->tv_Destination->resizeColumnToContents(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const QString destinationDir = this->getThisVersionDirectory();
|
||||||
|
const QModelIndex destinationIndex = destinationModel->setRootPath(destinationDir);
|
||||||
|
ui->tv_Destination->setRootIndex(destinationIndex);
|
||||||
|
ui->tv_Destination->setSortingEnabled(true);
|
||||||
|
ui->tv_Destination->resizeColumnToContents(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCopyConfigurationComponent::currentVersionChanged(const QString &text)
|
||||||
|
{
|
||||||
|
Q_UNUSED(text);
|
||||||
|
this->initCurrentDirectories();
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &CCopyConfigurationComponent::getThisVersionDirectory() const
|
||||||
|
{
|
||||||
|
return ui->rb_Cache->isChecked() ? CDataCache::persistentStore() : CSettingsCache::persistentStore();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CCopyConfigurationComponent::getOtherVersionsSelectedDirectory() const
|
||||||
|
{
|
||||||
|
const QString s = m_versionDirs.at(ui->cb_OtherVersions->currentIndex());
|
||||||
|
const QFileInfoList dirs(CDirectoryUtils::swiftApplicationDataDirectories());
|
||||||
|
if (dirs.isEmpty()) { return ""; }
|
||||||
|
QString dir;
|
||||||
|
for (const QFileInfo &info : dirs)
|
||||||
|
{
|
||||||
|
if (info.absoluteFilePath().contains(s))
|
||||||
|
{
|
||||||
|
dir = info.absoluteFilePath();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dir.isEmpty()) { return ""; }
|
||||||
|
dir = CFileUtils::appendFilePaths(dir, ui->rb_Cache->isChecked() ?
|
||||||
|
CDataCache::relativeFilePath() :
|
||||||
|
CSettingsCache::relativeFilePath());
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CCopyConfigurationComponent::getSelectedFiles() const
|
||||||
|
{
|
||||||
|
const QModelIndexList indexes = ui->tv_Source->selectionModel()->selectedIndexes();
|
||||||
|
if (indexes.isEmpty()) { return QStringList(); }
|
||||||
|
const QFileSystemModel *sourceModel = qobject_cast<QFileSystemModel *>(ui->tv_Source->model());
|
||||||
|
|
||||||
|
QStringList files;
|
||||||
|
for (const QModelIndex &index : indexes)
|
||||||
|
{
|
||||||
|
if (!index.isValid()) continue;
|
||||||
|
const QString file = sourceModel->filePath(index);
|
||||||
|
if (!files.contains(file))
|
||||||
|
{
|
||||||
|
files.push_back(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCopyConfigurationComponent::setComboBoxWidth()
|
||||||
|
{
|
||||||
|
const int width = this->width() * 0.45;
|
||||||
|
ui->cb_OtherVersions->setFixedWidth(width);
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
namespace Ui { class CCopyConfigurationComponent; }
|
namespace Ui { class CCopyConfigurationComponent; }
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
@@ -21,7 +22,7 @@ namespace BlackGui
|
|||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Copy configuration (ie settings and cache files)
|
* Copy configuration (i.e. settings and cache files)
|
||||||
*/
|
*/
|
||||||
class BLACKGUI_EXPORT CCopyConfigurationComponent : public QFrame
|
class BLACKGUI_EXPORT CCopyConfigurationComponent : public QFrame
|
||||||
{
|
{
|
||||||
@@ -34,7 +35,38 @@ namespace BlackGui
|
|||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CCopyConfigurationComponent();
|
virtual ~CCopyConfigurationComponent();
|
||||||
|
|
||||||
|
//! Cache mode
|
||||||
|
void setCacheMode();
|
||||||
|
|
||||||
|
//! Settings mode
|
||||||
|
void setSettingsMode();
|
||||||
|
|
||||||
|
//! Selected files are copied
|
||||||
|
void copySelectedFiles();
|
||||||
|
|
||||||
|
//! Preselect newer files
|
||||||
|
void preselectMissingOurOutdated();
|
||||||
|
|
||||||
|
//! Init file content
|
||||||
|
void initCurrentDirectories();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
//! The current version changed
|
||||||
|
void currentVersionChanged(const QString &text);
|
||||||
|
|
||||||
|
//! This version's directory (cache or setting)
|
||||||
|
const QString &getThisVersionDirectory() const;
|
||||||
|
|
||||||
|
//! Get the selected directory
|
||||||
|
QString getOtherVersionsSelectedDirectory() const;
|
||||||
|
|
||||||
|
//! Get the selected files
|
||||||
|
QStringList getSelectedFiles() const;
|
||||||
|
|
||||||
|
//! Combobox width
|
||||||
|
void setComboBoxWidth();
|
||||||
|
|
||||||
|
QStringList m_versionDirs;
|
||||||
QScopedPointer<Ui::CCopyConfigurationComponent> ui;
|
QScopedPointer<Ui::CCopyConfigurationComponent> ui;
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -20,32 +20,110 @@
|
|||||||
<enum>QFrame::Raised</enum>
|
<enum>QFrame::Raised</enum>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="1">
|
<item row="3" column="0">
|
||||||
<widget class="QGroupBox" name="gb_Destination">
|
|
||||||
<property name="title">
|
|
||||||
<string>Destination</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QTreeView" name="tv_Destination"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QGroupBox" name="gb_Source">
|
<widget class="QGroupBox" name="gb_Source">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Source</string>
|
<string>Source (other versions)</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeView" name="tv_Source"/>
|
<widget class="QTreeView" name="tv_Source">
|
||||||
|
<property name="alternatingRowColors">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::MultiSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sortingEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="animated">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="3" column="1">
|
||||||
<widget class="QComboBox" name="cb_Version"/>
|
<widget class="QGroupBox" name="gb_Destination">
|
||||||
|
<property name="title">
|
||||||
|
<string>Destination (this version)</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeView" name="tv_Destination">
|
||||||
|
<property name="alternatingRowColors">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::NoSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sortingEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="animated">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="le_CurrentVersion">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QComboBox" name="cb_OtherVersions"/>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0" colspan="2">
|
||||||
|
<widget class="QWidget" name="wi_Mode" native="true">
|
||||||
|
<layout class="QHBoxLayout" name="hl_RadioButtons">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="rb_Settings">
|
||||||
|
<property name="text">
|
||||||
|
<string>Settings</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="rb_Cache">
|
||||||
|
<property name="text">
|
||||||
|
<string>Cache</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="hs_Mode">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
Reference in New Issue
Block a user