-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
248 lines (175 loc) · 6.85 KB
/
mainwindow.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QFile>
#include<QTextStream>
#include<QMessageBox>
#include<QDir>
#include<QFileDialog>
#include<QInputDialog>
#include<iostream>
#include<fstream>
#include"header.h"
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
for(int i=1;i<=3;i++)
ui->user->addItem("user_"+QString::number(i));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_openfile_clicked()
{
QString currentUser = ui->user->currentText();
QString pathToDirectory = "C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\"+currentUser;
QString currentFilename="program.txt";
mFilename="C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\"+currentUser+"\\program.txt";
string ifile=mFilename.toLocal8Bit().constData();
ifstream fp(ifile, std::ios::binary);
string temp="C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\temp.txt";
ofstream tp(temp,ios::binary);
tp<<fp.rdbuf();
int count=ui->version->count();
for(int i=0;i<=count;i++)
{
ui->version->clear();
}
QFile file( QString("%1//%2").arg(pathToDirectory, currentFilename) );
// do stuff with that file
if(!file.open(QIODevice::ReadOnly))
QMessageBox::information(0,"info",file.errorString());
QTextStream in(&file);
ui->textEdit->setText(in.readAll());
tp<<fp.rdbuf();
ui->label_2->setText(" ");
QStringRef userId(¤tUser,5,1);
count=countFiles(pathToDirectory);
for(int i=1;i<count;i++)
ui->version->addItem("program"+userId+"."+QString::number(i));
}
void MainWindow::on_actionCut_triggered()
{
ui->textEdit->cut();
}
void MainWindow::on_actionUndo_triggered()
{
ui->textEdit->undo();
}
void MainWindow::on_actionRedo_triggered()
{
ui->textEdit->redo();
}
void MainWindow::on_actionPaste_triggered()
{
ui->textEdit->paste();
}
void MainWindow::on_actionCopy_triggered()
{
ui->textEdit->copy();
}
void MainWindow::on_actionSave_triggered()
{
QString currentUser = ui->user->currentText();
QString pathToDirectory = "C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\"+currentUser;
/*QString currentFilename="program.txt";
QFile file( QString("%1//%2").arg(pathToDirectory, currentFilename) )
*/
mFilename="C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\"+currentUser+"\\program.txt";
string path =pathToDirectory.toLocal8Bit().constData();
string user=currentUser.toLocal8Bit().constData();
string ifile=mFilename.toLocal8Bit().constData();
string temp="C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\temp.txt";
QFile sfile(mFilename);
if(sfile.open(QFile::WriteOnly) | QFile::Text)
{
QTextStream out(&sfile);
out<<ui->textEdit->toPlainText();
sfile.flush();
sfile.close();
}
ui->label_2->setText( mFilename+" was saved!");
int flag=compareFiles(ifile,temp);
string f=to_string(flag);
QString qstr = QString::fromStdString(f);
createVersion(pathToDirectory,ifile,user);
}
void MainWindow::on_actionCommit_triggered()
{
QString currentUser = ui->user->currentText();
QString pathToDirectory = "C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\";
string filepath=pathToDirectory.toLocal8Bit().constData();
string user=currentUser.toLocal8Bit().constData();
mFilename="C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\"+currentUser+"\\program.txt";
string ifile=mFilename.toLocal8Bit().constData();
QFile sfile(mFilename);
if(sfile.open(QFile::WriteOnly) | QFile::Text)
{
QTextStream out(&sfile);
out<<ui->textEdit->toPlainText();
sfile.flush();
sfile.close();
}
ui->label_2->setText("You commited the changes of"+mFilename);
}
void MainWindow::on_view_clicked()
{
QString currentUser=ui->user->currentText();
QString pathToDirectory = "C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\"+currentUser+"\\";
QString currentFileName = ui->version->currentText()+".txt";
QFile file( QString("%1//%2").arg(pathToDirectory, currentFileName) );
// do stuff with that file
if(!file.open(QIODevice::ReadOnly))
QMessageBox::information(0,"info",file.errorString());
QTextStream in(&file);
ui->textEdit->setText(in.readAll());
}
void MainWindow::on_revert_clicked()
{
QString currentUser=ui->user->currentText();
QString pathToDirectory = "C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\"+currentUser+"\\";
string user=currentUser.toLocal8Bit().constData();
QString currentFile=ui->version->currentText();
string filename=currentFile.toLocal8Bit().constData();
string filepath="C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\"+user+"\\";
int count=countFiles(pathToDirectory);
revert(filepath,filename,count);
ui->label_2->setText("The program was reverted to "+currentFile);
}
void MainWindow::on_actionPush_triggered()
{
QString answer=QInputDialog::getText(this,"Push File To Application Folder","Enter \"commit\" to verify commit");
string ans=answer.toLocal8Bit().constData();
if(ans=="commit")
{
/*copy contents of user_id/program.txt to application folder"*/
QString currentUser = ui->user->currentText();
QString pathToDirectory = "C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\"+currentUser;
string path =pathToDirectory.toLocal8Bit().constData();
string user=currentUser.toLocal8Bit().constData();
QString appath="C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\Application\\";
string filepath=path+"\\program.txt";
ifstream ip(filepath,ios::binary);
string name="program_v";
string dest="C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\Application\\"+name+user[5]+".txt";
ofstream fp(dest,ios::binary|ios::app);
fp<<"\n";
fp<<ip.rdbuf();
fp<<"\n"<<"----------------------------------------------------------------------------------------";
}
}
void MainWindow::on_pull_clicked()
{
QString currentUser = ui->lineEdit->text();
QString pathToDirectory = "C:\\Users\\Rachita Nayak\\Desktop\\FS Mini Project\\Application";
QString currentFilename="program_v"+currentUser[5]+".txt";
QFile file( QString("%1//%2").arg(pathToDirectory, currentFilename) );
// do stuff with that file
if(!file.open(QIODevice::ReadOnly))
QMessageBox::information(0,"info",file.errorString());
QTextStream in(&file);
ui->textEdit->setText(in.readAll());
}