KNewStuff

downloaddialog.cpp
1 /*
2  knewstuff3/ui/downloaddialog.cpp.
3  SPDX-FileCopyrightText: 2005 Enrico Ros <[email protected]>
4  SPDX-FileCopyrightText: 2005-2007 Josef Spillner <[email protected]>
5  SPDX-FileCopyrightText: 2007 Dirk Mueller <[email protected]>
6  SPDX-FileCopyrightText: 2007-2009 Jeremy Whiting <[email protected]>
7  SPDX-FileCopyrightText: 2009-2010 Frederik Gladhorn <[email protected]>
8 
9  SPDX-License-Identifier: LGPL-2.1-or-later
10 */
11 
12 #include "downloaddialog.h"
13 
14 
15 #include <KSharedConfig>
16 #include <KTitleWidget>
17 #include <kwindowconfig.h>
18 #include <QCoreApplication>
19 #include <KStandardGuiItem>
20 #include <KLocalizedString>
21 #include <KAuthorized>
22 #include <KMessageBox>
23 
24 #include "downloadwidget.h"
25 #include "downloadwidget_p.h"
26 #include "ui/widgetquestionlistener.h"
27 
28 namespace KNS3
29 {
30 class DownloadDialogPrivate
31 {
32 public:
33  ~DownloadDialogPrivate()
34  {
35  delete downloadWidget;
36  }
37 
38  DownloadWidget *downloadWidget = nullptr;
39 };
40 }
41 
42 using namespace KNS3;
43 
44 const char ConfigGroup[] = "DownloadDialog Settings";
45 
47  : QDialog(parent)
48  , d(new DownloadDialogPrivate)
49 {
51  init(name + QStringLiteral(".knsrc"));
52 }
53 
55  : QDialog(parent)
56  , d(new DownloadDialogPrivate)
57 {
58  init(configFile);
59 }
60 
61 void DownloadDialog::init(const QString &configFile)
62 {
63  // load the last size from config
64  KConfigGroup group(KSharedConfig::openConfig(), ConfigGroup);
66  setMinimumSize(700, 400);
67 
68  setWindowTitle(i18n("Get Hot New Stuff"));
69 
70  QVBoxLayout *layout = new QVBoxLayout(this);
71  d->downloadWidget = new DownloadWidget(configFile, this);
72  // DownloadWidget already provides margins, which would duplicate the dialog layout margins.
73  // As the widget theme could use different margin sizes for a dialog/window outer layout,
74  // so from the duplicated margins we pick the internal margins to remove here.
75  d->downloadWidget->layout()->setContentsMargins(0, 0, 0, 0);
76  layout->addWidget(d->downloadWidget);
77 
78  if (group.hasKey("Name")) {
79  d->downloadWidget->setTitle(group.readEntry("Name"));
80  } else {
82  if (displayName.isEmpty()) {
83  displayName = QCoreApplication::applicationName();
84  }
85  d->downloadWidget->setTitle(i18nc("Program name followed by 'Add On Installer'",
86  "%1 Add-On Installer", displayName));
87  }
88  //d->downloadWidget->d->ui.m_titleWidget->setPixmap(QIcon::fromTheme(KGlobal::activeComponent().aboutData()->programIconName()));
89  d->downloadWidget->d->ui.m_titleWidget->setVisible(true);
90  d->downloadWidget->d->ui.closeButton->setVisible(true);
91  KStandardGuiItem::assign(d->downloadWidget->d->ui.closeButton, KStandardGuiItem::Close);
92  d->downloadWidget->d->dialogMode = true;
93  connect(d->downloadWidget->d->ui.closeButton, &QAbstractButton::clicked, this, &QDialog::accept);
94  WidgetQuestionListener::instance();
95 }
96 
98 {
99  KConfigGroup group(KSharedConfig::openConfig(), ConfigGroup);
101  delete d;
102 }
103 
104 int DownloadDialog::exec()
105 {
106  if (!KAuthorized::authorize(QStringLiteral("ghns"))) {
107  KMessageBox::information(this, QStringLiteral("Get Hot New Stuff is disabled by the administrator"), QStringLiteral("Get Hot New Stuff disabled"));
108  return QDialog::Rejected;
109  }
110  return QDialog::exec();
111 }
112 
113 void DownloadDialog::open()
114 {
115  if (!KAuthorized::authorize(QStringLiteral("ghns"))) {
116  KMessageBox::information(this, QStringLiteral("Get Hot New Stuff is disabled by the administrator"), QStringLiteral("Get Hot New Stuff disabled"));
117  return;
118  }
119  QDialog::open();
120 }
121 
122 void DownloadDialog::showEvent(QShowEvent *event)
123 {
124  if (!KAuthorized::authorize(QStringLiteral("ghns"))) {
125  KMessageBox::information(this, QStringLiteral("Get Hot New Stuff is disabled by the administrator"), QStringLiteral("Get Hot New Stuff disabled"));
126  return;
127  }
128  QWidget::showEvent(event);
129 }
130 
132 {
133  d->downloadWidget->setTitle(title);
134 }
135 
137 {
138  return d->downloadWidget->title();
139 }
140 
142 {
143  return d->downloadWidget->engine();
144 }
145 
147 {
148  return d->downloadWidget->changedEntries();
149 }
150 
152 {
153  return d->downloadWidget->installedEntries();
154 }
155 
QLayout * layout() const const
virtual void open()
QString title() const
Get the current title.
virtual int exec()
KNewStuff download widget.
void setMinimumSize(const QSize &)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
virtual void showEvent(QShowEvent *event)
void setTitle(const QString &title)
Set the title for display purposes in the widget&#39;s title.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
bool isEmpty() const const
void clicked(bool checked)
~DownloadDialog() override
destructor
DownloadDialog(QWidget *parent=nullptr)
Create a DownloadDialog that lets the user install, update and uninstall contents.
virtual void accept()
KNS3::Entry::List changedEntries()
The list of entries with changed status (installed/uninstalled)
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
bool hasKey(const QString &key) const
QWindow * windowHandle() const const
QString i18n(const char *text, const TYPE &arg...)
KNSCore::Engine * engine()
void setWindowTitle(const QString &)
KCONFIGCORE_EXPORT bool authorize(const QString &action)
KNewStuff engine.
Definition: engine.h:59
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
void information(QWidget *parent, const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
The namespace for the KNewStuff classes.
Definition: button.cpp:19
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
virtual bool event(QEvent *event) override
T readEntry(const QString &key, const T &aDefault) const
QString applicationDisplayName()
KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal)
KNS3::Entry::List installedEntries()
The list of entries that have been newly installed.
QString applicationName()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 18 2021 22:43:49 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.