Warning, file /education/kstars/kstars/dialogs/addlinkdialog.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2001 Jason Harris <kstars@30doradus.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "addlinkdialog.h"
0008 #include "Options.h"
0009 
0010 #include <QPushButton>
0011 #include <QUrl>
0012 #include <QDesktopServices>
0013 
0014 #include <KMessageBox>
0015 
0016 #include "skyobjects/skyobject.h"
0017 
0018 AddLinkDialogUI::AddLinkDialogUI(QWidget *parent) : QFrame(parent)
0019 {
0020     setupUi(this);
0021 }
0022 
0023 AddLinkDialog::AddLinkDialog(QWidget *parent, const QString &oname) : QDialog(parent), ObjectName(oname)
0024 {
0025 #ifdef Q_OS_OSX
0026     setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
0027 #endif
0028     ald = new AddLinkDialogUI(this);
0029 
0030     setWindowTitle(i18nc("@title:window", "Add Custom URL to %1", oname));
0031 
0032     QVBoxLayout *mainLayout = new QVBoxLayout;
0033     mainLayout->addWidget(ald);
0034     setLayout(mainLayout);
0035 
0036     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0037     mainLayout->addWidget(buttonBox);
0038     connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
0039     connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
0040 
0041     //connect signals to slots
0042     connect(ald->URLButton, SIGNAL(clicked()), this, SLOT(checkURL()));
0043     connect(ald->ImageRadio, SIGNAL(toggled(bool)), this, SLOT(changeDefaultDescription(bool)));
0044 
0045     ald->ImageRadio->setChecked(true);
0046     ald->DescBox->setText(i18n("Show image of ") + ObjectName);
0047 }
0048 
0049 void AddLinkDialog::checkURL(void)
0050 {
0051     QUrl _url(url());
0052     if (_url.isValid()) //Is the string a valid URL?
0053     {
0054         QDesktopServices::openUrl(_url); //If so, launch the browser to see if it's the correct document
0055     }
0056     else //If not, print a warning message box that offers to open the browser to a search engine.
0057     {
0058         QString message =
0059             i18n("The URL is not valid. Would you like to open a browser window\nto the Google search engine?");
0060         QString caption = i18n("Invalid URL");
0061         if (KMessageBox::warningYesNo(nullptr, message, caption, KGuiItem(i18n("Browse Google")),
0062                                       KGuiItem(i18n("Do Not Browse"))) == KMessageBox::Yes)
0063         {
0064             QDesktopServices::openUrl(QUrl("https://www.google.com"));
0065         }
0066     }
0067 }
0068 
0069 void AddLinkDialog::changeDefaultDescription(bool imageEnabled)
0070 {
0071     if (imageEnabled)
0072         ald->DescBox->setText(i18n("Show image of ") + ObjectName);
0073     else
0074         ald->DescBox->setText(i18n("Show webpage about ") + ObjectName);
0075 }