File: HACKING

package info (click to toggle)
digikam 2%3A0.9.4-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 51,608 kB
  • ctags: 23,024
  • sloc: cpp: 153,444; ansic: 89,986; sh: 9,942; perl: 3,122; makefile: 1,798
file content (287 lines) | stat: -rw-r--r-- 10,248 bytes parent folder | download
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
This file's purpose is to guide contributors and developers to help on the
digiKam project.

========================================================================
10 golden rules for starting with open source
========================================================================

Before to contribute to digiKam project, please take a look to this link:

http://schlitt.info/applications/blog/index.php?/archives/541-10-golden-rules-for-starting-with-open-source.html

========================================================================
Source code formatting:
========================================================================

Adhere to this style guide strictly while adding new code to digiKam or 
working on existing code. 

-------------------------------------------------------------------------
* Indentation length
-------------------------------------------------------------------------

Indent with 4 spaces exactly.

for eg:

void function()
{
....int a;                    // 4 spaces from beginning
....for (int i=0; i<10; i++)  // 4 spaces from beginning
....{                         // 4 spaces from beginning
........a = i;                // 4 spaces from previous indent block

Emacs by default will indent to 4 spaces
vim users add this to you .vimrc
 set tabstop=4        

-------------------------------------------------------------------------
* Tabs vs Spaces
-------------------------------------------------------------------------

Absolutely no tabs. Use a sensible editor which will convert tabs to spaces. 
This will reduce unnecessary changes in your cvs commits.

Emacs by default will convert tab to spaces.
For vim users, add this to your .vimrc
  set expandtab

-------------------------------------------------------------------------
* Line length
-------------------------------------------------------------------------

Line length should never exceed 80 chars (unless really necessary - these 
cases are rare). Having long lines greatly reduces readability of code

-------------------------------------------------------------------------
* Bracketing
-------------------------------------------------------------------------

In almost all cases, {} brackets should start on a newline and should be 
aligned with previous line (follow the indentation spaces). for eg.

class A 
{ //new line
...

for (int i=0; i<10; i++)
{ //new line

if (a == foobar)
{ //new line
... 
}
else
{ // new line
..
} 

-------------------------------------------------------------------------
* Positioning of Access modifiers
-------------------------------------------------------------------------

public, private, protected, public slots, ... should be aligned to the 
beginning of the line with no margin

class A
{
public: // aligned to left 
...
private slots: // aligned to left 


Follow a consistent order in defining these attributes. The recommended
order is public, protected (functions), private (functions), 
signals, public slots, protected slots, private slots, private (variables)

========================================================================
Class, file and Variable names:
========================================================================

-------------------------------------------------------------------------
* Class and filenames
-------------------------------------------------------------------------

- filenames should always be in lower-case 
- class names should match the filenames. Capitalize the first letter and
  other letters logically to improve readability

-------------------------------------------------------------------------
* Protected Member variables
-------------------------------------------------------------------------

- protected member variable names should always be of the form m_varName. 
- Captilize logically so that it becomes easy to read it. Do not capitalize
  the first letter after _ (Use m_varName not m_VarName)
- variable names should be indicative of their functionality and also of 
  the type they belong too if they are instances of qt widgets.
  for eg, QCheckBox* m_autoRotateCheckBox;

-------------------------------------------------------------------------
* Non-Member variables
-------------------------------------------------------------------------

- non-member variables should follow the same naming convention as the member 
  variables, except for the leading m_

-------------------------------------------------------------------------
* Private Member variables
-------------------------------------------------------------------------

- private member variables must be stored in a d private container to reduce
  compilation time and improve binary compatibilty between digiKam components.
  See more informations how to use a 'd' private class at this url: 

  http://developer.kde.org/policies/librarypolicy.html

========================================================================
Comments and Whitespace
========================================================================

Use whitespaces liberally to improve readability. Add blank lines between logical
sections of the code.

Comment as much as possible. Position comments at the beginning of the
section/line you want to comment, NEVER at the end of the line

// put your comments here
a = (b == foobar) ? 1 : -1; 

a = (b == foobar) ? 1 : -1; // you are asking for trouble by putting comments here


========================================================================
Header files
========================================================================

- Add copyright to top of every file. Use the same header than others digiKam
  source code.
- Double inclusion protection defines are all upper case letters and are 
  composed of the classname and a H suffix separated by underscore

#ifndef ANOTHERNICECLASS_H
#define ANOTHERNICECLASS_H

class AnotherNiceClass
{
...
}

#endif

- Use forward declarations as much as possible.

class QFileInfo;

class A
{
....QFileInfo* m_fileInfo;

========================================================================
General recommendations
========================================================================

Please take a look into KDE contrib page tips before to write code/patches for 
digiKam project : http://techbase.kde.org/Contribute

Use the same .cpp/.h header than the rest of digiKam project.

Use a decent editor which does auto-indentation/syntax-highlighting for you. 
I personally use Emacs (Renchi) or Kdevelop (Gilles).
There are excellent initializer scripts in the kdesdk
package for xemacs and vim which can substantially increase your productivity.

Just to give a taste of what i can do with emacs (and kdesdk):

* automatically insert copyright (and ifdefs) in new files.
* insertion of class function definitions for declared class 
  functions in header with one keystroke
* switch between header and declaration files with one keystroke
* go to corresponding definition/declaration with one keystroke
* tab completion of variable/function names already declared.

========================================================================
GDB Backtrace 
========================================================================

If you found a context to crash digiKam, you can provide a backtrace using GDB debugger.
digiKam need to be compiled with all debug info else the backtrace will not suitable.
There is a configure option for that:

# make -f Makefile.cvs
# ./configure --enable-debug=full
# make
# su
# make install.

To make a backtrace with GDB use following command:

# gdb digikam
> run
> ...
> _crash here_
> ...
> bt
> _the backtrace is here_
> quit

Post this backtrace at the right place (B.K.O or devel ML) for investigations by developers.

========================================================================
Memory leak 
========================================================================

To check any memory leak problem in digiKam, valgrind is your friend (http://valgrind.org)
Try this command line to use with valgrind :

valgrind --tool=memcheck --leak-check=full --error-limit=no digikam

========================================================================
Profiling with cachegrind
========================================================================

Valgrind also includes a tool to find out in which parts of your code time is spent.

valgrind --tool=callgrind digikam

Profiling can be disabled at startup to limit the output to the code you are interested in.
Start with

valgrind --tool=callgrind --instr-atstart=no digikam

and prepare the situation you want to profile. Then, in another console, start profiling with
"callgrind_control -i on" and, after the situation has passed, request a profile dump with
"callgrind_control -d".
The resulting callgrind.out files need to be viewed with the kcachegrind program, e.g.:

kcachegrind callgrind.out.16693.1

=================================================================================
API Documentation Validation, User Documentation Validation, Source Code Checking
=================================================================================

The following site check on a dayly basis for the a.m. errors:
www.englishbreakfastnetwork.org/krazy/

It can be very useful, in particular before major releases.
Don't trust it blindly! Sometimes they propose too advanced modifications that are no compatible with the prevailant include files.

========================================================================
Usability issues
========================================================================

OpenUsability project has define default menu structure and keyboard shortcuts:

http://wiki.openusability.org/guidelines/index.php/Appendices:Keyboard_Shortcuts

========================================================================
Generate API documentation
========================================================================

To generate API documentation, you need to install:

- Doxygen program (http://www.doxygen.org).
- Dot program (http://www.graphviz.org)

Go to 'project' sub-folder and just run doxygen binary program. A new subfolder 
named 'api' will be create. Warning, this can take a while.