Kstars

addlinkdialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2001 Jason Harris <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "addlinkdialog.h"
8 #include "Options.h"
9 
10 #include <QPushButton>
11 #include <QUrl>
12 #include <QDesktopServices>
13 
14 #include <KMessageBox>
15 
16 #include "skyobjects/skyobject.h"
17 
18 AddLinkDialogUI::AddLinkDialogUI(QWidget *parent) : QFrame(parent)
19 {
20  setupUi(this);
21 }
22 
23 AddLinkDialog::AddLinkDialog(QWidget *parent, const QString &oname) : QDialog(parent), ObjectName(oname)
24 {
25 #ifdef Q_OS_OSX
27 #endif
28  ald = new AddLinkDialogUI(this);
29 
30  setWindowTitle(i18nc("@title:window", "Add Custom URL to %1", oname));
31 
32  QVBoxLayout *mainLayout = new QVBoxLayout;
33  mainLayout->addWidget(ald);
34  setLayout(mainLayout);
35 
37  mainLayout->addWidget(buttonBox);
38  connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
39  connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
40 
41  //connect signals to slots
42  connect(ald->URLButton, SIGNAL(clicked()), this, SLOT(checkURL()));
43  connect(ald->ImageRadio, SIGNAL(toggled(bool)), this, SLOT(changeDefaultDescription(bool)));
44 
45  ald->ImageRadio->setChecked(true);
46  ald->DescBox->setText(i18n("Show image of ") + ObjectName);
47 }
48 
49 void AddLinkDialog::checkURL(void)
50 {
51  QUrl _url(url());
52  if (_url.isValid()) //Is the string a valid URL?
53  {
54  QDesktopServices::openUrl(_url); //If so, launch the browser to see if it's the correct document
55  }
56  else //If not, print a warning message box that offers to open the browser to a search engine.
57  {
59  i18n("The URL is not valid. Would you like to open a browser window\nto the Google search engine?");
60  QString caption = i18n("Invalid URL");
61  if (KMessageBox::warningYesNo(nullptr, message, caption, KGuiItem(i18n("Browse Google")),
62  KGuiItem(i18n("Do Not Browse"))) == KMessageBox::Yes)
63  {
64  QDesktopServices::openUrl(QUrl("https://www.google.com"));
65  }
66  }
67 }
68 
69 void AddLinkDialog::changeDefaultDescription(bool imageEnabled)
70 {
71  if (imageEnabled)
72  ald->DescBox->setText(i18n("Show image of ") + ObjectName);
73  else
74  ald->DescBox->setText(i18n("Show webpage about ") + ObjectName);
75 }
virtual void reject()
bool openUrl(const QUrl &url)
QString caption()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
ButtonCode warningYesNo(QWidget *parent, const QString &text, const QString &title=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const QString &dontAskAgainName=QString(), Options options=Options(Notify|Dangerous))
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void rejected()
QString i18n(const char *text, const TYPE &arg...)
void setWindowFlags(Qt::WindowFlags type)
void setWindowTitle(const QString &)
virtual void accept()
void setupUi(QWidget *widget)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
AddLinkDialog(QWidget *parent=nullptr, const QString &oname=i18n("object"))
Constructor.
void setLayout(QLayout *layout)
QString message
QString url() const
Definition: addlinkdialog.h:44
void accepted()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 15 2022 04:03:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.