Commit a678aec0 authored by heretik's avatar heretik
Browse files

add correct handling of temporary files in the "cache" directory. The...

add correct handling of temporary files in the "cache" directory. The directory is deleted when application is closed.
parent f14943b9
......@@ -6,6 +6,7 @@ set( CMAKE_AUTOUIC ON )
set( CMAKE_AUTORCC ON )
set( CMAKE_INCLUDE_CURRENT_DIR ON )
find_package( Boost REQUIRED )
find_package( Qt5Widgets REQUIRED )
find_package( Qt5LinguistTools REQUIRED )
......@@ -20,7 +21,7 @@ set( ${PROJECT_NAME}_SOURCES
qt5_create_translation( QM_FILES ${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_TS} )
# executable
include_directories( ${CMAKE_SOURCE_DIR}/src )
include_directories( ${CMAKE_SOURCE_DIR}/src ${Boost_INCLUDE_DIR} )
add_executable( ${PROJECT_NAME} ${${PROJECT_NAME}_SOURCES} ${QM_FILES} )
target_link_libraries( ${PROJECT_NAME} Qt5::Widgets stdc++fs )
......
......@@ -2,6 +2,10 @@
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
#include <QSettings>
#include <QStandardPaths>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <filesystem>
#include <fstream>
......@@ -10,7 +14,7 @@ namespace fs = std::filesystem;
MainWindow::MainWindow( QWidget *parent )
: QMainWindow( parent )
, ui_ptr_{ new Ui::MainWindow }
, directory_{ fs::temp_directory_path() / "prototypator" }
, directory_{}
, process_{ parent }
, plain_text_{ nullptr }
, commands_{}
......@@ -118,6 +122,10 @@ MainWindow::~MainWindow() = default;
void MainWindow::closeEvent( QCloseEvent *event )
{
// delete directory
fs::remove_all( directory_ );
// save settings
auto settings = QSettings{};
settings.beginGroup( "main_window" );
settings.setValue( "geometry", saveGeometry() );
......@@ -129,11 +137,10 @@ void MainWindow::closeEvent( QCloseEvent *event )
void MainWindow::prepare_directory()
{
// TODO revoir la gestion des repertoires temporaires
// pour pouvoir gérer la gestion de plusieurs applications lancees en meme temps
// erase directory
fs::remove_all( directory_ );
// get unique writeable directory
auto cache_dir = QStandardPaths::writableLocation( QStandardPaths::CacheLocation ).toStdString();
namespace bu = ::boost::uuids;
directory_ = cache_dir + "/" + bu::to_string( bu::random_generator()() );
// create directory
fs::create_directories( directory_ / "build" );
......
......@@ -39,36 +39,36 @@
<translation></translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.cpp" line="35"/>
<location filename="../src/prototypator/mainwindow.cpp" line="39"/>
<source>testing presence of cmake...
</source>
<translation></translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.cpp" line="39"/>
<location filename="../src/prototypator/mainwindow.cpp" line="43"/>
<source>running &apos;cmake&apos;...
</source>
<translation></translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.cpp" line="43"/>
<location filename="../src/prototypator/mainwindow.cpp" line="47"/>
<source>running &apos;make&apos;...
</source>
<translation></translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.cpp" line="47"/>
<location filename="../src/prototypator/mainwindow.cpp" line="51"/>
<source>running application...
</source>
<translation></translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.cpp" line="104"/>
<location filename="../src/prototypator/mainwindow.cpp" line="108"/>
<source> exited with code </source>
<translation></translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.cpp" line="164"/>
<location filename="../src/prototypator/mainwindow.cpp" line="171"/>
<source>failed to start &apos;</source>
<translation></translation>
</message>
......
......@@ -39,40 +39,40 @@
<translation>Entrée/sortie</translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.cpp" line="35"/>
<location filename="../src/prototypator/mainwindow.cpp" line="39"/>
<source>testing presence of cmake...
</source>
<translation>test de la présence de cmake...
</translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.cpp" line="39"/>
<location filename="../src/prototypator/mainwindow.cpp" line="43"/>
<source>running &apos;cmake&apos;...
</source>
<translation>démarrage de &apos;cmake&apos;...
</translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.cpp" line="43"/>
<location filename="../src/prototypator/mainwindow.cpp" line="47"/>
<source>running &apos;make&apos;...
</source>
<translation>démarrage de &apos;make&apos;...
</translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.cpp" line="47"/>
<location filename="../src/prototypator/mainwindow.cpp" line="51"/>
<source>running application...
</source>
<translation>démarrage de l&apos;application...
</translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.cpp" line="104"/>
<location filename="../src/prototypator/mainwindow.cpp" line="108"/>
<source> exited with code </source>
<translation> s&apos;est terminé avec le code </translation>
</message>
<message>
<location filename="../src/prototypator/mainwindow.cpp" line="164"/>
<location filename="../src/prototypator/mainwindow.cpp" line="171"/>
<source>failed to start &apos;</source>
<translation>impossible de démarrer &apos;</translation>
</message>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment