LCOV - code coverage report
Current view: top level - cui/source/options - optopencl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 221 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 40 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <vcl/fixed.hxx>
      21             : #include <vcl/svapp.hxx>
      22             : #include <vcl/window.hxx>
      23             : #include <vcl/settings.hxx>
      24             : #include <svl/zforlist.hxx>
      25             : #include <opencl/openclconfig.hxx>
      26             : #include <officecfg/Office/Common.hxx>
      27             : #include <svtools/simptabl.hxx>
      28             : #include "optHeaderTabListbox.hxx"
      29             : 
      30             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      31             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      32             : #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
      33             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      34             : #include <com/sun/star/frame/Desktop.hpp>
      35             : #include <com/sun/star/util/XChangesBatch.hpp>
      36             : #include <com/sun/star/setup/UpdateCheckConfig.hpp>
      37             : 
      38             : #include "cuires.hrc"
      39             : #include "optopencl.hxx"
      40             : #include <svtools/treelistentry.hxx>
      41             : 
      42           0 : SvxOpenCLTabPage::SvxOpenCLTabPage(vcl::Window* pParent, const SfxItemSet& rSet) :
      43             :     SfxTabPage(pParent, "OptOpenCLPage", "cui/ui/optopenclpage.ui", &rSet),
      44           0 :     maConfig(OpenCLConfig::get())
      45             : {
      46           0 :     get(mpUseOpenCL, "useopencl");
      47           0 :     get(mpBlackListTable, "blacklist");
      48           0 :     get(mpBlackListFrame,"blacklistframe");
      49           0 :     get(mpBlackListEdit, "bledit");
      50           0 :     get(mpBlackListAdd, "bladd");
      51           0 :     get(mpBlackListDelete, "bldelete");
      52           0 :     get(mpWhiteListTable, "whitelist");
      53           0 :     get(mpWhiteListFrame,"whitelistframe");
      54           0 :     get(mpWhiteListEdit, "wledit");
      55           0 :     get(mpWhiteListAdd, "wladd");
      56           0 :     get(mpWhiteListDelete, "wldelete");
      57           0 :     get(mpOS,"os");
      58           0 :     get(mpOSVersion,"osversion");
      59           0 :     get(mpDevice,"device");
      60           0 :     get(mpVendor,"vendor");
      61           0 :     get(mpDrvVersion,"driverversion");
      62             : 
      63           0 :     mpUseOpenCL->Check(maConfig.mbUseOpenCL);
      64           0 :     mpUseOpenCL->SetClickHdl(LINK(this, SvxOpenCLTabPage, EnableOpenCLHdl));
      65             : 
      66           0 :     mpBlackListEdit->SetClickHdl(LINK(this, SvxOpenCLTabPage, BlackListEditHdl));
      67           0 :     mpBlackListAdd->SetClickHdl(LINK(this, SvxOpenCLTabPage, BlackListAddHdl));
      68           0 :     mpBlackListDelete->SetClickHdl(LINK(this, SvxOpenCLTabPage, BlackListDeleteHdl));
      69             : 
      70           0 :     mpWhiteListEdit->SetClickHdl(LINK(this, SvxOpenCLTabPage, WhiteListEditHdl));
      71           0 :     mpWhiteListAdd->SetClickHdl(LINK(this, SvxOpenCLTabPage, WhiteListAddHdl));
      72           0 :     mpWhiteListDelete->SetClickHdl(LINK(this, SvxOpenCLTabPage, WhiteListDeleteHdl));
      73             : 
      74           0 :     WinBits nBits = WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP;
      75           0 :     mpBlackList = VclPtr<SvSimpleTable>::Create( *mpBlackListTable, nBits );
      76           0 :     mpWhiteList = VclPtr<SvSimpleTable>::Create( *mpWhiteListTable, nBits );
      77             : 
      78           0 :     HeaderBar &rBlBar = mpBlackList->GetTheHeaderBar();
      79           0 :     HeaderBar &rWiBar = mpWhiteList->GetTheHeaderBar();
      80             : 
      81           0 :     HeaderBarItemBits nHBits = HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER | HeaderBarItemBits::CLICKABLE;
      82           0 :     rBlBar.InsertItem( 1, mpOS->GetText(),         0, nHBits );
      83           0 :     rBlBar.InsertItem( 2, mpOSVersion->GetText(),  0, nHBits );
      84           0 :     rBlBar.InsertItem( 3, mpVendor->GetText(),     0, nHBits );
      85           0 :     rBlBar.InsertItem( 4, mpDevice->GetText(),     0, nHBits );
      86           0 :     rBlBar.InsertItem( 5, mpDrvVersion->GetText(), 0, nHBits );
      87             : 
      88           0 :     rWiBar.InsertItem( 1, mpOS->GetText(),         0, nHBits );
      89           0 :     rWiBar.InsertItem( 2, mpOSVersion->GetText(),  0, nHBits );
      90           0 :     rWiBar.InsertItem( 3, mpVendor->GetText(),     0, nHBits );
      91           0 :     rWiBar.InsertItem( 4, mpDevice->GetText(),     0, nHBits );
      92           0 :     rWiBar.InsertItem( 5, mpDrvVersion->GetText(), 0, nHBits );
      93             : 
      94           0 :     long aTabs[] = {5, 0, 0, 0, 0, 0};
      95           0 :     aTabs[1] = rBlBar.GetTextWidth(rBlBar.GetItemText(1)) + 12;
      96           0 :     aTabs[2] = rBlBar.GetTextWidth(rBlBar.GetItemText(2)) + aTabs[1] + 12;
      97           0 :     aTabs[3] = rBlBar.GetTextWidth(rBlBar.GetItemText(3)) + aTabs[2] + 12;
      98           0 :     aTabs[4] = rBlBar.GetTextWidth(rBlBar.GetItemText(4)) + aTabs[3] + 12;
      99           0 :     aTabs[5] = rBlBar.GetTextWidth(rBlBar.GetItemText(5)) + aTabs[4] + 12;
     100           0 :     mpBlackList->SetTabs(aTabs, MAP_PIXEL);
     101           0 :     mpWhiteList->SetTabs(aTabs, MAP_PIXEL);
     102             : 
     103           0 : }
     104             : 
     105           0 : SvxOpenCLTabPage::~SvxOpenCLTabPage()
     106             : {
     107           0 :     disposeOnce();
     108           0 : }
     109             : 
     110           0 : void SvxOpenCLTabPage::dispose()
     111             : {
     112           0 :    for ( sal_uLong i = 0; i < mpBlackList->GetEntryCount(); ++i )
     113           0 :         delete static_cast<OpenCLConfig::ImplMatcher*>(mpBlackList->GetEntry(i)->GetUserData());
     114           0 :     for ( sal_uLong i = 0; i < mpWhiteList->GetEntryCount(); ++i )
     115           0 :         delete static_cast<OpenCLConfig::ImplMatcher*>(mpWhiteList->GetEntry(i)->GetUserData());
     116           0 :     mpBlackList.disposeAndClear();
     117           0 :     mpWhiteList.disposeAndClear();
     118             : 
     119           0 :     mpUseOpenCL.clear();
     120           0 :     mpBlackListFrame.clear();
     121           0 :     mpBlackListTable.clear();
     122           0 :     mpBlackListEdit.clear();
     123           0 :     mpBlackListAdd.clear();
     124           0 :     mpBlackListDelete.clear();
     125           0 :     mpOS.clear();
     126           0 :     mpOSVersion.clear();
     127           0 :     mpDevice.clear();
     128           0 :     mpVendor.clear();
     129           0 :     mpDrvVersion.clear();
     130           0 :     mpWhiteListFrame.clear();
     131           0 :     mpWhiteListTable.clear();
     132           0 :     mpWhiteListEdit.clear();
     133           0 :     mpWhiteListAdd.clear();
     134           0 :     mpWhiteListDelete.clear();
     135             : 
     136           0 :     SfxTabPage::dispose();
     137           0 : }
     138             : 
     139           0 : VclPtr<SfxTabPage> SvxOpenCLTabPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
     140             : {
     141           0 :     return VclPtr<SvxOpenCLTabPage>::Create(pParent, *rAttrSet);
     142             : }
     143             : 
     144           0 : bool SvxOpenCLTabPage::FillItemSet( SfxItemSet* )
     145             : {
     146           0 :     bool bModified = false;
     147           0 :     std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
     148             : 
     149           0 :     if (mpUseOpenCL->IsValueChangedFromSaved())
     150           0 :         maConfig.mbUseOpenCL = mpUseOpenCL->IsChecked();
     151             : 
     152           0 :     if (maConfig != OpenCLConfig::get())
     153             :     {
     154           0 :         maConfig.set();
     155           0 :         bModified = true;
     156             :     }
     157             : 
     158           0 :     if (bModified)
     159           0 :         batch->commit();
     160             : 
     161           0 :     return bModified;
     162             : }
     163             : 
     164             : namespace {
     165             : 
     166           0 : OUString format(const OpenCLConfig::ImplMatcher& rImpl)
     167             : {
     168           0 :     return (rImpl.maOS + "\t" +
     169           0 :             rImpl.maOSVersion + "\t" +
     170           0 :             rImpl.maPlatformVendor + "\t" +
     171           0 :             rImpl.maDevice + "\t" +
     172           0 :             rImpl.maDriverVersion);
     173             : }
     174             : 
     175           0 : void fillListBox(SvSimpleTable* pListBox, const OpenCLConfig::ImplMatcherSet& rSet)
     176             : {
     177           0 :     pListBox->SetUpdateMode(false);
     178             : // kill added UserData to treeitem
     179           0 :     for ( sal_uLong i = 0; i < pListBox->GetEntryCount(); ++i )
     180           0 :         delete static_cast<OpenCLConfig::ImplMatcher*>(pListBox->GetEntry(i)->GetUserData());
     181             : 
     182           0 :     pListBox->Clear();
     183           0 :     for (auto i = rSet.cbegin(); i != rSet.cend(); ++i)
     184             :     {
     185           0 :         OpenCLConfig::ImplMatcher* pImpl = new OpenCLConfig::ImplMatcher(*i);
     186           0 :         pListBox->InsertEntry(format(*i), NULL, false, TREELIST_APPEND, pImpl);
     187             :     }
     188             : 
     189           0 :     pListBox->SetUpdateMode(true);
     190           0 : }
     191             : 
     192             : }
     193             : 
     194           0 : void SvxOpenCLTabPage::Reset( const SfxItemSet* )
     195             : {
     196           0 :     maConfig = OpenCLConfig::get();
     197             : 
     198           0 :     mpUseOpenCL->Check(maConfig.mbUseOpenCL);
     199           0 :     mpUseOpenCL->SaveValue();
     200             : 
     201           0 :     fillListBox(mpBlackList, maConfig.maBlackList);
     202           0 :     fillListBox(mpWhiteList, maConfig.maWhiteList);
     203           0 : }
     204             : 
     205           0 : void SvxOpenCLTabPage::FillUserData()
     206             : {
     207           0 : }
     208             : 
     209             : namespace {
     210             : 
     211             : class ListEntryDialog : public ModalDialog
     212             : {
     213             : public:
     214             :     OpenCLConfig::ImplMatcher maEntry;
     215             : 
     216             :     VclPtr<ListBox> mpOS;
     217             :     VclPtr<Edit> mpOSVersion;
     218             :     VclPtr<Edit> mpPlatformVendor;
     219             :     VclPtr<Edit> mpDevice;
     220             :     VclPtr<Edit> mpDriverVersion;
     221             : 
     222             :     DECL_LINK(OSSelectHdl, ListBox*);
     223             :     DECL_LINK(EditModifiedHdl, Edit*);
     224             : 
     225             :     ListEntryDialog(vcl::Window* pParent, const OpenCLConfig::ImplMatcher& rEntry, const OString& rTag);
     226           0 :     virtual ~ListEntryDialog() { disposeOnce(); }
     227           0 :     virtual void dispose() SAL_OVERRIDE
     228             :     {
     229           0 :         mpOS.clear();
     230           0 :         mpOSVersion.clear();
     231           0 :         mpPlatformVendor.clear();
     232           0 :         mpDevice.clear();
     233           0 :         mpDriverVersion.clear();
     234           0 :         ModalDialog::dispose();
     235           0 :     }
     236             : 
     237             : };
     238             : 
     239           0 : ListEntryDialog::ListEntryDialog(vcl::Window* pParent, const OpenCLConfig::ImplMatcher& rEntry, const OString& rTag)
     240             :     : ModalDialog(pParent, "BlackOrWhiteListEntryDialog",
     241             :                   "cui/ui/blackorwhitelistentrydialog.ui"),
     242           0 :     maEntry(rEntry)
     243             : {
     244           0 :     get(mpOS, "os");
     245           0 :     get(mpOSVersion, "osversion");
     246           0 :     get(mpPlatformVendor, "platformvendor");
     247           0 :     get(mpDevice, "device");
     248           0 :     get(mpDriverVersion, "driverversion");
     249             : 
     250             :     // Hardcode knowledge that entry 0 is the "Any"
     251           0 :     if (maEntry.maOS.isEmpty())
     252             :     {
     253           0 :         mpOS->SelectEntryPos(0, false);
     254             :     }
     255             :     else
     256             :     {
     257           0 :         for (int i = 0; i < mpOS->GetEntryCount(); ++i)
     258             :         {
     259           0 :             if (maEntry.maOS == mpOS->GetEntry(i))
     260           0 :                 mpOS->SelectEntryPos(i, false);
     261             :         }
     262             :     }
     263           0 :     mpOSVersion->SetText(rEntry.maOSVersion);
     264           0 :     mpPlatformVendor->SetText(rEntry.maPlatformVendor);
     265           0 :     mpDevice->SetText(rEntry.maDevice);
     266           0 :     mpDriverVersion->SetText(rEntry.maDriverVersion);
     267             : 
     268           0 :     mpOS->SetSelectHdl(LINK( this, ListEntryDialog, OSSelectHdl));
     269           0 :     mpOSVersion->SetModifyHdl(LINK(this, ListEntryDialog, EditModifiedHdl));
     270           0 :     mpPlatformVendor->SetModifyHdl(LINK(this, ListEntryDialog, EditModifiedHdl));
     271           0 :     mpDevice->SetModifyHdl(LINK(this, ListEntryDialog, EditModifiedHdl));
     272           0 :     mpDriverVersion->SetModifyHdl(LINK(this, ListEntryDialog, EditModifiedHdl));
     273             : 
     274           0 :     SetText(get<FixedText>(rTag + "title")->GetText());
     275           0 : }
     276             : 
     277           0 : IMPL_LINK(ListEntryDialog, OSSelectHdl, ListBox*, pListBox)
     278             : {
     279           0 :     if (pListBox == mpOS)
     280             :     {
     281           0 :         if (mpOS->GetSelectEntryPos() == 0)
     282           0 :             maEntry.maOS.clear();
     283             :         else
     284           0 :             maEntry.maOS = mpOS->GetSelectEntry();
     285             :     }
     286             : 
     287           0 :     return 0;
     288             : }
     289             : 
     290           0 : IMPL_LINK(ListEntryDialog, EditModifiedHdl, Edit*, pEdit)
     291             : {
     292           0 :     if (pEdit == mpOSVersion)
     293           0 :         maEntry.maOSVersion = pEdit->GetText();
     294           0 :     else if (pEdit == mpPlatformVendor)
     295           0 :         maEntry.maPlatformVendor = pEdit->GetText();
     296           0 :     else if (pEdit == mpDevice)
     297           0 :         maEntry.maDevice = pEdit->GetText();
     298           0 :     else if (pEdit == mpDriverVersion)
     299           0 :         maEntry.maDriverVersion = pEdit->GetText();
     300             : 
     301           0 :     return 0;
     302             : }
     303             : 
     304           0 : void openListDialog(SvxOpenCLTabPage* pTabPage, OpenCLConfig::ImplMatcher& rEntry, const OString& rTag)
     305             : {
     306           0 :     ScopedVclPtrInstance< ListEntryDialog > aDlg(pTabPage, rEntry, rTag);
     307             : 
     308           0 :     if (aDlg->Execute() == RET_OK)
     309           0 :         rEntry = aDlg->maEntry;
     310           0 : }
     311             : 
     312           0 : const OpenCLConfig::ImplMatcher& findCurrentEntry(OpenCLConfig::ImplMatcherSet& rSet, SvSimpleTable* pListBox)
     313             : {
     314           0 :     SvTreeListEntry* pEntry = pListBox->FirstSelected() ;
     315             : 
     316           0 :     const OpenCLConfig::ImplMatcher* pSet = static_cast<OpenCLConfig::ImplMatcher*>(pEntry->GetUserData());
     317             : 
     318           0 :     for (auto i = rSet.cbegin(); i != rSet.cend(); ++i)
     319             :     {
     320           0 :         if (*i == *pSet)
     321             :         {
     322           0 :             return *i;
     323             :         }
     324             :     }
     325           0 :     auto i = rSet.begin();
     326           0 :     return *i;
     327             : }
     328             : 
     329             : }
     330             : 
     331           0 : long SvxOpenCLTabPage::EditHdl(SvSimpleTable* pListBox, OpenCLConfig::ImplMatcherSet& rSet, const OString& rTag)
     332             : {
     333           0 :     if (!pListBox->FirstSelected())
     334           0 :         return 0;
     335             : 
     336           0 :     OpenCLConfig::ImplMatcher rEntry(findCurrentEntry(rSet, pListBox));
     337           0 :     rSet.erase(rEntry);
     338           0 :     openListDialog(this, rEntry, rTag);
     339           0 :     rSet.insert(rEntry);
     340           0 :     fillListBox(pListBox, rSet);
     341             : 
     342           0 :     return 0;
     343             : }
     344             : 
     345           0 : long SvxOpenCLTabPage::AddHdl(SvSimpleTable* pListBox, OpenCLConfig::ImplMatcherSet& rSet, const OString& rTag)
     346             : {
     347           0 :     OpenCLConfig::ImplMatcher rEntry;
     348           0 :     openListDialog(this, rEntry, rTag);
     349           0 :     if (rEntry != OpenCLConfig::ImplMatcher())
     350             :     {
     351           0 :         rSet.insert(rEntry);
     352           0 :         fillListBox(pListBox, rSet);
     353             :     }
     354             : 
     355           0 :     return 0;
     356             : }
     357             : 
     358           0 : long SvxOpenCLTabPage::DeleteHdl(SvSimpleTable* pListBox, OpenCLConfig::ImplMatcherSet& rSet)
     359             : {
     360           0 :     if (!pListBox->FirstSelected())
     361           0 :         return 0;
     362             : 
     363           0 :     OpenCLConfig::ImplMatcher rEntry(findCurrentEntry(rSet, pListBox));
     364           0 :     rSet.erase(rEntry);
     365           0 :     fillListBox(pListBox, rSet);
     366             : 
     367           0 :     return 0;
     368             : }
     369             : 
     370           0 : void SvxOpenCLTabPage::EnableOpenCLHdl(VclFrame* pFrame, bool aEnable)
     371             : {
     372           0 :     pFrame->Enable(aEnable);
     373           0 : }
     374             : 
     375           0 : IMPL_LINK_NOARG(SvxOpenCLTabPage, BlackListEditHdl)
     376             : {
     377           0 :     return EditHdl(mpBlackList, maConfig.maBlackList, "bledit");
     378             : }
     379             : 
     380           0 : IMPL_LINK_NOARG(SvxOpenCLTabPage, BlackListAddHdl)
     381             : {
     382           0 :     return AddHdl(mpBlackList, maConfig.maBlackList, "bladd");
     383             : }
     384             : 
     385           0 : IMPL_LINK_NOARG(SvxOpenCLTabPage, BlackListDeleteHdl)
     386             : {
     387           0 :     return DeleteHdl(mpBlackList, maConfig.maBlackList);
     388             : }
     389             : 
     390           0 : IMPL_LINK_NOARG(SvxOpenCLTabPage, WhiteListEditHdl)
     391             : {
     392           0 :     return EditHdl(mpWhiteList, maConfig.maWhiteList, "wledit");
     393             : }
     394             : 
     395           0 : IMPL_LINK_NOARG(SvxOpenCLTabPage, WhiteListAddHdl)
     396             : {
     397           0 :     return AddHdl(mpWhiteList, maConfig.maWhiteList, "wladd");
     398             : }
     399             : 
     400           0 : IMPL_LINK_NOARG(SvxOpenCLTabPage, WhiteListDeleteHdl)
     401             : {
     402           0 :     return DeleteHdl(mpWhiteList, maConfig.maWhiteList);
     403             : }
     404             : 
     405           0 : IMPL_LINK_NOARG(SvxOpenCLTabPage, EnableOpenCLHdl)
     406             : {
     407           0 :     EnableOpenCLHdl(mpBlackListFrame, mpUseOpenCL->IsChecked());
     408           0 :     EnableOpenCLHdl(mpWhiteListFrame, mpUseOpenCL->IsChecked());
     409           0 :     return 0;
     410           0 : }
     411             : 
     412             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11