/* Copyright 2010 Reza Arbab Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #define class _class #include #include #include #undef class #include #include #include #include #include #include #include #include #include #include char * device_description(struct CuDv *cudv) { char *desc= NULL; struct PdDv *pddv = cudv->PdDvLn; /* link to Predefined Devices database */ nl_catd cat; cat = catopen("/usr/lib/methods/devices.cat", NL_CAT_LOCALE); if ((int)cat == -1) return NULL; desc = strdup(catgets(cat, pddv->setno, pddv->msgno, "N/A") ); catclose(cat); return desc; } bool list_devices(QListView *lBox, char *criteria) { struct CuDv *cudv; /* Customized Devices */ struct listinfo info; int i; char *cudv_desc; QString cudv_status; QListViewItem *lastitem= NULL; lBox->addColumn(i18n("Name")); lBox->addColumn(i18n("Status")); lBox->addColumn(i18n("Location")); lBox->addColumn(i18n("Description")); if (odm_initialize() == -1) { kError(0) << "odm_initialize() failed: odmerrno = " << odmerrno << endl; return (false); } cudv = (struct CuDv *) odm_get_list(CuDv_CLASS, criteria, &info, 100, 2); if ((int)cudv == -1) { odm_terminate(); kError(0) << "odm_get_list() failed: odmerrno = " << odmerrno << endl; return (false); } else if (!cudv) /* empty list */ { odm_terminate(); return (true); } for (i=0; i tosize) /* E.g., from 2048 to 512. */ return blocks * (fromsize / tosize); else /* E.g., from 256 to 512. */ return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize); } /* Fill in the fields of FSP with information about space usage for the filesystem on which PATH resides. Return 0 if successful, -1 if not. */ #define CONVERT_BLOCKS(b) fs_adjust_blocks ((b), fsd.f_bsize, 512) static int get_fs_usage(char *path, long *l_total, long *l_avail) { struct statfs fsd; /* 4.3BSD, SunOS 4, HP-UX, AIX. */ unsigned long fsu_blocks, fsu_bfree, fsu_bavail; *l_total = *l_avail = 0; if (statfs(path, &fsd) < 0) return -1; fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks); fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree); fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail); *l_avail = getuid() ? fsu_bavail/2 : fsu_bfree/2; *l_total = fsu_blocks/2; return 0; }