From 2509a1581bb8c5faab0984696bc1c9d2f2797df2 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 25 Dec 2017 13:14:14 +0100 Subject: [PATCH] Ref T199, copy configuration as dialog + some utility functions --- .../components/copyconfigurationcomponent.cpp | 35 ++++++-- .../components/copyconfigurationcomponent.h | 6 ++ .../components/copyconfigurationdialog.cpp | 43 +++++++++ .../components/copyconfigurationdialog.h | 52 +++++++++++ .../components/copyconfigurationdialog.ui | 88 +++++++++++++++++++ 5 files changed, 218 insertions(+), 6 deletions(-) create mode 100644 src/blackgui/components/copyconfigurationdialog.cpp create mode 100644 src/blackgui/components/copyconfigurationdialog.h create mode 100644 src/blackgui/components/copyconfigurationdialog.ui diff --git a/src/blackgui/components/copyconfigurationcomponent.cpp b/src/blackgui/components/copyconfigurationcomponent.cpp index 5f0d14b4d..b55da084a 100644 --- a/src/blackgui/components/copyconfigurationcomponent.cpp +++ b/src/blackgui/components/copyconfigurationcomponent.cpp @@ -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 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() }; diff --git a/src/blackgui/components/copyconfigurationcomponent.h b/src/blackgui/components/copyconfigurationcomponent.h index 822bf696f..e6827847b 100644 --- a/src/blackgui/components/copyconfigurationcomponent.h +++ b/src/blackgui/components/copyconfigurationcomponent.h @@ -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; QString m_initializedSourceDir; diff --git a/src/blackgui/components/copyconfigurationdialog.cpp b/src/blackgui/components/copyconfigurationdialog.cpp new file mode 100644 index 000000000..17f44b8fe --- /dev/null +++ b/src/blackgui/components/copyconfigurationdialog.cpp @@ -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 diff --git a/src/blackgui/components/copyconfigurationdialog.h b/src/blackgui/components/copyconfigurationdialog.h new file mode 100644 index 000000000..4ae273b96 --- /dev/null +++ b/src/blackgui/components/copyconfigurationdialog.h @@ -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 +#include + +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; + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackgui/components/copyconfigurationdialog.ui b/src/blackgui/components/copyconfigurationdialog.ui new file mode 100644 index 000000000..65853748a --- /dev/null +++ b/src/blackgui/components/copyconfigurationdialog.ui @@ -0,0 +1,88 @@ + + + CCopyConfigurationDialog + + + + 0 + 0 + 640 + 480 + + + + + 600 + 400 + + + + Copy configuration component + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + BlackGui::Components::CCopyConfigurationComponent + QFrame +
blackgui/components/copyconfigurationcomponent.h
+ 1 +
+
+ + + + bb_CopyConfigurationDialog + accepted() + CCopyConfigurationDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + bb_CopyConfigurationDialog + rejected() + CCopyConfigurationDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +