|
|
|
|
@ -2,7 +2,9 @@
|
|
|
|
|
#include "./ui_mainwindow.h"
|
|
|
|
|
|
|
|
|
|
#include <QCloseEvent>
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
#include <QUndoStack>
|
|
|
|
|
#include <QUndoView>
|
|
|
|
|
|
|
|
|
|
@ -13,6 +15,7 @@
|
|
|
|
|
#include "genericcore.h"
|
|
|
|
|
#include "model/tablemodel.h"
|
|
|
|
|
|
|
|
|
|
static QStandardPaths::StandardLocation standardLocation = QStandardPaths::HomeLocation;
|
|
|
|
|
static QString updateTextClean = "Do you want to update the application now?";
|
|
|
|
|
static QString updateTextDirty = "Do you want to save the tasks & update the application now?";
|
|
|
|
|
|
|
|
|
|
@ -238,6 +241,39 @@ void MainWindow::saveItems() {
|
|
|
|
|
m_core->saveItems();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::importCSV() {
|
|
|
|
|
showStatusMessage(tr("Invoked 'File|Import CSV'"));
|
|
|
|
|
const QString csvFilePath = QFileDialog::getOpenFileName(
|
|
|
|
|
this, tr("Import CSV"), QStandardPaths::standardLocations(standardLocation).first(),
|
|
|
|
|
tr("CSV Files (*.csv)"));
|
|
|
|
|
if (QFileInfo::exists(csvFilePath)) {
|
|
|
|
|
m_core->importCSVFile(csvFilePath);
|
|
|
|
|
showStatusMessage(tr("Imported CSV file."));
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << "Selected CSV file path doesn't exist. Doing nothing...";
|
|
|
|
|
showStatusMessage(tr("Could't find CSV file!"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::exportCSV() {
|
|
|
|
|
showStatusMessage(tr("Invoked 'File|Export'"));
|
|
|
|
|
const QString filter = tr("CSV Files (*.csv)");
|
|
|
|
|
const QString location = QStandardPaths::standardLocations(standardLocation).first();
|
|
|
|
|
QFileDialog dialog(this, "Export CSV File", location, "Comma-separated file (*.csv)");
|
|
|
|
|
dialog.setDefaultSuffix(".csv");
|
|
|
|
|
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
|
|
|
if (dialog.exec()) {
|
|
|
|
|
const QString csvFilePath = dialog.selectedFiles().first();
|
|
|
|
|
const bool successful = m_core->exportCSVFile(csvFilePath);
|
|
|
|
|
if (successful) {
|
|
|
|
|
const QString message = QString(tr("CSV exported to: %1")).arg(csvFilePath);
|
|
|
|
|
showStatusMessage(message);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << "Selected CSV file path doesn't exist. Doing nothing...";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::createActions() {
|
|
|
|
|
// TODO add generic menu actions (file/new, edit/cut, ...)
|
|
|
|
|
createFileActions();
|
|
|
|
|
@ -270,14 +306,12 @@ void MainWindow::createFileActions() {
|
|
|
|
|
|
|
|
|
|
m_importAct = make_unique<QAction>(tr("&Import CSV..."), this);
|
|
|
|
|
m_importAct->setStatusTip(tr("Import an existing CSV file"));
|
|
|
|
|
// connect(m_importAct, &QAction::triggered, this, &MainWindow::importCSV);
|
|
|
|
|
m_importAct->setEnabled(false);
|
|
|
|
|
connect(m_importAct.get(), &QAction::triggered, this, &MainWindow::importCSV);
|
|
|
|
|
ui->menu_File->addAction(m_importAct.get());
|
|
|
|
|
|
|
|
|
|
m_exportAct = make_unique<QAction>(tr("&Export CSV..."), this);
|
|
|
|
|
m_exportAct->setStatusTip(tr("Export content to a CSV document to disk"));
|
|
|
|
|
// connect(m_exportAct, &QAction::triggered, this, &MainWindow::exportCSV);
|
|
|
|
|
m_exportAct->setEnabled(false);
|
|
|
|
|
connect(m_exportAct.get(), &QAction::triggered, this, &MainWindow::exportCSV);
|
|
|
|
|
ui->menu_File->addAction(m_exportAct.get());
|
|
|
|
|
|
|
|
|
|
ui->menu_File->addSeparator();
|
|
|
|
|
|