-
Notifications
You must be signed in to change notification settings - Fork 7
/
HACKING
299 lines (205 loc) · 8.79 KB
/
HACKING
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
$Id$
Vidalia Coding and Repository Specification
0. Introduction
This document is intended to loosely specify coding conventions followed in
Vidalia code, as well as conventions used in Vidalia's Subversion
repository.
1. Repository Organization
1.1. Subversion Location
Vidalia's repository supports anonymous checkout. You can grab the most
recent revision of Vidalia's source code via:
svn co https://svn.vidalia-project.net/svn/vidalia/trunk/ vidalia
1.2 Directory Layout
The following are the current directories found in Vidalia's SVN repository
and a general decription of their intended contents:
From https://svn.vidalia-project.net/svn/vidalia:
./tags:
Snapshots of all Vidalia releases will be contained in a sub-directory
of ./tags, named according to the Vidalia version specification.
For example, ./tags/vidalia-0.0.1/ would contain the 0.0.1 release of
Vidalia.
./trunk:
Contains the main branch of Vidalia's source code.
./trunk/doc:
Contains Vidalia's documentation, such as specifications and todo
lists.
./trunk/src:
All Vidalia source code will be contained under this directory.
./trunk/src/torcontrol:
Code in this directory implements Tor's control protocol. It also
handles things such as starting and stopping Tor and checking the
status of the Tor process.
./trunk/src/vidalia:
This directory contains code that implements the GUI components of
Vidalia. Whenever possible and sane, each component should be placed in
an appropriately-named subdirectory of ./trunk/src/vidalia.
./trunk/src/vidalia/res:
All GUI-related resource files, such as images, should go in this
directory. Images should be placed in sub-directories appropriate for
their image size. For example, 16x16 images would go in
./trunk/src/vidalia/res/16x16/
./trunk/src/common:
If a source file doesn't belong in the previous directories, it should
go here. This directory will containg various utility functions, such
as date or time parsing, custom string manipulation functions, etc. If
a particular utility has multiple source files, they should all be
placed in a subdirectory. For example, if there were several source
files that implemented various string manipulation functions, they
could go in ./trunk/src/common/string.
2. Coding Conventions
This section aims to provide a small overview of coding conventions used in
Vidalia, to keep the look of the code consistent between developers and
contributors. Since it would be impossible to specify all aspects of coding
here, common sense should be employed for things not specified below.
2.1. Naming Conventions
2.1.1. Source File Names
C++ classes should be divided in to a <ClassName>.h file, containing the
class declarations, and a <ClassName>.cpp file containg the class
implementation. Each .cpp file should implement only one public class.
Filenames containing a class should follow the same "CamelCase"
capitalization format as the class name itself.
Source files that do not implement a C++ class should be named logically and
in all lowercase letters. For example, threading-related code would go in
thread.cpp and thread.h.
2.1.2. Class Names
Class names should begin with a capital letter. If a name is a combination
of distinct words, each word should be capitalized. The purpose of the class
should be explained in Doxygen tags. Example:
/** A brief description of MyClass. */
/**
* Alternatively, here is a more detailed description of MyClass.
*/
class MyClass
{
};
Doxygen-style comments should be used above each method declaration in
the class.
2.1.3. Method Names
Method names should begin with a lower case letter. If a method name is a
combination of distinct words, each word should be capitalized. Methods
should have descriptions of their purpose. Example:
/* Description of what someMethod does. */
int
MyClass::someMethod(int foo)
{
}
Doxygen tags should be used for comments above the method definition
ONLY if the method's declaration in the class header file does not
already have a Doxygen-style comments.
Note that the method's return type is declared on a line by itself. Private
member function should NOT have an underscore prepended to their name.
2.1.4. Variable Names
Variable names should follow a convention similar to method names. Variable
names should be descriptive if their purpose is non-obvious.
Variables that are members of a class should have a leading underscore to
distinguish them from local variables in a method. Member variables should
also have a description of their purpose in Doxygen tags. For example:
/** A brief description of MyClass */
/**
* A more detailed description of MyClass.
*/
class MyClass
{
private:
int _myVariable; /**< Description of what _myVariable is */
};
2.1.5. Ordering of Method and Member Variable Declarations
Class member method and variable declarations should be arranged according
to decreasing order of visibility.
class MyClass : public QObject
{
Q_OBJECT
public:
/* Public enums */
/* Public methods */
public slots:
/* Public slots */
signals:
/* Signals emitted by this class */
protected:
/* Protected methods */
/* Protected member variables */
protected slots:
/* Protected slots */
private:
/* Private methods */
/* Private member variables */
private slots:
/* Private slots */
};
2.1.6. Widget Names
Every widget declared in a Qt Designer .ui file must have a short three or
four letter prefix that describes the widget's type.
Widget Type Prefix Example
------------------------------------------------------------
QCheckBox chk chkEnableFoo
QComboBox cmbo cmboNames
QDialogButtonBox - buttonBox
QFrame frm frmMain
QGroupBox grp grpAdvanced
QLabel lbl lblHeader
QLineEdit line lineAddress
QListView lst lstMessages
QProgressBar pbar pbarDownload
- progressBar
QPushButton btn btnClose
QRadioButton rdo rdoSomeOption
QSpinBox spn spnDial
QTableView tbl tblSpreadsheet
QTabWidget tab tabServerOptions
QToolButton btn btnExit
QTreeView tree treeFolders
2.2. Comments
Comments should be standard C style comments. For example:
int fooCounter; /* Comment about counting foo */
Multi-line comments should be formatted as:
/*
* This section of code is potentially confusing or ambiguous, so here is a
* long comment that takes up multiple lines.
*/
2.3. Indentation
All source code should follow these conventions:
1. Tabs should be 2 characters wide.
2. Your editor should be set to replace tabs with spaces.
3. Lines should be less than 80 characters wide whenever possible.
2.4. Bracing
2.4.1. Methods
Opening and closing braces for functions should be placed at column 1. For
example:
void
Foo::bar(void)
{
}
2.4.2. Loops
Braces for loops should be formatted as follows:
for (i = 0; i < 10; i++) {
/* Do something ten times */
}
2.4.3. if-else Statements
The `else' portion of an if-else statement, if present, should begin on the
same line as the closing brace of the `if' portion.
if (foo == bar) {
/* Do something */
} else {
/* My foo doesn't equal bar */
}
Braces may be omitted if there is only one line of code to be executed if
the evaluated condition is true. For example, the following is permitted:
if (foo == bar)
return;
2.5. Parentheses
There should NOT be a space between an opening parenthesis and the
first argument, nor between the end of the last argument and a closing
parenthesis.
int value = someObject.someMethod(foo, bar, baz);
2.6. Method Arguments
const-correctness should be enforced whenever possible. Objects passed as
arguments to a method should be passed by a const reference, as in the
following example:
void
SomeClass::someMethod(const OtherClass &oc)
{
/* Do something with oc */
}
2.7. Other
Source files should end with a single blank line.