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 <config_folders.h>
21 :
22 : #include <generic/gensys.h>
23 :
24 : #include <vcl/msgbox.hxx>
25 : #include <vcl/button.hxx>
26 :
27 : #include <svdata.hxx>
28 :
29 : #include <rtl/ustrbuf.hxx>
30 : #include <rtl/strbuf.hxx>
31 : #include <rtl/bootstrap.hxx>
32 : #include <osl/process.h>
33 : #include <osl/thread.h>
34 : #include <unotools/configmgr.hxx>
35 :
36 : #include "vcl/unohelp.hxx"
37 : #include <com/sun/star/beans/PropertyValue.hpp>
38 : #include <com/sun/star/container/XNameAccess.hpp>
39 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 :
41 : using namespace com::sun::star;
42 :
43 : namespace {
44 :
45 0 : OUString GetNativeMessageBoxButtonText( StandardButtonType nButtonId, bool bUseResources )
46 : {
47 0 : OUString aText;
48 0 : if( bUseResources )
49 : {
50 0 : aText = Button::GetStandardText( nButtonId );
51 : }
52 0 : if( aText.isEmpty() )
53 : {
54 0 : switch( nButtonId )
55 : {
56 : case StandardButtonType::OK:
57 0 : aText = "OK";
58 0 : break;
59 : case StandardButtonType::Cancel:
60 0 : aText = "Cancel";
61 0 : break;
62 : case StandardButtonType::Abort:
63 0 : aText = "Abort";
64 0 : break;
65 : case StandardButtonType::Retry:
66 0 : aText = "Retry";
67 0 : break;
68 : case StandardButtonType::Ignore:
69 0 : aText = "Ignore";
70 0 : break;
71 : case StandardButtonType::Yes:
72 0 : aText = "Yes";
73 0 : break;
74 : case StandardButtonType::No:
75 0 : aText = "No";
76 0 : break;
77 0 : default: break;
78 : }
79 : }
80 0 : return aText;
81 : }
82 :
83 : }
84 :
85 99 : SalGenericSystem::SalGenericSystem()
86 : {
87 99 : }
88 :
89 97 : SalGenericSystem::~SalGenericSystem()
90 : {
91 97 : }
92 :
93 0 : int SalGenericSystem::ShowNativeMessageBox( const OUString& rTitle, const OUString& rMessage,
94 : int nButtonCombination, int nDefaultButton,
95 : bool bUseResources )
96 : {
97 0 : int nDefButton = 0;
98 0 : std::list< OUString > aButtons;
99 0 : int nButtonIds[5] = {0}, nBut = 0;
100 :
101 0 : ImplHideSplash();
102 :
103 0 : if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK ||
104 : nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL )
105 : {
106 0 : aButtons.push_back( GetNativeMessageBoxButtonText( StandardButtonType::OK, bUseResources ) );
107 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_OK;
108 : }
109 0 : if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL ||
110 : nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO )
111 : {
112 0 : aButtons.push_back( GetNativeMessageBoxButtonText( StandardButtonType::Yes, bUseResources ) );
113 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_YES;
114 0 : aButtons.push_back( GetNativeMessageBoxButtonText( StandardButtonType::No, bUseResources ) );
115 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO;
116 0 : if( nDefaultButton == SALSYSTEM_SHOWNATIVEMSGBOX_BTN_NO )
117 0 : nDefButton = 1;
118 : }
119 0 : if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_OK_CANCEL ||
120 0 : nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_YES_NO_CANCEL ||
121 : nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL )
122 : {
123 0 : if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_RETRY_CANCEL )
124 : {
125 0 : aButtons.push_back( GetNativeMessageBoxButtonText( StandardButtonType::Retry, bUseResources ) );
126 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY;
127 : }
128 0 : aButtons.push_back( GetNativeMessageBoxButtonText( StandardButtonType::Cancel, bUseResources ) );
129 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL;
130 0 : if( nDefaultButton == SALSYSTEM_SHOWNATIVEMSGBOX_BTN_CANCEL )
131 0 : nDefButton = aButtons.size()-1;
132 : }
133 0 : if( nButtonCombination == SALSYSTEM_SHOWNATIVEMSGBOX_BTNCOMBI_ABORT_RETRY_IGNORE )
134 : {
135 0 : aButtons.push_back( GetNativeMessageBoxButtonText( StandardButtonType::Abort, bUseResources ) );
136 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_ABORT;
137 0 : aButtons.push_back( GetNativeMessageBoxButtonText( StandardButtonType::Retry, bUseResources ) );
138 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY;
139 0 : aButtons.push_back( GetNativeMessageBoxButtonText( StandardButtonType::Ignore, bUseResources ) );
140 0 : nButtonIds[nBut++] = SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE;
141 0 : switch( nDefaultButton )
142 : {
143 0 : case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_RETRY: nDefButton = 1;break;
144 0 : case SALSYSTEM_SHOWNATIVEMSGBOX_BTN_IGNORE: nDefButton = 2;break;
145 : }
146 : }
147 :
148 0 : int nResult = ShowNativeDialog( rTitle, rMessage, aButtons, nDefButton );
149 :
150 0 : return nResult != -1 ? nButtonIds[ nResult ] : 0;
151 : }
152 :
153 : #if !defined(ANDROID) && !defined(IOS)
154 :
155 : // X11-specific
156 :
157 42 : const char* SalGenericSystem::getFrameResName()
158 : {
159 : /* according to ICCCM:
160 : * first search command line for -name parameter
161 : * then try RESOURCE_NAME environment variable
162 : * then use argv[0] stripped by directories
163 : */
164 42 : static OStringBuffer aResName;
165 42 : if( aResName.isEmpty() )
166 : {
167 3 : int nArgs = osl_getCommandArgCount();
168 21 : for( int n = 0; n < nArgs-1; n++ )
169 : {
170 18 : OUString aArg;
171 18 : osl_getCommandArg( n, &aArg.pData );
172 18 : if( aArg.equalsIgnoreAsciiCase("-name") )
173 : {
174 0 : osl_getCommandArg( n+1, &aArg.pData );
175 0 : aResName.append( OUStringToOString( aArg, osl_getThreadTextEncoding() ) );
176 0 : break;
177 : }
178 18 : }
179 3 : if( aResName.isEmpty() )
180 : {
181 3 : const char* pEnv = getenv( "RESOURCE_NAME" );
182 3 : if( pEnv && *pEnv )
183 0 : aResName.append( pEnv );
184 : }
185 3 : if( aResName.isEmpty() )
186 : aResName.append( OUStringToOString( utl::ConfigManager::getProductName().toAsciiLowerCase(),
187 3 : osl_getThreadTextEncoding()));
188 : }
189 42 : return aResName.getStr();
190 : }
191 :
192 42 : const char* SalGenericSystem::getFrameClassName()
193 : {
194 42 : static OStringBuffer aClassName;
195 42 : if( aClassName.isEmpty() )
196 : {
197 6 : OUString aIni, aProduct;
198 3 : rtl::Bootstrap::get( "BRAND_BASE_DIR", aIni );
199 3 : aIni += "/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap" );
200 6 : rtl::Bootstrap aBootstrap( aIni );
201 3 : aBootstrap.getFrom( "ProductKey", aProduct );
202 :
203 3 : if( !aProduct.isEmpty() )
204 3 : aClassName.append( OUStringToOString( aProduct, osl_getThreadTextEncoding() ) );
205 : else
206 3 : aClassName.append( OUStringToOString( utl::ConfigManager::getProductName(), osl_getThreadTextEncoding()));
207 : }
208 42 : return aClassName.getStr();
209 : }
210 :
211 : #endif
212 :
213 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|