1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <inspector/TInspector_OpenButton.hxx>
18 #include <inspector/TInspector_Communicator.hxx>
19 #include <inspector/TInspector_OpenFileDialog.hxx>
21 #include <Standard_WarningsDisable.hxx>
22 #include <QApplication>
24 #include <QPushButton>
25 #include <Standard_WarningsRestore.hxx>
27 const int RECENT_FILES_CACHE_SIZE = 10;
29 // =======================================================================
30 // function : Constructor
32 // =======================================================================
33 TInspector_OpenButton::TInspector_OpenButton (QObject* theParent)
34 : QObject (theParent), myStartButton (0)
38 // =======================================================================
39 // function : StartButton
41 // =======================================================================
42 QPushButton* TInspector_OpenButton::StartButton()
46 myStartButton = new QPushButton();
47 myStartButton->setIcon (QIcon (":folder_open.png"));
48 connect (myStartButton, SIGNAL (clicked()), this, SLOT (onStartButtonClicked()));
53 // =======================================================================
54 // function : onStartButtonClicked
56 // =======================================================================
57 void TInspector_OpenButton::onStartButtonClicked()
59 QPushButton* aButton = (QPushButton*)sender();
60 TCollection_AsciiString aPluginName (aButton->objectName().toStdString().c_str());
61 if (aPluginName.IsEmpty())
64 QStringList aPluginRecentlyOpenedFiles;
65 if (myRecentlyOpenedFiles.contains(aPluginName))
67 QStringList aFileNames = myRecentlyOpenedFiles[aPluginName];
68 for (int i = 0; i < aFileNames.size(); i++)
70 QFileInfo aFileInfo (aFileNames[i]);
71 if (aFileInfo.exists() && aFileInfo.isFile())
72 aPluginRecentlyOpenedFiles.append(aFileInfo.absoluteFilePath());
76 QString aFileName = TInspector_OpenFileDialog::OpenFile (0, aPluginRecentlyOpenedFiles);
77 aFileName = QDir().toNativeSeparators (aFileName);
78 if (!aFileName.isEmpty()) {
79 QApplication::setOverrideCursor (Qt::WaitCursor);
80 TInspector_OpenFileDialog::Communicator()->OpenFile (aPluginName, TCollection_AsciiString (aFileName.toUtf8().data()));
82 QFileInfo aFileInfo (aFileName);
83 if (!aPluginRecentlyOpenedFiles.contains (aFileInfo.absoluteFilePath()))
85 myRecentlyOpenedFiles[aPluginName].append (aFileInfo.absoluteFilePath());
86 for (int i = 0; i < myRecentlyOpenedFiles[aPluginName].size() - RECENT_FILES_CACHE_SIZE; i++)
87 myRecentlyOpenedFiles[aPluginName].removeFirst();
88 TInspector_OpenFileDialog::SetPluginRecentlyOpenedFiles (aPluginName,
89 TInspector_OpenFileDialog::Communicator(), myRecentlyOpenedFiles[aPluginName]);
91 TInspector_OpenFileDialog::Communicator()->GetPluginParameters()->StorePreferences();
94 QApplication::restoreOverrideCursor();