-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetdirectorywindow.cpp
More file actions
75 lines (67 loc) · 1.92 KB
/
getdirectorywindow.cpp
File metadata and controls
75 lines (67 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "getdirectorywindow.h"
#include "ui_getdirectorywindow.h"
#include <QString>
#include <QFileDialog>
#include <QDir>
#include <QMessageBox>
#include "mainwindow.h"
#include <QTextStream>
#include <QFile>
GetDirectoryWindow::GetDirectoryWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::GetDirectoryWindow)
{
ui->setupUi(this);
}
GetDirectoryWindow::~GetDirectoryWindow()
{
delete ui;
}
void GetDirectoryWindow::on_dirBtn_clicked()
{
// -- Opens file explorer -- //
QString filename = QFileDialog::getExistingDirectory(
this,
"Select Directory",
QDir::homePath());
ui->filePathInput->setText(filename);
}
void GetDirectoryWindow::on_nextBtn_clicked()
{
QString dirName = ui->dirNameInput->text();
QString filepath = ui->filePathInput->text();
if(filepath.isEmpty()){
QMessageBox::warning(this, "Information Missing", "Enter a directory please.");
}else if(dirName.isEmpty()){
QMessageBox::warning(this, "Information Missing", "Enter a directory name please.");
}else{
//make textbook directories and such
QDir dir(filepath);
if(!dir.exists()){
dir.mkpath(".");
}else{
//Make Project Folder
if(!dir.exists(dirName)){
dir.mkdir(dirName);
}
}
//make a text file to store directory path
QString pathname = filepath + "/" + dirName;
dir.cd(QDir::homePath());
if(!dir.exists("StateInfo")){
dir.mkdir("StateInfo");
}
//use this file path to get project dir
QFile file(QDir::homePath()+"/StateInfo/Directory_Path.txt");
if (file.open(QIODevice::WriteOnly | QIODevice::Text)){
QTextStream out(&file);
out << pathname;
}
file.close();
close();
}
}
void GetDirectoryWindow::on_cancelBtn_clicked()
{
close();
}