LibreOffice Module cui (master) 1
GraphicTestsDialog.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
13#include <osl/file.hxx>
17#include <vcl/test/GraphicsRenderTests.hxx>
18#include <svl/svlresid.hxx>
19#include <svl/svl.hrc>
20#include <vcl/svapp.hxx>
21
22#include <dialmgr.hxx>
23#include <strings.hrc>
24#include <ImageViewerDialog.hxx>
25
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)
33{
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));
45 m_xContainer->show();
46}
47
48IMPL_LINK(GraphicTestEntry, HandleResultViewRequest, weld::Button&, rButton, void)
49{
50 if (rButton.get_label() == SvlResId(GRTSTR_SKIPPED))
51 {
52 return;
53 }
54 ImageViewerDialog m_ImgVwDialog(m_xParentDialog, BitmapEx(m_xResultBitmap),
55 rButton.get_tooltip_text());
56 m_ImgVwDialog.run();
57}
58
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"))
64{
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));
70}
71
73{
74 GraphicsRenderTests aTestObject;
75 aTestObject.run(true);
76 OUString aResultLog
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())
81 {
82 auto xGpTest = std::make_unique<GraphicTestEntry>(m_xContainerBox.get(), m_xDialog.get(),
83 test.getTestName(), test.getStatus(true),
84 test.getBitmap());
85 m_xContainerBox->reorder_child(xGpTest->get_widget(), nTestNumber++);
86 m_xGraphicTestEntries.push_back(std::move(xGpTest));
87 }
88 return GenericDialogController::run();
89}
90
91IMPL_LINK_NOARG(GraphicsTestsDialog, HandleDownloadRequest, weld::Button&, void)
92{
93 osl::File::remove(m_xZipFileUrl); // Remove the previous export
94 try
95 {
97 aZipHelper.addFolderWithContent(aZipHelper.getRootFolder(), m_xCreateFolderUrl);
98 aZipHelper.savePackage();
99 }
100 catch (const std::exception&)
101 {
102 std::unique_ptr<weld::MessageDialog> xBox(
103 Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Warning,
104 VclButtonsType::Ok, CuiResId(RID_CUISTR_ZIPFAIL)));
105 xBox->run();
106 return;
107 }
108 FileExportedDialog aDialog(m_xDialog.get(), CuiResId(RID_CUISTR_SAVED));
109 aDialog.run();
110}
111
113{
115}
IMPL_LINK(GraphicTestEntry, HandleResultViewRequest, weld::Button &, rButton, void)
IMPL_LINK_NOARG(GraphicsTestsDialog, HandleDownloadRequest, weld::Button &, void)
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
std::unique_ptr< weld::Button > m_xTestButton
GraphicTestEntry(weld::Container *pParent, weld::Dialog *pDialog, OUString aTestName, OUString aTestStatus, Bitmap aTestBitmap)
std::unique_ptr< weld::Container > m_xContainer
std::unique_ptr< weld::Label > m_xTestLabel
weld::Dialog * m_xParentDialog
std::vector< VclTestResult > & getTestResults()
OUString getResultString(bool bLocalize=false)
void run(bool storeResultBitmap=false)
virtual short run() override
std::vector< std::unique_ptr< GraphicTestEntry > > m_xGraphicTestEntries
std::unique_ptr< weld::Button > m_xDownloadResults
GraphicsTestsDialog(weld::Container *pParent)
std::unique_ptr< weld::Box > m_xContainerBox
std::unique_ptr< weld::TextView > m_xResultLog
static const OUString & getUserProfileURL()
static bool deleteDirRecursively(const OUString &rDirURL)
void addFolderWithContent(css::uno::Reference< css::uno::XInterface > const &xRootFolder, const OUString &rDirURL)
css::uno::Reference< css::uno::XInterface > & getRootFolder()
virtual short run()
std::shared_ptr< weld::Dialog > m_xDialog
constexpr ::Color COL_LIGHTRED(0xFF, 0x00, 0x00)
constexpr ::Color COL_YELLOW(0xFF, 0xFF, 0x00)
constexpr ::Color COL_LIGHTGRAY(0xC0, 0xC0, 0xC0)
constexpr ::Color COL_LIGHTGREEN(0x00, 0xFF, 0x00)
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
Reference< XComponentContext > getProcessComponentContext()
Reference< XNameAccess > m_xContainer
SVL_DLLPUBLIC OUString SvlResId(TranslateId sContextAndId)