shortcut.h

Go to the documentation of this file.
00001 #ifndef __SHORTCUT_H__
00002 #define __SHORTCUT_H__
00003 
00004 /**
00005  * File Name  : shortcut.h
00006  *
00007  * Description: Content browser functions handling shortcut files (xx.desktop)
00008  */
00009 
00010 /*
00011  * This file is part of ctb.
00012  *
00013  * ctb is free software: you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation, either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * ctb is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00025  */
00026 
00027 /**
00028  * Copyright (C) 2008 iRex Technologies B.V.
00029  * All rights reserved.
00030  */
00031 
00032 
00033 //----------------------------------------------------------------------------
00034 // Include Files
00035 //----------------------------------------------------------------------------
00036 
00037 #include <glib.h>
00038 
00039 G_BEGIN_DECLS
00040 
00041 
00042 //----------------------------------------------------------------------------
00043 // Macro Definitions
00044 //---------------------------------------------------------------------------- 
00045 
00046 #define MAX_SHORTCUT_NESTING            5       // maximum nesting level for shortcuts,
00047                                                 // i.e. maximum number of shortcuts in a chain
00048 
00049 
00050 //----------------------------------------------------------------------------
00051 // Forward Declarations
00052 //----------------------------------------------------------------------------
00053 
00054 
00055 //----------------------------------------------------------------------------
00056 // Type Declarations
00057 //----------------------------------------------------------------------------
00058 
00059 // types of shortcuts
00060 typedef enum
00061         {
00062             SHORTCUT_EMPTY = 0,
00063             SHORTCUT_TO_FILE,
00064             SHORTCUT_TO_WEB_LOCATION,
00065             SHORTCUT_TO_FOLDER,
00066             SHORTCUT_TO_APPLICATION,
00067             NUM_SHORTCUTS
00068         }                       shortcut_type_t;
00069 
00070 // details from shortcut file
00071 typedef struct
00072         {
00073             // raw key-value data
00074             gchar               *filepath;
00075             GKeyFile            *keyfile;
00076 
00077             // interpreted fields for shortcut
00078             shortcut_type_t     type;
00079             gchar               *name;
00080             gchar               *comment;
00081             union
00082             {
00083                 struct
00084                 {
00085                     gchar       *directory;             // target directory
00086                     gchar       *filename;              // target filename
00087                 }               file;
00088                 struct
00089                 {
00090                     gchar       *url;                   // target URL
00091                 }               web;
00092                 struct
00093                 {
00094                     gchar       *directory;             // target directory
00095                     gchar       *filename;              // target filename (shortcut file)
00096                     gchar       *path;                  // 'Path=' value
00097                 }               folder;
00098                 struct
00099                 {
00100                     gchar       *command_line;
00101                     gchar       *work_dir;
00102                 }               application;
00103             }                   details;
00104         }                       shortcut_t;
00105 
00106 
00107 /**---------------------------------------------------------------------------
00108  *
00109  * Name :  create_shortcut_file
00110  *
00111  * @brief  create a shortcut file
00112  *
00113  * @param  [in]  target_dir     - folder in which the target is located
00114  *                                specified as an absolute path
00115  * @param  [in]  target_file    - file or folder to which the shortcut must point
00116  * @param  [in]  target_display - name displayed for target
00117  * @param  [in]  shortcut_dir   - directory in which the shortcut file (xx.desktop) must be created
00118  *                                specified as an absolute path
00119  * @param  [out] shortcut_file  - filename of the shortcut file created in shortcut_dir,
00120  *                                or ignored when caller passes a NULL pointer here.
00121  *                                Note: caller must allocate and release this GString.
00122  *
00123  * @return ER_OK           - ok
00124  *         ER_NOT_FOUND    - target not found
00125  *         ER_FORBIDDEN    - directory or target directory not allowed
00126  *         or other error code
00127  *
00128  *--------------------------------------------------------------------------*/
00129 int create_shortcut_file ( const gchar   *target_dir,
00130                            const gchar   *target_file,
00131                            const gchar   *target_display,
00132                            const gchar   *shortcut_dir,
00133                                  GString *shortcut_file  );
00134 
00135 
00136 /**---------------------------------------------------------------------------
00137  *
00138  * Name :  parse_shortcut_file
00139  *
00140  * @brief  get details from shortcut file
00141  *         parses shortcut files recursively when applicable
00142  *
00143  * @param  [in]  directory  - directory in which the shortcut file (xx.desktop) is located
00144  * @param  [in]  filename   - filename of the shortcut file
00145  * @param  [out] p_shortcut - structure with details of the requested shortcut,
00146  *                            caller must release this with shortcut_free()
00147  *
00148  * @return ER_OK           - ok
00149  *         ER_NOT_FOUND    - target location not found
00150  *         ER_INVALID_DATA - contents of shortcut file is corrupt
00151  *         ER_FORBIDDEN    - target directory not allowed
00152  *         or other error code
00153  *
00154  *--------------------------------------------------------------------------*/
00155 int parse_shortcut_file ( const gchar      *directory,
00156                           const gchar      *filename,
00157                                 shortcut_t **p_shortcut );
00158 
00159 
00160 /**---------------------------------------------------------------------------
00161  *
00162  * Name :  shortcut_free
00163  *
00164  * @brief  free the memory allocated to a shortcut_t structure
00165  *         and free the memory allocated to elements it contains
00166  *         and clear the pointer passed as argument
00167  *
00168  * @param  [in]  directory - directory in which the shortcut file (xx.desktop) is located
00169  * @param  [in]  fileinfo - details of the shortcut file
00170  *
00171  * @return ER_OK or error code
00172  *
00173  *--------------------------------------------------------------------------*/
00174 #define shortcut_free(thiz)             \
00175         {                               \
00176             shortcut_free_impl(thiz);   \
00177             (thiz) = NULL;              \
00178         }
00179 void shortcut_free_impl ( shortcut_t* thiz );
00180 
00181 
00182 G_END_DECLS
00183 
00184 #endif // __SHORTCUT_H__
Generated by  doxygen 1.6.2-20100208