Always remember previously used directory

This commit is contained in:
Robin Stuart 2017-07-27 10:21:46 +01:00
parent b9f37ebceb
commit 468f44f298
4 changed files with 114 additions and 91 deletions

View File

@ -1,6 +1,6 @@
/*
Zint Barcode Generator - the open source barcode generator
Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009-2017 Robin Stuart <rstuart114@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -22,6 +22,7 @@
#include <QUiLoader>
#include <QStringList>
#include <QMessageBox>
#include <QSettings>
#include "datawindow.h"
#include <stdio.h>
@ -71,33 +72,31 @@ void DataWindow::okay()
void DataWindow::from_file()
{
//QString fileName;
//QFileDialog fdialog;
QFile file;
//fdialog.setFileMode(QFileDialog::ExistingFile);
//
//if(fdialog.exec()) {
// fileName = fdialog.selectedFiles().at(0);
//} else {
// return;
//}
QSettings settings;
QFileDialog open_dialog;
QString filename;
QFile file;
QByteArray outstream;
open_dialog.setWindowTitle("Open File");
open_dialog.setDirectory(settings.value("studio/default_dir", QDir::toNativeSeparators(QDir::homePath())).toString());
if (open_dialog.exec()) {
filename = open_dialog.selectedFiles().at(0);
} else {
return;
}
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open File"),
"./",
tr("All Files (*);;Text Files (*.txt)"));
if (fileName.isEmpty())
return;
file.setFileName(filename);
if(!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, tr("Open Error"), tr("Could not open selected file."));
return;
}
file.setFileName(fileName);
if(!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, tr("Open Error"), tr("Could not open selected file."));
return;
}
QByteArray outstream = file.readAll();
txtDataInput->setPlainText(QString(outstream));
file.close();
outstream = file.readAll();
txtDataInput->setPlainText(QString(outstream));
file.close();
settings.setValue("studio/default_dir", filename.mid(0, filename.lastIndexOf(QDir::separator())));
}

View File

@ -1,6 +1,6 @@
/*
Zint Barcode Generator - the open source barcode generator
Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009-2017 Robin Stuart <rstuart114@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -29,20 +29,25 @@
ExportWindow::ExportWindow()
{
QSettings settings;
setupUi(this);
linDestPath->setText(QDir::toNativeSeparators(QDir::homePath()));
connect(btnCancel, SIGNAL( clicked( bool )), SLOT(quit_now()));
connect(btnOK, SIGNAL( clicked( bool )), SLOT(process()));
connect(btnDestPath, SIGNAL( clicked( bool )), SLOT(get_directory()));
setupUi(this);
linDestPath->setText(settings.value("studio/export/destination", QDir::toNativeSeparators(QDir::homePath())).toString());
linPrefix->setText(settings.value("studio/export/file_prefix", "bcs_").toString());
cmbFileName->setCurrentIndex(settings.value("studio/export/name_format", 0).toInt());
cmbFileFormat->setCurrentIndex(settings.value("studio/export/filetype", 0).toInt());
connect(btnCancel, SIGNAL( clicked( bool )), SLOT(quit_now()));
connect(btnOK, SIGNAL( clicked( bool )), SLOT(process()));
connect(btnDestPath, SIGNAL( clicked( bool )), SLOT(get_directory()));
}
ExportWindow::~ExportWindow()
{
QSettings settings;
settings.setValue("studio/export/destination", linDestPath->text());
settings.setValue("studio/export/file_prefix", linPrefix->text());
settings.setValue("studio/export/name_format", cmbFileName->currentIndex());
settings.setValue("studio/export/filetype", cmbFileFormat->currentIndex());
}
@ -53,18 +58,21 @@ void ExportWindow::quit_now()
void ExportWindow::get_directory()
{
QString directory;
QFileDialog fdialog;
fdialog.setFileMode(QFileDialog::Directory);
if(fdialog.exec()) {
directory = fdialog.selectedFiles().at(0);
} else {
return;
}
linDestPath->setText(QDir::toNativeSeparators(directory));
QSettings settings;
QString directory;
QFileDialog fdialog;
fdialog.setFileMode(QFileDialog::Directory);
fdialog.setDirectory(settings.value("studio/default_dir", QDir::toNativeSeparators(QDir::homePath())).toString());
if(fdialog.exec()) {
directory = fdialog.selectedFiles().at(0);
} else {
return;
}
linDestPath->setText(QDir::toNativeSeparators(directory));
settings.setValue("studio/default_dir", directory);
}
void ExportWindow::process()

View File

@ -1,6 +1,6 @@
/***************************************************************************
* Copyright (C) 2008 by BogDan Vatra <bogdan@licentia.eu> *
* Copyright (C) 2009-2016 by Robin Stuart <rstuart114@gmail.com> *
* Copyright (C) 2009-2017 by Robin Stuart <rstuart114@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@ -198,26 +198,32 @@ void MainWindow::reset_view()
bool MainWindow::save()
{
bool status;
QSettings settings;
QFileDialog save_dialog;
QString filename;
save_dialog.setAcceptMode(QFileDialog::AcceptSave);
save_dialog.setWindowTitle("Save Barcode Image");
save_dialog.setDirectory(settings.value("studio/default_dir", QDir::toNativeSeparators(QDir::homePath())).toString());
#ifdef NO_PNG
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save Barcode Image"), ".",
tr("Encapsulated Post Script (*.eps);;Graphics Interchange Format (*.gif);;Scalable Vector Graphic (*.svg);;Windows Bitmap (*.bmp);;ZSoft PC Painter Image (*.pcx);;Extended Metafile (*.emf);;Tagged Image File Format (*.tif)"));
save_dialog.setNameFilter(tr("Encapsulated Post Script (*.eps);;Graphics Interchange Format (*.gif);;Scalable Vector Graphic (*.svg);;Windows Bitmap (*.bmp);;ZSoft PC Painter Image (*.pcx);;Extended Metafile (*.emf);;Tagged Image File Format (*.tif)"));
#else
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save Barcode Image"), ".",
tr("Portable Network Graphic (*.png);;Encapsulated Post Script (*.eps);;Graphics Interchange Format (*.gif);;Scalable Vector Graphic (*.svg);;Windows Bitmap (*.bmp);;ZSoft PC Painter Image (*.pcx);;Extended Metafile (*.emf);;Tagged Image File Format (*.tif)"));
save_dialog.setNameFilter(tr("Portable Network Graphic (*.png);;Encapsulated Post Script (*.eps);;Graphics Interchange Format (*.gif);;Scalable Vector Graphic (*.svg);;Windows Bitmap (*.bmp);;ZSoft PC Painter Image (*.pcx);;Extended Metafile (*.emf);;Tagged Image File Format (*.tif)"));
#endif
if (fileName.isEmpty())
return false;
status = m_bc.bc.save_to_file(fileName);
if(status == false) {
if (save_dialog.exec()) {
filename = save_dialog.selectedFiles().at(0);
} else {
return false;
}
if(m_bc.bc.save_to_file(filename) == false) {
QMessageBox::critical(this,tr("Save Error"),m_bc.bc.error_message());
return false;
}
return status;
settings.setValue("studio/default_dir", filename.mid(0, filename.lastIndexOf(QDir::separator())));
return true;
}
void MainWindow::about()

View File

@ -1,6 +1,6 @@
/*
Zint Barcode Generator - the open source barcode generator
Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009-2017 Robin Stuart <rstuart114@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -22,6 +22,7 @@
#include <QUiLoader>
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#include "sequencewindow.h"
#include "exportwindow.h"
@ -30,8 +31,14 @@
SequenceWindow::SequenceWindow()
{
setupUi(this);
QSettings settings;
QValidator *intvalid = new QIntValidator(this);
linStartVal->setText(settings.value("studio/sequence/start_value", "1").toString());
linEndVal->setText(settings.value("studio/sequence/end_value", "10").toString());
linIncVal->setText(settings.value("studio/sequence/increment", "1").toString());
linFormat->setText(settings.value("studio/sequence/format", "$$$$$$").toString());
linStartVal->setValidator(intvalid);
linEndVal->setValidator(intvalid);
linIncVal->setValidator(intvalid);
@ -45,6 +52,12 @@ SequenceWindow::SequenceWindow()
SequenceWindow::~SequenceWindow()
{
QSettings settings;
settings.setValue("studio/sequence/start_value", linStartVal->text());
settings.setValue("studio/sequence/end_value", linEndVal->text());
settings.setValue("studio/sequence/increment", linIncVal->text());
settings.setValue("studio/sequence/format", linFormat->text());
}
void SequenceWindow::quit_now()
@ -153,36 +166,33 @@ void SequenceWindow::check_generate()
void SequenceWindow::import()
{
//QString fileName;
//QFileDialog fdialog;
QFile file;
QString selectedFilter;
QSettings settings;
QFileDialog import_dialog;
QString filename;
QFile file;
QByteArray outstream;
import_dialog.setWindowTitle("Import File");
import_dialog.setDirectory(settings.value("studio/default_dir", QDir::toNativeSeparators(QDir::homePath())).toString());
//fdialog.setFileMode(QFileDialog::ExistingFile);
//if(fdialog.exec()) {
// fileName = fdialog.selectedFiles().at(0);
//} else {
// return;
//}
if (import_dialog.exec()) {
filename = import_dialog.selectedFiles().at(0);
} else {
return;
}
file.setFileName(filename);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::critical(this, tr("Open Error"), tr("Could not open selected file."));
return;
}
QString fileName = QFileDialog::getOpenFileName(this,
tr("Import File"),
"./",
tr("All Files (*);;Text Files (*.txt)"));
if (fileName.isEmpty())
return;
file.setFileName(fileName);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::critical(this, tr("Open Error"), tr("Could not open selected file."));
return;
}
outstream = file.readAll();
QByteArray outstream = file.readAll();
txtPreview->setPlainText(QString(outstream));
file.close();
txtPreview->setPlainText(QString(outstream));
file.close();
settings.setValue("studio/default_dir", filename.mid(0, filename.lastIndexOf(QDir::separator())));
}
void SequenceWindow::generate_sequence()