File indexing completed on 2024-05-12 16:39:56
0001 /* This file is part of the KDE project 0002 Copyright (C) 2013 Oleg Kukharchuk <oleg.kuh@gmail.com> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this program; see the file COPYING. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KexiPushButton.h" 0021 #include <KLocalizedString> 0022 0023 #include <QDir> 0024 #include <QUrl> 0025 0026 class Q_DECL_HIDDEN KexiPushButton::Private 0027 { 0028 public: 0029 explicit Private(KexiPushButton *qq) 0030 : hyperlinkType(KexiPushButton::NoHyperlink) 0031 , hyperlinkTool(KexiUtils::OpenHyperlinkOptions::DefaultHyperlinkTool) 0032 , executable(false) 0033 , remote(false) 0034 , q(qq) 0035 { 0036 QObject::connect(q, SIGNAL(clicked()), q, SLOT(slotClicked())); 0037 } 0038 0039 QString hyperlink; 0040 KexiPushButton::HyperlinkType hyperlinkType; 0041 KexiUtils::OpenHyperlinkOptions::HyperlinkTool hyperlinkTool; 0042 bool executable; 0043 bool remote; 0044 QString basePath; 0045 0046 KexiPushButton *q; 0047 }; 0048 0049 KexiPushButton::KexiPushButton(QWidget *parent) 0050 : QPushButton(parent) 0051 , d(new Private(this)) 0052 { 0053 } 0054 0055 KexiPushButton::KexiPushButton(const QString &text, QWidget *parent) 0056 : QPushButton(parent) 0057 , d(new Private(this)) 0058 { 0059 setText(text); 0060 } 0061 0062 KexiPushButton::~KexiPushButton() 0063 { 0064 delete d; 0065 } 0066 0067 void KexiPushButton::setHyperlink(const QString &url) 0068 { 0069 d->hyperlink = url; 0070 } 0071 0072 QString KexiPushButton::hyperlink() const 0073 { 0074 return d->hyperlink; 0075 } 0076 0077 void KexiPushButton::setHyperlinkType(HyperlinkType type) 0078 { 0079 d->hyperlinkType = type; 0080 } 0081 0082 KexiPushButton::HyperlinkType KexiPushButton::hyperlinkType() const 0083 { 0084 return d->hyperlinkType; 0085 } 0086 0087 void KexiPushButton::setHyperlinkTool(KexiUtils::OpenHyperlinkOptions::HyperlinkTool tool) 0088 { 0089 d->hyperlinkTool = tool; 0090 } 0091 0092 KexiUtils::OpenHyperlinkOptions::HyperlinkTool KexiPushButton::hyperlinkTool() const 0093 { 0094 return d->hyperlinkTool; 0095 } 0096 0097 void KexiPushButton::setHyperlinkExecutable(bool exec) 0098 { 0099 d->executable = exec; 0100 } 0101 0102 bool KexiPushButton::isHyperlinkExecutable() const 0103 { 0104 return d->executable; 0105 } 0106 0107 void KexiPushButton::setRemoteHyperlink(bool remote) 0108 { 0109 d->remote = remote; 0110 } 0111 0112 bool KexiPushButton::isRemoteHyperlink() const 0113 { 0114 return d->remote; 0115 } 0116 0117 void KexiPushButton::setLocalBasePath(const QString &basePath) 0118 { 0119 d->basePath = basePath; 0120 } 0121 0122 void KexiPushButton::slotClicked() 0123 { 0124 if (d->hyperlinkType == KexiPushButton::NoHyperlink) { 0125 return; 0126 } 0127 0128 QUrl url(d->hyperlink); 0129 if (d->hyperlinkTool == KexiUtils::OpenHyperlinkOptions::MailerHyperlinkTool 0130 && url.scheme().isEmpty()) 0131 { 0132 url.setScheme("mailto"); 0133 } 0134 0135 if (url.isRelative()) { 0136 url.setUrl(d->basePath + QDir::separator() + d->hyperlink); 0137 url.setScheme("file"); 0138 } 0139 0140 KexiUtils::OpenHyperlinkOptions opt; 0141 opt.allowExecutable = d->executable; 0142 opt.allowRemote = d->remote; 0143 opt.tool = d->hyperlinkTool; 0144 KexiUtils::openHyperLink(url, this, opt); 0145 }