mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-30 14:15:35 +08:00
Allow to delete data directory from application view
* allow to re-init applicazion list (needed because directories can be deleted) * context menu for "delete data directory"
This commit is contained in:
@@ -419,7 +419,7 @@ namespace BlackGui
|
|||||||
void CCopyConfigurationComponent::initOtherSwiftVersions()
|
void CCopyConfigurationComponent::initOtherSwiftVersions()
|
||||||
{
|
{
|
||||||
ui->cb_OtherVersions->clear();
|
ui->cb_OtherVersions->clear();
|
||||||
const QMap<QString, CApplicationInfo> otherVersions = CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion();
|
const QMap<QString, CApplicationInfo> otherVersions = CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion(true);
|
||||||
for (const QString &directory : otherVersions.keys())
|
for (const QString &directory : otherVersions.keys())
|
||||||
{
|
{
|
||||||
const CApplicationInfo info(otherVersions.value(directory));
|
const CApplicationInfo info(otherVersions.value(directory));
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ namespace BlackGui
|
|||||||
m_sortOrder = Qt::DescendingOrder;
|
m_sortOrder = Qt::DescendingOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CApplicationInfoListModel::otherSwiftVersionsFromDataDirectories()
|
void CApplicationInfoListModel::otherSwiftVersionsFromDataDirectories(bool reinit)
|
||||||
{
|
{
|
||||||
this->update(CApplicationInfoList::fromOtherSwiftVersionsFromDataDirectories());
|
this->update(CApplicationInfoList::fromOtherSwiftVersionsFromDataDirectories(reinit));
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace BlackGui
|
|||||||
virtual ~CApplicationInfoListModel() {}
|
virtual ~CApplicationInfoListModel() {}
|
||||||
|
|
||||||
//! \copydoc BlackMisc::CApplicationInfoList::fromOtherSwiftVersionsFromDataDirectories
|
//! \copydoc BlackMisc::CApplicationInfoList::fromOtherSwiftVersionsFromDataDirectories
|
||||||
void otherSwiftVersionsFromDataDirectories();
|
void otherSwiftVersionsFromDataDirectories(bool reinit);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -8,9 +8,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "applicationinfoview.h"
|
#include "applicationinfoview.h"
|
||||||
|
#include "blackmisc/fileutils.h"
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackGui::Models;
|
using namespace BlackGui::Models;
|
||||||
|
using namespace BlackGui::Menus;
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
@@ -19,6 +24,7 @@ namespace BlackGui
|
|||||||
CApplicationInfoView::CApplicationInfoView(QWidget *parent) : CViewBase(parent)
|
CApplicationInfoView::CApplicationInfoView(QWidget *parent) : CViewBase(parent)
|
||||||
{
|
{
|
||||||
this->standardInit(new CApplicationInfoListModel(this));
|
this->standardInit(new CApplicationInfoListModel(this));
|
||||||
|
this->setCustomMenu(new CApplicationInfoMenu(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
int CApplicationInfoView::otherSwiftVersionsFromDataDirectories()
|
int CApplicationInfoView::otherSwiftVersionsFromDataDirectories()
|
||||||
@@ -28,5 +34,41 @@ namespace BlackGui
|
|||||||
m_acceptRowSelection = (others.size() > 0);
|
m_acceptRowSelection = (others.size() > 0);
|
||||||
return others.size();
|
return others.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CApplicationInfoView::deleteSelectedDataDirectories()
|
||||||
|
{
|
||||||
|
if (!this->hasSelection()) { return; }
|
||||||
|
const QMessageBox::StandardButton reply = QMessageBox::question(this, "Delete?", "Delete selected data directories?", QMessageBox::Yes | QMessageBox::No);
|
||||||
|
if (reply != QMessageBox::Yes) { return; }
|
||||||
|
|
||||||
|
QStringList deletedDirectories;
|
||||||
|
for (const CApplicationInfo &info : this->selectedObjects())
|
||||||
|
{
|
||||||
|
const QString d = CFileUtils::fixWindowsUncPath(info.getApplicationDataDirectory());
|
||||||
|
QDir dir(d);
|
||||||
|
if (!dir.exists()) { continue; }
|
||||||
|
if (dir.removeRecursively())
|
||||||
|
{
|
||||||
|
deletedDirectories << d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (deletedDirectories.isEmpty()) { return; }
|
||||||
|
this->otherSwiftVersionsFromDataDirectories();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CApplicationInfoMenu::customMenu(CMenuActions &menuActions)
|
||||||
|
{
|
||||||
|
if (!this->view()) { return; }
|
||||||
|
if (!this->view()->isEmpty())
|
||||||
|
{
|
||||||
|
m_menuActionDeleteDirectory = menuActions.addAction(m_menuActionDeleteDirectory, CIcons::delete16(), "Delete data directories", CMenuAction::pathNone(), this, { this->view(), &CApplicationInfoView::deleteSelectedDataDirectories });
|
||||||
|
}
|
||||||
|
this->nestedCustomMenu(menuActions);
|
||||||
|
}
|
||||||
|
|
||||||
|
CApplicationInfoView *CApplicationInfoMenu::view() const
|
||||||
|
{
|
||||||
|
return static_cast<CApplicationInfoView *>(this->parent());
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -14,9 +14,10 @@
|
|||||||
|
|
||||||
#include "blackgui/views/viewbase.h"
|
#include "blackgui/views/viewbase.h"
|
||||||
#include "blackgui/models/applicationinfolistmodel.h"
|
#include "blackgui/models/applicationinfolistmodel.h"
|
||||||
|
#include "blackgui/menus/menudelegate.h"
|
||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
|
|
||||||
class QWidget;
|
#include <QAction>
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
@@ -31,7 +32,28 @@ namespace BlackGui
|
|||||||
|
|
||||||
//! BlackMisc::CApplicationInfoList::otherSwiftVersionsFromDataDirectories
|
//! BlackMisc::CApplicationInfoList::otherSwiftVersionsFromDataDirectories
|
||||||
int otherSwiftVersionsFromDataDirectories();
|
int otherSwiftVersionsFromDataDirectories();
|
||||||
|
|
||||||
|
//! Delete the selected directories
|
||||||
|
void deleteSelectedDataDirectories();
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
//! Menu base class for aircraft model view menus
|
||||||
|
class CApplicationInfoMenu : public Menus::IMenuDelegate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Constructor
|
||||||
|
CApplicationInfoMenu(CApplicationInfoView *modelView) : Menus::IMenuDelegate(modelView)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//! \copydoc Menus::IMenuDelegate::customMenu
|
||||||
|
virtual void customMenu(Menus::CMenuActions &menuActions);
|
||||||
|
|
||||||
|
private:
|
||||||
|
//! Model view
|
||||||
|
CApplicationInfoView *view() const;
|
||||||
|
|
||||||
|
QAction *m_menuActionDeleteDirectory = nullptr; //!< action to delete menu
|
||||||
|
};
|
||||||
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ namespace BlackMisc
|
|||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CApplicationInfoList::otherSwiftVersionsFromDataDirectories()
|
int CApplicationInfoList::otherSwiftVersionsFromDataDirectories(bool reinit)
|
||||||
{
|
{
|
||||||
this->clear();
|
this->clear();
|
||||||
const QMap<QString, CApplicationInfo> otherVersions = CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion();
|
const QMap<QString, CApplicationInfo> otherVersions = CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion(reinit);
|
||||||
for (const QString &directory : otherVersions.keys())
|
for (const QString &directory : otherVersions.keys())
|
||||||
{
|
{
|
||||||
CApplicationInfo info(otherVersions.value(directory));
|
CApplicationInfo info(otherVersions.value(directory));
|
||||||
@@ -54,14 +54,10 @@ namespace BlackMisc
|
|||||||
return this->size();
|
return this->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
CApplicationInfoList CApplicationInfoList::fromOtherSwiftVersionsFromDataDirectories()
|
CApplicationInfoList CApplicationInfoList::fromOtherSwiftVersionsFromDataDirectories(bool reinit)
|
||||||
{
|
{
|
||||||
static CApplicationInfoList info = []
|
CApplicationInfoList il;
|
||||||
{
|
il.otherSwiftVersionsFromDataDirectories(reinit);
|
||||||
CApplicationInfoList il;
|
return il;
|
||||||
il.otherSwiftVersionsFromDataDirectories();
|
|
||||||
return il;
|
|
||||||
}();
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -44,10 +44,10 @@ namespace BlackMisc
|
|||||||
QStringList processNames() const;
|
QStringList processNames() const;
|
||||||
|
|
||||||
//! Fill from cache data directories
|
//! Fill from cache data directories
|
||||||
int otherSwiftVersionsFromDataDirectories();
|
int otherSwiftVersionsFromDataDirectories(bool reinit = false);
|
||||||
|
|
||||||
//! Filled from cache data directories
|
//! Filled from cache data directories
|
||||||
static CApplicationInfoList fromOtherSwiftVersionsFromDataDirectories();
|
static CApplicationInfoList fromOtherSwiftVersionsFromDataDirectories(bool reinit = false);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
|
|||||||
@@ -144,42 +144,41 @@ namespace BlackMisc
|
|||||||
return dirs;
|
return dirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CDirectoryUtils::FilePerApplication &CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion()
|
const CDirectoryUtils::FilePerApplication &CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion(bool reinit)
|
||||||
{
|
{
|
||||||
static const FilePerApplication dirs = [ = ]() -> FilePerApplication
|
static FilePerApplication dirs;
|
||||||
{
|
if (!reinit && !dirs.isEmpty()) { return dirs; }
|
||||||
FilePerApplication directories;
|
|
||||||
for (const QFileInfo &info : CDirectoryUtils::applicationDataDirectories())
|
|
||||||
{
|
|
||||||
if (caseInsensitiveStringCompare(info.filePath(), CDirectoryUtils::normalizedApplicationDataDirectory())) { continue; }
|
|
||||||
|
|
||||||
// the application info will be written by each swift application started
|
FilePerApplication directories;
|
||||||
// so the application type will always contain that application
|
for (const QFileInfo &info : CDirectoryUtils::applicationDataDirectories())
|
||||||
const QString appInfoFile = CFileUtils::appendFilePaths(info.filePath(), CApplicationInfo::fileName());
|
{
|
||||||
const QString appInfoJson = CFileUtils::readFileToString(appInfoFile);
|
if (caseInsensitiveStringCompare(info.filePath(), CDirectoryUtils::normalizedApplicationDataDirectory())) { continue; }
|
||||||
CApplicationInfo appInfo;
|
|
||||||
if (appInfoJson.isEmpty())
|
// the application info will be written by each swift application started
|
||||||
{
|
// so the application type will always contain that application
|
||||||
const QString exeDir = CDirectoryUtils::decodeNormalizedDirectory(info.filePath());
|
const QString appInfoFile = CFileUtils::appendFilePaths(info.filePath(), CApplicationInfo::fileName());
|
||||||
appInfo.setExecutablePath(exeDir);
|
const QString appInfoJson = CFileUtils::readFileToString(appInfoFile);
|
||||||
}
|
CApplicationInfo appInfo;
|
||||||
else
|
if (appInfoJson.isEmpty())
|
||||||
{
|
{
|
||||||
appInfo = CApplicationInfo::fromJson(appInfoJson);
|
const QString exeDir = CDirectoryUtils::decodeNormalizedDirectory(info.filePath());
|
||||||
}
|
appInfo.setExecutablePath(exeDir);
|
||||||
appInfo.setApplicationDataDirectory(info.filePath());
|
|
||||||
directories.insert(info.filePath(), appInfo);
|
|
||||||
}
|
}
|
||||||
// https://stackoverflow.com/q/51635959/356726
|
else
|
||||||
// cppcheck-suppress returnReference
|
{
|
||||||
return directories;
|
appInfo = CApplicationInfo::fromJson(appInfoJson);
|
||||||
}();
|
}
|
||||||
|
appInfo.setApplicationDataDirectory(info.filePath());
|
||||||
|
directories.insert(info.filePath(), appInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
dirs = directories;
|
||||||
return dirs;
|
return dirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDirectoryUtils::hasOtherSwiftDataDirectories()
|
bool CDirectoryUtils::hasOtherSwiftDataDirectories(bool reinit)
|
||||||
{
|
{
|
||||||
return CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion().size() > 0;
|
return CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion(reinit).size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &CDirectoryUtils::normalizedApplicationDataDirectory()
|
const QString &CDirectoryUtils::normalizedApplicationDataDirectory()
|
||||||
|
|||||||
@@ -62,10 +62,10 @@ namespace BlackMisc
|
|||||||
static QStringList applicationDataDirectoryList(bool withoutCurrent = false, bool decodedDirName = false);
|
static QStringList applicationDataDirectoryList(bool withoutCurrent = false, bool decodedDirName = false);
|
||||||
|
|
||||||
//! swift application data sub directories with info if available
|
//! swift application data sub directories with info if available
|
||||||
static const FilePerApplication &applicationDataDirectoryMapWithoutCurrentVersion();
|
static const FilePerApplication &applicationDataDirectoryMapWithoutCurrentVersion(bool reinit = false);
|
||||||
|
|
||||||
//! Other swift data directories
|
//! Other swift data directories
|
||||||
static bool hasOtherSwiftDataDirectories();
|
static bool hasOtherSwiftDataDirectories(bool reinit = false);
|
||||||
|
|
||||||
//! Is MacOS application bundle?
|
//! Is MacOS application bundle?
|
||||||
//! \remark: Means the currently running executable is a MacOS bundle, but not all our executables are bundles on MacOS
|
//! \remark: Means the currently running executable is a MacOS bundle, but not all our executables are bundles on MacOS
|
||||||
|
|||||||
Reference in New Issue
Block a user