swift
Loading...
Searching...
No Matches
applicationinfoview.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QDir>
7#include <QMessageBox>
8
9#include "misc/fileutils.h"
10
11using namespace swift::misc;
12using namespace swift::gui::models;
13using namespace swift::gui::menus;
14
15namespace swift::gui::views
16{
22
24 {
25 const CApplicationInfoList others =
27 m_acceptRowSelection = (!others.isEmpty());
28
29 this->updateContainer(others);
30 return others.size();
31 }
32
34 {
35 const int r = this->otherSwiftVersionsFromDataDirectories(reinitOtherVersion);
38 return r;
39 }
40
42 {
43 if (!this->hasSelection())
44 {
45 return;
46 }
48 this, "Delete?", "Delete selected data directories?", QMessageBox::Yes | QMessageBox::No);
49 if (reply != QMessageBox::Yes)
50 {
51 return;
52 }
53
54 QStringList deletedDirectories;
55 for (const CApplicationInfo &info : this->selectedObjects())
56 {
57 const QString d = CFileUtils::fixWindowsUncPath(info.getApplicationDataDirectory());
58 QDir dir(d);
59 if (!dir.exists())
60 {
61 continue;
62 }
63 if (dir.removeRecursively())
64 {
65 deletedDirectories << d;
66 }
67 }
68 if (deletedDirectories.isEmpty())
69 {
70 return;
71 }
73 }
74
76 {
77 if (!this->view())
78 {
79 return;
80 }
81 if (!this->view()->isEmpty())
82 {
83 m_menuActionDeleteDirectory = menuActions.addAction(
84 m_menuActionDeleteDirectory, CIcons::delete16(), "Delete data directories", CMenuAction::pathNone(),
86 }
87 this->nestedCustomMenu(menuActions);
88 }
89
90 CApplicationInfoView *CApplicationInfoMenu::view() const
91 {
92 return static_cast<CApplicationInfoView *>(this->parent());
93 }
94} // namespace swift::gui::views
static const QString & pathNone()
No key.
Definition menuaction.h:108
Bunch of CMenuAction objects.
Definition menuaction.h:384
CMenuAction addAction(const CMenuAction &menuAction)
Add menu action.
void nestedCustomMenu(CMenuActions &menuActions) const
Delegate down one level.
Menu base class for aircraft model view menus.
void customMenu(menus::CMenuActions &menuActions)
Display custom menu.
CApplicationInfoView(QWidget *parent=nullptr)
Constructor.
int otherSwiftVersionsFromDataDiretoriesAndResize(bool reinitOtherVersion=false)
Display versions and resize.
int otherSwiftVersionsFromDataDirectories(bool reinitOtherVersions=false)
swift::misc::CApplicationInfoList::otherSwiftVersionsFromDataDirectories
void deleteSelectedDataDirectories()
Delete the selected directories.
CViewBase(QWidget *parent, ModelClass *model=nullptr)
Definition viewbase.cpp:31
int updateContainer(const ContainerType &container, bool sort=true, bool resize=true)
Definition viewbase.cpp:41
bool m_acceptRowSelection
selection changed
Definition viewbase.h:595
menus::IMenuDelegate * setCustomMenu(menus::IMenuDelegate *menu, bool nestPreviousMenu=true)
Set custom menu if applicable.
bool hasSelection() const
Selection (selected rows).
Description of a swift application.
List of swift application descriptions.
static CApplicationInfoList fromOtherSwiftVersionsFromDataDirectories(bool reinit=false)
Filled from cache data directories.
static QString fixWindowsUncPath(const QString &filePath)
UNC file paths on Qt start with "/", but UNC file paths only work when they start with "//".
static const QPixmap & delete16()
Delete.
size_type size() const
Returns number of elements in the sequence.
Definition sequence.h:273
bool isEmpty() const
Synonym for empty.
Definition sequence.h:285
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
Free functions in swift::misc.
bool exists() const const
bool removeRecursively()
bool isEmpty() const const
QMessageBox::StandardButton question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QObject * parent() const const
void resizeRowsToContents()