1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <comphelper/backupfilehelper.hxx>
11 #include <comphelper/processfactory.hxx>
12 #include <comphelper/DirectoryHelper.hxx>
13 #include <osl/file.hxx>
14 #include <svx/FileExportedDialog.hxx>
15 #include <unotools/ZipPackageHelper.hxx>
16 #include <GraphicsTestsDialog.hxx>
17 #include <vcl/test/GraphicsRenderTests.hxx>
18 #include <svl/svlresid.hxx>
19 #include <svl/svl.hrc>
20 #include <vcl/svapp.hxx>
22 #include <dialmgr.hxx>
23 #include <strings.hrc>
24 #include <ImageViewerDialog.hxx>
26 GraphicTestEntry::GraphicTestEntry(weld::Container
* pParent
, weld::Dialog
* pDialog
,
27 OUString aTestName
, OUString aTestStatus
, Bitmap aTestBitmap
)
28 : m_xBuilder(Application::CreateBuilder(pParent
, "cui/ui/graphictestentry.ui"))
29 , m_xContainer(m_xBuilder
->weld_container("gptestbox"))
30 , m_xTestLabel(m_xBuilder
->weld_label("gptestlabel"))
31 , m_xTestButton(m_xBuilder
->weld_button("gptestbutton"))
32 , m_xResultBitmap(aTestBitmap
)
34 m_xParentDialog
= pDialog
;
35 m_xTestLabel
->set_label(aTestName
);
36 m_xTestButton
->set_label(aTestStatus
);
37 m_xTestButton
->set_tooltip_text(aTestName
);
38 m_xTestButton
->set_background(
39 aTestStatus
== SvlResId(GRTSTR_PASSED
)
41 : aTestStatus
== SvlResId(GRTSTR_QUIRKY
)
43 : aTestStatus
== SvlResId(GRTSTR_FAILED
) ? COL_LIGHTRED
: COL_LIGHTGRAY
);
44 m_xTestButton
->connect_clicked(LINK(this, GraphicTestEntry
, HandleResultViewRequest
));
48 IMPL_LINK(GraphicTestEntry
, HandleResultViewRequest
, weld::Button
&, rButton
, void)
50 if (rButton
.get_label() == SvlResId(GRTSTR_SKIPPED
))
54 ImageViewerDialog
m_ImgVwDialog(m_xParentDialog
, BitmapEx(m_xResultBitmap
),
55 rButton
.get_tooltip_text());
59 GraphicsTestsDialog::GraphicsTestsDialog(weld::Container
* pParent
)
60 : GenericDialogController(pParent
, "cui/ui/graphictestdlg.ui", "GraphicTestsDialog")
61 , m_xResultLog(m_xBuilder
->weld_text_view("gptest_txtVW"))
62 , m_xDownloadResults(m_xBuilder
->weld_button("gptest_downld"))
63 , m_xContainerBox(m_xBuilder
->weld_box("gptest_box"))
65 OUString userProfile
= comphelper::BackupFileHelper::getUserProfileURL();
66 m_xZipFileUrl
= userProfile
+ "/GraphicTestResults.zip";
67 m_xCreateFolderUrl
= userProfile
+ "/GraphicTestResults";
68 osl::Directory::create(m_xCreateFolderUrl
);
69 m_xDownloadResults
->connect_clicked(LINK(this, GraphicsTestsDialog
, HandleDownloadRequest
));
72 short GraphicsTestsDialog::run()
74 GraphicsRenderTests aTestObject
;
75 aTestObject
.run(true);
77 = aTestObject
.getResultString(true) + "\n" + CuiResId(RID_CUISTR_CLICK_RESULT
);
78 m_xResultLog
->set_text(aResultLog
);
79 sal_Int32 nTestNumber
= 0;
80 for (VclTestResult
& test
: aTestObject
.getTestResults())
82 auto xGpTest
= std::make_unique
<GraphicTestEntry
>(m_xContainerBox
.get(), m_xDialog
.get(),
83 test
.getTestName(), test
.getStatus(true),
85 m_xContainerBox
->reorder_child(xGpTest
->get_widget(), nTestNumber
++);
86 m_xGraphicTestEntries
.push_back(std::move(xGpTest
));
88 return GenericDialogController::run();
91 IMPL_LINK_NOARG(GraphicsTestsDialog
, HandleDownloadRequest
, weld::Button
&, void)
93 osl::File::remove(m_xZipFileUrl
); // Remove the previous export
96 utl::ZipPackageHelper
aZipHelper(comphelper::getProcessComponentContext(), m_xZipFileUrl
);
97 aZipHelper
.addFolderWithContent(aZipHelper
.getRootFolder(), m_xCreateFolderUrl
);
98 aZipHelper
.savePackage();
100 catch (const std::exception
&)
102 std::unique_ptr
<weld::MessageDialog
> xBox(
103 Application::CreateMessageDialog(m_xDialog
.get(), VclMessageType::Warning
,
104 VclButtonsType::Ok
, CuiResId(RID_CUISTR_ZIPFAIL
)));
108 FileExportedDialog
aDialog(m_xDialog
.get(), CuiResId(RID_CUISTR_SAVED
));
112 GraphicsTestsDialog::~GraphicsTestsDialog()
114 comphelper::DirectoryHelper::deleteDirRecursively(m_xCreateFolderUrl
);