Kstars

addlinkdialog.cpp
1/*
2 SPDX-FileCopyrightText: 2001 Jason Harris <kstars@30doradus.org>
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
18AddLinkDialogUI::AddLinkDialogUI(QWidget *parent) : QFrame(parent)
19{
20 setupUi(this);
21}
22
23AddLinkDialog::AddLinkDialog(QWidget *parent, const QString &oname) : QDialog(parent), ObjectName(oname)
24{
25#ifdef Q_OS_MACOS
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
49void 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 {
58 QString message =
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::warningContinueCancel(nullptr, message, caption, KGuiItem(i18n("Browse Google")),
62 KGuiItem(i18n("Do Not Browse"))) == KMessageBox::Continue)
63 {
64 QDesktopServices::openUrl(QUrl("https://www.google.com"));
65 }
66 }
67}
68
69void 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}
QString url() const
AddLinkDialog(QWidget *parent=nullptr, const QString &oname=i18n("object"))
Constructor.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
ButtonCode warningContinueCancel(QWidget *parent, const QString &text, const QString &title=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
bool openUrl(const QUrl &url)
virtual void accept()
void accepted()
virtual void reject()
void rejected()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setLayout(QLayout *layout)
void setWindowFlags(Qt::WindowFlags type)
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:52:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.