Ref T199, copy configuration as dialog + some utility functions

This commit is contained in:
Klaus Basan
2017-12-25 13:14:14 +01:00
parent be05afa542
commit 2509a1581b
5 changed files with 218 additions and 6 deletions

View File

@@ -43,9 +43,7 @@ namespace BlackGui
ui(new Ui::CCopyConfigurationComponent)
{
ui->setupUi(this);
ui->cb_OtherVersions->clear();
ui->cb_OtherVersions->addItems(CDirectoryUtils::applicationDataDirectoryList(true, true));
m_otherVersionDirs = CDirectoryUtils::applicationDataDirectoryList(true, false); // not beautified
this->initOtherSwiftVersions();
connect(ui->rb_Cache, &QRadioButton::toggled, [ = ](bool) { this->initCurrentDirectories(true); });
connect(ui->cb_OtherVersions, &QComboBox::currentTextChanged, [ = ] { this->initCurrentDirectories(true); });
@@ -259,6 +257,11 @@ namespace BlackGui
ui->rb_Settings->setEnabled(allow);
}
void CCopyConfigurationComponent::selectAll()
{
ui->tv_Source->selectAll();
}
void CCopyConfigurationComponent::resizeEvent(QResizeEvent *event)
{
const int w = 0.45 * this->width();
@@ -279,9 +282,9 @@ namespace BlackGui
QString CCopyConfigurationComponent::getOtherVersionsSelectedDirectory() const
{
if (ui->cb_OtherVersions->count() < 1) { return ""; }
if (ui->cb_OtherVersions->count() < 1) { return QStringLiteral(""); }
const QFileInfoList dirs(CDirectoryUtils::applicationDataDirectories());
if (dirs.isEmpty()) { return ""; }
if (dirs.isEmpty()) { return QStringLiteral(""); }
const QString otherVersionDir = m_otherVersionDirs.at(ui->cb_OtherVersions->currentIndex());
QString dir;
for (const QFileInfo &info : dirs)
@@ -292,7 +295,7 @@ namespace BlackGui
break;
}
}
if (dir.isEmpty()) { return ""; }
if (dir.isEmpty()) { return QStringLiteral(""); }
dir = CFileUtils::appendFilePaths(dir, ui->rb_Cache->isChecked() ?
CDataCache::relativeFilePath() :
CSettingsCache::relativeFilePath());
@@ -354,6 +357,26 @@ namespace BlackGui
CGuiApplication::processEventsFor(2500);
}
void CCopyConfigurationComponent::initOtherSwiftVersions()
{
ui->cb_OtherVersions->clear();
const QMap<QString, CApplicationInfo> otherVersions = CDirectoryUtils::applicationDataDirectoryMap(true);
for (const QString &directory : otherVersions.keys())
{
const CApplicationInfo info(otherVersions.value(directory));
if (info.isNull())
{
ui->cb_OtherVersions->addItem(CDirectoryUtils::decodeNormalizedDirectory(directory));
}
else
{
static const QString item("swift %1 (%2)");
ui->cb_OtherVersions->addItem(item.arg(info.getVersionString(), info.getPlatform()));
}
m_otherVersionDirs.push_back(directory);
}
}
const CLogCategoryList &CCopyConfigurationWizardPage::getLogCategories()
{
static const BlackMisc::CLogCategoryList cats { CLogCategory::wizard(), CLogCategory::guiComponent() };

View File

@@ -63,6 +63,9 @@ namespace BlackGui
//! Log copied files
void logCopiedFiles(bool log) { m_logCopiedFiles = log; }
//! Select all
void selectAll();
protected:
//! \copydoc QWidget::resizeEvent
virtual void resizeEvent(QResizeEvent *event) override;
@@ -93,6 +96,9 @@ namespace BlackGui
//! Init model caches if required (create .rev entries with high level functions)
void initModelCaches(const QStringList &files);
//! Init the other swift versions
void initOtherSwiftVersions();
QStringList m_otherVersionDirs;
QScopedPointer<Ui::CCopyConfigurationComponent> ui;
QString m_initializedSourceDir;

View File

@@ -0,0 +1,43 @@
/* Copyright (C) 2017
* swift project community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "copyconfigurationdialog.h"
#include "ui_copyconfigurationdialog.h"
namespace BlackGui
{
namespace Components
{
CCopyConfigurationDialog::CCopyConfigurationDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CCopyConfigurationDialog)
{
ui->setupUi(this);
this->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
}
CCopyConfigurationDialog::~CCopyConfigurationDialog()
{ }
void CCopyConfigurationDialog::setCacheCode()
{
ui->comp_CopyConfiguration->setCacheMode();
}
void CCopyConfigurationDialog::setSettingsMode()
{
ui->comp_CopyConfiguration->setSettingsMode();
}
void CCopyConfigurationDialog::selectAll()
{
ui->comp_CopyConfiguration->selectAll();
}
} // ns
} // ns

View File

@@ -0,0 +1,52 @@
/* Copyright (C) 2017
* swift project community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKGUI_COMPONENTS_COPYCONFIGURATIONDIALOG_H
#define BLACKGUI_COMPONENTS_COPYCONFIGURATIONDIALOG_H
#include "blackgui/blackguiexport.h"
#include <QDialog>
#include <QScopedPointer>
namespace Ui { class CCopyConfigurationDialog; }
namespace BlackGui
{
namespace Components
{
/**
* Dialog to copy cache and settings
*/
class BLACKGUI_EXPORT CCopyConfigurationDialog : public QDialog
{
Q_OBJECT
public:
//! Constructor
explicit CCopyConfigurationDialog(QWidget *parent = nullptr);
//! Destructor
virtual ~CCopyConfigurationDialog();
//! For cache data
void setCacheCode();
//! For settings
void setSettingsMode();
//! Select all settings or caches
void selectAll();
private:
QScopedPointer<Ui::CCopyConfigurationDialog> ui;
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CCopyConfigurationDialog</class>
<widget class="QDialog" name="CCopyConfigurationDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>480</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>600</width>
<height>400</height>
</size>
</property>
<property name="windowTitle">
<string>Copy configuration component</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="BlackGui::Components::CCopyConfigurationComponent" name="comp_CopyConfiguration">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="bb_CopyConfigurationDialog">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Components::CCopyConfigurationComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/copyconfigurationcomponent.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>bb_CopyConfigurationDialog</sender>
<signal>accepted()</signal>
<receiver>CCopyConfigurationDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>bb_CopyConfigurationDialog</sender>
<signal>rejected()</signal>
<receiver>CCopyConfigurationDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>