~ghugesss/xpad/refactor_code

« back to all changes in this revision

Viewing changes to src/xpad-session-manager.c

  • Committer: Arthur Borsboom
  • Date: 2014-06-20 00:28:20 UTC
  • mfrom: (665.1.67 xpad-4.3)
  • Revision ID: arthurborsboom@gmail.com-20140620002820-c4nuneh78qv4pu31
    Arthur Borsboom 2014-06-20 * Fix: reduced code by using existing functions, merging functions, removing obsolete code and duplicate texts
    Arthur Borsboom 2014-06-19 * Fix: Another try to prevent an error loop on application exit

Show diffs side-by-side

added added

removed removed

Lines of Context:
213
213
        prop[3].vals = vals.user;
214
214
        prop[4].vals = vals.process;
215
215
        
216
 
        for (i = 0; i < G_N_ELEMENTS (prop); i++) {
 
216
        for (i = 0; i < G_N_ELEMENTS (prop); i++)
217
217
                props[i] = &prop[i];
218
 
        }
219
218
        
220
219
        pw = getpwuid (getuid ());
221
220
 
222
221
        /* While setting all the properties, safe casts are being used. */
 
222
        const gchar *casting_warning = "Casting problem occured in the session manager. Xpad might not function as expected. Please send a bugreport.";
223
223
        vals.user->value = pw ? pw->pw_name : "";
224
224
        string_length = strlen (vals.user->value);
225
225
        if (string_length <= INT_MAX)
226
226
                vals.user->length = (int) string_length;
227
227
        else
228
 
                g_warning("While setting the session manager properties a casting problem has occured. Xpad might not function as expected. Please send a bugreport.");
 
228
                g_warning(casting_warning);
229
229
        
230
230
        vals.program->value = command;
231
231
        string_length = strlen (vals.program->value);
232
232
        if (string_length <= INT_MAX)
233
233
                vals.program->length = (int) string_length;
234
234
        else
235
 
                g_warning("While setting the session manager properties a casting problem has occured. Xpad might not function as expected. Please send a bugreport.");
 
235
                g_warning(casting_warning);
236
236
        
237
237
        vals.clone->value = command;
238
238
        string_length = strlen (vals.clone->value);
239
239
        if (string_length <= INT_MAX)
240
240
                vals.clone->length = (int) string_length;
241
241
        else
242
 
                g_warning("While setting the session manager properties a casting problem has occured. Xpad might not function as expected. Please send a bugreport.");
 
242
                g_warning(casting_warning);
243
243
        
244
244
        vals.restart[0].value = command;
245
245
        string_length = strlen (vals.restart[0].value);
246
246
        if (string_length <= INT_MAX)
247
247
                vals.restart[0].length = (int) string_length;
248
248
        else
249
 
                g_warning("While setting the session manager properties a casting problem has occured. Xpad might not function as expected. Please send a bugreport.");
 
249
                g_warning(casting_warning);
250
250
 
251
251
        vals.restart[1].value = "--sm-client-id";
252
252
        string_length = strlen (vals.restart[1].value);
253
253
        if (string_length <= INT_MAX)
254
254
                vals.restart[1].length = (int) string_length;
255
255
        else
256
 
                g_warning("While setting the session manager properties a casting problem has occured. Xpad might not function as expected. Please send a bugreport.");
 
256
                g_warning(casting_warning);
257
257
 
258
258
        vals.restart[2].value = client_id;
259
259
        string_length = strlen (vals.restart[2].value);
260
260
        if (string_length <= INT_MAX)
261
261
                vals.restart[2].length = (int) string_length;
262
262
        else
263
 
                g_warning("While setting the session manager properties a casting problem has occured. Xpad might not function as expected. Please send a bugreport.");
 
263
                g_warning(casting_warning);
264
264
        
265
265
        pid_str = g_strdup_printf ("%i", getpid ());
266
266
        vals.process->value = pid_str;
268
268
        if (string_length <= INT_MAX)
269
269
                vals.process->length = (int) string_length;
270
270
        else
271
 
                g_warning("While setting the session manager properties a casting problem has occured. Xpad might not function as expected. Please send a bugreport.");
 
271
                g_warning(casting_warning);
272
272
        
273
273
        SmcSetProperties (xpad_session_manager_conn, 4, (SmProp **) &props);
274
274
        
344
344
}
345
345
 
346
346
static void
347
 
xpad_session_manager_save_global (Bool fast)
348
 
{
349
 
        /* A dirty way to silence the compiler for these unused variables. */
350
 
        (void) fast;
351
 
 
352
 
        /* No need to do anything.  Currently, all xpad pads are always current with
353
 
        hard drive. */
354
 
}
355
 
 
356
 
static void
357
347
xpad_session_manager_save_local (Bool fast)
358
348
{
359
349
        /* A dirty way to silence the compiler for these unused variables. */
387
377
                break;
388
378
        
389
379
        case SmSaveGlobal:
390
 
                xpad_session_manager_save_global (fast);
391
380
                break;
392
381
        
393
382
        case SmSaveBoth:
394
 
                xpad_session_manager_save_global (fast);
395
383
                xpad_session_manager_save_local (fast);
396
384
                break;
397
385
        }