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>
15 #include <GraphicsTestsDialog.hxx>
17 
19  OUString aTestName, OUString aTestStatus, Bitmap aTestBitmap)
20  : m_xBuilder(Application::CreateBuilder(pParent, "cui/ui/graphictestentry.ui"))
21  , m_xContainer(m_xBuilder->weld_container("gptestbox"))
22  , m_xTestLabel(m_xBuilder->weld_label("gptestlabel"))
23  , m_xTestButton(m_xBuilder->weld_button("gptestbutton"))
24  , m_xResultBitmap(aTestBitmap)
25 {
26  m_xParentDialog = pDialog;
27  m_xTestLabel->set_label(aTestName);
28  m_xTestButton->set_label(aTestStatus);
29  m_xTestButton->set_tooltip_text(aTestName);
30  m_xTestButton->set_background(
31  aTestStatus == "PASSED"
33  : aTestStatus == "QUIRKY" ? COL_YELLOW
34  : aTestStatus == "FAILED" ? COL_LIGHTRED : COL_LIGHTGRAY);
35  m_xTestButton->connect_clicked(LINK(this, GraphicTestEntry, HandleResultViewRequest));
36  m_xContainer->show();
37 }
38 
39 IMPL_LINK(GraphicTestEntry, HandleResultViewRequest, weld::Button&, rButton, void)
40 {
41  if (rButton.get_label() == "SKIPPED")
42  {
43  return;
44  }
45  ImageViewerDialog m_ImgVwDialog(m_xParentDialog, BitmapEx(m_xResultBitmap),
46  rButton.get_tooltip_text());
47  m_ImgVwDialog.run();
48 }
49 
51  : GenericDialogController(pParent, "cui/ui/graphictestdlg.ui", "GraphicTestsDialog")
52  , m_xResultLog(m_xBuilder->weld_text_view("gptest_txtVW"))
53  , m_xDownloadResults(m_xBuilder->weld_button("gptest_downld"))
54  , m_xContainerBox(m_xBuilder->weld_box("gptest_box"))
55 {
56  OUString userProfile = comphelper::BackupFileHelper::getUserProfileURL();
57  m_xZipFileUrl = userProfile + "/GraphicTestResults.zip";
58  m_xCreateFolderUrl = userProfile + "/GraphicTestResults";
59  osl::Directory::create(m_xCreateFolderUrl);
60  m_xDownloadResults->connect_clicked(LINK(this, GraphicsTestsDialog, HandleDownloadRequest));
61 }
62 
64 {
65  GraphicsRenderTests aTestObject;
66  aTestObject.run(true);
67  OUString aResultLog = aTestObject.getResultString()
68  + "\n(Click on any test to view its resultant bitmap image)";
69  m_xResultLog->set_text(aResultLog);
70  sal_Int32 nTestNumber = 0;
71  for (const VclTestResult& test : aTestObject.getTestResults())
72  {
73  auto xGpTest = std::make_unique<GraphicTestEntry>(m_xContainerBox.get(), m_xDialog.get(),
74  test.getTestName(), test.getStatus(),
75  test.getBitmap());
76  m_xContainerBox->reorder_child(xGpTest->get_widget(), nTestNumber++);
77  m_xGraphicTestEntries.push_back(std::move(xGpTest));
78  }
79  return GenericDialogController::run();
80 }
81 
82 IMPL_LINK_NOARG(GraphicsTestsDialog, HandleDownloadRequest, weld::Button&, void)
83 {
84  osl::File::remove(m_xZipFileUrl); // Remove the previous export
85  try
86  {
88  aZipHelper.addFolderWithContent(aZipHelper.getRootFolder(), m_xCreateFolderUrl);
89  aZipHelper.savePackage();
90  }
91  catch (const std::exception&)
92  {
93  std::unique_ptr<weld::MessageDialog> xBox(
94  Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Warning,
95  VclButtonsType::Ok, "Creation of Zip file failed!"));
96  xBox->run();
97  return;
98  }
99  FileExportedDialog aDialog(
100  m_xDialog.get(),
101  "The results have been successfully saved in the file 'GraphicTestResults.zip' !");
102  aDialog.run();
103 }
104 
106 {
108 }
std::shared_ptr< weld::Dialog > m_xDialog
virtual short run() override
weld::Dialog * m_xParentDialog
std::vector< VclTestResult > & getTestResults()
constexpr::Color COL_LIGHTGRAY(0xC0, 0xC0, 0xC0)
void addFolderWithContent(css::uno::Reference< css::uno::XInterface > const &xRootFolder, const OUString &rDirURL)
std::unique_ptr< weld::TextView > m_xResultLog
static const OUString & getUserProfileURL()
Reference< XNameAccess > m_xContainer
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_LIGHTRED
std::unique_ptr< weld::Container > m_xContainer
css::uno::Reference< css::uno::XInterface > & getRootFolder()
IMPL_LINK(GraphicTestEntry, HandleResultViewRequest, weld::Button &, rButton, void)
OUString getResultString()
std::unique_ptr< weld::Label > m_xTestLabel
std::unique_ptr< weld::Button > m_xTestButton
GraphicsTestsDialog(weld::Container *pParent)
std::unique_ptr< weld::Button > m_xDownloadResults
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_LIGHTGREEN
Reference< XExecutableDialog > m_xDialog
virtual short run()
std::unique_ptr< weld::Box > m_xContainerBox
Reference< XComponentContext > getProcessComponentContext()
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_YELLOW
IMPL_LINK_NOARG(GraphicsTestsDialog, HandleDownloadRequest, weld::Button &, void)
GraphicTestEntry(weld::Container *pParent, weld::Dialog *pDialog, OUString aTestName, OUString aTestStatus, Bitmap aTestBitmap)
static bool deleteDirRecursively(const OUString &rDirURL)
void run(bool storeResultBitmap=false)
std::vector< std::unique_ptr< GraphicTestEntry > > m_xGraphicTestEntries
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)