author | treke <treke> | 2002-09-04 17:53:12 (UTC) |
---|---|---|
committer | treke <treke> | 2002-09-04 17:53:12 (UTC) |
commit | 605d854057eb470a1d75210193b82eb0b1ad6b53 (patch) (unidiff) | |
tree | c411b661d5211fefbd83a7c8f63eef8c9cca72ee /noncore/comm/keypebble/kvncbookmarkdlg.cpp | |
parent | c35a5eabd8f5ed18e4216f6c88ee6794bacfb491 (diff) | |
download | opie-605d854057eb470a1d75210193b82eb0b1ad6b53.zip opie-605d854057eb470a1d75210193b82eb0b1ad6b53.tar.gz opie-605d854057eb470a1d75210193b82eb0b1ad6b53.tar.bz2 |
Major modifications to the User Interface
1) Bookmark support added, all options are stored on a per bookmark basis
2) 16 Bit color is now a supported bit depth for the server
Diffstat (limited to 'noncore/comm/keypebble/kvncbookmarkdlg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/comm/keypebble/kvncbookmarkdlg.cpp | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/noncore/comm/keypebble/kvncbookmarkdlg.cpp b/noncore/comm/keypebble/kvncbookmarkdlg.cpp new file mode 100644 index 0000000..1f97d13 --- a/dev/null +++ b/noncore/comm/keypebble/kvncbookmarkdlg.cpp | |||
@@ -0,0 +1,220 @@ | |||
1 | #include <qframe.h> | ||
2 | #include <qvbox.h> | ||
3 | #include <qcheckbox.h> | ||
4 | #include <qspinbox.h> | ||
5 | #include <qlabel.h> | ||
6 | #include <qlayout.h> | ||
7 | #include <qwhatsthis.h> | ||
8 | #include <qfile.h> | ||
9 | #include <qdir.h> | ||
10 | #include <qstring.h> | ||
11 | #include <qapplication.h> | ||
12 | #include <qlineedit.h> | ||
13 | #include <qtextstream.h> | ||
14 | #include <qpushbutton.h> | ||
15 | #include <qlistbox.h> | ||
16 | #include <qpe/config.h> | ||
17 | #include <qpe/global.h> | ||
18 | #include "krfbserver.h" | ||
19 | #include "kvncbookmarkdlg.h" | ||
20 | |||
21 | KVNCBookmarkDlg::KVNCBookmarkDlg( QWidget * parent=0, const char * name=0, WFlags f=0 ) | ||
22 | |||
23 | : KVNCBookmarkDlgBase( parent, name,f) | ||
24 | { | ||
25 | readBookmarks(); | ||
26 | refresh(); | ||
27 | |||
28 | } | ||
29 | |||
30 | KVNCBookmarkDlg::~KVNCBookmarkDlg() | ||
31 | { | ||
32 | } | ||
33 | |||
34 | void KVNCBookmarkDlg::addBookmark(KRFBServer * server) | ||
35 | { | ||
36 | if (server) { | ||
37 | servers.append(server); | ||
38 | bookmarkList->insertItem(server->name); | ||
39 | writeBookmarks(); | ||
40 | refresh(); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | void KVNCBookmarkDlg::deleteBookmark(QString name) | ||
45 | { | ||
46 | KRFBServer * server=0; | ||
47 | for ( server=servers.first(); server != 0; server=servers.next() ) { | ||
48 | if (server->name==name) { | ||
49 | servers.remove(servers.at()); | ||
50 | writeBookmarks(); | ||
51 | refresh(); | ||
52 | return; | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | KRFBServer *KVNCBookmarkDlg::getServer(QString name) | ||
57 | { | ||
58 | KRFBServer * server=0; | ||
59 | for ( server=servers.first(); server != 0; server=servers.next() ) { | ||
60 | if (server->name==name) | ||
61 | |||
62 | return server; | ||
63 | } | ||
64 | return 0; | ||
65 | } | ||
66 | |||
67 | |||
68 | /* | ||
69 | Note that the degree of protection offered by the encryption here is | ||
70 | only sufficient to avoid the most casual observation of the configuration | ||
71 | files. People with access to the files can write down the contents and | ||
72 | decrypt it using this source code. | ||
73 | |||
74 | Conceivably, and at some burden to the user, this encryption could | ||
75 | be improved. | ||
76 | */ | ||
77 | QString KVNCBookmarkDlg::encipher(const QString& plain) | ||
78 | { | ||
79 | // mainly, we make it long | ||
80 | QString cipher; | ||
81 | int mix=28730492; | ||
82 | for (int i=0; i<(int)plain.length(); i++) { | ||
83 | int u = plain[i].unicode(); | ||
84 | int c = u ^ mix; | ||
85 | QString x = QString::number(c,36); | ||
86 | cipher.append(QChar('a'+x.length())); | ||
87 | cipher.append(x); | ||
88 | mix *= u; | ||
89 | } | ||
90 | return cipher; | ||
91 | } | ||
92 | |||
93 | QString KVNCBookmarkDlg::decipher(const QString& cipher) | ||
94 | { | ||
95 | QString plain; | ||
96 | int mix=28730492; | ||
97 | for (int i=0; i<(int)cipher.length();) { | ||
98 | int l = cipher[i].unicode()-'a'; | ||
99 | QString x = cipher.mid(i+1,l); i+=l+1; | ||
100 | int u = x.toInt(0,36) ^ mix; | ||
101 | plain.append(QChar(u)); | ||
102 | mix *= u; | ||
103 | } | ||
104 | return plain; | ||
105 | } | ||
106 | |||
107 | void KVNCBookmarkDlg::readBookmarks(void) | ||
108 | { | ||
109 | QFile f(QDir::homeDirPath() + QString("/Applications/keypebble/bookmarks")); | ||
110 | |||
111 | QStringList entry; | ||
112 | QString key, val; | ||
113 | KRFBServer * server=0; | ||
114 | |||
115 | if ( f.open(IO_ReadOnly) ) { | ||
116 | QTextStream t( &f ); | ||
117 | QString s; | ||
118 | int n = 1; | ||
119 | while ( !t.eof() ) { | ||
120 | s = t.readLine(); | ||
121 | |||
122 | |||
123 | entry=QStringList::split('=',s); | ||
124 | key=entry[0].stripWhiteSpace().lower(); | ||
125 | val=entry[1].stripWhiteSpace(); | ||
126 | |||
127 | if (key=="server") { | ||
128 | |||
129 | if (server){ | ||
130 | servers.append(server); | ||
131 | server=0; | ||
132 | } | ||
133 | server = new KRFBServer(); | ||
134 | |||
135 | if (!server) | ||
136 | return; | ||
137 | server->name=val; | ||
138 | |||
139 | } | ||
140 | else if (key=="hostname") | ||
141 | server->hostname=val; | ||
142 | else if (key=="password") | ||
143 | server->password=decipher(val); | ||
144 | else if (key=="display") | ||
145 | server->display=val.toInt(); | ||
146 | else if (key=="hextile") | ||
147 | server->hexTile=val.toInt(); | ||
148 | else if (key=="corre") | ||
149 | server->corre=val.toInt(); | ||
150 | else if (key=="rre") | ||
151 | server->rre=val.toInt(); | ||
152 | else if (key=="copyrect") | ||
153 | server->copyrect=val.toInt(); | ||
154 | else if (key=="colors256") | ||
155 | server->colors256=val.toInt(); | ||
156 | else if (key=="shared") | ||
157 | server->shared=val.toInt(); | ||
158 | else if (key=="readonly") | ||
159 | server->readOnly=val.toInt(); | ||
160 | else if (key=="deiconify") | ||
161 | server->deIconify=val.toInt(); | ||
162 | else if (key=="updaterate") | ||
163 | server->updateRate=val.toInt(); | ||
164 | |||
165 | } | ||
166 | if (server){ | ||
167 | servers.append(server); | ||
168 | server=0; | ||
169 | } | ||
170 | f.close(); | ||
171 | } | ||
172 | } | ||
173 | |||
174 | void KVNCBookmarkDlg::writeBookmarks(void) | ||
175 | { | ||
176 | QString filename=Global::applicationFileName("keypebble","bookmarks"); | ||
177 | |||
178 | QFile f(filename); | ||
179 | |||
180 | QString key, val; | ||
181 | KRFBServer * server=0; | ||
182 | |||
183 | if ( f.open(IO_ReadWrite) ) { | ||
184 | QTextStream t( &f ); | ||
185 | QString s; | ||
186 | int n = 1; | ||
187 | KRFBServer *server; | ||
188 | |||
189 | for ( server=servers.first(); server != 0; server=servers.next() ) { | ||
190 | qDebug(server->name); | ||
191 | t << "server=" << server->name << '\n'; | ||
192 | t << "\thostname=" << server->hostname << '\n'; | ||
193 | t << "\tpassword=" << encipher(server->password )<< '\n'; | ||
194 | t << "\tdisplay=" << server->display << '\n'; | ||
195 | t << "\thextile=" << server->hexTile << '\n'; | ||
196 | t << "\tcorre=" << server->corre << '\n'; | ||
197 | t << "\trre=" << server->rre << '\n'; | ||
198 | t << "\tcopyrect=" << server->copyrect << '\n'; | ||
199 | t << "\tshared=" << server->shared << '\n'; | ||
200 | t << "\treadonly=" << server->readOnly << '\n'; | ||
201 | t << "\tdeiconify=" << server->deIconify << '\n'; | ||
202 | t << "\tupdaterate=" << server->updateRate << '\n'; | ||
203 | |||
204 | } | ||
205 | f.close(); | ||
206 | } | ||
207 | } | ||
208 | void KVNCBookmarkDlg::refresh(void) | ||
209 | { | ||
210 | bookmarkList->clear(); | ||
211 | KRFBServer * server=0; | ||
212 | for ( server=servers.first(); server != 0; server=servers.next() ) { | ||
213 | bookmarkList->insertItem(server->name); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | QString KVNCBookmarkDlg::selectedBookmark() | ||
218 | { | ||
219 | return bookmarkList->currentText(); | ||
220 | } | ||