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 <osl/file.hxx>
21 #include <unotools/resmgr.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/weld.hxx>
24 
25 #include <strings.hrc>
26 #include "nameclashdlg.hxx"
27 
28 // NameClashDialog ---------------------------------------------------------
29 
IMPL_LINK(NameClashDialog,ButtonHdl_Impl,weld::Button &,rBtn,void)30 IMPL_LINK(NameClashDialog, ButtonHdl_Impl, weld::Button&, rBtn, void)
31 {
32     long nRet = long(ABORT);
33     if (m_xBtnRename.get() == &rBtn)
34     {
35         nRet = long(RENAME);
36         OUString aNewName = m_xEDNewName->get_text();
37         if ( ( aNewName == m_aNewName ) || aNewName.isEmpty() )
38         {
39             std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(m_xDialog.get(),
40                                                       VclMessageType::Warning, VclButtonsType::Ok,
41                                                       m_aSameName));
42             xErrorBox->run();
43             return;
44         }
45         m_aNewName = aNewName;
46     }
47     else if (m_xBtnOverwrite.get() == &rBtn)
48         nRet = long(OVERWRITE);
49 
50     m_xDialog->response(nRet);
51 }
52 
53 
NameClashDialog(weld::Window * pParent,const std::locale & rResLocale,OUString const & rTargetFolderURL,OUString const & rClashingName,OUString const & rProposedNewName,bool bAllowOverwrite)54 NameClashDialog::NameClashDialog( weld::Window* pParent, const std::locale& rResLocale,
55                                   OUString const & rTargetFolderURL,
56                                   OUString const & rClashingName,
57                                   OUString const & rProposedNewName,
58                                   bool bAllowOverwrite )
59     : GenericDialogController(pParent, "uui/ui/simplenameclash.ui", "SimpleNameClashDialog")
60     , m_aNewName(rClashingName)
61     , m_xFTMessage(m_xBuilder->weld_label("warning"))
62     , m_xEDNewName(m_xBuilder->weld_entry("newname"))
63     , m_xBtnOverwrite(m_xBuilder->weld_button("replace"))
64     , m_xBtnRename(m_xBuilder->weld_button("rename"))
65     , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
66 {
67     Link<weld::Button&,void> aLink( LINK( this, NameClashDialog, ButtonHdl_Impl ) );
68     m_xBtnOverwrite->connect_clicked( aLink );
69     m_xBtnRename->connect_clicked( aLink );
70     m_xBtnCancel->connect_clicked( aLink );
71 
72     OUString aInfo;
73     if ( bAllowOverwrite )
74     {
75         aInfo = Translate::get(STR_RENAME_OR_REPLACE, rResLocale);
76     }
77     else
78     {
79         aInfo = Translate::get(STR_NAME_CLASH_RENAME_ONLY, rResLocale);
80         m_xBtnOverwrite->hide();
81     }
82 
83     OUString aPath;
84     if ( osl::FileBase::E_None != osl::FileBase::getSystemPathFromFileURL( rTargetFolderURL, aPath ) )
85         aPath = rTargetFolderURL;
86 
87     m_aSameName = Translate::get(STR_SAME_NAME_USED, rResLocale);
88 
89     aInfo = aInfo.replaceFirst( "%NAME", rClashingName );
90     aInfo = aInfo.replaceFirst( "%FOLDER", aPath );
91     m_xFTMessage->set_label(aInfo);
92     if ( !rProposedNewName.isEmpty() )
93         m_xEDNewName->set_text( rProposedNewName );
94     else
95         m_xEDNewName->set_text( rClashingName );
96 }
97 
~NameClashDialog()98 NameClashDialog::~NameClashDialog()
99 {
100 }
101 
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
103