5 #include "updatedialog.h"
8 AppsWidget::AppsWidget(QWidget *parent) : QWidget(parent) {
9 const int padding = 30;
11 QBoxLayout *layout = new QHBoxLayout(this);
12 layout->setMargin(padding);
13 layout->setSpacing(padding*2);
14 layout->setAlignment(Qt::AlignCenter);
17 const QString ext = "dmg";
19 const QString ext = "exe";
21 const QString ext = "deb";
25 setupApp("Sofa", "sofa." + ext);
27 setupApp("Finetune", "finetune." + ext);
28 setupApp("Musictube", "musictube." + ext);
29 setupApp("Musique", "musique." + ext);
32 void AppsWidget::setupApp(const QString &name, const QString &code) {
33 AppWidget *w = new AppWidget(name, code);
34 layout()->addWidget(w);
37 void AppsWidget::paintEvent(QPaintEvent *e) {
42 style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this);
45 AppWidget::AppWidget(const QString &name, const QString &code, QWidget *parent)
46 : QWidget(parent), name(name), downloadButton(nullptr) {
47 const QString unixName = code.left(code.lastIndexOf('.'));
48 const QString baseUrl = QLatin1String("https://") + Constants::ORG_DOMAIN;
49 const QString filesUrl = baseUrl + QLatin1String("/files/");
50 url = filesUrl + unixName + QLatin1String("/") + code;
51 webPage = baseUrl + QLatin1String("/") + unixName;
53 QBoxLayout *layout = new QVBoxLayout(this);
55 layout->setAlignment(Qt::AlignHCenter);
58 icon->setMinimumHeight(128);
59 layout->addWidget(icon);
60 QString pixelRatioString;
61 if (devicePixelRatioF() > 1.0)
62 pixelRatioString = '@' + QString::number(devicePixelRatio()) + 'x';
63 const QString iconUrl = filesUrl + QLatin1String("products/") + unixName + pixelRatioString +
64 QLatin1String(".png");
65 QObject *reply = Http::instance().get(iconUrl);
66 connect(reply, SIGNAL(data(QByteArray)), SLOT(iconDownloaded(QByteArray)));
68 QLabel *appTitle = new QLabel(name);
69 appTitle->setAlignment(Qt::AlignHCenter);
70 layout->addWidget(appTitle);
73 #if !defined(APP_UBUNTU) && !defined(APP_MAC_STORE)
74 downloadButton = new QPushButton(tr("Download"));
75 downloadButton->setAttribute(Qt::WA_MacSmallSize);
76 downloadButton->setCursor(Qt::ArrowCursor);
77 QSizePolicy sp = downloadButton->sizePolicy();
78 sp.setHorizontalPolicy(QSizePolicy::Fixed);
79 sp.setRetainSizeWhenHidden(true);
80 downloadButton->setSizePolicy(sp);
81 connect(downloadButton, SIGNAL(clicked(bool)), SLOT(downloadApp()));
82 layout->addWidget(downloadButton, Qt::AlignHCenter);
83 layout->setAlignment(downloadButton, Qt::AlignHCenter);
84 downloadButton->hide();
88 setCursor(Qt::PointingHandCursor);
91 void AppWidget::enterEvent(QEvent *e) {
93 if (downloadButton) downloadButton->show();
96 void AppWidget::leaveEvent(QEvent *e) {
98 if (downloadButton) downloadButton->hide();
101 void AppWidget::mouseReleaseEvent(QMouseEvent *e) {
102 if (e->button() == Qt::LeftButton) {
103 QDesktopServices::openUrl(webPage);
107 void AppWidget::iconDownloaded(const QByteArray &bytes) {
109 pixmap.loadFromData(bytes, "PNG");
110 pixmap.setDevicePixelRatio(devicePixelRatioF());
111 icon->setPixmap(pixmap);
114 void AppWidget::downloadApp() {
117 UpdateDialog *dialog = new UpdateDialog(icon->pixmap(), name, QString(), url, this);
118 dialog->downloadUpdate();