~cairo-dock-team/ubuntu/natty/cairo-dock-plug-ins/2.3.0-2.1

« back to all changes in this revision

Viewing changes to GMenu/src/applet-util.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2010-08-10 00:05:57 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810000557-pfxoz5w7hbyclcqh
Tags: 2.2.0~0beta4-0ubuntu1
* New Upstream Version (LP: #614625)
* Fixed a few bugs on LP:
 - LP: #483963: Dustbin applet does not display trashes on all volumes
 - LP: #485159: Some apps have problem with Systray
 - LP: #500677: ~/.xsession-errors is too much used by CD
 - LP: #500979: Shortcuts: the order gets messed up
 - LP: #521531: Mail: crashes on Maildir
 - LP: #519915: GTG: create a new applet to control GTG
 - LP: #526138: GMenu doesn't handle desktop file exec strings properly
 - LP: #531317: CMake: Added an error if the prefix of 'cairo-dock-plugins'
                 is not the same 'cairo-dock-core'
 - LP: #531319: CMake: check the version of 'cairo-dock' when building
                 'cairo-dock-plugins'
 - LP: #537115: Click at the position where icon lavel was, the icon
                 and dock still receive the event
 - LP: #537943: Terminal applet shortkey behaviour
 - LP: #538637: Trash applet doesn't create .trashinfo files on XFCE
 - More details on the 'ChangeLog' file
* debian/rules:
 - Autotools has been replaced by CMake
 - cdbs is now used.
* debian/copyright:
 - Updated with the new applets
* debian/control:
 - Autotools has been replaced by CMake
 - Added libcurl4-gnutls-dev, libindicator-dev, libdbusmenu-glib-dev
   libido-0.1-dev, libical-dev, libdbusmenu-gtk-dev as Build-deps
 - Bump Standard-Version to 3.9.1
 - Wget is required for dnd2share applet
 - Added the exact realease for 'cairo-dock-dev' in order to prevent any
    build error if this package is not already available (thx to didrocks)
* debian/cairo-dock-plug-ins*.install:
 - All sonames are now installed into lib32 or lib64 (lib*)

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
}
86
86
#endif
87
87
 
 
88
#define CD_EXPAND_FIELD_CODES //comment this line to switch off the arguments parsing.
 
89
static gchar * cd_expand_field_codes(const gchar* cCommand, GKeyFile* keyfile)  // Thanks to Tristan Moody for this patch !
 
90
{
 
91
        //g_print ("%s (%s)\n", __func__, cCommand);
 
92
        gchar* cCommandExpanded = NULL;
 
93
#ifdef CD_EXPAND_FIELD_CODES
 
94
        gchar* cField = strchr (cCommand, '%');
 
95
        gchar* cFieldLast;
 
96
        gchar* cFieldCodeToken = NULL;
 
97
        GError* erreur = NULL;
 
98
 
 
99
        // Break out immediately if there are no field codes
 
100
        if( cField == NULL )
 
101
        {
 
102
                cCommandExpanded = g_strdup(cCommand);
 
103
                return cCommandExpanded;
 
104
        }
 
105
        
 
106
        // parse all the %x tokens, replacing them with the value they represent.
 
107
        // Exec=krusader -caption "%c" %i %m 
 
108
        GString *sExpandedcCommand = g_string_new ("");
 
109
        g_string_append_len (sExpandedcCommand, cCommand, cField - cCommand/** - (*(cField-1) != ' ')*/);  // take the command until the first % (not included).
 
110
        while ( cField != NULL )
 
111
        {
 
112
                cField ++;  // jump to the code.
 
113
                gboolean bAddQuote = FALSE;
 
114
                switch ( *cField ) // Make sure field code is valid
 
115
                {
 
116
                        case 'f':
 
117
                        case 'F':
 
118
                        case 'u':
 
119
                        case 'U':  //Is there any reason to expect these codes in a launcher for the main menu?
 
120
                                cd_warning("Unexpected field code %%%c in exec string '%s' : cannot handle file or url codes in the menu.", *cField, cCommand);
 
121
                                break;
 
122
                        case 'd':
 
123
                        case 'D':
 
124
                        case 'n':
 
125
                        case 'N':
 
126
                        case 'w':
 
127
                        case 'm':  //Deprecated field codes ignored and stripped, per freedesktop spec
 
128
                                cd_warning("Deprecated field code %%%c ignored in exec string '%s'.", *cField, cCommand);
 
129
                                break;
 
130
                        case 'c':
 
131
                                cFieldCodeToken = g_key_file_get_locale_string (keyfile, "Desktop Entry", "Name", NULL, &erreur);
 
132
                                if (erreur != NULL)
 
133
                                {
 
134
                                        cd_warning ("Error while expanding %c in exec string '%s' : %s", *cField, cCommand, erreur->message);
 
135
                                        g_error_free (erreur);
 
136
                                        erreur = NULL;
 
137
                                }
 
138
                                if (*(cField-2) == ' ')  // add quotes if not present.
 
139
                                {
 
140
                                        gchar *tmp = cFieldCodeToken;
 
141
                                        cFieldCodeToken = g_strdup_printf ("\"%s\"", cFieldCodeToken);
 
142
                                        g_free (tmp);
 
143
                                }
 
144
                                break;
 
145
                        case 'i':
 
146
                                cFieldCodeToken = g_key_file_get_locale_string (keyfile, "Desktop Entry", "Icon", NULL, NULL);  // Icon key not required.  If not found, no error message necessary.
 
147
                                if (cFieldCodeToken != NULL)
 
148
                                {
 
149
                                        gchar *tmp = cFieldCodeToken;
 
150
                                        cFieldCodeToken = g_strdup_printf ("--icon \"%s\"", cFieldCodeToken);
 
151
                                        g_free (tmp);
 
152
                                }
 
153
                                break;
 
154
                        case 'k':
 
155
                                cd_warning("Field code %%k not handled yet");
 
156
                                break;
 
157
                        case '%': // %% is a literal % sign.
 
158
                                cFieldCodeToken = g_strdup("%");
 
159
                                //cField ++; // to avoid capturing this %-sign as the beginning of the next field code
 
160
                                break;
 
161
                        default:
 
162
                                cd_warning("Invalid field code %%%c in exec string '%s'", *cField, cCommand);
 
163
                                break;  // we'll try to launch it anyway.
 
164
                }
 
165
                
 
166
                if (cFieldCodeToken != NULL)  // there is a token to add to the command.
 
167
                {
 
168
                        g_string_append_printf (sExpandedcCommand, "%s", cFieldCodeToken);
 
169
                        g_free (cFieldCodeToken);
 
170
                        cFieldCodeToken = NULL;
 
171
                }
 
172
                cFieldLast = cField;
 
173
                ///if (*(cField+1) != ' ' && *(cField+1) != '\0')  // on enleve les eventuels '"'.
 
174
                ///     cFieldLast ++;
 
175
                cField = strchr(cField + 1, '%');  // next field.
 
176
                // we append everything between the current filed and the next field.
 
177
                if (cField != NULL)
 
178
                        g_string_append_len (sExpandedcCommand, cFieldLast+1, cField - cFieldLast - 1);
 
179
                else
 
180
                        g_string_append (sExpandedcCommand, cFieldLast+1);
 
181
        }
 
182
        cCommandExpanded = sExpandedcCommand->str;
 
183
        g_string_free (sExpandedcCommand, FALSE);
 
184
#else 
 
185
        gchar *str = strchr (cCommand, '%');
 
186
        if (str != NULL)
 
187
                cCommandExpanded = g_strndup (cCommand, str - cCommand);
 
188
        else
 
189
                cCommandExpanded = g_strdup (cCommand);
 
190
#endif //CD_EXPAND_FIELD_CODES
 
191
        g_print ("cCommandExpanded : %s\n", cCommandExpanded);
 
192
        return cCommandExpanded;
 
193
}
88
194
static void _launch_from_file (const gchar *cDesktopFilePath)
89
195
{
 
196
        //\____________ On ouvre le .desktop
90
197
        GError *erreur = NULL;
91
198
        GKeyFile* keyfile = g_key_file_new();
92
 
        g_key_file_load_from_file (keyfile, cDesktopFilePath, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &erreur);
 
199
        g_key_file_load_from_file (keyfile, cDesktopFilePath, 0, &erreur);  //skip comments and translations.
93
200
        if (erreur != NULL)
94
201
        {
95
202
                cd_warning ("while trying to read %s : %s", cDesktopFilePath, erreur->message);
96
203
                g_error_free (erreur);
97
204
                return ;
98
205
        }
 
206
        //\____________ On recupere la commande.
99
207
        gchar *cCommand = g_key_file_get_string (keyfile, "Desktop Entry", "Exec", &erreur);
100
208
        if (erreur != NULL)
101
209
        {
103
211
                g_error_free (erreur);
104
212
                erreur = NULL;
105
213
        }
106
 
        gchar *cWorkingDirectory = NULL;
107
 
        if (cCommand != NULL)
108
 
        {
109
 
                gchar *str = strchr (cCommand, '%');
110
 
                if (str != NULL)
111
 
                        *str = '\0';
 
214
        g_return_if_fail (cCommand != NULL);
 
215
        
 
216
        //\____________ On gere les arguments de la forme %x.
 
217
        gchar *cCommandExpanded = NULL;
 
218
#ifdef CD_EXPAND_FIELD_CODES
 
219
        cCommandExpanded = cd_expand_field_codes(cCommand, keyfile);
 
220
#else 
 
221
        gchar *str = strchr (cCommand, '%');
 
222
        if (str != NULL)
 
223
                *str = '\0';
 
224
#endif //CD_EXPAND_FIELD_CODES
 
225
        
 
226
        //\____________ On gere le lancement dans un terminal.
 
227
        gboolean bExecInTerminal = g_key_file_get_boolean (keyfile, "Desktop Entry", "Terminal", NULL);
 
228
        if (bExecInTerminal)  // on le fait apres l'expansion.
 
229
        {
 
230
                gchar *cOldCommand = cCommand;
 
231
                const gchar *cTerm = g_getenv ("COLORTERM");
 
232
                if (cTerm != NULL && strlen (cTerm) > 1)  // on filtre les cas COLORTERM=1 ou COLORTERM=y. ce qu'on veut c'est le nom d'un terminal.
 
233
                        cCommand = g_strdup_printf ("$COLORTERM -e \"%s\"", cOldCommand);
 
234
                else if (g_getenv ("TERM") != NULL)
 
235
                        cCommand = g_strdup_printf ("$TERM -e \"%s\"", cOldCommand);
 
236
                else
 
237
                        cCommand = g_strdup_printf ("xterm -e \"%s\"", cOldCommand);
 
238
                g_free (cOldCommand);
 
239
        }
 
240
        
 
241
        //\____________ On recupere le repertoire d'execution.
 
242
        gchar *cWorkingDirectory = g_key_file_get_string (keyfile, "Desktop Entry", "Path", NULL);
 
243
        if (cWorkingDirectory != NULL && *cWorkingDirectory == '\0')
 
244
        {
112
245
                g_free (cWorkingDirectory);
113
 
                cWorkingDirectory = g_key_file_get_string (keyfile, "Desktop Entry", "Path", NULL);
114
 
                if (cWorkingDirectory != NULL && *cWorkingDirectory == '\0')
115
 
                {
116
 
                        g_free (cWorkingDirectory);
117
 
                        cWorkingDirectory = NULL;
118
 
        }
119
 
        }
120
 
        cairo_dock_launch_command_full (cCommand, cWorkingDirectory);
 
246
                cWorkingDirectory = NULL;
 
247
        }
 
248
        
 
249
        //\____________ On lance le tout.
 
250
        cairo_dock_launch_command_full (cCommandExpanded, cWorkingDirectory);
121
251
        g_free (cCommand);
 
252
        g_free (cCommandExpanded);
122
253
        g_free (cWorkingDirectory);
123
254
124
255
static void _launch_from_basename (const gchar *cDesktopFileName)