Kde-guidelines.md (4466B)
1 # Coding Style 2 3 - Indentation using 3 spaces 4 - 0 Indentation for preprocessor 5 - Class declaration intentation = 0 space for 6 public/private/protected/Q\_SIGNALS, 3 space for the methods, 7 friends and attributes 8 - Every function/method need a oneliner doxygen description using 9 "///" 10 - Function need to be ordered by 1) usage (history, contact, slots) 2) 11 alphabetical order 12 - Lines related to each other (like many setter on the same object 13 need to be aligned down to the ";" 14 - Oneliner if-elseif/switch/connect/tables need to have an header 15 using /\* HEADER \*/ where \*/ close of the end of the table, also 16 align the lines 17 - Header file function need to be classified and aligned 18 - License header is necessary for all source files 19 - Attribute are named with prefix "m\_", then "s" for static, then "p" 20 for pointer, "l" for list, "h" for hash, "f" for function/lambdas 21 then the first letter is uppercase 22 - Includes are located in the .cpp and only "class" and "namespace" 23 are declared in the .h (where applicable) 24 - Includes are sorted by libraries (Qt -> QtCore/QtGui/QtDbus, KDE 25 -> Akonadi/KABC, Dring) 26 - Setters take const references as parameter 27 - Destructor are always virtual 28 - C++11 is allowed 29 - Every class need a oneliner "///@class <Classname> <description>" 30 description 31 - Use QDebug 32 - Align everything as much as possible 33 - one line "if" block and "()?:;" are allowed and recommended 34 - Minimize the number of lines, but add as many white lines are 35 necessary 36 - Header ifnedef need to be the class upper name with upper replaced 37 with \_ and \_H as suffix 38 - functions/methods need to end with } //function name (more than 10 39 lines only) 40 - "using" (namespace keyword) usage is prohibited 41 - Every \#endif need to make explicit what it is closing "\#endif 42 MY\_CLASS\_H" 43 - Code block have the "{" at the end of line while mothods use "\\n{" 44 - Use enum class where possible 45 - Always use the Full::Path for enums 46 - Expose library objects as "real" qobjects (with Q\_PROPERTY, 47 Q\_ENUM, Q\_FLAGS, Q\_INTERFACE and Q\_DECLARE\_NAME) 48 - Follow Qt getter/setter naming conventions 49 - Follow Krazy2 advices 50 - string should be stored in a static struct or class as "constexpr 51 static const char\*". C++14 will add 52 - daemon constants should always be stored in the .h in pure static 53 structs (with embedded structs to emulate namespace) 54 - avoid keeping maps and list around when they represent an object. 55 - transform string into enum class literal or object as soon as 56 possible in the code 57 - use const and static variables in methods where applicable 58 - Classes should not expose multiple mutually exclusive boolean 59 properties and use enum classes instead. (Example: isAudioOnly() 60 and hasVideo()) 61 - Friendship ("friend" keyword) is accepted between the model and 62 their data object to avoid exposing factory interfaces 63 - Private classes declaration need to be at the top of the CPP file 64 - Always an empty line before and after if/else, for, while, do, 65 lambda 66 67 # Necessary Constraints 68 69 - D-Pointer (public class pointer to private structure) need to be 70 called d\_ptr <http://qt-project.org/wiki/Dpointer> 71 - Q-Pointer (not to be confused with QPointer) need to be called 72 q\_ptr <http://qt-project.org/wiki/Dpointer> 73 - If a private header is necessary, then add it to the private folder 74 with a classname\_p.h name. Do not install those, never \#include 75 them in other .h, only .cpp 76 77 # Design Guideline 78 79 - No hack 80 - No logic that belong to the daemon 81 - Use the state machine, don't add useless functions 82 - Coherent code is not a very high priority, but avoid making things 83 worst 84 - Avoid using dbus call outside of the library, if you have to, your 85 doing it wrong 86 87 # Current Design 88 89 ``` 90 =========================QML plasmoid====== <- Abstact frontend using the dataengine model 91 =====KDE frontend=========Dateengine======= <- Library frontend 92 ==============KDE library================== <- Common GUI code and contact implementation 93 =============libringclient================= <- Dbus to C++ object + state machine + frontend model, -GUI LESS- 94 ==================DBUS===================== 95 ==================DRing==================== 96 ==================PJSIP==================== 97 ===================UDP===================== 98 =================SERVER==================== 99 ```