Skip to content

Commit a143152

Browse files
committed
Issue #86, show license dialog at first startup.
1 parent 1e93322 commit a143152

9 files changed

+194
-9
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
0.9.18
2+
Issue #86, show license dialog at first startup.
3+
14
0.9.17
25
Issue #83, the license dialog don't ask questions anymore.
36
Option to load a base64 coded data file in base64 dialog.

src/licensedialog.cpp

+25-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@
2020
* Boston, MA 02110-1301 USA *
2121
**************************************************************************/
2222

23-
23+
#include "xmlEdit.h"
2424
#include "licensedialog.h"
25+
#include "qxmleditconfig.h"
2526
#include "ui_licensedialog.h"
26-
#include "xmlEdit.h"
27+
28+
void LicenseDialog::licenseAgreement()
29+
{
30+
if(!Config::getBool(Config::KEY_GENERAL_LICENSE_AGREED, false)) {
31+
LicenseDialog dlg;
32+
dlg.exec();
33+
Config::saveBool(Config::KEY_GENERAL_LICENSE_AGREED, true);
34+
}
35+
}
2736

2837
LicenseDialog::LicenseDialog(QWidget *parent) :
2938
QDialog(parent),
@@ -42,6 +51,20 @@ LicenseDialog::~LicenseDialog()
4251
delete ui;
4352
}
4453

54+
#ifdef QXMLEDIT_TEST
55+
bool LicenseDialog::testLicenseValid = false ;
56+
#endif
57+
58+
void LicenseDialog::showEvent(QShowEvent *event)
59+
{
60+
#ifdef QXMLEDIT_TEST
61+
QString license = ui->textBrowser->toPlainText();
62+
testLicenseValid = !license.isEmpty();
63+
QTimer::singleShot(200, this, SLOT(accept()));
64+
#endif
65+
QDialog::showEvent(event);
66+
}
67+
4568
QString LicenseDialog::readLicense(const QString & filePath)
4669
{
4770
QString result ;

src/licensedialog.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ class LicenseDialog : public QDialog
3838
QString readLicense(const QString & filePath);
3939
public:
4040
explicit LicenseDialog(QWidget *parent = 0);
41-
~LicenseDialog();
41+
virtual ~LicenseDialog();
4242

43+
static void licenseAgreement();
44+
#ifdef QXMLEDIT_TEST
45+
static bool testLicenseValid;
46+
#endif
47+
48+
protected:
49+
virtual void showEvent(QShowEvent *event);
4350
private:
4451
Ui::LicenseDialog *ui;
4552
};

src/main.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,7 @@ void installMsgHandler()
300300

301301
static void licenseAgreement()
302302
{
303-
if(!Config::getBool(Config::KEY_GENERAL_LICENSE_AGREED, false)) {
304-
LicenseDialog dlg;
305-
Config::saveBool(Config::KEY_GENERAL_LICENSE_AGREED, true);
306-
}
303+
LicenseDialog::licenseAgreement();
307304
}
308305

309306
#if !defined(QXMLEDIT_NOMAIN)

test/TestQXmlEdit.h

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
#include "testtestxmlfile.h"
108108
#include "testloadsample.h"
109109
#include "testxmlbeans.h"
110+
#include "testabout.h"
110111

111112
class TestQXmlEdit : public QObject
112113
{
@@ -223,6 +224,7 @@ private Q_SLOTS:
223224
void testTestXMLFile();
224225
void testLoadSample();
225226
void testXMLBeans();
227+
void testAbout();
226228
};
227229

228230

test/test.pro

+4-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ SOURCES += \
191191
testloadsample.cpp \
192192
testxmlbeans.cpp \
193193
testhelpers/xml2xsdtest.cpp \
194-
testhelpers/xsd2xmltest.cpp
194+
testhelpers/xsd2xmltest.cpp \
195+
testabout.cpp
195196

196197
DEFINES += SRCDIR=\\\"$$PWD/\\\"
197198

@@ -318,7 +319,8 @@ HEADERS += \
318319
testloadsample.h \
319320
testxmlbeans.h \
320321
testhelpers/xml2xsdtest.h \
321-
testhelpers/xsd2xmltest.h
322+
testhelpers/xsd2xmltest.h \
323+
testabout.h
322324

323325
#OTHER_FILES += \
324326

test/testabout.cpp

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**************************************************************************
2+
* This file is part of QXmlEdit *
3+
* Copyright (C) 2022 by Luca Bellonda and individual contributors *
4+
* as indicated in the AUTHORS file *
5+
* lbellonda _at_ gmail.com *
6+
* *
7+
* This library is free software; you can redistribute it and/or *
8+
* modify it under the terms of the GNU Library General Public *
9+
* License as published by the Free Software Foundation; either *
10+
* version 2 of the License, or (at your option) any later version. *
11+
* *
12+
* This library is distributed in the hope that it will be useful, *
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15+
* Library General Public License for more details. *
16+
* *
17+
* You should have received a copy of the GNU Library General Public *
18+
* License along with this library; if not, write to the *
19+
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20+
* Boston, MA 02110-1301 USA *
21+
**************************************************************************/
22+
23+
#include "testabout.h"
24+
#include "licensedialog.h"
25+
26+
TestAbout::TestAbout()
27+
{
28+
Config::setBackend(&_configBackend);
29+
}
30+
31+
TestAbout::~TestAbout()
32+
{
33+
Config::setBackend(NULL);
34+
}
35+
36+
bool TestAbout::testFast()
37+
{
38+
return testLicense();
39+
}
40+
41+
bool TestAbout::testUnit() {
42+
_testName = "testUnit";
43+
if(!testLicense()) {
44+
return false;
45+
}
46+
return true ;
47+
}
48+
49+
bool TestAbout::testLicense()
50+
{
51+
_subTestName = "testLicense";
52+
if(!testLicenseStart()) {
53+
return false;
54+
}
55+
if(!testLicenseStarted()) {
56+
return false;
57+
}
58+
return true;
59+
}
60+
61+
bool TestAbout::testLicenseStart() {
62+
_subTestName = "testLicense/Start";
63+
Config::setBackend(&_configBackend);
64+
LicenseDialog::testLicenseValid = false;
65+
Config::saveBool(Config::KEY_GENERAL_LICENSE_AGREED, false);
66+
//
67+
LicenseDialog::licenseAgreement();
68+
//
69+
if(!Config::getBool(Config::KEY_GENERAL_LICENSE_AGREED, false)) {
70+
return error("After dialog, no settings");
71+
}
72+
if(!LicenseDialog::testLicenseValid) {
73+
return error("After dialog, no settings");
74+
}
75+
return true;
76+
}
77+
78+
bool TestAbout::testLicenseStarted() {
79+
_subTestName = "testLicense/Started";
80+
Config::setBackend(&_configBackend);
81+
LicenseDialog::testLicenseValid = false;
82+
Config::saveBool(Config::KEY_GENERAL_LICENSE_AGREED, true);
83+
//
84+
LicenseDialog::licenseAgreement();
85+
//
86+
if(!Config::getBool(Config::KEY_GENERAL_LICENSE_AGREED, false)) {
87+
return error("After dialog, no settings");
88+
}
89+
if(LicenseDialog::testLicenseValid) {
90+
return error("After dialog, no settings");
91+
}
92+
return true;
93+
}

test/testabout.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**************************************************************************
2+
* This file is part of QXmlEdit *
3+
* Copyright (C) 2022 by Luca Bellonda and individual contributors *
4+
* as indicated in the AUTHORS file *
5+
* lbellonda _at_ gmail.com *
6+
* *
7+
* This library is free software; you can redistribute it and/or *
8+
* modify it under the terms of the GNU Library General Public *
9+
* License as published by the Free Software Foundation; either *
10+
* version 2 of the License, or (at your option) any later version. *
11+
* *
12+
* This library is distributed in the hope that it will be useful, *
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15+
* Library General Public License for more details. *
16+
* *
17+
* You should have received a copy of the GNU Library General Public *
18+
* License along with this library; if not, write to the *
19+
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20+
* Boston, MA 02110-1301 USA *
21+
**************************************************************************/
22+
23+
#ifndef TESTABOUT_H
24+
#define TESTABOUT_H
25+
26+
#include "testbase.h"
27+
28+
class TestAbout : public TestBase
29+
{
30+
QMap<QString, QVariant> _configBackend;
31+
bool testLicense();
32+
bool testLicenseStart();
33+
bool testLicenseStarted();
34+
public:
35+
TestAbout();
36+
virtual ~TestAbout();
37+
38+
bool testFast();
39+
bool testUnit();
40+
41+
};
42+
43+
#endif // TESTABOUT_H

test/tst_qxmledit.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,20 @@ void TestQXmlEdit::testXMLBeans()
16551655
}
16561656
}
16571657

1658+
void TestQXmlEdit::testAbout()
1659+
{
1660+
{
1661+
TestAbout test;
1662+
const bool result = test.testFast();
1663+
QVERIFY2(result, (QString("test about: testFast() '%1'").arg(test.errorString())).toLatin1().data());
1664+
}
1665+
{
1666+
TestAbout test;
1667+
const bool result = test.testUnit();
1668+
QVERIFY2(result, (QString("test about: testUnit() '%1'").arg(test.errorString())).toLatin1().data());
1669+
}
1670+
}
1671+
16581672
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
16591673
// This function enabled for debug purposes. DO NOT REMOVE
16601674
//static void msgHandler(QtMsgType type, const char *msg)
@@ -1680,6 +1694,7 @@ void TestQXmlEdit::testNew()
16801694
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
16811695
qInstallMessageHandler(msgHandler);
16821696
#endif
1697+
testAbout();
16831698
}
16841699

16851700
QTEST_MAIN(TestQXmlEdit)

0 commit comments

Comments
 (0)