]> git.sur5r.net Git - minitube/blob - src/aboutview.cpp
New upstream version 3.8
[minitube] / src / aboutview.cpp
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Minitube 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
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
18
19 $END_LICENSE */
20
21 #include "aboutview.h"
22 #include "constants.h"
23 #ifdef APP_EXTRA
24 #include "extra.h"
25 #endif
26 #ifdef APP_ACTIVATION
27 #include "activation.h"
28 #endif
29 #ifdef APP_MAC
30 #include "mac_startup.h"
31 #include "macutils.h"
32 #endif
33 #include "appwidget.h"
34 #include "clickablelabel.h"
35 #include "fontutils.h"
36 #include "iconutils.h"
37 #include "mainwindow.h"
38
39 #ifdef UPDATER
40 #include "updater.h"
41 #include "waitingspinnerwidget.h"
42 #endif
43
44 AboutView::AboutView(QWidget *parent) : View(parent) {
45     const int padding = 30;
46     const char *buildYear = __DATE__ + 7;
47
48     setBackgroundRole(QPalette::Base);
49     setForegroundRole(QPalette::Text);
50     setAutoFillBackground(true);
51
52     QBoxLayout *verticalLayout = new QVBoxLayout(this);
53     verticalLayout->setMargin(0);
54     verticalLayout->setSpacing(0);
55
56     QBoxLayout *aboutlayout = new QHBoxLayout();
57     verticalLayout->addLayout(aboutlayout, 1);
58     aboutlayout->setAlignment(Qt::AlignCenter);
59     aboutlayout->setMargin(padding);
60     aboutlayout->setSpacing(padding);
61
62     ClickableLabel *logo = new ClickableLabel();
63     auto setLogoPixmap = [logo] {
64         logo->setPixmap(IconUtils::pixmap(":/images/app.png", logo->devicePixelRatioF()));
65     };
66     setLogoPixmap();
67     connect(window()->windowHandle(), &QWindow::screenChanged, this, setLogoPixmap);
68
69     connect(logo, &ClickableLabel::clicked, MainWindow::instance(), &MainWindow::visitSite);
70     aboutlayout->addWidget(logo, 0, Qt::AlignTop);
71
72     QBoxLayout *layout = new QVBoxLayout();
73     layout->setAlignment(Qt::AlignCenter);
74     layout->setSpacing(padding);
75     layout->setMargin(padding / 2);
76     aboutlayout->addLayout(layout);
77
78     QColor lightTextColor = palette().text().color();
79 #ifdef APP_MAC
80     lightTextColor.setAlphaF(.75);
81 #endif
82 #ifdef APP_MAC
83     QColor linkColor = mac::accentColor();
84 #else
85     QColor linkColor = palette().highlight().color();
86 #endif
87
88     QString info = "<html><style>"
89                    "body { color: " +
90                    lightTextColor.name(QColor::HexArgb) +
91                    "; } "
92                    "h1 { color: palette(text); font-weight: 100; } "
93                    "a { color: " +
94                    linkColor.name(QColor::HexArgb) +
95                    "; text-decoration: none; font-weight: normal; }"
96                    "</style><body>";
97
98     info += "<h1>" + QString(Constants::NAME) +
99             "</h1>"
100             "<p>" +
101             tr("There's life outside the browser!") +
102             "</p>"
103             "<p>" +
104             tr("Version %1").arg(Constants::VERSION) + "</p>" +
105             QString("<p><a href=\"%1/\">%1</a></p>").arg(Constants::WEBSITE);
106
107 #ifdef APP_ACTIVATION
108     QString email = Activation::instance().getEmail();
109     if (!email.isEmpty()) info += "<p>" + tr("Licensed to: %1").arg("<b>" + email + "</b>");
110 #endif
111
112 #ifndef APP_EXTRA
113     info += "<p>" +
114             tr("%1 is Free Software but its development takes precious time.")
115                     .arg(Constants::NAME) +
116             "<br/>" +
117             tr("Please <a href='%1'>donate</a> to support the continued development of %2.")
118                     .arg(QString(Constants::WEBSITE).append("#donate"), Constants::NAME) +
119             "</p>";
120 #endif
121
122     info += "<p>" +
123             tr("Translate %1 to your native language using %2")
124                     .arg(Constants::NAME)
125                     .arg("<a href='http://www.transifex.net/projects/p/" +
126                          QString(Constants::UNIX_NAME) + "/'>Transifex</a>") +
127             "</p>";
128
129     info += "<p>" +
130             tr("Powered by %1")
131                     .arg("<a href='https://" + QLatin1String(Constants::ORG_DOMAIN) +
132                          "/opensource'>" + tr("Open-source software") + "</a>") +
133             "</p>";
134
135     info += "<p>" +
136             tr("Icon designed by %1.").arg("<a href='http://www.kolorguild.co.za/'>David Nel</a>") +
137             "</p>"
138
139 #ifndef APP_EXTRA
140             "<p>" +
141             tr("Released under the <a href='%1'>GNU General Public License</a>")
142                     .arg("http://www.gnu.org/licenses/gpl.html") +
143             "</p>"
144 #endif
145             "<p>&copy; " +
146             buildYear + " " + Constants::ORG_NAME +
147             "</p>"
148             "</body></html>";
149
150     QLabel *infoLabel = new QLabel(info, this);
151     infoLabel->setOpenExternalLinks(true);
152     infoLabel->setWordWrap(true);
153     layout->addWidget(infoLabel);
154
155 #ifdef UPDATER
156     int capHeight = fontMetrics().capHeight();
157
158     QBoxLayout *updateLayout = new QHBoxLayout();
159     updateLayout->setMargin(0);
160     updateLayout->setSpacing(capHeight);
161     updateLayout->setAlignment(Qt::AlignLeft);
162
163     auto spinner = new WaitingSpinnerWidget(this, false, false);
164     spinner->setColor(palette().windowText().color());
165     spinner->setLineLength(capHeight / 2);
166     spinner->setNumberOfLines(spinner->lineLength() * 2);
167     spinner->setInnerRadius(spinner->lineLength());
168     auto spinnerStartStop = [spinner](auto status) {
169         if (status == Updater::Status::DownloadingUpdate)
170             spinner->start();
171         else
172             spinner->stop();
173     };
174     connect(&Updater::instance(), &Updater::statusChanged, this, spinnerStartStop);
175     updateLayout->addWidget(spinner);
176     spinnerStartStop(Updater::instance().getStatus());
177
178     updateLayout->addWidget(Updater::instance().getLabel());
179
180     layout->addLayout(updateLayout);
181 #endif
182
183     QLayout *buttonLayout = new QHBoxLayout();
184     buttonLayout->setMargin(0);
185     buttonLayout->setAlignment(Qt::AlignLeft);
186
187 #ifdef UPDATER
188     buttonLayout->addWidget(Updater::instance().getButton());
189 #endif
190
191     closeButton = new QPushButton(tr("&Close"), this);
192     closeButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
193     closeButton->setDefault(true);
194     closeButton->setShortcut(Qt::Key_Escape);
195     closeButton->setFocus();
196     connect(closeButton, SIGNAL(clicked()), MainWindow::instance(), SLOT(goBack()));
197     buttonLayout->addWidget(closeButton);
198
199     layout->addLayout(buttonLayout);
200
201     verticalLayout->addWidget(new AppsWidget());
202 }
203
204 void AboutView::appear() {
205     closeButton->setFocus();
206 #ifdef UPDATER
207     Updater::instance().checkWithoutUI();
208 #endif
209 }