Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

utils.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the OPIE Project
00003 
00004                =.            Copyright (c)  2002 Andy Qua <andy.qua@blueyonder.co.uk>
00005              .=l.                                Dan Williams <drw@handhelds.org>
00006            .>+-=
00007  _;:,     .>    :=|.         This file is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This file is distributed in the hope that
00015      +  .  -:.       =       it will be useful, but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU General
00019 ..}^=.=       =       ;      Public License for more details.
00020 ++=   -.     .`     .:
00021  :     =  ...= . :.=-        You should have received a copy of the GNU
00022  -.   .:....=;==+<;          General Public License along with this file;
00023   -_. . .   )=.  =           see the file COPYING. If not, write to the
00024     --        :-=`           Free Software Foundation, Inc.,
00025                              59 Temple Place - Suite 330,
00026                              Boston, MA 02111-1307, USA.
00027 
00028 */
00029 
00030 #include <sys/vfs.h>
00031 
00032 #include "utils.h"
00033 #include "global.h"
00034 
00035 Utils :: Utils()
00036 {
00037 }
00038 
00039 Utils :: ~Utils()
00040 {
00041 }
00042 
00043 QString Utils :: getPathfromIpkFilename( const QString &file )
00044 {
00045     int p = file.findRev( "/" );
00046     QString path = "";
00047     if ( p != -1 )
00048         path = file.left( p );
00049 
00050     return path;
00051 
00052 }
00053 
00054 QString Utils :: getFilenameFromIpkFilename( const QString &file )
00055 {
00056     int p = file.findRev( "/" );
00057     QString name = file;
00058     if ( p != -1 )
00059         name = name.mid( p + 1 );
00060 
00061 
00062     return name;
00063 }
00064 
00065 QString Utils :: getPackageNameFromIpkFilename( const QString &file )
00066 {
00067     int p = file.findRev( "/" );
00068     QString name = file;
00069     if ( p != -1 )
00070         name = name.mid( p + 1 );
00071     p = name.find( "_" );
00072     QString packageName = name.mid( 0, p );
00073     return packageName;
00074 }
00075 
00076 QString Utils :: getPackageVersionFromIpkFilename( const QString &file )
00077 {
00078     int p = file.findRev( "/" );
00079     QString name = file;
00080     if ( p != -1 )
00081         name = name.mid( p + 1 );
00082     p = name.find( "_" ) + 1;
00083     int p2 = name.find( "_", p );
00084     QString version = name.mid( p, p2 - p );
00085     return version;
00086 }
00087 
00088 
00089 bool Utils :: getStorageSpace( const char *path, long *blockSize, long *totalBlocks, long *availBlocks )
00090 {
00091     bool ret = false;
00092 
00093     struct statfs fs;
00094     if ( !statfs( path, &fs ) )
00095     {
00096         *blockSize = fs.f_bsize;
00097         *totalBlocks = fs.f_blocks;
00098         *availBlocks = fs.f_bavail;
00099         ret = true;
00100     }
00101 
00102     return ret;
00103 }
00104 

Generated on Sat Nov 5 16:17:48 2005 for OPIE by  doxygen 1.4.2