-rw-r--r-- | core/opie-login/loginwindowimpl.cpp | 25 | ||||
-rw-r--r-- | noncore/apps/opie-reader/Bkmks.cpp | 1 |
2 files changed, 22 insertions, 4 deletions
diff --git a/core/opie-login/loginwindowimpl.cpp b/core/opie-login/loginwindowimpl.cpp index 547a9b3..b9a286d 100644 --- a/core/opie-login/loginwindowimpl.cpp +++ b/core/opie-login/loginwindowimpl.cpp | |||
@@ -1,259 +1,276 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the OPIE Project | 2 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | 3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This file is free software; you can | 5 | _;:, .> :=|. This file is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This file is distributed in the hope that | 12 | .i_,=:_. -<s. This file is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
17 | ..}^=.= = ; Public License for more details. | 17 | ..}^=.= = ; Public License for more details. |
18 | ++= -. .` .: | 18 | ++= -. .` .: |
19 | : = ...= . :.=- You should have received a copy of the GNU | 19 | : = ...= . :.=- You should have received a copy of the GNU |
20 | -. .:....=;==+<; General Public License along with this file; | 20 | -. .:....=;==+<; General Public License along with this file; |
21 | -_. . . )=. = see the file COPYING. If not, write to the | 21 | -_. . . )=. = see the file COPYING. If not, write to the |
22 | -- :-=` Free Software Foundation, Inc., | 22 | -- :-=` Free Software Foundation, Inc., |
23 | 59 Temple Place - Suite 330, | 23 | 59 Temple Place - Suite 330, |
24 | Boston, MA 02111-1307, USA. | 24 | Boston, MA 02111-1307, USA. |
25 | 25 | ||
26 | */ | 26 | */ |
27 | #include <qpe/version.h> | 27 | #include <qpe/version.h> |
28 | #include <qpushbutton.h> | 28 | #include <qpushbutton.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qlineedit.h> | 30 | #include <qlineedit.h> |
31 | #include <qtimer.h> | 31 | #include <qtimer.h> |
32 | #include <qcombobox.h> | 32 | #include <qcombobox.h> |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | #include <qpopupmenu.h> | 34 | #include <qpopupmenu.h> |
35 | #include <qmessagebox.h> | 35 | #include <qmessagebox.h> |
36 | #if QT_VERSION < 0x030000 | 36 | #if QT_VERSION < 0x030000 |
37 | #include <qgfx_qws.h> | 37 | #include <qgfx_qws.h> |
38 | #endif | 38 | #endif |
39 | #include <qwindowsystem_qws.h> | 39 | #include <qwindowsystem_qws.h> |
40 | 40 | ||
41 | #include <qpe/qcopenvelope_qws.h> | 41 | #include <qpe/qcopenvelope_qws.h> |
42 | #include <qpe/config.h> | 42 | #include <qpe/config.h> |
43 | 43 | ||
44 | #include <opie2/odevice.h> | 44 | #include <opie2/odevice.h> |
45 | #include <opie2/oresource.h> | 45 | #include <opie2/oresource.h> |
46 | 46 | ||
47 | #include <stdio.h> | 47 | #include <stdio.h> |
48 | #include <stdlib.h> | 48 | #include <stdlib.h> |
49 | 49 | ||
50 | #include "passworddialogimpl.h" | 50 | #include "passworddialogimpl.h" |
51 | #include "loginwindowimpl.h" | 51 | #include "loginwindowimpl.h" |
52 | #include "loginapplication.h" | 52 | #include "loginapplication.h" |
53 | #include "inputmethods.h" | 53 | #include "inputmethods.h" |
54 | 54 | ||
55 | using namespace Opie::Core; | 55 | using namespace Opie::Core; |
56 | 56 | ||
57 | 57 | ||
58 | LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) | 58 | LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) |
59 | { | 59 | { |
60 | QPopupMenu *pop = new QPopupMenu ( this ); | 60 | QPopupMenu *pop = new QPopupMenu ( this ); |
61 | pop-> insertItem ( tr( "Restart" ), this, SLOT( restart())); | 61 | pop-> insertItem ( tr( "Restart" ), this, SLOT( restart())); |
62 | pop-> insertItem ( tr( "Quit" ), this, SLOT( quit())); | 62 | pop-> insertItem ( tr( "Quit" ), this, SLOT( quit())); |
63 | m_menu-> setPopup ( pop ); | 63 | m_menu-> setPopup ( pop ); |
64 | 64 | ||
65 | QCopChannel *channel = new QCopChannel ( "QPE/TaskBar", this ); | 65 | QCopChannel *channel = new QCopChannel ( "QPE/TaskBar", this ); |
66 | connect ( channel, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( receive(const QCString&,const QByteArray&))); | 66 | connect ( channel, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( receive(const QCString&,const QByteArray&))); |
67 | 67 | ||
68 | QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); | 68 | QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); |
69 | m_input = new InputMethods ( m_taskbar ); | 69 | m_input = new InputMethods ( m_taskbar ); |
70 | connect ( m_input, SIGNAL( inputToggled(bool)), this, SLOT( calcMaxWindowRect())); | 70 | connect ( m_input, SIGNAL( inputToggled(bool)), this, SLOT( calcMaxWindowRect())); |
71 | lay-> addWidget ( m_input ); | 71 | lay-> addWidget ( m_input ); |
72 | lay-> addStretch ( 10 ); | 72 | lay-> addStretch ( 10 ); |
73 | 73 | ||
74 | setActiveWindow ( ); | 74 | setActiveWindow ( ); |
75 | m_password-> setFocus ( ); | 75 | m_password-> setFocus ( ); |
76 | 76 | ||
77 | m_user-> insertStringList ( lApp-> allUsers ( )); | 77 | m_user-> insertStringList ( lApp-> allUsers ( )); |
78 | 78 | ||
79 | //there is no point in displaying the IM for a zaurus | 79 | //there is no point in displaying the IM for a zaurus |
80 | if (ODevice::inst ( )-> series ( ) != Model_Zaurus){ | 80 | if (ODevice::inst ( )-> series ( ) != Model_Zaurus){ |
81 | QTimer::singleShot ( 0, this, SLOT( showIM())); | 81 | QTimer::singleShot ( 0, this, SLOT( showIM())); |
82 | } | 82 | } |
83 | 83 | ||
84 | QString opiedir = ::getenv ( "OPIEDIR" ); | 84 | QString opiedir = ::getenv ( "OPIEDIR" ); |
85 | QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" ); | 85 | QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" ); |
86 | 86 | ||
87 | if ( !bgpix. isNull ( )) { | 87 | if ( !bgpix. isNull ( )) { |
88 | setBackgroundPixmap ( bgpix ); | 88 | setBackgroundPixmap ( bgpix ); |
89 | m_caption-> setBackgroundPixmap ( bgpix); | 89 | m_caption-> setBackgroundPixmap ( bgpix); |
90 | TextLabel1-> setBackgroundPixmap ( bgpix); | 90 | TextLabel1-> setBackgroundPixmap ( bgpix); |
91 | TextLabel2-> setBackgroundPixmap ( bgpix); | 91 | TextLabel2-> setBackgroundPixmap ( bgpix); |
92 | } | 92 | } |
93 | 93 | ||
94 | //m_caption-> setText ( tr("<center>Welcome to OPIE %1</center><center>& %2 %3</center>"). arg(QPE_VERSION). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); | 94 | //m_caption-> setText ( tr("<center>Welcome to OPIE %1</center><center>& %2 %3</center>"). arg(QPE_VERSION). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); |
95 | 95 | ||
96 | Config cfg ( "opie-login" ); | 96 | Config cfg ( "opie-login" ); |
97 | cfg. setGroup ( "General" ); | 97 | cfg. setGroup ( "General" ); |
98 | QString last = cfg. readEntry ( "LastLogin" ); | 98 | QString last = cfg. readEntry ( "LastLogin" ); |
99 | 99 | ||
100 | if ( !last. isEmpty ( )) | 100 | if ( !last. isEmpty ( )) |
101 | m_user-> setEditText ( last ); | 101 | m_user-> setEditText ( last ); |
102 | 102 | ||
103 | calcMaxWindowRect ( ); | 103 | calcMaxWindowRect ( ); |
104 | 104 | ||
105 | if ( PasswordDialogImpl::needDialog() ) | 105 | if ( PasswordDialogImpl::needDialog() ) |
106 | QTimer::singleShot(10, this, SLOT(showPasswordDialog()) ); | 106 | QTimer::singleShot(10, this, SLOT(showPasswordDialog()) ); |
107 | 107 | ||
108 | 108 | ||
109 | } | 109 | } |
110 | 110 | ||
111 | LoginWindowImpl::~LoginWindowImpl ( ) | 111 | LoginWindowImpl::~LoginWindowImpl ( ) |
112 | { | 112 | { |
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
116 | void LoginWindowImpl::receive ( const QCString &msg, const QByteArray &data ) | 116 | void LoginWindowImpl::receive ( const QCString &msg, const QByteArray &data ) |
117 | { | 117 | { |
118 | QDataStream stream ( data, IO_ReadOnly ); | 118 | QDataStream stream ( data, IO_ReadOnly ); |
119 | 119 | ||
120 | if ( msg == "hideInputMethod()" ) | 120 | if ( msg == "hideInputMethod()" ) |
121 | m_input-> hideInputMethod ( ); | 121 | m_input-> hideInputMethod ( ); |
122 | else if ( msg == "showInputMethod()" ) | 122 | else if ( msg == "showInputMethod()" ) |
123 | m_input-> showInputMethod ( ); | 123 | m_input-> showInputMethod ( ); |
124 | else if ( msg == "reloadInputMethods()" ) | 124 | else if ( msg == "reloadInputMethods()" ) |
125 | m_input-> loadInputMethods ( ); | 125 | m_input-> loadInputMethods ( ); |
126 | } | 126 | } |
127 | 127 | ||
128 | void LoginWindowImpl::calcMaxWindowRect ( ) | 128 | void LoginWindowImpl::calcMaxWindowRect ( ) |
129 | { | 129 | { |
130 | #ifdef Q_WS_QWS | 130 | #ifdef Q_WS_QWS |
131 | QRect wr; | 131 | QRect wr; |
132 | int displayWidth = qApp-> desktop ( )-> width ( ); | 132 | int displayWidth = qApp-> desktop ( )-> width ( ); |
133 | QRect ir = m_input-> inputRect ( ); | 133 | QRect ir = m_input-> inputRect ( ); |
134 | if ( ir.isValid() ) | 134 | if ( ir.isValid() ) |
135 | wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); | 135 | wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); |
136 | else | 136 | else |
137 | wr.setCoords( 0, 0, displayWidth-1, m_taskbar->y()-1 ); | 137 | wr.setCoords( 0, 0, displayWidth-1, m_taskbar->y()-1 ); |
138 | 138 | ||
139 | #if QT_VERSION < 0x030000 | 139 | #if QT_VERSION < 0x030000 |
140 | wr = qt_screen-> mapToDevice ( wr, QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); | 140 | wr = qt_screen-> mapToDevice ( wr, QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); |
141 | #endif | 141 | #endif |
142 | 142 | ||
143 | QWSServer::setMaxWindowRect( wr ); | 143 | QWSServer::setMaxWindowRect( wr ); |
144 | #endif | 144 | #endif |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) | 148 | void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) |
149 | { | 149 | { |
150 | switch ( e-> key ( )) { | 150 | switch ( e-> key ( )) { |
151 | case HardKey_Suspend: suspend ( ); | 151 | case HardKey_Suspend: suspend ( ); |
152 | break; | 152 | break; |
153 | case HardKey_Backlight: backlight ( ); | 153 | case HardKey_Backlight: backlight ( ); |
154 | break; | 154 | break; |
155 | default: e-> ignore ( ); | 155 | default: e-> ignore ( ); |
156 | break; | 156 | break; |
157 | } | 157 | } |
158 | LoginWindow::keyPressEvent ( e ); | 158 | LoginWindow::keyPressEvent ( e ); |
159 | } | 159 | } |
160 | 160 | ||
161 | 161 | ||
162 | void LoginWindowImpl::toggleEchoMode ( bool t ) | 162 | void LoginWindowImpl::toggleEchoMode ( bool t ) |
163 | { | 163 | { |
164 | m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password ); | 164 | m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password ); |
165 | } | 165 | } |
166 | 166 | ||
167 | void LoginWindowImpl::showIM ( ) | 167 | void LoginWindowImpl::showIM ( ) |
168 | { | 168 | { |
169 | m_input-> showInputMethod ( ); | 169 | m_input-> showInputMethod ( ); |
170 | } | 170 | } |
171 | 171 | ||
172 | void LoginWindowImpl::restart ( ) | 172 | void LoginWindowImpl::restart ( ) |
173 | { | 173 | { |
174 | qApp-> quit ( ); | 174 | qApp-> quit ( ); |
175 | } | 175 | } |
176 | 176 | ||
177 | void LoginWindowImpl::quit ( ) | 177 | void LoginWindowImpl::quit ( ) |
178 | { | 178 | { |
179 | lApp-> quitToConsole ( ); | 179 | lApp-> quitToConsole ( ); |
180 | } | 180 | } |
181 | 181 | ||
182 | void LoginWindowImpl::suspend ( ) | 182 | void LoginWindowImpl::suspend ( ) |
183 | { | 183 | { |
184 | ODevice::inst ( )-> suspend ( ); | 184 | ODevice::inst ( )-> suspend ( ); |
185 | 185 | ||
186 | QCopEnvelope e("QPE/System", "setBacklight(int)"); | 186 | QCopEnvelope e("QPE/System", "setBacklight(int)"); |
187 | e << -3; // Force on | 187 | e << -3; // Force on |
188 | } | 188 | } |
189 | 189 | ||
190 | void LoginWindowImpl::backlight ( ) | 190 | void LoginWindowImpl::backlight ( ) |
191 | { | 191 | { |
192 | QCopEnvelope e("QPE/System", "setBacklight(int)"); | 192 | QCopEnvelope e("QPE/System", "setBacklight(int)"); |
193 | e << -2; // toggle | 193 | e << -2; // toggle |
194 | } | 194 | } |
195 | 195 | ||
196 | class WaitLogo : public QLabel { | 196 | class WaitLogo : public QLabel { |
197 | public: | 197 | public: |
198 | WaitLogo ( ) : QLabel ( 0, "wait hack!", WStyle_Customize | WStyle_NoBorder | WStyle_Tool ) | 198 | WaitLogo ( ) : QLabel ( 0, "wait hack!", WStyle_Customize | WStyle_NoBorder | WStyle_Tool ) |
199 | { | 199 | { |
200 | setPixmap( Opie::Core::OResource::loadPixmap( "launcher/new_wait" ) ); | 200 | setPixmap( Opie::Core::OResource::loadPixmap( "launcher/new_wait" ) ); |
201 | setAlignment ( AlignCenter ); | 201 | setAlignment ( AlignCenter ); |
202 | move ( 0, 0 ); | 202 | move ( 0, 0 ); |
203 | resize ( qApp-> desktop ( )-> width ( ), qApp-> desktop ( )-> height ( )); | 203 | resize ( qApp-> desktop ( )-> width ( ), qApp-> desktop ( )-> height ( )); |
204 | 204 | ||
205 | m_visible = false; | 205 | m_visible = false; |
206 | show ( ); | 206 | show ( ); |
207 | } | 207 | } |
208 | 208 | ||
209 | virtual void showEvent ( QShowEvent *e ) | 209 | virtual void showEvent ( QShowEvent *e ) |
210 | { | 210 | { |
211 | QLabel::showEvent ( e ); | 211 | QLabel::showEvent ( e ); |
212 | m_visible = true; | 212 | m_visible = true; |
213 | } | 213 | } |
214 | 214 | ||
215 | virtual void paintEvent ( QPaintEvent *e ) | 215 | virtual void paintEvent ( QPaintEvent *e ) |
216 | { | 216 | { |
217 | QLabel::paintEvent ( e ); | 217 | QLabel::paintEvent ( e ); |
218 | if ( m_visible ) | 218 | if ( m_visible ) |
219 | qApp-> quit ( ); | 219 | qApp-> quit ( ); |
220 | } | 220 | } |
221 | 221 | ||
222 | private: | 222 | private: |
223 | bool m_visible; | 223 | bool m_visible; |
224 | }; | 224 | }; |
225 | 225 | ||
226 | void LoginWindowImpl::login ( ) | 226 | void LoginWindowImpl::login ( ) |
227 | { | 227 | { |
228 | const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( )); | 228 | char *const user = ::strdup ( m_user-> currentText ( ). local8Bit ( )); |
229 | const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( )); | 229 | char *pass = ::strdup ( m_password-> text ( ). local8Bit ( )); |
230 | 230 | ||
231 | if ( !user || !user [0] ) | 231 | if ( !user ) { |
232 | if ( pass ) | ||
233 | free( pass ); | ||
232 | return; | 234 | return; |
233 | if ( !pass ) | 235 | } |
236 | if ( !user [0] ) { | ||
237 | free( user ); | ||
238 | if ( pass ) | ||
239 | free( pass ); | ||
240 | return; | ||
241 | } | ||
242 | bool passwordIsEmpty = false; | ||
243 | if ( !pass ) { | ||
244 | passwordIsEmpty = true; | ||
234 | pass = ""; | 245 | pass = ""; |
246 | } | ||
235 | 247 | ||
236 | if ( lApp-> checkPassword ( user, pass )) { | 248 | if ( lApp-> checkPassword ( user, pass )) { |
249 | if ( !passwordIsEmpty ) | ||
250 | free(pass); | ||
237 | Config cfg ( "opie-login" ); | 251 | Config cfg ( "opie-login" ); |
238 | cfg. setGroup ( "General" ); | 252 | cfg. setGroup ( "General" ); |
239 | cfg. writeEntry ( "LastLogin", user ); | 253 | cfg. writeEntry ( "LastLogin", user ); |
240 | cfg. write ( ); | 254 | cfg. write ( ); |
241 | 255 | ||
242 | lApp-> setLoginAs ( user ); | 256 | lApp-> setLoginAs ( user ); |
243 | 257 | ||
244 | // Draw a big wait icon, the image can be altered in later revisions | 258 | // Draw a big wait icon, the image can be altered in later revisions |
245 | m_input-> hideInputMethod ( ); | 259 | m_input-> hideInputMethod ( ); |
246 | new WaitLogo ( ); | 260 | new WaitLogo ( ); |
247 | // WaitLogo::showEvent() calls qApp-> quit() | 261 | // WaitLogo::showEvent() calls qApp-> quit() |
248 | } | 262 | } |
249 | else { | 263 | else { |
250 | QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." )); | 264 | QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." )); |
251 | m_password-> clear ( ); | 265 | m_password-> clear ( ); |
266 | free( user ); | ||
267 | if ( !passwordIsEmpty ) | ||
268 | free( pass ); | ||
252 | } | 269 | } |
253 | } | 270 | } |
254 | 271 | ||
255 | void LoginWindowImpl::showPasswordDialog() { | 272 | void LoginWindowImpl::showPasswordDialog() { |
256 | PasswordDialogImpl dia( this ); | 273 | PasswordDialogImpl dia( this ); |
257 | dia.showMaximized(); | 274 | dia.showMaximized(); |
258 | dia.exec(); | 275 | dia.exec(); |
259 | } | 276 | } |
diff --git a/noncore/apps/opie-reader/Bkmks.cpp b/noncore/apps/opie-reader/Bkmks.cpp index 28f6318..00141a3 100644 --- a/noncore/apps/opie-reader/Bkmks.cpp +++ b/noncore/apps/opie-reader/Bkmks.cpp | |||
@@ -1,415 +1,416 @@ | |||
1 | #include <qmessagebox.h> | 1 | #include <qmessagebox.h> |
2 | 2 | ||
3 | #include "Bkmks.h" | 3 | #include "Bkmks.h" |
4 | 4 | ||
5 | #include "StyleConsts.h" | 5 | #include "StyleConsts.h" |
6 | #include "Markups.h" | 6 | #include "Markups.h" |
7 | #include "my_list.h" | 7 | #include "my_list.h" |
8 | #include "version.h" | 8 | #include "version.h" |
9 | #include "names.h" | 9 | #include "names.h" |
10 | 10 | ||
11 | const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE); | 11 | const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE); |
12 | 12 | ||
13 | Bkmk::Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p) : | 13 | Bkmk::Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p) : |
14 | m_name(0), | 14 | m_name(0), |
15 | m_namelen(0), | 15 | m_namelen(0), |
16 | m_anno(0), | 16 | m_anno(0), |
17 | m_annolen(0), | 17 | m_annolen(0), |
18 | m_position(0) | 18 | m_position(0) |
19 | { | 19 | { |
20 | init(_nm, _nmlen, _anno, _annolen, _p); | 20 | init(_nm, _nmlen, _anno, _annolen, _p); |
21 | } | 21 | } |
22 | 22 | ||
23 | Bkmk::Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short annolen, unsigned int _p) : m_position(_p) | 23 | Bkmk::Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short annolen, unsigned int _p) : m_position(_p) |
24 | { | 24 | { |
25 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, annolen, _p); | 25 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, annolen, _p); |
26 | } | 26 | } |
27 | 27 | ||
28 | Bkmk::Bkmk(const Bkmk& rhs) : | 28 | Bkmk::Bkmk(const Bkmk& rhs) : |
29 | m_name(0), | 29 | m_name(0), |
30 | m_namelen(0), | 30 | m_namelen(0), |
31 | m_anno(0), | 31 | m_anno(0), |
32 | m_annolen(0), | 32 | m_annolen(0), |
33 | m_position(0) | 33 | m_position(0) |
34 | { | 34 | { |
35 | init(rhs.name(), sizeof(tchar)*(ustrlen(rhs.name())+1), rhs.anno(), | 35 | init(rhs.name(), sizeof(tchar)*(ustrlen(rhs.name())+1), rhs.anno(), |
36 | sizeof(tchar)*(ustrlen(rhs.anno())+1), rhs.value()); | 36 | sizeof(tchar)*(ustrlen(rhs.anno())+1), rhs.value()); |
37 | } | 37 | } |
38 | 38 | ||
39 | Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p) | 39 | Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p) |
40 | { | 40 | { |
41 | if (_anno == NULL) | 41 | if (_anno == NULL) |
42 | { | 42 | { |
43 | tchar t = 0; | 43 | tchar t = 0; |
44 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p); | 44 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p); |
45 | } | 45 | } |
46 | else | 46 | else |
47 | { | 47 | { |
48 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p); | 48 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p, unsigned int _p2) : m_position(_p) | 52 | Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p, unsigned int _p2) : m_position(_p) |
53 | { | 53 | { |
54 | if (_anno == NULL) | 54 | if (_anno == NULL) |
55 | { | 55 | { |
56 | tchar t = 0; | 56 | tchar t = 0; |
57 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p); | 57 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p); |
58 | } | 58 | } |
59 | else | 59 | else |
60 | { | 60 | { |
61 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p); | 61 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p); |
62 | } | 62 | } |
63 | m_position2 = _p2; | 63 | m_position2 = _p2; |
64 | m_red = m_green = m_blue = 127; | 64 | m_red = m_green = m_blue = 127; |
65 | } | 65 | } |
66 | 66 | ||
67 | void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsigned short _annolen, unsigned int _p) | 67 | void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsigned short _annolen, unsigned int _p) |
68 | { | 68 | { |
69 | m_namelen = _nmlen; | 69 | m_namelen = _nmlen; |
70 | if (m_namelen > 0) | 70 | if (m_namelen > 0) |
71 | { | 71 | { |
72 | m_name = new unsigned char[m_namelen]; | 72 | m_name = new unsigned char[m_namelen]; |
73 | memcpy(m_name, _nm, m_namelen); | 73 | memcpy(m_name, _nm, m_namelen); |
74 | } | 74 | } |
75 | else | 75 | else |
76 | { | 76 | { |
77 | m_name = NULL; | 77 | m_name = NULL; |
78 | } | 78 | } |
79 | 79 | ||
80 | m_annolen = _annolen; | 80 | m_annolen = _annolen; |
81 | if (m_annolen > 0) | 81 | if (m_annolen > 0) |
82 | { | 82 | { |
83 | m_anno = new unsigned char[m_annolen]; | 83 | m_anno = new unsigned char[m_annolen]; |
84 | memcpy(m_anno, _anno, m_annolen); | 84 | memcpy(m_anno, _anno, m_annolen); |
85 | } | 85 | } |
86 | else | 86 | else |
87 | { | 87 | { |
88 | m_anno = NULL; | 88 | m_anno = NULL; |
89 | } | 89 | } |
90 | m_position = _p; | 90 | m_position = _p; |
91 | m_position2 = _p; | 91 | m_position2 = _p; |
92 | m_red = m_green = m_blue = 255; | 92 | m_red = m_green = m_blue = 255; |
93 | m_level = 0; | 93 | m_level = 0; |
94 | } | 94 | } |
95 | 95 | ||
96 | Bkmk::~Bkmk() | 96 | Bkmk::~Bkmk() |
97 | { | 97 | { |
98 | if (m_name != NULL) delete [] m_name; | 98 | if (m_name != NULL) delete [] m_name; |
99 | m_name = NULL; | 99 | m_name = NULL; |
100 | if (m_anno != NULL) delete [] m_anno; | 100 | if (m_anno != NULL) delete [] m_anno; |
101 | m_anno = NULL; | 101 | m_anno = NULL; |
102 | } | 102 | } |
103 | 103 | ||
104 | Bkmk& Bkmk::operator=(const Bkmk& rhs) | 104 | Bkmk& Bkmk::operator=(const Bkmk& rhs) |
105 | { | 105 | { |
106 | if (m_name != NULL) | 106 | if (m_name != NULL) |
107 | { | 107 | { |
108 | delete [] m_name; | 108 | delete [] m_name; |
109 | m_name = NULL; | 109 | m_name = NULL; |
110 | } | 110 | } |
111 | if (m_anno != NULL) | 111 | if (m_anno != NULL) |
112 | { | 112 | { |
113 | delete [] m_anno; | 113 | delete [] m_anno; |
114 | m_anno = NULL; | 114 | m_anno = NULL; |
115 | } | 115 | } |
116 | if (rhs.m_name != NULL) | 116 | if (rhs.m_name != NULL) |
117 | { | 117 | { |
118 | m_namelen = rhs.m_namelen; | 118 | m_namelen = rhs.m_namelen; |
119 | m_name = new unsigned char[m_namelen]; | 119 | m_name = new unsigned char[m_namelen]; |
120 | memcpy(m_name, rhs.m_name, m_namelen); | 120 | memcpy(m_name, rhs.m_name, m_namelen); |
121 | } | 121 | } |
122 | else | 122 | else |
123 | m_name = NULL; | 123 | m_name = NULL; |
124 | if (rhs.m_anno != NULL) | 124 | if (rhs.m_anno != NULL) |
125 | { | 125 | { |
126 | m_annolen = rhs.m_annolen; | 126 | m_annolen = rhs.m_annolen; |
127 | m_anno = new unsigned char[m_annolen]; | 127 | m_anno = new unsigned char[m_annolen]; |
128 | memcpy(m_anno, rhs.m_anno, m_annolen); | 128 | memcpy(m_anno, rhs.m_anno, m_annolen); |
129 | } | 129 | } |
130 | else | 130 | else |
131 | m_anno = NULL; | 131 | m_anno = NULL; |
132 | m_position = rhs.m_position; | 132 | m_position = rhs.m_position; |
133 | m_position2 = rhs.m_position2; | 133 | m_position2 = rhs.m_position2; |
134 | m_red = rhs.m_red; | 134 | m_red = rhs.m_red; |
135 | m_green = rhs.m_green; | 135 | m_green = rhs.m_green; |
136 | m_blue = rhs.m_blue; | 136 | m_blue = rhs.m_blue; |
137 | m_level = rhs.m_level; | 137 | m_level = rhs.m_level; |
138 | return *this; | 138 | return *this; |
139 | } | 139 | } |
140 | 140 | ||
141 | bool Bkmk::operator==(const Bkmk& rhs) | 141 | bool Bkmk::operator==(const Bkmk& rhs) |
142 | { | 142 | { |
143 | return ((m_position == rhs.m_position) && (m_position2 == rhs.m_position2) && (rhs.m_namelen == m_namelen) && memcmp(m_name,rhs.m_name,m_namelen) == 0); | 143 | return ((m_position == rhs.m_position) && (m_position2 == rhs.m_position2) && (rhs.m_namelen == m_namelen) && memcmp(m_name,rhs.m_name,m_namelen) == 0); |
144 | } | 144 | } |
145 | 145 | ||
146 | void Bkmk::setAnno(unsigned char* t, unsigned short len) | 146 | void Bkmk::setAnno(unsigned char* t, unsigned short len) |
147 | { | 147 | { |
148 | if (m_anno != NULL) | 148 | if (m_anno != NULL) |
149 | { | 149 | { |
150 | delete [] m_anno; | 150 | delete [] m_anno; |
151 | m_anno = NULL; | 151 | m_anno = NULL; |
152 | } | 152 | } |
153 | if (t != NULL) | 153 | if (t != NULL) |
154 | { | 154 | { |
155 | m_annolen = len; | 155 | m_annolen = len; |
156 | m_anno = new unsigned char[m_annolen]; | 156 | m_anno = new unsigned char[m_annolen]; |
157 | memcpy(m_anno, t, m_annolen); | 157 | memcpy(m_anno, t, m_annolen); |
158 | } | 158 | } |
159 | else | 159 | else |
160 | { | 160 | { |
161 | m_annolen = sizeof(tchar); | 161 | m_annolen = sizeof(tchar); |
162 | m_anno = new unsigned char[m_annolen]; | 162 | m_anno = new unsigned char[m_annolen]; |
163 | *((tchar*)m_anno) = 0; | 163 | *((tchar*)m_anno) = 0; |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | void Bkmk::setAnno(tchar* t) | 167 | void Bkmk::setAnno(tchar* t) |
168 | { | 168 | { |
169 | if (m_anno != NULL) | 169 | if (m_anno != NULL) |
170 | { | 170 | { |
171 | delete [] m_anno; | 171 | delete [] m_anno; |
172 | m_anno = NULL; | 172 | m_anno = NULL; |
173 | } | 173 | } |
174 | if (t != NULL) | 174 | if (t != NULL) |
175 | { | 175 | { |
176 | unsigned short len = ustrlen(t)+1; | 176 | unsigned short len = ustrlen(t)+1; |
177 | m_annolen = sizeof(tchar)*len; | 177 | m_annolen = sizeof(tchar)*len; |
178 | m_anno = new unsigned char[m_annolen]; | 178 | m_anno = new unsigned char[m_annolen]; |
179 | memcpy(m_anno, t, m_annolen); | 179 | memcpy(m_anno, t, m_annolen); |
180 | } | 180 | } |
181 | else | 181 | else |
182 | { | 182 | { |
183 | m_annolen = sizeof(tchar); | 183 | m_annolen = sizeof(tchar); |
184 | m_anno = new unsigned char[m_annolen]; | 184 | m_anno = new unsigned char[m_annolen]; |
185 | *((tchar*)m_anno) = 0; | 185 | *((tchar*)m_anno) = 0; |
186 | } | 186 | } |
187 | } | 187 | } |
188 | 188 | ||
189 | BkmkFile::BkmkFile(const char *fnm, bool w, bool _x) | 189 | BkmkFile::BkmkFile(const char *fnm, bool w, bool _x) |
190 | : | 190 | : |
191 | wt(w), isUpgraded(false), m_extras(_x) | 191 | wt(w), isUpgraded(false), m_extras(_x) |
192 | { | 192 | { |
193 | if (w) | 193 | if (w) |
194 | { | 194 | { |
195 | f = fopen(fnm, "wb"); | 195 | f = fopen(fnm, "wb"); |
196 | } | 196 | } |
197 | else | 197 | else |
198 | { | 198 | { |
199 | f = fopen(fnm, "rb"); | 199 | f = fopen(fnm, "rb"); |
200 | } | 200 | } |
201 | } | 201 | } |
202 | 202 | ||
203 | BkmkFile::~BkmkFile() | 203 | BkmkFile::~BkmkFile() |
204 | { | 204 | { |
205 | if (f != NULL) fclose(f); | 205 | if (f != NULL) fclose(f); |
206 | } | 206 | } |
207 | 207 | ||
208 | void BkmkFile::write(const Bkmk& b) | 208 | void BkmkFile::write(const Bkmk& b) |
209 | { | 209 | { |
210 | if (f != NULL) | 210 | if (f != NULL) |
211 | { | 211 | { |
212 | fwrite(&b.m_namelen, sizeof(b.m_namelen),1,f); | 212 | fwrite(&b.m_namelen, sizeof(b.m_namelen),1,f); |
213 | fwrite(b.m_name,1,b.m_namelen,f); | 213 | fwrite(b.m_name,1,b.m_namelen,f); |
214 | fwrite(&b.m_annolen, sizeof(b.m_annolen),1,f); | 214 | fwrite(&b.m_annolen, sizeof(b.m_annolen),1,f); |
215 | fwrite(b.m_anno,1,b.m_annolen,f); | 215 | fwrite(b.m_anno,1,b.m_annolen,f); |
216 | fwrite(&b.m_position,sizeof(b.m_position),1,f); | 216 | fwrite(&b.m_position,sizeof(b.m_position),1,f); |
217 | if (m_extras) | 217 | if (m_extras) |
218 | { | 218 | { |
219 | fwrite(&b.m_position2,sizeof(b.m_position2),1,f); | 219 | fwrite(&b.m_position2,sizeof(b.m_position2),1,f); |
220 | fwrite(&b.m_red,sizeof(b.m_red),1,f); | 220 | fwrite(&b.m_red,sizeof(b.m_red),1,f); |
221 | fwrite(&b.m_green,sizeof(b.m_green),1,f); | 221 | fwrite(&b.m_green,sizeof(b.m_green),1,f); |
222 | fwrite(&b.m_blue,sizeof(b.m_blue),1,f); | 222 | fwrite(&b.m_blue,sizeof(b.m_blue),1,f); |
223 | fwrite(&b.m_level,sizeof(b.m_level),1,f); | 223 | fwrite(&b.m_level,sizeof(b.m_level),1,f); |
224 | } | 224 | } |
225 | } | 225 | } |
226 | } | 226 | } |
227 | 227 | ||
228 | void BkmkFile::write(CList<Bkmk>& bl) | 228 | void BkmkFile::write(CList<Bkmk>& bl) |
229 | { | 229 | { |
230 | if (f != NULL) | 230 | if (f != NULL) |
231 | { | 231 | { |
232 | fwrite(&magic, sizeof(magic), 1, f); | 232 | fwrite(&magic, sizeof(magic), 1, f); |
233 | for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++) | 233 | for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++) |
234 | { | 234 | { |
235 | write(*i); | 235 | write(*i); |
236 | } | 236 | } |
237 | } | 237 | } |
238 | } | 238 | } |
239 | 239 | ||
240 | CList<Bkmk>* BkmkFile::readall() | 240 | CList<Bkmk>* BkmkFile::readall() |
241 | { | 241 | { |
242 | CList<Bkmk>* bl = NULL; | 242 | CList<Bkmk>* bl = NULL; |
243 | if (f != NULL) | 243 | if (f != NULL) |
244 | { | 244 | { |
245 | unsigned long newmagic; | 245 | unsigned long newmagic; |
246 | fread(&newmagic, sizeof(newmagic), 1, f); | 246 | fread(&newmagic, sizeof(newmagic), 1, f); |
247 | if ((newmagic & 0xffffff00) != (magic & 0xffffff00)) | 247 | if ((newmagic & 0xffffff00) != (magic & 0xffffff00)) |
248 | { | 248 | { |
249 | if (QMessageBox::warning(NULL, "Old bookmark file!", "Which version of " PROGNAME "\ndid you upgrade from?", "0_4*", "Any other version") == 0) | 249 | if (QMessageBox::warning(NULL, "Old bookmark file!", "Which version of " PROGNAME "\ndid you upgrade from?", "0_4*", "Any other version") == 0) |
250 | { | 250 | { |
251 | fseek(f,0,SEEK_SET); | 251 | fseek(f,0,SEEK_SET); |
252 | bl = readall00(&read05); | 252 | bl = readall00(&read05); |
253 | } | 253 | } |
254 | else | 254 | else |
255 | { | 255 | { |
256 | fseek(f,0,SEEK_SET); | 256 | fseek(f,0,SEEK_SET); |
257 | bl = readall00(&read03); | 257 | bl = readall00(&read03); |
258 | } | 258 | } |
259 | isUpgraded = true; | 259 | isUpgraded = true; |
260 | } | 260 | } |
261 | else | 261 | else |
262 | { | 262 | { |
263 | switch(newmagic & 0xff) | 263 | switch(newmagic & 0xff) |
264 | { | 264 | { |
265 | case 7: | 265 | case 7: |
266 | isUpgraded = false; | 266 | isUpgraded = false; |
267 | bl = readall00(read07); | 267 | bl = readall00(read07); |
268 | // qDebug("Correct version!"); | 268 | // qDebug("Correct version!"); |
269 | break; | 269 | break; |
270 | case 6: | 270 | case 6: |
271 | isUpgraded = true; | 271 | isUpgraded = true; |
272 | bl = readall00(read06); | 272 | bl = readall00(read06); |
273 | // qDebug("Correct version!"); | 273 | // qDebug("Correct version!"); |
274 | break; | 274 | break; |
275 | case 5: | 275 | case 5: |
276 | isUpgraded = true; | 276 | isUpgraded = true; |
277 | bl = readall00(read05); | 277 | bl = readall00(read05); |
278 | // qDebug("Known version!"); | 278 | // qDebug("Known version!"); |
279 | break; | 279 | break; |
280 | default: | 280 | default: |
281 | // qDebug("Unknown version!"); | 281 | // qDebug("Unknown version!"); |
282 | isUpgraded = true; | 282 | isUpgraded = true; |
283 | bl = readall00(read05); | 283 | bl = readall00(read05); |
284 | } | 284 | } |
285 | } | 285 | } |
286 | } | 286 | } |
287 | return bl; | 287 | return bl; |
288 | } | 288 | } |
289 | 289 | ||
290 | CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(BkmkFile*, FILE*)) | 290 | CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(BkmkFile*, FILE*)) |
291 | { | 291 | { |
292 | CList<Bkmk>* bl = new CList<Bkmk>; | 292 | CList<Bkmk>* bl = new CList<Bkmk>; |
293 | while (1) | 293 | while (1) |
294 | { | 294 | { |
295 | Bkmk* b = (*readfn)(this, f); | 295 | Bkmk* b = (*readfn)(this, f); |
296 | if (b == NULL) break; | 296 | if (b == NULL) break; |
297 | bl->push_back(*b); | 297 | bl->push_back(*b); |
298 | delete b; | 298 | delete b; |
299 | } | 299 | } |
300 | return bl; | 300 | return bl; |
301 | } | 301 | } |
302 | 302 | ||
303 | Bkmk* BkmkFile::read03(BkmkFile* /*_this*/, FILE* f) | 303 | Bkmk* BkmkFile::read03(BkmkFile* /*_this*/, FILE* f) |
304 | { | 304 | { |
305 | Bkmk* b = NULL; | 305 | Bkmk* b = NULL; |
306 | if (f != NULL) | 306 | if (f != NULL) |
307 | { | 307 | { |
308 | unsigned short ln; | 308 | unsigned short ln; |
309 | if (fread(&ln,sizeof(ln),1,f) == 1) | 309 | if (fread(&ln,sizeof(ln),1,f) == 1) |
310 | { | 310 | { |
311 | tchar* name = new tchar[ln+1]; | 311 | tchar* name = new tchar[ln+1]; |
312 | fread(name,sizeof(tchar),ln,f); | 312 | fread(name,sizeof(tchar),ln,f); |
313 | name[ln] = 0; | 313 | name[ln] = 0; |
314 | 314 | ||
315 | ln = 0; | 315 | ln = 0; |
316 | tchar* anno = new tchar[ln+1]; | 316 | tchar* anno = new tchar[ln+1]; |
317 | anno[ln] = 0; | 317 | anno[ln] = 0; |
318 | 318 | ||
319 | unsigned int pos; | 319 | unsigned int pos; |
320 | fread(&pos,sizeof(pos),1,f); | 320 | fread(&pos,sizeof(pos),1,f); |
321 | b = new Bkmk(name,anno,pos); | 321 | b = new Bkmk(name,anno,pos); |
322 | delete [] anno; | ||
322 | } | 323 | } |
323 | } | 324 | } |
324 | return b; | 325 | return b; |
325 | } | 326 | } |
326 | 327 | ||
327 | Bkmk* BkmkFile::read05(BkmkFile* /*_this*/, FILE* f) | 328 | Bkmk* BkmkFile::read05(BkmkFile* /*_this*/, FILE* f) |
328 | { | 329 | { |
329 | Bkmk* b = NULL; | 330 | Bkmk* b = NULL; |
330 | if (f != NULL) | 331 | if (f != NULL) |
331 | { | 332 | { |
332 | unsigned short ln; | 333 | unsigned short ln; |
333 | if (fread(&ln,sizeof(ln),1,f) == 1) | 334 | if (fread(&ln,sizeof(ln),1,f) == 1) |
334 | { | 335 | { |
335 | tchar* nm = new tchar[ln+1]; | 336 | tchar* nm = new tchar[ln+1]; |
336 | fread(nm,sizeof(tchar),ln,f); | 337 | fread(nm,sizeof(tchar),ln,f); |
337 | nm[ln] = 0; | 338 | nm[ln] = 0; |
338 | fread(&ln,sizeof(ln),1,f); | 339 | fread(&ln,sizeof(ln),1,f); |
339 | tchar* anno = new tchar[ln+1]; | 340 | tchar* anno = new tchar[ln+1]; |
340 | if (ln > 0) fread(anno,sizeof(tchar),ln,f); | 341 | if (ln > 0) fread(anno,sizeof(tchar),ln,f); |
341 | anno[ln] = 0; | 342 | anno[ln] = 0; |
342 | unsigned int pos; | 343 | unsigned int pos; |
343 | fread(&pos,sizeof(pos),1,f); | 344 | fread(&pos,sizeof(pos),1,f); |
344 | b = new Bkmk(nm,anno,pos); | 345 | b = new Bkmk(nm,anno,pos); |
345 | } | 346 | } |
346 | } | 347 | } |
347 | return b; | 348 | return b; |
348 | } | 349 | } |
349 | 350 | ||
350 | Bkmk* BkmkFile::read06(BkmkFile* /*_this*/, FILE* f) | 351 | Bkmk* BkmkFile::read06(BkmkFile* /*_this*/, FILE* f) |
351 | { | 352 | { |
352 | Bkmk* b = NULL; | 353 | Bkmk* b = NULL; |
353 | if (f != NULL) | 354 | if (f != NULL) |
354 | { | 355 | { |
355 | unsigned short ln; | 356 | unsigned short ln; |
356 | if (fread(&ln,sizeof(ln),1,f) == 1) | 357 | if (fread(&ln,sizeof(ln),1,f) == 1) |
357 | { | 358 | { |
358 | b = new Bkmk; | 359 | b = new Bkmk; |
359 | b->m_namelen = ln; | 360 | b->m_namelen = ln; |
360 | b->m_name = new unsigned char[b->m_namelen]; | 361 | b->m_name = new unsigned char[b->m_namelen]; |
361 | fread(b->m_name,1,b->m_namelen,f); | 362 | fread(b->m_name,1,b->m_namelen,f); |
362 | 363 | ||
363 | fread(&(b->m_annolen),sizeof(b->m_annolen),1,f); | 364 | fread(&(b->m_annolen),sizeof(b->m_annolen),1,f); |
364 | if (b->m_annolen > 0) | 365 | if (b->m_annolen > 0) |
365 | { | 366 | { |
366 | b->m_anno = new unsigned char[b->m_annolen]; | 367 | b->m_anno = new unsigned char[b->m_annolen]; |
367 | fread(b->m_anno,1,b->m_annolen,f); | 368 | fread(b->m_anno,1,b->m_annolen,f); |
368 | } | 369 | } |
369 | fread(&(b->m_position),sizeof(b->m_position),1,f); | 370 | fread(&(b->m_position),sizeof(b->m_position),1,f); |
370 | b->m_position2 = b->m_position+b->m_namelen-1; | 371 | b->m_position2 = b->m_position+b->m_namelen-1; |
371 | b->m_red = b->m_green = b->m_blue = 127; | 372 | b->m_red = b->m_green = b->m_blue = 127; |
372 | b->m_level = 0; | 373 | b->m_level = 0; |
373 | } | 374 | } |
374 | } | 375 | } |
375 | return b; | 376 | return b; |
376 | } | 377 | } |
377 | 378 | ||
378 | Bkmk* BkmkFile::read07(BkmkFile* _this, FILE* f) | 379 | Bkmk* BkmkFile::read07(BkmkFile* _this, FILE* f) |
379 | { | 380 | { |
380 | Bkmk* b = NULL; | 381 | Bkmk* b = NULL; |
381 | if (f != NULL) | 382 | if (f != NULL) |
382 | { | 383 | { |
383 | unsigned short ln; | 384 | unsigned short ln; |
384 | if (fread(&ln,sizeof(ln),1,f) == 1) | 385 | if (fread(&ln,sizeof(ln),1,f) == 1) |
385 | { | 386 | { |
386 | b = new Bkmk; | 387 | b = new Bkmk; |
387 | b->m_namelen = ln; | 388 | b->m_namelen = ln; |
388 | b->m_name = new unsigned char[b->m_namelen]; | 389 | b->m_name = new unsigned char[b->m_namelen]; |
389 | fread(b->m_name,1,b->m_namelen,f); | 390 | fread(b->m_name,1,b->m_namelen,f); |
390 | 391 | ||
391 | fread(&(b->m_annolen),sizeof(b->m_annolen),1,f); | 392 | fread(&(b->m_annolen),sizeof(b->m_annolen),1,f); |
392 | if (b->m_annolen > 0) | 393 | if (b->m_annolen > 0) |
393 | { | 394 | { |
394 | b->m_anno = new unsigned char[b->m_annolen]; | 395 | b->m_anno = new unsigned char[b->m_annolen]; |
395 | fread(b->m_anno,1,b->m_annolen,f); | 396 | fread(b->m_anno,1,b->m_annolen,f); |
396 | } | 397 | } |
397 | fread(&(b->m_position),sizeof(b->m_position),1,f); | 398 | fread(&(b->m_position),sizeof(b->m_position),1,f); |
398 | if (_this->m_extras) | 399 | if (_this->m_extras) |
399 | { | 400 | { |
400 | fread(&(b->m_position2),sizeof(b->m_position2),1,f); | 401 | fread(&(b->m_position2),sizeof(b->m_position2),1,f); |
401 | fread(&(b->m_red),sizeof(b->m_red),1,f); | 402 | fread(&(b->m_red),sizeof(b->m_red),1,f); |
402 | fread(&(b->m_green),sizeof(b->m_green),1,f); | 403 | fread(&(b->m_green),sizeof(b->m_green),1,f); |
403 | fread(&(b->m_blue),sizeof(b->m_blue),1,f); | 404 | fread(&(b->m_blue),sizeof(b->m_blue),1,f); |
404 | fread(&(b->m_level),sizeof(b->m_level),1,f); | 405 | fread(&(b->m_level),sizeof(b->m_level),1,f); |
405 | } | 406 | } |
406 | else | 407 | else |
407 | { | 408 | { |
408 | b->m_position2 = b->m_position; | 409 | b->m_position2 = b->m_position; |
409 | b->m_red = b->m_green = b->m_blue = 255; | 410 | b->m_red = b->m_green = b->m_blue = 255; |
410 | b->m_level = 0; | 411 | b->m_level = 0; |
411 | } | 412 | } |
412 | } | 413 | } |
413 | } | 414 | } |
414 | return b; | 415 | return b; |
415 | } | 416 | } |