/
connectdialog.cpp
116 lines (92 loc) · 3.25 KB
/
connectdialog.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
#include "connectdialog.h"
#include "ui_connectdialog.h"
#include <QCompleter>
#include <QMessageBox>
#include "AnsiString.h"
#include <sys/stat.h>
#include <unistd.h>
ConnectDialog::ConnectDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ConnectDialog) {
ui->setupUi(this);
setWindowIcon(QIcon(QString::fromUtf8(":/resources/conceptclienticon.png")));
ui->label->setBuddy(ui->addressEdit);
QStringList wordList;
AnsiString history;
#ifdef _WIN32
h_path = getenv("LOCALAPPDATA");
if (!h_path.Length())
h_path = getenv("APPDATA");
mkdir(h_path + "/ConceptClient-private");
h_path += (char *)"/ConceptClient-history.dat";
#else
h_path = getenv("HOME");
mkdir(h_path + "/.ConceptClient-private", 0777L);
h_path += (char *)"/.ConceptClient-history";
#endif
history.LoadFile(h_path.c_str());
this->history = history;
AnsiString sep = "\n";
int len_sep = sep.Length();
int pos = history.Pos(sep);
int index = 0;
int start = 0;
while (pos > 0) {
if (pos > 1) {
history.c_str()[pos - 1] = 0;
wordList << history.c_str();
}
AnsiString temp = history;
history = temp.c_str() + pos + len_sep - 1;
pos = history.Pos(sep);
}
QCompleter *completer = new QCompleter(wordList);
completer->setCaseSensitivity(Qt::CaseInsensitive);
ui->addressEdit->setCompleter(completer);
ui->addressEdit->setText(QString::fromUtf8("concept://"));
ui->addressEdit->addAction(QIcon(QString::fromUtf8(":/resources/gtk-index.png")), QLineEdit::LeadingPosition);
QAction *action = ui->addressEdit->addAction(QIcon(QString::fromUtf8(":/resources/gtk-delete.png")), QLineEdit::TrailingPosition);
QStyle *l_style = QApplication::style();
ui->OkButton->setIcon(l_style->standardIcon(QStyle::SP_DialogOkButton));
ui->CancelButton->setIcon(l_style->standardIcon(QStyle::SP_DialogCancelButton));
QObject::connect(action, SIGNAL(triggered()), this, SLOT(clearHistory()));
}
void ConnectDialog::clearHistory() {
int res = QMessageBox::question(this, "Clear history", "Are you sure you want to delete all the history?");
if (res == QMessageBox::Yes) {
ui->addressEdit->setCompleter(NULL);
#ifdef _WIN32
AnsiString h_path = getenv("LOCALAPPDATA");
if (!h_path.Length())
h_path = getenv("APPDATA");
mkdir(h_path + "/ConceptClient-private");
h_path += (char *)"/ConceptClient-history.dat";
#else
AnsiString h_path = getenv("HOME");
mkdir(h_path + "/.ConceptClient-private", 0777L);
h_path += (char *)"/.ConceptClient-history";
#endif
unlink(h_path.c_str());
}
}
ConnectDialog::~ConnectDialog() {
delete ui;
}
AnsiString ConnectDialog::getText() {
QString str = ui->addressEdit->text();
QByteArray ba = str.toLocal8Bit();
const char *c_str2 = ba.data();
AnsiString res((char *)c_str2);
return res;
}
void ConnectDialog::setText(const char *text) {
ui->addressEdit->setText(text);
}
void ConnectDialog::on_OkButton_clicked() {
this->setResult(QDialog::Accepted);
this->accept();
}
void ConnectDialog::on_CancelButton_clicked() {
this->setResult(QDialog::Rejected);
this->reject();
}