# Getting started on hacking Planner

## Getting started

The first thing to do if you want to help out hacking on Planner is to join the Planner-devel mailing list. List information can be found at: http://lists.codefactory.se/mailman/listinfo/planner-devel .

Then read through this document to learn how we work and the coding style rules that should be used in Planner code. Finally, please join us for discussions in #planner at Gimpnet (irc.gnome.org).

### Requirements

#### libplanner

#### libplanner dependencies

Package | Version
glib | >=2.0.4
libxml2 | >=2.4.7

#### planner

#### planner dependencies

Package | Version
libplanner | *
gtk+ | >= 2.0.3
libgnomecanvas | >= 2.0.1

### Getting the source

When developing on Planner we strongly recommend using the source from CVS. If you have a CVS account at cvs.gnome.org you get the source code by:

    # export CVSROOT=":pserver:yourlogin@cvs.gnome.org:/cvs/gnome"
    # cvs co libplanner
    # cvs co planner

Otherwise you can download it from our anonymous cvs with the following commands.

    # export CVSROOT=":pserver:anonymous@anoncvs.gnome.org:/cvs/gnome"
    # cvs login

    (No password, just press enter.)

    # cvs -z3 co libplanner
    # cvs -z3 co planner

### Building the source

To build Planner you need to first build libplanner. Just execute the following commands.

    # cd libplanner
    # ./autogen.sh --prefix=/prefix
    # make
    # make install

Then you can build Planner by the following set of commands.

    # cd planner
    # ./autogen.sh --prefix=/prefix
    # make
    # make install

### Creating patches

The easiest way to create patches is by using CVS. Before you make the patch, make sure that you have the latest changes from the CVS by executing:

    # cvs up -Pd

Then you can create the patch with:

    # cvs diff -u > file.patch

Make sure you use the -u flag, that makes the patch easier to read.

### Submitting your patches

Submitting patches can either be done by sending them to the planner-devel mailing list. Or by adding them as merge requests to the issue the patch solves at: https://gitlab.gnome.org/World/planner/ .

## Programming Guidelines

This chapter discuss the coding guide lines that should be used in all Planner code. Please notice that if your code doesn't follow these guide lines it won't be included in Planner, therefor please make sure that it does before sending the patches.

### Naming conventions

The naming schemes is a little different between libplanner and planner, this is to make it clear by looking at a function name to see where it belongs. The reason for a naming scheme is that it should be easy to find the definition and implementation of a function/enum/class/... by just looking at the name of it.

#### Class Names

- Classes should be named with a prefix Mrp for classes in libplanner and Planner for classes in planner.

- Use upper case letters as word separators, lower case for the rest of the word.

- No underscores ("_") in the names.

##### Class Names

     class MrpTaskManager
     class PlannerResourceModel

#### File Names

File names should be named as follows:

- No upper case letters.

- Use a hyphen ("-") to separate words.

- Prefix filenames with mrp- for files in libplanner and planner- for files in planner.

##### Filenames

     mrp-task-manager.c
     mrp-task-manager.h
     planner-resource-model.c
     planner-resource-model.h

#### External Functions Names

External functions should be named as the file names with every hyphen ("-") replaced by an underscore ("_").

##### External function names

     mrp_task_manager_get_root (...)
     planner_resource_model_get_type_string (...)

#### Static Functions Names

This use the same scheme as external functions names but remove the prefix. So for example:

##### Static Functions Names

An external function

     mrp_resource_get_name (...)

would become

     resource_get_name (...)

if it was a static function withing mrp-resource.c.

Notice that this scheme is currently not used in Planner but we'll change to it whenever we are editing those files, please use this scheme for all new code.

#### Enum/Struct Names

Enum and structs follow the same naming convention as the classes.

##### Enum/Struct names

in mrp-resource.h

     typedef enum {
       	MRP_RESOURCE_TYPE_NONE,
    	MRP_RESOURCE_TYPE_WORK,
    	MRP_RESOURCE_TYPE_MATERIAL
     } MrpResourceType;

Same goes for structures.

#### #define and Macro Names

#defines and macros should be named in the same way as functions but with uppercase letters instead of lowercase.

##### #define and macro names

In mrp-resource.h

     #define MRP_TYPE_RESOURCE         (mrp_resource_get_type ())

In planner-resource-model.h

    #define PLANNER_IS_RESOURCE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
                                       PLANNER_TYPE_RESOURCE_MODEL))

### Code Formatting

In order to make the code more readable we here define a number of formatting rules that has to be followed. If everyone hacking on Planner uses the same code formatting it will be much easier to read other persons code.

#### Indentation

Indentation should be done using tabs and one tab is eight spaces wide.

##### Indentation

    static void
    mrp_resource_new (void)
    {
            MrpResource *resource;

            resource = g_object_new (MRP_TYPE_RESOURCE, NULL);

            return resource;
    }

This is the same style used by the Linux kernel and by the GNOME project.

#### Braces policy

- All if-, while-, do-, for-statements should use braces, even one-liners. This is because it's obvious where the statement starts/ends, it's also good when you want to put another line in the same statement and you don't have to make sure that you put the braces there.

  ##### Braces used for statements

      if (i >= 0) {
              /* do something */
      }

- For these types of statements, the open brace should be placed on the same line as the statement with a single space between the statement and the opening brace.

  ##### One line statements

      for (i = 0; i < len; ++i) {
              /* my one-liner */
      }

- For functions the opening brace should be placed below the function

  ##### Braces around function statements

      void static
      my_function (void)
      {
              /* do something */
      }

- If-elseif-else-statements should use the following formatting.

  ##### If-elseif-else statement

      if (...) {
              /* do something */
      }
      else if (...) {
              /* do something else */
      } else {
              /* do yet another thing */
      }

#### Parenthesis policy

#### Function declarations and implementation

A few guidelines on how to write functions.

- In declaration, always put one argument per row and align the functions, types and arguments for easy reading.

  ##### Function declarations

      void      mrp_resource_assign             (MrpResource     *resource,
      		                           MrpTask         *task,
      					   gint             units);

      GList *   mrp_resource_get_assignments    (MrpResource     *resource);

- When implementing the function, try to fit all arguments on one row, if that doesn't fit in 80 chars width, split them up with one argument per row. Put a single space between the longest type and the arguments.

  ##### Function implementation

      void
      mrp_resource_assign (MrpResource *resource, MrpTask *task, gint units)
      {
              /* ... */
      }

      gboolean
      mrp_project_save_as (MrpProject   *project,
                           const gchar  *uri,
                           gboolean      force,
                           GError      **error)
      {
              /* ... */
      }

- If you have pointer arguments with * or ** they should be placed together with the argument, not with the type. Also they should be aligned as

  ##### Align pointer arguments

      gboolean
      mrp_project_save_as (MrpProject   *project,
                           const gchar  *uri,
                           gboolean      force,
                           GError      **error)
      {
              /* ... */
      }

#### Variable definitions

Variables should be aligned in the same way as function arguments. Put one space between longest type and arguments and align with * and ** in the same way as for function arguments.

### Structure of source files

All source files should start with the header used in Planner.

####

    /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
    /*
     * Copyright (C) 2002 Your name <your@email>
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License as
     * published by the Free Software Foundation; either version 2 of the
     * License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     * General Public License for more details.
     *
     * You should have received a copy of the GNU General Public
     * License along with this program; if not, write to the
     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
     * Boston, MA 02110-1301, USA.
     */

The first row is to make sure that everyone using Emacs gets the correct tab-width and programming mode.

#### Header Files

Header files is built up as follows.

##### Commented header file

    /* Header as described above */

    /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
    /*
     * Copyright (C) 2001-2002 CodeFactory AB
     * Copyright (C) 2001-2002 Richard Hult <rhult@codefactory.se>
     * Copyright (C) 2001-2002 Mikael Hallendal <micke@codefactory.se>
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License as
     * published by the Free Software Foundation; either version 2 of the
     * License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     * General Public License for more details.
     *
     * You should have received a copy of the GNU General Public
     * License along with this program; if not, write to the
     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
     * Boston, MA 02110-1301, USA.
     */

    /*
     * include guards, these are to make sure that the same header only
     * gets included once.
     */
    #ifndef __MRP_ASSIGNMENT_H__
    #define __MRP_ASSIGNMENT_H__

    /*
     * Includes needed by this header, put as much includes as possible in
     * the C-file rather than the header file.
     */
    #include <planner/mrp-object.h>
    #include <planner/mrp-time.h>
    #include <planner/mrp-types.h>

    /*
     * If it is a class you are defining you need this convenience macros,
     * they should come directly after the includes.
     */
    #define MRP_TYPE_ASSIGNMENT         (mrp_assignment_get_type ())
    #define MRP_ASSIGNMENT(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o),
                                         MRP_TYPE_ASSIGNMENT, MrpAssignment))
    #define MRP_ASSIGNMENT_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k),
                                         MRP_TYPE_ASSIGNMENT, MrpAssignmentClass))
    #define MRP_IS_ASSIGNMENT(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o),
                                         MRP_TYPE_ASSIGNMENT))
    #define MRP_IS_ASSIGNMENT_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k),
                                         MRP_TYPE_ASSIGNMENT))
    #define MRP_ASSIGNMENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o),
                                         MRP_TYPE_ASSIGNMENT, MrpAssignmentClass))

    /*
     * Defining the class structures
     */
    typedef struct _MrpAssignmentClass MrpAssignmentClass;
    typedef struct _MrpAssignmentPriv  MrpAssignmentPriv;

    struct _MrpAssignment {
            MrpObject          parent;

            MrpAssignmentPriv *priv;
    };

    struct _MrpAssignmentClass {
            MrpObjectClass parent_class;
    };

    /* Function declarations */
    GType              mrp_assignment_get_type     (void) G_GNUC_CONST;

    MrpAssignment     *mrp_assignment_new          (void);

    MrpTimeInterval   *mrp_assignment_get_interval (MrpAssignment *assignment);

    MrpTask           *mrp_assignment_get_task     (MrpAssignment *assignment);
    MrpResource       *mrp_assignment_get_resource (MrpAssignment *assignment);
    gint               mrp_assignment_get_units    (MrpAssignment *assignemnt);

    /* End of the include guard */
    #endif /* __MRP_ASSIGNMENT_H__ */

#### C Files

##### Commented C file

    /* Same header as in the header file */

    /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
    /*
     * Copyright (C) 2001-2002 CodeFactory AB
     * Copyright (C) 2001-2002 Richard Hult <rhult@codefactory.se>
     * Copyright (C) 2001-2002 Mikael Hallendal <micke@codefactory.se>
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License as
     * published by the Free Software Foundation; either version 2 of the
     * License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     * General Public License for more details.
     *
     * You should have received a copy of the GNU General Public
     * License along with this program; if not, write to the
     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
     * Boston, MA 02110-1301, USA.
     */

    /*
     * Declarations of private structures and enums, the should come
     * before the internal functions since some of the internal functions
     * might need these structures/enums.
     */
    struct _MrpAssignmentPriv {
    	MrpTask     *task;
    	MrpResource *resource;

    	gint         units;
    };

    /* Properties */
    enum {
            PROP_0,
            PROP_TASK,
            PROP_RESOURCE,
            PROP_UNITS
    };

    /* Declaration of internal functions */
    static void mpa_class_init        (MrpAssignmentClass *klass);
    static void mpa_init              (MrpAssignment      *assignment);
    static void mpa_finalize          (GObject            *object);
    static void mpa_set_property      (GObject            *object,
    				   guint               prop_id,
    				   const GValue       *value,
    				   GParamSpec         *pspec);
    static void mpa_get_property      (GObject            *object,
    				   guint               prop_id,
    				   GValue             *value,
    				   GParamSpec         *pspec);

    /*
     * Declaration of internal file global variables
     * NOTE! Try to not use file global variables and instead put them in
     *       a privat structure as in this example
     */
    static MrpObjectClass *parent_class;

    /*
     * Put the get_type function as the first function implementation.
     */
    GType
    mrp_assignment_get_type (void)
    {
            /* ... */
    }

    /*
     * It should be directly followed by the static variables
     * (in the same order as they were defined).
     */
    static void
    mpa_class_init (MrpAssignmentClass *klass)
    {
          /* <snip> */
    }

    /* After the internal functions you put the implementations of the
     * external functions.
     * (These too in the same order as they were declared).
     */

The reason I'm nagging about putting the implementations in the same order as the declarations is that it's much easier to find a function if you do.

#### Use of private structures

We strongly suggest that you use private structures as where done in the code example above. This makes the code better object oriented and makes sure that you are not using the internal variables directly.

## Design of Planner

### Directory structure

#### libplanner

    libplanner
     |
     +- docs              All documentation
     |   |
     |   +- design        Design documentation
     |
     |
     +- planner         The exported libplanner
     |
     |
     +- po                Translation files.
     |
     |
     +- storage-modules   Storage modules that can be used from Planner
     |   |
     |   +- mpx           MPX loader (Microsoft Project eXchange format)
     |   |
     |   +- planner-1   The old Planner 0.5 file format
     |   |
     |   +- xml           The new XML-based format (currently not used).
     |
     |
     +- tests             Various tests to check that the library does what it's
                          supposed to do.

#### planner

    planner
     |
     +- data                   Extra data files.
     |   |
     |   +- icons              Icon files for the GUI and the desktop.
     |   |
     |   +- mime               Mime-type information for .planner files.
     |
     |
     +- docs                   Documentation about Planner
     |   |
     |   +- design             Design documents
     |   |
     |   +- user-guide         Planner User Guide
     |
     |
     +- po                     Translation files.
     |
     |
     +- src                    The source code for Planner.
         |
         +- app                Main application files.
         |                     (including the planner binary).
         |
         +- cell-renderers     Various GtkTreeView cell renderers
         |
         +- dialogs            The dialogs used in Planner (the more
         |   |                 complicated).
         |   |
         |   +- task-dialog    The Task Dialog (used to edit task properties)
         |
         +- models             GtkTreeView storage modules.
         |
         +- util               Utility functions and marshal definitions used
         |                     throughout the entire Planner
         |
         +- widgets            Own defined widgets.
         |   |
         |   +- sidebar        The Sidebar used in Planner, we have our own
         |                     now instead of using the one from GAL.
         |
         +- views              The various views (displayed in the sidebar).
             |
             +- gantt          The Gantt view and the Task table views. Put
             |                 together because they have very much in common
             |                 and depend on each other.
             |
             +- resources      Resource view and Group dialog (should probably
                               be moved to dialogs/group-dialog).