Back to index

libappindicator  12.10.0
generate-id.c
Go to the documentation of this file.
00001 /*
00002 Quick litte lack to generate the ordering ID.
00003 
00004 Copyright 2010 Canonical Ltd.
00005 
00006 Authors:
00007     Ted Gould <ted@canonical.com>
00008 
00009 This program is free software: you can redistribute it and/or modify it 
00010 under the terms of the GNU General Public License version 3, as published 
00011 by the Free Software Foundation.
00012 
00013 This program is distributed in the hope that it will be useful, but 
00014 WITHOUT ANY WARRANTY; without even the implied warranties of 
00015 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
00016 PURPOSE.  See the GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License along 
00019 with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 #include "generate-id.h"
00023 
00024 #define MULTIPLIER 32
00025 
00026 guint32
00027 _generate_id (const AppIndicatorCategory catenum, const gchar * id)
00028 {
00029        guchar category = 0;
00030        guchar first = 0;
00031        guchar second = 0;
00032        guchar third = 0;
00033 
00034        switch (catenum) {
00035        case APP_INDICATOR_CATEGORY_OTHER:
00036               category = MULTIPLIER * 5;
00037               break;
00038        case APP_INDICATOR_CATEGORY_APPLICATION_STATUS:
00039               category = MULTIPLIER * 4;
00040               break;
00041        case APP_INDICATOR_CATEGORY_COMMUNICATIONS:
00042               category = MULTIPLIER * 3;
00043               break;
00044        case APP_INDICATOR_CATEGORY_SYSTEM_SERVICES:
00045               category = MULTIPLIER * 2;
00046               break;
00047        case APP_INDICATOR_CATEGORY_HARDWARE:
00048               category = MULTIPLIER * 1;
00049               break;
00050        default:
00051               g_warning("Got an undefined category: %d", category);
00052               category = 0;
00053               break;
00054        }
00055        
00056        if (id != NULL) {
00057               if (id[0] != '\0') {
00058                      first = id[0];
00059                      if (id[1] != '\0') {
00060                             second = id[1];
00061                             if (id[2] != '\0') {
00062                                    third = id[2];
00063                             }
00064                      }
00065               }
00066        }
00067 
00068        return (((((category * 256) + first) * 256) + second) * 256) + third;
00069 }