swift
otherswiftversionscomponent.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QDesktopServices>
7 #include <QUrl>
8 
9 #include "ui_otherswiftversionscomponent.h"
10 
11 #include "gui/guiapplication.h"
12 #include "misc/directoryutils.h"
13 #include "misc/swiftdirectories.h"
14 
15 using namespace swift::misc;
16 using namespace swift::gui::views;
17 
18 namespace swift::gui::components
19 {
20  COtherSwiftVersionsComponent::COtherSwiftVersionsComponent(QWidget *parent)
21  : QFrame(parent), ui(new Ui::COtherSwiftVersionsComponent)
22  {
23  ui->setupUi(this);
24 
25  ui->tvp_ApplicationInfo->menuRemoveItems(CApplicationInfoView::MenuClear);
26  ui->tvp_ApplicationInfo->menuAddItems(CApplicationInfoView::MenuRefresh);
27  ui->tvp_ApplicationInfo->otherSwiftVersionsFromDataDirectories();
28 
29  ui->le_ThisVersion->setText(sGui->getApplicationInfo().asOtherSwiftVersionString());
30  ui->le_ThisVersion->home(false);
31 
32  connect(ui->tb_DataDir, &QToolButton::clicked, this, &COtherSwiftVersionsComponent::openDataDirectory);
33  connect(ui->tvp_ApplicationInfo, &CApplicationInfoView::objectSelected, this,
34  &COtherSwiftVersionsComponent::onObjectSelected);
35  connect(ui->tvp_ApplicationInfo, &CApplicationInfoView::requestUpdate, this,
37  }
38 
40 
41  bool COtherSwiftVersionsComponent::hasSelection() const { return (ui->tvp_ApplicationInfo->hasSelection()); }
42 
44  {
45  if (!this->hasSelection()) { return CApplicationInfo::null(); }
46  return ui->tvp_ApplicationInfo->selectedObject();
47  }
48 
50  {
51  if (deferMs <= 0) { ui->tvp_ApplicationInfo->otherSwiftVersionsFromDataDiretoriesAndResize(true); }
52  else
53  {
54  QPointer<COtherSwiftVersionsComponent> myself(this);
55  QTimer::singleShot(deferMs, this, [=] {
56  if (myself) { myself->reloadOtherVersionsDeferred(-1); }
57  });
58  }
59  }
60 
61  void COtherSwiftVersionsComponent::openDataDirectory()
62  {
63  const QString dir = CSwiftDirectories::applicationDataDirectory();
64  const QUrl url = QUrl::fromLocalFile(dir);
65  QDesktopServices::openUrl(url);
66  }
67 
68  void COtherSwiftVersionsComponent::onObjectSelected(const CVariant &object)
69  {
70  if (!object.canConvert<CApplicationInfo>()) { return; }
71  const CApplicationInfo info(object.value<CApplicationInfo>());
72  emit this->versionChanged(info);
73  }
74 } // namespace swift::gui::components
const swift::misc::CApplicationInfo & getApplicationInfo() const
swift application running
Definition: application.h:138
swift::misc::CApplicationInfo selectedOtherVersion() const
Get the selected other version.
void versionChanged(const swift::misc::CApplicationInfo &info)
Selection changed.
Description of a swift application.
QString asOtherSwiftVersionString(const QString &separator=" | ") const
Formatted info.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition: variant.h:66
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
High level reusable GUI components.
Definition: aboutdialog.cpp:13
Views, mainly QTableView.
Free functions in swift::misc.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...
Definition: threadutils.h:30