~sachinr/xpad/xpad-qt

« back to all changes in this revision

Viewing changes to src/pad.cpp

  • Committer: Sachin Raut
  • Date: 2013-09-19 16:29:31 UTC
  • Revision ID: great.sachin@gmail.com-20130919162931-rkup975f66xjsgvr
pad saving with 0 based files
added persistency to pads.
changed icon and saved pads path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "pad.h"
2
 
#include<QtCore>
3
 
#include<iostream>
 
2
#include <QtCore>
 
3
#include <iostream>
 
4
#include <fstream>
 
5
#include <string>
 
6
#include <QFile>
 
7
 
4
8
Pad::Pad()
5
9
{
6
10
    padwindow.SetPad(this);
7
11
    padwindow.show();
8
12
}
9
13
 
 
14
// close clicked handler
10
15
void Pad::dataReceived(QString data)
11
16
{
12
17
    windowBuffer = data;
13
 
//    qDebug()<<data;
14
 
}
15
 
 
16
 
PadWindow& Pad::GetWindow()
17
 
{
18
 
    return padwindow;
 
18
    saveToFile();
19
19
}
20
20
 
21
21
void Pad::show()
23
23
    padwindow.show();
24
24
}
25
25
 
 
26
void Pad::setFilename(QString file)
 
27
{
 
28
    filename = file;
 
29
}
 
30
 
 
31
void Pad::loadFromFile()
 
32
{
 
33
    QFile file(filename);
 
34
    file.open(QIODevice::ReadOnly);
 
35
    QTextStream in(&file);
 
36
    QString contents;
 
37
    while(!in.atEnd())
 
38
    {
 
39
        QString line = in.readLine();
 
40
        contents.append(line);
 
41
        contents.append('\n');
 
42
    }
 
43
    windowBuffer = contents;
 
44
    padwindow.SetText(windowBuffer);
 
45
}
 
46
 
 
47
void Pad::saveToFile()
 
48
{
 
49
    // wofstream doesn't work in qt
 
50
//    wstring f;
 
51
//    wofstream file;
 
52
//    file.open(f.c_str()); // error
 
53
//    file << windowBuffer;
 
54
//    file.close();
 
55
 
 
56
    QFile file(filename);
 
57
    if (file.open(QIODevice::WriteOnly))
 
58
    {
 
59
        QTextStream stream(&file);
 
60
        stream << windowBuffer << endl;
 
61
    }
 
62
}
 
63
 
26
64
Pad::~Pad()
27
65
{
28
 
    qDebug() << "pad with data - " << windowBuffer << "deleted";
29
66
}