test
[push-it] / src / aboutdialog.cpp
1 /*
2     Copyright (C) <2010>  <Markus Scharnowski markus.scharnowski@gmail.com>
3
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include <QPushButton>
18 #include <QTextEdit>
19 #include <QHBoxLayout>
20 #include <QLabel>
21
22 #include "aboutdialog.hpp"
23
24 AboutDialog::AboutDialog(QString name, QString customUrl, QWidget *parent) :
25     QDialog(parent)
26 {
27   browserGeneral = new QTextBrowser;
28   browserGeneral->setOpenExternalLinks(true);
29   browserDonate = new QTextBrowser;
30   browserDonate->setOpenExternalLinks(true);
31   browserWebsite = new QTextBrowser;
32   browserWebsite->setOpenExternalLinks(true);
33   browserFeedback = new QTextBrowser;
34   browserFeedback->setOpenExternalLinks(true);
35
36   tabs = new QTabWidget;
37   tabs->insertTab(1,browserGeneral,tr("&General"));
38   tabs->insertTab(2,browserDonate,tr("&Donate"));
39   tabs->insertTab(3,browserWebsite,tr("&Website"));
40   tabs->insertTab(4,browserFeedback,tr("&Feedback"));
41
42   QHBoxLayout *layout = new QHBoxLayout();
43   layout->addWidget(tabs);
44
45   setLayout(layout);
46   setBaseSize(700,400);
47   setMinimumWidth(700);
48 //  setMinimumHeight(400);
49
50   setProgramName(name);
51   setProgramUrl(customUrl);
52   setGeneralHtmlText();
53   setWebsiteHtmlText();
54   setDonateHtmlText();
55   setFeedbackHtmlText();
56   hide();
57 }
58
59 AboutDialog::~AboutDialog()
60 {
61 }
62
63 int AboutDialog::setProgramName(QString name)
64 {
65   programName = name;
66
67   QString wTitle = "About " + name;
68   setWindowTitle(tr(wTitle.toStdString().c_str()));
69
70   refreshDefaultTexts();
71   return EXIT_SUCCESS;
72 }
73
74 int AboutDialog::setProgramUrl(QString url)
75 {
76   programUrl = url;
77   refreshDefaultTexts();
78   return EXIT_SUCCESS;
79 }
80
81 int AboutDialog::setGeneralHtmlText(QString htmlText)
82 {
83   if("" == htmlText)
84   {
85     textGeneral =
86         "<p>" + programName + "</p>"
87         "<p>Idea and programming: <a href=\"mailto:markus.scharnowski@gmail.com?subject=Thank you for " + programName +
88         "&body=Hello Markus,\">Markus Scharnowski</a></p>"
89         ;
90   }
91   else
92   {
93     textGeneral = htmlText;
94   }
95
96   browserGeneral->setText(tr(textGeneral.toStdString().c_str()));
97   return EXIT_SUCCESS;
98 }
99
100 int AboutDialog::setDonateHtmlText(QString htmlText)
101 {
102   if("" == htmlText)
103   {
104     textDonate =
105         "You like what you have in your hands? You use it on regular basis? Support the devolpment by making a donation."
106         "<p>Donate through "
107         "<a href=\"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=TPX9PV29D4L9Y\">paypal</a></p>"
108         "<p>Visit the projects <a href=\"https://sites.google.com/site/markusscharnowski/donate\">donation website</a></p>"
109         ;
110   }
111   else
112   {
113     textDonate = htmlText;
114   }
115
116   browserDonate->setText(tr(textDonate.toStdString().c_str()));
117   return EXIT_SUCCESS;
118 }
119
120 int AboutDialog::setWebsiteHtmlText(QString htmlText)
121 {
122   if("" == htmlText)
123   {
124     textWebsite =
125         "<p>Visit</p>"
126         "<p>"
127         "<a href=\""+ programUrl + "\">" + programUrl + "</a><br>"
128         "<a href=\"http://sites.google.com/site/markusscharnowski\">http://sites.google.com/site/markusscharnowski</a>"
129         "</p>"
130         ;
131   }
132   else
133   {
134     textWebsite = htmlText;
135   }
136
137   browserWebsite->setText(tr(textWebsite.toStdString().c_str()));
138   return EXIT_SUCCESS;
139 }
140
141 int AboutDialog::setFeedbackHtmlText(QString htmlText)
142 {
143   if("" == htmlText)
144   {
145     textFeedback =
146         "<p>Do you have ideas for improving the program? You want a specific functionality? "
147         ""
148         "You have found a bug?</p>"
149         "<p>Email <a href=\"mailto:markus.scharnowski@gmail.com?subject=SW Feedback " + programName +
150         " &body=Hello Markus,\">Feedback</a></p>"
151         ;
152   }
153   else
154   {
155     textFeedback = htmlText;
156   }
157
158   browserFeedback->setText(tr(textFeedback.toStdString().c_str()));
159   return EXIT_SUCCESS;
160 }
161
162 int AboutDialog::refreshDefaultTexts()
163 {
164   setGeneralHtmlText("");
165   setWebsiteHtmlText("");
166   setDonateHtmlText("");
167   setFeedbackHtmlText("");
168   return EXIT_SUCCESS;
169 }