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 const OUString
& aTestName
, const OUString
& aTestStatus
,
29 : m_xBuilder(Application::CreateBuilder(pParent
, u
"cui/ui/graphictestentry.ui"_ustr
))
30 , m_xContainer(m_xBuilder
->weld_container(u
"gptestbox"_ustr
))
31 , m_xTestLabel(m_xBuilder
->weld_label(u
"gptestlabel"_ustr
))
32 , m_xTestButton(m_xBuilder
->weld_button(u
"gptestbutton"_ustr
))
33 , m_xResultBitmap(aTestBitmap
)
35 m_xParentDialog
= pDialog
;
36 m_xTestLabel
->set_label(aTestName
);
37 m_xTestButton
->set_label(aTestStatus
);
38 m_xTestButton
->set_tooltip_text(aTestName
);
39 m_xTestButton
->set_background(
40 aTestStatus
== SvlResId(GRTSTR_PASSED
)
42 : aTestStatus
== SvlResId(GRTSTR_QUIRKY
)
44 : aTestStatus
== SvlResId(GRTSTR_FAILED
) ? COL_LIGHTRED
: COL_LIGHTGRAY
);
45 m_xTestButton
->connect_clicked(LINK(this, GraphicTestEntry
, HandleResultViewRequest
));
49 IMPL_LINK(GraphicTestEntry
, HandleResultViewRequest
, weld::Button
&, rButton
, void)
51 if (rButton
.get_label() == SvlResId(GRTSTR_SKIPPED
))
55 ImageViewerDialog
m_ImgVwDialog(m_xParentDialog
, BitmapEx(m_xResultBitmap
),
56 rButton
.get_tooltip_text());
60 GraphicsTestsDialog::GraphicsTestsDialog(weld::Container
* pParent
)
61 : GenericDialogController(pParent
, u
"cui/ui/graphictestdlg.ui"_ustr
, u
"GraphicTestsDialog"_ustr
)
62 , m_xResultLog(m_xBuilder
->weld_text_view(u
"gptest_txtVW"_ustr
))
63 , m_xDownloadResults(m_xBuilder
->weld_button(u
"gptest_downld"_ustr
))
64 , m_xContainerBox(m_xBuilder
->weld_box(u
"gptest_box"_ustr
))
66 OUString userProfile
= comphelper::BackupFileHelper::getUserProfileURL();
67 m_xZipFileUrl
= userProfile
+ "/GraphicTestResults.zip";
68 m_xCreateFolderUrl
= userProfile
+ "/GraphicTestResults";
69 osl::Directory::create(m_xCreateFolderUrl
);
70 m_xDownloadResults
->connect_clicked(LINK(this, GraphicsTestsDialog
, HandleDownloadRequest
));
73 short GraphicsTestsDialog::run()
75 GraphicsRenderTests aTestObject
;
76 aTestObject
.run(true);
78 = aTestObject
.getResultString(true) + "\n" + CuiResId(RID_CUISTR_CLICK_RESULT
);
79 m_xResultLog
->set_text(aResultLog
);
80 sal_Int32 nTestNumber
= 0;
81 for (VclTestResult
& test
: aTestObject
.getTestResults())
83 auto xGpTest
= std::make_unique
<GraphicTestEntry
>(m_xContainerBox
.get(), m_xDialog
.get(),
84 test
.getTestName(), test
.getStatus(true),
86 m_xContainerBox
->reorder_child(xGpTest
->get_widget(), nTestNumber
++);
87 m_xGraphicTestEntries
.push_back(std::move(xGpTest
));
89 return GenericDialogController::run();
92 IMPL_LINK_NOARG(GraphicsTestsDialog
, HandleDownloadRequest
, weld::Button
&, void)
94 osl::File::remove(m_xZipFileUrl
); // Remove the previous export
97 utl::ZipPackageHelper
aZipHelper(comphelper::getProcessComponentContext(), m_xZipFileUrl
);
98 aZipHelper
.addFolderWithContent(aZipHelper
.getRootFolder(), m_xCreateFolderUrl
);
99 aZipHelper
.savePackage();
101 catch (const std::exception
&)
103 std::unique_ptr
<weld::MessageDialog
> xBox(
104 Application::CreateMessageDialog(m_xDialog
.get(), VclMessageType::Warning
,
105 VclButtonsType::Ok
, CuiResId(RID_CUISTR_ZIPFAIL
)));
109 FileExportedDialog
aDialog(m_xDialog
.get(), CuiResId(RID_CUISTR_SAVED
));
113 GraphicsTestsDialog::~GraphicsTestsDialog()
115 comphelper::DirectoryHelper::deleteDirRecursively(m_xCreateFolderUrl
);