1 /* This file is part of the KDE project
2    Copyright (C) 2012-2013 Oleg Kukharchuk <oleg.kuh@gmail.com>
3    Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
4    Copyright (C) 2004-2005 Jarosław Staniek <staniek@kde.org>
5 
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Library General Public
8    License as published by the Free Software Foundation; either
9    version 2 of the License, or (at your option) any later version.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Library General Public License for more details.
15 
16    You should have received a copy of the GNU Library General Public License
17    along with this program; see the file COPYING.  If not, write to
18    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20 */
21 
22 #include "kexidbcommandlinkbutton.h"
23 #include <core/kexiproject.h>
24 #include <core/KexiMainWindowIface.h>
25 
26 #include <KDbConnection>
27 
28 #include <QUrl>
29 
30 class KexiDBCommandLinkButtonPrivate
31 {
32 public:
KexiDBCommandLinkButtonPrivate()33     KexiDBCommandLinkButtonPrivate() {}
34 
35     KexiFormEventAction::ActionData onClickActionData;
36 };
37 
KexiDBCommandLinkButton(const QString & text,const QString & description,QWidget * parent)38 KexiDBCommandLinkButton::KexiDBCommandLinkButton(const QString &text,
39                                                  const QString &description, QWidget * parent)
40         : KexiCommandLinkButton(text, description, parent)
41         , d(new KexiDBCommandLinkButtonPrivate)
42 {
43     QString basePath = Kexi::basePathForProject(
44         KexiMainWindowIface::global()->project()->dbConnection()->data());
45     if (!basePath.isEmpty()) {
46         setLocalBasePath(basePath);
47     }
48 }
49 
~KexiDBCommandLinkButton()50 KexiDBCommandLinkButton::~KexiDBCommandLinkButton()
51 {
52     delete d;
53 }
54 
setValueInternal(const QVariant & add,bool removeOld)55 void KexiDBCommandLinkButton::setValueInternal(const QVariant& add, bool removeOld)
56 {
57     Q_UNUSED(add)
58     Q_UNUSED(removeOld)
59 
60     if (KexiPushButton::hyperlinkType() == KexiPushButton::DynamicHyperlink) {
61         KexiPushButton::setHyperlink(KexiDataItemInterface::originalValue().toString());
62     }
63 
64     QUrl url(KexiDataItemInterface::originalValue().toString());
65     setDescription(url.url(QUrl::PreferLocalFile));
66     setToolTip(url.url(QUrl::PreferLocalFile));
67 }
68 
value()69 QVariant KexiDBCommandLinkButton::value()
70 {
71     if (KexiPushButton::hyperlinkType() == KexiPushButton::DynamicHyperlink) {
72         return KexiPushButton::hyperlink();
73     }
74     return QVariant();
75 }
76 
clear()77 void KexiDBCommandLinkButton::clear()
78 {
79     if (KexiPushButton::hyperlinkType() == KexiPushButton::DynamicHyperlink) {
80         KexiPushButton::setHyperlink(QString());
81     }
82 }
83 
cursorAtStart()84 bool KexiDBCommandLinkButton::cursorAtStart()
85 {
86     return false;
87 }
88 
cursorAtEnd()89 bool KexiDBCommandLinkButton::cursorAtEnd()
90 {
91     return false;
92 }
93 
valueIsNull()94 bool KexiDBCommandLinkButton::valueIsNull()
95 {
96     if (KexiPushButton::hyperlinkType() == KexiPushButton::DynamicHyperlink) {
97         return KexiPushButton::hyperlink().isNull();
98     }
99     return true;
100 }
101 
valueIsEmpty()102 bool KexiDBCommandLinkButton::valueIsEmpty()
103 {
104     if (KexiPushButton::hyperlinkType() == KexiPushButton::DynamicHyperlink) {
105         return KexiPushButton::hyperlink().isEmpty();
106     }
107     return true;
108 }
109 
setInvalidState(const QString & displayText)110 void KexiDBCommandLinkButton::setInvalidState(const QString &displayText)
111 {
112     if (KexiPushButton::hyperlinkType() == KexiPushButton::DynamicHyperlink) {
113         setText(displayText);
114     }
115 }
isReadOnly() const116 bool KexiDBCommandLinkButton::isReadOnly() const
117 {
118     return true;
119 }
120 
setReadOnly(bool readOnly)121 void KexiDBCommandLinkButton::setReadOnly(bool readOnly)
122 {
123     Q_UNUSED(readOnly);
124 }
125 
onClickAction() const126 QString KexiDBCommandLinkButton::onClickAction() const
127 {
128     return d->onClickActionData.string;
129 }
130 
setOnClickAction(const QString & actionString)131 void KexiDBCommandLinkButton::setOnClickAction(const QString& actionString)
132 {
133     d->onClickActionData.string = actionString;
134 }
135 
onClickActionOption() const136 QString KexiDBCommandLinkButton::onClickActionOption() const
137 {
138      return d->onClickActionData.option;
139 }
140 
setOnClickActionOption(const QString & option)141 void KexiDBCommandLinkButton::setOnClickActionOption(const QString& option)
142 {
143      d->onClickActionData.option = option;
144 }
145 
146