1 // Copyright (C) 2012-2019 The VPaint Developers.
2 // See the COPYRIGHT file at the top-level directory of this distribution
3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #include "UpdateCheckDialog.h"
18 
19 #include <QVBoxLayout>
20 #include <QLabel>
21 #include <QCheckBox>
22 #include <QDialogButtonBox>
23 
24 #include "Application.h"
25 #include "Global.h"
26 
UpdateCheckDialog(QString newVersion,QWidget * parent,Qt::WindowFlags f)27 UpdateCheckDialog::UpdateCheckDialog(QString newVersion, QWidget *parent, Qt::WindowFlags f)
28 {
29     setParent(parent, f);
30     setWindowTitle(tr("Updates Available"));
31     setMinimumSize(500, 200);
32 
33     QString updateText = tr(
34             "An update is available for VPaint. The current version is %1"
35             " and the newest version of VPaint is %2.<br><br>"
36             " "
37             "The latest version for your system can be downloaded"
38             " <a href=\"$DOWNLOAD_LINK\">here</a>.").arg(qApp->applicationVersion(), newVersion);
39 
40     // Insert the os specific download link into updateText
41 #ifdef Q_OS_WIN32
42     updateText.replace(QString("$DOWNLOAD_LINK"), QString("https://github.com/dalboris/vpaint/releases/download/v$NEW_VERSION/VPaint.$NEW_VERSION.Setup.msi"));
43 #endif
44 #ifdef Q_OS_MAC
45     updateText.replace(QString("$DOWNLOAD_LINK"), QString("https://github.com/dalboris/vpaint/releases/download/v$NEW_VERSION/VPaint.$NEW_VERSION.dmg"));
46 #else
47     updateText.replace(QString("$DOWNLOAD_LINK"), QString("https://github.com/dalboris/vpaint/releases/tag/v$NEW_VERSION"));
48 #endif
49 
50     // Set version in download link
51     updateText.replace(QString("$NEW_VERSION"), newVersion);
52 
53     // Main description
54     QLabel * mainDesc = new QLabel(updateText);
55     mainDesc->setWordWrap(true);
56     mainDesc->setTextFormat(Qt::RichText);
57     mainDesc->setAlignment(Qt::AlignTop | Qt::AlignLeft);
58     mainDesc->setOpenExternalLinks(true);
59 
60     // Skip version checkbox
61     skipVersionCheckBox_ = new QCheckBox(QString("Don't remind me about this version again"));
62     skipVersionCheckBox_->setChecked(false);
63 
64     // Stop checking checkbox
65     stopCheckingCheckBox_ = new QCheckBox(QString("Stop checking for updates"));
66     stopCheckingCheckBox_->setChecked(false);
67     connect(stopCheckingCheckBox_, SIGNAL(stateChanged(int)), this, SLOT(stopCheckingChanged_()));
68 
69     // Dialog button
70     QDialogButtonBox * buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
71     connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
72     connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
73 
74     // Main layout
75     QVBoxLayout * layout = new QVBoxLayout();
76     layout->addWidget(mainDesc);
77     layout->addWidget(skipVersionCheckBox_);
78     layout->addWidget(stopCheckingCheckBox_);
79     layout->addWidget(buttonBox);
80     setLayout(layout);
81 }
82 
skipVersion()83 bool UpdateCheckDialog::skipVersion()
84 {
85     return skipVersionCheckBox_->checkState() == Qt::Checked;
86 }
87 
stopChecking()88 bool UpdateCheckDialog::stopChecking()
89 {
90     return stopCheckingCheckBox_->checkState() == Qt::Checked;
91 }
92 
stopCheckingChanged_()93 void UpdateCheckDialog::stopCheckingChanged_()
94 {
95     if(stopChecking())
96     {
97         skipVersionCheckBox_->setDisabled(true);
98     }
99     else
100     {
101         skipVersionCheckBox_->setDisabled(false);
102     }
103 }
104