KNewStuff

downloaddialog.cpp
1 /*
2  knewstuff3/ui/downloaddialog.cpp.
3  Copyright (C) 2005 by Enrico Ros <[email protected]>
4  Copyright (C) 2005 - 2007 Josef Spillner <[email protected]>
5  Copyright (C) 2007 Dirk Mueller <[email protected]>
6  Copyright (C) 2007-2009 Jeremy Whiting <[email protected]>
7  Copyright (C) 2009-2010 Frederik Gladhorn <[email protected]>
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "downloaddialog.h"
24 
25 
26 #include <KSharedConfig>
27 #include <KTitleWidget>
28 #include <kwindowconfig.h>
29 #include <QCoreApplication>
30 #include <KStandardGuiItem>
31 #include <KLocalizedString>
32 #include <KAuthorized>
33 #include <KMessageBox>
34 
35 #include "downloadwidget.h"
36 #include "downloadwidget_p.h"
37 #include "ui/widgetquestionlistener.h"
38 
39 namespace KNS3
40 {
41 class DownloadDialogPrivate
42 {
43 public:
44  ~DownloadDialogPrivate()
45  {
46  delete downloadWidget;
47  }
48 
49  DownloadWidget *downloadWidget = nullptr;
50 };
51 }
52 
53 using namespace KNS3;
54 
55 const char ConfigGroup[] = "DownloadDialog Settings";
56 
58  : QDialog(parent)
59  , d(new DownloadDialogPrivate)
60 {
62  init(name + QStringLiteral(".knsrc"));
63 }
64 
66  : QDialog(parent)
67  , d(new DownloadDialogPrivate)
68 {
69  init(configFile);
70 }
71 
72 void DownloadDialog::init(const QString &configFile)
73 {
74  // load the last size from config
75  KConfigGroup group(KSharedConfig::openConfig(), ConfigGroup);
77  setMinimumSize(700, 400);
78 
79  setWindowTitle(i18n("Get Hot New Stuff"));
80 
81  QVBoxLayout *layout = new QVBoxLayout(this);
82  d->downloadWidget = new DownloadWidget(configFile, this);
83  // DownloadWidget already provides margins, which would duplicate the dialog layout margins.
84  // As the widget theme could use different margin sizes for a dialog/window outer layout,
85  // so from the duplicated margins we pick the internal margins to remove here.
86  d->downloadWidget->layout()->setContentsMargins(0, 0, 0, 0);
87  layout->addWidget(d->downloadWidget);
88 
89  if (group.hasKey("Name")) {
90  d->downloadWidget->setTitle(group.readEntry("Name"));
91  } else {
93  if (displayName.isEmpty()) {
94  displayName = QCoreApplication::applicationName();
95  }
96  d->downloadWidget->setTitle(i18nc("Program name followed by 'Add On Installer'",
97  "%1 Add-On Installer", displayName));
98  }
99  //d->downloadWidget->d->ui.m_titleWidget->setPixmap(QIcon::fromTheme(KGlobal::activeComponent().aboutData()->programIconName()));
100  d->downloadWidget->d->ui.m_titleWidget->setVisible(true);
101  d->downloadWidget->d->ui.closeButton->setVisible(true);
102  KStandardGuiItem::assign(d->downloadWidget->d->ui.closeButton, KStandardGuiItem::Close);
103  d->downloadWidget->d->dialogMode = true;
104  connect(d->downloadWidget->d->ui.closeButton, &QAbstractButton::clicked, this, &QDialog::accept);
105  WidgetQuestionListener::instance();
106 }
107 
109 {
110  KConfigGroup group(KSharedConfig::openConfig(), ConfigGroup);
112  delete d;
113 }
114 
115 int DownloadDialog::exec()
116 {
117  if (!KAuthorized::authorize(QStringLiteral("ghns"))) {
118  KMessageBox::information(this, QStringLiteral("Get Hot New Stuff is disabled by the administrator"), QStringLiteral("Get Hot New Stuff disabled"));
119  return QDialog::Rejected;
120  }
121  return QDialog::exec();
122 }
123 
124 void DownloadDialog::open()
125 {
126  if (!KAuthorized::authorize(QStringLiteral("ghns"))) {
127  KMessageBox::information(this, QStringLiteral("Get Hot New Stuff is disabled by the administrator"), QStringLiteral("Get Hot New Stuff disabled"));
128  return;
129  }
130  QDialog::open();
131 }
132 
133 void DownloadDialog::showEvent(QShowEvent *event)
134 {
135  if (!KAuthorized::authorize(QStringLiteral("ghns"))) {
136  KMessageBox::information(this, QStringLiteral("Get Hot New Stuff is disabled by the administrator"), QStringLiteral("Get Hot New Stuff disabled"));
137  return;
138  }
139  QWidget::showEvent(event);
140 }
141 
143 {
144  d->downloadWidget->setTitle(title);
145 }
146 
148 {
149  return d->downloadWidget->title();
150 }
151 
153 {
154  return d->downloadWidget->engine();
155 }
156 
158 {
159  return d->downloadWidget->changedEntries();
160 }
161 
163 {
164  return d->downloadWidget->installedEntries();
165 }
166 
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:70
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)
Definition: button.cpp:29
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-2020 The KDE developers.
Generated on Sun Aug 9 2020 22:43:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.