swift
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 
4 #include "applicationinfoview.h"
5 
6 #include <QDir>
7 #include <QMessageBox>
8 
9 #include "misc/fileutils.h"
10 
11 using namespace swift::misc;
12 using namespace swift::gui::models;
13 using namespace swift::gui::menus;
14 
15 namespace swift::gui::views
16 {
17  CApplicationInfoView::CApplicationInfoView(QWidget *parent) : CViewBase(parent)
18  {
19  this->standardInit(new CApplicationInfoListModel(this));
20  this->setCustomMenu(new CApplicationInfoMenu(this));
21  }
22 
24  {
25  const CApplicationInfoList others =
26  CApplicationInfoList::fromOtherSwiftVersionsFromDataDirectories(reinitOtherVersions);
27  m_acceptRowSelection = (!others.isEmpty());
28 
29  this->updateContainer(others);
30  return others.size();
31  }
32 
34  {
35  const int r = this->otherSwiftVersionsFromDataDirectories(reinitOtherVersion);
37  this->resizeRowsToContents();
38  return r;
39  }
40 
42  {
43  if (!this->hasSelection()) { return; }
44  const QMessageBox::StandardButton reply = QMessageBox::question(
45  this, "Delete?", "Delete selected data directories?", QMessageBox::Yes | QMessageBox::No);
46  if (reply != QMessageBox::Yes) { return; }
47 
48  QStringList deletedDirectories;
49  for (const CApplicationInfo &info : this->selectedObjects())
50  {
51  const QString d = CFileUtils::fixWindowsUncPath(info.getApplicationDataDirectory());
52  QDir dir(d);
53  if (!dir.exists()) { continue; }
54  if (dir.removeRecursively()) { deletedDirectories << d; }
55  }
56  if (deletedDirectories.isEmpty()) { return; }
58  }
59 
61  {
62  if (!this->view()) { return; }
63  if (!this->view()->isEmpty())
64  {
65  m_menuActionDeleteDirectory = menuActions.addAction(
66  m_menuActionDeleteDirectory, CIcons::delete16(), "Delete data directories", CMenuAction::pathNone(),
68  }
69  this->nestedCustomMenu(menuActions);
70  }
71 
72  CApplicationInfoView *CApplicationInfoMenu::view() const
73  {
74  return static_cast<CApplicationInfoView *>(this->parent());
75  }
76 } // namespace swift::gui::views
Bunch of CMenuAction objects.
Definition: menuaction.h:384
CMenuAction addAction(const CMenuAction &menuAction)
Add menu action.
Definition: menuaction.cpp:210
void nestedCustomMenu(CMenuActions &menuActions) const
Delegate down one level.
Definition: menudelegate.h:49
Menu base class for aircraft model view menus.
virtual void customMenu(menus::CMenuActions &menuActions)
Display custom menu.
int otherSwiftVersionsFromDataDiretoriesAndResize(bool reinitOtherVersion=false)
Display versions and resize.
int otherSwiftVersionsFromDataDirectories(bool reinitOtherVersions=false)
swift::misc::CApplicationInfoList::otherSwiftVersionsFromDataDirectories
void deleteSelectedDataDirectories()
Delete the selected directories.
Base class for views.
Definition: viewbase.h:648
void standardInit(ModelClass *model=nullptr)
Standard initialization.
Definition: viewbase.cpp:572
virtual ContainerType selectedObjects() const
Selected objects.
Definition: viewbase.cpp:240
void setPercentageColumnWidths()
Set the widths based on the column percentages.
Definition: viewbase.cpp:549
int updateContainer(const ContainerType &container, bool sort=true, bool resize=true)
Update whole container.
Definition: viewbase.cpp:38
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.
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.